/
area/city/
area/crypts/
area/guilds/
area/psuedowild/
area/religion/
data/documents/MPDocs/
data/html/
data/mobprogs/
data/quest/
data/world/
data/world/_utilities/
data/world/images/
design/html/
notes/
player/
#if defined(macintosh)
#include <types.h>
#include <time.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "interp.h"
#include "magic.h"
#include "experience.h"
#include "class.h"

#define ptc printf_to_char

const struct experience_type experience_table[] = {
        // Wizard       Cleric          Thief           Warrior
/*  0 */{  0,           0,              0,              0},
/*  1 */{  500,         450,            400,            300},
/*  2 */{  1000,        900,            800,            600},
/*  3 */{  2000,        1800,           1600,           1200},
/*  4 */{  4000,        3600,           3200,           2400},
/*  6 */{  8000,        7200,           6400,           4800},
/*  7 */{ 16000,        14400,          13800,          9000},
/*  8 */{ 30000,        28000,          26000,          20000},
/*  9 */{ 50000,        45000,          40000,          35000},
/* 10 */{ 90000,        80000,          70000,          60000},
/* 11 */{130000,       120000,         110000,         100000},
/* 12 */{150000,       140000,         130000,         120000},
/* 13 */{180000,       175000,         160000,         150000},
/* 14 */{220000,       210000,         200000,         200000},
/* 15 */{250000,       250000,         250000,         250000},
/* 16 */{350000,       350000,         350000,         350000},
/* 17 */{550000,       550000,         550000,         550000},
/* 18 */{850000,       850000,         850000,         850000},
/* 19 */{1250000,     1250000,        1250000,        1250000},
/* 20 */{1750000,     1750000,        1750000,        1750000},
/* 21 */{2250000,     2250000,        2250000,        2250000},
};

/*
 * gain_exp()
 *
 * Moved here for easy access
 */
#define LEVEL_HEROX         105
#define LEVEL_PLAYER_MAX    105

void gain_exp (CHAR_DATA * ch, int gain)
{
    char buf[MAX_STRING_LENGTH];
    int needed, x;
        
    if (IS_NPC (ch) || ch->level >= LEVEL_HEROX)
        return;

    /* Bleh, if 0, no message */
    if (gain == 0)
        return;
    
    ch->exp += gain;

    needed = exp_total_for_level2(ch->level);
        
    while (ch->exp >= needed)
    {
        if (ch->level >= 105)
        {
            stc("Heros cannot gain experience!\n\r", ch);
            return;
        }
        send_to_char ("{GYou raise a level!!\n\r{x", ch);
        ch->level += 1;
        advance_level_new (ch);
        save_char_obj (ch);
        
        needed = exp_total_for_level2(ch->level);
        
        for (x = 0; skill_table[x].name != NULL; x++)
        {
            if (skill_table[x].skill_level[ch->class] == ch->level)
            {
                ptc(ch, "You have gained knowledge of '%s'\n\r", skill_table[x].name);
                ch->pcdata->learned[skill_lookup(skill_table[x].name)] = 1;
            }
        }

        /* Messages */
        sprintf (buf, "%s gained level %d", ch->name, ch->level);
        log_string (buf);
        sprintf (buf, "$N has attained level %d!", ch->level);
        wiznet (buf, ch, NULL, WIZ_LEVELS, 0, 0);

    }
    return;
}

/*
 * advance_level_new()
 *
 * New Advance level code.
 */
void advance_level_new(CHAR_DATA * ch)
{
    int add_hp;
    int add_ma;
    int add_mv;
    char buf[MSL];
    
    ch->pcdata->last_level = (ch->played + (int) (current_time - ch->logon)) / 3600;
    add_hp = level_char_hp(ch);
    add_ma = level_char_mana(ch);
    add_mv = level_char_move(ch);
    ch->max_hit             += add_hp;
    ch->max_mana            += add_ma;
    ch->max_move            += add_mv;
    ch->pcdata->perm_hit    += add_hp;
    ch->pcdata->perm_mana   += add_ma;
    ch->pcdata->perm_move   += add_mv;
    ch->hit                 = ch->max_hit;
    ch->mana                = ch->max_mana;
    ch->move                = ch->max_move;
    ch->train               += 2;
    ch->practice            += 3;
    sprintf(buf, "You have attained level %d! You gained %d hitpoints, %d mana, and %d movement.\n\r",
        ch->level, add_hp, add_ma, add_ma);
    stc(buf, ch);
    
    return;
}

int exp_total_for_level (CHAR_DATA * ch)
{
    int xp_needed;

    xp_needed = ch->level * 200 * (ch->level * 1.5);

    return (xp_needed);
}

int exp_total_for_level2 (int level)
{
    int xp_needed;

    xp_needed = 200 + level * 200 * (level * 1.5);

    return (xp_needed);
}


int exp_needed_to_level (CHAR_DATA * ch)
{
    int xp_needed;
    int xp_current;
        
    if (ch->level >= 105)
        return -1;
        
    xp_current = ch->exp;
        
    xp_needed = exp_total_for_level2 (ch->level);
    
    return (xp_needed - xp_current);
}
                

void do_experience (CHAR_DATA * ch, char *argument)
{
    char buf[MSL];
    int count = 0;
        
    while (count != LEVEL_HEROX)
    {
        sprintf(buf, "Level %2d   - %d\n\r", count, exp_total_for_level2(count));
        stc(buf, ch);
        count++;
    }
}