Re: Class Restrictions

From: Edward (dustlos@hotmail.com)
Date: 09/21/01


Well, I went a complex but working way, it may or may not be one way to do
it, I made two functions, one would look at the current player and decide
which classes they can be in (it goes through a list of classes and checks
them and builds an array of strings with the classes names in the them),
another function takes an input from the player and then it builds another
array of strings and then does a strcmp between the input and the list of
classes; its bulky for certain, but it is dynamic...

I made a structure for classes and races and put all relevant information
and restrictions in them.

Here is my code, obviously it won't work for your MUD directly but should
be easy to change:
classes and races are the structures.

void do_list_playerinfo(struct char_data *ch) {
 int i = 0, j = 0;

    sprintf(buf, "Listing of classes/races/stats:\r\n");
    send_to_char(buf, ch);

    sprintf(buf, "                     ");
    for (i = 0; i < NUM_OF_RACES; i++) {
  sprintf(buf+strlen(buf),
          "%s ", races[i].abbrev);
 }
 send_to_char(buf, ch);
 send_to_char("\r\n", ch);

 // Check if they can be a race depedent on the class
 for (i = 0; i < NUM_CLASSES; i++) {
  sprintf(buf, "%-20s", classes[i].name);
  for (j = 0; j < NUM_OF_RACES; j++) {
   if (classes[i].allowed_races[j] == 1) {
    sprintf(buf+strlen(buf), "  *");
   }
   else {
    sprintf(buf+strlen(buf), "   ");
   }
  }
  send_to_char(buf, ch);
  send_to_char("\r\n", ch);
 }

 // See if they can be a class depedent on their stats
 for (i = 0; i < NUM_CLASSES; i++) {
  sprintf(buf, "%-20s", classes[i].name);
  for (j = 0; j < 6; j++) {
   sprintf(buf+strlen(buf), "%-4d", classes[i].stats_needed[j]);
  }
  send_to_char(buf, ch);
  send_to_char("\r\n", ch);
 }
}

int parse_general_class(char *arg, struct descriptor_data *d) {
  int i = 0;
  char *gofer = str_dup(arg);
  const char *def_classes[NUM_CLASSES][1];

 // Put NONE in the entire array of strings
  for (i = 0; i < NUM_CLASSES; i++)
     def_classes[i][0] = str_dup("NONE");

 // Do the actual checking
  for (i = 0; i < NUM_CLASSES; i++) {
    if (!classes[i].allowed_races[(int)GET_RACE(d->character)])
       continue;
    if (classes[i].stats_needed[R_STR] > GET_STR(d->character))
       continue;
    if (classes[i].stats_needed[R_DEX] > GET_DEX(d->character))
       continue;
    if (classes[i].stats_needed[R_CON] > GET_CON(d->character))
       continue;
    if (classes[i].stats_needed[R_INT] > GET_INT(d->character))
       continue;
    if (classes[i].stats_needed[R_WIS] > GET_WIS(d->character))
       continue;
    if (classes[i].stats_needed[R_CHA] > GET_CHA(d->character))
       continue;
    def_classes[i][0] = str_dup(classes[i].name);
  }

  // Now run the comparisons
  for (i = 0; i < NUM_CLASSES; i++) {
    if (!strcmp(def_classes[i][0], "NONE"))
       continue;
    if (is_abbrev(gofer, def_classes[i][0]))
       return i;
  }
  return CLASS_UNDEFINED;
}

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



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