public override void Init() { base.Init(); var customParams = CustomParams; Data.baseRadius = Mathf.InverseLerp(BaseRadiusMin, BaseRadiusMax, (float)lord.ownedPawns.Count / 50); Data.baseRadius = Mathf.Clamp(Data.baseRadius, BaseRadiusMin, BaseRadiusMax); List <Thing> list = new List <Thing>(); var placedBlueprints = CustomSiegeUtility.PlaceBlueprints(Data, base.Map, lord.faction).ToList(); for (int i = 0; i < placedBlueprints.Count; i++) { var blueprint_Build = placedBlueprints[i]; Data.blueprints.Add(blueprint_Build); using (List <ThingDefCountClass> .Enumerator enumerator2 = blueprint_Build.MaterialsNeeded().GetEnumerator()) { while (enumerator2.MoveNext()) { ThingDefCountClass cost = enumerator2.Current; Thing thing = list.FirstOrDefault((Thing t) => t.def == cost.thingDef); if (thing != null) { thing.stackCount += cost.count; } else { Thing thing2 = ThingMaker.MakeThing(cost.thingDef, null); thing2.stackCount = cost.count; list.Add(thing2); } } } ThingDef thingDef = blueprint_Build.def.entityDefToBuild as ThingDef; if (thingDef != null) { ThingDef turret = thingDef; bool allowEMP = false; TechLevel techLevel = lord.faction.def.techLevel; ThingDef thingDef2 = TurretGunUtility.TryFindRandomShellDef(turret, allowEMP, true, techLevel, false, 250f); if (thingDef2 != null) { Thing thing3 = ThingMaker.MakeThing(thingDef2, null); thing3.stackCount = InitalShellsPerCannon; list.Add(thing3); } } } for (int i = 0; i < list.Count; i++) { list[i].stackCount = Mathf.CeilToInt((float)list[i].stackCount * Rand.Range(1f, 1.2f)); } List <List <Thing> > list2 = new List <List <Thing> >(); for (int j = 0; j < list.Count; j++) { while (list[j].stackCount > list[j].def.stackLimit) { int num = Mathf.CeilToInt((float)list[j].def.stackLimit * Rand.Range(0.9f, 0.999f)); Thing thing4 = ThingMaker.MakeThing(list[j].def, null); thing4.stackCount = num; list[j].stackCount -= num; list.Add(thing4); } } List <Thing> list3 = new List <Thing>(); for (int k = 0; k < list.Count; k++) { list3.Add(list[k]); if (k % 2 == 1 || k == list.Count - 1) { list2.Add(list3); list3 = new List <Thing>(); } } List <Thing> list4 = new List <Thing>(); int num2 = Mathf.RoundToInt(NutritionRangePerRaider.RandomInRange / customParams.mealDef.GetStatValueAbstract(StatDefOf.Nutrition) * lord.ownedPawns.Count); for (int l = 0; l < num2; l++) { Thing item = ThingMaker.MakeThing(customParams.mealDef, null); list4.Add(item); } list2.Add(list4); if (lord.faction.def.techLevel >= TechLevel.Industrial) { DropPodUtility.DropThingGroupsNear(Data.siegeCenter, Map, list2, 110); } else { for (int i = 0; i < list2.Count; i++) { var group = list2[i]; if (DropCellFinder.TryFindDropSpotNear(Data.siegeCenter, Map, out IntVec3 pos, false, false)) { for (int j = 0; j < group.Count; j++) { var thing = group[j]; thing.SetForbidden(true, false); GenPlace.TryPlaceThing(thing, pos, Map, ThingPlaceMode.Near); } } } } Data.desiredBuilderFraction = BuilderCountFraction.RandomInRange; }
public override void LordToilTick() { base.LordToilTick(); var customParams = CustomParams; var data = Data; if (lord.ticksInToil == StartBuildingDelay) { lord.CurLordToil.UpdateAllDuties(); } if (lord.ticksInToil > StartBuildingDelay && lord.ticksInToil % 500 == 0) { UpdateAllDuties(); } if (Find.TickManager.TicksGame % 500 == 0) { if (!(from frame in Frames where !frame.Destroyed select frame).Any <Frame>()) { if (!(from blue in data.blueprints where !blue.Destroyed select blue).Any <Blueprint>() && !base.Map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial).Any((Thing b) => b.Faction == lord.faction && b.def.building.buildingTags.Contains("Artillery"))) { lord.ReceiveMemo("NoArtillery"); return; } } var arties = Artillery; int shellCount = 0; int foodCount = 0; for (int i = 0; i < GenRadial.NumCellsInRadius(20); i++) { IntVec3 c = data.siegeCenter + GenRadial.RadialPattern[i]; if (c.InBounds(Map)) { List <Thing> thingList = c.GetThingList(Map); for (int j = 0; j < thingList.Count; j++) { var curThing = thingList[j]; if (curThing.def.IsShell && arties.Any(a => CustomSiegeUtility.AcceptsShell(a, curThing.def))) { shellCount += curThing.stackCount; } if (curThing.def == customParams.mealDef) { foodCount += curThing.stackCount; } } } } // Prevent the shellpocalypse today! if (arties.Any() && shellCount < ReplenishAtShells) { bool allowEMP = false; var techLevel = lord.faction.def.techLevel; var distinctArtillery = data.artilleryCounts.Keys.ToList(); var shellCountsToGive = new Dictionary <ThingDef, int>(); for (int i = 0; i < ShellReplenishCount; i++) { var artillery = distinctArtillery.RandomElementByWeight(a => data.artilleryCounts[a]); ThingDef shellDef = TurretGunUtility.TryFindRandomShellDef(artillery, allowEMP, true, techLevel, false, 250f); if (shellDef != null) { if (shellCountsToGive.ContainsKey(shellDef)) { shellCountsToGive[shellDef]++; } else { shellCountsToGive.Add(shellDef, 1); } } } foreach (var shell in shellCountsToGive) { DropSupplies(shell.Key, shell.Value); } } if (foodCount < FoodUtility.StackCountForNutrition(ReplenishAtMeals, customParams.mealDef.GetStatValueAbstract(StatDefOf.Nutrition))) { DropSupplies(customParams.mealDef, FoodUtility.StackCountForNutrition(MealReplenishCount, customParams.mealDef.GetStatValueAbstract(StatDefOf.Nutrition))); } } }