Monday, November 7, 2011

Coding Quandary for Brawler Scores

One of the principal challenges in establishing this new brawler scoreboard was establishing the framework for it.  The scoreboard, in the simplest sense, made of a string of individual brawlers and their scores.  As such, it would make sense to attach this information to each brawler's pfile (which is where their stats, equipment, description, et cetera are stored) since brawler scores are just another stat.  At the same time though, pfiles are loaded into the game dynamically--if a character isn't logged in, all of the information stored in his pfile (stats, equipment, description, et cetera) are totally unknown to the game.

Think about it.  Are there any commands that let you get information from another character who isn't logged in?  The only example of this that comes to mind reading notes posted by characters who aren't logged in; this is possible because notes are stored in a fashion similar to areas--they are saved to their own special file that is read in when the game starts up, and then the list of notes just floats in the game's permanent memory forever.  As new notes are posted, they also go into permanent memory, and they are saved to the special note file so that they can be reloaded after the next reboot.

Notes are static though;  once they're up, they really never need to be changed.  Brawler stats, on the other hand, will constantly be changing as people claim victory over each other.  Although these changes will only happen when brawlers are logged in to fight each other, what do we do with their scores when those brawlers log out?  They still need to be accessible by everyone on the scoreboard, and they need to be able to be reloaded after reboots.

This question highlights one of the principal design decisions I had to make in deciding how to actually implement this brawler scoreboard.  On the one hand, brawler scores need to be stored permanently like notes are, but on the other hand, they are fundamentally a stat that is attached to one and only one character.  Furthermore, we may need to be able to modify brawler scores even if the brawlers aren't logged in (e.g., in case of wimpouts or losses that need to be verified by imms).  How can these conflicting ideas be reconciled?  Here are the two options that I first considered:

  1. Store brawler scores in permanent memory, but have players "download" them to their character when they log in and "upload" their new scores when they log out
  2. Store brawler scores in permanent memory AND on the pfile, then keep track of which set of scores (the ones in permanent memory or the ones on the pfile) were updated most recently and use those
Unfortunately, both of these options raise problems with consistency.  Because information gets stored in two places in both cases, it becomes easy to envision a scenario where the information in one place doesn't get updated in the other place and suddenly one brawler has two different sets of scores.  This isn't an issue in 100% bug-free code, but the fact is that the system is not robust; if I (or a future coder) needs to modify the brawler code a few years down the road, we have to remember to make sure that both sets of scores need to be manually synced up or else problems arise.

A better option (and what I wound up doing) is to store brawler stats in permanent memory, and instead of worry about uploading/downloading/syncing those numbers against a pfile when it is loaded, just "attach" each player's brawler score info (still in permanent memory) to the pfile when the character logs in.  When the character logs out, the attachment breaks, but the brawler record is still floating in the permanent memory.

While we still have to make sure that brawler scores are properly attached to characters when they're logged in, this is far less flaky of a process than ensuring data is consistent across two places since it's trivial to perform the attachment.  So, in addition to checking for attachment when a character logs in, we can check for attachment at other critical points in the code such as when a brawler gets thrown out of brawler or scores another kill.

Speaking of getting thrown out of brawler, the reason why I bring this all up is because Stage 2 will include a new "leavebrawler" command that players can use to voluntarily quit.  However, quitting Brawler will also ban you from re-joining it for thirty real-life days.  Because we store brawler scores in permanent memory rather than on the pfile, this ban has the unintentional (but fortuitous) effect of persisting across recreates.  Even though a player may have deleted and re-created his character, that character's brawler record is stored in permanent memory and cannot be deleted by the player.

This might sound a bit trivial ("It'll take 30 days to level back up to 50 anyway!"), but a more powerful result of this is that immortals will have the ability to ban characters from brawler for life (such as may be necessary if they are caught abusing brawler perks).  Recreating won't circumvent that ban, which imposes an interesting incentive for players to not try to get cheap healing in a real fight by cheating the system.  A ban from brawler will truly be a ban for life.

No comments:

Post a Comment