Jump to content

  • Log In with Google      Sign In   
  • Create Account


OO Design Continuation


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Spyder   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 January 2001 - 07:19 AM

quote:
int Character::GetTotalModifiersTo(String stat) const {
// Loop through all effects. If the stat matches this one, apply the
// difference to the running total. Return the final amount
int total_modifier = 0;
EffectList::const_iterator eli;
for (eli = effects.begin(); eli != effects.end(); ++eli)
total_modifier += (*eli)->GetModifiersTo(stat);
return total_modifier; }

Kylotan posted this in the earlier thread that kinda went off topic. The code above works great for attributes, but what is a good way to implement skills that operate on the attributes? Should every skill be each own class? Diff player and NPC types may share some skills etc. Any ideas?

Sponsor:

#2 Kylotan   Moderators   -  Reputation: 3338

Like
Likes
Like

Posted 19 January 2001 - 11:45 AM

Stealing my code? I hope I get mentioned in the credits

To give an answer to your question, I''d need to know more about what you mean by "operate on". How about an example or two? In my system, skills tend to have little or no effect on attributes, so the 2 sub-systems are distinct and have little to no relationship with each other.

My skills are divided into several subclasses (Spell, Ability, Action, Language, etc) which are derived from a Skill interface. Each individual skill is an instance of one of the above, which are held in a master Skill Table. And each character who is capable of learning skills will have a structure that pairs up a reference to a skill to the degree that it is learned by that character.

#3 Spyder   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 January 2001 - 07:06 AM

Well I''m not interested in stealing any code. What does interest me is the OO design and your example on character modifiers was a good example.

Your skills example also made sense. Skills in my game will prob use stats to modify the outcome. Does anyone else have any other design thoughts on skills as classes.

#4 Kylotan   Moderators   -  Reputation: 3338

Like
Likes
Like

Posted 20 January 2001 - 02:38 PM

I was just joking about the code theft.

What do you mean by ''the outcome'' of skills? Are skills things that affect a character permanently, or do they just have transient effects... do they affect existing attributes, or are there special attributes that just relate to skills? As far as I can tell, there''s no reason why a simple adaptation of the code of mine that you posted wouldn''t work for what you describe... each Skill type would store a list of the Attributes that it modifies, and each Character could contain a list of the Skills that the character knows. Then, when querying a Character for any Attribute, you can loop through the Character''s list of Skills, which is likely to be stored as pointers or IDNumbers to some central Skill table, and from that, find out any modifiers to the given attribute.

Of course, this is not necessarily the most efficient way of doing it. Why loop through everything each time? Instead, whenever you learn a skill, you could directly increment the attribute, so long as you have a well-defined system for decrementing the attributes if and when a skill ''goes away''. Or, as an intermediate solution, still have the looping as originally described, except (a) have an attribute cache, (b) whenever the character is queried for attributes, loop through every skill and populate the attribute cache. Next time you query the character, you can get the value from the cache instead of looping through everything again. And © Have a boolean variable which stores whether the cache is valid or not. Whenever a character''s skills change, the validity variable should become false, meaning that the next query will have to check the individual skills again, upon which it will revalidate the cache and set the validity variable to true. (Some kind of Proxy or Facade pattern at work here, depending on how you do it.)

Oh, and by the way... I decided to implement ''Action'' skills (that is, skills that you explicitly invoke, such as a kind of attack) as a single class, rather than subclassing Action for each type of Action. I figured that using function pointers rather than inheritance would not only reduce the number of classes I was using (and thus my system''s complexity), but also allow for greater flexibility (mainly, changing functions and skill details at run-time).

#5 Spyder   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 February 2001 - 08:24 PM

quote:
My skills are divided into several subclasses (Spell, Ability, Action, Language, etc) which are derived from a Skill interface. Each
individual skill is an instance of one of the above, which are held in a master Skill Table. And each character who is capable of
learning skills will have a structure that pairs up a reference to a skill to the degree that it is learned by that character.


Examples of skills in my game would be: kick, trip, sneak, lockpick, backstab, read, write, gamble

Some skills would operate on attributes like Concentration would increase the attribute awareness, but like you say it''s easily done.

My major concerns are that every skill has somewhat unique functionality and I end up with billions of classes. Storing them all in a table sounds reasonable.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS