Character creation order

Posted by Tseris on Tue 27 Oct 2009 10:38 PM — 19 posts, 82,565 views.

#0
In stock 1.9 smaug during character creation it asks for the user to choose class, then race. This always seemed a little backward to me. Has anyone attempted to rearrange the order so it requests race choice first? Is it as simple as moving the get class section in the nanny function to be after the get race section?
Australia Forum Administrator #1
You need to change the order in which the state machine asks for things.

At the end of nanny_get_new_sex there are the lines:


   write_to_buffer( d, "\r\nSelect a class, or type help [class] to learn more about that class.\r\n[", 0 );
   buf[0] = '\0';

   for( iClass = 0; iClass < MAX_PC_CLASS; iClass++ )
   {
      if( class_table[iClass]->who_name && class_table[iClass]->who_name[0] != '\0' )
      {
         if( iClass > 0 )
         {
            if( strlen( buf ) + strlen( class_table[iClass]->who_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, class_table[iClass]->who_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_CLASS;


That is listing the current classes and asking which one you want (and setting the state machine to check your class).

Then at the end of nanny_get_new_class it lists your races and asks you to choose one:


   write_to_buffer( d, "\r\nYou may choose from the following races, or type help [race] to learn more:\r\n[", 0 );
   buf[0] = '\0';
   for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
   {
      if( iRace != RACE_VAMPIRE
          && race_table[iRace]->race_name && race_table[iRace]->race_name[0] != '\0'
          && !IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class )
          && str_cmp( race_table[iRace]->race_name, "unused" ) )
      {
         if( iRace > 0 )
         {
            if( strlen( buf ) + strlen( race_table[iRace]->race_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, race_table[iRace]->race_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_RACE;


So basically you swap those pieces of code around. At the end of getting their sex, you now list the races and ask which one they want. Then at the end of getting the races you list the classes and ask which one they want.

So now, at the end of nanny_get_new_class you now do what it does at the end of nanny_get_new_race, that is to ask for whether you want colour or not:


   write_to_buffer( d, "\r\nWould you like RIP, ANSI or no graphic/color support, (R/A/N)? ", 0 );
   d->connected = CON_GET_WANT_RIPANSI;

#2
Thats what I was hoping for. My only concern was that it might have a problem since each race can only be certain classes, and I didnt know if this dependancy somehow necessitated them being asked in the order that they are.
#3
Alright, so I tried that and after making sure my iRace and iClass were declared in the right places it compiled. When starting a new character it asked for race first just as I want, however it only listed one of the six races I have set up, and when I attempted to choose a race not on the list, it returned with "That is not a race."

Any thoughts?
Australia Forum Administrator #4
Well, see this line:


 && !IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class )


That is testing for the class restriction for the race (ie. only showing valid races for the class you selected). Now by asking for the race first, that would have to go, and rework it so you test for if the class is valid for the already-selected race.
#5
Ok thanks Nick, ill work on it.
#6
Okay. So I changed the order around, and then had to move a few things like where it prompts for rip/ansi/no color. It appears to work, asks for race first, lists the races appropriately. But then it would only allow you to pick one race. Any other choices and it would return with "that is not a race". So I commented out the class restriction line to see if that was interfering with it. But now it wont accept any of the choices, and returns with "that is not a race" no matter what is typed in. Heres the code, although its a little lengthy i left in the section before it so you could see if theres something out of place that Im not seeing. At the end of this starts the void nanny_get_new_class section.


void nanny_get_new_sex( DESCRIPTOR_DATA * d, char *argument )
{
   CHAR_DATA *ch;
   char buf[MAX_STRING_LENGTH];
   int iRace;

   ch = d->character;

   switch ( argument[0] )
   {
      case 'm':
      case 'M':
         ch->sex = SEX_MALE;
         break;
      case 'f':
      case 'F':
         ch->sex = SEX_FEMALE;
         break;
      default:
         write_to_buffer( d, "That's not a sex.\r\nWhat IS your sex? ", 0 );
         return;
   }
   
   write_to_buffer( d, "\r\nYou may choose from the following races, or type help [race] to learn more:\r\n[", 0 );
   buf[0] = '\0';
   for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
   {
      if( iRace != RACE_VAMPIRE
          && race_table[iRace]->race_name && race_table[iRace]->race_name[0] != '\0'
          && str_cmp( race_table[iRace]->race_name, "unused" ) )
      {
         if( iRace > 0 )
         {
            if( strlen( buf ) + strlen( race_table[iRace]->race_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, race_table[iRace]->race_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_RACE;
   
}

void nanny_get_new_race( DESCRIPTOR_DATA * d, const char *argument )
{
   CHAR_DATA *ch;
   char arg[MAX_STRING_LENGTH];
   int iRace;

   ch = d->character;
   argument = one_argument( argument, arg );
   if( !str_cmp( arg, "help" ) )
   {
      for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
      {
         if( toupper( argument[0] ) == toupper( race_table[iRace]->race_name[0] )
             && !str_prefix( argument, race_table[iRace]->race_name ) )
         {
            do_help( ch, argument );
            write_to_buffer( d, "Please choose a race: ", 0 );
            return;
         }
      }
      write_to_buffer( d, "No help on that topic.  Please choose a race: ", 0 );
      return;
   }


   for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
   {
      if( toupper( arg[0] ) == toupper( race_table[iRace]->race_name[0] )
          && !str_prefix( arg, race_table[iRace]->race_name ) )
      {
         ch->race = iRace;
         break;
      }
   }

   if( iRace == MAX_PC_RACE
       || !race_table[iRace]->race_name || race_table[iRace]->race_name[0] == '\0'
       /*|| iRace == RACE_VAMPIRE */
       /*|| IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class ) */
       || !str_cmp( race_table[iRace]->race_name, "unused" ) )
   {
      write_to_buffer( d, "That's not a race.\r\nWhat IS your race? ", 0 );
      return;
   }

   if( check_bans( ch, BAN_RACE ) )
   {
      write_to_buffer( d, "That race is not currently available.\r\nWhat is your race? ", 0 );
      return;
   }

}


Australia Forum Administrator #7
I put your code in and tested it. It worked after a fashion. ;)

What you didn't say was, that when you put in the race nothing happened. Then if you hit <enter> it said "that is not a race".

The reason is, that after it gets a correct race, in your code you didn't change the d->connected to CON_GET_NEW_CLASS. Since you basically did nothing after a good race was entered, it just asked for the race again, until you got bored and entered an invalid race (like hitting enter would do).

My nanny_get_new_race, which works and then moves on to asking for the class, is as follows (extra lines in bold):



void nanny_get_new_race( DESCRIPTOR_DATA * d, const char *argument )
{
   CHAR_DATA *ch;
   char arg[MAX_STRING_LENGTH];
   int iRace, iClass;
   char buf[MAX_STRING_LENGTH];


   ch = d->character;
   argument = one_argument( argument, arg );
   if( !str_cmp( arg, "help" ) )
   {
      for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
      {
         if( toupper( argument[0] ) == toupper( race_table[iRace]->race_name[0] )
             && !str_prefix( argument, race_table[iRace]->race_name ) )
         {
            do_help( ch, argument );
            write_to_buffer( d, "Please choose a race: ", 0 );
            return;
         }
      }
      write_to_buffer( d, "No help on that topic.  Please choose a race: ", 0 );
      return;
   }


   for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
   {
      if( toupper( arg[0] ) == toupper( race_table[iRace]->race_name[0] )
          && !str_prefix( arg, race_table[iRace]->race_name ) )
      {
         ch->race = iRace;
         break;
      }
   }

   if( iRace == MAX_PC_RACE
       || !race_table[iRace]->race_name || race_table[iRace]->race_name[0] == '\0'
       /*|| iRace == RACE_VAMPIRE */
       /*|| IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class ) */
       || !str_cmp( race_table[iRace]->race_name, "unused" ) )
   {
      write_to_buffer( d, "That's not a race.\r\nWhat IS your race? ", 0 );
      return;
   }

   if( check_bans( ch, BAN_RACE ) )
   {
      write_to_buffer( d, "That race is not currently available.\r\nWhat is your race? ", 0 );
      return;
   }

  
 
  // good race entered at this point

   write_to_buffer( d, "\r\nSelect a class, or type help [class] to learn more about that class.\r\n[", 0 );
   buf[0] = '\0';

   for( iClass = 0; iClass < MAX_PC_CLASS; iClass++ )
   {
      if( class_table[iClass]->who_name && class_table[iClass]->who_name[0] != '\0' )
      {
         if( iClass > 0 )
         {
            if( strlen( buf ) + strlen( class_table[iClass]->who_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, class_table[iClass]->who_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_CLASS;   
}


Amended on Thu 29 Oct 2009 10:19 PM by Nick Gammon
#8
Okay, awesome. Now, can I take the line


If (IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class ) )
{
      write_to_buffer( d, "That class is not available to you", 0 );
      return;
   }


and put it into


write_to_buffer( d, "\r\nSelect a class, or type help [class] to learn more about that class.\r\n[", 0 );
   buf[0] = '\0';

   for( iClass = 0; iClass < MAX_PC_CLASS; iClass++ )
   {
      if( class_table[iClass]->who_name && class_table[iClass]->who_name[0] != '\0' )
      {
         if( iClass > 0 )
         {
            if( strlen( buf ) + strlen( class_table[iClass]->who_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, class_table[iClass]->who_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_CLASS;   


to allow only certain choices?
#9
I attempted to do this in several places and got a mud crash as soon as a class was selected. Hrmm
Australia Forum Administrator #10
Tseris said:



If (IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class ) )
{
      write_to_buffer( d, "That class is not available to you", 0 );
      return;
   }



Apart from the strange upper-case "If", you need to rejig this a bit. They have already selected a race, right? So the race will be in ch->race, not iRace. The variable iRace may be undefined which could cause a crash. And they are currently selecting a class, so instead of ch->Class you need iClass.

You need to think about when these variables are set up.

So possibly this will work better:



if (IS_SET( race_table[ch->race]->class_restriction, 1 << iClass ) )
{
      write_to_buffer( d, "That class is not available to you", 0 );
      return;
   }


However I haven't actually tested it. Remember, gdb is your friend. If you can't get it to work, start up gdb, put a breakpoint in nanny_get_new_class (ie. type "break nanny_get_new_class") and then step through, checking variables as you go.

http://www.gammon.com.au/gdb
Canada #11
Just a thought, have you unset all the race dependencies for each class in-game?

What you said in the first post is right, I don't think this is as easy as it seems. And I'd hazard a guess to say it's the dependencies that are screwing things up. Sorry I can't offer any more insight than above.
Australia Forum Administrator #12
I'm not sure the whole thing makes a heap of difference. After all if you ask the race first, they may find the class they wanted isn't available. But if you ask for the class first they may find the race they wanted isn't available too.

I would prefer some sort of system of allowing them to keep changing all aspects until they are ready, eg.


Currently:

Name:   Agreramond
Class:  Warrior
Race:   Troll
Gender: Male

Type Y to accept the above, or change:
(N)ame, (C)lass, (R)ace, (G)ender ...


That way they can keep fiddling with their character until they get it right.
#13
So after messing with it quite a bit, the short story is that no, the code does not like it if you ask for race first, and this leads to mud crashing. I agree with Nick, that in theory it shouldnt matter because whichever you ask for first, it should check what the race/class restrictions are and then give you the appropriate choices. So what Ive decided to do is start over and try a different way.

I copied over the source code for the section so its back to how it was originally. But for my particular mud, since the name of the race and the name of the class are the same, id like to have it ask what class you want, and then automatically assign your race without giving you any prompt at all, and go immediately into asking for rip/ansi.

Id like to do this because as far as the players are concerned, there is no race/class distinction. If you're a Werewolf, youre a Werewolf, thats it. But in terms of game mechanics Im still using the race and class so I can take advantage of things like race based RIS's. Im just removing the text displaying race and class from the "do_score" output.

What would the syntax look like for coding in automatic assignment of race, based on what class you chose?
#14
ive got it to work just fine...only it doesn't display classes anymore and any new attempts to alter the code only causes it to not compile at all
Australia Forum Administrator #15
Impossible to help without seeing any of your changes, and what the error message is.
#16
You can always add in a race_restriction to the classes.

grep class_restriction in .c and .h files, see how it works?

define race_restriction in mud.h

and then from observing class_restriction, add in race_restriction to the classes... I believe the files you'll need to edit are act_wiz.c, and tables.c

Then just switch the class_restriction to race_restriction in comm.c

If (IS_SET( class_table[iClass]->race_restriction, 1 << ch->race ) )
{
write_to_buffer( d, "That class is not available to you", 0 );
return;
}


I hope this makes sense, it seemed like the logical fix to me, since you're wanting to switch the order... you need to make races restricted instead of classes?

It works for me in SmaugFUSS1.9 anyway.

That way you can have races before classes, and it wont show the classes that restrict the race as available in the list.
Amended on Thu 28 Jan 2010 06:11 AM by SirRoughknight
#17
I just realized how poorly I explained that... here:

in mud.h

struct class_type
{
   const char *who_name;   /* Name for 'who'    */
   EXT_BV affected;
   short attr_prime; /* Prime attribute      */
   short attr_second;   /* Second attribute     */
   short attr_deficient;   /* Deficient attribute     */
add--> int race_restriction;  /* Flags for illegal races  */
   int resist;
   int suscept;
   int weapon; /* First weapon         */
   int guild;  /* Vnum of guild room      */
   short skill_adept;   /* Maximum skill level     */
   short thac0_00;   /* Thac0 for level  0      */
   short thac0_32;   /* Thac0 for level 32      */
   short hp_min;  /* Min hp gained on leveling  */
   short hp_max;  /* Max hp gained on leveling  */
   bool fMana; /* Class gains mana on level  */
   short exp_base;   /* Class base exp    */
};


and in act_wiz.c

void do_showclass( CHAR_DATA* ch, const char* argument)
{
   char arg1[MAX_INPUT_LENGTH];
   char arg2[MAX_INPUT_LENGTH];
   struct class_type *Class;
   int cl, low, hi, i, ct;

   set_pager_color( AT_PLAIN, ch );

   argument = one_argument( argument, arg1 );
   argument = one_argument( argument, arg2 );
   if( arg1[0] == '\0' )
   {
      send_to_char( "Syntax: showclass <class> [level range]\r\n", ch );
      return;
   }
   if( is_number( arg1 ) && ( cl = atoi( arg1 ) ) >= 0 && cl < MAX_CLASS )
      Class = class_table[cl];
   else
   {
      Class = NULL;
      for( cl = 0; cl < MAX_CLASS && class_table[cl]; cl++ )
         if( !str_cmp( class_table[cl]->who_name, arg1 ) )
         {
            Class = class_table[cl];
            break;
         }
   }
   if( !Class )
   {
      send_to_char( "No such class.\r\n", ch );
      return;
   }
   pager_printf_color( ch, "&wCLASS: &W%s\r\n&wPrime Attribute: &W%-14s  &wWeapon: &W%-5d      &wGuild: &W%-5d\r\n",
                       Class->who_name, affect_loc_name( Class->attr_prime ), Class->weapon, Class->guild );
   pager_printf_color( ch, "&wSecond Attribute:  &W%-14s  &wDeficient Attribute:  &W%-14s\r\n",
                       affect_loc_name( Class->attr_second ), affect_loc_name( Class->attr_deficient ) );
   pager_printf_color( ch, "&wMax Skill Adept: &W%-3d             &wThac0 : &W%-5d     &wThac32: &W%d\r\n",
                       Class->skill_adept, Class->thac0_00, Class->thac0_32 );
   pager_printf_color( ch, "&wHp Min/Hp Max  : &W%-2d/%-2d           &wMana  : &W%-3s      &wExpBase: &W%d\r\n",
                       Class->hp_min, Class->hp_max, Class->fMana ? "yes" : "no ", Class->exp_base );
   pager_printf_color( ch, "&wAffected by:  &W%s\r\n", affect_bit_name( &Class->affected ) );
   pager_printf_color( ch, "&wResistant to: &W%s\r\n", flag_string( Class->resist, ris_flags ) );
   pager_printf_color( ch, "&wSusceptible to: &W%s\r\n", flag_string( Class->suscept, ris_flags ) );
   
   send_to_char( "Disallowed races: ", ch );
   for( i = 0; i < MAX_RACE; i++ )
   {
      if( IS_SET( Class->race_restriction, 1 << i ) )
      {
         ct++;
         ch_printf( ch, "%s ", race_table[.i]->race_name );
         if( ct % 6 == 0 )
            send_to_char( "\r\n", ch );
      }
   }
   if( ( ct % 6 != 0 ) || ( ct == 0 ) )
      send_to_char( "\r\n", ch );

   ct = 0;
   send_to_char( "Allowed races: ", ch );
   for( i = 0; i < MAX_RACE; i++ )
   {
      if( !IS_SET( Class->race_restriction, 1 << i ) )
      {
         ct++;
         ch_printf( ch, "%s ", race_table[.i]->race_name );
         if( ct % 6 == 0 )
            send_to_char( "\r\n", ch );
      }
   }

That was how mine looks. to prevent the forum from making it italic in I added a [.i] period in there, remove it in the code. Though it does display "unused" when you type showclass # Someone else might be able to clean that up, it eludes me.

in tables.c

search for KEY ( "Resist"

         case 'R':
add-->      KEY( "Races", Class->race_restriction, fread_number( fp ) );
            KEY( "Resist", Class->resist, fread_number( fp ) );
            break;


and...

search for fprintf( fpout, "Class       %d\n", cl );

below it add

fprintf( fpout, "Races     %d\n", Class->race_restriction );


then finally in comm.c

 write_to_buffer( d, "\r\nSelect a class, or type help [class] to learn more about that class.\r\n[", 0 );
   buf[0] = '\0';

   for( iClass = 0; iClass < MAX_PC_CLASS; iClass++ )
   {
      if( class_table[iClass]->who_name && class_table[iClass]->who_name[0] != '\0' 
		  && !IS_SET( class_table[iClass]->race_restriction, 1 << ch->race ) )

and...

 if( iClass == MAX_PC_CLASS
       || !class_table[iClass]->who_name
	   || IS_SET( class_table[iClass]->race_restriction, 1 << ch->race )
       || class_table[iClass]->who_name[0] == '\0' || !str_cmp( class_table[iClass]->who_name, "unused" ) )
   {
      write_to_buffer( d, "That's not a class.\r\nWhat IS your class? ", 0 );
      return;
   }
Amended on Thu 28 Jan 2010 06:00 AM by SirRoughknight
#18
On a side note the problem of races not showing up in the list sounds more like a RACE file being incorrectly numbered or the race.lst not set up properly.

Make sure all the races are numbered appropriately 0 - ##, and make sure they appear in descending order in the .lst file

Having two races with the same number or the race.lst out of order will really bugger things up.

race0.race
race1.race
race2.race
$

Otherwise with Nick's instructions switching the race/class functions around in nanny, and adding in race_restrictions like I did seems to work like a charm.