Playing my favorite game, Forge Of Empires (shortly FoE) recently I stuck to a problem.
For those of you who haven't heard of this awesome web2 online game its levels are called "Eras", starting from "Stone Age" with a small city and up to the highest era for 2023 and 2024, called "Space Age Titan".
With each new era, a certain free extensions are available to expand your city and a certain limited number of paid, with diamonds, that's the money equivalent of the game. So with each new era, the cities become bigger and bigger.
Some of the buildings have the feature to be upgraded to the latest era via a "Renovation Kit" or upgraded one era up via a "One Up Kit".
So here is the game problem I stumbled upon. I reached a moment when all my upgradable buildings are already maxed. So I don't need any more Reno kits as far as I have enough One Up kits to upgrade all my buildings once a new era is opened by the game developers. So, how do I count all my upgradable buildings. I wouldn't do that manually as here is how my city looks at the moment:
Those are hundreds of buildings and some of them are quite small, taking 1 square (the city space unit).
The game itself doesn't provide that info.
There is a wonderful browser addon, called FoE Helper, developed by a talented German developer.
It has a map feature:
Unfortunately it doesn't show the building counts, but the squares taken instead, so, not useful enough in my case.
However, it has a "Copy city data" button that copies, in my case, a huge 16 MB JSON file in the clipboard.
Pasted inside Visual Studio Code, originally it looks like this:
Not quite human-readable but the Outline VSC windows helps a bit to explore its content and figure out I should be querying the "CityMapData" block elements for certain "type" attributes:
After a short research a came to this popular query language for JSON data, called JMESPath:
I spent some time learning it and it is a great language, something like Regular Expressions for JSON but I soon realized it would take me more time to learn it than manually counting all the buildings, LOL.
So here Python came to help. Shortly I came up with this neat script :)
Now I have a quick script that prints for me a Python Set with all the counts of the types of buildings in my city and the total number of One Up Kits needed.
I guess I can sell all my Renovation Kits now at the Antiques Dealer as I currently have about 300 One Up Kits but as my city produces 2-3 of them each day, I feel I am pretty much covered as there aren't any news about a new era yet.
So from now on, when I reconstruct the city, I just have to copy my city data and save the json file and just re-execute the script to get the updated total needed. Easy-peasy...
To those of you who play FoE: