Пример #1
0
 private static bool Witnessed(Pawn p, Pawn victim)
 {
     if (!p.Awake() || !p.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
     {
         return(false);
     }
     if (victim.IsCaravanMember())
     {
         return(victim.GetCaravan() == p.GetCaravan());
     }
     return(victim.Spawned && p.Spawned && p.Position.InHorDistOf(victim.Position, 12f) && GenSight.LineOfSight(victim.Position, p.Position, victim.Map, false, null, 0, 0));
 }
Пример #2
0
 public override void DrawHighlight(LocalTargetInfo target)
 {
     if (target.IsValid && ValidJumpTarget(caster.Map, target.Cell))
     {
         GenDraw.DrawTargetHighlightWithLayer(target.CenterVector3, AltitudeLayer.MetaOverlays);
     }
     GenDraw.DrawRadiusRing(caster.Position, EffectiveRange, Color.white, (IntVec3 c) => GenSight.LineOfSight(caster.Position, c, caster.Map) && ValidJumpTarget(caster.Map, c));
 }
 private static bool TryFindSitSpotOnGroundNear(IntVec3 center, Pawn sitter, out IntVec3 result)
 {
     for (int i = 0; i < 30; i++)
     {
         IntVec3 intVec = center + GenRadial.RadialPattern[Rand.Range(1, JoyGiver_SocialRelax.NumRadiusCells)];
         if (sitter.CanReserveAndReach(intVec, PathEndMode.OnCell, Danger.None, 1, -1, null, false) && intVec.GetEdifice(sitter.Map) == null && GenSight.LineOfSight(center, intVec, sitter.Map, true, null, 0, 0))
         {
             result = intVec;
             return(true);
         }
     }
     result = IntVec3.Invalid;
     return(false);
 }
        // Added targetThing to parameters so we can calculate its height
        private bool CanHitCellFromCellIgnoringRange(IntVec3 sourceSq, IntVec3 targetLoc, Thing targetThing = null, bool includeCorners = false)
        {
            // Vanilla checks
            if (this.verbProps.mustCastOnOpenGround && (!targetLoc.Standable(this.caster.Map) || this.caster.Map.thingGrid.CellContains(targetLoc, ThingCategory.Pawn)))
            {
                return(false);
            }
            if (this.verbProps.requireLineOfSight)
            {
                // Calculate shot vector
                Vector3 shotSource = ShotSource;

                Vector3 targetPos;
                if (targetThing != null)
                {
                    Vector3 targDrawPos = targetThing.DrawPos;
                    targetPos = new Vector3(targDrawPos.x, new CollisionVertical(targetThing).Max, targDrawPos.z);
                    var targPawn = targetThing as Pawn;
                    if (targPawn != null)
                    {
                        targetPos += targPawn.Drawer.leaner.LeanOffset * 0.5f;
                    }
                }
                else
                {
                    targetPos = targetLoc.ToVector3Shifted();
                }
                Ray shotLine = new Ray(shotSource, (targetPos - shotSource));

                // Create validator to check for intersection with partial cover
                var aimMode = CompFireModes?.CurrentAimMode;
                Func <IntVec3, bool> validator = delegate(IntVec3 cell)
                {
                    // Skip this check entirely if we're doing suppressive fire and cell is adjacent to target
                    if (VerbPropsCE.ignorePartialLoSBlocker || aimMode == AimMode.SuppressFire)
                    {
                        return(true);
                    }

                    Thing cover = cell.GetFirstPawn(caster.Map);
                    if (cover == null)
                    {
                        cover = cell.GetCover(caster.Map);
                    }

                    if (cover != null && cover != ShooterPawn && cover != caster && cover != targetThing && !cover.IsPlant() && !cover.Position.AdjacentTo8Way(sourceSq))
                    {
                        Bounds bounds = CE_Utility.GetBoundsFor(cover);

                        // Check for intersect
                        if (bounds.IntersectRay(shotLine))
                        {
                            if (Controller.settings.DebugDrawPartialLoSChecks)
                            {
                                caster.Map.debugDrawer.FlashCell(cell, 0, bounds.size.y.ToString());
                            }
                            return(false);
                        }
                        else if (Controller.settings.DebugDrawPartialLoSChecks)
                        {
                            caster.Map.debugDrawer.FlashCell(cell, 0.7f, bounds.size.y.ToString());
                        }
                    }
                    return(true);
                };
                // Add validator to parameters

                /*
                 * if (!includeCorners)
                 * {
                 *  if (!GenSight.LineOfSight(sourceSq, targetLoc, this.caster.Map, true, validator, 0, 0))
                 *  {
                 *      return false;
                 *  }
                 * }
                 * else if (!GenSight.LineOfSightToEdges(sourceSq, targetLoc, this.caster.Map, true, validator))
                 * {
                 *  return false;
                 * }
                 */
                var exactTargetSq = targetPos.ToIntVec3();
                foreach (IntVec3 curCell in GenSight.PointsOnLineOfSight(sourceSq, exactTargetSq))
                {
                    if (curCell != sourceSq && curCell != exactTargetSq && !validator(curCell))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #5
0
 public void TryForceFleeCowards()
 {
     if (cowards is null)
     {
         PreInit();
     }
     foreach (var pawn in cowards)
     {
         if (pawn?.Map != null && !pawn.Downed && !pawn.Dead && Rand.Chance(0.1f))
         {
             var enemies = pawn.Map.attackTargetsCache?.GetPotentialTargetsFor(pawn)?.Where(x =>
                                                                                            (x is Pawn pawnEnemy && !pawnEnemy.Dead && !pawnEnemy.Downed || !(x.Thing is Pawn) && x.Thing.DestroyedOrNull()) &&
                                                                                            x.Thing.Position.DistanceTo(pawn.Position) < 15f &&
                                                                                            GenSight.LineOfSight(x.Thing.Position, pawn.Position, pawn.Map))?.Select(y => y.Thing);
             if (enemies?.Count() > 0)
             {
                 if (pawn.Faction == Faction.OfPlayer)
                 {
                     TraitUtils.MakeFlee(pawn, enemies.OrderBy(x => x.Position.DistanceTo(pawn.Position)).First(), 15, enemies.ToList());
                     Messages.Message("VTE.PawnCowardlyFlees".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false);
                 }
                 else if (pawn.Faction != null)
                 {
                     TraitUtils.MakeExit(pawn);
                     if (pawn.HostileTo(Faction.OfPlayer))
                     {
                         Messages.Message("VTE.PawnCowardlyExitMapHostile".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false);
                     }
                     else if (pawn.Faction.RelationKindWith(Faction.OfPlayer) == FactionRelationKind.Ally)
                     {
                         Messages.Message("VTE.PawnCowardlyExitMapAlly".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false);
                     }
                     else
                     {
                         Messages.Message("VTE.PawnCowardlyExitMapNeutral".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false);
                     }
                 }
             }
         }
     }
 }
 private static bool EverPossibleToWatchFrom(IntVec3 watchCell, IntVec3 buildingCenter, Map map, bool bedAllowed)
 {
     return((watchCell.Standable(map) || (bedAllowed && watchCell.GetEdifice(map) is Building_Bed)) && GenSight.LineOfSight(buildingCenter, watchCell, map, true, null, 0, 0));
 }
Пример #7
0
        // Token: 0x0600011D RID: 285 RVA: 0x0000B9D8 File Offset: 0x00009DD8
        public void MakeValidAllowedZone()
        {
            IEnumerable <IntVec3> enumerable = from cell in GenRadial.RadialCellsAround(this.parent.Position, 18f, true)
                                               where cell.InHorDistOf(this.parent.Position, 12f) && GenSight.LineOfSight(this.parent.Position, cell, this.parent.Map, true, null, 0, 0)
                                               select cell;
            Area_Allowed area_Allowed;

            this.parent.Map.areaManager.TryMakeNewAllowed(out area_Allowed);
            foreach (IntVec3 intVec in enumerable)
            {
                area_Allowed[this.parent.Map.cellIndices.CellToIndex(intVec)] = true;
            }
            area_Allowed.SetLabel(string.Format("HoloEmitter area for {0}.", this.pawn.Name.ToStringShort));
            this.pawn.playerSettings.AreaRestriction = area_Allowed;
        }
Пример #8
0
 // Token: 0x0600569D RID: 22173 RVA: 0x001CFADC File Offset: 0x001CDCDC
 public static bool TryFindSpawnCell(Thing parent, ThingDef thingToSpawn, int spawnCount, out IntVec3 result)
 {
     foreach (IntVec3 intVec in GenAdj.CellsAdjacent8Way(parent).InRandomOrder(null))
     {
         if (intVec.Walkable(parent.Map))
         {
             Building edifice = intVec.GetEdifice(parent.Map);
             if (edifice == null || !thingToSpawn.IsEdifice())
             {
                 Building_Door building_Door = edifice as Building_Door;
                 if ((building_Door == null || building_Door.FreePassage) && (parent.def.passability == Traversability.Impassable || GenSight.LineOfSight(parent.Position, intVec, parent.Map, false, null, 0, 0)))
                 {
                     bool         flag      = false;
                     List <Thing> thingList = intVec.GetThingList(parent.Map);
                     for (int i = 0; i < thingList.Count; i++)
                     {
                         Thing thing = thingList[i];
                         if (thing.def.category == ThingCategory.Item && (thing.def != thingToSpawn || thing.stackCount > thingToSpawn.stackLimit - spawnCount))
                         {
                             flag = true;
                             break;
                         }
                     }
                     if (!flag)
                     {
                         result = intVec;
                         return(true);
                     }
                 }
             }
         }
     }
     result = IntVec3.Invalid;
     return(false);
 }
Пример #9
0
 private static bool NearFollowee(Pawn follower, Pawn followee, float radius)
 {
     return(follower.Position.AdjacentTo8WayOrInside(followee.Position) || (follower.Position.InHorDistOf(followee.Position, radius) && GenSight.LineOfSight(follower.Position, followee.Position, follower.Map, false, null, 0, 0)));
 }
Пример #10
0
        private static float FriendlyFireBlastRadiusTargetScoreOffset(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb)
        {
            float result;

            if (verb.verbProps.ai_AvoidFriendlyFireRadius <= 0f)
            {
                result = 0f;
            }
            else
            {
                Map     map      = target.Thing.Map;
                IntVec3 position = target.Thing.Position;
                int     num      = GenRadial.NumCellsInRadius(verb.verbProps.ai_AvoidFriendlyFireRadius);
                float   num2     = 0f;
                for (int i = 0; i < num; i++)
                {
                    IntVec3 intVec = position + GenRadial.RadialPattern[i];
                    if (intVec.InBounds(map))
                    {
                        bool         flag      = true;
                        List <Thing> thingList = intVec.GetThingList(map);
                        for (int j = 0; j < thingList.Count; j++)
                        {
                            if (thingList[j] is IAttackTarget && thingList[j] != target)
                            {
                                if (flag)
                                {
                                    if (!GenSight.LineOfSight(position, intVec, map, true, null, 0, 0))
                                    {
                                        break;
                                    }
                                    flag = false;
                                }
                                float num3;
                                if (thingList[j] == searcher)
                                {
                                    num3 = 40f;
                                }
                                else if (thingList[j] is Pawn)
                                {
                                    num3 = ((!thingList[j].def.race.Animal) ? 18f : 7f);
                                }
                                else
                                {
                                    num3 = 10f;
                                }
                                if (searcher.Thing.HostileTo(thingList[j]))
                                {
                                    num2 += num3 * 0.6f;
                                }
                                else
                                {
                                    num2 -= num3;
                                }
                            }
                        }
                    }
                }
                result = num2;
            }
            return(result);
        }
Пример #11
0
        public static bool ShouldFleeFrom(Thing t, Pawn pawn, bool checkDistance, bool checkLOS)
        {
            if (t == pawn || (checkDistance && !t.Position.InHorDistOf(pawn.Position, 8f)))
            {
                return(false);
            }
            if (t.def.alwaysFlee)
            {
                return(true);
            }
            if (!t.HostileTo(pawn))
            {
                return(false);
            }
            IAttackTarget attackTarget = t as IAttackTarget;

            return(attackTarget != null && !attackTarget.ThreatDisabled(pawn) && t is IAttackTargetSearcher && (!checkLOS || GenSight.LineOfSight(pawn.Position, t.Position, pawn.Map, false, null, 0, 0)));
        }
 public static void DrawMeditationSpotOverlay(IntVec3 center, Map map)
 {
     GenDraw.DrawRadiusRing(center, FocusObjectSearchRadius);
     foreach (Thing item in GenRadial.RadialDistinctThingsAround(center, map, FocusObjectSearchRadius, useCenter: false))
     {
         if (!(item is Building_Throne) && item.def != ThingDefOf.Wall && item.TryGetComp <CompMeditationFocus>() != null && GenSight.LineOfSight(center, item.Position, map))
         {
             GenDraw.DrawLineBetween(center.ToVector3() + new Vector3(0.5f, 0f, 0.5f), item.TrueCenter(), SimpleColor.White);
         }
     }
 }
 private bool Witnessed(Pawn pawn, Pawn victim)
 {
     if (!pawn.Awake() || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
     {
         return(false);
     }
     if (victim.IsCaravanMember())
     {
         return(victim.GetCaravan() == pawn.GetCaravan());
     }
     return(victim.Spawned && pawn.Spawned && (pawn.Position.InHorDistOf(victim.Position, 12f) && GenSight.LineOfSight(victim.Position, pawn.Position, victim.Map, false, (Func <IntVec3, bool>)null, 0, 0)));
 }
Пример #14
0
        public static bool TryFindWalkPath(Pawn pawn, IntVec3 root, out List <IntVec3> result)
        {
            List <IntVec3> list = new List <IntVec3>();

            list.Add(root);
            IntVec3 intVec = root;

            for (int i = 0; i < 8; i++)
            {
                IntVec3 intVec2 = IntVec3.Invalid;
                float   num     = -1f;
                for (int num2 = WalkPathFinder.StartRadialIndex; num2 > WalkPathFinder.EndRadialIndex; num2 -= WalkPathFinder.RadialIndexStride)
                {
                    IntVec3 intVec3 = intVec + GenRadial.RadialPattern[num2];
                    if (intVec3.InBounds(pawn.Map) && intVec3.Standable(pawn.Map) && !intVec3.IsForbidden(pawn) && GenSight.LineOfSight(intVec, intVec3, pawn.Map, false, null, 0, 0) && !intVec3.Roofed(pawn.Map) && !PawnUtility.KnownDangerAt(intVec3, pawn))
                    {
                        float num3 = 10000f;
                        for (int j = 0; j < list.Count; j++)
                        {
                            num3 += (float)(list[j] - intVec3).LengthManhattan;
                        }
                        float num4 = (float)(intVec3 - root).LengthManhattan;
                        if (num4 > 40.0)
                        {
                            num3 *= Mathf.InverseLerp(70f, 40f, num4);
                        }
                        if (list.Count >= 2)
                        {
                            float angleFlat  = (list[list.Count - 1] - list[list.Count - 2]).AngleFlat;
                            float angleFlat2 = (intVec3 - intVec).AngleFlat;
                            float num5;
                            if (angleFlat2 > angleFlat)
                            {
                                num5 = angleFlat2 - angleFlat;
                            }
                            else
                            {
                                angleFlat = (float)(angleFlat - 360.0);
                                num5      = angleFlat2 - angleFlat;
                            }
                            if (num5 > 110.0)
                            {
                                num3 = (float)(num3 * 0.0099999997764825821);
                            }
                        }
                        if (list.Count >= 4 && (intVec - root).LengthManhattan < (intVec3 - root).LengthManhattan)
                        {
                            num3 = (float)(num3 * 9.9999997473787516E-06);
                        }
                        if (num3 > num)
                        {
                            intVec2 = intVec3;
                            num     = num3;
                        }
                    }
                }
                if (num < 0.0)
                {
                    result = null;
                    return(false);
                }
                list.Add(intVec2);
                intVec = intVec2;
            }
            list.Add(root);
            result = list;
            return(true);
        }
Пример #15
0
        protected void TrySpread()
        {
            IntVec3 intVec = base.Position;
            bool    flag;

            Rand.PushState();
            if (Rand.Chance(0.8f))
            {
                intVec = base.Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(1, 8)];
                flag   = true;
            }
            else
            {
                intVec = base.Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(10, 20)];
                flag   = false;
            }
            Rand.PopState();
            if (!intVec.InBounds(base.Map))
            {
                return;
            }

            float chance;

            if (this.def.projectile.damageDef == AdeptusDamageDefOf.OG_Chaos_Deamon_Warpfire)
            {
                chance = WarpfireUtility.ChanceToStartWarpfireIn(intVec, base.Map);
            }
            else
            {
                chance = FireUtility.ChanceToStartFireIn(intVec, base.Map);
            }

            Rand.PushState();
            bool f = Rand.Chance(chance);

            Rand.PopState();
            if (f)
            {
                if (!flag)
                {
                    CellRect startRect = CellRect.SingleCell(base.Position);
                    CellRect endRect   = CellRect.SingleCell(intVec);
                    if (!GenSight.LineOfSight(base.Position, intVec, base.Map, startRect, endRect, null))
                    {
                        return;
                    }
                    Spark spark;
                    if (this.def.projectile.damageDef == AdeptusDamageDefOf.OG_Chaos_Deamon_Warpfire)
                    {
                        spark = (Spark)GenSpawn.Spawn(AdeptusThingDefOf.OG_WarpSpark, base.Position, base.Map, WipeMode.Vanish);
                    }
                    else
                    {
                        spark = (Spark)GenSpawn.Spawn(ThingDefOf.Spark, base.Position, base.Map, WipeMode.Vanish);
                    }
                    spark.Launch(this, intVec, intVec, ProjectileHitFlags.All, null);
                }
                else
                {
                    if (this.def.projectile.damageDef == AdeptusDamageDefOf.OG_Chaos_Deamon_Warpfire)
                    {
                        WarpfireUtility.TryStartWarpfireIn(intVec, base.Map, 0.1f);
                    }
                    else
                    {
                        FireUtility.TryStartFireIn(intVec, base.Map, 0.1f);
                    }
                }
            }
        }
Пример #16
0
        private static void _AppendThoughts_Humanlike(Pawn victim, DamageInfo?dinfo, Hediff hediff, PawnDiedOrDownedThoughtsKind thoughtsKind, List <IndividualThoughtToAdd> outIndividualThoughts, List <ThoughtDef> outAllColonistsThoughts)
        {
            var  IsExecution        = typeof(PawnDiedOrDownedThoughtsUtility).GetMethod("IsExecution", BindingFlags.Static | BindingFlags.NonPublic);
            var  IsInnocentPrisoner = typeof(PawnDiedOrDownedThoughtsUtility).GetMethod("IsInnocentPrisoner", BindingFlags.Static | BindingFlags.NonPublic);
            bool flag  = (bool)IsExecution.Invoke(null, new object[] { dinfo, hediff });
            bool flag2 = (bool)IsInnocentPrisoner.Invoke(null, new object[] { victim });
            bool flag3 = dinfo.HasValue && dinfo.Value.Def.externalViolence && dinfo.Value.Instigator != null && dinfo.Value.Instigator is Pawn;

            if (flag3)
            {
                Pawn pawn = (Pawn)dinfo.Value.Instigator;
                if (!pawn.Dead && pawn.needs.mood != null && pawn.story != null && pawn != victim)
                {
                    if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died)
                    {
                        outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KilledHumanlikeBloodlust, pawn, null, 1f, 1f));
                    }
                    if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died && victim.HostileTo(pawn))
                    {
                        if (victim.Faction != null && PawnUtility.IsFactionLeader(victim) && victim.Faction.HostileTo(pawn.Faction))
                        {
                            outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.DefeatedHostileFactionLeader, pawn, victim, 1f, 1f));
                        }
                        else if (victim.Faction != null && victim.Faction.HostileTo(pawn.Faction) && !flag2)
                        {
                            outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KilledHumanlikeEnemy, pawn, victim, 1f, 1f));
                        }
                        if (victim.kindDef.combatPower > 250f)
                        {
                            outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.DefeatedMajorEnemy, pawn, victim, 1f, 1f));
                        }
                    }
                }
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died && victim.Spawned)
            {
                List <Pawn> allPawnsSpawned = victim.Map.mapPawns.AllPawnsSpawned;
                for (int i = 0; i < allPawnsSpawned.Count; i++)
                {
                    Pawn pawn2 = allPawnsSpawned[i];
                    if (pawn2 != victim && pawn2.needs.mood != null)
                    {
                        if (!flag && (pawn2.MentalStateDef != MentalStateDefOf.SocialFighting || ((MentalState_SocialFighting)pawn2.MentalState).otherPawn != victim))
                        {
                            if (pawn2.Position.InHorDistOf(victim.Position, 12f) && GenSight.LineOfSight(victim.Position, pawn2.Position, victim.Map, false) && pawn2.Awake() && pawn2.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
                            {
                                if (pawn2.Faction == victim.Faction)
                                {
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathAlly, pawn2, null, 1f, 1f));
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.WitnessedDeathAllyBleedingHeart, pawn2, null, 1f, 1f));
                                }
                                else if (victim.Faction == null || (!victim.Faction.HostileTo(pawn2.Faction) || pawn2.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart)))
                                {
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathNonAlly, pawn2, null, 1f, 1f));
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.WitnessedDeathNonAllyBleedingHeart, pawn2, null, 1f, 1f));
                                }
                                if (pawn2.relations.FamilyByBlood.Contains(victim))
                                {
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathFamily, pawn2, null, 1f, 1f));
                                }
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathBloodlust, pawn2, null, 1f, 1f));
                                if (!pawn2.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn2.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn2.story.traits.HasTrait(TraitDefOf.Bloodlust) && !pawn2.story.traits.HasTrait(TraitDefOfPsychology.Desensitized))
                                {
                                    if (((pawn2.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn2) + GenLocalDate.Year(pawn2) + (int)(GenLocalDate.DayPercent(pawn2) * 5) * 60) * 391) % 1000) == 0)
                                    {
                                        pawn2.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized));
                                        pawn2.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.RecentlyDesensitized, null);
                                    }
                                }
                            }
                            else if (victim.Faction == Faction.OfPlayer && victim.Faction == pawn2.Faction && victim.HostFaction != pawn2.Faction)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KnowColonistDied, pawn2, null, 1f, 1f));
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KnowColonistDiedBleedingHeart, pawn2, null, 1f, 1f));
                            }
                            if (flag2 && pawn2.Faction == Faction.OfPlayer && !pawn2.IsPrisoner)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KnowPrisonerDiedInnocent, pawn2, null, 1f, 1f));
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KnowPrisonerDiedInnocentBleedingHeart, pawn2, null, 1f, 1f));
                            }
                        }
                    }
                }
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Abandoned && victim.IsColonist)
            {
                outAllColonistsThoughts.Add(ThoughtDefOf.ColonistAbandoned);
                outAllColonistsThoughts.Add(ThoughtDefOfPsychology.ColonistAbandonedBleedingHeart);
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.AbandonedToDie)
            {
                if (victim.IsColonist)
                {
                    outAllColonistsThoughts.Add(ThoughtDefOf.ColonistAbandonedToDie);
                    outAllColonistsThoughts.Add(ThoughtDefOfPsychology.ColonistAbandonedToDieBleedingHeart);
                }
                else if (victim.IsPrisonerOfColony)
                {
                    outAllColonistsThoughts.Add(ThoughtDefOf.PrisonerAbandonedToDie);
                    outAllColonistsThoughts.Add(ThoughtDefOfPsychology.PrisonerAbandonedToDieBleedingHeart);
                }
            }
        }
Пример #17
0
        public override void Tick()
        {
            base.Tick();

            if (this.ageTracker.CurLifeStage.defName.ToString().Equals("MareepStage"))
            {
                float mareepCount = 1;

                for (int i = 0; i < 10; i++)
                {
                    IntVec3 intVec = this.Position + GenRadial.RadialPattern [i];
                    if (intVec.InBounds(base.Map))
                    {
                        Thing thing = intVec.GetThingList(base.Map).Find((Thing x) => x is Pawn);
                        if (thing != null)
                        {
                            if (GenSight.LineOfSight(this.Position, intVec, base.Map, false, null, 0, 0))
                            {
                                Pawn   pDummy = (Pawn)thing;
                                string d      = thing.def.defName.ToString();

                                if (d.Equals("Pokemon_Mareep") && pDummy.ageTracker.CurLifeStage.defName.ToString().Equals("MareepStage"))
                                {
                                    ++mareepCount;
                                }
                            }
                        }
                    }
                }

                this.StoredEnergy += (mareepCount / 40) * Rand.Value;
            }

            if (this.Faction != null)
            {
                if (this.StoredEnergy <= this.Def.storedEnergyMaxUtility * 0.05f)
                {
                    this.closestDischarger = null;
                    this.jobs.ClearQueuedJobs();
                }

                if (this.StoredEnergy >= this.Def.storedEnergyMaxUtility)
                {
                    if (this.closestDischarger == null)
                    {
                        for (int i = 0; i < 1200; i++)
                        {
                            IntVec3 intVec = this.Position + GenRadial.RadialPattern [i];
                            if (intVec.InBounds(base.Map))
                            {
                                Thing thing = intVec.GetThingList(base.Map).Find((Thing x) => x is Building);
                                if (thing != null)
                                {
                                    if (GenSight.LineOfSight(this.Position, intVec, base.Map, false, null, 0, 0))
                                    {
                                        Building closest = (Building)thing;
                                        string   d       = closest.def.defName.ToString();
                                        string[] splt    = d.Split('_');

                                        //Log.Message (d);

                                        if (splt.Length == 2 && splt [0].Equals("Mareep"))
                                        {
                                            //Log.Message ("Found discharging station");
                                            this.closestDischarger = closest;
                                            this.pather.StartPath(new LocalTargetInfo(this.closestDischarger), Verse.AI.PathEndMode.OnCell);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Message("No discharging station found");
                    }
                }

                if (this.closestDischarger != null)
                {
                    if (this.Position.AdjacentTo8WayOrInside(this.closestDischarger))
                    {
                        PawnUtility.ForceWait(this, 5);
                        List <ThingComp>     lt   = this.closestDischarger.AllComps;
                        CompPowerPlantMareep comp = (CompPowerPlantMareep)lt [0];
                        comp.AddToStoredPower(1f);
                        this.StoredEnergy -= 1f;
                    }
                }
            }
            else
            {
                if (this.StoredEnergy >= this.Def.storedEnergyMaxUtility * 0.1f)
                {
                    this.StoredEnergy -= 0.1f * Rand.Value;
                }
            }

            if (this.StoredEnergy > this.Def.storedEnergyMaxUtility + this.Def.storedEnergyMaxUtility * 0.2f)
            {
                IntVec3 randomCell = this.OccupiedRect().RandomCell;
                float   radius     = Rand.Range(0.5f, 1f) * 3f;
                GenExplosion.DoExplosion(randomCell, base.Map, radius, DamageDefOf.EMP, null, -1, 0f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                this.StoredEnergy -= 800f;
            }
        }
Пример #18
0
        public static bool TryFindRandomSpotJustOutsideColony(IntVec3 root, Map map, Pawn searcher, out IntVec3 result, Predicate <IntVec3> extraValidator = null)
        {
            bool desperate                = false;
            int  minColonyBuildingsLOS    = 0;
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!c.Standable(map))
                {
                    return(false);
                }
                Room room = c.GetRoom(map, RegionType.Set_Passable);
                if (room.PsychologicallyOutdoors && room.TouchesMapEdge)
                {
                    if (room != null && room.CellCount >= 25)
                    {
                        if (!desperate && !map.reachability.CanReachColony(c))
                        {
                            return(false);
                        }
                        if (extraValidator != null && !extraValidator(c))
                        {
                            return(false);
                        }
                        if (minColonyBuildingsLOS > 0)
                        {
                            int colonyBuildingsLOSFound = 0;
                            RCellFinder.tmpBuildings.Clear();
                            RegionTraverser.BreadthFirstTraverse(c, map, (Region from, Region to) => true, delegate(Region reg)
                            {
                                Faction ofPlayer  = Faction.OfPlayer;
                                List <Thing> list = reg.ListerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial);
                                for (int i = 0; i < list.Count; i++)
                                {
                                    Thing thing = list[i];
                                    if (thing.Faction == ofPlayer && thing.Position.InHorDistOf(c, 16f) && GenSight.LineOfSight(thing.Position, c, map, true, null, 0, 0) && !RCellFinder.tmpBuildings.Contains(thing))
                                    {
                                        RCellFinder.tmpBuildings.Add(thing);
                                        colonyBuildingsLOSFound++;
                                        if (colonyBuildingsLOSFound >= minColonyBuildingsLOS)
                                        {
                                            return(true);
                                        }
                                    }
                                }
                                return(false);
                            }, 12, RegionType.Set_Passable);
                            RCellFinder.tmpBuildings.Clear();
                            if (colonyBuildingsLOSFound < minColonyBuildingsLOS)
                            {
                                return(false);
                            }
                        }
                        if (root.IsValid)
                        {
                            TraverseParms traverseParams = (searcher == null) ? ((TraverseParms)TraverseMode.PassDoors) : TraverseParms.For(searcher, Danger.Deadly, TraverseMode.ByPawn, false);
                            if (!map.reachability.CanReach(root, c, PathEndMode.Touch, traverseParams))
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    return(false);
                }
                return(false);
            };
            int num = 0;

            while (num < 100)
            {
                Building building = null;
                if ((from b in map.listerBuildings.allBuildingsColonist
                     where b.def.designationCategory != DesignationCategoryDefOf.Structure && b.def.building.ai_chillDestination
                     select b).TryRandomElement <Building>(out building))
                {
                    if (num < 10)
                    {
                        minColonyBuildingsLOS = 4;
                    }
                    else if (num < 25)
                    {
                        minColonyBuildingsLOS = 3;
                    }
                    else if (num < 40)
                    {
                        minColonyBuildingsLOS = 2;
                    }
                    else
                    {
                        minColonyBuildingsLOS = 1;
                    }
                    int squareRadius = 10 + num / 5;
                    desperate = (num > 60);
                    if (CellFinder.TryFindRandomCellNear(building.Position, map, squareRadius, validator, out result))
                    {
                        return(true);
                    }
                    num++;
                    continue;
                }
                break;
            }
            int num2 = 0;

            while (num2 < 50)
            {
                Building building2 = null;
                if (((IEnumerable <Building>)map.listerBuildings.allBuildingsColonist).TryRandomElement <Building>(out building2))
                {
                    if (num2 < 10)
                    {
                        minColonyBuildingsLOS = 3;
                    }
                    else if (num2 < 20)
                    {
                        minColonyBuildingsLOS = 2;
                    }
                    else if (num2 < 30)
                    {
                        minColonyBuildingsLOS = 1;
                    }
                    else
                    {
                        minColonyBuildingsLOS = 0;
                    }
                    desperate = (num2 > 20);
                    if (CellFinder.TryFindRandomCellNear(building2.Position, map, 14, validator, out result))
                    {
                        return(true);
                    }
                    num2++;
                    continue;
                }
                break;
            }
            int num3 = 0;

            while (num3 < 100)
            {
                Pawn pawn = null;
                if (map.mapPawns.FreeColonistsAndPrisonersSpawned.TryRandomElement <Pawn>(out pawn))
                {
                    minColonyBuildingsLOS = 0;
                    desperate             = (num3 > 50);
                    if (CellFinder.TryFindRandomCellNear(pawn.Position, map, 14, validator, out result))
                    {
                        return(true);
                    }
                    num3++;
                    continue;
                }
                break;
            }
            desperate             = true;
            minColonyBuildingsLOS = 0;
            if (CellFinderLoose.TryGetRandomCellWith(validator, map, 1000, out result))
            {
                return(true);
            }
            return(false);
        }
Пример #19
0
 // Token: 0x0600011B RID: 283 RVA: 0x0000B7C4 File Offset: 0x00009BC4
 private void HoloTickPawn()
 {
     if (this.pawn != null)
     {
         if (this.pawn.Dead)
         {
             Log.Message(string.Format("{0} is dead.", this.pawn.Name.ToStringShort));
             if (this.pawn.Corpse.holdingOwner != this.Emitter.GetDirectlyHeldThings())
             {
                 if (this.Emitter.TryAcceptThing(this.pawn.Corpse, true))
                 {
                 }
             }
         }
         else
         {
             if (!this.pawn.health.hediffSet.HasHediff(HediffDef.Named("Holographic")))
             {
                 this.SetUpPawn();
             }
             if (!this.pawn.Spawned)
             {
                 GenSpawn.Spawn(this.pawn, this.parent.Position, this.parent.Map);
             }
             this.pawn.needs.food.CurLevel     = 1f;
             this.pawn.needs.joy.CurLevel      = 1f;
             this.pawn.needs.rest.CurLevel     = 1f;
             this.pawn.needs.outdoors.CurLevel = 1f;
             this.pawn.needs.comfort.CurLevel  = 1f;
             this.pawn.needs.beauty.CurLevel   = 1f;
             if (!this.pawn.Position.InHorDistOf(this.parent.Position, 12f) || !GenSight.LineOfSight(this.parent.Position, this.pawn.Position, this.parent.Map, true, null, 0, 0))
             {
                 this.pawn.inventory.DropAllNearPawn(this.pawn.Position, false, false);
                 this.pawn.equipment.DropAllEquipment(this.pawn.Position, false);
                 this.pawn.DeSpawn();
                 GenSpawn.Spawn(this.pawn, this.parent.Position, this.parent.Map);
             }
             this.pawn.health.Reset();
             this.pawn.health.AddHediff(HediffDef.Named("Holographic"));
         }
     }
 }
Пример #20
0
        public static bool TryFindDirectFleeDestination(IntVec3 root, float dist, Pawn pawn, out IntVec3 result)
        {
            for (int i = 0; i < 30; i++)
            {
                result = root + IntVec3.FromVector3(Vector3Utility.HorizontalVectorFromAngle((float)Rand.Range(0, 360)) * dist);
                if (result.Walkable(pawn.Map) && result.DistanceToSquared(pawn.Position) < result.DistanceToSquared(root) && GenSight.LineOfSight(root, result, pawn.Map, true, null, 0, 0))
                {
                    return(true);
                }
            }
            Region region = pawn.GetRegion(RegionType.Set_Passable);

            for (int j = 0; j < 30; j++)
            {
                Region  region2    = CellFinder.RandomRegionNear(region, 15, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), null, null, RegionType.Set_Passable);
                IntVec3 randomCell = region2.RandomCell;
                if (randomCell.Walkable(pawn.Map) && (float)(root - randomCell).LengthHorizontalSquared > dist * dist)
                {
                    using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, randomCell, pawn, PathEndMode.OnCell))
                    {
                        if (PawnPathUtility.TryFindCellAtIndex(path, (int)dist + 3, out result))
                        {
                            return(true);
                        }
                    }
                }
            }
            result = pawn.Position;
            return(false);
        }
        /// <summary>
        /// Checks for cover along the flight path of the bullet, doesn't check for walls or trees, only intended for cover with partial fillPercent
        /// </summary>
        /// <param name="target">The target of which to find cover of</param>
        /// <param name="cover">Output parameter, filled with the highest cover object found</param>
        /// <returns>True if cover was found, false otherwise</returns>
        private bool GetHighestCoverAndSmokeForTarget(LocalTargetInfo target, out Thing cover, out float smokeDensity)
        {
            Map   map                = caster.Map;
            Thing targetThing        = target.Thing;
            Thing highestCover       = null;
            float highestCoverHeight = 0f;

            smokeDensity = 0;

            // Iterate through all cells on line of sight and check for cover and smoke
            var cells = GenSight.PointsOnLineOfSight(target.Cell, caster.Position).ToArray();

            if (cells.Length < 3)
            {
                cover = null;
                return(false);
            }
            for (int i = 0; i <= cells.Length / 2; i++)
            {
                var cell = cells[i];

                if (cell.AdjacentTo8Way(caster.Position))
                {
                    continue;
                }

                // Check for smoke
                var gas = cell.GetGas(map);
                if (gas != null)
                {
                    smokeDensity += gas.def.gas.accuracyPenalty;
                }

                // Check for cover in the second half of LoS
                if (i <= cells.Length / 2)
                {
                    Pawn  pawn     = cell.GetFirstPawn(map);
                    Thing newCover = pawn == null?cell.GetCover(map) : pawn;

                    float newCoverHeight = new CollisionVertical(newCover).Max;

                    // Cover check, if cell has cover compare collision height and get the highest piece of cover, ignore if cover is the target (e.g. solar panels, crashed ship, etc)
                    if (newCover != null &&
                        (targetThing == null || !newCover.Equals(targetThing)) &&
                        (highestCover == null || highestCoverHeight < newCoverHeight) &&
                        newCover.def.Fillage == FillCategory.Partial &&
                        !newCover.IsPlant())
                    {
                        highestCover       = newCover;
                        highestCoverHeight = newCoverHeight;
                        if (Controller.settings.DebugDrawTargetCoverChecks)
                        {
                            map.debugDrawer.FlashCell(cell, highestCoverHeight, highestCoverHeight.ToString());
                        }
                    }
                }
            }
            cover = highestCover;

            //Report success if found cover
            return(cover != null);
        }
Пример #22
0
 private bool TryFindSpawnCell(out IntVec3 result)
 {
     foreach (IntVec3 current in GenAdj.CellsAdjacent8Way(this.parent).InRandomOrder(null))
     {
         if (current.Walkable(this.parent.Map))
         {
             Building edifice = current.GetEdifice(this.parent.Map);
             if (edifice == null || !this.Props.thingResult.IsEdifice())
             {
                 Building_Door building_door = edifice as Building_Door;
                 if (building_door == null || building_door.FreePassage)
                 {
                     if (this.parent.def.passability == Traversability.Impassable || GenSight.LineOfSight(this.parent.Position, current, this.parent.Map, false, null, 0, 0))
                     {
                         bool         flag      = false;
                         List <Thing> thingList = current.GetThingList(this.parent.Map);
                         for (int i = 0; i < thingList.Count; i++)
                         {
                             Thing thing = thingList[i];
                             if (thing.def.category == ThingCategory.Item && (thing.def != this.Props.thingResult || thing.stackCount > this.Props.thingResult.stackLimit - this.Props.resultCount))
                             {
                                 flag = true;
                                 break;
                             }
                         }
                         if (!flag)
                         {
                             result = current;
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     result = IntVec3.Invalid;
     return(false);
 }
Пример #23
0
        public static Thing FindTarget(Pawn pawn)
        {
            List <Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned;

            if (allPawns == null || !allPawns.Any())
            {
                return(null);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(null);
            }
            List <Thing> targets = new List <Thing>();

            foreach (Pawn target in allPawns)
            {
                if (!target.DestroyedOrNull() && !target.Downed)
                {
                    if (target.Faction == null || (target.Faction != null && target.Faction != pawn.Faction))
                    {
                        bool recentAttack          = target.mindState != null && target.mindState.lastAttackedTarget == pawn && target.mindState.lastAttackTargetTick <= Find.TickManager.TicksGame && target.mindState.lastAttackTargetTick > Find.TickManager.TicksGame - ticksInAttackMode;
                        bool withinHiveAndInVisual = JobGiver_InsectGather.WithinHive(pawn, target as Thing, false) && GenSight.LineOfSight(pawn.Position, target.Position, pawn.Map, true, null, 0, 0);
                        if (recentAttack || withinHiveAndInVisual)
                        {
                            if (!BetterInfestationsMod.settings.disabledDefList.Contains(target.def.defName))
                            {
                                targets.Add(target as Thing);
                            }
                        }
                    }
                }
            }
            return(JobGiver_InsectGather.GetClosest(pawn, targets));
        }
 public static bool AnimalAwareOf(this Pawn p, Thing t)
 {
     return(p.RaceProps.ToolUser || p.Faction != null || ((float)(p.Position - t.Position).LengthHorizontalSquared <= 900f && p.GetRoom(RegionType.Set_Passable) == t.GetRoom(RegionType.Set_Passable) && GenSight.LineOfSight(p.Position, t.Position, p.Map, false, null, 0, 0)));
 }
Пример #25
0
 // Token: 0x06000016 RID: 22 RVA: 0x000028CC File Offset: 0x00000ACC
 public static bool IsTargetHidden(Pawn target, Pawn seer)
 {
     if (target == null || seer == null)
     {
         Log.Message("Target/Seer Null", false);
         return(false);
     }
     if (target != null && seer != null)
     {
         if (target == seer)
         {
             return(false);
         }
         if (CamoUtility.TryGetCamoHidValue(seer, target, out bool result))
         {
             return(result);
         }
     }
     if (target != null && target.Spawned)
     {
         bool    flag    = false;
         Apparel apparel = null;
         if (!CamoUtility.IsDebugMode() || !Controller.Settings.forcePassive)
         {
             flag = CamoUtility.IsCamoActive(target, out Apparel apparel2);
             if (apparel2 != null)
             {
                 apparel = apparel2;
             }
         }
         if ((!flag || (flag && seer.CurrentEffectiveVerb.IsMeleeAttack)) && CamoUtility.SimplyTooClose(seer, target))
         {
             CamoUtility.TryAddCamoHidValue(seer, target, false);
             return(false);
         }
         if (flag || (CamoUtility.IsDebugMode() && Controller.Settings.forceActive))
         {
             if (seer == null || !seer.Spawned)
             {
                 return(false);
             }
             if ((target?.Map) == null || (seer?.Map) == null || target.Map != seer.Map || (seer.InMentalState && target.InMentalState))
             {
                 CamoUtility.TryAddCamoHidValue(seer, target, false);
                 return(false);
             }
             if (!GenSight.LineOfSight(seer.Position, target.Position, seer.Map, false, null, 0, 0))
             {
                 return(true);
             }
             float num  = 0.75f;
             int   num2 = 0;
             bool  flag2;
             if (CamoUtility.IsDebugMode() && Controller.Settings.forceActive)
             {
                 apparel = null;
                 flag2   = Controller.Settings.forceStealth;
                 if (flag2)
                 {
                     num2 = 5;
                 }
             }
             else
             {
                 num   = ThingCompUtility.TryGetComp <CompGearCamo>(apparel).Props.ActiveCamoEff;
                 num2  = ThingCompUtility.TryGetComp <CompGearCamo>(apparel).Props.StealthCamoChance;
                 flag2 = (num2 > 0 && num > 0f);
             }
             if (CamoUtility.CamoEffectWorked(target, seer, apparel, num, true, flag2, num2, out int chance, out float scaler))
             {
                 CamoUtility.DoCamoMote(seer, target, true, chance, num, scaler);
                 CamoUtility.TryAddCamoHidValue(seer, target, true);
                 CamoAIUtility.CorrectLordForCamo(seer, target);
                 return(true);
             }
             CamoUtility.DoCamoMote(seer, target, false, chance, num, scaler);
             CamoUtility.TryAddCamoHidValue(seer, target, false);
             return(false);
         }
         else if (seer != null && seer.Spawned)
         {
             if (!CamoGearUtility.GetCurCamoEff(target, out string str, out float camoEff))
             {
                 CamoUtility.TryAddCamoHidValue(seer, target, false);
                 return(false);
             }
             if (CamoUtility.IsDebugMode())
             {
                 if (Controller.Settings.forcePassive)
                 {
                     camoEff = 0.75f;
                 }
                 Log.Message("Camo: " + str + " : " + camoEff.ToString("F2"), false);
             }
             if ((target?.Map) == null || (seer?.Map) == null || target.Map != seer.Map || (seer.InMentalState && target.InMentalState))
             {
                 CamoUtility.TryAddCamoHidValue(seer, target, false);
                 return(false);
             }
             if (!GenSight.LineOfSight(seer.Position, target.Position, seer.Map, false, null, 0, 0))
             {
                 return(true);
             }
             if (CamoUtility.CamoEffectWorked(target, seer, null, camoEff, false, false, 0, out int chance2, out float scaler2))
             {
                 CamoUtility.DoCamoMote(seer, target, true, chance2, camoEff, scaler2);
                 CamoUtility.TryAddCamoHidValue(seer, target, true);
                 CamoAIUtility.CorrectLordForCamo(seer, target);
                 return(true);
             }
             CamoUtility.DoCamoMote(seer, target, false, chance2, camoEff, scaler2);
             CamoUtility.TryAddCamoHidValue(seer, target, false);
             return(false);
         }
     }
     return(false);
 }
Пример #26
0
 public static bool IsGoodPositionForInteraction(IntVec3 cell, IntVec3 recipientCell, Map map)
 {
     return(cell.InHorDistOf(recipientCell, 6f) && GenSight.LineOfSight(cell, recipientCell, map, true, null, 0, 0));
 }
 private static bool TryFindChairNear(IntVec3 center, Pawn sitter, out Thing chair)
 {
     for (int i = 0; i < JoyGiver_SocialRelax.RadialPatternMiddleOutward.Count; i++)
     {
         IntVec3  c       = center + JoyGiver_SocialRelax.RadialPatternMiddleOutward[i];
         Building edifice = c.GetEdifice(sitter.Map);
         if (edifice != null && edifice.def.building.isSittable && sitter.CanReserve(edifice, 1, -1, null, false) && !edifice.IsForbidden(sitter) && GenSight.LineOfSight(center, edifice.Position, sitter.Map, true, null, 0, 0))
         {
             chair = edifice;
             return(true);
         }
     }
     chair = null;
     return(false);
 }
Пример #28
0
        private void Tick_CheckDevelopBondRelation()
        {
            if (!this.pawn.Spawned || !this.pawn.RaceProps.Animal || this.pawn.Faction != Faction.OfPlayer || this.pawn.playerSettings.RespectedMaster == null)
            {
                return;
            }
            Pawn respectedMaster = this.pawn.playerSettings.RespectedMaster;

            if (this.pawn.IsHashIntervalTick(2500) && this.pawn.Position.InHorDistOf(respectedMaster.Position, 12f) && GenSight.LineOfSight(this.pawn.Position, respectedMaster.Position, this.pawn.Map, false, null, 0, 0))
            {
                RelationsUtility.TryDevelopBondRelation(respectedMaster, this.pawn, 0.001f);
            }
        }
        public static bool TryFindSpectatorCellFor(Pawn p, CellRect spectateRect, Map map, out IntVec3 cell, SpectateRectSide allowedSides = SpectateRectSide.All, int margin = 1, List <IntVec3> extraDisallowedCells = null)
        {
            spectateRect.ClipInsideMap(map);
            if (spectateRect.Area == 0 || allowedSides == SpectateRectSide.None)
            {
                cell = IntVec3.Invalid;
                return(false);
            }
            CellRect            rectWithMargin = spectateRect.ExpandedBy(margin).ClipInsideMap(map);
            Predicate <IntVec3> predicate      = delegate(IntVec3 x)
            {
                if (!x.InBounds(map))
                {
                    return(false);
                }
                if (!x.Standable(map))
                {
                    return(false);
                }
                if (x.Fogged(map))
                {
                    return(false);
                }
                if (rectWithMargin.Contains(x))
                {
                    return(false);
                }
                if ((x.z <= rectWithMargin.maxZ || (allowedSides & SpectateRectSide.Up) != SpectateRectSide.Up) && (x.x <= rectWithMargin.maxX || (allowedSides & SpectateRectSide.Right) != SpectateRectSide.Right) && (x.z >= rectWithMargin.minZ || (allowedSides & SpectateRectSide.Down) != SpectateRectSide.Down) && (x.x >= rectWithMargin.minX || (allowedSides & SpectateRectSide.Left) != SpectateRectSide.Left))
                {
                    return(false);
                }
                IntVec3 intVec3 = spectateRect.ClosestCellTo(x);
                if ((float)intVec3.DistanceToSquared(x) > 210.25f)
                {
                    return(false);
                }
                if (!GenSight.LineOfSight(intVec3, x, map, true, null, 0, 0))
                {
                    return(false);
                }
                if (x.GetThingList(map).Find((Thing y) => y is Pawn && y != p) != null)
                {
                    return(false);
                }
                if (p != null)
                {
                    if (!p.CanReserveAndReach(x, PathEndMode.OnCell, Danger.Some, 1, -1, null, false))
                    {
                        return(false);
                    }
                    Building edifice = x.GetEdifice(map);
                    if (edifice != null && edifice.def.category == ThingCategory.Building && edifice.def.building.isSittable && !p.CanReserve(edifice, 1, -1, null, false))
                    {
                        return(false);
                    }
                    if (x.IsForbidden(p))
                    {
                        return(false);
                    }
                    if (x.GetDangerFor(p, map) != Danger.None)
                    {
                        return(false);
                    }
                }
                if (extraDisallowedCells != null && extraDisallowedCells.Contains(x))
                {
                    return(false);
                }
                if (!SpectatorCellFinder.CorrectlyRotatedChairAt(x, map, spectateRect))
                {
                    int num = 0;
                    for (int k = 0; k < GenAdj.AdjacentCells.Length; k++)
                    {
                        IntVec3 x2 = x + GenAdj.AdjacentCells[k];
                        if (SpectatorCellFinder.CorrectlyRotatedChairAt(x2, map, spectateRect))
                        {
                            num++;
                        }
                    }
                    if (num >= 3)
                    {
                        return(false);
                    }
                    int num2 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(-1, 0, 0), map, 4, spectateRect);
                    if (num2 >= 0)
                    {
                        int num3 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(1, 0, 0), map, 4, spectateRect);
                        if (num3 >= 0 && Mathf.Abs(num2 - num3) <= 1)
                        {
                            return(false);
                        }
                    }
                    int num4 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(0, 0, 1), map, 4, spectateRect);
                    if (num4 >= 0)
                    {
                        int num5 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(0, 0, -1), map, 4, spectateRect);
                        if (num5 >= 0 && Mathf.Abs(num4 - num5) <= 1)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            };

            if (p != null && predicate(p.Position) && SpectatorCellFinder.CorrectlyRotatedChairAt(p.Position, map, spectateRect))
            {
                cell = p.Position;
                return(true);
            }
            for (int i = 0; i < 1000; i++)
            {
                IntVec3 intVec = rectWithMargin.CenterCell + GenRadial.RadialPattern[i];
                if (predicate(intVec))
                {
                    if (!SpectatorCellFinder.CorrectlyRotatedChairAt(intVec, map, spectateRect))
                    {
                        for (int j = 0; j < 90; j++)
                        {
                            IntVec3 intVec2 = intVec + GenRadial.RadialPattern[j];
                            if (SpectatorCellFinder.CorrectlyRotatedChairAt(intVec2, map, spectateRect) && predicate(intVec2))
                            {
                                cell = intVec2;
                                return(true);
                            }
                        }
                    }
                    cell = intVec;
                    return(true);
                }
            }
            cell = IntVec3.Invalid;
            return(false);
        }
        public static bool ShouldFleeFrom(Thing t, Pawn pawn, bool checkDistance, bool checkLOS)
        {
            if (t == pawn || (checkDistance && !t.Position.InHorDistOf(pawn.Position, 8f)))
            {
                return(false);
            }
            if (t.def.alwaysFlee)
            {
                return(true);
            }
            if (!t.HostileTo(pawn))
            {
                return(false);
            }
            IAttackTarget attackTarget = t as IAttackTarget;

            if (attackTarget == null || attackTarget.ThreatDisabled(pawn) || !(t is IAttackTargetSearcher) || (checkLOS && !GenSight.LineOfSight(pawn.Position, t.Position, pawn.Map)))
            {
                return(false);
            }
            return(true);
        }