Hello. I have implemented classes and races into my mud and simplified the code for that part. The problem I had was how to let the mud know that the race/class combination was invalid without adding an aditional parameter to the function call. I came up with the following system and I'd like any comments and suggestions concerning it that anyone can offer. /* Race - Class combinations */ const bool race_class_ok[NUM_RACES][NUM_CLASSES] = { /* Race/Class Nec, Wil, Ele, Ran, Pal, Ber, Mon, Dru, Rog, Ass, Bla */ /* Human - 10 */ { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 }, /* Elf - 5 */ { 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 1 }, /* Dwarf - 5 */ { 0 , 0 , 1 , 0 , 0 , 1 , 1 , 1 , 1 , 0 , 0 }, /* Gnome - 5 */ { 1 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 0 }, /* Drow - 5 */ { 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 }, /* Orc - 5 */ { 0 , 0 , 0 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 } }; /* * Jurko, 24.02.1996 * Returns RACE_x if race is found and race/class combination matches * Returns RACE_x + NUM_RACES if race is found but r/c comb. doesn't match * Returns RACE_UNDEFINED if race is not found */ int parse_race(char *arg, int class) { int retval; for (retval = RACE_HUMAN; (retval < NUM_RACES); retval++) if (!strn_cmp(arg, pc_race_types[retval], strlen(arg))) if (class == CLASS_UNDEFINED) return retval; else if (race_class_ok[retval][class]) return retval; else return (retval + NUM_RACES); return RACE_UNDEFINED; } /* * Jurko, 24.02.1996 * Returns CLASS_x if class is found and race/class combination matches * Returns CLASS_x + NUM_CLASSES if class is found but r/c comb. doesn't match * Returns CLASS_UNDEFINED if class is not found */ int parse_class(char *arg, int race) { int retval; for (retval = 0; (retval < NUM_CLASSES); retval++) if (!strn_cmp(arg, pc_class_types[retval], strlen(arg))) if (race == RACE_UNDEFINED) return retval; else if (race_class_ok[race][retval]) return retval; else return (retval + NUM_CLASSES); return CLASS_UNDEFINED; } In the source, whenever these functions are called I just check if the return value is over NUM_CLASSES and if it is I don't allow that combination. (except for set class and set race commands which allow implementors only to set the class / race combination to a non-regular combination - just set it to return value - NUM_CLASSES.) Thanks in advance for any smart suggestions, Jurko
This archive was generated by hypermail 2b30 : 12/07/00 PST