magic.c

dotd-2.3.7/src/magic.c · 241.0 KB

From the archive dotd-2.3.7.tar.bz2

Download the archive   « Back to the archive contents

/****************************************************************************
 * [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame      |   \\._.//   *
 * -----------------------------------------------------------|   (0...0)   *
 * SMAUG 1.0 (C) 1994, 1995, 1996 by Derek Snider             |    ).:.(    *
 * -----------------------------------------------------------|    {o o}    *
 * SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus,      |   / ' ' \   *
 * Scryn, Rennard, Swordbearer, Gorog, Grishnakh and Tricops  |~'~.VxvxV.~'~*
 * ------------------------------------------------------------------------ *
 * Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael        *
 * Chastain, Michael Quan, and Mitchell Tse.                                *
 * Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,          *
 * Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.     *
 * ------------------------------------------------------------------------ *
 *			     Spell handling module			    *
 ****************************************************************************/

/*static char rcsid[] = "$Id: magic.c,v 1.103 2004/04/06 22:00:10 dotd Exp $";*/

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <time.h>

#include "mud.h"
#include "gsn.h"
#include "poly.h"
#include "rareobj.h"

DECLARE_DO_FUN(do_look);
DECLARE_DO_FUN(do_recall);
DECLARE_DO_FUN(do_cast);

extern bool fBootDb;
extern int top_affect;
extern int top_room_vnum;

/*
 * Local functions.
 */
void	say_spell	args( ( CHAR_DATA *ch, int sn ) );
CHAR_DATA *make_poly_mob args( (CHAR_DATA *ch, int vnum) );
ch_ret	spell_affect	args( ( int sn, int level, CHAR_DATA *ch, void *vo ) );
ch_ret	spell_affectchar args( ( int sn, int level, CHAR_DATA *ch, void *vo ) );

/*
 * Is immune to a damage type
 */
bool is_immune( CHAR_DATA *ch, SKILLTYPE *skill )
{
    AFFECT_DATA *paf;
    int sn;

    if (!ch)
	return FALSE;

    if (number_percent() < ch->antimagicp)
        return TRUE;

    switch( SPELL_DAMAGE(skill) )
    {
    case SD_FIRE:	     if (IS_IMMUNE(ch, RIS_FIRE))	 return TRUE;
    case SD_COLD:	     if (IS_IMMUNE(ch, RIS_COLD))	 return TRUE;
    case SD_ELECTRICITY:     if (IS_IMMUNE(ch, RIS_ELECTRICITY)) return TRUE;
    case SD_ENERGY:	     if (IS_IMMUNE(ch, RIS_ENERGY)) 	 return TRUE;
    case SD_ACID:	     if (IS_IMMUNE(ch, RIS_ACID))	 return TRUE;
    case SD_POISON:	     if (IS_IMMUNE(ch, RIS_POISON)) 	 return TRUE;
    case SD_DRAIN:	     if (IS_IMMUNE(ch, RIS_DRAIN))	 return TRUE;
    case SD_NONE: return FALSE;
    }

    if (!(sn = skill_lookup(skill->name)))
        return FALSE;

    for ( paf = ch->first_affect; paf; paf = paf->next )
        if ( paf->location == APPLY_IMMUNESPELL )
            if ( paf->modifier == sn )
                return TRUE;

    return FALSE;
}

/*
 * Lookup a skill by name, only stopping at skills the player has.
 */
int ch_slookup( CHAR_DATA *ch, const char *name )
{
    int sn;

    if ( IS_NPC(ch) && !IS_ACT_FLAG(ch, ACT_POLYMORPHED))
        return skill_lookup( name );
    for ( sn = 0; sn < top_sn; sn++ )
    {
        if ( !skill_table[sn]->name )
            break;
        if (  LEARNED(ch, sn) > 0
              &&    CanUseSkill(ch, sn)
              &&    LOWER(name[0]) == LOWER(skill_table[sn]->name[0])
              &&   !str_prefix( name, skill_table[sn]->name ) )
            return sn;
    }

    return -1;
}

/*
 * Lookup an herb by name.
 */
int herb_lookup( const char *name )
{
    int sn;

    for ( sn = 0; sn < top_herb; sn++ )
    {
        if ( !herb_table[sn] || !herb_table[sn]->name )
            return -1;
        if ( LOWER(name[0]) == LOWER(herb_table[sn]->name[0])
             &&  !str_prefix( name, herb_table[sn]->name ) )
            return sn;
    }
    return -1;
}

/*
 * Lookup a personal skill
 */
int personal_lookup( CHAR_DATA *ch, const char *name )
{
    return -1;
}

/*
 * Lookup a skill by name.
 */
int skill_lookup( const char *name )
{
    int sn;

    if ( (sn=bsearch_skill_exact(name, gsn_first_spell, GSN_LAST_SPELL)) != -1 )
        return sn;

    if ( (sn=bsearch_skill_exact(name, gsn_first_skill, GSN_LAST_SKILL)) != -1 )
        return sn;

    if ( (sn=bsearch_skill_exact(name, gsn_first_weapon, GSN_LAST_WEAPON)) != -1 )
        return sn;

    if ( (sn=bsearch_skill_exact(name, gsn_first_tongue, GSN_LAST_TONGUE)) != -1 )
        return sn;

    if ( (sn=bsearch_skill_exact(name, gsn_first_lore, GSN_LAST_LORE)) != -1 )
        return sn;

    if ( (sn=bsearch_skill_exact(name, gsn_first_psispell, GSN_LAST_PSISPELL)) != -1 )
	return sn;

    if ( (sn=bsearch_skill(name, gsn_first_spell, GSN_LAST_SPELL)) != -1 )
        return sn;

    if ( (sn=bsearch_skill(name, gsn_first_skill, GSN_LAST_SKILL)) != -1 )
        return sn;

    if ( (sn=bsearch_skill(name, gsn_first_weapon, GSN_LAST_WEAPON)) != -1 )
        return sn;

    if ( (sn=bsearch_skill(name, gsn_first_tongue, GSN_LAST_TONGUE)) != -1 )
        return sn;

    if ( (sn=bsearch_skill(name, gsn_first_lore, GSN_LAST_LORE)) != -1 )
        return sn;

    if ( (sn=bsearch_skill(name, gsn_first_psispell, GSN_LAST_PSISPELL)) != -1 )
        return sn;

    if ( gsn_top_sn < top_sn )
    {
        for ( sn = gsn_top_sn; sn < top_sn; sn++ )
        {
            if ( !skill_table[sn] || !skill_table[sn]->name )
                return -1;
            if ( LOWER(name[0]) == LOWER(skill_table[sn]->name[0]) &&
                 !str_cmp( name, skill_table[sn]->name ) )
                return sn;
        }

        for ( sn = gsn_top_sn; sn < top_sn; sn++ )
        {
            if ( !skill_table[sn] || !skill_table[sn]->name )
                return -1;
            if ( LOWER(name[0]) == LOWER(skill_table[sn]->name[0]) &&
                 !str_prefix( name, skill_table[sn]->name ) )
                return sn;
        }
        bug("skill_lookup: unknown skill: %s", name);
    }

    return -1;
}

/*
 * Return a skilltype pointer based on sn			-Thoric
 * Returns NULL if bad, unused or personal sn.
 */
SKILLTYPE *get_skilltype( int sn )
{
    if ( sn >= TYPE_PERSONAL )
        return NULL;
    if ( sn >= TYPE_HERB )
        return IS_VALID_HERB(sn-TYPE_HERB) ? herb_table[sn-TYPE_HERB] : NULL;
    if ( sn >= TYPE_HIT )
        return NULL;
    return IS_VALID_SN(sn) ? skill_table[sn] : NULL;
}

/*
 * Perform a binary search on a section of the skill table	-Thoric
 * Each different section of the skill table is sorted alphabetically
 */
int bsearch_skill( const char *name, int first, int top )
{
    int sn;

    for (;;)
    {
        sn = (first + top) >> 1;

        if ( LOWER(name[0]) == LOWER(skill_table[sn]->name[0])
             &&  !str_prefix(name, skill_table[sn]->name) )
            return sn;
        if (first >= top)
            return -1;
        if (strcmp(name, skill_table[sn]->name) < 1)
            top = sn - 1;
        else
            first = sn + 1;
    }
    return -1;
}

/*
 * Perform a binary search on a section of the skill table	-Thoric
 * Each different section of the skill table is sorted alphabetically
 * Check for exact matches only
 */
int bsearch_skill_exact( const char *name, int first, int top )
{
    int sn;

    for (;;)
    {
        sn = (first + top) >> 1;
        if ( !str_cmp(name, skill_table[sn]->name) )
            return sn;
        if (first >= top)
            return -1;
        if (strcmp(name, skill_table[sn]->name) < 1)
            top = sn - 1;
        else
            first = sn + 1;
    }
    return -1;
}

/*
 * Perform a binary search on a section of the skill table
 * Each different section of the skill table is sorted alphabetically
 * Only match skills player knows				-Thoric
 */
int ch_bsearch_skill( CHAR_DATA *ch, const char *name, int first, int top )
{
    int sn;

    for (;;)
    {
        sn = (first + top) >> 1;

        if ( LOWER(name[0]) == LOWER(skill_table[sn]->name[0])
             &&  !str_prefix(name, skill_table[sn]->name)
             &&   LEARNED(ch, sn) > 0
             &&   CanUseSkill(ch, sn) )
            return sn;
        if (first >= top)
            return -1;
        if (strcmp( name, skill_table[sn]->name) < 1)
            top = sn - 1;
        else
            first = sn + 1;
    }
    return -1;
}


int find_spell( CHAR_DATA *ch, const char *name, bool know )
{
    if ( IS_NPC(ch) || !know )
        return bsearch_skill( name, gsn_first_spell, GSN_LAST_SPELL );
    else
        return ch_bsearch_skill( ch, name, gsn_first_spell, GSN_LAST_SPELL  );
}

int find_skill( CHAR_DATA *ch, const char *name, bool know )
{
    if ( IS_NPC(ch) || !know )
        return bsearch_skill( name, gsn_first_skill, GSN_LAST_SKILL );
    else
        return ch_bsearch_skill( ch, name, gsn_first_skill, GSN_LAST_SKILL  );
}

int find_weapon( CHAR_DATA *ch, const char *name, bool know )
{
    if ( IS_NPC(ch) || !know )
        return bsearch_skill( name, gsn_first_weapon, GSN_LAST_WEAPON);
    else
        return ch_bsearch_skill( ch, name, gsn_first_weapon, GSN_LAST_WEAPON );
}

int find_tongue( CHAR_DATA *ch, const char *name, bool know )
{
    if ( IS_NPC(ch) || !know )
        return bsearch_skill( name, gsn_first_tongue, GSN_LAST_TONGUE );
    else
        return ch_bsearch_skill( ch, name, gsn_first_tongue, GSN_LAST_TONGUE );
}

int find_lore( CHAR_DATA *ch, const char *name, bool know )
{
    if ( IS_NPC(ch) || !know )
        return bsearch_skill( name, gsn_first_lore, GSN_LAST_LORE );
    else
        return ch_bsearch_skill( ch, name, gsn_first_lore, GSN_LAST_LORE );
}

int find_psispell( CHAR_DATA *ch, const char *name, bool know )
{
    if ( IS_NPC(ch) || !know )
        return bsearch_skill( name, gsn_first_psispell, GSN_LAST_PSISPELL );
    else
        return ch_bsearch_skill( ch, name, gsn_first_psispell, GSN_LAST_PSISPELL  );
}


/*
 * Lookup a skill by slot number.
 * Used for object loading.
 */
int slot_lookup( int slot )
{
    int sn;

    if ( slot <= 0 )
        return -1;

    for ( sn = 0; sn < top_sn; sn++ )
        if ( slot == skill_table[sn]->slot )
            return sn;

    if ( fBootDb )
    {
        bug( "Slot_lookup: bad slot %d.", slot );
        /*	abort( );*/
    }

    return -1;
}

/*
 * Fancy message handling for a successful casting		-Thoric
 */
void successful_casting( SKILLTYPE *skill, CHAR_DATA *ch,
                         CHAR_DATA *victim, OBJ_DATA *obj )
{
    char buf[MAX_INPUT_LENGTH];
    unsigned int x;
    sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
    sh_int chit	    = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
    sh_int chitme   = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);

    if ( skill->target != TAR_CHAR_OFFENSIVE )
    {
        chit = chitroom;
        chitme = chitroom;
    }

    if ( ch && ch != victim )
    {
        if ( skill->hit_char && skill->hit_char[0] != '\0' )
        {
            sprintf(buf, "%s", skill->hit_char);
            if ( obj && !victim && !(strstr(buf,"$P") || strstr(buf,"$p")))
                for (x=0;x<strlen(buf)-1;x++)
                {
                    if (buf[x]=='$' && buf[x+1]=='N')
                        buf[x+1]='p';
                    else if (buf[x]=='$' && buf[x+1]=='n')
                        buf[x+1]='p';
                }
            act( chit, buf, ch, obj, victim, TO_CHAR );
        }
        else
            if ( skill->type == SKILL_SPELL )
                act( chit, "Ok.", ch, NULL, NULL, TO_CHAR );
    }

    if ( ch && skill->hit_room && skill->hit_room[0] != '\0' )
    {
        sprintf(buf, "%s", skill->hit_room);
        if ( obj && !victim && !(strstr(buf,"$P") || strstr(buf,"$p")))
            for (x=0;x<strlen(buf)-1;x++)
            {
                if (buf[x]=='$' && buf[x+1]=='N')
                    buf[x+1]='p';
                else if (buf[x]=='$' && buf[x+1]=='n')
                    buf[x+1]='p';
            }
        act( chitroom, buf, ch, obj, victim, TO_NOTVICT );
    }

    if ( ch && victim && skill->hit_vict && skill->hit_vict[0] != '\0' )
    {
        if ( ch != victim )
            act( chitme, skill->hit_vict, ch, obj, victim, TO_VICT );
        else
            act( chitme, skill->hit_vict, ch, obj, victim, TO_CHAR );
    }
    else
        if ( ch && ch == victim && skill->type == SKILL_SPELL )
            act( chitme, "Ok.", ch, NULL, NULL, TO_CHAR );
}

/*
 * Fancy message handling for a failed casting			-Thoric
 */
void failed_casting( SKILLTYPE *skill, CHAR_DATA *ch,
                     CHAR_DATA *victim, OBJ_DATA *obj )
{
    sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
    sh_int chit	    = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
    sh_int chitme   = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);

    if ( skill->target != TAR_CHAR_OFFENSIVE )
    {
        chit = chitroom;
        chitme = chitroom;
    }

    if ( ch && ch != victim )
    {
        if ( skill->miss_char && skill->miss_char[0] != '\0' )
            act( chit, skill->miss_char, ch, obj, victim, TO_CHAR );
        else
            if ( skill->type == SKILL_SPELL )
                act( chit, "You failed.", ch, NULL, NULL, TO_CHAR );
    }
    if ( ch && skill->miss_room && skill->miss_room[0] != '\0' )
        act( chitroom, skill->miss_room, ch, obj, victim, TO_NOTVICT );
    if ( ch && victim && skill->miss_vict && skill->miss_vict[0] != '\0' )
    {
        if ( ch != victim )
            act( chitme, skill->miss_vict, ch, obj, victim, TO_VICT );
        else
            act( chitme, skill->miss_vict, ch, obj, victim, TO_CHAR );
    }
    else
        if ( ch && ch == victim )
        {
            if ( skill->miss_char && skill->miss_char[0] != '\0' )
                act( chitme, skill->miss_char, ch, obj, victim, TO_CHAR );
            else
                if ( skill->type == SKILL_SPELL )
                    act( chitme, "You failed.", ch, NULL, NULL, TO_CHAR );
        }
}

/*
 * Fancy message handling for being immune to something		-Thoric
 */
void immune_casting( SKILLTYPE *skill, CHAR_DATA *ch,
                     CHAR_DATA *victim, OBJ_DATA *obj )
{
    sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
    sh_int chit	    = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
    sh_int chitme   = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);

    if ( skill->target != TAR_CHAR_OFFENSIVE )
    {
        chit = chitroom;
        chitme = chitroom;
    }

    if ( ch && ch != victim )
    {
        if ( skill->imm_char && skill->imm_char[0] != '\0' )
            act( chit, skill->imm_char, ch, obj, victim, TO_CHAR );
        else
            if ( skill->miss_char && skill->miss_char[0] != '\0' )
                act( chit, skill->hit_char, ch, obj, victim, TO_CHAR );
            else
                if ( skill->type == SKILL_SPELL || skill->type == SKILL_SKILL )
                    act( chit, "That appears to have no effect.", ch, NULL, NULL, TO_CHAR );
    }
    if ( ch && skill->imm_room && skill->imm_room[0] != '\0' )
        act( chitroom, skill->imm_room, ch, obj, victim, TO_NOTVICT );
    else
        if ( ch && skill->miss_room && skill->miss_room[0] != '\0' )
            act( chitroom, skill->miss_room, ch, obj, victim, TO_NOTVICT );
    if ( ch && victim && skill->imm_vict && skill->imm_vict[0] != '\0' )
    {
        if ( ch != victim )
            act( chitme, skill->imm_vict, ch, obj, victim, TO_VICT );
        else
            act( chitme, skill->imm_vict, ch, obj, victim, TO_CHAR );
    }
    else
        if ( ch && victim && skill->miss_vict && skill->miss_vict[0] != '\0' )
        {
            if ( ch != victim )
                act( chitme, skill->miss_vict, ch, obj, victim, TO_VICT );
            else
                act( chitme, skill->miss_vict, ch, obj, victim, TO_CHAR );
        }
        else
            if ( ch && ch == victim )
            {
                if ( skill->imm_char && skill->imm_char[0] != '\0' )
                    act( chit, skill->imm_char, ch, obj, victim, TO_CHAR );
                else
                    if ( skill->miss_char && skill->miss_char[0] != '\0' )
                        act( chit, skill->hit_char, ch, obj, victim, TO_CHAR );
                    else
                        if ( skill->type == SKILL_SPELL || skill->type == SKILL_SKILL )
                            act( chit, "That appears to have no affect.", ch, NULL, NULL, TO_CHAR );
            }
}


/*
 * Utter mystical words for an sn.
 */
void say_spell( CHAR_DATA *ch, int sn )
{
    char buf  [MAX_STRING_LENGTH];
    char buf2 [MAX_STRING_LENGTH];
    CHAR_DATA *rch;
    char *pName;
    int iSyl;
    int length;
    SKILLTYPE *skill = get_skilltype( sn );

    struct syl_type
    {
        char *	old;
        char *	snew;
    };

    static const struct syl_type syl_table[] =
    {
        { " ",		" "		},
        { "ar",		"abra"		},
        { "au",		"kada"		},
        { "bless",	"fido"		},
        { "blind",	"nose"		},
        { "bur",	"mosa"		},
        { "cu",		"judi"		},
        { "de",		"oculo"		},
        { "en",		"unso"		},
        { "light",	"dies"		},
        { "lo",		"hi"		},
        { "mor",	"zak"		},
        { "move",	"sido"		},
        { "ness",	"lacri"		},
        { "ning",	"illa"		},
        { "per",	"duda"		},
        { "ra",		"gru"		},
        { "re",		"candus"	},
        { "son",	"sabru"		},
        { "tect",	"infra"		},
        { "tri",	"cula"		},
        { "ven",	"nofo"		},
        { "a", "a" }, { "b", "b" }, { "c", "q" }, { "d", "e" },
        { "e", "z" }, { "f", "y" }, { "g", "o" }, { "h", "p" },
        { "i", "u" }, { "j", "y" }, { "k", "t" }, { "l", "r" },
        { "m", "w" }, { "n", "i" }, { "o", "a" }, { "p", "s" },
        { "q", "d" }, { "r", "f" }, { "s", "g" }, { "t", "h" },
        { "u", "j" }, { "v", "z" }, { "w", "x" }, { "x", "n" },
        { "y", "l" }, { "z", "k" },
        { "", "" }
    };

    buf[0]	= '\0';
    for ( pName = skill->name; *pName != '\0'; pName += length )
    {
        for ( iSyl = 0; (length = strlen(syl_table[iSyl].old)) != 0; iSyl++ )
        {
            if ( !str_prefix( syl_table[iSyl].old, pName ) )
            {
                strcat( buf, syl_table[iSyl].snew );
                break;
            }
        }

        if ( length == 0 )
            length = 1;
    }

    sprintf( buf2, "$n utters the words, '%s'.", buf );
    sprintf( buf,  "$n utters the words, '%s'.", skill->name );

    for ( rch = ch->in_room->first_person; rch; rch = rch->next_in_room )
    {
        if ( rch != ch )
            act( AT_MAGIC, IS_ACTIVE(rch, BestSkCl(ch, sn)) ? buf : buf2,
                 ch, NULL, rch, TO_VICT );

    }

    return;
}


/*
 * Make adjustments to saving throw based in RIS		-Thoric
 */
int ris_save( CHAR_DATA *ch, int percent, int ris )
{
    sh_int modifier;

    modifier = 10;
    if ( IS_SET(ch->absorb, ris ) )
        modifier -= 10;
    if ( IS_IMMUNE(ch, ris ) )
        modifier -= 10;
    if ( IS_SET(ch->resistant, ris ) )
        modifier -= 2;
    if ( IS_SET(ch->susceptible, ris ) )
        modifier += 2;
    if ( modifier <= 0 )
        return 1000;
    if ( modifier == 10 )
        return percent;
    return (percent * modifier) / 10;
}


/*								    -Thoric
 * Fancy dice expression parsing complete with order of operations,
 * simple exponent support, dice support as well as a few extra
 * variables: L = level, H = hp, M = mana, V = move, S = str, X = dex
 *            I = int, W = wis, C = con, A = cha, U = luck, A = age
 *
 * Used for spell dice parsing, ie: 3d8+L-6
 *
 */
int rd_parse(CHAR_DATA *ch, int level, char *exp)
{
    int x, y, len = 0;
    int lop = 0, gop = 0, eop = 0;
    char operation;
    char *sexp[2];
    int total = 0;

    /* take care of nulls coming in */
    if (!exp || !strlen(exp))
        return 0;

    /* get rid of brackets if they surround the entire expresion */
    if ((*exp == '(') && !index(exp+1,'(') && exp[strlen(exp)-1] == ')')
    {
        exp[strlen(exp)-1] = '\0';
        exp++;
    }

    /* check if the expresion is just a number */
    len = strlen(exp);
    if ( len == 1 && isalpha(exp[0]) )
    {
        /*log_printf("r1: %c",exp[0]);*/
        switch(exp[0]) {
        case 'L': case 'l':	return level;
        case 'H': case 'h':	return ch?GET_HIT(ch):0;
        case 'M': case 'm':	return ch?GET_MANA(ch):0;
        case 'V': case 'v':	return ch?GET_MOVE(ch):0;
        case 'S': case 's':	return ch?get_curr_str(ch):0;
        case 'I': case 'i':	return ch?get_curr_int(ch):0;
        case 'W': case 'w':	return ch?get_curr_wis(ch):0;
        case 'X': case 'x':	return ch?get_curr_dex(ch):0;
        case 'C': case 'c':	return ch?get_curr_con(ch):0;
        case 'A': case 'a':	return ch?get_curr_cha(ch):0;
        case 'U': case 'u':	return ch?get_curr_lck(ch):0;
        case 'Y': case 'y':	return ch?get_age(ch):0;
        case 'Z': case 'z':     return (int)DUR_CONV;
        }
    }

    for (x = 0; x < len; ++x)
        if (!isdigit(exp[x]) && !isspace(exp[x]))
            break;
    if (x == len)
    {
        /*log_printf("r2: %d",atoi(exp));*/
        return(atoi(exp));
    }
    /* break it into 2 parts */
    for (x = 0; x < strlen(exp); ++x)
        switch(exp[x]) {
        case '^':
            if (!total)
                eop = x;
            break;
        case '-': case '+':
            if (!total)
                lop = x;
            break;
        case '*': case '/': case '%': case 'd': case 'D':
        case '<': case '>': case '{': case '}': case '=':
            if (!total)
                gop =  x;
            break;
        case '(':
            ++total;
            break;
        case ')':
            --total;
            break;
        }
    if (lop) x = lop;
    else
        if (gop) x = gop;
        else
            x = eop;
    operation = exp[x];
    exp[x] = '\0';
    sexp[0] = exp;
    sexp[1] = (char *)(exp+x+1);

    /* work it out */
    /*log_printf("1: %s, %c, %s", sexp[0], operation, sexp[1]);*/
    total = rd_parse(ch, level, sexp[0]);
    /*log_printf("2: %d, %c, %s", total, operation, sexp[1]);*/
    switch(operation) {
    case '-':		total -= rd_parse(ch, level, sexp[1]);	break;
    case '+':		total += rd_parse(ch, level, sexp[1]);	break;
    case '*':		total *= rd_parse(ch, level, sexp[1]);	break;
    case '/':		y = rd_parse(ch, level, sexp[1]);
    if (y == 0)
        total = 0;
    else
        total /= y;
    break;
    case '%':		total %= rd_parse(ch, level, sexp[1]);	break;
    case 'd': case 'D':	total = dice( total, rd_parse(ch, level, sexp[1]) );	break;
    case '<':		total = (total < rd_parse(ch, level, sexp[1])); break;
    case '>':		total = (total > rd_parse(ch, level, sexp[1])); break;
    case '=':		total = (total == rd_parse(ch, level, sexp[1])); break;
    case '{':		total = UMIN( total, rd_parse(ch, level, sexp[1])); break;
    case '}':		total = UMAX( total, rd_parse(ch, level, sexp[1])); break;
    case '^':
        {
            int z = total;

            y = rd_parse(ch, level, sexp[1]);

            for (x = 1; x < y; ++x, z *= total);
            total = z;
            break;
        }
    }
    /*log_printf("r3: %d", total);*/
    return total;
}

/* wrapper function so as not to destroy exp */
int dice_parse(CHAR_DATA *ch, int level, char *dicestr)
{
    char buf[MAX_INPUT_LENGTH];

    strcpy( buf, dicestr );
    return rd_parse(ch, level, buf);
}

#if 1
/* Dale saving -Garil 10/5/2002 */
const sh_int saving_throws[REAL_MAX_CLASS][5][MAX_LEVEL] =
{
    /*
     * mage
     */
    {
        {16, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 8, 6, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 5, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 15, 15, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {14, 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * cleric
     */
    {
        {11, 10, 10, 10, 9, 9, 9, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 13, 13, 13, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 12, 12, 12, 10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 7, 7, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 15, 15, 15, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 8, 8, 7, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 14, 14, 14, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 7, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * thief
     */
    {
        {16, 14, 14, 13, 13, 11, 11, 10, 10, 8, 8, 7, 7, 5, 5, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 15, 15, 13, 13, 12, 12, 10, 10, 9, 9, 7, 7, 6, 6, 5, 5, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 14, 14, 12, 12, 11, 11, 9, 9, 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {20, 17, 17, 16, 16, 13, 13, 12, 12, 9, 9, 8, 8, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {19, 17, 17, 16, 16, 14, 14, 13, 13, 11, 11, 10, 10, 8, 8, 7, 7, 6, 6, 6, 6, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * warrior
     */
    {
        {15, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9, 8, 7, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 14, 12, 12, 12, 12, 10, 10, 10, 10, 8, 8, 8, 8, 6, 6, 6, 6, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {14, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9, 8, 8, 8, 8, 7, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 9, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 15, 13, 13, 13, 13, 11, 11, 11, 11, 9, 9, 9, 9, 7, 7, 7, 7, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * vampire (same as warrior)
     */
    {
        {15, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9, 8, 7, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 14, 12, 12, 12, 12, 10, 10, 10, 10, 8, 8, 8, 8, 6, 6, 6, 6, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {14, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9, 8, 8, 8, 8, 7, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 9, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 15, 13, 13, 13, 13, 11, 11, 11, 11, 9, 9, 9, 9, 7, 7, 7, 7, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * druid
     */
    {
        {11, 10, 10, 10, 9, 9, 9, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 13, 13, 13, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 12, 12, 12, 10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 7, 7, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 15, 15, 15, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 8, 8, 7, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 14, 14, 14, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 7, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * ranger (same as druid)
     */
    {
        {11, 10, 10, 10, 9, 9, 9, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 13, 13, 13, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 12, 12, 12, 10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 7, 7, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 15, 15, 15, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 8, 8, 7, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 14, 14, 14, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 7, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * amazon (same as druid)
     */
    {
        {11, 10, 10, 10, 9, 9, 9, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 13, 13, 13, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 12, 12, 12, 10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 7, 7, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 15, 15, 15, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 8, 8, 7, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 14, 14, 14, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 7, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * paladin (same as cleric)
     */
    {
        {11, 10, 10, 10, 9, 9, 9, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 13, 13, 13, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 12, 12, 12, 10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 7, 7, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 15, 15, 15, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 8, 8, 7, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 14, 14, 14, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 7, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * barbarian
     */
    {
        {15, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9, 8, 7, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 14, 12, 12, 12, 12, 10, 10, 10, 10, 8, 8, 8, 8, 6, 6, 6, 6, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {14, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9, 8, 8, 8, 8, 7, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 9, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 15, 13, 13, 13, 13, 11, 11, 11, 11, 9, 9, 9, 9, 7, 7, 7, 7, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * psi
     */
    {
        {16, 14, 14, 13, 13, 11, 11, 10, 10, 8, 8, 7, 7, 5, 5, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 15, 15, 13, 13, 12, 12, 10, 10, 9, 9, 7, 7, 6, 6, 5, 5, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 14, 14, 12, 12, 11, 11, 9, 9, 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {20, 17, 17, 16, 16, 13, 13, 12, 12, 9, 9, 8, 8, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {19, 17, 17, 16, 16, 14, 14, 13, 13, 11, 11, 10, 10, 8, 8, 7, 7, 6, 6, 6, 6, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * artificer (same as psi)
     */
    {
        {16, 14, 14, 13, 13, 11, 11, 10, 10, 8, 8, 7, 7, 5, 5, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 15, 15, 13, 13, 12, 12, 10, 10, 9, 9, 7, 7, 6, 6, 5, 5, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 14, 14, 12, 12, 11, 11, 9, 9, 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {20, 17, 17, 16, 16, 13, 13, 12, 12, 9, 9, 8, 8, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {19, 17, 17, 16, 16, 14, 14, 13, 13, 11, 11, 10, 10, 8, 8, 7, 7, 6, 6, 6, 6, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * monk
     */
    {
        {16, 14, 14, 13, 13, 11, 11, 10, 10, 8, 8, 7, 7, 5, 5, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 15, 15, 13, 13, 12, 12, 10, 10, 9, 9, 7, 7, 6, 6, 5, 5, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 14, 14, 12, 12, 11, 11, 9, 9, 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {20, 17, 17, 16, 16, 13, 13, 12, 12, 9, 9, 8, 8, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {19, 17, 17, 16, 16, 14, 14, 13, 13, 11, 11, 10, 10, 8, 8, 7, 7, 6, 6, 6, 6, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * necromancer (same as sorcerer)
     */
    {
        {16, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 8, 6, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 5, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 15, 15, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {14, 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * antipaladin (same as cleric)
     */
    {
        {11, 10, 10, 10, 9, 9, 9, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {16, 14, 14, 14, 13, 13, 13, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 12, 12, 12, 10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 7, 7, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18, 16, 16, 16, 15, 15, 15, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 8, 8, 7, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 14, 14, 14, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 7, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    },
    /*
     * sorcerer
     */
    {
        {16, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 8, 6, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {15, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 5, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {17, 15, 15, 15, 15, 15, 13, 13, 13, 13, 13, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 7, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {14, 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    }
};


/* level is unused, it's a smaug thing and we need the level and class, rather
   than passing it, just use the char's best */
bool saves_generic( int level, CHAR_DATA *victim, int victim_save, int save_type)
{
    int save = 0;

    if (GET_RACE(victim) == RACE_GOD ||
        IS_IMMORTAL(victim))
        return TRUE;

    if (!IS_NPC(victim) || IS_ACT_FLAG(victim, ACT_POLYMORPHED))
        save = saving_throws[BestMagicClass(victim)][save_type][GET_LEVEL(victim, BestMagicClass(victim))];

    return (UMAX(1, (victim_save + save)) < number_range(1, 20));
}

bool saves_poison_death( int level, CHAR_DATA *victim )
{
    return saves_generic(level, victim, victim->saving_poison_death, 0);
}
bool saves_wands( int level, CHAR_DATA *victim ) /* rod */
{
    return saves_generic(level, victim, victim->saving_wand, 1);
}
bool saves_para_petri( int level, CHAR_DATA *victim ) /* petri */
{
    return saves_generic(level, victim, victim->saving_para_petri, 2);
}
bool saves_breath( int level, CHAR_DATA *victim ) /* breath */
{
    return saves_generic(level, victim, victim->saving_breath, 3);
}
bool saves_spell_staff( int level, CHAR_DATA *victim ) /* spell */
{
    return saves_generic(level, victim, victim->saving_spell_staff, 4);
}
#else
/* the old smaug way -Garil 10/5/2002 */
/*
 * Compute a saving throw.
 * Negative apply's make saving throw better.
 */
bool saves_poison_death( int level, CHAR_DATA *victim )
{
    int save;

    if (!victim)
        return FALSE;

    save = 50 + ( GetMaxLevel(victim) - level - victim->saving_poison_death ) * 5;
    save = URANGE( 5, save, 95 );
    return chance( victim, save );
}
bool saves_wands( int level, CHAR_DATA *victim )
{
    int save;

    if (!victim)
        return FALSE;

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
        return TRUE;

    save = 50 + ( GetMaxLevel(victim) - level - victim->saving_wand ) * 5;
    save = URANGE( 5, save, 95 );
    return chance( victim, save );
}
bool saves_para_petri( int level, CHAR_DATA *victim )
{
    int save;

    if (!victim)
        return FALSE;

    save = 50 + ( GetMaxLevel(victim) - level - victim->saving_para_petri) * 5;
    save = URANGE( 5, save, 95 );
    return chance( victim, save );
}
bool saves_breath( int level, CHAR_DATA *victim )
{
    int save;

    if (!victim)
        return FALSE;

    save = 50 + ( GetMaxLevel(victim) - level - victim->saving_breath ) * 5;
    save = URANGE( 5, save, 95 );
    return chance( victim, save );
}
bool saves_spell_staff( int level, CHAR_DATA *victim )
{
    int save;

    if (!victim)
        return FALSE;

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
        return TRUE;

    if ( IS_NPC( victim ) && level > 10 )
        level -= 5;
    save = 50 + ( GetMaxLevel(victim) - level - victim->saving_spell_staff) * 5;
    save = URANGE( 5, save, 95 );
    return chance( victim, save );
}
#endif

/*
 * Process the spell's required components, if any		-Thoric
 * -----------------------------------------------
 * T###		check for item of type ###
 * V#####	check for item of vnum #####
 * Kword	check for item with keyword 'word'
 * G#####	check if player has ##### amount of gold
 * H####	check if player has #### amount of hitpoints
 *
 * Special operators:
 * ! spell fails if player has this
 * + don't consume this component
 * @ decrease component's value[0], and extract if it reaches 0
 * # decrease component's value[1], and extract if it reaches 0
 * $ decrease component's value[2], and extract if it reaches 0
 * % decrease component's value[3], and extract if it reaches 0
 * ^ decrease component's value[4], and extract if it reaches 0
 * & decrease component's value[5], and extract if it reaches 0
 */
bool process_spell_components( CHAR_DATA *ch, int sn )
{
    SKILLTYPE *skill	= get_skilltype(sn);
    char *comp		= skill->components;
    char *check;
    char arg[MAX_INPUT_LENGTH];
    bool consume, fail, found;
    int  val, value;
    OBJ_DATA *obj;

    /* if no components necessary, then everything is cool */
    if ( !comp || comp[0] == '\0' )
        return TRUE;

    while ( comp[0] != '\0' )
    {
        comp = one_argument( comp, arg );
        consume = TRUE;
        fail = found = FALSE;
        val = -1;
        switch( arg[1] )
        {
        default:	check = arg+1;				break;
        case '!':	check = arg+2;	fail = TRUE;		break;
        case '+':	check = arg+2;	consume = FALSE;	break;
        case '@':	check = arg+2;	val = 0;		break;
        case '#':	check = arg+2;	val = 1;		break;
        case '$':	check = arg+2;	val = 2;		break;
        case '%':	check = arg+2;	val = 3;		break;
        case '^':	check = arg+2;	val = 4;		break;
        case '&':	check = arg+2;	val = 5;		break;
        }
        value = atoi(check);
        obj = NULL;
        switch( UPPER(arg[0]) )
        {
        case 'T':
            for ( obj = ch->first_carrying; obj; obj = obj->next_content )
                if ( obj->item_type == value )
                {
                    if ( fail )
                    {
                        send_to_char( "Something disrupts the casting of this spell...\n\r", ch );
                        return FALSE;
                    }
                    found = TRUE;
                    break;
                }
            break;
        case 'V':
            for ( obj = ch->first_carrying; obj; obj = obj->next_content )
                if ( obj->vnum == value )
                {
                    if ( fail )
                    {
                        send_to_char( "Something disrupts the casting of this spell...\n\r", ch );
                        return FALSE;
                    }
                    found = TRUE;
                    break;
                }
            break;
        case 'K':
            for ( obj = ch->first_carrying; obj; obj = obj->next_content )
                if ( nifty_is_name( check, obj->name ) )
                {
                    if ( fail )
                    {
                        send_to_char( "Something disrupts the casting of this spell...\n\r", ch );
                        return FALSE;
                    }
                    found = TRUE;
                    break;
                }
            break;
        case 'G':
            if ( GET_MONEY(ch, DEFAULT_CURR) >= value )
            {
                if ( fail )
                {
                    send_to_char( "Something disrupts the casting of this spell...\n\r", ch );
                    return FALSE;
                }
                else
                {
                    if ( consume )
                    {
                        set_char_color( AT_GOLD, ch );
                        send_to_char( "You feel a little lighter...\n\r", ch );
                        GET_MONEY(ch, DEFAULT_CURR) -= value;
                    }
                    continue;
                }
            }
            break;
        case 'H':
            if ( GET_HIT(ch) >= value )
            {
                if ( fail )
                {
                    send_to_char( "Something disrupts the casting of this spell...\n\r", ch );
                    return FALSE;
                }
                else
                {
                    if ( consume )
                    {
                        set_char_color( AT_BLOOD, ch );
                        send_to_char( "You feel a little weaker...\n\r", ch );
                        GET_HIT(ch) -= value;
                        update_pos( ch );
                    }
                    continue;
                }
            }
            break;
        }
        /* having this component would make the spell fail... if we get
         here, then the caster didn't have that component */
        if ( fail )
            continue;
        if ( !found )
        {
            send_to_char( "Something is missing...\n\r", ch );
            return FALSE;
        }
        if ( obj )
        {
            if ( val >=0 && val < 6 )
            {
                separate_obj(obj);
                if ( obj->value[val] <= 0 )
                    return FALSE;
                else
                    if ( --obj->value[val] == 0 )
                    {
                        act( AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, NULL, TO_CHAR );
                        act( AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, NULL, TO_ROOM );
                        extract_obj( obj );
                    }
                    else
                        act( AT_MAGIC, "$p glows briefly and a whisp of smoke rises from it.", ch, obj, NULL, TO_CHAR );
            }
            else
                if ( consume )
                {
                    separate_obj(obj);
                    act( AT_MAGIC, "$p glows brightly, then disappears in a puff of smoke!", ch, obj, NULL, TO_CHAR );
                    act( AT_MAGIC, "$p glows brightly, then disappears in a puff of smoke!", ch, obj, NULL, TO_ROOM );
                    extract_obj( obj );
                }
                else
                {
                    int count = obj->count;

                    obj->count = 1;
                    act( AT_MAGIC, "$p glows briefly.", ch, obj, NULL, TO_CHAR );
                    obj->count = count;
                }
        }
    }
    return TRUE;
}

int pAbort;

/*
 * Locate targets.
 */
void *locate_targets( CHAR_DATA *ch, char *arg, int sn,
                      CHAR_DATA **victim, OBJ_DATA **obj )
{
    SKILLTYPE *skill = get_skilltype( sn );
    void *vo	= NULL;

    *victim	= NULL;
    *obj	= NULL;

    switch ( skill->target )
    {
    default:
        bug( "Do_cast: bad target for sn %d.", sn );
        return &pAbort;

    case TAR_IGNORE:
        break;

    case TAR_CHAR_OFFENSIVE:
        if ( arg[0] == '\0' )
        {
            if ( ( *victim = who_fighting( ch ) ) == NULL )
            {
                if (skill->skill_fun!=do_smaug_skill)
                    send_to_char( "Cast the spell on whom?\n\r", ch );
                else
                    send_to_char( "I don't see them anywhere!\n\r", ch);
                return &pAbort;
            }
        }
        else
        {
            if ( ( *victim = get_char_room( ch, arg ) ) == NULL )
            {
                send_to_char( "They aren't here.\n\r", ch );
                return &pAbort;
            }
        }

        if ( is_safe( ch, *victim ) )
            return &pAbort;

        if ( ch == *victim )
        {
            send_to_char( "Cast this on yourself?  Okay...\n\r", ch );
            /*
             send_to_char( "You can't do that to yourself.\n\r", ch );
             return &pAbort;
             */
        }

        if ( !IS_NPC(ch) )
        {
            if ( !IS_NPC(*victim) )
            {
                /*  Sheesh! can't do anything
                 send_to_char( "You can't do that on a player.\n\r", ch );
                 return &pAbort;
                 */
                /*
                 if( IS_SET(*victim->act, PLR_PK))
                 */
                if ( get_timer( ch, TIMER_PKILLED ) > 0 )
                {
                    send_to_char( "You have been killed in the last 5 minutes.\n\r", ch);
                    return &pAbort;
                }

                if ( get_timer( *victim, TIMER_PKILLED ) > 0 )
                {
                    send_to_char( "This player has been killed in the last 5 minutes.\n\r", ch );
                    return &pAbort;
                }

                if ( *victim != ch)
                    send_to_char( "You really shouldn't do this to another player...\n\r", ch );
            }

            if ( IS_AFFECTED(ch, AFF_CHARM) && ch->master == *victim )
            {
                send_to_char( "You can't do that on your own follower.\n\r", ch );
                return &pAbort;
            }
        }

        if ( check_illegal_pk(ch, *victim) )
        {
            send_to_char( "The gods will not permit you to cast offensive spells on them.\n\r", ch );
            return &pAbort;
        }

        if ( ch != *victim ) adjust_favor( ch, 4, 1 );
        vo = (void *) *victim;
        break;

    case TAR_CHAR_DEFENSIVE:
        if ( arg[0] == '\0' )
            *victim = ch;
        else
        {
            if ( ( *victim = get_char_room( ch, arg ) ) == NULL )
            {
                send_to_char( "They aren't here.\n\r", ch );
                return &pAbort;
            }
        }
        if ( ( *victim != ch )
             && !IS_NPC( *victim ) ) adjust_favor( ch, 7, 1 );
        if ( ( *victim != ch )
             && !IS_NPC( ch ) ) adjust_favor( *victim, 13, 1 );
        vo = (void *) *victim;
        break;

    case TAR_CHAR_SELF:
        if ( arg[0] != '\0' &&
             !IS_NPC(ch) &&
             !nifty_is_name( arg, ch->name ) &&
             !nifty_is_name(arg, "self") )
        {
            send_to_char( "You cannot cast this spell on another.\n\r", ch );
            return &pAbort;
        }

        vo = (void *) ch;
        break;

    case TAR_OBJ_INV:
        if ( arg[0] == '\0' )
        {
            send_to_char( "What should the spell be cast upon?\n\r", ch );
            return &pAbort;
        }

        if ( ( *obj = get_obj_carry( ch, arg ) ) == NULL )
        {
            send_to_char( "You are not carrying that.\n\r", ch );
            return &pAbort;
        }

        vo = (void *) *obj;
        break;

    case TAR_OBJ_ROOM:
        if ( arg[0] == '\0' )
        {
            send_to_char( "What should the spell be cast upon?\n\r", ch );
            return &pAbort;
        }

        if ( ( *obj = get_obj_list_rev( ch, arg, ch->in_room->last_content ) ) == NULL )
        {
            send_to_char( "You are not carrying that.\n\r", ch );
            return &pAbort;
        }

        vo = (void *) *obj;
        break;
    }

    return vo;
}


void do_mind( CHAR_DATA *ch, char *argument )
{
    do_cast( ch, argument );
}

/*
 * The kludgy global is for spells who want more stuff from command line.
 */
char *target_name;

/*
 * Cast a spell.  Multi-caster and component support by Thoric
 */
void do_cast( CHAR_DATA *ch, char *argument )
{
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    static char staticbuf[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    OBJ_DATA *obj;
    void *vo = NULL;
    int mana;
    int blood;
    int sn;
    int max = 0;
    ch_ret retcode;
    bool dont_wait = FALSE;
    SKILLTYPE *skill = NULL;
    struct timeval time_used;
    bool mind = FALSE;

    retcode = rNONE;

    if (ch->last_cmd == do_mind)
        mind = TRUE;

    if (IS_SYSTEMFLAG(SYS_NOMAGIC))
    {
        send_to_char("You can't seem to remember how to cast!  The Gods must be angry!\n\r", ch);
        return;
    }

    switch( ch->substate )
    {
    default:
        /* no ordering charmed mobs to cast spells */
        if ( IS_NPC(ch) && IS_AFFECTED( ch, AFF_CHARM ) )
        {
            send_to_char( "You can't seem to do that right now...\n\r", ch );
            return;
        }

        if (IS_SET(ch->in_room->room_flags, ROOM_NO_MAGIC))
        {
            set_char_color( AT_MAGIC, ch );
            send_to_char("Ancient Magiks bar your path.\n\r", ch);
            if (IS_IMMORTAL(ch))
                send_to_char("However, your immortality overcomes them.\n\r", ch);
            else
                return;
        }

        target_name = one_argument( argument, arg1 );
        one_argument( target_name, arg2 );

        if ( arg1[0] == '\0' )
	{
	    if (mind)
		send_to_char( "Mind which what where?\n\r", ch );
            else
		send_to_char( "Cast which what where?\n\r", ch );
            if (IS_NPC(ch))
                log_printf_plus(LOG_MAGIC, UMAX(GetMaxLevel(ch),LEVEL_LOG_CSET), SEV_DEBUG,
                                "do_cast: %s (u%d) cast with no arguments",
                                ch->name, ch->unum);
            return;
        }

        if ( get_trust(ch) < LEVEL_GOD )
	{
	    if (mind)
		sn=find_psispell(ch, arg1, TRUE);
	    else
		sn=find_spell(ch, arg1, TRUE);
	    if (sn < 0)
	    {
		send_to_char( "You can't do that.\n\r", ch );
		return;
	    }

            if (!CanUseSkill(ch, sn))
            {
                send_to_char( "You can't use that.\n\r", ch );
                return;
            }
        }
        else
        {
            if ( (sn=skill_lookup(arg1)) < 0 )
            {
                send_to_char( "We didn't create that yet...\n\r", ch );
                return;
            }
            if ( sn >= MAX_SKILL )
            {
                send_to_char( "Hmm... that might hurt.\n\r", ch );
                return;
            }
        }

	if ( (skill=get_skilltype(sn)) == NULL )
	{
	    send_to_char( "Something is severely wrong with that one...\n\r", ch );
	    return;
	}

	if ( mind && skill->type != SKILL_PSISPELL )
	{
	    send_to_char( "That isn't a psionic skill.\n\r", ch );
	    return;
	}
	if ( !mind && skill->type != SKILL_SPELL )
	{
	    send_to_char( "That isn't a spell.\n\r", ch );
	    return;
	}
        /*
         * Something else removed by Merc			-Thoric
         */
        if ( ch->position < skill->minimum_position )
        {
            switch( ch->position )
            {
            default:
                send_to_char( "You can't concentrate enough.\n\r", ch );
                break;
            case POS_SITTING:
                log_printf_plus(LOG_MAGIC, LEVEL_IMMORTAL, SEV_DEBUG, "%s trying to cast %s while sitting.",GET_NAME(ch),skill->name);
                send_to_char( "You can't summon enough energy sitting down.\n\r", ch );
                break;
            case POS_RESTING:
                log_printf_plus(LOG_MAGIC, LEVEL_IMMORTAL, SEV_DEBUG, "%s trying to cast %s while resting.",GET_NAME(ch),skill->name);
                send_to_char( "You're too relaxed to use that.\n\r", ch );
                break;
            case POS_FIGHTING:
                if (IS_NPC(ch))
                    log_printf_plus(LOG_MAGIC, LEVEL_IMMORTAL, SEV_DEBUG, "%s trying to cast %s while fighting.",GET_NAME(ch),skill->name);
                send_to_char( "You can't concentrate enough while fighting!\n\r", ch );
                break;
	    case POS_SLEEPING:
		if (mind)
		    send_to_char( "You dream about great feats of mental prowess.\n\r", ch );
		else
		    send_to_char( "You dream about great feats of magic.\n\r", ch );
                break;
            }
            return;
        }

        if ( skill->spell_fun == spell_null )
        {
            send_to_char( "That's not a spell!\n\r", ch );
            bug("Null spell: %s", skill->name);
            return;
        }

        if ( !skill->spell_fun )
        {
            send_to_char( "You cannot use that... yet.\n\r", ch );
            bug("Spell with no fun: %s", skill->name);
            return;
        }

        /* psi's don't speak their spells */
        if (!mind)
        {
            if ( ch->in_room->sector_type == SECT_UNDERWATER )
            {
                send_to_char("Speak underwater, are you mad????\n\r", ch);
                return;
            }

            if ( IS_ROOM_FLAG( ch->in_room, ROOM_SILENCE ) )
            {
                send_to_char("You are in a silent zone, you can't make a sound!\n\r", ch);
                return;
            }

            if (IS_SILENCED(ch))
            {
                send_to_char("You are silenced, you can't make a sound!\n\r", ch);
                return;
            }
        }

        if ( !IS_NPC(ch)			/* fixed by Thoric */
             &&   !IS_IMMORTAL(ch)
             &&    skill->guild != CLASS_NONE
             &&  (!ch->pcdata->clan
                  || skill->guild != ch->pcdata->clan->cl) )
        {
            send_to_char( "That is only available to members of a certain guild.\n\r", ch);
            return;
        }

        mana = (IS_NPC(ch) || MEMORIZED(ch, sn)) ? 0 : skill->min_mana;
        /*
         * Locate targets.
         */
        vo = locate_targets( ch, arg2, sn, &victim, &obj );
        if ( vo == &pAbort )
            return;

        /*
         * Vampire spell casting				-Thoric
         */
        blood = UMAX(1, (mana+4) / 8);      /* NPCs don't have PCDatas. -- Altrag */
        if ( IS_VAMPIRE(ch) )
        {
            if (GET_COND(ch, COND_BLOODTHIRST) < blood)
            {
                send_to_char( "You don't have enough blood power.\n\r", ch );
                return;
            }
        }
        else
            if ( !IS_NPC(ch) && GET_MANA(ch) < mana )
            {
                send_to_char( "You don't have enough mana.\n\r", ch );
                return;
            }
        if ( skill->participants <= 1 )
            break;
        /* multi-participant spells			-Thoric */
        add_timer( ch, TIMER_DO_FUN,
                   UMAX(skill->beats/SPELL_BEATS_PER_ROUND, 1),
                   do_cast, 1 );

        if (skill->part_start_char && *skill->part_start_char)
            act( AT_MAGIC, skill->part_start_char, ch, NULL, NULL, TO_CHAR );
        else
            act( AT_MAGIC, "You begin to chant...", ch, NULL, NULL, TO_CHAR );
        if (skill->part_start_room && *skill->part_start_room)
            act( AT_MAGIC, skill->part_start_room, ch, NULL, NULL, TO_ROOM );
        else
            act( AT_MAGIC, "$n begins to chant...", ch, NULL, NULL, TO_ROOM );

        sprintf( staticbuf, "'%s' %s", arg2, target_name );
        ch->dest_buf = str_dup( staticbuf );
        ch->tempnum = sn;
        return;
    case SUB_TIMER_DO_ABORT:
        DISPOSE( ch->dest_buf );
        if ( IS_VALID_SN((sn = ch->tempnum)) )
        {
            if ( (skill=get_skilltype(sn)) == NULL )
            {
                send_to_char( "Something went wrong...\n\r", ch );
                bug( "do_cast: SUB_TIMER_DO_ABORT: bad sn %d", sn );
                return;
            }
            mana = IS_NPC(ch) ? 0 : UMAX(skill->min_mana,
                                         100 / UMAX(2,(2 + BestSkLv(ch, sn)) - skill->skill_level[BestSkCl(ch, sn)]));
            blood = UMAX(1, (mana+4) / 8);
            if ( IS_VAMPIRE(ch) )
                gain_condition( ch, COND_BLOODTHIRST, - UMAX(1, (blood >> 1)) );
            else if (!IS_IMMORTAL(ch))    /* so imms dont lose mana */
                GET_MANA(ch) -= (mana >> 1);
        }
        if (skill->part_abort_char && *skill->part_abort_char)
            act( AT_MAGIC, skill->part_abort_char, ch, NULL, NULL, TO_CHAR );
        else
            act( AT_MAGIC, "You stop chanting...", ch, NULL, NULL, TO_CHAR );
        /* should add chance of backfire here */
        return;
    case 1:
        sn = ch->tempnum;
        if ( (skill=get_skilltype(sn)) == NULL )
        {
            send_to_char( "Something went wrong...\n\r", ch );
            bug( "do_cast: substate 1: bad sn %d", sn );
            return;
        }
        if ( !ch->dest_buf || !IS_VALID_SN(sn) || skill->type != SKILL_SPELL )
        {
            send_to_char( "Something cancels out the spell!\n\r", ch );
            bug( "do_cast: ch->dest_buf NULL or bad sn (%d)", sn );
            return;
        }
        mana = IS_NPC(ch) ? 0 : UMAX(skill->min_mana,
                                     100 / UMAX(2,(2 + BestSkLv(ch, sn)) - skill->skill_level[BestSkCl(ch, sn)]) );
        blood = UMAX(1, (mana+4) / 8);
        strcpy( staticbuf, (char *)ch->dest_buf );
        target_name = one_argument(staticbuf, arg2);
        DISPOSE( ch->dest_buf );
        ch->substate = SUB_NONE;
        if ( skill->participants > 1 )
        {
            int cnt = 1;
            CHAR_DATA *tmp;
            TIMER *t = NULL;

            for ( tmp = ch->in_room->first_person; tmp; tmp = tmp->next_in_room )
                if (  tmp != ch
                      &&   (t = get_timerptr( tmp, TIMER_DO_FUN )) != NULL
                      &&    t->count >= 1 && t->do_fun == do_cast
                      &&    tmp->tempnum == sn && tmp->dest_buf
                      &&   !str_cmp( (char *)tmp->dest_buf, staticbuf ) )
                    ++cnt;

            if ( cnt >= skill->participants )
            {
                for ( tmp = ch->in_room->first_person; tmp; tmp = tmp->next_in_room )
                    if (  tmp != ch
                          &&   (t = get_timerptr( tmp, TIMER_DO_FUN )) != NULL
                          &&    t->count >= 1 && t->do_fun == do_cast
                          &&    tmp->tempnum == sn && tmp->dest_buf
                          &&   !str_cmp( (char *)tmp->dest_buf, staticbuf ) )
                    {
                        extract_timer( tmp, t );

                        if (skill->part_end_vict && *skill->part_end_vict)
                            act( AT_MAGIC, skill->part_end_vict, ch, NULL, tmp, TO_VICT );
                        else
                            act( AT_MAGIC, "You channel your energy into $n!", ch, NULL, tmp, TO_VICT );
                        if (skill->part_end_char && *skill->part_end_char)
                            act( AT_MAGIC, skill->part_end_char, ch, NULL, tmp, TO_CHAR );
                        else
                            act( AT_MAGIC, "$N channels $S energy into you!", ch, NULL, tmp, TO_CHAR );
                        if (skill->part_end_room && *skill->part_end_room)
                            act( AT_MAGIC, skill->part_end_room, ch, NULL, tmp, TO_NOTVICT );
                        else
                            act( AT_MAGIC, "$N channels $S energy into $n!", ch, NULL, tmp, TO_NOTVICT );

                        learn_from_success( tmp, sn );
                        if ( IS_VAMPIRE(ch) )
                            gain_condition( tmp, COND_BLOODTHIRST, - blood/2);
                        else if (!IS_IMMORTAL(tmp))
                            GET_MANA(tmp) -= mana;
                        tmp->substate = SUB_NONE;
                        tmp->tempnum = -1;
                        DISPOSE( tmp->dest_buf );
                    }
                dont_wait = TRUE;
                if (skill->part_end_caster && *skill->part_end_caster)
                    act( AT_MAGIC, skill->part_end_caster, ch, NULL, NULL, TO_CHAR );
                else
                    act( AT_MAGIC, "You concentrate all the energy into a burst of mystical words!", ch, NULL, NULL, TO_CHAR );
                vo = locate_targets( ch, arg2, sn, &victim, &obj );
                if ( vo == &pAbort )
                    return;
            }
            else
            {
                if (skill->part_miss_char && *skill->part_miss_char)
                    act( AT_MAGIC, skill->part_miss_char, ch, NULL, NULL, TO_CHAR );
                else
                    act( AT_MAGIC, "There was not enough power the spell to succeed...", ch, NULL, NULL, TO_CHAR );
                if (skill->part_miss_room && *skill->part_miss_room)
                    act( AT_MAGIC, skill->part_miss_room, ch, NULL, NULL, TO_ROOM );

                if ( IS_VAMPIRE(ch) )
                    gain_condition( ch, COND_BLOODTHIRST, - UMAX(1, blood / 2) );
                else if (!IS_IMMORTAL(ch))    /* so imms dont lose mana */
                    GET_MANA(ch) -= mana/2;
                learn_from_failure( ch, sn );
                return;
            }
        }
    }

    if ( str_cmp( skill->name, "ventriloquate" ) && !mind )
        say_spell( ch, sn );

    /*
     * Getting ready to cast... check for spell components	-Thoric
     */
    if ( !process_spell_components( ch, sn ) )
    {
        if ( IS_VAMPIRE(ch) )
            gain_condition( ch, COND_BLOODTHIRST, - UMAX(1, blood / 2) );
        else if (!IS_IMMORTAL(ch))    /* so imms dont lose mana */
            GET_MANA(ch) -= mana / 2;
        learn_from_failure( ch, sn );
        if ( !dont_wait )
            spell_lag(ch, sn);
        return;
    }

    if (IS_NPC(ch) && !IS_ACT_FLAG(ch, ACT_POLYMORPHED))
    {
        max = 1;
    }
    else
    {
        int cl;

        max = 0;

        for (cl = 0; cl < MAX_CLASS; cl++)
        {
            if (!IS_ACTIVE(ch, cl))
                continue;

            switch (cl)
            {
            default:
                break;
            case CLASS_MAGE:
            case CLASS_SORCERER:
                if (EqWBits(ch, ITEM_ANTI_MAGE))
                    max += 10;
                break;
            case CLASS_NECROMANCER:
                if (EqWBits2(ch, ITEM2_ANTI_NECROMANCER))
                    max += 10;
                break;
            case CLASS_CLERIC:
                if (EqWBits(ch, ITEM_ANTI_CLERIC))
                    max += 10;
                break;
            case CLASS_DRUID:
                if (EqWBits(ch, ITEM_ANTI_DRUID))
                    max += 10;
                break;
            case CLASS_PALADIN:
                if (EqWBits2(ch, ITEM2_ANTI_PALADIN))
                    max += 5;
                break;
            case CLASS_ANTIPALADIN:
                if (EqWBits2(ch, ITEM2_ANTI_APALADIN))
                    max += 5;
                break;
            case CLASS_PSIONIST:
                if (EqWBits2(ch, ITEM2_ANTI_PSI))
                    max += 1;
                break;
            case CLASS_RANGER:
                if (EqWBits2(ch, ITEM2_ANTI_RANGER))
                    max += 5;
                break;
            case CLASS_VAMPIRE:
                if (EqWBits(ch, ITEM_ANTI_VAMPIRE))
                    max += 10;
                break;
            case CLASS_ARTIFICER:
                if (EqWBits2(ch, ITEM2_ANTI_ARTIFICER))
                    max += 10;
                break;
            case CLASS_MONK:
                if (EqWBits2(ch, ITEM2_ANTI_MONK))
                    max += 1;
                break;
            case CLASS_THIEF:
                if (EqWBits(ch, ITEM_ANTI_THIEF))
                    max += 1;
                break;
            case CLASS_AMAZON:
                if (EqWBits2(ch, ITEM2_ANTI_AMAZON))
                    max += 1;
                break;
            case CLASS_WARRIOR:
                if (EqWBits(ch, ITEM_ANTI_WARRIOR))
                    max += 1;
                break;
            }
        }

        if (max > 0 && GetMaxLevel(ch)<5)
            send_to_char("Note: You are wearing anti-class eq, removing it will improve your spellfail.\n\r(This message will self-destruct when you reach level 5)\n\r", ch);

        max += ch->spellfail + (skill->difficulty * 5) + (GET_COND(ch, COND_DRUNK) * 2);

        log_printf_plus(LOG_DEBUG, LEVEL_IMMORTAL, SEV_DEBUG, "do_cast: %s spellfail: %d  sn: %d", GET_NAME(ch), max, sn);
    }

    if (IS_IMMORTAL(ch))
        max = 1;

    /* memorized spells don't use mana nor do they fail */
    if ( MEMORIZED(ch, sn) )
    {
        int adept;

        forget_spell(ch, sn);

        adept = GET_ADEPT(ch, sn);

        if (!IS_NPC(ch) && LEARNED(ch, sn) < adept)
            ch->pcdata->learned[sn] = UMIN( adept, LEARNED(ch, sn) + 1);
    }
    else
    {
        if (IS_ACTIVE(ch, CLASS_SORCERER))
        {
            int cl;

            for (cl=0;cl<MAX_CLASS;cl++)
            {
                if (cl == CLASS_SORCERER)
                    continue;
                if (CanUseSkillClass(ch, sn, cl))
                    break;
            }
            if (!CanUseSkillClass(ch, sn, cl) || cl == CLASS_SORCERER)
            {
                send_to_char("You must memorize that before you can cast it.\n\r", ch);
                return;
            }
            else if (cl < MAX_CLASS && !IS_IMMORTAL(ch))
            {
                bug("Sorcerer %s casting %s as %s",
                    GET_NAME(ch), skill->name, pc_class[cl]);
            }
        }

        if ( number_range(1, max) > LEARNED(ch, sn) )
        {
            /* Some more interesting loss of concentration messages  -Thoric */
            switch( number_bits(2) )
            {
            case 0:	/* too busy */
                if ( ch->fighting )
                    send_to_char( "This round of battle is too hectic to concentrate properly.\n\r", ch );
                else
                    send_to_char( "You lost your concentration.\n\r", ch );
                break;
            case 1:	/* irritation */
                if ( number_bits(2) == 0 )
                {
                    switch( number_bits(2) )
                    {
                    case 0: send_to_char( "A tickle in your nose prevents you from keeping your concentration.\n\r", ch ); break;
                    case 1: send_to_char( "An itch on your leg keeps you from properly casting your spell.\n\r", ch ); break;
                    case 2: send_to_char( "Something in your throat prevents you from uttering the proper phrase.\n\r", ch ); break;
                    case 3: send_to_char( "A twitch in your eye disrupts your concentration for a moment.\n\r", ch ); break;
                    }
                }
                else
                    send_to_char( "Something distracts you, and you lose your concentration.\n\r", ch );
                break;
            case 2:	/* not enough time */
                if ( ch->fighting )
                    send_to_char( "There wasn't enough time this round to complete the casting.\n\r", ch );
                else
                    send_to_char( "You lost your concentration.\n\r", ch );
                break;
            case 3:
                send_to_char( "You get a mental block mid-way through the casting.\n\r", ch );
                break;
            }
            if ( IS_VAMPIRE(ch) )
                gain_condition( ch, COND_BLOODTHIRST, - UMAX(1, blood) );
            else if (!IS_IMMORTAL(ch))    /* so imms dont lose mana */
                GET_MANA(ch) -= (mana >> 1);
            learn_from_failure( ch, sn );
            if ( !dont_wait )
                spell_lag(ch, sn);
            return;
        }

        if ( IS_VAMPIRE(ch) )
            gain_condition( ch, COND_BLOODTHIRST, - blood/2);
        else if (!IS_IMMORTAL(ch))
            GET_MANA(ch) -= mana;
    }

    if ( !dont_wait )
        spell_lag(ch, sn);

    if (!IS_NPC(ch))
        log_printf_plus(LOG_MAGIC, UMAX(GetMaxLevel(ch),LEVEL_LOG_CSET), SEV_DEBUG, "%s: Caster: %s, Level: %d, Learned: %d, Use: %d, Used: %d",
                        skill->name, GET_NAME(ch), BestSkLv(ch,sn), LEARNED(ch, sn), skill->min_mana, mana);

    /*
     * check for immunity to magic if victim is known...
     * and it is a TAR_CHAR_DEFENSIVE/SELF spell
     * otherwise spells will have to check themselves
     */
    if (victim && GET_AMAGICP(victim) > number_percent())
    {
        send_to_char( "Your magic was absorbed!\n\r", ch);
        return;
    }

    if ( (skill->target == TAR_CHAR_DEFENSIVE ||
          skill->target == TAR_CHAR_SELF) &&
         victim && IS_SET(victim->immune, RIS_MAGIC) )
    {
        immune_casting( skill, ch, victim, NULL );
        retcode = rSPELL_FAILED;
    }
    else if (victim && is_immune(victim, skill))
    {
        immune_casting( skill, ch, victim, NULL );
        log_printf_plus(LOG_MAGIC, UMAX(GetMaxLevel(ch), GetMaxLevel(victim)), SEV_DEBUG, "is_immune: Spell: %s, Caster: %s, Target: %s",
                        skill->name, GET_NAME(ch), GET_NAME(victim));
        retcode = rSPELL_FAILED;
    }
    else
    {
        start_timer(&time_used);
        retcode = (*skill->spell_fun) ( sn, BestSkLv(ch, sn), ch, vo );
        end_timer(&time_used);
        update_userec(&time_used, &skill->userec);
    }

    if ( retcode == rCHAR_DIED || retcode == rERROR || char_died(ch) )
        return;
    if ( retcode != rSPELL_FAILED )
        learn_from_success( ch, sn );
    else
        learn_from_failure( ch, sn );

    if (ch==supermob)
        return;

    /*
     * Fixed up a weird mess here, and added double safeguards	-Thoric
     */

    if ( skill->target == TAR_CHAR_OFFENSIVE
         &&   victim
         &&  !char_died(victim)
         &&	 victim != ch )
    {
        CHAR_DATA *vch, *vch_next;

        for ( vch = ch->in_room->first_person; vch; vch = vch_next )
        {
            vch_next = vch->next_in_room;

            if ( vch == victim )
            {
                if ( victim->master != ch
                     &&  !victim->fighting )
                    retcode = multi_hit( victim, ch, TYPE_UNDEFINED );
                break;
            }
        }
    }

    return;
}


/*
 * Cast spells at targets using a magical object.
 */
ch_ret obj_cast_spell( int sn, int level, CHAR_DATA *ch, CHAR_DATA *victim, OBJ_DATA *obj )
{
    void *vo;
    ch_ret retcode = rNONE;
    int levdiff = GetAveLevel(ch) - level;
    SKILLTYPE *skill = get_skilltype( sn );
    struct timeval time_used;

    if ( sn == -1 )
        return retcode;
    if ( !skill || !skill->spell_fun )
    {
        bug( "Obj_cast_spell: bad sn %d.", sn );
        return rERROR;
    }

    if (IS_SET( ch->in_room->room_flags, ROOM_NO_MAGIC))
    {
        set_char_color( AT_MAGIC, ch );
        send_to_char( "The magic fizzles and dies, nothing happens...\n\r", ch );
        return rNONE;
    }

    /*
     * Basically this was added to cut down on level 5 players using level
     * 40 scrolls in battle too often ;)		-Thoric
     */
    if ( (skill->target == TAR_CHAR_OFFENSIVE
          ||    number_bits(7) == 1)	/* 1/128 chance if non-offensive */
         &&    skill->type != SKILL_HERB
         &&   !chance( ch, 95 + levdiff ) )
    {
        switch( number_bits(2) )
        {
        case 0: failed_casting( skill, ch, victim, NULL );	break;
        case 1:
            act( AT_MAGIC, "The $t spell backfires!", ch, skill->name, victim, TO_CHAR );
            if ( victim )
                act( AT_MAGIC, "$n's $t spell backfires!", ch, skill->name, victim, TO_VICT );
            act( AT_MAGIC, "$n's $t spell backfires!", ch, skill->name, victim, TO_NOTVICT );
            return damage( ch, ch, number_range( 1, level ), TYPE_UNDEFINED );
        case 2: failed_casting( skill, ch, victim, NULL );	break;
        case 3:
            act( AT_MAGIC, "The $t spell backfires!", ch, skill->name, victim, TO_CHAR );
            if ( victim )
                act( AT_MAGIC, "$n's $t spell backfires!", ch, skill->name, victim, TO_VICT );
            act( AT_MAGIC, "$n's $t spell backfires!", ch, skill->name, victim, TO_NOTVICT );
            return damage( ch, ch, number_range( 1, level ), TYPE_UNDEFINED );
        }
        return rNONE;
    }

    target_name = "";
    switch ( skill->target )
    {
    default:
        bug( "Obj_cast_spell: bad target for sn %d.", sn );
        return rERROR;

    case TAR_IGNORE:
        vo = NULL;
        if ( victim )
            target_name = victim->name;
        else
            if ( obj )
                target_name = obj->name;
        break;

    case TAR_CHAR_OFFENSIVE:
        if ( victim != ch )
        {
            if ( !victim )
                victim = who_fighting( ch );
            if ( !victim || !IS_NPC(victim) )
            {
                send_to_char( "You can't do that.\n\r", ch );
                return rNONE;
            }
        }
        if ( ch != victim && is_safe( ch, victim ) )
            return rNONE;
        vo = (void *) victim;
        break;

    case TAR_CHAR_DEFENSIVE:
        if ( victim == NULL )
            victim = ch;
        vo = (void *) victim;
        if ( skill->type != SKILL_HERB
             &&   IS_SET(victim->immune, RIS_MAGIC ) )
        {
            immune_casting( skill, ch, victim, NULL );
            return rNONE;
        }
        break;

    case TAR_CHAR_SELF:
        vo = (void *) ch;
        if ( skill->type != SKILL_HERB
             &&   IS_SET(ch->immune, RIS_MAGIC ) )
        {
            immune_casting( skill, ch, victim, NULL );
            return rNONE;
        }
        break;

    case TAR_OBJ_INV:
        if ( obj == NULL )
        {
            send_to_char( "You can't do that.\n\r", ch );
            return rNONE;
        }
        vo = (void *) obj;
        break;
    }

    start_timer(&time_used);
    retcode = (*skill->spell_fun) ( sn, level, ch, vo );
    end_timer(&time_used);
    update_userec(&time_used, &skill->userec);

    if ( retcode == rSPELL_FAILED )
        retcode = rNONE;

    if ( retcode == rCHAR_DIED || retcode == rERROR )
        return retcode;

    if ( char_died(ch) )
        return rCHAR_DIED;

    if ( skill->target == TAR_CHAR_OFFENSIVE
         &&   victim != ch
         &&  !char_died(victim) )
    {
        CHAR_DATA *vch;
        CHAR_DATA *vch_next;

        for ( vch = ch->in_room->first_person; vch; vch = vch_next )
        {
            vch_next = vch->next_in_room;
            if ( victim == vch && !victim->fighting && victim->master != ch )
            {
                retcode = multi_hit( victim, ch, TYPE_UNDEFINED );
                break;
            }
        }
    }

    return retcode;
}

/* this function is to handle changes in PULSE_PER_SECOND for spell lag */
void spell_lag(CHAR_DATA *ch, int sn)
{
    int pulses;

    SKILLTYPE *skill = get_skilltype(sn);

    if (!skill)
        return;

    /*
     * convert beats to pulses for pc's
     * npc's run at 1/second so formula is different
     */
    if (!IS_NPC(ch))
        pulses = (skill->beats*PULSE_VIOLENCE)/SPELL_BEATS_PER_ROUND;
    else
        pulses = (skill->beats*4)/SPELL_BEATS_PER_ROUND;

    WAIT_STATE(ch, pulses);

}

void make_charmie(CHAR_DATA *ch, CHAR_DATA *mob, int sn)
{
    AFFECT_DATA af;

    GET_ALIGN(mob) = GET_ALIGN(ch);
    REMOVE_ACT_FLAG(mob, ACT_META_AGGR);
    REMOVE_ACT_FLAG(mob, ACT_AGGRESSIVE);
    REMOVE_ACT_FLAG(mob, ACT_SENTINEL);

    if ( mob->master )
        stop_follower( mob );

    add_follower( mob, ch );

    af.type      = sn;
    af.duration  = (int)((24 * (UMAX(12, get_curr_cha(ch)) / 12)) * DUR_CONV);
    af.location  = 0;
    af.modifier  = 0;
    af.bitvector = AFF_CHARM;
    affect_to_char( mob, &af );
}


/*
 * Spell functions.
 */
ch_ret spell_acid_blast( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int dam;

    dam = dice( level, 6 );
    if ( saves_spell_staff( level, victim ) )
        dam /= 2;
    return damage( ch, victim, dam, sn );
}


ch_ret spell_blindness( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;
    int tmp;
    SKILLTYPE *skill = get_skilltype(sn);

    if ( SPELL_FLAG(skill, SF_PKSENSITIVE)
         &&  !IS_NPC(ch) && !IS_NPC(victim) )
        tmp = level/2;
    else
        tmp = level;

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
    {
        immune_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }
    if ( is_affected(victim, gsn_blindness) ||
         IS_AFFECTED(victim, AFF_BLIND) ||
         saves_spell_staff( tmp, victim ) )
    {
        failed_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    af.type      = sn;
    af.duration  = (short int)((1 + (level / 2)) * DUR_CONV);
    af.bitvector = AFF_BLIND;

    if ( SPELL_POWER(skill) > SP_NONE )
        af.duration *= SPELL_POWER(skill);

    af.location  = APPLY_HITROLL;
    af.modifier  = -4;
    affect_to_char( victim, &af );

    af.location  = APPLY_AC;
    af.modifier  = 20;
    affect_to_char( victim, &af );

    set_char_color( AT_MAGIC, victim );
    send_to_char( "You have been blinded!\n\r", victim );
    if ( ch != victim )
        act(AT_MAGIC,"$n seems to be blinded!",victim,NULL,NULL,TO_ROOM);
    return rNONE;
}


ch_ret spell_burning_hands( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    static const sh_int dam_each[] =
    {
        0,
        0,  0,  0,  0,	14,	17, 20, 23, 26, 29,
        29, 29, 30, 30,	31,	31, 32, 32, 33, 33,
        34, 34, 35, 35,	36,	36, 37, 37, 38, 38,
        39, 39, 40, 40,	41,	41, 42, 42, 43, 43,
        44, 44, 45, 45, 46, 46, 47, 47, 48, 48,
        49, 49, 50, 50, 51, 51, 52, 52, 53, 53,
        54, 54, 55, 55, 56, 56, 57, 57, 58, 58
    };
    int dam;

    level	= UMIN(level, sizeof(dam_each)/sizeof(dam_each[0]) - 1);
    level	= UMAX(0, level);
    dam		= number_range( dam_each[level] / 2, dam_each[level] * 2 );
    if ( saves_spell_staff( level, victim ) )
        dam /= 2;
    return damage( ch, victim, dam, sn );
}



ch_ret spell_call_lightning( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *vch;
    CHAR_DATA *vch_next;
    int dam;
    bool ch_died;
    ch_ret retcode = 0;

    if ( !IS_OUTSIDE(ch) || ch->in_room->area->weather->precip<=0 )
    {
        send_to_char( "The proper atmospheric conditions are not at hand.\n\r", ch );
        return rSPELL_FAILED;
    }

    dam = dice(level/2, 8);

    set_char_color( AT_MAGIC, ch );
    send_to_char( "God's lightning strikes your foes!\n\r", ch );
    act( AT_MAGIC, "$n calls God's lightning to strike $s foes!",
         ch, NULL, NULL, TO_ROOM );

    ch_died = FALSE;
    for ( vch = first_char; vch; vch = vch_next )
    {
        vch_next	= vch->next;
        if ( !vch->in_room )
            continue;
        if ( vch->in_room == ch->in_room )
        {
            if ( !IS_NPC( vch ) && vch->pcdata->wizinvis >= LEVEL_IMMORTAL )
                continue;

            if ( vch != ch && ( IS_NPC(ch) ? !IS_NPC(vch) : IS_NPC(vch) ) )
                retcode = damage( ch, vch, saves_spell_staff( level, vch ) ? dam/2 : dam, sn );
            if ( retcode == rCHAR_DIED || char_died(ch) )
                ch_died = TRUE;
            continue;
        }

        if ( !ch_died
             &&   vch->in_room->area == ch->in_room->area
             &&   IS_OUTSIDE(vch)
             &&   IS_AWAKE(vch) ) {
            set_char_color( AT_MAGIC, vch );
            send_to_char( "Lightning flashes in the sky.\n\r", vch );
        }
    }

    if ( ch_died )
        return rCHAR_DIED;
    else
        return rNONE;
}


ch_ret spell_change_sex( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;
    SKILLTYPE *skill = get_skilltype(sn);

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
    {
        immune_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }
    if ( is_affected( victim, sn ) )
        return rSPELL_FAILED;
    af.type      = sn;
    af.duration  = (int)(10 * level * DUR_CONV);
    af.location  = APPLY_SEX;
    do
    {
        af.modifier  = number_range( 0, 2 ) - victim->sex;
    }
    while ( af.modifier == 0 );
    af.bitvector = 0;
    affect_to_char( victim, &af );
    set_char_color( AT_MAGIC, victim );
    send_to_char( "You feel different.\n\r", victim );
    if ( ch != victim )
        send_to_char( "Ok.\n\r", ch );
    return rNONE;
}


ch_ret spell_charm_person( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int saves;
    SKILLTYPE *skill = get_skilltype(sn);

    if ( victim == ch )
    {
        send_to_char( "You like yourself even better!\n\r", ch );
        return rSPELL_FAILED;
    }

    if ( !IsPerson(victim) ||
         IS_SET( victim->immune, RIS_MAGIC ) ||
         IS_SET( victim->immune, RIS_CHARM ) )
    {
        immune_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    saves = ris_save( victim, level, RIS_CHARM );

    if ( IS_AFFECTED(victim, AFF_CHARM)
         ||   saves == 1000
         ||   IS_AFFECTED(ch, AFF_CHARM)
         ||   GetMaxLevel(victim) > level+10
         ||   circle_follow( victim, ch )
         ||   saves_spell_staff( saves, victim ) )
    {
        failed_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    if (too_many_followers(ch))
    {
        act(AT_MAGIC, "You are not charismatic enough to charm that many.", ch, NULL, victim, TO_CHAR);
        act(AT_MAGIC, "$n is not charismatic enough to charm $N.", ch, NULL, victim, TO_ROOM);
        return rSPELL_FAILED;
    }

    make_charmie(ch, victim, sn);

    act( AT_MAGIC, "Isn't $n just such a nice fellow?", ch, NULL, victim, TO_VICT );
    act( AT_MAGIC, "$N's eyes glaze over...", ch, NULL, victim, TO_ROOM );
    if ( ch != victim )
        send_to_char( "Ok.\n\r", ch );

    sprintf( log_buf, "%s has charmed %s.", ch->name, victim->name);
    log_string_plus( log_buf, LOG_MONITOR, GetMaxLevel(ch), SEV_NOTICE );

    return rNONE;
}


ch_ret spell_chill_touch( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;
    int dam;

    dam = number_range( level, level*3 );

    if ( !saves_spell_staff( level, victim ) )
    {
        af.type      = sn;
        af.duration  = (int)(6 * DUR_CONV);
        af.location  = APPLY_STR;
        af.modifier  = -1;
        af.bitvector = 0;
        affect_join( victim, &af );
    }
    else
    {
        dam /= 2;
    }

    return damage( ch, victim, dam, sn );
}



ch_ret spell_colour_spray( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int dam;

    dam = 4 * level;

    if ( saves_spell_staff( level, victim ) )
        dam /= 2;

    return damage( ch, victim, dam, sn );
}


ch_ret spell_control_weather( int sn, int level, CHAR_DATA *ch, void *vo )
{
    SKILLTYPE *skill = get_skilltype(sn);
    WEATHER_DATA *weath;
    int change;

    if ( !IS_OUTSIDE(ch) )
    {
        send_to_char( "You need to be outside.\n\r", ch );
        return rSPELL_FAILED;
    }

    weath = ch->in_room->area->weather;

    change = number_range(-rand_factor, rand_factor) +
        (GetMaxLevel(ch)*3)/(2*max_vector);

    if ( !str_cmp( target_name, "warmer" ) )
        weath->temp_vector += change;
    else if ( !str_cmp( target_name, "colder" ) )
        weath->temp_vector -= change;
    else if(!str_cmp(target_name, "wetter"))
        weath->precip_vector += change;
    else if(!str_cmp(target_name, "drier"))
        weath->precip_vector -= change;
    else if(!str_cmp(target_name, "windier"))
        weath->wind_vector += change;
    else if(!str_cmp(target_name, "calmer"))
        weath->wind_vector -= change;
    else
    {
        send_to_char ("Do you want it to get warmer, colder, wetter, "
                      "drier, windier, or calmer?\n\r", ch );
        return rSPELL_FAILED;
    }
    weath->temp_vector = URANGE(-max_vector,
                                weath->temp_vector, max_vector);
    weath->precip_vector = URANGE(-max_vector,
                                  weath->precip_vector, max_vector);
    weath->wind_vector = URANGE(-max_vector,
                                weath->wind_vector, max_vector);

    successful_casting( skill, ch, NULL, NULL );
    return rNONE;
}


ch_ret spell_create_food( int sn, int level, CHAR_DATA *ch, void *vo )
{
    OBJ_DATA *mushroom;

    mushroom = create_object( OBJ_VNUM_MUSHROOM );
    if (!mushroom)
    {
        act( AT_MAGIC, "Something blinks in then out of existance.", ch, NULL, NULL, TO_ROOM );
        act( AT_MAGIC, "Something blinks in then out of existance.", ch, NULL, NULL, TO_CHAR );
        return rNONE;
    }
    mushroom->value[0] = 5 + level;
    act( AT_MAGIC, "$p suddenly appears.", ch, mushroom, NULL, TO_ROOM );
    act( AT_MAGIC, "$p suddenly appears.", ch, mushroom, NULL, TO_CHAR );
    mushroom = obj_to_room( mushroom, ch->in_room );
    return rNONE;
}


ch_ret spell_create_water( int sn, int level, CHAR_DATA *ch, void *vo )
{
    OBJ_DATA *obj = (OBJ_DATA *) vo;
    int water;

    if ( obj->item_type != ITEM_DRINK_CON )
    {
        send_to_char( "It is unable to hold water.\n\r", ch );
        return rSPELL_FAILED;
    }

    if ( obj->value[2] != LIQ_WATER && obj->value[1] != 0 )
    {
        send_to_char( "It contains some other liquid.\n\r", ch );
        return rSPELL_FAILED;
    }

    water = UMIN(
                 level * (ch->in_room->area->weather->precip > 0 ? 4 : 2),
                 obj->value[0] - obj->value[1]
                );

    if ( water > 0 )
    {
        separate_obj(obj);
        obj->value[2] = LIQ_WATER;
        obj->value[1] += water;
        if ( !is_name( "water", obj->name ) )
        {
            char buf[MAX_STRING_LENGTH];

            sprintf( buf, "%s water", obj->name );
            STRFREE( obj->name );
            obj->name = STRALLOC( buf );
        }
        act( AT_MAGIC, "$p is filled.", ch, obj, NULL, TO_CHAR );
    }

    return rNONE;
}


ch_ret spell_cure_blindness( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    SKILLTYPE *skill = get_skilltype(sn);

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
    {
        immune_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    if ( !is_affected( victim, gsn_blindness ) )
        return rSPELL_FAILED;
    affect_strip( victim, gsn_blindness );
    set_char_color( AT_MAGIC, victim);
    send_to_char( "Your vision returns!\n\r", victim );
    if ( ch != victim )
        send_to_char( "Ok.\n\r", ch );
    return rNONE;
}


ch_ret spell_cure_poison( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    SKILLTYPE *skill = get_skilltype(sn);

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
    {
        immune_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    if ( is_affected( victim, gsn_poison ) )
    {
        affect_strip( victim, gsn_poison );
        act( AT_MAGIC, "$N looks better.", ch, NULL, victim, TO_ROOM );
        set_char_color( AT_MAGIC, victim);
        send_to_char( "A warm feeling runs through your body.\n\r", victim );
        victim->mental_state = URANGE( -100, victim->mental_state, -10 );
        send_to_char( "Ok.\n\r", ch );
        return rNONE;
    }
    else
        return rSPELL_FAILED;
}


ch_ret spell_curse( int sn, int level, CHAR_DATA *ch, void *vo )
{
    OBJ_DATA *obj = NULL;
    CHAR_DATA *victim = NULL;
    AFFECT_DATA af;
    SKILLTYPE *skill = get_skilltype(sn);

    if ((obj = get_obj_carry(ch, target_name)))
    {
        SET_OBJ_STAT(obj, ITEM_ANTI_GOOD);
        SET_OBJ_STAT(obj, ITEM_NODROP);
        SET_OBJ_STAT(obj, ITEM_NOREMOVE);

        /* LOWER ATTACK DICE BY -1 */
        if(obj->item_type == ITEM_WEAPON)
            obj->value[2]--;
        act(AT_MAGIC, "$p glows red.", ch, obj, NULL, TO_CHAR);

        return rNONE;
    }

    if (!(victim = get_char_room(ch, target_name)))
    {
        act(AT_MAGIC, "Nobody here by that name.", ch, NULL, NULL, TO_CHAR);
        return rNONE;
    }

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
    {
        immune_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    if ( saves_spell_staff(level, victim) ||
         is_affected(victim, gsn_curse))
    {
        failed_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    af.type      = sn;
    af.duration  = (int)(24*7*DUR_CONV);
    af.modifier  = -1;
    af.location  = APPLY_HITROLL;
    af.bitvector = AFF_CURSE;
    affect_to_char(victim, &af);

    af.location = APPLY_SAVING_PARA;
    af.modifier = 1;
    affect_to_char(victim, &af);

    successful_casting( skill, ch, victim, NULL );

    if (IS_NPC(victim) && !who_fighting(victim))
        set_fighting(victim,ch);

    if (!IS_NPC(ch))
        ch->alignment -= 2;

    return rNONE;
}


ch_ret spell_detect_poison( int sn, int level, CHAR_DATA *ch, void *vo )
{
    OBJ_DATA *obj = (OBJ_DATA *) vo;

    set_char_color( AT_MAGIC, ch);
    if ( obj->item_type == ITEM_DRINK_CON || obj->item_type == ITEM_FOOD )
    {
        if ( obj->value[3] != 0 )
            send_to_char( "You smell poisonous fumes.\n\r", ch );
        else
            send_to_char( "It looks very delicious.\n\r", ch );
    }
    else
    {
        send_to_char( "It doesn't look poisoned.\n\r", ch );
    }

    return rNONE;
}


ch_ret spell_dispel_evil( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    SKILLTYPE *skill = get_skilltype(sn);

    if ( !IS_NPC(ch) && IS_EVIL(ch) )
        victim = ch;

    if ( IS_GOOD(victim) )
    {
        act( AT_MAGIC, "Good protects $N.", ch, NULL, victim, TO_ROOM );
        return rSPELL_FAILED;
    }

    if ( IS_NEUTRAL(victim) )
    {
        act( AT_MAGIC, "$N does not seem to be affected.", ch, NULL, victim, TO_CHAR );
        return rSPELL_FAILED;
    }

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
    {
        immune_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    if ( saves_spell_staff( level, victim ) )
    {
        act(AT_MAGIC,"$N resists the attack.",ch,NULL,victim,TO_CHAR);
        act(AT_MAGIC,"You resist $n's attack.",ch,NULL,victim,TO_VICT);
        return damage( ch, victim, 1, sn );
    }

    act(AT_MAGIC,"$n forces $N from this plane.",ch,NULL,victim,TO_ROOM);
    act(AT_MAGIC,"You force $N from this plane.",ch,NULL,victim,TO_CHAR);
    act(AT_MAGIC,"$n forces you from this plane.",ch,NULL,victim,TO_VICT);
    gain_exp(ch,UMIN(GET_EXP(victim)/2,50000));
    extract_char(victim, FALSE);
    return rCHAR_DIED;
}


ch_ret spell_dispel_good( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    SKILLTYPE *skill = get_skilltype(sn);

    if ( !IS_NPC(ch) && IS_GOOD(ch) )
        victim = ch;

    if ( IS_EVIL(victim) )
    {
        act( AT_MAGIC, "Evil protects $N.", ch, NULL, victim, TO_ROOM );
        return rSPELL_FAILED;
    }

    if ( IS_NEUTRAL(victim) )
    {
        act( AT_MAGIC, "$N does not seem to be affected.", ch, NULL, victim, TO_CHAR );
        return rSPELL_FAILED;
    }

    if ( IS_SET( victim->immune, RIS_MAGIC ) )
    {
        immune_casting( skill, ch, victim, NULL );
        return rSPELL_FAILED;
    }

    if ( saves_spell_staff( level, victim ) )
    {
        act(AT_MAGIC,"$N resists the attack.",ch,NULL,victim,TO_CHAR);
        act(AT_MAGIC,"You resist $n's attack.",ch,NULL,victim,TO_VICT);
        return damage( ch, victim, 1, sn );
    }

    act(AT_MAGIC,"$n forces $N from this plane.",ch,NULL,victim,TO_ROOM);
    act(AT_MAGIC,"You force $N from this plane.",ch,NULL,victim,TO_CHAR);
    act(AT_MAGIC,"$n forces you from this plane.",ch,NULL,victim,TO_VICT);
    gain_exp(ch,UMIN(GET_EXP(victim)/2,50000));
    extract_char(victim, FALSE);
    return rCHAR_DIED;
}


ch_ret spell_dispel_magic( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim;
    OBJ_DATA *obj;
    SKILLTYPE *skill = get_skilltype(sn);
    int hitp = 0, tmpgsn;

    if (target_name[0] == '\0')
    {
        send_to_char("Cast this where?\n\r", ch);
        return rSPELL_FAILED;
    }

    victim = get_char_room(ch, target_name);
    obj = get_obj_carry(ch, target_name);
    if (!victim && !obj)
    {
        send_to_char( "I can't find one of those anywhere!\n\r", ch );
        return rSPELL_FAILED;
    }

    if (obj)
    {
        if (IS_OBJ_STAT(obj, ITEM_INVIS))
        {
            act(AT_MAGIC, "$p fades into existance.",ch,obj,NULL,TO_CHAR);
            act(AT_MAGIC, "$p fades into existance.",ch,obj,NULL,TO_ROOM);
            REMOVE_OBJ_STAT(obj, ITEM_INVIS);
        }
        if (IS_OBJ_STAT(obj, ITEM_BLESS))
        {
            act(AT_MAGIC, "$p looks less blessed.",ch,obj,NULL,TO_CHAR);
            act(AT_MAGIC, "$p looks less blessed.",ch,obj,NULL,TO_ROOM);
    

Showing the first 100 KB of 241.0 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571