db.cc
AwakeMUD-0.6Beta/src/db.cc · 123.2 KB
From the archive AwakeMUD-0.60_Beta.tgz
Download the archive « Back to the archive contents
/* ************************************************************************
* File: db.c Part of CircleMUD *
* Usage: Loading/saving chars, booting/resetting world, internal funcs *
* *
* All rights reserved. See license.doc for complete information. *
* *
* Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University *
* CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. *
************************************************************************ */
#define __DB_CC__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream.h>
#include <iomanip.h>
#include <ctype.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include "structs.h"
#include "awake.h"
#include "vehicles.h"
#include "utils.h"
#include "db.h"
#include "comm.h"
#include "handler.h"
#include "spells.h"
#include "mail.h"
#include "interpreter.h"
#include "house.h"
#include "memory.h"
#include "dblist.h"
#include "quest.h"
#include "shop.h"
void save_etext(struct char_data *ch);
int real_zone(int virt);
extern void read_spells(struct char_data *ch);
extern struct obj_data *find_obj(int num);
extern void obj_to_cyberware(struct obj_data *, struct char_data *);
extern void obj_from_cyberware(struct obj_data *);
extern void obj_to_bioware(struct obj_data *, struct char_data *);
extern void obj_from_bioware(struct obj_data *);
extern char *cleanup(char *dest, const char *src);
/**************************************************************************
* declarations of most of the 'global' variables *
************************************************************************ */
// beginning of mud time
long beginning_of_time = 2157880000U;
long mud_boot_time = 0;
struct room_data *world = NULL; /* array of rooms */
int top_of_world = 0; /* ref to top element of world */
int top_of_world_array = 0;
int world_chunk_size = 100; /* size of world to add on each reallocation */
int olc_state = 1; /* current olc state */
int ANTI_LAR = 0; /* ANTI-LAR code */
int LAREXCEPT = 0; /* ANTI-LAR code */
struct char_data *character_list = NULL; /* global linked list of
* chars */
struct index_data *mob_index; /* index table for mobile file */
struct char_data *mob_proto; /* prototypes for mobs */
int top_of_mobt = 0; /* top of mobile index table */
int top_of_mob_array = 0;
int mob_chunk_size = 100; // default to 100
class objList ObjList; // contains the global list of perm objects
struct index_data *obj_index; /* index table for object file */
struct obj_data *obj_proto; /* prototypes for objs */
int top_of_objt = 0; /* top of object index table */
int top_of_obj_array = 0;
int obj_chunk_size = 100; // default to 100
struct quest_data *quest_table = NULL; // array of quests
int top_of_questt = 0;
int top_of_quest_array = 0;
int quest_chunk_size = 25;
struct shop_data *shop_table = NULL; // array of shops
int top_of_shopt = 0; // ref to top element of shop_table
int top_of_shop_array = 0;
int shop_chunk_size = 25;
struct zone_data *zone_table; /* zone table */
int top_of_zone_table = 0; /* top element of zone tab */
struct message_list fight_messages[MAX_MESSAGES]; /* fighting messages */
struct player_index_element *player_table = NULL; /* index to plr file */
FILE *player_fl = NULL; /* file desc of player file */
int top_of_p_table = 0; /* ref to top of table */
int top_of_p_file = 0; /* ref of size of p file */
long top_idnum = 0; /* highest idnum in use */
int no_mail = 0; /* mail disabled? */
int mini_mud = 0; /* mini-mud mode? */
int no_rent_check = 0; /* skip rent check on boot? */
time_t boot_time = 0; /* time of mud boot */
int restrict = 0; /* level of game restriction */
sh_int r_mortal_start_room; /* rnum of mortal start room */
sh_int r_immort_start_room; /* rnum of immort start room */
sh_int r_frozen_start_room; /* rnum of frozen start room */
sh_int r_newbie_start_room; /* rnum of newbie start room */
char *credits = NULL; /* game credits */
char *news = NULL; /* mud news */
char *motd = NULL; /* message of the day - mortals */
char *imotd = NULL; /* message of the day - immorts */
char *help = NULL; /* help screen */
char *info = NULL; /* info page */
char *wizlist = NULL; /* list of higher gods */
char *immlist = NULL; /* list of lower gods */
char *background = NULL; /* background story */
char *handbook = NULL; /* handbook for new immortals */
char *policies = NULL; /* policies page */
char *hindex = NULL; /* index of help files */
FILE *help_fl = NULL; /* file for help text */
struct help_index_element *help_index = 0; /* the help table */
int top_of_helpt; /* top of help index table */
FILE *wizhelp_fl = NULL; /* file for wizhelp text */
struct help_index_element *wizhelp_index = 0;
int top_of_wizhelpt;
struct time_info_data time_info;/* the infomation about the time */
struct weather_data weather_info; /* the infomation about the weather */
struct player_special_data dummy_mob; /* dummy spec area for mobs */
struct reset_q_type reset_q; /* queue of zones to be reset */
/* local functions */
void setup_dir(FILE * fl, int room, int dir);
void index_boot(int mode);
void discrete_load(FILE * fl, int mode);
void parse_room(FILE * fl, int virtual_nr);
void parse_mobile(FILE * mob_f, int nr);
char *parse_object(FILE * obj_f, int nr);
void parse_shop(FILE * fl, int virtual_nr);
void parse_quest(FILE * fl, int virtual_nr);
void load_zones(FILE * fl, char *zonename);
void assign_mobiles(void);
void assign_objects(void);
void assign_rooms(void);
void assign_vehicles(void);
void assign_the_shopkeepers(void);
void assign_johnsons(void);
void randomize_shop_prices(void);
void build_player_index(void);
void char_to_store(struct char_data * ch, struct char_file_u * st);
void store_to_char(struct char_file_u * st, struct char_data * ch);
int is_empty(int zone_nr);
void reset_zone(int zone, int reboot);
int file_to_string(char *name, char *buf);
int file_to_string_alloc(char *name, char **buf);
void check_start_rooms(void);
void renum_world(void);
void renum_zone_table(void);
void log_zone_error(int zone, int cmd_no, char *message);
void reset_time(void);
void clear_char(struct char_data * ch);
void sprintbits(long vektor, char *outstring);
void tag_argument(char *argument, char *tag);
void clean_pfiles(void);
long asciiflag_conv(char *);
void kill_ems(char *);
void save_player_index(void);
int find_name(char *);
/* external functions */
extern struct descriptor_data *descriptor_list;
void load_messages(void);
void weather_and_time(int mode);
void boot_social_messages(void);
void update_obj_file(void); /* In objsave.c */
void sort_commands(void);
void sort_spells(void);
void load_banned(void);
void init_speech(void);
void init_quests(void);
void init_elevators(void);
void Read_Invalid_List(void);
struct help_index_element *build_help_index(FILE * fl, int *num);
extern void affect_total(struct char_data * ch);
extern void load_fixer_data(struct char_data *ch);
/* external vars */
extern int no_specials;
extern int rev_dir[];
extern int min_wizlist_lev;
/* external ascii pfile vars */
extern struct pclean_criteria_data pclean_criteria[];
extern int selfdelete_fastwipe;
extern int auto_pwipe;
extern const char *pc_race_types[];
/* memory objects */
extern class memoryClass *Mem;
extern int Crash_delete_file(char *name);
/*************************************************************************
* routines for booting the system *
*********************************************************************** */
/* this is necessary for the autowiz system */
void reboot_wizlists(void)
{
sprintf(buf, "nice ../bin/autowiz %d %s %d %s %d &", min_wizlist_lev,
WIZLIST_FILE, LVL_LEGEND, IMMLIST_FILE, (int) getpid());
system(buf);
file_to_string_alloc(WIZLIST_FILE, &wizlist);
file_to_string_alloc(IMMLIST_FILE, &immlist);
}
// create the index file here
void create_index()
{
int i = 0, j = 0;
char pletter = 'a';
FILE *index_f;
index_f = fopen("text/index", "w+");
if (!index_f) {
log("SYSERR: Failed opening lib/index.\n");
return;
}
for (; i < top_of_helpt; ++i) {
for (; (pletter <= 'z') && (i < top_of_helpt); ++pletter) {
fprintf(index_f, "\t\t\t\t ^W%c\n", pletter);
fprintf(index_f, "----------------------------------------------------------------------------^n\n");
for (j = (strlen(help_index[i].keyword) + 2); (i < top_of_helpt) &&
(*help_index[(i < top_of_helpt) ? i+1 : i].keyword <= pletter)
; ) {
j += (strlen(help_index[(i < top_of_helpt) ? i+1 : i].keyword) + 2);
if (j < 70)
fprintf(index_f, "%s, ", help_index[++i].keyword);
else {
j = (strlen(help_index[i].keyword) + 2);
fprintf(index_f, "%s\n", help_index[++i].keyword);
}
}
fprintf(index_f, "\n\n");
}
}
fclose(index_f);
}
ACMD(do_reboot)
{
int i;
one_argument(argument, arg);
if (!str_cmp(arg, "all") || *arg == '*') {
sprintf(buf, "nice ../bin/autowiz %d %s %d %s %d &", min_wizlist_lev,
WIZLIST_FILE, LVL_LEGEND, IMMLIST_FILE, (int) getpid());
system(buf);
file_to_string_alloc(NEWS_FILE, &news);
file_to_string_alloc(CREDITS_FILE, &credits);
file_to_string_alloc(MOTD_FILE, &motd);
file_to_string_alloc(IMOTD_FILE, &imotd);
file_to_string_alloc(HELP_PAGE_FILE, &help);
file_to_string_alloc(INFO_FILE, &info);
file_to_string_alloc(WIZLIST_FILE, &wizlist);
file_to_string_alloc(IMMLIST_FILE, &immlist);
file_to_string_alloc(POLICIES_FILE, &policies);
file_to_string_alloc(HANDBOOK_FILE, &handbook);
file_to_string_alloc(BACKGROUND_FILE, &background);
} else if (!str_cmp(arg, "wizlist")) {
sprintf(buf, "nice ../bin/autowiz %d %s %d %s %d &", min_wizlist_lev,
WIZLIST_FILE, LVL_LEGEND, IMMLIST_FILE, (int) getpid());
system(buf);
file_to_string_alloc(WIZLIST_FILE, &wizlist);
} else if (!str_cmp(arg, "immlist")) {
sprintf(buf, "nice ../bin/autowiz %d %s %d %s %d &", min_wizlist_lev,
WIZLIST_FILE, LVL_LEGEND, IMMLIST_FILE, (int) getpid());
system(buf);
file_to_string_alloc(IMMLIST_FILE, &immlist);
} else if (!str_cmp(arg, "news"))
file_to_string_alloc(NEWS_FILE, &news);
else if (!str_cmp(arg, "credits"))
file_to_string_alloc(CREDITS_FILE, &credits);
else if (!str_cmp(arg, "motd"))
file_to_string_alloc(MOTD_FILE, &motd);
else if (!str_cmp(arg, "imotd"))
file_to_string_alloc(IMOTD_FILE, &imotd);
else if (!str_cmp(arg, "help"))
file_to_string_alloc(HELP_PAGE_FILE, &help);
else if (!str_cmp(arg, "info"))
file_to_string_alloc(INFO_FILE, &info);
else if (!str_cmp(arg, "policy"))
file_to_string_alloc(POLICIES_FILE, &policies);
else if (!str_cmp(arg, "handbook"))
file_to_string_alloc(HANDBOOK_FILE, &handbook);
else if (!str_cmp(arg, "background"))
file_to_string_alloc(BACKGROUND_FILE, &background);
else if (!str_cmp(arg, "index")) {
create_index();
file_to_string_alloc(HINDEX_FILE, &hindex);
} else if (!str_cmp(arg, "xhelp")) {
if (help_fl)
fclose(help_fl);
if (!(help_fl = fopen(HELP_KWRD_FILE, "r")))
return;
else {
for (i = 0; i < top_of_helpt; i++)
delete [] help_index[i].keyword;
delete [] help_index;
help_index = build_help_index(help_fl, &top_of_helpt);
create_index();
}
} else if (!str_cmp(arg, "wizhelp")) {
if (wizhelp_fl)
fclose(wizhelp_fl);
if (!(wizhelp_fl = fopen(WIZHELP_FILE, "r")))
return;
else {
for (i = 0; i < top_of_wizhelpt; i++)
delete [] wizhelp_index[i].keyword;
delete [] wizhelp_index;
wizhelp_index = build_help_index(wizhelp_fl, &top_of_wizhelpt);
}
} else {
send_to_char("Unknown reboot option.\r\n", ch);
return;
}
send_to_char(OK, ch);
}
void boot_world(void)
{
log("Loading zone table.");
index_boot(DB_BOOT_ZON);
log("Loading rooms.");
index_boot(DB_BOOT_WLD);
log("Renumbering rooms.");
renum_world();
log("Checking start rooms.");
check_start_rooms();
log("Loading mobs and generating index.");
index_boot(DB_BOOT_MOB);
log("Loading objs and generating index.");
index_boot(DB_BOOT_OBJ);
//log("Loading vehicles and generating index.");
//index_boot(DB_BOOT_VEH);
log("Loading quests.");
index_boot(DB_BOOT_QST);
log("Loading shops.");
index_boot(DB_BOOT_SHP);
log("Renumbering zone table.");
renum_zone_table();
}
/* body of the booting system */
void boot_db(void)
{
int i;
log("Boot db -- BEGIN.");
log("Resetting the game time:");
reset_time();
log("Reading news, credits, help, bground, info & motds.");
file_to_string_alloc(NEWS_FILE, &news);
file_to_string_alloc(CREDITS_FILE, &credits);
file_to_string_alloc(MOTD_FILE, &motd);
file_to_string_alloc(IMOTD_FILE, &imotd);
file_to_string_alloc(HELP_PAGE_FILE, &help);
file_to_string_alloc(INFO_FILE, &info);
file_to_string_alloc(WIZLIST_FILE, &wizlist);
file_to_string_alloc(IMMLIST_FILE, &immlist);
file_to_string_alloc(POLICIES_FILE, &policies);
file_to_string_alloc(HANDBOOK_FILE, &handbook);
file_to_string_alloc(BACKGROUND_FILE, &background);
log("Opening help file.");
if (!(help_fl = fopen(HELP_KWRD_FILE, "r")))
log(" Could not open help file.");
else help_index = build_help_index(help_fl, &top_of_helpt);
log("Creating Help Index.");
create_index();
file_to_string_alloc(HINDEX_FILE, &hindex);
log("Opening wizhelp file.");
if (!(wizhelp_fl = fopen(WIZHELP_FILE, "r")))
log(" Could not open wizhelp file.");
else wizhelp_index = build_help_index(wizhelp_fl, &top_of_wizhelpt);
log("Booting World.");
boot_world();
log("Generating player index.");
build_player_index();
if(auto_pwipe)
{
log("Cleaning out the pfiles.");
clean_pfiles();
}
log("Loading fight messages.");
load_messages();
log("Loading social messages.");
boot_social_messages();
log("Assigning function pointers:");
if (!no_specials) {
log(" Mobiles.");
assign_mobiles();
log(" Johnsons.");
assign_johnsons();
log(" Shopkeepers.");
assign_the_shopkeepers();
randomize_shop_prices();
log(" Objects.");
assign_objects();
log(" Rooms.");
assign_rooms();
// log(" Vehicles.");
// assign_vehicles();
}
log("Sorting command list and spells.");
sort_commands();
sort_spells();
log("Booting mail system.");
if (!scan_file()) {
log(" Mail boot failed -- Mail system disabled");
no_mail = 1;
}
log("Reading banned site and invalid-name list.");
load_banned();
Read_Invalid_List();
log("Initializing mob speech system.");
init_speech();
log("Initializing elevator system.");
init_elevators();
if (!no_rent_check) {
log("Deleting timed-out crash and rent files:");
update_obj_file();
log("Done.");
}
for (i = 0; i <= top_of_zone_table; i++) {
sprintf(buf2, "Resetting %s (rooms %d-%d).", zone_table[i].name,
(i ? (zone_table[i - 1].top + 1) : 0), zone_table[i].top);
log(buf2);
reset_zone(i, 1);
}
reset_q.head = reset_q.tail = NULL;
if (!mini_mud) {
log("Booting houses.");
House_boot();
}
boot_time = time(0);
log("Boot db -- DONE.");
}
/* reset the time in the game from file
weekday is lost on reboot.... implement
something different if this is mission
breaking behavior */
void reset_time(void)
{
extern struct time_info_data mud_time_passed(time_t t2, time_t t1);
mud_boot_time = time(0);
time_info = mud_time_passed(beginning_of_time, time(0));
if (time_info.year < 2050)
time_info.year = 2050;
time_info.minute = 0;
time_info.weekday = 0;
if (time_info.hours <= 5)
weather_info.sunlight = SUN_DARK;
else if (time_info.hours == 6)
weather_info.sunlight = SUN_RISE;
else if (time_info.hours <= 18)
weather_info.sunlight = SUN_LIGHT;
else if (time_info.hours == 19)
weather_info.sunlight = SUN_SET;
else weather_info.sunlight = SUN_DARK;
sprintf(buf, " Current Gametime: %d/%d/%d %d:00.", time_info.month,
time_info.day, time_info.year,
(time_info.hours % 12) == 0 ? 12 : time_info.hours % 12);
log(buf);
weather_info.pressure = 960;
if ((time_info.month >= 7) && (time_info.month <= 12))
weather_info.pressure += dice(1, 50);
else weather_info.pressure += dice(1, 80);
if(time_info.day < 7)
weather_info.moonphase = MOON_NEW;
else if(time_info.day > 7 && time_info.day < 14)
weather_info.moonphase = MOON_WAX;
else if(time_info.day > 14 && time_info.day < 21)
weather_info.moonphase = MOON_FULL;
else
weather_info.moonphase = MOON_WANE;
weather_info.change = 0;
if (weather_info.pressure <= 980)
weather_info.sky = SKY_LIGHTNING;
else if (weather_info.pressure <= 1000)
weather_info.sky = SKY_RAINING;
else if (weather_info.pressure <= 1020)
weather_info.sky = SKY_CLOUDY;
else weather_info.sky = SKY_CLOUDLESS;
}
/* generate index table for the player file */
void build_player_index(void)
{
int rec_count = 0, i,j;
FILE *plr_index;
char index_name[40], line[256], bits[64];
char arg2[80];
long idNum;
int lvl;
long last;
sprintf(index_name, "%s", PLR_INDEX_FILE);
if(!(plr_index = fopen(index_name, "r+b")))
{
top_of_p_table = -1;
log("No player index file! First new char will be IMP!");
return;
}
while(get_line(plr_index, line))
if(*line != '~')
rec_count++;
rewind(plr_index);
if(rec_count == 0)
{
player_table = NULL;
top_of_p_file = top_of_p_table = -1;
return;
}
// Hack here to make all name lower case in index file
player_table = new struct player_index_element[rec_count];
for(i = 0; i < rec_count; i++) {
get_line(plr_index, line);
sscanf(line, "%ld %s %d %s %ld",&idNum,arg2,&lvl,bits,&last);
player_table[i].name = new char[strlen(arg2) + 1];
for (j = 0;
(*(player_table[i].name + j) = LOWER(*(arg2 + j))); j++);
player_table[i].id = idNum;
player_table[i].level = lvl;
player_table[i].last = last;
player_table[i].flags = asciiflag_conv(bits);
top_idnum = MAX(top_idnum, player_table[i].id);
}
fclose(plr_index);
top_of_p_file = top_of_p_table = i - 1;
}
/* function to count how many hash-mark delimited records exist in a file */
int count_hash_records(FILE * fl)
{
char buf[128];
int count = 0;
while (fgets(buf, 128, fl))
if (*buf == '#')
count++;
return count;
}
void index_boot(int mode)
{
char *index_filename, *prefix;
FILE *index, *db_file;
int rec_count = 0;
switch (mode) {
case DB_BOOT_WLD:
prefix = WLD_PREFIX;
break;
case DB_BOOT_MOB:
prefix = MOB_PREFIX;
break;
case DB_BOOT_OBJ:
prefix = OBJ_PREFIX;
break;
case DB_BOOT_ZON:
prefix = ZON_PREFIX;
break;
case DB_BOOT_SHP:
prefix = SHP_PREFIX;
break;
case DB_BOOT_QST:
prefix = QST_PREFIX;
break;
default:
log("SYSERR: Unknown subcommand to index_boot!");
exit(1);
break;
}
if (mini_mud)
index_filename = MINDEX_FILE;
else index_filename = INDEX_FILE;
sprintf(buf2, "%s/%s", prefix, index_filename);
if (!(index = fopen(buf2, "r"))) {
sprintf(buf1, "Error opening index file '%s'", buf2);
perror(buf1);
exit(1);
}
/* first, count the number of records in the file so we can calloc */
fscanf(index, "%s\n", buf1);
while (*buf1 != '$') {
sprintf(buf2, "%s/%s", prefix, buf1);
if (!(db_file = fopen(buf2, "r"))) {
/* geez, no need to not boot just cause it's not found... */
//perror(buf2);
//exit(1);
sprintf(buf, "Unable to find file %s.", buf2);
mudlog(buf, NULL, LOG_SYSLOG, TRUE);
} else {
if (mode == DB_BOOT_ZON)
rec_count++;
else rec_count += count_hash_records(db_file);
fclose(db_file);
}
fscanf(index, "%s\n", buf1);
}
if (!rec_count) {
log("SYSERR: boot error - 0 records counted");
exit(1);
}
rec_count++;
switch (mode) {
case DB_BOOT_WLD:
// here I'm booting with 100 extra slots for creation
world = new struct room_data[rec_count + world_chunk_size];
memset((char *) world, 0, (sizeof(struct room_data) *
(rec_count + world_chunk_size)));
top_of_world_array = rec_count + world_chunk_size; // assign the real size of the array
break;
case DB_BOOT_MOB:
// here I'm booting with 100 extra slots for creation
mob_proto = new struct char_data[rec_count + mob_chunk_size];
memset((char *) mob_proto, 0, (sizeof(struct char_data) *
(rec_count + mob_chunk_size)));
mob_index = new struct index_data[rec_count + mob_chunk_size];
memset((char *) mob_index, 0, (sizeof(struct index_data) *
(rec_count + mob_chunk_size)));
top_of_mob_array = rec_count + mob_chunk_size; // assign the real size of the array
break;
case DB_BOOT_OBJ:
// here I'm booting with 100 extra slots for creation
obj_proto = new struct obj_data[rec_count + obj_chunk_size];
memset((char *) obj_proto, 0, (sizeof(struct obj_data) *
(rec_count + obj_chunk_size)));
obj_index = new struct index_data[rec_count + obj_chunk_size];
memset((char *) obj_index, 0, (sizeof(struct index_data) *
(rec_count + obj_chunk_size)));
top_of_obj_array = rec_count + obj_chunk_size;
break;
/* This is hacked. I'm sure we will need to fix it. -- Dunk. */
// case DB_BOOT_VEH:
// veh_proto = new struct obj_data[rec_count + veh_chunk_size];
// memset((char *) veh_index, 0, (sizeof(struct veh_data) *
// (rec_count + veh_chunk_size)));
// veh_index = new struct veh_data[rec_count + veh_chunk_size];
// memset((char *) veh_index, 0, (sizeof(struct veh_data) *
// (rec_count + veh_chunk_size)));
//
// top_of_veh_array = rec_count + veh_chunk_size;
// break;
/* End of Hack */
case DB_BOOT_ZON:
// the zone table is pretty small, so it's no biggie
zone_table = new struct zone_data[rec_count];
memset((char *) zone_table, 0, (sizeof(struct zone_data) * rec_count));
break;
case DB_BOOT_SHP:
shop_table = new struct shop_data[rec_count + shop_chunk_size];
memset((char *) shop_table, 0, (sizeof(struct shop_data) *
(rec_count + shop_chunk_size)));
top_of_shop_array = rec_count + shop_chunk_size;
break;
case DB_BOOT_QST:
quest_table = new struct quest_data[rec_count + quest_chunk_size];
memset((char *) quest_table, 0, (sizeof(struct quest_data) *
(rec_count + quest_chunk_size)));
top_of_quest_array = rec_count + quest_chunk_size;
break;
}
rewind(index);
fscanf(index, "%s\n", buf1);
while (*buf1 != '$') {
sprintf(buf2, "%s/%s", prefix, buf1);
if (!(db_file = fopen(buf2, "r"))) {
sprintf(buf, "Unable to find file %s.", buf2);
mudlog(buf, NULL, LOG_SYSLOG, TRUE);
// perror(buf2);
// exit(1);
} else {
switch (mode) {
case DB_BOOT_WLD:
case DB_BOOT_OBJ:
case DB_BOOT_MOB:
case DB_BOOT_SHP:
case DB_BOOT_QST:
discrete_load(db_file, mode);
break;
case DB_BOOT_ZON:
load_zones(db_file, buf2);
break;
}
fclose(db_file);
}
fscanf(index, "%s\n", buf1);
}
}
void discrete_load(FILE * fl, int mode)
{
int nr = -1, last = 0;
char line[256];
/* Note commented-out "veh" ref here */
char *modes[] = {"world", "mob", "obj", /* "veh", */ "zon", "shop", "quest"};
for (;;) {
/*
* we have to do special processing with the obj files because they have
* no end-of-record marker :(
*/
if (mode != DB_BOOT_OBJ || nr < 0)
if (!get_line(fl, line)) {
fprintf(stderr, "Format error after %s #%d\n", modes[mode], nr);
exit(1);
}
if (*line == '$')
return;
if (*line == '#') {
last = nr;
if (sscanf(line, "#%d", &nr) != 1) {
fprintf(stderr, "Format error after %s #%d\n", modes[mode], last);
exit(1);
}
if (nr >= 99999)
return;
else switch (mode) {
case DB_BOOT_WLD:
parse_room(fl, nr);
break;
case DB_BOOT_MOB:
parse_mobile(fl, nr);
break;
case DB_BOOT_OBJ:
strcpy(line, parse_object(fl, nr));
break;
/* hack begins for vehicles */
// case DB_BOOT_VEH:
// parse_veh(fl, nr);
// break;
/* end vehicle addition */
case DB_BOOT_QST:
parse_quest(fl, nr);
break;
case DB_BOOT_SHP:
parse_shop(fl, nr);
break;
}
} else {
fprintf(stderr, "Format error in %s file near %s #%d\n",
modes[mode], modes[mode], nr);
fprintf(stderr, "Offending line: '%s'\n", line);
exit(1);
}
}
}
long asciiflag_conv(char *flag)
{
long flags = 0;
int is_number = 1;
register char *p;
for (p = flag; *p; p++) {
if (islower(*p))
flags |= 1 << (*p - 'a');
else if (isupper(*p))
flags |= 1 << (26 + (*p - 'A'));
if (!isdigit(*p))
is_number = 0;
}
if (is_number)
flags = atol(flag);
return flags;
}
/* Ok around here somewhere,
* we will need somebody to
* code up the function to
* load the vehicles to the
* mud... void parse_room()
* and stuff... I'm too new
* at this to write anything
* as complex as what is
* written below for similar
* purposes. --Dunk */
/* load the rooms */
void parse_room(FILE * fl, int virtual_nr)
{
static int room_nr = 0, zone = 0;
int t[10], i;
char line[256], flags[128];
struct extra_descr_data *new_descr;
struct use_descr_data *use_descr;
sprintf(buf2, "room #%d", virtual_nr);
if (virtual_nr <= (zone ? zone_table[zone - 1].top : -1)) {
fprintf(stderr, "Room #%d is below zone %d.\n", virtual_nr, zone);
exit(1);
}
while (virtual_nr > zone_table[zone].top)
if (++zone > top_of_zone_table) {
fprintf(stderr, "Room %d is outside of any zone.\n", virtual_nr);
exit(1);
}
world[room_nr].zone = zone;
world[room_nr].number = virtual_nr;
world[room_nr].name = fread_string(fl, buf2);
if (!world[room_nr].name)
world[room_nr].name = str_dup("An unnamed room");
world[room_nr].description = fread_string(fl, buf2);
if (!world[room_nr].description)
world[room_nr].description = str_dup("You stand in an empty room.");
// we check for the old version too
if (!get_line(fl, line) || sscanf(line, " %d %s %d %d ", t, flags, t + 2, t + 3) != 4)
if (sscanf(line, " %d %s %d ", t, flags, t+2) != 3)
{
fprintf(stderr, "Old format error in room #%d\n", virtual_nr);
exit(1);
}
world[room_nr].spec = t[0];
world[room_nr].room_flags = asciiflag_conv(flags);
world[room_nr].sector_type = t[2];
world[room_nr].rating = t[3];
world[room_nr].func = NULL;
world[room_nr].contents = NULL;
world[room_nr].people = NULL;
world[room_nr].light = 0; /* Zero light sources */
world[room_nr].x_coord = 0;
world[room_nr].y_coord = 0;
world[room_nr].z_coord = 0;
for (i = 0; i < NUM_OF_DIRS; i++)
world[room_nr].dir_option[i] = NULL;
world[room_nr].ex_description = NULL;
sprintf(buf, "Format error in room #%d (expecting D/E/S)", virtual_nr);
for (;;) {
if (!get_line(fl, line)) {
fprintf(stderr, "%s\n", buf);
exit(1);
}
switch (*line) {
case 'D':
setup_dir(fl, room_nr, atoi(line + 1));
break;
case 'E':
new_descr = new extra_descr_data;
new_descr->keyword = fread_string(fl, buf2);
new_descr->description = fread_string(fl, buf2);
new_descr->next = world[room_nr].ex_description;
world[room_nr].ex_description = new_descr;
break;
case 'M':
world[room_nr].msp_trigger = fread_string(fl, buf2);
break;
case 'S': /* end of room */
top_of_world = room_nr++;
return;
case 'C':
sscanf(line, "%s %d %d %d", flags , t , t + 1 ,t + 2);
world[room_nr].x_coord = t[0];
world[room_nr].y_coord = t[1];
world[room_nr].z_coord = t[2];
break;
default:
fprintf(stderr, "%s\n", buf);
exit(1);
break;
}
}
}
/* read direction data */
void setup_dir(FILE * fl, int room, int dir)
{
int t[7];
char line[256];
int retval;
sprintf(buf2, "room #%d, direction D%d", world[room].number, dir);
world[room].dir_option[dir] = new room_direction_data;
world[room].dir_option[dir]->general_description = fread_string(fl, buf2);
world[room].dir_option[dir]->keyword = fread_string(fl, buf2);
if (!get_line(fl, line)) {
fprintf(stderr, "Format error, %s\n", buf2);
exit(1);
}
if ((retval = sscanf(line, " %d %d %d %d %d %d %d", t, t + 1, t + 2, t + 3,
t + 4, t + 5, t + 6)) < 4) {
fprintf(stderr, "Format error, %s\n", buf2);
exit(1);
}
if (t[0] == 1)
world[room].dir_option[dir]->exit_info = EX_ISDOOR;
else if (t[0] == 2)
world[room].dir_option[dir]->exit_info = EX_ISDOOR | EX_PICKPROOF;
else world[room].dir_option[dir]->exit_info = 0;
world[room].dir_option[dir]->key = t[1];
world[room].dir_option[dir]->to_room = MAX(0, t[2]);
world[room].dir_option[dir]->key_level = t[3];
world[room].dir_option[dir]->material = (retval > 4) ? t[4] : 5;
world[room].dir_option[dir]->barrier = (retval > 5) ? t[5] : 4;
world[room].dir_option[dir]->condition = (retval > 5) ? t[5] : 4;
world[room].dir_option[dir]->hidden = (retval > 6) ? t[6] : 0;
}
/* make sure the start rooms exist & resolve their vnums to rnums */
void check_start_rooms(void)
{
extern sh_int mortal_start_room;
extern sh_int immort_start_room;
extern sh_int frozen_start_room;
extern sh_int newbie_start_room;
if ((r_mortal_start_room = real_room(mortal_start_room)) < 0) {
log("SYSERR: Mortal start room does not exist. Change in config.c.");
exit(1);
}
if ((r_immort_start_room = real_room(immort_start_room)) < 0) {
if (!mini_mud)
log("SYSERR: Warning: Immort start room does not exist. Change in config.c.");
r_immort_start_room = r_mortal_start_room;
}
if ((r_frozen_start_room = real_room(frozen_start_room)) < 0) {
if (!mini_mud)
log("SYSERR: Warning: Frozen start room does not exist. Change in config.c.");
r_frozen_start_room = r_mortal_start_room;
}
if ((r_newbie_start_room = real_room(newbie_start_room)) < 0) {
if (!mini_mud)
log("SYSERR: Warning: Newbie start room does not exist. Change in config.c.");
r_newbie_start_room = r_mortal_start_room;
}
}
/* resolve all vnums into rnums in the world */
void renum_world(void)
{
register int room, door;
/* before renumbering the exits, copy them to to_room_vnum */
for (room = 0; room <= top_of_world; room++)
for (door = 0; door < NUM_OF_DIRS; door++)
if (world[room].dir_option[door]) {
/* copy */
world[room].dir_option[door]->to_room_vnum =
world[room].dir_option[door]->to_room;
if (world[room].dir_option[door]->to_room != NOWHERE)
world[room].dir_option[door]->to_room =
real_room(world[room].dir_option[door]->to_room);
}
}
#define ZCMD zone_table[zone].cmd[cmd_no]
/* resulve vnums into rnums in the zone reset tables */
void renum_zone_table(void)
{
int zone, cmd_no, a, b;
for (zone = 0; zone <= top_of_zone_table; zone++)
for (cmd_no = 0; cmd_no < zone_table[zone].num_cmds; cmd_no++) {
a = b = 0;
switch (ZCMD.command) {
case 'M':
a = ZCMD.arg1 = real_mobile(ZCMD.arg1);
b = ZCMD.arg3 = real_room(ZCMD.arg3);
break;
case 'O':
a = ZCMD.arg1 = real_object(ZCMD.arg1);
if (ZCMD.arg3 != NOWHERE)
b = ZCMD.arg3 = real_room(ZCMD.arg3);
break;
case 'G': case 'C':
a = ZCMD.arg1 = real_object(ZCMD.arg1);
break;
case 'E':
a = ZCMD.arg1 = real_object(ZCMD.arg1);
break;
case 'P':
a = ZCMD.arg1 = real_object(ZCMD.arg1);
b = ZCMD.arg3 = real_object(ZCMD.arg3);
break;
case 'D':
a = ZCMD.arg1 = real_room(ZCMD.arg1);
break;
case 'R': /* rem obj from room */
a = ZCMD.arg1 = real_room(ZCMD.arg1);
b = ZCMD.arg2 = real_object(ZCMD.arg2);
break;
case 'N':
a = ZCMD.arg1 = real_object(ZCMD.arg1);
break;
}
if (a < 0 || b < 0) {
if (!mini_mud)
log_zone_error(zone, cmd_no, "Invalid vnum, cmd disabled");
ZCMD.command = '*';
}
}
}
void parse_mobile(FILE * mob_f, int nr)
{
static int i = 0;
int j, t[10], x;
char line[256], *tmpptr;
char f1[128], f2[128];
mob_index[i].virt = nr;
mob_index[i].number = 0;
mob_index[i].func = NULL;
clear_char(mob_proto + i);
mob_proto[i].player_specials = &dummy_mob;
sprintf(buf2, "mob vnum %d", nr);
/***** String data *** */
mob_proto[i].player.name = fread_string(mob_f, buf2);
tmpptr = mob_proto[i].player.short_descr = fread_string(mob_f, buf2);
if (tmpptr && *tmpptr)
if (!str_prefix("A ", tmpptr) || !str_prefix("An ", tmpptr) ||
!str_prefix("The ", tmpptr))
*tmpptr = LOWER(*tmpptr);
if (!tmpptr)
mob_proto[i].player.short_descr = str_dup("unnamed");
mob_proto[i].player.long_descr = fread_string(mob_f, buf2);
if (!tmpptr)
mob_proto[i].player.long_descr = str_dup("An unnamed mob");
mob_proto[i].player.description = fread_string(mob_f, buf2);
if (!tmpptr)
mob_proto[i].player.description = str_dup("You see an unnamed mob.");
mob_proto[i].player.title = NULL;
mob_proto[i].mob_specials.arrive = fread_string(mob_f, buf2);
mob_proto[i].mob_specials.leave = fread_string(mob_f, buf2);
/* *** Numeric data *** */
get_line(mob_f, line);
if (sscanf(line, "%s %s %d %d %d", f1, f2, t + 2, t + 3, t + 4) != 5) {
fprintf(stderr, "Format error in mob#%d, 1st number line\n"
"...expecting line of form '# # # # #'\n", nr);
exit(1);
}
MOB_FLAGS(mob_proto + i) = asciiflag_conv(f1);
SET_BIT(MOB_FLAGS(mob_proto + i), MOB_ISNPC);
AFF_FLAGS(mob_proto + i) = asciiflag_conv(f2);
GET_ALIGNMENT(mob_proto + i) = t[2];
GET_BANK(mob_proto + i) = t[3];
GET_KARMA(mob_proto + i) = t[4];
/* scan in mob abilities, yep, all 9 of them - Flynn */
get_line(mob_f, line);
if (sscanf(line, "%d %d %d %d %d %d %d %d %d", t, t+1, t+2, t+3, t+4, t+5, t+6,
t+7, t+8) != 9) {
fprintf(stderr, "Format error in mob#%d, abilities line (second line)\n"
"...expecting line of form '# # # # # # # # #'\n", nr);
exit(1);
}
mob_proto[i].real_abils.bod = t[0];
mob_proto[i].real_abils.qui = t[1];
mob_proto[i].real_abils.str = t[2];
mob_proto[i].real_abils.cha = t[3];
mob_proto[i].real_abils.intel = t[4];
mob_proto[i].real_abils.wil = t[5];
mob_proto[i].real_abils.mag = t[7] * 100;
mob_proto[i].real_abils.rmag = t[7] * 100;
mob_proto[i].real_abils.rea = (t[1] + t[4]) >> 1;
mob_proto[i].real_abils.ess = 600;
mob_proto[i].real_abils.bod_index = t[0] * 100;
/* scan in mob skills, max 5 for now - Flynn */
get_line(mob_f, line);
if (sscanf(line, "%d %d %d %d %d %d %d %d %d %d", t, t+1, t+2, t+3, t+4,
t+5, t+6, t+7, t+8, t+9) != 10) {
fprintf(stderr, "Format error in mob#%d, skills line (third line)\n"
"...expecting line of form '# # # # # # # # # #'\n", nr);
exit(1);
}
if (t[0] > MAX_SPELLS && t[0] < MAX_SKILLS)
mob_proto[i].char_specials.saved.skills[t[0]] = t[1];
if (t[2] > MAX_SPELLS && t[2] < MAX_SKILLS)
mob_proto[i].char_specials.saved.skills[t[2]] = t[3];
if (t[4] > MAX_SPELLS && t[4] < MAX_SKILLS)
mob_proto[i].char_specials.saved.skills[t[4]] = t[5];
if (t[6] > MAX_SPELLS && t[6] < MAX_SKILLS)
mob_proto[i].char_specials.saved.skills[t[6]] = t[7];
if (t[8] > MAX_SPELLS && t[8] < MAX_SKILLS)
mob_proto[i].char_specials.saved.skills[t[8]] = t[9];
// gotta do this so when the editors write the skills, the values are correct
mob_proto[i].mob_specials.mob_skills[0] = t[0];
mob_proto[i].mob_specials.mob_skills[1] = t[1];
mob_proto[i].mob_specials.mob_skills[2] = t[2];
mob_proto[i].mob_specials.mob_skills[3] = t[3];
mob_proto[i].mob_specials.mob_skills[4] = t[4];
mob_proto[i].mob_specials.mob_skills[5] = t[5];
mob_proto[i].mob_specials.mob_skills[6] = t[6];
mob_proto[i].mob_specials.mob_skills[7] = t[7];
mob_proto[i].mob_specials.mob_skills[8] = t[8];
mob_proto[i].mob_specials.mob_skills[9] = t[9];
get_line(mob_f, line);
if (sscanf(line, " %d %d %d %d %d %d ",
t, t + 1, t + 2, t + 3, t + 4, t + 5) != 6) {
fprintf(stderr, "Format error in mob #%d, number line 4.\n"
"...expecting line of form '# # # # # #'\n", nr);
exit(1);
}
GET_LEVEL(mob_proto + i) = t[0];
mob_proto[i].points.ballistic = t[1];
mob_proto[i].points.impact = t[2];
mob_proto[i].points.max_physical = t[3] * 100;
mob_proto[i].points.physical = t[3] * 100;
mob_proto[i].points.max_mental = t[4] * 100;
mob_proto[i].points.mental = t[4] * 100;
GET_NUYEN(mob_proto + i) = t[5];
mob_proto[i].points.sustained = 0;
mob_proto[i].points.grade = 0;
/* set pools to 0 initially, affect total will correct them */
mob_proto[i].real_abils.astral_pool = 0;
mob_proto[i].real_abils.defense_pool = 0;
mob_proto[i].real_abils.combat_pool = 0;
mob_proto[i].real_abils.offense_pool = 0;
mob_proto[i].real_abils.hacking_pool = 0;
mob_proto[i].real_abils.magic_pool = 0;
get_line(mob_f, line);
if (sscanf(line, " %d %d %d %d %d %d %d", t, t + 1, t + 2, t + 3, t + 4,
t + 5, t + 6) != 7) {
fprintf(stderr, "Format error in mob #%d, number line 5.\n"
"...expecting line of form '# # # # # # #'\n", nr);
exit(1);
}
mob_proto[i].char_specials.position = t[0];
mob_proto[i].char_specials.saved.idnum = -1;
mob_proto[i].mob_specials.mood = number(-5, 4);
mob_proto[i].mob_specials.default_pos = t[1];
mob_proto[i].player.sex = t[2];
mob_proto[i].mob_specials.attack_type = (t[3] < TYPE_HIT) ? t[3] + TYPE_HIT : t[3];
mob_proto[i].player.race = t[4];
mob_proto[i].player.weight = t[5];
mob_proto[i].player.height = t[6];
for (j = 0; j < 3; j++)
GET_COND(mob_proto + i, j) = -1;
mob_proto[i].aff_abils = mob_proto[i].real_abils;
for (j = 0; j < NUM_WEARS; j++)
mob_proto[i].equipment[j] = NULL;
mob_proto[i].cyberware = NULL;
mob_proto[i].bioware = NULL;
mob_proto[i].nr = i;
mob_proto[i].desc = NULL;
top_of_mobt = i++;
}
/* read all objects from obj file; generate index and prototypes */
char *parse_object(FILE * obj_f, int nr)
{
static int i = 0, retval;
static char line[256];
int t[10], j;
char *tmpptr;
char f1[256], f2[256];
struct extra_descr_data *new_descr;
struct use_descr_data *use_descr;
obj_index[i].virt = nr;
obj_index[i].number = 0;
obj_index[i].func = NULL;
clear_object(obj_proto + i);
obj_proto[i].in_room = NOWHERE;
obj_proto[i].item_number = i;
sprintf(buf2, "object #%d", nr);
/* *** string data *** */
if ((obj_proto[i].name = fread_string(obj_f, buf2)) == NULL) {
fprintf(stderr, "Null obj name or format error at or near %s\n", buf2);
obj_proto[i].name = str_dup("unnamed");
}
tmpptr = obj_proto[i].short_description = fread_string(obj_f, buf2);
if (tmpptr && *tmpptr)
if (!str_prefix("A ", tmpptr) || !str_prefix("An ", tmpptr) ||
!str_prefix("The ", tmpptr))
*tmpptr = LOWER(*tmpptr);
if (!tmpptr)
obj_proto[i].short_description = str_dup("an unnamed object");
tmpptr = obj_proto[i].description = fread_string(obj_f, buf2);
if (tmpptr && *tmpptr)
*tmpptr = UPPER(*tmpptr);
if (!tmpptr)
obj_proto[i].description = str_dup("An unnamed object sits here.");
obj_proto[i].long_description = fread_string(obj_f, buf2);
if (!tmpptr)
obj_proto[i].long_description = str_dup("You see an uncreative object.");
/* *** numeric data *** */
/*
Modify this code to be able to handle diff formats
*/
if (!get_line(obj_f, line) ||
(retval = sscanf(line, " %d %s %s %d %d %d ", t, f1, f2, t + 1, t + 2,
t + 3)) != 6)
if ((retval = sscanf(line, " %d %s %s ", t, f1, f2)) != 3)
{
fprintf(stderr, "Format error in first numeric line (expecting 3 or 5 args, got %d), %s\n",
retval, buf2);
exit(1);
}
obj_proto[i].obj_flags.type_flag = t[0];
obj_proto[i].obj_flags.extra_flags = asciiflag_conv(f1);
obj_proto[i].obj_flags.wear_flags = asciiflag_conv(f2);
obj_proto[i].obj_flags.material = (retval > 3) ? t[1] : 5;
obj_proto[i].obj_flags.barrier = MAX(1, (retval > 4) ? t[2] : 3);
obj_proto[i].obj_flags.condition = obj_proto[i].obj_flags.barrier;
obj_proto[i].obj_flags.bitvector = (retval > 5) ? t[3] : 0;
obj_proto[i].obj_flags.quest_id = 0;
/*
Modify this code to be able to handle diff formats
*/
if (!get_line(obj_f, line) ||
(retval = sscanf(line, "%d %d %d %d %d %d %d %d %d %d", t, t + 1, t + 2,
t + 3, t + 4, t + 5, t + 6, t + 7, t + 8, t + 9)) < 7)
{
fprintf(stderr, "Format error in second numeric line (expecting 7 args, got %d), %s\n",
retval, buf2);
exit(1);
}
obj_proto[i].obj_flags.value[0] = t[0];
obj_proto[i].obj_flags.value[1] = t[1];
obj_proto[i].obj_flags.value[2] = t[2];
// make sure to adapt new values
if ((obj_proto[i].obj_flags.type_flag == ITEM_WEAPON) && (t[3] < TYPE_HIT))
obj_proto[i].obj_flags.value[3] = t[3] + TYPE_HIT;
else
obj_proto[i].obj_flags.value[3] = t[3];
obj_proto[i].obj_flags.value[4] = t[4];
obj_proto[i].obj_flags.value[5] = t[5];
obj_proto[i].obj_flags.value[6] = t[6];
obj_proto[i].obj_flags.value[7] = (retval < 10 ? 0 : t[7]);
obj_proto[i].obj_flags.value[8] = (retval < 10 ? 0 : t[8]);
obj_proto[i].obj_flags.value[9] = (retval < 10 ? 0 : t[9]);
/*
Modify this code to be able to handle diff formats
*/
if (!get_line(obj_f, line) ||
(retval = sscanf(line, "%d %d %d", t, t + 1, t + 2)) != 3) {
fprintf(stderr, "Format error in third numeric line (expecting 3 args, got %d), %s\n", retval, buf2);
exit(1);
}
obj_proto[i].obj_flags.weight = t[0];
obj_proto[i].obj_flags.cost = t[1];
obj_proto[i].obj_flags.cost_per_day = t[2];
/* *** extra descriptions and affect fields *** */
for (j = 0; j < MAX_OBJ_AFFECT; j++) {
obj_proto[i].affected[j].location = APPLY_NONE;
obj_proto[i].affected[j].modifier = 0;
}
strcat(buf2, ", after numeric constants (expecting E/A/#xxx)");
j = 0;
for (;;) {
if (!get_line(obj_f, line)) {
fprintf(stderr, "Format error in %s\n", buf2);
exit(1);
}
switch (*line) {
case 'E':
new_descr = new extra_descr_data;
new_descr->keyword = fread_string(obj_f, buf2);
new_descr->description = fread_string(obj_f, buf2);
new_descr->next = obj_proto[i].ex_description;
obj_proto[i].ex_description = new_descr;
break;
case 'U':
use_descr = new use_descr_data;
use_descr->keyword = fread_string(obj_f, buf2);
use_descr->description1 = fread_string(obj_f, buf2);
use_descr->description2 = fread_string(obj_f, buf2);
use_descr->next = obj_proto[i].use_description;
obj_proto[i].use_description = use_descr;
break;
case 'A':
if (j >= MAX_OBJ_AFFECT) {
fprintf(stderr, "Too many A fields (%d max), %s\n", MAX_OBJ_AFFECT, buf2);
exit(1);
}
get_line(obj_f, line);
sscanf(line, " %d %d ", t, t + 1);
obj_proto[i].affected[j].location = t[0];
obj_proto[i].affected[j].modifier = t[1];
j++;
break;
case '$':
case '#':
top_of_objt = i++;
return line;
break;
default:
fprintf(stderr, "Format error in %s\n", buf2);
exit(1);
break;
}
}
}
void parse_quest(FILE * fl, int virtual_nr)
{
static int quest_nr = 0;
int j, t[12];
char line[256];
quest_table[quest_nr].virt = virtual_nr;
get_line(fl, line);
if (sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d", t, t + 1, t + 2, t + 3,
t + 4, t + 5, t + 6, t + 7, t + 8, t + 9, t + 10, t + 11) != 12) {
fprintf(stderr, "Format error in quest #%d, expecting # # # # # # # # #\n",
quest_nr);
exit(1);
}
quest_table[quest_nr].johnson = t[0];
quest_table[quest_nr].time = t[1];
quest_table[quest_nr].min_rep = t[2];
quest_table[quest_nr].max_rep = t[3];
quest_table[quest_nr].nuyen = t[4];
quest_table[quest_nr].karma = t[5];
quest_table[quest_nr].reward = (real_object(t[6]) > -1 ? t[6] : -1);
quest_table[quest_nr].num_objs = t[7];
quest_table[quest_nr].num_mobs = t[8];
quest_table[quest_nr].s_time = t[9];
quest_table[quest_nr].e_time = t[10];
quest_table[quest_nr].s_room = t[11];
if (quest_table[quest_nr].num_objs > 0) {
quest_table[quest_nr].obj = new quest_om_data[quest_table[quest_nr].num_objs];
for (j = 0; j < quest_table[quest_nr].num_objs; j++) {
get_line(fl, line);
if (sscanf(line, "%d %d %d %d %d %d %d %d", t, t + 1, t + 2, t + 3,
t + 4, t + 5, t + 6, t + 7) != 8) {
fprintf(stderr, "Format error in quest #%d, obj #%d\n", quest_nr, j);
exit(1);
}
quest_table[quest_nr].obj[j].vnum = t[0];
quest_table[quest_nr].obj[j].nuyen = t[1];
quest_table[quest_nr].obj[j].karma = t[2];
quest_table[quest_nr].obj[j].load = (byte) t[3];
quest_table[quest_nr].obj[j].objective = (byte) t[4];
quest_table[quest_nr].obj[j].l_data = t[5];
quest_table[quest_nr].obj[j].l_data2 = t[6];
quest_table[quest_nr].obj[j].o_data = t[7];
}
} else quest_table[quest_nr].obj = NULL;
if (quest_table[quest_nr].num_mobs > 0) {
quest_table[quest_nr].mob = new quest_om_data[quest_table[quest_nr].num_mobs];
for (j = 0; j < quest_table[quest_nr].num_mobs; j++) {
get_line(fl, line);
if (sscanf(line, "%d %d %d %d %d %d %d %d", t, t + 1, t + 2, t + 3,
t + 4, t + 5, t + 6, t + 7) != 8) {
fprintf(stderr, "Format error in quest #%d, mob #%d\n", quest_nr, j);
exit(1);
}
quest_table[quest_nr].mob[j].vnum = t[0];
quest_table[quest_nr].mob[j].nuyen = t[1];
quest_table[quest_nr].mob[j].karma = t[2];
quest_table[quest_nr].mob[j].load = (byte) t[3];
quest_table[quest_nr].mob[j].objective = (byte) t[4];
quest_table[quest_nr].mob[j].l_data = t[5];
quest_table[quest_nr].mob[j].l_data2 = t[6];
quest_table[quest_nr].mob[j].o_data = t[7];
}
} else quest_table[quest_nr].mob = NULL;
quest_table[quest_nr].intro = fread_string(fl, buf2);
quest_table[quest_nr].decline = fread_string(fl, buf2);
quest_table[quest_nr].quit = fread_string(fl, buf2);
quest_table[quest_nr].finish = fread_string(fl, buf2);
quest_table[quest_nr].info = fread_string(fl, buf2);
quest_table[quest_nr].s_string = fread_string(fl, buf2);
quest_table[quest_nr].e_string = fread_string(fl, buf2);
quest_nr++;
top_of_questt = quest_nr;
}
void parse_shop(FILE * fl, int virtual_nr)
{
static int shop_nr = 0;
char line[256];
int t[5], i, max;
float buy, sell;
shop_table[shop_nr].virt = virtual_nr;
get_line(fl, line);
if (sscanf(line, "%d %d %d", t, t + 1, t + 2) != 3) {
fprintf(stderr, "Format error in shop #%d, expecting # # #\n", shop_nr);
exit(1);
}
shop_table[shop_nr].num_producing = t[0];
shop_table[shop_nr].num_buy_types = t[1];
shop_table[shop_nr].num_rooms = t[2];
max = MAX(t[0], MAX(t[1], t[2]));
if (shop_table[shop_nr].num_producing > 0)
shop_table[shop_nr].producing = new int[shop_table[shop_nr].num_producing];
else shop_table[shop_nr].producing = NULL;
if (shop_table[shop_nr].num_buy_types > 0)
shop_table[shop_nr].type = new int[shop_table[shop_nr].num_buy_types];
else
shop_table[shop_nr].type = NULL;
if (shop_table[shop_nr].num_rooms > 0)
shop_table[shop_nr].in_room = new int[shop_table[shop_nr].num_rooms];
else shop_table[shop_nr].in_room = NULL;
for (i = 0; i < max; i++) {
get_line(fl, line);
if (sscanf(line, "%d %d %d", t, t + 1, t + 2) != 3) {
fprintf(stderr, "Format error in shop #%d, p/t/r line #%d", shop_nr, i);
exit(1);
}
if (t[0] > 0 && i < shop_table[shop_nr].num_producing)
shop_table[shop_nr].producing[i] = t[0];
if (t[1] > 0 && i < shop_table[shop_nr].num_buy_types)
shop_table[shop_nr].type[i] = t[1];
if (t[2] > 0 && i < shop_table[shop_nr].num_rooms)
shop_table[shop_nr].in_room[i] = t[2];
}
get_line(fl, line);
if (sscanf(line, "%f %f %d %d %d %d %d", &buy, &sell, t, t + 1, t + 2,
t + 3, t + 4) != 7) {
fprintf(stderr, "Format error in shop #%d, expecting # # # # # # #", shop_nr);
exit(1);
}
shop_table[shop_nr].profit_buy = buy;
shop_table[shop_nr].profit_sell = sell;
shop_table[shop_nr].percentage = t[0],
shop_table[shop_nr].temper = t[1];
shop_table[shop_nr].bitvector = t[2];
shop_table[shop_nr].keeper = t[3];
shop_table[shop_nr].with_who = t[4];
get_line(fl, line);
if (sscanf(line, "%d %d %d %d", t, t + 1, t + 2, t + 3) != 4) {
fprintf(stderr, "Format error in shop #%d, expecting # # # #", shop_nr);
exit(1);
}
shop_table[shop_nr].open1 = t[0];
shop_table[shop_nr].close1 = t[1];
shop_table[shop_nr].open2 = t[2];
shop_table[shop_nr].close2 = t[3];
shop_table[shop_nr].no_such_item1 = fread_string(fl, buf2);
shop_table[shop_nr].no_such_item2 = fread_string(fl, buf2);
shop_table[shop_nr].do_not_buy = fread_string(fl, buf2);
shop_table[shop_nr].missing_cash1 = fread_string(fl, buf2);
shop_table[shop_nr].missing_cash2 = fread_string(fl, buf2);
shop_table[shop_nr].message_buy = fread_string(fl, buf2);
shop_table[shop_nr].message_sell = fread_string(fl, buf2);
SHOP_BANK(shop_nr) = 0;
SHOP_SORT(shop_nr) = 0;
SHOP_LASTTIME(shop_nr) = 0;
shop_nr++;
top_of_shopt = shop_nr;
}
#define Z zone_table[zone]
/* load the zone table and command tables */
void load_zones(FILE * fl, char *zonename)
{
static int zone = 0;
int cmd_no = 0, line_num = 0, tmp, error;
char *ptr, buf[256], zname[256];
strcpy(zname, zonename);
Z.num_cmds = 0;
while (get_line(fl, buf))
Z.num_cmds++;
// subtract the first 4 lines
Z.num_cmds -= 4;
rewind(fl);
if (Z.num_cmds == 0) {
fprintf(stderr, "%s is empty.\n", zname);
Z.cmd = NULL;
// exit(0); -- it's okay, we can deal with empty zones
} else
Z.cmd = new struct reset_com[Z.num_cmds];
line_num += get_line(fl, buf);
if (sscanf(buf, "#%d", &Z.number) != 1) {
fprintf(stderr, "Format error in %s, line %d\n", zname, line_num);
exit(0);
}
//sprintf(buf2, "beginning of zone #%d", Z.number);
line_num += get_line(fl, buf);
if ((ptr = strchr((const char *)buf, '~')) != NULL) /* take off the '~' if it's there */
*ptr = '\0';
Z.name = str_dup(buf);
line_num += get_line(fl, buf);
if (sscanf(buf, " %d %d %d %d %d", &Z.top, &Z.lifespan, &Z.reset_mode, &Z.security, &Z.connected) != 5) {
fprintf(stderr, "Format error in 5-constant line of %s", zname);
exit(0);
}
line_num += get_line(fl, buf);
// This next section reads in the id nums of the players that can edit
// this zone.
if (sscanf(buf, "%d %d %d %d %d", &Z.editor_ids[0], &Z.editor_ids[1],
&Z.editor_ids[2], &Z.editor_ids[3], &Z.editor_ids[4]) != 5)
{
fprintf(stderr, "Format error in editor id list of %s", zname);
exit(0);
}
cmd_no = 0;
// go ahead and skip this zone from here on if it has no cmds
for (;Z.num_cmds > 0;) {
if (!(tmp = get_line(fl, buf))) {
fprintf(stderr, "Format error in %s - premature end of file\n", zname);
exit(0);
}
line_num += tmp;
ptr = buf;
skip_spaces(&ptr);
if ((ZCMD.command = *ptr) == '*')
continue;
ptr++;
if (ZCMD.command == '$')
break;
error = 0;
if (strchr((const char *)"MOENPD", ZCMD.command) == NULL) { /* a 3-arg command */
if (sscanf(ptr, " %d %d %d ", &tmp, &ZCMD.arg1, &ZCMD.arg2) != 3)
error = 1;
} else {
if (sscanf(ptr, " %d %d %d %d ", &tmp, &ZCMD.arg1, &ZCMD.arg2,
&ZCMD.arg3) != 4)
error = 1;
}
ZCMD.if_flag = tmp;
if (error) {
fprintf(stderr, "Format error in %s, line %d: '%s'\n", zname, line_num, buf);
exit(0);
}
ZCMD.line = line_num;
cmd_no++;
}
top_of_zone_table = zone++;
rewind(fl);
}
#undef Z
/*************************************************************************
* procedures for resetting, both play-time and boot-time *
*********************************************************************** */
int vnum_mobile_karma(char *searchname, struct char_data * ch)
{
SPECIAL(shop_keeper);
extern int calc_karma(struct char_data *ch, struct char_data *vict);
int nr, found = 0;
int karma;
int i;
for (i = 1000; i >= 0; i--)
{
for (nr = 0; nr <= top_of_mobt; nr++) {
if (mob_index[nr].func == shop_keeper
||mob_index[nr].sfunc == shop_keeper)
continue;
karma = calc_karma(NULL, &mob_proto[nr]);
if ( karma < i )
continue;
if ( i != 1000 && karma > i )
continue;
sprintf(buf, "%3d. [%5d] %5.2f %s\r\n", ++found,
mob_index[nr].virt,
(float)karma/100.0,
mob_proto[nr].player.short_descr);
send_to_char(buf, ch);
}
}
return (found);
}
int vnum_mobile(char *searchname, struct char_data * ch)
{
int nr, found = 0;
if (!strcmp(searchname,"karmalist"))
return vnum_mobile_karma(searchname,ch);
for (nr = 0; nr <= top_of_mobt; nr++) {
if (isname(searchname, mob_proto[nr].player.name)
||isname(searchname, mob_proto[nr].player.short_descr)) {
sprintf(buf, "%3d. [%5d] %s\r\n", ++found,
mob_index[nr].virt,
mob_proto[nr].player.short_descr == NULL ? "(BUG)" :
mob_proto[nr].player.short_descr );
send_to_char(buf, ch);
}
}
return (found);
}
int vnum_object_weapons(char *searchname, struct char_data * ch)
{
extern const char *wound_arr[];
int nr, found = 0;
for (nr = 0; nr <= top_of_objt; nr++) {
if (GET_OBJ_TYPE(&obj_proto[nr]) == ITEM_WEAPON
&& !from_ip_zone(obj_index[nr].virt)) {
#if 0
if (GET_OBJ_VAL(&obj_proto[nr], 2) == 0)
continue;
#endif
sprintf(buf, "%3d. [%5d] %2d%s +%d %s\r\n", ++found,
obj_index[nr].virt,
GET_OBJ_VAL(&obj_proto[nr], 0),
wound_arr[GET_OBJ_VAL(&obj_proto[nr], 1)],
GET_OBJ_VAL(&obj_proto[nr], 2),
obj_proto[nr].short_description);
send_to_char(buf, ch);
}
}
return (found);
}
int vnum_object_foci(char *searchname, struct char_data * ch)
{
extern const char *wound_arr[];
int nr, found = 0;
for (nr = 0; nr <= top_of_objt; nr++) {
if (GET_OBJ_TYPE(&obj_proto[nr]) == ITEM_FOCUS
&& !from_ip_zone(obj_index[nr].virt)) {
sprintf(buf, "%3d. [%5d] %d +%2d %s\r\n", ++found,
obj_index[nr].virt,
GET_OBJ_VAL(&obj_proto[nr], VALUE_FOCUS_TYPE),
GET_OBJ_VAL(&obj_proto[nr], VALUE_FOCUS_RATING),
obj_proto[nr].short_description);
send_to_char(buf, ch);
}
}
return (found);
}
int vnum_object_type(int type, struct char_data * ch)
{
int nr, found = 0;
for (nr = 0; nr <= top_of_objt; nr++) {
if (GET_OBJ_TYPE(&obj_proto[nr]) == type)
{
sprintf(buf, "%3d. [%5d] %s %s\r\n", ++found,
obj_index[nr].virt,
from_ip_zone(obj_index[nr].virt) ? " " : "*",
obj_proto[nr].short_description);
send_to_char(buf, ch);
}
}
return (found);
}
int vnum_object(char *searchname, struct char_data * ch)
{
int nr, found = 0;
char arg1[MAX_STRING_LENGTH];
char arg2[MAX_STRING_LENGTH];
two_arguments(searchname, arg1, arg2);
if (!strcmp(searchname,"weaponslist"))
return vnum_object_weapons(searchname,ch);
if (!strcmp(searchname,"focilist"))
return vnum_object_foci(searchname,ch);
if (!strcmp(arg1,"objtype"))
return vnum_object_type(atoi(arg2),ch);
for (nr = 0; nr <= top_of_objt; nr++) {
if (isname(searchname, obj_proto[nr].name)
||isname(searchname, obj_proto[nr].short_description)) {
sprintf(buf, "%3d. [%5d] %s %s\r\n", ++found,
obj_index[nr].virt,
from_ip_zone(obj_index[nr].virt) ? " " : "*",
obj_proto[nr].short_description);
send_to_char(buf, ch);
}
}
return (found);
}
/* create a character, and add it to the char list */
struct char_data *create_char(void)
{
struct char_data *ch;
ch = Mem->GetCh();
ch->next = character_list;
character_list = ch;
return ch;
}
/* create a new mobile from a prototype */
struct char_data *read_mobile(int nr, int type)
{
int i;
struct char_data *mob;
if (type == VIRTUAL) {
if ((i = real_mobile(nr)) < 0) {
sprintf(buf, "Mobile (V) %d does not exist in database.", nr);
return (0);
}
} else i = nr;
mob = Mem->GetCh();
*mob = mob_proto[i];
mob->next = character_list;
character_list = mob;
mob->points.physical = mob->points.max_physical;
mob->points.mental = mob->points.max_mental;
mob->player.time.birth = time(0);
mob->player.time.played = 0;
mob->player.time.logon = time(0);
mob->char_specials.saved.left_handed = (!number(0, 9) ? 1 : 0);
GET_WIELDED(mob, 0) = 0;
GET_WIELDED(mob, 1) = 0;
mob_index[i].number++;
affect_total(mob);
if (GET_MOB_SPEC(mob) && !MOB_FLAGGED(mob, MOB_SPEC))
SET_BIT(MOB_FLAGS(mob), MOB_SPEC);
return mob;
}
/* create an object, and add it to the object list */
struct obj_data *create_obj(void)
{
struct obj_data *obj;
/* Old Object Code
obj = new obj_data;
//the objects are cleared already
clear_object(obj);
obj->next = object_list;
object_list = obj;
*/
obj = Mem->GetObject();
ObjList.ADD(obj);
return obj;
}
/* create a new object from a prototype */
struct obj_data *read_object(int nr, int type)
{
struct obj_data *obj;
int i;
if (nr < 0)
{
log("SYSERR: trying to create obj with negative num!");
return NULL;
}
if (type == VIRTUAL)
{
if ((i = real_object(nr)) < 0)
{
sprintf(buf, "Object (V) %d does not exist in database.", nr);
return NULL;
}
}
else
i = nr;
/* Old Object Code
obj = new obj_data;
clear_object(obj);
obj->next = object_list;
object_list = obj;
*/
obj = Mem->GetObject();
*obj = obj_proto[i];
ObjList.ADD(obj);
obj_index[i].number++;
return obj;
}
void spec_update(void)
{
int i;
struct obj_data *obj;
for (i = 0; i < top_of_world; i++)
if (world[i].func != NULL)
world[i].func (NULL, world + i, 0, "");
ObjList.CallSpec();
}
#define ZO_DEAD 999
/* update zone ages, queue for reset if necessary, and dequeue when possible */
void zone_update(void)
{
int i;
struct reset_q_element *update_u, *temp;
static int timer = 0;
char buf[128];
/* jelson 10/22/92 */
if (((++timer * PULSE_ZONE) / PASSES_PER_SEC) >= 60) {
/* one minute has passed */
/*
* NOT accurate unless PULSE_ZONE is a multiple of PASSES_PER_SEC or a
* factor of 60
*/
timer = 0;
/* since one minute has passed, increment zone ages */
for (i = 0; i <= top_of_zone_table; i++) {
if (zone_table[i].age < zone_table[i].lifespan &&
zone_table[i].reset_mode)
(zone_table[i].age)++;
if (zone_table[i].age >= zone_table[i].lifespan &&
zone_table[i].age < ZO_DEAD && zone_table[i].reset_mode) {
/* enqueue zone */
update_u = new reset_q_element;
update_u->zone_to_reset = i;
update_u->next = 0;
if (!reset_q.head)
reset_q.head = reset_q.tail = update_u;
else {
reset_q.tail->next = update_u;
reset_q.tail = update_u;
}
zone_table[i].age = ZO_DEAD;
}
}
} /* end - one minute has passed */
/* dequeue zones (if possible) and reset */
/* this code is executed every 10 seconds (i.e. PULSE_ZONE) */
for (update_u = reset_q.head; update_u; update_u = update_u->next)
if (zone_table[update_u->zone_to_reset].reset_mode == 2 ||
is_empty(update_u->zone_to_reset)) {
reset_zone(update_u->zone_to_reset, 0);
sprintf(buf, "Auto zone reset: %s",
zone_table[update_u->zone_to_reset].name);
mudlog(buf, NULL, LOG_ZONELOG, FALSE);
/* dequeue */
if (update_u == reset_q.head)
reset_q.head = reset_q.head->next;
else {
for (temp = reset_q.head; temp->next != update_u; temp = temp->next);
if (!update_u->next)
reset_q.tail = temp;
temp->next = update_u->next;
}
delete update_u;
break;
}
}
void log_zone_error(int zone, int cmd_no, char *message)
{
char buf[256];
sprintf(buf, "error in zone file: %s", message);
mudlog(buf, NULL, LOG_ZONELOG, TRUE);
sprintf(buf, " ...offending cmd: '%c' cmd in zone #%d, line %d, cmd %d",
ZCMD.command, zone_table[zone].number, ZCMD.line, cmd_no);
mudlog(buf, NULL, LOG_ZONELOG, TRUE);
}
#define ZONE_ERROR(message) {log_zone_error(zone, cmd_no, message); last_cmd = 0;}
/* execute the reset command table of a given zone */
void reset_zone(int zone, int reboot)
{
SPECIAL(fixer);
int cmd_no, j, last_cmd = 0, found = 0, no_mob = 0;
static int i;
struct char_data *mob = NULL;
struct obj_data *obj, *obj_to, *check;
for (cmd_no = 0; cmd_no < zone_table[zone].num_cmds; cmd_no++)
{
if (ZCMD.if_flag && !last_cmd)
continue;
found = 0;
switch (ZCMD.command) {
case '$':
last_cmd = 0;
break;
case '*': /* ignore command */
last_cmd = 0;
break;
case 'M': /* read a mobile */
if ((mob_index[ZCMD.arg1].number < ZCMD.arg2) || (ZCMD.arg2 == -1) ||
(ZCMD.arg2 == 0 && reboot)) {
mob = read_mobile(ZCMD.arg1, REAL);
char_to_room(mob, ZCMD.arg3);
if (GET_MOB_SPEC(mob) && GET_MOB_SPEC(mob) == fixer &&
mob_index[mob->nr].number == 1)
load_fixer_data(mob);
last_cmd = 1;
} else {
if (ZCMD.arg2 == 0 && !reboot)
no_mob = 1;
else no_mob = 0;
last_cmd = 0;
mob = NULL;
}
break;
case 'O': /* read an object */
if ((obj_index[ZCMD.arg1].number < ZCMD.arg2) || (ZCMD.arg2 == -1) ||
(ZCMD.arg2 == 0 && reboot)) {
obj = read_object(ZCMD.arg1, REAL);
obj_to_room(obj, ZCMD.arg3);
if (!from_ip_zone(GET_OBJ_VNUM(obj)) && !zone_table[zone].connected)
SET_BIT(GET_OBJ_EXTRA(obj), ITEM_VOLATILE);
last_cmd = 1;
} else last_cmd = 0;
break;
case 'P': /* object to object */
if ((obj_index[ZCMD.arg1].number < ZCMD.arg2) || (ZCMD.arg2 == -1) ||
(ZCMD.arg2 == 0 && reboot)) {
obj = read_object(ZCMD.arg1, REAL);
if (!(obj_to = ObjList.FindObj(ZCMD.arg3))) {
ZONE_ERROR("target obj not found");
break;
}
obj_to_obj(obj, obj_to);
if (!from_ip_zone(GET_OBJ_VNUM(obj)) && !zone_table[zone].connected)
SET_BIT(GET_OBJ_EXTRA(obj), ITEM_VOLATILE);
last_cmd = 1;
} else last_cmd = 0;
break;
case 'G': /* obj_to_char */
if (!mob) {
if (!no_mob)
ZONE_ERROR("attempt to give obj to non-existant mob");
break;
}
if ((obj_index[ZCMD.arg1].number < ZCMD.arg2) || (ZCMD.arg2 == -1) ||
(ZCMD.arg2 == 0 && reboot)) {
obj = read_object(ZCMD.arg1, REAL);
obj_to_char(obj, mob);
if (!from_ip_zone(GET_OBJ_VNUM(obj)) && !zone_table[zone].connected)
SET_BIT(GET_OBJ_EXTRA(obj), ITEM_VOLATILE);
last_cmd = 1;
} else last_cmd = 0;
break;
case 'E': /* object to equipment list */
if (!mob) {
if (!no_mob)
ZONE_ERROR("trying to equip non-existant mob");
break;
}
if ((obj_index[ZCMD.arg1].number < ZCMD.arg2) || (ZCMD.arg2 == -1) ||
(ZCMD.arg2 == 0 && reboot)) {
if (ZCMD.arg3 < 0 || ZCMD.arg3 >= NUM_WEARS) {
ZONE_ERROR("invalid equipment pos number");
} else {
obj = read_object(ZCMD.arg1, REAL);
equip_char(mob, obj, ZCMD.arg3);
if (!from_ip_zone(GET_OBJ_VNUM(obj)) && !zone_table[zone].connected)
SET_BIT(GET_OBJ_EXTRA(obj), ITEM_VOLATILE);
last_cmd = 1;
}
} else last_cmd = 0;
break;
case 'N': // give x number of items to a mob
if (!mob) {
if (!no_mob)
ZONE_ERROR("attempt to give obj to non-existant mob");
break;
}
last_cmd = 0;
for (i = 0; (i < ZCMD.arg3) && ((obj_index[ZCMD.arg1].number < ZCMD.arg2) ||
(ZCMD.arg2 == -1) || (ZCMD.arg2 == 0 && reboot)); ++i) {
obj = read_object(ZCMD.arg1, REAL);
obj_to_char(obj, mob);
if (!from_ip_zone(GET_OBJ_VNUM(obj)) && !zone_table[zone].connected)
SET_BIT(GET_OBJ_EXTRA(obj), ITEM_VOLATILE);
last_cmd = 1;
}
break;
case 'C': // give mob bio/cyberware
if (!mob) {
if (!no_mob)
ZONE_ERROR("attempt to give obj to non-existant mob");
break;
}
obj = read_object(ZCMD.arg1, REAL);
if (!ZCMD.arg2) {
if (GET_OBJ_TYPE(obj) != ITEM_CYBERWARE) {
ZONE_ERROR("attempt to install non-cyberware to mob");
break;
}
if (GET_ESS(mob) < GET_OBJ_VAL(obj, 1))
break;
for (check = mob->cyberware; check && !found; check = check->next_content) {
if ((GET_OBJ_VNUM(check) == GET_OBJ_VNUM(obj)))
found = 1;
if (GET_OBJ_VAL(check, 2) == GET_OBJ_VAL(obj, 2))
found = 1;
}
if (GET_OBJ_VAL(obj, 2) == 23 || GET_OBJ_VAL(obj, 2) == 30 ||
GET_OBJ_VAL(obj, 2) == 20)
for (check = mob->bioware; check && !found; check = check->next_content) {
if (GET_OBJ_VAL(check, 2) == 2 && GET_OBJ_VAL(obj, 2) == 23)
found = 1;
if (GET_OBJ_VAL(check, 2) == 8 && GET_OBJ_VAL(obj, 2) == 30)
found = 1;
if (GET_OBJ_VAL(check, 2) == 10 && GET_OBJ_VAL(obj, 2) == 20)
found = 1;
}
if (found)
break;
obj_to_cyberware(obj, mob);
} else {
if (GET_OBJ_TYPE(obj) != ITEM_BIOWARE) {
ZONE_ERROR("attempt to install non-bioware to mob");
break;
}
if (GET_INDEX(mob) < GET_OBJ_VAL(obj, 1))
break;
for (check = mob->bioware; check && !found; check = check->next_content) {
if ((GET_OBJ_VNUM(check) == GET_OBJ_VNUM(obj)))
found = 1;
if (GET_OBJ_VAL(check, 2) == GET_OBJ_VAL(obj, 2))
found = 1;
}
if (GET_OBJ_VAL(obj, 2) == 2 || GET_OBJ_VAL(obj, 2) == 8 || GET_OBJ_VAL(obj, 2) == 10)
for (check = mob->cyberware; check; check = check->next_content) {
if (GET_OBJ_VAL(check, 2) == 23 && GET_OBJ_VAL(obj, 2) == 2)
found = 1;
if (GET_OBJ_VAL(check, 2) == 30 && GET_OBJ_VAL(obj, 2) == 8)
found = 1;
if (GET_OBJ_VAL(check, 2) == 20 && GET_OBJ_VAL(obj, 2) == 10)
found = 1;
}
if (found)
break;
if (GET_OBJ_VAL(obj, 2) == 0)
GET_OBJ_VAL(obj, 5) = 24;
obj_to_bioware(obj, mob);
}
last_cmd = 1;
break;
case 'R': /* rem obj from room */
if ((obj = get_obj_in_list_num(ZCMD.arg2, world[ZCMD.arg1].contents)) != NULL) {
obj_from_room(obj);
extract_obj(obj);
}
last_cmd = 1;
break;
case 'D': /* set state of door */
if (ZCMD.arg2 < 0 || ZCMD.arg2 >= NUM_OF_DIRS ||
(world[ZCMD.arg1].dir_option[ZCMD.arg2] == NULL)) {
ZONE_ERROR("door does not exist");
} else {
bool ok = FALSE;
int opposite = MAX(0, world[ZCMD.arg1].dir_option[ZCMD.arg2]->to_room);
if (!world[opposite].dir_option[rev_dir[ZCMD.arg2]] || (ZCMD.arg1 !=
world[opposite].dir_option[rev_dir[ZCMD.arg2]]->to_room)) {
sprintf(buf, "Note: Exits from %d to %d do not coincide (zone %d, line %d, cmd %d)",
world[opposite].number, world[ZCMD.arg1].number, zone_table[zone].number,
ZCMD.line, cmd_no);
mudlog(buf, NULL, LOG_ZONELOG, FALSE);
} else ok = TRUE;
// here I set the hidden flag for the door if hidden > 0
if (world[ZCMD.arg1].dir_option[ZCMD.arg2]->hidden)
SET_BIT(world[ZCMD.arg1].dir_option[ZCMD.arg2]->exit_info, EX_HIDDEN);
if (ok && world[opposite].dir_option[rev_dir[ZCMD.arg2]]->hidden)
SET_BIT(world[opposite].dir_option[rev_dir[ZCMD.arg2]]->exit_info, EX_HIDDEN);
// repair all damage
REMOVE_BIT(world[ZCMD.arg1].dir_option[ZCMD.arg2]->exit_info, EX_DESTROYED);
world[ZCMD.arg1].dir_option[ZCMD.arg2]->condition =
world[ZCMD.arg1].dir_option[ZCMD.arg2]->barrier;
if (ok) {
world[opposite].dir_option[rev_dir[ZCMD.arg2]]->material =
world[ZCMD.arg1].dir_option[ZCMD.arg2]->material;
world[opposite].dir_option[rev_dir[ZCMD.arg2]]->barrier =
world[ZCMD.arg1].dir_option[ZCMD.arg2]->barrier;
world[opposite].dir_option[rev_dir[ZCMD.arg2]]->condition =
world[ZCMD.arg1].dir_option[ZCMD.arg2]->condition;
REMOVE_BIT(world[opposite].dir_option[rev_dir[ZCMD.arg2]]->exit_info, EX_DESTROYED);
}
switch (ZCMD.arg3) {
// you now only have to set one side of a door
case 0:
REMOVE_BIT(world[ZCMD.arg1].dir_option[ZCMD.arg2]->exit_info, EX_LOCKED);
REMOVE_BIT(world[ZCMD.arg1].dir_option[ZCMD.arg2]->exit_info, EX_CLOSED);
if (ok) {
REMOVE_BIT(world[opposite].dir_option[rev_dir[ZCMD.arg2]]->exit_info, EX_LOCKED);
REMOVE_BIT(world[opposite].dir_option[rev_dir[ZCMD.arg2]]->exit_info, EX_CLOSED);
}
break;
case 1:
SET_BIT(world[ZCMD.arg1].dir_option[ZCMD.arg2]->exit_info, EX_CLOSED);
REMOVE_BIT(world[ZCMD.arg1].dir_option[ZCMD.arg2]->exit_info, EX_LOCKED);
if (ok) {
SET_BIT(world[opposite].dir_option[rev_dir[ZCMD.arg2]]->exit_info, EX_CLOSED);
REMOVE_BIT(world[opposite].dir_option[rev_dir[ZCMD.arg2]]->exit_info, EX_LOCKED);
}
break;
case 2:
SET_BIT(world[ZCMD.arg1].dir_option[ZCMD.arg2]->exit_info, EX_LOCKED);
SET_BIT(world[ZCMD.arg1].dir_option[ZCMD.arg2]->exit_info, EX_CLOSED);
if (ok) {
SET_BIT(world[opposite].dir_option[rev_dir[ZCMD.arg2]]->exit_info, EX_LOCKED);
SET_BIT(world[opposite].dir_option[rev_dir[ZCMD.arg2]]->exit_info, EX_CLOSED);
}
break;
}
}
last_cmd = 1;
break;
default:
ZONE_ERROR("unknown cmd in reset table; cmd disabled");
ZCMD.command = '*';
break;
}
}
zone_table[zone].age = 0;
if (zone_table[zone].alert != 4)
zone_table[zone].alert = 0;
if (zone == real_zone(31))
for (j = 0; j <= top_of_zone_table; j++)
zone_table[j].alert = 0;
}
/* for use in reset_zone; return TRUE if zone 'nr' is Free of PC's */
int is_empty(int zone_nr)
{
struct descriptor_data *i;
for (i = descriptor_list; i; i = i->next)
if (!i->connected)
if (world[i->character->in_room].zone == zone_nr)
return 0;
return 1;
}
/*************************************************************************
* stuff related to the save/load player system *
*********************************************************************** */
void html_stats(void)
{
extern const char *pc_race_types[];
FILE *html;
if (!(html = fopen("../../public_html/plrstats.html", "w+"))) {
log("Error opening plrstats.html.");
return;
}
struct char_data *vict;
int total = top_of_p_table + 1;
int humans = 0, elves = 0, dwarves = 0, trolls = 0, orks = 0;
int actives[6], mages[6], shamans[6], adepts[6];
int height[6], weight[6], righties[6];
sh_int i, num = 0;
char *tmstr;
time_t thetime = time(0);
tmstr = (char *) asctime(localtime(&thetime));
*(tmstr + strlen(tmstr) - 6) = '\0';
for (i = 0; i < 6; i++) {
mages[i] = 0;
shamans[i] = 0;
adepts[i] = 0;
height[i] = 0;
weight[i] = 0;
righties[i] = 0;
}
for (i = 0; i <= top_of_p_table; i++) {
vict = Mem->GetCh();
if ((load_char((player_table + i)->name, vict)) < 0)
continue;
num = GET_RACE(vict);
switch (num) {
case RACE_HUMAN: humans++; break;
case RACE_DWARF: dwarves++; break;
case RACE_ELF: elves++; break;
case RACE_ORK: orks++; break;
case RACE_TROLL: trolls++; break;
}
switch (GET_TRADITION(vict)) {
case TRAD_HERMETIC: mages[num]++; break;
case TRAD_SHAMANIC: shamans[num]++; break;
case TRAD_ADEPT: adepts[num]++; break;
}
if (!(vict->char_specials.saved.left_handed))
righties[num]++;
height[num] += vict->player.height;
weight[num] += vict->player.weight;
}
for (i = 0; i < 6; i++)
actives[i] = mages[i] + shamans[i] + adepts[i];
for (i = 0; i < 5; i++) {
height[5] += height[i];
weight[5] += weight[i];
righties[5] += righties[i];
actives[5] += actives[i];
mages[5] += mages[i];
shamans[5] += shamans[i];
adepts[5] += adepts[i];
}
fprintf(html, "<html>\n<head>\n<title>Player statistics</title></head>\n");
fprintf(html, "<body text=\"#808080\" bgcolor=\"#000000\" link=\"#0000FF\" "
"vlink=\"#000080\" alink=\"#0000A0\">\n\n");
fprintf(html, "<h2 align=center><font color=\"#0000F0\">Player statistics</font></h2>\n");
fprintf(html, "<h5 align=center>Last updated: %s</h5>\n", tmstr + 4);
fprintf(html, "<hr size=1 align=center width=75%%>\n<tt>\n");
for (i = 0; i <= 5; i++) {
switch (i) {
case 0: num = humans; break;
case 1: num = dwarves; break;
case 2: num = elves; break;
case 3: num = orks; break;
case 4: num = trolls; break;
case 5: num = total; break;
}
if (i < 5)
fprintf(html, "<h4>%s: %d (%0.2f%%)</h4>\n", pc_race_types[i], num,
((float)num * 100 / total));
else fprintf(html, "<h3>Total: %d</h3>\n", num);
fprintf(html, "<pre> Average height: %0.2f m, average weight: %0.2f kg.\n",
((float)height[i] / (100 * num)), ((float)weight[i] / num));
fprintf(html, " %d (%0.2f%%) are right-handed.\n",
righties[i], ((float)righties[i] * 100 / num));
fprintf(html, " %d (%0.2f%%) are magically active, of which:\n",
actives[i], ((float)actives[i] * 100 / num));
fprintf(html, " %d (%0.2f%%) follow the hermetic tradition,\n",
mages[i], ((float)mages[i] * 100 / num));
fprintf(html, " %d (%0.2f%%) follow the shamanic tradition, and\n",
shamans[i], ((float)shamans[i] * 100 / num));
fprintf(html, " %d (%0.2f%%) are physical adepts.</pre>\n\n",
adepts[i], ((float)adepts[i] * 100 / num));
}
fprintf(html, "</p>\n</body>\n</html>\n");
fclose(html);
}
long get_id_by_name(char *name)
{
int i;
one_argument(name, arg);
for (i = 0; i <= top_of_p_table; i++)
if (!strcmp((player_table + i)->name, arg))
return ((player_table + i)->id);
return -1;
}
char *get_name_by_id(long id)
{
int i;
if (id < 1 || id > top_idnum)
return NULL;
for (i = 0; i <= top_of_p_table; i++)
if ((player_table + i)->id == id)
return ((player_table + i)->name);
return NULL;
}
int load_char(char *name, struct char_data *ch)
{
int id, num = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0, i;
FILE *fl;
char filename[40];
char buf[128], line[MAX_INPUT_LENGTH + 1], tag[6], bits[127];
struct affected_type af;
if((id = find_name(name)) < 0)
return (-1);
else
{
for (i = 0;(*(bits + i) = LOWER(*(player_table[id].name + i))); i++);
sprintf(filename, "%s%s%c%s%s%s", PLR_PREFIX, SLASH, *bits,
SLASH, bits, PLR_SUFFIX);
if(!(fl = fopen(filename, "r")))
{
sprintf(buf, "SYSERR: Couldn't open player file %s", filename);
mudlog(buf, NULL, LOG_SYSLOG, TRUE);
return (-1);
}
/* character initializations */
/* initializations necessary to keep some things straight */
if(ch->player_specials == NULL)
ch->player_specials = new player_special_data;
init_char(ch);
ch->affected = NULL;
for(i = 1; i <= MAX_SKILLS; i++)
GET_SKILL(ch, i) = 0;
//ch->player.short_descr = NULL;
//ch->player.long_descr = NULL;
ch->player.time.logon = time(0);
//if (ch->points.max_physical < 1000)
// ch->points.max_physical = 1000;
//if (ch->points.max_mental < 1000)
// ch->points.max_mental = 1000;
ch->char_specials.carry_weight = 0;
ch->char_specials.carry_items = 0;
ch->points.ballistic = 0;
ch->points.impact = 0;
ch->points.init_dice = 0;
ch->points.init_roll = 0;
ch->points.sustained = 0;
while(get_line(fl, line))
{
tag_argument(line, tag);
num = atoi(line);
switch (*tag)
{
case 'A':
if(!strcmp(tag, "Anam"))
ch->player.aname = str_dup(line);
else if(!strcmp(tag, "Act "))
PLR_FLAGS(ch) = num;
else if(!strcmp(tag, "Aff "))
AFF_FLAGS(ch) = asciiflag_conv(line);
/* Do Not Apply Affects from a load, since affects are sustained */
//*
else if(!strcmp(tag, "Affs"))
{
i = 0;
do
{
get_line(fl, line);
sscanf(line, "%d %d %d %d %d", &num, &num2, &num3, &num4, &num5);
if(num > 0)
{
af.type = num;
af.duration = num2;
af.modifier = num3;
af.location = num4;
af.bitvector = num5;
affect_to_char(ch, &af);
i++;
}
}
while (num != 0);
}
//*
else if(!strcmp(tag, "Alin"))
GET_ALIGNMENT(ch) = num;
else if(!strcmp(tag, "Ades"))
ch->player.adesc = str_dup(line);
else if(!strcmp(tag, "Asde"))
ch->player.asdesc = str_dup(line);
else if(!strcmp(tag, "Alde"))
ch->player.aldesc = str_dup(line);
else if(!strcmp(tag, "Apoo"))
GET_ASTRAL(ch) = num;
else if(!strcmp(tag, "Ally"))
GET_ALLERGY(ch) = num;
else if(!strcmp(tag, "Asev"))
GET_SEVERITY(ch) = num;
else if(!strcmp(tag, "Arec"))
GET_REACTION(ch) = num;
break;
case 'B':
if(!strcmp(tag, "Badp"))
GET_BAD_PWS(ch) = num;
else if(!strcmp(tag, "Bank"))
GET_BANK(ch) = num;
else if(!strcmp(tag, "Brth"))
ch->player.time.birth = num;
else if(!strcmp(tag, "Bod "))
ch->real_abils.bod = num;
else if(!strcmp(tag, "BInd"))
ch->real_abils.bod_index = num;
break;
case 'C':
if(!strcmp(tag, "Cha "))
ch->real_abils.cha = num;
if(!strcmp(tag, "CLan"))
ch->char_specials.saved.cur_lang = num;
break;
case 'D':
if(!strcmp(tag, "Desc"))
{
ch->player.description = fread_string(fl,line);
}
else if(!strcmp(tag, "Drnk"))
GET_COND(ch, DRUNK) = 0;
else if(!strcmp(tag , "Dpoo"))
GET_DEFENSE(ch) = 0;
break;
case 'E':
if(!strcmp(tag, "Ess "))
ch->real_abils.ess = 600;
break;
case 'F':
if(!strcmp(tag, "Frez"))
GET_FREEZE_LEV(ch) = num;
break;
case 'G':
if(!strcmp(tag, "Grad"))
GET_GRADE(ch) = num;
break;
case 'H':
if(!strcmp(tag, "Hite"))
GET_HEIGHT(ch) = num;
else if(!strcmp(tag, "Home"))
GET_LASTROOM(ch) = num;
else if(!strcmp(tag, "Host"))
ch->player.host = str_dup(line);
else if(!strcmp(tag, "Hung"))
GET_COND(ch, FULL) = num;
else if(!strcmp(tag, "Hpoo"))
GET_HACKING(ch) = 0;
break;
case 'I':
if(!strcmp(tag, "Id "))
GET_IDNUM(ch) = num;
else if(!strcmp(tag, "Int "))
ch->real_abils.intel = num;
else if(!strcmp(tag, "Invs"))
{
if(num > GET_LEVEL(ch) || num < 0)
GET_INVIS_LEV(ch) = 0;
else
GET_INVIS_LEV(ch) = num;
}
break;
case 'K':
if(!strcmp(tag, "Karm"))
GET_KARMA(ch) = num;
break;
case 'L':
if(!strcmp(tag, "Last"))
ch->player.time.logon = num;
else if(!strcmp(tag, "Levl"))
GET_LEVEL(ch) = num;
else if(!strcmp(tag, "LHan"))
ch->char_specials.saved.left_handed = num;
break;
case 'M':
if(!strcmp(tag, "Ment"))
{
sscanf(line, "%d/%d", &num, &num2);
GET_MAX_MENTAL(ch) = num2;
GET_MENTAL(ch) = num;
}
else if(!strcmp(tag, "Mpoo"))
GET_MAGIC(ch) = 0;
else if(!strcmp(tag, "Mag "))
{
if(num < 0)
ch->real_abils.mag = 600;
else
ch->real_abils.mag = num;
}
else if(!strcmp(tag, "Mdes"))
ch->player.mdesc = str_dup(line);
else if(!strcmp(tag, "Msde"))
ch->player.msdesc = str_dup(line);
else if(!strcmp(tag, "Mlde"))
ch->player.mldesc = str_dup(line);
else if(!strcmp(tag, "Mnam"))
ch->player.mname = str_dup(line);
break;
case 'N':
if(!strcmp(tag, "Name"))
GET_NAME(ch) = str_dup(line);
else if(!strcmp(tag, "Nuye"))
GET_NUYEN(ch) = num;
break;
case 'O':
if(!strcmp(tag, "Opoo"))
GET_OFFENSE(ch) = 0;
break;
case 'P':
if(!strcmp(tag, "Pass"))
strcpy(GET_PASSWD(ch), line);
else if(!strcmp(tag, "Plyd"))
ch->player.time.played = num;
else if(!strcmp(tag, "PfIn"))
POOFIN(ch) = str_dup(line);
else if(!strcmp(tag, "PfOt"))
POOFOUT(ch) = str_dup(line);
else if(!strcmp(tag, "Pref"))
{
PRF_FLAGS(ch) = asciiflag_conv(line);
if ( GET_LEVEL(ch) < LVL_LEGEND )
REMOVE_BIT(PRF_FLAGS(ch), PRF_ROLLS);
}
else if(!strcmp(tag , "PTit"))
GET_PRETITLE(ch) = str_dup(line);
else if(!strcmp(tag, "Prom"))
ch->player.prompt = str_dup(line);
else if(!strcmp(tag, "Phys"))
{
sscanf(line, "%d/%d", &num, &num2);
GET_MAX_PHYSICAL(ch) = num2;
GET_PHYSICAL(ch) = num;
}
break;
case 'Q':
if(!strcmp(tag, "Qui "))
ch->real_abils.qui = num;
break;
case 'R':
if(!strcmp(tag, "Room"))
GET_LOADROOM(ch) = num;
else if(!strcmp(tag, "Rea "))
ch->real_abils.rea = num;
else if(!strcmp(tag, "Rep "))
GET_REP(ch) = num;
else if(!strcmp(tag, "Race"))
GET_RACE(ch) = num;
else if(!strcmp(tag, "RMag"))
{
if(num < 100 && num > 0)
GET_MAX_MAG(ch) = 600;
else
GET_MAX_MAG(ch) = num;
}
break;
case 'S':
if(!strcmp(tag, "Sex "))
GET_SEX(ch) = num;
else if(!strcmp(tag, "Skil"))
{
do
{
get_line(fl, line);
sscanf(line, "%d %d", &num, &num2);
if(num != 0)
GET_SKILL(ch, num) = num2;
}
while (num != 0);
}
else if(!strcmp(tag, "Str "))
ch->real_abils.str = num;
else if(!strcmp(tag, "Sust"))
ch->points.sustained = num;
else if(!strcmp(tag, "Satt"))
GET_ATT_POINTS(ch) = num;
else if(!strcmp(tag, "Sskl"))
GET_SKILL_POINTS(ch) = num;
break;
case 'T':
if(!strcmp(tag, "Thir"))
GET_COND(ch, THIRST) = num;
else if(!strcmp(tag, "Titl"))
GET_TITLE(ch) = str_dup(line);
else if(!strcmp(tag, "Trad"))
GET_TRADITION(ch) = num;
else if(!strcmp(tag, "Totm"))
GET_TOTEM(ch) = num;
break;
case 'W':
if(!strcmp(tag, "Wate"))
GET_WEIGHT(ch) = num;
else if(!strcmp(tag, "Wimp"))
GET_WIMP_LEV(ch) = num;
else if(!strcmp(tag, "Wil "))
ch->real_abils.wil = num;
else if(!strcmp(tag, "WTit"))
GET_WHOTITLE(ch) = str_dup(line);
break;
case 'Z':
if(!strcmp(tag, "Znum"))
ch->player_specials->saved.zonenum = num;
break;
default:
sprintf(buf, "SYSERR: Unknown tag %s in pfile %s", tag, name);
}
}
}
ch->in_room = real_room(GET_LOADROOM(ch));
GET_LAST_TELL(ch) = NOBODY;
affect_total(ch);
if (!IS_AFFECTED(ch, AFF_POISON) && (((long) (time(0) - ch->player.time.logon)) >= SECS_PER_REAL_HOUR))
{
GET_PHYSICAL(ch) = GET_MAX_PHYSICAL(ch);
GET_MENTAL(ch) = GET_MAX_MENTAL(ch);
}
if(GET_LEVEL(ch) < LVL_LEGEND && ( ((long) (time(0) - ch->player.time.logon)) <= SECS_PER_REAL_HOUR))
{
if(GET_LASTROOM(ch) != NOWHERE && GET_LASTROOM(ch) > 599 && GET_LASTROOM(ch) < 610)
GET_LOADROOM(ch) = GET_LASTROOM(ch);
}
/* initialization for imms */
if(GET_LEVEL(ch) >= LVL_LEGEND)
{
GET_COND(ch, FULL) = -1;
GET_COND(ch, THIRST) = -1;
GET_COND(ch, DRUNK) = -1;
}
fclose(fl);
return(id);
}
/* write the vital data of a player to the player file */
/*
This is the ascii pfiles save routine
Code Need sto be correct here to copy the player and use the copy
for the save
*/
void save_char(struct char_data * player, sh_int load_room)
{
FILE *fl;
char outname[40], bits[127], buf[MAX_STRING_LENGTH];
int i, id, save_index = FALSE;
struct obj_data *char_eq[NUM_WEARS];
int wield[2];
struct obj_data *temp, *next_obj;
struct affected_type *af;
/* Memory copy of data*/
struct player_special_data_saved ps_saved;
struct char_special_data_saved ch_saved;
struct affected_type affected[MAX_AFFECT];
struct char_point_data points;
struct char_ability_data abilities;
if (IS_NPC(player) || GET_PFILEPOS(player) < 0)
return;
/**************************************************/
/** Do In-Memory Copy **/
wield[0] = GET_WIELDED(player, 0);
wield[1] = GET_WIELDED(player, 1);
/* Unaffect everything a character can be affected by */
/* worn eq */
for (i = 0; i < NUM_WEARS; i++) {
if (player->equipment[i])
char_eq[i] = unequip_char(player, i);
else char_eq[i] = NULL;
}
GET_WIELDED(player, 0) = wield[0];
GET_WIELDED(player, 1) = wield[1];
/* cyberware */
for (temp = player->cyberware; temp; temp = next_obj) {
next_obj = temp->next_content;
obj_from_cyberware(temp);
obj_to_char(temp, player);
}
/* bioware */
for (temp = player->bioware; temp; temp = next_obj) {
next_obj = temp->next_content;
obj_from_bioware(temp);
obj_to_char(temp, player);
}
for (af = player->affected, i = 0; i < MAX_AFFECT; i++) {
if (af) {
affected[i] = *af;
affected[i].next = NULL;
af = af->next;
} else {
affected[i].type = 0; /* Zero signifies not used */
affected[i].duration = 0;
affected[i].modifier = 0;
affected[i].location = 0;
affected[i].bitvector = 0;
affected[i].next = NULL;
}
}
/*
* remove the affections so that the raw values are stored; otherwise the
* effects are doubled when the char logs back in.
*/
while (player->affected)
affect_remove(player, player->affected, 0);
if ((i >= MAX_AFFECT) && af && af->next)
log("SYSERR: WARNING: OUT OF STORE ROOM FOR AFFECTED TYPES!!!");
player->aff_abils = player->real_abils;
memcpy(&abilities,&player->real_abils,sizeof(struct char_ability_data));
memcpy(&points,&player->points,sizeof(struct char_point_data));
memcpy(&ch_saved,&player->char_specials.saved,sizeof(struct char_special_data_saved));
memcpy(&ps_saved,&player->player_specials->saved,sizeof(struct player_special_data_saved));
/* add spell and eq affections back in now */
for (temp = player->carrying; temp; temp = next_obj)
{
next_obj = temp->next_content;
if ((GET_OBJ_TYPE(temp) == ITEM_CYBERWARE) && (GET_OBJ_VAL(temp, 4) == 1))
{
obj_from_char(temp);
obj_to_cyberware(temp, player);
}
/* bioware next */
if (GET_OBJ_TYPE(temp) == ITEM_BIOWARE && GET_OBJ_VAL(temp, 4) == 1)
{
obj_from_char(temp);
obj_to_bioware(temp, player);
}
}
for (i = 0; i < MAX_AFFECT; i++) {
if (affected[i].type)
affect_to_char(player, &affected[i]);
}
// then worn eq
for (i = 0; i < NUM_WEARS; i++) {
if (char_eq[i])
equip_char(player, char_eq[i], i);
}
affect_total(player);
/**************************************************/
if (load_room == NOWHERE)
load_room = GET_LOADROOM(player);
if (!PLR_FLAGGED(player, PLR_LOADROOM))
GET_LOADROOM(player) = load_room;
for (i = 0;(*(bits + i) = LOWER(*(GET_NAME(player) + i))); i++);
sprintf(outname, "%s%s%c%s%s%s", PLR_PREFIX, SLASH, *bits, SLASH, bits, PLR_SUFFIX);
if (!(fl = fopen(outname, "w")))
{
sprintf(buf, "SYSERR: Couldn't open player file (%s) %s for write",outname,GET_NAME(player));
mudlog(buf, NULL, LOG_SYSLOG, TRUE);
return;
}
/***************************************/
/* Code Here for the actual Save Washu */
/***************************************/
/* Player Data */
fprintf(fl, "Name: %s\n", GET_NAME(player));
fprintf(fl, "Pass: %s\n", GET_PASSWD(player));
if(player->player.description && *player->player.description)
{
strcpy(buf, player->player.description);
kill_ems(buf);
fprintf(fl, "Desc: \n%s~\n", buf);
}
else
fprintf(fl, "Desc: \nA %s stands here.\n~\n", pc_race_types[GET_RACE(player)]);
if(POOFIN(player))
fprintf(fl, "PfIn: %s\n", POOFIN(player));
else
fprintf(fl, "PfIn: %s appears in a cloud of smoke.\n", GET_NAME(player));
if(POOFOUT(player))
fprintf(fl, "PfOt: %s\n", POOFOUT(player));
else
fprintf(fl, "PfOt: %s disappears in a cloud of smoke.\n", GET_NAME(player));
if(GET_TITLE(player))
fprintf(fl, "Titl: %s\n", GET_TITLE(player));
if(GET_PRETITLE(player))
fprintf(fl, "PTit: %s\n", GET_PRETITLE(player));
if(GET_WHOTITLE(player))
fprintf(fl, "WTit: %s\n", GET_WHOTITLE(player));
else
fprintf(fl, "WTit: %s\n", pc_race_types[GET_RACE(player)]);
if (player->player.prompt)
fprintf(fl, "Prom: %s\n", player->player.prompt);
if(player->player.mname)
fprintf(fl, "Mnam: %s\n", player->player.mname);
else
fprintf(fl, "Mnam: persona\n");
if(player->player.msdesc)
fprintf(fl, "Msde: %s\n",player->player.msdesc);
else
fprintf(fl, "Msde: a persona\n");
if (player->player.mdesc)
fprintf(fl, "Mdes: %s\n",player->player.mdesc);
else
fprintf(fl, "Mdes: A nondescript persona stands idly here.\n");
if (player->player.mldesc)
fprintf(fl, "Mlde: %s\n", player->player.mldesc);
else
fprintf(fl, "Mlde: You see an nondescript icon.\n");
if (player->player.aname)
fprintf(fl, "Anam: %s\n", player->player.aname);
else
fprintf(fl, "Anam: reflection\n");
if (player->player.asdesc)
fprintf(fl, "Asde: %s\n", player->player.asdesc);
else
fprintf(fl, "Asde: a reflection\n");
if (player->player.adesc)
fprintf(fl, "Ades: %s\n", player->player.adesc);
else
fprintf(fl, "Ades: The reflection of some physical being stands here.\n");
if (player->player.aldesc)
fprintf(fl, "Alde: %s\n", player->player.aldesc);
else
fprintf(fl, "Alde: You see an astral reflection.\n");
fprintf(fl, "Sex : %d\n", GET_SEX(player));
fprintf(fl, "Levl: %d\n", GET_LEVEL(player));
if(player->in_room != NOWHERE)
fprintf(fl, "Home: %d\n", world[player->in_room].number);
else
fprintf(fl, "Home: %d\n", NOWHERE);
fprintf(fl, "Brth: %ld\n", player->player.time.birth);
fprintf(fl, "Plyd: %d\n", player->player.time.played);
fprintf(fl, "Last: %ld\n", time(0));
if(player->player.host)
fprintf(fl, "Host: %s\n", player->player.host);
fprintf(fl, "Hite: %d\n", GET_HEIGHT(player));
fprintf(fl, "Wate: %d\n", GET_WEIGHT(player));
fprintf(fl, "Trad: %d\n", GET_TRADITION(player));
fprintf(fl, "Race: %d\n", GET_RACE(player));
/* End Player Data */
/* Ability Data*/
fprintf(fl, "Str : %d\n", abilities.str);
fprintf(fl, "Int : %d\n", abilities.intel);
fprintf(fl, "Wil : %d\n", abilities.wil);
fprintf(fl, "Qui : %d\n", abilities.qui);
fprintf(fl, "Bod : %d\n", abilities.bod);
fprintf(fl, "Cha : %d\n", abilities.cha);
fprintf(fl, "Mag : %d\n", abilities.mag);
fprintf(fl, "RMag: %d\n", abilities.rmag);
fprintf(fl, "Ess : %d\n", abilities.ess);
fprintf(fl, "Rea : %d\n", abilities.rea);
fprintf(fl, "BInd: %d\n", abilities.bod_index);
fprintf(fl, "Apoo: %d\n", abilities.astral_pool);
fprintf(fl, "Dpoo: %d\n", abilities.defense_pool);
fprintf(fl, "Cpoo: %d\n", abilities.combat_pool);
fprintf(fl, "Hpoo: %d\n", abilities.hacking_pool);
fprintf(fl, "Mpoo: %d\n", abilities.magic_pool);
fprintf(fl, "Opoo: %d\n", abilities.offense_pool);
fprintf(fl, "Rpoo: 0\n");
/* End Ability data */
/* Point Data */
fprintf(fl, "Balc: %d\n",0);
fprintf(fl, "Impt: %d\n",0);
fprintf(fl, "IDic: %d\n",0);
fprintf(fl, "IRol: %d\n",0);
fprintf(fl, "Sust: %d\n",0);
fprintf(fl, "Ment: %d/%d\n", points.mental, points.max_mental);
fprintf(fl, "Phys: %d/%d\n", points.physical, points.max_physical);
fprintf(fl, "Nuye: %d\n", points.nuyen);
fprintf(fl, "Bank: %d\n", points.bank);
fprintf(fl, "Karm: %d\n", points.karma);
fprintf(fl, "Rep : %d\n", points.rep);
fprintf(fl, "Grad: %d\n", points.grade);
/* End point data */
/* Char Specials Saved */
fprintf(fl, "Alin: %d\n", ch_saved.alignment);
fprintf(fl, "Id : %ld\n", ch_saved.idnum);
if(ch_saved.act != 0)
fprintf(fl, "Act : %ld\n", ch_saved.act);
if(ch_saved.affected_by != 0)
{
sprintbits(ch_saved.affected_by, bits);
fprintf(fl, "Aff : %s\n", bits);
}
fprintf(fl, "Skil:\n");
for(i = 1; i <= MAX_SKILLS; i++)
{
if(ch_saved.skills[i])
fprintf(fl, "%d %d\n", i, ch_saved.skills[i]);
}
fprintf(fl, "0 0\n");
fprintf(fl, "LHan: %d\n",ch_saved.left_handed);
fprintf(fl, "CLan: %d\n",ch_saved.cur_lang);
/* End Char Special Saved*/
/* player Specials Saved */
fprintf(fl, "Wimp: %d\n", ps_saved.wimp_level);
if(ps_saved.freeze_level != 0)
fprintf(fl, "Frez: %d\n", ps_saved.freeze_level);
if(ps_saved.invis_level != 0)
fprintf(fl, "Invs: %d\n", ps_saved.invis_level);
fprintf(fl, "Room: %d\n", ps_saved.load_room);
if(ps_saved.pref != 0)
{
sprintbits(ps_saved.pref, bits);
fprintf(fl, "Pref: %s\n", bits);
}
if(ps_saved.bad_pws != 0)
fprintf(fl, "Badp: %d\n", ps_saved.bad_pws);
if(ps_saved.conditions[FULL] != 0 && GET_LEVEL(player) < LVL_LEGEND)
fprintf(fl, "Hung: %d\n", ps_saved.conditions[FULL]);
if(ps_saved.conditions[THIRST] != 0 && GET_LEVEL(player) < LVL_LEGEND)
fprintf(fl, "Thir: %d\n", ps_saved.conditions[THIRST]);
if(ps_saved.conditions[DRUNK] != 0 && GET_LEVEL(player) < LVL_LEGEND)
fprintf(fl, "Drnk: %d\n", ps_saved.conditions[DRUNK]);
fprintf(fl, "Ally: %d\n", ps_saved.allergy);
fprintf(fl, "Asev: %d\n", ps_saved.severity);
fprintf(fl, "Arec: %d\n", ps_saved.reaction);
if(ps_saved.totem != 0)
fprintf(fl, "Totm: %d\n", ps_saved.totem);
if(ps_saved.att_points != 0)
fprintf(fl, "Satt: %d\n", ps_saved.att_points);
if(ps_saved.skill_points != 0)
fprintf(fl, "Sskl: %d\n", ps_saved.skill_points);
if(GET_LEVEL(player) >= LVL_LEGEND)
fprintf(fl, "Znum: %d\n", ps_saved.zonenum);
fclose(fl);
if((id = find_name(GET_NAME(player))) < 0)
return;
player_table[id].level = GET_LEVEL(player);
i = player_table[id].flags;
if(PLR_FLAGGED(player, PLR_DELETED))
SET_BIT(player_table[id].flags, PINDEX_DELETED);
else
REMOVE_BIT(player_table[id].flags, PINDEX_DELETED);
if(PLR_FLAGGED(player, PLR_NODELETE) || PLR_FLAGGED(player, PLR_CRYO))
SET_BIT(player_table[id].flags, PINDEX_NODELETE);
else
REMOVE_BIT(player_table[id].flags, PINDEX_NODELETE);
if(player_table[id].flags != i || save_index)
save_player_index();
}
/* copy data from the file structure to a char struct */
void save_etext(struct char_data * ch)
{
if (!get_filename(GET_NAME(ch), buf2, ETEXT_FILE) || !GET_ALIASES(ch))
return;
FILE *outFile;
if (!(outFile = fopen(buf2, "w+"))) {
sprintf(buf, "Unable to write %s's alias file.\n", GET_NAME(ch));
mudlog(buf, ch, LOG_SYSLOG, TRUE);
return;
}
for (struct alias *a = GET_ALIASES(ch); a; a = a->next)
fprintf(outFile, "%s %s\n", a->command, a->replacement);
fclose(outFile);
}
void read_etext(struct char_data *ch)
{
if (GET_ALIASES(ch) || !get_filename(GET_NAME(ch), buf2, ETEXT_FILE))
return;
FILE *inFile;
if (!(inFile = fopen(buf2, "r"))) {
if (errno != ENOENT) {
sprintf(buf, "Unable to open %s's alias file.\n", GET_NAME(ch));
mudlog(buf, ch, LOG_SYSLOG, TRUE);
}
return;
}
char *repl;
char line[256];
while (get_line(inFile, line)) {
repl = any_one_arg(line, arg);
struct alias *a = new alias;
a->command = str_dup(arg);
skip_spaces(&repl);
a->replacement = str_dup(repl);
if (strchr((const char *)repl, ALIAS_SEP_CHAR) ||
strchr((const char *)repl, ALIAS_VAR_CHAR))
a->type = ALIAS_COMPLEX;
else a->type = ALIAS_SIMPLE;
a->next = GET_ALIASES(ch);
GET_ALIASES(ch) = a;
}
fclose(inFile);
}
/* create a new entry in the in-memory index table for the player file */
int create_entry(char *name)
{
int i;
if (top_of_p_table == -1) {
player_table = new player_index_element;
top_of_p_table = 0;
}
else
{
player_index_element *temp = new player_index_element[++top_of_p_table + 1];
if (!temp)
{
perror("create entry");
exit(1);
}
for (register int iterator = 0; iterator < (top_of_p_table + 1); ++iterator)
{
temp[iterator].name = player_table[iterator].name;
temp[iterator].id = player_table[iterator].id;
temp[iterator].level = player_table[iterator].level;
temp[iterator].flags = player_table[iterator].flags;
temp[iterator].last = player_table[iterator].last;
}
delete [] player_table;
player_table = temp;
}
player_table[top_of_p_table].name = new char[strlen(name) + 1];
/* copy lowercase equivalent of name to table field */
for (i = 0; (*(player_table[top_of_p_table].name + i) = LOWER(*(name + i)));i++);
return (top_of_p_table);
}
/************************************************************************
* funcs of a (more or less) general utility nature *
********************************************************************** */
// These were added for OLC purposes. They'll allocate a new array of
// the old size + 100 elements, copy over, and Free up the old one.
// They return TRUE if it worked, FALSE if it didn't. I could add in some
// checks and report to folks using OLC that currently there's not enough
// room to allocate. Obviously these belong in an object once I convert
// completely over to C++.
bool resize_world_array()
{
int counter, result;
struct room_data *new_world;
new_world = new struct room_data[top_of_world_array + world_chunk_size];
if (!new_world) {
mudlog("Unable to allocate new world array.", NULL, LOG_SYSLOG, TRUE);
mudlog("OLC temporarily unavailable.", NULL, LOG_SYSLOG, TRUE);
olc_state = 0; // disallow any olc from here on
return FALSE;
}
// remember that top_of_world is the actual rnum in the array
for (counter = 0; counter <= top_of_world; counter++)
new_world[counter] = world[counter];
top_of_world_array += world_chunk_size;
delete [] world;
world = new_world;
sprintf(buf, "World array resized to %d.", top_of_world_array);
mudlog(buf, NULL, LOG_SYSLOG, TRUE);
return TRUE;
}
bool resize_mob_array() {
int counter;
struct char_data *new_mob;
struct index_data *new_mob_index;
new_mob = new struct char_data[top_of_mob_array + mob_chunk_size];
if (!new_mob) {
mudlog("Unable to allocate new mob array.", NULL, LOG_SYSLOG, TRUE);
mudlog("OLC temporarily unavailable.", NULL, LOG_SYSLOG, TRUE);
olc_state = 0;
return FALSE;
}
new_mob_index = new struct index_data[top_of_mob_array + mob_chunk_size];
if (!new_mob_index) {
mudlog("Unable to allocate new mob index array.", NULL, LOG_SYSLOG, TRUE);
mudlog("OLC temporarily unavailable.", NULL, LOG_SYSLOG, TRUE);
olc_state = 0;
return FALSE;
}
// do both mob_proto and mob_index
for (counter = 0; counter <= top_of_mobt; counter++) {
new_mob[counter] = mob_proto[counter];
new_mob_index[counter] = mob_index[counter];
}
top_of_mob_array += mShowing the first 100 KB of 123.2 KB. Download the archive for the full file.