eldhamud_2.3.3/clans/
eldhamud_2.3.3/councils/
eldhamud_2.3.3/doc/
eldhamud_2.3.3/doc/DIKU/
eldhamud_2.3.3/doc/DIKU/.svn/
eldhamud_2.3.3/doc/DIKU/.svn/prop-base/
eldhamud_2.3.3/doc/DIKU/.svn/text-base/
eldhamud_2.3.3/doc/MERC/
eldhamud_2.3.3/doc/MERC/.svn/
eldhamud_2.3.3/doc/SMAUG/.svn/
eldhamud_2.3.3/doc/SMAUG/mudprogs/
eldhamud_2.3.3/doc/SMAUG/mudprogs/.svn/
eldhamud_2.3.3/doc/mudprogs/
eldhamud_2.3.3/gods/
eldhamud_2.3.3/houses/
eldhamud_2.3.3/player/a/
/****************************************************************************
 *			Eldhamud Codebase V2.2				    *
 * ------------------------------------------------------------------------ *
 *          EldhaMUD code (C) 2003-2008 by Robert Powell (Tommi)            *
 * ------------------------------------------------------------------------ *
 * Original SMAUG 1.4a written by Thoric (Derek Snider) with Altrag,        *
 * Blodkai, Haus, Narn, Scryn, Swordbearer, Tricops, Gorog, Rennard,        *
 * Grishnakh, Fireblade, and Nivek.                                         *
 *                                                                          *
 * Original MERC 2.1 code by Hatchet, Furey, and Kahn.                      *
 *                                                                          *
 * Original DikuMUD code by: Hans Staerfeldt, Katja Nyboe, Tom Madsen,      *
 * Michael Seifert, and Sebastian Hammer.                                   *
 * ------------------------------------------------------------------------ *
 *			   "Special procedure" module			    *
 ****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "./Headers/mud.h"
/*
 * The following special functions are available for mobiles.
 */
DECLARE_SPEC_FUN( spec_cast_adept );
DECLARE_SPEC_FUN( spec_cast_cleric );
DECLARE_SPEC_FUN( spec_cast_mage );
DECLARE_SPEC_FUN( spec_cast_undead );
DECLARE_SPEC_FUN( spec_executioner );
DECLARE_SPEC_FUN( spec_fido );
DECLARE_SPEC_FUN( spec_guard );
DECLARE_SPEC_FUN( spec_janitor );
DECLARE_SPEC_FUN( spec_poison );
DECLARE_SPEC_FUN( spec_thief );
/*
 * Given a name, return the appropriate spec fun.
 */
SPEC_FUN *spec_lookup( const char *name )
{
   if( !str_cmp( name, "spec_cast_adept" ) )
      return spec_cast_adept;
   if( !str_cmp( name, "spec_cast_cleric" ) )
      return spec_cast_cleric;
   if( !str_cmp( name, "spec_cast_mage" ) )
      return spec_cast_mage;
   if( !str_cmp( name, "spec_cast_undead" ) )
      return spec_cast_undead;
   if( !str_cmp( name, "spec_executioner" ) )
      return spec_executioner;
   if( !str_cmp( name, "spec_fido" ) )
      return spec_fido;
   if( !str_cmp( name, "spec_guard" ) )
      return spec_guard;
   if( !str_cmp( name, "spec_janitor" ) )
      return spec_janitor;
   if( !str_cmp( name, "spec_poison" ) )
      return spec_poison;
   if( !str_cmp( name, "spec_thief" ) )
      return spec_thief;
   return 0;
}

/*
 * Given a pointer, return the appropriate spec fun text.
 */
char *lookup_spec( SPEC_FUN * special )
{
   if( special == spec_cast_adept )
      return "spec_cast_adept";
   if( special == spec_cast_cleric )
      return "spec_cast_cleric";
   if( special == spec_cast_mage )
      return "spec_cast_mage";
   if( special == spec_cast_undead )
      return "spec_cast_undead";
   if( special == spec_executioner )
      return "spec_executioner";
   if( special == spec_fido )
      return "spec_fido";
   if( special == spec_guard )
      return "spec_guard";
   if( special == spec_janitor )
      return "spec_janitor";
   if( special == spec_poison )
      return "spec_poison";
   if( special == spec_thief )
      return "spec_thief";
   return "";
}

/* if a spell casting mob is hating someone... try and summon them */
void summon_if_hating( CHAR_DATA * ch )
{
   CHAR_DATA *victim;
   char buf[MAX_STRING_LENGTH];
   char name[MAX_INPUT_LENGTH];
   bool found = FALSE;
   if( ch->position <= POS_SLEEPING )
      return;
   if( ch->fighting || ch->fearing || !ch->hating || xIS_SET( ch->in_room->room_flags, ROOM_SAFE ) )
      return;
   /*
    * if player is close enough to hunt... don't summon 
    */
   if( ch->hunting )
      return;
   one_argument( ch->hating->name, name );
   /*
    * make sure the char exists - works even if player quits 
    */
   for( victim = first_char; victim; victim = victim->next )
   {
      if( !str_cmp( ch->hating->name, victim->name ) )
      {
         found = TRUE;
         break;
      }
   }
   if( !found )
      return;
   if( ch->in_room == victim->in_room )
      return;
   if( !IS_NPC( victim ) )
      sprintf( buf, "summon 0.%s", name );
   else
      sprintf( buf, "summon %s", name );
   do_cast( ch, buf );
   return;
}

bool spec_cast_adept( CHAR_DATA * ch )
{
   CHAR_DATA *victim;
   CHAR_DATA *v_next;
   if( !IS_AWAKE( ch ) || ch->fighting )
      return FALSE;
   for( victim = ch->in_room->first_person; victim; victim = v_next )
   {
      v_next = victim->next_in_room;
      if( victim != ch && can_see( ch, victim, FALSE ) && number_bits( 1 ) == 0 )
         break;
   }
   if( !victim )
      return FALSE;
   switch ( number_bits( 3 ) )
   {
      case 0:
         act( AT_MAGIC, "$n utters the word 'ciroht'.", ch, NULL, NULL, TO_ROOM );
         spell_smaug( skill_lookup( "armor" ), ch->level, ch, victim );
         return TRUE;
      case 1:
         act( AT_MAGIC, "$n utters the word 'sunimod'.", ch, NULL, NULL, TO_ROOM );
         spell_smaug( skill_lookup( "bless" ), ch->level, ch, victim );
         return TRUE;
      case 2:
         act( AT_MAGIC, "$n utters the word 'suah'.", ch, NULL, NULL, TO_ROOM );
         spell_cure_blindness( skill_lookup( "cure blindness" ), ch->level, ch, victim );
         return TRUE;
      case 3:
         act( AT_MAGIC, "$n utters the word 'nran'.", ch, NULL, NULL, TO_ROOM );
         spell_smaug( skill_lookup( "cure light" ), ch->level, ch, victim );
         return TRUE;
      case 4:
         act( AT_MAGIC, "$n utters the word 'nyrcs'.", ch, NULL, NULL, TO_ROOM );
         spell_cure_poison( skill_lookup( "cure poison" ), ch->level, ch, victim );
         return TRUE;
      case 5:
         act( AT_MAGIC, "$n utters the word 'gartla'.", ch, NULL, NULL, TO_ROOM );
         spell_smaug( skill_lookup( "refresh" ), ch->level, ch, victim );
         return TRUE;
      case 6:
         act( AT_MAGIC, "$n utters the word 'naimad'.", ch, NULL, NULL, TO_ROOM );
         spell_smaug( skill_lookup( "cure serious" ), ch->level, ch, victim );
         return TRUE;
      case 7:
         act( AT_MAGIC, "$n utters the word 'gorog'.", ch, NULL, NULL, TO_ROOM );
         spell_remove_curse( skill_lookup( "remove curse" ), ch->level, ch, victim );
         return TRUE;
   }
   return FALSE;
}

bool spec_cast_cleric( CHAR_DATA * ch )
{
   return FALSE;
}

bool spec_cast_mage( CHAR_DATA * ch )
{
   return FALSE;
}

bool spec_cast_undead( CHAR_DATA * ch )
{
   return FALSE;
}

bool spec_executioner( CHAR_DATA * ch )
{
   char buf[MAX_STRING_LENGTH];
   MOB_INDEX_DATA *cityguard;
   CHAR_DATA *victim;
   CHAR_DATA *v_next;
   char *crime;
   if( !IS_AWAKE( ch ) || ch->fighting )
      return FALSE;
   crime = "";
   for( victim = ch->in_room->first_person; victim; victim = v_next )
   {
      v_next = victim->next_in_room;
      if( !IS_NPC( victim ) && xIS_SET( victim->act, PLR_KILLER ) )
      {
         crime = "KILLER";
         break;
      }
      if( !IS_NPC( victim ) && xIS_SET( victim->act, PLR_THIEF ) )
      {
         crime = "THIEF";
         break;
      }
   }
   if( !victim )
      return FALSE;
   if( xIS_SET( ch->in_room->room_flags, ROOM_SAFE ) )
   {
      sprintf( buf, "%s is a %s!  As well as a COWARD!", victim->name, crime );
      do_yell( ch, buf );
      return TRUE;
   }
   sprintf( buf, "%s is a %s!  PROTECT THE INNOCENT!  MORE BLOOOOD!!!", victim->name, crime );
   do_yell( ch, buf );
   multi_hit( ch, victim, TYPE_UNDEFINED );
   if( char_died( ch ) )
      return TRUE;
   /*
    * Added log in case of missing cityguard -- Tri 
    */
   cityguard = get_mob_index( MOB_VNUM_CITYGUARD );
   if( !cityguard )
   {
      sprintf( buf, "Missing Cityguard - Vnum:[%d]", MOB_VNUM_CITYGUARD );
      bug( buf, 0 );
      return TRUE;
   }
   char_to_room( create_mobile( cityguard ), ch->in_room );
   char_to_room( create_mobile( cityguard ), ch->in_room );
   return TRUE;
}

bool spec_fido( CHAR_DATA * ch )
{
   OBJ_DATA *corpse;
   OBJ_DATA *c_next;
   OBJ_DATA *obj;
   OBJ_DATA *obj_next;
   if( !IS_AWAKE( ch ) )
      return FALSE;
   for( corpse = ch->in_room->first_content; corpse; corpse = c_next )
   {
      c_next = corpse->next_content;
      if( corpse->item_type != ITEM_CORPSE_NPC )
         continue;
      if( IS_ACT_FLAG( ch, ACT_ONMAP ) )
      {
         if( ch->map != corpse->map || ch->x != corpse->x || ch->y != corpse->y )
            continue;
      }
      act( AT_ACTION, "$n savagely devours a corpse.", ch, NULL, NULL, TO_ROOM );
      for( obj = corpse->first_content; obj; obj = obj_next )
      {
         obj_next = obj->next_content;
         obj_from_obj( obj );
         obj_to_room( obj, ch->in_room, ch );
      }
      extract_obj( corpse );
      return TRUE;
   }
   return FALSE;
}

bool spec_guard( CHAR_DATA * ch )
{
   char buf[MAX_STRING_LENGTH];
   CHAR_DATA *victim;
   CHAR_DATA *v_next;
   CHAR_DATA *ech;
   char *crime;
   int max_evil;
   if( !IS_AWAKE( ch ) || ch->fighting )
      return FALSE;
   if( IS_ACT_FLAG( ch, ACT_ONMAP ) || IS_PLR_FLAG( ch, PLR_ONMAP ) )
      return FALSE;
   max_evil = 300;
   ech = NULL;
   crime = "";
   for( victim = ch->in_room->first_person; victim; victim = v_next )
   {
      v_next = victim->next_in_room;
      if( !IS_NPC( victim ) && xIS_SET( victim->act, PLR_KILLER ) )
      {
         crime = "KILLER";
         break;
      }
      if( !IS_NPC( victim ) && xIS_SET( victim->act, PLR_THIEF ) )
      {
         crime = "THIEF";
         break;
      }
      if( victim->fighting && who_fighting( victim ) != ch && victim->alignment < max_evil )
      {
         max_evil = victim->alignment;
         ech = victim;
      }
   }
   if( victim && xIS_SET( ch->in_room->room_flags, ROOM_SAFE ) )
   {
      sprintf( buf, "%s is a %s!  As well as a COWARD!", victim->name, crime );
      do_yell( ch, buf );
      return TRUE;
   }
   if( victim )
   {
      sprintf( buf, "%s is a %s!  PROTECT THE INNOCENT!!  BANZAI!!", victim->name, crime );
      do_yell( ch, buf );
      multi_hit( ch, victim, TYPE_UNDEFINED );
      return TRUE;
   }
   if( ech )
   {
      act( AT_YELL, "$n screams 'PROTECT THE INNOCENT!!  BANZAI!!", ch, NULL, NULL, TO_ROOM );
      multi_hit( ch, ech, TYPE_UNDEFINED );
      return TRUE;
   }
   return FALSE;
}

bool spec_janitor( CHAR_DATA * ch )
{
   OBJ_DATA *trash;
   OBJ_DATA *trash_next;
   if( !IS_AWAKE( ch ) )
      return FALSE;
   for( trash = ch->in_room->first_content; trash; trash = trash_next )
   {
      trash_next = trash->next_content;
      if( !IS_SET( trash->wear_flags, ITEM_TAKE ) || IS_OBJ_STAT( trash, ITEM_BURIED ) )
         continue;
      if( IS_ACT_FLAG( ch, ACT_ONMAP ) )
      {
         if( ch->map != trash->map || ch->x != trash->x || ch->y != trash->y )
            continue;
      }
      if( trash->item_type == ITEM_DRINK_CON
          || trash->item_type == ITEM_TRASH || trash->cost < 10 || ( trash->pIndexData->vnum == OBJ_VNUM_SHOPPING_BAG && !trash->first_content ) )
      {
         act( AT_ACTION, "$n picks up some trash.", ch, NULL, NULL, TO_ROOM );
         obj_from_room( trash );
         obj_to_char( trash, ch );
         return TRUE;
      }
   }
   return FALSE;
}

bool spec_poison( CHAR_DATA * ch )
{
   CHAR_DATA *victim;
   if( ch->position != POS_FIGHTING && ch->position != POS_EVASIVE && ch->position != POS_DEFENSIVE && ch->position != POS_AGGRESSIVE && ch->position != POS_BERSERK )
      return FALSE;
   if( ( victim = who_fighting( ch ) ) == NULL || number_percent(  ) > 2 * ch->level )
      return FALSE;
   act( AT_HIT, "You bite $N!", ch, NULL, victim, TO_CHAR );
   act( AT_ACTION, "$n bites $N!", ch, NULL, victim, TO_NOTVICT );
   act( AT_POISON, "$n bites you!", ch, NULL, victim, TO_VICT );
   spell_poison( gsn_poison, ch->level, ch, victim );
   return TRUE;
}

bool spec_thief( CHAR_DATA * ch )
{
   CHAR_DATA *victim;
   CHAR_DATA *v_next;
   int gold, maxgold;
   if( ch->position != POS_STANDING )
      return FALSE;
   for( victim = ch->in_room->first_person; victim; victim = v_next )
   {
      v_next = victim->next_in_room;
      if( IS_NPC( victim ) || victim->level >= LEVEL_IMMORTAL || number_bits( 2 ) != 0 || !can_see( ch, victim, FALSE ) )  /* Thx Glop */
         continue;
      if( IS_AWAKE( victim ) && number_range( 0, ch->level ) == 0 )
      {
         act( AT_ACTION, "You discover $n's hands in your sack of gold!", ch, NULL, victim, TO_VICT );
         act( AT_ACTION, "$N discovers $n's hands in $S sack of gold!", ch, NULL, victim, TO_NOTVICT );
         return TRUE;
      }
      else
      {
         maxgold = ch->level * ch->level * 1000;
         gold = victim->gold * number_range( 1, URANGE( 2, ch->level / 4, 10 ) ) / 100;
         ch->gold += 9 * gold / 10;
         victim->gold -= gold;
         if( ch->gold > maxgold )
         {
            boost_economy( ch->in_room->area, ch->gold - maxgold / 2 );
            ch->gold = maxgold / 2;
         }
         return TRUE;
      }
   }
   return FALSE;
}