示例#1
0
        public static bool GetColonyWanderRoot(ref IntVec3 __result, Pawn pawn)
        {
            if (pawn.RaceProps.Humanlike)
            {
                if (gatherSpots == null)
                {
                    gatherSpots = new List <IntVec3>();
                }
                else
                {
                    gatherSpots.Clear();
                }

                for (int index = 0; index < pawn.Map.gatherSpotLister.activeSpots.Count; ++index)
                {
                    IntVec3 position = pawn.Map.gatherSpotLister.activeSpots[index].parent.Position;
                    if (!position.IsForbidden(pawn) && pawn.CanReach(position, PathEndMode.Touch, Danger.None, false, TraverseMode.ByPawn))
                    {
                        gatherSpots.Add(position);
                    }
                }
                if (gatherSpots.Count > 0)
                {
                    __result = gatherSpots.RandomElement();
                    return(false);
                }
            }
            //WanderUtility.candidateCells.Clear();
            if (candidateCells == null)
            {
                candidateCells = new List <IntVec3>();
            }
            else
            {
                candidateCells.Clear();
            }
            //WanderUtility.candidateBuildingsInRandomOrder.Clear();
            if (candidateBuildingsInRandomOrder == null)
            {
                candidateBuildingsInRandomOrder = new List <Building>();
            }
            else
            {
                candidateBuildingsInRandomOrder.Clear();
            }
            candidateBuildingsInRandomOrder.AddRange(pawn.Map.listerBuildings.allBuildingsColonist);
            candidateBuildingsInRandomOrder.Shuffle();
            int num    = 0;
            int index1 = 0;

            while (index1 < candidateBuildingsInRandomOrder.Count)
            {
                if (num > 80 && candidateCells.Count > 0)
                {
                    __result = candidateCells.RandomElement();
                    return(false);
                }
                Building building = candidateBuildingsInRandomOrder[index1];
                if ((building.def == ThingDefOf.Wall || building.def.building.ai_chillDestination) && (!building.Position.IsForbidden(pawn) && pawn.Map.areaManager.Home[building.Position]))
                {
                    IntVec3 c = GenAdjFast.AdjacentCells8Way(building).RandomElement();
                    if (c.Standable(building.Map) && !c.IsForbidden(pawn) && (pawn.CanReach(c, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn) && !c.IsInPrisonCell(pawn.Map)))
                    {
                        candidateCells.Add(c);
                        if ((pawn.Position - building.Position).LengthHorizontalSquared <= 1225)
                        {
                            __result = c;
                            return(false);
                        }
                    }
                }
                ++index1;
                ++num;
            }
            Pawn        result;
            Map         map                  = pawn.Map;
            MapPawns    mapPawns             = map.mapPawns;
            List <Pawn> freeColonistsSpawned = mapPawns.FreeColonistsSpawned;

            List <Pawn> pawnList = new List <Pawn>(freeColonistsSpawned.Count);

            for (int i = 0; i < freeColonistsSpawned.Count; i++)
            {
                Pawn p;
                try
                {
                    p = freeColonistsSpawned[i];
                } catch (ArgumentOutOfRangeException)
                {
                    break;
                }
                if (p != null)
                {
                    IntVec3 position = p.Position;
                    if (position != null)
                    {
                        if (!p.Position.IsForbidden(pawn))
                        {
                            bool canReach = pawn.CanReach(
                                p.Position,
                                PathEndMode.Touch,
                                Danger.None,
                                false,
                                TraverseMode.ByPawn);
                            if (canReach)
                            {
                                pawnList.Add(p);
                            }
                        }
                    }
                }
            }
            __result = pawnList.TryRandomElement(out result) ?
                       result.Position :
                       pawn.Position;
            return(false);
        }
        public static void CheckVision(Pawn pawn)
        {
            // Basically a copy of the function in PawnObserver
            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Sight) || pawn.needs.mood == null)
            {
                return;
            }
            // caravans have some different management
            Caravan caravan = pawn.GetCaravan();

            if (caravan != null)
            {
                // inside caravan
                // see other
                foreach (Pawn potentialOther in caravan.PawnsListForReading)
                {
                    Find.World.GetComponent <FriendshipMemoryGlobalTracker>().Notify_PhysicalSightOccured(pawn, potentialOther);
                }
                // see dead
                foreach (Thing thing in CaravanInventoryUtility.AllInventoryItems(caravan))
                {
                    Corpse potentialCorpse = thing as Corpse;
                    if (potentialCorpse != null)
                    {
                        Pawn deadPawn = potentialCorpse.InnerPawn;
                        Find.World.GetComponent <FriendshipMemoryGlobalTracker>().Notify_PhysicalSightOfCorpseOccured(pawn, deadPawn);
                    }
                }
                return;
            }
            Map map = pawn.Map;

            if (map == null)
            {
                return;
            }
            MapPawns pawns        = pawn.Map.mapPawns;
            IntVec3  selfPosition = pawn.Position;

            // seen alive
            foreach (Pawn potentialOther in pawns.AllPawnsSpawned)
            {
                if (GenSight.LineOfSight(selfPosition, potentialOther.Position, map, skipFirstCell: true))
                {
                    // can see!
                    float distanceSq = selfPosition.DistanceToSquared(potentialOther.Position);
                    if (distanceSq > 25)
                    {
                        // distance radius > 5, excluded
                        continue;
                    }
                    Find.World.GetComponent <FriendshipMemoryGlobalTracker>().Notify_PhysicalSightOccured(pawn, potentialOther);
                }
            }
            // seen corpse
            for (int i = 0; (float)i < 100f; i++)
            {
                IntVec3 intVec = pawn.Position + GenRadial.RadialPattern[i];
                if (!intVec.InBounds(map) || !GenSight.LineOfSight(intVec, pawn.Position, map, skipFirstCell: true))
                {
                    continue;
                }
                List <Thing> thingList = intVec.GetThingList(map);
                for (int j = 0; j < thingList.Count; j++)
                {
                    Corpse potentialCorpse = thingList[j] as Corpse;
                    if (potentialCorpse != null)
                    {
                        Pawn deadPawn = potentialCorpse.InnerPawn;
                        Find.World.GetComponent <FriendshipMemoryGlobalTracker>().Notify_PhysicalSightOfCorpseOccured(pawn, deadPawn);
                    }
                }
            }
            // tick the stuff
            Find.World.GetComponent <FriendshipMemoryGlobalTracker>().GetFriendshipMemoryTrackerForSubject(pawn)?.Notify_TickOnce(TickIntervalVision);
        }
示例#3
0
        public static bool RegisterPawn(MapPawns __instance, Pawn p)
        {
            if (p.Dead)
            {
                Log.Warning(string.Concat("Tried to register dead pawn ", p, " in ", __instance.GetType(), "."));
            }
            else if (!p.Spawned)
            {
                Log.Warning(string.Concat("Tried to register despawned pawn ", p, " in ", __instance.GetType(), "."));
            }
            else if (p.Map != mapFieldRef(__instance))
            {
                Log.Warning(string.Concat("Tried to register pawn ", p, " but his Map is not this one."));
            }
            else
            {
                if (!p.mindState.Active)
                {
                    return(false);
                }

                EnsureFactionsListsInit(__instance);
                if (!pawnsSpawnedFieldRef(__instance).Contains(p))
                {
                    lock (__instance)
                    {
                        if (!pawnsSpawnedFieldRef(__instance).Contains(p))
                        {
                            List <Pawn> newPawnsSpawned = new List <Pawn>(pawnsSpawnedFieldRef(__instance))
                            {
                                p
                            };
                            pawnsSpawnedFieldRef(__instance) = newPawnsSpawned;
                        }
                    }
                }
                if (p.Faction != null && !pawnsInFactionSpawned(__instance)[p.Faction].Contains(p))
                {
                    lock (__instance)
                    {
                        if (!pawnsInFactionSpawned(__instance)[p.Faction].Contains(p))
                        {
                            List <Pawn> newPawnList = new List <Pawn>
                            {
                                p
                            };
                            if (p.Faction == Faction.OfPlayer)
                            {
                                newPawnList.InsertionSort(delegate(Pawn a, Pawn b)
                                {
                                    int num   = (a.playerSettings != null) ? a.playerSettings.joinTick : 0;
                                    int value = (b.playerSettings != null) ? b.playerSettings.joinTick : 0;
                                    return(num.CompareTo(value));
                                });
                            }
                            pawnsInFactionSpawned(__instance)[p.Faction] = newPawnList;
                        }
                    }
                }

                if (p.IsPrisonerOfColony && !prisonersOfColonySpawned(__instance).Contains(p))
                {
                    lock (__instance)
                    {
                        if (p.IsPrisonerOfColony && !prisonersOfColonySpawned(__instance).Contains(p))
                        {
                            List <Pawn> newPrisonersOfColonySpawned = new List <Pawn>
                            {
                                p
                            };
                            prisonersOfColonySpawned(__instance) = newPrisonersOfColonySpawned;
                        }
                    }
                }

                actionDoListChangedNotifications(__instance);
            }
            return(false);
        }
示例#4
0
        public static bool get_AnyPawnBlockingMapRemoval(MapPawns __instance, ref bool __result)
        {
            Faction     ofPlayer     = Faction.OfPlayer;
            List <Pawn> pawnsSpawned = pawnsSpawnedFieldRef(__instance);

            for (int i = 0; i < pawnsSpawned.Count; i++)
            {
                if (!pawnsSpawned[i].Downed && pawnsSpawned[i].IsColonist)
                {
                    __result = true;
                    return(false);
                }

                if (pawnsSpawned[i].relations != null && pawnsSpawned[i].relations.relativeInvolvedInRescueQuest != null)
                {
                    __result = true;
                    return(false);
                }

                if (pawnsSpawned[i].Faction == ofPlayer || pawnsSpawned[i].HostFaction == ofPlayer)
                {
                    Job curJob = pawnsSpawned[i].CurJob;
                    if (curJob != null && curJob.exitMapOnArrival)
                    {
                        __result = true;
                        return(false);
                    }
                }

                if (CaravanExitMapUtility.FindCaravanToJoinFor(pawnsSpawned[i]) != null && !pawnsSpawned[i].Downed)
                {
                    __result = true;
                    return(false);
                }
            }

            List <Thing> list = mapFieldRef(__instance).listerThings.ThingsInGroup(ThingRequestGroup.ThingHolder);

            for (int j = 0; j < list.Count; j++)
            {
                if (!(list[j] is IActiveDropPod) && !(list[j] is PawnFlyer) && list[j].TryGetComp <CompTransporter>() == null)
                {
                    continue;
                }

                IThingHolder thingHolder = list[j].TryGetComp <CompTransporter>();
                IThingHolder holder      = thingHolder ?? ((IThingHolder)list[j]);
                if (tmpThings == null)
                {
                    tmpThings = new List <Thing>();
                }
                else
                {
                    tmpThings.Clear();
                }
                ThingOwnerUtility.GetAllThingsRecursively(holder, tmpThings);
                for (int k = 0; k < tmpThings.Count; k++)
                {
                    Pawn pawn = tmpThings[k] as Pawn;
                    if (pawn != null && !pawn.Dead && !pawn.Downed && pawn.IsColonist)
                    {
                        tmpThings.Clear();
                        __result = true;
                        return(false);
                    }
                }
            }

            //tmpThings.Clear();
            __result = false;
            return(false);
        }
示例#5
0
 public static void AnyColonistTameAnimalOrPrisonerOfColonyPostFix(ref bool __result, MapPawns __instance)
 {
     if (!__result)
     {
         Map map = Traverse.Create(__instance).Field("map").GetValue <Map>();
         if (map != null)
         {
             List <Thing> list = map.listerThings.AllThings.FindAll(x => x is ShipBase_Traveling || x is ShipBase);
             if (list.Count > 0)
             {
                 __result = true;
             }
         }
     }
 }
示例#6
0
        public static void FreeHumanlikesInVehicles(Faction faction, ref List <Pawn> __result, MapPawns __instance)
        {
            List <Pawn> innerPawns = __instance.AllPawns.Where(p => p.Faction == faction && p is VehiclePawn).SelectMany(v => (v as VehiclePawn).AllPawnsAboard).ToList();

            __result.AddRange(innerPawns);
        }
示例#7
0
        public static bool RegisterPawn(MapPawns __instance, Pawn p)
        {
            if (p.Dead)
            {
                Log.Warning(string.Concat("Tried to register dead pawn ", p, " in ", __instance.GetType(), "."));
                return(false);
            }
            if (!p.Spawned)
            {
                Log.Warning(string.Concat("Tried to register despawned pawn ", p, " in ", __instance.GetType(), "."));
                return(false);
            }
            if (p.Map != __instance.map)
            {
                Log.Warning(string.Concat("Tried to register pawn ", p, " but his Map is not this one."));
                return(false);
            }

            if (!p.mindState.Active)
            {
                return(false);
            }

            EnsureFactionsListsInit(__instance);
            List <Pawn> pawnList = __instance.pawnsSpawned;

            if (!pawnList.Contains(p))
            {
                lock (__instance)
                {
                    if (!pawnList.Contains(p))
                    {
                        pawnList.Add(p);
                    }
                }
            }

            Dictionary <Faction, List <Pawn> > pawnsInFactionSpawned = __instance.pawnsInFactionSpawned;

            if (p.Faction != null)
            {
                List <Pawn> pawnList2 = pawnsInFactionSpawned[p.Faction];
                if (!pawnList2.Contains(p))
                {
                    lock (__instance)
                    {
                        if (!pawnList2.Contains(p))
                        {
                            pawnList2.Add(p);
                            if (p.Faction == Faction.OfPlayer)
                            {
                                pawnList2.InsertionSort(delegate(Pawn a, Pawn b)
                                {
                                    int num   = a.playerSettings?.joinTick ?? 0;
                                    int value = b.playerSettings?.joinTick ?? 0;
                                    return(num.CompareTo(value));
                                });
                            }
                        }
                    }
                }
            }

            if (p.IsPrisonerOfColony)
            {
                List <Pawn> pawnList3 = __instance.prisonersOfColonySpawned;
                if (!pawnList3.Contains(p))
                {
                    lock (__instance)
                    {
                        if (!pawnList3.Contains(p))
                        {
                            pawnList3.Add(p);
                        }
                    }
                }
            }

            __instance.DoListChangedNotifications();

            return(false);
        }