forked from DIKUNIX/dikumud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.c
2292 lines (1773 loc) · 48.3 KB
/
db.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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**************************************************************************
* file: db.c , Database module. Part of DIKUMUD *
* Usage: Loading/Saving chars, booting world, resetting etc. *
* Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
***************************************************************************/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "structs.h"
#include "utils.h"
#include "db.h"
#include "comm.h"
#include "handler.h"
#include "limits.h"
#define NEW_ZONE_SYSTEM
/**************************************************************************
* declarations of most of the 'global' variables *
************************************************************************ */
struct room_data *world; /* dyn alloc'ed array of rooms */
int top_of_world = 0; /* ref to the top element of world */
struct obj_data *object_list = 0; /* the global linked list of obj's */
struct char_data *character_list = 0; /* global l-list of chars */
struct zone_data *zone_table; /* table of reset data */
int top_of_zone_table = 0;
struct message_list fight_messages[MAX_MESSAGES]; /* fighting messages */
struct player_index_element *player_table = 0; /* index to player file */
int top_of_p_table = 0; /* ref to top of table */
int top_of_p_file = 0;
char credits[MAX_STRING_LENGTH]; /* the Credits List */
char news[MAX_STRING_LENGTH]; /* the news */
char motd[MAX_STRING_LENGTH]; /* the messages of today */
char help[MAX_STRING_LENGTH]; /* the main help page */
char info[MAX_STRING_LENGTH]; /* the info text */
char wizlist[MAX_STRING_LENGTH]; /* the wizlist */
FILE *mob_f, /* file containing mob prototypes */
*obj_f, /* obj prototypes */
*help_fl; /* file for help texts (HELP <kwd>)*/
struct index_data *mob_index; /* index table for mobile file */
struct index_data *obj_index; /* index table for object file */
struct help_index_element *help_index = 0;
int top_of_mobt = 0; /* top of mobile index table */
int top_of_objt = 0; /* top of object index table */
int top_of_helpt; /* top of help index table */
struct time_info_data time_info; /* the infomation about the time */
struct weather_data weather_info; /* the infomation about the weather */
bool wizlock = FALSE; /* is the game wizlocked */
/* local procedures */
void boot_zones(void);
void setup_dir(FILE *fl, int room, int dir);
void allocate_room(int new_top);
void boot_world(void);
struct index_data *generate_indices(FILE *fl, int *top);
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 file_to_string(char *name, char *buf);
void renum_world(void);
void renum_zone_table(void);
void reset_time(void);
void clear_char(struct char_data *ch);
/* external refs */
extern struct descriptor_data *descriptor_list;
void load_messages(void);
void weather_and_time ( int mode );
void assign_command_pointers ( void );
void assign_spell_pointers ( void );
void log_message(char *str);
int dice(int number, int size);
int number(int from, int to);
void boot_social_messages(void);
void boot_pose_messages(void);
void update_obj_file(void); /* In reception.c */
struct help_index_element *build_help_index(FILE *fl, int *num);
/*************************************************************************
* routines for booting the system *
*********************************************************************** */
/* body of the booting system */
void boot_db(void)
{
int i;
extern int no_specials;
log_message("Boot db -- BEGIN.");
log_message("Resetting the game time:");
reset_time();
log_message("Reading newsfile, credits, help-page, info and motd.");
file_to_string(NEWS_FILE, news);
file_to_string(CREDITS_FILE, credits);
file_to_string(MOTD_FILE, motd);
file_to_string(HELP_PAGE_FILE, help);
file_to_string(INFO_FILE, info);
file_to_string(WIZLIST_FILE, wizlist);
log_message("Opening mobile, object and help files.");
if (!(mob_f = fopen(MOB_FILE, "r")))
{
perror("boot");
exit(0);
}
if (!(obj_f = fopen(OBJ_FILE, "r")))
{
perror("boot");
exit(0);
}
if (!(help_fl = fopen(HELP_KWRD_FILE, "r")))
log_message(" Could not open help file.");
else
help_index = build_help_index(help_fl, &top_of_helpt);
log_message("Loading zone table.");
boot_zones();
log_message("Loading rooms.");
boot_world();
log_message("Renumbering rooms.");
renum_world();
log_message("Generating index tables for mobile and object files.");
mob_index = generate_indices(mob_f, &top_of_mobt);
obj_index = generate_indices(obj_f, &top_of_objt);
log_message("Renumbering zone table.");
renum_zone_table();
log_message("Generating player index.");
build_player_index();
log_message("Loading fight messages.");
load_messages();
log_message("Loading social messages.");
boot_social_messages();
log_message("Loading pose messages.");
boot_pose_messages();
log_message("Assigning function pointers:");
if (!no_specials)
{
log_message(" Mobiles.");
assign_mobiles();
log_message(" Objects.");
assign_objects();
log_message(" Room.");
assign_rooms();
}
log_message(" Commands.");
assign_command_pointers();
log_message(" Spells.");
assign_spell_pointers();
log_message("Updating characters with saved items:");
update_obj_file();
for (i = 0; i <= top_of_zone_table; i++)
{
fprintf(stderr, "Performing boot-time reset of %s (rooms %d-%d).\n",
zone_table[i].name,
(i ? (zone_table[i - 1].top + 1) : 0),
zone_table[i].top);
reset_zone(i);
}
reset_q.head = reset_q.tail = 0;
log_message("Boot db -- DONE.");
}
/* reset the time in the game from file */
void reset_time(void)
{
char buf[MAX_STRING_LENGTH];
struct time_info_data mud_time;
long beginning_of_time = 650336715;
struct time_info_data mud_time_passed(time_t t2, time_t t1);
time_info = mud_time_passed(time(0), beginning_of_time);
/*
FILE *f1;
long current_time;
long last_time;
long diff_time;
long diff_hours;
if (!(f1 = fopen(TIME_FILE, "r")))
{
perror("reset time");
exit(0);
}
fscanf(f1, "#\n");
fscanf(f1, "%ld\n", &last_time);
fscanf(f1, "%d\n", &last_time_info.hours);
fscanf(f1, "%d\n", &last_time_info.day);
fscanf(f1, "%d\n", &last_time_info.month);
fscanf(f1, "%d\n", &last_time_info.year);
fclose(f1);
sprintf(buf," Last Gametime: %dH %dD %dM %dY.",
last_time_info.hours, last_time_info.day,
last_time_info.month, last_time_info.year);
log_message(buf);
current_time = time(0);
diff_time = current_time - last_time;
sprintf(buf," Time since last shutdown: %d.", diff_time);
log_message(buf);
time_info.hours = last_time_info.hours;
time_info.day = last_time_info.day;
time_info.month = last_time_info.month;
time_info.year = last_time_info.year;
diff_hours = diff_time/SECS_PER_MUD_HOUR;
diff_time = diff_time % SEC_PR_HOUR;
sprintf(buf," Real time lack : %d sec.", diff_time);
log_message(buf);
for(;diff_hours > 0; diff_hours--)
weather_and_time(0);
*/
switch(time_info.hours){
case 0 :
case 1 :
case 2 :
case 3 :
case 4 :
{
weather_info.sunlight = SUN_DARK;
break;
}
case 5 :
{
weather_info.sunlight = SUN_RISE;
break;
}
case 6 :
case 7 :
case 8 :
case 9 :
case 10 :
case 11 :
case 12 :
case 13 :
case 14 :
case 15 :
case 16 :
case 17 :
case 18 :
case 19 :
case 20 :
{
weather_info.sunlight = SUN_LIGHT;
break;
}
case 21 :
{
weather_info.sunlight = SUN_SET;
break;
}
case 22 :
case 23 :
default :
{
weather_info.sunlight = SUN_DARK;
break;
}
}
sprintf(buf," Current Gametime: %dH %dD %dM %dY.",
time_info.hours, time_info.day,
time_info.month, time_info.year);
log_message(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);
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;
}
/* update the time file */
void update_time(void)
{
FILE *f1;
extern struct time_info_data time_info;
long current_time;
return;
if (!(f1 = fopen(TIME_FILE, "w")))
{
perror("update time");
exit(0);
}
current_time = time(0);
log_message("Time update.");
fprintf(f1, "#\n");
fprintf(f1, "%d\n", current_time);
fprintf(f1, "%d\n", time_info.hours);
fprintf(f1, "%d\n", time_info.day);
fprintf(f1, "%d\n", time_info.month);
fprintf(f1, "%d\n", time_info.year);
fclose(f1);
}
/* generate index table for the player file */
void build_player_index(void)
{
int nr = -1, i;
struct char_file_u dummy;
FILE *fl;
if (!(fl = fopen(PLAYER_FILE, "rb+")))
{
perror("build player index");
exit(0);
}
for (; !feof(fl);)
{
fread(&dummy, sizeof(struct char_file_u), 1, fl);
if (!feof(fl)) /* new record */
{
/* Create new entry in the list */
if (nr == -1) {
CREATE(player_table,
struct player_index_element, 1);
nr = 0;
} else {
if (!(player_table = (struct player_index_element *)
realloc(player_table, (++nr + 1) *
sizeof(struct player_index_element))))
{
perror("generate index");
exit(0);
}
}
player_table[nr].nr = nr;
CREATE(player_table[nr].name, char,
strlen(dummy.name) + 1);
for (i = 0; *(player_table[nr].name + i) =
LOWER(*(dummy.name + i)); i++);
}
}
fclose(fl);
top_of_p_table = nr;
top_of_p_file = top_of_p_table;
}
/* generate index table for object or monster file */
struct index_data *generate_indices(FILE *fl, int *top)
{
int i = 0;
struct index_data *index;
long pos;
char buf[82];
rewind(fl);
for (;;)
{
if (fgets(buf, 81, fl))
{
if (*buf == '#')
{
/* allocate new cell */
if (!i) /* first cell */
CREATE(index, struct index_data, 1);
else
if (!(index =
(struct index_data*) realloc(index,
(i + 1) * sizeof(struct index_data))))
{
perror("load indices");
exit(0);
}
sscanf(buf, "#%d", &index[i].virtual);
index[i].pos = ftell(fl);
index[i].number = 0;
index[i].func = 0;
i++;
}
else
if (*buf == '$') /* EOF */
break;
}
else
{
perror("generate indices");
exit(0);
}
}
*top = i - 2;
return(index);
}
/* load the rooms */
void boot_world(void)
{
FILE *fl;
int room_nr = 0, zone = 0, dir_nr, virtual_nr, flag, tmp;
char *temp, chk[50];
struct extra_descr_data *new_descr;
world = 0;
character_list = 0;
object_list = 0;
if (!(fl = fopen(WORLD_FILE, "r")))
{
perror("fopen");
log_message("boot_world: could not open world file.");
exit(0);
}
do
{
fscanf(fl, " #%d\n", &virtual_nr);
temp = fread_string(fl);
if (flag = (*temp != '$')) /* a new record to be read */
{
allocate_room(room_nr);
world[room_nr].number = virtual_nr;
world[room_nr].name = temp;
world[room_nr].description = fread_string(fl);
if (top_of_zone_table >= 0)
{
fscanf(fl, " %*d ");
/* OBS: Assumes ordering of input rooms */
if (world[room_nr].number <= (zone ? zone_table[zone-1].top : -1))
{
fprintf(stderr, "Room nr %d is below zone %d.\n",
room_nr, zone);
exit(0);
}
while (world[room_nr].number > zone_table[zone].top)
if (++zone > top_of_zone_table)
{
fprintf(stderr, "Room %d is outside of any zone.\n",
virtual_nr);
exit(0);
}
world[room_nr].zone = zone;
}
fscanf(fl, " %d ", &tmp);
world[room_nr].room_flags = tmp;
fscanf(fl, " %d ", &tmp);
world[room_nr].sector_type = tmp;
world[room_nr].funct = 0;
world[room_nr].contents = 0;
world[room_nr].people = 0;
world[room_nr].light = 0; /* Zero light sources */
for (tmp = 0; tmp <= 5; tmp++)
world[room_nr].dir_option[tmp] = 0;
world[room_nr].ex_description = 0;
for (;;)
{
fscanf(fl, " %s \n", chk);
if (*chk == 'D') /* direction field */
setup_dir(fl, room_nr, atoi(chk + 1));
else if (*chk == 'E') /* extra description field */
{
CREATE(new_descr, struct extra_descr_data, 1);
new_descr->keyword = fread_string(fl);
new_descr->description = fread_string(fl);
new_descr->next = world[room_nr].ex_description;
world[room_nr].ex_description = new_descr;
}
else if (*chk == 'S') /* end of current room */
break;
}
room_nr++;
}
}
while (flag);
free(temp); /* cleanup the area containing the terminal $ */
fclose(fl);
top_of_world = --room_nr;
}
void allocate_room(int new_top)
{
struct room_data *new_world;
if (new_top)
{
if (!(new_world = (struct room_data *)
realloc(world, (new_top + 1) * sizeof(struct room_data))))
{
perror("alloc_room");
exit(0);
}
}
else
CREATE(new_world, struct room_data, 1);
world = new_world;
}
/* read direction data */
void setup_dir(FILE *fl, int room, int dir)
{
int tmp;
CREATE(world[room].dir_option[dir],
struct room_direction_data, 1);
world[room].dir_option[dir]->general_description =
fread_string(fl);
world[room].dir_option[dir]->keyword = fread_string(fl);
fscanf(fl, " %d ", &tmp);
if (tmp == 1)
world[room].dir_option[dir]->exit_info = EX_ISDOOR;
else if (tmp == 2)
world[room].dir_option[dir]->exit_info = EX_ISDOOR | EX_PICKPROOF;
else
world[room].dir_option[dir]->exit_info = 0;
fscanf(fl, " %d ", &tmp);
world[room].dir_option[dir]->key = tmp;
fscanf(fl, " %d ", &tmp);
world[room].dir_option[dir]->to_room = tmp;
}
void renum_world(void)
{
register int room, door;
for (room = 0; room <= top_of_world; room++)
for (door = 0; door <= 5; door++)
if (world[room].dir_option[door])
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);
}
#ifdef NEW_ZONE_SYSTEM
void renum_zone_table(void)
{
int zone, comm;
for (zone = 0; zone <= top_of_zone_table; zone++)
for (comm = 0; zone_table[zone].cmd[comm].command != 'S'; comm++)
switch(zone_table[zone].cmd[comm].command)
{
case 'M':
zone_table[zone].cmd[comm].arg1 =
real_mobile(zone_table[zone].cmd[comm].arg1);
zone_table[zone].cmd[comm].arg3 =
real_room(zone_table[zone].cmd[comm].arg3);
break;
case 'O':
zone_table[zone].cmd[comm].arg1 =
real_object(zone_table[zone].cmd[comm].arg1);
if (zone_table[zone].cmd[comm].arg3 != NOWHERE)
zone_table[zone].cmd[comm].arg3 =
real_room(zone_table[zone].cmd[comm].arg3);
break;
case 'G':
zone_table[zone].cmd[comm].arg1 =
real_object(zone_table[zone].cmd[comm].arg1);
break;
case 'E':
zone_table[zone].cmd[comm].arg1 =
real_object(zone_table[zone].cmd[comm].arg1);
break;
case 'P':
zone_table[zone].cmd[comm].arg1 =
real_object(zone_table[zone].cmd[comm].arg1);
zone_table[zone].cmd[comm].arg3 =
real_object(zone_table[zone].cmd[comm].arg3);
break;
case 'D':
zone_table[zone].cmd[comm].arg1 =
real_room(zone_table[zone].cmd[comm].arg1);
break;
}
}
#else
void renum_zone_table(void)
{
int zone, comm;
for (zone = 0; zone <= top_of_zone_table; zone++)
for (comm = 0; zone_table[zone].cmd[comm].command != 'S'; comm++)
switch(zone_table[zone].cmd[comm].command)
{
case 'M':
zone_table[zone].cmd[comm].arg1 =
real_mobile(zone_table[zone].cmd[comm].arg1);
zone_table[zone].cmd[comm].arg3 =
real_room(zone_table[zone].cmd[comm].arg3);
break;
case 'O':
zone_table[zone].cmd[comm].arg1 =
real_object(zone_table[zone].cmd[comm].arg1);
if (zone_table[zone].cmd[comm].arg3 != NOWHERE)
zone_table[zone].cmd[comm].arg3 =
real_room(zone_table[zone].cmd[comm].arg3);
break;
case 'G':
zone_table[zone].cmd[comm].arg1 =
real_object(zone_table[zone].cmd[comm].arg1);
zone_table[zone].cmd[comm].arg2 =
real_mobile(zone_table[zone].cmd[comm].arg2);
break;
case 'E':
zone_table[zone].cmd[comm].arg1 =
real_object(zone_table[zone].cmd[comm].arg1);
zone_table[zone].cmd[comm].arg2 =
real_mobile(zone_table[zone].cmd[comm].arg2);
break;
case 'P':
zone_table[zone].cmd[comm].arg1 =
real_object(zone_table[zone].cmd[comm].arg1);
zone_table[zone].cmd[comm].arg2 =
real_object(zone_table[zone].cmd[comm].arg2);
break;
case 'D':
zone_table[zone].cmd[comm].arg1 =
real_room(zone_table[zone].cmd[comm].arg1);
break;
}
}
#endif
#ifdef NEW_ZONE_SYSTEM
/* load the zone table and command tables */
void boot_zones(void)
{
FILE *fl;
int zon = 0, cmd_no = 0, ch, expand, tmp;
char *check, buf[81];
if (!(fl = fopen(ZONE_FILE, "r")))
{
perror("boot_zones");
exit(0);
}
for (;;)
{
fscanf(fl, " #%*d\n");
check = fread_string(fl);
if (*check == '$')
break; /* end of file */
/* alloc a new zone */
if (!zon)
CREATE(zone_table, struct zone_data, 1);
else
if (!(zone_table = (struct zone_data *) realloc(zone_table,
(zon + 1) * sizeof(struct zone_data))))
{
perror("boot_zones realloc");
exit(0);
}
zone_table[zon].name = check;
fscanf(fl, " %d ", &zone_table[zon].top);
fscanf(fl, " %d ", &zone_table[zon].lifespan);
fscanf(fl, " %d ", &zone_table[zon].reset_mode);
/* read the command table */
cmd_no = 0;
for (expand = 1;;)
{
if (expand)
if (!cmd_no)
CREATE(zone_table[zon].cmd, struct reset_com, 1);
else
if (!(zone_table[zon].cmd =
(struct reset_com *) realloc(zone_table[zon].cmd,
(cmd_no + 1) * sizeof(struct reset_com))))
{
perror("reset command load");
exit(0);
}
expand = 1;
fscanf(fl, " "); /* skip blanks */
fscanf(fl, "%c",
&zone_table[zon].cmd[cmd_no].command);
if (zone_table[zon].cmd[cmd_no].command == 'S')
break;
if (zone_table[zon].cmd[cmd_no].command == '*')
{
expand = 0;
fgets(buf, 80, fl); /* skip command */
continue;
}
fscanf(fl, " %d %d %d",
&tmp,
&zone_table[zon].cmd[cmd_no].arg1,
&zone_table[zon].cmd[cmd_no].arg2);
zone_table[zon].cmd[cmd_no].if_flag = tmp;
if (zone_table[zon].cmd[cmd_no].command == 'M' ||
zone_table[zon].cmd[cmd_no].command == 'O' ||
zone_table[zon].cmd[cmd_no].command == 'E' ||
zone_table[zon].cmd[cmd_no].command == 'P' ||
zone_table[zon].cmd[cmd_no].command == 'D')
fscanf(fl, " %d", &zone_table[zon].cmd[cmd_no].arg3);
fgets(buf, 80, fl); /* read comment */
cmd_no++;
}
zon++;
}
top_of_zone_table = --zon;
free(check);
fclose(fl);
}
#else
/* load the zone table and command tables */
void boot_zones(void)
{
FILE *fl;
int zon = 0, cmd_no = 0, ch, expand;
char *check, buf[81];
if (!(fl = fopen(ZONE_FILE, "r")))
{
perror("boot_zones");
exit(0);
}
for (;;)
{
fscanf(fl, " #%*d\n");
check = fread_string(fl);
if (*check == '$')
break; /* end of file */
/* alloc a new zone */
if (!zon)
CREATE(zone_table, struct zone_data, 1);
else
if (!(zone_table = (struct zone_data *) realloc(zone_table,
(zon + 1) * sizeof(struct zone_data))))
{
perror("boot_zones realloc");
exit(0);
}
zone_table[zon].name = check;
fscanf(fl, " %d ", &zone_table[zon].top);
fscanf(fl, " %d ", &zone_table[zon].lifespan);
fscanf(fl, " %d ", &zone_table[zon].reset_mode);
/* read the command table */
cmd_no = 0;
for (expand = 1;;)
{
if (expand)
if (!cmd_no)
CREATE(zone_table[zon].cmd, struct reset_com, 1);
else
if (!(zone_table[zon].cmd =
(struct reset_com *) realloc(zone_table[zon].cmd,
(cmd_no + 1) * sizeof(struct reset_com))))
{
perror("reset command load");
exit(0);
}
expand = 1;
fscanf(fl, " "); /* skip blanks */
fscanf(fl, "%c",
&zone_table[zon].cmd[cmd_no].command);
if (zone_table[zon].cmd[cmd_no].command == 'S')
break;
if (zone_table[zon].cmd[cmd_no].command == '*')
{
expand = 0;
fgets(buf, 80, fl); /* skip command */
continue;
}
fscanf(fl, " %d %d %d",
&zone_table[zon].cmd[cmd_no].if_flag,
&zone_table[zon].cmd[cmd_no].arg1,
&zone_table[zon].cmd[cmd_no].arg2);
if (zone_table[zon].cmd[cmd_no].command == 'M' ||
zone_table[zon].cmd[cmd_no].command == 'O' ||
zone_table[zon].cmd[cmd_no].command == 'E' ||
zone_table[zon].cmd[cmd_no].command == 'D')
fscanf(fl, " %d", &zone_table[zon].cmd[cmd_no].arg3);
fgets(buf, 80, fl); /* read comment */
cmd_no++;
}
zon++;
}
top_of_zone_table = --zon;
free(check);
fclose(fl);
}
#endif
/*************************************************************************
* procedures for resetting, both play-time and boot-time *
*********************************************************************** */
/* read a mobile from MOB_FILE */
struct char_data *read_mobile(int nr, int type)
{
int i, skill_nr;
long tmp, tmp2, tmp3;
struct char_data *mob;
char chk[10], buf[100];
char letter;
i = nr;
if (type == VIRTUAL)
if ((nr = real_mobile(nr)) < 0)
{
sprintf(buf, "Mobile (V) %d does not exist in database.", i);
return(0);
}
fseek(mob_f, mob_index[nr].pos, 0);
CREATE(mob, struct char_data, 1);
clear_char(mob);
/***** String data *** */
mob->player.name = fread_string(mob_f);
mob->player.short_descr = fread_string(mob_f);
mob->player.long_descr = fread_string(mob_f);
mob->player.description = fread_string(mob_f);
mob->player.title = 0;
/* *** Numeric data *** */
fscanf(mob_f, "%d ", &tmp);
mob->specials.act = tmp;
SET_BIT(mob->specials.act, ACT_ISNPC);
fscanf(mob_f, " %d ", &tmp);
mob->specials.affected_by = tmp;
fscanf(mob_f, " %d ", &tmp);
mob->specials.alignment = tmp;
fscanf(mob_f, " %c \n", &letter);
if (letter == 'S') {
/* The new easy monsters */
mob->abilities.str = 11;
mob->abilities.intel = 11;
mob->abilities.wis = 11;
mob->abilities.dex = 11;
mob->abilities.con = 11;
fscanf(mob_f, " %ld ", &tmp);
GET_LEVEL(mob) = tmp;
fscanf(mob_f, " %ld ", &tmp);
mob->points.hitroll = 20-tmp;
fscanf(mob_f, " %ld ", &tmp);
mob->points.armor = 10*tmp;
fscanf(mob_f, " %ldd%ld+%ld ", &tmp, &tmp2, &tmp3); /* here */