Re: [QUESTION][CODE] Skill/Spell Choosing: Tree Structure

From: Edward Felch (
Date: 06/17/01

Well so far I have made progress in this using the prereq like college
courses. However, I've run into a problem where it doesn't seem to be doing
it correctly, thus far I have this:

A new class called Adventurer

Added this into the spell structure in spells.h:
   int prereq[3]; // 2 skills, then a min level

Added in the command learn in act.other.c:
  if (IS_NPC(ch))
  if (!IS_ADVENTURER(ch)) {
  one_argument(argument, arg);
  if (*arg)
    send_to_char("You can only learn skills at a teacher.\r\n", ch);

Added in a function in class.c:
void init_adven_spells(void) {
  adven_decla(SKILL_KICK, -1, -1, 1);
  adven_decla(SKILL_BASH, SKILL_KICK, -1, 2);

Added in this to spell_parser.c:
void adven_decla(int spell, int pre1, int pre2, int level)
  int bad = 0;
  if (spell < 0 || spell > TOP_SPELL_DEFINE) {
    log("SYSERR: attempting assign to illegal spellnum %d/%d", spell,
  if (level < 1 || level > LVL_IMPL) {
    log("SYSERR: assigning '%s' to illegal level %d/%d.", skill_name(spell),
                level, LVL_IMPL);
    bad = 1;
  if (!bad) {
    spell_info[spell].prereq[0] = pre1;
    spell_info[spell].prereq[1] = pre2;
    spell_info[spell].prereq[2] = level;

And in spello threw this in:
  for (i = 0; i < 3; i++)
    spell_info[spl].prereq[i] = -2;

In spec_procs.c I added this function, check_level(struct char_data *ch, int
skill) checks to see if a player knows/can use that spell or skill, returns
true if they can, false if they cant:
void list_learnable(struct char_data * ch)
  int i;

  sprintf(buf, "You could learn the following:\r\n");

  for (i = 1; i <= MAX_SKILLS; i++) {
    if (strlen(buf) >= MAX_STRING_LENGTH - 32) {
      strcat(buf, "**OVERFLOW**\r\n");
    if (spell_info[i].prereq[0] > 0)
      if (!check_level(ch, spell_info[i].prereq[0]))

    if (spell_info[i].prereq[1] > 0)
      if (!check_level(ch, spell_info[i].prereq[1]))

    if (spell_info[i].prereq[2] > 0)
      if (GET_LEVEL(ch) < spell_info[i].prereq[2])

    if (check_level(ch, i))

    if (strcmp(spell_info[i].name, "!UNUSED!")) {
      sprintf(buf2, "%-20s\r\n", spell_info[i].name);
      strcat(buf, buf2);
  page_string(ch->desc, buf, 1);

In db.c this is what I have for bootup:
  log("Assigning spell and skill levels.");

The problem is, typing learn either lists all the skills for a new
adventurer (it should only list kick, [not bash since bash needs kick]), or
in the case of an IMP who has skillsetted kick and bash to 0, it lists

[5000/5000 5000/5000 5000/5000][]
You change Dust's kick to 0.

[5000/5000 5000/5000 5000/5000][]
You could learn the following:

i'm pretty sure its something stupid, I just hope it isn't too stupid... I
tried to use an array to contain the prerequired skills and the level but
that didn't seem to work out very well. Thanks for any input!
Get your FREE download of MSN Explorer at

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/05/01 PST