Race/Class Implementation

  • h3dg3hug
  • h3dg3hug's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #9893 by h3dg3hug
Race/Class Implementation was created by h3dg3hug
Here's the setup: I have 4 races and 4 classes. I created 2 of the classes to be named the same as 2 of the races (Wyrm and Undead) -- if the player selects Wyrm or Undead as a race, I want to automatically assign the appropriate class to them, skip the class selection menu, and go right to the MOTD/game menu.
Here is the route I've been going down:
  case CON_QRACE:
    load_result = parse_race(*arg);
    if (load_result == RACE_UNDEFINED) {
      write_to_output(d, "\r\nThat's not a appropriate people group.\r\nYour people: ");
      return;
    } else
      GET_RACE(d->character) = load_result;
    if (load_result == RACE_WYRM){
      GET_CLASS(d->character) = CLASS_WYRM;
      STATE(d) = CON_RMOTD;
      return;
    } else if (load_result == RACE_UNDEAD) {
      GET_CLASS(d->character) = CLASS_UNDEAD;
      STATE(d) = CON_RMOTD;
      return;
    } else {
      write_to_output(d, "%s\r\nYour occupation: ", class_menu);
      STATE(d) = CON_QCLASS;
      break;
    
    case CON_QCLASS:
      load_result = parse_class(*arg);
      if (load_result == CLASS_UNDEFINED) {
        write_to_output(d, "\r\nThat's not a proper occupation.\r\nYour occupation: ");
        return;
      } else
        GET_CLASS(d->character) = load_result;
    }

I've tried a few different iterations of this tactic, but none have totally worked. This one just stalls if I select Wyrm from the race menu, until I hit enter again and it goes straight to the menu (bypassing MOTD). When I enter the game it displays the proper race/class in "who", but when I type "score" it crashes, which makes me think it's not actually being defined properly.

Please Log in or Create an account to join the conversation.

  • h3dg3hug
  • h3dg3hug's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #9894 by h3dg3hug
Replied by h3dg3hug on topic Race/Class Implementation
Nevermind, I removed the returns and the attempts to set STATE(d) = CON_QCLASS......

Seems to work as intended so far. Should I take down the post, or leave it up in case someone runs into a similar situation in the future? =)

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago #9895 by thomas
Replied by thomas on topic Race/Class Implementation
Leave it up :) Good work there.
The following user(s) said Thank You: h3dg3hug

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago #9901 by cunning
Replied by cunning on topic Race/Class Implementation
I use an array to match Class vs Race to accomplish the same thing. Makes it much more efficient then multiple if/then

case CON_QCLASS:
switch (*arg) {
case 't':
case 'T':
display_classes_help(d, FALSE);
STATE(d) = CON_CLASS_HELP;
return;
}

if (load_result == CLASS_UNDEFINED)
load_result = parse_class(d->character, atoi(arg), FALSE);

if (load_result == CLASS_UNDEFINED) {
write_to_output(d, "\r\nThat's not a class.\r\nClass: ");
return;
} else
GET_CLASS(d->character) = load_result;


int parse_class(struct char_data *ch, int arg, int remort)
{
int chclass = CLASS_UNDEFINED;

switch (arg) {
case 0 : chclass = CLASS_MAGIC_USER ; break;
case 1 : chclass = CLASS_CLERIC ; break;
case 2 : chclass = CLASS_THIEF ; break;
case 3 : chclass = CLASS_WARRIOR ; break;
default: chclass = CLASS_UNDEFINED ; break;
}

if (chclass >= 0 && chclass < NUM_CLASSES)
if (!class_ok_race[(int)GET_RACE(ch)][chclass])
chclass = CLASS_UNDEFINED;

int class_ok_race[NUM_RACES][NUM_CLASSES] = {
/* Cl1,CL2,CL3,CL4*/
/* RACE1 */ { Y, Y, Y, Y },
/* RACE2 */ { Y, Y, Y, Y },
/* RACE3 */ { Y, Y, Y, Y },
/* RACE4 */ { Y, Y, Y, Y },
/* RACE5 */ { Y, Y, Y, Y },
/* RACE6 */ { Y, Y, Y, Y },
/* RACE7 */ { Y, Y, Y, Y },
/* RACE8 */ { Y, Y, Y, Y },
/* RACE9 */ { Y, Y, Y, Y },
/* RACE10 */ { Y, Y, Y, Y },
/* RACE11 */ { Y, Y, Y, Y }
};

Please Log in or Create an account to join the conversation.

Time to create page: 0.141 seconds