Re: Vehicle Code

From: Scott Warren (dswarren@MAIL.CLT.BELLSOUTH.NET)
Date: 08/16/97


>Yes, Im interested to see how you did this differently from my original
>Vehicles code.
Hi Chris,
        Hope this is all the code needed to get this running. (see
attachments).
Good luck.
Scott Warren
dswarren@bellsouth.net

--8<--

/*
Dec 96 by DSW aka Calain for Reimsmud (now defunct)

File: act.drive.c

This file is for do_drive and do_sail routines.
Probably get around to using tents and any enterable objects here.
OBJ_VAL location 0 holds the VNUM of the room that is the 'inside'
of the object. That room must be flagged ROOM_LEAVE in order to leave
the object from that room. Otherwise, for example if you want two
teleporters, you could have a second ENTERABLE object that points to
the room where the first object is located.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* include every dang thang */
#include "conf.h"
#include "sysdep.h"

#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "spells.h"

extern struct room_data *world;
extern int top_of_world;
extern char *dirs[];
const int rev_dir[];
extern struct obj_data *object_list;
void die_follower(struct char_data *ch);
int real_room(int vnum);

void enter_an_object(struct char_data *ch, struct obj_data *obj)
{
int new_room;

/* make it easy - no following or mounts into objects. */
/* looks funny but 'die_follower' does the necessary stuff */
new_room = real_room(GET_OBJ_VAL(obj, 0));
if(new_room <= 0 || new_room > top_of_world)
 {
 log("Error: Trying to enter a poorly designed object!");
 send_to_char("This object is bad. Please inform the mud staff\r\n", ch);
 return;
 }
die_follower(ch);
sprintf(buf, "$n enters %s.", obj->short_description);
act(buf, TRUE, ch, 0, 0, TO_ROOM);
sprintf(buf,"You enter %s.\r\n", obj->short_description);
send_to_char(buf, ch);
char_from_room(ch);
char_to_room(ch, new_room);
if(ch->desc != NULL)
  look_at_room(ch, 0);
sprintf(buf, "$n has entered %s.", obj->short_description);
act(buf, TRUE, ch, 0, 0, TO_ROOM);
/* when you enter go ahead and set the object associated with that room
   to the object we have */
if(world[ch->in_room].entrance == NULL)
  world[ch->in_room].entrance = obj;

return;
}

void leave_an_object(struct char_data *ch)
{
struct obj_data *obj;

/* find the object associated with this leave room */
obj = world[ch->in_room].entrance;

/* ick, have to search all objects */
if(obj == NULL)
 {
  obj = object_list;
  while(obj)
    {
     if(GET_OBJ_TYPE(obj) == ITEM_SAILBOAT ||
        GET_OBJ_TYPE(obj) == ITEM_ENTERABLE ||
        GET_OBJ_TYPE(obj) == ITEM_CAR)
     if(GET_OBJ_VAL(obj, 0) == world[ch->in_room].number)
            break;
     obj = obj->next;
     }
  /* fix this room */
  world[ch->in_room].entrance = obj;
  }

if(obj == NULL)
  {
/* big problem - happens when someone puts a car in their pocket ;) */
    log("SYSERR: Room flagged ROOM_LEAVE with no associated object.");
    return;
  }
if(obj->in_room <= 0 || obj->in_room > top_of_world)
  {
   log("Error: Trying to leave but the object heading toward is not in a room");
   send_to_char("The exit is blocked!\r\n", ch);
   return;
  }
/* make it easy - no following or mounts into objects. */
/* looks funny but 'die_follower' does the necessary stuff */
die_follower(ch);

sprintf(buf, "$n leaves %s.", obj->short_description);
act(buf, TRUE, ch, 0, 0, TO_ROOM);
sprintf(buf, "You leave %s.\r\n", obj->short_description);
send_to_char(buf, ch);
/* undo pilot flag */
if(IS_SET(PLR_FLAGS(ch), PLR_PILOT))
  TOGGLE_BIT(PLR_FLAGS(ch), PLR_PILOT);
char_from_room(ch);
char_to_room(ch, obj->in_room);
if(ch->desc != NULL)
  look_at_room(ch, 0);
sprintf(buf, "$n has arrived from %s.", obj->short_description);
act(buf, TRUE, ch, 0, 0, TO_ROOM);

return;
}

void do_look_out(struct char_data *ch)
{
struct obj_data *obj;
int temp_room;

if(!ROOM_FLAGGED(ch->in_room, ROOM_LEAVE))
{
 send_to_char("Can't do that here.\r\n", ch);
 return;
}
obj = world[ch->in_room].entrance;
if(obj == NULL)
 {
  obj = object_list;
  while(obj)
    {
     if(GET_OBJ_TYPE(obj) == ITEM_SAILBOAT ||
        GET_OBJ_TYPE(obj) == ITEM_ENTERABLE ||
        GET_OBJ_TYPE(obj) == ITEM_CAR)
     if(GET_OBJ_VAL(obj, 0) == world[ch->in_room].number)
            break;
     obj = obj->next;
     }
  /* fix this room */
  world[ch->in_room].entrance = obj;
  }
if(obj == NULL) /* can't do anything about this */
{send_to_char("Error: bad room/object combo.\r\n", ch);
 return;
}
temp_room = ch->in_room;
ch->in_room = obj->in_room;
if(ch->desc)
  look_at_room(ch, 0);
ch->in_room = temp_room;
return;
}

ACMD(do_sail)
{
int door, new_room;
struct obj_data *tempobj;
struct char_data *temp;

one_argument(argument, arg);
if(GET_SKILL(ch, SKILL_SAIL) == 0)
  { send_to_char("You have no idea how to do that.\r\n", ch);
    return;
  }
if(!ROOM_FLAGGED(ch->in_room, ROOM_HELM))
  { send_to_char("You must sit at the helm to navigate.\r\n", ch);
    return;
  }
if(!*arg)
  { for(temp = world[ch->in_room].people; temp; temp= temp->next_in_room)
     if(temp && ch != temp && IS_SET(PLR_FLAGS(temp), PLR_PILOT))
       {send_to_char("Someone is already in piloting this ship!\r\n", ch);
        return;
       }
     if(!IS_SET(PLR_FLAGS(ch), PLR_PILOT)) {
     TOGGLE_BIT(PLR_FLAGS(ch), PLR_PILOT);
     send_to_char("The helm is yours.\r\n", ch);
     act("$n takes the helm.",TRUE, ch, 0,0,  TO_ROOM );}
     else {
     TOGGLE_BIT(PLR_FLAGS(ch), PLR_PILOT);
     send_to_char("You relenquish the helm.\r\n", ch);
     act("$n relenquishes the helm.", TRUE, ch, 0, 0, TO_ROOM);
          }
     return;
   }
if((door = search_block(arg, dirs, FALSE)) == -1)
   {send_to_char("Which direction?\r\n", ch);
    return;}
/* assuming that this room is the ROOM_LEAVE room. Need to change this
sometime. */
tempobj = world[ch->in_room].entrance;
if(tempobj == NULL)
 {
  tempobj = object_list;
  while(tempobj)
    {
     if(GET_OBJ_TYPE(tempobj) == ITEM_SAILBOAT ||
        GET_OBJ_TYPE(tempobj) == ITEM_ENTERABLE ||
        GET_OBJ_TYPE(tempobj) == ITEM_CAR)
     if(GET_OBJ_VAL(tempobj, 0) == world[ch->in_room].number)
            break;
     tempobj = tempobj->next;
     }
  /* fix this room */
  world[ch->in_room].entrance = tempobj;
  }
if(tempobj == NULL)
 {
 send_to_char("Error: Object associated with this room is missing!\r\n", ch);
 return;
 }

if(!EXIT(tempobj, door))
  {send_to_char("Can't go that way.\r\n", ch);
   return;}
if((SECT(EXIT(tempobj, door)->to_room) != SECT_WATER_NOSWIM) ||
   (SECT(EXIT(tempobj, door)->to_room) != SECT_WATER_SWIM) ||
   (SECT(EXIT(tempobj, door)->to_room) != SECT_PIER))
   { send_to_char("Can't sail into that!\r\n", ch);
     return;
   }
else {
  sprintf(buf, "%s sails %s.\r\n", tempobj->short_description, dirs[door]);
  send_to_room(buf, tempobj->in_room);
  obj_from_room(tempobj);
  new_room = EXIT(tempobj, door)->to_room;
  obj_to_room(tempobj, new_room);
/* this is a hack - should put another version of look_at_room here */
  new_room = ch->in_room;
  ch->in_room = tempobj->in_room;
  look_at_room(ch, 0);
  ch->in_room = new_room;
     }
/* might want to put in a message to everyone on board the ship */
return;
}


ACMD(do_drive)
{
int door, new_room;
struct obj_data *tempobj;
struct char_data *temp;

one_argument(argument, arg);
if(GET_SKILL(ch, SKILL_DRIVE) == 0)
  { send_to_char("You have no idea how to do that.\r\n", ch);
    return;
  }
if(!ROOM_FLAGGED(ch->in_room, ROOM_HELM))
  { send_to_char("There is no driver's seat.\r\n", ch);
    return;
  }
if(!*arg)
  {
    for(temp = world[ch->in_room].people; temp; temp= temp->next_in_room)
     {
     if(temp && ch != temp && IS_SET(PLR_FLAGS(temp), PLR_PILOT))
       {
        send_to_char("Someone is already in charge!\r\n", ch);
        return;
       }
     }
     if(!IS_SET(PLR_FLAGS(ch), PLR_PILOT))
      {
      TOGGLE_BIT(PLR_FLAGS(ch), PLR_PILOT);
      send_to_char("The wheel is in your hands.\r\n", ch);
      act("$n takes the wheel.",TRUE, ch, 0,0,  TO_ROOM );
      }
     else
      {
     TOGGLE_BIT(PLR_FLAGS(ch),PLR_PILOT);
     send_to_char("You relenquish the driver's seat.\r\n", ch);
     act("$n relenquishes the driver's seat.", TRUE, ch, 0, 0, TO_ROOM);
      }
     return;
   }
if((door = search_block(arg, dirs, FALSE)) == -1)
   {send_to_char("Which direction?\r\n", ch);
    return;}
if(!IS_SET(PLR_FLAGS(ch), PLR_PILOT))
   return;
/*
assuming that the leave room is the same room as the pilot room.
have to change this sometime.
*/
tempobj = world[ch->in_room].entrance;
if(tempobj == NULL)
 {
  tempobj = object_list;
  while(tempobj)
    {
     if(GET_OBJ_TYPE(tempobj) == ITEM_SAILBOAT ||
        GET_OBJ_TYPE(tempobj) == ITEM_ENTERABLE ||
        GET_OBJ_TYPE(tempobj) == ITEM_CAR)
     if(GET_OBJ_VAL(tempobj, 0) == world[ch->in_room].number)
            break;
     tempobj = tempobj->next;
     }
  /* fix this room */
  world[ch->in_room].entrance = tempobj;
  }
if(tempobj == NULL) /* can't do anything about this */
 {
 send_to_char("Bad object! Notify imms!\r\n", ch);
 return;
  }

if(!EXIT(tempobj, door))
  {send_to_char("Can't go that way.\r\n", ch);
   return;}
if((SECT(EXIT(tempobj, door)->to_room) == SECT_WATER_NOSWIM) ||
   (SECT(EXIT(tempobj, door)->to_room) == SECT_WATER_SWIM) ||
   (SECT(EXIT(tempobj, door)->to_room) == SECT_MOUNTAIN))
   { send_to_char("Can't drive into that!\r\n", ch);
     return;
   }
else {
  sprintf(buf, "%s rolls %s.\r\n", tempobj->short_description, dirs[door]);
  send_to_room(buf, tempobj->in_room);
  new_room = EXIT(tempobj, door)->to_room;
  obj_from_room(tempobj);
  sprintf(buf, "%s rolls in from the %s.", tempobj->short_description,
               dirs[rev_dir[door]]);
  obj_to_room(tempobj, new_room);
  send_to_room(buf, tempobj->in_room);
/* this is a hack - should put another version of look_at_room here */
  new_room = ch->in_room;
  ch->in_room = tempobj->in_room;
  look_at_room(ch, 0);
  ch->in_room = new_room;
     }
return;
}

     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST