コード例 #1
0
 public static bool CanPlantRightNow(this IPlantToGrowSettable planter)
 {
     return((!planter.CanAcceptSowNow()) ? false :
            (planter is Zone_Growing z) ? z.allowSow :
            (planter is Thing t) ? !t.IsForbidden(Faction.OfPlayer) :
            true);
 }
コード例 #2
0
            static void RespectRequirementsPatch([NotNull] IPlantToGrowSettable settable, [NotNull] Pawn pawn, ref bool __result)
            {
                if (!__result)
                {
                    return;
                }
                IntVec3 c;

                if (settable is Zone_Growing growingZone)
                {
                    c = growingZone.Cells[0];
                }
                else
                {
                    c = ((Thing)settable).Position;
                }

                var plant = WorkGiver_Grower.CalculateWantedPlantDef(c, pawn.Map);

                if (plant == null)
                {
                    return;
                }
                __result = plant.IsValidFor(pawn);
            }
コード例 #3
0
        public Command_SetPlantToGrow()
        {
            this.tutorTag = "GrowingZoneSetPlant";
            ThingDef thingDef = null;
            bool     flag     = false;

            foreach (object current in Find.Selector.SelectedObjects)
            {
                IPlantToGrowSettable plantToGrowSettable = current as IPlantToGrowSettable;
                if (plantToGrowSettable != null)
                {
                    if (thingDef != null && thingDef != plantToGrowSettable.GetPlantDefToGrow())
                    {
                        flag = true;
                        break;
                    }
                    thingDef = plantToGrowSettable.GetPlantDefToGrow();
                }
            }
            if (flag)
            {
                this.icon         = Command_SetPlantToGrow.SetPlantToGrowTex;
                this.defaultLabel = "CommandSelectPlantToGrowMulti".Translate();
            }
            else
            {
                this.icon         = thingDef.uiIcon;
                this.iconAngle    = thingDef.uiIconAngle;
                this.defaultLabel = "CommandSelectPlantToGrow".Translate(new object[]
                {
                    thingDef.label
                });
            }
        }
コード例 #4
0
        private static bool IsCellOpenForSowingPlantOfType(IntVec3 cell, Map map, ThingDef plantDef)
        {
            IPlantToGrowSettable playerSetPlantForCell = GetPlayerSetPlantForCell(cell, map);

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

            ThingDef plantDefToGrow = playerSetPlantForCell.GetPlantDefToGrow();

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

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

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

            foreach (Thing current in map.thingGrid.ThingsListAt(cell))
            {
                if (current.def.BlockPlanting)
                {
                    return(false);
                }
            }
            return(GenPlant.CanEverPlantAt(plantDefToGrow, cell, map) && GenPlant.GrowthSeasonNow(cell, map));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public Command_SetPlantToGrow()
        {
            tutorTag = "GrowingZoneSetPlant";
            ThingDef thingDef = null;
            bool     flag     = false;

            foreach (object selectedObject in Find.Selector.SelectedObjects)
            {
                IPlantToGrowSettable plantToGrowSettable = selectedObject as IPlantToGrowSettable;
                if (plantToGrowSettable != null)
                {
                    if (thingDef != null && thingDef != plantToGrowSettable.GetPlantDefToGrow())
                    {
                        flag = true;
                        break;
                    }
                    thingDef = plantToGrowSettable.GetPlantDefToGrow();
                }
            }
            if (flag)
            {
                icon         = SetPlantToGrowTex;
                defaultLabel = "CommandSelectPlantToGrowMulti".Translate();
            }
            else
            {
                icon         = thingDef.uiIcon;
                iconAngle    = thingDef.uiIconAngle;
                iconOffset   = thingDef.uiIconOffset;
                defaultLabel = "CommandSelectPlantToGrow".Translate(thingDef.LabelCap);
            }
        }
コード例 #7
0
 public static void Postfix(ref bool __result, IPlantToGrowSettable settable)
 {
     if (settable is Zone_Growing zone)
     {
         __result = zone.Map.GetComponent <HarvestManager_MapComponent>().CanHarvestZone(zone);
     }
 }
コード例 #8
0
 public static Command SetPlantCommand(IPlantToGrowSettable newSettable)
 {
     return(new Command_SetPlantWithSecondaryToGrow {
         defaultDesc = "CommandSelectPlantToGrowDesc".Translate(),
         hotKey = KeyBindingDefOf.Misc1,
         settable = newSettable
     });
 }
コード例 #9
0
 private static void Postfix(IPlantToGrowSettable settable, Pawn pawn, ref bool __result)
 {
     if (__result)
     {
         ThingDef plant = WorkGiver_Grower.CalculateWantedPlantDef((settable as Zone_Growing)?.Cells[0] ?? ((Thing)settable).Position, pawn.Map);
         __result = RaceAddonTools.CheckPlant(pawn.def, plant);
     }
 }
コード例 #10
0
        protected override void FillTab()
        {
            if (this.rightClicked != null && this.infoFloatMenu != null && Find.WindowStack.Top() != this.infoFloatMenu)
            {
                this.rightClicked  = null;
                this.infoFloatMenu = null;
            }
            Text.Font = GameFont.Small;
            IPlantToGrowSettable plantToGrowSettable = (IPlantToGrowSettable)Find.Selector.SelectedObjects.First <object>();
            Rect position = new Rect(ITab_Growing_Alternate.PaddingSize.x, ITab_Growing_Alternate.PaddingSize.y, ITab_Growing_Alternate.ContentSize.x, ITab_Growing_Alternate.ContentSize.y);

            GUI.BeginGroup(position);
            Rect viewRect = new Rect(0f, 0f, position.width, position.height);

            this.scrollView.Begin(viewRect);
            float num  = 0f;
            int   num2 = 0;

            foreach (ThingDef current in GenPlant.ValidPlantTypesForGrower(Find.Selector.SingleSelectedObject))
            {
                float num3 = Text.CalcHeight(current.LabelCap, ITab_Growing_Alternate.ContentSize.x - 32f);
                if (num3 < 30f)
                {
                    num3 = 30f;
                }
                GUI.color = Color.white;
                Rect    rect          = new Rect(0f, num + 1f, ITab_Growing_Alternate.ContentSize.x - 28f, num3);
                Rect    position2     = new Rect(0f, rect.y - 1f, rect.width, rect.height + 2f);
                Vector2 mousePosition = Event.current.mousePosition;
                if (position2.Contains(mousePosition) && mousePosition.y > this.scrollView.Position.y && mousePosition.y < this.scrollView.Position.y + this.scrollView.ViewHeight)
                {
                    GUI.DrawTexture(position2, TexUI.HighlightTex);
                }
                else if (num2 % 2 == 0)
                {
                    GUI.DrawTexture(position2, TabDrawer.AlternateRowTexture);
                }
                rect.x     += 6f;
                rect.y     += 3f;
                rect.width -= 4f;
                Widgets.InfoCardButton(rect.x, rect.y, current);
                rect.x     += 34f;
                rect.width -= 34f;
                if ((Widgets.InvisibleButton(new Rect(rect.x, rect.y, rect.width - 36f, rect.height)) || WidgetDrawer.DrawLabeledRadioButton(rect, current.LabelCap, current == plantToGrowSettable.GetPlantDefToGrow(), false)) && plantToGrowSettable.GetPlantDefToGrow() != current)
                {
                    plantToGrowSettable.SetPlantDefToGrow(current);
                    SoundDefOf.RadioButtonClicked.PlayOneShotOnCamera();
                    ConceptDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total);
                }
                num += num3;
                num += 2f;
                num2++;
            }
            this.scrollView.End(num);
            TutorUIHighlighter.HighlightOpportunity("GrowingZoneSetPlant", new Rect(0f, 0f, ITab_Growing_Alternate.ContentSize.x, num));
            GUI.EndGroup();
        }
コード例 #11
0
        public static Command_SetPlantToGrow SetPlantToGrowCommand(IPlantToGrowSettable settable)
        {
            Command_SetPlantToGrow command_SetPlantToGrow = new Command_SetPlantToGrow();

            command_SetPlantToGrow.defaultDesc = "CommandSelectPlantToGrowDesc".Translate();
            command_SetPlantToGrow.hotKey      = KeyBindingDefOf.Misc1;
            command_SetPlantToGrow.settable    = settable;
            return(command_SetPlantToGrow);
        }
コード例 #12
0
        public static IPlantToGrowSettable GetPlantToGrowSettable(this IntVec3 c, Map map)
        {
            IPlantToGrowSettable plantToGrowSettable = c.GetEdifice(map) as IPlantToGrowSettable;

            if (plantToGrowSettable == null)
            {
                plantToGrowSettable = (c.GetZone(map) as IPlantToGrowSettable);
            }
            return(plantToGrowSettable);
        }
コード例 #13
0
        public static ThingDef CalculateWantedPlantDef(IntVec3 c, Map map)
        {
            IPlantToGrowSettable plantToGrowSettable = c.GetPlantToGrowSettable(map);

            if (plantToGrowSettable == null)
            {
                return(null);
            }
            return(plantToGrowSettable.GetPlantDefToGrow());
        }
コード例 #14
0
        private static IPlantToGrowSettable GetPlayerSetPlantForCell(IntVec3 cell, Map map)
        {
            IPlantToGrowSettable plantToGrowSettable = GridsUtility.GetEdifice(cell, map) as IPlantToGrowSettable;

            if (plantToGrowSettable == null)
            {
                plantToGrowSettable = (map.zoneManager.ZoneAt(cell) as IPlantToGrowSettable);
            }
            return(plantToGrowSettable);
        }
コード例 #15
0
                internal static void Postfix(Pawn pawn, IPlantToGrowSettable settable, ref bool __result)
                {
                    if (!__result)
                    {
                        return;
                    }
                    //TODO implement some mutagenic plants
                    if (false) //replace with check for mutagenic plant when we have some
#pragma warning disable 162
                    {
                        __result = pawn.CanGrowMutagenicPlants();
                    }
#pragma warning restore 162
                }
コード例 #16
0
        public static ThingDef CalculateWantedPlantDef(IntVec3 c, Map map)
        {
            IPlantToGrowSettable plantToGrowSettable = c.GetPlantToGrowSettable(map);
            ThingDef             result;

            if (plantToGrowSettable == null)
            {
                result = null;
            }
            else
            {
                result = plantToGrowSettable.GetPlantDefToGrow();
            }
            return(result);
        }
コード例 #17
0
        protected void DetermineWantedPlantDef(IntVec3 c)
        {
            IPlantToGrowSettable plantToGrowSettable = c.GetEdifice() as IPlantToGrowSettable;

            if (plantToGrowSettable == null)
            {
                plantToGrowSettable = (Find.ZoneManager.ZoneAt(c) as IPlantToGrowSettable);
            }
            if (plantToGrowSettable == null)
            {
                wantedPlantDef = null;
            }
            else
            {
                wantedPlantDef = plantToGrowSettable.GetPlantDefToGrow();
            }
        }
コード例 #18
0
        public override bool DoIterationWork(IntVec3 c)
        {
            IPlantToGrowSettable plantToGrowSettable = Utilities.GetIPlantToGrowSettable(c, Map);
            var plantDef = plantToGrowSettable.GetPlantDefToGrow();

            foreach (var t in c.GetThingList(Map))
            {
                if (t is Plant p)
                {
                    if (t.def == plantDef)
                    {
                        if (p.Growth + 0.001f >= 1.00f)
                        {
                            //Harvests fully grown plants
                            CreatePlantProducts(p);
                            return(false);
                        }
                        return(true);
                    }
                    else
                    {
                        //Destroys foreign plants
                        CreatePlantProducts(p);
                        if (!p.Destroyed)
                        {
                            p.Destroy();
                        }
                        return(false);
                    }
                }
            }
            //If no plant of specified type, plants one
            if (plantDef != null && plantToGrowSettable.CanPlantRightNow())
            {
                TryPlantNew(c, plantDef);
            }
            return(true);
        }
コード例 #19
0
        private bool ExtraRequirements(IPlantToGrowSettable settable, Pawn pawn)
        {
            if (!settable.CanAcceptSowNow())
            {
                return(false);
            }
            Zone_Orchard orchardZone = settable as Zone_Orchard;
            IntVec3      c;

            if (orchardZone != null)
            {
                if (!orchardZone.allowSow)
                {
                    return(false);
                }
                c = orchardZone.Cells[0];
            }
            else
            {
                c = ((Thing)settable).Position;
            }
            wantedPlantDef = CalculateWantedPlantDef(c, pawn.Map);
            return(wantedPlantDef != null);
        }
コード例 #20
0
 // Token: 0x060000A4 RID: 164 RVA: 0x000059F8 File Offset: 0x00003BF8
 protected virtual bool ExtraRequirements(IPlantToGrowSettable settable, Pawn pawn)
 {
     return(true);
 }
コード例 #21
0
        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);
        }
コード例 #22
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);
            }
        }
コード例 #23
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);
        }
コード例 #24
0
        // Not synced with CanGiveJob
        public override Job JobOnCell(Pawn pawn, IntVec3 c)
        {
            if (c.IsForbidden(pawn))
            {
                return(null);
            }
            if (!GenPlant.GrowthSeasonNow(c, pawn.Map))
            {
                return(null);
            }
            if (wantedPlantDef == null)
            {
                wantedPlantDef = CalculateWantedPlantDef(c, pawn.Map);
                if (wantedPlantDef == null)
                {
                    return(null);
                }
            }
            List <Thing> thingList = c.GetThingList(pawn.Map);

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

            if (plant != null && plant.def.plant.blockAdjacentSow)
            {
                if (!pawn.CanReserve(plant) || plant.IsForbidden(pawn))
                {
                    return(null);
                }
                return(new Job(JobDefOf.CutPlant, plant));
            }
            else
            {
                Thing thing2 = GenPlant.AdjacentSowBlocker(wantedPlantDef, c, pawn.Map);
                if (thing2 != null)
                {
                    if (thing2 is Plant plant2 && pawn.CanReserve(plant2, 1, -1, null, false) && !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 (wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Growing).Level < wantedPlantDef.plant.sowMinSkill)
                {
                    return(null);
                }
                int j = 0;
                while (j < thingList.Count)
                {
                    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);
                        }
                        else
                        {
                            if (thing3.def.EverHaulable)
                            {
                                return(HaulAIUtility.HaulAsideJobFor(pawn, thing3));
                            }
                            return(null);
                        }
                    }
                    else
                    {
                        j++;
                    }
                }
                if (!wantedPlantDef.CanEverPlantAt(c, pawn.Map) || !GenPlant.GrowthSeasonNow(c, pawn.Map) || !pawn.CanReserve(c, 1, -1, null, false))
                {
                    return(null);
                }
                return(new Job(ZenDefOf.ZEN_PlantsSowSecondary, c)
                {
                    plantDefToSow = wantedPlantDef
                });
            }
        }
コード例 #25
0
 public static bool ExtraRequirements(IPlantToGrowSettable settable, Pawn pawn)
 {
     return(true);
 }
コード例 #26
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;
        }
コード例 #27
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);
        }
コード例 #28
0
        // Token: 0x060000AB RID: 171 RVA: 0x00005B20 File Offset: 0x00003D20
        public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            Map  map  = pawn.Map;
            bool flag = c.IsForbidden(pawn);
            Job  result;

            if (flag)
            {
                result = null;
            }
            else
            {
                bool flag2 = !PlantUtility.GrowthSeasonNow(c, map, false);
                if (flag2)
                {
                    result = null;
                }
                else
                {
                    bool flag3 = WorkGiver_WPGrower.wantedPlantDef == null;
                    if (flag3)
                    {
                        WorkGiver_WPGrower.wantedPlantDef = WorkGiver_WPGrower.CalculateWantedPlantDef(c, map);
                        bool flag4 = WorkGiver_WPGrower.wantedPlantDef == null;
                        if (flag4)
                        {
                            return(null);
                        }
                    }
                    List <Thing> thingList = c.GetThingList(map);
                    bool         flag5     = false;
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        Thing thing = thingList[i];
                        bool  flag6 = thing.def == WorkGiver_WPGrower.wantedPlantDef;
                        if (flag6)
                        {
                            return(null);
                        }
                        bool flag7 = (thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction;
                        if (flag7)
                        {
                            flag5 = true;
                        }
                    }
                    bool flag8 = flag5;
                    if (flag8)
                    {
                        Thing edifice = c.GetEdifice(map);
                        bool  flag9   = edifice == null || edifice.def.fertility < 0f;
                        if (flag9)
                        {
                            return(null);
                        }
                    }
                    bool cavePlant = WorkGiver_WPGrower.wantedPlantDef.plant.cavePlant;
                    if (cavePlant)
                    {
                        bool flag10 = !c.Roofed(map);
                        if (flag10)
                        {
                            JobFailReason.Is(WorkGiver_WPGrowerSow.CantSowCavePlantBecauseUnroofedTrans, null);
                            return(null);
                        }
                        bool flag11 = map.glowGrid.GameGlowAt(c, true) > 0f;
                        if (flag11)
                        {
                            JobFailReason.Is(WorkGiver_WPGrowerSow.CantSowCavePlantBecauseOfLightTrans, null);
                            return(null);
                        }
                    }
                    Plant plant  = c.GetPlant(map);
                    bool  flag12 = plant != null && plant.def.plant.blockAdjacentSow;
                    if (flag12)
                    {
                        bool flag13 = !pawn.CanReserve(plant, 1, -1, null, false) || plant.IsForbidden(pawn);
                        if (flag13)
                        {
                            result = null;
                        }
                        else
                        {
                            result = new Job(JobDefOf.CutPlant, plant);
                        }
                    }
                    else
                    {
                        Thing thing2 = PlantUtility.AdjacentSowBlocker(WorkGiver_WPGrower.wantedPlantDef, c, map);
                        bool  flag14 = thing2 != null;
                        if (flag14)
                        {
                            Plant plant2 = thing2 as Plant;
                            bool  flag15 = plant2 != null && pawn.CanReserve(plant2, 1, -1, null, false) && !plant2.IsForbidden(pawn);
                            if (flag15)
                            {
                                IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map);
                                bool flag16 = plantToGrowSettable == null || plantToGrowSettable.GetPlantDefToGrow() != plant2.def;
                                if (flag16)
                                {
                                    return(new Job(JobDefOf.CutPlant, plant2));
                                }
                            }
                            result = null;
                        }
                        else
                        {
                            bool flag17 = WorkGiver_WPGrower.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < WorkGiver_WPGrower.wantedPlantDef.plant.sowMinSkill;
                            if (flag17)
                            {
                                result = null;
                            }
                            else
                            {
                                int j = 0;
                                while (j < thingList.Count)
                                {
                                    Thing thing3        = thingList[j];
                                    bool  blockPlanting = thing3.def.BlockPlanting;
                                    if (blockPlanting)
                                    {
                                        bool flag18 = !pawn.CanReserve(thing3, 1, -1, null, false);
                                        if (flag18)
                                        {
                                            return(null);
                                        }
                                        bool flag19 = thing3.def.category == ThingCategory.Plant;
                                        if (flag19)
                                        {
                                            bool flag20 = !thing3.IsForbidden(pawn);
                                            if (flag20)
                                            {
                                                return(new Job(JobDefOf.CutPlant, thing3));
                                            }
                                            return(null);
                                        }
                                        else
                                        {
                                            bool everHaulable = thing3.def.EverHaulable;
                                            if (everHaulable)
                                            {
                                                return(HaulAIUtility.HaulAsideJobFor(pawn, thing3));
                                            }
                                            return(null);
                                        }
                                    }
                                    else
                                    {
                                        j++;
                                    }
                                }
                                bool flag21 = !WorkGiver_WPGrower.wantedPlantDef.CanEverPlantAt(c, map) || !PlantUtility.GrowthSeasonNow(c, map, false) || !pawn.CanReserve(c, 1, -1, null, false);
                                if (flag21)
                                {
                                    result = null;
                                }
                                else
                                {
                                    result = new Job(WPJobDefOf.WPSow, c)
                                    {
                                        plantDefToSow = WorkGiver_WPGrower.wantedPlantDef
                                    };
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }