private static bool SpawnAnimalPrefix(WildAnimalSpawner __instance, ref IntVec3 loc, ref bool __result, Map ___map) { if (ZLevelsMod.settings.allowZLevelsInfestation) { try { bool result = false; var comp = ZUtils.GetMapComponentZLevel(___map); var ZTracker = ZUtils.ZTracker; if (___map.Parent is MapParent_ZLevel && comp != null && ZTracker.GetUpperLevel(___map.Tile, ___map) != null && !ZUtils.GetMapComponentZLevel(ZTracker.GetUpperLevel(___map.Tile, ___map)) .hasCavesBelow.GetValueOrDefault(false)) { result = false; } else { PawnKindDef pawnKindDef = (from a in ___map.Biome.AllWildAnimals where ___map.mapTemperature.SeasonAcceptableFor(a.race) select a) .RandomElementByWeight((PawnKindDef def) => ___map.Biome.CommonalityOfAnimal(def) / def.wildGroupSize.Average); if (pawnKindDef == null) { Log.Error("No spawnable animals right now."); result = false; } else { ZLogger.Message("Spawning animal: " + pawnKindDef + " in biome: " + ___map.Biome); int randomInRange = pawnKindDef.wildGroupSize.RandomInRange; int radius = Mathf.CeilToInt(Mathf.Sqrt((float)pawnKindDef.wildGroupSize.max)); if (___map.Parent is MapParent_ZLevel && !loc.Walkable(___map)) { loc = CellFinderLoose.RandomCellWith((IntVec3 sq) => sq.Walkable(___map), ___map); } for (int i = 0; i < randomInRange; i++) { IntVec3 loc2 = CellFinder.RandomClosewalkCellNear(loc, ___map, radius, null); GenSpawn.Spawn(PawnGenerator.GeneratePawn(pawnKindDef, null), loc2, ___map, WipeMode.Vanish); } result = true; } } __result = result; } catch (Exception ex) { Log.Error("[Z-Levels] SpawnAnimalPrefix patch produced an error. That should not happen and will break things. Send a Hugslib log to the Z-Levels developers. Error message: " + ex); } return(false); } return(true); }
public static bool CanPawnKindAllowed(IntVec3 loc, ref WildAnimalSpawner __instance, ref bool __result) { // public static FieldInfo mapField = typeof(WeatherDecider).GetField("map", BindingFlags.Instance | BindingFlags.NonPublic); Map map = getMap(__instance); if (map.IsSpace()) { __result = false; return(false); } return(true); }
static float CurrentTotalAnimalNumber(WildAnimalSpawner __instance) { // map is a private field so we access it with Traverse var trv = Traverse.Create(__instance); Map map = trv.Field("map").GetValue <Map>(); // count all animals on the map float num = 0f; List <Pawn> allPawnsSpawned = map.mapPawns.AllPawnsSpawned; for (int i = 0; i < allPawnsSpawned.Count; i++) { if (allPawnsSpawned[i].Faction == null) { num++; } } // return the amount of animals on the map return(num); }
static bool Prefix(ref WildAnimalSpawner __instance) { if (Find.TickManager.TicksGame % 1213 < RefcellRespeedConfig.currentTimeMultiplier || __instance.AnimalEcosystemFull || !Rand.Chance(0.02695556f * __instance.DesiredAnimalDensity)) { return(false); } TraverseParms traverseParms = TraverseParms.For(TraverseMode.NoPassClosedDoors); IntVec3 result; Map map = __instance.map; if (!RCellFinder.TryFindRandomPawnEntryCell(out result, __instance.map, CellFinder.EdgeRoadChance_Animal, true, (Predicate <IntVec3>) (cell => map.reachability.CanReachMapEdge(cell, traverseParms)))) { return(false); } __instance.SpawnRandomWildAnimalAt(result); return(false); }
public void ConstructComponents() { this.spawnedThings = new ThingOwner <Thing>(this); this.cellIndices = new CellIndices(this); this.listerThings = new ListerThings(ListerThingsUse.Global); this.listerBuildings = new ListerBuildings(); this.mapPawns = new MapPawns(this); this.dynamicDrawManager = new DynamicDrawManager(this); this.mapDrawer = new MapDrawer(this); this.tooltipGiverList = new TooltipGiverList(); this.pawnDestinationReservationManager = new PawnDestinationReservationManager(); this.reservationManager = new ReservationManager(this); this.physicalInteractionReservationManager = new PhysicalInteractionReservationManager(); this.designationManager = new DesignationManager(this); this.lordManager = new LordManager(this); this.debugDrawer = new DebugCellDrawer(); this.passingShipManager = new PassingShipManager(this); this.haulDestinationManager = new HaulDestinationManager(this); this.gameConditionManager = new GameConditionManager(this); this.weatherManager = new WeatherManager(this); this.zoneManager = new ZoneManager(this); this.resourceCounter = new ResourceCounter(this); this.mapTemperature = new MapTemperature(this); this.temperatureCache = new TemperatureCache(this); this.areaManager = new AreaManager(this); this.attackTargetsCache = new AttackTargetsCache(this); this.attackTargetReservationManager = new AttackTargetReservationManager(this); this.lordsStarter = new VoluntarilyJoinableLordsStarter(this); this.thingGrid = new ThingGrid(this); this.coverGrid = new CoverGrid(this); this.edificeGrid = new EdificeGrid(this); this.blueprintGrid = new BlueprintGrid(this); this.fogGrid = new FogGrid(this); this.glowGrid = new GlowGrid(this); this.regionGrid = new RegionGrid(this); this.terrainGrid = new TerrainGrid(this); this.pathGrid = new PathGrid(this); this.roofGrid = new RoofGrid(this); this.fertilityGrid = new FertilityGrid(this); this.snowGrid = new SnowGrid(this); this.deepResourceGrid = new DeepResourceGrid(this); this.exitMapGrid = new ExitMapGrid(this); this.linkGrid = new LinkGrid(this); this.glowFlooder = new GlowFlooder(this); this.powerNetManager = new PowerNetManager(this); this.powerNetGrid = new PowerNetGrid(this); this.regionMaker = new RegionMaker(this); this.pathFinder = new PathFinder(this); this.pawnPathPool = new PawnPathPool(this); this.regionAndRoomUpdater = new RegionAndRoomUpdater(this); this.regionLinkDatabase = new RegionLinkDatabase(); this.moteCounter = new MoteCounter(); this.gatherSpotLister = new GatherSpotLister(); this.windManager = new WindManager(this); this.listerBuildingsRepairable = new ListerBuildingsRepairable(); this.listerHaulables = new ListerHaulables(this); this.listerMergeables = new ListerMergeables(this); this.listerFilthInHomeArea = new ListerFilthInHomeArea(this); this.reachability = new Reachability(this); this.itemAvailability = new ItemAvailability(this); this.autoBuildRoofAreaSetter = new AutoBuildRoofAreaSetter(this); this.roofCollapseBufferResolver = new RoofCollapseBufferResolver(this); this.roofCollapseBuffer = new RoofCollapseBuffer(); this.wildAnimalSpawner = new WildAnimalSpawner(this); this.wildPlantSpawner = new WildPlantSpawner(this); this.steadyEnvironmentEffects = new SteadyEnvironmentEffects(this); this.skyManager = new SkyManager(this); this.overlayDrawer = new OverlayDrawer(); this.floodFiller = new FloodFiller(this); this.weatherDecider = new WeatherDecider(this); this.fireWatcher = new FireWatcher(this); this.dangerWatcher = new DangerWatcher(this); this.damageWatcher = new DamageWatcher(); this.strengthWatcher = new StrengthWatcher(this); this.wealthWatcher = new WealthWatcher(this); this.regionDirtyer = new RegionDirtyer(this); this.cellsInRandomOrder = new MapCellsInRandomOrder(this); this.rememberedCameraPos = new RememberedCameraPos(this); this.mineStrikeManager = new MineStrikeManager(); this.storyState = new StoryState(this); this.retainedCaravanData = new RetainedCaravanData(this); this.components.Clear(); this.FillComponents(); }
static bool Prefix(WildAnimalSpawner __instance, IntVec3 loc) { // map is private so we access it with Traverse var trv = Traverse.Create(__instance); Map map = trv.Field("map").GetValue <Map>(); if (map == null) { Log.Message("[RD_WildAnimalAlert] Map is null, something is wrong here"); return(false); } // select a valid pawnkind to spawn PawnKindDef pawnKindDef = (from a in map.Biome.AllWildAnimals where map.mapTemperature.SeasonAcceptableFor(a.race) select a).RandomElementByWeight((PawnKindDef def) => map.Biome.CommonalityOfAnimal(def) / def.wildGroupSize.Average); if (pawnKindDef == null) { Log.Error("No spawnable animals right now."); return(false); } // choose an amount of pawns to spawn int randomInRange = pawnKindDef.wildGroupSize.RandomInRange; // and a radius within which to spawn them int radius = Mathf.CeilToInt(Mathf.Sqrt((float)pawnKindDef.wildGroupSize.max)); string text = "DEBUG STRING: something went wrong, contact lost_RD with details"; // check the amount of animals on the map float animals_before_current_spawns = CurrentTotalAnimalNumber(__instance); int males = 0; int females = 0; string malesStr = "WAA_Males".Translate(); string femalesStr = "WAA_Females".Translate(); for (int i = 0; i < randomInRange; i++) { // find a valid place to spawn the pawns IntVec3 loc2 = CellFinder.RandomClosewalkCellNear(loc, map, radius); Pawn newThing = PawnGenerator.GeneratePawn(pawnKindDef, null); if (newThing.gender == Gender.Female) { females++; } else if (newThing.gender == Gender.Male) { males++; } GenSpawn.Spawn(newThing, loc2, map); if (randomInRange == 1) { // text to use when spawning only one animal text = "WAA_Message_SpawnSingle".Translate(newThing.Label, newThing.GetGenderLabel(), newThing.ageTracker.AgeBiologicalYears); //text = String.Concat(new string[] { "A wild ", newThing.Label, " appeared! ", //newThing.gender.ToString(), " ", newThing.Label, ", ", //newThing.ageTracker.AgeBiologicalYears.ToString(), " years old. ", //}); } } if (males == 1) { malesStr = "WAA_Male".Translate(); } if (females == 1) { femalesStr = "WAA_Female".Translate(); } if (randomInRange > 1) { // text to use when spawning more than one animal //text = "WAA_Message_SpawnGroup".Translate(randomInRange, pawnKindDef.label, males, malesStr.Translate(), females, femalesStr.Translate()); I think this line is broken, see next line text = "WAA_Message_SpawnGroup".Translate(randomInRange, pawnKindDef.label, males, malesStr, females, femalesStr); //text = String.Concat(new string[] { "A group of ", randomInRange.ToString(), " wild ", pawnKindDef.label, " appeared! ", males.ToString(), malesStr, " and ", females.ToString(), femalesStr }); } // check whether the alert should be played if ((animals_before_current_spawns < Settings.AnimalCount) && (Settings.EnableMod)) { if (pawnKindDef.RaceProps.predator) { if (Settings.PredatorsOnly) { Messages.Message(text, new TargetInfo(loc, map, false), MessageTypeDefOf.NegativeEvent); } else { Messages.Message(text, new TargetInfo(loc, map, false), MessageTypeDefOf.PositiveEvent); } } else { if (!Settings.PredatorsOnly) { Messages.Message(text, new TargetInfo(loc, map, false), MessageTypeDefOf.PositiveEvent); } } } // return false to prevent the vanilla code from running (which would spawn another animal/group of animals) return(false); }