Hello,

This only mildly pertains to ROM, but this place has been a rich resource of information in the past, plus the project I am working on is a server based on
ROM, so hey.

Enough ennui, now on to the question (you can skip way down if you'd like):

I'm rebuilding skills for increased flexibility and semi-realtime skill
creation. Skills are creatable online and can potentially have four different
functions:
1) An on-cast function;
2) An on-pulse function (adjustable pulse--i.e. a napalm spell, keep burning on
                       each pulse);
2) An on-upkeep function (caster pays mana to keep spell up);
2) An on-expiration function.


This is how it is currently done:

class Skill
{
   public:
       string name;
       int mana;
       ...
       SKILL_FUN *cast_code;
       SKILL_FUN *pulse_code;
       SKILL_FUN *upkeep_code;
       SKILL_FUN *expire_code;
};

Since the MUD automatically creates the functions for you when you add new
skills, it has to write out header files, function templates, and function
tables:
On save/new skill:
"skill_code.h" <-- appended to for each new skill.
DECLARE_SKILL_FUN( x_cast_code );
DECLARE_SKILL_FUN( x_pulse_code );
DECLARE_SKILL_FUN( x_upkeep_code );
DECLARE_SKILL_FUN( x_expire_code );

"skill_code.c" <-- appended to for each new skill.
SKILL_RET x_cast_code (CHAR_DATA *ch, const char *argument)
{
   return DEFAULT_RETURN;
}
...

"skill_c.h" <--rewritten each time Skills save.
const struct skill_code_type skill_code_table[] =
{
   {"x", x_cast_code, x_pulse_code, x_upkeep_code, x_expire_code}
};

int MAX_SKILL = 1;

const int COMPILED_MAX_SKILL = 1;

--------
Now for when skills load:
bool Skill::assign_code(const int foo)
{
   bool ret_val = false;

   //if foo >= COMPILED_MAX_SKILL then it is a new skill that
   //does not have any functions yet compiled into the game.
   //You must recompile for newly-added skills to be linked
   //to their functions.
   if (foo >= 0 && foo < COMPILED_MAX_SKILL)
   {
       //gsn = skill_code_table[foo].gsn;
       //*gsn = foo;
       cast_code = skill_code_table[foo].cast_code;
       pulse_code = skill_code_table[foo].pulse_code;
       upkeep_code = skill_code_table[foo].upkeep_code;
       expire_code = skill_code_table[foo].expire_code;
       ret_val = true;
   }

   return ret_val;
}

--------
So now on load skills have their functions attached to them.  However, I've
recently come back to the code and realized that this is fundamentally weak:
I want the Skill functions to be inherent to the Skill.  That is, I want
to be able to do this (for ex.):

SKILL_RET Skill::x_cast_code (CHAR_DATA *ch, const char *argument)
{
   if (ch->mana < mana)
       return CAST_FAILURE;
ch_printf(ch, "Casting %s...\n\r", name.c_str());
   return DEFAULT_RETURN;
}

Where "name" and "mana" are class members.

This way each Skill knows itself and can look at its own mana costs, target
flags, and so on.  If this function does not belong to the Skill class, I'd
have to pass something for the skill to "find itself" in the array of skills
to check costs and so on.  This is problematic--I have the Skill functions
defined as ROM functions--e.g. (ch, argument) functions:
typedef SKILL_RET SKILL_FUN (CHAR_DATA *, const char *);

Anyone have any idea how I can these functions "belong" to skills without
getting this problem? :

[EMAIL PROTECTED] src $ make
g++ skill_code.c -Wall -O -ggdb -I -Dunix -DNOCRYPT -c -o obj/skill_code.o
skill_code.c:19: error: no `bool Skill::x_cast_code(CHAR_DATA*, const
  char*)' member function declared in class `Skill'


Thank you if you can throw me a couple of pointers.

-- Jeremy

Reply via email to