Example #1
0
        public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            Job   job  = new Job(JobDefOf.Harvest);
            Map   map  = pawn.Map;
            Room  room = c.GetRoom(map, RegionType.Set_Passable);
            float num  = 0f;

            for (int i = 0; i < 40; i++)
            {
                IntVec3 intVec = c + GenRadial.RadialPattern[i];
                if (intVec.GetRoom(map, RegionType.Set_Passable) == room)
                {
                    if (this.HasJobOnCell(pawn, intVec, false))
                    {
                        Plant plant = intVec.GetPlant(map);
                        if (!(intVec != c) || plant.def == WorkGiver_Grower.CalculateWantedPlantDef(intVec, map))
                        {
                            num += plant.def.plant.harvestWork;
                            if (intVec != c && num > 2400f)
                            {
                                break;
                            }
                            job.AddQueuedTarget(TargetIndex.A, plant);
                        }
                    }
                }
            }
            if (job.targetQueueA != null && job.targetQueueA.Count >= 3)
            {
                job.targetQueueA.SortBy((LocalTargetInfo targ) => targ.Cell.DistanceToSquared(pawn.Position));
            }
            return(job);
        }
        protected override bool ExtraRequirements(IPlantToGrowSettable settable, Pawn pawn)
        {
            bool result;

            if (!settable.CanAcceptSowNow())
            {
                result = false;
            }
            else
            {
                Zone_Growing zone_Growing = settable as Zone_Growing;
                IntVec3      c;
                if (zone_Growing != null)
                {
                    if (!zone_Growing.allowSow)
                    {
                        return(false);
                    }
                    c = zone_Growing.Cells[0];
                }
                else
                {
                    c = ((Thing)settable).Position;
                }
                WorkGiver_Grower.wantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, pawn.Map);
                result = (WorkGiver_Grower.wantedPlantDef != null);
            }
            return(result);
        }
        public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            Map map = pawn.Map;
            Job result;

            if (c.IsForbidden(pawn))
            {
                result = null;
            }
            else if (!GenPlant.GrowthSeasonNow(c, map, true))
            {
                result = null;
            }
            else
            {
                if (WorkGiver_Grower.wantedPlantDef == null)
                {
                    WorkGiver_Grower.wantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, map);
                    if (WorkGiver_Grower.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_Grower.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_Grower.wantedPlantDef.plant.cavePlant)
                {
                    if (!c.Roofed(map))
                    {
                        JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseUnroofedTrans, null);
                        return(null);
                    }
                    if (map.glowGrid.GameGlowAt(c, true) > 0f)
                    {
                        JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseOfLightTrans, null);
                        return(null);
                    }
                }
                if (WorkGiver_Grower.wantedPlantDef.plant.interferesWithRoof && c.Roofed(pawn.Map))
                {
                    result = null;
                }
                else
                {
                    Plant plant = c.GetPlant(map);
                    if (plant != null)
                    {
                        if (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));
                        }
                    }
                    Thing thing2 = GenPlant.AdjacentSowBlocker(WorkGiver_Grower.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));
                                }
                            }
                        }
                        result = null;
                    }
                    else
                    {
                        if (WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill > 0)
                        {
                            if (pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < WorkGiver_Grower.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_Grower.wantedPlantDef.CanEverPlantAt(c, map) && GenPlant.GrowthSeasonNow(c, map, true))
                        {
                            LocalTargetInfo target = c;
                            if (pawn.CanReserve(target, 1, -1, null, forced))
                            {
                                return(new Job(JobDefOf.Sow, c)
                                {
                                    plantDefToSow = WorkGiver_Grower.wantedPlantDef
                                });
                            }
                        }
                        result = null;
                    }
                }
            }
            return(result);
        }
Example #4
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, forSowing: true))
            {
                return(null);
            }
            if (WorkGiver_Grower.wantedPlantDef == null)
            {
                WorkGiver_Grower.wantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, map);
                if (WorkGiver_Grower.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_Grower.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_Grower.wantedPlantDef.plant.cavePlant)
            {
                if (!c.Roofed(map))
                {
                    JobFailReason.Is(CantSowCavePlantBecauseUnroofedTrans);
                    return(null);
                }
                if (map.glowGrid.GameGlowAt(c, ignoreCavePlants: true) > 0f)
                {
                    JobFailReason.Is(CantSowCavePlantBecauseOfLightTrans);
                    return(null);
                }
            }
            if (WorkGiver_Grower.wantedPlantDef.plant.interferesWithRoof && c.Roofed(pawn.Map))
            {
                return(null);
            }
            Plant plant = c.GetPlant(map);

            if (plant != null && plant.def.plant.blockAdjacentSow)
            {
                if (!pawn.CanReserve(plant, 1, -1, null, forced) || plant.IsForbidden(pawn))
                {
                    return(null);
                }
                return(JobMaker.MakeJob(JobDefOf.CutPlant, plant));
            }
            Thing thing2 = PlantUtility.AdjacentSowBlocker(WorkGiver_Grower.wantedPlantDef, 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(JobMaker.MakeJob(JobDefOf.CutPlant, plant2));
                    }
                }
                return(null);
            }
            if (WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill)
            {
                JobFailReason.Is("UnderAllowedSkill".Translate(WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill), def.label);
                return(null);
            }
            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))
                {
                    return(null);
                }
                if (thing3.def.category == ThingCategory.Plant)
                {
                    if (!thing3.IsForbidden(pawn))
                    {
                        return(JobMaker.MakeJob(JobDefOf.CutPlant, thing3));
                    }
                    return(null);
                }
                if (thing3.def.EverHaulable)
                {
                    return(HaulAIUtility.HaulAsideJobFor(pawn, thing3));
                }
                return(null);
            }
            if (!WorkGiver_Grower.wantedPlantDef.CanEverPlantAt_NewTemp(c, map) || !PlantUtility.GrowthSeasonNow(c, map, forSowing: true) || !pawn.CanReserve(c, 1, -1, null, forced))
            {
                return(null);
            }
            Job job = JobMaker.MakeJob(JobDefOf.Sow, c);

            job.plantDefToSow = WorkGiver_Grower.wantedPlantDef;
            return(job);
        }
Example #5
0
        public override Job JobOnCell(Pawn pawn, IntVec3 c)
        {
            Map map = pawn.Map;

            if (c.IsForbidden(pawn))
            {
                return(null);
            }
            if (!GenPlant.GrowthSeasonNow(c, map))
            {
                return(null);
            }
            if (WorkGiver_Grower.wantedPlantDef == null)
            {
                WorkGiver_Grower.wantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, map);
                if (WorkGiver_Grower.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_Grower.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 < 0.0))
                {
                    goto IL_00dc;
                }
                return(null);
            }
            goto IL_00dc;
IL_00dc:
            if (WorkGiver_Grower.wantedPlantDef.plant.cavePlant)
            {
                if (!c.Roofed(map))
                {
                    JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseUnroofedTrans);
                    return(null);
                }
                if (map.glowGrid.GameGlowAt(c, true) > 0.0)
                {
                    JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseOfLightTrans);
                    return(null);
                }
            }
            Plant plant = c.GetPlant(map);

            if (plant != null && plant.def.plant.blockAdjacentSow)
            {
                if (pawn.CanReserve(plant, 1, -1, null, false) && !plant.IsForbidden(pawn))
                {
                    return(new Job(JobDefOf.CutPlant, plant));
                }
                return(null);
            }
            Thing thing2 = GenPlant.AdjacentSowBlocker(WorkGiver_Grower.wantedPlantDef, c, map);

            if (thing2 != null)
            {
                Plant plant2 = thing2 as Plant;
                if (plant2 != null && pawn.CanReserve(plant2, 1, -1, null, false) && !plant2.IsForbidden(pawn))
                {
                    IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map);
                    if (plantToGrowSettable != null && plantToGrowSettable.GetPlantDefToGrow() == plant2.def)
                    {
                        goto IL_0211;
                    }
                    return(new Job(JobDefOf.CutPlant, plant2));
                }
                goto IL_0211;
            }
            if (WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Growing).Level < WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill)
            {
                return(null);
            }
            for (int j = 0; j < thingList.Count; j++)
            {
                Thing 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);
                }
            }
            if (WorkGiver_Grower.wantedPlantDef.CanEverPlantAt(c, map) && GenPlant.GrowthSeasonNow(c, map) && pawn.CanReserve(c, 1, -1, null, false))
            {
                Job job = new Job(JobDefOf.Sow, c);
                job.plantDefToSow = WorkGiver_Grower.wantedPlantDef;
                return(job);
            }
            return(null);

IL_0211:
            return(null);
        }