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 }
};