MegaMek / megamek

MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight using giant robots, tanks, and/or infantry on a hex-based map.
http://www.megamek.org
GNU General Public License v2.0
296 stars 286 forks source link

Improve robustness of EntityListFile to null entity.getGame #5332

Open AaronGullickson opened 6 months ago

AaronGullickson commented 6 months ago

Issue MegaMek/mekhq#3978 occurred because EntityListFile was calling entity.getGame() several places but BotForces don't have games. if we want to consolidate the entity XML reading/writing across MM and MHQ (which I think we do) then EntityListFile needs to be more robust in dealing with these kind of issues. I made a short term solution of adding additional checks for game being null but I don't love this solution for the long term.

Most of the usages of entity.getGame() are to check game options. One relatively easy solution would be to feed in game options to the write methods. MekHQ has game options even if BotForces do not have games. However, I did notice two other places that we depend on game. The first is writing out C3Master information and the second is writing out Force information, so we would need other ways of handling that.

The longer-longer term solution would be a (much) bigger rewrite to leave game out of entity. Its kind of weird really. It worked fine when it was just MM and we could always assume that if you had an entity you had a game. But that assumption has long since been broken.

Sleet01 commented 6 months ago

BotForces may not have games, but do we have access to the Bot's client instance in this context? If so, I believe we can get the game instance from that.

Edit: or is this entirely external to MM, so no Bot either? In that case, yeah, either pass in the game options or encapsulate them in a settings datatype would be my vote.

AaronGullickson commented 6 months ago

Entirely external to MM. Its the BotForce assigned to a Scenario. It doesn't get a proper Bot until the game is started in GameThread.