private void MakeBlueprintRoom(CellRect mapRect, Map map, MapGeneratorBlueprintDef blueprint, ThingDef stuffDef) { blueprint.buildingData = CleanUpBlueprintData(blueprint.buildingData); blueprint.floorData = CleanUpBlueprintData(blueprint.floorData); blueprint.pawnData = CleanUpBlueprintData(blueprint.pawnData); blueprint.itemData = CleanUpBlueprintData(blueprint.itemData); if (blueprint.buildingData == null && blueprint.floorData == null) { Log.ErrorOnce(string.Format("After cleaning the BlueprintData and FloorData of blueprint {0} -> both are null, nothing will be done!", blueprint.defName), 313001); return; } IntVec3 spawnBaseCell = new IntVec3(mapRect.BottomLeft.x, mapRect.TopRight.y, mapRect.TopRight.z); IntVec3 spawnCell; foreach (IntVec3 cell in mapRect) { // Check all cells and abort if there is something indestructible found if (!CheckCell(cell, map)) { return; } } allSpawnedPawns = null; try { // Work through blueprint. Note: top-left to bottom-right for (int zn = 0; zn < blueprint.size.z; zn++) { for (int x = 0; x < blueprint.size.x; x++) { //// map can be clipped, don't work with the clipped parts //if (x > mapRect.Width - 1 || zn > mapRect.Height - 1) // continue; spawnCell = spawnBaseCell + new IntVec3(x, 0, -zn); int itemPos = x + blueprint.size.x * zn; ThingDef thingDef = TryGetThingDefFromBuildingData(blueprint, itemPos); Rot4 thingRot = TryGetRotationFromBuildingData(blueprint, itemPos); TerrainDef terrainDef = TryGetTerrainDefFromFloorData(blueprint, itemPos); PawnKindDef pawnKindDef = TryGetPawnKindDefFromPawnData(blueprint, itemPos); ThingDef itemDef = TryGetItemDefFromItemData(blueprint, itemPos); List <Thing> list = map.thingGrid.ThingsListAt(spawnCell); for (int i = 0; i < list.Count; i++) { if (list[i].def == thingDef) { continue; } } //Only clear the space, if something will be made here if (thingDef != null || terrainDef != null || pawnKindDef != null || itemDef != null) { ClearCell(spawnCell, map); } if ((blueprint.canHaveHoles || (MapGenerator_ModSettings.createAllNonPawnBPsWithHoles && (blueprint.pawnLegend == null || blueprint.pawnLegend.Count <= 0))) && Rand.Value < MapGenerator_ModSettings.chanceForHoles) { continue; } // If placed on water, increase the hole chance, if no pawns are to be placed! if (spawnCell.GetTerrain(map).defName.ToLower().Contains("water") && (blueprint.pawnLegend == null || blueprint.pawnLegend.Count <= 0) && Rand.Value < MapGenerator_ModSettings.chanceForHolesOnWater) { continue; } TrySetCellAs(spawnCell, map, thingDef, thingRot, stuffDef, terrainDef, pawnKindDef, itemDef, blueprint); } } } catch (Exception ex) { Log.Warning("Misc. MapGenerator -- Error with blueprint '" + blueprint.defName + "'. Placement position at " + mapRect.CenterCell.ToString() + " on a map of the size " + map.Size.ToString() + "\n" + ex.Message + "\n" + ex.StackTrace); } // If pawns are spawned, place ancient shrine trigger if (allSpawnedPawns != null && allSpawnedPawns.Count > 0) { int nextSignalTagID = Find.UniqueIDsManager.GetNextSignalTagID(); string signalTag = "ancientTempleApproached-" + nextSignalTagID; SignalAction_Letter signalAction_Letter = (SignalAction_Letter)ThingMaker.MakeThing(ThingDefOf.SignalAction_Letter, null); signalAction_Letter.signalTag = signalTag; signalAction_Letter.letter = LetterMaker.MakeLetter("LetterLabelAncientShrineWarning".Translate(), "AncientShrineWarning".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(mapRect.CenterCell, map, false)); GenSpawn.Spawn(signalAction_Letter, mapRect.CenterCell, map); RectTrigger rectTrigger = (RectTrigger)ThingMaker.MakeThing(ThingDefOf.RectTrigger, null); rectTrigger.signalTag = signalTag; rectTrigger.Rect = mapRect.ExpandedBy(1).ClipInsideMap(map); rectTrigger.destroyIfUnfogged = true; GenSpawn.Spawn(rectTrigger, mapRect.CenterCell, map); } // also if pawns are spawned make the appropriate LordJob LordJob lordJob; if (allSpawnedPawns != null && allSpawnedPawns.Count > 0) { if (blueprint.factionSelection == FactionSelection.friendly) { lordJob = new LordJob_AssistColony(allSpawnedPawns[0].Faction, allSpawnedPawns[0].Position); } else { if (Rand.Value < 0.5f) { lordJob = new LordJob_DefendPoint(allSpawnedPawns[0].Position); } else { lordJob = new LordJob_AssaultColony(allSpawnedPawns[0].Faction, false, false, false, false, false); } } LordMaker.MakeNewLord(allSpawnedPawns[0].Faction, lordJob, map, allSpawnedPawns); allSpawnedPawns = null; } }
protected override void FinalizeDesignationSucceeded() { base.FinalizeDesignationSucceeded(); CompSkyMind csm = target.TryGetComp <CompSkyMind>(); CompAndroidState cas = target.TryGetComp <CompAndroidState>(); string surrogateName = target.LabelShortCap; CompSurrogateOwner cso = null; if (cas.externalController != null) { surrogateName = cas.externalController.LabelShortCap; cso = cas.externalController.TryGetComp <CompSurrogateOwner>(); } Lord clord = target.GetLord(); int nbp = Utils.GCATPP.getNbHackingPoints(); int nbpToConsume = 0; //Check points switch (hackType) { case 1: nbpToConsume = Settings.costPlayerVirus; break; case 2: nbpToConsume = Settings.costPlayerExplosiveVirus; break; case 3: nbpToConsume = Settings.costPlayerHackTemp; break; case 4: nbpToConsume = Settings.costPlayerHack; break; } if (nbpToConsume > nbp) { Messages.Message("ATPP_CannotHackNotEnoughtHackingPoints".Translate(), MessageTypeDefOf.NegativeEvent); return; } //Si faction alliée ou neutre ==> pénalitée if (target.Faction.RelationKindWith(Faction.OfPlayer) != FactionRelationKind.Hostile) { target.Faction.TryAffectGoodwillWith(Faction.OfPlayer, -1 * Rand.Range(5, 36)); } //Application effet switch (hackType) { case 1: case 2: csm.Hacked = hackType; //Surrogate va attaquer la colonnie target.SetFactionDirect(Faction.OfAncients); LordJob_AssistColony lordJob; Lord lord = null; IntVec3 fallbackLocation; RCellFinder.TryFindRandomSpotJustOutsideColony(target.PositionHeld, target.Map, out fallbackLocation); target.mindState.Reset(); target.mindState.duty = null; target.jobs.StopAll(); target.jobs.ClearQueuedJobs(); target.ClearAllReservations(); if (target.drafter != null) { target.drafter.Drafted = false; } lordJob = new LordJob_AssistColony(Faction.OfAncients, fallbackLocation); if (lordJob != null) { lord = LordMaker.MakeNewLord(Faction.OfAncients, lordJob, Current.Game.CurrentMap, null); } if (clord != null) { if (clord.ownedPawns.Contains(target)) { clord.Notify_PawnLost(target, PawnLostCondition.IncappedOrKilled, null); } } lord.AddPawn(target); //Si virus explosive enclenchement de la détonnation if (hackType == 2) { csm.infectedExplodeGT = Find.TickManager.TicksGame + (Settings.nbSecExplosiveVirusTakeToExplode * 60); } break; case 3: case 4: bool wasPrisonner = target.IsPrisoner; Faction prevFaction = target.Faction; target.SetFaction(Faction.OfPlayer); if (target.workSettings == null) { target.workSettings = new Pawn_WorkSettings(target); target.workSettings.EnableAndInitialize(); } if (clord != null) { if (clord.ownedPawns.Contains(target)) { clord.Notify_PawnLost(target, PawnLostCondition.ChangedFaction, null); } } if (cso != null) { cso.disconnectControlledSurrogate(null); } if (hackType == 4) { //Contorle definitif on jerte l'externalController if (cas != null) { cas.externalController = null; } } target.Map.attackTargetsCache.UpdateTarget(target); PawnComponentsUtility.AddAndRemoveDynamicComponents(target, false); Find.ColonistBar.MarkColonistsDirty(); if (hackType == 3) { csm.Hacked = hackType; csm.hackOrigFaction = prevFaction; if (wasPrisonner) { csm.hackWasPrisoned = true; } else { csm.hackWasPrisoned = false; } csm.hackEndGT = Find.TickManager.TicksGame + (Settings.nbSecDurationTempHack * 60); } else { //Si le surrogate quon veux controlé est infecté alors on enleve l'infection et on reset ses stats if (csm.Infected != -1) { csm.Infected = -1; if (target.skills != null && target.skills.skills != null) { foreach (var sr in target.skills.skills) { sr.levelInt = 0; } } } } break; } Utils.GCATPP.decHackingPoints(nbpToConsume); Utils.soundDefSurrogateHacked.PlayOneShot(null); //Notif d'applciation de l'effet Messages.Message("ATPP_SurrogateHackOK".Translate(surrogateName), target, MessageTypeDefOf.PositiveEvent); //ANimation sonore et visuelle Utils.soundDefSurrogateConnection.PlayOneShot(null); MoteMaker.ThrowDustPuffThick(pos.ToVector3Shifted(), cmap, 4.0f, Color.red); Find.DesignatorManager.Deselect(); }
public override void MapComponentTick() { base.MapComponentTick(); if (Find.TickManager.TicksGame % 250 == 0) { var plants = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy); //Log.Message("Checking orbital strike, " + this.OrbitalHelpActive + " - " + plants.Count); if (plants != null && ((this.OrbitalHelpActive == true && plants.Count > 0) || plants.Count > 2000)) // && Rand.Chance(PurpleIvyData.getFogProgress(plants.Count))) { if (this.OrbitalHelpActive == false) { this.OrbitalHelpActive = true; Find.LetterStack.ReceiveLetter("OrbitalHelpFromAncients".Translate(), "OrbitalHelpFromAncientsDesc".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(plants.RandomElement().Position, map, false)); } PowerBeam powerBeam = (PowerBeam)GenSpawn.Spawn(PurpleIvyDefOf.PI_PowerBeam, plants.RandomElement().Position, this.map, 0); powerBeam.duration = 200; powerBeam.instigator = null; powerBeam.weaponDef = null; powerBeam.StartStrike(); } if ((plants.Count <= 0 || plants == null) && this.OrbitalHelpActive == true) { Log.Message("Orbital help"); this.OrbitalHelpActive = false; List <Pawn> list = new List <Pawn>(); var alpha = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteAlpha); var beta = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteBeta); var gamma = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteGamma); var omega = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteOmega); var guard = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteNestGuard); int pawnCount = alpha.Count; pawnCount += beta.Count; pawnCount += gamma.Count; pawnCount += omega.Count; pawnCount += guard.Count; Predicate <IntVec3> predicate = delegate(IntVec3 c) { return(!GridsUtility.Fogged(c, map) && !GridsUtility.Roofed(c, map) && GenGrid.InBounds(c, map) && GenRadial.RadialCellsAround(c, 10, true).Where(x => map.thingGrid.ThingsListAt(x).Where(y => y.Faction == PurpleIvyData.AlienFaction) != null) != null); }; IntVec3 position = CellFinder.RandomClosewalkCellNear(this.map.Center, this.map, 500, predicate); foreach (var num in Enumerable.Range(1, pawnCount / 2)) { Faction faction = FactionUtility.DefaultFactionFrom(PurpleIvyDefOf.KorsolianFaction); Pawn NewPawn = PawnGenerator.GeneratePawn(PurpleIvyDefOf.KorsolianSoldier, faction); if (faction != null && faction != Faction.OfPlayer) { Lord lord = null; if (this.map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != NewPawn)) { lord = ((Pawn)GenClosest.ClosestThing_Global(NewPawn.Position, this.map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, (Thing p) => p != NewPawn && ((Pawn)p).GetLord() != null, null)).GetLord(); } if (lord == null) { var lordJob = new LordJob_AssistColony(Faction.OfPlayer, position); //LordJob_DefendPoint lordJob = new LordJob_DefendPoint(position); lord = LordMaker.MakeNewLord(faction, lordJob, this.map, null); } lord.AddPawn(NewPawn); } Log.Message(NewPawn?.Faction?.def?.defName); list.Add(NewPawn); } DropPodUtility.DropThingsNear(position, this.map, list, 30, false, true, true, true); Find.LetterStack.ReceiveLetter("AncientsLandOnTheGround".Translate(), "AncientsLandOnTheGroundDesc".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(position, map, false)); } //Log.Message("Alpha limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteAlpha.defName]); //Log.Message("Beta limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteBeta.defName]); //Log.Message("Gamma limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteGamma.defName]); //Log.Message("Omega limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteOmega.defName]); int count = plants.Count; bool comeFromOuterSource; var tempComp = new WorldObjectComp_InfectedTile(); tempComp.infectedTile = map.Tile; if (PurpleIvyUtils.getFogProgressWithOuterSources(count, tempComp, out comeFromOuterSource) > 0f && !map.gameConditionManager.ConditionIsActive(PurpleIvyDefOf.PurpleFogGameCondition)) { GameCondition_PurpleFog gameCondition = (GameCondition_PurpleFog)GameConditionMaker.MakeConditionPermanent (PurpleIvyDefOf.PurpleFogGameCondition); map.gameConditionManager.RegisterCondition(gameCondition); if (comeFromOuterSource == false) { Find.LetterStack.ReceiveLetter(gameCondition.LabelCap, gameCondition.LetterText, gameCondition.def.letterDef, new TargetInfo(map.Center, map, false)); } else { Find.LetterStack.ReceiveLetter("PurpleFogСomesFromInfectedSites".Translate(), "PurpleFogСomesFromInfectedSitesDesc".Translate(), LetterDefOf.ThreatBig, new TargetInfo(map.Center, map, false)); Log.Message("PurpleFogСomesFromInfectedSites: " + map.ToString() + " - " + Find.TickManager.TicksGame.ToString()); } if (map.Parent.GetComponent <WorldObjectComp_InfectedTile>() == null) { var comp = new WorldObjectComp_InfectedTile(); comp.parent = map.Parent; comp.StartInfection(); comp.gameConditionCaused = PurpleIvyDefOf.PurpleFogGameCondition; comp.counter = count; comp.infectedTile = map.Tile; comp.radius = comp.GetRadius(); PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(comp.counter); comp.fillRadius(); map.Parent.AllComps.Add(comp); Log.Message("Adding comp to: " + map.Parent.ToString()); } } } if (Find.TickManager.TicksGame % 60000 == 0) { int count = 0; var alphaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSac); var betaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacBeta); var gammaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacGamma); var nestsEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacNestGuard); var omegaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.ParasiteEgg); Log.Message("Total PurpleIvy count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy).Count.ToString(), true); count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteAlpha).Count; if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteAlpha.defName]) { foreach (var egg in alphaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = true; } } else { foreach (var egg in alphaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = false; } } Log.Message("Total Genny_ParasiteAlpha count on the map: " + count.ToString(), true); count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteBeta).Count; if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteBeta.defName]) { foreach (var egg in betaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = true; } } else { foreach (var egg in betaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = false; } } Log.Message("Total Genny_ParasiteBeta count on the map: " + count.ToString(), true); count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteGamma).Count; if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteGamma.defName]) { foreach (var egg in gammaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = true; } } else { foreach (var egg in gammaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = false; } } Log.Message("Total Genny_ParasiteGamma count on the map: " + count.ToString(), true); count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteOmega).Count; if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteOmega.defName]) { foreach (var egg in omegaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = true; } } else { foreach (var egg in omegaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = false; } } Log.Message("Total Genny_ParasiteOmega count on the map: " + count.ToString(), true); Log.Message("Total Genny_ParasiteNestGuard count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteNestGuard).Count.ToString(), true); Log.Message("Total EggSac count on the map: " + alphaEggs.Count.ToString(), true); Log.Message("Total EggSac beta count on the map: " + betaEggs.Count.ToString(), true); Log.Message("Total EggSac gamma count on the map: " + gammaEggs.Count.ToString(), true); Log.Message("Total EggSac NestGuard count on the map: " + nestsEggs.Count.ToString(), true); Log.Message("Total ParasiteEgg count on the map: " + omegaEggs.Count.ToString(), true); Log.Message("Total GasPump count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.GasPump).Count.ToString(), true); Log.Message("Total GenTurretBase count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.GenTurretBase).Count.ToString(), true); Log.Message("Total Turret_GenMortarSeed count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Turret_GenMortarSeed).Count.ToString(), true); Log.Message("Total Nest count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PI_Nest).Count.ToString(), true); } }
// Token: 0x06000004 RID: 4 RVA: 0x00002428 File Offset: 0x00000628 private void MakeBlueprintRoom(CellRect mapRect, MapGeneratorBlueprintDef blueprint, Map map, ThingDef stuffDef) { blueprint.buildingData = CleanUpBlueprintData(blueprint.buildingData); blueprint.floorData = CleanUpBlueprintData(blueprint.floorData); blueprint.pawnData = CleanUpBlueprintData(blueprint.pawnData); blueprint.itemData = CleanUpBlueprintData(blueprint.itemData); if (blueprint.buildingData == null && blueprint.floorData == null) { Log.ErrorOnce( $"After cleaning the BlueprintData and FloorData of blueprint {blueprint.defName} -> both are null, nothing will be done!", 313001); } else { var a = new IntVec3(mapRect.BottomLeft.x, mapRect.TopRight.y, mapRect.TopRight.z); foreach (var c in mapRect) { if (!CheckCell(c, map)) { return; } } allSpawnedPawns = null; for (var i = 0; i < blueprint.size.z; i++) { for (var j = 0; j < blueprint.size.x; j++) { var c2 = a + new IntVec3(j, 0, -i); var itemPos = j + (blueprint.size.x * i); var thingDef = TryGetThingDefFromBuildingData(blueprint, itemPos); var thingRot = TryGetRotationFromBuildingData(blueprint, itemPos); var terrainDef = TryGetTerrainDefFromFloorData(blueprint, itemPos); var pawnKindDef = TryGetPawnKindDefFromPawnData(blueprint, itemPos); var thingDef2 = TryGetItemDefFromItemData(blueprint, itemPos); var list = map.thingGrid.ThingsListAt(c2); foreach (var thing in list) { if (thing.def == thingDef) { } } if (thingDef != null || terrainDef != null || pawnKindDef != null || thingDef2 != null) { ClearCell(c2, map); } if (!(blueprint.canHaveHoles && Rand.Value < 0.08f)) { TrySetCellAs(c2, thingDef, thingRot, map, stuffDef, terrainDef, pawnKindDef, thingDef2, blueprint); } } } if (allSpawnedPawns != null && allSpawnedPawns.Count > 0) { var rectTrigger = (RectTrigger)ThingMaker.MakeThing(ThingDefOf.RectTrigger); rectTrigger.Rect = mapRect.ExpandedBy(1).ClipInsideMap(map); //rectTrigger.letter = new Letter(Translator.Translate("LetterLabelAncientShrineWarning"), Translator.Translate("AncientShrineWarning"), 1, mapRect.CenterCell); rectTrigger.destroyIfUnfogged = false; GenSpawn.Spawn(rectTrigger, mapRect.CenterCell, map); } if (allSpawnedPawns == null || allSpawnedPawns.Count <= 0) { return; } LordJob lordJob; if (blueprint.factionSelection == FactionSelection.friendly) { lordJob = new LordJob_AssistColony(allSpawnedPawns[0].Faction, allSpawnedPawns[0].Position); } else { if (Rand.Value < 0.5f) { lordJob = new LordJob_DefendPoint(allSpawnedPawns[0].Position); } else { lordJob = new LordJob_AssaultColony(allSpawnedPawns[0].Faction, false, false); } } LordMaker.MakeNewLord(allSpawnedPawns[0].Faction, lordJob, map, allSpawnedPawns); allSpawnedPawns = null; } }
private static void MakeBlueprintObject(CellRect mapRect, Map map, Faction faction, MapGeneratorBlueprintDef blueprint, ThingDef stuffDef) { blueprint.buildingData = GetCleanedBlueprintData(blueprint.buildingData); blueprint.floorData = GetCleanedBlueprintData(blueprint.floorData); blueprint.pawnData = GetCleanedBlueprintData(blueprint.pawnData); blueprint.itemData = GetCleanedBlueprintData(blueprint.itemData); if (blueprint.buildingData == null && blueprint.floorData == null) { Log.Error(string.Format("After cleaning the BlueprintData and FloorData of blueprint {0} -> both are null, nothing will be done!", blueprint.defName)); return; } IntVec3 spawnBaseCell = new IntVec3(mapRect.BottomLeft.x, mapRect.TopRight.y, mapRect.TopRight.z); IntVec3 spawnCell; // Check all cells and abort if there is something indestructible found foreach (IntVec3 cell in mapRect) { if (!CheckCell(cell, map)) { return; } } allSpawnedPawns = null; // Disable automatic room updating map.regionAndRoomUpdater.Enabled = false; int step = 1; while (step <= 4) { // Work through blueprint - Note: top-left to bottom-right // Work step by step: 1st all floors, 2nd all things, 3rd all items, 4th all pawns for (int zn = 0; zn < blueprint.size.z; zn++) { for (int x = 0; x < blueprint.size.x; x++) { // map can be clipped, don't work with the clipped parts if (x > mapRect.Width - 1 || zn > mapRect.Height - 1) { continue; } if (blueprint.canHaveHoles && Rand.Value < 0.08f) { continue; } spawnCell = spawnBaseCell + new IntVec3(x, 0, -zn); if (!TrySetCell_prepare_CheckCell(spawnCell, map)) { continue; } int itemPos = x + blueprint.size.x * zn; try { ThingDef thingDef = TryGetThingDefFromBuildingData(blueprint, itemPos); Rot4 thingRot = TryGetRotationFromBuildingData(blueprint, itemPos); TerrainDef terrainDef = TryGetTerrainDefFromFloorData(blueprint, itemPos); PawnKindDef pawnKindDef = TryGetPawnKindDefFromPawnData(blueprint, itemPos); ThingDef itemDef = TryGetItemDefFromItemData(blueprint, itemPos); //Only clear the space, if something will be made here // Do only in step 1: if (step == 1) { if (thingDef != null || terrainDef != null || pawnKindDef != null || itemDef != null) { ClearCell(spawnCell, map); } } switch (step) { case 1: // Terrain TrySetCell_1_SetFloor(spawnCell, map, terrainDef, thingDef, stuffDef); break; case 2: // Building TrySetCell_2_SetThing(spawnCell, map, thingDef, thingRot, stuffDef); break; case 3: // Item TrySetCell_4_SetItem(spawnCell, map, itemDef, blueprint); break; case 4: // Pawn TrySetCell_5_SetPawn(spawnCell, map, faction, pawnKindDef, blueprint); break; default: return; } } catch (Exception ex) { Log.Warning("MapGeneratorFactionBase - Error while creating the blueprint (" + blueprint.defName + ")\n" + ex.Message + "\n" + ex.StackTrace); } } } step++; } // Update the powernets map.powerNetManager.UpdatePowerNetsAndConnections_First(); // Enable automatic room updating and rebuild all rooms map.regionAndRoomUpdater.Enabled = true; map.regionAndRoomUpdater.RebuildAllRegionsAndRooms(); LordJob lordJob; if (allSpawnedPawns != null && allSpawnedPawns.Count > 0) { if (blueprint.factionSelection == FactionSelection.friendly) { lordJob = new LordJob_AssistColony(allSpawnedPawns[0].Faction, allSpawnedPawns[0].Position); } else { if (Rand.Value < 0.5f) { lordJob = new LordJob_DefendPoint(allSpawnedPawns[0].Position); } else { lordJob = new LordJob_AssaultColony(allSpawnedPawns[0].Faction, false, false, false); } } LordMaker.MakeNewLord(allSpawnedPawns[0].Faction, lordJob, map, allSpawnedPawns); // make the appropriate Lord pawnLord = LordMaker.MakeNewLord(faction, lordJob, map, null); // Get points used by current pawns float pointsUsed = 0f; if (allSpawnedPawns != null && allSpawnedPawns.Count > 0) { foreach (Pawn pawnSpawned in allSpawnedPawns) { pointsUsed += pawnSpawned.kindDef.combatPower; } } if (allSpawnedPawns != null) { foreach (Pawn pawn in allSpawnedPawns) { pawnLord.AddPawn(pawn); } } allSpawnedPawns = null; } }