direction = find_path(ch->in_room, victim->in_room, skill, &distance);
int find_path(ROOM_INDEX_DATA *from, ROOM_INDEX_DATA *to, int max_depth, int* dist)
for (depth = 0; depth < max_depth; depth++)
{
*dist = depth+1;
rlist = track_room_list;
int find_path(ROOM_INDEX_DATA *from, ROOM_INDEX_DATA *to, int max_depth, int *dist)
{
int bitvector[PATH_MAX_VNUM/BITS_PER_INT];
ROOM_INDEX_DATA *rlist;
ROOM_INDEX_DATA *track_room_list;
int i, depth;
// int distance = 0;
bzero(bitvector, sizeof(bitvector));
PATH_SET_FLAG(bitvector, from->vnum);
track_room_list = from;
track_room_list->next_track = NULL;
for (depth = 0; depth < max_depth; depth++)
{
*dist = depth+1;
rlist = track_room_list;
track_room_list = NULL;
for (; rlist; rlist = rlist->next_track)
{
for (i = 0; i < PATH_MAX_DIR; i++)
{
if (!rlist->exit[i] || !rlist->exit[i]->u1.to_room ||
PATH_IS_FLAG(bitvector, rlist->exit[i]->u1.to_room->vnum))
continue;
PATH_SET_FLAG(bitvector, rlist->exit[i]->u1.to_room->vnum);
rlist->exit[i]->u1.to_room->track_came_from = rlist;
if (rlist->exit[i]->u1.to_room == to)
{
if (rlist == from)
return i;
// if you need access to the entire path, this is the place to get it.
// basically it's back-tracking how it got to the destination.
// Also a good place to hinder track based on sector, weather, etc.
while (rlist->track_came_from != from)
rlist = rlist->track_came_from;
for (i = 0; i < PATH_MAX_DIR; i++)
if (from->exit[i] && from->exit[i]->u1.to_room == rlist)
return i;
return -1;
}
else
{
rlist->exit[i]->u1.to_room->next_track = track_room_list;
track_room_list = rlist->exit[i]->u1.to_room;
}
}
}
}
return -1;
}
#define PATH_IS_FLAG(flag, bit) ((unsigned)flag[bit/BITS_PER_INT]>>bit%BITS_PER_INT&01) /*+track*/
#define PATH_SET_FLAG(flag, bit) (flag[bit/BITS_PER_INT] |= 1 << bit%BITS_PER_INT) /*+track*/
#define PATH_MAX_VNUM 32768 /*+track*/
#define PATH_MAX_DIR 6 /*+track*/
ROOM_INDEX_DATA * track_came_from; /*+track*/
"track", {53, 53, 1, 1}, {2, 2, 2, 2}, /*+track*/
spell_null, TAR_IGNORE, POS_STANDING,
&gsn_hunt, SLOT (0), 0, 12,
"", "!Track!", ""}
{
char buf[MAX_STRING_LENGTH];
char arg[MAX_STRING_LENGTH];
CHAR_DATA *victim;
int direction;
bool fArea;
int skill = 100;
skill /= 4;
skill += ch->level/5;
one_argument( argument, arg );
if (IS_NPC(ch)
|| ch->level < skill_table[gsn_hunt].skill_level[ch->class])
{
send_to_char("Huh?\n\r",ch);
return;
}
if( arg[0] == '\0' )
{
send_to_char( "Whom are you trying to hunt?\n\r", ch );
return;
}
/* only imps can hunt to different areas */
fArea = ( get_trust(ch) < MAX_LEVEL );
if( fArea )
victim = get_char_area( ch, arg );
else
victim = get_char_world( ch, arg );
if( victim == NULL )
{
send_to_char("No-one around by that name.\n\r", ch );
return;
}
if( ch->in_room == victim->in_room )
{
act( "$N is here!", ch, NULL, victim, TO_CHAR );
return;
}
/*
* Deduct some movement.
*/
if( ch->move > 2 )
ch->move -= 3;
else
{
send_to_char( "You're too exhausted to hunt anyone!\n\r", ch );
return;
}
act( "$n carefully sniffs the air.", ch, NULL, NULL, TO_ROOM );
WAIT_STATE( ch, skill_table[skill_lookup("hunt")].beats );
direction = find_path(ch->in_room, victim->in_room, skill);
if( direction == -1 )
{
act( "You couldn't find a path to $N from here.",
ch, NULL, victim, TO_CHAR );
return;
}
if( direction < 0 || direction > 5 )
{
send_to_char( "Hmm… Something seems to be wrong.\n\r", ch );
return;
}
/*
* Give a random direction if the player misses the die roll.
*/
if( ( IS_NPC (ch) && number_percent () > 75) /* NPC @ 25% */
|| (!IS_NPC (ch) && number_percent () > /* PC @ norm */
ch->pcdata->learned[skill_lookup("hunt")] ) )
{
do
{
direction = number_door();
}
while((ch->in_room->exit[direction] == NULL )
|| ( ch->in_room->exit[direction]->u1.to_room == NULL) );
}
/*
* Display the results of the search.
*/
sprintf( buf, "$N is %s from here.", dir_name[direction] );
act( buf, ch, NULL, victim, TO_CHAR );
check_improve(ch,skill_lookup("hunt"),TRUE,1);
return;
}
{
int bitvector[PATH_MAX_VNUM/BITS_PER_INT];
ROOM_INDEX_DATA *rlist;
ROOM_INDEX_DATA *track_room_list;
int i, depth;
bzero(bitvector, sizeof(bitvector));
PATH_SET_FLAG(bitvector, from->vnum);
track_room_list = from;
track_room_list->next_track = NULL;
for (depth = 0; depth < max_depth; depth++)
{
rlist = track_room_list;
track_room_list = NULL;
for (; rlist; rlist = rlist->next_track)
{
for (i = 0; i < PATH_MAX_DIR; i++)
{
if (!rlist->exit|| !rlist->exit->u1.to_room ||
PATH_IS_FLAG(bitvector, rlist->exit->u1.to_room->vnum))
continue;
PATH_SET_FLAG(bitvector, rlist->exit->u1.to_room->vnum);
rlist->exit->u1.to_room->track_came_from = rlist;
if (rlist->exit->u1.to_room == to)
{
if (rlist == from)
return i;
// if you need access to the entire path, this is the place to get it.
// basically it's back-tracking how it got to the destination.
// Also a good place to hinder track based on sector, weather, etc.
while (rlist->track_came_from != from)
rlist = rlist->track_came_from;
for (i = 0; i < PATH_MAX_DIR; i++)
if (from->exit&& from->exit->u1.to_room == rlist)
return i;
return -1;
}
else
{
rlist->exit->u1.to_room->next_track = track_room_list;
track_room_list = rlist->exit->u1.to_room;
}
}
}
}
return -1;
}