#include <glib.h>
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <merc.h>
#include <recycle.h>
#include <tables.h>
extern bool fBootDb;
/*
* Translates mob virtual number to its mob index struct.
* Hash table lookup.
*/
MOB_INDEX_DATA *get_mob_index( int vnum )
{
MOB_INDEX_DATA *pMobIndex;
for ( pMobIndex = mob_index_hash[vnum % MAX_KEY_HASH];
pMobIndex != NULL;
pMobIndex = pMobIndex->next )
{
if ( pMobIndex->vnum == vnum )
return pMobIndex;
}
if ( fBootDb )
{
bug( "Get_mob_index: bad vnum %d.", vnum );
exit( 1 );
}
return NULL;
}
/*
* Create an instance of a mobile.
*/
CHAR_DATA *create_mobile( MOB_INDEX_DATA *pMobIndex )
{
CHAR_DATA *mob;
int tempvalue = 0;
if (pMobIndex == NULL){
bug("Null pMobIndex used as a argument.",0);
return NULL;
}
//DEBUG
check_both("Call Create Mobile");
mob = new_char();
mob->pIndexData = pMobIndex;
mob->hunting = g_string_assign(mob->hunting,"");
mob->lord = g_string_assign(mob->lord,"");
mob->clan = 0;
mob->morph = g_string_assign(mob->morph,"");
mob->createtime = g_string_assign(mob->createtime,"");
mob->lasttime = g_string_assign(mob->lasttime,"");
mob->lasthost = g_string_assign(mob->lasthost,"");
mob->powertype = g_string_assign(mob->powertype,"");
mob->poweraction = g_string_assign(mob->poweraction,"");
mob->pload = g_string_assign(mob->pload,"");
mob->prompt = g_string_assign(mob->prompt,"");
mob->cprompt = g_string_assign(mob->cprompt,"");
mob->sect = 0;
mob->pk_sect = 0;
mob->id = get_mob_id();
mob->delay_timer = 0;
mob->pk_timer = 0;
mob->killed_by = NULL;
mob->name = g_string_assign(mob->name,pMobIndex->player_name);
mob->short_descr = g_string_assign(mob->short_descr,pMobIndex->short_descr);
mob->long_descr = g_string_assign(mob->long_descr,pMobIndex->long_descr);
mob->description = g_string_assign(mob->description,pMobIndex->description);
mob->spec_fun = pMobIndex->spec_fun;
mob->home = 3001;
mob->form = 32767;
mob->level = number_fuzzy( pMobIndex->level );
mob->act = pMobIndex->act;
mob->affected_by = pMobIndex->affected_by;
if (IS_SET(mob->affected_by,AFF_SHADOWPLANE))
mob->plane = PLANE_SHADOW;
else
mob->plane = PLANE_NORMAL;
mob->alignment = pMobIndex->alignment;
mob->sex = pMobIndex->sex;
mob->added = pMobIndex->added;
mob->mob_fight = pMobIndex->mob_fight;
mob->sphere_spaffect = pMobIndex->sphere_spaffect;
mob->mob_con = pMobIndex->mob_con;
mob->mprog_target = NULL;
mob->sphere_spaffect = 0;
mob->added = 0;
mob->sphere_affected_by[0] = 0;
mob->sphere_affected_by[1] = 0;
mob->sphere_affected_by[2] = 0;
mob->sphere_affected_by[3] = 0;
mob->armor = (pMobIndex->ac == 0) ?
interpolate( mob->level, 100, -100 ):
pMobIndex->ac;
tempvalue = mob->level * 8 + number_range(
mob->level * mob->level / 4,
mob->level * mob->level );
if (pMobIndex->hitnodice == 0
&& pMobIndex->hitsizedice == 0
&& pMobIndex->hitplus == 0)
{
mob->max_hit = tempvalue;
}
else
{
mob->max_hit = dice(pMobIndex->hitnodice, pMobIndex->hitsizedice)
+ pMobIndex->hitplus;
}
mob->hit = mob->max_hit;
mob->hitroll = (pMobIndex->hitroll == 0) ?
mob->level:
pMobIndex->hitroll;
if (pMobIndex->damnodice == 0
&& pMobIndex->damsizedice == 0
&& pMobIndex->damplus == 0)
{
mob->damroll = mob->level;
}
else
{
mob->damroll = dice(pMobIndex->damnodice, pMobIndex->damsizedice)
+ pMobIndex->damplus;
}
/*
* Set the mobile stance here
*/
/*
* Insert in list.
*/
mob->next = char_list;
char_list = mob;
pMobIndex->count++;
//Add the total of mobiles to the list -- Spiral
mudsetting->total_mobiles_created++;
mudsetting->mobiles_created++;
check_both("Call Create Mobile Finished");
return mob;
}
void set_random_stance( CHAR_DATA *ch)
{
/*
* this little jewl is cause I need to call it 2 times or more
*/
int num;
char buf[MAX_STRING_LENGTH];
num = number_range(1,10);
ch->stance[num] = 200;
ch->stance[0] = num;
sprintf(buf,"%s", stance_msg_table[num].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
ch->pk_timer = 1;
}
void set_mob_stance ( CHAR_DATA *ch )
{
char buf[MAX_STRING_LENGTH];
switch ( ch->mob_fight )
{
case FIGHT_VIPER:
ch->stance[0] = STANCE_VIPER;
ch->stance[STANCE_VIPER] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_VIPER].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_CRANE:
ch->stance[0] = STANCE_CRANE;
ch->stance[STANCE_CRANE] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_CRANE].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_MONGOOSE:
ch->stance[0] = STANCE_MONGOOSE;
ch->stance[STANCE_MONGOOSE] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_MONGOOSE].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_BULL:
ch->stance[0] = STANCE_BULL;
ch->stance[STANCE_BULL] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_BULL].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_CRAB:
ch->stance[0] = STANCE_CRAB;
ch->stance[STANCE_CRAB] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_CRAB].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_MANTIS:
ch->stance[0] = STANCE_MANTIS;
ch->stance[STANCE_MANTIS] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_MANTIS].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_TIGER:
ch->stance[0] = STANCE_TIGER;
ch->stance[STANCE_TIGER] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_TIGER].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_DRAGON:
ch->stance[0] = STANCE_DRAGON;
ch->stance[STANCE_DRAGON] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_DRAGON].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_MONKEY:
ch->stance[0] = STANCE_MONKEY;
ch->stance[STANCE_MONKEY] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_MONKEY].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_SWALLOW:
ch->stance[0] = STANCE_SWALLOW;
ch->stance[STANCE_SWALLOW] = 200;
sprintf(buf,"%s", stance_msg_table[STANCE_SWALLOW].haunt);
act(buf,ch,NULL,NULL,TO_ROOM);
break;
case FIGHT_RANDOM:
set_random_stance(ch);
break;
case FIGHT_MASTER:
set_master_stance(ch);
break;
default:
break;
}
}
void set_master_stance ( CHAR_DATA *ch )
{
CHAR_DATA *victim;
char buf2[MAX_STRING_LENGTH];
victim = ch->fighting;
if ( victim == NULL )
return;
if ( ch->in_room == NULL )
return;
switch ( victim->stance[0] )
{
default:
ch->stance[0] = STANCE_DRAGON;
ch->stance[STANCE_DRAGON] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_DRAGON].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_VIPER:
ch->stance[0] = STANCE_VIPER;
ch->stance[STANCE_VIPER] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_VIPER].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_CRANE:
ch->stance[0] = STANCE_CRANE;
ch->stance[STANCE_CRANE] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_CRANE].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_MONGOOSE:
ch->stance[0] = STANCE_MANTIS;
ch->stance[STANCE_MANTIS] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_MANTIS].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_BULL:
ch->stance[0] = STANCE_MANTIS;
ch->stance[STANCE_MANTIS] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_MANTIS].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_CRAB:
ch->stance[0] = STANCE_MANTIS;
ch->stance[STANCE_MANTIS] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_MANTIS].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_MANTIS:
ch->stance[0] = STANCE_MANTIS;
ch->stance[STANCE_MANTIS] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_MANTIS].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_TIGER:
ch->stance[0] = STANCE_DRAGON;
ch->stance[STANCE_DRAGON] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_DRAGON].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_DRAGON:
ch->stance[0] = STANCE_SWALLOW;
ch->stance[STANCE_SWALLOW] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_SWALLOW].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_MONKEY:
ch->stance[0] = STANCE_MONKEY;
ch->stance[STANCE_MONKEY] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_MONKEY].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
case STANCE_SWALLOW:
ch->stance[0] = STANCE_MANTIS;
ch->stance[STANCE_MANTIS] = 200;
sprintf(buf2,"%s", stance_msg_table[STANCE_MANTIS].haunt);
act(buf2,ch,NULL,victim,TO_ROOM);
break;
}
return;
}