-
Notifications
You must be signed in to change notification settings - Fork 0
/
genwld.c
executable file
·533 lines (454 loc) · 14.6 KB
/
genwld.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
/************************************************************************
* Generic OLC Library - Rooms / genwld.c v1.0 *
* Original author: Levork *
* Copyright 1996 by Harvey Gilpin *
* Copyright 1997-2001 by George Greer (greerga@circlemud.org) *
************************************************************************/
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "db.h"
#include "handler.h"
#include "comm.h"
#include "genolc.h"
#include "genwld.h"
#include "genzon.h"
#include "dg_olc.h"
extern struct room_data *world;
extern struct zone_data *zone_table;
extern struct index_data *mob_index;
extern zone_rnum top_of_zone_table;
extern room_rnum r_mortal_start_room;
extern room_rnum r_immort_start_room;
extern room_rnum r_frozen_start_room;
extern room_rnum r_newbie_start_room;
extern room_rnum r_sorin_start_room;
/*
* This function will copy the strings so be sure you free your own
* copies of the description, title, and such.
*/
room_rnum add_room(struct room_data *room)
{
struct char_data *tch;
struct obj_data *tobj;
int i, j, found = FALSE;
if (room == NULL)
return NOWHERE;
if ((i = real_room(room->number)) != NOWHERE) {
tch = world[i].people;
tobj = world[i].contents;
copy_room(&world[i], room);
world[i].people = tch;
world[i].contents = tobj;
add_to_save_list(zone_table[room->zone].number, SL_WLD);
log("GenOLC: add_room: Updated existing room #%d.", room->number);
return i;
}
RECREATE(world, struct room_data, top_of_world + 2);
top_of_world++;
for (i = top_of_world; i > 0; i--) {
if (room->number > world[i - 1].number) {
world[i] = *room;
copy_room_strings(&world[i], room);
found = i;
break;
} else {
/* Copy the room over now. */
world[i] = world[i - 1];
/* People in this room must have their in_rooms moved up one. */
for (tch = world[i].people; tch; tch = tch->next_in_room)
IN_ROOM(tch) += (IN_ROOM(tch) != NOWHERE);
/* Move objects too. */
for (tobj = world[i].contents; tobj; tobj = tobj->next_content)
IN_ROOM(tobj) += (IN_ROOM(tobj) != NOWHERE);
}
}
if (!found) {
world[0] = *room; /* Last place, in front. */
copy_room_strings(&world[0], room);
}
log("GenOLC: add_room: Added room %d at index #%d.", room->number, found);
/* found is equal to the array index where we added the room. */
/*
* Find what zone that room was in so we can update the loading table.
*/
for (i = room->zone; i <= top_of_zone_table; i++)
for (j = 0; ZCMD(i, j).command != 'S'; j++)
switch (ZCMD(i, j).command) {
case 'M':
case 'O':
case 'T':
case 'V':
ZCMD(i, j).arg3 += (ZCMD(i, j).arg3 >= found);
break;
case 'D':
case 'R':
ZCMD(i, j).arg1 += (ZCMD(i, j).arg1 >= found);
case 'G':
case 'P':
case 'E':
case '*':
/* Known zone entries we don't care about. */
break;
default:
mudlog(BRF, LVL_DEITY, TRUE, "SYSERR: GenOLC: add_room: Unknown zone entry found!");
}
/*
* Update the loadroom table. Adds 1 or 0.
*/
r_mortal_start_room += (r_mortal_start_room >= found);
r_immort_start_room += (r_immort_start_room >= found);
r_frozen_start_room += (r_frozen_start_room >= found);
r_newbie_start_room += (r_newbie_start_room >= found);
r_sorin_start_room += (r_sorin_start_room >= found);
/*
* Update world exits & triggers.
*/
for (i = top_of_world; i >= 0; i--) {
/* exits */
for (j = 0; j < NUM_OF_DIRS; j++)
if (W_EXIT(i, j))
W_EXIT(i, j)->to_room += (W_EXIT(i, j)->to_room >= found);
/* TRIGGERS */
if(SCRIPT(&world[i])) {
extract_script(SCRIPT(&world[i]));
SCRIPT(&world[i]) = NULL;
}
assign_triggers(&world[i], WLD_TRIGGER);
}
add_to_save_list(zone_table[room->zone].number, SL_WLD);
/*
* Return what array entry we placed the new room in.
*/
return found;
}
/* -------------------------------------------------------------------------- */
int delete_room(room_rnum rnum)
{
int i, j;
struct char_data *ppl, *next_ppl;
struct obj_data *obj, *next_obj;
struct room_data *room;
if (rnum <= 0 || rnum > top_of_world) /* Can't delete void yet. */
return FALSE;
room = &world[rnum];
add_to_save_list(zone_table[room->zone].number, SL_WLD);
/* This is something you might want to read about in the logs. */
log("GenOLC: delete_room: Deleting room #%d (%s).", room->number, room->name);
if (r_mortal_start_room == rnum) {
log("WARNING: GenOLC: delete_room: Deleting mortal start room!");
r_mortal_start_room = 0; /* The Void */
}
if (r_immort_start_room == rnum) {
log("WARNING: GenOLC: delete_room: Deleting immortal start room!");
r_immort_start_room = 0; /* The Void */
}
if (r_newbie_start_room == rnum) {
log("WARNING: GenOLC: delete_room: Deleting newbie start room!");
r_newbie_start_room = 0; /* The Void */
}
if (r_sorin_start_room == rnum) {
log("WARNING: GenOLC: delete_room: Deleting sorin start room!");
r_sorin_start_room = 0; /* The Void */
}
if (r_frozen_start_room == rnum) {
log("WARNING: GenOLC: delete_room: Deleting frozen start room!");
r_frozen_start_room = 0; /* The Void */
}
/*
* Dump the contents of this room into the Void. We could also just
* extract the people, mobs, and objects here.
*/
for (obj = world[rnum].contents; obj; obj = next_obj) {
next_obj = obj->next_content;
obj_from_room(obj);
obj_to_room(obj, 0);
}
for (ppl = world[rnum].people; ppl; ppl = next_ppl) {
next_ppl = ppl->next_in_room;
char_from_room(ppl);
char_to_room(ppl, 0);
}
free_room_strings(room);
/*
* Change any exit going to this room to go the void.
* Also fix all the exits pointing to rooms above this.
*/
for (i = top_of_world; i >= 0; i--)
for (j = 0; j < NUM_OF_DIRS; j++)
if (W_EXIT(i, j) == NULL)
continue;
else if (W_EXIT(i, j)->to_room > rnum)
W_EXIT(i, j)->to_room--;
else if (W_EXIT(i, j)->to_room == rnum)
W_EXIT(i, j)->to_room = 0; /* Some may argue -1. */
/*
* Find what zone that room was in so we can update the loading table.
*/
for (i = 0; i <= top_of_zone_table; i++)
for (j = 0; ZCMD(i , j).command != 'S'; j++)
switch (ZCMD(i, j).command) {
case 'M':
case 'O':
case 'T':
case 'V':
if (ZCMD(i, j).arg3 == rnum)
ZCMD(i, j).command = '*'; /* Cancel command. */
else if (ZCMD(i, j).arg3 > rnum)
ZCMD(i, j).arg3--;
break;
case 'D':
case 'R':
if (ZCMD(i, j).arg1 == rnum)
ZCMD(i, j).command = '*'; /* Cancel command. */
else if (ZCMD(i, j).arg1 > rnum)
ZCMD(i, j).arg1--;
case 'G':
case 'P':
case 'E':
case '*':
/* Known zone entries we don't care about. */
break;
default:
mudlog(BRF, LVL_DEITY, TRUE, "SYSERR: GenOLC: delete_room: Unknown zone entry found!");
}
/*
* Now we actually move the rooms down.
*/
for (i = rnum; i < top_of_world; i++) {
world[i] = world[i + 1];
for (ppl = world[i].people; ppl; ppl = ppl->next_in_room)
IN_ROOM(ppl) -= (IN_ROOM(ppl) != NOWHERE); /* Redundant check? */
for (obj = world[i].contents; obj; obj = obj->next_content)
IN_ROOM(obj) -= (IN_ROOM(obj) != NOWHERE); /* Redundant check? */
}
top_of_world--;
RECREATE(world, struct room_data, top_of_world + 1);
return TRUE;
}
int save_rooms(zone_rnum rzone)
{
int i;
int dflag = 0;
struct room_data *room;
FILE *sf;
char buf[MAX_STRING_LENGTH];
char buf1[MAX_STRING_LENGTH];
char buf2[MAX_STRING_LENGTH];
if (rzone == NOWHERE || rzone > top_of_zone_table) {
log("SYSERR: GenOLC: save_rooms: Invalid zone number %d passed! (0-%d)", rzone, top_of_zone_table);
return FALSE;
}
log("GenOLC: save_rooms: Saving rooms in zone #%d (%d-%d).",
zone_table[rzone].number, genolc_zone_bottom(rzone), zone_table[rzone].top);
sprintf(buf, "%s/%d.new", WLD_PREFIX, zone_table[rzone].number);
if (!(sf = fopen(buf, "w"))) {
perror("SYSERR: save_rooms");
return FALSE;
}
for (i = genolc_zone_bottom(rzone); i <= zone_table[rzone].top; i++) {
int rnum;
if ((rnum = real_room(i)) != NOWHERE) {
int j;
room = (world + rnum);
/*
* Copy the description and strip off trailing newlines.
*/
strcpy(buf, room->description ? room->description : "Empty room.");
strip_cr(buf);
/*
* Save the numeric and string section of the file.
*/
sprintasciilong(buf2, room->room_flags);
fprintf(sf, "#%d\n"
"%s%c\n"
"%s%c\n"
"%d %s %d %d %d %d %d\n",
room->number,
room->name ? room->name : "Untitled", STRING_TERMINATOR,
buf, STRING_TERMINATOR,
zone_table[room->zone].number, buf2, room->sector_type,
room->size, room->nat_light, room->min_level, room->max_level
);
/*
* Now you write out the exits for the room.
*/
for (j = 0; j < NUM_OF_DIRS; j++) {
if (R_EXIT(room, j)) {
if (R_EXIT(room, j)->general_description) {
strcpy(buf, R_EXIT(room, j)->general_description);
strip_cr(buf);
} else
*buf = '\0';
/*
* Figure out door flag.
*/
if (IS_SET(R_EXIT(room, j)->exit_info, EX_ISDOOR)) {
dflag = 1;
if (IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF) &&
!IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN))
dflag = 2;
if (IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN) &&
!IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF))
dflag = 3;
if (IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN) &&
IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF))
dflag = 4;
} else
if (!IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN))
dflag = 0;
if (R_EXIT(room, j)->keyword)
strcpy(buf1, R_EXIT(room, j)->keyword);
else
*buf1 = '\0';
/*
* Now write the exit to the file.
*/
fprintf(sf, "D%d\n"
"%s~\n"
"%s~\n"
"%d %d %d\n", j, buf, buf1, dflag,
R_EXIT(room, j)->key, R_EXIT(room, j)->to_room != -1 ?
world[R_EXIT(room, j)->to_room].number : -1);
}
}
if (room->ex_description) {
struct extra_descr_data *xdesc;
for (xdesc = room->ex_description; xdesc; xdesc = xdesc->next) {
strcpy(buf, xdesc->description);
strip_cr(buf);
fprintf(sf, "E\n"
"%s~\n"
"%s~\n", xdesc->keyword, buf);
}
}
if (room->pain_message) {
fprintf(sf, "P\n"
"%s~\n"
"%d~\n"
"%d~\n", room->pain_message, room->pain_damage,
room->pain_rate );
}
if (room->nomagic_message_room && room->nomagic_message_caster ) {
fprintf(sf, "N\n"
"%s~\n"
"%s~\n",
room->nomagic_message_caster, room->nomagic_message_room );
}
if (room->min_level_message || room->max_level_message ) {
fprintf(sf, "F\n"
"%s~\n"
"%s~\n",
room->min_level_message, room->max_level_message );
}
fprintf(sf, "S\n");
script_save_to_disk(sf, room, WLD_TRIGGER);
}
}
/*
* Write the final line and close it.
*/
fprintf(sf, "$~\n");
fclose(sf);
/* New file we just made. */
sprintf(buf, "%s/%d.new", WLD_PREFIX, zone_table[rzone].number);
/* Old file we're replacing. */
sprintf(buf2, "%s/%d.wld", WLD_PREFIX, zone_table[rzone].number);
remove(buf2);
rename(buf, buf2);
remove_from_save_list(zone_table[rzone].number, SL_WLD);
return TRUE;
}
int copy_room(struct room_data *to, struct room_data *from)
{
free_room_strings(to);
*to = *from;
copy_room_strings(to, from);
/* Don't put people and objects in two locations.
Am thinking this shouldn't be done here... */
from->people = NULL;
from->contents = NULL;
return TRUE;
}
/*
* Idea by: Cris Jacobin <jacobin@bellatlantic.net>
*/
room_rnum duplicate_room(room_vnum dest_vnum, room_rnum orig)
{
int new_rnum, znum;
struct room_data nroom;
if (orig == NOWHERE || orig > top_of_world) {
log("SYSERR: GenOLC: copy_room: Given bad original real room.");
return -1;
} else if ((znum = real_zone_by_thing(dest_vnum)) == NOWHERE) {
log("SYSERR: GenOLC: copy_room: No such destination zone.");
return -1;
}
/*
* add_room will make its own copies of strings.
*/
if ((new_rnum = add_room(&nroom)) == NOWHERE) {
log("SYSERR: GenOLC: copy_room: Problem adding room.");
return -1;
}
nroom = world[new_rnum];
nroom.number = dest_vnum;
nroom.zone = znum;
/* So the people and objects aren't in two places at once... */
nroom.contents = NULL;
nroom.people = NULL;
return new_rnum;
}
/* -------------------------------------------------------------------------- */
/*
* Copy strings over so bad things don't happen. We do not free the
* existing strings here because copy_room() did a shallow copy previously
* and we'd be freeing the very strings we're copying. If this function
* is used elsewhere, be sure to free_room_strings() the 'dest' room first.
*/
int copy_room_strings(struct room_data *dest, struct room_data *source)
{
int i;
if (dest == NULL || source == NULL) {
log("SYSERR: GenOLC: copy_room_strings: NULL values passed.");
return FALSE;
}
dest->description = strdup(source->description ? source->description : "<NULL>");
dest->name = strdup(source->name ? source->name : "<NULL>");
for (i = 0; i < NUM_OF_DIRS; i++) {
if (!R_EXIT(source, i))
continue;
CREATE(R_EXIT(dest, i), struct room_direction_data, 1);
*R_EXIT(dest, i) = *R_EXIT(source, i);
if (R_EXIT(source, i)->general_description)
R_EXIT(dest, i)->general_description = strdup(R_EXIT(source, i)->general_description);
if (R_EXIT(source, i)->keyword)
R_EXIT(dest, i)->keyword = strdup(R_EXIT(source, i)->keyword);
}
if (source->ex_description)
copy_ex_descriptions(&dest->ex_description, source->ex_description);
return TRUE;
}
int free_room_strings(struct room_data *room)
{
int i;
/* Free descriptions. */
if (room->name)
free(room->name);
if (room->description)
free(room->description);
if (room->ex_description)
free_ex_descriptions(room->ex_description);
/* Free exits. */
for (i = 0; i < NUM_OF_DIRS; i++) {
if (room->dir_option[i]) {
if (room->dir_option[i]->general_description)
free(room->dir_option[i]->general_description);
if (room->dir_option[i]->keyword)
free(room->dir_option[i]->keyword);
free(room->dir_option[i]);
}
}
return TRUE;
}