コード例 #1
0
ファイル: GenExplosion.cs プロジェクト: KraigXu/GameProject
        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);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static void NotifyNearbyPawnsOfDangerousExplosive(Thing exploder, DamageDef damage, Faction onlyFaction = null)
        {
            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) && damage.ExternalViolenceFor(pawn))
                        {
                            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);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        private bool IsGoodExitCell(IntVec3 cell)
        {
            bool result;

            if (!cell.CanBeSeenOver(this.map))
            {
                result = false;
            }
            else
            {
                int num = GenRadial.NumCellsInRadius(2f);
                for (int i = 0; i < num; i++)
                {
                    IntVec3 intVec = cell + GenRadial.RadialPattern[i];
                    if (intVec.InBounds(this.map) && intVec.OnEdge(this.map) && intVec.CanBeSeenOverFast(this.map) && GenSight.LineOfSight(cell, intVec, this.map, false, null, 0, 0))
                    {
                        return(true);
                    }
                }
                result = false;
            }
            return(result);
        }
コード例 #4
0
        public static IntVec3 FindNoWipeSpawnLocNear(IntVec3 near, Map map, ThingDef thingToSpawn, Rot4 rot, int maxDist = 2, Predicate <IntVec3> extraValidator = null)
        {
            int     num    = GenRadial.NumCellsInRadius(maxDist);
            IntVec3 result = IntVec3.Invalid;
            float   num2   = 0f;

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = near + GenRadial.RadialPattern[i];
                if (!intVec.InBounds(map))
                {
                    continue;
                }
                CellRect cellRect = GenAdj.OccupiedRect(intVec, rot, thingToSpawn.size);
                if (!cellRect.InBounds(map) || !GenSight.LineOfSight(near, intVec, map, skipFirstCell: true) || (extraValidator != null && !extraValidator(intVec)) || (thingToSpawn.category == ThingCategory.Building && !GenConstruct.CanBuildOnTerrain(thingToSpawn, intVec, map, rot)))
                {
                    continue;
                }
                bool flag  = false;
                bool flag2 = false;
                tmpUniqueWipedThings.Clear();
                foreach (IntVec3 item in cellRect)
                {
                    if (item.Impassable(map))
                    {
                        flag2 = true;
                    }
                    List <Thing> thingList = item.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) && !tmpUniqueWipedThings.Contains(thingList[j]))
                        {
                            tmpUniqueWipedThings.Add(thingList[j]);
                        }
                    }
                }
                if (flag && thingToSpawn.passability == Traversability.Impassable)
                {
                    tmpUniqueWipedThings.Clear();
                    continue;
                }
                if (flag2 && thingToSpawn.category == ThingCategory.Item)
                {
                    tmpUniqueWipedThings.Clear();
                    continue;
                }
                float num3 = 0f;
                for (int k = 0; k < tmpUniqueWipedThings.Count; k++)
                {
                    if (tmpUniqueWipedThings[k].def.category == ThingCategory.Building && !tmpUniqueWipedThings[k].def.costList.NullOrEmpty() && tmpUniqueWipedThings[k].def.costStuffCount == 0)
                    {
                        List <ThingDefCountClass> list = tmpUniqueWipedThings[k].CostListAdjusted();
                        for (int l = 0; l < list.Count; l++)
                        {
                            num3 += list[l].thingDef.GetStatValueAbstract(StatDefOf.MarketValue) * (float)list[l].count * (float)tmpUniqueWipedThings[k].stackCount;
                        }
                    }
                    else
                    {
                        num3 += tmpUniqueWipedThings[k].MarketValue * (float)tmpUniqueWipedThings[k].stackCount;
                    }
                    if (tmpUniqueWipedThings[k].def.category == ThingCategory.Building || tmpUniqueWipedThings[k].def.category == ThingCategory.Item)
                    {
                        num3 = Mathf.Max(num3, 0.001f);
                    }
                }
                tmpUniqueWipedThings.Clear();
                if (!result.IsValid || num3 < num2)
                {
                    if (num3 == 0f)
                    {
                        return(intVec);
                    }
                    result = intVec;
                    num2   = num3;
                }
            }
            if (!result.IsValid)
            {
                return(near);
            }
            return(result);
        }
コード例 #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);
        }
コード例 #6
0
ファイル: ExitMapGrid.cs プロジェクト: potsh/RimWorld
        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);
        }
コード例 #7
0
        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);
        }