Skip to content

Commit

Permalink
More Anomaly syncing (#448)
Browse files Browse the repository at this point in the history
* More Anomaly syncing

I'm trying to avoid (too many) spoilers about anomaly, so I'm patching stuff as I go through and progress the DLC. I've gone through and tested some of the stuff that I already saw in game, and fixed whatever needed fixing.

Changes:

- Creating corpse stockpile for harbinger trees needed `SyncContext.MapSelected`
- Synced a float menu option for capturing entity into any holding building
  - The interaction would work if selecting a specific holding building
- Synced a float menu option for drafted carrying an entity to a holding building
  - It was not needed, but was synced like the other similar methods to save up on the amount of data that would end up being synced
- Moved the gizmo for carry to shuttle interaction lower, as the other sync delegates were ordered by their `lambdaOrdinal`
- Synced `CompStudiable.studyEnabled` field changes from `ITab_StudyNotes.DrawTitle`
  - Changing it using a gizmo was synced already
- Synced `CompHoldingPlatformTarget.containmentMode` field changes from `ITab_Entity.FillTab`

* Sync extract bioferrite checkbox

The checkbox was added in a recent update, so it requires an update to `Krafs.RimWorld.Ref` package to work. I've not included it here as I feel it would not fit the PR this belongs to.

* Add SetDebugOnly for a dev-mode only gizmo

* Sync ActivityGizmo/CompActivity, don't sync HarbingerTree.UpdateRoots

Syncing of `HarbingerTree.UpdateRoots` was removed, as the method would naturally be queued up during simulation (SpawnSetup) and called in as a long event, causing the call to be synced. If dev mode syncing was disabled it would end up never being called.

Synced following fields:
- `ActivityGizmo.targetValuePct`
- `CompActivity.suppressIfAbove`
- `CompActivity.suppressionEnabled`

This required creating a sync worker for `ActivityGizmo`.

The syncing here is pretty similar to syncing of `GeneGizmo_Resource`, `Gene_Resource`, and `Gene_Hemogen`. It would potentially be possible to make a more universal approach, but I could not think of one myself.

`SyncGeneGizmoResource` and `SyncActivityGizmoTarget` sync the same field (`Gizmo_Slider.targetValuePct`), but we can't register sync field targeting `Gizmo_Slider` as that type is not syncable.
  • Loading branch information
SokyranTheDragon authored May 24, 2024
1 parent 6390871 commit 29a4dca
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Source/Client/Syncing/Dict/SyncDictDlc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@ public static class SyncDictDlc
}
},
#endregion

#region Anomaly

{
(ByteWriter data, ActivityGizmo gizmo) => WriteSync(data, gizmo.Comp),
(ByteReader data) =>
{
var comp = ReadSync<CompActivity>(data);

// The gizmo may not yet be initialized for the comp.
comp.gizmo ??= new ActivityGizmo(comp.parent);

return (ActivityGizmo)comp.gizmo;
}
}

#endregion
};
}
}
6 changes: 4 additions & 2 deletions Source/Client/Syncing/Game/SyncDelegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public static void Init()
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddHumanlikeOrders), 7).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Capture slave
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddHumanlikeOrders), 8).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Capture prisoner
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddHumanlikeOrders), 9).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Carry to cryptosleep casket
SyncDelegate.LocalFunc(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddHumanlikeOrders), "CarryToShuttleAct").CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Carry to shuttle
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddHumanlikeOrders), 12).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Capture entity
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddHumanlikeOrders), 50).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Reload
SyncDelegate.LocalFunc(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddHumanlikeOrders), "CarryToShuttleAct").CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Carry to shuttle
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddDraftedOrders), 3).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Drafted carry to bed
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddDraftedOrders), 4).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Drafted carry to bed (arrest)
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddDraftedOrders), 5).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Drafted carry entity to holding building
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddDraftedOrders), 6).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Drafted carry to transport shuttle
SyncDelegate.Lambda(typeof(FloatMenuMakerMap), nameof(FloatMenuMakerMap.AddDraftedOrders), 7).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Drafted carry to cryptosleep casket

Expand Down Expand Up @@ -195,7 +197,7 @@ public static void Init()
SyncDelegate.Lambda(typeof(Pawn), nameof(Pawn.GetGizmos), 5).SetDebugOnly(); // Set growth tier

// Building_HoldingPlatform and related comps
SyncDelegate.Lambda(typeof(Building_HoldingPlatform), nameof(Building_HoldingPlatform.GetGizmos), 1); // Set escape tick
SyncDelegate.Lambda(typeof(Building_HoldingPlatform), nameof(Building_HoldingPlatform.GetGizmos), 1).SetDebugOnly(); // Set escape tick
SyncMethod.Lambda(typeof(CompActivity), nameof(CompActivity.CompGetGizmosExtra), 0).SetDebugOnly(); // Dev activity -5%
SyncMethod.Lambda(typeof(CompActivity), nameof(CompActivity.CompGetGizmosExtra), 1).SetDebugOnly(); // Dev activity +5%
SyncMethod.Lambda(typeof(CompActivity), nameof(CompActivity.CompGetGizmosExtra), 2).SetDebugOnly(); // Dev go active/go passive
Expand Down
43 changes: 43 additions & 0 deletions Source/Client/Syncing/Game/SyncFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ public static class SyncFields
public static ISyncField SyncMechCarrierGizmoTargetValue;
public static ISyncField SyncMechCarrierMaxToFill;

public static ISyncField SyncStudiableCompEnabled;
public static ISyncField SyncEntityContainmentMode;
public static ISyncField SyncExtractBioferrite;

public static ISyncField SyncActivityGizmoTarget;
public static ISyncField SyncActivityCompTarget;
public static ISyncField SyncActivityCompSuppression;

public static void Init()
{
SyncMedCare = Sync.Field(typeof(Pawn), nameof(Pawn.playerSettings), nameof(Pawn_PlayerSettings.medCare));
Expand Down Expand Up @@ -208,6 +216,14 @@ public static void Init()
SyncMechAutoRepair = Sync.Field(typeof(CompMechRepairable), nameof(CompMechRepairable.autoRepair));
SyncMechCarrierGizmoTargetValue = Sync.Field(typeof(MechCarrierGizmo), nameof(MechCarrierGizmo.targetValue)).SetBufferChanges();
SyncMechCarrierMaxToFill = Sync.Field(typeof(CompMechCarrier), nameof(CompMechCarrier.maxToFill)).SetBufferChanges();

SyncStudiableCompEnabled = Sync.Field(typeof(CompStudiable), nameof(CompStudiable.studyEnabled));
SyncEntityContainmentMode = Sync.Field(typeof(CompHoldingPlatformTarget), nameof(CompHoldingPlatformTarget.containmentMode));
SyncExtractBioferrite = Sync.Field(typeof(CompHoldingPlatformTarget), nameof(CompHoldingPlatformTarget.extractBioferrite));

SyncActivityGizmoTarget = Sync.Field(typeof(ActivityGizmo), nameof(ActivityGizmo.targetValuePct)).SetBufferChanges();
SyncActivityCompTarget = Sync.Field(typeof(CompActivity), nameof(CompActivity.suppressIfAbove)).SetBufferChanges();
SyncActivityCompSuppression = Sync.Field(typeof(CompActivity), nameof(CompActivity.suppressionEnabled));
}

[MpPrefix(typeof(StorytellerUI), nameof(StorytellerUI.DrawStorytellerSelectionInterface))]
Expand Down Expand Up @@ -523,6 +539,14 @@ static void SyncGeneResourceChange(Gizmo_Slider __instance)
if (geneGizmo.gene is Gene_Hemogen)
SyncGeneHemogenAllowed.Watch(geneGizmo.gene);
}
else if (__instance is ActivityGizmo activityGizmo)
{
SyncActivityGizmoTarget.Watch(activityGizmo);

var comp = activityGizmo.Comp;
SyncActivityCompTarget.Watch(comp);
SyncActivityCompSuppression.Watch(comp);
}
}

[MpPrefix(typeof(ITab_ContentsGenepackHolder), nameof(ITab_ContentsGenepackHolder.DoItemsLists))]
Expand Down Expand Up @@ -557,6 +581,25 @@ static void WatchMechCarrierMaxToFill(MechCarrierGizmo __instance)
SyncMechCarrierGizmoTargetValue.Watch(__instance);
SyncMechCarrierMaxToFill.Watch(__instance.carrier);
}

[MpPrefix(typeof(ITab_StudyNotes), nameof(ITab_StudyNotes.DrawTitle))]
static void CompStudiableEnabledCheckbox(ITab_StudyNotes __instance)
{
var comp = __instance.StudiableThing.TryGetComp<CompStudiable>();
if (comp != null)
SyncStudiableCompEnabled.Watch(comp);
}

[MpPrefix(typeof(ITab_Entity), nameof(ITab_Entity.FillTab))]
static void CompHoldingPlatformTargetMode(ITab_Entity __instance)
{
var comp = __instance.SelPawn.TryGetComp<CompHoldingPlatformTarget>();
if (comp != null)
{
SyncEntityContainmentMode.Watch(comp);
SyncExtractBioferrite.Watch(comp);
}
}
}

}
3 changes: 1 addition & 2 deletions Source/Client/Syncing/Game/SyncMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,9 @@ public static void Init()
SyncMethod.Lambda(typeof(Building_VoidMonolith), nameof(Building_VoidMonolith.GetGizmos), 2).SetDebugOnly(); // Dev relink

// Harbinger Tree
SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.CreateCorpseStockpile));
SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.CreateCorpseStockpile)).SetContext(SyncContext.MapSelected);
SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.AddNutrition)).SetDebugOnly();
SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.SpawnNewTree)).SetDebugOnly();
SyncMethod.Register(typeof(HarbingerTree), nameof(HarbingerTree.UpdateRoots)).SetDebugOnly();
SyncMethod.LocalFunc(typeof(HarbingerTree), nameof(HarbingerTree.GetGizmos), "DelayedSplatter").SetDebugOnly(); // Set blood splatters delay

// Pawn creep joiner tracker
Expand Down

0 comments on commit 29a4dca

Please sign in to comment.