Don't format too much.

This commit is contained in:
Foxtr0t1337
2024-12-28 09:00:44 +08:00
parent eda1f302b7
commit b7e44bc4cc
5 changed files with 46 additions and 38 deletions
@@ -31,12 +31,12 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
{
if (!IsStorageBlocker(thing.def))
return;
var thingEvents = thing.Events();
thingEvents.RegisteredAtThingGrid += SetStorageBlocker;
thingEvents.DeregisteredAtThingGrid += TryUnsetStorageBlocker;
}
public static bool IsStorageBlocker(ThingDef thingDef)
=> (thingDef.entityDefToBuild != null && thingDef.entityDefToBuild.passability != 0)
|| (thingDef.passability != 0
@@ -59,7 +59,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
map.StorageBlockerGrid()[cell] = false;
}
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
=> ilProcessor.ReplaceBodyWith(ReplacementBody);
@@ -70,7 +70,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
if (c.GetItemCount(map) < c.GetMaxItemsAllowedInCell(map))
return true;
var thingsAtCell = map.thingGrid.ThingsListAt(c);
var thingCount = thingsAtCell.Count;
for (var i = 0; i < thingCount; i++)
@@ -105,13 +105,13 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
public override MethodBase TargetMethodBase { get; }
= methodof(StoreUtility.TryFindBestBetterStoreCellForWorker);
protected internal override void OnPatchingCompleted() => ThingEvents.Initialized += TryRegister;
public static void TryRegister(Thing thing)
{
var thingEvents = thing.Events();
if (thing is ISlotGroupParent)
thingEvents.Spawned += StorageSettingsPatches.InitializeSlotGroupParent;
@@ -126,7 +126,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
{
if (cell.GetSlotGroupParent(map) is { } parent and Thing)
parent.GetThingStoreSettings()?.Cache().Notify_ReceivedThing(thing);
map.StorageDistrictGrid()[cell]?.AddThing(thing);
}
@@ -134,7 +134,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
{
if (cell.GetSlotGroupParent(map) is { } parent and Thing)
parent.GetThingStoreSettings()?.Cache().Notify_LostThing(thing);
map.StorageDistrictGrid()[cell]?.RemoveThing(thing);
}
@@ -152,32 +152,32 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
{
if (slotGroup == null || !slotGroup.Settings.AllowedToAccept(t) || !CapacityAllows(slotGroup, t))
return;
var thingPosition = t.SpawnedOrAnyParentSpawned ? t.PositionHeld : carrier.PositionHeld;
var slotGroupCells = slotGroup.CellsList;
var maxValidCellsToCheck
= !FishSettings.ImproveHaulingAccuracy && needAccurateResult
? Mathf.FloorToInt(slotGroupCells.Count * Rand.Range(0.005f, 0.018f))
: 0;
StartOfDistrictLoop:
var districts = GetDistricts(slotGroup);
for (var districtIndex = 0; districtIndex < districts.Length; districtIndex++)
{
var district = districts[districtIndex];
if (!district.CapacityAllows(t))
continue;
var districtCells = districts.Length > 1 ? district.Cells : slotGroupCells;
for (var i = 0; i < districtCells.Count; i++)
{
var slotGroupCell = districtCells[i];
var cellDistance = (float)(thingPosition - slotGroupCell).LengthHorizontalSquared;
if (cellDistance > closestDistSquared
|| !StoreUtility.IsGoodStoreCell(slotGroupCell, map, t, carrier, faction))
{
@@ -189,7 +189,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
district.Parent.ResetAndRemakeDistricts(); // TODO: figure out why this happens
goto StartOfDistrictLoop;
}
closestSlot = slotGroupCell;
closestDistSquared = cellDistance;
foundPriority = slotGroup.Settings.Priority;
@@ -211,7 +211,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
public static bool CapacityAllows(ISlotGroup iSlotGroup, Thing t)
=> iSlotGroup is not SlotGroup slotGroup || CapacityAllows(slotGroup, t);
[MethodImpl(MethodImplOptions.NoInlining)]
public static bool CapacityAllows(SlotGroup slotGroup, Thing t)
{
@@ -221,7 +221,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
ref var cache = ref storageSettings.Cache();
StorageSettingsPatches.Debug.VerifyItemCount((Thing)storageSettings.owner, ref cache);
return cache.FreeSlots > 0 || AcceptsForStacking(ref cache, t);
}
@@ -256,7 +256,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
if (!Debug.LoggedOnce && !(Current.Game?.tickManager?.Paused ?? true))
Debug.LogStuff(haulDestinationManager);
#endif
var foundPriority = currentPriority;
var closestDistSquared = (float)int.MaxValue;
var closestSlot = IntVec3.Invalid;
@@ -270,7 +270,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
for (var priorityGroupIndex = groupCountByPriority.Length; priorityGroupIndex-- > 0;)
{
var groupsOfPriorityCount = groupCountByPriority[priorityGroupIndex];
if ((StoragePriority)priorityGroupIndex < foundPriority) // succeeded finding a higher priority storage
break;
@@ -284,7 +284,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
{
if (i >= listInPriorityOrderCount)
goto FixCache;
var slotGroup = listInPriorityOrder[i++];
int otherGroupMembers;
var storageGroup = slotGroup.StorageGroup;
@@ -293,11 +293,11 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
otherGroupMembers = storageGroup.SpawnedMemberCount() - 1;
if (otherGroupMembers < 0)
goto FixCache;
Debug.VerifyStorageGroup(otherGroupMembers, listInPriorityOrder, i, storageGroup);
groupsOfPriorityCount -= otherGroupMembers;
if (!storageGroup.Accepts(t))
{
i += otherGroupMembers;
@@ -316,10 +316,10 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
if (otherGroupMembers <= 0)
break;
if (i >= listInPriorityOrderCount)
goto FixCache;
otherGroupMembers--;
slotGroup = listInPriorityOrder[i++];
}
@@ -332,10 +332,10 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
foundCell = IntVec3.Invalid;
return false;
}
foundCell = closestSlot;
return true;
FixCache:
if (!hadToFixCache)
{
@@ -355,7 +355,11 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
public static void LogErrorForFailedTryFindBestBetterStoreCellForAttempt(Thing t, Pawn carrier, Map? map,
StoragePriority currentPriority, Faction faction, IntVec3 closestSlot)
=> Log.Error($"Performance Fish's TryFindBestBetterStoreCellFor patch failed to compute accurate "
+ $"results after a recache attempt for thing '{t}', pawn '{carrier}', map '{map}', currentPriority '{currentPriority}', faction '{faction}'. The last found cell was '{closestSlot}'. It is most likely incompatible with something in the mod list.\n{Debug.GetStorageGroupInfo(map?.haulDestinationManager)}");
+ $"results after a recache attempt for thing '{t}', pawn '{carrier}', map '{
map}', currentPriority '{currentPriority}', faction '{
faction}'. The last found cell was '{
closestSlot}'. It is most likely incompatible with something in the mod list.\n{
Debug.GetStorageGroupInfo(map?.haulDestinationManager)}");
[MethodImpl(MethodImplOptions.NoInlining)]
public static void UpdateCache(HaulDestinationManager haulDestinationManager)
@@ -371,13 +375,13 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
if (member.Group != group)
members.RemoveAt(j);
}
if (members.Count == 0)
storageGroups.RemoveAt(i);
}
haulDestinationManager.RecalculateStorageGroupMemberCount();
haulDestinationManager.AllGroupsListInPriorityOrder.InsertionSort(HaulDestinationManager
.CompareSlotGroupPrioritiesDescending);
haulDestinationManager.Cache().OnPriorityChanged(haulDestinationManager);
@@ -423,7 +427,9 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
if (otherSlotGroup.StorageGroup == storageGroup)
continue;
Log.Error($"Incorrect haul destination order! Storage '{otherSlotGroup.parent}' was expected to have Storage group '{storageGroup}', but had '{otherSlotGroup.StorageGroup.ToStringSafe()}' instead");
Log.Error($"Incorrect haul destination order! Storage '{
otherSlotGroup.parent}' was expected to have Storage group '{storageGroup}', but had '{
otherSlotGroup.StorageGroup.ToStringSafe()}' instead");
}
}
@@ -439,10 +445,12 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
var slotGroupsInPriorityOrder = haulDestinationManager?.AllGroupsListInPriorityOrder;
if (slotGroupsInPriorityOrder is null)
return string.Empty;
var storageGroups = haulDestinationManager!.map.storageGroups.groups;
return StringHelper.Resolve($"SlotGroup count: {slotGroupsInPriorityOrder.Count}, StorageGroup count: {storageGroups.Count}, slotGroups in storage groups: {storageGroups
return StringHelper.Resolve($"SlotGroup count: {
slotGroupsInPriorityOrder.Count}, StorageGroup count: {
storageGroups.Count}, slotGroups in storage groups: {storageGroups
.Select(static group => group!.SpawnedMemberCount())
.Sum()}, outside of storage groups: {slotGroupsInPriorityOrder
.Select(static slotGroup => slotGroup.StorageGroup)
@@ -487,7 +495,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
{
public override string? Description { get; }
= "Optimization for this method by reducing its amount of instructions without changing results";
public override MethodBase TargetMethodBase { get; }
= methodof((Func<Thing, SlotGroup>)StoreUtility.GetSlotGroup);
@@ -502,7 +510,7 @@ public sealed class StoreUtilityPrepatches : ClassWithFishPrepatches
{
public override string? Description { get; }
= "Optimization for this method by reducing its amount of instructions without changing results";
public override MethodBase TargetMethodBase { get; }
= methodof(StoreUtility.CurrentHaulDestinationOf);