Porting a PHP Based Web Game to Mobile Part 2

First things first; we've got a case of inverted map syndrome. When parsing the game.php response for this map: We get the following output: Here, green refers to terrain, grey to buildings and red to units. You might notice that the map is inverted along the x axis. What should be at the top of the map is at the bottom, and vice versa. A simple enough fix, just tweaking our tile positions after instantiation. Unity (and to be honest, most all engines that deal with positions), deal with positive Y as upwards. AWBW however, takes positive Y in the downward direction, so to account for this in unity, we just need to invert the Y position of the tile when spawning it. Inverting like so: foreach (TileInfo buildingTile in buildingsInfo.Tiles) { GenerateMapTile(TileType.Building) .transform.localPosition = new Vector3((int)buildingTile.X, (int)-buildingTile.Y, 0); } foreach (TileInfo terrainTile in terrainInfo.Tiles) { GenerateMapTile(TileType.Terrain) .transform.localPosition = new Vector3((int)terrainTile.X, (int)-terrainTile.Y, 0); } foreach(TileInfo unitTile in unitsInfo.Tiles) { GenerateMapTile(TileType.Unit) .transform.localPosition = new Vector3((int)unitTile.X, (int)-unitTile.Y, 0); } That seems to do the trick, as we now have a map that matches - at least in spirit - the map we are trying to reproduce. Now, we need to distinguish between the different units, buildings and terrain on the board. As we are just blocking out the game functionality at the moment, the first thing that comes to mind is just a letter to represent each unit. Since you will never have both a building and terrain on the same tile, we can do the same for buildings and terrain. For buildings and terrain we'll put the letter in one of the corners, and for the units we'll put it in the center. Let's see how that goes. That's pretty good! Now I won't lie, I did run into a few speed bumps, firstly, when a country controls a building, that country's name is included in the building name. I wasn't able to find another to distinguish building types, so I had to just filter out building names like so: public static List BUILDING_NAMES = new List { "CITY", "BASE", "AIRPORT", "TOWER", "HQ", "LAB" }; string tileName = tileInfo.Name; string buildingName = GameInfoUtils.BUILDING_NAMES.Find(x => tileName.ToUpper().Contains(x)); if(buildingName != null) tileName = buildingName; Not the cleanest in the world, but it works. Secondly, and this one I haven't resolved yet, the tile name also includes the variant of the tile. For example, there are many types of "Road" tiles. Despite them all having the same effect on the game, their names are different, I imagine to help distinguish them when their sprites are being assigned. The last issue I encountered was unit's who's names start with the same letter. This was an issue I assumed would come up, however I may just hard code 2 letters for these edge cases and deal with it properly later once we start adding sprites.

Apr 10, 2025 - 13:34
 0
Porting a PHP Based Web Game to Mobile Part 2

First things first; we've got a case of inverted map syndrome. When parsing the game.php response for this map:
Image description
We get the following output:
Image description
Here, green refers to terrain, grey to buildings and red to units. You might notice that the map is inverted along the x axis. What should be at the top of the map is at the bottom, and vice versa. A simple enough fix, just tweaking our tile positions after instantiation. Unity (and to be honest, most all engines that deal with positions), deal with positive Y as upwards. AWBW however, takes positive Y in the downward direction, so to account for this in unity, we just need to invert the Y position of the tile when spawning it. Inverting like so:

foreach (TileInfo buildingTile in buildingsInfo.Tiles)
        {
            GenerateMapTile(TileType.Building)
                .transform.localPosition = new Vector3((int)buildingTile.X, (int)-buildingTile.Y, 0);
        }

        foreach (TileInfo terrainTile in terrainInfo.Tiles)
        {
            GenerateMapTile(TileType.Terrain)
                .transform.localPosition = new Vector3((int)terrainTile.X, (int)-terrainTile.Y, 0);
        }

        foreach(TileInfo unitTile in unitsInfo.Tiles)
        {
            GenerateMapTile(TileType.Unit)
                .transform.localPosition = new Vector3((int)unitTile.X, (int)-unitTile.Y, 0);
        }

That seems to do the trick, as we now have a map that matches - at least in spirit - the map we are trying to reproduce.
Image description
Now, we need to distinguish between the different units, buildings and terrain on the board. As we are just blocking out the game functionality at the moment, the first thing that comes to mind is just a letter to represent each unit. Since you will never have both a building and terrain on the same tile, we can do the same for buildings and terrain. For buildings and terrain we'll put the letter in one of the corners, and for the units we'll put it in the center. Let's see how that goes.
Image description
That's pretty good! Now I won't lie, I did run into a few speed bumps, firstly, when a country controls a building, that country's name is included in the building name. I wasn't able to find another to distinguish building types, so I had to just filter out building names like so:

public static List BUILDING_NAMES = new List
    {
        "CITY",
        "BASE",
        "AIRPORT",
        "TOWER",
        "HQ",
        "LAB"
    };

string tileName = tileInfo.Name;
        string buildingName = GameInfoUtils.BUILDING_NAMES.Find(x => tileName.ToUpper().Contains(x));
        if(buildingName != null) tileName = buildingName;

Not the cleanest in the world, but it works. Secondly, and this one I haven't resolved yet, the tile name also includes the variant of the tile. For example, there are many types of "Road" tiles. Despite them all having the same effect on the game, their names are different, I imagine to help distinguish them when their sprites are being assigned. The last issue I encountered was unit's who's names start with the same letter. This was an issue I assumed would come up, however I may just hard code 2 letters for these edge cases and deal with it properly later once we start adding sprites.