magic.c

emud/src/magic.c · 202.1 KB

From the archive emud-3.0.tar.gz

Download the archive   « Back to the archive contents

/***************************************************************************
 * Emud  2.2 by Igor van den Hoven, Michiel Lange, and Martin Bethlehem.   *
 *                                                                         *
 * MrMud 1.4 by David Bills and Dug Michael.                               *
 *                                                                         *
 * 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{rfeld, Tom Madsen, and Katje Nyboe.     *
 ***************************************************************************/

#include "emud.h"

/*
	Local functions.
*/

void		say_spell			args( ( CHAR_DATA *ch, int sn ) );
int		multi_spell_level	args( ( CHAR_DATA *ch, int sn ) );
int		can_cast_spell		args( ( CHAR_DATA *ch, int sn ) );

int		caster_levels		args( ( CHAR_DATA *ch ) );
bool		is_safe_magic		args( ( CHAR_DATA *ch, CHAR_DATA *victim, int sn ) );
int		magic_modify		args( ( CHAR_DATA *ch, CHAR_DATA *victim, int sn, int level ) );
bool		can_mass_cast		args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );

#define DO_SPELL(spell) void spell( int sn, int level, CHAR_DATA *ch, void *vo, int target )

int value;	/* This is the value after the target */

void make_char_fight_char( CHAR_DATA *ch, CHAR_DATA *victim )
{
	push_call("make_char_fight_char(%p,%p)",ch,victim);

	if (ch == NULL || victim == NULL || victim->position == POS_DEAD)
	{
		pop_call();
		return;
	}

	if (ch == victim)
	{
		pop_call();
		return;
	}

	/*
		set recently fought
	*/

	if (!IS_NPC(ch) && IS_NPC(victim))
	{
		if (ch->leader && !IS_NPC(ch->leader))
		{
			victim->npcdata->pvnum_last_hit = ch->leader->pcdata->pvnum;
		}
		else
		{
			victim->npcdata->pvnum_last_hit = ch->pcdata->pvnum;
		}
	}
	pop_call();
	return;
}

/*
	Lookup a skill by name.
*/

int skill_lookup( char *name )
{
	int sn;

	push_call("skill_lookup(%p)",name);

	for (sn = 0 ; sn < MAX_SKILL ; sn++)
	{
		if (tolower(name[0]) == skill_table[sn].name[0])
		{
			if (!strcmp(name, skill_table[sn].name))
			{
				pop_call();
				return sn;
			}
		}
	}

	for (sn = 0 ; sn < MAX_SKILL ; sn++)
	{
		if (tolower(name[0]) == skill_table[sn].name[0])
		{
			if (is_multi_name_short(name, skill_table[sn].name))
			{
				pop_call();
				return sn;
			}
		}
	}

	pop_call();
	return -1;
}

/*
	Lookup a skill by slot number.
	Used for object loading.
*/

int slot_lookup( int slot )
{
	int sn;

	push_call("slot_lookup(%p)",slot);

	if (slot <= 0)
	{
		pop_call();
		return 0;
	}

	for (sn = 0 ; sn < MAX_SKILL ; sn++ )
	{
		if (slot == skill_table[sn].slot)
		{
			pop_call();
			return sn;
		}
	}

	bug("slot_lookup: bad slot %d.", slot);

	if (IS_SET(mud->flags, MUD_EMUD_BOOTDB))
	{
		abort();
	}

	pop_call();
	return -1;
}

/*
	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;

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

	static const struct syl_type syl_table[] =
	{
		{ " ",      " "		},
		{ "ar",     "abra"		},
		{ "au",     "kada"		},
		{ "bless",  "fido"		},
		{ "blind",  "nose"		},
		{ "bur",    "mosa"		},
		{ "cu",     "judi"		},
		{ "de",     "oculo"		},
		{ "en",     "unso"		},
		{ "hance",  "sch"		},
		{ "light",  "dies"		},
		{ "lo",     "hi"		},
		{ "mor",    "zak"		},
		{ "move",   "sido"		},
		{ "ob",     "kn"		},
		{ "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" }, {  "", ""  }
	};

	push_call("say_spell(%p,%p)",ch,sn);

	buf[0]	= '\0';

	for (pName = skill_table[sn].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].new);
				break;
			}
		}

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

	sprintf( buf2, "$n utters the words, '%s'.", buf );
	sprintf( buf,  "$n utters the words, '%s'.", skill_table[sn].name );

	/*
	   make wizcloaked gods even more invis,
	   their uttering cannot be heard...
	*/

	if (!IS_NPC(ch) && IS_SET(ch->act, PLR_WIZCLOAK))
	{
		pop_call();
		return;
	}

	for (rch = ch->in_room->first_person ; rch ; rch = rch->next_in_room)
	{
		if (rch != ch)
		{
			if (IS_NPC(rch) || !IS_SET(rch->pcdata->spam, 4096))
			{
				if (IS_NPC(rch) || learned(rch, sn) == 0
				|| (IS_AFFECTED(ch, AFF2_QUICKEN) && !IS_AFFECTED(rch, AFF2_QUICKEN))
				|| (skill_table[sn].follower && which_god(ch) != which_god(rch))
				|| (skill_table[sn].race && ch->race != rch->race))
				{
					act(buf2, ch, NULL, rch, TO_VICT);
				}
				else
				{
					act(buf,  ch, NULL, rch, TO_VICT);
				}
			}
		}
	}

	pop_call();
	return;
}

/*
	Compute a saving throw.
	Negative apply's make saving throw better.
*/

bool saves_spell( int level, CHAR_DATA *ch, CHAR_DATA *victim )
{
	CHAR_DATA *fch;
	int range, point;

	push_call("saves_spell(%p,%p,%p)",level,ch,victim);

	point = 50 + level * 3 / 4;

	if (IS_NPC(victim))
	{
		range = 100 + victim->level / 2 - GET_SAVING_THROW(victim) * 2;
	}
	else
	{
		range = 100 - GET_SAVING_THROW(victim) * 4;
	}

	/* Add a bit of distraction to tanking spell casters - Chaos 7/11/96  */

	for (fch = ch->in_room->first_person ; fch != NULL ; fch = fch->next_in_room)
	{
		if (fch != ch && fch->fighting != NULL && fch->fighting->who == ch)
		{
			range += fch->level/5;
		}
	}

	range -= get_curr_int(ch);

	if (IS_AFFECTED(victim, AFF_PROTECT_EVIL) && IS_EVIL(ch))
	{
		range += 15;
	}

	if (IS_AFFECTED(victim, AFF_PROTECT_GOOD) && IS_GOOD(ch))
	{
		range += 15;
	}

	if (range > 1 && number_range(1, range) >= point)
	{
		pop_call();
		return(TRUE);    /* Spell Fails */
	}
	else
	{
		pop_call();
		return( FALSE );   /* Spell Works */
	}
	/*  Chaos changing to universal scaling system  12/16/94 */
}

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

char *target_name;

void do_cast( CHAR_DATA *ch, char *argument )
{
	char arg1[MAX_INPUT_LENGTH];
	char arg2[MAX_INPUT_LENGTH];
	char arg3[MAX_INPUT_LENGTH];
	CHAR_DATA *victim;
	OBJ_DATA *obj;
	void *vo;
	int mana, sn, level, percentage, target;

	push_call("do_cast(%p,%p)",ch,argument);

	if (strlen(argument) > 100)
	{
		*(argument+80)='\0';
	}

	percentage = 100;

	argument = one_argument(argument, arg1);

	/*
		Grab reduced spell strength percentage value - Chaos 7/26/96
	*/

	if (*arg1 != '\0' && is_number(arg1))
	{
		percentage = atol(arg1);

		argument = one_argument(argument, arg1);

		percentage = URANGE(1, percentage, 100);
	}

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

	if (strlen(target_name) > 50)
	{
		target_name[50] = '\0';
	}

	if (arg1[0] == '\0')
	{
		send_to_char( "Cast which what where?\n\r", ch );
		pop_call();
		return;
	}

	value = -1;   /* Default value */

	if (is_number(arg2))   /*  Special numbers only spell */
	{
		value = atol(arg2);
		strcpy( arg2, "");
		if (value < 1)
		{
			value = -1;   /* Default value */
		}
	}
	else if (arg3[0] != '\0')     /* Read the extra value  - Chaos  2/8/95  */
	{
		value = atol( arg3 );
		if ( value < 1 )
		{
			value = -1;   /* Default value */
		}
	}

	sn = skill_lookup( arg1 );

	if (sn < 0 || !is_spell(sn))
	{
		if (!IS_NPC(ch) && ch->desc == NULL)
		{
			log_printf("[%u] casting unknown spell: %s", ch->pIndexData->vnum, arg1);
		}
		send_to_char( "That is not a spell.\n\r", ch );
		pop_call();
		return;
	}

	if ((level = can_cast_spell(ch, sn)) == -1)
	{
		pop_call();
		return;
	}

	if (is_safe_magic(ch, NULL, sn))
	{
		pop_call();
		return;
	}

	mana  = get_mana(ch, sn);

	level = level * percentage / 100 ;

	if (level < 1)
	{
		level = 1;
	}

	/*
		Locate targets.
	*/

	victim	= NULL;
	obj		= NULL;
	vo		= NULL;
	target	= skill_table[sn].target;

	switch (target)
	{
		default:
			bug( "do_cast: bad target for sn %d.", sn );
			pop_call();
			return;

		case TAR_IGNORE:
			break;

		case TAR_CHAR_OFFENSIVE:
			if (arg2[0] == '\0')
			{
				if (ch->fighting == NULL || ch->fighting->who == NULL)
				{
					send_to_char( "Cast the spell on whom?\n\r", ch );
					pop_call();
					return;
				}
				victim = ch->fighting->who;
			}
			else
			{
				if ((victim = get_char_room(ch, arg2)) == NULL)
				{
					send_to_char( "They aren't here.\n\r", ch );
					pop_call();
					return;
				}
			}
			if (is_safe_magic(ch, victim, sn))
			{
				pop_call();
				return;
			}
			vo = (void *) victim;
			break;

		case TAR_CHAR_DEFENSIVE:

			if (arg2[0] == '\0')
			{
				victim = ch;
			}
			else
			{
				if ((victim = get_char_room(ch, arg2)) == NULL)
				{
					send_to_char( "They aren't here.\n\r", ch );
					pop_call();
					return;
				}
			}

			if (is_safe_magic(ch, victim, sn))
			{
				pop_call();
				return;
			}

			vo = (void *) victim;
			break;

		case TAR_CHAR_SELF:

			if (arg2[0] != '\0' && !is_name_short(arg2, ch->name))
			{
				send_to_char( "You cannot cast this spell on another.\n\r", ch );
				pop_call();
				return;
			}
			vo = (void *) ch;
			break;

		case TAR_OBJ_INV:

			if (arg2[0] == '\0')
			{
				send_to_char( "What should the spell be cast upon?\n\r", ch );
				pop_call();
				return;
			}

			if ((obj = get_obj_carry(ch, arg2)) == NULL)
			{
				send_to_char( "You are not carrying that.\n\r", ch );
				pop_call();
				return;
			}
			vo = (void *) obj;
			break;

		case TAR_OBJ_CHAR_DEF:

			if (arg2[0] == '\0')
			{
				victim = ch;
			}
			else	if ((victim = get_char_room(ch, arg2)) == NULL)
			{
				if ((obj = get_obj_carry(ch, arg2)) == NULL)
				{
					send_to_char( "Who or what should the spell be cast upon?\n\r", ch );
					pop_call();
					return;
				}
			}

			if (victim)
			{
				if (is_safe_magic(ch, victim, sn))
				{
					pop_call();
					return;
				}
				target = TAR_CHAR_DEFENSIVE;
				vo     = (void *) victim;
			}
			else
			{
				target = TAR_OBJ_INV;
				vo     = (void *) obj;
			}
			break;

		case TAR_OBJ_CHAR_OFF:

			if (arg2[0] == '\0')
			{
				if (who_fighting(ch) == NULL)
				{
					send_to_char("Cast the spell on whom?\n\r", ch);
					pop_call();
					return;
				}
				victim = ch->fighting->who;
			}
			else	if ((victim = get_char_room(ch, arg2)) == NULL)
			{
				if ((obj = get_obj_carry(ch, arg2)) == NULL)
				{
					send_to_char( "Who or what should the spell be cast upon?\n\r", ch );
					pop_call();
					return;
				}
			}

			if (victim)
			{
				if (is_safe_magic(ch, victim, sn))
				{
					pop_call();
					return;
				}
				target = TAR_CHAR_OFFENSIVE;
				vo     = (void *) victim;
			}
			else
			{
				target = TAR_OBJ_INV;
				vo     = (void *) obj;
			}
			break;
	}

	if (!IS_IMMORTAL(ch) && ch->mana < mana)
	{
		send_to_char( "You don't have enough mana.\n\r", ch );
		pop_call();
		return;
	}

	if (strcasecmp( skill_table[sn].name, "ventriloquate" ) )
	{
		say_spell( ch, sn );
	}

	if (IS_AFFECTED(ch, AFF2_QUICKEN))
	{
		wait_state( ch, skill_table[sn].beats * 4 / 5 );
	}
	else
	{
		wait_state( ch, skill_table[sn].beats );
	}

	if (!IS_IMMORTAL(ch) && number_percent() > learned(ch, sn))
	{
		if (ch->fighting != NULL)
		{
			switch (number_bits(3))
			{
				case 0 : send_to_char( "This round of battle is too hectic to concentrate properly.\n\r",     ch ); break;
				case 1 : send_to_char( "There wasn't enough time this round to complete the casting.\n\r",    ch ); break;
				case 2 : send_to_char( "Despite your efforts you only produce worthless smoke.\n\r",          ch ); break;
				case 3 : send_to_char( "You lose control over your magic and only scorch the ground.\n\r",    ch ); break;
				case 4 : send_to_char( "The air sizzles with magic, but you fail to strike your victim.\n\r", ch ); break;
				case 5 : send_to_char( "You hesitate mid-way through the casting and nothing happens.\n\r",   ch ); break;
				default: send_to_char( "You lost your concentration.\n\r",                                    ch ); break;
			}
		}
		else
		{
			switch (number_bits(3))
			{
				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;
				case 4 : send_to_char( "You get a mental block mid-way through the casting.\n\r",                    ch ); break;
				default: send_to_char( "You lost your concentration.\n\r",                                           ch ); break;
			}
		}
		ch->mana -= mana / 2;
	}
	else
	{
		if (!IS_IMMORTAL(ch))
		{
			ch->mana -= mana;
		}

		if (number_bits(1) == 0 && is_affected(ch, gsn_mana_shackles))
		{
			switch (number_bits(2))
			{
				case 0:
					act("Your magical shackles send searing lightning through you as you cast.", ch, NULL, NULL, TO_CHAR);
					act("$n's magical shackles send searing lightning through $m as $e casts.",  ch, NULL, NULL, TO_ROOM);
					break;
				case 1:
					act("You reel in shock as your magical shackles claw into you as you cast.", ch, NULL, NULL, TO_CHAR);
					act("$n reels in shock as $s magical shackles claw into $m as $e casts.",    ch, NULL, NULL, TO_ROOM);
					break;
				case 2:
					act("Your magical shackles shock you to the core as you cast.", ch, NULL, NULL, TO_CHAR);
					act("$n's magical shackles shock $m to the core as $e casts.",  ch, NULL, NULL, TO_ROOM);
					break;
				case 3:
					act("You scream out in agony as your magical shackles shock you as you cast.", ch, NULL, NULL, TO_CHAR);
					act("$n screams out in agony as $s magical shackles shock $m as $e casts.",    ch, NULL, NULL, TO_ROOM);
					break;
			}
			ch->hit -= number_range(mana*3, mana*6);
		}

		if (victim && victim != ch && !IS_NPC(victim) && target == TAR_CHAR_OFFENSIVE)
		{
			if (IS_AWAKE(victim) && number_percent() < learned(victim, gsn_lightning_reflexes) / 4)
			{
				switch (number_bits(2))
				{
					case 0:
						act("You dive away from $n's $t with a lightning fast reflex.", ch, skill_table[sn].noun_damage, victim, TO_VICT);
						act("$N dives away from your $t with a lightning fast reflex.", ch, skill_table[sn].noun_damage, victim, TO_CHAR);
						break;
					case 1:
						act("You avoid $n's $t with a lightning fast side step.", ch, skill_table[sn].noun_damage, victim, TO_VICT);
						act("$N avoids your $t with a lightning fast side step.", ch, skill_table[sn].noun_damage, victim, TO_CHAR);
						break;
					case 2:
						act("You throw your body aside escaping from $n's $t.", ch, skill_table[sn].noun_damage, victim, TO_VICT);
						act("$N throws $S body aside escaping from your $t.",   ch, skill_table[sn].noun_damage, victim, TO_CHAR);
						break;
					case 3:
						act("You deftly move aside watching $n's $t go past.", ch, skill_table[sn].noun_damage, victim, TO_VICT);
						act("$N deftly moves aside watching your $t go past.", ch, skill_table[sn].noun_damage, victim, TO_CHAR);
						break;
				}
				check_improve(victim, gsn_lightning_reflexes);
				pop_call();
				return;
			}
		}

		if (victim && victim != ch && number_range(0, 4) == 0)
		{
			if (is_affected(victim, gsn_magic_mirror))
			{
				act("White lightning surrounds you, reflecting $n's magic.", ch, NULL, victim, TO_VICT    );
				act("White lightning surrounds $N, reflecting your magic.",  ch, NULL, victim, TO_CHAR    );
				act("White lightning surrounds $N, reflecting $n's magic.",  ch, NULL, victim, TO_NOTVICT );
				vo = (void *) ch;
				ch = victim;
			}
		}

		level = magic_modify(ch, victim, sn, level);

		(*skill_table[sn].spell_fun) (sn, level, ch, vo, target);

		check_improve(ch, sn);
	}

	if (target == TAR_CHAR_OFFENSIVE)
	{
		if (victim != ch && victim->fighting == NULL)
		{
			make_char_fight_char( ch, victim );
			multi_hit( victim, ch, TYPE_UNDEFINED );
		}
	}
	pop_call();
	return;
}

/*
	Cast spells at targets using a magical object.
*/

void obj_cast_spell( int sn, int level, CHAR_DATA *ch, CHAR_DATA *victim, OBJ_DATA *obj )
{
	void *vo;
	int target;

	push_call("obj_cast_spell(%p,%p,%p,%p,%p)",sn,level,ch,victim,obj);

	if (sn <= 0)
	{
		pop_call();
		return;
	}

	if (sn <= MAX_SKILL && skill_table[sn].slot == -1)
	{
		pop_call();
		return;
	}

	if (is_safe_magic(ch, NULL, sn))
	{
		pop_call();
		return;
	}

	if (sn >= MAX_SKILL || skill_table[sn].spell_fun == 0)
	{
		if (obj != NULL)
		{
			log_printf("obj_cast_spell: Vnum %u bad sn %d.", obj->pIndexData->vnum, sn);
		}
		else
		{
			log_printf("Unknown item cast sn %d", sn);
		}
		pop_call();
		return;
	}

	level  = level * caster_levels(ch) / UMAX(1, ch->level);
	target = skill_table[sn].target;

	switch (target)
	{
		default:
			bug( "obj_cast_spell: bad target for sn %d.", sn );
			pop_call();
			return;

		case TAR_IGNORE:
			vo = NULL;
			break;

		case TAR_CHAR_OFFENSIVE:

			if (victim == ch || victim == NULL)
			{
				if (who_fighting(ch))
				{
					victim = ch->fighting->who;
				}
			}

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

			if (is_safe_magic(ch, victim, sn))
			{
				pop_call();
				return;
			}
			vo = (void *) victim;
			break;

		case TAR_CHAR_DEFENSIVE:

			if (victim == NULL)
			{
				victim = ch;
			}

			if (is_safe_magic(ch, victim, sn))
			{
				pop_call();
				return;
			}

			vo = (void *) victim;
			break;

		case TAR_CHAR_SELF:

			if (victim == NULL)
			{
				victim = ch;
			}

			vo = (void *) ch;
			break;

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

		case TAR_OBJ_CHAR_DEF:

			if (victim)
			{
				if (is_safe_magic(ch, victim, sn))
				{
					pop_call();
					return;
				}
				target = TAR_CHAR_DEFENSIVE;
				vo     = (void *) victim;
			}
			else
			{
				target = TAR_OBJ_INV;
				vo     = (void *) obj;
			}
			break;

		case TAR_OBJ_CHAR_OFF:

			if (victim)
			{
				if (victim == ch && who_fighting(ch))
				{
					victim = ch->fighting->who;
				}

				if (is_safe_magic(ch, victim, sn))
				{
					pop_call();
					return;
				}
				target = TAR_CHAR_OFFENSIVE;
				vo     = (void *) victim;
			}
			else
			{
				target = TAR_OBJ_INV;
				vo     = (void *) obj;
			}
			break;
	}

	target_name = "";

	level = magic_modify(ch, victim, sn, level);

	(*skill_table[sn].spell_fun) ( sn, level, ch, vo, target );

	if (target == TAR_CHAR_OFFENSIVE)
	{
		if (victim != ch && victim->fighting == NULL)
		{
			make_char_fight_char( ch, victim );
			multi_hit( victim, ch, TYPE_UNDEFINED );
		}
	}
	pop_call();
	return;
}

/*
	Magical Totem casting spells on the room
*/

void totem_cast_spell( OBJ_DATA *obj )
{
	CHAR_DATA *totem, *rch, *rch_next;
	int sn, level, target;

	push_call("totem_cast_spell(%p)",obj);

	if (obj->in_room == NULL)
	{
		pop_call();
		return;
	}

	if (obj->in_room->area->nplayer == 0)
	{
		pop_call();
		return;
	}

	if ((totem = mob_index[MOB_VNUM_TOTEM]->first_instance) == NULL)
	{
		pop_call();
		return;
	}

	target_name = "";

	STRFREE(totem->short_descr);
	totem->short_descr = STRDUPE(obj->short_descr);

	char_to_room(totem, obj->in_room->vnum);

	act("The air thickens with magic as $n starts to hum.", totem, NULL, NULL, TO_ROOM);

	for (rch = obj->in_room->first_person ; rch ; rch = rch_next)
	{
		rch_next = rch->next_in_room;

		if (rch == totem)
		{
			continue;
		}

		if (IS_NPC(rch) && IS_AFFECTED(rch, AFF_ETHEREAL))
		{
			continue;
		}

		if (is_affected(rch, gsn_anti_magic_shell))
		{
			continue;
		}

		sn = obj->value[number_range(0,3)];

		if (!is_spell(sn))
		{
			continue;
		}

		level  = obj->level;
		level  = magic_modify(totem, rch, sn, level);
		target = skill_table[sn].target;

		switch (target)
		{
			case TAR_OBJ_CHAR_OFF:
				target = TAR_CHAR_OFFENSIVE;
				break;
			case TAR_OBJ_CHAR_DEF:
				target = TAR_CHAR_DEFENSIVE;
				break;
		}

		(*skill_table[sn].spell_fun) (sn, level, totem, rch, target);
	}

	char_to_room(totem, ROOM_VNUM_TOTEM);

	pop_call();
	return;
}

/*
	Takes any offensive spell for a sorcerer and defensive spell
	for a shaman and applies it to all the appropriate char's.
	Costs more mana than the combined casts, but takes less time.
*/

void do_mass( CHAR_DATA *ch, char *argument )
{
	char arg1[MAX_INPUT_LENGTH];
	CHAR_DATA *victim, *next_vict;
	int sn, sha_mlv, sor_mlv, level, mana, target;

	push_call("do_mass(%p,%p)",ch,argument);

	argument = one_argument( argument, arg1 );

	if (arg1[0] == '\0')
	{
		send_to_char( "Cast which what where?\n\r", ch );
		pop_call();
		return;
	}

	if (!IS_NPC(ch) && multi(ch, gsn_mass) == -1)
	{
		send_to_char( "You can't do that!\n\r", ch );
		pop_call();
		return;
	}

	if (number_percent() > learned(ch, gsn_mass))
	{
		send_to_char("You failed to enter the proper state of mind to amass that much energy!\n\r",ch);
		wait_state(ch, skill_table[gsn_mass].beats);
		pop_call();
		return;
	}

	sn = skill_lookup( arg1 );

	if (sn < 0 || !is_spell(sn))
	{
		send_to_char( "That is not a spell.\n\r", ch );
		if (!IS_NPC(ch) && ch->desc == NULL)
		{
			log_printf("[%u] massing unknown spell: %s", ch->pIndexData->vnum, arg1);
		}
		pop_call();
		return;
	}

	if ((level = can_cast_spell(ch, sn)) == -1)
	{
		pop_call();
		return;
	}

	sha_mlv = (IS_NPC(ch) || IS_IMMORTAL(ch)) ? 100 : ch->pcdata->mclass[CLASS_SHAMAN];
	sor_mlv = (IS_NPC(ch) || IS_IMMORTAL(ch)) ? 100 : ch->pcdata->mclass[CLASS_SORCERER];

	target  = skill_table[sn].target;

	switch (target)
	{
		case TAR_CHAR_OFFENSIVE:
		case TAR_OBJ_CHAR_OFF:
			if (sor_mlv < skill_table[gsn_mass].skill_level[CLASS_SORCERER])
			{
				send_to_char( "You don't have enough skill in the proper class!\n\r", ch );
				pop_call();
				return;
			}
			target = TAR_CHAR_OFFENSIVE;
			break;
		case TAR_CHAR_DEFENSIVE:
		case TAR_OBJ_CHAR_DEF:
			if (sha_mlv < skill_table[gsn_mass].skill_level[CLASS_SHAMAN])
			{
				send_to_char( "You don't have enough skill in the proper class!\n\r", ch );
				pop_call();
				return;
			}
			target = TAR_CHAR_DEFENSIVE;
			break;
		default:
			send_to_char("You would kill yourself trying to amass that much energy!\n\r",ch);
			pop_call();
			return;
 	}

	if (is_safe_magic(ch, NULL, sn))
	{
		pop_call();
		return;
	}

	mana = get_mana(ch, sn) * 5 / 4;

	/*
		Locate targets.
	*/

	switch (target)
	{
		case TAR_CHAR_OFFENSIVE:
			send_to_char("You unleash your magic upon your foes!\n\r", ch);
			break;
		case TAR_CHAR_DEFENSIVE:
			send_to_char("You sent forth your magic to aid your group.\n\r", ch);
			break;
	}

	for (victim = ch->in_room->last_person ; victim ; victim = next_vict)
	{
		next_vict = victim->prev_in_room;

		switch (target)
		{
			case TAR_CHAR_OFFENSIVE:

				if (!can_mass_cast(ch, victim))
				{
					continue;
				}

				if (!IS_IMMORTAL(ch) && ch->mana < mana)
				{
					act("You don't have enough mana for $N.", ch, NULL, victim, TO_CHAR);
					wait_state( ch, skill_table[sn].beats );
					pop_call();
					return;
				}
				if (!IS_IMMORTAL(ch) && number_percent() > learned(ch, sn))
				{
					act("You lost your concentration on $N.", ch, NULL, victim, TO_CHAR);
					ch->mana -= mana / 2;
					continue;
				}

				if (!IS_IMMORTAL(ch))
				{
					ch->mana -= mana;
				}

				level = magic_modify(ch, victim, sn, level);

				(*skill_table[sn].spell_fun) (sn, level, ch, victim, target);

				check_improve(ch, sn);

				if (victim != ch && victim->fighting == NULL)
				{
					make_char_fight_char( ch, victim );
					multi_hit( victim, ch, TYPE_UNDEFINED );
				}
				break;

			case TAR_CHAR_DEFENSIVE:

				if (!is_same_group(ch, victim))
				{
					continue;
				}

				if (is_safe_magic(ch, victim, sn))
				{
					continue;
				}

				if (!IS_IMMORTAL(ch) && ch->mana < mana)
				{
					act("You don't have enough mana for $N.",ch,NULL,victim,TO_CHAR);
					wait_state( ch, skill_table[sn].beats );
					pop_call();
					return;
				}

				if (!IS_IMMORTAL(ch) && number_percent() > learned(ch, sn))
				{
					act("You lost your concentration on $N.",ch,NULL,victim,TO_CHAR);
					ch->mana -= mana / 2;
					continue;
				}
				if (!IS_IMMORTAL(ch))
				{
    					ch->mana -= mana;
    				}

				level = magic_modify(ch, victim, sn, level);

				(*skill_table[sn].spell_fun) ( sn, level, ch, victim, target );

				check_improve(ch, sn);

				break;

		}
	}
	if (IS_AFFECTED(ch, AFF2_QUICKEN))
	{
		wait_state( ch, skill_table[sn].beats * 2 * 4 / 5);
	}
	else
	{
		wait_state( ch, skill_table[sn].beats * 2);
	}
	check_improve(ch, gsn_mass);

	pop_call();
	return;
}

/*
	Finds target in adjusting room and casts the spell on it for
	double mana cost.
*/

void do_range_cast( CHAR_DATA *ch, char *argument )
{
	char *arg1,buf1[MAX_INPUT_LENGTH];
	char *arg2,buf2[MAX_INPUT_LENGTH];
	char *arg3,buf3[MAX_INPUT_LENGTH];
	ROOM_INDEX_DATA *temp_room;
	EXIT_DATA *pexit;
	CHAR_DATA *victim, *next_victim;
	void *vo;
	int mana, sn, dir, level, target;
	long long actn;

	push_call("do_range_cast(%p,%p)",ch,argument);

	if (!IS_NPC(ch) && multi(ch, gsn_range_cast) == -1)
	{
		send_to_char("Better leave the envisioning to the rangecasters.\n\r", ch);
		pop_call();
		return;
	}

	if (strlen( argument) > 120 )
	{
		*(argument+120)='\0';
	}

	target_name = one_argument( argument, buf1 );
	target_name = one_argument( target_name, buf2 );
	target_name = one_argument( target_name, buf3 );

	/*
		Get proper room for given direction
	*/

	if ((dir = direction_door(buf1)) == -1)
	{
		if ((dir = direction_door(buf2)) == -1)
		{
			if ((dir = direction_door(buf3)) == -1)
			{
				send_to_char("Range cast which direction?\n\r",ch);
				pop_call();
				return;
			}

			/* buf3 is direction */

			arg1=buf1;
			arg2=buf2;
			arg3=buf3;
		}

		/* buf2 is direction */

		arg1=buf1;
		arg2=buf3;
		arg3=buf2;
	}
	else
	{
		/* buf1 is direction */

		arg1=buf2;
		arg2=buf3;
		arg3=buf1;
	}

	pexit = get_exit(ch->in_room->vnum, dir);

	if (pexit == NULL
	||  room_index[pexit->to_room]->area != ch->in_room->area
	||  IS_SET(ch->in_room->exit[dir]->exit_info, EX_CLOSED))
	{
		send_to_char( "You can't range cast in that direction!\n\r", ch );
		pop_call();
		return;
	}

	for (victim = room_index[pexit->to_room]->first_person ; victim ; victim = victim->next_in_room)
	{
		if (IS_NPC(victim) && (victim->pIndexData->pShop != NULL))
		{
			send_to_char( "You can't range cast into a shop!\n\r", ch );
			pop_call();
			return;
		}
	}

	if (arg1[0] == '\0')
	{
		send_to_char( "Cast which what where?\n\r", ch );
		pop_call();
		return;
	}

	sn = skill_lookup( arg1 );

	if (sn < 0 || !is_spell(sn))
	{
		if (!IS_NPC(ch) && ch->desc == NULL)
		{
			log_printf("[%u] rangecast unknown spell: %s", ch->pIndexData->vnum, arg1);
		}
		send_to_char( "That is not a spell.\n\r", ch );
		pop_call();
		return;
	}

	if ((level = can_cast_spell(ch, sn)) == -1)
	{
		pop_call();
		return;
	}

	if (is_safe_magic(ch, NULL, sn))
	{
		pop_call();
		return;
	}

	target = skill_table[sn].target;

	switch (target)
	{
		case TAR_OBJ_CHAR_DEF:
			target = TAR_CHAR_DEFENSIVE;
			break;
		case TAR_OBJ_CHAR_OFF:
			target = TAR_CHAR_OFFENSIVE;
			break;
	}

	if (IS_SET(room_index[pexit->to_room]->room_flags, ROOM_SAFE) && (target != TAR_CHAR_DEFENSIVE))
	{
		send_to_char( "You can't range cast in that direction!\n\r", ch );
		pop_call();
		return;
	}

	mana = 3 * get_mana(ch, sn);

	/*
		Locate targets.
	*/

	victim	= NULL;
	vo		= NULL;

	temp_room = ch->in_room;

	switch ( target )
	{
		default:
			bug( "do_range_cast: bad target for sn %d.", sn );
			pop_call();
			return;

		case TAR_CHAR_SELF:
		case TAR_OBJ_INV:
			send_to_char("That type of target is not allowed at range.\n\r",ch);
			pop_call();
			return;

		case TAR_IGNORE:
			break;

		case TAR_CHAR_OFFENSIVE:

			if (arg2[0] == '\0')
			{
				send_to_char( "Range cast whom?\n\r", ch );
				pop_call();
				return;
			}

			ch->in_room = room_index[pexit->to_room];

			if ((victim = get_char_room(ch, arg2)) == NULL)
			{
				send_to_char( "They aren't there.\n\r", ch );
				ch->in_room = temp_room;

				pop_call();
				return;
			}
			ch->in_room = temp_room;

			if (victim == ch)
			{
				send_to_char( "They aren't there.\n\r", ch );
				pop_call();
				return;
			}

			if (is_safe_magic(ch, victim, sn))
			{
				pop_call();
				return;
			}
			vo = (void *) victim;
			break;

		case TAR_CHAR_DEFENSIVE:
			if (arg2[0] == '\0')
			{
				send_to_char( "Range cast whom?\n\r", ch );
				pop_call();
				return;
			}

			ch->in_room = room_index[pexit->to_room];

			if ((victim = get_char_room( ch, arg2 ) ) == NULL)
			{
				send_to_char( "They aren't there.\n\r", ch );
				ch->in_room = temp_room;

				pop_call();
				return;
			}
			ch->in_room = temp_room;

			if (victim == ch)
			{
				send_to_char( "They aren't there.\n\r", ch );
				pop_call();
				return;
			}

			if (is_safe_magic(ch, victim, sn))
			{
				pop_call();
				return;
			}

			vo = (void *) victim;
			break;
	}

	if (!IS_IMMORTAL(ch) && ch->mana < mana)
	{
		send_to_char( "You don't have enough mana.\n\r", ch );
		pop_call();
		return;
	}

	if (number_percent() > learned(ch, gsn_range_cast))
	{
		send_to_char("You envisioned the area but failed to remain focussed.\n\r",ch);
		wait_state(ch, skill_table[sn].beats/2);
		pop_call();
		return;
	}

	wait_state( ch, skill_table[sn].beats);

	send_to_char("You close your eyes, envision the area, and cast!\n\r",ch);

	if (!IS_IMMORTAL(ch) && number_percent() > learned(ch, sn))
	{
		send_to_char( "You lost your concentration.\n\r", ch );
		ch->mana -= mana / 2;
		pop_call();
		return;
	}

	if (!IS_IMMORTAL(ch))
	{
		ch->mana -= mana;
	}

	char_from_room(ch);
	char_to_room(ch, pexit->to_room);

	/* turn off autosac, autoloot */

	actn = ch->act;
	REMOVE_BIT(ch->act, PLR_AUTOSAC|PLR_AUTOLOOT|PLR_AUTO_SPLIT);

	level = magic_modify(ch, victim, sn, level);

	(*skill_table[sn].spell_fun) ( sn, level, ch, vo, target );

	check_improve(ch, sn);

	if (target == TAR_CHAR_OFFENSIVE)
	{
		make_char_fight_char( ch, victim );
	}

	ch->act = actn;

	char_from_room(ch);
	char_to_room(ch, temp_room->vnum);

	/*
		Move some creatures into room of caster
	*/

	if (target == TAR_CHAR_DEFENSIVE)
	{
		pop_call();
		return;
	}

	if (target == TAR_IGNORE)
	{
		if (skill_table[sn].minimum_position != POS_FIGHTING)
		{
			pop_call();
			return;
		}
	}

	for (victim = room_index[pexit->to_room]->last_person ; victim ; victim = next_victim)
	{
		next_victim = victim->prev_in_room;

		if (victim->fighting != NULL && victim->fighting->who != ch)
		{
			continue;
		}

		if (victim->fighting == NULL && number_bits(2) != 0)
		{
			continue;
		}

		if (!IS_NPC(victim) || !IS_IMMORTAL(victim) || IS_AFFECTED(victim, AFF_ETHEREAL) || number_bits(3) == 0)
		{
			continue;
		}

		char_from_room(victim);
		char_to_room(victim, ch->in_room->vnum);

		act("$n arrives, glaring around angrily!", victim, NULL, NULL, TO_ROOM);
		if (!IS_NPC(ch) && victim->npcdata->pvnum_last_hit == ch->pcdata->pvnum)
		{
			make_char_fight_char( ch, victim );
			multi_hit( victim, ch, TYPE_UNDEFINED );
		}
	}
	pop_call();
	return;
}

/*
	Returns -1 if one cannot cast the spell, otherwise it Returns the
	spell level - Scandum 01/04/2002
*/

int can_cast_spell( CHAR_DATA *ch, int sn )
{
	int level;

	push_call("can_cast_spell(%p,%p)",ch,sn);

	if (IS_NPC(ch))
	{
		level = UMAX(ch->level * 3 / 4, 1);

		pop_call();
		return(level);
	}

	if (!IS_IMMORTAL(ch))
	{
		if (!IS_SET(skill_table[sn].race, 1 << ch->race) && multi(ch, sn) == -1)
		{
			send_to_char( "You cannot cast that spell.\n\r", ch );
			pop_call();
			return(-1);
		}
	}

	if (IS_IMMORTAL(ch) || IS_SET(skill_table[sn].race, 1 << ch->race))
	{
		level = ch->level;
	}
	else
	{
		level = multi_spell_level(ch, sn);

		level = level * ch->pcdata->learned[sn] / 100 + 1;
	}

	/*
		Added SFOL check and bonus based on int of caster, ranging from
		103% to 139% for a 0 to 10 reinc lvl 95 human - Scandum 30-03-2002
	*/

	if (IS_IMMORTAL(ch)
	|| (skill_table[sn].follower == SFOL_NONE)
	|| (skill_table[sn].follower & SFOL_ULMO 	&& ch->pcdata->god == GOD_ULMO)
	|| (skill_table[sn].follower & SFOL_DEMISE   && ch->pcdata->god == GOD_DEMISE)
	|| (skill_table[sn].follower & SFOL_GAIA     && ch->pcdata->god == GOD_GAIA)
	|| (skill_table[sn].follower & SFOL_ILUVATAR && ch->pcdata->god == GOD_ILUVATAR)
	|| (skill_table[sn].follower & SFOL_HYPNOS   && ch->pcdata->god == GOD_HYPNOS)
	|| (skill_table[sn].follower & SFOL_MANWE    && ch->pcdata->god == GOD_MANWE))
	{
		if (get_curr_int(ch) > 28)
		{
				level = level * get_curr_int(ch) / 28;
		}
	}
	else
	{
		send_to_char( "You lack the skill with the elements to cast that spell.\n\r", ch );

		pop_call();
		return(-1);
	}
	pop_call();
	return(level);
}

/*
	Returns TRUE and gives appropriate spams if one cannot cast a spell
	on the victim, if victim is NULL only room and ch based stuff is
	checked - Scandum 01-04-2002
*/

bool is_safe_magic( CHAR_DATA *ch, CHAR_DATA *victim, int sn)
{
	push_call("is_safe_magic(%p,%p)",ch,victim);

	if (is_affected(ch, gsn_anti_magic_shell))
	{
		if ((victim && victim != ch) || skill_table[sn].target == TAR_IGNORE)
		{
			send_to_char("The flows of magic shatter against the shell surrounding you.\n\r", ch);
			pop_call();
			return TRUE;
		}
	}

	if (find_keeper(ch) != NULL)
	{
		ch_printf(ch, "%s%s tells you 'No magic in here! You punk!'\n\r", get_color_string(ch,COLOR_SPEACH,VT102_BOLD), capitalize(find_keeper(ch)->short_descr));
		pop_call();
		return TRUE;
	}

	if (IS_SET(ch->in_room->room_flags, ROOM_SAFE))
	{
		if (skill_table[sn].target == TAR_IGNORE)
		{
			if (skill_table[sn].minimum_position == POS_FIGHTING)
			{
				send_to_char( "You cannot do that here.\n\r", ch);
				pop_call();
				return TRUE;
			}
		}
		if (skill_table[sn].target == TAR_CHAR_OFFENSIVE
		||  skill_table[sn].target == TAR_OBJ_CHAR_OFF)
		{
			send_to_char( "You cannot do that here.\n\r", ch);
			pop_call();
			return TRUE;
		}
	}

	if (ch->position < skill_table[sn].minimum_position)
	{
		send_to_char( "You can't concentrate enough.\n\r", ch );
		pop_call();
		return TRUE;
	}

	if (victim == NULL)
	{
		pop_call();
		return FALSE;
	}

	if (victim == ch)
	{
		pop_call();
		return FALSE;
	}

	if (is_affected(victim, gsn_anti_magic_shell))
	{
		act("The flows of magic shatter against the shell surrounding $N.", ch, NULL, victim, TO_CHAR);
		pop_call();
		return TRUE;
	}

	if (ch->fighting != NULL && ch->fighting->who == victim)
	{
		pop_call();
		return FALSE;
	}

	if (ch->in_room->area->low_r_vnum == ROOM_VNUM_ARENA)
	{
		pop_call();
		return FALSE;
	}

	switch (skill_table[sn].target)
	{
		default:

			bug( "is_safe_magic: bad target for sn %d.", sn );
			pop_call();
			return TRUE;
			break;

		case TAR_CHAR_OFFENSIVE:
		case TAR_OBJ_CHAR_OFF:
			if (IS_NPC(ch) && ch->fighting == NULL && ch->hit < ch->max_hit / 2)
			{
				if (ch->desc == NULL)
				{
					pop_call();
					return TRUE;
				}
			}

			if (ch->desc)
			{
				if (!IS_NPC(victim))
				{
					send_to_char( "You must MURDER a player.\n\r", ch);
					pop_call();
					return TRUE;
				}
			}

			if (!IS_NPC(ch))
			{
				ch->pcdata->just_died_ctr = 0;
			}

			if (IS_NPC(victim) && IS_AFFECTED(victim, AFF_CHARM) && victim->master != NULL)
			{
				if (victim->master == ch)
				{
					raw_kill( victim );
					pop_call();
					return TRUE;
				}
			}

			if (ch->fighting == NULL || ch->fighting->who != victim )
			{
				if (!IS_NPC(ch) && IS_NPC(victim) && IS_AFFECTED(victim, AFF_CHARM))
				{
					send_to_char( "You cannot kill a slave.\n\r", ch);
					pop_call();
					return TRUE;
				}
			}

			if (IS_NPC(victim) && victim->fighting != NULL
			&& !IS_NPC(ch) && !is_same_group(ch, victim->fighting->who))
			{
				ch_printf(ch, "%s seems to be busy!\n\r", capitalize(get_name(victim)));
				pop_call();
				return TRUE;
			}

			if (check_recently_fought(ch, victim))
			{
				ch_printf(ch, "%s was recently fought.  Try later.\n\r", capitalize(get_name(victim)));
				pop_call();
				return TRUE;
			}
			break;

		case TAR_CHAR_DEFENSIVE:
		case TAR_OBJ_CHAR_DEF:

			if (!IS_NPC(ch) && victim->fighting != NULL)
			{
				if (!IS_NPC(victim) && !IS_NPC(victim->fighting->who))
				{
					ch_printf(ch ,"%s seems to be busy!\n\r", capitalize(get_name(victim)));
					pop_call();
					return TRUE;
				}
				if (!is_same_group(ch, victim))
				{
					ch_printf(ch ,"%s seems to be busy!\n\r", capitalize(get_name(victim)));
					pop_call();
					return TRUE;
				}
			}
			break;
	}
	pop_call();
	return FALSE;
}

/*
	true if victim is a legal target for a mass attack - Scandum 01/04/2002
*/

bool can_mass_cast( CHAR_DATA *ch, CHAR_DATA *victim )
{
	push_call("can_mass_cast(%p,%p)",ch,victim);

	if (victim == ch)
	{
		pop_call();
		return FALSE;
	}

	if (is_affected(victim, gsn_anti_magic_shell))
	{
		act("The flows of magic shatter against a shell surrounding $N.", ch, NULL, victim, TO_CHAR);
		pop_call();
		return FALSE;
	}

	if (victim->fighting && victim->fighting->who == ch)
	{
		pop_call();
		return TRUE;
	}

	if (victim->fighting && !is_same_group(ch, victim->fighting->who))
	{
		pop_call();
		return FALSE;
	}

	if (IS_NPC(victim) && IS_AFFECTED(victim, AFF_ETHEREAL))
	{
		pop_call();
		return FALSE;
	}

	if (is_same_group(ch, victim))
	{
		pop_call();
		return FALSE;
	}

	if (ch->in_room->area->low_r_vnum == ROOM_VNUM_ARENA)
	{
		pop_call();
		return TRUE;
	}

	if (IS_NPC(victim) && IS_AFFECTED(victim, AFF_CHARM))
	{
		pop_call();
		return FALSE;
	}

	if (!IS_NPC(ch) && !IS_NPC(victim))
	{
		pop_call();
		return FALSE;
	}

	if (IS_NPC(ch) && ch->desc && !IS_NPC(victim))
	{
		pop_call();
		return FALSE;
	}

	if (check_recently_fought(ch, victim))
	{
		pop_call();
		return FALSE;
	}
	pop_call();
	return TRUE;
}

void do_mana( CHAR_DATA *ch, char *argument )
{
	char buf[MAX_STRING_LENGTH];
	int sn;

	push_call("do_mana(%p,%p)",ch,argument);

	if (*argument == '\0')
	{
		send_to_char("Usage: mana <spell name>.\n\r", ch);
		pop_call();
		return;
	}

	sn = skill_lookup( argument );
	if (sn < 0 || !is_spell(sn))
	{
		send_to_char( "That is not a spell.\n\r", ch );
		pop_call();
		return;
	}

	if ((can_cast_spell(ch, sn)) == -1)
	{
		pop_call();
		return;
	}

	sprintf( buf, "Mana usage for '%s' is: %d\n\r",
	skill_table[sn].name, get_mana( ch, sn));
	send_to_char( buf, ch);
	pop_call();
	return;
}

int get_mana( CHAR_DATA *ch, int sn)
{
	int mana,mnx,cnt;

	push_call("get_mana(%p,%p)",ch,sn);

	if (IS_NPC(ch) || IS_SET(skill_table[sn].race, 1 << ch->race))
	{
		mana = skill_table[sn].min_mana;
	}
	else
	{
		cnt = multi(ch, sn);

		mnx = skill_table[sn].skill_level[cnt] / 2 + 1;

		mana = 50 * mnx / (ch->pcdata->mclass[cnt] + mnx - skill_table[sn].skill_level[cnt]) - (get_curr_wis(ch)-13) / 2;

		mana = UMAX(skill_table[sn].min_mana, mana);
	}

	if (IS_AFFECTED(ch, AFF2_QUICKEN))
	{
		mana += mana;
	}

	pop_call();
	return(mana);
}

void do_move( CHAR_DATA *ch, char *argument )
{
	char buf[MAX_STRING_LENGTH];
	int sn, cnt, move;

	push_call("do_move(%p,%p)",ch,argument);

	sn = skill_lookup( argument );
	if( sn < 0 || is_spell(sn))
	{
		send_to_char( "That doesn't cost any movement.\n\r", ch );
		pop_call();
		return;
	}

	cnt = multi( ch, sn);

	if(cnt==-1 && !IS_NPC(ch))
	{
		send_to_char( "You can't do that.\n\r", ch );
		pop_call();
		return;
	}
	move = IS_NPC(ch) ? 0 : skill_table[sn].min_mana;

	sprintf(buf,"Movement usage for '%s' is: %d\n\r",skill_table[sn].name,move);
	send_to_char(buf,ch);
	pop_call();
	return;
}

bool is_spell(int sn)
{
	push_call("is_spell(%p)",sn);

	if (sn > 0 && sn < MAX_SKILL && IS_SET(skill_table[sn].flags, FSKILL_SPELL))
	{
		pop_call();
  		return TRUE;
  	}

	pop_call();
	return FALSE;
}

int caster_levels( CHAR_DATA *ch )
{
	int levels;

	push_call("caster_levels(%p)",ch);

	if (IS_NPC(ch))
	{
		pop_call();
		return( ch->level );
	}

	levels  = ch->pcdata->mclass[ CLASS_DRUID     ];
	levels += ch->pcdata->mclass[ CLASS_SORCERER  ];
	levels += ch->pcdata->mclass[ CLASS_SHAMAN    ];
	levels += ch->pcdata->mclass[ CLASS_WARLOCK   ];
	/*
		Non specialist caster-levels count only half	21/10/2000 - Manwe
	*/
	levels += ch->pcdata->mclass[ CLASS_WARRIOR   ] / 2;
	levels += ch->pcdata->mclass[ CLASS_MARAUDER  ] / 2;
	levels += ch->pcdata->mclass[ CLASS_GLADIATOR ] / 2;
	levels += ch->pcdata->mclass[ CLASS_NINJA     ] / 2;

	if (levels > ch->level)
	{
		levels = ch->level;
	}
	pop_call();
	return( levels );
}

int magic_modify( CHAR_DATA *ch, CHAR_DATA *victim, int sn, int level )
{
	int dam_type = DAM_THRUST;

	push_call("damage_modify(%p,%p,%p,%p)",ch,victim,sn,level);

	if (level <= 0)
	{
		pop_call();
		return 0;
	}

	if (victim == NULL)
	{
		pop_call();
		return level;
	}

	switch (skill_table[sn].target)
	{
		case TAR_CHAR_DEFENSIVE:
		case TAR_OBJ_CHAR_DEF:
			if (!IS_IMMORTAL(ch) && victim != ch)
			{
				if (level > victim->level * 2)
				{
					level = victim->level * 2;
				}
			}
			break;
	}

	dam_type = skill_table[sn].dam_type;

	if (dam_type == DAM_NONE)
	{
		pop_call();
		return level;
	}

	if (dam_type == god_table[which_god(victim)].resistance)
	{
		level = level * 75 / 100;
	}

	if (IS_UNDEAD(victim))
	{
		if (IS_SET(DAM_LIFE|DAM_POISON|DAM_EVIL, dam_type))
		{
			level = level * 75 / 100;
		}
	}

	if (IS_SET(race_table[victim->race].res_low, dam_type))
	{
		level = level * 90 / 100;
	}

	if (IS_SET(race_table[victim->race].res_high, dam_type))
	{
		level = level * 80 / 100;
	}

	if (IS_SET(race_table[victim->race].vul_low, dam_type))
	{
		level = level * 110 / 100;
	}

	if (IS_SET(race_table[victim->race].vul_high, dam_type))
	{
		level = level * 120 / 100;
	}

	level = UMAX(1, level);

	pop_call();
	return level;
}

int multi_spell_level( CHAR_DATA *ch, int sn)
{
	int cnt, mlv;

	push_call("multi_spell_level(%p,%p)",ch,sn);

	mlv = 0;

	if (IS_NPC(ch))
	{
		mlv = ch->level;
		pop_call();
		return(mlv);
	}

	for (cnt = 0 ; cnt < MAX_CLASS ; cnt++)
	{
		if (skill_table[sn].skill_level[cnt] < MAX_LEVEL)
		{
			mlv += ch->pcdata->mclass[cnt];
		}
		else if (cnt >= 4)
		{
			mlv += ch->pcdata->mclass[cnt] * 3 / 4;
		}
		else
		{
			mlv += ch->pcdata->mclass[cnt] * 1 / 4;
		}
	}
	if (mlv > ch->level)
	{
		mlv = ch->level;
	}
	if (ch->race == RACE_HUMAN)
	{
		mlv += ch->pcdata->reincarnation;
	}
	pop_call();
	return(mlv);
}

ROOM_INDEX_DATA *get_rift_room( CHAR_DATA *ch, int rift_number)
{
	ROOM_INDEX_DATA *rift_room;

	push_call("get_rift_room(%p,%p)",ch,rift_number);

	srand(value + ch->pcdata->pvnum + 1);

	while (TRUE)
	{
		rift_room = get_room_index(rand() % 20000);

		if (rift_room == NULL)
		{
			continue;
		}
		if (IS_SET(rift_room->room_flags, ROOM_SAFE))
		{
			continue;
		}
		if (IS_SET(rift_room->room_flags, ROOM_IS_CASTLE))
		{
			continue;
		}
		if (IS_SET(rift_room->room_flags, ROOM_PET_SHOP))
		{
			continue;
		}
		if (IS_SET(rift_room->room_flags, ROOM_PRIVATE))
		{
			continue;
		}
		if (IS_SET(rift_room->room_flags, ROOM_SOLITARY))
		{
			continue;
		}
		if (IS_SET(rift_room->room_flags, ROOM_NO_RECALL))
		{
			continue;
		}
		if (rift_room->sector_type == SECT_ETHEREAL)
		{
			continue;
		}
		if (rift_room->sector_type == SECT_ASTRAL)
		{
			continue;
		}
		if (IS_SET(rift_room->area->flags, AFLAG_NOTELEPORT))
		{
			continue;
		}
		if (IS_SET(rift_room->area->flags, AFLAG_NORECALL))
		{
			continue;
		}
		if (IS_SET(rift_room->area->flags, AFLAG_NORIP))
		{
			continue;
		}
		if (!IS_IMMORTAL(ch))
		{
			if (ch->level < rift_room->area->low_hard_range)
			{
				continue;
			}
			if (ch->level > rift_room->area->hi_hard_range)
			{
				continue;
			}
		}
		break;
	}
	pop_call();
	return rift_room;
}

/*
	Spell functions.
*/

DO_SPELL(spell_acid_blast)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_acid_blast(%p,%p,%p,%p)",sn,level,ch,vo);

	dam = number_range(level*3+50, level*5+100);

	if ( saves_spell( level, ch, victim ) )
	{
		dam /= 2;
	}
	damage( ch, victim, dam, sn );

	pop_call();
	return;
}

DO_SPELL(spell_armor)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_armor(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( is_affected( victim, sn ) )
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}

	af.type = sn;

	if (!IS_NPC(ch) && ch->pcdata->mclass[CLASS_DRUID] > 0)
	{
		af.duration  = 48;
		af.modifier  = -15;
	}
	else
	{
		af.duration  = 24;
		af.modifier  = -5;
	}
	af.location  = APPLY_AC;
	af.bittype   = AFFECT_TO_NONE;
	af.bitvector = 0;
	affect_to_char( victim, &af );

	act( "$n's armor begins to glow softly as it is enhanced by a cantrip.", victim, NULL, NULL, TO_ROOM );
	send_to_char( "Your armor begins to glow softly as it is enhanced by a cantrip.\n\r", victim );

	pop_call();
	return;
}

DO_SPELL(spell_bless)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_bless(%p,%p,%p,%p)",sn,level,ch,vo);

	if( is_affected( victim, sn ) )
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type      = sn;
	af.duration  = 6+level/2;
	af.bittype   = AFFECT_TO_NONE;
	af.bitvector = 0;

	af.location  = APPLY_HITROLL;
	af.modifier  = level/9;
	affect_to_char( victim, &af );

	af.location  = APPLY_SAVING_SPELL;
	af.modifier  = 0 - level / 8;
	affect_to_char( victim, &af );

	act( "A powerful blessing is laid upon $n.", victim, NULL, NULL, TO_ROOM );
	send_to_char( "A powerful blessing is laid upon you.\n\r", victim );
	pop_call();
	return;
}

DO_SPELL(spell_blindness)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_blindness(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( IS_AFFECTED(victim, AFF_BLIND) )
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}

	if (IS_AFFECTED(victim, AFF_TRUESIGHT ))
	{
		act( "$N sees through the veil on reality you try to impose.", ch, NULL, victim, TO_CHAR );
		act( "You see through the veil on reality $n attempts to impose.", ch, NULL, victim, TO_VICT );
		pop_call();
		return;
	}

	if ( saves_spell( level, ch, victim ) )
	{
		send_to_char( "Nothing happens.\n\r", ch );
		pop_call();
		return;
	}

	af.type      = sn;
	af.location  = APPLY_HITROLL;
	af.modifier  = -2*level/5;
	af.duration  = 1+level/5;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF_BLIND;
	affect_to_char( victim, &af );

	send_to_char( "You are blinded!\n\r", victim );

	if ( ch != victim )
	{
		send_to_char( "Your foe is now blinded.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_burning_hands)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_burning_hands(%p,%p,%p,%p)",sn,level,ch,vo);

	dam  = number_range( level+50, level+100 );

	if (saves_spell(level, ch, victim))
	{
		dam /= 2;
	}
	damage( ch, victim, dam, sn );

	pop_call();
	return;
}

DO_SPELL(spell_call_lightning)
{
	CHAR_DATA *vch, *vch_next;
	int dam, door, temp_vnum;
	EXIT_DATA *pexit;

	push_call("spell_call_lightning(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( !IS_OUTSIDE(ch) )
	{
		send_to_char( "You must be out of doors.\n\r", ch );
		pop_call();
		return;
	}

	if (NO_WEATHER_SECT(ch->in_room->sector_type))
	{
		send_to_char( "You must be out of doors.\n\r", ch );
		pop_call();
		return;
	}

	if ( ch->in_room->area->weather_info->sky < SKY_RAINING )
	{
		send_to_char( "You need bad weather.\n\r", ch );
		pop_call();
		return;
	}

	send_to_char( "Elemental lightning strikes your foes!\n\r", ch );
	act( "$n calls elemental lightning to strike $s foes!", ch, NULL, NULL, TO_ROOM );

	for (vch = ch->in_room->last_person ; vch ; vch = vch_next)
	{
		vch_next = vch->prev_in_room;

		if (!can_mass_cast(ch, vch))
		{
			continue;
		}
		dam = number_range(level*1, level*4);
		damage( ch, vch, saves_spell(level, ch, vch) ? dam/2 : dam, sn );
	}

	temp_vnum = ch->in_room->vnum;

	for (door = 0 ; door < 6 ; door++)
	{
		if ((pexit = get_exit(temp_vnum, door)) && pexit->to_room != temp_vnum)
		{
			ch->in_room = room_index[pexit->to_room];
			act("Lightning flashes in the sky.", ch, NULL, NULL, TO_ROOM );
		}
	}
	ch->in_room = room_index[temp_vnum];

	pop_call();
	return;
}

DO_SPELL(spell_chain_lightning)
{
	CHAR_DATA *vch, *vch_next;
	ROOM_INDEX_DATA *temp_room = ch->in_room;
	int dam, targets;

	push_call("spell_chain_lightning(%p,%p,%p,%p)",sn,level,ch,vo);

	if (!IS_OUTSIDE(ch) || NO_WEATHER_SECT(ch->in_room->sector_type))
	{
		send_to_char( "You must be out of doors.\n\r", ch );
		pop_call();
		return;
	}

	if (ch->in_room->area->weather_info->sky < SKY_RAINING)
	{
		level = level * 2 / 3;
	}

	if (ch->in_room->area->weather_info->sky < SKY_LIGHTNING)
	{
		level = level * 2 / 3;
	}

	act( "You call forth a bolt of chain lightning!", ch, NULL, NULL, TO_CHAR );
	act( "$n calls forth a bolt of chain lightning!", ch, NULL, NULL, TO_ROOM );

	while (level > 0)
	{
		for (targets = 0, vch = ch->in_room->last_person ; vch ; vch = vch_next)
		{
			vch_next = vch->prev_in_room;

			if (!can_mass_cast(ch, vch))
			{
				continue;
			}

			dam     = saves_spell(level, ch, vch) ? dice(level, 3) : dice(level, 6);
			level  -= 20;
			targets += 1;

			switch (number_bits(2))
			{
				case 0:
					act("The searing bolt of chain lightning arcs to you.", vch, NULL, NULL, TO_CHAR);
					act("The searing bolt of chain lightning arcs to $n.",  vch, NULL, NULL, TO_ROOM);
					break;
				case 1:
					act("The sizzling bolt of chain lightning arcs to you.", vch, NULL, NULL, TO_CHAR);
					act("The sizzling bolt of chain lightning arcs to $n.",  vch, NULL, NULL, TO_ROOM);
					break;
				case 2:
					act("The crackling bolt of chain lightning arcs to you.", vch, NULL, NULL, TO_CHAR);
					act("The crackling bolt of chain lightning arcs to $n.",  vch, NULL, NULL, TO_ROOM);
					break;
				case 3:
					act("The fiery bolt of chain lightning arcs to you.", vch, NULL, NULL, TO_CHAR);
					act("The fiery bolt of chain lightning arcs to $n.",  vch, NULL, NULL, TO_ROOM);
					break;
			}
			damage( ch, vch, dam, sn );

			if (level <= 0)
			{
				break;
			}
		}
		if (level > 0)
		{
			if (targets == 1)
			{
				vch     = ch;
				dam     = saves_spell(level, ch, vch) ? dice(level, 6) : dice(level, 3);
				level  -= 20;

				switch (number_bits(2))
				{
					case 0:
						act("The searing bolt of chain lightning arcs to you.", vch, NULL, NULL, TO_CHAR);
						act("The searing bolt of chain lightning arcs to $n.",  vch, NULL, NULL, TO_ROOM);
						break;
					case 1:
						act("The sizzling bolt of chain lightning arcs to you.", vch, NULL, NULL, TO_CHAR);
						act("The sizzling bolt of chain lightning arcs to $n.",  vch, NULL, NULL, TO_ROOM);
						break;
					case 2:
						act("The crackling bolt of chain lightning arcs to you.", vch, NULL, NULL, TO_CHAR);
						act("The crackling bolt of chain lightning arcs to $n.",  vch, NULL, NULL, TO_ROOM);
						break;
					case 3:
						act("The fiery bolt of chain lightning arcs to you.", vch, NULL, NULL, TO_CHAR);
						act("The fiery bolt of chain lightning arcs to $n.",  vch, NULL, NULL, TO_ROOM);
						break;
				}
				damage( ch, vch, dam, sn );
			}

			if (ch->in_room != temp_room)
			{
				send_to_room("The bolt of chain lightning loses power and fizzles out.\n\r", temp_room);
				pop_call();
				return;
			}

			if (targets == 0)
			{
				act("You catch the bolt of lightning and send it back into the sky.",   ch, NULL, NULL, TO_CHAR);
				act("$n catches the bolt of lightning and sends it back into the sky.", ch, NULL, NULL, TO_ROOM);
				pop_call();
				return;
			}
		}
	}

	switch (number_bits(2))
	{
		case 0: send_to_room("The searing bolt of chain lightning loses power and fizzles out.\n\r",          temp_room); break;
		case 1: send_to_room("The sizzling bolt of chain lightning arcs to the ground and dissipates.\n\r",   temp_room); break;
		case 2: send_to_room("The crackling arc of chain lightning strikes the ground and vanishes.\n\r",     temp_room); break;
		case 3: send_to_room("The fiery bolt of chain lightning loses power before reaching its target.\n\r", temp_room); break;
	}

	pop_call();
	return;
}

DO_SPELL(spell_cause_light)
{
	push_call("spell_cause_light(%p,%p,%p,%p)",sn,level,ch,vo);

	damage( ch, (CHAR_DATA *) vo, dice(1, 15) + level / 2, sn );

	pop_call();
	return;
}

DO_SPELL(spell_cause_serious)
{
	push_call("spell_cause_serious(%p,%p,%p,%p)",sn,level,ch,vo);

	damage( ch, (CHAR_DATA *) vo, dice(1, 25) + level * 2 / 3, sn );

	pop_call();
	return;
}

DO_SPELL(spell_cause_critical)
{
	push_call("spell_cause_critical(%p,%p,%p,%p)",sn,level,ch,vo);

	damage( ch, (CHAR_DATA *) vo, dice(1, 50) + level, sn );

	pop_call();
	return;
}

DO_SPELL(spell_change_sex)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_change_sex(%p,%p,%p,%p)",sn,level,ch,vo);

	if (IS_SET(ch->in_room->room_flags, ROOM_SAFE))
	{
		send_to_char("You are forbidden from casting that here.\n\r", ch);
		pop_call();
		return;
	}
	if ( is_affected( victim, sn ) )
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type      = sn;
	af.duration  = level/4;
	af.location  = APPLY_SEX;

	if (victim->sex <= 0)
	{
		if (number_bits(1) == 0)
		{
			af.modifier  = 1;
		}
		else
		{
			af.modifier  = 2;
		}
	}
	else if (victim->sex == 1)
	{
		if (number_bits(1) == 0)
		{
			af.modifier  = 1;
		}
		else
		{
			af.modifier  = -1;
		}
	}
	else if (victim->sex >= 2)
	{
		if (number_bits(1) == 0)
		{
			af.modifier  = -1;
		}
		else
		{
			af.modifier  = -2;
		}
	}
	af.bittype   = AFFECT_TO_NONE;
	af.bitvector = 0;
	affect_to_char( victim, &af );

	send_to_char( "You writhe in agony as your gender changes.\n\r", victim );
	act( "$n writhes in agony as $s gender changes.", victim, NULL, NULL, TO_ROOM);

	pop_call();
	return;
}

DO_SPELL(spell_charm_person)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_charm_person(%p,%p,%p,%p)",sn,level,ch,vo);

	if (IS_SET(ch->in_room->room_flags, ROOM_SAFE))
	{
		send_to_char("You are forbidden from casting that here.\n\r", ch);
		pop_call();
		return;
	}

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

	if (!IS_NPC(victim) || !can_mass_cast(ch, victim))
	{
		send_to_char( "They seem to be unaffected by your magic.\n\r", ch );
		pop_call();
		return;
	}

	if (IS_AFFECTED(victim, AFF_CHARM))
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}

	if (level/3 < victim->level
	||  saves_spell(level, ch, victim)
	||  get_pets(ch) >= 2)
	{
		do_say(victim, "I don't want to be charmed!");
		act( "$n suddenly looks VERY angry!",victim,NULL,NULL,TO_ROOM);
		if (victim->fighting == NULL)
		{
			make_char_fight_char( ch, victim );
			multi_hit(victim, ch, TYPE_UNDEFINED);
		}
		pop_call();
		return;
	}

	if ( victim->master )
	{
		stop_follower( victim );
	}

	add_follower( victim, ch );
	af.type      = sn;
	af.duration  = number_fuzzy( level / 4 );
	af.location  = 0;
	af.modifier  = 0;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF_CHARM;
	affect_to_char( victim, &af );

	act( "Isn't $n just so nice?", ch, NULL, victim, TO_VICT );
	act( "$N looks at you with adoring eyes.", ch, NULL, victim, TO_CHAR );
	act( "$N looks at $n with adoring eyes.",  ch, NULL, victim, TO_NOTVICT );
	pop_call();
	return;
}

DO_SPELL(spell_chill_touch)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;

	int dam;

	push_call("spell_chill_touch(%p,%p,%p,%p)",sn,level,ch,vo);

	dam = number_range(level+10, level+130);

	if (saves_spell(level, ch, victim))
	{
		dam /= 2;
	}
	else if (number_bits(1) == 0)
	{
		AFFECT_DATA af;

		af.type      = sn;
		af.duration  = 1;
		if (!IS_NPC(victim))
		{
			af.location  = APPLY_STR;
		}
		else
		{
			af.location  = APPLY_DAMROLL;
		}
		af.modifier  = -1;
		af.bittype   = AFFECT_TO_NONE;
		af.bitvector = 0;
		affect_join( victim, &af );
	}

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

DO_SPELL(spell_stone_fist)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;
	int body_part = 0;

	push_call("spell_stone_fist(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( is_affected( victim, sn ) )
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type = sn;

	if (which_god(victim) == GOD_GAIA)
	{
		af.duration  = 24;
	}
	else
	{
		af.duration  = 8;
	}
	af.modifier  = 0;
	af.location  = APPLY_NONE;
	af.bittype   = AFFECT_TO_NONE;
	af.bitvector = 0;
	affect_to_char( victim, &af );

	if (IS_NPC(victim) && IS_SET(victim->act, ACT_BODY))
	{
		body_part = victim->pIndexData->attack_parts;
	}
	else if (!IS_NPC(victim) || IS_SET(victim->act, ACT_RACE))
	{
		body_part = race_table[victim->race].attack_parts;
	}

	if (IS_SET(body_part, BODY_TENTACLE))
	{
		act( "$n's tentacles turn to stone.", victim, NULL, NULL, TO_ROOM );
		send_to_char( "Your tentacles turn to stone.\n\r", victim );
	}
	else if (IS_SET(body_part, BODY_CLAW))
	{
		act( "$n's claws turn to stone.", victim, NULL, NULL, TO_ROOM );
		send_to_char( "Your claws turn to stone.\n\r", victim );
	}
	else if (IS_SET(body_part, BODY_BRANCH))
	{
		act( "$n's branches turn to stone.", victim, NULL, NULL, TO_ROOM );
		send_to_char( "Your branches turn to stone.\n\r", victim );
	}
	else
	{
		act( "$n's fists turn to stone.", victim, NULL, NULL, TO_ROOM );
		send_to_char( "Your fists turn to stone.\n\r", victim );
	}
	pop_call();
	return;
}

DO_SPELL(spell_color_spray)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_color_spray)",sn,level,ch,vo);

	dam = number_range( level*3+30, level*5+40 );

	if ( saves_spell( level, ch, victim ) )
	{
		damage( ch, victim, dam/2, sn);
	}
	else
	{
		/*
			Added blindness as an extra effect to this spell,
			21/10/2000 - Manwe
			Lets not make it too easy pls, merged the two spells into one
			01/04/2002 - Scandum
		*/

		damage( ch, victim, dam, sn );

		if (ch->in_room == victim->in_room && number_bits(3) == 0 && !IS_AFFECTED(victim, AFF_BLIND))
		{
			AFFECT_DATA af;

			af.type      = gsn_blindness;
			af.location  = APPLY_HITROLL;
			af.modifier  = -1*level/5;
			af.duration  = level/10;
			af.bittype   = AFFECT_TO_CHAR;
			af.bitvector = AFF_BLIND;
			affect_to_char( victim, &af );

			send_to_char( "You are blinded by a dazzling ray of light!\n\r", victim );
			if (ch != victim)
			{
				send_to_char( "A dazzling ray of light blinds your foe.\n\r", ch );
			}
		}
	}

	pop_call();
	return;
}

DO_SPELL(spell_continual_light)
{
	OBJ_DATA *light;

	push_call("spell_continual_light(%p,%p,%p,%p)",sn,level,ch,vo);

	light = create_object( get_obj_index( OBJ_VNUM_LIGHT_BALL ), 0 );
	light->timer = level / 2;
	light->level = level;
	act( "Shards of iridescent light collide to form a dazzling ball.", ch, NULL, NULL, TO_CHAR );
	act( "Shards of iridescent light collide to form a dazzling ball.", ch, NULL, NULL, TO_ROOM );
	obj_to_room( light, ch->in_room->vnum );
	pop_call();
	return;
}

DO_SPELL(spell_control_weather)
{
	push_call("spell_control_weather(%p,%p,%p,%p)",sn,level,ch,vo);

	if (!strcasecmp(target_name, "wet"))
	{
		ch->in_room->area->weather_info->change		+= 1 + level / 33;
	}
	else if (!strcasecmp(target_name, "dry"))
	{
		ch->in_room->area->weather_info->change		-= 1 + level / 33;
	}
	else if (!strcasecmp(target_name, "windy"))
	{
		ch->in_room->area->weather_info->wind_speed	+= 1 + level / 33;
	}
	else if (!strcasecmp(target_name, "calm"))
	{
		ch->in_room->area->weather_info->wind_speed	-= 1 + level / 33;
	}
	else
	{
		send_to_char ("Do you want the weather calm, windy, wet, or dry?\n\r", ch );
		pop_call();
		return;
	}
	send_to_char( "Ok.\n\r", ch );
	pop_call();
	return;
}

DO_SPELL(spell_feast)
{
	CHAR_DATA *fch;

	push_call("spell_feast(%p,%p,%p,%p)",sn,level,ch,vo);

	/*
		Added blood feast for undead and vampiric races - Scandum 01/04/2002
	*/

	if (rspec_req(ch, RSPEC_VAMPIRIC) || rspec_req(ch, RSPEC_UNDEAD))
	{
		act( "$n spreads $s arms and blood spurts forth from $s opened hands.",     ch, NULL, NULL, TO_ROOM );
		act( "You spread your arms and blood spurts forth from your opened hands.", ch, NULL, NULL, TO_CHAR );
		act( "Everyone in the room joins you as you drink your fill.",              ch, NULL, NULL, TO_CHAR );

		gain_condition( ch, COND_FULL,   50 );
		gain_condition( ch, COND_THIRST, 50 );

		for (fch = ch->in_room->first_person ; fch ; fch = fch->next_in_room)
		{
			if (!IS_NPC(fch) && fch->position >= POS_RESTING && fch != ch)
			{
				if (!rspec_req(fch,RSPEC_VAMPIRIC) && !rspec_req(fch,RSPEC_UNDEAD))
				{
					send_to_char( "You turn away your head in dismay as the undeads drink.\n\r", fch );
				}
				else
				{
					gain_condition( fch, COND_FULL,   50 );
					gain_condition( fch, COND_THIRST, 50 );
					send_to_char( "You join in the blood feast and drink your fill.\n\r", fch );
				}
			}
		}
	}
	else
	{
		act( "$n creates a large selection of food and drinks.",     ch, NULL, NULL, TO_ROOM );
		act( "You create a large selection of food and drinks.",     ch, NULL, NULL, TO_CHAR );
		act( "Everyone in the room joins you as you eat your fill.", ch, NULL, NULL, TO_CHAR );

		gain_condition( ch, COND_FULL, 50 );
		gain_condition( ch, COND_THIRST, 50 );

		for (fch = ch->in_room->first_person ; fch ; fch = fch->next_in_room)
		{
			if (!IS_NPC(fch) && fch->position >= POS_RESTING && fch != ch)
			{
				if (!rspec_req(fch,RSPEC_VAMPIRIC) && !rspec_req(fch,RSPEC_UNDEAD))
				{
					gain_condition( fch, COND_FULL, 50 );
					gain_condition( fch, COND_THIRST, 50 );
					send_to_char( "You join in the feast and eat your fill.\n\r", fch );
				}
				else
				{
					send_to_char( "You turn away your head in dismay as the mortals eat.\n\r", fch );
				}
			}
		}
	}
	pop_call();
	return;
}

DO_SPELL(spell_restore)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int heal, scale_top, scale_bot;
	char buf[MAX_INPUT_LENGTH];

	push_call("spell_restore(%p,%p,%p,%p)",sn,level,ch,vo);

	scale_top = 10;  /* The fraction for the hp/mana ratio */
	scale_bot = 7;

	if (value == -1 || value > ch->mana )
	{
		value = ch->mana;
	}

	heal = value * scale_top / scale_bot ;

	if (victim->hit + heal > victim->max_hit)
	{
		heal = victim->max_hit - victim->hit ;
	}

	value = heal * scale_bot / scale_top;

	sprintf( buf, "Restoring %d hitpoints for %d mana.\n\r", heal, value + get_mana(ch,sn));
	send_to_char( buf, ch);

	victim->hit += heal;
	ch->mana -= value;

	update_pos( victim );
	send_to_char( "You are filled with an overwhelming feeling of warmth.\n\r", victim );
	affect_strip(victim, gsn_critical_hit);
	if ( ch != victim )
	{
		send_to_char( "You restore them.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_energy_shift)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int heal, scale_top, scale_bot;
	char buf[MAX_INPUT_LENGTH];

	push_call("spell_energy_shift(%p,%p,%p,%p)",sn,level,ch,vo);

	scale_top = 65;  /* The fraction for the mana_to/mana_from ratio */
	scale_bot = 100;

	if( value == -1 || value > ch->mana )
	{
		value = ch->mana;
	}

	heal = value * scale_top / scale_bot ;
	if( victim->mana + heal > victim->max_mana )
	{
		heal = victim->max_mana - victim->mana ;
	}
	value = ( heal * scale_bot / scale_top );

	sprintf( buf, "Shifting %d mana for %d mana.\n\r", heal, value + get_mana(ch,sn));
	send_to_char( buf, ch);

	victim->mana += heal;
	ch->mana -= value;

	update_pos( victim );
	send_to_char( "You feel a surge of power.\n\r", victim );
	if ( ch != victim )
	{
		send_to_char( "You transfer energy to them.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_induction)
{
	int heal, scale_top, scale_bot;
	char buf[MAX_INPUT_LENGTH];

	push_call("spell_induction(%p,%p,%p,%p)",sn,level,ch,vo);

	scale_top = 7;  /* The fraction for the mana_to/hp_from ratio */
	scale_bot = 10;

	if (value < 0 || value > ch->hit - 10 )
	{
		value = ch->hit-10;
	}

	heal = value * scale_top / scale_bot;

	if (ch->mana + heal > ch->max_mana)
	{
		heal = ch->max_mana - ch->mana ;
     }

	if (heal < 0)
	{
		heal = 0;
	}
	value = heal * scale_bot / scale_top;

	sprintf( buf, "Inducing %d mana points for %d hitpoints.\n\r", heal, value );
	send_to_char( buf, ch);

	ch->mana += heal;
	ch->hit -= value;

	update_pos( ch );
	if (heal > 0)
	{
		send_to_char( "You feel a surge of power.\n\r", ch );
		act( "$n drains $s strength to further $s magic.", ch, NULL, NULL, TO_ROOM);
	}
	pop_call();
	return;
}

DO_SPELL(spell_create_food)
{
	OBJ_DATA *mushroom;

	push_call("spell_create_food(%p,%p,%p,%p)",sn,level,ch,vo);

	mushroom = create_object( get_obj_index( OBJ_VNUM_MUSHROOM ), 0 );
	mushroom->value[0] = 5 + level;
	act( "$p suddenly appears.", ch, mushroom, NULL, TO_ROOM );
	act( "$p suddenly appears.", ch, mushroom, NULL, TO_CHAR );
	obj_to_room( mushroom, ch->in_room->vnum );

	pop_call();
	return;
}

DO_SPELL(spell_create_spring)
{
	OBJ_DATA *spring;

	push_call("spell_create_spring(%p,%p,%p,%p)",sn,level,ch,vo);

	spring = create_object( get_obj_index( OBJ_VNUM_SPRING ), 0 );
	spring->timer = level;
	act( "Tracing a ring before you, the graceful flow of a mystical spring emerges.", ch, spring, NULL, TO_CHAR );
	act( "As $n traces a ring through the air, the graceful flow of a mystical spring emerges.", ch, spring, NULL, TO_ROOM );
	obj_to_room( spring, ch->in_room->vnum );

	pop_call();
	return;
}

DO_SPELL(spell_ice_arrow)
{
	OBJ_DATA *arrow;
	int type;

	push_call("spell_ice_arrow(%p,%p,%p,%p)",sn,level,ch,vo);

	if ((type = get_flag(target_name, bow_types)) == -1)
	{
		ch_printf(ch, "Create what kind of arrow, %s?\n\r", give_flags(bow_types));
		pop_call();
		return;
	}
	arrow = create_object(get_obj_index(OBJ_VNUM_ICE_ARROW), 0);

	arrow->value[0] = type;
	arrow->value[1] = level;
	arrow->value[2] = URANGE(10, level/4, 20);
	arrow->value[3] = 5;
	arrow->level    = level / 2;

	SET_BIT(arrow->extra_flags, ITEM_MODIFIED);

	act("$p of frigid, dangerous beauty takes shape in your hand.", ch, arrow, NULL, TO_CHAR);
	act("$p of frigid, dangerous beauty takes shape in $n's hand.", ch, arrow, NULL, TO_ROOM);

	if (ch->carry_number < can_carry_n(ch) && ch->carry_weight < can_carry_w(ch))
	{
		obj_to_char(arrow, ch);
	}
	else
	{	
		obj_to_room(arrow, ch->in_room->vnum);
	}
	pop_call();
	return;
}

DO_SPELL(spell_cure_blindness)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;

	push_call("spell_cure_blindness(%p,%p,%p,%p)",sn,level,ch,vo);

	if (!is_affected(victim, gsn_blindness))
	{
		if (!is_affected(victim, gsn_gouge))
		{
			if (!is_affected(victim, gsn_flash_powder))
			{
				send_to_char( "They aren't blinded.\n\r", ch );
	
				pop_call();
				return;
			}
		}
	}

	affect_strip( victim, gsn_blindness );
	affect_strip( victim, gsn_gouge );
	affect_strip( victim, gsn_flash_powder );

	send_to_char( "Your vision returns!\n\r", victim );

	if (ch != victim)
	{
		send_to_char( "They are no longer blinded.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_cure_light)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int heal;

	push_call("spell_cure_light(%p,%p,%p,%p)",sn,level,ch,vo);

	heal = dice(1, 15) + level / 2;

	victim->hit = UMIN( victim->hit + heal, victim->max_hit );
	update_pos( victim );

	send_to_char( "Your light wounds mend and your pain ebbs slightly.\n\r", victim );

	if (ch != victim)
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_cure_serious)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int heal;

	push_call("spell_cure_serious(%p,%p,%p,%p)",sn,level,ch,vo);

	heal = dice(1, 25) + level * 2 / 3 ;

	victim->hit = UMIN( victim->hit + heal, victim->max_hit );
	update_pos( victim );

	send_to_char( "Your serious wounds mend and your pain ebbs away.\n\r", victim );

	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_cure_critical)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int heal;

	push_call("spell_cure_critical(%p,%p,%p,%p)",sn,level,ch,vo);

	heal = dice(1, 50) + level;

	victim->hit = UMIN( victim->hit + heal, victim->max_hit );
	update_pos( victim );

	send_to_char( "Your critical wounds close and your pain ebbs away.\n\r", victim );
	affect_strip(victim,gsn_critical_hit);

	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_cure_poison)
{
	CHAR_DATA	*victim = (CHAR_DATA *) vo;
	bool		cured   = FALSE;

	push_call("spell_cure_poison(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( is_affected( victim, gsn_poison ) )
	{
		affect_strip( victim, gsn_poison );
		cured = TRUE;
	}

	if (victim->poison != NULL)
	{
		POISON_DATA *npd, *pd;
		cured = TRUE;

		pd = victim->poison;
		victim->poison = NULL;

		while (pd != NULL)
		{
			npd = pd->next;
			FREEMEM( pd );
			pd = npd;
		}
	}

	if ( cured )
	{
		act( "$N looks better.", ch, NULL, victim, TO_CHAR );
		act( "$N looks better.", ch, NULL, victim, TO_ROOM );
		send_to_char( "A warm feeling runs through your body.\n\r", victim );
	}
	else
	{
		act( "$N does not seem to be poisoned.", ch, NULL, victim, TO_CHAR );
	}
	pop_call();
	return;
}

DO_SPELL(spell_curse)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_curse(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( IS_AFFECTED(victim, AFF_CURSE) )
	{
		send_to_char( "They are already cursed.\n\r", ch );
		pop_call();
		return;
	}

	if ( saves_spell( level, ch, victim ) )
	{
		send_to_char( "Your curse did not strike them.\n\r", ch );
		pop_call();
		return;
	}

	af.type      = sn;
	af.duration  = level/15;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF_CURSE;

	af.location  = APPLY_SAVING_SPELL;
	af.modifier  = UMAX(level/20, 3);
	affect_to_char( victim, &af );

	af.location  = APPLY_HITROLL;
	af.modifier  = UMIN(level/-10, -6);
	affect_to_char( victim, &af );

	send_to_char( "You feel unclean.\n\r", victim );

	if ( ch != victim )
	{
		send_to_char( "Your foe is now cursed.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_detect_evil)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_detect_evil(%p,%p,%p,%p)",sn,level,ch,vo);

	if (is_affected(victim, sn))
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type      = sn;
	af.duration  = level;
	af.modifier  = 0;
	af.location  = APPLY_NONE;
	af.bittype   = AFFECT_TO_NONE;
	af.bitvector = 0;
	affect_to_char( victim, &af );

	send_to_char( "Traces of red outline all evil in plain sight.\n\r", victim );

	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_detect_hidden)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_detect_hidden(%p,%p,%p,%p)",sn,level,ch,vo);

	if (IS_AFFECTED(victim, AFF_DETECT_HIDDEN) || IS_AFFECTED(victim, AFF_TRUESIGHT))
	{
		send_to_char( "You are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type      = sn;
	af.duration  = level;
	af.location  = APPLY_NONE;
	af.modifier  = 0;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF_DETECT_HIDDEN;
	affect_to_char( victim, &af );

	send_to_char( "Your senses are heightened to those of an animal.\n\r", victim );

	pop_call();
	return;
}

DO_SPELL(spell_detect_invis)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_detect_invis(%p,%p,%p,%p)",sn,level,ch,vo);

	if (IS_AFFECTED(victim, AFF_DETECT_INVIS) || IS_AFFECTED(victim, AFF_TRUESIGHT))
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type      = sn;
	af.duration  = level;
	af.modifier  = 0;
	af.location  = APPLY_NONE;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF_DETECT_INVIS;
	affect_to_char( victim, &af );

	send_to_char( "Your eyes fixate as they gain the ability to see the unseen.\n\r", victim );

	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_detect_poison)
{
	OBJ_DATA *obj = (OBJ_DATA *) vo;

	push_call("spell_detect_poison(%p,%p,%p,%p)",sn,level,ch,vo);

	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 );
	}
	pop_call();
	return;
}

/*
	Changed dispel spells slightly, you now damage the victim and make
	it gain or lose alignment, when the victim hits neutral alignment
	their gear will be checked for zappers - Scandum 01/04/2002
*/

DO_SPELL(spell_dispel_evil)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_dispel_evil(%p,%p,%p,%p)",sn,level,ch,vo);

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

	if (!IS_EVIL(victim))
	{
		act( "$N does not seem to be affected.", ch, NULL, victim, TO_CHAR );
		pop_call();
		return;
	}

	dam = number_range(level, level * 5);

	if ( saves_spell( level, ch, victim ) )
	{
		dam /= 2;
	}

	damage( ch, victim, dam, sn );

	victim->alignment += 5;

	if (IS_NEUTRAL(victim))
	{
		check_zap(victim, TRUE);
	}
	pop_call();
	return;
}

DO_SPELL(spell_dispel_good)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_dispel_good(%p,%p,%p,%p)",sn,level,ch,vo);

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

	if (!IS_GOOD(victim))
	{
		act( "$N does not seem to be affected.", ch, NULL, victim, TO_CHAR );
		pop_call();
		return;
	}

	dam = number_range (level, level * 5);

	if ( saves_spell( level, ch, victim ) )
	{
		dam /= 2;
	}

	damage( ch, victim, dam, sn );

	victim->alignment -= 5;

	if (IS_NEUTRAL(victim))
	{
		check_zap(victim, TRUE);
	}
	pop_call();
	return;
}

DO_SPELL(spell_dispel_undead)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_dispel_undead(%p,%p,%p,%p)",sn,level,ch,vo);

	if (IS_NPC(victim) && !IS_SET(victim->act , ACT_UNDEAD))
	{
		if (!rspec_req(victim, RSPEC_UNDEAD))
		{
			act( "$N is not affected.", ch, NULL, victim, TO_CHAR);
			pop_call();
			return;
		}
	}

	dam = number_range(level*3, level*9);

	if ( saves_spell( level/2, ch, victim ) )
	{
		dam /= 3;
	}
	damage( ch, victim, dam, sn );
	pop_call();
	return;
}

DO_SPELL(spell_dispel_magic)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	OBJ_DATA *obj = (OBJ_DATA *) vo;
	AFFECT_DATA *paf, *paf_prev;
	int paf_type;

	push_call("spell_dispel_magic(%p,%p,%p,%p)",sn,level,ch,vo);

	if (target == TAR_CHAR_DEFENSIVE)
	{
		if (saves_spell(level, ch, victim))
		{
			send_to_char( "You failed.\n\r", ch );
			pop_call();
			return;
		}

		for (paf_type = 0, paf = victim->last_affect ; paf ; paf = paf_prev)
		{
			paf_prev = paf->prev;

			if (!is_spell(paf->type))
			{
				continue;
			}

			switch (paf->bitvector)
			{
				case AFF2_POSSESS:
				case AFF_CHARM:
					continue;
			}

			if (paf_type && paf->type != paf_type)
			{
				continue;
			}

			if (paf_type == 0 && paf->duration >= 0)
			{
				if (skill_table[paf->type].msg_off)
				{
					act(skill_table[paf->type].msg_off, victim, NULL, NULL, TO_CHAR);
				}
			}
			paf_type = paf->type;
			affect_from_char(victim, paf);
		}

		if (paf_type == 0)
		{
			send_to_char( "Nothing appears to happen.\n\r", ch );
		}
		else if (victim != ch)
		{
			send_to_char( "Their magic spells seem to vanish slowly.\n\r", ch );
		}
	}
	else
	{
		for (paf_type = 0, paf = obj->last_affect ; paf ; paf = paf_prev)
		{
			paf_prev = paf->prev;

			if (!is_spell(paf->type))
			{
				continue;
			}

			if (paf_type && paf->type != paf_type)
			{
				continue;
			}

			if (paf_type == 0 && paf->duration >= 0)
			{
				if (skill_table[paf->type].msg_obj_off)
				{
					act(skill_table[paf->type].msg_obj_off, ch, obj, NULL, TO_CHAR);
				}
			}
			paf_type = paf->type;
			affect_from_obj(obj, paf);
		}

		if (paf_type == 0)
		{
			send_to_char( "Nothing appears to happen.\n\r", ch );
		}
	}
	pop_call();
	return;
}

DO_SPELL(spell_earthquake)
{
	CHAR_DATA *vch;
	CHAR_DATA *vch_next;
	EXIT_DATA *pexit;
	int door, temp_vnum;

	push_call("spell_earthquake(%p,%p,%p,%p)",sn,level,ch,vo);

	/*
		no earthquakes in the air
	*/

	if (ch->in_room->sector_type == SECT_AIR)
	{
		send_to_char("The earth trembles far beneath you.\n\r",ch);
		pop_call();
		return;
	}

	send_to_char( "The earth trembles beneath your feet!\n\r", ch );
	act( "$n makes the earth tremble and shiver.", ch, NULL, NULL, TO_ROOM );

	temp_vnum = ch->in_room->vnum;

	for (door = 0 ; door <= 5 ; door++)
	{
		if ((pexit = get_exit(temp_vnum, door)) && pexit->to_room != temp_vnum)
		{
			ch->in_room = room_index[pexit->to_room];
			act("The earth trembles and shivers.", ch, NULL, NULL, TO_ROOM );
		}
	}
	ch->in_room = room_index[temp_vnum];

	for (vch = ch->in_room->last_person ; vch ; vch = vch_next)
	{
		vch_next	= vch->prev_in_room;

		if (CAN_FLY(vch))
		{
			continue;
		}
		if (!can_mass_cast(ch, vch))
		{
			continue;
		}
		damage( ch, vch, level + dice(2, 8), sn );
	}
	pop_call();
	return;
}

DO_SPELL(spell_tremor)
{
	CHAR_DATA *vch;
	CHAR_DATA *vch_next;
	EXIT_DATA *pexit;
	int door, temp_vnum;

	push_call("spell_tremor(%p,%p,%p,%p)",sn,level,ch,vo);

	if (ch->in_room->sector_type == SECT_AIR)
	{
		send_to_char("The earth tremors far beneath you.\n\r",ch);
		pop_call();
		return;
	}

	temp_vnum = ch->in_room->vnum;

	for (door = 0 ; door <= 5 ; door++)
	{
		if ((pexit = get_exit(temp_vnum, door)) && pexit->to_room != temp_vnum)
		{
			ch->in_room = room_index[pexit->to_room];
			act("You hear a loud wrenching noise from the ground.", ch, NULL, NULL, TO_ROOM );
		}
	}
	ch->in_room = room_index[temp_vnum];

	send_to_char( "The earth tremors beneath your feet!\n\r", ch );
	act( "$n makes the earth shake.", ch, NULL, NULL, TO_ROOM );

	for (vch = ch->in_room->last_person ; vch ; vch = vch_next)
	{
		vch_next	= vch->prev_in_room;

		if (CAN_FLY(vch))
		{
			continue;
		}
		if (!can_mass_cast(ch, vch))
		{
			continue;
		}
		if (number_bits(3) == 0)
		{
			vch->position = POS_RESTING;
		}
		damage(ch, vch, number_range(level * 2, level * 3) + dice(5, 20), sn);
	}
	pop_call();
	return;
}

DO_SPELL(spell_enchant_weapon)
{
	OBJ_DATA *obj = (OBJ_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_enchant_weapon(%p,%p,%p,%p)",sn,level,ch,vo);

	if (!IS_NPC(ch) && multi(ch, sn) == -1)
	{
		send_to_char( "You can't do that!\n\r", ch);
		pop_call();
		return;
	}

	if (obj->item_type != ITEM_WEAPON || IS_OBJ_STAT(obj, ITEM_MAGIC) || obj->first_affect != NULL)
	{
		send_to_char( "That object cannot be enchanted.\n\r", ch);
		pop_call();
		return;
	}

	SET_BIT(obj->extra_flags, ITEM_MODIFIED);
	SET_BIT(obj->extra_flags, ITEM_MAGIC);

	af.type		= sn;
	af.duration	= -1;
	af.bittype	= AFFECT_TO_NONE;
	af.bitvector	= 0;

	af.location	= APPLY_HITROLL;
	af.modifier	= level / 5;

	affect_to_obj(obj, &af);

	af.location	= APPLY_DAMROLL;
	af.modifier	= level / 10;

	affect_to_obj(obj, &af);

	obj->level += level/3;


	if (IS_GOOD(ch))
	{
		SET_BIT(obj->extra_flags, ITEM_ANTI_EVIL);
		act("$p glows yellow.", ch, obj, NULL, TO_ROOM);
	}
	else if (IS_EVIL(ch))
	{
		SET_BIT(obj->extra_flags, ITEM_ANTI_GOOD);
		act("$p glows red.", ch, obj, NULL, TO_ROOM);
	}
	else
	{
		SET_BIT(obj->extra_flags, ITEM_ANTI_EVIL);
		SET_BIT(obj->extra_flags, ITEM_ANTI_GOOD);
		act("$p glows blue.", ch, obj, NULL, TO_ROOM);
	}

	act("$p has been enchanted.", ch, obj, NULL, TO_CHAR);
	pop_call();
	return;
}

DO_SPELL(spell_energy_bolt)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_energy_bolt(%p,%p,%p,%p)",sn,level,ch,vo);

	dam = 10 + number_range(level, level*2);

	if ( saves_spell( level, ch, victim ) )
	{
		dam /= 2;
	}
	damage( ch, victim, dam, sn );

	pop_call();
	return;
}

DO_SPELL(spell_energy_drain)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_energy_drain(%p,%p,%p,%p)",sn,level,ch,vo);

	if (saves_spell(5 * level / 4, ch, victim))
	{
		switch(number_range(1,3))
		{

			case 1: act( "$N shrugs off your deathly embrace!", ch, NULL, victim, TO_CHAR); break;
			case 2: act( "$N flinches but is unharmed.", ch, NULL, victim, TO_CHAR); break;
			case 3: act( "$N moans softly from your spine chilling spell, but is otherwise unharmed.", ch, NULL, victim, TO_CHAR); break;
		}
		pop_call();
		return;
	}

	if (!IS_NPC(victim))
	{
		gain_exp(victim, 0 - dice(level, 5));
	}
	dam			= number_range(level * 2, level * 4) + 50;
	ch->hit		= UMIN(ch->hit + dam / 6, ch->max_hit);
	victim->move	= UMAX(0, victim->move - number_fuzzy(dam) / 3);
	victim->mana	= UMAX(0, victim->mana - number_fuzzy(dam) / 3);

	damage( ch, victim, dam, sn );

	pop_call();
	return;
}

DO_SPELL(spell_fireball)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_fireball(%p,%p,%p,%p)",sn,level,ch,vo);

	dam   = number_range( level*3 , level*5);

	if (saves_spell(level, ch, victim))
	{
		dam /= 2;
	}
	damage( ch, victim, dam, sn );

	pop_call();
	return;
}

DO_SPELL(spell_flamestrike)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_flamestrike(%p,%p,%p,%p)",sn,level,ch,vo);

	dam = number_range(level, level+150);

	if ( saves_spell( level, ch, victim ) )
	{
		dam /= 2;
	}
	damage( ch, victim, dam, sn );

	pop_call();
	return;
}

DO_SPELL(spell_faerie_fire)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_faerie_fire(%p,%p,%p,%p)",sn,level,ch,vo);

	if (is_affected(victim, gsn_faerie_fire))
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type      = sn;
	af.duration  = level;
	af.location  = APPLY_AC;
	af.modifier  = 2 * level;
	af.bittype   = AFFECT_TO_NONE;
	af.bitvector = 0;
	affect_to_char( victim, &af );

	send_to_char( "You are surrounded by a pink outline.\n\r", victim );
	act( "$n is surrounded by a pink outline.", victim, NULL, NULL, TO_ROOM );

	pop_call();
	return;
}

DO_SPELL(spell_faerie_fog)
{
	CHAR_DATA *ich;

	push_call("spell_faerie_fog(%p,%p,%p,%p)",sn,level,ch,vo);

	act( "$n conjures a cloud of purple smoke.", ch, NULL, NULL, TO_ROOM );
	send_to_char( "You conjure a cloud of purple smoke.\n\r", ch );

	for ( ich = ch->in_room->first_person; ich != NULL; ich = ich->next_in_room )
	{
		if ( !IS_NPC(ich) && IS_SET(ich->act, PLR_WIZINVIS) )
			continue;

		if ( !IS_NPC(ich) && IS_SET(ich->act, PLR_WIZCLOAK) )
			continue;

		if( IS_NPC(ich) && IS_AFFECTED(ich, AFF_ETHEREAL) )
			continue;

		if ( ich == ch || saves_spell( level, ch, ich ) )
			continue;

		affect_strip ( ich, gsn_invis					);
		affect_strip ( ich, gsn_sneak					);
		affect_strip ( ich, gsn_stealth				);
		REMOVE_BIT   ( ich->affected_by, AFF_HIDE		);
		REMOVE_BIT   ( ich->affected_by, AFF_INVISIBLE	);
		REMOVE_BIT   ( ich->affected_by, AFF_SNEAK		);
		REMOVE_BIT   ( ich->affected_by, AFF_STEALTH		);
		REMOVE_BIT   ( ich->affected_by, AFF_IMP_INVISIBLE);
		act( "$n is revealed!", ich, NULL, NULL, TO_ROOM );
		send_to_char( "You are revealed!\n\r", ich );
	}
	pop_call();
	return;
}

DO_SPELL(spell_fly)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_fly(%p,%p,%p,%p)",sn,level,ch,vo);

	if (IS_AFFECTED(victim, AFF2_EARTHBIND))
	{
		send_to_char("They are bound to the earth.\n\r", ch);
		pop_call();
		return;
	}

	if (CAN_FLY(victim))
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type      = sn;
	af.duration  = level + 3;
	af.location  = 0;
	af.modifier  = 0;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF_FLYING;
	affect_to_char( victim, &af );
	send_to_char( "Your feet rise off the ground.\n\r", victim );
	act( "$n's feet rise off the ground.", victim, NULL, NULL, TO_ROOM );

	pop_call();
	return;
}

DO_SPELL(spell_gate)
{
	CHAR_DATA *victim;
	OBJ_DATA *gate;

	push_call("spell_gate(%p,%p,%p,%p)",sn,level,ch,vo);

	if (target_name[0] == '\0')
	{
		send_to_char("Whom would you want to gate to?\n\r", ch);
		pop_call();
		return;
	}

	if ((victim = get_char_area(ch, target_name)) == NULL)
	{
		send_to_char("There is none named like that.\n\r", ch);
		pop_call();
		return;
	}

	if  (IS_SET(ch->in_room->room_flags, ROOM_IS_CASTLE)
	||  (IS_NPC(victim) && level / 3 < victim->level)
	|| (!IS_NPC(victim) && level - 3 < victim->level))
	{
		send_to_char( "They are protected from your power.\n\r", ch);
		pop_call();
		return;
	}

	if (!IS_NPC(victim) && is_affected(victim, gsn_anti_magic_shell))
	{
		act("The flows of magic shatter against a shell surrounding $N.", ch, NULL, victim, TO_CHAR);
		pop_call();
		return;
	}

	if (victim == ch
	|| victim->in_room == NULL
	|| IS_SET(victim->in_room->room_flags, ROOM_SAFE)
	|| IS_SET(victim->in_room->room_flags, ROOM_PRIVATE)
	|| IS_SET(victim->in_room->room_flags, ROOM_SOLITARY)
	|| IS_SET(victim->in_room->room_flags, ROOM_NO_RECALL)
	|| IS_SET(ch->in_room->room_flags, ROOM_NO_RECALL)
	|| victim->in_room->sector_type == SECT_ETHEREAL
	|| victim->in_room->sector_type == SECT_ASTRAL
	|| ch->in_room->sector_type == SECT_ETHEREAL
	|| ch->in_room->sector_type == SECT_ASTRAL
	|| IS_SET(ch->in_room->area->flags, AFLAG_NORECALL)
	|| IS_SET(ch->in_room->area->flags, AFLAG_NOSUMMON)
	|| victim->level > UMIN(ch->level-3, level - 3)
	|| find_keeper(victim) != NULL)
	{
		send_to_char( "You failed.\n\r", ch );
		pop_call();
		return;
	}

	if (ch->in_room == victim->in_room)
	{
		send_to_char("You are already there.\n\r",ch);
		pop_call();
		return;
	}

	if (saves_spell(level,ch,victim))
	{
		send_to_char("You failed to envision your victim.\n\r", ch);
		pop_call();
		return;
	}

	gate = create_object(get_obj_index(OBJ_VNUM_GATE), 0);

	if (!gate)
	{
		ch_printf(ch,"You try to create a gate, but it does not seem possible somehow.\n\r");
		pop_call();
		return;
	}
	gate->value[3] = victim->in_room->vnum;

	obj_to_room(gate, ch->in_room->vnum);

	act( "$p opens before you.", ch, gate, NULL, TO_CHAR);
	act( "$p opens before $n.",  ch, gate, NULL, TO_ROOM);

	do_enter(ch, "i23");
	obj_from_room(gate);
	junk_obj(gate);
	pop_call();
	return;
}

/*
 * Spell for mega1.are from Glop/Erkenbrand.
 */

DO_SPELL(spell_general_purpose)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_general_purpose(%p,%p,%p,%p)",sn,level,ch,vo);

	dam = number_range( 25, 100 );
	if ( saves_spell( level, ch, victim ) )
		dam /= 2;
	damage( ch, victim, dam, sn );
	pop_call();
	return;
}

DO_SPELL(spell_giant_strength)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_giant_strength(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( is_affected( victim, sn ) )
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	af.type      = sn;
	af.duration  = level;
	af.location  = APPLY_STR;
	af.modifier  = 1 + (level >= 18) + (level >= 25);
	af.bittype   = AFFECT_TO_NONE;
	af.bitvector = 0;
	affect_to_char( victim, &af );
	send_to_char( "You feel the strength of a giant.\n\r", victim );
	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_harm)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_harm(%p,%p,%p,%p)",sn,level,ch,vo);

	dam = 100 + number_range(0, 4) * 50;

	if (saves_spell(level, ch, victim))
	{
		dam /= 2;
	}

	damage( ch, victim, number_fuzzy(dam), sn );

	pop_call();
	return;
}

DO_SPELL(spell_heal)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;

	push_call("spell_heal(%p,%p,%p,%p)",sn,level,ch,vo);

	victim->hit = UMIN( victim->hit + 100, victim->max_hit );
	update_pos( victim );
	send_to_char( "A warm feeling fills your body.\n\r", victim );
	affect_strip(victim,gsn_critical_hit);
	affect_strip(victim,631); /* HALLUCINATE */
	if ( ch != victim )
	{
		send_to_char( "Healing powers at work.\n\r", ch );
	}
	pop_call();
	return;
}

/*
 * Spell for mega1.are from Glop/Erkenbrand.
 */

DO_SPELL(spell_high_explosive)
{

	CHAR_DATA *victim = (CHAR_DATA *) vo;
	int dam;

	push_call("spell_high_explosive(%p,%p,%p,%p)",sn,level,ch,vo);

	dam = number_range( 30, 120 );
	if ( saves_spell( level, ch, victim ) )
		dam /= 2;
	damage( ch, victim, dam, sn );
	pop_call();
	return;
}

DO_SPELL(spell_identify)
{
	OBJ_DATA *obj = (OBJ_DATA *) vo;
	char buf[MAX_STRING_LENGTH];
	AFFECT_DATA *paf;

	push_call("spell_identify(%p,%p,%p,%p)",sn,level,ch,vo);

	ch_printf(ch, "%s is type %s, extra flags %s.\n\rWeight is %d, value is %d, level is %d.\n\r",
		capitalize(obj->short_descr),
		item_type_name(obj),
		flag_string(obj->extra_flags, o_flags),
		get_obj_weight(obj),
		obj->cost,
		obj->level);

	switch ( obj->item_type )
	{
		case ITEM_SCROLL:
		case ITEM_POTION:
		case ITEM_PILL:
			sprintf(buf, "Level %d spells of:", obj->value[0]);

			if (obj->value[1] > 0 && obj->value[1] < MAX_SKILL)
			{
				cat_sprintf(buf, " '%s'", skill_table[obj->value[1]].name);
			}

			if (obj->value[2] > 0 && obj->value[2] < MAX_SKILL)
			{
				cat_sprintf(buf, " '%s'", skill_table[obj->value[2]].name);
			}

			if (obj->value[3] > 0 && obj->value[3] < MAX_SKILL)
			{
				cat_sprintf(buf, " '%s'", skill_table[obj->value[3]].name);
			}
			ch_printf(ch, "%s\n\r", buf);
			break;

		case ITEM_WAND:
		case ITEM_STAFF:
			sprintf(buf, "Has %d/%d charges of level %d",
				obj->value[2],
				obj->value[1],
				obj->value[0]);

			if (obj->value[3] >= 0 && obj->value[3] < MAX_SKILL)
			{
				cat_sprintf(buf, " '%s'", skill_table[obj->value[3]].name);
			}
			ch_printf(ch, "%s\n\r", buf);
			break;

		case ITEM_WEAPON:
			switch (obj->value[0])
			{
				case WEAPON_TYPE_WEAPON:
					ch_printf(ch, "Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_SWORD:
					ch_printf(ch, "This weapon is a sword. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_DAGGER:
					ch_printf(ch, "This weapon is a dagger. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_AXE:
					ch_printf(ch, "This weapon is an axe. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_MACE:
					ch_printf(ch, "This weapon is a mace. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_STAFF:
					ch_printf(ch, "This weapon is a staff. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_WHIP:
					ch_printf(ch, "This weapon is a whip. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_FLAIL:
					ch_printf(ch, "This weapon is a flail. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_SPEAR:
					ch_printf(ch, "This weapon is a spear. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_CLAW:
					ch_printf(ch, "This weapon is a claw. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_SHORTBOW:
					ch_printf(ch, "This weapon is a short bow. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_LONGBOW:
					ch_printf(ch, "This weapon is a long bow. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_CROSSBOW:
					ch_printf(ch, "This weapon is a cross bow. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				case WEAPON_TYPE_BLOWPIPE:
					ch_printf(ch, "This weapon is a blow pipe. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
				default:
					ch_printf(ch, "This weapon is faulty. Talk to Demise. Damage is %dd%d.\n\r", obj->value[1], obj->value[2]);
					break;
			}
			break;

		case ITEM_ARMOR:
			ch_printf(ch, "Armor class is %d.\n\r", obj->value[0] );
			break;

		case ITEM_AMMO:
			switch (obj->value[0])
			{
				case WEAPON_TYPE_SHORTBOW:
					ch_printf(ch, "Ammo type for short bows, Damage is %d, Speed is %d, Range is %d.\n\r",
						obj->value[1], obj->value[2], obj->value[3]);
					break;
				case WEAPON_TYPE_LONGBOW:
					ch_printf(ch, "Ammo type for long bows, Damage is %d, Speed is %d, Range is %d.\n\r",
						obj->value[1], obj->value[2], obj->value[3]);
					break;
				case WEAPON_TYPE_CROSSBOW:
					ch_printf(ch, "Ammo type for cross bows, Damage is %d, Speed is %d, Range is %d.\n\r",
						obj->value[1], obj->value[2], obj->value[3]);
					break;
				case WEAPON_TYPE_BLOWPIPE:
					ch_printf(ch, "Ammo type for blow pipes, Damage is %d, Speed is %d, Range is %d.\n\r",
						obj->value[1], obj->value[2], obj->value[3]);
					break;
				default:
					ch_printf(ch, "Ammo type is faulty. Talk to Demise. Damage is %d, Speed is %d, Range is %d.\n\r",
						obj->value[1], obj->value[2], obj->value[3]);
					break;
			}
			break;
		case ITEM_CONTAINER:
			ch_printf(ch, "Capacity is %d weight and %d items.\n\r", obj->value[0], obj->value[3] ? obj->value[3] : MAX_OBJECTS_IN_CONTAINER);
			break;
	}

	for (paf = obj->pIndexData->first_affect ; paf ; paf = paf->next)
	{
		switch (paf->location)
		{
			case APPLY_NONE:
				break;

			default:
				ch_printf(ch, "Affects %s by %d.\n\r", affect_loc_name(paf->location), paf->modifier);
				break;
		}
		switch (paf->bittype)
		{
			case AFFECT_TO_NONE:
				break;

			case AFFECT_TO_CHAR:
				ch_printf(ch, "Affects wearer with %s.\n\r", affect_bit_name(paf->bitvector));
				break;

			case AFFECT_TO_OBJ:
				ch_printf(ch, "Affects object with %s.\n\r", flag_string(paf->bitvector, o_flags));
				break;
		}
	}

	for (paf = obj->first_affect ; paf != NULL ; paf = paf->next)
	{
		switch (paf->location)
		{
			case APPLY_NONE:
				break;

			default:
				ch_printf(ch, "Affects %s by %d.\n\r", affect_loc_name(paf->location), paf->modifier);
				break;
		}
		switch (paf->bittype)
		{
			case AFFECT_TO_NONE:
				break;

			case AFFECT_TO_CHAR:
				ch_printf(ch, "Affects wearer with %s.\n\r", affect_bit_name(paf->bitvector));
				break;

			case AFFECT_TO_OBJ:
				ch_printf(ch, "Affects object with %s.\n\r", flag_string(paf->bitvector, o_flags));
				break;
		}
	}
	sprintf(buf, "Wear locations:");

	if (!IS_SET(obj->wear_flags, ITEM_TAKE))
	{
		strcat( buf, " Cannot take");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_FINGER))
	{
		strcat( buf, " Fingers");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_NECK))
	{
		strcat( buf, " Neck");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_BODY))
	{
		strcat( buf, " Body");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_HEAD))
	{
		strcat( buf, " Head");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_LEGS))
	{
		strcat( buf, " Legs");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_FEET))
	{
		strcat( buf, " Feet");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_HANDS))
	{
		strcat( buf, " Hands");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_ARMS))
	{
		strcat( buf, " Arms");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_SHIELD))
	{
		strcat( buf, " Shield");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_ABOUT))
	{
		strcat( buf, " About");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_WAIST))
	{
		strcat( buf, " Waist");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_WRIST))
	{
		strcat( buf, " Wrist");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_WIELD))
	{
		strcat( buf, " Wield");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_HOLD))
	{
		strcat( buf, " Hold");
	}
	if (IS_SET(obj->wear_flags, ITEM_WEAR_HEART))
	{
		strcat( buf, " Heart");
	}
	if (strlen(buf) < 17)
	{
		strcat( buf, " Carry only");
	}
	ch_printf(ch, "%s.\n\r", buf);

	pop_call();
	return;
}

DO_SPELL(spell_infravision)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_infravision(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( IS_AFFECTED(victim, AFF_INFRARED) )
	{
		send_to_char( "They are already affected.\n\r", ch );
		pop_call();
		return;
	}
	act( "$n's eyes glow red.", ch, NULL, NULL, TO_ROOM );
	af.type      = sn;
	af.duration  = 2 * level;
	af.location  = APPLY_NONE;
	af.modifier  = 0;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF_INFRARED;
	affect_to_char( victim, &af );
	send_to_char( "Your eyes glow red.\n\r", victim );
	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_enhanced_heal)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_enhanced_heal(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( IS_AFFECTED(victim, AFF2_ENHANCED_HEAL) )
	{
		send_to_char("They are already healing easily.\n\r", ch);
		pop_call();
		return;
	}

	act( "$n heals easily.", victim, NULL, NULL, TO_ROOM );
	af.type      = sn;
	af.duration  = 24;
	af.location  = APPLY_NONE;
	af.modifier  = 0;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF2_ENHANCED_HEAL;
	affect_to_char( victim, &af );
	send_to_char( "You heal easily.\n\r", victim );
	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_enhanced_revive)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_enhanced_revive(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( IS_AFFECTED(victim, AFF2_ENHANCED_REVIVE) )
	{
		send_to_char("They are already reviving easily.\n\r", ch);
		pop_call();
		return;
      }

	act( "$n revives easily.", victim, NULL, NULL, TO_ROOM );
	af.type      = sn;
	af.duration  = 24;
	af.location  = APPLY_NONE;
	af.modifier  = 0;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF2_ENHANCED_REVIVE;
	affect_to_char( victim, &af );
	send_to_char( "You revive easily.\n\r", victim );
	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_enhanced_rest)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_enhanced_rest(%p,%p,%p,%p)",sn,level,ch,vo);

	if ( IS_AFFECTED(victim, AFF2_ENHANCED_REST) )
	{
		send_to_char("They are already resting easily.\n\r", ch);
		pop_call();
		return;
	}

	act( "$n rests easily.", victim, NULL, NULL, TO_ROOM );
	af.type      = sn;
	af.duration  = 24;
	af.location  = APPLY_NONE;
	af.modifier  = 0;
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF2_ENHANCED_REST;
	affect_to_char( victim, &af );
	send_to_char( "You rest easily.\n\r", victim );
	if ( ch != victim )
	{
		send_to_char( "Ok.\n\r", ch );
	}
	pop_call();
	return;
}

DO_SPELL(spell_remove_fear)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_remove_fear(%p,%p,%p,%p)",sn,level,ch,vo);

	if (saves_spell(level, ch, victim))
	{
		send_to_char( "They are not made fearless.\n\r", ch );
		pop_call();
		return;
	}

	if (!IS_NPC(victim))
	{
		if (is_affected(victim, sn))
		{
			send_to_char("They are already fearless.\n\r", ch);
			pop_call();
			return;
		}

		af.type		= sn;
		af.duration	= level / 3;
		af.bittype	= AFFECT_TO_NONE;
		af.bitvector	= 0;
		af.location	= APPLY_NONE;
		af.modifier	= 0;

		affect_to_char(victim, &af);

		affect_strip(victim, gsn_fear);

		victim->pcdata->wimpy = 0;
	}
	else
	{
		if (!IS_SET(victim->act, ACT_WIMPY))
		{
			send_to_char( "They are already fearless.\n\r", ch );
			pop_call();
			return;
		}
		REMOVE_BIT(victim->act, ACT_WIMPY);
	}
	act("You become fearless!", victim, NULL, NULL, TO_CHAR );
	act("$n becomes fearless!", victim, NULL, NULL, TO_ROOM );

	pop_call();
	return;
}

DO_SPELL(spell_fear)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_fear(%p,%p,%p,%p)",sn,level,ch,vo);

	if (saves_spell(level, ch, victim))
	{
		send_to_char( "They are not made frightened.\n\r", ch );
		pop_call();
		return;
	}

	if (!IS_NPC(victim))
	{
		if (is_affected(victim, sn))
		{
			send_to_char("They are already frightened.\n\r", ch);
			pop_call();
			return;
		}

		af.type		= sn;
		af.duration	= level / 3;
		af.bittype	= AFFECT_TO_NONE;
		af.bitvector	= 0;
		af.location	= APPLY_NONE;
		af.modifier	= 0;

		affect_to_char(victim, &af);

		affect_strip(victim, gsn_remove_fear);

		victim->pcdata->wimpy = victim->max_hit / 2;
	}
	else
	{
		if (IS_SET(victim->act, ACT_WIMPY))
		{
			send_to_char( "They are already frightened.\n\r", ch );
			pop_call();
			return;
		}
		SET_BIT(victim->act, ACT_WIMPY);
	}
	act("You become filled with fear!", victim, NULL, NULL, TO_CHAR );
	act("$n becomes filled with fear!", victim, NULL, NULL, TO_ROOM );

	pop_call();
	return;
}

DO_SPELL(spell_haste)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_haste(%p,%p,%p,%p)",sn,level,ch,vo);

	if (IS_AFFECTED(victim, AFF_HASTE))
	{
		send_to_char("They are already fast.\n\r", ch);
		pop_call();
		return;
	}

	af.type      = sn;
	af.location  = APPLY_DEX;

	if (which_god(victim) != GOD_MANWE)
	{
		af.duration = URANGE(6, level / 8, 24);
		af.modifier = 1 + (level > 49) + (level > 99);
	}
	else
	{
		af.duration = URANGE(12, level / 4, 48);
		af.modifier = 1 + (level > 24) + (level > 49) + (level > 74) + (level > 99) + (level > 124);
	}
	af.bittype   = AFFECT_TO_CHAR;
	af.bitvector = AFF_HASTE;
	affect_to_char(victim, &af);

	send_to_char("You speed up.\n\r", victim);
	act("$n speeds up.", victim, NULL, NULL, TO_ROOM);

	pop_call();
	return;
}

DO_SPELL(spell_invis)
{
	CHAR_DATA *victim = (CHAR_DATA *) vo;
	OBJ_DATA *obj = (OBJ_DATA *) vo;
	AFFECT_DATA af;

	push_call("spell_invis(%p,%p,%p,%p)",sn,level,ch,vo);

	if (target == TAR_CHAR_DEFENSIVE)
	{
		if (IS_AFFECTED(victim, AFF_INVISIBLE) || IS_AFFECTED(victim, AFF_IMP_INVISIBLE))
		{
			send_to_char("They are already invisible.\n\r", ch);
			pop_call();
			return;
		}

		act("You fade out of existence.", victim, NULL, NULL, TO_CHAR);
		act("$n fades out of existence.", victim, NULL, NULL, TO_ROOM);

		af.type      = sn;
		af.duration  = level;
		af.location  = APPLY_NONE;
		af.modifier  = 0;
		af.bittype   = AFFECT_TO_CHAR;
		af.bitvector = AFF_INVISIBLE;
		affect_to_char( victim, &af );
	}
	else if (target == TAR_OBJ_INV)
	{
		if (IS_SET(obj->extra_flags, ITEM_INVIS))
		{
			act("$p is already invisible.", ch, obj, NULL, TO_CHAR);
			pop_call();
			return;
		}

		af.type      = sn;
		af.duration  = level;
		af.location  = APPLY_NONE;
		af.modifier  = 0;
		af.bittype   = AFFECT_TO_OBJ;
		af.bitvector = ITEM_INVIS;

		affect_to_obj(obj, &af );

		SET_BIT(obj->extra

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

Site Stats

Snippets: 1791
Codebases: 571