コード例 #1
0
        private static IntVec3 GetRestSpot(IntVec3 originCell, Danger maxDanger, Pawn me)
        {
            if (!(me is PawnConverted))
            {
                return(originCell);
            }

            var currentDanger = me.Position.GetDangerFor(me);
            var danger        = (Danger)Math.Max((int)maxDanger, (int)currentDanger);

            Predicate <IntVec3> validator = c => c.Standable() && Find.RoofGrid.Roofed(c) &&
                                            CoverUtility.TotalSurroundingCoverScore(c) > 2.5f && !NextToDoor(c, me) &&
                                            originCell.CanReach(c, PathEndMode.OnCell, TraverseMode.PassDoors, danger);

            if (validator(originCell) && InRange(originCell, me, 20))
            {
                return(originCell);
            }

            for (int i = 0; i < 50; i++)
            {
                Thing thing = GetRandom(Find.ListerBuildings.allBuildingsColonist);

                if (thing == null)
                {
                    thing = GetRandom(Find.ListerBuildings.allBuildingsColonistCombatTargets);
                }
                if (thing == null)
                {
                    thing = GetRandom(Find.ListerPawns.FreeColonists);
                }
                if (thing == null)
                {
                    thing = GetRandom(Find.ListerPawns.ColonistsAndPrisoners);
                }

                if (thing == null)
                {
                    break;
                }
                IntVec3 result;
                if (CellFinder.TryFindRandomCellNear(thing.Position, 10, validator, out result))
                {
                    return(result);
                }
            }

            Predicate <IntVec3> simpleValidator = c => c.Standable() &&
                                                  CoverUtility.TotalSurroundingCoverScore(c) > 1 && !NextToDoor(c, me) &&
                                                  originCell.CanReach(c, PathEndMode.OnCell, TraverseMode.PassDoors, danger);

            IntVec3 randomCell;

            return(CellFinder.TryFindRandomCellNear(originCell, 20, simpleValidator, out randomCell) ? randomCell : originCell);
        }
コード例 #2
0
ファイル: Designator_Move.cs プロジェクト: BBream/Vehicle
 public override AcceptanceReport CanDesignateCell(IntVec3 loc)
 {
     if (loc.CanReach(vehicle, PathEndMode.OnCell, TraverseMode.ByPawn, Danger.Deadly))
         return true;
     else
         return new AcceptanceReport(txtCannotMove.Translate());
 }
コード例 #3
0
 public override AcceptanceReport CanDesignateCell(IntVec3 loc)
 {
     if (loc.CanReach(driver, PathEndMode.OnCell, TraverseMode.ByPawn, Danger.Deadly))
     {
         return(true);
     }
     return(new AcceptanceReport(txtCannotMove.Translate()));
 }
コード例 #4
0
        public static Thing ClosestThing_Global_Reachable(IntVec3 center, IEnumerable<Thing> searchSet, PathEndMode pathMode, TraverseParms traverseParams, float maxDistance, Pawn pawn)
        {
            if (searchSet == null)
            {
                return null;
            }
            int num = 0;
            int num2 = 0;
            Thing result = null;
            int num3 = -2147483648;
            int num4 = 0;
            float num5 = maxDistance * maxDistance;
            float num6 = 2.14748365E+09f;
            foreach (Thing current in searchSet)
            {
                num2++;
                float lengthHorizontalSquared = (center - current.Position).LengthHorizontalSquared;
                if (lengthHorizontalSquared <= num5)
                {
                    if (num4 > num3 || lengthHorizontalSquared < num6)
                    {
                        if (center.CanReach(current, pathMode, traverseParams))
                        {
                            if (current.SpawnedInWorld)
                            {

                                if(((Building_DroidChargePad)current).IsAvailable(pawn))
                                {
                                    result = current;
                                    num6 = lengthHorizontalSquared;
                                    num3 = num4;
                                    num++;
                                }
                            }
                        }
                    }
                }
            }
            return result;
        }
コード例 #5
0
        // overhauled version (vanilla is bugged)
        public static PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Thing thing, IntVec3 center)
        {
            if (!c.InBounds() || !c.Walkable())
            {
                return PlaceSpotQuality.Unusable;
            }

            List<Thing> list = Find.ThingGrid.ThingsListAt(c);

            // if other things on cell
            int i = 0;
            while (i < list.Count)
            {
                Thing thing2 = list[i];
                if (thing.def.saveCompressible && thing2.def.saveCompressible)
                {
                    return PlaceSpotQuality.Unusable;
                }
                // same thing type
                if (thing2.def.category == ThingCategory.Item)
                {
                    // can stack with
                    if (thing2.def == thing.def && thing2.stackCount < thing.def.stackLimit)
                    {
                        // can absorb
                        // Required, because thing reference is changed to the absorber, if absorbed
                        Thing t = thing2;
                        if (thing.TryAbsorbStack(thing2, true))
                        {
                            // Clean up to prevent haulables lists overflow
                            RemoveHaulableFromLists(t);
                            return PlaceSpotQuality.Perfect;
                        }
                        // cannot absorb all/anything
                        else
                            return PlaceSpotQuality.Unusable;
                    }
                    return PlaceSpotQuality.Unusable;
                }
                else
                {
                    i++;
                }
            }
            // if in same room
            if (c.GetRoom() == center.GetRoom())
            {
                PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Perfect;
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing3 = list[j];
                    if (thing3.def.thingClass == typeof(Building_Door))
                    {
                        return PlaceSpotQuality.Bad;
                    }
                    Pawn pawn = thing3 as Pawn;
                    if (pawn != null)
                    {
                        if (pawn.Downed)
                        {
                            return PlaceSpotQuality.Bad;
                        }
                        if (placeSpotQuality > PlaceSpotQuality.Okay)
                        {
                            placeSpotQuality = PlaceSpotQuality.Okay;
                        }
                    }
                    if (thing3.def.category == ThingCategory.Plant && thing3.def.selectable && placeSpotQuality > PlaceSpotQuality.Okay)
                    {
                        placeSpotQuality = PlaceSpotQuality.Okay;
                    }
                }
                return placeSpotQuality;
            }
            if (!center.CanReach(c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly))
            {
                return PlaceSpotQuality.Awful;
            }
            return PlaceSpotQuality.Okay;
        }
コード例 #6
0
        public static Thing ClosestThingReachable_JT(IntVec3 root, ThingRequest thingReq, PathEndMode peMode, TraverseParms traverseParams, float maxDistance = 9999f, Predicate <Thing> validator = null, IEnumerable <Thing> customGlobalSearchSet = null, int searchRegionsMax = -1, bool forceGlobalSearch = false)
        {
            //customGlobalSearchSet in context of hauling is list of things to be hauled
            //forceGlobalSearch is true when customGlobalSearchSet is not null
            //searchRegionMax is only used for cleaning
            ProfilerThreadCheck.BeginSample("ClosestThingReachable");
            //Guessing if searchRegionsMax is > 0, customGlobalSearchSet is not suppose to be used.
            if (searchRegionsMax > 0 && customGlobalSearchSet != null && !forceGlobalSearch)
            {
                Log.ErrorOnce("searchRegionsMax > 0 && customGlobalSearchSet != null && !forceGlobalSearch. customGlobalSearchSet will never be used.", 634984);
            }
            //There is no null check for thingReq, always not null?
            //if thingReq group == nothing ||
            //if there is thingReq and customGlobalSearchSet is null and there are things matching thingReq
            if (EarlyOutSearch_JT(root, thingReq, customGlobalSearchSet))
            {
                ProfilerThreadCheck.EndSample();
                return(null);
            }
            //Use either searchRegionsMax or customGlobalSearchSet
            //We're interested in thingReq.group == HaulableEver, HaulableAlways, HaulableEverOrMinifiable
            //This means customGlobalSearch has to have something (when there are such items on map) --> correct
            //Actual stuff begins?
            Thing thing = null;

            //IsUndefined == singleDef == null && thingReq group == Undefined
            if (!thingReq.IsUndefined)
            {
                //The debug bellow only resuted in group == Pawn, 7 times with 3 pawns all set only to haul, perhaps dogs loving?
                //Therefore probably ignore this if
                //Log.Message("First if was called. " + thingReq.group.ToString());
                //Hauling: searchRegionsMax should be -1 --> maxRegions = 30
                int maxRegions = (searchRegionsMax <= 0) ? 30 : searchRegionsMax;
                thing = GenClosest.RegionwiseBFSWorker(root, thingReq, peMode, traverseParams, validator, null, 0, maxRegions, maxDistance);
            }
            if (thing == null && (searchRegionsMax < 0 || forceGlobalSearch))
            {
                //validator = (Thing t) => !t.IsForbidden(pawn) && scanner.HasJobOnThing(pawn, t);
                //Debug bellow gives thingReq group to be Undefined, skips first
                //Log.Message("First if resulted in null " + thingReq.group.ToString());
                Predicate <Thing>   validator2 = (Thing t) => root.CanReach(t, peMode, traverseParams) && (validator == null || validator(t));
                IEnumerable <Thing> searchSet  = customGlobalSearchSet ?? Find.ListerThings.ThingsMatching(thingReq);
                //Main start of my code
                List <Thing> degrade   = new List <Thing>();
                List <Thing> undegrade = new List <Thing>();
                //Seperate into degrade or not
                foreach (Thing t in searchSet)
                {
                    if (t.GetStatValue(StatDefOf.DeteriorationRate) > 0)
                    {
                        degrade.Add(t);
                    }
                    else
                    {
                        undegrade.Add(t);
                    }
                }
                //Loop through all haul areas in order
                foreach (Area a in AreaFinder.getHaulAreas())
                {
                    //Check if got degradable item
                    thing = GenClosest.ClosestThing_Global(root, AreaFinder.searcher(a, degrade), maxDistance, validator2);
                    if (thing != null)
                    {
                        break;
                    }

                    //Check if got undegradable item
                    thing = GenClosest.ClosestThing_Global(root, AreaFinder.searcher(a, undegrade), maxDistance, validator2);
                    if (thing != null)
                    {
                        break;
                    }
                }
                if (thing == null)
                {
                    thing = GenClosest.ClosestThing_Global(root, degrade, maxDistance, validator2);
                    if (thing == null)
                    {
                        thing = GenClosest.ClosestThing_Global(root, undegrade, maxDistance, validator2);
                    }
                }

                /* old 50 cell code
                 *              thing = GenClosest.ClosestThing_Global(root, degrade, 50f, validator2); //If there is degradable with 50 cells
                 * if (thing == null)
                 * {
                 *  thing = GenClosest.ClosestThing_Global(root, undegrade, 50f, validator2);//If there is undegradable with 50 cells
                 *  if (thing == null)
                 *  {
                 *      thing = GenClosest.ClosestThing_Global(root, degrade, maxDistance, validator2); //If there is degradable
                 *      if (thing == null)
                 *      {
                 *          thing = GenClosest.ClosestThing_Global(root, undegrade, maxDistance, validator2); //If there is undegradable
                 *      }
                 *  }
                 * }
                 */
                //Main end of my code
            }

            /*
             * if (thing != null)
             * {
             *  Log.Message(thing.def.defName);
             * }
             * else {
             *  Log.Message("Resulted in null");
             * }*/
            ProfilerThreadCheck.EndSample();
            return(thing);
        }
コード例 #7
0
        // overhauled version (vanilla is bugged)
        public static PlaceSpotQuality PlaceSpotQualityAt(IntVec3 c, Thing thing, IntVec3 center)
        {
            if (!c.InBounds() || !c.Walkable())
            {
                return(PlaceSpotQuality.Unusable);
            }

            List <Thing> list = Find.ThingGrid.ThingsListAt(c);

            // if other things on cell
            int i = 0;

            while (i < list.Count)
            {
                Thing thing2 = list[i];
                if (thing.def.saveCompressible && thing2.def.saveCompressible)
                {
                    return(PlaceSpotQuality.Unusable);
                }
                // same thing type
                if (thing2.def.category == ThingCategory.Item)
                {
                    // can stack with
                    if (thing2.def == thing.def && thing2.stackCount < thing.def.stackLimit)
                    {
                        // can absorb
                        // Required, because thing reference is changed to the absorber, if absorbed
                        Thing t = thing2;
                        if (thing.TryAbsorbStack(thing2, true))
                        {
                            // Clean up to prevent haulables lists overflow
                            RemoveHaulableFromLists(t);
                            return(PlaceSpotQuality.Perfect);
                        }
                        // cannot absorb all/anything
                        else
                        {
                            return(PlaceSpotQuality.Unusable);
                        }
                    }
                    return(PlaceSpotQuality.Unusable);
                }
                else
                {
                    i++;
                }
            }
            // if in same room
            if (c.GetRoom() == center.GetRoom())
            {
                PlaceSpotQuality placeSpotQuality = PlaceSpotQuality.Perfect;
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing3 = list[j];
                    if (thing3.def.thingClass == typeof(Building_Door))
                    {
                        return(PlaceSpotQuality.Bad);
                    }
                    Pawn pawn = thing3 as Pawn;
                    if (pawn != null)
                    {
                        if (pawn.Downed)
                        {
                            return(PlaceSpotQuality.Bad);
                        }
                        if (placeSpotQuality > PlaceSpotQuality.Okay)
                        {
                            placeSpotQuality = PlaceSpotQuality.Okay;
                        }
                    }
                    if (thing3.def.category == ThingCategory.Plant && thing3.def.selectable && placeSpotQuality > PlaceSpotQuality.Okay)
                    {
                        placeSpotQuality = PlaceSpotQuality.Okay;
                    }
                }
                return(placeSpotQuality);
            }
            if (!center.CanReach(c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly))
            {
                return(PlaceSpotQuality.Awful);
            }
            return(PlaceSpotQuality.Okay);
        }
コード例 #8
0
        internal static _GenPlace._PlaceSpotQuality _PlaceSpotQualityAt(IntVec3 c, Thing thing, IntVec3 center)
        {
            if (
                (!c.InBounds()) ||
                (!c.Walkable())
                )
            {
                return(_GenPlace._PlaceSpotQuality.Unusable);
            }
            List <Thing> list = Find.ThingGrid.ThingsListAt(c);

            for (int index = 0; index < list.Count; ++index)
            {
                Thing thing1 = list[index];
                if (
                    (thing.def.saveCompressible) &&
                    (thing1.def.saveCompressible)
                    )
                {
                    return(_GenPlace._PlaceSpotQuality.Unusable);
                }
                if (thing1.def.category == ThingCategory.Item)
                {
                    return
                        ((
                             (thing1.def == thing.def) &&
                             (thing1.stackCount < thing.def.stackLimit)
                             )
                        ? _GenPlace._PlaceSpotQuality.Perfect
                        : _GenPlace._PlaceSpotQuality.Unusable);
                }
            }
            if (c.GetRoom() != center.GetRoom())
            {
                return
                    ((!center.CanReach(c, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly))
                    ? _GenPlace._PlaceSpotQuality.Awful
                    : _GenPlace._PlaceSpotQuality.Bad);
            }
            _GenPlace._PlaceSpotQuality placeSpotQuality = _GenPlace._PlaceSpotQuality.Perfect;
            for (int index = 0; index < list.Count; ++index)
            {
                Thing thing1 = list[index];
                if (
                    (thing1.def.thingClass == typeof(Building_Door)) ||
                    (thing1.def.thingClass.IsSubclassOf(typeof(Building_Door)))
                    )
                {
                    return(_GenPlace._PlaceSpotQuality.Bad);
                }
                Pawn pawn = thing1 as Pawn;
                if (pawn != null)
                {
                    if (pawn.Downed)
                    {
                        return(_GenPlace._PlaceSpotQuality.Bad);
                    }
                    if (placeSpotQuality > _GenPlace._PlaceSpotQuality.Okay)
                    {
                        placeSpotQuality = _GenPlace._PlaceSpotQuality.Okay;
                    }
                }
                if (
                    (thing1.def.category == ThingCategory.Plant) &&
                    (thing1.def.selectable) &&
                    (placeSpotQuality > _GenPlace._PlaceSpotQuality.Okay)
                    )
                {
                    placeSpotQuality = _GenPlace._PlaceSpotQuality.Okay;
                }
            }
            return(placeSpotQuality);
        }