Logical Player Information Grouping
I am just playing with creating a C++ class that generates character data. As it is, I am about 75% done with it. The other 25% involves making things pretty, finishing a few stat functions, and moving global variables to an appropriate class. That is where I am having difficulty. I have a list of player types (human, elf, etc.) in an array and a list of max and mins for the player types (min/max strength, min/max intelligence, etc). I don''t want to dupe this data every time I make a new player entity (class CPlayer in my case). After a few hundred or so players (on and off screen) I can see memory starting to become an issue. I am thinking of doing two things - 1) making object oriented purist cry and keeping the variables global or 2) creating a player management class that simply has a CPlayer and loads all of those globals up. The downfall to #2 is that I will need to write some functions that somehow push out the strings and min/max stats when the information is needed elsewhere.
There isn''t a game or anything associated with this character generation stuff but I hope to make it flexible enough to allow some minor changes to allow for it to be used in a variety of RPGs. That would be the last 5% of getting it completed to a beta state.
Instead of staticly imbeding the stats into the exe, allow them to be load at run-time. If your using Borland C++ biulder you have a neat INI file class. Use this to load & save the settings. To load a race loop through the list of sections, with each section being a race
ie
[Human]
AncestorRace=Mammal
...
[Elf]
AncestorRace=Mammal
...
[Human-Elf]
AncestorRace=Human,Elf
...
[Dragon]
AncestorRace=Lizard
...
By allowing ancestor races you can allow a race to inherit abilites from predefined races. Then have a pointer to the stats class(CPlayerStatLimits), and only have the current states in the actual char.
Edited by - ggs on February 17, 2001 7:51:21 PM
ie
[Human]
AncestorRace=Mammal
...
[Elf]
AncestorRace=Mammal
...
[Human-Elf]
AncestorRace=Human,Elf
...
[Dragon]
AncestorRace=Lizard
...
By allowing ancestor races you can allow a race to inherit abilites from predefined races. Then have a pointer to the stats class(CPlayerStatLimits), and only have the current states in the actual char.
Edited by - ggs on February 17, 2001 7:51:21 PM
I''d still need to stick that data somewhere and a text file wouldn''t be the best solution here in this bot age . I can see the new superduperuberman class character, Ed, running around on a MP server with 1 zillion hit poins on a no frills clearance sale on the general populance
I''m not sure if C++ has this, but in java there is a keyword called static which makes it so that the variable is used for all the class objects. It is kind of like global. Example:
class Character
{
static int maxStrength;//global
int strength;//local
Character(int str)//constructor
{
if(strstrength=str;
else System.out.println("invalid value");
}
}
ok so now I want to set the maxStrength to 8, I just:
Character.maxStrength = 8;
Now I make a character:
Character c1 = new Character(6);
then I try this:
Character c2 = new Character(9); and it prints out an error.
Now if I want to raise the maxStrength I can do it two ways:
Character.maxStrength = 12;
c1.maxStrength = 12;
either works because it is the same variable, though the first option is strongly prefered. If you don''t want it changing then make it "final" which I think is the same as const, or make it private (actually protected would be better) and have a get and set methods.
class Character
{
static int maxStrength;//global
int strength;//local
Character(int str)//constructor
{
if(strstrength=str;
else System.out.println("invalid value");
}
}
ok so now I want to set the maxStrength to 8, I just:
Character.maxStrength = 8;
Now I make a character:
Character c1 = new Character(6);
then I try this:
Character c2 = new Character(9); and it prints out an error.
Now if I want to raise the maxStrength I can do it two ways:
Character.maxStrength = 12;
c1.maxStrength = 12;
either works because it is the same variable, though the first option is strongly prefered. If you don''t want it changing then make it "final" which I think is the same as const, or make it private (actually protected would be better) and have a get and set methods.
static, I keep forgetting that little keyword. That is an excellent approach.
static int aminmaxstats[NUM_CLASSES][]={10,20....];
I prefer just using a #define over a const for quick numbers. ggg''s approach will also be applicable if I implement binary and checksum format as opposed to text. Then I could just have a static variable that is defined by a static file loader.
The only problem with statics is that after a certain ''depth'' of inheritance, the pointer reference chain to the static can get quite deep. As all creatures in the character generation system will fit into the CPlayer class, this won''t be an issue.
static int aminmaxstats[NUM_CLASSES][]={10,20....];
I prefer just using a #define over a const for quick numbers. ggg''s approach will also be applicable if I implement binary and checksum format as opposed to text. Then I could just have a static variable that is defined by a static file loader.
The only problem with statics is that after a certain ''depth'' of inheritance, the pointer reference chain to the static can get quite deep. As all creatures in the character generation system will fit into the CPlayer class, this won''t be an issue.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement