eldhamud/boards/
eldhamud/clans/
eldhamud/classes/
eldhamud/councils/
eldhamud/deity/
eldhamud/doc/
eldhamud/doc/DIKU/
eldhamud/doc/MERC/
eldhamud/doc/mudprogs/
eldhamud/houses/
eldhamud/src/o/CVS/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "mud.h"

void do_train( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    char buf2[20];
    CHAR_DATA *mob = NULL;
    int add_hp = 0;
    int add_mana = 0;
    short *AttrPerm;
    char *pOutput;
    int cost,cost1,cost2,cost3,cost4,cost5;  /* Urrgghh */
    buf[0] = '\0';
    buf2[0] = '\0';

    if ( IS_NPC(ch) )
    {
        send_to_char( "Not for NPCs.  Sorry.\n\r", ch );
        return;
    }

    /*
     * Check for trainer.
     */

     
    for ( mob = ch->in_room->first_person; mob; mob = mob->next_in_room )
      {
        if ( IS_NPC(mob) && IS_ACT_FLAG(mob, ACT_TRAINER) )
              break;
      }

    if ( mob == NULL  )
      {
        send_to_char( "You can't do that here.\n\r", ch );
        return;
      }

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

    cost = 8;

    if ( !str_cmp( argument, "str" ) )
      {
       
        if ( class_table[ch->class]->attr_second == APPLY_STR )
              cost    = 7;
        AttrPerm    = &ch->perm_str;
        pOutput     = "strength";
      }

    else if ( !str_cmp( argument, "str" ) )
      { 
    
        if ( class_table[ch->class]->attr_prime == APPLY_STR )
              cost    = 6;
        AttrPerm    = &ch->perm_str;
        pOutput     = "strength";  
      }

    else if ( !str_cmp( argument, "int" ) )
      {

        if ( class_table[ch->class]->attr_second == APPLY_INT )
              cost    = 6;
        AttrPerm   = &ch->perm_int;
        pOutput     = "intelligence";
      }

    else if ( !str_cmp( argument, "int" ) )
      {
        if ( class_table[ch->class]->attr_prime == APPLY_INT )
              cost    = 6;
        AttrPerm   = &ch->perm_int; 
        pOutput     = "intelligence";
      }

    else if ( !str_cmp( argument, "wis" ) )
      {
        if ( class_table[ch->class]->attr_second == APPLY_WIS )
              cost    = 7;
        AttrPerm    = &ch->perm_wis;
        pOutput     = "wisdom";
      }

    else if ( !str_cmp( argument, "wis" ) )
      {
        if ( class_table[ch->class]->attr_prime == APPLY_WIS ) 
              cost    = 7;
        AttrPerm    = &ch->perm_wis;
        pOutput     = "wisdom";
      }

    else if ( !str_cmp( argument, "dex" ) )
      {
        if ( class_table[ch->class]->attr_second == APPLY_DEX )
              cost    = 7;
        AttrPerm   = &ch->perm_dex;
        pOutput     = "dexterity"; 
      }

    else if ( !str_cmp( argument, "dex" ) )
      {
        if ( class_table[ch->class]->attr_prime == APPLY_DEX ) 
              cost    = 6;
        AttrPerm   = &ch->perm_dex; 
        pOutput     = "dexterity";
      }

    else if ( !str_cmp( argument, "con" ) )
      {
        if ( class_table[ch->class]->attr_second == APPLY_CON )
              cost    = 7;
        AttrPerm    = &ch->perm_con; 
        pOutput     = "constitution";
      }

    else if ( !str_cmp( argument, "con" ) )
      {
        if ( class_table[ch->class]->attr_prime == APPLY_CON )
              cost    = 6;
        AttrPerm    = &ch->perm_con;
        pOutput     = "constitution";
      }

    else if ( !str_cmp( argument, "hp" ) )
      {
        AttrPerm = &ch->max_hit;
        pOutput = "number of hit points";
        cost = 10;    /* this is pracs per "train hp" */
        add_hp = 10; /* this is hp gained per "train hp" */
      }

    else if ( !str_cmp( argument, "mana" ) )
      {
        AttrPerm = &ch->max_mana;
        pOutput = "amount of mana";
        cost = 10;
        add_mana = 10;
      }

    else

      {
        /* Work out the costs... */
        cost1=8 ;cost2=8 ;cost3=8 ;cost4=8 ;cost5=8;
        if ( class_table[ch->class]->attr_prime == APPLY_STR )
              cost1    = 6;
        if ( class_table[ch->class]->attr_second == APPLY_STR )
             cost1     = 7;       
        if ( class_table[ch->class]->attr_prime == APPLY_INT )
              cost2    = 6;
        if ( class_table[ch->class]->attr_second == APPLY_INT )
              cost2    = 7;
        if ( class_table[ch->class]->attr_prime == APPLY_WIS )
              cost3    = 6;
        if ( class_table[ch->class]->attr_second == APPLY_WIS )
              cost3    = 7;
        if ( class_table[ch->class]->attr_prime == APPLY_DEX )
              cost4    = 6;
        if ( class_table[ch->class]->attr_second == APPLY_DEX )
              cost4    = 7;
        if ( class_table[ch->class]->attr_prime == APPLY_CON )
              cost5    = 6;
        if ( class_table[ch->class]->attr_second == APPLY_CON )
              cost5    = 7;

        strcpy( buf, "You can train: hp (4)  mana (5)" );

        if ( ch->perm_str < 25 )
        {
            strcat( buf, "  str" );
            sprintf( buf2, " (%d)", cost1 );
            strcat( buf, buf2 );
        }
        if ( ch->perm_int < 25 )
        {
            strcat( buf, "  int" );
            sprintf( buf2, " (%d)", cost2 );
            strcat( buf, buf2 );
        }
        if ( ch->perm_wis < 25 )
        {
            strcat( buf, "  wis" );
            sprintf( buf2, " (%d)", cost3 );
            strcat( buf, buf2 );
        }
        if ( ch->perm_dex < 25 )
        {
            strcat( buf, "  dex" );
            sprintf( buf2, " (%d)", cost4 );
            strcat( buf, buf2 );
        }
        if ( ch->perm_con < 25 )
        {
            strcat( buf, "  con" );
            sprintf( buf2, " (%d)", cost5 );
            strcat( buf, buf2 );
        }
        if ( buf[strlen(buf)-1] != ':' )
          {
                strcat( buf, ".\n\r" );
                    send_to_char( buf, ch );
              }
         return;
      }



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

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

             ch->practice        -= 10;
/*             *AttrPerm           += add_hp;*/
             ch->max_hit         += add_hp;
             act( AT_ACTION, "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
             act( AT_ACTION, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
             return;
      }

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

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

             ch->practice        -= 10;
/*             *AttrPerm           += add_mana;*/
             ch->max_mana       += add_mana;

             act( AT_ACTION, "Your $T increases!", ch, NULL,  pOutput, TO_CHAR );
             act( AT_ACTION, "$n's $T increases!", ch, NULL,  pOutput, TO_ROOM );
             return;
      }
    
      if ( !str_cmp( argument, "str" ) )
      {
          if ( *AttrPerm >= 25 )
           {
            act( AT_ACTION, "Your $T is already at maximum.", ch,NULL, pOutput, TO_CHAR );
	    return;
            }

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

             ch->practice        -= cost;
/*             *AttrPerm           += add_mana;*/
             ch->perm_str       += 1;

             act( AT_ACTION, "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
             act( AT_ACTION, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
             return;
      }

      if ( !str_cmp( argument, "int" ) )
      {
          if ( *AttrPerm >= 25 )
           {
            act( AT_ACTION, "Your $T is already at maximum.", ch, NULL, pOutput, TO_CHAR );
            return;
            }

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

             ch->practice        -= cost;
/*             *AttrPerm           += add_mana;*/
             ch->perm_int       += 1;

             act( AT_ACTION, "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
             act( AT_ACTION, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
             return;
      }

      if ( !str_cmp( argument, "wis" ) )
      {
          if ( *AttrPerm >= 25 )
           {
            act( AT_ACTION, "Your $T is already at maximum.", ch, NULL, pOutput, TO_CHAR );
            return;
            }

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

             ch->practice        -= cost;
/*             *AttrPerm           += add_mana;*/
             ch->perm_wis       += 1;

             act( AT_ACTION, "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
             act( AT_ACTION, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
             return;
      }

      if ( !str_cmp( argument, "dex" ) )
      {
          if ( *AttrPerm >= 25 )
           {
            act( AT_ACTION, "Your $T is already at maximum.", ch, NULL, pOutput, TO_CHAR );
            return;
            }

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

             ch->practice        -= cost;
/*             *AttrPerm           += add_mana;*/
             ch->perm_dex       += 1;

             act( AT_ACTION, "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
             act( AT_ACTION, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
             return;
      }

      if ( !str_cmp( argument, "con" ) )
      {
          if ( *AttrPerm >= 25 )
           {
            act( AT_ACTION, "Your $T is already at maximum.", ch, NULL, pOutput, TO_CHAR );
            return;
            }

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

             ch->practice        -= cost;
/*             *AttrPerm           += add_mana;*/
             ch->perm_con       += 1;

             act( AT_ACTION, "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
             act( AT_ACTION, "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
             return;
      }
}