Re: [CODE] Multiclass problem

From: John Madrell (JMadrell@madz.demon.co.uk)
Date: 08/26/99


----- Original Message -----
From: Phillip A Ames <kirk47@JUNO.COM>
To: <CIRCLE@post.queensu.ca>
Sent: Thursday, August 26, 1999 1:04 AM
Subject:  [CODE] Multiclass problem


> Hi all, in my effort to perfect my multiclass code, I've hacked up a
> function that (should) tell the players how many times they can level in
> each different class, based on their current exp.  It's (appropriately)
> named 'level_check'.  Now, the problem is this.  Whenever a player gets
> any amount of exp, even if its 1 and they had 0 before, this is the
> output:

> void level_check(struct char_data *ch){
> int i, check_class_lev, num_levels;
> char classname[MAX_STRING_LENGTH+1];
>
> if(GET_LEVEL(ch) >= LVL_ORGANIAN)
>    return;
> sprintf(buf, ""); // Clear anything in buf since we use sprintf(buf +
> strlen(buf) ...)
>
> for(i = 0; i < NUM_CLASSES; i++){

fine

>
> for(check_class_lev = GET_CLASS_LEV(ch, i), check_class_lev++;
> GET_EXP(ch) > level_exp(check_class_lev); check_class_lev+=1){ // Check
> if they have enough XP to level, and how many times, in each class
>   num_levels++;

get rid of this or loop and use a while loop to get the number of levels
they can raise a class.  Also for each class before you check if it can be
raised you need to reset num_levels to 0.

    check_class_lev = GET_CLASS_LEV(ch,i);
    num_levels=0; // reset levels counter to 0
    check_class_lev++;
    while (GET_EXP(ch)>=level_exp(check_class_lev)){

   /* if in here (the while loop) they can level, stay in here while they
can
       level when it finishes the loop, num_levels holds the number of
levels
      this class can be raised */

         num_levels++;
        check_class_lev++;
    }

you might want to stick another control on the while loop to cover all bases
for errors
summat like && (check_class_lev<LEV_WHATEVER_YOUR_IMMORT_CLASS_IS)


> }
> if(num_levels > 0){
>     sprinttype(i, pc_class_types, classname);
>     sprintf(buf + strlen(buf), "You can rise %d level%s in: %s\r\n",
> num_levels, num_levels > 1 ? "" : "s", classname);
>         }
> }
>
> send_to_char(buf, ch);
>
> }
>

The code isnt tried and tested and double check the loop control as that is
usually where I make mistakes.

HTH

-Madz


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST