/***************************************************************************
* Mud20 1.0 by Todd H. Johnson (Kregor) a derivative of the Open Gaming *
* License by Wizards of the Coast. All comments referring to D20, OGL, *
* and SRD refer to the System Reference Document for the Open Gaming *
* system. Any inclusion of these derivatives must include credit to the *
* Mud20 system, the full and complete Open Gaming LIcense, and credit to *
* the respective authors. See ../doc/srd.txt for more information. *
* *
* Emud 2.2 by Igor van den Hoven, Michiel Lange, and Martin Bethlehem. *
* *
* MrMud 1.4 by David Bills, Dug Michael and Martin Gallwey *
* *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* Original Diku Mud copyright (C) 1990 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeld, Tom Madsen, and Katje Nyboe. *
***************************************************************************/
/***************************************************************************
* mob_handler.c: handler functions for mob progs *
***************************************************************************/
#include "mud.h"
/*
even_blinded functions to support mobile commands - Scandum 20/03/02
*/
OBJ_DATA *get_obj_here_even_blinded( CHAR_DATA *ch, char *argument )
{
OBJ_DATA *obj;
push_call("get_obj_here_even_blinded(%p,%p)",ch,argument);
if ((obj = get_obj_wear_even_blinded(ch, argument)) != NULL)
{
pop_call();
return obj;
}
if ((obj = get_obj_carry_even_blinded(ch, argument)) != NULL)
{
pop_call();
return obj;
}
if ((obj = get_obj_list_even_blinded(ch, argument, ch->in_room->first_content)) != NULL)
{
pop_call();
return obj;
}
pop_call();
return NULL;
}
OBJ_DATA *get_obj_wear_even_blinded( CHAR_DATA *ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
OBJ_DATA *obj;
int number, count;
push_call("get_obj_wear_even_blinded(%p,%p)",ch,argument);
number = number_argument(argument, arg);
count = 0;
for (obj = ch->first_carrying ; obj != NULL ; obj = obj->next_content)
{
if (obj->wear_loc != WEAR_NONE && is_name(arg, obj->name))
{
if (++count == number)
{
pop_call();
return obj;
}
}
}
pop_call();
return NULL;
}
OBJ_DATA *get_obj_carry_even_blinded( CHAR_DATA *ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
OBJ_DATA *obj;
int number, count;
push_call("get_obj_carry_even_blinded(%p,%p)",ch,argument);
number = number_argument( argument, arg );
count = 0;
for (obj = ch->first_carrying ; obj != NULL ; obj = obj->next_content)
{
if (obj->wear_loc == WEAR_NONE && is_name(arg, obj->name))
{
if (++count == number)
{
pop_call();
return obj;
}
}
}
pop_call();
return NULL;
}
OBJ_DATA *get_obj_list_even_blinded( CHAR_DATA *ch, char *argument, OBJ_DATA *list )
{
char arg[MAX_INPUT_LENGTH];
OBJ_DATA *obj;
int number, count;
push_call("get_obj_list_even_blinded(%p,%p,%p)",ch,argument,list);
number = number_argument( argument, arg );
count = 0;
for (obj = list ; obj != NULL ; obj = obj->next_content)
{
if (is_name( arg, obj->name ) )
{
if ( ++count == number )
{
pop_call();
return obj;
}
}
}
pop_call();
return NULL;
}
OBJ_DATA *get_obj_area_even_blinded( CHAR_DATA *ch, char *argument )
{
OBJ_DATA *obj;
char arg[MAX_INPUT_LENGTH];
int number, count, vnum;
push_call("get_obj_area_even_blinded(%p,%p)",ch,argument);
number = number_argument(argument, arg);
count = 0;
for (vnum = ch->in_room->area->low_r_vnum ; vnum <= ch->in_room->area->hi_r_vnum ; vnum++)
{
if (room_index[vnum] == NULL)
{
continue;
}
for (obj = room_index[vnum]->first_content ; obj ; obj = obj->next_content)
{
if (is_name(arg, obj->name))
{
if (++count == number)
{
pop_call();
return obj;
}
}
}
}
pop_call();
return NULL;
}
OBJ_DATA *get_obj_world_even_blinded( CHAR_DATA *ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
OBJ_DATA *obj;
int number, count;
push_call("get_obj_world_even_blinded(%p,%p)",ch,argument);
number = number_argument( argument, arg );
count = 0;
if ((obj = get_obj_here_even_blinded(ch, argument)) != NULL)
{
pop_call();
return obj;
}
for (obj = mud->f_obj ; obj ; obj = obj->next)
{
if (is_name(arg, obj->name))
{
if (++count == number)
{
pop_call();
return obj;
}
}
}
pop_call();
return NULL;
}
CHAR_DATA *get_char_room_even_blinded( CHAR_DATA *ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
CHAR_DATA *rch;
int number, count;
push_call("get_char_room_even_blinded(%p,%p)",ch,argument);
number = number_argument( argument, arg );
count = 0;
if (!strcasecmp(arg, "self"))
{
pop_call();
return ch;
}
for (rch = ch->in_room->first_person ; rch != NULL ; rch = rch->next_in_room)
{
if (is_name(arg, rch->name))
{
if (!IS_NPC(rch) && IS_SET(rch->act, PLR_WIZINVIS))
{
continue;
}
if (++count == number)
{
pop_call();
return rch;
}
}
}
pop_call();
return NULL;
}
CHAR_DATA *get_char_area_even_blinded( CHAR_DATA *ch, char *argument )
{
CHAR_DATA *ach;
char arg[MAX_INPUT_LENGTH];
int number, count, vnum;
push_call("get_char_area_even_blinded(%p,%p)",ch,argument);
number = number_argument(argument, arg);
count = 0;
for (vnum = ch->in_room->area->low_r_vnum ; vnum <= ch->in_room->area->hi_r_vnum ; vnum++)
{
if (room_index[vnum] == NULL)
{
continue;
}
for (ach = room_index[vnum]->first_person ; ach ; ach = ach->next_in_room)
{
if (is_name(arg, ach->name))
{
if (!IS_NPC(ach) && IS_SET(ach->act, PLR_WIZINVIS))
{
continue;
}
if (++count == number)
{
pop_call();
return ach;
}
}
}
}
pop_call();
return NULL;
}
CHAR_DATA *get_char_world_even_blinded( CHAR_DATA *ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
CHAR_DATA *wch;
int number, count;
push_call("get_char_world(%p,%p)",ch,argument);
number = number_argument( argument, arg );
count = 0;
if ((wch = get_char_room_even_blinded(ch, argument)) != NULL)
{
pop_call();
return wch;
}
if ((wch = get_player_world_even_blinded(argument)) != NULL)
{
pop_call();
return wch;
}
for (wch = mud->f_char ; wch ; wch = wch->next)
{
if (is_name(arg,wch->name))
{
if (IS_PLR(wch, PLR_WIZINVIS))
{
continue;
}
if (++count == number)
{
pop_call();
return wch;
}
}
}
pop_call();
return NULL;
}
CHAR_DATA *get_player_world_even_blinded( char *argument )
{
char arg[MAX_INPUT_LENGTH];
PLAYER_GAME *fpl;
push_call("get_player_world_even_blinded(%p)",argument);
argument = one_argument( argument, arg );
for (fpl = mud->f_player ; fpl ; fpl = fpl->next)
{
if (is_name(arg, fpl->ch->name))
{
if (IS_PLR(fpl->ch, PLR_WIZINVIS))
{
continue;
}
pop_call();
return fpl->ch;
}
}
pop_call();
return NULL;
}
int find_mp_location( CHAR_DATA *ch, char *arg )
{
CHAR_DATA *victim;
push_call("find_mp_location(%p,%p)",ch,arg);
if (is_number(arg))
{
if (get_room_index(atol(arg)))
{
pop_call();
return atol(arg);
}
pop_call();
return -1;
}
if ((victim = get_player_world_even_blinded(arg)) != NULL)
{
pop_call();
return victim->in_room->vnum;
}
if ((victim = get_char_area_even_blinded(ch, arg)) != NULL)
{
pop_call();
return victim->in_room->vnum;
}
pop_call();
return -1;
}
bool is_room_good_for_teleport( CHAR_DATA *victim, int rvnum )
{
ROOM_INDEX_DATA *pRoomIndex;
push_call_format("is_room_good_for_teleport(%p,%d)",victim,rvnum);
pRoomIndex = get_room_index( rvnum );
if (pRoomIndex == NULL)
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->area->flags, AFLAG_NOTELEPORT))
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->area->flags, AFLAG_NORECALL))
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->area->flags, AFLAG_NORIP))
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->room_flags, ROOM_NO_RECALL))
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->room_flags, ROOM_PRIVATE))
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->room_flags, ROOM_NO_ASTRAL))
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->room_flags, ROOM_SOLITARY))
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->room_flags, ROOM_CLANHALL))
{
pop_call();
return( FALSE );
}
if (IS_SET(pRoomIndex->room_flags, ROOM_RIP))
{
pop_call();
return( FALSE );
}
if (pRoomIndex->sector_type == SECT_ETHEREAL)
{
pop_call();
return( FALSE );
}
if (pRoomIndex->sector_type == SECT_ASTRAL)
{
pop_call();
return( FALSE );
}
if (pRoomIndex->area->low_hard_range != 0 || pRoomIndex->area->hi_hard_range != 0)
{
if (victim->level < LEVEL_IMMORTAL)
{
if (victim->level < pRoomIndex->area->low_hard_range)
{
pop_call();
return( FALSE );
}
if (victim->level > pRoomIndex->area->hi_hard_range)
{
pop_call();
return( FALSE );
}
}
}
if (is_affected(victim, gsn_dimensional_anchor))
{
pop_call();
return( FALSE );
}
pop_call();
return( TRUE );
}
void set_exit( int room, int door, int dest)
{
EXIT_DATA *pExit;
push_call("set_exit(%p,%p,%p)",room,door,dest);
if (room <= 0 || dest < -1
|| room_index[room] == NULL
|| door < 0 || door > 5
|| (dest != -1 && room_index[dest] == NULL))
{
log_printf("Bad room connect at %d door %d to %d", room, door, dest);
pop_call();
return;
}
if (room_index[room]->exit[door] == NULL && dest > 0)
{
create_exit(room_index[room], door);
}
pExit = room_index[room]->exit[door];
if (dest > 0)
{
pExit->to_room = dest;
}
else
{
if (pExit)
{
pExit->to_room = 0;
}
}
pop_call();
return;
}
lg_int translate_bits( char *string )
{
int cnt, num;
lg_int number;
char c;
char buf[100];
push_call("translate_bits(%p)",string);
cnt = 0;
number = 0;
for (c = string[cnt] ; isdigit(c) || isupper(c) || c == '_' ; c = string[++cnt])
{
buf[cnt] = c;
}
buf[cnt] = '\0';
if (isupper(buf[0]))
{
for (num = mud->bitvector_ref[*buf - 'A'] ; *bitvector_table[cnt].name != '\0' ; num++)
{
if (!strcmp(bitvector_table[num].name, buf))
{
number = bitvector_table[num].value;
break;
}
}
if (*bitvector_table[cnt].name == '\0')
{
log_printf("translate_bits: bad vector '%s'", buf);
}
}
else
{
number = atoll(buf);
}
if (c == '|')
{
number += translate_bits(&string[cnt + 1]);
}
pop_call();
return number;
}