Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Whirlwind

Logical Player Information Grouping

This topic is 6451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!