In the course of #5387, this patch transforms the session.js reportGame and sendLobbyPlayerlistUpdate function to use class syntax.
Additionally it moves the lobby code including globals to a separate session/lobby/ folder that can be deleted without further modification if someone wants to distribute 0ad without lobby code (refs D2284).
Unfortunately many bugs have been discovered during the implementation of this that can't be all addressed here.
This is mostly caused by duplicating code and then only one of the copies getting updates.
- rP12914 introduced score counts, where the total score = economic score + military score + exploration score rP14098 introduced the lobby including rating code, added a field for totalScore in the database but didn't receive the value for that from session.js.
- rP14752 added the totalScore sending, but it copy&pasted the function from the summary screen, so that future updates to the summary screen code would not get into this score value. The duplication cannot be removed here without introducing two random score functions to gui/common/ and I'd rather add comments that will be ignored by developers and broken again than introducing again incohesive code to that folder. rP14752 also missed to add the exploration score present in rP12914.
- rP14098 added trailing commas to all reported values and added python code to remove them again. All of that for no apparent reason. This is not going to be fixed in this diff to keep this a GUI only diff.
- rP14703 introduced counting of specific unit and building classes in the summary screen and StatisticsTracker. It modified the session.js reportGame function to hardcode unit and class names in both the StatisticsTracker AND session.js. This is not obvious at all that these have to be duplicates, it more appears like a selection of specific classes chosen in the lobby rating client code, but it's not. D2384 removes the duplication for the StatisticsTracker, this diff removes the duplication for the GUI.
- rP16550 implemented capturing, rP18395 introduced capturing statistics. Due to the duplication effect, it added the buildingsCaptured property for the StatisticsTracker, but not for the reportGame function, so the same problem still exists here. This is not fixed in this patch as the bot needs to be updated for that, and with that the ratings db table would have to be migrated too.
- rP16624 introduced ceasefire, added it to reportGame, making it being sent, but the bot never reads from it. Secondly it converted the time number to string while the timeElapsed is sent as a number. I suppose someone looking at the ratings database would rather be interested in the ceasefire time that was set in the matchsettings, rather than the remaining ceasefire time (as only resign and gaia can defeat someone during that time). So this is removed in this patch. It had been added apparently for consistency, and this makes one wonder whether one shouldnt just send the playerstate instead of copying and transforming every property individually... But I want to be conservative with this patch and finish the OOP rewrite before going down too many rabbitholes (which I already do as you see).
- rP14703 broke the economic score by counting vegetarianFood twice. rP14752 copied the mistake to the rating reporter code. This was first noticed by causative in http://irclogs.wildfiregames.com/2016-06/2016-06-07-QuakeNet-%230ad-dev.log Notice that this double-counting of vegetarian food has been claimed to be a feature by both causative and later by temple too, because for all gathered resources one has 0 investment costs except for corrals where they are 50%, so the score ended up in showing the corral player to be twice as many resources available which was not the case due to the investment. rP19584 fixed the doublecounting for the statistics code but not for the rating reporter copy. It also added trade to the statistics economy score, but not to the rating reporter code. rP20543 changed the mechanism to reduce the number of resources gathered when training animals, but again not for the rating code. If only counting "net resources" as introduced by that commit is reasonable, then this should be renamed to such, both shown in the summary screen page and in the variable names. Because everyone looking at "gathered resources" will think it's amount of resources gathered. But one can actually get negative gathered resources and economy score if one trains sheep without gathering them. This behavior is not changed in this patch because unrelated, but that doesn't stop this issue from slowing down development of this patch. Ahhhh!