Exemplo n.º 1
0
        protected override NVector CreateNewSpot()
        {
            int              level = Math.Max(GameMgmt.Get().data.map.standard - 1, 0); //underground
            GameMapData      gmap  = GameMgmt.Get().data.map;
            GameMapDataLevel gmdl  = GameMgmt.Get().data.map.levels[level];

            int i = 0;

            while (i < 1000)
            {
                i++;
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = gmdl.Terrain(x, y);


                if (t.MoveCost("float") == 0 || t.MoveCost("float") > 10)
                {
                    continue;                                                       // can walk?
                }
                if (!S.Unit().Free(new NVector(x, y, gmap.standard)))
                {
                    continue;                                                 //near water?
                }
                return(new NVector(x, y, level));
            }

            Debug.Log($"{level}/{gmap.levels.Count}");

            NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard);

            Debug.LogError($"Can not find a start position using {pos}");
            return(pos);
        }
Exemplo n.º 2
0
        protected virtual NVector CreateNewSpot()
        {
            GameMapData      gmap = GameMgmt.Get().data.map;
            GameMapDataLevel gmdl = GameMgmt.Get().data.map.levels[gmap.standard];

            int i = 0;

            while (i < 1000)
            {
                i++;
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = gmdl.Terrain(x, y);

                if (t.MoveCost("walk") == 0 || t.MoveCost("walk") > 10)
                {
                    continue;                                                     // can walk?
                }
                if (!gmdl.TerrainNear(x, y, "water", 2))
                {
                    continue;                                      //near water?
                }
                if (!S.Unit().Free(new NVector(x, y, gmap.standard)))
                {
                    continue;                                                 //near water?
                }
                return(new NVector(x, y, gmap.standard));
            }

            NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard);

            Debug.LogError($"Can not find a start position using {pos}");
            return(pos);
        }
Exemplo n.º 3
0
        protected virtual void CreateTile(GameMapDataLevel std, int x, int y, int layer, int[][] layerData, int height,
                                          DataTerrain invisible)
        {
            int oTerrain = std.At(new Vector3Int(x, y, layer));

            if (oTerrain == -1)
            {
                layerData[height - y - 1][x] = -1;
                return;
            }

            DataTerrain org = L.b.terrains[oTerrain];

            //has element?
            try
            {
                if (mapGeneration.terrains.ContainsKey(org.id))
                {
                    layerData[height - y - 1][x] = L.b.terrains[mapGeneration.terrains[org.id]].defaultTile;
                }
                else if (layer == 0)
                {
                    layerData[height - y - 1][x] = invisible.defaultTile;
                }
                else
                {
                    layerData[height - y - 1][x] = -1;
                }
            }
            catch (Exception e)
            {
                Debug.Log($"{y}/{height - y - 1}/{height},{x}/{GameMgmt.Get().data.map.width}");
                throw e;
            }
        }
Exemplo n.º 4
0
        public void Init(int level)
        {
            this.level = level;
            dataLevel  = GameMgmt.Get().data.map.levels[level];
            mapData    = GameMgmt.Get().data.map;

            _pathFinding       = new MapPathFinding(level);
            _winterPathFinding = new MapPathFinding(level);
        }
Exemplo n.º 5
0
        protected override void CreateTile(GameMapDataLevel std, int x, int y, int layer, int[][] layerData, int height,
                                           DataTerrain invisible)
        {
            int oTerrain = std.At(new Vector3Int(x, y, layer));

            if (oTerrain == -1 && Random.Range(0, 10) <= 7) // 70%
            {
                layerData[height - y - 1][x] = L.b.terrains["deepWall"].defaultTile;
                return;
            }

            base.CreateTile(std, x, y, layer, layerData, height, invisible);
        }
Exemplo n.º 6
0
        private void CalcGrid(Player player, string moveType)
        {
            GameMapData      gmap  = GameMgmt.Get().data.map;
            GameMapDataLevel level = GameMgmt.Get().newMap[_id].dataLevel;

            float[,] costMap = new float[gmap.width, gmap.height];

            for (int x = 0; x < gmap.width; x++)
            {
                for (int y = 0; y < gmap.height; y++)
                {
                    costMap[x, y] = L.b.modifiers[C.MoveCost].CalcModi(level.Terrain(x, y).MoveCost(moveType), player,
                                                                       new NVector(x, y, _id));// level.Terrain(x, y).MoveCost(moveType, nation);
                    //Debug.LogWarning($"Cost for {X},{Y} for {nation}-{moveType} is {costMap[x,y]}");
                }
            }

            _grids[Key(player, moveType)] = new PGrid(costMap);
        }
Exemplo n.º 7
0
        public void Generate(GameMapDataLevel gmdl)
        {
            int              height    = GameMgmt.Get().data.map.height;
            DataTerrain      invisible = L.b.terrains["invisible"];
            GameMapDataLevel std       = GameMgmt.Get().data.map.levels[GameMgmt.Get().data.map.standard];

            Debug.Log($"Generate layer {mapGeneration.Name()}:{GameMgmt.Get().data.map.width}/{height}");

            for (int layer = 0; layer < std.LayerCount(); layer++)
            {
                int[][] layerData = new int[height][];
                for (int y = 0; y < height; y++)
                {
                    layerData[height - y - 1] = new int[GameMgmt.Get().data.map.width];
                    for (int x = 0; x < GameMgmt.Get().data.map.width; x++)
                    {
                        CreateTile(std, x, y, layer, layerData, height, invisible);
                    }
                }
                gmdl.AddLayer(layerData);
            }
        }
Exemplo n.º 8
0
        // Update is called once per frame
        public IEnumerator LoadMap(DataMap map)
        {
            yield return(GameMgmt.Get().load.ShowSubMessage($"Loading Map data"));

            //read data
            GameMapData gmap = GameMgmt.Get().data.map;
            IniData     data = map.Config();

            //add level
            foreach (SectionData section in data.Sections)
            {
                GameMapDataLevel n = new GameMapDataLevel();
                n.name = section.SectionName;
                yield return(GameMgmt.Get().load.ShowSubMessage($"Reading {n.name} map data"));

                if (data[section.SectionName].ContainsKey("standard"))
                {
                    gmap.standard = gmap.levels.Count();
                }

                //add layer
                int m = Int32.Parse(data[section.SectionName]["layer"]);
                for (int i = 0; i < m; i++)
                {
                    n.AddLayer(map.Layer(data[section.SectionName]["format"], i));
                    yield return(GameMgmt.Get().load.ShowSubMessage($"Reading {n.name} map data {i}/{m}"));
                }
                gmap.levels.Add(n);
            }

            //set size
            gmap.width  = gmap.levels.First().Width();
            gmap.height = gmap.levels.First().Height();

            Debug.Log($"Load Map {map.Name()} ({gmap.width}/{gmap.height})");

            yield return(CreateLayers());
        }
Exemplo n.º 9
0
        public IEnumerator CreateMap()
        {
            //can load?
            if (GameMgmt.Get().data.map.id == null)
            {
                //TODO show error
                yield return(GameMgmt.Get().load.ShowSubMessage($"Map is missing for creation. Please restart 9 Nations"));

                yield break;
            }
            //load Map
            yield return(GameMgmt.Get().load.ShowSubMessage($"Create Map data"));

            //read data
            DataMap     map  = LSys.tem.maps[GameMgmt.Get().data.map.id];
            GameMapData gmap = GameMgmt.Get().data.map;
            IniData     data = map.Config();

            //set size
            gmap.width  = map.width;
            gmap.height = map.height;

            //add level
            foreach (SectionData section in data.Sections)
            {
                GameMapDataLevel n = new GameMapDataLevel();
                n.Init(gmap.levels.Count, section.SectionName);
                gmap.levels.Add(n);
                yield return(GameMgmt.Get().load.ShowSubMessage($"Reading {n.name} map data"));

                if (data[section.SectionName].ContainsKey("generate"))
                {
                    n.generate = data[section.SectionName]["generate"];
                    continue;
                }

                if (data[section.SectionName].ContainsKey("standard"))
                {
                    gmap.standard = gmap.levels.Count() - 1;
                }

                //add layer
                int m = Int32.Parse(data[section.SectionName]["layer"]);
                for (int i = 0; i < m; i++)
                {
                    yield return(GameMgmt.Get().load.ShowSubMessage($"Reading {n.name} map data {i}/{m}"));

                    n.AddLayer(map.Layer(data[section.SectionName]["format"], i));
                }
            }

            //check generate
            foreach (GameMapDataLevel gmdl in gmap.levels)
            {
                yield return(GameMgmt.Get().load.ShowSubMessage($"Finishing layer {gmdl.name}"));

                gmdl.FinishBuild();
            }

            Debug.Log($"Load Map {map.Name()} ({gmap.levels.Count}:{gmap.width}/{gmap.height})");

            yield return(CreateLayers());
        }