Exemplo n.º 1
0
        public override void TickRare()
        {
            base.TickRare();
            if (base.Destroyed)
            {
                return;
            }

            if (Spawned)
            {
                base.Map.mapDrawer.MapMeshDirty(base.Position, MapMeshFlag.Things);
                //this.DirtyMapMesh(this.MapHeld);

                if (PlantUtility.GrowthSeasonNow(base.Position, base.Map))
                {
                    this.growthInt += this.GrowthPerTick * 2000f;
                    if (this.growthInt > 1f)
                    {
                        this.growthInt = 1f;
                    }
                }
                if (!this.HasEnoughLightToGrow)
                {
                    this.unlitTicks += 2000;
                }
                else
                {
                    this.unlitTicks = 0;
                }
                this.ageInt += 2000;
                this.cachedLabelMouseover = null;
            }
        }
        static bool IsCellOpenForSowingPlantOfType(IntVec3 cell, Map map, ThingDef plantDef)
        {
            var playerSetPlantForCell = GetPlayerSetPlantForCell(cell, map);

            if (playerSetPlantForCell == null || !playerSetPlantForCell.CanAcceptSowNow())
            {
                return(false);
            }

            var plantDefToGrow = playerSetPlantForCell.GetPlantDefToGrow();

            if (plantDefToGrow == null || plantDefToGrow != plantDef)
            {
                return(false);
            }

            if (cell.GetPlant(map) != null)
            {
                return(false);
            }

            if (PlantUtility.AdjacentSowBlocker(plantDefToGrow, cell, map) != null)
            {
                return(false);
            }

            foreach (Thing current in map.thingGrid.ThingsListAt(cell))
            {
                if (current.def.BlockPlanting)
                {
                    return(false);
                }
            }
            return(plantDefToGrow.CanEverPlantAt(cell, map) && PlantUtility.GrowthSeasonNow(cell, map));
        }
Exemplo n.º 3
0
        public static void PlantTickLong(Plant __instance)
        {
            Plant plant = __instance;

            if (PlantUtility.GrowthSeasonNow(plant.Position, plant.Map))
            {
                if (plant.HitPoints < plant.MaxHitPoints && plant.def != ThingDefOf.BurnedTree)
                {
                    // Log.Message (plant+" before: "+plant.HitPoints.ToString() +"/"+growthIntField.GetValue (plant));

                    // heal up
                    plant.HitPoints += (int)Math.Ceiling(plant.HitPoints / 500f);
                    if (plant.HitPoints > plant.MaxHitPoints)
                    {
                        Log.Message(plant + " fully healed up: " + plant.def);
                        plant.HitPoints = plant.MaxHitPoints;
                    }

                    // less growth
                    float num    = (float)growthIntField.GetValue(plant);
                    float newNum = num - (float)growthPerTickField.GetValue(plant, null) * 100f;
                    growthIntField.SetValue(plant, newNum);                     // took half growth constant from Plant.cs
                    // Log.Message (plant+" after: "+plant.HitPoints.ToString() +"/"+growthIntField.GetValue (plant));
                }
            }
        }
Exemplo n.º 4
0
        public override string GetInspectString()
        {
            string text = string.Empty;

            if (!base.Cells.NullOrEmpty <IntVec3>())
            {
                IntVec3 c = base.Cells.First <IntVec3>();
                if (c.UsesOutdoorTemperature(base.Map))
                {
                    string text2 = text;
                    text = string.Concat(new string[]
                    {
                        text2,
                        "OutdoorGrowingPeriod".Translate(),
                        ": ",
                        Zone_Growing.GrowingQuadrumsDescription(base.Map.Tile),
                        "\n"
                    });
                }
                if (PlantUtility.GrowthSeasonNow(c, base.Map, true))
                {
                    text += "GrowSeasonHereNow".Translate();
                }
                else
                {
                    text += "CannotGrowBadSeasonTemperature".Translate();
                }
            }
            return(text);
        }
Exemplo n.º 5
0
 public override string GetInspectString()
 {
     if (base.Spawned)
     {
         return(!PlantUtility.GrowthSeasonNow(base.Position, base.Map, true) ? "CannotGrowBadSeasonTemperature".Translate() : "GrowSeasonHereNow".Translate());
     }
     return("VFEF.Building_PlantGrower_NoEmptyLines: GetInspectString() called but building is not spawned.");
 }
        public override string GetInspectString()
        {
            string text = "Oh my god \n";

            if (base.Spawned)
            {
                if (PlantUtility.GrowthSeasonNow(base.Position, base.Map, true))
                {
                    text = text + "\n" + "GrowSeasonHereNow".Translate();
                }
                else
                {
                    text = text + "\n" + "CannotGrowBadSeasonTemperature".Translate();
                }
            }
            return(text);
        }
        private bool CanSpawnAt(IntVec3 c, Map map)
        {
            if (!c.Standable(map) || c.Fogged(map) || map.fertilityGrid.FertilityAt(c) < DefDatabase <ThingDef> .GetNamed("RG-TF_Alastairus").plant.fertilityMin || !c.GetRoom(map).PsychologicallyOutdoors ||
                c.GetEdifice(map) != null || !PlantUtility.GrowthSeasonNow(c, map))
            {
                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 == DefDatabase <ThingDef> .GetNamed("RG-TF_Alastairus"))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 8
0
        public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            Map map = pawn.Map;

            if (c.IsForbidden(pawn))
            {
                return(null);
            }
            if (!PlantUtility.GrowthSeasonNow(c, map, true))
            {
                return(null);
            }
            if (WorkGiver_GrowerBotany.wantedPlantDef == null)
            {
                WorkGiver_GrowerBotany.wantedPlantDef = WorkGiver_GrowerBotany.CalculateWantedPlantDef(c, map);
                if (WorkGiver_GrowerBotany.wantedPlantDef == null)
                {
                    return(null);
                }
            }
            List <Thing> thingList = c.GetThingList(map);
            bool         flag      = false;

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (thing.def == WorkGiver_GrowerBotany.wantedPlantDef)
                {
                    return(null);
                }
                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);
                }
            }
            if (WorkGiver_GrowerBotany.wantedPlantDef.plant.cavePlant)
            {
                if (!c.Roofed(map))
                {
                    JobFailReason.Is(WorkGiver_GrowerSowBotany.CantSowCavePlantBecauseUnroofedTrans, null);
                    return(null);
                }
                if (map.glowGrid.GameGlowAt(c, true) > 0f)
                {
                    JobFailReason.Is(WorkGiver_GrowerSowBotany.CantSowCavePlantBecauseOfLightTrans, null);
                    return(null);
                }
            }
            if (WorkGiver_GrowerBotany.wantedPlantDef.plant.interferesWithRoof && c.Roofed(pawn.Map))
            {
                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));
            }
            else
            {
                Thing thing2 = PlantUtility.AdjacentSowBlocker(WorkGiver_GrowerBotany.wantedPlantDef, c, map);
                if (thing2 != null)
                {
                    Plant plant2 = thing2 as Plant;
                    if (plant2 != null)
                    {
                        LocalTargetInfo target = plant2;
                        if (pawn.CanReserve(target, 1, -1, null, forced) && !plant2.IsForbidden(pawn))
                        {
                            IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map);
                            if (plantToGrowSettable == null || plantToGrowSettable.GetPlantDefToGrow() != plant2.def)
                            {
                                return(new Job(JobDefOf.CutPlant, plant2));
                            }
                        }
                    }
                    return(null);
                }
                if (WorkGiver_GrowerBotany.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < WorkGiver_GrowerBotany.wantedPlantDef.plant.sowMinSkill)
                {
                    return(null);
                }
                int j = 0;
                while (j < thingList.Count)
                {
                    Thing thing3 = thingList[j];
                    if (thing3.def.BlockPlanting)
                    {
                        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 (WorkGiver_GrowerBotany.wantedPlantDef.CanEverPlantAt(c, map) && PlantUtility.GrowthSeasonNow(c, map, true))
                {
                    LocalTargetInfo target = c;
                    if (pawn.CanReserve(target, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.Sow, c)
                        {
                            plantDefToSow = WorkGiver_GrowerBotany.wantedPlantDef
                        });
                    }
                }
                return(null);
            }
        }
        public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            //if (!pawn.IsPrisoner)
            //    return null;
            if (c.IsForbidden(pawn))
            {
                return(null);
            }
            if (!PlantUtility.GrowthSeasonNow(c, pawn.Map))
            {
                return(null);
            }
            if (wantedPlantDef == null)
            {
                wantedPlantDef = CalculateWantedPlantDef(c, pawn.Map);
                if (wantedPlantDef == null)
                {
                    return(null);
                }
            }
            var thingList = c.GetThingList(pawn.Map);

            for (var i = 0; i < thingList.Count; i++)
            {
                var thing = thingList[i];
                if (thing.def == wantedPlantDef)
                {
                    return(null);
                }
                if ((thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction)
                {
                    return(null);
                }
            }
            var plant = c.GetPlant(pawn.Map);

            if (plant != null && plant.def.plant.blockAdjacentSow)
            {
                if (!pawn.CanReserve(plant, 1, -1, null, false) || plant.IsForbidden(pawn))
                {
                    return(null);
                }
                return(new Job(JobDefOf.CutPlant, plant));
            }
            var thing2 = PlantUtility.AdjacentSowBlocker(wantedPlantDef, c, pawn.Map);

            if (thing2 != null)
            {
                var plant2 = thing2 as Plant;
                if (plant2 != null && pawn.CanReserve(plant2, 1, -1, null, false) && !plant2.IsForbidden(pawn))
                {
                    var plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map);
                    if (plantToGrowSettable == null || plantToGrowSettable.GetPlantDefToGrow() != plant2.def)
                    {
                        return(new Job(JobDefOf.CutPlant, plant2));
                    }
                }
                return(null);
            }
            if (wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < wantedPlantDef.plant.sowMinSkill)
            {
                return(null);
            }
            if (pawn.IsPrisoner && wantedPlantDef.plant.sowMinSkill > 6 && !PrisonLaborPrefs.AdvancedGrowing)
            {
                Tutorials.Growing();
                return(null);
            }
            var j = 0;

            while (j < thingList.Count)
            {
                var thing3 = thingList[j];
                if (thing3.def.BlockPlanting)
                {
                    if (!pawn.CanReserve(thing3, 1, -1, null, false))
                    {
                        return(null);
                    }
                    if (thing3.def.category == ThingCategory.Plant)
                    {
                        if (!thing3.IsForbidden(pawn))
                        {
                            return(new Job(JobDefOf.CutPlant, thing3));
                        }
                        return(null);
                    }
                    if (thing3.def.EverHaulable)
                    {
                        return(HaulAIUtility.HaulAsideJobFor(pawn, thing3));
                    }
                    return(null);
                }
                j++;
            }
            if (!wantedPlantDef.CanEverPlantAt(c, pawn.Map) || !PlantUtility.GrowthSeasonNow(c, pawn.Map) ||
                !pawn.CanReserve(c, 1, -1, null, false))
            {
                return(null);
            }
            return(new Job(JobDefOf.Sow, c)
            {
                plantDefToSow = wantedPlantDef
            });
        }
        // 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) < AdeptusThingDefOf.OG_Plant_Orkoid_Cocoon.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 == AdeptusThingDefOf.OG_Plant_Orkoid_Cocoon)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 11
0
        private static bool JobOnCellTest(WorkGiverDef def, Pawn pawn, IntVec3 c, bool forced = false)
        {
            Map map = pawn.Map;

            if (c.IsForbidden(pawn))
            {
#if DEBUG
                Log.Warning("IsForbidden");
#endif
                PlantSowing_Cache.ReregisterObject(map, c, awaitingPlantCellsMapDict);
                return(false);
            }

            if (!PlantUtility.GrowthSeasonNow(c, map, forSowing: true))
            {
#if DEBUG
                Log.Warning("GrowthSeasonNow");
#endif
                return(false);
            }

            ThingDef localWantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, map);
            WorkGiver_GrowerSow.wantedPlantDef = localWantedPlantDef;
            if (localWantedPlantDef == null)
            {
#if DEBUG
                Log.Warning("localWantedPlantDef==null");
#endif
                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)
                {
#if DEBUG
                    Log.Warning("thing.def == localWantedPlantDef... RemoveObjectFromAwaitingHaulingHashSets");
#endif
                    PlantSowing_Cache.ReregisterObject(map, c, awaitingPlantCellsMapDict);
                    //JumboCellCache.AddObjectToActionableObjects(map, c, c, awaitingPlantCellsMapDict);
                    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)
                {
#if DEBUG
                    Log.Warning("fertility");
#endif
                    return(false);
                }
            }

            if (localWantedPlantDef.plant.cavePlant)
            {
                if (!c.Roofed(map))
                {
#if DEBUG
                    Log.Warning("cavePlant");
#endif
                    return(false);
                }

                if (map.glowGrid.GameGlowAt(c, ignoreCavePlants: true) > 0f)
                {
#if DEBUG
                    Log.Warning("GameGlowAt");
#endif
                    return(false);
                }
            }

            if (localWantedPlantDef.plant.interferesWithRoof && c.Roofed(pawn.Map))
            {
                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))
                {
#if DEBUG
                    Log.Warning("blockAdjacentSow");
#endif
                    return(false);
                }

                return(true);                // JobMaker.MakeJob(JobDefOf.CutPlant, plant);
            }

            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)
                    {
                        return(true);                        // JobMaker.MakeJob(JobDefOf.CutPlant, plant2);
                    }
                }
#if DEBUG
                Log.Warning("AdjacentSowBlocker");
#endif
                PlantSowing_Cache.ReregisterObject(map, c, awaitingPlantCellsMapDict);
                return(false);
            }

            if (localWantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < localWantedPlantDef.plant.sowMinSkill)
            {
#if DEBUG
                Log.Warning("UnderAllowedSkill");
#endif
                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))
                {
#if DEBUG
                    Log.Warning("!CanReserve");
#endif
                    PlantSowing_Cache.ReregisterObject(map, c, awaitingPlantCellsMapDict);

                    return(false);
                }

                if (thing3.def.category == ThingCategory.Plant)
                {
                    if (!thing3.IsForbidden(pawn))
                    {
                        return(true);                        // JobMaker.MakeJob(JobDefOf.CutPlant, thing3);
                    }
#if DEBUG
                    Log.Warning("Plant IsForbidden");
#endif
                    PlantSowing_Cache.ReregisterObject(map, c, awaitingPlantCellsMapDict);

                    return(false);
                }

                if (thing3.def.EverHaulable)
                {
                    return(true);                    //HaulAIUtility.HaulAsideJobFor(pawn, thing3);
                }
#if DEBUG
                Log.Warning("EverHaulable");
#endif
                PlantSowing_Cache.ReregisterObject(map, c, awaitingPlantCellsMapDict);
                return(false);
            }

            if (!localWantedPlantDef.CanEverPlantAt(c, map))
            {
#if DEBUG
                Log.Warning("CanEverPlantAt_NewTemp");
#endif
                PlantSowing_Cache.ReregisterObject(map, c, awaitingPlantCellsMapDict);
                return(false);
            }

            if (!PlantUtility.GrowthSeasonNow(c, map, forSowing: true))
            {
#if DEBUG
                Log.Warning("GrowthSeasonNow");
#endif
                return(false);
            }

            if (!pawn.CanReserve(c, 1, -1, null, forced))
            {
#if DEBUG
                Log.Warning("!pawn.CanReserve(c");
#endif
                PlantSowing_Cache.ReregisterObject(map, c, awaitingPlantCellsMapDict);
                //JumboCellCache.AddObjectToActionableObjects(map, c, c, awaitingPlantCellsMapDict);
                return(false);
            }

            //Job job = JobMaker.MakeJob(JobDefOf.Sow, c);
            //job.plantDefToSow = wantedPlantDef;
            return(true);            //job;
        }
        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);

            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(CantSowCavePlantBecauseUnroofedTrans);
                    __result = null;
                    return(false);
                }

                if (map.glowGrid.GameGlowAt(c, ignoreCavePlants: true) > 0f)
                {
                    JobFailReason.Is(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_NewTemp(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);
        }
Exemplo n.º 13
0
        /**********************************************************************
         * void TickRare (override)
         *    Gives insructions on what to do every time this building is
         * ticked. A normal Tick() is 1/60th of a second, a TickRare() is
         * 250 normal ticks, and a TickLong() is 2000 normal ticks.
         *    Basically a copy-paste from RimWorld.Plant.
         *********************************************************************/
        public override void TickLong()
        {
            if (growthInt < 1f)     //If the building is mature, skip all this.
            {
                if (base.Destroyed) //Is the colony destroyed?
                {
                    return;
                }

                int ticks = 2000;

                if (PlantUtility.GrowthSeasonNow(base.Position, base.Map)) //Is it currently growing season?
                {
                    this.growthInt += this.GrowthPerTick * ticks;
                    if (LifeStage == PlantLifeStage.Mature)
                    {
                        growthInt = 1f;
                    }
                }

                if (!this.HasEnoughLightToGrow) //Is it bright enough to grow?
                {
                    this.unlitTicks += ticks;
                }
                else
                {
                    this.unlitTicks = 0;
                }

                this.ageInt += ticks;
                if (this.HitPoints < this.MaxHitPoints)
                {
                    this.HitPoints += (def as BioThingDef).healRate;
                }
            }
            else //When ready to progress to the next stage..
            {
                if (nextStage != null) //If there is a next stage..
                {
                    //Copy current stats
                    IntVec3  currentPosition = this.Position;
                    Map      currentMap      = this.Map;
                    Faction  currentFaction  = this.factionInt;
                    ThingDef blueprint       = def.blueprintDef;

                    //Destroy current building
                    this.Destroy();

                    //Create new building
                    Thing newBuilding = GenSpawn.Spawn(ThingMaker.MakeThing(nextStage),
                                                       currentPosition,
                                                       currentMap); //You have no idea how long it took me to figure out how to do this.
                    newBuilding.SetFactionDirect(currentFaction);
                    newBuilding.def.blueprintDef = blueprint;
                }
                else //Otherwise log an error.
                {
                    Log.ErrorOnce("ThingDef nextStage for " + this.def.defName + " was null.\nBuilding at "
                                  + this.Position + " will not be updated.", thingIDNumber);
                }
            }

            this.cachedLabelMouseover = null; //Don't know if we need to do this, but just in case...
        }
Exemplo n.º 14
0
        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);
        }