Beispiel #1
0
        private bool IsGoodExitCell(IntVec3 cell)
        {
            if (!cell.CanBeSeenOver(map))
            {
                return(false);
            }
            int num = GenRadial.NumCellsInRadius(2f);

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = cell + GenRadial.RadialPattern[i];
                if (intVec.InBounds(map) && intVec.OnEdge(map) && intVec.CanBeSeenOverFast(map) && GenSight.LineOfSight(cell, intVec, map))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #2
0
        public static void NotifyNearbyPawnsOfDangerousExplosive(Thing exploder, DamageDef damage, Faction onlyFaction = null)
        {
            if (!damage.externalViolence)
            {
                return;
            }
            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);
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
 public IEnumerable <IntVec3> Points()
 {
     return(GenSight.PointsOnLineOfSight(source, dest));
 }
        public static bool LineOfSightToEdges(IntVec3 start, IntVec3 end, Map map, bool skipFirstCell = false, Func <IntVec3, bool> validator = null)
        {
            if (GenSight.LineOfSight(start, end, map, skipFirstCell, validator, 0, 0))
            {
                return(true);
            }
            int num = (start * 2).DistanceToSquared(end * 2);

            for (int i = 0; i < 4; i++)
            {
                if ((start * 2).DistanceToSquared(end * 2 + GenAdj.CardinalDirections[i]) <= num && GenSight.LineOfSight(start, end, map, skipFirstCell, validator, GenAdj.CardinalDirections[i].x, GenAdj.CardinalDirections[i].z))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #5
0
        public static IntVec3 FindNoWipeSpawnLocNear(IntVec3 near, Map map, ThingDef thingToSpawn, Rot4 rot, int maxDist = 2, Predicate <IntVec3> extraValidator = null)
        {
            int     num    = GenRadial.NumCellsInRadius((float)maxDist);
            IntVec3 intVec = IntVec3.Invalid;
            float   num2   = 0f;

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec2 = near + GenRadial.RadialPattern[i];
                if (intVec2.InBounds(map))
                {
                    CellRect cellRect = GenAdj.OccupiedRect(intVec2, rot, thingToSpawn.size);
                    if (cellRect.InBounds(map))
                    {
                        if (GenSight.LineOfSight(near, intVec2, map, true, null, 0, 0))
                        {
                            if (extraValidator == null || extraValidator(intVec2))
                            {
                                if (thingToSpawn.category != ThingCategory.Building || GenConstruct.CanBuildOnTerrain(thingToSpawn, intVec2, map, rot, null))
                                {
                                    bool flag  = false;
                                    bool flag2 = false;
                                    CellFinder.tmpUniqueWipedThings.Clear();
                                    CellRect.CellRectIterator iterator = cellRect.GetIterator();
                                    while (!iterator.Done())
                                    {
                                        if (iterator.Current.Impassable(map))
                                        {
                                            flag2 = true;
                                        }
                                        List <Thing> thingList = iterator.Current.GetThingList(map);
                                        for (int j = 0; j < thingList.Count; j++)
                                        {
                                            if (thingList[j] is Pawn)
                                            {
                                                flag = true;
                                            }
                                            else if (GenSpawn.SpawningWipes(thingToSpawn, thingList[j].def) && !CellFinder.tmpUniqueWipedThings.Contains(thingList[j]))
                                            {
                                                CellFinder.tmpUniqueWipedThings.Add(thingList[j]);
                                            }
                                        }
                                        iterator.MoveNext();
                                    }
                                    if (flag && thingToSpawn.passability == Traversability.Impassable)
                                    {
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                    }
                                    else if (flag2 && thingToSpawn.category == ThingCategory.Item)
                                    {
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                    }
                                    else
                                    {
                                        float num3 = 0f;
                                        for (int k = 0; k < CellFinder.tmpUniqueWipedThings.Count; k++)
                                        {
                                            if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building && !CellFinder.tmpUniqueWipedThings[k].def.costList.NullOrEmpty <ThingDefCountClass>() && CellFinder.tmpUniqueWipedThings[k].def.costStuffCount == 0)
                                            {
                                                List <ThingDefCountClass> list = CellFinder.tmpUniqueWipedThings[k].CostListAdjusted();
                                                for (int l = 0; l < list.Count; l++)
                                                {
                                                    num3 += list[l].thingDef.GetStatValueAbstract(StatDefOf.MarketValue, null) * (float)list[l].count * (float)CellFinder.tmpUniqueWipedThings[k].stackCount;
                                                }
                                            }
                                            else
                                            {
                                                num3 += CellFinder.tmpUniqueWipedThings[k].MarketValue * (float)CellFinder.tmpUniqueWipedThings[k].stackCount;
                                            }
                                            if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building || CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Item)
                                            {
                                                num3 = Mathf.Max(num3, 0.001f);
                                            }
                                        }
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                        if (!intVec.IsValid || num3 < num2)
                                        {
                                            if (num3 == 0f)
                                            {
                                                return(intVec2);
                                            }
                                            intVec = intVec2;
                                            num2   = num3;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return((!intVec.IsValid) ? near : intVec);
        }
Beispiel #6
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))
                {
                    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);
                            }
                        }
                    }
                }
            }
        }