/
area/city/
area/crypts/
area/guilds/
area/psuedowild/
area/religion/
data/documents/MPDocs/
data/html/
data/mobprogs/
data/quest/
data/world/
data/world/_utilities/
data/world/images/
design/html/
notes/
player/
/***************************************************************************
 *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
 *  Michael Seifert, Hans Henrik Strfeldt, Tom Madsen, and Katja Nyboe.    *
 *                                                                         *
 *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
 *  Chastain, Michael Quan, and Mitchell Tse.                              *
 *                                                                         *
 *  In order to use any part of this Merc Diku Mud, you must comply with   *
 *  both the original Diku license in 'license.doc' as well the Merc       *
 *  license in 'license.txt'.  In particular, you may not remove either of *
 *  these copyright notices.                                               *
 *                                                                         *
 *  Much time and thought has gone into this software and you are          *
 *  benefitting.  We hope that you share your changes too.  What goes      *
 *  around, comes around.                                                  *
 ***************************************************************************/

/***************************************************************************
 *  ROM 2.4 is copyright 1993-1998 Russ Taylor                             *
 *  ROM has been brought to you by the ROM consortium                      *
 *      Russ Taylor (rtaylor@hypercube.org)                                *
 *      Gabrielle Taylor (gtaylor@hypercube.org)                           *
 *      Brian Moore (zump@rom.org)                                         *
 *  By using this code, you have agreed to follow the terms of the         *
 *  ROM license, in the file Rom24/doc/rom.license                         *
 ***************************************************************************/

#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "interp.h"
#include "magic.h"
#include "balance.h"


extern char *target_name;

void spell_farsight (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    if (IS_AFFECTED (ch, AFF_BLIND))
    {
        send_to_char ("Maybe it would help if you could see?\n", ch);
        return;
    }

    do_function (ch, &do_scan, target_name);
}


void spell_portal (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim;
    OBJ_DATA *portal, *stone;

    if ((victim = get_char_world (ch, target_name)) == NULL
        || victim == ch
        || victim->in_room == NULL
        || !can_see_room (ch, victim->in_room)
        || IS_SET (victim->in_room->room_flags, ROOM_SAFE)
        || IS_SET (victim->in_room->room_flags, ROOM_PRIVATE)
        || IS_SET (victim->in_room->room_flags, ROOM_SOLITARY)
        || IS_SET (victim->in_room->room_flags, ROOM_NO_RECALL)
        || IS_SET (ch->in_room->room_flags, ROOM_NO_RECALL)
        || victim->level >= level + 3 || (!IS_NPC (victim) && victim->level >= LEVEL_HERO)    /* NOT trust */
        || (IS_NPC (victim) && IS_SET (victim->imm_flags, IMM_SUMMON))
        || (IS_NPC (victim) && saves_spell (level, victim, DAM_NONE))
        || (is_clan (victim) && !is_same_clan (ch, victim)))
    {
        send_to_char ("You failed.\n", ch);
        return;
    }

    stone = get_eq_char (ch, WEAR_HOLD);
    if (!IS_IMMORTAL (ch)
        && (stone == NULL || stone->item_type != ITEM_WARP_STONE))
    {
        send_to_char ("You lack the proper component for this spell.\n",
                      ch);
        return;
    }

    if (stone != NULL && stone->item_type == ITEM_WARP_STONE)
    {
        act ("You draw upon the power of $p.", ch, stone, NULL, TO_CHAR);
        act ("It flares brightly and vanishes!", ch, stone, NULL, TO_CHAR);
        extract_obj (stone);
    }

    portal = create_object (get_obj_index (OBJ_VNUM_PORTAL), 0);
    portal->timer = 2 + level / 25;
    portal->value[3] = victim->in_room->vnum;

    obj_to_room (portal, ch->in_room);

    act ("$p rises up from the ground.", ch, portal, NULL, TO_ROOM);
    act ("$p rises up before you.", ch, portal, NULL, TO_CHAR);
}

void spell_nexus (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim;
    OBJ_DATA *portal, *stone;
    ROOM_INDEX_DATA *to_room, *from_room;

    from_room = ch->in_room;

    if ((victim = get_char_world (ch, target_name)) == NULL
        || victim == ch
        || (to_room = victim->in_room) == NULL
        || !can_see_room (ch, to_room) || !can_see_room (ch, from_room)
        || IS_SET (to_room->room_flags, ROOM_SAFE)
        || IS_SET (from_room->room_flags, ROOM_SAFE)
        || IS_SET (to_room->room_flags, ROOM_PRIVATE)
        || IS_SET (to_room->room_flags, ROOM_SOLITARY)
        || IS_SET (to_room->room_flags, ROOM_NO_RECALL)
        || IS_SET (from_room->room_flags, ROOM_NO_RECALL)
        || victim->level >= level + 3 || (!IS_NPC (victim) && victim->level >= LEVEL_HERO)    /* NOT trust */
        || (IS_NPC (victim) && IS_SET (victim->imm_flags, IMM_SUMMON))
        || (IS_NPC (victim) && saves_spell (level, victim, DAM_NONE))
        || (is_clan (victim) && !is_same_clan (ch, victim)))
    {
        send_to_char ("You failed.\n", ch);
        return;
    }

    stone = get_eq_char (ch, WEAR_HOLD);
    if (!IS_IMMORTAL (ch)
        && (stone == NULL || stone->item_type != ITEM_WARP_STONE))
    {
        send_to_char ("You lack the proper component for this spell.\n",
                      ch);
        return;
    }

    if (stone != NULL && stone->item_type == ITEM_WARP_STONE)
    {
        act ("You draw upon the power of $p.", ch, stone, NULL, TO_CHAR);
        act ("It flares brightly and vanishes!", ch, stone, NULL, TO_CHAR);
        extract_obj (stone);
    }

    /* portal one */
    portal = create_object (get_obj_index (OBJ_VNUM_PORTAL), 0);
    portal->timer = 1 + level / 10;
    portal->value[3] = to_room->vnum;

    obj_to_room (portal, from_room);

    act ("$p rises up from the ground.", ch, portal, NULL, TO_ROOM);
    act ("$p rises up before you.", ch, portal, NULL, TO_CHAR);

    /* no second portal if rooms are the same */
    if (to_room == from_room)
        return;

    /* portal two */
    portal = create_object (get_obj_index (OBJ_VNUM_PORTAL), 0);
    portal->timer = 1 + level / 10;
    portal->value[3] = from_room->vnum;

    obj_to_room (portal, to_room);

    if (to_room->people != NULL)
    {
        act ("$p rises up from the ground.", to_room->people, portal, NULL,
             TO_ROOM);
        act ("$p rises up from the ground.", to_room->people, portal, NULL,
             TO_CHAR);
    }
}

/*
 * spell_restoration()
 *
 * White magic spell. High level heal spell.
 */
void spell_restoration (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int heal;

    heal            = dice (50, 50) + level / 2;
    victim->hit     = UMIN (victim->hit + heal, victim->max_hit);
    victim->move    = UMIN (victim->move + heal, victim->max_move);
    update_pos (victim);
    send_to_char ("You feel fully restored!\n", victim);
    if (ch != victim)
        send_to_char ("Ok.\n", ch);
    return;
}

/*
 * spell_sacred_flame()
 *
 * Mid-level white magic offensive spell.
 * FIXME: Count + Damage mods
 */
void spell_sacred_flame (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int i = level / 20;
    int dam;

    act ("$n calls down a scared flame!.", ch, NULL, victim, TO_NOTVICT);
    act ("$n calls down a scared flame on you!", ch, NULL, victim,TO_VICT);
    act ("You call down a scared flame on $N", ch, NULL, victim, TO_CHAR);
    
    while (i != 0)
    {

        dam = fix_spell_damage(level, i);
        if (!IS_NPC(ch))
            dam = dam * ch->pcdata->learned[skill_lookup("sacred flame")] / 100;
        
        damage (ch, (CHAR_DATA *) vo, dam, sn, DAM_FIRE, TRUE, TRUE);
        i--;
    }
    return;
}

/*
 * spell_scared_cloak()
 *
 * Mid-level white magic defensive spell.
 * TODO: effect + duration
 */
void spell_scared_cloak (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;

    if (is_affected (victim, sn))
    {
        if (victim == ch)
            send_to_char ("You are already protected by the scared cloak.\n", ch);
        else
            act ("$N is already protected by the scared cloak..", ch, NULL, victim, TO_CHAR);
        return;
    }
    
    int mod = dice(5, 4);
    
    mod += ((get_skill (ch, gsn_alteration)) + (get_skill (ch, gsn_white_magic)) / 2);
    
    af.where            = TO_AFFECTS;
    af.type             = sn;
    af.level            = level;
    af.duration         = 30;
    af.modifier         = mod;
    af.location         = APPLY_AC;
    af.bitvector        = 0;
    affect_to_char (victim, &af);
    send_to_char ("You feel the warmth of the sacred cloak.\n", victim);
    if (ch != victim)
        act ("$N is protected by your scared cloak.", ch, NULL, victim, TO_CHAR);
    return;
}




/*
 * spell_speak_with_animal()
 *
 * Simple animal handling spell,
 * allows for animal handlers to 'talk' with
 * their animal for a while. Speech is limited.
 */
void spell_speak_with_animal (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;

    if (victim != ch)
    {
        stc("You cannot cast this spell on another.\n", ch);
        return;
    }
    
    if (is_affected (victim, sn))
    {
        send_to_char ("You can already speak with animals!\n", ch);
        return;
    }
    
    af.where            = TO_AFFECTS;
    af.type             = sn;
    af.level            = level;
    af.duration         = 10;
    af.modifier         = 1;
    af.location         = 0;
    af.bitvector        = 0;
    affect_to_char (victim, &af);
    send_to_char ("You feel the power to speak with animals.\n", ch);
    return;
}

/*
 * spell_calm_animal()
 *
 * Calms an animal down, removes it's aggressiveness
 * TODO: Only animals
 */
void spell_calm_animal (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;

    if (is_affected (victim, sn))
    {
        if (victim == ch)
            send_to_char ("You are already calmed.\n", ch);
        else
            act ("$N is already calmed.", ch, NULL, victim, TO_CHAR);
        return;
    }

    af.where        = TO_AFFECTS;
    af.type         = sn;
    af.level        = level;
    af.duration     = level / 6;
    af.location     = APPLY_NONE;
    af.modifier     = 0;
    af.bitvector    = 0;
    affect_to_char (victim, &af);
    act ("$n's rage ebbs.", victim, NULL, NULL, TO_ROOM);
    send_to_char ("You become calm.\n", victim);
    return;
}

/*
 * spell_toxic_cloud()
 *
 * area effect spell, decent damage
 */
void spell_toxic_cloud (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *vch;
    CHAR_DATA *vch_next;
    int dam;
    
    int i = 1;

    for (vch = ch->in_room->people; vch != NULL; vch = vch_next)
    {
        vch_next = vch->next_in_room;
        if (vch == ch)
            {}
        else
        {
            if (vch == ch)
                {}
            else if (is_same_group (ch, vch))
                {}
            else
            {
                dam = fix_spell_damage(level, i);
                if (!IS_NPC(ch))
                    dam = dam * ch->pcdata->learned[skill_lookup("toxic cloud")] / 100;
                damage (ch, vch, dam, sn, DAM_POISON, TRUE, TRUE);
            }
        } 

    }

    return;
}


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

    if (is_affected (victim, sn))
    {
        send_to_char ("You are already have the ritual of death.\n", ch);
        return;
    }

    af.where        = TO_AFFECTS;
    af.type         = sn;
    af.level        = level;
    af.duration     = level / 6;
    af.location     = APPLY_NONE;
    af.modifier     = 0;
    af.bitvector    = 0;
    affect_to_char (victim, &af);
    act ("$n is surrounded with a black aura.", victim, NULL, NULL, TO_ROOM);
    send_to_char ("You do the dance of death...\n", victim);
    return;
}

/*
 * spell_supression()
 *
 * Offensive spellcaster enchantment,
 * cuts spell damage to victim by 1/2
 */
void spell_supression (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;

    if (is_affected (victim, sn))
    {
        if (victim == ch)
            send_to_char ("You are already supressed.\n", ch);
        else
            act ("$N has already had their casting abilitys supressed.", ch, NULL, victim, TO_CHAR);
        return;
    }

    af.where        = TO_AFFECTS;
    af.type         = sn;
    af.level        = level;
    af.duration     = level / 6;
    af.location     = APPLY_NONE;
    af.modifier     = 0;
    af.bitvector    = 0;
    affect_to_char (victim, &af);
    act ("$n has had their spell casting abilities suppressed!", victim, NULL, NULL, TO_ROOM);
    send_to_char ("Your mind feels weak.\n", victim);
    return;
}

/*
 * spell_erode()
 *
 * Offensive spell, makes effected player's enchantments
 * wear off 10x faster.
 */
void spell_erode (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;

    if (is_affected (victim, sn))
    {
        if (victim == ch)
            send_to_char ("You are already eroding.\n", ch);
        else
            act ("$N's is already eroding.", ch, NULL, victim, TO_CHAR);
        return;
    }

    af.where        = TO_AFFECTS;
    af.type         = sn;
    af.level        = level;
    af.duration     = level;
    af.location     = APPLY_NONE;
    af.modifier     = 0;
    af.bitvector    = 0;
    affect_to_char (victim, &af);
    act ("$n's body begins to erode!", victim, NULL, NULL, TO_ROOM);
    send_to_char ("Your body begins to erode.\n", victim);
    return;
}

/*
 * spell_hand_of_death()
 *
 * Mid/Low level damage spell for White magic.
 */
void spell_hand_of_death (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    int i = 3;
    int dam;

    while (i != 0)
    {
        dam = fix_spell_damage(level, i);
        if (!IS_NPC(ch))
            dam = dam * ch->pcdata->learned[skill_lookup("hand of death")] / 100;
        damage (ch, (CHAR_DATA *) vo, dam, sn, DAM_OTHER, TRUE, TRUE);
        i--;
    }
    return;
}

/*
 * spell_death_touch()
 *
 * Mid/Low level damage spell for White magic.
 * Does multiple damage types.
 * FIXME: Count + Damage mods
 */
void spell_death_touch (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    int i = 1 + (ch->level / 100);
    int dam;

    while (i != 0)
        {
        dam = fix_spell_damage(level, i);
        if (!IS_NPC(ch))
            dam = dam * ch->pcdata->learned[skill_lookup("death touch")] / 100;
        
        damage (ch, (CHAR_DATA *) vo, dam, sn, DAM_OTHER, TRUE, TRUE);
        i--;
    }
    return;
}

void spell_anti_magic_shell (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af2;

    sn = skill_lookup ("anti-magic shell");

    if (is_affected (ch, sn))
    {
        send_to_char ("You are already in an anti-magic shell.\n",ch);
        return;
    }


    af2.where = TO_RESIST;    // Immunity to...
    af2.type = sn;
    af2.duration = level / 2;    // Duration? (how many ticks)
    af2.level = ch->level;    // Level of the spell? (for dispel/cancel)
    af2.bitvector = RES_MAGIC;    // <Immunity here>
    af2.location = 0;        // Theres no APPLY, so this is 0.
    af2.modifier = 0;        // Since theres no APPLY, it doesnt need to add a number to it
    affect_to_char (ch, &af2);    // Now apply all the af2.* items to the charater.

    send_to_char ("You surround yourself in an anti-magic shell.\n", victim);
    act ("$n surrounds themself in an anti-magic shell.", victim, NULL, NULL, TO_ROOM);
  return;
}

void spell_fear( int sn, int level, CHAR_DATA *ch, void *vo, int target )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    ROOM_INDEX_DATA *in_room;
    EXIT_DATA *pexit;
    int door;

    if (       (victim == ch)
    || (!victim->in_room)
    || ( IS_SET( victim->in_room->room_flags, ROOM_SAFE      ) )
    || ( IS_SET( victim->in_room->room_flags, ROOM_PRIVATE   ) )
    || ( IS_SET( victim->in_room->room_flags, ROOM_SOLITARY  ) )
    || ( IS_SET( victim->in_room->room_flags, ROOM_NO_RECALL ) )
    || ( !IS_AWAKE( victim ) )
    || ( victim->level >= level)
    || ( victim->in_room->area != ch->in_room->area )
    || (( IS_NPC( victim ) && saves_spell( level, victim, DAM_CHARM))))
    {
    send_to_char( "You failed to inspire fear.\n", ch );
    return;
    }

    check_killer (ch, victim);
    act ("$n scares the hell out of $N!", ch, NULL, victim,
         TO_NOTVICT);
    act ("$n scares the hell out of you!", ch, NULL, victim,
         TO_VICT);
    act ("You scare the hell out of $N!", ch, NULL, victim, TO_CHAR);

    if ((victim->fighting) == NULL)
     {
       //this bit is "borrowed" from stock update.c, can be changed
       //to make fear more successful by always finding a
       //random exit.
       in_room = victim->in_room;
       for (door = 0; door < 6; door++)
                {
         if ( (number_bits (3) == 0)
             && ((door = number_bits (5)) <= 5)
                 && ((pexit = ch->in_room->exit[door]) != NULL)
                 && (pexit->u1.to_room != NULL)
                 && (!IS_SET (pexit->exit_info, EX_CLOSED))
                 && (!IS_SET (pexit->u1.to_room->room_flags, ROOM_NO_MOB))
                 && (!IS_SET (ch->act, ACT_STAY_AREA) || (pexit->u1.to_room->area == ch->in_room->area))
                 && (!IS_SET (ch->act, ACT_OUTDOORS) || !IS_SET (pexit->u1.to_room->room_flags, ROOM_INDOORS))
                 && (!IS_SET (ch->act, ACT_INDOORS)  || IS_SET (pexit->u1.to_room->room_flags, ROOM_INDOORS)))

                {
                 if (victim->position < POS_STANDING) do_stand(victim, NULL);
                 act ("$N runs for $S life!", ch, NULL, victim, TO_NOTVICT);
                 act ("You run in terror from $n!", ch, NULL, victim, TO_VICT);
                   act ("$N flees from the sight of your indominable menace!", ch, NULL, victim, TO_CHAR);
                move_char (victim, door, FALSE);
                return;
                }
        }

            act ("But $N is too panicked to escape!", ch, NULL, victim, TO_NOTVICT);
            act ("But you are too panicked to escape!", ch, NULL, victim, TO_VICT);
            act ("But $N is too terrified to escape your wrath!", ch, NULL, victim, TO_CHAR);
            return;

       }
    else do_flee( victim, "" );
    return;
}

void spell_wizard_eye (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
  ROOM_INDEX_DATA *original;
  CHAR_DATA *wch;
  CHAR_DATA *victim;

  if (!(victim = get_char_world (ch, target_name))
      || victim == ch || !victim->in_room)

    {
      send_to_char ("You have failed.\n", ch);
      return;
    }


  original = ch->in_room;
  char_from_room (ch);
  char_to_room (ch, victim->in_room);

  do_look (ch, "auto");

  /*
   * See if 'ch' still exists before continuing!
   * Handles 'c 'wizard eye' XXXX quit' case.
   */
  for (wch = char_list; wch; wch = wch->next)
    {
      if (wch == ch)
    {
      char_from_room (ch);
      char_to_room (ch, original);
      break;
    }
    }

  return;
}

void spell_knock ( int sn, int level, CHAR_DATA *ch, void *vo , int target)
{
    char arg[MAX_INPUT_LENGTH];
    int chance=0;
    int door;
    const       sh_int  rev_dir         []              =
        {
            2, 3, 0, 1, 5, 4, 9, 8, 7, 6
        };

    target_name = one_argument(target_name,arg);

    if (arg[0] == '\0')
    {
    send_to_char("Knock which door or direction.\n",ch);
    return;
    }

    if (ch->fighting)
    {
        send_to_char("Wait until the fight finishes.\n",ch);
        return;
    }

    if ( ( door = find_door( ch, arg ) ) >= 0 )
    {
        ROOM_INDEX_DATA *to_room;
        EXIT_DATA *pexit;
        EXIT_DATA *pexit_rev;

        pexit = ch->in_room->exit[door];
        if ( !IS_SET(pexit->exit_info, EX_CLOSED) )
            { send_to_char( "It's already open.\n",      ch ); return; }
        if ( !IS_SET(pexit->exit_info, EX_LOCKED) )
            { send_to_char( "Just try to open it.\n",     ch ); return; }
        if ( IS_SET(pexit->exit_info, EX_NOPASS) )
            { send_to_char( "A mystical shield protects the exit.\n",ch ); return; };
        if ( IS_SET(pexit->exit_info, EX_MAGICAL) )
            { send_to_char( "A mystical shield protects the exit from being      magically opened.\n",ch);return; }
    chance = ch->level / 5 + get_curr_stat(ch,STAT_INT) + get_skill(ch,sn) / 5;

    act("You cast knock on the $d, and try to open the $d!",
             ch,NULL,pexit->keyword,TO_CHAR);

    if (room_is_dark(ch->in_room))
                chance /= 2;

    /* now the attack */
    if (number_percent() < chance )
     {
        REMOVE_BIT(pexit->exit_info, EX_LOCKED);
        REMOVE_BIT(pexit->exit_info, EX_CLOSED);
        act( "$n knocks on the $d and opens the lock.", ch, NULL,
                pexit->keyword, TO_ROOM );
        send_to_char( "You successfully open the door.\n", ch );

        /* open the other side */
        if ( ( to_room   = pexit->u1.to_room            ) != NULL
        &&   ( pexit_rev = to_room->exit[rev_dir[door]] ) != NULL
        &&   pexit_rev->u1.to_room == ch->in_room )
        {
            CHAR_DATA *rch;
               REMOVE_BIT( pexit_rev->exit_info, EX_CLOSED );
            REMOVE_BIT( pexit_rev->exit_info, EX_LOCKED );
            for ( rch = to_room->people; rch != NULL; rch = rch->next_in_room )
                act( "The $d opens.", rch, NULL, pexit_rev->keyword, TO_CHAR );
        }
     }
    else
     {
        act("You couldn't magically open the $d!",
            ch,NULL,pexit->keyword,TO_CHAR);
        act("$n failed to magically open the $d.",
            ch,NULL,pexit->keyword,TO_ROOM);
     }
    return;
    }

  send_to_char("You can't see that here.\n",ch);
  return;
}

void spell_power_word_stun (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
  CHAR_DATA *victim = (CHAR_DATA *) vo;
  char buf[MSL];

  stc ("You utter the words, 'Power Word STUN'.\n", ch);
  sprintf(buf, "%s falls to the ground.\n", victim->short_descr);
  stc(buf, ch);
  act ("$n utters the words, 'Power Word STUN'.", ch, NULL, NULL, TO_ROOM);
  act (buf, ch, NULL, NULL, TO_ROOM);


  stop_fighting (ch, TRUE);
  stop_fighting (victim, TRUE);
  stop_fighting (ch, TRUE);
  stop_fighting (victim, TRUE);
  do_function (victim, &do_sleep, "");

  return;
}


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

    if (IS_AFFECTED (victim, AFF_BLIND) || saves_spell (level * 2, victim, DAM_OTHER))
        return;

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


void spell_counterspell (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    char buf[MSL];

    sprintf (buf, "You attempt to counter %s's Spell.\n", victim->short_descr);
    send_to_char(buf, ch);
    act ("$n attempts to counter $N's spell.", ch, NULL, victim, TO_ROOM);

    if (number_range(1, 100) > 50)
    {
        stop_spell( victim );
    }
    else
        stc("You are unable to counter the spell.\n", ch);

    return;
}

void spell_power_word_kill (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    char buf[MSL];

    stc ("You utter the words, 'Power Word KILL'.\n", ch);;
    act ("$n utters the words, 'Power Word KILL'.", ch, NULL, NULL, TO_ROOM);

    if (saves_spell (level / 2, victim, DAM_OTHER))
    {
        send_to_char("Your spell fails. (Saved vs spells)\n", ch);
        return;
    }

    if (victim->max_hit > 500)
    {
        send_to_char("Your spell fails.\n", ch);
        return;
    }

    if (victim->level > ch->level)
    {
    send_to_char("Your spell fails.\n", ch);
    return;
    }

    sprintf(buf, "%s falls to the ground dead.\n", victim->short_descr);
    stc(buf, ch);
    sprintf(buf, "$N falls to the ground dead.\n");
    act (buf, ch, NULL, NULL, TO_ROOM);
    raw_kill (victim);

  return;
}


void spell_meteor_swarm (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
  int dam;
  CHAR_DATA *victim = (CHAR_DATA *) vo;
  CHAR_DATA *vch;
  CHAR_DATA *vch_next;
  int i = level / 5;

  act ("$n summons down a meteor swarm centered on $N!", ch, NULL, victim, TO_ROOM);
  act ("$n has summoned a meteor swarm on you!!", ch, NULL, victim,
       TO_VICT);
  send_to_char ("You summon forth a meteor swarm!\n", ch);

    for (vch = ch->in_room->people; vch != NULL; vch = vch_next)
    {
        dam = dice(10, 4);
        
        vch_next = vch->next_in_room;
        if (vch == ch)
            {}
        else
            damage (ch, vch, dam, sn, DAM_FIRE, TRUE, TRUE);
    }

    while (i > 0)
    {
      for (vch = ch->in_room->people; vch != NULL; vch = vch_next)
    {
      dam = dice(10, 4);
      vch_next = vch->next_in_room;
        if (vch == ch)
        {}
      else
      damage (ch, vch, dam, sn, DAM_FIRE, TRUE, TRUE);
    }
    i--;
    }

  return;
}

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

    if (is_affected (victim, sn))
    {
        if (victim == ch)
            send_to_char ("You are force spiked.\n", ch);
        else
            act ("$N's magical energies are already spiked.", ch, NULL, victim, TO_CHAR);
        return;
    }

    af.where        = TO_AFFECTS;
    af.type         = sn;
    af.level        = level;
    af.duration     = level;
    af.location     = APPLY_NONE;
    af.modifier     = 0;
    af.bitvector    = 0;
    affect_to_char (victim, &af);
    act ("$n's magical energies begins to spike!", victim, NULL, NULL, TO_ROOM);
    send_to_char ("Your magical energies begin to spike!\n", victim);
    return;
}


void spell_juxtapose (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int a, b;
    
    if (ch->fighting == NULL)
    {
        stc("You are not fighting anyone!\n", ch);
        return;
    }
    
    send_to_char ("You attempt to juxtapose...\n\r", victim);
    act ("$N attempts to juxtapose with $n...", victim, NULL, NULL, TO_ROOM);
    
    if (number_range(1, 100) > 25)
        return;
    
    a = victim->hit;
    b = ch->hit;
    
    victim->hit = b;
    ch->hit = a;
    
    send_to_char ("You have sucessfuly juxtaposed!\n\r", victim);
    act ("$N sucessfuly juxtaposed with $n!!", victim, NULL, NULL, TO_ROOM);
    
}


/*
 * spell_mana_shield()
 *
 * while affected, damage to the player is partialy absorbed by their mana
 */
void spell_mana_shield (int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    AFFECT_DATA af;

    if (is_affected (victim, sn))
    {
        if (victim == ch)
            send_to_char ("You already shield yourself behind your mana.\n", ch);
        else
            act ("$N already shields themselfs behind their mana.", ch, NULL, victim, TO_CHAR);
        return;
    }

    af.where        = TO_AFFECTS;
    af.type         = sn;
    af.level        = level;
    af.duration     = 50;
    af.location     = APPLY_FOCUS;
    af.modifier     = level * 20;
    af.bitvector    = 0;
    affect_to_char (victim, &af);
    act ("$n's shields themself behind their mana!", victim, NULL, NULL, TO_ROOM);
    send_to_char ("Your shield yourself behind your mana!\n", victim);
    return;
}