Esempio n. 1
0
 public static void NotifyNearbyPawnsOfDangerousExplosive(Thing exploder, DamageDef damage, Faction onlyFaction = null)
 {
     if (damage.externalViolence)
     {
         Room room = exploder.GetRoom(RegionType.Set_Passable);
         for (int i = 0; i < GenExplosion.PawnNotifyCellCount; i++)
         {
             IntVec3 c = exploder.Position + GenRadial.RadialPattern[i];
             if (c.InBounds(exploder.Map))
             {
                 List <Thing> thingList = c.GetThingList(exploder.Map);
                 for (int j = 0; j < thingList.Count; j++)
                 {
                     Pawn pawn = thingList[j] as Pawn;
                     if (pawn != null && pawn.RaceProps.intelligence >= Intelligence.Humanlike && (onlyFaction == null || pawn.Faction == onlyFaction))
                     {
                         Room room2 = pawn.GetRoom(RegionType.Set_Passable);
                         if (room2 == null || room2.CellCount == 1 || (room2 == room && GenSight.LineOfSight(exploder.Position, pawn.Position, exploder.Map, true, null, 0, 0)))
                         {
                             pawn.mindState.Notify_DangerousExploderAboutToExplode(exploder);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public static void NotifyNearbyPawnsOfDangerousExplosive(Thing exploder, DamageDef damage, Faction onlyFaction = null)
        {
            Room room = exploder.GetRoom();

            for (int i = 0; i < PawnNotifyCellCount; i++)
            {
                IntVec3 c = exploder.Position + GenRadial.RadialPattern[i];
                if (!c.InBounds(exploder.Map))
                {
                    continue;
                }
                List <Thing> thingList = c.GetThingList(exploder.Map);
                for (int j = 0; j < thingList.Count; j++)
                {
                    Pawn pawn = thingList[j] as Pawn;
                    if (pawn != null && (int)pawn.RaceProps.intelligence >= 2 && (onlyFaction == null || pawn.Faction == onlyFaction) && damage.ExternalViolenceFor(pawn))
                    {
                        Room room2 = pawn.GetRoom();
                        if (room2 == null || room2.CellCount == 1 || (room2 == room && GenSight.LineOfSight(exploder.Position, pawn.Position, exploder.Map, skipFirstCell: true)))
                        {
                            pawn.mindState.Notify_DangerousExploderAboutToExplode(exploder);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public static IntVec3 GetFleeDestToolUser(Pawn pawn, List <Thing> threats, float distance = 23f)
        {
            IntVec3       bestPos       = pawn.Position;
            float         bestScore     = -1f;
            TraverseParms traverseParms = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);

            RegionTraverser.BreadthFirstTraverse(pawn.GetRegion(RegionType.Set_Passable), (Region from, Region reg) => reg.Allows(traverseParms, false), delegate(Region reg)
            {
                Danger danger = reg.DangerFor(pawn);
                Map map       = pawn.Map;
                foreach (IntVec3 current in reg.Cells)
                {
                    if (current.Standable(map))
                    {
                        if (!reg.IsDoorway)
                        {
                            Thing thing = null;
                            float num   = 0f;
                            for (int i = 0; i < threats.Count; i++)
                            {
                                float num2 = (float)current.DistanceToSquared(threats[i].Position);
                                if (thing == null || num2 < num)
                                {
                                    thing = threats[i];
                                    num   = num2;
                                }
                            }
                            float num3 = Mathf.Sqrt(num);
                            float f    = Mathf.Min(num3, distance);
                            float num4 = Mathf.Pow(f, 1.2f);
                            num4      *= Mathf.InverseLerp(50f, 0f, (current - pawn.Position).LengthHorizontal);
                            if (current.GetRoom(map, RegionType.Set_Passable) != thing.GetRoom(RegionType.Set_Passable))
                            {
                                num4 *= 4.2f;
                            }
                            else if (num3 < 8f)
                            {
                                num4 *= 0.05f;
                            }
                            if (!map.pawnDestinationReservationManager.CanReserve(current, pawn, false))
                            {
                                num4 *= 0.5f;
                            }
                            if (danger == Danger.Deadly)
                            {
                                num4 *= 0.8f;
                            }
                            if (num4 > bestScore)
                            {
                                bestPos   = current;
                                bestScore = num4;
                            }
                        }
                    }
                }
                return(false);
            }, 20, RegionType.Set_Passable);
            return(bestPos);
        }
            internal bool <> m__1(Region reg)
            {
                Danger danger = reg.DangerFor(this.pawn);
                Map    map    = this.pawn.Map;

                foreach (IntVec3 intVec in reg.Cells)
                {
                    if (intVec.Standable(map))
                    {
                        if (!reg.IsDoorway)
                        {
                            Thing thing = null;
                            float num   = 0f;
                            for (int i = 0; i < this.threats.Count; i++)
                            {
                                float num2 = (float)intVec.DistanceToSquared(this.threats[i].Position);
                                if (thing == null || num2 < num)
                                {
                                    thing = this.threats[i];
                                    num   = num2;
                                }
                            }
                            float num3 = Mathf.Sqrt(num);
                            float f    = Mathf.Min(num3, this.distance);
                            float num4 = Mathf.Pow(f, 1.2f);
                            num4 *= Mathf.InverseLerp(50f, 0f, (intVec - this.pawn.Position).LengthHorizontal);
                            if (intVec.GetRoom(map, RegionType.Set_Passable) != thing.GetRoom(RegionType.Set_Passable))
                            {
                                num4 *= 4.2f;
                            }
                            else if (num3 < 8f)
                            {
                                num4 *= 0.05f;
                            }
                            if (!map.pawnDestinationReservationManager.CanReserve(intVec, this.pawn, false))
                            {
                                num4 *= 0.5f;
                            }
                            if (danger == Danger.Deadly)
                            {
                                num4 *= 0.8f;
                            }
                            if (num4 > this.bestScore)
                            {
                                this.bestPos   = intVec;
                                this.bestScore = num4;
                            }
                        }
                    }
                }
                return(false);
            }
        public static RoomGroup GetRoomGroup(this Thing thing)
        {
            Room room = thing.GetRoom(RegionType.Set_All);

            return((room == null) ? null : room.Group);
        }