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(); }
public static Dictionary <ThingDef, float> CalculateDistancesToNearbyClusters2(WildPlantSpawner __instance, IntVec3 c) { Map map2 = map(__instance); //nearbyClusters.Clear(); //nearbyClustersList.Clear(); Dictionary <ThingDef, List <float> > nearbyClusters = new Dictionary <ThingDef, List <float> >(); List <KeyValuePair <ThingDef, List <float> > > nearbyClustersList = new List <KeyValuePair <ThingDef, List <float> > >(); int num = GenRadial.NumCellsInRadius(map2.Biome.MaxWildAndCavePlantsClusterRadius * 2); for (int i = 0; i < num; i++) { IntVec3 intVec = c + GenRadial.RadialPattern[i]; if (!intVec.InBounds(map2)) { continue; } List <Thing> list = map2.thingGrid.ThingsListAtFast(intVec); for (int j = 0; j < list.Count; j++) { Thing thing = list[j]; if (thing.def.category == ThingCategory.Plant && thing.def.plant.GrowsInClusters) { float item = intVec.DistanceToSquared(c); if (!nearbyClusters.TryGetValue(thing.def, out List <float> value)) { value = new List <float>(); //SimplePool<List<float>>.Get(); nearbyClusters.Add(thing.def, value); nearbyClustersList.Add(new KeyValuePair <ThingDef, List <float> >(thing.def, value)); } value.Add(item); } } } //distanceSqToNearbyClusters.Clear(); Dictionary <ThingDef, float> distanceSqToNearbyClusters = new Dictionary <ThingDef, float>(); for (int k = 0; k < nearbyClustersList.Count; k++) { List <float> value2 = nearbyClustersList[k].Value; value2.Sort(); distanceSqToNearbyClusters.Add(nearbyClustersList[k].Key, value2[value2.Count / 2]); value2.Clear(); SimplePool <List <float> > .Return(value2); } return(distanceSqToNearbyClusters); }
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(earlyTryMode: true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Inject selected language data into game data (early pass)."); try { LanguageDatabase.activeLanguage.InjectIntoData_BeforeImpliedDefs(); } 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(earlyTryMode: false); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations (pre-resolve)."); try { PlayerKnowledgeDatabase.ReloadAndRebind(); LessonAutoActivator.Reset(); CostListCalculator.Reset(); Pawn.ResetStaticData(); PawnApparelGenerator.Reset(); RestUtility.Reset(); ThoughtUtility.Reset(); PawnWeaponGenerator.Reset(); ThinkTreeKeyAssigner.Reset(); ThingCategoryNodeDatabase.FinalizeInit(); TrainableUtility.Reset(); HaulAIUtility.Reset(); GenConstruct.Reset(); MedicalCareUtility.Reset(); InspectPaneUtility.Reset(); GraphicDatabaseHeadRecords.Reset(); DateReadout.Reset(); ResearchProjectDef.GenerateNonOverlappingCoordinates(); BaseGen.Reset(); ResourceCounter.ResetDefs(); ApparelProperties.ResetStaticData(); WildPlantSpawner.ResetStaticData(); PawnGenerator.Reset(); TunnelHiveSpawner.ResetStaticData(); Hive.ResetStaticData(); ExpectationsUtility.Reset(); WealthWatcher.ResetStaticData(); SkillUI.Reset(); WorkGiver_FillFermentingBarrel.ResetStaticData(); WorkGiver_DoBill.ResetStaticData(); WorkGiver_InteractAnimal.ResetStaticData(); WorkGiver_Warden_DoExecution.ResetStaticData(); WorkGiver_GrowerSow.ResetStaticData(); WorkGiver_Miner.ResetStaticData(); WorkGiver_FixBrokenDownBuilding.ResetStaticData(); WorkGiver_ConstructDeliverResources.ResetStaticData(); } 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(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (post-resolve)."); try { DefGenerator.GenerateImpliedDefs_PostResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations (post-resolve)."); try { BuildingProperties.FinalizeInit(); ThingSetMakerUtility.Reset(); } 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_AfterImpliedDefs(); GenLabel.ClearCache(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { StaticConstructorOnStartupUtility.CallAll(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } }); }
public static bool CheckSpawnWildPlantAt(WildPlantSpawner __instance, ref bool __result, IntVec3 c, float plantDensity, float wholeMapNumDesiredPlants, bool setRandomGrowth = false) { Map map2 = map(__instance); if (plantDensity <= 0f || c.GetPlant(map2) != null || c.GetCover(map2) != null || c.GetEdifice(map2) != null || map2.fertilityGrid.FertilityAt(c) <= 0f || !PlantUtility.SnowAllowsPlanting(c, map2)) { __result = false; return(false); } bool cavePlants = funcGoodRoofForCavePlant(__instance, c); if (funcSaturatedAt(__instance, c, plantDensity, cavePlants, wholeMapNumDesiredPlants)) { __result = false; return(false); } if (tmpPossiblePlants == null) { tmpPossiblePlants = new List <ThingDef>(); } else { tmpPossiblePlants.Clear(); } actionCalculatePlantsWhichCanGrowAt(__instance, c, tmpPossiblePlants, cavePlants, plantDensity); if (!tmpPossiblePlants.Any()) { __result = false; return(false); } Dictionary <ThingDef, float> distanceSqToNearbyClusters = CalculateDistancesToNearbyClusters2(__instance, c); if (tmpPossiblePlantsWithWeight == null) { tmpPossiblePlantsWithWeight = new List <KeyValuePair <ThingDef, float> >(); } else { tmpPossiblePlantsWithWeight.Clear(); } for (int i = 0; i < tmpPossiblePlants.Count; i++) { float value = funcPlantChoiceWeight(__instance, tmpPossiblePlants[i], c, distanceSqToNearbyClusters, wholeMapNumDesiredPlants, plantDensity); tmpPossiblePlantsWithWeight.Add(new KeyValuePair <ThingDef, float>(tmpPossiblePlants[i], value)); } if (!tmpPossiblePlantsWithWeight.TryRandomElementByWeight((KeyValuePair <ThingDef, float> x) => x.Value, out KeyValuePair <ThingDef, float> result)) { __result = false; return(false); } Plant plant = (Plant)ThingMaker.MakeThing(result.Key); if (setRandomGrowth) { plant.Growth = Rand.Range(0.07f, 1f); if (plant.def.plant.LimitedLifespan) { plant.Age = Rand.Range(0, Mathf.Max(plant.def.plant.LifespanTicks - 50, 0)); } } GenSpawn.Spawn(plant, c, map2); __result = true; return(false); }
public static void Postfix(WildPlantSpawner __instance, IntVec3 c, float plantDensity, float wholeMapNumDesiredPlants, bool setRandomGrowth, ref bool __result) { if (__result == false) { Map map = Traverse.Create(__instance).Field("map").GetValue <Map>(); if (!(plantDensity <= 0.0) && c.GetPlant(map) == null && c.GetCover(map) == null && c.GetEdifice(map) == null && PlantUtility.SnowAllowsPlanting(c, map)) { //check if we're on water or salt. TerrainDef terrain = c.GetTerrain(map); BiomeSeasonalSettings biomeSet = map.Biome.GetModExtension <BiomeSeasonalSettings>(); if (biomeSet.specialPlants != null) { //spawn any special plants WildPlantSpawner.tmpPossiblePlants this.CalculatePlantsWhichCanGrowAt(c, WildPlantSpawner.tmpPossiblePlants, cavePlants, plantDensity); if (!WildPlantSpawner.tmpPossiblePlants.Any()) { return(false); } this.CalculateDistancesToNearbyClusters(c); WildPlantSpawner.tmpPossiblePlantsWithWeight.Clear(); for (int i = 0; i < WildPlantSpawner.tmpPossiblePlants.Count; i++) { float value = this.PlantChoiceWeight(WildPlantSpawner.tmpPossiblePlants[i], c, WildPlantSpawner.distanceSqToNearbyClusters, wholeMapNumDesiredPlants, plantDensity); WildPlantSpawner.tmpPossiblePlantsWithWeight.Add(new KeyValuePair <ThingDef, float>(WildPlantSpawner.tmpPossiblePlants[i], value)); } KeyValuePair <ThingDef, float> keyValuePair = default(KeyValuePair <ThingDef, float>); if (!((IEnumerable <KeyValuePair <ThingDef, float> >)WildPlantSpawner.tmpPossiblePlantsWithWeight).TryRandomElementByWeight <KeyValuePair <ThingDef, float> >((Func <KeyValuePair <ThingDef, float>, float>)((KeyValuePair <ThingDef, float> x) => x.Value), out keyValuePair)) { return(false); } Plant plant = (Plant)ThingMaker.MakeThing(keyValuePair.Key, null); if (setRandomGrowth) { plant.Growth = Rand.Range(0.07f, 1f); if (plant.def.plant.LimitedLifespan) { plant.Age = Rand.Range(0, Mathf.Max(plant.def.plant.LifespanTicks - 50, 0)); } } GenSpawn.Spawn(plant, c, map, WipeMode.Vanish); return(true); } PlantDef = c.GetPlant(map); if (__result == true && plantDef != null && c != null && map != null) { BiomeDef biome = map.Biome; BiomeSeasonalSettings biomeSettings = biome.GetModExtension <BiomeSeasonalSettings>(); if (biomeSettings != null) { if (!biomeSettings.canPutOnTerrain(c, plantDef, map)) { __result = false; } } } } } }
public static void WildPlantSpawnerListTick() { while (true) { int ticketIndex = Interlocked.Increment(ref wildPlantSpawnerTicksCompleted) - 1; if (ticketIndex >= wildPlantSpawnerTicksCount) { return; } int wildPlantSpawnerIndex = 0; while (ticketIndex < wildPlantSpawnerTicksCount) { int index = ticketIndex; while (ticketIndex >= wildPlantSpawners[wildPlantSpawnerIndex].ticks) { wildPlantSpawnerIndex++; } if (wildPlantSpawnerIndex > 0) { index = ticketIndex - wildPlantSpawners[wildPlantSpawnerIndex - 1].ticks; } try { WildPlantSpawnerStructure wpsStruct = wildPlantSpawners[wildPlantSpawnerIndex]; WildPlantSpawner spawner = wpsStruct.wildPlantSpawnerInstance; int cycleIndex = (wpsStruct.cycleIndexOffset - index) % wpsStruct.area; IntVec3 intVec = wpsStruct.randomCells.Get(cycleIndex); if ((wpsStruct.cycleIndexOffset - index) > wpsStruct.area) { Interlocked.Add(ref wpsStruct.desiredPlants2Tmp1000, 1000 * (int)spawner.GetDesiredPlantsCountAt( intVec, intVec, wpsStruct.plantDensity)); if (intVec.GetTerrain(wildPlantSpawners[wildPlantSpawnerIndex].map).fertility > 0f) { Interlocked.Increment(ref wpsStruct.fertilityCells2Tmp); } float mtb = spawner.GoodRoofForCavePlant(intVec) ? 130f : wpsStruct.map.Biome.wildPlantRegrowDays; if (Rand.Chance(wpsStruct.chance) && Rand.MTBEventOccurs(mtb, 60000f, 10000) && spawner.CanRegrowAt(intVec)) { spawner.CheckSpawnWildPlantAt(intVec, wpsStruct.plantDensity, wpsStruct.desiredPlantsTmp1000 / 1000.0f); } } else { Interlocked.Add(ref wpsStruct.desiredPlantsTmp1000, 1000 * (int)spawner.GetDesiredPlantsCountAt(intVec, intVec, wpsStruct.plantDensity)); if (intVec.GetTerrain(wpsStruct.map).fertility > 0f) { Interlocked.Increment(ref wpsStruct.fertilityCellsTmp); } float mtb = spawner.GoodRoofForCavePlant(intVec) ? 130f : wpsStruct.map.Biome.wildPlantRegrowDays; if (Rand.Chance(wpsStruct.chance) && Rand.MTBEventOccurs(mtb, 60000f, 10000) && spawner.CanRegrowAt(intVec)) { spawner.CheckSpawnWildPlantAt(intVec, wpsStruct.plantDensity, wpsStruct.desiredPlants); } } if (ticketIndex == wildPlantSpawners[wildPlantSpawnerIndex].ticks - 1) { if ((wpsStruct.cycleIndexOffset - index) > wpsStruct.area) { spawner.calculatedWholeMapNumDesiredPlants = wpsStruct.desiredPlantsTmp1000 / 1000.0f; spawner.calculatedWholeMapNumDesiredPlantsTmp = wpsStruct.desiredPlants2Tmp1000 / 1000.0f; spawner.calculatedWholeMapNumNonZeroFertilityCells = wpsStruct.fertilityCellsTmp; spawner.calculatedWholeMapNumNonZeroFertilityCellsTmp = wpsStruct.fertilityCells2Tmp; } else { spawner.calculatedWholeMapNumDesiredPlantsTmp = wpsStruct.desiredPlantsTmp1000 / 1000.0f; spawner.calculatedWholeMapNumNonZeroFertilityCells = wpsStruct.fertilityCellsTmp; } } } catch (Exception ex) { Log.Error("Exception ticking WildPlantSpawner: " + ex); } ticketIndex = Interlocked.Increment(ref wildPlantSpawnerTicksCompleted) - 1; } } }