Jump to content
  • Advertisement
Sign in to follow this  
Son of Cain

Skill Tree

This topic is 4905 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

Hi, Straight to the matter... How to implement an hierarchy of skills? A basic skill must have a certain degree (percentage, points, whatever) in order to let the player advance for an advanced skill. Is the following way too crazy?
// I'm a BIG newbie in C++
class Skill {
  
  private:
    int points;
    int requirements;
    Skill* previous;
    Skill* next;

  public:
    Skill();
   ~Skill();
   int getReq();
   int getPts();
}

// Then, somewhere
if ( next->getReq() > skill->getPts() )
  // you can't get it 
else...
  // go on
Hope you understand my mumbling ;) Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement

const int MAX_SKILLS = 5;
const int MAX_REQUISITES = 3;

struct skill_data
{
char* name;
struct requisite_data;
{
int index;
int level;
} requisites[MAX_REQUISITES];
};

const skill_data skill_table[MAX_SKILLS]
{
{ "FOO", { 0 } }, // No prereqs (arrays get padded with 0)
{ "BAR", { 0, 5 } }, // req FOO 5 (again, 0-padded)
{ "BAZ", { 0, 10, 1, 2 } }, // req FOO 10, BAR 2
{ "QUX", { 0 } }, // No prereqs
{ "BLA", { 1, 5, 2, 5, 3, 10 } }, // req BAR 5, BAZ 5, QUX 10
};

class Player
{
int skills[MAX_SKILLS];
public:
bool is_skill_open(int index)
{
bool is_open = true;
const skill_data::requisite_data* requisites = skill_table[index].requisites;

for( int i = 0; i < MAX_REQUISITES; ++i)
is_open &= skills[requisites.index] >= requisites.level;

return is_open;
}
};

Share this post


Link to post
Share on other sites
There, of course, are other ways to do it, but this should give you an idea of how to get started.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!