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);
            }
        }
        private void init()
        {
            // Reveal the starting position if home map and no pawns (landing).
            if (map.IsPlayerHome && map.mapPawns.ColonistsSpawnedCount == 0)
            {
                IntVec3 playerStartSpot = MapGenerator.PlayerStartSpot;
                ShadowCaster.computeFieldOfViewWithShadowCasting(playerStartSpot.x, playerStartSpot.z, Mathf.RoundToInt(CompFieldOfViewWatcher.NON_MECH_DEFAULT_RANGE),
                                                                 viewBlockerCells, map.Size.x, map.Size.z,
                                                                 false, null, null, null, // Directly updating known cells. No need to call incrementSeen.
                                                                 knownCells, 0, 0, mapSizeX,
                                                                 null, 0, 0, 0, 0, 0);

                for (int i = 0; i < mapCellLength; i++)
                {
                    if (knownCells[i])
                    {
                        IntVec3 cell = CellIndicesUtility.IndexToCell(i, mapSizeX);
                        foreach (Thing t in map.thingGrid.ThingsListAtFast(cell))
                        {
                            CompMainComponent compMain = (CompMainComponent)t.TryGetComp(CompMainComponent.COMP_DEF);
                            if (compMain != null && compMain.compHideFromPlayer != null)
                            {
                                compMain.compHideFromPlayer.forceSeen();
                            }
                        }
                    }
                }
            }

            // Update all thing FoV and visibility.
            foreach (Thing thing in map.listerThings.AllThings)
            {
                if (thing.Spawned)
                {
                    CompMainComponent compMain = (CompMainComponent)thing.TryGetComp(CompMainComponent.COMP_DEF);
                    if (compMain != null)
                    {
                        if (compMain.compComponentsPositionTracker != null)
                        {
                            compMain.compComponentsPositionTracker.updatePosition();
                        }
                        if (compMain.compFieldOfViewWatcher != null)
                        {
                            compMain.compFieldOfViewWatcher.updateFoV();
                        }
                        if (compMain.compHideFromPlayer != null)
                        {
                            compMain.compHideFromPlayer.updateVisibility(true);
                        }
                    }
                }
            }

            // Redraw everything.
            mapDrawer.RegenerateEverythingNow();
        }
Example #3
0
        private bool CellBoolDrawerGetBoolInt(int index)
        {
            IntVec3 intVec = CellIndicesUtility.IndexToCell(index, map.Size.x);

            if (intVec.Filled(map) || intVec.Fogged(map))
            {
                return(false);
            }
            return(FertilityAt(intVec) > 0.69f);
        }
Example #4
0
 public IntVec3 this[int index]
 {
     get
     {
         return(CellIndicesUtility.IndexToCell(grid[index], mapSizeX));
     }
     set
     {
         grid[index] = CellIndicesUtility.CellToIndex(value, mapSizeX);
     }
 }
Example #5
0
 public IntVec3 this[int x, int z]
 {
     get
     {
         int num = CellIndicesUtility.CellToIndex(x, z, mapSizeX);
         return(CellIndicesUtility.IndexToCell(grid[num], mapSizeX));
     }
     set
     {
         int num = CellIndicesUtility.CellToIndex(x, z, mapSizeX);
         grid[num] = CellIndicesUtility.CellToIndex(x, z, mapSizeX);
     }
 }
Example #6
0
 public IntVec3 this[IntVec3 c]
 {
     get
     {
         int num = CellIndicesUtility.CellToIndex(c, mapSizeX);
         return(CellIndicesUtility.IndexToCell(grid[num], mapSizeX));
     }
     set
     {
         int num = CellIndicesUtility.CellToIndex(c, mapSizeX);
         grid[num] = CellIndicesUtility.CellToIndex(value, mapSizeX);
     }
 }
Example #7
0
        private Color CellBoolDrawerGetExtraColorInt(int index)
        {
            float num = FertilityAt(CellIndicesUtility.IndexToCell(index, map.Size.x));

            if (num <= 0.95f)
            {
                return(LowFertilityColor);
            }
            if (num <= 1.1f)
            {
                return(MediumFertilityColor);
            }
            if (num >= 1.1f)
            {
                return(HighFertilityColor);
            }
            return(Color.white);
        }
Example #8
0
 public IntVec3 IndexToCell(int ind)
 {
     return(CellIndicesUtility.IndexToCell(ind, mapSizeX));
 }
        private void init()
        {
            // Retrieve map sections and store in a linear array.
            Section[,] mapDrawerSections = (Section[, ])Traverse.Create(mapDrawer).Field("sections").GetValue();
            sectionsSizeX = mapDrawerSections.GetLength(0);
            sectionsSizeY = mapDrawerSections.GetLength(1);

            sections = new Section[sectionsSizeX * sectionsSizeY];
            for (int y = 0; y < sectionsSizeY; y++)
            {
                for (int x = 0; x < sectionsSizeX; x++)
                {
                    sections[y * sectionsSizeX + x] = mapDrawerSections[x, y];
                }
            }

            // Initialize mining designators (add notifications intercepted by detours aren't fired on load).
            List <Designation> designations = map.designationManager.allDesignations;

            for (int i = 0; i < designations.Count; i++)
            {
                Designation des = designations[i];
                if (des.def == DesignationDefOf.Mine && !des.target.HasThing)
                {
                    registerMineDesignation(des);
                }
            }

            // Reveal the starting position if home map and no pawns (landing).
            if (map.IsPlayerHome && map.mapPawns.ColonistsSpawnedCount == 0)
            {
                IntVec3 playerStartSpot = MapGenerator.PlayerStartSpot;
                ShadowCaster.computeFieldOfViewWithShadowCasting(playerStartSpot.x, playerStartSpot.z, Mathf.RoundToInt(CompFieldOfViewWatcher.NON_MECH_DEFAULT_RANGE),
                                                                 viewBlockerCells, map.Size.x, map.Size.z,
                                                                 false, null, null, null, // Directly updating known cells. No need to call incrementSeen.
                                                                 knownCells, 0, 0, mapSizeX,
                                                                 null, 0, 0, 0, 0, 0);

                for (int i = 0; i < mapCellLength; i++)
                {
                    if (knownCells[i])
                    {
                        IntVec3 cell = CellIndicesUtility.IndexToCell(i, mapSizeX);
                        foreach (Thing t in map.thingGrid.ThingsListAtFast(cell))
                        {
                            CompMainComponent compMain = (CompMainComponent)t.TryGetComp(CompMainComponent.COMP_DEF);
                            if (compMain != null && compMain.compHideFromPlayer != null)
                            {
                                compMain.compHideFromPlayer.forceSeen();
                            }
                        }
                    }
                }
            }

            // Update all thing FoV and visibility.
            foreach (Thing thing in map.listerThings.AllThings)
            {
                if (thing.Spawned)
                {
                    CompMainComponent compMain = (CompMainComponent)thing.TryGetComp(CompMainComponent.COMP_DEF);
                    if (compMain != null)
                    {
                        if (compMain.compComponentsPositionTracker != null)
                        {
                            compMain.compComponentsPositionTracker.updatePosition();
                        }
                        if (compMain.compFieldOfViewWatcher != null)
                        {
                            compMain.compFieldOfViewWatcher.updateFoV();
                        }
                        if (compMain.compHideFromPlayer != null)
                        {
                            compMain.compHideFromPlayer.updateVisibility(true);
                        }
                    }
                }
            }

            // Redraw everything.
            mapDrawer.RegenerateEverythingNow();
        }
Example #10
0
        public void SpawnDynamicMinerals()
        {
            foreach (ThingDef_DynamicMineral mineralType in DefDatabase <ThingDef_DynamicMineral> .AllDefs)
            {
                //var watch = System.Diagnostics.Stopwatch.StartNew();

                // Check that the map type is ok
                if (!mineralType.CanSpawnInBiome(map))
                {
                    continue;
                }

                // Get number of positions to check
                float numToCheck = map.Area * mineralType.spawnProb * MineralsMain.Settings.mineralSpawningSetting;

                if (numToCheck <1 & Rand.Range(0f, 1f)> numToCheck)
                {
                    continue;
                }
                else
                {
                    numToCheck = 1;
                }

                //Log.Message("Trying to spawn " + mineralType.defName + " with prob of " + mineralType.spawnProb + " and " + numToCheck + " blocks");


                // Try to spawn in a subset of positions
                for (int i = 0; i < numToCheck; i++)
                {
                    // Pick a random location
//                    IntVec3 aPos = map.AllCells.RandomElement(); // too slow
                    IntVec3 aPos = CellIndicesUtility.IndexToCell(Rand.RangeInclusive(0, map.Area - 1), map.Size.x);

                    // Dont always spawn if growth rate is not good
                    if (Rand.Range(0f, 1f) > mineralType.GrowthRateAtPos(map, aPos))
                    {
                        continue;
                    }

//                    // If it is an associated ore, find a position nearby
//                    if (mineralType.PosIsAssociatedOre(map, aPos))
//                    {
//                        IntVec3 dest;
//                        if (mineralType.TryFindReproductionDestination(map, aPos, out dest))
//                        {
//                            aPos = dest;
//                        }
//                    }


                    // Try to spawn at that location
                    //Log.Message("Trying to spawn " + mineralType.defName);
                    //mineralType.TrySpawnAt(aPos, map, 0.01f);
                    mineralType.SpawnCluster(map, aPos, Rand.Range(0.01f, 0.05f), Rand.Range(mineralType.minSpawnClusterSize, mineralType.maxSpawnClusterSize));
                }

                //watch.Stop();
                //Log.Message("Spawning " + mineralType.defName + " took: " + watch.ElapsedMilliseconds);
            }
        }
Example #11
0
        public void SpawnDynamicMinerals()
        {
            foreach (ThingDef_DynamicMineral mineralType in DefDatabase <ThingDef_DynamicMineral> .AllDefs)
            {
                //var watch = System.Diagnostics.Stopwatch.StartNew();
                //Log.Message("Trying to spawn " + mineralType.defName);


                // Check that the map type is ok
                if (!mineralType.CanSpawnInBiome(map))
                {
                    continue;
                }
                //Log.Message("   Biome OK");

                // Get number of positions to check
                float perMapGrowthFactor = mineralType.GrowthRateAtMap(map);
                //Log.Message("   perMapGrowthFactor: " + perMapGrowthFactor);
                //Log.Message("   spawnProb: " + mineralType.spawnProb);
                float numToCheck = map.Area * mineralType.spawnProb * perMapGrowthFactor * MineralsMain.Settings.mineralSpawningSetting;
                if (numToCheck <= 0)
                {
                    continue;
                }

                // If less than one cell should be checked, randomly decide to check one or none
                if (numToCheck < 1)
                {
                    if (Rand.Range(0f, 1f) < numToCheck)
                    {
                        numToCheck = 1;
                    }
                    else
                    {
                        continue;
                    }
                }

                // Never check more than 1/10 of the map (performance failsafe)
                if (numToCheck > map.Area / 10)
                {
                    numToCheck = map.Area / 10;
                }

                // Round to integer
                numToCheck = (float)Math.Round(numToCheck);

                //Log.Message("   numToCheck: " + numToCheck);

                // Try to spawn in a subset of positions
                for (int i = 0; i < numToCheck; i++)
                {
                    // Pick a random location
                    IntVec3 aPos = CellIndicesUtility.IndexToCell(Rand.RangeInclusive(0, map.Area - 1), map.Size.x);

                    // Dont always spawn if growth rate is not good
                    if (Rand.Range(0f, 1f) > mineralType.GrowthRateAtPos(map, aPos, false))
                    {
                        continue;
                    }

//                    // If it is an associated ore, find a position nearby
//                    if (mineralType.PosIsAssociatedOre(map, aPos))
//                    {
//                        IntVec3 dest;
//                        if (mineralType.TryFindReproductionDestination(map, aPos, out dest))
//                        {
//                            aPos = dest;
//                        }
//                    }


                    // Try to spawn at that location
                    //Log.Message("Trying to spawn " + mineralType.defName);
                    //mineralType.TrySpawnAt(aPos, map, 0.01f);
                    mineralType.TrySpawnCluster(map, aPos, Rand.Range(0.01f, 0.05f), Rand.Range(mineralType.minSpawnClusterSize, mineralType.maxSpawnClusterSize));
                }

                //watch.Stop();
                //Log.Message("Spawning " + mineralType.defName + " took: " + watch.ElapsedMilliseconds);
            }
        }