Jump to content

Obtaining Player State


Rishabh
 Share

Recommended Posts

Hey all,

I was trying to play around with the network protocol. How can I extract the state of the game currently? I couldn't seem to find this part in the source. I want to be able to send my state to the other player without hashing it.

Thanks in advance.

Edited by Rishabh
Link to comment
Share on other sites

3 hours ago, Rishabh said:

How can I extract the state of the game currently? I couldn't seem to find this part in the source. I want to be able to send my state to the other player without hashing it.

You can check out how the simulation state is serialized for the hashing itself, see CComponentManager::ComputeStateHash , as the code comment says:

Quote

// Hash serialization: this includes the minimal data necessary to detect
// differences in the state, and ignores things like counts and names

// If 'quick' is set, this checks even fewer things, so that it will
// be fast enough to run every turn but will typically detect any
// out-of-syncs fairly soon

For the full simulation state serialization / deserialization you can examine the save / load game mechanics, see SavedGame.cpp

Link to comment
Share on other sites

Isn't the game state in one of these objects?

https://github.com/0ad/0ad/blob/9c792c327af49702eb146d8551235ebc650fd561/binaries/data/mods/public/simulation/ai/common-api/shared.js

baseAI uses it like this

this.gameState = sharedAI.gameState[this.player];

I think its a pretty elaborate js object with many nested dictionaries and somewhere in the simulation code gets updated each player's turn.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...