happyleavesaoc / aoc-mgz

Age of Empires II recorded game parsing and summarization in Python 3.
MIT License
197 stars 41 forks source link

question: Way to calculate unit/building ids during game #68

Closed christinoleo closed 2 years ago

christinoleo commented 3 years ago

I am trying to use a rec to reconstruct the units and buildings built during the game but I can't figure out how aoe generates and associates new ids to units and buildings.

I've noticed that the building's ids are given when they are placed and same to units when they are queued, but I can't map out the entire rec's ids only by this because it seems that walls and other entities also are given ids. Is there a way to for me to run a summary function to gather all ids and what they are (vills, houses, etc) of a rec?

Btw, thanks for the library! If this id part works out, I plan to use it in a research project.

happyleavesaoc commented 3 years ago

Hi, you cannot know from the rec what ID resulted from a build or queue action with full accuracy, without actually running the game simulation.

For example, a player may queue a unit (which you'll see in the rec, with an object_id of the building the unit is queued in, and a unit_id corresponding to the unit type (but critically, not the object_id of the actual unit). Then, the unit might be created and die without the player ever issuing a command, which means its object_id will never even show up in the rec. In fact, the building might be destroyed while the unit is in queue, so it could have never been created in the first place.

christinoleo commented 3 years ago

Hi. Thanks for the answer. So from what you said, I get that there is no built-in method of calculating or interpolating the ids without a simulation of the game. I don't mind doing a simulation of the game, but I have no clue where to start. Even annotating manually seem a problem since I can't see the unit and building ids in-game on a DE recording.

I've been building a dual method to try to interpolate (with some errors allowed) the ids. One is what you said, using all unit-type and building-type commands (e.g. only buildings have de_queue and research, and only units have formations). I even built a tech-tree-map so that I know what type of building it is given a queue or research. Another is assuming the "best case scenario" and giving an id for all buildings and units queued to be built. The first one is incomplete as you have noted, but a weird thing is that the second one has many less ids (numerically) than the first. In the rec I am using for this, the first method has less ids identified, but the id number goes from 13720 to 16k, and the second method goes only up to 14k (I add one id for each building or unit queued). I feel I am missing a core game mechanic here. Do you know if there are large jumps in id assignment throughout the game? Certainly a 2k difference of ids in a game that ended in early-castle is strange.

Do you have any insight of this id discrepancy issue? If I am able to add information to the first method from the error-prone second method (even if some of the information is wrong), I'd be able to continue other parts of my research. The rec is here if you want to check it out too. Thanks!

AgeIIDE_Replay_113129016.zip

happyleavesaoc commented 3 years ago

The only foolproof way to do what you want is to replay the recorded game and inspect the game's memory. Any other simulation will make assumptions or miss information that will accumulate error as the game goes on.

Unfortunately I'm not familiar with the ID assignment scheme. Just a guess, but doppleganger objects (fog-of-war object placeholders) could be contributing.