Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        /// <summary>
        /// Get a start position or an exception
        /// </summary>
        /// <param name="nation"></param>
        /// <returns></returns>
        /// <exception cref="System.MissingMemberException"></exception>
        public NVector GetStartPos(string nation)
        {
            GameMapData gmap = GameMgmt.Get().data.map;

            Nation n = L.b.nations[nation];
            int    i = 0;

            while (i < 1000)
            {
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = _map.Terrain(new NVector(x, y, gmap.standard));

                //right terrain?
                //TODO  && t.visible > 0
                if (t.id == n.Terrain || (t.MoveCost("walk") > 0 && t.MoveCost("walk") <= 10))
                {
                    //has a unit?
                    if (S.Unit().Free(new NVector(x, y, gmap.standard)))
                    {
                        //TODO find right spot with level support
                        return(new NVector(x, y, gmap.standard));
                    }
                }

                i++;
            }

            Debug.Log($"{gmap.standard}/{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 for {nation} using {pos}");
            return(pos);
        }
Beispiel #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);
        }
    // Use this for initialization
    void Awake()
    {
        if (Instance != null)
        {
            Instance = null;
        }

        Instance = this;
    }
Beispiel #6
0
        private IEnumerator CreateLayers()
        {
            GameMapData gmap = GameMgmt.Get().data.map;

            //load layer
            levels = new List <GameMapLevel>();
            for (int i = 0; i < gmap.levels.Count; i++)
            {
                GameMapLevel g = CreateNewLevel(gmap.levels[i].name, i);
                yield return(g.AddLayers());
            }
            view.Init();
        }
Beispiel #7
0
        public void repointNextMap(GameMapData mapData, MapPointer nextMapPointer)
        {
            int mapAddressToRepoint;

            mapAddressToRepoint = getEntityDataOffset(mapData) + spaceCalculator.getUsedSpaceEntities(mapData.entities) + 1;
            //Plus 1 for 0xFF room ending byte

            if (mapData.map == 0xFF && LAGame.dungeon != 0xFF || (LAGame.map == 0x15 && LAGame.dungeon == 0xFF))
            {
                mapAddressToRepoint = getEntityDataOffset(mapData);
            }


            if (LAGame.overworldFlag)
            {
                if (mapAddressToRepoint >= 0x59663)
                {
                    mapAddressToRepoint = 0x59661;
                }
            }
            else
            {
                if (LAGame.dungeon == 0xFF && mapAddressToRepoint >= 0x596FF)
                {
                    mapAddressToRepoint = 0x596FD;
                }
                else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && mapAddressToRepoint >= 0x59185 && LAGame.dungeon != 0xFF)
                {
                    mapAddressToRepoint = 0x59183;
                }
                else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && mapAddressToRepoint >= 0x58CA3 && LAGame.dungeon != 0xFF)
                {
                    mapAddressToRepoint = 0x58CA1;
                }
            }


            if (nextMapPointer != null)
            {
                nextMapPointer.mapAddress = mapAddressToRepoint;
            }
            else
            {
                nextMapPointer            = new MapPointer();
                nextMapPointer.mapAddress = mapAddressToRepoint;
                nextMapPointer.map        = mapData.map;
            }

            repointMapEntities(nextMapPointer);
        }
Beispiel #8
0
        public GameMapData GetMapData()
        {
            GameMapData data = new GameMapData(Width, Height);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int tile = tilemap.GetTile(x, y) == floorBrush ? 0 : 1;

                    data.Set(x, y, tile);
                }
            }

            return(data);
        }
        public GameMapData GetGameMapData()
        {
            var data = new GameMapData(Width, Height);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int tileIndex = floor[x, y] ? 0 : 1; //TODO: add proper indices and tilesets.

                    data.Set(x, y, tileIndex);
                }
            }

            return(data);
        }
        private int getCollisionDataOverworldOffset(GameMapData mapData)
        {
            int i = -1;
            int secondhalf;

            if (mapData.specialFlag)
            {
                switch (mapData.map)
                {
                case 0x06: i = 0x31F4; break;

                case 0x0E: i = 0x31C4; break;

                case 0x1B: i = 0x3204; break;

                case 0x2B: i = 0x3214; break;

                case 0x79: i = 0x31E4; break;

                case 0x8C: i = 0x31D4; break;
                }
            }
            if (i > 0)
            {
                secondhalf = LAGame.gbROM.Get2BytePointerAtAddress(i);
                if (mapData.map > 0x7F)
                {
                    secondhalf += 0x68000;
                }
                else
                {
                    secondhalf += 0x24000;
                }
                LAGame.gbROM.BufferLocation = secondhalf;
            }
            else
            {
                secondhalf = 0x24000 + (mapData.map * 2);
                secondhalf = LAGame.gbROM.Get2BytePointerAtAddress(secondhalf);
                if (mapData.map > 0x7F)
                {
                    secondhalf = 0x68000 + (secondhalf - 0x24000);
                }
                LAGame.gbROM.BufferLocation = secondhalf;
            }
            return(LAGame.gbROM.BufferLocation);
        }
Beispiel #11
0
        private int getEntityListForRewriteAndIndex()
        {
            gameMapData = new List <GameMapData>();
            int index = 0;

            if (LAGame.dungeon == 0xFF)
            {
                for (int map = 0; map < 0x16; map++)
                {
                    GameMapData gameData = new GameMapData();
                    gameData = LoadEntityData(map);

                    if (map == LAGame.map)
                    {
                        gameData.entities = entityLoader.entities;
                    }
                    gameMapData.Add(gameData);

                    if (map == LAGame.map)
                    {
                        index = gameMapData.IndexOf(gameData);
                    }
                }
            }
            else
            {
                for (int map = 0; map < 256; map++)
                {
                    GameMapData gameData = new GameMapData();
                    gameData = LoadEntityData(map);

                    if (map == LAGame.map)
                    {
                        gameData.entities = entityLoader.entities;
                    }

                    gameMapData.Add(gameData);

                    if (map == LAGame.map)
                    {
                        index = gameMapData.IndexOf(gameData);
                    }
                }
            }
            return(index);
        }
Beispiel #12
0
 private int getEntityDataOffset(GameMapData mapData)
 {
     if (LAGame.overworldFlag)
     {
         LAGame.gbROM.BufferLocation = 0x58000 + mapData.map * 2;
     }
     else
     {
         LAGame.gbROM.BufferLocation = 0x58200 + mapData.map * 2;;
         if (LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A)
         {
             LAGame.gbROM.BufferLocation = 0x58400 + mapData.map * 2;
         }
         else if (LAGame.dungeon == 0xFF)
         {
             LAGame.gbROM.BufferLocation = 0x58600 + mapData.map * 2;
         }
     }
     LAGame.gbROM.BufferLocation = LAGame.gbROM.Get2BytePointerAtAddress(LAGame.gbROM.BufferLocation);
     return(LAGame.gbROM.BufferLocation);
 }
 private int getCollisionDataDungeonOffset(GameMapData mapData)
 {
     if ((mapData.specialFlag && mapData.map == 0xF5 && LAGame.dungeon >= 0x1A) || mapData.specialFlag && mapData.map == 0xF5 && LAGame.dungeon < 6)
     {
         LAGame.gbROM.BufferLocation  = LAGame.gbROM.Get2BytePointerAtAddress(0x3198);
         LAGame.gbROM.BufferLocation += 0x28000;
     }
     else
     {
         LAGame.gbROM.BufferLocation = 0x28000;
         if (LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A)
         {
             LAGame.gbROM.BufferLocation += 0x4000;
         }
         else if (LAGame.dungeon == 0xFF)
         {
             LAGame.gbROM.BufferLocation = 0x2BB77;
         }
         LAGame.gbROM.BufferLocation = LAGame.gbROM.Get2BytePointerAtAddress(LAGame.gbROM.BufferLocation + (mapData.map * 2));
     }
     return(LAGame.gbROM.BufferLocation);
 }
Beispiel #14
0
        public void CreateMap(GameMapData data)
        {
            size = new Vector2Int(data.Width, data.Height);

            tilemap.Resize(size.x, size.y);

            tiles         = new Tile[size.x, size.y];
            visibilityMap = new VisibilityMap(size.x, size.y);

            DestroyEntites();
            entityMap = new EntityMap(size.x, size.y);

            fovMaterial.SetVector("_FogSize", new Vector4(Width * TileSize, Height * TileSize, 0, 0));
            fovMaterial.SetTexture("_FogMapA", visibilityMap.texturePrev);
            fovMaterial.SetTexture("_FogMapB", visibilityMap.textureCur);

            //create tiles
            for (int x = 0; x < size.x; x++)
            {
                for (int y = 0; y < size.y; y++)
                {
                    var brush = data.Get(x, y) == 0 ? floorBrush : wallBrush;

                    tilemap.SetTile(x, y, brush);
                }
            }

            for (int x = 0; x < size.x; x++)
            {
                for (int y = 0; y < size.y; y++)
                {
                    tiles[x, y] = tilemap.GetTileInstance(x, y).GetComponent <Tile>();
                }
            }

            pathfindingNodes = new TileGridNodes(this);

            RecalulatePathfinding();
        }
Beispiel #15
0
    protected override void OnInstanceInit()
    {
        mMapData = GetComponent <GameMapData>();
        if (mMapData == null)
        {
            Debug.LogError("GameMapData not found!");
            return;
        }

        //setup current palette
        for (int i = 0; i < mapData.initialPalette.Length; i++)
        {
            var paletteItem = mapData.initialPalette[i];

            if (paletteItem.amount > 0)
            {
                mBlockPalette.Add(paletteItem.blockName, paletteItem.amount);
            }

            //generate pool
            var blockInfo = GameData.instance.GetBlockInfo(paletteItem.blockName);
            if (blockInfo != null)
            {
                int poolCapacity = paletteItem.amount + paletteItem.capacityAdd;
                if (poolCapacity <= 0)
                {
                    poolCapacity = mapData.paletteDefaultPoolCapacity;
                }

                blockInfo.GeneratePool(transform, poolCapacity, poolCapacity);
            }
            else
            {
                Debug.LogWarning("Block does not exists: " + paletteItem.blockName);
            }
        }
    }
Beispiel #16
0
        private GameMapData LoadEntityData(int map)
        {
            GameMapData mapData = new GameMapData();

            mapData.map = map;

            getEntityDataOffset(mapData);

            byte b;

            while ((b = LAGame.gbROM.ReadByte()) != 0xFF) //0xFF = End of room
            {
                Entity ent = new Entity(LAGame);          // 2-Byte tiles
                ent.yPos = (byte)(b >> 4);
                ent.xPos = (byte)(b & 0xF);
                ent.id   = LAGame.gbROM.ReadByte();
                int temp = LAGame.gbROM.BufferLocation;
                ent.loadSprite();
                LAGame.gbROM.BufferLocation = temp;
                mapData.entities.Add(ent);
            }

            return(mapData);
        }
        private GameMapData LoadCollisionDataOverworld(int map, bool specialFlag)
        {
            CollisionObject overworldObjects = new CollisionObject();
            GameMapData     mapData          = new GameMapData();

            mapData.map         = map;
            mapData.specialFlag = specialFlag;

            //Sets the buffer address
            LAGame.gbROM.BufferLocation = getCollisionDataOverworldOffset(mapData);
            mapData.animation           = LAGame.gbROM.ReadByte();
            mapData.tilePreset          = LAGame.gbROM.ReadByte();

            byte b;

            while ((b = LAGame.gbROM.ReadByte()) != 0xFE) //0xFE = End of room
            {
                if (map < 0x80 && LAGame.gbROM.BufferLocation >= 0x2668D)
                {
                    break;
                }
                if (map > 0x7F && LAGame.gbROM.BufferLocation >= 0x69E75)
                {
                    break;
                }

                //Check to see if we are reading empty space
                if (b == 0)
                {
                    //We need a 00 00 pair for it to be empty space. Otherwise it could just be an object in XY position 0.
                    byte x = LAGame.gbROM.ReadByte();
                    if (x == 0)
                    {
                        continue;
                    }
                    else
                    {
                        LAGame.gbROM.BufferLocation--;
                    }
                }

                if (b >> 4 == 0xE)
                {
                    if (map < 0x80 && LAGame.gbROM.BufferLocation + 4 > 0x2668D)
                    {
                        continue;
                    }
                    if (map > 0x7F && LAGame.gbROM.BufferLocation + 4 > 0x69E75)
                    {
                        continue;
                    }

                    Warps w = new Warps();
                    w.type   = (byte)(b & 0x0F);
                    w.region = LAGame.gbROM.ReadByte();
                    w.map    = LAGame.gbROM.ReadByte();
                    w.x      = LAGame.gbROM.ReadByte();
                    w.y      = LAGame.gbROM.ReadByte();
                    mapData.warpObjects.Add(w);
                    continue;
                }
                if (b >> 4 == 8 || b >> 4 == 0xC) //3-Byte objects
                {
                    if (map < 0x80 && LAGame.gbROM.BufferLocation + 2 > 0x2668D)
                    {
                        continue;
                    }
                    if (map > 0x7F && LAGame.gbROM.BufferLocation + 2 > 0x69E75)
                    {
                        continue;
                    }

                    CollisionObject o = new CollisionObject();
                    o.is3Byte   = true;
                    o.length    = (byte)(b & 0xF);
                    o.direction = (byte)(b >> 4);
                    byte b2 = LAGame.gbROM.ReadByte();
                    o.yPos = (byte)(b2 >> 4);
                    o.xPos = (byte)(b2 & 0xF);
                    o.id   = LAGame.gbROM.ReadByte();
                    overworldObjects.getOverworldObjs(o);
                    //mapData.collisionObjects.Add(o);
                    continue;
                }
                else
                {
                    if (map < 0x80 && LAGame.gbROM.BufferLocation + 1 > 0x2668D)
                    {
                        continue;
                    }
                    if (map > 0x7F && LAGame.gbROM.BufferLocation + 1 > 0x69E75)
                    {
                        continue;
                    }

                    CollisionObject o = new CollisionObject(); // 2-Byte objects
                    o.yPos = (byte)(b >> 4);
                    o.xPos = (byte)(b & 0xF);
                    o.id   = LAGame.gbROM.ReadByte();
                    overworldObjects.getOverworldObjs(o);
                    //mapData.collisionObjects.Add(o);
                    continue;
                }
            }

            foreach (CollisionObject obj in overworldObjects.objectIDs)
            {
                mapData.collisionObjects.Add(obj);
            }

            return(mapData);
        }
        private int getCollisionListForRewriteAndIndex()
        {
            gameMapData = new List <GameMapData>();
            int index = 0;

            if (LAGame.dungeon == 0xFF)
            {
                for (int map = 0; map < 0x16; map++)
                {
                    GameMapData gameData = new GameMapData();
                    gameData = LoadCollisionDataDungeon(map, false);

                    if (map == LAGame.map && !LAGame.specialFlag)
                    {
                        gameData.collisionObjects = mapTileData.collisionObjects;
                        gameData.warpObjects      = mapTileData.warpObjects;
                    }
                    gameMapData.Add(gameData);

                    if (map == LAGame.map && !LAGame.specialFlag)
                    {
                        index = gameMapData.IndexOf(gameData);
                    }
                }
            }
            else
            {
                for (int map = 0; map < 256; map++)
                {
                    GameMapData gameData = new GameMapData();
                    if (LAGame.overworldFlag)
                    {
                        gameData = LoadCollisionDataOverworld(map, false);
                    }
                    else
                    {
                        gameData = LoadCollisionDataDungeon(map, false);
                    }

                    if (map == LAGame.map && !LAGame.specialFlag)
                    {
                        gameData.collisionObjects = mapTileData.collisionObjects;
                        gameData.warpObjects      = mapTileData.warpObjects;
                    }
                    gameMapData.Add(gameData);

                    if (map == LAGame.map && !LAGame.specialFlag)
                    {
                        index = gameMapData.IndexOf(gameData);
                    }

                    if (LAGame.overworldFlag)
                    {
                        switch (map)
                        {
                        case 0x06:
                        case 0x0E:
                        case 0x1B:
                        case 0x2B:
                        case 0x79:
                        case 0x8C:
                            gameData             = new GameMapData();
                            gameData             = LoadCollisionDataOverworld(map, true);
                            gameData.specialFlag = true;

                            if (map == LAGame.map && LAGame.specialFlag)
                            {
                                gameData.collisionObjects = mapTileData.collisionObjects;
                                gameData.warpObjects      = mapTileData.warpObjects;
                            }

                            gameMapData.Add(gameData);

                            if (map == LAGame.map && LAGame.specialFlag)
                            {
                                index = gameMapData.IndexOf(gameData);
                            }

                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        if (LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A)
                        {
                            switch (map)
                            {
                            case 0xF5:
                                gameData             = new GameMapData();
                                gameData             = LoadCollisionDataDungeon(map, true);
                                gameData.specialFlag = true;

                                if (map == LAGame.map && LAGame.specialFlag)
                                {
                                    gameData.collisionObjects = mapTileData.collisionObjects;
                                    gameData.warpObjects      = mapTileData.warpObjects;
                                }

                                gameMapData.Add(gameData);

                                if (map == LAGame.map && LAGame.specialFlag)
                                {
                                    index = gameMapData.IndexOf(gameData);
                                }

                                break;
                            }
                        }
                    }
                }
            }
            return(index);
        }
        public void saveCollisionDungeonData(GameMapData mapData)
        {
            byte b;
            bool outofbounds = false;

            LAGame.gbROM.BufferLocation = getCollisionDataDungeonOffset(mapData);

            if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation >= 0x2BF43)
            {
                LAGame.gbROM.BufferLocation = 0x2BF41;
                outofbounds = true;
            }
            else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation >= 0x2FFFF)
            {
                LAGame.gbROM.BufferLocation = 0x2FFFD;
                outofbounds = true;
            }
            else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation >= 0x2BB77 && LAGame.dungeon != 0xFF)
            {
                LAGame.gbROM.BufferLocation = 0x2BB75;
                outofbounds = true;
            }


            LAGame.gbROM.WriteByte(mapData.animation);
            LAGame.gbROM.WriteByte(mapData.tilePreset);

            if (outofbounds)
            {
                LAGame.gbROM.WriteByte(0xFE);
                return;
            }

            foreach (CollisionObject obj in mapData.collisionObjects)
            {
                int objectSize;

                if (obj.is3Byte)
                {
                    objectSize = 3;
                }
                else
                {
                    objectSize = 2;
                }

                if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation + objectSize >= 0x2BF43)
                {
                    LAGame.gbROM.WriteByte(0xFE);
                    return;
                }
                else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation + objectSize >= 0x2FFFF)
                {
                    LAGame.gbROM.WriteByte(0xFE);
                    return;
                }
                else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation + objectSize >= 0x2BB77 && LAGame.dungeon != 0xFF)
                {
                    LAGame.gbROM.WriteByte(0xFE);
                    return;
                }


                if (obj.is3Byte)
                {
                    if (obj.direction == 8)
                    {
                        b = (byte)(0x80 + obj.length);
                        LAGame.gbROM.WriteByte(b);
                    }
                    else
                    {
                        b = (byte)(0xC0 + obj.length);
                        LAGame.gbROM.WriteByte(b);
                    }
                    b = (byte)((obj.yPos * 0x10) + obj.xPos);
                    LAGame.gbROM.WriteByte(b);
                    LAGame.gbROM.WriteByte(obj.id);
                }
                else
                {
                    b = (byte)((obj.yPos * 0x10) + obj.xPos);
                    LAGame.gbROM.WriteByte(b);
                    LAGame.gbROM.WriteByte(obj.id);
                }
            }
            if (mapData.warpObjects.Count != 0)
            {
                foreach (Warps warp in mapData.warpObjects)
                {
                    int objectSize = 5;

                    if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation + objectSize >= 0x2BF43)
                    {
                        LAGame.gbROM.WriteByte(0xFE);
                        return;
                    }
                    else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation + objectSize >= 0x2FFFF)
                    {
                        LAGame.gbROM.WriteByte(0xFE);
                        return;
                    }
                    else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation + objectSize >= 0x2BB77 && LAGame.dungeon != 0xFF)
                    {
                        LAGame.gbROM.WriteByte(0xFE);
                        return;
                    }

                    b = (byte)(0xE0 + warp.type);
                    LAGame.gbROM.WriteByte(b);
                    LAGame.gbROM.WriteByte(warp.region);
                    LAGame.gbROM.WriteByte(warp.map);
                    LAGame.gbROM.WriteByte(warp.x);
                    LAGame.gbROM.WriteByte(warp.y);
                }
            }

            LAGame.gbROM.WriteByte(0xFE);
        }
        public void saveCollisionOverworldData(GameMapData mapData)
        {
            byte b;
            bool outofbounds = false;

            LAGame.gbROM.BufferLocation = getCollisionDataOverworldOffset(mapData);

            if (mapData.map >= 0x80 && mapData.map <= 0xFF)
            {
                if (LAGame.gbROM.BufferLocation > 0x69E73)
                {
                    LAGame.gbROM.BufferLocation = 0x69E71;
                    outofbounds = true;
                }
            }
            else if (mapData.map <= 0x7F)
            {
                if (LAGame.gbROM.BufferLocation > 0x2668B)
                {
                    LAGame.gbROM.BufferLocation = 0x26689;
                    outofbounds = true;
                }
            }
            LAGame.gbROM.WriteByte(mapData.animation);
            LAGame.gbROM.WriteByte(mapData.tilePreset);

            if (outofbounds)
            {
                LAGame.gbROM.WriteByte(0xFE);
                return;
            }

            foreach (CollisionObject obj in mapData.collisionObjects)
            {
                int objectSize;

                if (obj.is3Byte)
                {
                    objectSize = 3;
                }
                else
                {
                    objectSize = 2;
                }
                if (mapData.map >= 0x80 && mapData.map <= 0xFF)
                {
                    if (LAGame.gbROM.BufferLocation + objectSize > 0x69E73)
                    {
                        return;
                    }
                }
                else if (mapData.map <= 0x7F)
                {
                    if (LAGame.gbROM.BufferLocation + objectSize > 0x2668B)
                    {
                        return;
                    }
                }

                if (obj.is3Byte)
                {
                    if (obj.direction == 8)
                    {
                        b = (byte)(0x80 + obj.length);
                        LAGame.gbROM.WriteByte(b);
                    }
                    else
                    {
                        b = (byte)(0xC0 + obj.length);
                        LAGame.gbROM.WriteByte(b);
                    }
                    b = (byte)((obj.yPos * 0x10) + obj.xPos);
                    LAGame.gbROM.WriteByte(b);
                    LAGame.gbROM.WriteByte(obj.id);
                }
                else
                {
                    b = (byte)((obj.yPos * 0x10) + obj.xPos);
                    LAGame.gbROM.WriteByte(b);
                    LAGame.gbROM.WriteByte(obj.id);
                }
            }
            if (mapData.warpObjects.Count != 0)
            {
                foreach (Warps warp in mapData.warpObjects)
                {
                    int objectSize = 5;

                    if (mapData.map >= 0x80 && mapData.map <= 0xFF)
                    {
                        if (LAGame.gbROM.BufferLocation + objectSize > 0x69E73)
                        {
                            //LAGame.gbROM.BufferLocation = 0X69E73;
                            LAGame.gbROM.WriteByte(0xFE);
                            return;
                        }
                    }
                    else if (mapData.map <= 0x7F)
                    {
                        if (LAGame.gbROM.BufferLocation + objectSize > 0x2668B)
                        {
                            //LAGame.gbROM.BufferLocation = 0x2668B;
                            LAGame.gbROM.WriteByte(0xFE);
                            return;
                        }
                    }

                    b = (byte)(0xE0 + warp.type);
                    LAGame.gbROM.WriteByte(b);
                    LAGame.gbROM.WriteByte(warp.region);
                    LAGame.gbROM.WriteByte(warp.map);
                    LAGame.gbROM.WriteByte(warp.x);
                    LAGame.gbROM.WriteByte(warp.y);
                }
            }

            LAGame.gbROM.WriteByte(0xFE);
        }
Beispiel #21
0
        private void saveEntityData(GameMapData mapData)
        {
            bool outofbounds = false;

            getEntityDataOffset(mapData);

            if (LAGame.overworldFlag && LAGame.gbROM.BufferLocation >= 0x59663)
            {
                LAGame.gbROM.BufferLocation = 0x59663;
                outofbounds = true;
            }
            else if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation >= 0x596FF)
            {
                LAGame.gbROM.BufferLocation = 0x596FF;
                outofbounds = true;
            }
            else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation >= 0x59185)
            {
                LAGame.gbROM.BufferLocation = 0x59185;
                outofbounds = true;
            }
            else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation >= 0x58CA3 && LAGame.dungeon != 0xFF && !LAGame.overworldFlag)
            {
                LAGame.gbROM.BufferLocation = 0x58CA3;
                outofbounds = true;
            }

            if (outofbounds)
            {
                LAGame.gbROM.WriteByte(0xFF);
                return;
            }

            foreach (Entity selectedEntity in mapData.entities)
            {
                if (LAGame.overworldFlag && LAGame.gbROM.BufferLocation + 2 >= 0x59663)
                {
                    LAGame.gbROM.WriteByte(0xFF);
                    return;
                }
                else if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation + 2 >= 0x596FF)
                {
                    LAGame.gbROM.WriteByte(0xFF);
                    return;
                }
                else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation + 2 >= 0x59185)
                {
                    LAGame.gbROM.WriteByte(0xFF);
                    return;
                }
                else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation + 2 >= 0x58CA3 && LAGame.dungeon != 0xFF && !LAGame.overworldFlag)
                {
                    LAGame.gbROM.WriteByte(0xFF);
                    return;
                }

                byte b = (byte)((selectedEntity.yPos * 0x10) + selectedEntity.xPos);
                LAGame.gbROM.WriteByte(b);
                LAGame.gbROM.WriteByte(selectedEntity.id);
            }
            LAGame.gbROM.WriteByte(0xFF);
        }
Beispiel #22
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());
        }
        public void repointNextMap(GameMapData mapData, MapPointer nextMapPointer)
        {
            int mapAddressToRepoint;

            if (LAGame.overworldFlag)
            {
                mapAddressToRepoint = getCollisionDataOverworldOffset(mapData) + spaceCalculator.getUsedSpaceCollisions(mapData.collisionObjects, mapData.warpObjects) + 3;
            }
            else
            {
                mapAddressToRepoint = getCollisionDataDungeonOffset(mapData) + spaceCalculator.getUsedSpaceCollisions(mapData.collisionObjects, mapData.warpObjects) + 3;
            }
            //Plus 1 for animation, 1 for tile preset and 1 for 0xFE room ending byte

            if (LAGame.overworldFlag)
            {
                if (mapData.map == 0xFF || mapData.map == 0x7F)
                {
                    mapAddressToRepoint = getCollisionDataOverworldOffset(mapData);
                }
            }
            else
            {
                if (mapData.map == 0xFF && LAGame.dungeon != 0xFF || (LAGame.map == 0x15 && LAGame.dungeon == 0xFF))
                {
                    mapAddressToRepoint = getCollisionDataDungeonOffset(mapData);
                }
            }


            if (LAGame.overworldFlag)
            {
                if (mapData.map < 0x80 && mapAddressToRepoint >= 0x2668D)
                {
                    mapAddressToRepoint = 0x2668B;
                }
                else if (mapData.map > 0x7F && mapAddressToRepoint >= 0x69E75)
                {
                    mapAddressToRepoint = 0x69E73;
                }
            }
            else
            {
                if (LAGame.dungeon == 0xFF && mapAddressToRepoint >= 0x2BF43)
                {
                    mapAddressToRepoint = 0x2BF41;
                }
                else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && mapAddressToRepoint >= 0x2FFFF && LAGame.dungeon != 0xFF)
                {
                    mapAddressToRepoint = 0x2FFFD;
                }
                else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && mapAddressToRepoint >= 0x2BB77 && LAGame.dungeon != 0xFF)
                {
                    mapAddressToRepoint = 0x2BB75;
                }
            }


            if (nextMapPointer != null)
            {
                nextMapPointer.mapAddress = mapAddressToRepoint;
            }
            else
            {
                nextMapPointer                = new MapPointer();
                nextMapPointer.mapAddress     = mapAddressToRepoint;
                nextMapPointer.map            = mapData.map;
                nextMapPointer.specialAddress = mapData.specialFlag;
            }

            repointMapCollisions(nextMapPointer);
        }
        private GameMapData LoadCollisionDataDungeon(int map, bool magnifyGlass)
        {
            GameMapData mapData = new GameMapData();

            mapData.map         = map;
            mapData.specialFlag = magnifyGlass;

            //Sets the buffer address
            LAGame.gbROM.BufferLocation = getCollisionDataDungeonOffset(mapData);
            mapData.animation           = LAGame.gbROM.ReadByte();
            mapData.tilePreset          = LAGame.gbROM.ReadByte();

            byte b;

            while ((b = LAGame.gbROM.ReadByte()) != 0xFE) //0xFE = End of room
            {
                //There is free space for room 0xFF (dungeon >=6) but there is no room ending byte
                if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation >= 0x2BF43)
                {
                    break;
                }
                else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation >= 0x2FFFF && LAGame.dungeon != 0xFF)
                {
                    break;
                }
                else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation >= 0x2BB77 && LAGame.dungeon != 0xFF)
                {
                    break;
                }


                //Check to see if we are reading empty space

                /*if (b == 0)
                 * {
                 *  //We need a 00 00 00 pair for it to be empty space. Otherwise it could just be an object in XY position 0.
                 *  byte x = LAGame.gbROM.ReadByte();
                 *  if (x == 0)
                 *  {
                 *      x = LAGame.gbROM.ReadByte();
                 *      if (x == 0 && x != 0xFE)
                 *      {
                 *          LAGame.gbROM.BufferLocation--;
                 *          continue;
                 *      }
                 *      if (x == 0xFE)
                 *          break;
                 *      else
                 *          LAGame.gbROM.BufferLocation -= 2;
                 *  }
                 * }*/

                if (b >> 4 == 0xE)
                {
                    if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation + 4 >= 0x2BF43)
                    {
                        break;
                    }
                    else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation + 4 >= 0x2FFFF && LAGame.dungeon != 0xFF)
                    {
                        break;
                    }
                    else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation + 4 >= 0x2BB77 && LAGame.dungeon != 0xFF)
                    {
                        break;
                    }

                    Warps w = new Warps();
                    w.type   = (byte)(b & 0x0F);
                    w.region = LAGame.gbROM.ReadByte();
                    w.map    = LAGame.gbROM.ReadByte();
                    w.x      = LAGame.gbROM.ReadByte();
                    w.y      = LAGame.gbROM.ReadByte();
                    mapData.warpObjects.Add(w);
                    continue;
                }
                if (b >> 4 == 8 || b >> 4 == 0xC) //3-Byte objects
                {
                    if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation + 2 >= 0x2BF43)
                    {
                        break;
                    }
                    else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation + 2 >= 0x2FFFF && LAGame.dungeon != 0xFF)
                    {
                        break;
                    }
                    else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation + 2 >= 0x2BB77 && LAGame.dungeon != 0xFF)
                    {
                        break;
                    }

                    CollisionObject o = new CollisionObject();
                    o.is3Byte   = true;
                    o.length    = (byte)(b & 0xF);
                    o.direction = (byte)(b >> 4);
                    byte b2 = LAGame.gbROM.ReadByte();
                    o.yPos = (byte)(b2 >> 4);
                    o.xPos = (byte)(b2 & 0xF);
                    o.id   = LAGame.gbROM.ReadByte();
                    if (o.id >= 0xEC && o.id <= 0xFD)// Door tiles
                    {
                        int bufferloc = LAGame.gbROM.BufferLocation;
                        o.dungeonDoors(LAGame, o);
                        LAGame.gbROM.BufferLocation = bufferloc;


                        foreach (CollisionObject obj in o.objectIDs)
                        {
                            mapData.collisionObjects.Add(obj);
                        }
                    }
                    else
                    {
                        mapData.collisionObjects.Add(o);
                    }
                    continue;
                }
                else
                {
                    if (LAGame.dungeon == 0xFF && LAGame.gbROM.BufferLocation + 1 >= 0x2BF43)
                    {
                        break;
                    }
                    else if ((LAGame.dungeon >= 6 && LAGame.dungeon < 0x1A) && LAGame.gbROM.BufferLocation + 1 >= 0x2FFFF && LAGame.dungeon != 0xFF)
                    {
                        break;
                    }
                    else if ((LAGame.dungeon < 6 || LAGame.dungeon >= 0x1A) && LAGame.gbROM.BufferLocation + 1 >= 0x2BB77 && LAGame.dungeon != 0xFF)
                    {
                        break;
                    }

                    CollisionObject ob = new CollisionObject(); // 2-Byte tiles
                    ob.yPos = (byte)(b >> 4);
                    ob.xPos = (byte)(b & 0xF);
                    ob.id   = LAGame.gbROM.ReadByte();
                    if (ob.id >= 0xEC && ob.id <= 0xFD)// Door tiles
                    {
                        int bufferloc = LAGame.gbROM.BufferLocation;
                        ob.dungeonDoors(LAGame, ob);
                        LAGame.gbROM.BufferLocation = bufferloc;


                        foreach (CollisionObject obj in ob.objectIDs)
                        {
                            mapData.collisionObjects.Add(obj);
                        }
                    }
                    else
                    {
                        mapData.collisionObjects.Add(ob);
                    }
                }
            }
            return(mapData);
        }