Exemplo n.º 1
0
 public static void RegenerateAvoidGridsFor(Faction faction, Map map)
 {
     if (faction.def.canUseAvoidGrid)
     {
         ByteGrid byteGrid = default(ByteGrid);
         if (faction.avoidGridsSmart.TryGetValue(map, out byteGrid))
         {
             byteGrid.Clear(0);
         }
         else
         {
             byteGrid = new ByteGrid(map);
             faction.avoidGridsSmart.Add(map, byteGrid);
         }
         ByteGrid byteGrid2 = default(ByteGrid);
         if (faction.avoidGridsBasic.TryGetValue(map, out byteGrid2))
         {
             byteGrid2.Clear(0);
         }
         else
         {
             byteGrid2 = new ByteGrid(map);
             faction.avoidGridsBasic.Add(map, byteGrid2);
         }
         AvoidGridMaker.GenerateAvoidGridInternal(byteGrid, faction, map, AvoidGridMode.Smart);
         AvoidGridMaker.GenerateAvoidGridInternal(byteGrid2, faction, map, AvoidGridMode.Basic);
     }
 }
Exemplo n.º 2
0
        private static void GenerateAvoidGridInternal(ByteGrid grid, Faction faction, Map map, AvoidGridMode mode)
        {
            List <TrapMemory> list = faction.TacticalMemory.TrapMemories();

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].map == map)
                {
                    AvoidGridMaker.PrintAvoidGridAroundTrapLoc(list[i], grid);
                }
            }
            if (mode == AvoidGridMode.Smart)
            {
                List <Building> allBuildingsColonist = map.listerBuildings.allBuildingsColonist;
                for (int j = 0; j < allBuildingsColonist.Count; j++)
                {
                    if (allBuildingsColonist[j].def.building.ai_combatDangerous)
                    {
                        Building_TurretGun building_TurretGun = allBuildingsColonist[j] as Building_TurretGun;
                        if (building_TurretGun != null)
                        {
                            AvoidGridMaker.PrintAvoidGridAroundTurret(building_TurretGun, grid);
                        }
                    }
                }
            }
            AvoidGridMaker.ExpandAvoidGridIntoEdifices(grid, map);
        }
Exemplo n.º 3
0
 public static void RegenerateAvoidGridsFor(Faction faction, Map map)
 {
     if (faction.def.canUseAvoidGrid)
     {
         Profiler.BeginSample("RegenerateAvoidGridsFor " + faction);
         ByteGrid byteGrid;
         if (faction.avoidGridsSmart.TryGetValue(map, out byteGrid))
         {
             byteGrid.Clear(0);
         }
         else
         {
             byteGrid = new ByteGrid(map);
             faction.avoidGridsSmart.Add(map, byteGrid);
         }
         ByteGrid byteGrid2;
         if (faction.avoidGridsBasic.TryGetValue(map, out byteGrid2))
         {
             byteGrid2.Clear(0);
         }
         else
         {
             byteGrid2 = new ByteGrid(map);
             faction.avoidGridsBasic.Add(map, byteGrid2);
         }
         AvoidGridMaker.GenerateAvoidGridInternal(byteGrid, faction, map, AvoidGridMode.Smart);
         AvoidGridMaker.GenerateAvoidGridInternal(byteGrid2, faction, map, AvoidGridMode.Basic);
         Profiler.EndSample();
     }
 }
 public static void Notify_CombatDangerousBuildingDespawned(Building building, Map map)
 {
     foreach (Faction faction in Find.FactionManager.AllFactions)
     {
         if (faction.HostileTo(Faction.OfPlayer) && map.mapPawns.SpawnedPawnsInFaction(faction).Count > 0)
         {
             AvoidGridMaker.RegenerateAvoidGridsFor(faction, map);
         }
     }
 }
Exemplo n.º 5
0
 internal static void Notify_CombatDangerousBuildingDespawned(Building building, Map map)
 {
     foreach (Faction current in Find.FactionManager.AllFactions)
     {
         if (current.HostileTo(Faction.OfPlayer) && map.mapPawns.SpawnedPawnsInFaction(current).Count > 0)
         {
             AvoidGridMaker.RegenerateAvoidGridsFor(current, map);
         }
     }
 }
Exemplo n.º 6
0
 public static void RegenerateAllAvoidGridsFor(Faction faction)
 {
     if (faction.def.canUseAvoidGrid)
     {
         List <Map> maps = Find.Maps;
         for (int i = 0; i < maps.Count; i++)
         {
             AvoidGridMaker.RegenerateAvoidGridsFor(faction, maps[i]);
         }
     }
 }
Exemplo n.º 7
0
        private static void PrintAvoidGridAroundTurret(Building_TurretGun tur, ByteGrid avoidGrid)
        {
            int num = GenRadial.NumCellsInRadius((float)(tur.GunCompEq.PrimaryVerb.verbProps.range + 4.0));

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = tur.Position + GenRadial.RadialPattern[i];
                if (intVec.InBounds(tur.Map) && intVec.Walkable(tur.Map) && GenSight.LineOfSight(intVec, tur.Position, tur.Map, true, null, 0, 0))
                {
                    AvoidGridMaker.IncrementAvoidGrid(avoidGrid, intVec, 12);
                }
            }
        }
Exemplo n.º 8
0
 public static void RegenerateAllAvoidGridsFor(Faction faction)
 {
     if (faction.def.canUseAvoidGrid)
     {
         Profiler.BeginSample("RegenerateAllAvoidGridsFor " + faction);
         List <Map> maps = Find.Maps;
         for (int i = 0; i < maps.Count; i++)
         {
             AvoidGridMaker.RegenerateAvoidGridsFor(faction, maps[i]);
         }
         Profiler.EndSample();
     }
 }
        private static void PrintAvoidGridAroundTrapLoc(Building b, ByteGrid avoidGrid)
        {
            Room room = b.Position.GetRoom(b.Map, RegionType.Set_Passable);

            for (int i = 0; i < AvoidGridMaker.TrapRadialCells; i++)
            {
                IntVec3 intVec = b.Position + GenRadial.RadialPattern[i];
                if (intVec.InBounds(b.Map) && intVec.Walkable(b.Map) && intVec.GetRoom(b.Map, RegionType.Set_Passable) == room)
                {
                    float num  = (float)Mathf.Max(1, intVec.DistanceToSquared(b.Position));
                    int   num2 = Mathf.Max(1, Mathf.RoundToInt(80f / num));
                    AvoidGridMaker.IncrementAvoidGrid(avoidGrid, intVec, num2);
                }
            }
        }
Exemplo n.º 10
0
        private static void PrintAvoidGridAroundTrapLoc(TrapMemory mem, ByteGrid avoidGrid)
        {
            Room room = mem.Cell.GetRoom(mem.map, RegionType.Set_Passable);

            for (int i = 0; i < AvoidGridMaker.TrapRadialCells; i++)
            {
                IntVec3 intVec = mem.Cell + GenRadial.RadialPattern[i];
                if (intVec.InBounds(mem.map) && intVec.Walkable(mem.map) && intVec.GetRoom(mem.map, RegionType.Set_Passable) == room)
                {
                    float num  = (float)Mathf.Max(1, intVec.DistanceToSquared(mem.Cell));
                    int   num2 = Mathf.Max(1, Mathf.RoundToInt((float)(32.0 * mem.PowerPercent / num)));
                    AvoidGridMaker.IncrementAvoidGrid(avoidGrid, intVec, num2);
                }
            }
        }
        private static void PrintAvoidGridAroundTurret(Building_TurretGun tur, ByteGrid avoidGrid)
        {
            float range = tur.GunCompEq.PrimaryVerb.verbProps.range;
            float num   = tur.GunCompEq.PrimaryVerb.verbProps.EffectiveMinRange(true);
            int   num2  = GenRadial.NumCellsInRadius(range + 4f);
            int   num3  = (num >= 1f) ? GenRadial.NumCellsInRadius(num) : 0;

            for (int i = num3; i < num2; i++)
            {
                IntVec3 intVec = tur.Position + GenRadial.RadialPattern[i];
                if (intVec.InBounds(tur.Map) && intVec.Walkable(tur.Map) && GenSight.LineOfSight(intVec, tur.Position, tur.Map, true, null, 0, 0))
                {
                    AvoidGridMaker.IncrementAvoidGrid(avoidGrid, intVec, 45);
                }
            }
        }
        public static void RegenerateAvoidGridsFor(Faction faction, Map map)
        {
            if (!faction.def.canUseAvoidGrid)
            {
                return;
            }
            ByteGrid byteGrid;

            if (faction.avoidGridsSmart.TryGetValue(map, out byteGrid))
            {
                byteGrid.Clear(0);
            }
            else
            {
                byteGrid = new ByteGrid(map);
                faction.avoidGridsSmart.Add(map, byteGrid);
            }
            AvoidGridMaker.GenerateAvoidGridInternal(byteGrid, faction, map, AvoidGridMode.Smart);
        }
        private static void GenerateAvoidGridInternal(ByteGrid grid, Faction faction, Map map, AvoidGridMode mode)
        {
            List <Building> allBuildingsColonist = map.listerBuildings.allBuildingsColonist;

            if (mode == AvoidGridMode.Smart)
            {
                for (int i = 0; i < allBuildingsColonist.Count; i++)
                {
                    if (Rand.Chance(0.5f) && allBuildingsColonist[i].def.building.isTrap)
                    {
                        AvoidGridMaker.PrintAvoidGridAroundTrapLoc(allBuildingsColonist[i], grid);
                    }
                    if (allBuildingsColonist[i].def.building.ai_combatDangerous)
                    {
                        Building_TurretGun building_TurretGun = allBuildingsColonist[i] as Building_TurretGun;
                        if (building_TurretGun != null)
                        {
                            AvoidGridMaker.PrintAvoidGridAroundTurret(building_TurretGun, grid);
                        }
                    }
                }
            }
            AvoidGridMaker.ExpandAvoidGridIntoEdifices(grid, map);
        }