-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathareas.cpp
2736 lines (2430 loc) · 81.4 KB
/
areas.cpp
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
/**************************************************************************/
// areas.cpp - reading/writing of NAFF area files (New Area File Format)
/***************************************************************************
* The Dawn of Time v1.69r (c)1997-2004 Michael Garratt *
* >> A number of people have contributed to the Dawn codebase, with the *
* majority of code written by Michael Garratt - www.dawnoftime.org *
* >> To use this source code, you must fully comply with the dawn license *
* in licenses.txt... In particular, you may not remove this copyright *
* notice. *
**************************************************************************/
//
// The concept of NAFF is based the following principles:
// * Never use a hard coded number in the area file.
// * Always use word representation of flags in areafiles.
// * As a general rule each line should stand alone and have a meaningful
// header, If multiple lines worth of information are needed to be stored
// but not necessarily stored in every situation (e.g. room exit flags),
// then reference something that was previously read in.
// * Put every string thru pack_string when writing, and unpack_string when
// loading. (These functions add a leading . if necessary + other things).
// * Put everything that will be read in with fread_word() thru pack_word
// when writing (this adds the ' 's if necessary).
// NOTE: pack_string() is not multibuffered!!!
// (This means do NOT call it more than once within a single fprintf()!)
//
#include "include.h"
#include "areas.h"
#include "db.h"
#include "olc.h"
#include "lockers.h"
#include "shop.h"
// mob_cmds.cpp
char *mprog_type_to_name( int type );
// gamble.cpp
char *gamble_name( GAMBLE_FUN *function);
GAMBLE_FUN *gamble_lookup( const char *name );
// db.cpp
/**************************************************************************/
// local prototypes
void fread_mob_NAFF( MOB_INDEX_DATA *pMob, FILE *fp );
/**************************************************************************/
// will change the vnum if it is only inside the untranslated vnum range
// of the area - needed to find the new reset values of mobs etc
void apply_area_vnum_offset(int *old_vnum)
{
if(!area_last){
bug("apply_area_offset called when area_last==NULL!");
}
// do the translation if necessary
if( area_last->vnum_offset
&& *old_vnum <= area_last->max_vnum
&& *old_vnum >= area_last->min_vnum)
{
*old_vnum+=area_last->vnum_offset;
}
}
/**************************************************************************/
// Prepare a word to be written to file by putting it in 's if necessary
// Also convert ''s to `'s
// Multibuffered :)
const char *pack_word(const char *word)
{
static int i;
static char buf[5][512];
++i%=5;
buf[i][0] = '\0';
if(IS_NULLSTR(word)){
return "''";
}
int j=1;
bool quote=false;
for(const char *p=word; *p; p++)
{
if(is_space(*p)){
quote=true;
buf[i][j]=*p;
}else if(*p=='\''){
buf[i][j]='`';
}else{
buf[i][j]=*p;
}
j++;
}
buf[i][j]='\0';
if(quote){
buf[i][0]='\'';
buf[i][j]='\'';
buf[i][j+1]='\0';
return buf[i];
}
return &buf[i][1];
}
/**************************************************************************/
// Prepare a string to be written to file - Kal Jan 2001
// - Removing all \r's
// - Converting ~'s into {-
// - Prefixing the string with a . if the string begins with a . or space
char *pack_string(const char *str)
{
if(IS_NULLSTR(str)){
return "";
}
const char *p=str;
char *result=&temp_HSL_workspace[1];
// process the input string
while(*p){
if(*p=='\r'){ // ignore \r's
p++;
}else if(*p=='~'){ // convert ~ into `-
*result++='`';
*result++='-';
p++;
}else{
*result++=*p++;
}
}
*result='\0';
if(is_space(temp_HSL_workspace[1]) || temp_HSL_workspace[1]=='.'){
temp_HSL_workspace[0]='.';
return temp_HSL_workspace;
}
return &temp_HSL_workspace[1];
}
/**************************************************************************/
// Remove a leading . from a string if it has one - Kal Jan 2001
char *unpack_string(char *str)
{
if(IS_NULLSTR(str)){
return str_dup("");
}
if(*str=='.'){
char *result=str_dup(str+1);
free_string(str);
return result;
}
return str;
}
/**************************************************************************/
void fwrite_roomecho(room_echo_data *pRe, FILE *fp)
{
fprintf(fp, "RoomEcho %2d %2d %3d %s~\n", pRe->firsthour, pRe->lasthour,
pRe->percentage,pack_string(pRe->echotext));
}
/**************************************************************************/
void fwrite_roomecho_recursive(room_echo_data *pRe, FILE *fp)
{
if(!pRe){ // no more? descripts to write
return;
}
fwrite_roomecho_recursive(pRe->next, fp);
fwrite_roomecho(pRe, fp);
}
/**************************************************************************/
void fwrite_extradesc(EXTRA_DESCR_DATA *pEd, FILE *fp)
{
fprintf( fp, "ExtraDesc %s~\n", pack_string(pEd->keyword));
fprintf( fp, "%s~\n",pack_string(pEd->description));
}
/**************************************************************************/
// extra description saving recursive loop in order to save the descripts
// in reverse order as loaded - Kal Jan 01
void fwrite_extradesc_recursive(EXTRA_DESCR_DATA *pEd, FILE *fp)
{
if(!pEd){ // no more? descripts to write
return;
}
fwrite_extradesc_recursive(pEd->next, fp);
fwrite_extradesc(pEd, fp);
}
/**************************************************************************/
// save one room in New Area File Format
// - Kal, based on what Kerenos started
void save_rooms_NAFF( FILE *fp, AREA_DATA *pArea )
{
ROOM_INDEX_DATA *pRoomIndex;
EXIT_DATA *pExit;
int i;
int exit;
fprintf( fp, "#ROOMS\n" );
for( i = pArea->min_vnum; i <= pArea->max_vnum; i++ ){
pRoomIndex=get_room_index(i);
if(pRoomIndex)
{
fprintf( fp, "#%d\n", pRoomIndex->vnum );
fprintf( fp, "Name %s~\n", pack_string(pRoomIndex->name));
fprintf( fp, "Desc %s~\n", pack_string(pRoomIndex->description));
fwrite_wordflag( room_flags, pRoomIndex->room_flags, "RoomFlags ", fp);
fwrite_wordflag( room2_flags, pRoomIndex->room2_flags, "Room2Flags ", fp);
fwrite_wordflag( sector_types, pRoomIndex->sector_type, "Sector ", fp);
if ( pRoomIndex->mana_rate != 100 ){
fprintf( fp, "Mana %d\n", pRoomIndex->mana_rate );
}
if ( pRoomIndex->heal_rate != 100 ){
fprintf( fp, "Heal %d\n", pRoomIndex->heal_rate );
}
if(pRoomIndex->lockers){
locker_room_data *rl=pRoomIndex->lockers;
if ( rl->quantity){
fprintf( fp, "LockerQuant %d\n", rl->quantity);
}
if(rl->initial_rent){
fprintf( fp, "LockerInitRent %d\n", rl->initial_rent);
}
if ( rl->ongoing_rent){
fprintf( fp, "LockerOngoRent %d\n", rl->ongoing_rent);
}
if ( rl->weight){
fprintf( fp, "LockerWeight %d\n", rl->weight);
}
if ( rl->capacity){
fprintf( fp, "LockerCapacity %d\n", rl->capacity);
}
if ( rl->pick_proof){
fprintf( fp, "LockerPickProof %d\n", rl->pick_proof);
}
}
if(!IS_NULLSTR(pRoomIndex->msp_sound)){
fprintf( fp, "MSP %s~\n", pack_string(pRoomIndex->msp_sound));
}
if(pRoomIndex->clan){
fprintf( fp, "Clan %s\n", pack_word(pRoomIndex->clan->savename()));
}
if(!IS_NULLSTR(pRoomIndex->owner)){
fprintf( fp, "Owner %s~\n", pack_string(pRoomIndex->owner));
}
// save any room echos
fwrite_roomecho_recursive(pRoomIndex->echoes, fp);
// save any extra descriptions
fwrite_extradesc_recursive(pRoomIndex->extra_descr, fp);
// Exits leading out of the room
for( exit= 0; exit<MAX_DIR; exit++)
{
if (( pExit = pRoomIndex->exit[exit] )
&& pExit->u1.to_room )
{
fprintf( fp, "Exit %s %d\n", pack_word(flag_string(direction_types, exit)),
pExit->u1.to_room->vnum);
fwrite_wordflag(exit_flags, pExit->rs_flags, "EFlags ", fp);
if(pExit->key){
fprintf( fp, "EKeyvnum %d\n", pExit->key);
}
if(!IS_NULLSTR(pExit->keyword)){
fprintf( fp, "EKeywords %s~\n", pack_string(pExit->keyword));
}
if(!IS_NULLSTR(pExit->description)){
fprintf( fp, "EDesc %s~\n", pack_string(pExit->description));
}
}
}
fprintf( fp, "End\n\n\n" );
}
}
fprintf( fp, "#0\n\n\n\n" );
return;
}
/**************************************************************************/
// - Kal, based on what Kerenos started
void load_rooms_NAFF( FILE *fp, int version)
{
ROOM_INDEX_DATA *pRoomIndex;
char *word=NULL;
char *previousword;
bool fMatch, done = false;
if ( area_last == NULL )
{
bug("Load_rooms_NAFF(): no #AREA seen yet.");
exit_error( 1 , "load_rooms_NAFF", "no #AREA seen yet");
}
for ( ; ; )
{
EXIT_DATA *last_exit;
vn_int vnum;
char letter;
int door;
int iHash;
letter = fread_letter( fp );
if ( letter != '#' )
{
bug("Load_rooms_NAFF: # not found.");
exit_error( 1 , "load_rooms_NAFF", "# not found");
}
vnum = fread_number( fp );
if ( vnum == 0 )
break;
vnum+= area_last->vnum_offset;
fBootDb = false;
ROOM_INDEX_DATA *dup_room_index=get_room_index( vnum );
if ( dup_room_index)
{
bugf( "Load_rooms_NAFF: vnum %d duplicated with room from areafile '%s'.",
vnum, dup_room_index->area?dup_room_index->area->file_name:"unknown");
exit_error( 1 , "load_rooms_NAFF", "duplicate vnum");
}
fBootDb = true;
last_vnum = vnum; // backup the last vnum for gdb use
last_exit=NULL;
pRoomIndex = new_room_index();
pRoomIndex->area = area_last;
pRoomIndex->vnum = vnum;
// check vnum fits in area vnum range
if ( vnum < pRoomIndex->area->min_vnum + pRoomIndex->area->vnum_offset)
{
bugf("Room with Vnum %d is less than area %s <%s> vnum %d!",
vnum,
pRoomIndex->area->name,
pRoomIndex->area->file_name,
pRoomIndex->area->min_vnum );
}
if ( vnum > pRoomIndex->area->max_vnum + pRoomIndex->area->vnum_offset)
{
bugf("Room with Vnum %d is greater than area %s <%s> vnum %d!",
vnum,
pRoomIndex->area->name,
pRoomIndex->area->file_name,
pRoomIndex->area->max_vnum );
}
for ( ; ; )
{
previousword = word;
word = feof( fp ) ? (char*)"End" : fread_word( fp );
fMatch = false;
switch ( UPPER(word[0]) )
{
case '*':
fMatch = true;
fread_to_eol( fp );
break;
case 'C':
KEY( "Clan", pRoomIndex->clan, clan_slookup(fread_word( fp )));
break;
case 'D':
KEY( "Desc", pRoomIndex->description, unpack_string(fread_string( fp )));
break;
case 'E':
if ( !str_cmp( word, "ExtraDesc" ))
{
EXTRA_DESCR_DATA *ed=new_extra_descr();
ed->keyword = unpack_string(fread_string( fp ));
ed->description = unpack_string(fread_string( fp ));
ed->next = pRoomIndex->extra_descr;
pRoomIndex->extra_descr = ed;
top_ed++;
fMatch = true;
break;
}
if ( !str_cmp( word, "Exit" ))
{
EXIT_DATA *pexit;
door = wordflag_to_value( direction_types, fread_word( fp ));
if ( door < 0 || door>=MAX_DIR )
{
bugf("load_rooms_NAFF: room vnum %d '%s' has bad door number.",
vnum, pRoomIndex->name);
exit_error( 1 , "load_rooms_NAFF", "room with bad doors");
}
pexit = new_exit();
pexit->u1.vnum = fread_number( fp );
apply_area_vnum_offset(&pexit->u1.vnum);
last_exit=pexit;
pRoomIndex->exit[door] = pexit;
top_exit++;
fMatch = true;
break;
}
KEY( "EFlags", last_exit->rs_flags, fread_wordflag( exit_flags, fp ));
KEY( "EKeyvnum", last_exit->key, fread_number(fp) );
KEY( "EKeywords", last_exit->keyword, unpack_string(fread_string(fp)));
KEY( "EDesc", last_exit->description, unpack_string(fread_string(fp)));
if ( !str_cmp( word, "End" ))
{
done = true;
fMatch = true;
break;
}
break;
case 'H':
KEY( "Heal", pRoomIndex->heal_rate, fread_number( fp ));
break;
case 'L':
{
if(!str_prefix("Locker", word)){
// allocate memory for lockers on a just in time basis
if(!pRoomIndex->lockers){
pRoomIndex->lockers=new locker_room_data;
pRoomIndex->lockers->quantity=0;
pRoomIndex->lockers->initial_rent=0;
pRoomIndex->lockers->ongoing_rent=0;
pRoomIndex->lockers->weight=0;
pRoomIndex->lockers->capacity=0;
pRoomIndex->lockers->pick_proof=0;
}
}
KEY( "LockerQuant", pRoomIndex->lockers->quantity, fread_number( fp ));
KEY( "LockerInitRent", pRoomIndex->lockers->initial_rent, fread_number( fp ));
KEY( "LockerOngoRent", pRoomIndex->lockers->ongoing_rent, fread_number( fp ));
KEY( "LockerWeight", pRoomIndex->lockers->weight, fread_number( fp ));
KEY( "LockerCapacity", pRoomIndex->lockers->capacity, fread_number( fp ));
KEY( "LockerPickProof", pRoomIndex->lockers->pick_proof, fread_number( fp ));
}
break;
case 'M':
KEY( "Mana", pRoomIndex->mana_rate, fread_number( fp ));
KEY( "MSP", pRoomIndex->msp_sound, unpack_string(fread_string( fp )));
break;
case 'N':
KEY( "Name", pRoomIndex->name, unpack_string(fread_string( fp )));
break;
case 'O':
KEY( "Owner", pRoomIndex->owner, unpack_string(fread_string( fp )));
break;
case 'R':
KEY( "RoomFlags", pRoomIndex->room_flags, fread_wordflag( room_flags, fp ));
KEY( "Room2Flags", pRoomIndex->room2_flags, fread_wordflag( room2_flags, fp ));
if(!str_cmp( word, "RoomEcho"))
{
room_echo_data *re=new_room_echo();
re->firsthour =fread_number(fp);
re->lasthour =fread_number(fp);
re->percentage =fread_number(fp);
re->echotext =unpack_string(fread_string(fp));
re->next =pRoomIndex->echoes;
pRoomIndex->echoes= re;
fMatch = true;
break;
}
break;
case 'S':
KEY( "Sector", pRoomIndex->sector_type, fread_wordflag( sector_types, fp ));
break;
}
if ( !fMatch )
{
bugf( "load_rooms_NAFF: no match for '%s', word before that = '%s'.",
word, previousword);
fread_to_eol( fp );
}
if ( done )
{
done = false;
break;
}
}
iHash = vnum % MAX_KEY_HASH;
pRoomIndex->next = room_index_hash[iHash];
room_index_hash[iHash] = pRoomIndex;
top_vnum_room = top_vnum_room < vnum ? vnum : top_vnum_room;
assign_area_vnum( vnum );
}
return;
}
/**************************************************************************/
// save one object in New Area File Format
// - Kal, based on what Kerenos started
void save_object_NAFF( FILE *fp, OBJ_INDEX_DATA *pObjIndex )
{
fprintf( fp, "#%d\n", pObjIndex->vnum );
fprintf( fp, "Name %s~\n", pack_string(pObjIndex->name));
fprintf( fp, "Short %s~\n", pack_string(pObjIndex->short_descr));
fprintf( fp, "Desc %s~\n", pack_string(pObjIndex->description));
fprintf( fp, "Level %d\n", pObjIndex->level );
// ItemType must be saved early, so loading knows how to handle values
fwrite_wordflag( item_types, pObjIndex->item_type, "ItemType ", fp);
if ( IS_TRAPPED( pObjIndex ))
{
fprintf( fp, "Trap %ld %d %d %d\n",
(long)pObjIndex->trap_trig,
pObjIndex->trap_dtype,
pObjIndex->trap_charge,
pObjIndex->trap_modifier );
}
fprintf( fp, "Cost %d\n", pObjIndex->cost );
if(pObjIndex->condition!=100){
fprintf( fp, "Condition %d\n", URANGE(1,pObjIndex->condition, 100));
}
fprintf( fp, "Asize %d\n", pObjIndex->absolute_size );
fprintf( fp, "Rsize %d\n", pObjIndex->relative_size );
fprintf( fp, "Values " ); save_object_values( fp, pObjIndex );
fprintf( fp, "Weight %d\n", pObjIndex->weight );
if(IS_NULLSTR(pObjIndex->material)){
fprintf( fp, "Material unknown~\n");
}else{
fprintf( fp, "Material %s~\n", pack_string(pObjIndex->material));
}
fwrite_wordflag( objextra_flags, pObjIndex->extra_flags, "Extra ", fp);
fwrite_wordflag( objextra2_flags, pObjIndex->extra2_flags,"Extra2 ", fp);
fwrite_wordflag( wear_flags, pObjIndex->wear_flags, "Wear ", fp);
fwrite_wordflag(classnames_flags, pObjIndex->class_allowances,"ClassAllowances ", fp );
fwrite_wordflag(attune_flags, pObjIndex->attune_flags,"AttuneFlags ", fp );
// save all the affects on an object
fwrite_affect_recursive(pObjIndex->affected, fp);
// save classgroup object restrictions - system not really finished
{
OBJRESTRICT_LIST_DATA *pr;
for( pr = pObjIndex->restrict; pr; pr = pr->next )
{
fprintf( fp, "Restrict %d %s %s\n",
pr->priority,
pack_word(pr->classgroup->name),
pack_word(pr->affectprofile->name));
}
}
// extra descriptions
fwrite_extradesc_recursive(pObjIndex->extra_descr, fp);
fprintf(fp, "End\n\n");
return;
}
/**************************************************************************/
// - Kal, based on what Kerenos started
void load_objects_NAFF( FILE *fp, int version)
{
OBJ_INDEX_DATA *pObjIndex;
char *word=NULL;
char *previousword;
bool fMatch, done = false;
if ( !area_last ) // OLC
{
bug("Load_objects: no #AREA seen yet.");
exit_error( 1 , "load_objects_NAFF", "no #AREA seen yet");
}
for ( ; ; )
{
vn_int vnum;
char letter;
int iHash;
letter = fread_letter( fp );
if ( letter != '#' )
{
bug("Load_objects_NAFF: # not found.");
exit_error( 1 , "load_objects_NAFF", "# not found");
}
vnum = fread_number( fp );
if ( vnum == 0 )
break;
vnum+= area_last->vnum_offset;
fBootDb = false;
if ( get_obj_index( vnum ) != NULL )
{
char *aname="an unknown area.";
if( get_obj_index( vnum )->area
&& get_obj_index( vnum )->area->file_name){
aname=get_obj_index( vnum )->area->file_name;
}
bugf( "Load_objects_NAFF: vnum %d duplicated.", vnum );
logf("with %s (%s) from %s",
get_obj_index( vnum )->short_descr,
get_obj_index( vnum )->name,
aname);
exit_error( 1 , "load_objects_NAFF", "duplicate vnum");
}
fBootDb = true;
last_vnum = vnum; // backup the last vnum for gdb use
pObjIndex = (OBJ_INDEX_DATA *)alloc_perm( sizeof(*pObjIndex) );
pObjIndex->vnum = vnum;
pObjIndex->area = area_last;
// check object vnum fits in areas vnum range
if ( vnum < pObjIndex->area->min_vnum + pObjIndex->area->vnum_offset)
{
bugf("Object with Vnum %d is less than area %s <%s> vnum %d!",
vnum,
pObjIndex->area->name,
pObjIndex->area->file_name,
pObjIndex->area->min_vnum
);
}
if ( vnum > pObjIndex->area->max_vnum + pObjIndex->area->vnum_offset)
{
bugf("Object with Vnum %d is greater than area %s <%s> vnum %d!",
vnum,
pObjIndex->area->name,
pObjIndex->area->file_name,
pObjIndex->area->max_vnum
);
}
pObjIndex->trap_trig = 0;
pObjIndex->trap_dtype = 0;
pObjIndex->trap_charge = 0;
pObjIndex->trap_modifier= 0;
pObjIndex->condition = 100;
pObjIndex->reset_num = 0;
for ( ; ; )
{
previousword = word;
word = feof( fp ) ? (char*)"End" : fread_word( fp );
fMatch = false;
switch ( UPPER(word[0]) )
{
case '*':
fMatch = true;
fread_to_eol( fp );
break;
case 'A':
KEY( "Asize", pObjIndex->absolute_size, fread_number( fp ));
KEY( "AttuneFlags", pObjIndex->attune_flags, fread_wordflag( attune_flags, fp ));
if ( !str_cmp( word, "Affect" ))
{
AFFECT_DATA *paf=fread_affect(fp);
paf->next = pObjIndex->affected;
pObjIndex->affected = paf;
top_affect++;
fMatch = true;
break;
}
break;
case 'C':
KEY( "Cost", pObjIndex->cost, fread_number( fp ));
KEY( "Condition", pObjIndex->condition, fread_number( fp ));
KEY( "ClassAllowances", pObjIndex->class_allowances,fread_wordflag( classnames_flags, fp ));
break;
case 'D':
KEY( "Desc", pObjIndex->description, unpack_string(fread_string( fp )));
break;
case 'E':
KEY( "Extra", pObjIndex->extra_flags, fread_wordflag( objextra_flags, fp ));
KEY( "Extra2", pObjIndex->extra2_flags, fread_wordflag( objextra2_flags, fp ));
if ( !str_cmp( word, "ExtraDesc" ))
{
EXTRA_DESCR_DATA *ed=new_extra_descr();
ed->keyword = unpack_string(fread_string( fp ));
ed->description = unpack_string(fread_string( fp ));
ed->next = pObjIndex->extra_descr;
pObjIndex->extra_descr = ed;
top_ed++;
fMatch = true;
if (str_len(ed->description)>MSL-4 || str_len(ed->keyword)>MSL-4 )
{
bugf("load_objects_NAFF: Extended description in object "
"%d is %d characters!!! (more than %d)",
(int)last_vnum, str_len(ed->description), MSL-4);
exit_error( 1 , "load_objects_NAFF", "extended description too long.");
}
break;
}
if ( !str_cmp( word, "End" ))
{
if(pObjIndex->item_type==0){
bugf("undefined item type for object %d... can not load area file!",
pObjIndex->vnum);
exit_error( 1 , "load_objects_NAFF", "undefined item type");
}
done = true;
fMatch = true;
break;
}
break;
case 'I':
KEY( "ItemType", pObjIndex->item_type, fread_wordflag( item_types, fp ));
break;
case 'L':
KEY( "Level", pObjIndex->level, fread_number( fp ));
break;
case 'M':
KEY( "Material", pObjIndex->material, unpack_string(fread_string(fp)));
break;
case 'N':
KEY( "Name", pObjIndex->name, unpack_string(fread_string(fp)));
break;
case 'R':
KEY( "Rsize", pObjIndex->relative_size, fread_number( fp ));
if ( !str_cmp( word, "Restrict" ))
{
OBJRESTRICT_LIST_DATA *pr;
classgroup_type * cg;
affectprofile_type *ap;
int priority = fread_number( fp );
char * classgroup = fread_word ( fp );
char * affectprofile = fread_word ( fp );
cg=classgroup_lookup(classgroup);
ap=affectprofile_lookup(affectprofile);
if(!cg || !ap){
if(!cg){
bugf("Unknown classgroup '%s' for object vnum %d restriction, IGNORING!",
classgroup, vnum);
}
if(!ap){
bugf("Unknown affectprofile '%s' for object vnum %d restriction, IGNORING!",
affectprofile, vnum);
}
}else{
pr=new OBJRESTRICT_LIST_DATA;
pr->affectprofile=ap;
pr->classgroup=cg;
pr->priority=priority;
// can't have positive affect modifiers
if(ap->wear_amount>0){
bugf("positive ap->wear_amount for %s, inverted.", ap->name);
ap->wear_amount=0-ap->wear_amount;
}
// Add it to the restricts list
pr->next = pObjIndex->restrict;
pObjIndex->restrict = pr;
SET_BIT(pObjIndex->objrestrict,(1<<cg->bitindex)); // create bit quick lookup
}
fMatch = true;
break;
}
break;
case 'S':
KEY( "Short", pObjIndex->short_descr, unpack_string(fread_string( fp )));
break;
case 'T':
if ( !str_cmp( word, "Trap" ))
{
pObjIndex->trap_trig = fread_number( fp );
pObjIndex->trap_dtype = fread_number( fp );
pObjIndex->trap_charge = fread_number( fp );
pObjIndex->trap_modifier= fread_number( fp );
fMatch = true;
break;
}
break;
case 'V':
if ( !str_cmp( word, "Values" )){
load_object_values( fp, version, pObjIndex );
fMatch = true;
break;
}
break;
case 'W':
KEY( "Wear", pObjIndex->wear_flags, fread_wordflag( wear_flags, fp ));
KEY( "Weight", pObjIndex->weight, fread_number( fp ));
break;
}
if ( !fMatch )
{
bugf( "load_objects_NAFF: no match for '%s', word before that = '%s'.",
word, previousword);
fread_to_eol( fp );
}
if ( done )
{
done = false;
break;
}
}
iHash = vnum % MAX_KEY_HASH;
pObjIndex->next = obj_index_hash[iHash];
obj_index_hash[iHash] = pObjIndex;
top_obj_index++;
}
return;
}
/**************************************************************************/
void fwrite_mobprog(MPROG_LIST *pMprog, FILE *fp)
{
if(pMprog->pos_flags){
// A '=' directly after the mprog word means the end of
// the line has the positions for the prog
fprintf(fp, "MProg = %s %d %s~%s~\n",
mprog_type_to_name(pMprog->trig_type),
pMprog->prog->vnum,
pack_string(pMprog->trig_phrase),
flag_string(position_flags, pMprog->pos_flags));
}else{
fprintf(fp, "MProg %s %d %s~\n",
mprog_type_to_name(pMprog->trig_type),
pMprog->prog->vnum,
pack_string(pMprog->trig_phrase));
}
}
/**************************************************************************/
// mobprog saving recursive loop in order to save the mobprogs in
// reverse order as loaded - Kal Jan 01
void fwrite_mobprog_recursive(MPROG_LIST *pMprog, FILE *fp)
{
if(!pMprog){ // no more? mobprogs to write
return;
}
fwrite_mobprog_recursive(pMprog->next, fp);
fwrite_mobprog(pMprog, fp);
}
/**************************************************************************/
// save one mobile in New Area File Format
// - Kal, based on what Kerenos started
void save_mobile_NAFF( FILE *fp, MOB_INDEX_DATA *pMobIndex )
{
fprintf( fp, "#%d\n", pMobIndex->vnum);
fprintf( fp, "Name %s~\n", pack_string( pMobIndex->player_name));
fprintf( fp, "ShortD %s~\n", pack_string( pMobIndex->short_descr));
fprintf( fp, "LongD %s~\n", pack_string( pMobIndex->long_descr ));
fprintf( fp, "Desc %s~\n", pack_string( pMobIndex->description));
fprintf( fp, "Race %s~\n", pack_string(race_table[pMobIndex->race]->name));
fprintf( fp, "Align %d %d\n", pMobIndex->tendency, pMobIndex->alliance );
if(pMobIndex->xp_mod!=100){
fprintf( fp, "XPMod %d\n", pMobIndex->xp_mod );
}
fprintf( fp, "Level %d\n", pMobIndex->level );
fprintf( fp, "Hitroll %d\n", pMobIndex->hitroll );
fprintf( fp, "HitDice %dd%d+%d\n", pMobIndex->hit[DICE_NUMBER],
pMobIndex->hit[DICE_TYPE],
pMobIndex->hit[DICE_BONUS] );
fprintf( fp, "ManaDice %dd%d+%d\n", pMobIndex->mana[DICE_NUMBER],
pMobIndex->mana[DICE_TYPE],
pMobIndex->mana[DICE_BONUS] );
fprintf( fp, "DamDice %dd%d+%d\n", pMobIndex->damage[DICE_NUMBER],
pMobIndex->damage[DICE_TYPE],
pMobIndex->damage[DICE_BONUS] );
fprintf( fp, "DamType %s\n", pack_word(attack_table[pMobIndex->dam_type].name));
fprintf( fp, "AC %d %d %d %d\n", pMobIndex->ac[AC_PIERCE],
pMobIndex->ac[AC_BASH],
pMobIndex->ac[AC_SLASH],
pMobIndex->ac[AC_EXOTIC]);
fprintf( fp, "Wealth %ld\n", pMobIndex->wealth );
fwrite_wordflag( act_flags, pMobIndex->act, "Act ", fp);
fwrite_wordflag( act2_flags, pMobIndex->act2, "Act2 ", fp);
fwrite_wordflag( affect_flags, pMobIndex->affected_by, "AffBy ", fp);
fwrite_wordflag( affect2_flags, pMobIndex->affected_by2,"AffBy2 ", fp);
fwrite_wordflag( off_flags, pMobIndex->off_flags, "Off ", fp);
fwrite_wordflag( imm_flags, pMobIndex->imm_flags, "Imm ", fp);
fwrite_wordflag( res_flags, pMobIndex->res_flags, "Res ", fp);
fwrite_wordflag( vuln_flags, pMobIndex->vuln_flags, "Vuln ", fp);
fwrite_wordflag( form_flags, pMobIndex->form, "Form ", fp);
fwrite_wordflag( part_flags, pMobIndex->parts, "Part ", fp);
fwrite_wordflag( position_types, pMobIndex->start_pos, "StartP ", fp);
fwrite_wordflag( position_types, pMobIndex->default_pos, "DefPos ", fp);
fwrite_wordflag( size_types, pMobIndex->size, "Size ", fp);
fwrite_wordflag( sex_types, pMobIndex->sex, "Sex ", fp);
if(pMobIndex->gamble_fun){
fprintf(fp,"Gamble %s\n", pack_word(gamble_name(pMobIndex->gamble_fun)));
}
if(pMobIndex->pInnData){
fprintf(fp,"InnBuy %d\n", pMobIndex->pInnData->profit_buy);
fprintf(fp,"InnSell %d\n", pMobIndex->pInnData->profit_sell);
fprintf(fp,"InnOpen %d\n", pMobIndex->pInnData->open_hour);
fprintf(fp,"InnClose %d\n", pMobIndex->pInnData->close_hour);
for(int i=0;i<MAX_INN; i++){
if(pMobIndex->pInnData->vnRoom[i]){
fprintf(fp,"InnRoom %d %d\n", pMobIndex->pInnData->vnRoom[i], pMobIndex->pInnData->shRate[i]);
}
}
}
if(IS_NULLSTR(pMobIndex->material)){
fprintf( fp, "Material unknown\n");
}else{
fprintf( fp, "Material %s\n" , pack_word(pMobIndex->material));
}
if (pMobIndex->group){
fprintf( fp, "Group %d\n", pMobIndex->group);
}
if (pMobIndex->helpgroup){
fprintf( fp, "Helpgroup %d\n", pMobIndex->helpgroup);
}
fwrite_mobprog_recursive(pMobIndex->mprogs, fp);
fprintf(fp, "END\n\n");
return;
}
/**************************************************************************/
// - Kal, based on what Kerenos started
void load_mobiles_NAFF( FILE *fp, int)
{
MOB_INDEX_DATA *pMobIndex;
if ( !area_last ) // OLC
{
bug("Load_mobiles: no #AREA seen yet.");
exit_error( 1 , "load_mobiles_NAFF", "no #AREA seen yet");
}
for ( ; ; )
{
vn_int vnum;
char letter;
int iHash;
letter = fread_letter( fp );
if ( letter != '#' )
{
bug("load_mobiles_NAFF(): # not found.");
exit_error( 1 , "load_mobiles_NAFF", "# not found");
}
vnum = fread_number( fp );
if ( vnum == 0 )// end of mobiles section
break;
// apply our vnum offset
vnum+= area_last->vnum_offset;
fBootDb = false; // Must be outside the get_mob_index() check as with fBootDb
// set to false get_mob_index() doesn't log the lookup
if ( get_mob_index( vnum ) != NULL )
{
char *aname="an unknown area.";
if( get_mob_index( vnum )->area
&& get_mob_index( vnum )->area->file_name){
aname=get_mob_index( vnum )->area->file_name;
}
bugf( "load_mobiles_NAFF(): vnum %d duplicated.", vnum );
logf("with %s (%s) from %s",
get_mob_index( vnum )->short_descr,
get_mob_index( vnum )->player_name,
aname);
exit_error( 1 , "load_mobiles_NAFF", "duplicate vnum");