This version ACTUALLY WORKS thanks to George Greer :) This one supports
multiple ferries, and works via a struct. I have 1 ferry in it (the
one I use on my mud) but you can easily add some. Another
version might be released that will cut the file size almost in half and
double the un-readability :)
Next on my list for this code is to make it so the ferry can make 2
cycles/day. To install:
In comm.c:
Near the top, with the prototypes add:
void init_ferry(void);
void update_ferry(void);
In game_loop, before /* The Main Loop. The Big Cheese. The...
add: init_ferry();
in heartbeat after weather_and_time(1); add:
update_ferry();
You will need to add the makefile entrys for ferry.c, but if you cant do that
you shouldn't be running a MUD.
Fili
--
Head Administrator for DarkStar: The Knight of Darkness
Begin Code:
/***************************************************************************
* ferry.c Added to CircleMUD *
* *
* Base Programming: Shadowbeam of Darkstar: The Knight of Darkness *
* Multiple Ferry Enhancement: Fili of Darkstar: The Knight of Darkness *
* Create_Exit & Remove_Exit Bugfixes: George Greer *
* (DARKSTAR: telnet://mdarkstar.ml.org:7007, http://mdarkstar.home.ml.org) *
* *
* Use of code requires credit in credit file and that you mail Fili at: *
* cybom@netropolis.net *
***************************************************************************/
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "db.h"
#define NUM_OF_FERRYS 1 // Change as needed
/*******************Externals and Other Globals*******************/
extern struct room_data *world;
extern struct time_info_data time_info;
struct ferry_info {
int f_from_room; //VNUM of one of the Ferry's docks
int ferry_room; //VNUM of the Ferry room
int f_to_room; //VNUM of the other of the Ferry's docks
int f_from_room_dir_from_room; //Direction from FROM_ROOM to the ferry
int f_from_room_dir_from_ferry;//Direction from the ferry to FROM_ROOM
int f_to_room_dir_from_room; //Direction from TO_ROOM to the ferry
int f_to_room_dir_from_ferry; //Direction from the ferry to TO_ROOM
int f_time_arrive_from_room; //Time the ferry arrives at FROM_ROOM
int f_time_leave_from_room; //Time the ferry leaves FROM_ROOM
int f_time_arrive_to_room; //Time the ferry arrives at TO_ROOM
int f_time_leave_to_room; // Time the ferry leaves TO_ROOM
char arrive_messg_from[100]; // Message sent to ferry at arrival at FROM_ROOM
char arrive_dock_from[100]; // Message sent to dock at arrival at FROM_ROOM
char leave_messg_from[100]; // Message sent to ferry when leaving FROM_ROOM
char leave_dock_from[100]; // Message sent to dock when leaving FROM_ROOM
char arrive_messg_to[100]; // Message sent to ferry at arrival at TO_ROOM
char arrive_dock_to[100]; // Message sent to dock at arrival at TO_ROOM
char leave_messg_to[100]; // Message sent to ferry when leaving TO_ROOM
char leave_dock_to[100]; // Message sent to dock when leaving TO_ROOM
};
struct ferry_info ferrys[NUM_OF_FERRYS];
/*******************Ferry Initializations*******************/
//This is the block of code used for initializing a ferry
void init_ferry(void)
{
//The ferry between Myrrak and the Mainland
ferrys[0].f_from_room = 1000;
ferrys[0].ferry_room = 1333;
ferrys[0].f_to_room = 6006;
ferrys[0].f_from_room_dir_from_room = WEST;
ferrys[0].f_from_room_dir_from_ferry = EAST;
ferrys[0].f_to_room_dir_from_room = EAST;
ferrys[0].f_to_room_dir_from_ferry = WEST;
ferrys[0].f_time_arrive_from_room = 6;
ferrys[0].f_time_leave_from_room = 12;
ferrys[0].f_time_arrive_to_room = 18;
ferrys[0].f_time_leave_to_room = 23;
sprintf(ferrys[0].arrive_messg_from, "The ferry docks and a gangplank is extended\r\n");
sprintf(ferrys[0].arrive_dock_from, "The ferry from the Mainland docks and a gangplank is extended\r\n");
sprintf(ferrys[0].arrive_messg_to, "The ferry docks and a gangplank is extended\r\n");
sprintf(ferrys[0].arrive_dock_to, "The ferry from Myrrak docks and a gangplank is extended\r\n");
sprintf(ferrys[0].leave_messg_from, "The ferry raises its sail and gangplank is hauled aboard\r\n");
sprintf(ferrys[0].leave_dock_from, "The ferry raises its sail and gangplank is hauled aboard\r\n");
sprintf(ferrys[0].leave_messg_to, "The ferry raises its sail and gangplank is hauled aboard\r\n");
sprintf(ferrys[0].leave_dock_to, "The ferry raises its sail and gangplank is hauled aboard\r\n");
}
/*******************FUNCTIONS*******************/
void create_exit(int vnum_from, int vnum_to, int from_dir)
{
char cebuf[128];
int rnum_from, rnum_to;
if ((rnum_from = real_room(vnum_from)) == NOWHERE) {
sprintf(cebuf, "SYSERR: Ferry: Couldn't find the 'from' room #%d.", vnum_from);
log(cebuf);
} else if ((rnum_to = real_room(vnum_to)) == NOWHERE) {
sprintf(cebuf, "SYSERR: Ferry: Couldn't find the 'to' room #%d.", vnum_to);
log(cebuf);
} else if (world[rnum_from].dir_option[from_dir] == NULL) {
CREATE(world[rnum_from].dir_option[from_dir], struct room_direction_data, 1);
world[rnum_from].dir_option[from_dir]->to_room = rnum_to;
} else {
sprintf(cebuf, "SYSERR: Ferry overwriting exit in room #%d.", world[rnum_from].number);
log(cebuf);
world[rnum_from].dir_option[from_dir]->to_room = rnum_to;
}
}
void remove_exit(int vnum_from, int vnum_to, int from_dir)
{
char rebuf[128];
int rnum_from, rnum_to;
if ((rnum_from = real_room(vnum_from)) == NOWHERE) {
sprintf(rebuf, "SYSERR: Ferry: Couldn't find the 'from' room #%d.", vnum_from);
log(rebuf);
} else if ((rnum_to = real_room(vnum_to)) == NOWHERE) {
sprintf(rebuf, "SYSERR: Ferry: Couldn't find the 'to' room #%d.", vnum_to);
log(rebuf);
} else if (world[rnum_from].dir_option[from_dir] == NULL) {
sprintf(rebuf, "SYSERR: Trying to remove non-existant exit in room #%d.", world[rnum_from].number);
log(rebuf);
} else {
free(world[rnum_from].dir_option[from_dir]);
world[rnum_from].dir_option[from_dir] = NULL;
}
}
void update_ferry(void) {
int onferrynum = 0; // Ferry cycle #
for(onferrynum = 0; onferrynum < NUM_OF_FERRYS; onferrynum++)
{
if(time_info.hours == ferrys[onferrynum].f_time_arrive_from_room){
create_exit(ferrys[onferrynum].f_from_room, ferrys[onferrynum].ferry_room, ferrys[onferrynum].f_from_room_dir_from_room);
create_exit(ferrys[onferrynum].ferry_room, ferrys[onferrynum].f_from_room, ferrys[onferrynum].f_from_room_dir_from_ferry);
send_to_room(ferrys[onferrynum].leave_dock_from, real_room(ferrys[onferrynum].f_from_room));
send_to_room(ferrys[onferrynum].arrive_messg_from, real_room(ferrys[onferrynum].ferry_room));
}
if(time_info.hours == ferrys[onferrynum].f_time_arrive_to_room){
create_exit(ferrys[onferrynum].f_to_room, ferrys[onferrynum].ferry_room, ferrys[onferrynum].f_to_room_dir_from_room);
create_exit(ferrys[onferrynum].ferry_room, ferrys[onferrynum].f_to_room, ferrys[onferrynum].f_to_room_dir_from_ferry);
send_to_room(ferrys[onferrynum].arrive_dock_to, real_room(ferrys[onferrynum].f_from_room));
send_to_room(ferrys[onferrynum].arrive_messg_to, real_room(ferrys[onferrynum].ferry_room));
}
if(time_info.hours == ferrys[onferrynum].f_time_leave_from_room){
remove_exit(ferrys[onferrynum].f_from_room, ferrys[onferrynum].ferry_room, ferrys[onferrynum].f_from_room_dir_from_room);
remove_exit(ferrys[onferrynum].ferry_room, ferrys[onferrynum].f_from_room, ferrys[onferrynum].f_from_room_dir_from_ferry);
send_to_room(ferrys[onferrynum].leave_dock_from, real_room(ferrys[onferrynum].f_from_room));
send_to_room(ferrys[onferrynum].leave_messg_from, real_room(ferrys[onferrynum].ferry_room));
}
if(time_info.hours == ferrys[onferrynum].f_time_leave_to_room){
remove_exit(ferrys[onferrynum].f_to_room, ferrys[onferrynum].ferry_room, ferrys[onferrynum].f_to_room_dir_from_room);
remove_exit(ferrys[onferrynum].ferry_room, ferrys[onferrynum].f_to_room, ferrys[onferrynum].f_to_room_dir_from_ferry);
send_to_room(ferrys[onferrynum].leave_dock_to, real_room(ferrys[onferrynum].f_to_room));
send_to_room(ferrys[onferrynum].leave_messg_to, real_room(ferrys[onferrynum].ferry_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