public override void Init() { if (Prefs.DevMode) { Log.Message("[Carnivale] Carnival is in defending mode."); } foreach (var lord in Map.lordManager.lords) { lord.ReceiveMemo("DangerPresent"); } if (lord.ownedPawns.Count > 10) { var steel = ThingMaker.MakeThing(ThingDefOf.Steel); steel.stackCount = 75; GenPlace.TryPlaceThing(steel, Info.setupCentre, Map, ThingPlaceMode.Near); var aveHostilePos = Map.attackTargetsCache.TargetsHostileToFaction(lord.faction) .Where(targ => !targ.ThreatDisabled()) .Select(targ => targ.Thing.Position) .Average(); var closestPos = Info.carnivalArea.ClosestCellTo(aveHostilePos); var line = CellLine.Between(closestPos, aveHostilePos); if (line.Slope > 1f || line.Slope < -1f) { for (int i = -3; i < 3; i++) { var spot = closestPos + IntVec3.West * i; if (AIBlueprintsUtility.CanPlaceBlueprintAt(spot, ThingDefOf.Sandbags)) { AIBlueprintsUtility.PlaceBlueprint(ThingDefOf.Sandbags, spot); } } } else { for (int i = -3; i < 3; i++) { var spot = closestPos + IntVec3.North * i; if (AIBlueprintsUtility.CanPlaceBlueprintAt(spot, ThingDefOf.Sandbags)) { AIBlueprintsUtility.PlaceBlueprint(ThingDefOf.Sandbags, spot); } } } } }
// OVERRIDE METHODS // public override void Init() { base.Init(); LordToilData_SetupCarnival data = (LordToilData_SetupCarnival)this.data; // Give em a wood for trash sign var log = ThingMaker.MakeThing(ThingDefOf.WoodLog); log.stackCount = 1; GenPlace.TryPlaceThing(log, Info.setupCentre, Map, ThingPlaceMode.Near); // Give chapiteau if (data.TryHaveWorkerCarry(_DefOf.Carn_Crate_TentHuge, 1, CarnUtils.RandomFabricByCheapness()) != 1) { Log.Error("[Carnivale] Could not give " + _DefOf.Carn_Crate_TentHuge + " to carnies of faction " + lord.faction + ". It will not be built."); } // Give lodging tents (currently 8 carnies per lodging tent) int numCarnies = this.lord.ownedPawns.Count - Info.pawnsWithRole[CarnivalRole.Carrier].Count; int numBedTents = numCarnies > 9 ? Mathf.CeilToInt(numCarnies / 8f) : 1; if (data.TryHaveWorkerCarry(_DefOf.Carn_Crate_TentLodge, numBedTents, CarnUtils.RandomFabricByCheapness()) != numBedTents) { Log.Error("[Carnivale] Could not give enough " + _DefOf.Carn_Crate_TentLodge + " to carnies of faction " + lord.faction + ". Some will not be built."); } if (Info.pawnsWithRole[CarnivalRole.Manager].Any()) { if (data.TryHaveWorkerCarry(_DefOf.Carn_Crate_TentMan, 1, CarnUtils.RandomFabricByExpensiveness()) != 1) { Log.Error("[Carnivale] Could not give " + _DefOf.Carn_Crate_TentMan + " to carnies of faction " + lord.faction + ". It will not be built."); } } // Give vendor stalls + entry sign int numStallCrates = Info.pawnsWithRole[CarnivalRole.Vendor].Count + _DefOf.Carn_SignEntry.costList.First().count; data.TryHaveWorkerCarry(_DefOf.Carn_Crate_Stall, numStallCrates, ThingDefOf.WoodLog); // Give game stalls data.TryHaveWorkerCarry(_DefOf.Carn_Crate_GameHighStriker, 1, ThingDefOf.WoodLog); // Place blueprints foreach (Blueprint bp in AIBlueprintsUtility.PlaceCarnivalBlueprints(Info)) { data.blueprints.Add(bp); } // Find spots for carriers to chill + a guard spot var guardSpot = GetCarrierSpots().Average(); // Assign guard spot at carriers Pawn guard = Info.GetBestGuard(); if (guard != null) { //Info.rememberedPositions.Add(guard, guardSpot); Info.guardPositions.Add(guardSpot); // if can feed animals, give em kibble if (!guard.story.WorkTypeIsDisabled(WorkTypeDefOf.Handling)) { Thing kib = ThingMaker.MakeThing(ThingDefOf.Kibble); kib.stackCount = 75; guard.inventory.TryAddItemNotForSale(kib); } } }