/*
  MAGIC SPELLS from the Mage's Lair MUD.  (c) The Mage 1998 (c)
  Issue Version 1.00

  The file is released under the GNU license. Feel free to use it.  Give
  me credit if you want.

  The headers for each spell should be added to your codebase if you use
  these spells or the ideas from them.

  The Mage IMP of The Mage's Lair (lordmage.erols.com port 4000)

  NOTE: This assumes you can put the stuff in magic.h and const.c
  It also uses Lopes Colour code.


  A note on magic_dam().  This function is used to centralize all the
  damage done via the spells.  It uses the DICE command so you could
  switch out all your other spells to use this function and then you
  would have 1 central place for all the spells in your system to be
  balanced and wieghed against each other.
                                              The Mage.


*/

/*
 * Current Spells included:
 * Banshee Scream. 	v 1.0
 * Ionwave. 		v 1.0
 * Vaccine.		v 1.0
 * Sunbeam.		v 1.0
 */

struct spell_power_table_st spell_power_table[] =
{
  {"banshee scream",	7,	7},
  {"ionwave",		9,	10},
  {"sunbeam",		9,	11},
  {NULL,		0,	0}
};

/* ================================ */
/* Centralized routine for magical damage */
/* Author The Mage:
 */
int magic_dam(int sn)
{
  /* REVERSE THIS LOOP TO SAVE TIME */

  int dam =0,i;
  for (i=0; spell_power_table[i].name != NULL; i++) {
    if (!str_cmp(skill_table[sn].name, spell_power_table[i].name)) {
      dam = dice(spell_power_table[i].number,
		 spell_power_table[i].size);
      return(dam*2);
    }
  }
  
  bugf("Error..  magic_dam could not find spell to set damage too -%s-",
       skill_table[sn].name);
  return (0);
}    
/*
  SPELL: Ionwave
  DESC: Sends a wave of energy from the caster in all directions.
  EFFECT: Everyone NOT the caster.
  AUTHOR: The Mage.
*/
void spell_ionwave( int sn, int level, CHAR_DATA *ch, void *vo, int target )
{
  CHAR_DATA *pChar, *pChar_next;
  int dam;
  pChar_next = NULL;

  for ( pChar = ch->in_room->people; pChar; pChar = pChar_next )
    {
      pChar_next = pChar->next_in_room;
      if ( !is_safe( ch, pChar ) && (pChar != ch))
	{
	  act( "$n sends a huge wave of energy out! The energy burns you{x!", ch, NULL, pChar, TO_VICT    );
	  dam = magic_dam(sn);
	  if ( saves_spell( ch->level, pChar, DAM_ENERGY ) )	
	    dam /= 2;
	  damage( ch, pChar, dam, sn, DAM_ENERGY,TRUE);
	}
    }
  return;
}
/*
  SPELL: Vaccine
  DESC: Adds resistance to DISEASE.
  EFFECT: Target.
  AUTHOR: The Mage.
*/
void spell_vaccine( 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 ) || (IS_SET(ch->res_flags,RES_DISEASE)))
    {
      if (victim == ch)
	send_to_char("You are already vaccinated.\n\r",ch);
      else
	act("$N is already vaccinated.",ch,NULL,victim,TO_CHAR);
      return;
    }
  af.where     = TO_RESIST;
  af.type      = sn;
  af.level     = level;
  af.duration  = level;
  af.location  = APPLY_NONE;
  af.modifier  = 0;
  af.bitvector = RES_DISEASE;
  affect_to_char( victim, &af );
  send_to_char( "{BYou feel someone vaccinating you.\n\r{x", victim );
  if ( ch != victim )
    act("{B$N{x is vaccinated by your magic.",ch,NULL,victim,TO_CHAR);
  return;

}
/*
  SPELL: Banshee Scream
  DESC: Sends a blast of SOUND out in all directions from the caster.
  EFFECT: SOUND damage to everyone not the CASTER.
  AUTHOR: The Mage.
*/
void spell_banshee_scream( int sn, int level, CHAR_DATA *ch, void *vo, int target )
{
  CHAR_DATA *pChar, *pChar_next;
  int dam;
  pChar_next = NULL;

  /* This spell will when used.. wipe out your mana */
  for ( pChar = ch->in_room->people; pChar; pChar = pChar_next )
    {
      pChar_next = pChar->next_in_room;
      if ( !is_safe( ch, pChar ) && (pChar != ch))
	{
	  act( "$n screams a horrible sound! Your ears pop{x!", ch, NULL, pChar, TO_VICT    );
	  dam = magic_dam(sn);
	  if ( saves_spell( ch->level, pChar, DAM_SOUND ) )	
	    dam /= 2;
	  damage( ch, pChar, dam, sn, DAM_SOUND,TRUE);
	}
    }
  return;
}
/* ================================ */
/*
  SPELL: Sunbeam
  DESC: Sends a blast of HOT LIGHT in a specific direction from the
        SUN to a target..
  EFFECT: Specific target.  Does LIGHT damage.
  AUTHOR: The Mage.
*/
void spell_sunbeam( int sn, int level, CHAR_DATA *ch, void *vo, int target )
{
  CHAR_DATA *victim = (CHAR_DATA *) vo;
  int dam;

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

  if ( weather_info.sky > SKY_CLOUDLESS )
    {
      send_to_char( "You need good sunny weather.\n\r", ch );
      return;
    }

  dam = magic_dam(sn);
  if ( saves_spell( level, victim, DAM_LIGHT ) )
    dam /= 2;
  damage( ch, victim, dam, sn,DAM_LIGHT,TRUE);
  return;
}
