train snippet

Original author: Joe Fabiano
Port to SmaugWiz by Zanthoris

Installation Instructions
-------------------------
1. In act_info.cpp add the following code:

/*****************************************************************\
* This is do_train ported over from Merc 2.1 to Smaug1.4          *
* by Joe Fabiano. If you have any questions about this snippet,   *
* email them to:  rinthos@yahoo.com.  Enjoy. :)  --Joe            *
*******************************************************************
*                           Train v1.0                            *
*******************************************************************
* Ported from Smaug 1.4 to SmaugWiz 2.01 by Zanthoris             *
* on 11/15/2000      Email: zanthoris@hotmail.com                 * 
\*****************************************************************/

void do_train(CCharacter *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    CCharacter *mob;
    int hp_gain = 0;
    int mana_gain = 0;
    int move_gain = 0; /* added for v1.2 */  
    short *pAbility;
    char *pOutput;
    int cost;    /*  the cost is in the form of practices (not gold).  -Joe */
	short MaxHp = ch->GetMaxHp();
	short MaxMove = ch->GetMaxMove();
	short MaxMana = ch->GetMaxMana();
    if (ch->IsNpc())
        return;

    /*
     * Check for trainer.
     */
    for(mob = ch->GetInRoom ()->first_person; mob; mob = mob->GetNextInRoom())
    {
      if(mob->IsNpc() && mob->IsAction(ACT_TRAIN))
         break;
    }
    if ( mob == NULL )
    {
        ch->SendText("You can't do that here.\n\r");
        return;
    }

    if ( argument[0] == '\0' )
    {
        sprintf( buf, "You have %d practice sessions.\n\r", ch->GetPractices());
        argument = "foo";
    }

    cost = 5;   /* the number of practices it costs to train an attribute that is not your prime attribute.
                        * Hp and Mana costs for training aren't affected by this setting.  -Joe
                        */

    if ( !str_cmp( argument, "str" ) )
    {
        if (ClassTable.GetAttrPrime(ch->GetClass()) == APPLY_STR)
            cost    = 3;     /* the cost to train strength if it is the prime attribute of your class -Joe*/
        pAbility    = &ch->perm_str;
        pOutput     = "strength";
    }

    else if ( !str_cmp( argument, "int" ) )
    {
        if (ClassTable.GetAttrPrime(ch->GetClass()) == APPLY_INT)
            cost    = 3;    /* the cost to train intelligence if it is the prime attribute of your class -Joe*/
        pAbility    = &ch->perm_int;
        pOutput     = "intelligence";
    } 

    else if ( !str_cmp( argument, "wis" ) )
    {
        if (ClassTable.GetAttrPrime(ch->GetClass()) == APPLY_WIS)
            cost    = 3;   /* the cost to train wisdom if it is the prime attribute of your class -Joe*/
        pAbility    = &ch->perm_wis;
        pOutput     = "wisdom";
    }

    else if ( !str_cmp( argument, "dex" ) )
    {
        if (ClassTable.GetAttrPrime(ch->GetClass()) == APPLY_DEX)
            cost    = 3;  /* the cost to train dexterity if it is the prime attribute of your class -Joe*/
        pAbility    = &ch->perm_dex;
        pOutput     = "dexterity";
    } 

    else if ( !str_cmp( argument, "con" ) )
    {
        if (ClassTable.GetAttrPrime(ch->GetClass()) == APPLY_CON)
            cost    = 3;  /* the cost to train constitution if it is the prime attribute of your class -Joe*/
        pAbility    = &ch->perm_con;
        pOutput     = "constitution";
    }  

    else if ( !str_cmp( argument, "cha" ) )
    {
        if (ClassTable.GetAttrPrime(ch->GetClass()) == APPLY_CHA)
            cost    = 3;  /* the cost to train charisma if it is the prime attribute of your class -Joe */
        pAbility    = &ch->perm_cha;
        pOutput     = "charisma";
    }

    else if ( !str_cmp( argument, "lck" ) )
    {
        if (ClassTable.GetAttrPrime(ch->GetClass()) == APPLY_LCK)
            cost    = 3;  /* the cost to train luck if it is the prime attribute of your class -Joe*/
        pAbility    = &ch->perm_lck;
        pOutput     = "luck";
    } 

    else if ( !str_cmp( argument, "hp" ) )
      {
        pAbility = &MaxHp;
        pOutput = "number of hit points";
        cost = 6;    /* this is cost to train hp once -Joe*/
        hp_gain = 10; /* this is hp gained by training hp once -Joe*/
      } 
/* new in v1.2 */
    else if ( !str_cmp( argument, "move" ) )
      {
       pAbility = &MaxMove;
       pOutput = "amount of movement";
       cost = 6;
       move_gain = 10;
      }

    else if ( !str_cmp( argument, "mana" ) )
      {
        pAbility = &MaxMana;
        pOutput = "amount of mana";
        cost =6;   /* this is the cost to train mana once -Joe*/
        mana_gain = 10;   /* this is the mana gained by training mana once -Joe*/
      } 

    else
    {
/* added move here for v1.2 */
   strcpy( buf, "You can train: hp mana move" );
        if ( ch->perm_str < 18 ) strcat( buf, " str" );
        if ( ch->perm_int < 18 ) strcat( buf, " int" );
        if ( ch->perm_wis < 18 ) strcat( buf, " wis" );
        if ( ch->perm_dex < 18 ) strcat( buf, " dex" );
        if ( ch->perm_con < 18 ) strcat( buf, " con" );
        if ( ch->perm_cha < 18 ) strcat( buf, " cha" );
        if ( ch->perm_lck < 18 ) strcat( buf, " lck" );

            strcat( buf, ".\n\r" );
            ch->SendText(buf);  


        return;
    } 

    if ( !str_cmp( argument, "hp" ) )
      {

        if ( cost > ch->GetPractices())
          {
            ch->SendText("You don't have enough practices.\n\r");
            return;
          }

             ch->AddPractices (-cost);
             *pAbility           += hp_gain;
                                 act(AT_RED, "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
                                 act(AT_RED, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
                                 return;
      } 
/* added this for v1.2 */
if ( !str_cmp( argument, "move" ) )
      {

        if ( cost > ch->GetPractices())
          {
            ch->SendText("You don't have enough practices.\n\r");
            return;
          }

             ch->AddPractices (-cost);
             *pAbility           += move_gain;
                                 act(AT_RED, "Your $T increases!", ch, NULL, pOutput, TO_CHAR ); 
                                 act(AT_RED, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
                                 return;
      }
  
if ( !str_cmp( argument, "mana" ) )
  {

        if ( cost > ch->GetPractices())
          {
            ch->SendText("You don't have enough practices.\n\r");
            return;
          }

            ch->AddPractices (-cost);
                                 *pAbility           += mana_gain;
                                 act(AT_RED, "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
                                 act(AT_RED, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
             return;
      }

    if ( *pAbility >= 18 )  /* 18 is the max you can train something to unless you change it here  -Joe */
   {                                     
        act(AT_RED, "Your $T is already at maximum.", ch, NULL, pOutput, TO_CHAR );
        return;
    }

    if ( cost > ch->GetPractices())
    {
        ch->SendText( "You don't have enough practices.\n\r");
        return;
    }  

    ch->AddPractices (-cost);
    *pAbility           += 1;
         act(AT_RED, "Your $T increases!", ch, NULL, pOutput, TO_CHAR);
         act(AT_RED, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM);
         return;
}   
/* the end of the train snippet -Joe*/

2. In smaug.h search for:

   DECLARE_DO_FUN(do_track); 

   and below that line add:

   DECLARE_DO_FUN(do_train);

3. In skills.cpp search for:

   if (!str_cmp (name, "do_track"))		return do_track;

   and below that line add:

   if (!str_cmp( name, "do_train"))              return do_train;

   also in skills.c search for:

   if (skill == do_track)			return "do_track";

   and below that line add:

   if (skill == do_train)          return "do_train";

4.   Make clean, then recompile.

And you should be set :)

After you start your mud up, type:
cedit train create do_train
cedit train level 1
cedit save

Players can now train stats at a trainer mob in addition to practicing skills/spells.


*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

This snippet was written for and tested on SmaugWiz version 2.01, I cannot guarantee that
it will work in previous versions without some modification (though I expect it will).  If
you have problems with this snippet let me know!

-=Zanthoris=-

zanthoris@hotmail.com
telnet:\\zanthoris.dhs.org:4000
http:\\zanthoris.home.dhs.org