Пример #1
0
        public static bool ThingAt(ThingGrid __instance, ref Thing __result, IntVec3 c, ThingDef def)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            if (!c.InBounds(this_map))
            {
                __result = null;
                return(false);
            }
            lock (thingGridDict[__instance][cellIndices.CellToIndex(c)])
            {
                List <Thing> thingList = thingGridDict[__instance][cellIndices.CellToIndex(c)];
                foreach (Thing t in thingList)
                {
                    if (t.def == def)
                    {
                        __result = t;
                        return(false);
                    }
                }
            }
            __result = null;
            return(false);
        }
Пример #2
0
        public static bool ThingAt(ThingGrid __instance, ref Thing __result, IntVec3 c, ThingDef def)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            if (!c.InBounds(this_map))
            {
                __result = null;
                return(false);
            }
            List <Thing> thingList = thingGrid(__instance)[cellIndices.CellToIndex(c)];
            Thing        thing;

            for (int index = 0; index < thingList.Count; index++)
            {
                try
                {
                    thing = thingList[index];
                }
                catch (ArgumentOutOfRangeException) { break; }
                if (thing.def == def)
                {
                    __result = thing;
                    return(false);
                }
            }
            __result = null;
            return(false);
        }
Пример #3
0
        public static bool ThingAt_Building_Door(ThingGrid __instance, ref Building_Door __result, IntVec3 c)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            __result = null;
            if (!c.InBounds(this_map))
            {
                __result = default(Building_Door);
                return(false);
            }
            lock (thingGridDict[__instance][cellIndices.CellToIndex(c)])
            {
                List <Thing> thingList = thingGridDict[__instance][cellIndices.CellToIndex(c)];
                foreach (Thing t in thingList)
                {
                    if (t is Building_Door obj)
                    {
                        __result = obj;
                        return(false);
                    }
                }
            }
            __result = default(Building_Door);
            return(false);
        }
        public MapComponentSeenFog(Map map) : base(map)
        {
            mapCellLength = map.cellIndices.NumGridCells;
            mapSizeX      = map.Size.x;
            mapSizeZ      = map.Size.z;

            fogGrid   = map.fogGrid;
            thingGrid = map.thingGrid;
            mapDrawer = map.mapDrawer;

            designationManager = this.map.designationManager;

            maxFactionLoadId = 0;
            foreach (Faction faction in Find.World.factionManager.AllFactionsListForReading)
            {
                maxFactionLoadId = Math.Max(maxFactionLoadId, faction.loadID);
            }
            factionsShownCells = new int[maxFactionLoadId + 1][];

            knownCells       = new bool[mapCellLength];
            viewBlockerCells = new bool[mapCellLength];

            idxToCellCache         = new IntVec3[mapCellLength];
            compHideFromPlayerGrid = new List <CompHideFromPlayer> [mapCellLength];
            compAffectVisionGrid   = new List <CompAffectVision> [mapCellLength];
            for (int i = 0; i < mapCellLength; i++)
            {
                idxToCellCache[i] = CellIndicesUtility.IndexToCell(i, mapSizeX);

                compHideFromPlayerGrid[i] = new List <CompHideFromPlayer>(16);
                compAffectVisionGrid[i]   = new List <CompAffectVision>(16);
            }
        }
Пример #5
0
        private void initMap()
        {
            if (map != parent.Map)
            {
                if (map != null && lastFaction != null)
                {
                    unseeSeenCells(lastFaction, lastFactionShownCells);
                }
                if (!disabled && mapCompSeenFog != null)
                {
                    mapCompSeenFog.fowWatchers.Remove(this);
                }
                map                   = parent.Map;
                mapCompSeenFog        = map.getMapComponentSeenFog();
                thingGrid             = map.thingGrid;
                glowGrid              = map.glowGrid;
                roofGrid              = map.roofGrid;
                weatherManager        = map.weatherManager;
                lastFactionShownCells = mapCompSeenFog.getFactionShownCells(parent.Faction);

                if (!disabled)
                {
                    mapCompSeenFog.fowWatchers.Add(this);
                }

                mapSizeX = map.Size.x;
                mapSizeZ = map.Size.z;
            }
        }
Пример #6
0
        public static bool ThingAt_Building_Door(ThingGrid __instance, ref Building_Door __result, IntVec3 c)
        {
            if (!c.InBounds(map(__instance)))
            {
                __result = null;
                return(false);
            }

            List <Thing> thingList = thingGrid(__instance)[map(__instance).cellIndices.CellToIndex(c)];
            Thing        thing;

            for (int index = 0; index < thingList.Count; index++)
            {
                try
                {
                    thing = thingList[index];
                } catch (ArgumentOutOfRangeException) { break; }
                Building_Door building_Door = thing as Building_Door;
                if (building_Door != null)
                {
                    __result = building_Door;
                    return(false);
                }
            }
            __result = null;
            return(false);
        }
Пример #7
0
        public static bool DeregisterInCell(ThingGrid __instance, Thing t, IntVec3 c)
        {
            Map this_map = map(__instance);

            if (!c.InBounds(this_map))
            {
                Log.Error(t.ToString() + " tried to de-register out of bounds at " + c, false);
                return(false);
            }

            int index = this_map.cellIndices.CellToIndex(c);

            List <Thing>[] thingGridInstance = thingGrid(__instance);
            List <Thing>   thingList         = thingGridInstance[index];

            if (thingList.Contains(t))
            {
                lock (__instance)
                {
                    thingList = thingGridInstance[index];
                    if (thingList.Contains(t))
                    {
                        List <Thing> newThingList = new List <Thing>(thingList);
                        newThingList.Remove(t);
                        thingGridInstance[index] = newThingList;
                    }
                }
            }

            return(false);
        }
Пример #8
0
        public static bool CellBeauty(ref float __result, IntVec3 c, Map map, List <Thing> countedThings = null)
        {
            float num1 = 0.0f;
            float num2 = 0.0f;
            bool  flag = false;

            if (map == null) //added
            {
                __result = 0f;
                return(false);
            }
            ThingGrid thingGrid = map.thingGrid;

            if (thingGrid == null) //added
            {
                __result = 0f;
                return(false);
            }
            List <Thing> thingList = thingGrid.ThingsListAt(c); //changed

            for (int index = 0; index < thingList.Count; ++index)
            {
                Thing thing = thingList[index];
                if (BeautyUtility.BeautyRelevant(thing.def.category))
                {
                    if (countedThings != null)
                    {
                        if (!countedThings.Contains(thing))
                        {
                            countedThings.Add(thing);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    SlotGroup slotGroup = thing.GetSlotGroup();
                    if (slotGroup == null || slotGroup.parent == thing || !slotGroup.parent.IgnoreStoredThingsBeauty)
                    {
                        float statValue = thing.GetStatValue(StatDefOf.Beauty);
                        if (thing is Filth && !map.roofGrid.Roofed(c))
                        {
                            statValue *= 0.3f;
                        }
                        if (thing.def.Fillage == FillCategory.Full)
                        {
                            flag  = true;
                            num2 += statValue;
                        }
                        else
                        {
                            num1 += statValue;
                        }
                    }
                }
            }
            __result = flag ? num2 : num1 + map.terrainGrid.TerrainAt(c).GetStatValueAbstract(StatDefOf.Beauty);
            return(false);
        }
Пример #9
0
        public static bool RegisterInCell(ThingGrid __instance, Thing t, IntVec3 c)
        {
            Map this_map = __instance.map;

            if (!c.InBounds(this_map))
            {
                Log.Warning(t.ToString() + " tried to register out of bounds at " + c + ". Destroying.");
                t.Destroy(DestroyMode.Vanish);
            }
            else
            {
                int index = this_map.cellIndices.CellToIndex(c);

                //int mapSizeX = this_map.Size.x;
                //int mapSizeZ = this_map.Size.z;

                lock (__instance)
                {
                    __instance.thingGrid[index].Add(t);
                }
                if (t.def.EverHaulable)
                {
                    HaulingCache.RegisterHaulableItem(t);
                }
                if (t is Building_PlantGrower building_PlantGrower)
                {
                    foreach (IntVec3 plantableLocation in building_PlantGrower.OccupiedRect())
                    {
                        PlantSowing_Cache.ReregisterObject(t.Map, plantableLocation, WorkGiver_Grower_Patch.awaitingPlantCellsMapDict);
                    }
                }

                /*
                 * if (!thingBillPoints.TryGetValue(t.def, out Dictionary<WorkGiver_Scanner, float> billPointsDict))
                 * {
                 *  billPointsDict = new Dictionary<WorkGiver_Scanner, float>();
                 *  thingBillPoints[t.def] = billPointsDict;
                 * }
                 * if (!mapIngredientDict.TryGetValue(this_map, out Dictionary<WorkGiver_Scanner, Dictionary<float, List<HashSet<Thing>[]>>> ingredientDict))
                 * {
                 *  ingredientDict = new Dictionary<WorkGiver_Scanner, Dictionary<float, List<HashSet<Thing>[]>>>();
                 *  mapIngredientDict[this_map] = ingredientDict;
                 * }
                 * foreach (KeyValuePair<WorkGiver_Scanner, float> billPoints in billPointsDict)
                 * {
                 *  int i = 0;
                 *  int power2;
                 *  do
                 *  {
                 *      power2 = power2array[i];
                 *      ingredientDict[billPoints.Key][billPoints.Value][i][CellToIndexCustom(c, mapSizeX, power2)].Add(t);
                 *      i++;
                 *  } while (power2 < mapSizeX || power2 < mapSizeZ);
                 * }
                 */
                //}
            }
            return(false);
        }
Пример #10
0
        public static bool ThingsListAtFast(ThingGrid __instance, ref List <Thing> __result, IntVec3 c)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            __result = thingGridDict[__instance][cellIndices.CellToIndex(c)];
            return(false);
        }
Пример #11
0
        public static List <Thing> ThingsListAt2(ThingGrid __instance, IntVec3 c)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            if (c.InBounds(this_map))
            {
                return(thingGridDict[__instance][cellIndices.CellToIndex(c)]);
            }
            Log.ErrorOnce("Got ThingsListAt out of bounds: " + c, 495287, false);
            return(EmptyThingList);
        }
Пример #12
0
        public static void Postfix_Constructor(ThingGrid __instance, Map map)
        {
            ThingGrid_Patch.map(__instance) = map;
            CellIndices cellIndices = map.cellIndices;

            List <Thing>[] thingGrid = new List <Thing> [cellIndices.NumGridCells];
            thingGridDict.Add(__instance, thingGrid);
            for (int i = 0; i < cellIndices.NumGridCells; ++i)
            {
                thingGrid[i] = new List <Thing>(4);
            }
        }
Пример #13
0
        public static bool ThingsAt(ThingGrid __instance, ref IEnumerable <Thing> __result, IntVec3 c)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            __result = null;
            if (c.InBounds(this_map))
            {
                __result = thingGridDict[__instance][cellIndices.CellToIndex(c)];
                return(false);
            }
            return(false);
        }
Пример #14
0
        public static bool ThingsListAt(ThingGrid __instance, ref List <Thing> __result, IntVec3 c)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            if (c.InBounds(this_map))
            {
                __result = thingGridDict[__instance][cellIndices.CellToIndex(c)];
                return(false);
            }
            Log.ErrorOnce("Got ThingsListAt out of bounds: " + c, 495287, false);
            __result = EmptyThingList;
            return(false);
        }
Пример #15
0
        public static bool GetThingList(ref List <Thing> __result, IntVec3 c, Map map)
        {
            __result = null;
            if (map == null)
            {
                return(false);
            }
            ThingGrid thingGrid = map.thingGrid;

            if (thingGrid == null)
            {
                return(false);
            }
            __result = thingGrid.ThingsListAt(c);
            return(false);
        }
Пример #16
0
        /*
         * public static void Postfix_Constructor(ThingGrid __instance, Map map)
         * {
         *  ThingGrid_Patch.map(__instance) = map;
         *  CellIndices cellIndices = map.cellIndices;
         *  List<Thing>[] thingGrid = new List<Thing>[cellIndices.NumGridCells];
         *  thingGridDict.Add(__instance, thingGrid);
         *  for (int i = 0; i < cellIndices.NumGridCells; ++i)
         *      thingGrid[i] = new List<Thing>(4);
         * }
         */
        public static bool RegisterInCell(ThingGrid __instance, Thing t, IntVec3 c)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            if (!c.InBounds(this_map))
            {
                Log.Warning(t.ToString() + " tried to register out of bounds at " + c + ". Destroying.", false);
                t.Destroy(DestroyMode.Vanish);
            }
            else
            {
                int index = cellIndices.CellToIndex(c);
                lock (thingGrid(__instance)[index]) {
                    thingGrid(__instance)[index].Add(t);
                }
            }
            return(false);
        }
        private void initMap()
        {
            if (map != parent.Map)
            {
                if (map != null && lastFaction != null)
                {
                    unseeSeenCells(lastFaction, lastFactionShownCells);
                }
                map                   = parent.Map;
                mapCompSeenFog        = map.getMapComponentSeenFog();
                thingGrid             = map.thingGrid;
                glowGrid              = map.glowGrid;
                roofGrid              = map.roofGrid;
                weatherManager        = map.weatherManager;
                lastFactionShownCells = mapCompSeenFog.getFactionShownCells(parent.Faction);

                mapSizeX = map.Size.x;
                mapSizeZ = map.Size.z;
            }
        }
Пример #18
0
        private static IEnumerable <Thing> ThingsAtEnumerableThing(ThingGrid __instance, IntVec3 c)
        {
            if (!c.InBounds(map(__instance)))
            {
                yield break;
            }
            List <Thing> list;

            try
            {
                list = thingGrid(__instance)[map(__instance).cellIndices.CellToIndex(c)];
            } catch (IndexOutOfRangeException) { yield break; }
            Thing thing;

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    thing = list[i];
                }
                catch (ArgumentOutOfRangeException) { break; }
                yield return(thing);
            }
        }
Пример #19
0
        public static bool DeregisterInCell(ThingGrid __instance, Thing t, IntVec3 c)
        {
            Map         this_map    = map(__instance);
            CellIndices cellIndices = this_map.cellIndices;

            if (!c.InBounds(this_map))
            {
                Log.Error(t.ToString() + " tried to de-register out of bounds at " + (object)c, false);
            }
            else
            {
                int            index     = cellIndices.CellToIndex(c);
                List <Thing>[] thingList = thingGrid(__instance);
                lock (thingList[index])
                {
                    if (!thingList[index].Contains(t))
                    {
                        return(false);
                    }
                    thingList[index].Remove(t);
                }
            }
            return(false);
        }
Пример #20
0
 public static void Deregister(ThingGrid __instance, Thing t)
 {
     Traverse.Create(__instance).Field <Map>("map").Value.GetComponent <SpaceAtmosphereMapComponent>().Deregister(t);
 }
Пример #21
0
        public static bool DeregisterInCell(ThingGrid __instance, Thing t, IntVec3 c)
        {
            Map this_map = __instance.map;

            if (!c.InBounds(this_map))
            {
                Log.Error(t.ToString() + " tried to de-register out of bounds at " + c);
                return(false);
            }

            int index = this_map.cellIndices.CellToIndex(c);

            List <Thing>[] thingGridInstance = __instance.thingGrid;
            List <Thing>   thingList         = thingGridInstance[index];
            List <Thing>   newThingList      = null;

            if (thingList.Contains(t))
            {
                bool found = false;
                lock (__instance)
                {
                    thingList = thingGridInstance[index];
                    if (thingList.Contains(t))
                    {
                        found        = true;
                        newThingList = new List <Thing>(thingList);
                        newThingList.Remove(t);
                        thingGridInstance[index] = newThingList;
                    }
                }
                if (found)
                {
                    if (t.def.EverHaulable)
                    {
                        HaulingCache.DeregisterHaulableItem(t);
                    }

                    if (c.GetZone(__instance.map) is Zone_Growing zone)
                    {
                        PlantSowing_Cache.ReregisterObject(zone.Map, c, WorkGiver_Grower_Patch.awaitingPlantCellsMapDict);
                    }

                    for (int i = newThingList.Count - 1; i >= 0; i--)
                    {
                        Thing thing2 = newThingList[i];
                        if (thing2 is Building_PlantGrower building_PlantGrower)
                        {
                            foreach (IntVec3 plantableLocation in building_PlantGrower.OccupiedRect())
                            {
                                PlantSowing_Cache.ReregisterObject(building_PlantGrower.Map, plantableLocation, WorkGiver_Grower_Patch.awaitingPlantCellsMapDict);
                            }
                        }
                    }
                }

                /*
                 * int mapSizeX = this_map.Size.x;
                 * int mapSizeZ = this_map.Size.z;
                 *
                 * if (!thingBillPoints.TryGetValue(t.def, out Dictionary<WorkGiver_Scanner, float> billPointsDict))
                 * {
                 *  billPointsDict = new Dictionary<WorkGiver_Scanner, float>();
                 *  thingBillPoints[t.def] = billPointsDict;
                 * }
                 * if (!mapIngredientDict.TryGetValue(this_map, out Dictionary<WorkGiver_Scanner, Dictionary<float, List<HashSet<Thing>[]>>> ingredientDict))
                 * {
                 *  ingredientDict = new Dictionary<WorkGiver_Scanner, Dictionary<float, List<HashSet<Thing>[]>>>();
                 *  mapIngredientDict[this_map] = ingredientDict;
                 * }
                 * foreach (KeyValuePair<WorkGiver_Scanner, float> billPoints in billPointsDict)
                 * {
                 *  int i = 0;
                 *  int power2;
                 *  do
                 *  {
                 *      power2 = power2array[i];
                 *      HashSet<Thing> newHashSet = new HashSet<Thing>(ingredientDict[billPoints.Key][billPoints.Value][i][CellToIndexCustom(c, mapSizeX, power2)]);
                 *      newHashSet.Remove(t);
                 *      ingredientDict[billPoints.Key][billPoints.Value][i][CellToIndexCustom(c, mapSizeX, power2)] = newHashSet;
                 *      i++;
                 *  } while (power2 < mapSizeX || power2 < mapSizeZ);
                 * }
                 */
                //}
                //}
            }

            return(false);
        }
Пример #22
0
 public static bool ThingsListAtFast(ThingGrid __instance, ref List <Thing> __result, int index)
 {
     __result = thingGridDict[__instance][index];
     return(false);
 }
Пример #23
0
 public static bool ThingsAt(ThingGrid __instance, ref IEnumerable <Thing> __result, IntVec3 c)
 {
     __result = ThingsAtEnumerableThing(__instance, c);
     return(false);
 }