ar.c

./mudd/src/ar.c · 18.8 KB

From the archive emlen.tar.gz

Download the archive   « Back to the archive contents

#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mud.h"

void 
do_mount (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH];
  CHAR_DATA *victim;
  DEFINE_COMMAND ("mount", do_mount, POSITION_STANDING, 0, LOG_NORMAL, "Allows you to mount a rideable creature or person.")

    one_argy (argy, buf);
  if (buf[0] == '\0')
    {
      send_to_char ("Mount whom?\n\r", ch);
      return;
    }
  if ((victim = get_char_room (ch, buf)) == NULL)
    {
      send_to_char ("They aren't here.\n\r", ch);
      return;
    }
  if (victim == ch)
    {
      send_to_char ("You can't mount yourself!\n\r", ch);
      return;
    }
  if (RIDING (ch) != NULL)
    {
      send_to_char ("Your riding someone else!\n\r", ch);
      return;
    }
  if (MOUNTED_BY (ch) != NULL)
    {
      send_to_char ("Your being ridden by someone else!\n\r", ch);
      return;
    }
  if (IS_SET (ch->aff[AFF], FLYING))
    {
      send_to_char ("You can't ride and fly at the same time!\n\r", ch);
      return;
    }
  if (IS_PLAYER (ch) && !IS_SET (victim->act, ACT_MOUNTABLE))
    {
      send_to_char ("You can't ride that.\n\r", ch);
      return;
    }
  if (RIDING (victim) != NULL)
    {
      send_to_char ("They are riding someone else!\n\r", ch);
      return;
    }
  if (MOUNTED_BY (victim) != NULL)
    {
      send_to_char ("They are being ridden by someone else!\n\r", ch);
      return;
    }
/*if (victim->level>ch->level) 
   {
   send_to_char("You cannot control mounts that are a higher level than your level.\n\r",ch); 
   return;
   }
 */
  check_fgt (ch);
  check_fgt (victim);
  ch->fgt->riding = victim;
  victim->fgt->mounted_by = ch;
  act ("$n mounts $N, and starts riding $M.", ch, NULL, victim, TO_ROOM);
  act ("You mount $N, and start riding $M.", ch, NULL, victim, TO_CHAR);
  act ("$n mounts you.", ch, NULL, victim, TO_VICT);
  return;
}

void 
do_dismount (CHAR_DATA * ch, char *argy)
{
  DEFINE_COMMAND ("dismount", do_dismount, POSITION_RESTING, 0, LOG_NORMAL, "Allows you to dismount from a mount.")

    if (RIDING (ch) == NULL)
    {
      send_to_char ("You're not riding anything.\n\r", ch);
      return;
    }
  act ("$n dismounts from $N.", ch, NULL, RIDING (ch), TO_NOTVICT);
  act ("You dismount from $N.", ch, NULL, RIDING (ch), TO_CHAR);
  act ("$n dismounts from you.", ch, NULL, RIDING (ch), TO_VICT);
  check_fgt (ch);
  check_fgt (ch->fgt->riding);
  ch->fgt->riding->fgt->mounted_by = NULL;
  ch->fgt->riding = NULL;
  return;
}

void 
do_buck (CHAR_DATA * ch, char *argy)
{
  DEFINE_COMMAND ("buck", do_buck, POSITION_RESTING, 0, LOG_NORMAL, "Bucks off your current rider.")

    if (MOUNTED_BY (ch) == NULL)
    {
      send_to_char ("There is no one riding you.\n\r", ch);
      return;
    }
  act ("$n bucks $N!", ch, NULL, MOUNTED_BY (ch), TO_NOTVICT);
  act ("You buck $M!", ch, NULL, MOUNTED_BY (ch), TO_CHAR);
  act ("$n bucks you from $m!", ch, NULL, MOUNTED_BY (ch), TO_VICT);
  check_fgt (ch);
  check_fgt (ch->fgt->mounted_by);
  ch->fgt->mounted_by->fgt->riding = NULL;
  NEW_POSITION(ch->fgt->mounted_by, POSITION_RESTING);
  ch->fgt->mounted_by = NULL;
  return;
}

/* #define TRACK_THROUGH_DOORS */
/* track idea taken from another mud code.  Not used - we use footprints instead */
#define BFS_ERROR -1
#define BFS_ALREADY_THERE -2
#define BFS_NO_PATH -3
struct bfs_queue_struct
{
  ROOM_DATA *room;
  short dir;
  short depth;
  struct bfs_queue_struct *next;
}

 ;
struct room_list_struct
  {
    ROOM_DATA *room;
    struct room_list_struct *next;
  }

 ;
static struct bfs_queue_struct *queue_head = NULL, *queue_tail = NULL;
static struct room_list_struct *list_head = NULL, *list_tail = NULL;
/*
   extern const char * dir_name [];
 */
/* Utility macros */
#define MARK( room ) ( SET_BIT( ( room )->room_flags, R_MARK))
#define UNMARK( room ) ( REMOVE_BIT( ( room )->room_flags, R_MARK))
#define IS_MARKED( room ) ( IS_SET( ( room )->room_flags, R_MARK))
/*
   #define TOROOM( room, y ) ( (ROOM_DATA *) ( room )->exit[ ( y ) ]->to_room )
 */
/*#define IS_CLOSED( room, y ) ( IS_SET( ( room )->exit[( y )]->exit_info, \
   EX_CLOSED))
 */
/*#ifdef TRACK_THROUGH_DOORS
   #define VALID_EDGE( room, y ) \
   ( ( room )->exit[( y )] && \
   ( TOROOM(( room ), ( y ) ) != NOWHERE ) && \
   ( !IS_MARKED( TOROOM( ( room ), ( y ) ) ) ) )
   #else */
/*#define VALID_EDGE( room , y 
   ) \
   ( ( room )->exit[ ( y ) ] && \
   ( TOROOM( ( room ), ( y ) ) != NULL ) && \
   ( !IS_CLOSED( (room), ( y ) ) ) && \
   ( !IS_MARKED( TOROOM( ( room ), ( y ) ) ) ) ) */
/* #endif */
void 
list_enqueue (ROOM_DATA * room)
{
  static struct room_list_struct *curr;
  curr = mem_alloc (sizeof (struct room_list_struct));
  curr->room = room;
  curr->next = NULL;
  if (list_tail != NULL)
    {
      list_tail->next = curr;
      list_tail = curr;
    }
  else
    list_head = list_tail = curr;
  return;
}

void 
bfs_enqueue (ROOM_DATA * room, short dir, short depth)
{
  struct bfs_queue_struct *curr;
  curr = mem_alloc (sizeof (struct bfs_queue_struct));
  curr->room = room;
  curr->dir = dir;
  curr->depth = depth + 1;
  curr->next = NULL;
  if (queue_tail != NULL)
    {
      queue_tail->next = curr;
      queue_tail = curr;
    }
  else
    queue_head = queue_tail = curr;
  list_enqueue (room);
  return;
}

void 
bfs_dequeue (void)
{
  struct bfs_queue_struct *curr;
  curr = queue_head;
  if ((queue_head = queue_head->next) == NULL)
    queue_tail = NULL;
  free_m (curr);
  return;
}

void 
list_dequeue (void)
{
  struct room_list_struct *curr;
  curr = list_head;
  if ((list_head = list_head->next) == NULL)
    list_tail = NULL;
  if (curr->room != NULL)
    {
      UNMARK (curr->room);
      free_m (curr);
    }
  return;
}

void 
bfs_clear_queue (void)
{
  while (queue_head != NULL)
    bfs_dequeue ();
  return;
}

void 
list_clear_queue (void)
{
  while (list_head != NULL)
    list_dequeue ();
}

int 
find_first_step (ROOM_DATA * src, ROOM_DATA * target)
{
  int curr_dir;

  if (src == target)
    return BFS_ALREADY_THERE;
  queue_head = queue_tail = NULL;
  list_head = list_tail = NULL;
  MARK (src);
  list_enqueue (src);
  for (curr_dir = 0; curr_dir < 6; curr_dir++)
    if (VALID_EDGE (src, curr_dir) &&
	!IS_SET (src->room_flags, ROOM_UNTRACKABLE))
      {
	MARK (TOROOM (src, curr_dir));
	bfs_enqueue (TOROOM (src, curr_dir), curr_dir, 0);
      }
  while (queue_head)
    {
      if (queue_head->depth >= (state_var_1 ? 90 : 15))
	{
	  bfs_clear_queue ();
	  list_clear_queue ();
	  return BFS_NO_PATH;
	}
      if (queue_head->room == target)
	{
	  curr_dir = queue_head->dir;
	  bfs_clear_queue ();
	  list_clear_queue ();
	  return curr_dir;
	}
      else
	{
	  for (curr_dir = 0; curr_dir < 6; curr_dir++)
	    {
	      if (VALID_EDGE (queue_head->room, curr_dir))
		{
		  MARK (TOROOM (queue_head->room, curr_dir));
		  bfs_enqueue (TOROOM (queue_head->room, curr_dir),
			       queue_head->dir, queue_head->depth);
		}
	    }
	  bfs_dequeue ();
	}
    }
  list_clear_queue ();
  return BFS_NO_PATH;
}



void 
do_track (CHAR_DATA * ch, char *argy)
{
  char arg[SML_LENGTH];
  char buf[SML_LENGTH];
  DEFINE_COMMAND ("track", do_track, POSITION_STANDING, 0, LOG_NORMAL, "Allows you to search for tracks.  See help track for more info.")
   
    if (ch->position == POSITION_FIGHTING)
      return;
  check_fgt(ch);
  if (IS_PLAYER (ch) && ch->pcdata->learned[gsn_track] == 0)
    {
      send_to_char ("You really have no clue what you are doing. It would be helpful to\n\rlearn the TRACK skill first!\n\r", ch);
      return;
    }
 
  one_argy (argy, arg);
  
  if (arg[0] == '\0' && HUNTING (ch) == NULL)
    {
      send_to_char ("Who are you trying to track?\n\r", ch);
      if (IS_PLAYER (ch))
	ch->pcdata->voting_on = 0;
      return;
    }

  if (arg[0] == '\0' && HUNTING (ch) != NULL)
    {
      do_track (ch, "continue");
      if (IS_PLAYER (ch))
	ch->pcdata->voting_on = 0;
      return;
    }

  if (strcmp (arg, "continue")) /* Not just looking for more tracks */
    {
      if (!str_cmp (arg, NAME (ch)) || !str_cmp(arg, "me"))
	{
	  send_to_char ("Strange... the tracks seem to end right here.\n\r", ch);  
	  if (HUNTING (ch) != NULL)
	    {
	      free_string (ch->fgt->hunting);
	      ch->fgt->hunting = NULL;
	      ch->pcdata->voting_on = 0;
	    }
	  return;
	}
      if (strlen (arg) > 19)
	{
	  send_to_char ("That name is too long to track.\n\r", ch);
	  return;
	}
      if (HUNTING (ch) != NULL)
	{
	  sprintf (buf, "You stop tracking %s and start tracking %s.\n\r", HUNTING(ch), arg);
	  send_to_char (buf, ch);
	  free_string (ch->fgt->hunting);
	  ch->fgt->hunting = NULL;
	}
      
      ch->fgt->hunting = str_dup(arg);
    }
  if (IS_PLAYER(ch))
    {
      ch->pcdata->tickcounts = 9;
      ch->pcdata->voting_on = 999;
    } 
  send_to_char ("You begin to look for tracks...\n\r", ch);
  if (IS_MOB(ch)) 
    do_track_t(ch, "continue");
  return;
}

void 
do_track_t (CHAR_DATA * ch, char *argy)
{ 
  char buf[STD_LENGTH];
  TRACK_DATA *tr;
  int dir;
  char *t;
  bool found = FALSE;
  check_fgt(ch);
  if (str_cmp(argy, "continue") || HUNTING (ch) == NULL)
    {
      send_to_char("You find some footprints of some sort, but aren't good enough to determine\n\r", ch);
      send_to_char("if they are your victim's, how old they are, or where they lead...\n\r", ch);
      if (HUNTING(ch))
        {
	  free_string(ch->fgt->hunting);
	  ch->fgt->hunting = NULL;
        }
      if (IS_PLAYER(ch))
	ch->pcdata->voting_on = 0;
      return;
    }
  if (IS_PLAYER (ch) && !check_skill(ch, gsn_track))
    {
      send_to_char ("You find some footprints of some sort, but aren't good enough to determine\n\r", ch);
      send_to_char ("if they are your victim's, how old they are, or where they lead...\n\r", ch);
      return;
    }
  for (tr = ch->in_room->tracks; tr != NULL; tr = tr->next)
    {
      t = tr->who;
      if (*t == K_CHAR)
	{
	  if (is_name (ch->fgt->hunting, ((CHAR_DATA *) tr->who)->pIndexData->name))
	    {
	      found = TRUE;
	      break;
	    }
	}
      else
	{
	  if (!str_cmp (ch->fgt->hunting, ((ONLINE *)tr->who)->name))
	    {
	      found = TRUE;
	      break;
	    }
	}
    }
  if (found)
    {
      if (tr->dir / 10 == MAX_DIR)
	{
	  send_to_char("Strange... the tracks seem to end right here.\n\r", ch);
	  free_string(ch->fgt->hunting);
	  ch->fgt->hunting = NULL;
	  if (IS_PLAYER(ch))
	    ch->pcdata->voting_on = 0;
	  return;
	}
      dir = tr->dir % 10;
      if (dir != MAX_DIR)
	{
	  if (dir >= 4)
	    sprintf (buf, "The tracks suggest that they entered the area from %s.\n\r", dir == 4 ? "above" : "below");
	  else
	    sprintf (buf, "The tracks suggest that they entered the area from the %s.\n\r", dir_name[dir]);
	  send_to_char (buf, ch);
	}
      dir = tr->dir / 10;
      if (dir >= 4)
	sprintf (buf, "The tracks appear to leave the area right %s you!\n\r",  dir == 4 ? "above" : "below");
      else
	sprintf (buf, "The tracks appear to leave the area heading %s!\n\r", dir_name[dir]);
      send_to_char (buf, ch);
      return;
    }	
  send_to_char ("You find some footprints of some sort, but aren't good enough to determine\n\r", ch);
  send_to_char ("if they are your victim's, how old they are, or where they lead...\n\r", ch);
  return;
}

void 
hunt_victim (CHAR_DATA * ch)
{
  char buf[STD_LENGTH];
  int dir;
  bool found = FALSE;
  TRACK_DATA *tr;
  char *t;
  CHAR_DATA *vict = NULL;
  check_fgt(ch);
  if (!ch->in_room) return;
  
  if (!ch->in_room || IS_PLAYER(ch) || FIGHTING (ch) || !ch->fgt)  
    return;
  if (IS_SET(ch->act, ACT_HUNTED_NOTHERE) &&
      number_range(1,10) != 3)
    return;
  for (tr = ch->in_room->tracks; tr; tr = tr->next)
    {
      t = tr->who;
      if (*t == K_CHAR)
	{
	  if (is_name (ch->fgt->hunting, ((CHAR_DATA *)tr->who)->pIndexData->name))
	    {
	      found = TRUE;
	      break;
	    }
	}
      else if (*t == K_ONLINE)
	{
	  if (!str_cmp (ch->fgt->hunting, ((ONLINE *) tr->who)->name))
	    {
	      found = TRUE;
	      break;
	    }
	}
      else if (*t == K_ROOM)
	{
	  if (((ROOM_DATA *)tr->who)->vnum == atoi (ch->fgt->hunting))
	    {
	      found = TRUE;
	      break;
	    }
	}
    }
  if (found)
    {
      found = FALSE;
      dir = tr->dir / 10;
      if (dir < 0 || dir > 5)
	{
	  SINGLE_OBJECT *portal;
	  ROOM_DATA *dest;
	  for (portal = ch->in_room->contents; portal != NULL; portal = portal->next_content)
	    {
	      if (portal->pIndexData->item_type == ITEM_FURNITURE &&
		  IS_SET(((I_FURNITURE *)portal->more)->type, FURN_EXIT))
		{
		  if ((dest = get_room_index(((I_FURNITURE *)portal->more)->to_room_vnum)) != NULL)
		    {
		      char_from_room(ch);
		      char_to_room(ch, get_room_index(((I_FURNITURE *)portal->more)->to_room_vnum));
		      return;
		    }
		}
	      if (portal->pIndexData->item_type == ITEM_CLIMBABLE || portal->pIndexData->item_type == ITEM_SCALABLE)
		{
		  I_CLIMBABLE *c = (I_CLIMBABLE *)portal->more;
		  if (number_range(1,2) == 1)
		    {
		      if (get_room_index(c->above) != NULL)
			{
			  char_from_room(ch);
			  char_to_room(ch, get_room_index(c->above));
			  return;
			}
		    }
		  else
		    {
		      if (get_room_index(c->below) != NULL)
			{
			  char_from_room(ch);
			  char_to_room(ch, get_room_index(c->below));
			  return;
			}
		    }
		}
	    }
	}
      else
	{
	  if (ch->in_room->exit[dir] && ch->in_room->exit[dir]->d_info)
	    do_open(ch, dir_name[dir]);
	  move_char(ch, dir);
	  found = TRUE;
	} 
    }
  if (number_range(1,2) != 2)
    return;
  
  
  if ((vict = get_char_world(ch, HUNTING(ch))) == NULL)
    {
      SET_BIT (ch->act, ACT_HUNTED_NOTHERE);
      return;
    }
  else
    {
      REMOVE_BIT (ch->act, ACT_HUNTED_NOTHERE);
    }
  
  if (!found && ch->in_room != vict->in_room)
    {
      dir = get_bfs(ch, vict);
      if (dir >= 0 && dir < MAX_DIR)
	move_char(ch, dir);
    }
  
  if (vict && !IS_SET (ch->pIndexData->act3, ACT3_MUTE) 
      && can_yell(ch)
      && (number_range(1,20) == 3) &&
      (ch->society == 0 || ch->society != vict->society))
    {
      switch (number_range(1,8))
	{
	case 1:
	  sprintf (buf, "%s! You can run, but you can't hide!", NAME (vict));
	  break;
	case 2:
	  sprintf (buf, "I got a big ol' can'o'whupass here for you, %s!", NAME (vict));
	  break;
	case 3:
	  sprintf (buf, "If you make me come and get you, %s, I'll make it hurt ten times as bad!", NAME (vict));
	  break;
	 case 4:
	  sprintf (buf, "You won't get away from me, %s!", NAME (vict));
	  break;
	 case 5:
	   sprintf (buf, "*sniff* *sniff* What's that!? I smell P***Y, %s!", NAME (vict));
	  break;
	case 6:
	  sprintf (buf, "Your ass is gonna be so kicked when I find you, %s!", NAME (vict));
	  break;
	case 7:
	  sprintf (buf, "RUN RUN RUN %s! You don't want to face me!", NAME (vict));
	  break;
	case 8:
	  sprintf (buf, "OOooOOOoooOOOooo it's Big Tough %s running like a little girl!", NAME (vict));
	  break;  
	}
      do_yell (ch, buf);
    }
  if (ch->in_room == vict->in_room )
    {
      if (IS_MOB (ch) && IS_MOB (vict) &&
	  ch->society != 0 && 
	  ch->society == vict->society)
	{
	  do_follow (ch, NAME (vict));
	  if (ch->fgt && ch->fgt->hunting)
	    {
	      free_string (ch->fgt->hunting);
	      ch->fgt->hunting = NULL;
	    }
	}
      else
	multi_hit(ch, vict, TYPE_UNDEFINED);
    }
  return;
}

int 
get_bfs(CHAR_DATA *ch, void *thing)
{
  
  static int depth = 1;
  int mindepth = BFS_DEPTH;
  int door;
  int newdepth;
  int dir_chosen = MAX_DIR;
  short loop_dir = MAX_DIR;
  short loop_dist = BFS_DEPTH;
  TRACK_DATA *trk;
  char *t;

  /* This is where we check if the mob is looping back on itself
     trying to track someone... */
  
  for (trk = ch->in_room->tracks; trk != NULL; trk = trk->next)
    {
      t = trk->who;
      if (*t == K_CHAR && trk->who == ((CHAR_DATA *) ch))
	{
	  if (trk->dir / 10 == trk->dir % 10)
	    {
	      loop_dir = trk->dir % 10;
	      break;
	    }
	}
    }   
  depth++;
  for (door = 0; door < MAX_DIR; door++)
    {
      SET_BIT(ch->in_room->room_flags, R_MARK);
      if (ch->in_room->exit[door] &&
	  ch->in_room->exit[door]->to_room)
	{
	  newdepth = get_bfs_dir(ch, thing, ch->in_room->exit[door]->to_room, depth, door);
          if (door == loop_dir) 
	    loop_dist = newdepth;
	  if (newdepth < mindepth && door != loop_dir)
	    {
	      mindepth = newdepth;
	      dir_chosen = door;
	    }
	  undo_it(ch->in_room);
	}
    }
  /* If no other exits yield a result, then go back the way you
     came assuming you get a trail. */
  if (mindepth == BFS_DEPTH && loop_dist < BFS_DEPTH)
    {
      dir_chosen = loop_dir;
    }
  depth--;
  if (dir_chosen != MAX_DIR && ch->in_room->exit[dir_chosen] &&
      ch->in_room->exit[dir_chosen]->to_room)
    {
      TRACK_DATA *trk;
      bfs_tracks (ch, thing, ch->in_room->exit[dir_chosen]->to_room, dir_chosen); 
      trk = new_track (thing, ch->in_room, MAX_DIR, dir_chosen);

    }
  undo_it (ch->in_room);
  return dir_chosen;
}


bool
bfs_tracks (CHAR_DATA *ch, void *thing, ROOM_DATA *rid, int came_from)
{
  short door;
  short i;
  CHAR_DATA *fch;
  TRACK_DATA *trk;
  ROOM_DATA *troom;
  if (IS_SET(rid->room_flags, R_MARK))
    return FALSE;
  SET_BIT(rid->room_flags, R_MARK);
  
  if (rid == thing)
    return TRUE;
  for (fch = rid->people; fch != NULL; fch = fch->next_in_room)
    {
      if (fch == thing)
	return TRUE;
    }
  for (trk = rid->tracks; trk; trk = trk->next)
    {
      if (trk->who == thing)
	return TRUE;
    }
  for (i = 0; i < MAX_DIR; i++)
    {
      door = ((i+came_from) % MAX_DIR);
      if (rid->exit[door] &&
	  (troom = rid->exit[door]->to_room) != NULL && 
	  ((troom->sector_type < SECT_WATER_SWIM || 
	   troom->sector_type > SECT_WATER_NOSWIM) &&
	   (IS_AFF (ch, FLYING) || (troom->sector_type != SECT_AIR &&
				    troom->sector_type != SECT_CLOUDS))))
	{
	  if (bfs_tracks (ch, thing,  rid->exit[door]->to_room, door))
	    {
	      new_track (thing, rid, MAX_DIR, door);
	      return TRUE;
	    }
	}
    }
  return FALSE;
}



int 
get_bfs_dir (CHAR_DATA *ch, void *thing, ROOM_DATA *rid, int depth, int came_from)
{
  short door;
  short mindepth = BFS_DEPTH;
  short newdepth = 0;
  short i;
  CHAR_DATA *fch;
  TRACK_DATA *trk;
  ROOM_DATA *troom;
  if (IS_SET(rid->room_flags, R_MARK) || depth > BFS_DEPTH -1)
    return BFS_DEPTH;
  
  SET_BIT(rid->room_flags, R_MARK);
  if (rid == thing)
    return depth;
  for (fch = rid->people; fch != NULL; fch = fch->next_in_room)
    {
      if (fch == thing)
	return depth;
    }
  for (trk = rid->tracks; trk; trk = trk->next)
    {
      if (trk->who == thing)
	return depth;
    }
  depth++;
  for (i = 0; i < MAX_DIR; i++)
    {
      door = ((i+came_from) % MAX_DIR);
      if (rid->exit[door] &&
	  (troom = rid->exit[door]->to_room) != NULL && 
	  ((troom->sector_type < SECT_WATER_SWIM || 
	   troom->sector_type > SECT_WATER_NOSWIM) &&
	   (IS_AFF (ch, FLYING) || (troom->sector_type != SECT_AIR &&
				    troom->sector_type != SECT_CLOUDS))))
	{
	  newdepth = get_bfs_dir(ch, thing, rid->exit[door]->to_room, depth, door);
	  if (mindepth > newdepth)
	    mindepth = newdepth;
	}
    }
  depth--;
  return mindepth;
}

Site Stats

Snippets: 1791
Codebases: 571