No, I didn’t just have some rich relative kick off and leave my name in the will. The closest I have to a rich relative is an uncle who can afford to buy a new pair of shoes every two years.
In the original MUD code and in most C-based codebases I’ve seen, mobs have one set of data and players have a similar but different set of data. They all have things like hitpoints and movement points, but mobs have things like AI scripts and behavior flags while players have extra things like skill values and guild memberships.
There are two ways to handle this in C: either have completely different sets of data for each, or have a core set of data and a pointer to the extended data depending on which type it is (player or mob). The first way is sloppy and dangerous, while the second is sort of a “poor man’s inheritance”.
I’ve rewritten this to use parent and derived classes and all of a sudden some things that were very hard to do are incredibly easy. It’s also become incredibly easy to have things work differently for mobs and players by being able to use overridden functions for the player versions of code.
For example, since mobs don’t have skill training, almost every check for something like a bash or headbutt is based on a combination of that mob’s level and racial statistics. For players the check uses skill values modified by actual attributes like dexterity and strength.
Instead of writing a huge function riddled with lots of “if” statements, I can now just write different versions for each. The code is cleaner, easier to write, and automatically smart enough to “do the right thing”.
I love C++. Even though I’m getting a bit addicted to C# lately, it still rocks.
I never could have made this change without massive use search-and-replace, since the way to access most of the data members of players has changed completely. I did not want to change 2000 data references by hand.