public override void Resolve(ResolveParams rp) { if (rp.singleThingToSpawn is Pawn) { ResolveParams resolveParams = rp; resolveParams.singlePawnToSpawn = (Pawn)rp.singleThingToSpawn; BaseGen.symbolStack.Push("pawn", resolveParams); } else { if (rp.singleThingToSpawn != null && rp.singleThingToSpawn.Spawned) { return; } ThingDef thingDef = (rp.singleThingToSpawn != null) ? rp.singleThingToSpawn.def : (rp.singleThingDef ?? ThingSetMakerUtility.allGeneratableItems.Where((ThingDef x) => x.IsWeapon || x.IsMedicine || x.IsDrug).RandomElement()); Rot4? rot = rp.thingRot; IntVec3 result; if (thingDef.category == ThingCategory.Item) { rot = Rot4.North; if (!TryFindSpawnCellForItem(rp.rect, out result)) { if (rp.singleThingToSpawn != null) { rp.singleThingToSpawn.Destroy(); } return; } } else { result = FindBestSpawnCellForNonItem(rp.rect, thingDef, ref rot, out bool hasToWipeBuilding, out bool doesntFit); if ((hasToWipeBuilding | doesntFit) && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.HasValue && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.Value) { return; } } if (!rot.HasValue) { Log.Error("Could not resolve rotation. Bug."); } Thing thing; if (rp.singleThingToSpawn == null) { ThingDef stuff = (rp.singleThingStuff == null || !rp.singleThingStuff.stuffProps.CanMake(thingDef)) ? GenStuff.RandomStuffInexpensiveFor(thingDef, rp.faction) : rp.singleThingStuff; thing = ThingMaker.MakeThing(thingDef, stuff); thing.stackCount = (rp.singleThingStackCount ?? 1); if (thing.stackCount <= 0) { thing.stackCount = 1; } if (thing.def.CanHaveFaction && thing.Faction != rp.faction) { thing.SetFaction(rp.faction); } thing.TryGetComp <CompQuality>()?.SetQuality(QualityUtility.GenerateQualityBaseGen(), ArtGenerationContext.Outsider); if (rp.postThingGenerate != null) { rp.postThingGenerate(thing); } } else { thing = rp.singleThingToSpawn; } if (!rp.spawnBridgeIfTerrainCantSupportThing.HasValue || rp.spawnBridgeIfTerrainCantSupportThing.Value) { BaseGenUtility.CheckSpawnBridgeUnder(thing.def, result, rot.Value); } thing = GenSpawn.Spawn(thing, result, BaseGen.globalSettings.map, rot.Value); if (thing != null && thing.def.category == ThingCategory.Item) { thing.SetForbidden(value: true, warnOnFail: false); } if (rp.postThingSpawn != null) { rp.postThingSpawn(thing); } } }
public override void Resolve(ResolveParams rp) { if (rp.singleThingToSpawn is Pawn) { ResolveParams resolveParams = rp; resolveParams.singlePawnToSpawn = (Pawn)rp.singleThingToSpawn; BaseGen.symbolStack.Push("pawn", resolveParams); } else { if (rp.singleThingToSpawn != null && rp.singleThingToSpawn.Spawned) { return; } ThingDef thingDef = (rp.singleThingToSpawn != null) ? rp.singleThingToSpawn.def : (rp.singleThingDef ?? (from x in ItemCollectionGeneratorUtility.allGeneratableItems where x.IsWeapon || x.IsMedicine || x.IsDrug select x).RandomElement()); Rot4? nullable = rp.thingRot; IntVec3 loc = default(IntVec3); if (thingDef.category == ThingCategory.Item) { nullable = Rot4.North; if (!this.TryFindSpawnCellForItem(rp.rect, out loc)) { if (rp.singleThingToSpawn != null) { rp.singleThingToSpawn.Destroy(DestroyMode.Vanish); } return; } } else { bool flag = default(bool); bool flag2 = default(bool); loc = this.FindBestSpawnCellForNonItem(rp.rect, thingDef, ref nullable, out flag, out flag2); if ((flag || flag2) && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.HasValue && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.Value) { return; } } if (!nullable.HasValue) { Log.Error("Could not resolve rotation. Bug."); } Thing thing; if (rp.singleThingToSpawn == null) { ThingDef stuff = (rp.singleThingStuff == null || !rp.singleThingStuff.stuffProps.CanMake(thingDef)) ? GenStuff.RandomStuffByCommonalityFor(thingDef, (rp.faction != null) ? rp.faction.def.techLevel : TechLevel.Undefined) : rp.singleThingStuff; thing = ThingMaker.MakeThing(thingDef, stuff); Thing thing2 = thing; int? singleThingStackCount = rp.singleThingStackCount; thing2.stackCount = ((!singleThingStackCount.HasValue) ? 1 : singleThingStackCount.Value); if (thing.stackCount <= 0) { thing.stackCount = 1; } if (thing.def.CanHaveFaction && thing.Faction != rp.faction) { thing.SetFaction(rp.faction, null); } CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityUtility.RandomBaseGenItemQuality(), ArtGenerationContext.Outsider); } if (rp.postThingGenerate != null) { rp.postThingGenerate(thing); } } else { thing = rp.singleThingToSpawn; } thing = GenSpawn.Spawn(thing, loc, BaseGen.globalSettings.map, nullable.Value, false); if (thing != null && thing.def.category == ThingCategory.Item) { thing.SetForbidden(true, false); } if (rp.postThingSpawn != null) { rp.postThingSpawn(thing); } } }
public override void Resolve(ResolveParams rp) { if (rp.singlePawnToSpawn == null || !rp.singlePawnToSpawn.Spawned) { Map map = BaseGen.globalSettings.map; IntVec3 loc; if (!SymbolResolver_SinglePawn.TryFindSpawnCell(rp, out loc)) { if (rp.singlePawnToSpawn != null) { Find.WorldPawns.PassToWorld(rp.singlePawnToSpawn, PawnDiscardDecideMode.Decide); } } else { Pawn pawn; if (rp.singlePawnToSpawn == null) { PawnGenerationRequest value; if (rp.singlePawnGenerationRequest != null) { value = rp.singlePawnGenerationRequest.Value; } else { PawnKindDef pawnKindDef; if ((pawnKindDef = rp.singlePawnKindDef) == null) { pawnKindDef = (from x in DefDatabase <PawnKindDef> .AllDefsListForReading where x.defaultFactionType == null || !x.defaultFactionType.isPlayer select x).RandomElement <PawnKindDef>(); } PawnKindDef pawnKindDef2 = pawnKindDef; Faction faction = rp.faction; if (faction == null && pawnKindDef2.RaceProps.Humanlike) { if (pawnKindDef2.defaultFactionType != null) { faction = FactionUtility.DefaultFactionFrom(pawnKindDef2.defaultFactionType); if (faction == null) { return; } } else if (!(from x in Find.FactionManager.AllFactions where !x.IsPlayer select x).TryRandomElement(out faction)) { return; } } PawnKindDef kind = pawnKindDef2; Faction faction2 = faction; int tile = map.Tile; value = new PawnGenerationRequest(kind, faction2, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null); } pawn = PawnGenerator.GeneratePawn(value); if (rp.postThingGenerate != null) { rp.postThingGenerate(pawn); } } else { pawn = rp.singlePawnToSpawn; } if (!pawn.Dead && rp.disableSinglePawn != null && rp.disableSinglePawn.Value) { pawn.mindState.Active = false; } GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish); if (rp.singlePawnLord != null) { rp.singlePawnLord.AddPawn(pawn); } if (rp.postThingSpawn != null) { rp.postThingSpawn(pawn); } } } }
public override void Resolve(ResolveParams rp) { if (rp.singlePawnToSpawn != null && rp.singlePawnToSpawn.Spawned) { return; } Map map = BaseGen.globalSettings.map; if (!TryFindSpawnCell(rp, out var cell)) { if (rp.singlePawnToSpawn != null) { Find.WorldPawns.PassToWorld(rp.singlePawnToSpawn); } return; } Pawn pawn; if (rp.singlePawnToSpawn == null) { PawnGenerationRequest request; if (rp.singlePawnGenerationRequest.HasValue) { request = rp.singlePawnGenerationRequest.Value; } else { PawnKindDef pawnKindDef = rp.singlePawnKindDef ?? DefDatabase <PawnKindDef> .AllDefsListForReading.Where((PawnKindDef x) => x.defaultFactionType == null || !x.defaultFactionType.isPlayer).RandomElement(); Faction result = rp.faction; if (result == null && pawnKindDef.RaceProps.Humanlike) { if (pawnKindDef.defaultFactionType != null) { result = FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType); if (result == null) { return; } } else if (!Find.FactionManager.AllFactions.Where((Faction x) => !x.IsPlayer).TryRandomElement(out result)) { return; } } request = new PawnGenerationRequest(pawnKindDef, result, PawnGenerationContext.NonPlayer, map.Tile); } pawn = PawnGenerator.GeneratePawn(request); if (rp.postThingGenerate != null) { rp.postThingGenerate(pawn); } } else { pawn = rp.singlePawnToSpawn; } if (!pawn.Dead && rp.disableSinglePawn.HasValue && rp.disableSinglePawn.Value) { pawn.mindState.Active = false; } GenSpawn.Spawn(pawn, cell, map); if (rp.singlePawnLord != null) { rp.singlePawnLord.AddPawn(pawn); } if (rp.postThingSpawn != null) { rp.postThingSpawn(pawn); } }
public override void Resolve(ResolveParams rp) { if (rp.singleThingToSpawn is Pawn) { ResolveParams resolveParams = rp; resolveParams.singlePawnToSpawn = (Pawn)rp.singleThingToSpawn; BaseGen.symbolStack.Push("pawn", resolveParams); } else if (rp.singleThingToSpawn == null || !rp.singleThingToSpawn.Spawned) { ThingDef thingDef2; if (rp.singleThingToSpawn == null) { ThingDef thingDef; if ((thingDef = rp.singleThingDef) == null) { thingDef = (from x in ThingSetMakerUtility.allGeneratableItems where x.IsWeapon || x.IsMedicine || x.IsDrug select x).RandomElement <ThingDef>(); } thingDef2 = thingDef; } else { thingDef2 = rp.singleThingToSpawn.def; } Rot4? rot = rp.thingRot; IntVec3 loc; if (thingDef2.category == ThingCategory.Item) { rot = new Rot4?(Rot4.North); if (!this.TryFindSpawnCellForItem(rp.rect, out loc)) { if (rp.singleThingToSpawn != null) { rp.singleThingToSpawn.Destroy(DestroyMode.Vanish); } return; } } else { bool flag; bool flag2; loc = this.FindBestSpawnCellForNonItem(rp.rect, thingDef2, ref rot, out flag, out flag2); if ((flag || flag2) && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit != null && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.Value) { return; } } if (rot == null) { Log.Error("Could not resolve rotation. Bug.", false); } Thing thing; if (rp.singleThingToSpawn == null) { ThingDef stuff; if (rp.singleThingStuff != null && rp.singleThingStuff.stuffProps.CanMake(thingDef2)) { stuff = rp.singleThingStuff; } else { stuff = GenStuff.RandomStuffInexpensiveFor(thingDef2, rp.faction); } thing = ThingMaker.MakeThing(thingDef2, stuff); Thing thing2 = thing; int? singleThingStackCount = rp.singleThingStackCount; thing2.stackCount = ((singleThingStackCount == null) ? 1 : singleThingStackCount.Value); if (thing.stackCount <= 0) { thing.stackCount = 1; } if (thing.def.CanHaveFaction && thing.Faction != rp.faction) { thing.SetFaction(rp.faction, null); } CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityUtility.GenerateQualityBaseGen(), ArtGenerationContext.Outsider); } if (rp.postThingGenerate != null) { rp.postThingGenerate(thing); } } else { thing = rp.singleThingToSpawn; } thing = GenSpawn.Spawn(thing, loc, BaseGen.globalSettings.map, rot.Value, WipeMode.Vanish, false); if (thing != null && thing.def.category == ThingCategory.Item) { thing.SetForbidden(true, false); } if (rp.postThingSpawn != null) { rp.postThingSpawn(thing); } } }