Re: [CODE] Multiclass problem

From: Kelemvor (kelemvor@exilemud.com)
Date: 08/26/99


-----Original Message-----
Date:    Wed, 25 Aug 1999 20:04:39 -0400
From:    Phillip A Ames <kirk47@juno.com>
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:

You receive 38 experience points.
You can rise 1345210671 level in: Command
You can rise 1345210671 level in: Helm
You can rise 1345210672 level in: Communications
You can rise 1345210673 level in: Engineer
You can rise 1345210674 level in: Security
You can rise 1345210675 level in: Tactical
You can rise 1345210676 level in: Medical
You can rise 1345210677 level in: Operations
You can rise 1345210678 level in: Science
You can rise 1345210679 level in: Global

Obviously, something is wrong, since they should need about 29,962 exp
more to level 1 more level.  Here's the function, apologies in advance
for the ugliness in formatting, etc.


My first question is: Why the second for loop?

>void level_check(struct char_data *ch){

You might want to think about initializing these variables to 0 as well.

>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++){
>

At this point I'm lost.  I don't know why you are using this for loop if it
is just
to return the number of levels a player has gained in a particular class.
The first
'for loop' cycles through all the available classes, I'm guessing so, you
will get
one sprintf statement for each class the player gains in.  I can see that,
but, this
loop below seems unnecessary.  Now without knowing what function you have
that actually
advances the character's level in his data struct, I'm going to assume you
didn't.  Otherwise
the value of check_class_lev will only be accurate once.

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

First, the only variable you have to worry about for the print statement is
num_levels.
check_class_lev is not necessary, and I think causes more confustion.  If
you want to see
how many levels the player rises, you have to actually change the value of
their level for
whatever class you are looking at, for example:

/* while player's exp is greater than the exp required for 1 + their current
level in that class */
/* Once their exp is less than the exp needed for 1 + their current level
(i.e. they can't advance anymore) */
/* Then we drop out of the loop */

while (GET_EXP(ch) > level_exp((GET_CLASS_LEV(ch, i)+1)) {
    /* Advance their level in that class, so that the value of GET_CLASS_LEV
will get them out of the loop */
    GET_CLASS_LEV(ch, i)++;
    /* Add one to num_levels */
    num_levels++;
}

>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);
>
>}
>
>Now, I think the problem lies in the for loop(d'uh).  But I, for the life
>of me, can't figure it out.  And in case you were wondering, level_exp is
>being called properly - each class has the exact same amount of XP needed
>to level for each different level, so I need no class integer at the end
>of calling it.  And in the code where it advances them a level, it will
>subtract the amount of XP they needed to level from their EXP so I know
>THAT isn't the problem.  Thanks in advance for any help you guys can
>offer,
>
>-Phillip

--
Kelemvor - Forger Coder
Exile - A home for the banished
http://www.exilemud.com
exilemud.com 6666


     +------------------------------------------------------------+
     | 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