static bool Prefix(WildSpawner __instance, IntVec3 loc) { // map is private so we access it with Traverse var trv = Traverse.Create(__instance); Map map = trv.Field("map").GetValue <Map>(); Pawn newThing = null; 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.wildSpawn_GroupSizeRange.Average); if (pawnKindDef == null) { Log.Error("No spawnable animals right now."); return(false); } // choose an amount of pawns to spawn int randomInRange = pawnKindDef.wildSpawn_GroupSizeRange.RandomInRange; // and a radius within which to spawn them int radius = Mathf.CeilToInt(Mathf.Sqrt((float)pawnKindDef.wildSpawn_GroupSizeRange.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); if (randomInRange > 1) { // text to use when spawning more than one animal text = String.Concat(new string[] { "A group of ", randomInRange.ToString(), " wild ", pawnKindDef.label, " appeared!" }); } for (int i = 0; i < randomInRange; i++) { // find a valid place to spawn the pawns IntVec3 loc2 = CellFinder.RandomClosewalkCellNear(loc, map, radius); newThing = PawnGenerator.GeneratePawn(pawnKindDef, null); GenSpawn.Spawn(newThing, loc2, map); if (randomInRange == 1) { // text to use when spawning only one animal text = String.Concat(new string[] { "A wild ", newThing.Label, " appeared! ", newThing.gender.ToString(), " ", newThing.Label, ", ", newThing.ageTracker.AgeBiologicalYears.ToString(), " years old. ", }); } } // check whether the alert should be played //ternary operators are a thing of beauty. if ((animals_before_current_spawns < Settings.AnimalCount) && (Settings.EnableMod) && ((Settings.PredatorOnly) ? newThing.RaceProps.predator : true)) { Messages.Message(text, new TargetInfo(loc, map, false), MessageTypeDefOf.NeutralEvent); } // return false to prevent the vanilla code from running (which would spawn another animal/group of animals) return(false); }
public static float DesiredTotalAnimalWeight(this WildSpawner wildSpawner, Map map) { float desiredAnimalDensity = wildSpawner.DesiredAnimalDensity(map); if (!(desiredAnimalDensity > 0f) && !(desiredAnimalDensity < 0f)) { return(0f); } float num = 10000f / desiredAnimalDensity; return(map.Area / num); }
public static void WildSpawnerTick_PostFix(WildSpawner __instance) { IntVec3 loc; if (Find.TickManager.TicksGame % 1210 == 0 && !__instance.AnimalEcosystemFull) { Log.Error("not full"); float desiredAnimalDensity = Traverse.Create(__instance).Property("DesiredAnimalDensity").GetValue <float>(); Log.Error(desiredAnimalDensity.ToString()); Log.Error((Rand.Value < 0.0268888883f * desiredAnimalDensity).ToString()); Map map = (Map)AccessTools.Field(typeof(WildSpawner), "map").GetValue(__instance); Log.Error(RCellFinder.TryFindRandomPawnEntryCell(out loc, map, CellFinder.EdgeRoadChance_Animal, null).ToString()); } }
public static float CurrentTotalAnimalWeight(this WildSpawner wildSpawner, Map map) { float num = 0f; List <Pawn> allPawnsSpawned = map.mapPawns.AllPawnsSpawned; for (int i = 0; i < allPawnsSpawned.Count; i++) { if (allPawnsSpawned[i].kindDef.wildSpawn_spawnWild && allPawnsSpawned[i].Faction == null) { num += allPawnsSpawned[i].kindDef.wildSpawn_EcoSystemWeight; } } return(num); }
private static void WildSpawner_TrySpawnPlantFromMapEdge_PostFix(WildSpawner __instance) { //every 2 in game seconds at speed 1 if ((Find.TickManager.TicksGame % 120) == 0) { float SpawnedMaturity = 0.05f; int SpawnRate = 1; //are we in the caverns Map map = (Map)typeof(WildSpawner).GetField("map", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance); if (map.Biome.defName == "RWBCavern") { //at normal spawnrate of 1 ThingDef plantDef; if (SpawnRate == 1) { if (!map.Biome.AllWildPlants.TryRandomElementByWeight((ThingDef def) => map.Biome.CommonalityOfPlant(def), out plantDef)) { return; } // Checks wether the plantdef has a fertility value(Added for TiberiumRim users since Tiberium has 0% fertility) if (plantDef.plant == null || plantDef.plant.fertilityMin <= 0f) { Log.Message("[Biomes!] if you see this message, contact the modmakers because of a mod conflict"); return; } IntVec3 source; int FailSafe = 0; do { //loop that runs 5 times to look for a plantable tile source = CellFinder.RandomCell(map); if (FailSafe >= 4) { return; // Exit because no free spot found. } FailSafe++; }while (!plantDef.CanEverPlantAt(source, map)); //plants GenPlantReproduction.TryReproduceInto(source, plantDef, map); if (source.GetPlant(map).def == plantDef) { source.GetPlant(map).Growth = SpawnedMaturity; } } } } }
public static float DesiredAnimalDensity(this WildSpawner wildSpawner, Map map) { float num = map.Biome.animalDensity * 2; float num2 = 0f; float num3 = 0f; foreach (PawnKindDef pawnKindDef in map.Biome.AllWildAnimals) { num3 += pawnKindDef.wildSpawn_EcoSystemWeight; if (map.mapTemperature.SeasonAcceptableFor(pawnKindDef.race)) { num2 += pawnKindDef.wildSpawn_EcoSystemWeight; } } num *= num2 / num3; num *= map.GameConditionManager.AggregateAnimalDensityFactor(); return(num); }
static float CurrentTotalAnimalNumber(WildSpawner __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].kindDef.wildSpawn_spawnWild && allPawnsSpawned[i].Faction == null) { num++; } } // return the amount of animals on the map return(num); }
private static void DoPlayLoad() { GraphicDatabase.Clear(); DeepProfiler.Start("Load all active mods."); try { LoadedModManager.LoadAllActiveMods(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load language metadata."); try { LanguageDatabase.LoadAllMetadata(); } finally { DeepProfiler.End(); } LongEventHandler.SetCurrentEventText("LoadingDefs".Translate()); DeepProfiler.Start("Copy all Defs from mods to global databases."); try { foreach (Type item in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods"); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between non-implied Defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind defs (early)."); try { DefOfHelper.RebindAllDefOfs(true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (pre-resolve)."); try { DefGenerator.GenerateImpliedDefs_PreResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind DefOfs (final)."); try { DefOfHelper.RebindAllDefOfs(false); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations."); try { PlayerKnowledgeDatabase.ReloadAndRebind(); LessonAutoActivator.Reset(); CostListCalculator.Reset(); PawnApparelGenerator.Reset(); RestUtility.Reset(); ThoughtUtility.Reset(); PawnWeaponGenerator.Reset(); ThinkTreeKeyAssigner.Reset(); ThingCategoryNodeDatabase.FinalizeInit(); TrainableUtility.Reset(); HaulAIUtility.Reset(); GenConstruct.Reset(); WorkGiver_FillFermentingBarrel.Reset(); WorkGiver_DoBill.Reset(); Pawn.Reset(); WorkGiver_InteractAnimal.Reset(); WorkGiver_Warden_DoExecution.Reset(); WorkGiver_GrowerSow.Reset(); WorkGiver_Miner.Reset(); MedicalCareUtility.Reset(); InspectPaneUtility.Reset(); GraphicDatabaseHeadRecords.Reset(); DateReadout.Reset(); ResearchProjectDef.GenerateNonOverlappingCoordinates(); WorkGiver_FixBrokenDownBuilding.CacheTranslations(); ItemCollectionGeneratorUtility.Reset(); BaseGen.Reset(); HealthUtility.Reset(); ResourceCounter.ResetDefs(); WildSpawner.Reset(); ApparelProperties.Reset(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve references."); try { foreach (Type item2 in typeof(Def).AllSubclasses()) { if (item2 != typeof(ThingDef)) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true); } } DefDatabase <ThingDef> .ResolveAllReferences(true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (post-resolve)."); try { DefGenerator.GenerateImpliedDefs_PostResolve(); } finally { DeepProfiler.End(); } if (Prefs.DevMode) { DeepProfiler.Start("Error check all defs."); try { foreach (Type item3 in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs"); } } finally { DeepProfiler.End(); } } LongEventHandler.SetCurrentEventText("Initializing".Translate()); DeepProfiler.Start("Load keyboard preferences."); try { KeyPrefs.Init(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Short hash giving."); try { ShortHashGiver.GiveAllShortHashes(); } finally { DeepProfiler.End(); } LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Load backstories."); try { BackstoryDatabase.ReloadAllBackstories(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Inject selected language data into game data."); try { LanguageDatabase.activeLanguage.InjectIntoData(); GenLabel.ClearCache(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { StaticConstructorOnStartupUtility.CallAll(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } }); }
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.slotGroupManager = new SlotGroupManager(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.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.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.wildSpawner = new WildSpawner(this); this.steadyAtmosphereEffects = new SteadyAtmosphereEffects(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.components.Clear(); this.FillComponents(); }