Sign in to follow this  

Skill Tree

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

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[i].index] >= requisites[i].level;

return is_open;
}
};

Share this post


Link to post
Share on other sites

This topic is 4692 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this