// Token: 0x06000E25 RID: 3621 RVA: 0x00069E88 File Offset: 0x00068288 private bool CanSpawnAt(IntVec3 c, Map map) { if (!c.Standable(map) || c.Fogged(map) || map.fertilityGrid.FertilityAt(c) < XenomorphDefOf.RRY_Plant_Neomorph_Fungus.plant.fertilityMin || !c.GetRoom(map, RegionType.Set_Passable).PsychologicallyOutdoors || c.GetEdifice(map) != null || !PlantUtility.GrowthSeasonNow(c, map, false)) { return(false); } Plant plant = c.GetPlant(map); if (plant != null && plant.def.plant.growDays > 10f) { return(false); } List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i].def == XenomorphDefOf.RRY_Plant_Neomorph_Fungus || thingList[i].def == XenomorphDefOf.RRY_Plant_Neomorph_Fungus_Hidden) { return(false); } } return(true); }
public static void AddObjectToActionableObjects(Map map, IntVec3 location, List <HashSet <IntVec3>[]> awaitingActionZoomLevels) { int jumboCellWidth; int mapSizeX = map.Size.x; int mapSizeZ = map.Size.z; int zoomLevel; //---START--- For plant sowing ThingDef localWantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(location, map); if (localWantedPlantDef == null) { return; } List <Thing> thingList = location.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def == localWantedPlantDef) { return; } } if (map.physicalInteractionReservationManager.IsReserved(location)) { return; } Thing thing2 = PlantUtility.AdjacentSowBlocker(localWantedPlantDef, location, map); if (thing2 != null) { if (thing2 is Plant plant2 && !plant2.IsForbidden(Faction.OfPlayer)) { IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map); if (plantToGrowSettable != null && plantToGrowSettable.GetPlantDefToGrow() == plant2.def) { return; } } } for (int j = 0; j < thingList.Count; j++) { Thing thing3 = thingList[j]; if (!thing3.def.BlocksPlanting()) { continue; } if (thing3.def.category == ThingCategory.Plant) { if (!thing3.IsForbidden(Faction.OfPlayer)) { break; // JobMaker.MakeJob(JobDefOf.CutPlant, thing3); } Log.Warning("Plant IsForbidden"); return; } if (thing3.def.EverHaulable) { break; //HaulAIUtility.HaulAsideJobFor(pawn, thing3); } return; } //TODO fix null check? find root cause. Or maybe it was just from a bad save? //if (localWantedPlantDef != null &&!localWantedPlantDef.CanEverPlantAt_NewTemp(location, map, true)) // this change helps with boulders blocking growing zones. likely at a small performance cost if (localWantedPlantDef != null && (!location.InBounds(map) || (double)map.fertilityGrid.FertilityAt(location) < localWantedPlantDef.plant.fertilityMin)) { return; } //---END-- zoomLevel = 0; do { jumboCellWidth = getJumboCellWidth(zoomLevel); HashSet <IntVec3>[] awaitingActionGrid = awaitingActionZoomLevels[zoomLevel]; int jumboCellIndex = CellToIndexCustom(location, mapSizeX, jumboCellWidth); HashSet <IntVec3> hashset = awaitingActionGrid[jumboCellIndex]; if (hashset == null) { hashset = new HashSet <IntVec3>(); lock (awaitingActionGrid) { awaitingActionGrid[jumboCellIndex] = hashset; } } lock (hashset) { hashset.Add(location); } zoomLevel++; } while (jumboCellWidth < mapSizeX || jumboCellWidth < mapSizeZ); }
public static void PlantCurrentProportions() { PlantUtility.LogPlantProportions(); }
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 = GoodRoofForCavePlant2(map2, c); if (SaturatedAt2(map2, c, plantDensity, cavePlants, wholeMapNumDesiredPlants)) { __result = false; return(false); } List <ThingDef> tmpPossiblePlants = new List <ThingDef>(); CalculatePlantsWhichCanGrowAt2(__instance, c, tmpPossiblePlants, cavePlants, plantDensity); if (!tmpPossiblePlants.Any()) { __result = false; return(false); } Dictionary <ThingDef, float> distanceSqToNearbyClusters = CalculateDistancesToNearbyClusters2(__instance, c); List <KeyValuePair <ThingDef, float> > tmpPossiblePlantsWithWeight = new List <KeyValuePair <ThingDef, float> >(); tmpPossiblePlantsWithWeight.Clear(); for (int i = 0; i < tmpPossiblePlants.Count; i++) { float value = PlantChoiceWeight2(__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 override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false) { if (!ResearchProjectDefOf.AC_Tilling.IsFinished) { return(null); } Map map = pawn.Map; bool flag = false; if (c.IsForbidden(pawn)) { return(null); } if (!PlantUtility.GrowthSeasonNow(c, map, true)) { return(null); } List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if ((thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction) { flag = true; } } if (flag) { Thing edifice = c.GetEdifice(map); if (edifice == null || edifice.def.fertility < 0f) { return(null); } } Plant plant = c.GetPlant(map); if (plant != null && plant.def.plant.blockAdjacentSow) { LocalTargetInfo target = plant; if (!pawn.CanReserve(target, 1, -1, null, forced) || plant.IsForbidden(pawn)) { return(null); } return(new Job(JobDefOf.CutPlant, plant)); } int j = 0; while (j < thingList.Count) { Thing thing3 = thingList[j]; if (thing3.def.BlocksPlanting()) { LocalTargetInfo target = thing3; if (!pawn.CanReserve(target, 1, -1, null, forced)) { return(null); } if (thing3.def.category == ThingCategory.Plant) { if (!thing3.IsForbidden(pawn)) { return(new Job(JobDefOf.CutPlant, thing3)); } return(null); } else { if (thing3.def.EverHaulable) { return(HaulAIUtility.HaulAsideJobFor(pawn, thing3)); } return(null); } } else { j++; } } if (PlantUtility.GrowthSeasonNow(c, map, true)) { LocalTargetInfo target = c; if (pawn.CanReserve(target, 1, -1, null, forced)) { return(new Job(JobDefOf.AC_Till, c)); } } return(null); }
public void Print(Plant plant, SectionLayer layer, Graphic newGraphic, int curLevel, int baseLevel) { Vector3 a = plant.TrueCenter(); Rand.PushState(); Rand.Seed = plant.Position.GetHashCode(); int num = Mathf.CeilToInt(plant.growthInt * (float)plant.def.plant.maxMeshCount); if (num < 1) { num = 1; } float num2 = plant.def.plant.visualSizeRange.LerpThroughRange(plant.growthInt); float num3 = plant.def.graphicData.drawSize.x * num2; Vector3 center = Vector3.zero; int num4 = 0; int[] positionIndices = PlantPosIndices.GetPositionIndices(plant); bool flag = false; foreach (int num5 in positionIndices) { if (plant.def.plant.maxMeshCount == 1) { center = a + Gen.RandomHorizontalVector(0.05f); float num6 = plant.Position.z; if (center.z - num2 / 2f < num6) { center.z = num6 + num2 / 2f; flag = true; } } else { int num7 = 1; switch (plant.def.plant.maxMeshCount) { case 1: num7 = 1; break; case 4: num7 = 2; break; case 9: num7 = 3; break; case 16: num7 = 4; break; case 25: num7 = 5; break; default: Log.Error(string.Concat(plant.def, " must have plant.MaxMeshCount that is a perfect square.")); break; } float num8 = 1f / (float)num7; center = plant.Position.ToVector3(); center.y = plant.def.Altitude; center.x += 0.5f * num8; center.z += 0.5f * num8; int num9 = num5 / num7; int num10 = num5 % num7; center.x += (float)num9 * num8; center.z += (float)num10 * num8; float max = num8 * 0.3f; center += Gen.RandomHorizontalVector(max); } bool @bool = Rand.Bool; Material matSingle = newGraphic.MatSingle; PlantUtility.SetWindExposureColors(Plant.workingColors, plant); center.z -= (curLevel - baseLevel) / 1.5f; center.y -= curLevel - baseLevel; num3 *= 1f - (((float)(curLevel) - (float)baseLevel) / 5f); Printer_Plane.PrintPlane(size: new Vector2(num3, num3), layer: layer, center: center, mat: matSingle, rot: 0f, flipUv: @bool, uvs: null, colors: Plant.workingColors, topVerticesAltitudeBias: 0.1f, uvzPayload: plant.HashOffset() % 1024); num4++; if (num4 >= num) { break; } } if (plant.def.graphicData.shadowData != null) { Vector3 center2 = a + plant.def.graphicData.shadowData.offset * num2; if (flag) { center2.z = plant.Position.ToVector3Shifted().z + plant.def.graphicData.shadowData.offset.z; } center2.y -= 3f / 70f; center2.z -= (curLevel - baseLevel) / 2f; center2.y -= curLevel - baseLevel; Vector3 volume = plant.def.graphicData.shadowData.volume * num2; Printer_Shadow.PrintShadow(layer, center2, volume, Rot4.North); } Rand.PopState(); }
public static bool JobOnCell(WorkGiver_GrowerSow __instance, ref Job __result, Pawn pawn, IntVec3 c, bool forced = false) { Map map = pawn.Map; if (c.IsForbidden(pawn)) { __result = null; return(false); } if (!PlantUtility.GrowthSeasonNow(c, map, forSowing: true)) { __result = null; return(false); } ThingDef localWantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, map); WorkGiver_GrowerSow.wantedPlantDef = localWantedPlantDef; if (localWantedPlantDef == null) { __result = null; return(false); } List <Thing> thingList = c.GetThingList(map); bool flag = false; for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def == localWantedPlantDef) { __result = null; return(false); } if ((thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction) { flag = true; } } if (flag) { Thing edifice = c.GetEdifice(map); if (edifice == null || edifice.def.fertility < 0f) { __result = null; return(false); } } if (localWantedPlantDef.plant.cavePlant) { if (!c.Roofed(map)) { JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseUnroofedTrans); __result = null; return(false); } if (map.glowGrid.GameGlowAt(c, ignoreCavePlants: true) > 0f) { JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseOfLightTrans); __result = null; return(false); } } if (localWantedPlantDef.plant.interferesWithRoof && c.Roofed(pawn.Map)) { __result = null; return(false); } Plant plant = c.GetPlant(map); if (plant != null && plant.def.plant.blockAdjacentSow) { if (!pawn.CanReserve(plant, 1, -1, null, forced) || plant.IsForbidden(pawn)) { __result = null; return(false); } __result = JobMaker.MakeJob(JobDefOf.CutPlant, plant); return(false); } Thing thing2 = PlantUtility.AdjacentSowBlocker(localWantedPlantDef, c, map); if (thing2 != null) { Plant plant2 = thing2 as Plant; if (plant2 != null && pawn.CanReserve(plant2, 1, -1, null, forced) && !plant2.IsForbidden(pawn)) { IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map); if (plantToGrowSettable == null || plantToGrowSettable.GetPlantDefToGrow() != plant2.def) { __result = JobMaker.MakeJob(JobDefOf.CutPlant, plant2); return(false); } } __result = null; return(false); } ThingDef thingdef = localWantedPlantDef; if (thingdef != null && thingdef.plant != null && thingdef.plant.sowMinSkill > 0 && pawn != null && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < localWantedPlantDef.plant.sowMinSkill) { WorkGiver workGiver = __instance; JobFailReason.Is("UnderAllowedSkill".Translate(localWantedPlantDef.plant.sowMinSkill), workGiver.def.label); __result = null; return(false); } for (int j = 0; j < thingList.Count; j++) { Thing thing3 = thingList[j]; if (!thing3.def.BlocksPlanting()) { continue; } if (!pawn.CanReserve(thing3, 1, -1, null, forced)) { __result = null; return(false); } if (thing3.def.category == ThingCategory.Plant) { if (!thing3.IsForbidden(pawn)) { __result = JobMaker.MakeJob(JobDefOf.CutPlant, thing3); return(false); } __result = null; return(false); } if (thing3.def.EverHaulable) { __result = HaulAIUtility.HaulAsideJobFor(pawn, thing3); return(false); } __result = null; return(false); } if (!localWantedPlantDef.CanEverPlantAt(c, map) || !PlantUtility.GrowthSeasonNow(c, map, forSowing: true) || !pawn.CanReserve(c, 1, -1, null, forced)) { __result = null; return(false); } Job job = JobMaker.MakeJob(JobDefOf.Sow, c); job.plantDefToSow = localWantedPlantDef; __result = job; return(false); }
public override void ProcessInput(Event ev) { base.ProcessInput(ev); List <FloatMenuOption> list = new List <FloatMenuOption>(); if (this.settables == null) { this.settables = new List <IPlantToGrowSettable>(); } if (!this.settables.Contains(this.settable)) { this.settables.Add(this.settable); } Command_SetPlantToGrow.tmpAvailablePlants.Clear(); foreach (ThingDef thingDef in PlantUtility.ValidPlantTypesForGrowers(this.settables)) { if (this.IsPlantAvailable(thingDef, this.settable.Map)) { Command_SetPlantToGrow.tmpAvailablePlants.Add(thingDef); } } Command_SetPlantToGrow.tmpAvailablePlants.SortBy((ThingDef x) => - this.GetPlantListPriority(x), (ThingDef x) => x.label); for (int i = 0; i < Command_SetPlantToGrow.tmpAvailablePlants.Count; i++) { ThingDef plantDef = Command_SetPlantToGrow.tmpAvailablePlants[i]; string text = plantDef.LabelCap; if (plantDef.plant.sowMinSkill > 0) { string text2 = text; text = string.Concat(new object[] { text2, " (", "MinSkill".Translate(), ": ", plantDef.plant.sowMinSkill, ")" }); } list.Add(new FloatMenuOption(text, delegate() { string s = this.tutorTag + "-" + plantDef.defName; if (!TutorSystem.AllowAction(s)) { return; } bool flag = true; for (int j = 0; j < this.settables.Count; j++) { this.settables[j].SetPlantDefToGrow(plantDef); if (flag && plantDef.plant.interferesWithRoof) { foreach (IntVec3 c in this.settables[j].Cells) { if (c.Roofed(this.settables[j].Map)) { Messages.Message("MessagePlantIncompatibleWithRoof".Translate(new object[] { Find.ActiveLanguageWorker.Pluralize(plantDef.LabelCap, -1) }), MessageTypeDefOf.CautionInput, false); flag = false; break; } } } } PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total); this.WarnAsAppropriate(plantDef); TutorSystem.Notify_Event(s); }, MenuOptionPriority.Default, null, null, 29f, (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, plantDef), null)); } Find.WindowStack.Add(new FloatMenu(list)); }