climb.c

./mudd/src/climb.c · 6.7 KB

From the archive emlen.tar.gz

Download the archive   « Back to the archive contents

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mud.h"
/* climb any item of type ITEM_CLIMBABLE 
   Some of this code was borrowed from the previous mud code 
*/
void 
do_climb (CHAR_DATA * ch, char *argy)
{
  CHAR_DATA *fch, *fch_next;
  SINGLE_OBJECT *obj;
  ROOM_DATA *to_room;
  ROOM_DATA *in_room;
  I_CLIMBABLE *c;
  char *arg;
  char buf[SML_LENGTH];
  char arg1[SML_LENGTH];
  char arg2[SML_LENGTH];
  EXIT_DATA *pexit;
  int dir;
  int door;
  bool siege = FALSE;
  DEFINE_COMMAND ("climb", do_climb, POSITION_STANDING, 0, LOG_NORMAL, "Allows you to climb up <object> or climb down <object>.")


    in_room = ch->in_room;

    arg = one_argy (argy, arg2);
  one_argy (arg, arg1);
  if (arg1[0] == '\0')
    {
      send_to_char ("Climb what?\n\r", ch);
      return;
    }
  if ((obj = get_obj_here (ch, arg1, SEARCH_ROOM_FIRST)) == NULL)
    {
      send_to_char ("There's nothing here to climb.\n\r", ch);
      return;
    }
  if (obj->pIndexData->item_type == ITEM_SCALABLE)
    {
      if (get_item_held (ch, ITEM_SCALE_DEV) == NULL)
	{
	  send_to_char ("You need something to scale it with.\n\r", ch);
	  return;
	}
    }
  else if (obj->pIndexData->item_type == ITEM_SIEGE &&
	   ((I_SIEGE *)obj->more)->type == SIEGE_TOWER)
    {
      siege = TRUE;
    }
  else if (obj->pIndexData->item_type != ITEM_CLIMBABLE)
    {
      send_to_char ("You can't climb that!\n\r", ch);
      return;
    }
  if (RIDING (ch) != NULL)
    {
      send_to_char ("You're mounted; you can't climb!\n\r", ch);
      return;
    }
  if (MOUNTED_BY (ch) != NULL)
    {
      send_to_char ("You can't climb while mounted.\n\r", ch);
      return;
    }
  if (!siege)
    {
      c = (I_CLIMBABLE *) obj->more;
      dir = c->up_down;
      if (arg2[0] == '\0' && dir == 2)
	{
	  send_to_char ("Which way? Up or down?\n\r", ch);
	  return;
	}
      in_room = ch->in_room;
      switch (arg2[0])
	{
	case 'U':
	case 'u':
	  if (dir == 0)
	    {
	      send_to_char ("It doesn't lead anywhere.\n\r", ch);
	      return;
	    }
	  else
	    {
	      if ((to_room = get_room_index (c->above)) == NULL)
		{
		  send_to_char ("It doesn't lead anywhere.\n\r", ch);
		  bug ("Do_climb: bad vnum up %d.",
		       c->above);
		  return;
		}
	      dir = 1;
	    }
	  break;
	case 'D':
	case 'd':
	  if (dir == 1)
	    {
	      send_to_char ("It doesn't lead anywhere.\n\r", ch);
	      return;
	    }
	  else
	    {
	      if ((to_room = get_room_index (c->below)) == NULL)
		{
		  send_to_char ("It doesn't lead anywhere.\n\r", ch);
		  bug ("Do_climb: bad vnum down %d.",
		       c->below);
		  return;
		}
	      dir = 0;
	    }
	  break;
	default:
	  if (dir == 0)
	    {
	      if ((to_room = get_room_index (c->below)) == NULL)
		{
		  send_to_char ("It doesn't lead anywhere.\n\r", ch);
		  bug ("Do_climb: bad vnum down %d.",
		       c->below);
		  return;
		}
	    }
	  else
	    {
	      if ((to_room = get_room_index (c->above)) == NULL)
		{
		  send_to_char ("It doesn't lead anywhere.\n\r", ch);
		  bug ("Do_climb: bad vnum up %d.",
		       c->above);
		  return;
		}
	      dir = 1;
	    }
	  break;
	}
    }
  else
    {
      dir = MAX_DIR;
      for (door = 0; door < 4; door++)
	{
	  if ((pexit = ch->in_room->exit[door]) != NULL &&
	      (to_room = pexit->to_room) != NULL &&
	      pexit->d_info &&
	      IS_SET (pexit->d_info->exit_info, EX_ISWALL))
	    {
	      dir = door;
	      break;
	    }
	}
      if (dir == MAX_DIR)
	{
	  send_to_char ("There are no walls to climb around here, so you climb back down.\n\r", ch);
	  return;
	}
      dir = 1;
    }
  
  if (IS_PLAYER (ch))
    {
      int move = 0;
      move -= ch->pcdata->carry_number - get_curr_str (ch);
      if (move < 2)
	move = 2;
      if (ch->move < move)
	{
	  send_to_char ("You are too exhausted.\n\r", ch);
	  return;
	}
      WAIT_STATE (ch, 1);
      SUBMOVE(ch,move);
    }
  if (IS_AFF (ch, SNEAK))
    sprintf (buf, "You sneak %s %s.\n\r",
	     (dir == 0 ? "down" : "up"), obj->pIndexData->short_descr);
  else if (IS_AFF (ch, FLYING))
    sprintf (buf, "You fly %s %s.\n\r",
	     (dir == 0 ? "down" : "up"), obj->pIndexData->short_descr);
  else
    sprintf (buf, "You climb %s %s.\n\r",
	     (dir == 0 ? "down" : "up"), obj->pIndexData->short_descr);
  buf[0] = UPPER (buf[0]);
  strcat (buf, "\n\r");
  send_to_char (buf, ch);
  for (fch = in_room->people; fch != NULL; fch = fch_next)
    {
      fch_next = fch->next_in_room;
      if (ch == fch || !can_see (fch, ch))
	continue;
      if (IS_AFF (ch, SNEAK))
	{
	  if (IS_SET (fch->act, PLR_HOLYLIGHT))
	    sprintf (buf, "%s sneaks %s %s.", PERS (ch, fch),
		     (dir == 0 ? "down" : "up"),
		     obj->pIndexData->short_descr);
	  else
	    buf[0] = '\0';
	}
      else if (IS_MOB (ch) && IS_SET (ch->act, ACT_SCRAMBLE))
	sprintf (buf, "%s rushes %s %s.", PERS (ch, fch),
		 (dir == 0 ? "down" : "up"),
		 obj->pIndexData->short_descr);
      else if (IS_AFF (ch, FLYING))
	sprintf (buf, "%s flies %s %s.", PERS (ch, fch),
		 (dir == 0 ? "down" : "up"),
		 obj->pIndexData->short_descr);
      else
	sprintf (buf, "%s climbs %s %s.", PERS (ch, fch),
		 (dir == 0 ? "down" : "up"),
		 obj->pIndexData->short_descr);
      buf[0] = UPPER (buf[0]);
      send_to_char (buf, fch);
      if (buf[0] != '\0')
	send_to_char ("\n\r", fch);
    }
  char_from_room (ch);
  char_to_room (ch, to_room);
  for (fch = to_room->people; fch != NULL; fch = fch_next)
    {
      fch_next = fch->next_in_room;
      if (ch == fch)
	continue;
      if (!can_see (fch, ch))
	continue;
      else if (IS_AFF (ch, SNEAK))
	{
	  if (IS_SET (fch->act, PLR_HOLYLIGHT))
	    sprintf (buf, "%s sneakily climbs %s from %s.", PERS (ch, fch),
		     (dir == 0 ? "down" : "up"),
		     (dir == 0 ? "above" : "below"));
	  else
	    buf[0] = '\0';
	}
      else if (IS_MOB (ch) && IS_SET (ch->act, ACT_SCRAMBLE))
	sprintf (buf, "%s rushes %s from %s.", PERS (ch, fch),
		 (dir == 0 ? "down" : "up"),
		 (dir == 0 ? "above" : "below"));
      else if (IS_AFF (ch, FLYING))
	sprintf (buf, "%s flies %s from %s.", PERS (ch, fch),
		 (dir == 0 ? "down" : "up"),
		 (dir == 0 ? "above" : "below"));
      else
	sprintf (buf, "%s climbs %s from %s.", PERS (ch, fch),
		 (dir == 0 ? "down" : "up"),
		 (dir == 0 ? "above" : "below"));
      buf[0] = UPPER (buf[0]);
      if (IS_AWAKE (fch))
	send_to_char (buf, fch);
      if (buf[0] != '\0')
	send_to_char ("\n\r", fch);
    }
  do_look (ch, "auto");
  if (HUNTING (ch) != NULL)
    do_track (ch, "continue");
  for (fch = in_room->people; fch != NULL; fch = fch_next)
    {
      fch_next = fch->next_in_room;
      if (MASTER (fch) == ch && fch->position >= POSITION_STANDING)
	{
	  act ("You follow $N $t.", fch,
	       (dir == 0 ? "down" : "up"), ch, TO_CHAR);
	  do_climb (fch, argy);
	}
    }
  
  return;
}

Site Stats

Snippets: 1791
Codebases: 571