forked from triem/Electric-Dreams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.c
8852 lines (7857 loc) · 252 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
/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#endif
#include <unistd.h>
#include "merc.h"
#if !defined(OLD_RAND)
/* long random(); */
void srandom(unsigned int);
int getpid();
time_t time(time_t *tloc);
#endif
#if defined(unix)
/* extern int getrlimit(int resource, struct rlimit *rlp); */
/* extern int setrlimit(int resource, const struct rlimit *rlp); */
#endif
#if !defined(macintosh)
extern int _filbuf args( (FILE *) );
#endif
long vnum_test = 0;
/*
* Globals.
*/
int mob_list_number = 0;
QUEST_DATA * quest_data_list;
GLOBAL_RANDOM_DATA * random_data_list;
HELP_DATA * help_first;
HELP_DATA * help_last;
SHOP_DATA * shop_first;
SHOP_DATA * shop_last;
CHAR_DATA * char_free;
EXTRA_DESCR_DATA * extra_descr_free;
NOTE_DATA * note_free;
GROUP_DATA * group_list;
OBJ_DATA * obj_free;
PC_DATA * pcdata_free;
char bug_buf [2*MAX_INPUT_LENGTH];
CHAR_DATA * char_list=NULL;
CHAR_DATA * mob_list_update[16];
CHAR_DATA * mob_list_current_update = NULL;
ROOM_INDEX_DATA * room_trig_list=NULL;
CLAN_DATA * clan_list=NULL;
TOP_TEN_DATA top_ten_list [ 10 ][ 3 ];
/*char * help_greeting;*/
char * help_greeting[MAX_GREETING];
struct race_list_type race_list[MAX_RACE];
struct social_type social_table [MAX_SOCIALS];
int social_count = 0;
sh_int language_table[ MAX_LANGUAGE ];
sh_int reboot_timer = 0;
bool disable_timer_abort; /* HOT boot */
bool reboot_pause = TRUE;
sh_int top_race=0;
sh_int top_guild=0;
sh_int top_greeting=0;
int LOGON_NUMBER;
char log_buf [2*MAX_INPUT_LENGTH];
char imp_buf [2*MAX_INPUT_LENGTH];
KILL_DATA kill_table [MAX_LEVEL];
NOTE_DATA * note_list=NULL;
OBJ_DATA * object_list=NULL;
TIME_INFO_DATA time_info[MAX_WORLD];
TIME_INFO_DATA time_new;
WEATHER_DATA weather_info[MAX_WORLD];
bool free_room[MAX_VNUM];
bool free_obj_list[MAX_VNUM];
bool free_trig_list[MAX_VNUM];
bool free_mob_list[MAX_VNUM];
OBJ_INDEX_DATA * free_obj_index;
MOB_INDEX_DATA * free_mob_index;
CHANGE_DATA * change_list = NULL;
CHANGE_DATA * change_free;
sh_int gsn_element_power[MAX_ELEMENT_TYPE][MAX_ELEMENT_POWER];
sh_int gsn_weapon_power[MAX_WEAPON_TYPE][MAX_WEAPON_POWER];
sh_int gsn_common;
sh_int gsn_belegfea;
sh_int gsn_mirros;
sh_int gsn_aranna;
sh_int gsn_iavartor;
sh_int gsn_tarnanthalion;
sh_int gsn_milrochdil;
sh_int gsn_manlhach;
sh_int gsn_nenkhilmen;
sh_int gsn_sulkano;
sh_int gsn_ventriloquate;
sh_int gsn_poison_blade;
sh_int gsn_double_strike;
sh_int gsn_strike;
sh_int gsn_shadowstrike;
sh_int gsn_retreat;
sh_int gsn_dodge;
sh_int gsn_quick_strike;
sh_int gsn_wind_over_sand;
sh_int gsn_hide;
sh_int gsn_fade;
sh_int gsn_hold_breath;
sh_int gsn_peek;
sh_int gsn_pick_lock;
sh_int gsn_first_aid;
sh_int gsn_tame_animal;
sh_int gsn_counter_tracking;
sh_int gsn_cooking;
sh_int gsn_track;
sh_int gsn_hunt;
sh_int gsn_detect_trap;
sh_int gsn_disarm_trap;
sh_int gsn_sneak;
sh_int gsn_steal;
sh_int gsn_remove_blindness;
sh_int gsn_remove_poison;
sh_int gsn_cure_disease;
sh_int gsn_disarm;
sh_int gsn_weapon_enhancement;
sh_int gsn_kick;
sh_int gsn_parry;
sh_int gsn_counter_strike;
sh_int gsn_repair;
sh_int gsn_rescue;
sh_int gsn_second_attack;
sh_int gsn_third_attack;
sh_int gsn_blinding_light;
sh_int gsn_sand_storm;
sh_int gsn_control_mind;
sh_int gsn_curse;
sh_int gsn_fire_shield;
sh_int gsn_stone_skin;
sh_int gsn_sanctuary;
sh_int gsn_earth_shield;
sh_int gsn_water_shield;
sh_int gsn_spirit_shield;
sh_int gsn_shadowform;
sh_int gsn_mass_shadowform;
sh_int gsn_poison;
sh_int gsn_plague;
sh_int gsn_sleep;
sh_int gsn_wind_shield;
/* new gsns */
sh_int gsn_shield_block;
sh_int gsn_create_minor_portal;
sh_int gsn_create_water;
sh_int gsn_sacrifice;
sh_int gsn_minor_sacrifice;
sh_int gsn_cure_light;
sh_int gsn_cure_serious;
sh_int gsn_cure_critical;
sh_int gsn_heal;
sh_int gsn_continual_light;
sh_int gsn_levitate;
sh_int gsn_swim;
sh_int gsn_jab;
sh_int gsn_endurance;
sh_int gsn_perception;
sh_int gsn_stun;
sh_int gsn_thrust;
sh_int gsn_rejuvenate;
sh_int gsn_whirl;
sh_int gsn_bash;
sh_int gsn_intimidate;
sh_int gsn_shriek;
sh_int gsn_fast;
sh_int gsn_breathfire;
sh_int gsn_precision_strike;
sh_int gsn_dual_wield;
sh_int gsn_berserk;
sh_int gsn_dirt;
sh_int gsn_hand_to_hand[MAX_WEAPON_POWER];
sh_int gsn_trip;
sh_int gsn_tail;
sh_int gsn_slam;
sh_int gsn_ki_force;
sh_int gsn_shola_punch;
sh_int gsn_shola_kick;
sh_int gsn_high_kick;
sh_int gsn_knee_punch;
sh_int gsn_leg_sweep;
sh_int gsn_shola_toss;
sh_int gsn_combination;
sh_int gsn_acidbrt;
sh_int gsn_bind_wounds;
sh_int gsn_courage;
sh_int gsn_tarvals_wrath;
sh_int gsn_blur;
sh_int gsn_haggle;
sh_int gsn_riding;
sh_int gsn_riding_air;
sh_int gsn_lore;
sh_int gsn_meditation;
sh_int gsn_youna;
sh_int gsn_deep_meditation;
sh_int gsn_scrolls;
sh_int gsn_staves;
sh_int gsn_wands;
sh_int gsn_refresh;
sh_int gsn_remove_curse;
sh_int gsn_awareness;
sh_int number_tokens;
sh_int number_tokens_2;
sh_int number_tokens_3;
sh_int number_tokens_4;
sh_int number_tokens_5;
sh_int number_tokens_6;
sh_int number_tokens_7;
sh_int number_tokens_8;
sh_int number_tokens_9;
sh_int number_tokens_10;
sh_int r_item;
sh_int gsn_senses;
sh_int gsn_detect_shadowform;
sh_int gsn_detect_hidden;
sh_int gsn_circle_of_protection;
sh_int gsn_faerie_fire;
sh_int gsn_fly;
sh_int gsn_haste;
sh_int gsn_slow;
sh_int gsn_calm_spirit;
sh_int gsn_infravision;
sh_int gsn_breathe_underwater;
sh_int gsn_dimension_walk;
sh_int gsn_rebuke;
sh_int gsn_mining;
sh_int gsn_golem_making;
sh_int gsn_weapon_smithing;
sh_int gsn_armor_smithing;
sh_int gsn_assaying;
sh_int gsn_metallurgy;
sh_int gsn_absorb;
/*
* Locals.
*/
MOB_INDEX_DATA * mob_index_hash [MAX_KEY_HASH];
TRIGGER_INDEX_DATA * trig_index_hash [MAX_KEY_HASH];
OBJ_INDEX_DATA * obj_index_hash [MAX_KEY_HASH];
ROOM_INDEX_DATA * room_index_hash [MAX_KEY_HASH];
char * string_hash [MAX_KEY_HASH];
AREA_DATA * area_first;
AREA_DATA * appartment_area;
AREA_DATA * area_last;
FINGER_DATA * finger_list;
char * string_space;
char * top_string;
char str_empty [1];
char * crnt_area;
int top_area;
int top_ed;
int top_card_data;
long top_exit;
long top_str_dup;
int top_help;
int top_change;
int top_bfs_queue;
int top_bfs_room;
int top_world;
int top_reset;
int top_event;
int top_quest;
int top_char_quests;
int top_shop;
int top_pcdata;
long top_obj_index;
long char_index;
long obj_index;
long top_mob_index;
long top_trigger_index;
long top_affect_obj;
long top_affect_mob;
long top_room;
long top_room_real;
long top_room_index;
int mobile_count = 0;
int object_count = 0;
long top_vnum_room;
long top_cont_data;
long top_alloc_mem;
long top_read_notes_data;
int top_debt_data;
int top_descriptor;
int top_bet_data;
int top_ban_data;
long top_skill_list;
long top_castle_data; /* castle code */
int top_buffer;
int top_finger_data;
int top_wizlist_data;
int top_specpro_list;
int top_bhost_list;
int top_editing_data;
int top_note_data;
int top_change_data;
int top_weather_data;
int top_group_data;
int top_gainer_data;
int top_clan_data;
long top_pcclan_data;
long top_track_data;
long top_track_type;
long top_inside_area_data;
long top_spell_data;
long top_gate_data;
long top_light_data;
long top_approve_data;
long top_lock_data;
long top_trigger_data;
long top_trigger_list_data;
long top_script_data;
long top_variable_data;
long top_wear_data;
long top_equip_data;
long top_inside_data;
long top_weapon_data;
long top_edible_data;
long top_trap_data;
long top_moveable_data;
long top_magic_data;
long top_logon_data;
long top_random_data;
char * world_group [] = { "nenkemen default", "maegmenel default", "lithdor default", "" };
/*
* Memory management.
* Increase MAX_STRING if you have too.
* Tune the others only if you understand what you're doing.
*/
/*#define MAX_STRING 8990976 */
#define MAX_STRING 3500000
#define MAX_PERM_BLOCK 438192
#define MAX_MEM_LIST 14
void * rgFreeList [MAX_MEM_LIST];
const long rgSizeList [MAX_MEM_LIST] =
{
16, 32, 64, 128, 256, 1024, 2048, 4096, 8192, 16384, 32768, 65536 ,131072,262144
};
int nAllocString;
int sAllocString;
int nAllocPerm;
int sAllocPerm;
/*
* Semi-locals.
*/
bool fBootDb;
bool fBootDB_Area_Update;
bool fBootHomes;
FILE * fpArea;
FILE * fpArea2;
FILE * tempArea;
char strArea[MAX_INPUT_LENGTH];
sh_int numWorld;
int numArea;
//char buf[MAX_STRING_LENGTH];
//char * buf2;
DECLARE_SPELL_FUN( spell_null );
#if defined(unix)
/* RT max open files fix */
void maxfilelimit()
{
struct rlimit r;
getrlimit(RLIMIT_NOFILE, &r);
r.rlim_cur = r.rlim_max;
setrlimit(RLIMIT_NOFILE, &r);
}
#endif
/*
* Big mama top level function.
*/
void boot_db( void )
{
char buf[MAX_STRING_LENGTH];
#if defined(unix)
/* open file fix */
maxfilelimit();
#endif
log_string("boot_db");
/*
* Init some data space stuff.
*/
{
int x;
if ( ( string_space = (char *) calloc( 1, MAX_STRING ) ) == NULL )
{
bug( "Boot_db: can't alloc %d string space.", MAX_STRING );
exit( 1 );
}
top_string = string_space;
fBootDb = TRUE;
for ( x = 0 ; x < 31 ; x++)
per_cpu_usage[x] = 0;
for ( x = 0; x < 16; x++ )
mob_list_update[x] = NULL;
}
object_list = NULL;
char_list = NULL;
/*
* Init random number generator.
*/
{
init_mm();
}
log_string("Loading Race List");
load_rlist();
log_string("Loading Races");
load_races();
log_string("Loading Guild List");
load_glist();
log_string("Loading Guilds");
load_guilds();
log_string("Loading Trigger Index");
load_trigger_index();
/*
* Set time.
*/
{
long lhour, lday, lmonth, world;
lhour = (current_time - 650336715)
/ (PULSE_TICK / PULSE_PER_SECOND);
time_new.hour = lhour %24;
lday = lhour / 24;
time_new.day = lday % 35;
lmonth = lday / 35;
time_new.month = lmonth % 17;
time_new.year = lmonth / 17;
for ( world = 0 ; world < MAX_WORLD ; world++ )
{
lhour += number_percent();
time_info[ world ].hour = lhour % time_table[ world ].hours_day;
lday = lhour / time_table[ world ].hours_day;
time_info[ world ].day = lday % time_table[ world ].days_month;
lmonth = lday / time_table[ world ].days_month;
time_info[ world ].month = lmonth % time_table[ world ].months_year;
time_info[ world ].year = lmonth / time_table[ world ].months_year;
}
}
/*
* Assign gsn's for skills which have them.
*/
{
int sn,language;
language = 0;
for ( sn = 0; sn < MAX_SKILL; sn++ )
{
if ( skill_table[sn].pgsn != NULL )
*skill_table[sn].pgsn = sn;
if ( is_language( sn ) )
language_table[ language++ ] = sn;
}
}
{
int race;
for( race = 0; race < MAX_HORSE_RACE; race++ )
setup_race( &horse_race_list[ race ] );
}
log_string("Loading Areas");
/*
* Read in all the area files.
*/
{
FILE *fpList;
crnt_area = "area";
if ( ( fpList = fopen( AREA_LIST, "r" ) ) == NULL )
{
perror( AREA_LIST );
exit( 1 );
}
for ( ; ; )
{
strcpy( strArea, fread_word( fpList ) );
if ( strArea[0] == '$' )
break;
sprintf(buf,"Loading %s",strArea);
log_string(buf);
new_load_area();
}
if ( fpList )
fclose( fpList );
}
/*
* Fix up exits.
* Declare db booting over.
* Reset all areas once.
* Load up the notes file.
* Load up the clans file.
*/
{
log_string("Fixing Exits");
fix_exits( );
fBootDb = FALSE;
log_string("Loading Wizlist");
load_wizlist();
log_string("Loading Finger");
load_finger();
log_string("Loading Notes");
load_notes( );
log_string("Loading Changes");
load_changes( );
clan_list = NULL;
log_string("Loading Clans");
load_clans( );
log_string("Loading Logons");
if (LOGON_ON)
load_logon( );
log_string("Loading Randoms");
load_random( );
log_string("Loading Counter");
load_counter( );
log_string("Loading TopTen");
load_topten( );
log_string("Loading Quests");
load_quests();
log_string("Loading Helps");
load_helps_new();
log_string("Loading Socials");
load_socials();
fBootHomes = TRUE;
log_string("Loading Perm Homes");
load_perm_rooms();
fBootHomes = FALSE;
log_string("Updating all areas");
fBootDB_Area_Update = TRUE;
area_update( );
fBootDB_Area_Update = FALSE;
}
return;
}
/*
* Snarf a help section.
*/
void load_helps_new()
{
HELP_DATA *pHelp;
FILE *fp;
if ( ( fp = fopen( HELPSAVE_FILE, "r" ) ) == NULL )
return;
for ( ; ; )
{
pHelp = new_help();
pHelp->level = fread_number( fp );
pHelp->vnum = fread_number( fp );
pHelp->vnum = top_help;
strncpy( pHelp->keyword, fread_string( fp ), 50 );
if ( pHelp->keyword[0] == '$' )
break;
pHelp->text = fread_string( fp );
if ( !str_cmp( pHelp->keyword, "greeting" ) )
{help_greeting[top_greeting] = pHelp->text;
top_greeting++;
}
if ( help_first == NULL )
help_first = pHelp;
if ( help_last != NULL )
help_last->next = pHelp;
help_last = pHelp;
pHelp->next = NULL;
}
if ( fp )
fclose(fp);
return;
}
#if defined(KEY)
#undef KEY
#endif
#define KEY( literal, field, value ) \
if ( !str_cmp( word, literal ) ) \
{ \
field = value; \
tMatch = TRUE; \
break; \
}
void load_trigger_index(void)
{
FILE *fp;
TRIGGER_INDEX_DATA *pTrigIndex;
int iHash;
char *word, *temp;
bool tMatch, tDone;
bool fMatch = TRUE;
bool fDone = FALSE;
pTrigIndex = NULL;
if ( ( fp = fopen( TRIGGER_DATA_FILE, "r" ) ) == NULL )
return;
for ( ; fMatch && !fDone; )
{ fMatch = FALSE;
tMatch = TRUE;
tDone = FALSE;
word = feof( fp ) ? str_dup("#END") : fread_word( fp );
switch ( UPPER( word[0] ) )
{
case '*': /* In-file comments */
fread_to_eol( fp );
fMatch = TRUE;
break;
case '#':
if ( !str_cmp( word, "#END" ) )
{
fMatch = TRUE;
fDone = TRUE;
break;
}
if ( !str_cmp( word, "#TRIGGER" ) )
{
fMatch = TRUE;
pTrigIndex = pTrigIndex_alloc();
temp = fread_word( fp ) ;
for ( ; tMatch && !tDone; )
{
word = feof( fp ) ? str_dup("End") : fread_word( fp );
tMatch = FALSE;
switch ( UPPER(word[0]) )
{
case '*': fread_to_eol( fp ); fMatch = TRUE; break;
case 'B':
if ( !str_cmp( word, "Builders" ) )
{
strncpy( pTrigIndex->builders, fread_string( fp ), 30 );
tMatch = TRUE;
break;
}
break;
case 'C':
KEY( "Chance", pTrigIndex->chance, fread_number( fp ) );
break;
case 'D':
if ( !str_cmp( word, "Desc" ) )
{
strncpy( pTrigIndex->desc, fread_string( fp ), 80 );
tMatch = TRUE;
break;
}
break;
case 'F':
KEY( "Flags", pTrigIndex->flags, fread_number( fp ) );
break;
case 'K':
if ( !str_cmp( word, "Keywords" ) || !str_cmp( word, "Key_sim" ) )
{
strncpy( pTrigIndex->key_sim, fread_string( fp ), 30 );
tMatch = TRUE;
break;
}
if ( !str_cmp( word, "Key_words" ) )
{
strncpy( pTrigIndex->key_words, fread_string( fp ), 30 );
tMatch = TRUE;
break;
}
if ( !str_cmp( word, "Key_string" ) )
{
strncpy( pTrigIndex->key_string, fread_string( fp ), 30 );
tMatch = TRUE;
break;
}
break;
case 'E':
if ( !str_cmp( word, "End" ) )
{
tMatch = TRUE;
tDone = TRUE;
}
break;
case 'G':
KEY( "Gets_vnum", pTrigIndex->gets_vnum, fread_number( fp ) );
break;
case 'M':
KEY( "Mob_vnum", pTrigIndex->mob_vnum, fread_number( fp ) );
break;
case 'N':
if ( !str_cmp( word, "Name" ) )
{
strncpy( pTrigIndex->name, fread_string( fp ), 30 );
tMatch = TRUE;
break;
}
break;
case 'Q':
KEY( "Quests", pTrigIndex->quests, fread_number( fp ) );
KEY( "Quests_pre", pTrigIndex->quests_pre, fread_number( fp ) );
break;
case 'S':
KEY( "Security", pTrigIndex->security, fread_number( fp ) );
KEY( "Script_type", pTrigIndex->script_type, fread_number( fp ) );
KEY( "Step", pTrigIndex->step, fread_number( fp ) );
KEY( "Step_pre", pTrigIndex->step_pre, fread_number( fp ) );
if ( !str_cmp( word, "Sc" ) || !str_cmp( word, "Script" ) )
{
SCRIPT_DATA *scr;
if ( pTrigIndex->script != NULL )
{
for ( scr = pTrigIndex->script; scr->next != NULL; scr = scr->next )
; /* scan to the end */
scr->next = (SCRIPT_DATA *) alloc_perm( sizeof(*scr) );
scr = scr->next;
top_script_data++;
}
else
{
pTrigIndex->script = (SCRIPT_DATA *) alloc_perm( sizeof(*scr) );
scr = pTrigIndex->script;
top_script_data++;
}
scr->command = fread_string( fp );
scr->next = NULL;
tMatch = TRUE;
}
break;
case 'T':
KEY( "Type", pTrigIndex->trigger_type, fread_number( fp ) );
KEY( "Timer", pTrigIndex->timer, fread_number( fp ) );
break;
case 'V':
if ( !str_cmp( word, "Vnum" ) )
{
pTrigIndex->vnum = fread_number( fp );
iHash = pTrigIndex->vnum % MAX_KEY_HASH;
pTrigIndex->next = trig_index_hash[iHash];
trig_index_hash[iHash] = pTrigIndex;
free_trig_list[pTrigIndex->vnum] = 1;
tMatch = TRUE;
}
break;
}
}
}
}
}
if ( !fMatch )
{
fpArea = fp;
bug( "Load_trigger_index: bad key word.", 0 );
exit( 1 );
}
return;
}
/*
* Snarf a reset section.
*/
void load_resets_new( AREA_DATA *pArea )
{
RESET_DATA *pReset;
FILE *fp;
char buf[MAX_INPUT_LENGTH];
sprintf(buf, "%s%s/resets", SAVEAREAS_DIR, pArea->filename );
if ( ( fp = fopen( buf, "r" ) ) == NULL )
return;
for ( ; ; )
{
ROOM_INDEX_DATA *pRoomIndex;
EXIT_DATA *pexit;
char letter;
if ( ( letter = fread_letter( fp ) ) == 'S' )
break;
if ( letter == '*' )
{
fread_to_eol( fp );
continue;
}
pReset = reset_alloc();
pReset->command = letter;
pReset->chance = fread_number( fp );
pReset->arg1 = fread_number( fp );
pReset->arg2 = fread_number( fp );
pReset->vnum = fread_number( fp );
pReset->arg3 = (letter == 'G' || letter == 'R')
? 0 : fread_number( fp );
fread_to_eol( fp );
if ( pReset->chance == 0 ) /* to allow for old files */
pReset->chance = 100;
/*
* Validate parameters.
* We're calling the index functions for the side effect.
*/
switch ( letter )
{
default:
bug( "Load_resets: bad command '%c'.", letter );
exit( 1 );
break;
case 'M':
get_mob_index ( pReset->arg1 );
get_room_index ( pReset->arg3 );
break;
case 'O':
get_room_index ( pReset->arg3 );
if (pReset->arg2 < 1 )
pReset->arg2 = 1; /* max to allow for older resets */
break;
case 'P':
get_obj_index ( pReset->arg3 );
if (pReset->arg2 < 1 )
pReset->arg2 = 1; /* max to allow for older resets */
break;
case 'G':
case 'E':
break;
case 'D':
pRoomIndex = get_room_index( pReset->arg1 );
if ( pReset->arg2 < 0
|| pReset->arg2 > 5
|| ( pexit = pRoomIndex->exit[pReset->arg2] ) == NULL )
{
bug( "Load_resets: 'D': exit %d not door.", pReset->arg2 );
exit( 1 );
}
if ( !IS_SET( pexit->exit_info, EX_ISDOOR ) )
{
bug( "Load_resets: 'D': exit %d not door. ( Ok to set )", pReset->arg2 );
SET_BIT( pexit->exit_info, EX_ISDOOR );
}
if ( pReset->arg3 < 0 || pReset->arg3 > 2 )
{
bug( "Load_resets: 'D': bad 'locks': %d.", pReset->arg3 );
exit( 1 );
}
break;
case 'R':
pRoomIndex = get_room_index( pReset->arg1 );
if ( pReset->arg2 < 0 || pReset->arg2 > 6 )
{
bug( "Load_resets: 'R': bad exit %d.", pReset->arg2 );
exit( 1 );
}
break;
}
if ( area_last->reset_first == NULL )
area_last->reset_first = pReset;
if ( area_last->reset_last != NULL )
area_last->reset_last->next = pReset;
area_last->reset_last = pReset;
pReset->next = NULL;
}
fclose(fp);
return;
}
void load_event_data(AREA_DATA *pArea)
{
FILE *fp;
char buf[MAX_INPUT_LENGTH];
EVENT_DATA *event;
ROOM_INDEX_DATA * room;
char *word;
bool tMatch, tDone;
bool fMatch = TRUE;
bool fDone = FALSE;
sprintf(buf, "%s%s/events", SAVEAREAS_DIR, pArea->filename );
if ( ( fp = fopen( buf, "r" ) ) == NULL )
{
char b_buf[MAX_STRING_LENGTH];
sprintf( b_buf, "Cannot open areafile %s ", buf );
bug( b_buf, 0 );
return;
}
event = NULL;
for ( ; fMatch && !fDone; )
{ fMatch = FALSE;
tMatch = TRUE;
tDone = FALSE;
word = feof( fp ) ? str_dup("#END") : fread_word( fp );
switch ( UPPER( word[0] ) )
{
case '*': /* In-file comments */
fread_to_eol( fp );
fMatch = TRUE;
break;
case '#':
if ( !str_cmp( word, "#END" ) )
{
fMatch = TRUE;
fDone = TRUE;
break;
}
if ( !str_cmp( word, "#EVENT" ) )
{
fMatch = TRUE;