Wanted to know how to do this with remort

Posted by Mefestos on Sat 29 May 2004 08:54 PM — 9 posts, 34,680 views.

#0
I installed Xerves's remort code and do not like the way morts can remort to ALL remort classes, and want to restrict that to two or three specific classes per base class. However, having little experience with C, I have worked with the code for the remort for hours to no avail. If someone could help me with this, it would be greatly appreciated.
USA #1
Quote:

However, having little experience with C,...


This poses a serious challenge for an experienced coder with having to find a way to track which classes a char has "lived" and incorporating the necessary checks into the remort system. For a beginning coder, I would say this is night impossible. As many strange and seriously difficult projects as I've attempted in my time as a coder, this is a project I would still be wary of attempting due to the extreme complexity of the tracking needed. Were this in C++ I might consider adding a STL class object to the char data structure to track their "lives" but even that would be more difficult than I could justify the time and effort for I suspect.

Even if you did find a way to track the classes "lived" by a given character, would you allow remorts from any class lived or just from the most recent? Would you allow remorts into other base classes? Would you allow multiple remorts at all? Single remorts wouldn't be too bad an implementation I suppose if it was kept very simple.

Something like

Switch (ch->class)
case 'warrior':
knight
brigand
heretic
case 'rogue':
brigand
illusionist
assassin
case 'cleric':
sage
sorcerer
knight
case 'mage':
sorcerer
heretic
primalist


Granted, that's a very simplified pseudocode but the basic check structure is there for a single remort system.
#2
actually, there are checks already implemented to check, as you say, how many "lives" a char has had, called tiers. Its an entry in the pfile itself, and there is a set tier for each class as well. thats not my problem.

I have the classes set up to where, right now, the remort class for each base is 10 higher than the base class, ie. the remort (for now) of mage, which is class 0, is class 10. What i am having trouble with is adding a check to see if the character of a certain class is choosing the class that is 10 above their current class.

here is the code:


if (ch->level == LEVEL_HERO)
          ch->pcdata->tier++;
       for ( iClass = 9; iClass <= MAX_PC_CLASS; iClass++ )
       {
        if ( class_table[iClass]->who_name[0] != '\0' && class_table[iClass]->remort_class <= ch->pcdata->tier-1)
	   {
	     if (!str_cmp(arg, class_table[iClass]->who_name))
	           break;
	   }
       }
       if (iClass == MAX_PC_CLASS)
       {
          if (ch->level == LEVEL_HERO)
             ch->pcdata->tier--;
          send_to_char("That is not a valid class.\n\r", ch);
          return;


My first intuition was to add, right after (&& class_table[iClass]->remort_class <= ch->pcdata->tier-1) (&& class_table[iClass] == ch->class+10), but that crashes the damn mud. I just need to know what to add to make that check.
Amended on Sun 30 May 2004 05:29 PM by Mefestos
USA #3
you could check that by adding say 10 to the class but you would ahve to make 10 base classes then 10 teir 1 classes then 10 teir 2 classes etc.. then you can limit it to only pick the current class and the next class or something. wouldnt be super hard but making that many classes would suck :p
#4
Kinda like this?


if ( class_table[iClass]->who_name[0] != '\0' && class_table[iClass]->remort_class <= ch->pcdata->tier-1 && class_table[iClass] == ch->class+10)


Ive tried that already, and it not only causes a compile warning, saying something to the tune of 'comparing pointer and integer" or something, but also causes the mud to crash when i try to remort.

I just need to know how to do this check CORRECTLY.
USA #5
Hmm, I think you have called it wrong. The class_table is bascially a table of pointers to the classes. Thus, your warning. Try something like this:

[EDIT] I forgot to say why you were calling it wrong. If you look in mud.h under char_data, class is defined as sh_int (short integer), and is consequently a number. If you look at the class table which is defined in mud.h as:

extern		struct	class_type *	class_table	[MAX_CLASS];

You can see that the return type for the class_table is struct class_type, which is a pointer to an allocated class structure. So your statement is comparing a pointer of allocated space to a number, which does not work. Hopefully you understand the cocept now. :)
[/EDIT]


if ( class_table[iClass]->who_name[0] != '\0' && class_table[iClass]->remort_class <= ch->pcdata->tier-1 && class_table[iClass] == class_table[ch->class+10])


I'm not sure what you are trying to accomplish, but that will take away that compile warning and that crash bug hopefully.

Best of luck!
Amended on Wed 02 Jun 2004 05:00 AM by Nick Cash
#6
it does fix the compile warning, but it still crashes. I changed the code to look like this:

if (ch->level == LEVEL_HERO)
          ch->pcdata->tier++;
       for ( iClass = 9; iClass <= MAX_PC_CLASS; iClass++ )
       {
	 if ( class_table[iClass] != class_table[ch->class+10])
           {
	     ch->pcdata->tier--;
             send_to_char("That is not a valid class.\n\r", ch);
	       return;
	   }
        if ( class_table[iClass]->who_name[0] != '\0' && class_table[iClass]->remort_class <= ch->pcdata->tier-1)
	      {
                 if (!str_cmp(arg, class_table[iClass]->who_name))
	              break;
              }
       }
       if (iClass == MAX_PC_CLASS)
       {
          if (ch->level == LEVEL_HERO)
             ch->pcdata->tier--;
          send_to_char("That is not a valid class.\n\r", ch);
          return;
       }
    }


The only problem is now i can't remort to any class at all. I know its the second if that its not getting by, but i dont know what to do about it. any help, as always, is appreciated.
Canada #7
What is your core dumpl telling you in gdb? Try running it inside gdb, and do a back trace when it crashes to see which line the problem is.
#8
Thanks for all the help, but i ended up having to rewrite most of the code i posted. Its long, but it works, and thats what I am concerned about. Thanks for all the help that everyone submitted.