Exemplo n.º 1
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced)
        {
            bool canBeHauled = HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t, forced);

            if (!canBeHauled)
            {
                return(null);
            }

            Job result = null;

            bool invalidStackCount = t.stackCount == 0;

            if (invalidStackCount)
            {
                return(null);
            }


            IntVec3 iceBoxCell         = IntVec3.Invalid;
            IntVec3 roofedCell         = IntVec3.Invalid;
            bool    canFindColderPlace = false;
            bool    canFindRoofedPlace = false;
            float   rotDays            = RottableUtil.GetRotDays(t);

            if (rotDays <= GenDate.DaysPerYear)
            {
                canFindColderPlace = TestStoreInColderPlace(pawn, t, out iceBoxCell);
            }

            canFindRoofedPlace = TestStoreUnderRoof(pawn, t, out roofedCell);

            if (canFindColderPlace)
            {
                result = HaulTherePlease.TestHaulMaxNumToCellJob(pawn, t, iceBoxCell, true);
            }

            if (canFindRoofedPlace)
            {
                result = HaulTherePlease.TestHaulMaxNumToCellJob(pawn, t, roofedCell, false);
            }

            //result = HaulTherePlease.HaulToStorageJob(pawn, t);

            return(result);
        }
Exemplo n.º 2
0
        List <Thing> ListPerishables(Pawn pawn)
        {
            var initialList = new List <Thing>();

            foreach (Thing potential in pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling())
            {
                float rotDays = RottableUtil.GetRotDays(potential);
                float detDays = GetDetDays(potential, pawn.Map);


                bool canDetOrRotSoon = !(detDays > DeteriorateDaysThresh && rotDays > GenDate.DaysPerYear);
                if (canDetOrRotSoon)
                {
                    IntVec3 position   = potential.Position;
                    RoofDef roof       = position.GetRoof(pawn.Map);
                    bool    canDetSoon = false || detDays <= DeteriorateDaysThresh;
                    if (canDetSoon)
                    {
                        bool isRoofed = false || roof != null;
                        if (!isRoofed)
                        {
                            initialList.Add(potential);
                        }
                    }
                    else
                    {
                        bool canRotSoon = rotDays <= GenDate.DaysPerYear;
                        if (canRotSoon)
                        {
                            initialList.Add(potential);
                        }
                    }
                }
            }


            var finalList = new List <Thing>();


            foreach (Thing rotOrDetHaulable in initialList)
            {
                if (finalList.Contains(rotOrDetHaulable))
                {
                    continue;
                }

                bool stacksToOne = rotOrDetHaulable.def.stackLimit == 1;

                if (stacksToOne)
                {
                    finalList.Add(rotOrDetHaulable);
                }
                else
                {
                    //finalList.Add(rotOrDetHaulable);
                    float detDays              = GetDetDays(rotOrDetHaulable, pawn.Map);
                    var   minNumToHaul         = (int)(rotOrDetHaulable.def.stackLimit * StackThreshPercent);
                    bool  stackBelowHaulThresh = rotOrDetHaulable.stackCount < minNumToHaul;
                    if (stackBelowHaulThresh && detDays > DeteriorateDaysThresh)
                    {
                        var dupeList = new List <Thing>();
                        int numDupes = rotOrDetHaulable.stackCount;
                        numDupes += DupeUtil.FindHowManyNearbyDupes(rotOrDetHaulable, GridRadiusToSearch, pawn,
                                                                    out dupeList);
                        bool stillBelowHaulThresh = numDupes < minNumToHaul;
                        if (!stillBelowHaulThresh)
                        {
                            finalList.Add(rotOrDetHaulable);
                            finalList.AddRange(dupeList);
                        }
                    }
                    else
                    {
                        finalList.Add(rotOrDetHaulable);
                    }
                }
            }


            return(finalList);
        }