().ToList();
}
/// The instance the game made for its architect menu, else a new one (the game makes them the same way).
private static TD GameDesignator| () where TD : Designator, new() =>
DefDatabase.AllDefsListForReading
.SelectMany(c => c.AllResolvedDesignators ?? new List())
.FirstOrDefault(d => d.GetType() == typeof(TD)) as TD ?? new TD();
private static ThingDef StuffFor(ThingDef def) => def.MadeFromStuff ? GenStuff.DefaultStuffFor(def) : null;
internal static StorageSettings SettingsOf(Thing t)
{
StorageSettings s = t is IStorageGroupMember member ? member.ThingStoreSettings : (t as IStoreSettingsParent)?.GetStoreSettings();
T.NotNull(s, "storage settings of " + t);
return s;
}
private static Blueprint_Storage PlaceBlueprint(ThingDef def, ThingDef stuff, IntVec3 at)
{
Blueprint_Build placed = GenConstruct.PlaceBlueprintForBuild(def, at, Fixtures.Map, Rot4.North, Faction.OfPlayer, stuff);
Fixtures.Track(placed);
var bp = placed as Blueprint_Storage;
T.NotNull(bp, "a Blueprint_Storage for " + def.defName + " (got " + placed?.GetType().Name + ")");
return bp;
}
///
/// Places a blueprint, lets the test change it, turns it into a frame and completes the frame with a
/// colonist, as a construction job does. Returns the building (tracked).
///
internal static Thing Build(ThingDef def, ThingDef stuff, IntVec3 at, Action onBlueprint = null)
{
Map map = Fixtures.Map;
Blueprint_Storage bp = PlaceBlueprint(def, stuff, at);
onBlueprint?.Invoke(bp);
Pawn worker = Fixtures.Worker();
T.Check(bp.TryReplaceWithSolidThing(worker, out Thing made, out bool _), "the " + def.defName + " blueprint did not turn into a frame");
var frame = made as Frame;
T.NotNull(frame, "the " + def.defName + " frame");
Fixtures.Track(frame);
frame.CompleteConstruction(worker);
Thing built = at.GetThingList(map).FirstOrDefault(t => t.def == def);
T.NotNull(built, "the built " + def.defName);
return Fixtures.Track(built);
}
///
/// Destroys a player building with auto-rebuild on and its cell in the home area, as a raid would, and
/// returns a copy of the rebuild blueprint's settings. Restores auto-rebuild and the home area, then
/// cancels the blueprint as a player would, so Replace Stuff (in -Compat runs) forgets the destroyed
/// building and doesn't revive it into a later test's building on the same cell.
///
private static StorageSettings DestroyWithAutoRebuild(Thing building, CellRect area)
{
Map map = Fixtures.Map;
T.Check(building.def.IsResearchFinished, building.def.defName + " needs research the test colony lacks, so auto-rebuild can't place it");
IntVec3 at = building.Position;
bool autoRebuild = Find.PlaySettings.autoRebuild;
Area_Home home = map.areaManager.Home;
var homeBefore = area.Cells.ToDictionary(c => c, c => home[c]);
try
{
Find.PlaySettings.autoRebuild = true;
foreach (IntVec3 c in area.Cells)
home[c] = true;
building.Destroy(DestroyMode.KillFinalize);
}
finally
{
Find.PlaySettings.autoRebuild = autoRebuild;
foreach (var kv in homeBefore)
home[kv.Key] = kv.Value;
}
Blueprint_Storage bp = at.GetThingList(map).OfType().FirstOrDefault();
T.NotNull(bp, "the rebuild blueprint of " + building.def.defName);
Fixtures.Track(bp);
var copy = new StorageSettings();
copy.CopyFrom(bp.settings);
bp.Destroy(DestroyMode.Cancel);
return copy;
}
}
}
|