コード例 #1
0
        public static IntVec3 GetFleeDestAnimal(Pawn pawn, List <Thing> threats, float distance = 23f)
        {
            Vector3 normalized = (pawn.Position - threats[0].Position).ToVector3().normalized;
            float   num        = distance - pawn.Position.DistanceTo(threats[0].Position);

            for (float num2 = 200f; num2 <= 360f; num2 += 10f)
            {
                IntVec3 intVec = pawn.Position + (normalized.RotatedBy(Rand.Range(-num2 / 2f, num2 / 2f)) * num).ToIntVec3();
                if (CellFinderLoose.CanFleeToLocation(pawn, intVec))
                {
                    return(intVec);
                }
            }
            float num3 = num;

            while (num3 * 3f > num)
            {
                IntVec3 intVec2 = pawn.Position + IntVec3Utility.RandomHorizontalOffset(num3);
                if (CellFinderLoose.CanFleeToLocation(pawn, intVec2))
                {
                    return(intVec2);
                }
                num3 -= distance / 10f;
            }
            return(pawn.Position);
        }
コード例 #2
0
        public static IntVec3 RandomCellWith(Predicate <IntVec3> validator, Map map, int maxTries = 1000)
        {
            IntVec3 result;

            CellFinderLoose.TryGetRandomCellWith(validator, map, maxTries, out result);
            return(result);
        }
コード例 #3
0
 protected virtual bool TryFindScatterCell(Map map, out IntVec3 result)
 {
     if (this.nearMapCenter)
     {
         if (RCellFinder.TryFindRandomCellNearWith(map.Center, (IntVec3 x) => this.CanScatterAt(x, map), map, out result, 3, 2147483647))
         {
             return(true);
         }
     }
     else
     {
         if (this.nearPlayerStart)
         {
             result = CellFinder.RandomClosewalkCellNear(MapGenerator.PlayerStartSpot, map, 20, (IntVec3 x) => this.CanScatterAt(x, map));
             return(true);
         }
         if (CellFinderLoose.TryFindRandomNotEdgeCellWith(5, (IntVec3 x) => this.CanScatterAt(x, map), map, out result))
         {
             return(true);
         }
     }
     if (this.warnOnFail)
     {
         Log.Warning("Scatterer " + this.ToString() + " could not find cell to generate at.", false);
     }
     return(false);
 }
コード例 #4
0
ファイル: DebugAutotests.cs プロジェクト: KraigXu/GameProject
        private static void TestForceKillx100()
        {
            int  num = 0;
            Pawn pawn;

            while (true)
            {
                if (num < 100)
                {
                    PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                    pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                    GenSpawn.Spawn(pawn, CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(Find.CurrentMap), Find.CurrentMap), Find.CurrentMap);
                    HealthUtility.DamageUntilDead(pawn);
                    if (!pawn.Dead)
                    {
                        break;
                    }
                    num++;
                    continue;
                }
                return;
            }
            Log.Error("Pawn died not die: " + pawn + " at " + pawn.Position);
        }
コード例 #5
0
 public static IntVec3 GetFleeDest(Pawn pawn, List <Thing> threats, float distance = 23f)
 {
     if (pawn.RaceProps.Animal)
     {
         return(CellFinderLoose.GetFleeDestAnimal(pawn, threats, distance));
     }
     return(CellFinderLoose.GetFleeDestToolUser(pawn, threats, distance));
 }
コード例 #6
0
        public static IntVec3 TryFindCentralCell(Map map, int tightness, int minCellCount, Predicate <IntVec3> extraValidator = null)
        {
            int debug_numStand            = 0;
            int debug_numRoom             = 0;
            int debug_numTouch            = 0;
            int debug_numRoomCellCount    = 0;
            int debug_numExtraValidator   = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    debug_numStand++;
                    return(false);
                }
                Room room = c.GetRoom(map, RegionType.Set_Passable);
                if (room == null)
                {
                    debug_numRoom++;
                    return(false);
                }
                if (!room.TouchesMapEdge)
                {
                    debug_numTouch++;
                    return(false);
                }
                if (room.CellCount < minCellCount)
                {
                    debug_numRoomCellCount++;
                    return(false);
                }
                if (extraValidator != null && !extraValidator(c))
                {
                    debug_numExtraValidator++;
                    return(false);
                }
                return(true);
            };

            for (int num = tightness; num >= 1; num--)
            {
                IntVec3 size            = map.Size;
                int     num2            = size.x / num;
                IntVec3 size2           = map.Size;
                int     minEdgeDistance = (size2.x - num2) / 2;
                IntVec3 result          = default(IntVec3);
                if (CellFinderLoose.TryFindRandomNotEdgeCellWith(minEdgeDistance, validator, map, out result))
                {
                    return(result);
                }
            }
            Log.Error("Found no good central spot. Choosing randomly. numStand=" + debug_numStand + ", numRoom=" + debug_numRoom + ", numTouch=" + debug_numTouch + ", numRoomCellCount=" + debug_numRoomCellCount + ", numExtraValidator=" + debug_numExtraValidator);
            return(CellFinderLoose.RandomCellWith((IntVec3 x) => x.Standable(map), map, 1000));
        }
コード例 #7
0
        public static bool TryFindSkyfallerCell(ThingDef skyfaller, Map map, out IntVec3 cell, int minDistToEdge = 10, IntVec3 nearLoc = default(IntVec3), int nearLocMaxDist = -1, bool allowRoofedCells = true, bool allowCellsWithItems = false, bool allowCellsWithBuildings = false, bool colonyReachable = false, Predicate <IntVec3> extraValidator = null)
        {
            Predicate <IntVec3> validator = delegate(IntVec3 x)
            {
                CellRect.CellRectIterator iterator = GenAdj.OccupiedRect(x, Rot4.North, skyfaller.size).GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 current = iterator.Current;
                    if (current.InBounds(map) && !current.Fogged(map) && current.Standable(map) && (!current.Roofed(map) || !current.GetRoof(map).isThickRoof))
                    {
                        if (!allowRoofedCells && current.Roofed(map))
                        {
                            return(false);
                        }
                        if (!allowCellsWithItems && current.GetFirstItem(map) != null)
                        {
                            return(false);
                        }
                        if (!allowCellsWithBuildings && current.GetFirstBuilding(map) != null)
                        {
                            return(false);
                        }
                        if (current.GetFirstSkyfaller(map) != null)
                        {
                            return(false);
                        }
                        iterator.MoveNext();
                        continue;
                    }
                    return(false);
                }
                if (minDistToEdge > 0 && x.DistanceToEdge(map) < minDistToEdge)
                {
                    return(false);
                }
                if (colonyReachable && !map.reachability.CanReachColony(x))
                {
                    return(false);
                }
                if (extraValidator != null && !extraValidator(x))
                {
                    return(false);
                }
                return(true);
            };

            if (nearLocMaxDist > 0)
            {
                return(CellFinder.TryFindRandomCellNear(nearLoc, map, nearLocMaxDist, validator, out cell));
            }
            return(CellFinderLoose.TryFindRandomNotEdgeCellWith(minDistToEdge, validator, map, out cell));
        }
コード例 #8
0
        public static bool TryFindSkyfallerCell(ThingDef skyfaller, Map map, out IntVec3 cell, int minDistToEdge = 10, IntVec3 nearLoc = default(IntVec3), int nearLocMaxDist = -1, bool allowRoofedCells = true, bool allowCellsWithItems = false, bool allowCellsWithBuildings = false, bool colonyReachable = false, bool avoidColonistsIfExplosive = true, bool alwaysAvoidColonists = false, Predicate <IntVec3> extraValidator = null)
        {
            bool avoidColonists           = (avoidColonistsIfExplosive && skyfaller.skyfaller.CausesExplosion) || alwaysAvoidColonists;
            Predicate <IntVec3> validator = delegate(IntVec3 x)
            {
                CellRect.CellRectIterator iterator = GenAdj.OccupiedRect(x, Rot4.North, skyfaller.size).GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 c = iterator.Current;
                    bool    result2;
                    if (!c.InBounds(map) || c.Fogged(map) || !c.Standable(map) || (c.Roofed(map) && c.GetRoof(map).isThickRoof))
                    {
                        result2 = false;
                    }
                    else if (!allowRoofedCells && c.Roofed(map))
                    {
                        result2 = false;
                    }
                    else if (!allowCellsWithItems && c.GetFirstItem(map) != null)
                    {
                        result2 = false;
                    }
                    else if (!allowCellsWithBuildings && c.GetFirstBuilding(map) != null)
                    {
                        result2 = false;
                    }
                    else
                    {
                        if (c.GetFirstSkyfaller(map) == null)
                        {
                            iterator.MoveNext();
                            continue;
                        }
                        result2 = false;
                    }
                    return(result2);
                }
                return((!avoidColonists || !SkyfallerUtility.CanPossiblyFallOnColonist(skyfaller, x, map)) && (minDistToEdge <= 0 || x.DistanceToEdge(map) >= minDistToEdge) && (!colonyReachable || map.reachability.CanReachColony(x)) && (extraValidator == null || extraValidator(x)));
            };
            bool result;

            if (nearLocMaxDist > 0)
            {
                result = CellFinder.TryFindRandomCellNear(nearLoc, map, nearLocMaxDist, validator, out cell, -1);
            }
            else
            {
                result = CellFinderLoose.TryFindRandomNotEdgeCellWith(minDistToEdge, validator, map, out cell);
            }
            return(result);
        }
コード例 #9
0
        private static void TestForceKillx100()
        {
            for (int i = 0; i < 100; i++)
            {
                PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                Pawn pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                GenSpawn.Spawn(pawn, CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(Find.CurrentMap), Find.CurrentMap), Find.CurrentMap);
                HealthUtility.DamageUntilDead(pawn);
                if (!pawn.Dead)
                {
                    Log.Error(string.Concat("Pawn died not die: ", pawn, " at ", pawn.Position));
                    break;
                }
            }
        }
コード例 #10
0
ファイル: DebugAutotests.cs プロジェクト: KraigXu/GameProject
        private static void TestSurgeryFailRidiculousx100()
        {
            for (int i = 0; i < 100; i++)
            {
                PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                Pawn pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                GenSpawn.Spawn(pawn, CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(Find.CurrentMap), Find.CurrentMap), Find.CurrentMap);
                pawn.health.forceIncap = true;
                HealthUtility.GiveInjuriesOperationFailureRidiculous(pawn);
                pawn.health.forceIncap = false;
                if (pawn.Dead)
                {
                    Log.Error("Pawn died: " + pawn + " at " + pawn.Position);
                }
            }
        }
コード例 #11
0
ファイル: DebugAutotests.cs プロジェクト: KraigXu/GameProject
        private static void TestSurgeryFailCatastrophicx100()
        {
            for (int i = 0; i < 100; i++)
            {
                PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                Pawn pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                GenSpawn.Spawn(pawn, CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(Find.CurrentMap), Find.CurrentMap), Find.CurrentMap);
                pawn.health.forceIncap = true;
                BodyPartRecord part = pawn.health.hediffSet.GetNotMissingParts().RandomElement();
                HealthUtility.GiveInjuriesOperationFailureCatastrophic(pawn, part);
                pawn.health.forceIncap = false;
                if (pawn.Dead)
                {
                    Log.Error("Pawn died: " + pawn + " at " + pawn.Position);
                }
            }
        }
コード例 #12
0
        public static IntVec3 TryFindCentralCell(Map map, int tightness, int minCellCount, Predicate <IntVec3> extraValidator = null)
        {
            int debug_numStand            = 0;
            int debug_numRoom             = 0;
            int debug_numTouch            = 0;
            int debug_numRoomCellCount    = 0;
            int debug_numExtraValidator   = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    debug_numStand++;
                    return(false);
                }
                Room room = c.GetRoom(map, RegionType.Set_Passable);
                if (room == null)
                {
                    debug_numRoom++;
                    return(false);
                }
                if (!room.TouchesMapEdge)
                {
                    debug_numTouch++;
                    return(false);
                }
                if (room.CellCount < minCellCount)
                {
                    debug_numRoomCellCount++;
                    return(false);
                }
                if (extraValidator != null && !extraValidator(c))
                {
                    debug_numExtraValidator++;
                    return(false);
                }
                return(true);
            };

            for (int i = tightness; i >= 1; i--)
            {
                int     num             = map.Size.x / i;
                int     minEdgeDistance = (map.Size.x - num) / 2;
                IntVec3 result;
                if (CellFinderLoose.TryFindRandomNotEdgeCellWith(minEdgeDistance, validator, map, out result))
                {
                    return(result);
                }
            }
            Log.Error(string.Concat(new object[]
            {
                "Found no good central spot. Choosing randomly. numStand=",
                debug_numStand,
                ", numRoom=",
                debug_numRoom,
                ", numTouch=",
                debug_numTouch,
                ", numRoomCellCount=",
                debug_numRoomCellCount,
                ", numExtraValidator=",
                debug_numExtraValidator
            }), false);
            return(CellFinderLoose.RandomCellWith((IntVec3 x) => x.Standable(map), map, 1000));
        }