Now one complication I've got right now is the data structures in the Java are more complicated than the old Delphi version. For e.g. the overland map, cities, buildings and so on in the old version, the server has (n+1) copies of the data - one being the 'true' copy of exactly how things are right now - but each player can only see what their units can see, so for a game with n players in it (raiders being 1 player, monsters in nodes/lairs/towers also being 1 player), the server then also has a copy of what that player knows about - which [unless they've cast Nature Awareness] won't be the whole map. The client only has 1 copy of the data, what that player knows about. But the old Delphi version didn't support that for units, it was just too complicated to deal with [for technical reasons that I won't get into], so the old Delphi server just had 1 copy of the unit data, and each player could either see a unit or not, they had no 'copy' of 'what they know' about each unit. Now in the new Java server they do - which means converting a lot of the routines across means taking that into account, so isn't as simple as just converting the code line-by-line.
So was struggling to get my head around how all this had to work when I was trying to write some of the code, and write tests for some of the code, so in the end decided I had to sit down and just write out all the rules about how unit statuses and updating player's memory of units worked, so I then had a reference to check all the code against. So now my head hurts x.x Anyway wanted to share this because thought people might find it interesting:
MoMIMEMessages.xsd wrote:Different statuses that a unit can have. This is extremely complicated now that there are 2 copies of the unit data to worry about
(the server's true memory, and the player's memory both as held on the server and client which should be identical) plus that the monsters player has its own special rules.
The server's true memory always knows about all units - they can never go out of sight. So:
- Heroes start at "Not Generated" or "Generated" depending on settings, then move to "Alive" when summoned.
- Regular units are created at "Alive".
- Units and heroes dying in combat move to status "Dead".
- At the end of combat, units at staus "Dead" are removed entirely.
- Even after the end of combat, heroes at status "Dead" are kept forever (since while dead heroes cannot be re-summoned,
they can be brought back with the life spell "Resurrection").
- Combat summons (like fire elementals or phantom warriors) go to status "Dead" when killed, and are removed entirely when the combat ends whether they were alive or not.
The player's memory (both server and client side) never has "Not Generated" or "Generated" heroes - heroes are only added once summoned. Players' memory of their
own units otherwise works as per the server's true memory, since players can always see and retain up to date info on their own units. So:
- Our units and heroes dying go to status "Dead", and after combat dead units are removed entirely but dead heroes are kept, same as in server's true memory.
- Enemy units that we kill in combat (i.e. we're involved in the combat) are retained at "Dead" for the duration of the combat and then removed entirely.
- Enemy heroes that we kill in combat are removed immediately since we can't Raise Dead or Resurrect them.
- Enemy units and heroes that somebody else kills in a combat for which we are an outside observer (e.g. standing next to 2 unit stacks
both owned by other players watching them fight) are removed immediately since we can't Raise Dead or Resurrect them. And therefore by implication,
if one of the players involved in the combat -does- Raise Dead the unit, for any outside observers to the combat, its treated like a re-add.
- Combat summons (like fire elementals or phantom warriors) go to status "Dead" when killed, and are removed entirely when the combat ends whether they were alive or not.
- Player's memory only contains monsters in nodes/lairs/towers when we are in a combat with them, so the monsters are added to the player's memory on the server
and sent to the client in the StartCombat message, go to status "Dead" when killed, and are removed from the player's memory when the combat ends
whether they were still alive (monsters won) or not.
- Combat summons (like fire elementals or phantom warriors) go to status "Dead" when killed, and are removed entirely when the combat ends whether they were alive or not.
- Outside observers to a node/lair/tower combat never get to see the monsters - they'll just see the attacking units taking damage.
- Enemy units that we can no longer see on the overland map if the units FOW setting = forget are removed entirely.
- Enemy units that we can no longer see on the overland map if the units FOW setting = remember are retained as we last saw them, including that if they get killed,
we don't know about it and will continue to remember the last place we saw that unit.
The monsters player (who owns the units guarding nodes/lairs/towers as well as rampaging monsters walking around the map) has a the exception that
they obviously are aware of their own units, so are the only player who knows the exact units in nodes/lairs/towers even when not involved in a combat there.