magic.c

cthulu3/drv8/magic.c · 255.4 KB

From the archive cthulu3-1.tar.gz

Download the archive   « Back to the archive contents

/*********************************************************
 *                   CTHULHUMUD                       	 *
 * CthulhuMud  driver  version 8.x copyright (C) 2000 	 *
 * by Mik Clarke (mykael@vianet.net.au)                  *
 * and Joachim Häusler (mystery@chello.at).              *
 *                                                       *
 * While the code is original, many concepts and the     *
 * typical look & feel are derived from MERC and its     *
 * derivatives - especially the SunderMud 1.0 prototype. *
 *                                                       *
 * Therefore we'd like to thank:                         *
 * Lotherius                                             *
 * Russ Taylor, Gabrielle Taylor, Brian Moore            *
 * Michael Chastain, Michael Quan, and Mitchell Tse      *
 *                                                       *
 * Please keep this code open-source and share your      *
 * ideas. It's still a long way to go.                   *
 *********************************************************/


#include "everything.h"
#include "magic.h"
#include "skill.h"
#include "fight.h"
#include "affect.h"
#include "spell.h"
#include "exp.h"
#include "profile.h"
#include "wev.h"
#include "mob.h"
#include "econd.h"
#include "tracks.h"
#include "race.h"
#include "olc.h"
#include "gsn.h"

/* command procedures needed */
DECLARE_DO_FUN(do_look);
DECLARE_DO_FUN(do_flee);
DECLARE_DO_FUN(do_stand);

extern void 	random_dream	(CHAR_DATA *ch);

void 	kill_msg			(CHAR_DATA *ch);
void 	raw_kill			(CHAR_DATA *victim, bool corpse ) ;
void 	heat_obj			(CHAR_DATA *ch, OBJ_DATA *obj, int level);
void 	identify_affect		(CHAR_DATA *ch, AFFECT_DATA *paf);

bool 	saves_dispel		(int dis_level, int aff_level, int duration);


extern int modlev;
extern char *target_name;
extern int spell_roll;
extern COMBAT_DATA *spell_CDB;
extern bool in_seq;


/*
 * Spell functions.
 */

void spell_absorb_magic( int sn, int level, CHAR_DATA *ch, void *vo ) {
    AFFECT_DATA af;

    if ( IS_AFFECTED(ch, AFF_ABSORB) ) {
        send_to_char("You are already able to absorb magic.\r\n",ch);
	return;
    }

    af.type      = sn;
    af.afn       = gafn_absorb_magic; 
    af.level     = level;
    af.duration  = number_fuzzy( level / 6 );
    af.location  = APPLY_NONE;
    af.modifier  = 0;
    af.bitvector = AFF_ABSORB;
    affect_to_char( ch, &af );

    act( "$n is surrounded by a strange mystical aura.", ch, NULL, NULL, TO_ROOM );
    send_to_char( "You are surrounded by a mystical absorbing aura.\r\n", ch  );
    return;
}

void spell_acid_blast( int sn, int level, CHAR_DATA *ch, void *vo ) {

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_ACID;
    spell_CDB->atk_blk_type = BLOCK_BOLT;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Set up and adjust damage... */

    spell_CDB->damage = dice(level/2, 10) + 6;

    if ( saves_spell( level, spell_CDB->defender ) ) {
     	spell_CDB->damage /= 2;
    }

   /* Apply the damage... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

   /* All done... */

    return;
}

void spell_entropy (int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_ENERGY;
    spell_CDB->atk_blk_type = BLOCK_BOLT;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Describe what happens... */

    act("A blast of chaotic magic surronds $N.",
        ch,NULL,victim,TO_ROOM);
    act("You release a blast of entropy to $N.",
        ch,NULL,victim,TO_CHAR);
    act("A blast of chaotic energy screaches from $n's hand and surrounds you!",
        ch,NULL,victim,TO_VICT);

   /* See what the impact is... */

    if ( !saves_spell ( level, victim ) ) {
	check_damage_obj (victim, NULL, 100);	/* gotcher equipment sucker! */
    } else {
	check_damage_obj(ch, NULL, 15);
    }

    return;
}

void spell_animate( int sn, int level, CHAR_DATA *ch, void *vo) {
    OBJ_DATA *obj;
    CHAR_DATA *mob;
    bool angry;
    int zlevel;

    obj = get_obj_here(ch, target_name );

    if ( obj == NULL ) {
        send_to_char( "Resurrect what?\r\n", ch );
        return;
    }

    /* Nothing but NPC corpses. */

    if( obj->item_type != ITEM_CORPSE_NPC ) {
        if( obj->item_type == ITEM_CORPSE_PC )
            send_to_char( "You can't resurrect players.\r\n", ch );
        else
            send_to_char( "It would serve no purpose...\r\n", ch );
        return;
    }

    angry = FALSE;

    zlevel = UMAX(obj->level - 4, 1);

    if( zlevel > (level) ) {
        angry = TRUE;
        zlevel += dice(1,6);
    }

    if( !angry 
     && ch->pet != NULL ) {
        send_to_char( "You already have a pet.\r\n", ch );
        return;
    }

    /* Chew on the zombie a little bit, recalculate level-dependant stats */

    mob = create_mobile_level(get_mob_index( MOB_VNUM_ZOMBIE ), "mob monster", zlevel );

    /* You rang? */

    char_to_room( mob, ch->in_room );

    act( "$p springs to life as a hideous zombie!", ch, obj, NULL, TO_ROOM );
    act( "$p springs to life as a hideous zombie!", ch, obj, NULL, TO_CHAR );

    extract_obj(obj);

    /* Yessssss, massssssster... */

    if (!angry) {
      SET_BIT(mob->affected_by, AFF_CHARM);
      SET_BIT(mob->act, ACT_FOLLOWER);

      add_follower( mob, ch );
      mob->leader = ch;
      ch->pet = mob;

     /* For a little flavor... */

      do_say( mob, "How may I serve you, master?" );

    } else {
      SET_BIT(mob->act, ACT_AGGRESSIVE);
      SET_BIT(mob->affected_by, AFF_HASTE);

      do_emote(mob, "Screams with rage and attacks!");

      multi_hit(mob, ch, TYPE_UNDEFINED);
    } 

    return;
}


void spell_mummify( int sn, int level, CHAR_DATA *ch, void *vo) {
OBJ_DATA *obj;
CHAR_DATA *mob;
bool angry;
int zlevel;

    obj = get_obj_here( ch, target_name );

    if ( obj == NULL ) {
        send_to_char( "Mummify what?\r\n", ch );
        return;
    }

    /* Nothing but NPC corpses. */

    if( obj->item_type != ITEM_CORPSE_NPC ) {
            send_to_char( "It would serve no purpose...\r\n", ch );
        return;
    }

    angry = FALSE;
    zlevel = UMAX(obj->level - 2, 1);

    if( zlevel > (level) ) {
        angry = TRUE;
        zlevel += dice(1,6);
    } else {
        if (number_percent() < 20)  {
            angry = TRUE;
            zlevel += dice(2,6);
        }

    }
    if( !angry 
     && ch->pet != NULL ) {
        send_to_char( "You already have a pet.\r\n", ch );
        return;
    }

    /* Chew on the zombie a little bit, recalculate level-dependant stats */

    mob = create_mobile_level( get_mob_index(MOB_VNUM_MUMMY), "mob monster", zlevel );
    char_to_room( mob, ch->in_room );

    act( "$p slowly comes to life as a monsterous mummy!", ch, obj, NULL, TO_ROOM );
    act( "$p slowly comes to life as a monsterous mummy!", ch, obj, NULL, TO_CHAR );

    extract_obj(obj);

    if (!angry) {
      SET_BIT(mob->affected_by, AFF_CHARM);
      SET_BIT(mob->act, ACT_FOLLOWER);

      add_follower( mob, ch );
      mob->leader = ch;
      ch->pet = mob;

     /* For a little flavor... */

      do_say( mob, "How may I serve you, master?" );

    } else {
      SET_BIT(mob->act, ACT_AGGRESSIVE);
      SET_BIT(mob->affected_by, AFF_HASTE);

      do_emote(mob, "Screams in rage and attacks!");

      multi_hit(mob, ch, TYPE_UNDEFINED);
    } 

    return;
}

void spell_summon_familier( int sn, int level, CHAR_DATA *ch, void *vo) {
CHAR_DATA *mob;

    int mob_level, mob_num;

   /* No previous pet... */

    if( ch->pet != NULL ) {
        send_to_char( "You already have a pet.\r\n", ch );
        return;
    }

   /* Create the mob... */

    mob_level = ch->level - 4;

    mob = create_mobile_level( get_mob_index(20020), "mob monster", mob_level );

   /* Work out what sort of familier they get... */

    mob_num = dice(1, 4) + 2;

    if (IS_EVIL(ch)) {
      mob_num -= 2;
    } else if (IS_GOOD(ch)) {
      mob_num += 2;
    } 

   /* 1 in 128 chance of getting a raw one... */
  
    if (number_bits(8) == 0) {
      mob_num = -1;
    }

   /* Taylor description and names... */

    switch (mob_num) {
      
      default:
        break; 

      case 1:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("homunlcus disgusting green");
        mob->short_descr = strdup("a disgusting green homunlcus");
        mob->long_descr = strdup("A disgusting green homunlcus\n");
        mob->description = strdup("It looks like the stories about the revolting things these abominations are\n made from are true. Yuk!\n");

        mob->sex = SEX_NEUTRAL;
        mob->race=15;
        mob->alignment = -1000;

        break;

      case 2:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("imp short red");
        mob->short_descr = strdup("a short red imp");
        mob->long_descr = strdup("A short, red imp\n");
        mob->description = strdup("He gives you a nasty look!\n");

        mob->sex = SEX_MALE;
        mob->race=20;
        mob->alignment = -750;

        SET_BIT(mob->affected_by, AFF_FLYING);

        break;

      case 3:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("python long");
        mob->short_descr = strdup("a long python");
        mob->long_descr = strdup("A long python\n");
        mob->description = strdup("It seems quite friendly.\n");

        mob->sex = SEX_NEUTRAL;
        mob->race=27;
        mob->alignment = -300;

        break;

      case 4:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("toad grey");
        mob->short_descr = strdup("a grey toad");
        mob->long_descr = strdup("A grey toad\n");
        mob->description = strdup("He is covered in ugly warts.\n");

        mob->sex = SEX_MALE ;
        mob->race=21;
        mob->alignment = -100;

        break;

      case 5:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("parrot green");
        mob->short_descr = strdup("a green parrot");
        mob->long_descr = strdup("A green parrot\n");
        mob->description = strdup("He looks like he belonged to a sailor.\n");

        mob->sex = SEX_MALE;
        mob->race=28;
        mob->alignment = 100;

        SET_BIT(mob->affected_by, AFF_FLYING);

        break;

      case 6:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("cat black");
        mob->short_descr = strdup("a black cat");
        mob->long_descr = strdup("A black cat\n");
        mob->description = strdup("She looks quite refined.\n");

        mob->sex = SEX_FEMALE;
        mob->race=12;
        mob->alignment = 300;

        break;

      case 7:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("bird blue beautiful");
        mob->short_descr = strdup("a blue bird");
        mob->long_descr = strdup("A beautiful blue bird\n");
        mob->description = strdup("She looks very happy (and somewhat like a chicken)!\n");

        mob->sex = SEX_FEMALE;
        mob->race=28;
        mob->alignment = 750;

        SET_BIT(mob->affected_by, AFF_FLYING);

        break;

      case 8:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("cherub cute");
        mob->short_descr = strdup("a cute cherub");
        mob->long_descr = strdup("A cute cherub\n");
        mob->description = strdup("He looks very beautiful, and has little wings on his back.\n");

        mob->sex = SEX_MALE;
        mob->race=2;
        mob->alignment = 1000;

        SET_BIT(mob->affected_by, AFF_FLYING);

        break;

    }  

   /* Deliver the familier */

    char_to_room( mob, ch->in_room );

    act( "$N steps out of the shadows...", ch, NULL, mob, TO_ROOM );
    act( "$N steps out of the shadows...", ch, NULL, mob, TO_CHAR );

   /* Enslave the familier... */

    SET_BIT(mob->affected_by, AFF_CHARM);
    SET_BIT(mob->act, ACT_FOLLOWER);

    add_follower( mob, ch );
    mob->leader = ch;
    ch->pet = mob;

   /* For a little flavor... */

    do_emote( mob, "looks at you expectently" );

    return;
}

void spell_summon_spirit( int sn, int level, CHAR_DATA *ch, void *vo) {
CHAR_DATA *mob;
int mob_level, mob_num;

   /* No previous pet... */

    if( ch->pet != NULL ) {
        send_to_char( "You already have a pet.\r\n", ch );
        return;
    }

   /* Create the mob... */

    mob_level = ch->level - 6;

    mob = create_mobile_level( get_mob_index( 20022 ), "mob mage", mob_level );

   /* Work out what sort of familier they get... */

    mob_num = 2;

    if (IS_EVIL(ch)) {
      mob_num = 1;
    } else if (IS_GOOD(ch)) {
      mob_num = 3;
    } 

    /* Taylor description and names... */

    switch (mob_num) {
      
      default:
        break; 

 case 1:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("efreet fiery");
        mob->short_descr = strdup("Efreet");
        mob->long_descr = strdup("An efreet is burning brightly here.\n");
        mob->description = strdup("An efreet is burning brightly here.\n");
       
        mob->sex = SEX_MALE;
        mob->alignment = -500;
        SET_BIT(mob->affected_by, AFF_FLYING);
        SET_BIT(mob->imm_flags, IMM_FIRE);
        SET_BIT(mob->vuln_flags, VULN_COLD);
        SET_BIT(mob->dam_type,WDT_FLAMING_BITE);
  
        break;

      case 2:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("genie aetheral");
        mob->short_descr = strdup("Genie");
        mob->long_descr = strdup("An aetheral genie is floating here.\n");
        mob->description = strdup("An aetheral genie is floating here.\n");

        mob->sex = SEX_MALE;
        mob->alignment = 0;
        SET_BIT(mob->affected_by, AFF_FLYING);
        SET_BIT(mob->affected_by, AFF_HASTE);
        SET_BIT(mob->dam_type,WDT_SHOCKING_BITE);

        break;

      case 3:
        free_string(mob->name);
        free_string(mob->short_descr);
        free_string(mob->long_descr);
        free_string(mob->description);

        mob->name = strdup("seraph");
        mob->short_descr = strdup("Seraph");
        mob->long_descr = strdup("A seraph is here, enveloped by a glowing halo.\n");
        mob->description = strdup("A seraph is here, enveloped by a glowing halo.\n");

        mob->sex = SEX_MALE;
        mob->alignment = 500;
        SET_BIT(mob->affected_by, AFF_FLYING);
        SET_BIT(mob->imm_flags, IMM_HOLY);
        SET_BIT(mob->vuln_flags, VULN_NEGATIVE);
        SET_BIT(mob->dam_type,WDT_DIVINE_POWER);

        break;

    }  

   /* Deliver the familier */

    char_to_room(mob, ch->in_room );

    act( "$N steps out of the shadows...", ch, NULL, mob, TO_ROOM );
    act( "$N steps out of the shadows...", ch, NULL, mob, TO_CHAR );

   /* Enslave the familier... */

    SET_BIT(mob->affected_by, AFF_CHARM);
    SET_BIT(mob->act, ACT_FOLLOWER);

    add_follower(mob, ch );
    mob->leader = ch;
    ch->pet = mob;

   /* For a little flavor... */

    do_emote(mob, "looks at you expectently" );

    return;
}


void spell_elder_watcher( int sn, int level, CHAR_DATA *ch, void *vo) {
CHAR_DATA *mob;
int mob_level;

   /* Create the mob... */

    mob_level = ch->level - 10;

    mob = create_mobile_level( get_mob_index( 20021 ), "mob monster", mob_level );

 
   /* Deliver the watcher */

    char_to_room( mob, ch->in_room );

    act( "The Watcher steps out of the shadows...", ch, NULL, NULL, TO_ROOM );
    act( "The Watcher steps out of the shadows...", ch, NULL, NULL, TO_CHAR );

   return;
}


void spell_minor_creation( int sn, int level, CHAR_DATA *ch, void *vo) {
OBJ_DATA *obj;
   
    if (!str_cmp(target_name, "boat"))    {
	obj = create_object (get_obj_index (OBJ_VNUM_BOAT), 0);
	obj->cost=0;
	obj_to_room (obj, ch->in_room);
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("A boat materializes before you.\r\n",ch);

    } else if (!str_cmp(target_name, "bag"))   {
	obj = create_object (get_obj_index (OBJ_VNUM_BAG), 0);
	obj->cost=0;
	obj_to_room (obj, ch->in_room);
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("A bag materializes before you.\r\n",ch);

    } else if (!str_cmp(target_name, "tool"))   {
	obj = create_object (get_obj_index (26), 0);
	obj->cost=0;
	obj_to_room (obj, ch->in_room);
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("A shovel materializes before you.\r\n",ch);

    } else if (!str_cmp(target_name, "camp"))   {
                for (obj = ch->in_room->contents; obj; obj =obj->next_content) {
                    if (obj->item_type == ITEM_DECORATION) break;
                }
                if (obj) {
 	    send_to_char( "You can't do that here.\r\n", ch );
 	    return;
                }

	obj = create_object (get_obj_index (OBJ_CAMP), 0);
                obj->value[0] = number_range(level/2, level);
                obj->value[1] = number_range(level/2, level);
	obj->cost=0;
                free_string(obj->name);
                obj->name = str_dup("sphere light");
                free_string(obj->short_descr);
                obj->short_descr = str_dup("a sphere of {Bblue light{x");
                free_string(obj->description);
                obj->description = str_dup("A sphere of {Bblue light{x floats here.\n");
	obj_to_room (obj, ch->in_room);
	act ("$n mutters some words and $p materializes from thin air.", ch, obj, NULL, TO_ROOM);
	send_to_char("A sphere of light materializes before you.\r\n",ch);

    } else {
               send_to_char("You don't know how to make that kind of object.\r\n",ch);
    }
    return;

}


void spell_greater_creation( int sn, int level, CHAR_DATA *ch, void *vo) {
OBJ_DATA *obj;

    if (!str_cmp(target_name, "amber"))    {
	obj = create_object (get_obj_index (5589), 0);
	obj->cost=0;
	obj_to_room (obj, ch->in_room);
                obj->timer = number_range(20,30);
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("Some scrying amber materializes before you.\r\n",ch);

    } else if (!str_cmp(target_name, "chain"))   {
	obj = create_object (get_obj_index (29), 0);
	obj->cost=0;
                obj->value[0]=50+(ch->level/25);
	obj_to_room (obj, ch->in_room);
                obj->timer = number_range(20,30);
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("Some magic chains materializes before you.\r\n",ch);

    } else if (!str_cmp(target_name, "anvil"))  {
	obj = create_object (get_obj_index (28), 0);
	obj->cost=0;
	obj_to_room (obj, ch->in_room);
                obj->timer = number_range(10,20);
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("A heavy anvil materializes before you.\r\n",ch);

    } else if (!str_cmp(target_name, "grimoire"))  {
                EXTRA_DESCR_DATA *ed;
                char buf[MAX_INPUT_LENGTH];

	obj = create_object (get_obj_index (51), 0);
	obj->cost=0;
	obj_to_room (obj, ch->in_room);
                obj->enchanted = TRUE;
                ed =   new_extra_descr();
                sprintf (buf, "read %s", obj->name);
                ed->keyword		= str_dup(buf);
                ed->description		= str_dup( "Disciplines: " );
                ed->next			= obj->extra_descr;
                obj->extra_descr		= ed;
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("An ancient grimoire materializes before you.\r\n",ch);

    } else if (!str_cmp(target_name, "focus"))  {
	obj = create_object (get_obj_index (49), 0);
	obj->cost=0;
	obj_to_room (obj, ch->in_room);
                obj->enchanted = TRUE;
                free_string(obj->owner);
                obj->owner = str_dup(ch->name);
                obj->timer = number_range(10, 50);
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("A magical focus materializes before you.\r\n",ch);

    } else if (!str_cmp(target_name, "protection"))   {
	obj = create_object (get_obj_index (27), 0);
	obj->cost=0;
                obj->level=(ch->level+2);
	obj->value[0] = obj->level / 8;
	obj->value[1] = obj->level / 8;
	obj->value[2] = obj->level / 8;
	obj->value[3] = obj->level / 8 + 12;
                obj_to_room (obj, ch->in_room);
                obj->timer = number_range(20,30);
	act ("$n mutters some words and $p materializes from thin air.",ch,obj,NULL,TO_ROOM);
	send_to_char("Some protective field materializes before you.\r\n",ch);

    } else {
               send_to_char("You don't know how to make that kind of object.\r\n",ch);
    }
    return;
}


void spell_soul_blade( int sn, int level, CHAR_DATA *ch, void *vo) {
    OBJ_DATA *obj;
    OBJ_DATA *sblade;
    int number,type;

    obj = get_obj_here( ch, target_name );

    if ( obj == NULL )    {
        send_to_char( "Cast Soul Blade on What?\r\n", ch );
        return;
    }

    /* Nothing but NPC corpses. */

    if( obj->item_type != ITEM_CORPSE_NPC )    {
        if( obj->item_type == ITEM_CORPSE_PC )
            send_to_char( "The player wishes to keep their soul.\r\n", ch );
        else
            send_to_char( "It would serve no purpose...\r\n", ch );
        return;
    }

    if( obj->level > (level + 2) )    {
        send_to_char( "You cannot forge such a soul into a blade.\r\n", ch );
        return;
    }

    /* Create the soulblade */

    sblade = create_object ( get_obj_index (OBJ_VNUM_SOULBLADE), 0);
    sblade->level                  = obj->level;
    if (sblade->level < 5 ) sblade->level=5;
    number = UMIN(sblade->level/4 + 1, 5);
    type   = (sblade->level + 10)/number;

    sblade->value[1] = number;
    sblade->value[2] = type;

    sblade->timer = (sblade->level +10)/2;

    /* Action! */
    obj_to_room( sblade, ch->in_room );
    act( "$n waves dramatically and $p appears.",   ch, sblade, NULL, TO_ROOM );
    act( "You wave dramatically and $p appears.", ch, sblade, NULL, TO_CHAR );

    extract_obj(obj);

    return;
}

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

    if ( is_affected( victim, gafn_armor ) ) {
        if (!in_seq) {
  	  if (victim == ch)
	    send_to_char("You are already protected.\r\n",ch);
	  else
	    act("$N is already armored.",ch,NULL,victim,TO_CHAR);
        }
	return;
    }
    af.type      = sn;
    af.afn	 = gafn_armor;
    af.level	 = level;
    af.duration  = 24 * (1 + level/30);
    af.modifier  = -1 * ( 50 + (level/2));
    af.location  = APPLY_AC;
    af.bitvector = 0;
    affect_to_char( victim, &af );
    if (!in_seq) {
      send_to_char( "You feel someone protecting you.\r\n", victim );
      if ( ch != victim )
  	  act("$N is protected by your magic.",ch,NULL,victim,TO_CHAR);
    }
    return;
}


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

    if ( victim->position == POS_FIGHTING ) {
	if (victim == ch) send_to_char("You cannot be blessed in combat!\r\n",ch);
	else act("$N is in combat!", ch, NULL, victim, TO_CHAR);
	return;
    }

    if (!IS_SET(victim->act, ACT_UNDEAD) && !str_cmp(target_name, "evil")) {
	  send_to_char("Better don't.\r\n",ch);
                  return;
    }

    if (IS_SET(victim->act, ACT_UNDEAD) && str_cmp(target_name, "evil")) {
            if (victim == ch) {
	  send_to_char("Better don't.\r\n",ch);
                  return;
            }

            spell_CDB = getCDB(ch, victim, get_spell_spn("bless"), FALSE, get_spell_spn("bless"), 0);
            spell_CDB->atk_dam_type = DAM_ENERGY;
            spell_CDB->atk_blk_type = BLOCK_NONE;

            spell_CDB->damage = dice(level, 6);
            send_to_char( "The blessing burns your flesh.\r\n", victim );

            if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
                   SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
                   apply_damage( spell_CDB);  
                   REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
            } else {
                   apply_damage( spell_CDB);
            }

    } else {
            if (is_affected( victim, gafn_bless )) {
	  if (victim == ch) send_to_char("You are already blessed.\r\n",ch);
	  else act("$N already has divine favor.",ch,NULL,victim,TO_CHAR);
	  return;
            }

            af.type      = sn;
            af.afn	 = gafn_bless;
            af.level	 = level;
            af.duration  = 6+level;
            af.location  = APPLY_HITROLL;
            af.modifier  = 1 + (level / 8);
            af.bitvector = 0;
            affect_to_char( victim, &af );

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

            send_to_char( "You feel righteous.\r\n", victim );
            if ( ch != victim ) act("You grant $N the favor of your god.",ch,NULL,victim,TO_CHAR);
    }
    return;
}



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

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_ENERGY;
    spell_CDB->atk_blk_type = BLOCK_ABSORB;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
    if ( IS_AFFECTED(victim, AFF_BLIND) || saves_spell( level, victim ) )
	return;

    af.type      = sn;
    af.afn	 = gafn_blindness;
    af.level     = level;
    af.location  = APPLY_HITROLL;
    af.modifier  = -4;
    af.duration  = 1+level;
    af.bitvector = AFF_BLIND;
    affect_to_char( victim, &af );
    send_to_char( "You are blinded!\r\n", victim );
    act("$n appears to be blinded.",victim,NULL,NULL,TO_ROOM);
    return;
}



void spell_burning_hands( int sn, int level, CHAR_DATA *ch, void *vo ) {
//    CHAR_DATA *victim = (CHAR_DATA *) vo;

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_FIRE;
    spell_CDB->atk_blk_type = BLOCK_BALL;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
    if (number_percent() < 5) harmful_effect(vo, level, TAR_CHAR_OFFENSIVE, DAM_FIRE);

   /* Set up and adjust damage... */

    spell_CDB->damage = 16 + dice((level/2), 3);

    if ( saves_spell( level, spell_CDB->defender ) )
	spell_CDB->damage /= 2;

   /* Roasting time... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

    return;
}



void spell_call_lightning( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *vch;
    CHAR_DATA *vch_next;
    int dam;

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

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

    send_to_char( "Lightning strikes from the skies!\r\n", ch );
    act( "$n calls down Lightning from the skies!",
	  ch, NULL, NULL, TO_ROOM );

    for ( vch = char_list; vch != NULL; vch = vch_next ) {

	vch_next	= vch->next;

       /* All characters in a room... */

	if ( vch->in_room == NULL )
	    continue;

       /* Those nearby see the lighting... */

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

       /* Can only hit those in the same sub-area... */

	if ( vch->in_room->subarea != ch->in_room->subarea
                || ch==vch) {
                      continue;
                }
  
       /* Reset spell_CDB... */

        spell_CDB = getCDB(ch, vch, sn, FALSE, sn, 0);

       /* Set up combat data... */

        spell_CDB->atk_dam_type = DAM_LIGHTNING;
        spell_CDB->atk_blk_type = BLOCK_LIGHTNING;
        spell_CDB->atk_desc = "lightning";

       /* Bail out if it misses... */
 
        if (!check_spell_hit(spell_CDB, spell_roll)) {
          continue;
        }   

       /* Set up and adjust damage... */

        dam = dice(level/2, 8) + 3;

        if ( vch->in_room != ch->in_room ) {
          dam /= 2;
        }

        spell_CDB->damage = dam;

        if ( saves_spell( level, spell_CDB->defender ) ) {
        	spell_CDB->damage /= 2;
        }

       /* Charging time... */

 if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

    }

    return;
}

/* RT calm spell stops all fighting in the room */

void spell_calm( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *vch;
    int mlevel = 0;
    int count = 0;
    int high_level = 0;    
    int chance;
    AFFECT_DATA af;

    /* get sum of all mobile levels in the room */
    for (vch = ch->in_room->people; vch != NULL; vch = vch->next_in_room)
    {
	if (vch->position == POS_FIGHTING)
	{
	    count++;
	    if (IS_NPC(vch))
	      mlevel += vch->level;
	    else
	      mlevel += vch->level/2;
	    high_level = UMAX(high_level,vch->level);
	}
    }

    /* compute chance of stopping combat */
    chance = 4 * level - high_level + 2 * count;

    if (IS_IMMORTAL(ch)) /* always works */
      mlevel = 0;

    if (number_range(0, chance) >= mlevel)  /* hard to stop large fights */
    {
	for (vch = ch->in_room->people; vch != NULL; vch = vch->next_in_room)
   	{
	    if (IS_NPC(vch) && (IS_SET(vch->imm_flags,IMM_MAGIC) ||
				IS_SET(vch->act,ACT_UNDEAD)))
	      return;

	    if (IS_AFFECTED(vch,AFF_CALM) || IS_AFFECTED(vch,AFF_BERSERK)
	    ||  is_affected(vch, gafn_frenzy))
	      return;
	    
	    send_to_char("A wave of calm passes over you.\r\n",vch);

	    if (vch->fighting || vch->position == POS_FIGHTING)
	      stop_fighting(vch,FALSE);

	    af.type = sn;
                    af.afn = gafn_calm;
  	    af.level = level;
	    af.duration = level/4;
	    af.location = APPLY_HITROLL;
	    if (!IS_NPC(vch))
	      af.modifier = -5;
	    else
	      af.modifier = -2;
	    af.bitvector = AFF_CALM;
	    affect_to_char(vch,&af);

	    af.location = APPLY_DAMROLL;
	    affect_to_char(vch,&af);
	}
    }
}

void spell_cancellation( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    bool found = FALSE;
 
    level += 2;

    if ((!IS_NPC(ch) && IS_NPC(victim) && 
	 !(IS_AFFECTED(ch, AFF_CHARM) && ch->master == victim) ) ||
        (IS_NPC(ch) && !IS_NPC(victim)) )
    {
	send_to_char("You failed, try dispel magic.\r\n",ch);
	return;
    }

    /* unlike dispel magic, the victim gets NO save */
 
    /* begin running through the spells */
	
 
    if (check_dispel(level,victim, gafn_absorb_magic))
        found = TRUE;
    
    if (check_dispel(level,victim, gafn_regeneration))
        found = TRUE;

    if (check_dispel(level,victim, gafn_armor))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_bless))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_blindness))
    {
        found = TRUE;
        act("$n is no longer blinded.",victim,NULL,NULL,TO_ROOM);
    }

    if (check_dispel(level,victim, gafn_calm))
    {
	found = TRUE;
	act("$n no longer looks so peaceful...",victim,NULL,NULL,TO_ROOM);
    }
 
    if (check_dispel(level,victim, gafn_sex_change))
    {
        found = TRUE;
        act("$n looks more like $mself again.",victim,NULL,NULL,TO_ROOM);
	send_to_char("You feel more like yourself again.\r\n",victim);
    }
 
    if (check_dispel(level,victim, gafn_charm))
    {
        found = TRUE;
        act("$n regains $s free will.",victim,NULL,NULL,TO_ROOM);
    }
 
    if (check_dispel(level,victim, gafn_chill_touch))
    {
        found = TRUE;
        act("$n looks warmer.",victim,NULL,NULL,TO_ROOM);
    }
 
    if (check_dispel(level,victim, gafn_curse))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_evil))
        found = TRUE;
    
    if (check_dispel(level,victim, gafn_detect_good))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_hidden))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_invis))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_hidden))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_magic))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_faerie_fire))
    {
        act("$n's outline fades.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
	
	if (check_dispel(level,victim, gafn_fear))
    {
        act("$n no longer looks so scared.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_fly))
    {
        act("$n falls to the ground!",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_frenzy)
    || check_dispel(level,victim, gafn_berserk))    {
	act("$n no longer looks so wild.",victim,NULL,NULL,TO_ROOM);
	found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_giant_strength))
    {
        act("$n no longer looks so mighty.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_haste))    {
	act("$n is no longer moving so quickly.",victim,NULL,NULL,TO_ROOM);
	found = TRUE;
    }

    if (check_dispel(level,victim, gafn_slow))    {
	act("$n is no longer moving so slowly.",victim,NULL,NULL,TO_ROOM);
	found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_infravision))   found = TRUE;
    if (check_dispel(level,victim, gafn_farsight))    found = TRUE;
 
    if (check_dispel(level,victim, gafn_invisability))
    {
        act("$n fades into existance.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
    if (check_dispel(level,victim, gafn_mind_meld))
    {
        act("$n has regained $s senses.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
    
    if (check_dispel(level,victim, gafn_mute))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_pass_door))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_protection_evil))
        found = TRUE;
    
    if (check_dispel(level,victim, gafn_protection_good))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_sanctuary))
    {
        act("The white aura around $n's body vanishes.",
            victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_shield))
    {
        act("The shield protecting $n vanishes.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_sleep))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_hard_skin))    {
        act("$n's skin regains its normal texture.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_globe))    {
        act("$n's globe of protection vanishes.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_size))    {
        act("$n's sizereturns to normal.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_vocalize))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_weakness))    {
        act("$n looks stronger.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_mist))    {
        act("$n looks solid again.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_water_breathing))
        found = TRUE;
 
    if (found)
        send_to_char("Ok.\r\n",ch);
    else
        send_to_char("Spell failed.\r\n",ch);
}

void spell_cause_light( int sn, int level, CHAR_DATA *ch, void *vo ) {
   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_HARM;
    spell_CDB->atk_blk_type = BLOCK_ABSORB;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Set up and adjust damage... */

    spell_CDB->damage = dice(1, 8) + level/3;

    if ( saves_spell( level, spell_CDB->defender ) ) {
     	spell_CDB->damage /= 2;
    }

   /* Apply the damage... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
 } else {
    apply_damage( spell_CDB);
 }

 return;
}


void spell_cause_critical( int sn, int level, CHAR_DATA *ch, void *vo ) {
   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_HARM;
    spell_CDB->atk_blk_type = BLOCK_ABSORB;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Set up and adjust damage... */

    spell_CDB->damage = dice(3, 8) + level;

    if ( saves_spell( level, spell_CDB->defender ) ) {
     	spell_CDB->damage /= 2;
    }

   /* Apply the damage... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
 } else {
    apply_damage( spell_CDB);
 }

    return;
}



void spell_cause_serious( int sn, int level, CHAR_DATA *ch, void *vo ) {
   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_HARM;
    spell_CDB->atk_blk_type = BLOCK_ABSORB;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Set up and adjust damage... */

    spell_CDB->damage = dice(2, 8) + level/2;

    if ( saves_spell( level, spell_CDB->defender ) ) {
     	spell_CDB->damage /= 2;
    }

   /* Apply the damage... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
 } else {
    apply_damage( spell_CDB);
 }

    return;
}

void spell_youth(int sn, int level, CHAR_DATA *ch, void *vo) {
        CHAR_DATA *victim = (CHAR_DATA *) vo;

        if ( IS_NPC(victim) ) {
	    send_to_char("This spell only affects players.", ch);
	    return;
        }

         if ( IS_SET(ch->act,ACT_UNDEAD)) {
	    send_to_char("You're beyond that point.", ch);
	    return;
        }

        send_to_char( "You feel a great weight lifted off your shoulders.\r\n", victim );
        act("$n's skin takes on a youthful glow.",victim,NULL,NULL,TO_ROOM);
	victim->pcdata->age_mod += number_range ( 1, 3 );
                if (get_age(victim) < 17) victim->pcdata->age_mod += 3;
	return;
}    

void spell_age(int sn, int level, CHAR_DATA *ch, void *vo) {
        CHAR_DATA *victim = (CHAR_DATA *) vo;

        if ( IS_NPC(victim))      {
            send_to_char("This spell only affects players.", ch);
            return;
        }

        send_to_char( "Your skin crawls as your life is sucked away\r\n",victim );
        act("$n appears to grow old before your eyes.",victim,NULL,NULL,TO_ROOM);
        victim->pcdata->age_mod -= number_range ( 1, 5 );
        return;
}

void spell_chain_lightning(int sn, int level, CHAR_DATA *ch, void *vo) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    CHAR_DATA *tmp_vict,*last_vict,*next_vict;
    bool found;
    int dam;

    /* first strike */

    act("A lightning bolt leaps from $n's hand and arcs to $N.",
        ch,NULL,victim,TO_ROOM);
    act("A lightning bolt leaps from your hand and arcs to $N.",
	ch,NULL,victim,TO_CHAR);
    act("A lightning bolt leaps from $n's hand and hits you!",
	ch,NULL,victim,TO_VICT);  

   /* Set up and adjust damage... */

    spell_CDB->damage = dice(level, 6);

    if ( saves_spell( level, spell_CDB->defender ) ) {
     	spell_CDB->damage /= 3;
    }

   /* Charging time... */

    apply_damage(spell_CDB);

    level -= 4;   /* decrement damage */

   /* Fry a few people... */

    found = FALSE;

    for ( tmp_vict = ch->in_room->people; 
          tmp_vict != NULL && level > 0; 
          tmp_vict = next_vict) { 
	
     /* Save next victim incase this one dies... */

      next_vict = tmp_vict->next_in_room;

     /* Do not fry the caster (yet)... */

      if (tmp_vict == ch) {
        continue;
      }

     /* Ok, frying time... */

      if (!is_safe_spell(ch,tmp_vict,TRUE)) { 
	
        found = TRUE;
        last_vict = tmp_vict;
        act("The bolt arcs to $n!",tmp_vict,NULL,NULL,TO_ROOM);

       /* Reset spell_CDB... */

        spell_CDB = getCDB(ch, tmp_vict, sn, FALSE, sn, 0);

       /* Set up combat data... */

        spell_CDB->atk_dam_type = DAM_LIGHTNING;
        spell_CDB->atk_blk_type = BLOCK_LIGHTNING;
        spell_CDB->atk_desc = "lightning";

       /* Bail out if it misses... */
 
        if (!check_spell_hit(spell_CDB, spell_roll)) {
          continue;
        }   

        act("The bolt hits you!",tmp_vict,NULL,NULL,TO_CHAR);

       /* Set up and adjust damage... */

        spell_CDB->damage = dice(level, 6);

        if ( saves_spell( level, spell_CDB->defender ) ) {
          spell_CDB->damage /= 3;
        }

       /* Charging time... */

 if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

        level -= 4;  /* decrement damage */
      }
    }

    if ( level > 0 
      && ch != NULL) {

      if (found) {
	act("The bolt seems to have fizzled out.",ch,NULL,NULL,TO_ROOM);
	act("The bolt grounds out through your body.",
	ch,NULL,NULL,TO_CHAR);
	return;
      } else {
        dam = dice(level,6);
        if (saves_spell(level,ch))
          dam /= 3;
        env_damage(ch, dam, DAM_LIGHTNING,
           "@v2 is struck by his own lightning bolt! [@n0]{x\r\n",
           "You are struck by your own lightning bolt! [@n0]{x\r\n" );
          
        level -= 4;  /* decrement damage */
      }
    }

    return;
}
	  

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

    if ( is_affected( victim, gafn_sex_change )) {
	if (victim == ch)
	  send_to_char("Your sex has already been changed.\r\n",ch);
	else
	  act("$N has already had $s(?) sex changed.",ch,NULL,victim,TO_CHAR);
	return;
    }
    if (saves_spell(level , victim))
	return;	
    af.type      = sn;
    af.afn	 = gafn_sex_change;
    af.level     = level;
    af.duration  = 2 * level;
    af.location  = APPLY_SEX;
    do
    {
	af.modifier  = number_range( 0, 2 ) - victim->sex;
    }
    while ( af.modifier == 0 );
    af.bitvector = 0;
    affect_to_char( victim, &af );
    send_to_char( "You feel different.\r\n", victim );
    act("$n doesn't look like $mself anymore...",victim,NULL,NULL,TO_ROOM);
    return;
}

void spell_lesser_possession(int sn, int level, CHAR_DATA *ch, void *vo) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;

    if ( ch->desc == NULL ) return;
        
    if ( ch->desc->original != NULL ) {
	send_to_char( "You are already switched.\r\n", ch );
	return;
    }

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

    if ( victim == ch ) {
	return;
    }

    if (!IS_NPC(victim)
    || !IS_AFFECTED(victim,AFF_CHARM)
    || IS_SET(victim->imm_flags, IMM_CHARM)){
	send_to_char("You can only switch into charmed pets.\r\n",ch);
	return;
    }

    if (victim->leader != ch) {
	send_to_char( "Not your follower.\r\n", ch );
	return;
    }

    if ( victim->desc != NULL ) {
	send_to_char( "Character in use.\r\n", ch );
	return;
    }
	
   /* Zeran - to fix null pointer dereferencing all over in the code,
	give switched player access to his pcdata fields. */

    victim->pcdata = ch->pcdata;
    ch->desc->character = victim;
    ch->desc->original  = ch;
    victim->desc        = ch->desc;
    victim->comm = ch->comm;
    victim->lines = ch->lines;
    REMOVE_BIT(victim->affected_by, AFF_CHARM);

    act("You possess $N.",ch, NULL, victim,TO_CHAR);
    act("$n possesses $N.",ch, NULL, victim,TO_ROOM);
    notify_message (ch, WIZNET_SWITCH, TO_IMM, victim->short_descr);

    return;
}


void spell_greater_possession(int sn, int level, CHAR_DATA *ch, void *vo) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int chance;

    if ( ch->desc == NULL ) return;
       
    if ( ch->desc->original != NULL ) {
	send_to_char( "You are already switched.\r\n", ch );
	return;
    }

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

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

    if (!IS_NPC(victim)
    || IS_SET(victim->act, ACT_AGGRESSIVE)
    || IS_SET(victim->act, ACT_INVADER)
    || IS_SET(victim->imm_flags, IMM_MAGIC)
    || IS_SET(victim->act, ACT_IS_HEALER)
    || IS_SET(victim->act, ACT_IS_ALIENIST)
    || IS_SET(victim->act, ACT_PRACTICE)
    || victim->pIndexData->pShop != NULL
    || IS_SET(victim->imm_flags, IMM_CHARM)){
	send_to_char("You can't switch into that mob.\r\n",ch);
	return;
    }

    if ( victim->desc != NULL ) {
	send_to_char( "Character in use.\r\n", ch );
	return;
    }
	
    chance = (level - victim->level)*5;
    if (number_percent() < chance) {
        victim->pcdata = ch->pcdata;
        ch->desc->character = victim;
        ch->desc->original  = ch;
        victim->desc        = ch->desc;
        victim->comm = ch->comm;
        victim->lines = ch->lines;
        act("You possess $N.",ch, NULL, victim,TO_CHAR);
        act("$n possesses $N.",ch, NULL, victim,TO_ROOM);
        notify_message (ch, WIZNET_SWITCH, TO_IMM, victim->short_descr);
     } else {
        if (victim->level < ch->level) {
             do_flee(victim,"");
        } else {
             SET_BIT(victim->act, ACT_AGGRESSIVE);
        }
     }
     return;
}


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

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

    if (!str_cmp(race_array[victim->race].name,"undead")
    || IS_SET(victim->act, ACT_UNDEAD)) {
        send_to_char( "You can't charm an undead.\r\n", ch );
        return;
      }

    if (!str_cmp(race_array[victim->race].name,"machine")
    || IS_SET(victim->form, FORM_MACHINE)) {
        send_to_char( "You can't charm a machine.\r\n", ch );
        return;
      }

   if (IS_SET(victim->act, ACT_AGGRESSIVE)) level /= 2;

    if ( IS_AFFECTED(victim, AFF_CHARM)
    ||   IS_AFFECTED(ch, AFF_CHARM)
    ||   level < victim->level
    ||   IS_SET(victim->imm_flags,IMM_CHARM)
    ||   saves_spell( level, victim ) )
	return;

    if (IS_SET(victim->in_room->room_flags,ROOM_LAW)
    || IS_SET(victim->in_room->area->area_flags, AREA_LAW))    {
	send_to_char("Marduk does not allow charming in the city limits.\r\n",ch);
	return;
    }

    if ( victim->master )
    stop_follower( victim );
    add_follower( victim, ch );
    victim->leader = ch;
    af.type      = sn;
    af.afn	 = gafn_charm;
    af.level	 = level;
    af.duration  = number_fuzzy( level / 4 );
    af.location  = 0;
    af.modifier  = 0;
    af.bitvector = AFF_CHARM;
    affect_to_char( victim, &af );
    act( "Isn't $n just so nice?", ch, NULL, victim, TO_VICT );
    if ( ch != victim ) act("$N looks at you with adoring eyes.",ch,NULL,victim,TO_CHAR);
    return;
}



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

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_COLD;
    spell_CDB->atk_blk_type = BLOCK_ALL;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Set up and adjust damage... */

    spell_CDB->damage = 10 + dice((level/4), 3);

    if ( saves_spell( level, spell_CDB->defender ) ) {
	spell_CDB->damage /= 2;
    } else {
	act("$n turns blue and shivers.",
             spell_CDB->defender,NULL,NULL,TO_ROOM);
	af.type      = sn;
	af.afn	     = gafn_chill_touch;	
        af.level     = level;
	af.duration  = 6;
	af.location  = APPLY_STR;
	af.modifier  = -1 * (1 + (spell_CDB->attacker->level/15));
	af.bitvector = 0;
	affect_join( spell_CDB->defender, &af );
    }

   /* Chilling time... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

    return;
}



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

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_LIGHT;
    spell_CDB->atk_blk_type = BLOCK_LIGHT;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Set up and adjust damage... */

    spell_CDB->damage = 30 + dice((level/3), 5);

    if ( saves_spell( level, spell_CDB->defender ) ) {
	spell_CDB->damage /= 2;
    } else {
	spell_blindness(get_skill_sn("blindness"),
                                    level/2, ch, (void *) victim);
    }

   /* Illuminating experience... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

    return;
}

/* Hmmmm....

void spell_darkness( int sn, int level, CHAR_DATA *ch, void *vo ) {
    int chance;

    chance = number_percent();
    if (chance >=5)    {
	--ch->in_room->light;
    }
}
*/

void spell_continual_light( int sn, int level, CHAR_DATA *ch, void *vo ) {
    OBJ_DATA *light;

    light = create_object( get_obj_index( OBJ_VNUM_LIGHT_BALL ), 0 );
    obj_to_room( light, ch->in_room );
    light->timer = level * 72;                          /* 3 days per level */
    if (!in_seq) { 
      act( "$n twiddles $s thumbs and $p appears.",   ch,light,NULL,TO_ROOM );
      act( "You twiddle your thumbs and $p appears.", ch,light,NULL,TO_CHAR );
    }
    return;
}

void spell_mage_light( int sn, int level, CHAR_DATA *ch, void *vo ) {
    OBJ_DATA *light;

    light = create_object( get_obj_index( OBJ_VNUM_LIGHT_BALL ), 0 );
    light->timer = 12 + level/3;           /* 12 hours plus 1 hour/3 levels */
    obj_to_room( light, ch->in_room );
    if (!in_seq) { 
      act( "$n twiddles $s thumbs and $p appears.",   ch,light,NULL,TO_ROOM );
      act( "You twiddle your thumbs and $p appears.", ch,light,NULL,TO_CHAR );
    }
    return;
}


void spell_control_weather( int sn, int level, CHAR_DATA *ch, void *vo ) {

    if ( !str_cmp( target_name, "better" ) ) {
      if ( weather_info.sky > SKY_CLOUDLESS ) {
        weather_info.sky -= 1;
        weather_update(FALSE);
      }
    } else if ( !str_cmp( target_name, "worse" ) ) {
      if ( weather_info.sky < SKY_LIGHTNING ) {
        weather_info.sky += 1;
        weather_update(FALSE);
      }
    } else {
      if (number_bits(2) > 1) {
        weather_info.sky += 1;
      } else { 
        weather_info.sky -= 1;
      }
      weather_info.sky = URANGE(SKY_CLOUDLESS, weather_info.sky, SKY_LIGHTNING);
      weather_update(FALSE);
    } 

    send_to_char( "Ok.\r\n", ch );

    return;
}


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

    mushroom = create_object( get_obj_index( OBJ_VNUM_MUSHROOM ), 0 );
    mushroom->value[0] = 4 + (level/5);
    obj_to_room( mushroom, ch->in_room );
    if (!in_seq) {
      act( "$p suddenly appears.", ch, mushroom, NULL, TO_ROOM );
      act( "$p suddenly appears.", ch, mushroom, NULL, TO_CHAR );
    }
    return;
}

void spell_create_buffet( int sn, int level, CHAR_DATA *ch, void *vo) {
     OBJ_DATA *mushroom;
     int counter=0;
     for(counter=0; counter < (level/10) + 1; counter++) {
       mushroom = create_object( get_obj_index( OBJ_VNUM_MUSHROOM ), 0 );
       mushroom->value[0] = 4 + (level / 10);
       obj_to_room( mushroom, ch->in_room );
       if (!in_seq) {
         act( "$p suddenly appears.", ch, mushroom, NULL, TO_ROOM );
         act( "$p suddenly appears.", ch, mushroom, NULL, TO_CHAR );
       } 
     }
     return;
}

void spell_create_spring( int sn, int level, CHAR_DATA *ch, void *vo ) {
    OBJ_DATA *spring;

        spring = create_object( get_obj_index( OBJ_VNUM_SPRING ), 0 );
        spring->timer = level;
        obj_to_room( spring, ch->in_room );
          if (!strcmp(target_name, "blood")) {
               spring->value[0] = LIQ_BLOOD;
               free_string(spring->name);
               spring->name = strdup("spring blood");
               free_string(spring->short_descr);
               spring->short_descr = strdup("a spring of blood");
               free_string(spring->description);
               spring->description = strdup("A spring of blood flows from the ground here.\n");
          }
        if (!in_seq) {
          act( "$p flows from the ground.", ch, spring, NULL, TO_ROOM );
          act( "$p flows from the ground.", ch, spring, NULL, TO_CHAR );
        }
        return;



}


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

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

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

    water = UMIN(	level * (weather_info.sky >= SKY_RAINING ? 4 : 2), obj->value[0] - obj->value[1]);
  
    if ( water > 0 )    {
	obj->value[2] = LIQ_WATER;
	obj->value[1] += water;
	if ( !is_name( "water", obj->name ) )	{
	    char buf[MAX_STRING_LENGTH];

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

    return;
}


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

    if ( !is_affected( victim, gafn_blindness ) )
    {
        if (victim == ch)
          send_to_char("You aren't blind.\r\n",ch);
        else
          act("$N doesn't appear to be blinded.",ch,NULL,victim,TO_CHAR);
        return;
    }
 
    if (check_dispel(level, victim, gafn_blindness))
    {
        send_to_char( "Your vision returns!\r\n", victim );
        act("$n is no longer blinded.",victim,NULL,NULL,TO_ROOM);
    }
    else
        send_to_char("Spell failed.\r\n",ch);

    return;
}

void spell_transformation( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int loss;

    if (victim->level<15
    || IS_NPC(victim)
    || IS_SET(victim->act, ACT_UNDEAD)) {
	send_to_char( "Your victim is not worthy to become a Were.\r\n", ch );
	return;
     }

    if (IS_SET(victim->act, ACT_WERE)) {
	send_to_char("It's already a Were.\r\n", ch );
	return;
     }

    if(!IS_NPC(ch)
    || IS_AFFECTED(ch, AFF_CHARM)
    || ch->desc) {
        if (victim->level*2 > ch->level) {
	send_to_char( "Your victim is too powerful.\r\n", ch );
	return;
         }
   
         if (weather_info.moon != MOON_FULL) {
	send_to_char( "The moon is not right.\r\n", ch );
	return;
         }
         WAIT_STATE(ch, 64);
         loss = victim->exp;
         gain_exp(ch, -1 * loss, FALSE);
    }

    SET_BIT(victim->act,ACT_WERE);

    if (!strcmp(target_name, "wolf")) {
         victim->were_type = 31;
    } else if (!strcmp(target_name, "cat")) {
         victim->were_type = 12;
    } else if (!strcmp(target_name, "fox")) {
         victim->were_type = 17;
    } else {
         victim->were_type = 31;
    }

    send_to_char ("You transfer the Power of Nature !\r\n",ch);
    send_to_char ("You feel your inner strength awaken!\r\n",victim);
    return;
}


void spell_cure_critical( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int heal;
    int tolimb;

    heal = dice(3, 8) + level - 6;
    victim->hit = UMIN( victim->hit + heal, victim->max_hit );
    if (number_percent()<50) {
           REMOVE_BIT(victim->form,FORM_BLEEDING);
           tolimb=number_range(0,5);
           if (ch->limb[tolimb]>0 && ch->limb[tolimb]<10) {
                   if (number_range(0,ch->limb[tolimb])/3 < 2) ch->limb[tolimb] -=1;
           }
           update_wounds(ch);
    }
    update_pos( victim );
    send_to_char( "You feel better!\r\n", victim );
    if ( ch != victim )
	send_to_char( "Ok.\r\n", ch );
    return;
}

/* RT added to cure plague */
void spell_cure_disease( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;

    if ( !is_affected( victim, gafn_plague ) )
    {
        if (victim == ch)
          send_to_char("You aren't ill.\r\n",ch);
        else
          act("$N doesn't appear to be diseased.",ch,NULL,victim,TO_CHAR);
        return;
    }
    
    if (check_dispel(level,victim, gafn_plague))
    {
	send_to_char("Your sores vanish.\r\n",victim);
	act("$n looks relieves as $s sores vanish.",victim,NULL,NULL,TO_ROOM);
    }
    else
	send_to_char("Spell failed.\r\n",ch);
}


void spell_cure_light( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int heal;
    int tolimb;

    heal = dice(1, 8) + level / 3;
    victim->hit = UMIN( victim->hit + heal, victim->max_hit );
    if (number_percent()<10) {
          REMOVE_BIT(victim->form,FORM_BLEEDING);
           tolimb=number_range(0,5);
           if (ch->limb[tolimb]>0 && ch->limb[tolimb]<10) {
                   if (number_range(0,ch->limb[tolimb])/2 < 2) ch->limb[tolimb] -=1;
           }
           update_wounds(ch);
    }
    update_pos( victim );
    send_to_char( "You feel better!\r\n", victim );
    if ( ch != victim )
	send_to_char( "Ok.\r\n", ch );
    return;
}


void spell_cure_poison( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
 
    if ( !is_affected( victim, gafn_poison ) )
    {
        if (victim == ch)
          send_to_char("You aren't poisoned.\r\n",ch);
        else
          act("$N doesn't appear to be poisoned.",ch,NULL,victim,TO_CHAR);
        return;
    }
 
    if (check_dispel(level,victim, gafn_poison))
    {
        send_to_char("A warm feeling runs through your body.\r\n",victim);
        act("$n looks much better.",victim,NULL,NULL,TO_ROOM);
    }
    else
        send_to_char("Spell failed.\r\n",ch);
}

void spell_cure_serious( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int heal;
    int tolimb;

    heal = dice(2, 8) + level /2 ;
    victim->hit = UMIN( victim->hit + heal, victim->max_hit );
    if (number_percent()<25) {
           REMOVE_BIT(victim->form,FORM_BLEEDING);
           tolimb=number_range(0,5);
           if (ch->limb[tolimb]>0 && ch->limb[tolimb]<10) {
                   if (number_range(0,ch->limb[tolimb])/2 < 2) ch->limb[tolimb] -=1;
           }
           update_wounds(ch);
    }
    update_pos( victim );
    send_to_char( "You feel better!\r\n", victim );
    if ( ch != victim )
	send_to_char( "Ok.\r\n", ch );
    return;
}


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

    if ( IS_AFFECTED(victim, AFF_CURSE) || saves_spell( level, victim ) )
	return;
    af.type      = sn;
    af.afn	 = gafn_curse;
    af.level     = level;
    af.duration  = 2*level;
    af.location  = APPLY_HITROLL;
    af.modifier  = -1 * (level / 8);
    af.bitvector = AFF_CURSE;
    affect_to_char( victim, &af );

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

    send_to_char( "You feel unclean.\r\n", victim );
    if ( ch != victim )
	act("$N looks very uncomfortable.",ch,NULL,victim,TO_CHAR);
    return;
}


void spell_exorcism(int sn, int level, CHAR_DATA *ch, void *vo) {
CHAR_DATA *victim = (CHAR_DATA *) vo;

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_HOLY;
    spell_CDB->atk_blk_type = BLOCK_ABSORB;

   /* Set up and adjust damage... */

    spell_CDB->damage = dice(level, 10);
    if ( IS_SET(victim->act,ACT_UNDEAD)) spell_CDB->damage *= 2;

   /* Theatrics... */

    act("$n invokes the wrath of his God on $N!", ch,NULL,victim,TO_ROOM);
    act("$n has called forth the Angels of heaven to exorcise you!", ch,NULL,victim,TO_VICT);
    send_to_char("You call forth Angels of God!\r\n",ch);
    
   /* Upset gods are a pain... */ 

    if ( !IS_NPC(ch) && !IS_GOOD(ch) ) {
        act("The Angels turn and attack $n!", ch, NULL,victim,TO_ROOM);
        send_to_char("The Angels turn to attack you!\r\n",ch);

        if ( saves_spell( level, ch ) ) {
	  spell_CDB->damage /= 2;
        } 

        env_damage(ch, spell_CDB->damage, DAM_HOLY,
           "@v2 is struck down by his own Angels! [@n0]{x\r\n",
           "The Angles strike you down! [@n0]{x\r\n" );

        return;  
    }

   /* ok, we're live... */

    ch->alignment = UMAX(1000, ch->alignment + 50);

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  

   /* Give the defender a saving throw... */
 
    if ( saves_spell( level, spell_CDB->defender ) ) {
	spell_CDB->damage /= 2;
    } 

   /* Illuminating experience... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

    return;
}

/* Mik demonfire, evil version of Exorcism */

void spell_demonfire(int sn, int level, CHAR_DATA *ch, void *vo) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_NEGATIVE;
    spell_CDB->atk_blk_type = BLOCK_ABSORB;

   /* Set up and adjust damage... */

    spell_CDB->damage = dice(level, 10);

   /* Theatrics... */

    act("$n commands a mutlitude of demons to attack $N!",
         ch,NULL,victim,TO_ROOM);
    act("$n has command a multitude of demons to slay you!",
         ch,NULL,victim,TO_VICT);
    send_to_char("You send forth a multitude of demons!\r\n",ch);
    
   /* Upset gods are a pain... */ 

    if ( !IS_NPC(ch) && !IS_EVIL(ch) ) {
        act("The Demons turn and attack $n!",
             ch,NULL,victim,TO_ROOM);
        send_to_char("The Demons turn and attack you!\r\n",ch);

        if ( saves_spell( level, ch ) ) {
	  spell_CDB->damage /= 2;
        } 

        env_damage(ch, spell_CDB->damage, DAM_NEGATIVE,
           "@v2 is pulled down by his own Demons! [@n0]{x\r\n",
           "The Demons pull you down! [@n0]{x\r\n" );

        return;  
    }

   /* ok, we're live... */

    ch->alignment = UMAX(-1000, ch->alignment - 50);

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  

   /* Give the defender a saving throw... */
 
    if ( saves_spell( level, spell_CDB->defender ) ) {
	spell_CDB->damage /= 2;
    } 

   /* Illuminating experience... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

    return;
}

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

    if ( IS_AFFECTED(victim, AFF_DETECT_EVIL) )    {
	if (victim == ch)
	  send_to_char("You can already sense evil.\r\n",ch);
	else
	  act("$N can already detect evil.",ch,NULL,victim,TO_CHAR);
	return;
    }
    af.type      = sn;
    af.afn	 = gafn_detect_evil;	
    af.level	 = level;
    af.duration  = level;
    af.modifier  = 0;
    af.location  = APPLY_NONE;
    af.bitvector = AFF_DETECT_EVIL;
    affect_to_char( victim, &af );
    send_to_char( "Your eyes tingle.\r\n", victim );
    if ( ch != victim )
	send_to_char( "Ok.\r\n", ch );
    return;
}

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

    if ( is_affected(victim, gafn_detect_good) )
    {
	if (victim == ch)
	  send_to_char("You can already sense good.\r\n",ch);
	else
	  act("$N can already detect good.",ch,NULL,victim,TO_CHAR);
	return;
    }
    af.type      = sn;
    af.afn 	 = gafn_detect_good;
    af.level	 = level;
    af.duration  = level;
    af.modifier  = 0;
    af.location  = APPLY_NONE;
	af.bitvector = 0;
    affect_to_char( victim, &af );
    send_to_char( "Your eyes tingle.\r\n", victim );
    if ( ch != victim )
	send_to_char( "Ok.\r\n", ch );
    return;
}


void spell_water_breathing( int sn, int level, CHAR_DATA *ch, void *vo ) {

    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;

    if ( IS_AFFECTED(victim, AFF_WATER_BREATHING) ) {

	if (victim == ch)
	  send_to_char("You can already breath water.\r\n",ch);
	else
	  act("$N can already breath water.",ch,NULL,victim,TO_CHAR);

	return;
    }

    af.type      = sn;
    af.afn 	 = gafn_water_breathing;
    af.level	 = level;
    af.duration  = level/6 + dice(1,6);
    af.modifier  = 0;
    af.location  = APPLY_NONE;
    af.bitvector = AFF_WATER_BREATHING;

    affect_to_char( victim, &af );

    send_to_char( "The air suddenly feels very dry!\r\n", victim );

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

    return;
}


void spell_true_dreaming( int sn, int level, CHAR_DATA *ch, void *vo ) {
CHAR_DATA *victim = (CHAR_DATA *) vo;

   /* Only works on dreaming victims... */

    if ( victim->waking_room == NULL ) { 
      if ( victim != ch ) send_to_char("They are not dreaming!\r\n", ch);
      else send_to_char("You are not dreaming!\r\n", ch);
      return;
    }
 
   /* And not the badly injured... */
 
    if ( victim->position < POS_STUNNED ) {
      send_to_char("Dreams won't help them now...\r\n", ch);
      return;
    }

    if (IS_SET(victim->in_room->room_flags, ROOM_NO_DREAM)) {
          send_to_char( "{cYour dreams are disturbing and frightening.{x\r\n", victim);
          return;
    }

   /* Others get a save... */

    if ( victim != ch ) {
      if ( saves_spell(level, victim) ) {
        send_to_char("You feel a little strange.\r\n", victim);
        send_to_char("They resist your spell!\r\n", ch);
        return;
      } 
    }

   /* Now you must make a dreaming check... */

    if ( !check_skill(ch, gsn_dreaming, ch->level - victim->level) ) {

      if (victim != ch) {
        send_to_char("You feel very strange!\r\n", victim);
      }

      send_to_char("Your dream manipulations fail!\r\n", ch);

      return;
    }

   /* Success, transform from dreaming to really here... */

    victim->waking_room = NULL;
    victim->dreaming_room = NULL;

    send_to_char("You feel like you have been turned inside out!\r\n", victim);

    if ( victim != ch ) {
      send_to_char("Success! They are now here for real!\r\n", ch);
    }

    return;
}


void spell_rude_awakening( int sn, int level, CHAR_DATA *ch, void *vo ) {
CHAR_DATA *victim = (CHAR_DATA *) vo;

   /* Only works on dreaming victims... */

    if ( victim->waking_room == NULL ) { 
      if ( victim != ch ) send_to_char("They are not dreaming!\r\n", ch);
      else send_to_char("You are not dreaming!\r\n", ch);
      return;
    }

   /* And not the badly injured... */
 
    if ( victim->position < POS_STUNNED ) {
      send_to_char("Dreams won't help them now...\r\n", ch);
      return;
    }

    if (IS_SET(victim->in_room->room_flags, ROOM_NO_DREAM)) {
          send_to_char( "{cYour dreams are disturbing and frightening.{x\r\n", victim);
          return;
    }

   /* Others get a save... */

    if ( victim != ch ) {
      if ( saves_spell(level, victim) ) {

        if ( victim->position == POS_SLEEPING
          || victim->position == POS_SITTING
          || victim->position == POS_RESTING ) {
          set_activity(victim, POS_STANDING, NULL, ACV_NONE, NULL);
        }  

        send_to_char("You feel wide awake!\r\n", victim);
        send_to_char("They resist your spell!\r\n", ch);

        return;
      } 
    }

   /* Now you must make a dreaming check... */

    if ( !check_skill(ch, gsn_dreaming, ch->level - victim->level) ) {

      if ( victim->position == POS_SLEEPING
        || victim->position == POS_SITTING
        || victim->position == POS_RESTING ) {
        set_activity(victim, POS_STANDING, NULL, ACV_NONE, NULL);
      }  

      if (victim != ch) {
        send_to_char("You feel wide awake!\r\n", victim);
      }

      send_to_char("Your dream manipulations fail!\r\n", ch);

      return;
    }

   /* Success, kick them back to the real world... */

    stop_fighting(victim, TRUE);
 
    act( "$n abruptly vanishes!", victim, NULL, NULL, TO_ROOM );

    victim->dreaming_room = victim->in_room;  /* Allow return */
    victim->nightmare = FALSE;
    add_tracks(ch, DIR_NONE, DIR_OTHER);

    char_from_room(victim);

    victim->in_zone = -1;

    char_to_room(victim, victim->waking_room);

    add_tracks(ch, DIR_OTHER, DIR_HERE);

    set_activity(victim, POS_STANDING, NULL, ACV_NONE, NULL);

    send_to_char("{mYou are suddenly wide awake!{x\r\n", victim);

    if ( victim != ch ) {
      send_to_char("Success! They are returned to the real world!\r\n", ch);
    }

    do_look(victim, "auto");

    return;
}


void spell_recurring_dream( int sn, int level, CHAR_DATA *ch, void *vo ) {
CHAR_DATA *victim = (CHAR_DATA *) vo;

   /* Only works on non-dreaming victims... */

    if ( victim->waking_room != NULL ) { 
      if ( victim != ch ) send_to_char("They are already dreaming!\r\n", ch);
      else send_to_char("You are already dreaming!\r\n", ch);
      return;
    }
 
   /* And not the badly injured... */
 
    if ( victim->position < POS_STUNNED ) {
      send_to_char("Dreams won't help them now...\r\n", ch);
      return;
    }

   /* ...with a dream to return to */

    if ( victim->dreaming_room == NULL ) { 
      if ( victim != ch ) send_to_char("They have lost their dream!\r\n", ch);
      else send_to_char("You have lost your dream!\r\n", ch);
      return;
    }
 
    if (IS_SET(victim->in_room->room_flags, ROOM_NO_DREAM)) {
          send_to_char( "{cYour dreams are disturbing and frightening.{x\r\n", victim );
          return;
    }

   /* Others get a save... */

    if ( victim != ch ) {
      if ( saves_spell(level, victim) ) {

        send_to_char("You feel a little sleepy!\r\n", victim);
        send_to_char("They resist your spell!\r\n", ch);

        return;
      } 
    }

   /* Now you must make a dreaming check... */

    if ( !check_skill(ch, gsn_dreaming, ch->level - victim->level) ) {

      stop_fighting(victim, TRUE);

      set_activity(victim, POS_RESTING, NULL, ACV_NONE, NULL);

      send_to_char("You feel very sleepy!\r\n", victim);
      send_to_char("Your dream manipulations fail!\r\n", ch);

      victim->dreaming_room = NULL;

      return;
    }

   /* Success, transform from dreaming to really here... */

    stop_fighting(victim, TRUE);
 
    act( "$n goes to sleep and fades away to the world of dreams...", 
            victim, NULL, NULL, TO_ROOM );

    send_to_char("You feel very, very tired...{x\r\n", victim);

    victim->waking_room = victim->in_room;    /* Allow awaken */

    add_tracks(ch, DIR_NONE, DIR_OTHER);

    char_from_room(victim);

    victim->in_zone = -1;

    char_to_room(victim, victim->dreaming_room);

    add_tracks(ch, DIR_OTHER, DIR_HERE);

    set_activity(victim, POS_STANDING, NULL, ACV_NONE, NULL);

    send_to_char("{mWhen you awaken you are somewhere else!{x\r\n", victim);

    if ( victim != ch ) {
      send_to_char("Success! They are returned to thier dreams!\r\n", ch);
    }

    do_look(victim, "auto");

    return;
}


void spell_enchanted_sleep( int sn, int level, CHAR_DATA *ch, void *vo ) {
CHAR_DATA *victim = (CHAR_DATA *) vo;

    ROOM_INDEX_DATA *room;

   /* Only works on non-dreaming victims... */

    if ( victim->waking_room != NULL ) { 
      if ( victim != ch ) send_to_char("They are already dreaming!\r\n", ch);
      else send_to_char("You are already dreaming!\r\n", ch);
      return;
    }
 
   /* And not the badly injured... */
 
    if ( victim->position < POS_STUNNED ) {
      send_to_char("Dreams won't help them now...\r\n", ch);
      return;
    }

    if (IS_SET(victim->in_room->room_flags, ROOM_NO_DREAM)) {
          send_to_char( "{cYour dreams are disturbing and frightening.{x\r\n", victim );
          return;
    }

   /* Others get a save... */

    if ( victim != ch ) {
      if ( saves_spell(level, victim) ) {

        send_to_char("You feel a little sleepy!\r\n", victim);
        send_to_char("They resist your spell!\r\n", ch);

        return;
      } 
    }

   /* Now you must make a dreaming check... */

    if ( !check_skill(ch, gsn_dreaming, ch->level - victim->level) ) {

      stop_fighting(victim, TRUE);

      set_activity(victim, POS_RESTING, NULL, ACV_NONE, NULL);

      send_to_char("You feel very sleepy!\r\n", victim);
      send_to_char("Your dream manipulations fail!\r\n", ch);

      return;
    }

   /* Now, where should we go? */
 
    room = NULL; 

    if ( ch->in_room != NULL
      && ch->in_room->dream != 0 ) {
      room = get_room_index(ch->in_room->dream);
    }

    if ( room == NULL 
      && ch->in_room != NULL
      && ch->in_room->area != NULL
      && ch->in_room->area->dream != 0 ) {
      room = get_room_index(ch->in_room->area->dream);
    }

    if ( room == NULL 
      && ch->in_room != NULL
      && ch->in_room->area != NULL
      && zones[ch->in_room->area->zone].dream != 0 ) {
      room = get_room_index(zones[ch->in_room->area->zone].dream);
    }

    if ( room == NULL 
      && mud.dream != 0 ) {
      room = get_room_index(mud.dream);
    }
       
   /* Just put to sleep and send a dream if nowhere to go... */

    if ( room == NULL ) {

      stop_fighting(victim, TRUE);

      act( "$n goes to sleep...", 
              victim, NULL, NULL, TO_ROOM );

      send_to_char("You feel very, very tired...{x\r\n", victim);

      if ( victim->position == POS_STANDING
        || victim->position == POS_SITTING
        || victim->position == POS_RESTING ) {
        set_activity(victim, POS_SLEEPING, NULL, ACV_NONE, NULL);
      }
 
      if (victim->position == POS_SLEEPING) { 
        random_dream(victim);
      }

      return;
    } 

   /* Success, transform from dreaming to really here... */

    stop_fighting(victim, TRUE);
 
    act( "$n goes to sleep and fades away to the world of dreams...", 
            victim, NULL, NULL, TO_ROOM );

    send_to_char("You feel very, very tired...{x\r\n", victim);

    victim->waking_room = victim->in_room;    /* Allow awaken */

    add_tracks(ch, DIR_NONE, DIR_OTHER);

    char_from_room(victim);

    victim->in_zone = -1;

    char_to_room(victim, room);

    add_tracks(ch, DIR_OTHER, DIR_HERE);

    victim->position = POS_STANDING;

    victim->dreaming_room = NULL;

    send_to_char("{mWhen you awaken you are somewhere else!{x\r\n", victim);

    if ( victim != ch ) {
      send_to_char("Success! They are returned to thier dreams!\r\n", ch);
    }

    do_look(victim, "auto");

    return;
}



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

    if ( IS_AFFECTED(victim, AFF_DETECT_HIDDEN) )
    {
        if (victim == ch)
          send_to_char("You are already as alert as you can be. \r\n",ch);
        else
          act("$N can already sense hidden lifeforms.",ch,NULL,victim,TO_CHAR);
        return;
    }
    af.type      = sn;
    af.afn	 = gafn_detect_hidden;
    af.level     = level;
    af.duration  = level;
    af.location  = APPLY_NONE;
    af.modifier  = 0;
    af.bitvector = AFF_DETECT_HIDDEN;
    affect_to_char( victim, &af );
    send_to_char( "Your awareness improves.\r\n", victim );
    if ( ch != victim )
	send_to_char( "Ok.\r\n", ch );
    return;
}



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

    if ( IS_AFFECTED(victim, AFF_DETECT_INVIS) )
    {
        if (victim == ch)
          send_to_char("You can already see invisible.\r\n",ch);
        else
          act("$N can already see invisible things.",ch,NULL,victim,TO_CHAR);
        return;
    }
    af.type      = sn;
    af.afn 	 = gafn_detect_invis;
    af.level     = level;
    af.duration  = level;
    af.modifier  = 0;
    af.location  = APPLY_NONE;
    af.bitvector = AFF_DETECT_INVIS;
    affect_to_char( victim, &af );
    send_to_char( "Your eyes tingle.\r\n", victim );
    if ( ch != victim )
	send_to_char( "Ok.\r\n", ch );
    return;
}



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

    if ( IS_AFFECTED(victim, AFF_DETECT_MAGIC) )
    {
        if (victim == ch)
          send_to_char("You can already sense magical auras.\r\n",ch);
        else
          act("$N can already detect magic.",ch,NULL,victim,TO_CHAR);
        return;
    }
    af.type      = sn;
    af.afn	 = gafn_detect_magic;
    af.level	 = level;
    af.duration  = level;
    af.modifier  = 0;
    af.location  = APPLY_NONE;
    af.bitvector = AFF_DETECT_MAGIC;
    affect_to_char( victim, &af );
    send_to_char( "Your eyes tingle.\r\n", victim );
    if ( ch != victim )
	send_to_char( "Ok.\r\n", ch );
    return;
}



void spell_detect_poison( int sn, int level, CHAR_DATA *ch, void *vo )
{
    OBJ_DATA *obj = (OBJ_DATA *) 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.\r\n", ch );
	else
	    send_to_char( "It looks delicious.\r\n", ch );
    }
    else
    {
	send_to_char( "It doesn't look poisoned.\r\n", ch );
    }

    return;
}



void spell_dispel_evil( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
  
    if ( !IS_NPC(ch) && IS_EVIL(ch) )
	victim = ch;
  
    if ( IS_GOOD(victim) )
    {
	act( "Dispel evil has no effect upon $N.", ch, NULL, victim, TO_ROOM );
	return;
    }

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

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_HOLY;
    spell_CDB->atk_blk_type = BLOCK_ABSORB;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Set up and adjust damage... */

    spell_CDB->damage = dice(level, 4);

    if ( saves_spell( level, spell_CDB->defender ) ) {
	spell_CDB->damage /= 2;
    } 

   /* Illuminating experience... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

    return;
}

void spell_dispel_good( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
 	
    if ( !IS_NPC(ch) && IS_GOOD(ch) )
	victim = ch;
 
    if ( IS_EVIL(victim) )
    {
	act( "Dispel good has no effect upon $N.", ch, NULL, victim, TO_ROOM );
	return;
    }

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

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_NEGATIVE;
    spell_CDB->atk_blk_type = BLOCK_ABSORB;

   /* Bail out if it misses... */
 
    if (!check_spell_hit(spell_CDB, spell_roll)) {
      return;
    }  
 
   /* Set up and adjust damage... */

    spell_CDB->damage = dice(level, 4);

    if ( saves_spell( level, spell_CDB->defender ) ) {
	spell_CDB->damage /= 2;
    } 

   /* Illuminating experience... */

if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

    return;
}


/* modified for enhanced use */

void spell_dispel_magic( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    bool found = FALSE;

    if (saves_spell(level, victim))
    {
	send_to_char( "You feel a brief tingling sensation.\r\n",victim);
	send_to_char( "You failed.\r\n", ch);
	return;
    }

    /* begin running through the spells */ 

    if (check_dispel(level,victim, gafn_absorb_magic))
        found = TRUE;
       
    if (check_dispel(level,victim, gafn_regeneration))
        found = TRUE;
   		 
    if (check_dispel(level,victim, gafn_armor))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_bless))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_blindness))
    {
        found = TRUE;
        act("$n is no longer blinded.",victim,NULL,NULL,TO_ROOM);
    }
 
    if (check_dispel(level,victim, gafn_calm))
    {
        found = TRUE;
        act("$n no longer looks so peaceful...",victim,NULL,NULL,TO_ROOM);
    }
 
    if (check_dispel(level,victim, gafn_sex_change))
    {
        found = TRUE;
        act("$n looks more like $mself again.",victim,NULL,NULL,TO_ROOM);
    }
 
    if (check_dispel(level,victim, gafn_charm))
    {
        found = TRUE;
        act("$n regains $s free will.",victim,NULL,NULL,TO_ROOM);
    }
 
    if (check_dispel(level,victim, gafn_chill_touch))
    {
        found = TRUE;
        act("$n looks warmer.",victim,NULL,NULL,TO_ROOM);
    }
 
    if (check_dispel(level,victim, gafn_curse))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_evil))
        found = TRUE;
    
    if (check_dispel(level,victim, gafn_detect_good))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_hidden))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_invis))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_hidden))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_detect_magic))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_faerie_fire))
    {
        act("$n's outline fades.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
    
    if (check_dispel(level,victim, gafn_fear))
    {
        act("$n no longer looks so scared.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
	
 
    if (check_dispel(level,victim, gafn_fly))
    {
        act("$n falls to the ground!",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_frenzy)
    || check_dispel(level,victim, gafn_berserk))    {
        act("$n no longer looks so wild.",victim,NULL,NULL,TO_ROOM);;
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_giant_strength))
    {
        act("$n no longer looks so mighty.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_haste))    {
        act("$n is no longer moving so quickly.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_slow))    {
        act("$n is no longer moving so slowly.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_infravision))   found = TRUE;
     if (check_dispel(level,victim, gafn_farsight))   found = TRUE;

    if (check_dispel(level,victim, gafn_invisability))
    {
        act("$n fades into existance.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_mask_self))    {
        act("$n suddenly appears as $s mask vanishes.",victim,NULL,NULL,TO_ROOM);
        undo_mask(victim, FALSE);
        found = TRUE;
    }
    
    if (check_dispel(level,victim, gafn_mind_meld))
    {
        act("$n has regained $s senses.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_mute))
        found = TRUE;
    
    if (check_dispel(level,victim, gafn_pass_door))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_protection_good))
        found = TRUE;
    
    if (check_dispel(level,victim, gafn_protection_evil))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_sanctuary))
    {
        act("The white aura around $n's body vanishes.",
            victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (IS_AFFECTED(victim,AFF_SANCTUARY) 
	&& !saves_dispel(level, victim->level,-1)
	&& !is_affected(victim, gafn_sanctuary)) {
	REMOVE_BIT(victim->affected_by,AFF_SANCTUARY);
        act("The white aura around $n's body vanishes.",
            victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_shield))
    {
        act("The shield protecting $n vanishes.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_sleep))
        found = TRUE;
 
    if (check_dispel(level,victim, gafn_hard_skin))    {
        act("$n's skin regains its normal texture.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_globe))    {
        act("$n's globe of protection vanishes.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_size))    {
        act("$n's size returns to normal.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (check_dispel(level,victim, gafn_vocalize))
        found = TRUE;
    
    if (check_dispel(level,victim, gafn_weakness))    {
        act("$n looks stronger.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }
 
    if (check_dispel(level,victim, gafn_mist))    {
        act("$n looks solid again.",victim,NULL,NULL,TO_ROOM);
        found = TRUE;
    }

    if (found) send_to_char("Ok.\r\n",ch);
    else send_to_char("Spell failed.\r\n",ch);
}


void spell_earthquake( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *vch;
    CHAR_DATA *vch_next;

    send_to_char( "The world shudders around you!\r\n", ch );
    act( "$n makes the earth tremble and shiver.", ch, NULL, NULL, TO_ROOM );

    for ( vch = char_list; vch != NULL; vch = vch_next )    {
	vch_next	= vch->next;

	if ( vch->in_room == NULL ) continue;

	if ( vch->in_room->area == ch->in_room->area) {

  	  if ( vch->in_room->subarea == ch->in_room->subarea
                  && vch != ch
                  && !is_safe_spell(ch, vch, TRUE) ) {

           /* Reset spell_CDB... */

            spell_CDB = getCDB(ch, vch, sn, FALSE, sn, 0);

           /* Set up combat data... */

            spell_CDB->atk_dam_type = DAM_BASH;
            spell_CDB->atk_blk_type = BLOCK_ABSORB;
            spell_CDB->atk_desc = "earthquake";

           /* Set up and adjust damage... */

            if ( ch->in_room == vch->in_room ) { 
              spell_CDB->damage = level + dice(4, 12);
            } else {						
              spell_CDB->damage = level/2 + dice(3, 6);
            }

            spell_CDB->damage += spell_roll;

            if ( vch == ch ) {
              spell_CDB->damage = (spell_CDB->damage * 3)/2; 
            } 

            if ( IS_AFFECTED(vch, AFF_FLYING) ) {
              spell_CDB->damage /= 2;
            }

            if ( saves_spell( level, spell_CDB->defender ) ) {
              spell_CDB->damage /= 2;
            }

           /* Charging time... */
   
 if  (!IS_SET(spell_CDB->attacker->plr, PLR_AUTOKILL)) {
     SET_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL);
     apply_damage( spell_CDB);  
     REMOVE_BIT(spell_CDB->attacker->plr, PLR_AUTOKILL) ;
 } else {
    apply_damage( spell_CDB);
 }

          } else {

	    send_to_char( "The earth trembles and shivers.\r\n", vch );
          }
        }
    }

    return;
}

void spell_enchant_armor( int sn, int level, CHAR_DATA *ch, void *vo ) {
    OBJ_DATA *obj = (OBJ_DATA *) vo;
    AFFECT_DATA *paf; 
    int result, fail;
    int ac_bonus, added;
    bool ac_found = FALSE;

    if (obj->item_type != ITEM_ARMOR)   {
	send_to_char("That isn't an armor.\r\n",ch);
	return;
    }

    if (obj->wear_loc != -1)   {
	send_to_char("The item must be carried to be enchanted.\r\n",ch);
	return;
    }

   if (IS_SET(obj->extra_flags, ITEM_ARTIFACT)) {
      sprintf_to_char(ch, "%s is much too powerful!\r\n", capitalize(obj->short_descr));
      return;
   }

    /* this means they have no bonus */
    ac_bonus = 0;
    fail = 25;	/* base 25% chance of failure */

    /* find the bonuses */

    if (!obj->enchanted)
    	for ( paf = obj->pIndexData->affected; paf != NULL; paf = paf->next )
    	{
            if ( paf->location == APPLY_AC )
            {
	    	ac_bonus = paf->modifier;
		ac_found = TRUE;
	    	fail += 5 * (ac_bonus * ac_bonus);
 	    }

	    else  /* things get a little harder */
	    	fail += 20;
    	}
 
    for ( paf = obj->affected; paf != NULL; paf = paf->next )
    {
	if ( paf->location == APPLY_AC )
  	{
	    ac_bonus = paf->modifier;
	    ac_found = TRUE;
	    fail += 5 * (ac_bonus * ac_bonus);
	}

	else /* things get a little harder */
	    fail += 20;
    }

    /* apply other modifiers */
    fail -= level;

    if (IS_OBJ_STAT(obj,ITEM_BLESS))
	fail -= 15;
    if (IS_OBJ_STAT(obj,ITEM_GLOW))
	fail -= 5;

    fail = URANGE(5,fail,95);

    result = number_percent();

    /* the moment of truth */
    if (result < (fail / 5))  /* item destroyed */
    {
	act("$p flares blindingly... and evaporates!",ch,obj,NULL,TO_CHAR);
	act("$p flares blindingly... and evaporates!",ch,obj,NULL,TO_ROOM);
	extract_obj(obj);
	return;
    }

    if (result < (fail / 2)) /* item disenchanted */
    {
	AFFECT_DATA *paf_next;

	act("$p glows brightly, then fades...oops.",ch,obj,NULL,TO_CHAR);
	act("$p glows brightly, then fades.",ch,obj,NULL,TO_ROOM);
	obj->enchanted = TRUE;

	/* remove all affects */
	for (paf = obj->affected; paf != NULL; paf = paf_next)
	{
	    paf_next = paf->next; 
	    paf->next = affect_free;
	    affect_free = paf;
	}
	obj->affected = NULL;

	/* clear all flags */
	obj->extra_flags = 0;
	return;
    }

    if ( result <= fail )  /* failed, no bad result */
    {
	send_to_char("Nothing seemed to happen.\r\n",ch);
	return;
    }

    /* okay, move all the old flags into new vectors if we have to */
    if (!obj->enchanted)
    {
	AFFECT_DATA *af_new;
	obj->enchanted = TRUE;

	for (paf = obj->pIndexData->affected; paf != NULL; paf = paf->next) {
	
            af_new = new_affect();
	
	    af_new->next = obj->affected;
	    obj->affected = af_new;

	    af_new->type 	= UMAX(0,paf->type);
            af_new->afn		= paf->afn;       
	    af_new->level	= paf->level;
	    af_new->duration	= paf->duration;
	    af_new->location	= paf->location;
	    af_new->skill	= paf->skill;
	    af_new->modifier	= paf->modifier;
	    af_new->bitvector	= paf->bitvector;
	}
    }

    if (result <= (100 - level/5))  /* success! */
    {
	act("$p shimmers with a gold aura.",ch,obj,NULL,TO_CHAR);
	act("$p shimmers with a gold aura.",ch,obj,NULL,TO_ROOM);
	SET_BIT(obj->extra_flags, ITEM_MAGIC);
	added = -1;
    }
    
    else  /* exceptional enchant */
    {
	act("$p glows a brillant gold!",ch,obj,NULL,TO_CHAR);
	act("$p glows a brillant gold!",ch,obj,NULL,TO_ROOM);
	SET_BIT(obj->extra_flags,ITEM_MAGIC);
	SET_BIT(obj->extra_flags,ITEM_GLOW);
	added = -2;
    }
		
    /* now add the enchantments */ 

    if (obj->level < MAX_LEVEL)
	obj->level = UMIN(MAX_LEVEL - 1,obj->level + 1);

    if (ac_found)
    {
	for ( paf = obj->affected; paf != NULL; paf = paf->next)
	{
	    if ( paf->location == APPLY_AC)
	    {
		paf->type = sn;
		paf->afn = gafn_enchant_armor;
		paf->modifier += added;
		paf->level = UMAX(paf->level,level);
	    }
	}
    }
    else {/* add a new affect */

        paf = new_affect();    

	paf->type	= sn;
        paf->afn	= gafn_enchant_armor;
	paf->level	= level;
	paf->duration	= -1;
	paf->location	= APPLY_AC;
        paf->skill      = SKILL_UNDEFINED;
	paf->modifier	=  added;
	paf->bitvector  = 0;
    	paf->next	= obj->affected;
    	obj->affected	= paf;
    }

}

void spell_brand (int sn, int level, CHAR_DATA *ch, void *vo) {
	OBJ_DATA *obj = (OBJ_DATA *) vo; 
    int roll;
	int all_brand=WEAPON_LIGHTNING+WEAPON_ACID+WEAPON_FLAMING+WEAPON_FROST;
	
	if (obj->item_type != ITEM_WEAPON)
		{
		send_to_char ("That isn't a weapon.\r\n",ch);
		return;
		}
    if (obj->wear_loc != -1)
    	{
		send_to_char("The item must be carried to be enchanted.\r\n",ch);
		return;
    	}
	if ((obj->value[4]&all_brand)!=0) /*Already branded*/
		{
		send_to_char("This weapon is already branded.\r\n",ch);
		return;
		}
	roll = number_percent();
	if (roll <= 5) /*oops, destroy weapon*/ 
		{	
		extract_obj(obj);
		send_to_char ("{mKaboom!{x  The weapon explodes!  *sigh*\r\n",ch);
		act("$p shivers violently and explodes!",ch,obj,NULL,TO_ROOM);
		return;
		}
	if (roll > ((get_curr_stat(ch,STAT_INT)/4)-18)*2 + 5 + ((int)(level/3))) /*spell failed*/
		{
		send_to_char ("Spell failed.\r\n",ch);
		return;
		}
	else /*spell worked!*/
		{
		int which=number_percent();
		int brand=0;
		char buf[80];
	
		if (which <= 25)
			{
			brand=WEAPON_FLAMING;
			strcpy (buf, "You have created a {rFLAME{x brand!\r\n");
			}
		else if (which <= 50)
			{
			brand=WEAPON_FROST;
			strcpy (buf, "You have created a {bFROST{x brand!\r\n");
			}
		else if (which <= 75)
			{
			brand=WEAPON_ACID;
			strcpy (buf, "You have created an {gACID{x brand!\r\n");
			}
		else 
			{
			brand=WEAPON_LIGHTNING;
			strcpy (buf, "You have created a {yLIGHTNING{x brand!\r\n");
			}
		
		/*set new brand on weapon*/
		obj->value[4]+=brand;
		obj->valueorig[4]+=brand;
		send_to_char(buf,ch);
		}
}	/*end*/

extern void create_potion(CHAR_DATA *ch, int s1, int s2, int s3);

void spell_create_potion( int sn, int level, CHAR_DATA *ch, void *vo) {

  create_potion(ch, 0, 0, 0);
 
  act("You create a potion!",ch,NULL,NULL,TO_CHAR);
  act("$n creates a potion!",ch,NULL,NULL,TO_ROOM);

  return;
}


void spell_enchant_weapon( int sn, int level, CHAR_DATA *ch, void *vo ) {
OBJ_DATA *obj = (OBJ_DATA *) vo;
AFFECT_DATA *paf; 
int result, fail;
int hit_bonus, dam_bonus, added;
bool hit_found = FALSE, dam_found = FALSE;

    if (obj->item_type != ITEM_WEAPON)    {
	send_to_char("That isn't a weapon.\r\n",ch);
	return;
    }

    if (obj->wear_loc != -1)    {
	send_to_char("The item must be carried to be enchanted.\r\n",ch);
	return;
    }

   if (IS_SET(obj->extra_flags, ITEM_ARTIFACT)) {
      sprintf_to_char(ch, "%s is much too powerful!\r\n", capitalize(obj->short_descr));
      return;
   }

    /* this means they have no bonus */
    hit_bonus = 0;
    dam_bonus = 0;
    fail = 25;	/* base 25% chance of failure */

    /* find the bonuses */

    if (!obj->enchanted)
    	for ( paf = obj->pIndexData->affected; paf != NULL; paf = paf->next )   	{
            if ( paf->location == APPLY_HITROLL )            {
	    	hit_bonus = paf->modifier;
		hit_found = TRUE;
	    	fail += 2 * (hit_bonus * hit_bonus);

 	    }   else if (paf->location == APPLY_DAMROLL )    {
	    	dam_bonus = paf->modifier;
		dam_found = TRUE;
	    	fail += 2 * (dam_bonus * dam_bonus);
	    }    else  fail += 25;
    	}
 
    for ( paf = obj->affected; paf != NULL; paf = paf->next )    {
	if ( paf->location == APPLY_HITROLL )  	{
	    hit_bonus = paf->modifier;
	    hit_found = TRUE;
	    fail += 2 * (hit_bonus * hit_bonus);
	} else if (paf->location == APPLY_DAMROLL ) {
	    dam_bonus = paf->modifier;
	    dam_found = TRUE;
	    fail += 2 * (dam_bonus * dam_bonus);
	} else     fail += 25;
    }

    /* apply other modifiers */
    fail -= 3 * level/2;

    if (IS_OBJ_STAT(obj,ITEM_BLESS))
	fail -= 15;
    if (IS_OBJ_STAT(obj,ITEM_GLOW))
	fail -= 5;

    fail = URANGE(5,fail,95);

    result = number_percent();

    /* the moment of truth */
    if (result < (fail / 5))  /* item destroyed */
    {
	act("$p shivers violently and explodes!",ch,obj,NULL,TO_CHAR);
	act("$p shivers violently and explodes!",ch,obj,NULL,TO_ROOM);
	extract_obj(obj);
	return;
    }

    if (result < (fail / 2)) /* item disenchanted */
    {
	AFFECT_DATA *paf_next;

	act("$p glows brightly, then fades...oops.",ch,obj,NULL,TO_CHAR);
	act("$p glows brightly, then fades.",ch,obj,NULL,TO_ROOM);
	obj->enchanted = TRUE;

	/* remove all affects */
	for (paf = obj->affected; paf != NULL; paf = paf_next)
	{
	    paf_next = paf->next; 
	    paf->next = affect_free;
	    affect_free = paf;
	}
	obj->affected = NULL;

	/* clear all flags */
	obj->extra_flags = 0;
	return;
    }

    if ( result <= fail )  /* failed, no bad result */
    {
	send_to_char("Nothing seemed to happen.\r\n",ch);
	return;
    }

    /* okay, move all the old flags into new vectors if we have to */
    if (!obj->enchanted)
    {
	AFFECT_DATA *af_new;
	obj->enchanted = TRUE;

	for (paf = obj->pIndexData->affected; paf != NULL; paf = paf->next) { 
	
            af_new = new_affect();
	
	    af_new->next = obj->affected;
	    obj->affected = af_new;

	    af_new->type 	= UMAX(0,paf->type);
            af_new->afn		= paf->afn;
	    af_new->level	= paf->level;
	    af_new->duration	= paf->duration;
	    af_new->location	= paf->location;
	    af_new->skill	= paf->skill;
	    af_new->modifier	= paf->modifier;
	    af_new->bitvector	= paf->bitvector;
	}
    }

    if (result <= (100 - level/5))  /* success! */
    {
	act("$p glows blue.",ch,obj,NULL,TO_CHAR);
	act("$p glows blue.",ch,obj,NULL,TO_ROOM);
	SET_BIT(obj->extra_flags, ITEM_MAGIC);
	added = 1;
    }
    
    else  /* exceptional enchant */
    {
	act("$p glows a brillant blue!",ch,obj,NULL,TO_CHAR);
	act("$p glows a brillant blue!",ch,obj,NULL,TO_ROOM);
	SET_BIT(obj->extra_flags,ITEM_MAGIC);
	SET_BIT(obj->extra_flags,ITEM_GLOW);
	added = 2;
    }
		
    /* now add the enchantments */ 

    if (obj->level < MAX_LEVEL - 1)
	obj->level = UMIN(MAX_LEVEL - 1,obj->level + 1);

    if (dam_found)
    {
	for ( paf = obj->affected; paf != NULL; paf = paf->next)
	{
	    if ( paf->location == APPLY_DAMROLL)
	    {
		paf->type = sn;
                paf->afn = gafn_enchant_weapon;
		paf->modifier += added;
		paf->level = UMAX(paf->level,level);
		if (paf->modifier > 4)
		    SET_BIT(obj->extra_flags,ITEM_HUM);
	    }
	}
    }
    else { /* add a new affect */
    
        paf = new_affect();

	paf->type	= sn;
	paf->afn	= gafn_enchant_weapon;
	paf->level	= level;
	paf->duration	= -1;
	paf->location	= APPLY_DAMROLL;
        paf->skill      = SKILL_UNDEFINED;
	paf->modifier	=  added;
	paf->bitvector  = 0;
    	paf->next	= obj->affected;
    	obj->affected	= paf;
    }

    if (hit_found)
    {
        for ( paf = obj->affected; paf != NULL; paf = paf->next)
	{
            if ( paf->location == APPLY_HITROLL)
            {
		paf->type = sn;
		paf->afn = gafn_enchant_weapon;
                paf->modifier += added;
                paf->level = UMAX(paf->level,level);
                if (paf->modifier > 4)
                    SET_BIT(obj->extra_flags,ITEM_HUM);
            }
	}
    }
    else { /* add a new affect */
    
        paf = new_affect();
 
        paf->type       = sn;
	paf->afn	= gafn_enchant_weapon;
        paf->level      = level;
        paf->duration   = -1;
        paf->location   = APPLY_HITROLL;
        paf->skill      = SKILL_UNDEFINED;
        paf->modifier   =  added;
        paf->bitvector  = 0;
        paf->next       = obj->affected;
        obj->affected   = paf;
    }

}


/*
 * Drain XP, MANA, HP.
 * Caster gains HP.
 */
void spell_energy_drain( int sn, int level, CHAR_DATA *ch, void *vo ) {
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int dam;

    if ( saves_spell( level, victim ) )
    {
	send_to_char("You feel a momentary chill.\r\n",victim);  	
	return;
    }

    ch->alignment = UMAX(-1000, ch->alignment - 50);
    if ( victim->level <= 2 )    {
	dam		 = ch->hit + 1;
    }    else    {
	gain_exp( victim, 0 -  5 * number_range( level/2, 3 * level / 2 ), FALSE);
	victim->mana	/= 2;
	victim->move	/= 2;
	dam		 = dice(1, level);
	ch->hit		= UMIN (ch->max_hit, (ch->hit+dam));

    }

    send_to_char("You feel your life slipping away!\r\n",victim);
    send_to_char("Wow....what a rush!\r\n",ch);

   /* Set up combat data... */

    spell_CDB->atk_dam_type = DAM_NEGATIVE;
    spell_CDB->atk_blk_type = BLOCK_NONE;

   /* Set up and adjust damage... */

  

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

Site Stats

Snippets: 1791
Codebases: 571