Example #1
0
        private void GenerateMap(bool fromScratch)
        {
            //Run the various generators.
            int seed   = Settings.Seed.GetHashCode();
            var biomes = Settings.Biome.Generate(Settings.Size, Settings.Size,
                                                 NThreads, unchecked (seed * 462315));
            var deposits = Settings.Deposits.Generate(Settings.Size, Settings.Size,
                                                      NThreads, unchecked (seed * 123));
            var rooms      = Settings.Rooms.Generate(biomes, NThreads, seed);
            var finalWalls = Settings.CA.Generate(biomes, rooms, NThreads, unchecked (seed * 3468));

            //Convert the generated data to actual game tiles.
            GameLogic.TileTypes[,] tiles = new GameLogic.TileTypes[Settings.Size, Settings.Size];
            foreach (Vector2i tilePos in tiles.AllIndices())
            {
                if (tilePos.x == 0 || tilePos.x == Settings.Size - 1 ||
                    tilePos.y == 0 || tilePos.y == Settings.Size - 1)
                {
                    tiles.Set(tilePos, GameLogic.TileTypes.Bedrock);
                }
                else if (finalWalls.Get(tilePos))
                {
                    tiles.Set(tilePos,
                              deposits.Get(tilePos) ?
                              GameLogic.TileTypes.Deposit :
                              GameLogic.TileTypes.Wall);
                }
                else
                {
                    tiles.Set(tilePos, GameLogic.TileTypes.Empty);
                }
            }
            Map.Tiles.Reset(tiles);

            //Generate units.
            var newUnits = Settings.PlayerChars.Generate(
                Map, Settings, rooms, NThreads, unchecked (seed * 135789),
                (fromScratch ? null : Progress.ExitedUnitIDs));

            Progress.ExitedUnitIDs.Clear();

            mapGameCoroutine = StartCoroutine(Map.RunGameCoroutine());

            //Make the camera focus in on the units.
            switch (Options.ViewMode)
            {
            case ViewModes.TwoD:
                Rendering.TwoD.Content2D.Instance.ZoomToSee(newUnits);
                break;

            case ViewModes.ThreeD: throw new NotImplementedException();

            default: throw new NotImplementedException(Options.ViewMode.ToString());
            }

            SaveWorld();
        }
 public void Callback_TileChanged(GameLogic.TileGrid tiles, Vector2i pos,
                                  GameLogic.TileTypes oldType, GameLogic.TileTypes newType)
 {
     if (currentChoice.Contains(pos) && !Target.IsTileValid(pos))
     {
         currentChoice.Remove(pos);
         canConfirm = !Target.MustBeConnected || IsFullyConnected();
     }
 }