-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcharacter.pb
2253 lines (1986 loc) · 88.1 KB
/
character.pb
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
; Lost Labyrinth VI: Portals
; character procedures
; written in PureBasic 4.20 (http://www.purebasic.com)
; created: 25.10.2008 Frank Malota <[email protected]>
; modified: 20.02.2009 Frank Malota <[email protected]>
XIncludeFile "constants.pb"
XIncludeFile "error_handling.pb"
; declarations
Declare character_gets_item(type.w, amount.w = 1, fuel.w = -1, magic_bonus.b = -1)
Declare.b power_available(power_id.w, gain_attribute.w = 0, gain_bonus.w = 0)
Declare update_abilities_adjustment_other()
Declare scramble_item_db_tiles(class$)
; initialize character
Procedure init_character(*char.char_struct)
Protected i.w
*char\xpos = 2
*char\ypos = 4
*char\facing = 0
*char\frame = 0
*char\map_filename$ = "map_start.xml"
*char\inventory_cursor_x = 0
*char\inventory_cursor_y = 0
For i=0 To #MAX_NUMBER_OF_ABILITIES - 1
With *char\ability[i]
\ability_value = 0
\attribute_max_value = ability_db(i)\attribute_start_value
\attribute_current_value = ability_db(i)\attribute_start_value
\power_adjustment = 0
\adjustment_duration = 0
\adjustment_name$ = ""
\adjustment_power_id = 0
\adjustment_item_id = 0
\item_bonus = 0
\activated = 0
\adjustment_other = 0
\adjustment_percentage = 100
EndWith
Next
For i=0 To #MAX_NUMBER_OF_POWERS-1
*char\power[i]\cooldown = 0
Next
For i = 0 To #MAX_NUMBER_OF_ITEMS - 1
*char\item_identification[i]\identified = item_identification_global
Next
*char\game_end_message$ = ""
ClearList(inventory())
update_abilities_adjustment_other()
scramble_item_db_tiles("Potion")
EndProcedure
; resets a single ability
Procedure reset_ability(*ability.ability_db_struct)
Protected i.w = 0
With *ability
\name$ = ""
\name_display$ = ""
\description$ = ""
\tile = 0
\attribute = 0
\color = $ffffff
\attribute_start_value = 0
\depletable = 0
\percentage = 0
\main_screen = 0
\displayed_as_bonus = 0
\randomizer_ability = 0
\randomizer_ability_name$ = ""
\xp = 0
\not_shown_if_zero = 0
\minimum = -1
\change_per_turn_chance = 0
\change_per_turn = 0
\change_per_move = 0
\turn_ends_if_lower = -32000
\restore_at_end_of_turn = 0
\game_ends = 0
\game_ends_val = 0
\game_ends_message$ = ""
\critical_hit_melee = 0
\attack_melee = 0
\defense_melee = 0
\modify_with_each_kill = 0
\damage_in_melee = 0
\lightradius = 0
\modify_per_point_of_damage = 0
\sneaking = 0
\backstab = 0
\perception_tile_class$ = ""
\modify_attribute = 0
\modify_attribute_name$ = ""
\modify_multiplier = 1
\modify_divisor = 1
\modify_animation$ = ""
\modify_sound$ = ""
\armor = 0
\movement = 0
\buffer_for_attribute = 0
\buffer_for_attribute_name$ = ""
\buffer_animation$ = ""
\hit_multiplier = 0
\hit_attribute = 0
\hit_attribute_name$ = ""
EndWith
For i=0 To #MAX_NUMBER_OF_ATTRIBUTE_BONI - 1
With *ability\attribute_bonus[i]
\attribute = 0
\bonus = 0
\displayed = 0
\name$ = ""
EndWith
Next
For i=0 To #MAX_NUMBER_OF_ABILITY_CAPS - 1
With *ability\ability_cap[i]
\ability = 0
\name$ = ""
\bonus = 0
\multiplier = 0
\divisor = 0
EndWith
Next
For i=0 To #MAX_NUMBER_OF_ABILITY_REQUIREMENTS - 1
With *ability\ability_requirement[i]
\attribute = 0
\value = 0
\name$ = ""
EndWith
Next
For i=0 To #MAX_NUMBER_OF_ABILITY_DISPLAYS - 1
With *ability\display[i]
\type = 0
\start_value = 0
\end_value = 0
\message$ = ""
\message2$ = ""
\color = 0
\expanded_value_display = 0
EndWith
Next
For i=0 To #MAX_NUMBER_OF_ABILITY_ADJUSTMENTS - 1
With *ability\adjustment[i]
\attribute = 0
\attribute_name$ = ""
\value = 0
\percentage = 100
\percentage_attribute_multiplier = 0
\percentage_bonus = 0
EndWith
Next
For i = 0 To #MAX_NUMBER_OF_ABILITY_STARTING_EQUIPMENT - 1
With *ability\starting_equipment[i]
\item = 0
\item_name$ = ""
\amount = 1
EndWith
Next
EndProcedure
; resets abilities db
Procedure reset_ability_db()
Protected i.w, j.w
For i=0 To #MAX_NUMBER_OF_ABILITIES - 1
reset_ability(@ability_db(i))
Next
EndProcedure
; resolves name placeholders in ability boni and sets ability ID in
Procedure ability_db_resolve_names()
Protected i.w, j.w, k.w
For i=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(i)\randomizer_ability = 0 And ability_db(i)\randomizer_ability_name$ <> ""
For k=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(k)\name$ = ability_db(i)\randomizer_ability_name$
ability_db(i)\randomizer_ability = k
EndIf
Next
If ability_db(i)\randomizer_ability = 0
error_message("ability_db_resolve_names(): cannot find ability " + Chr(34) + ability_db(i)\randomizer_ability_name$ + Chr(34))
EndIf
EndIf
If ability_db(i)\modify_attribute = 0 And ability_db(i)\modify_attribute_name$ <> ""
For k=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(k)\name$ = ability_db(i)\modify_attribute_name$
ability_db(i)\modify_attribute = k
EndIf
Next
If ability_db(i)\modify_attribute = 0
error_message("ability_db_resolve_names(): cannot find ability " + Chr(34) + ability_db(i)\modify_attribute_name$ + Chr(34))
EndIf
EndIf
If ability_db(i)\buffer_for_attribute = 0 And ability_db(i)\buffer_for_attribute_name$ <> ""
For k=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(k)\name$ = ability_db(i)\buffer_for_attribute_name$
ability_db(i)\buffer_for_attribute = k
EndIf
Next
If ability_db(i)\buffer_for_attribute = 0
error_message("ability_db_resolve_names(): cannot find ability " + Chr(34) + ability_db(i)\buffer_for_attribute_name$ + Chr(34))
EndIf
EndIf
If ability_db(i)\hit_attribute = 0 And ability_db(i)\hit_attribute_name$ <> ""
For k=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(k)\name$ = ability_db(i)\hit_attribute_name$
ability_db(i)\hit_attribute = k
EndIf
Next
If ability_db(i)\hit_attribute = 0
error_message("ability_db_resolve_names(): cannot find ability " + Chr(34) + ability_db(i)\hit_attribute_name$ + Chr(34))
EndIf
EndIf
For j=0 To #MAX_NUMBER_OF_ATTRIBUTE_BONI - 1
If ability_db(i)\attribute_bonus[j]\attribute = 0 And ability_db(i)\attribute_bonus[j]\name$ <> ""
For k=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(k)\name$ = ability_db(i)\attribute_bonus[j]\name$
ability_db(i)\attribute_bonus[j]\attribute = k
EndIf
Next
If ability_db(i)\attribute_bonus[j]\attribute = 0
error_message("ability_resolve_names(): could not find ability " + Chr(34) + ability_db(i)\attribute_bonus[j]\name$ + Chr(34))
EndIf
EndIf
Next
For j=0 To #MAX_NUMBER_OF_ABILITY_CAPS - 1
If ability_db(i)\ability_cap[j]\ability = 0 And ability_db(i)\ability_cap[j]\name$ <> ""
For k=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(k)\name$ = ability_db(i)\ability_cap[j]\name$
ability_db(i)\ability_cap[j]\ability = k
EndIf
Next
If ability_db(i)\ability_cap[j]\ability = 0
error_message("ability_resolve_names(): could not find ability " + Chr(34) + ability_db(i)\ability_cap[j]\name$ + Chr(34))
EndIf
EndIf
Next
For j=0 To #MAX_NUMBER_OF_ABILITY_REQUIREMENTS - 1
If ability_db(i)\ability_requirement[j]\attribute = 0 And ability_db(i)\ability_requirement[j]\name$ <> ""
For k=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(k)\name$ = ability_db(i)\ability_requirement[j]\name$
ability_db(i)\ability_requirement[j]\attribute = k
EndIf
Next
If ability_db(i)\ability_requirement[j]\attribute = 0
error_message("ability_resolve_names(): could not find ability " + Chr(34) + ability_db(i)\ability_requirement[j]\name$ + Chr(34))
EndIf
EndIf
Next
For j=0 To #MAX_NUMBER_OF_ABILITY_ADJUSTMENTS - 1
If ability_db(i)\adjustment[j]\attribute = 0 And ability_db(i)\adjustment[j]\attribute_name$ <> ""
For k=0 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(k)\name$ = ability_db(i)\adjustment[j]\attribute_name$
ability_db(i)\adjustment[j]\attribute = k
EndIf
Next
If ability_db(i)\adjustment[j]\attribute = 0
error_message("ability_resolve_names(): could not find ability " + Chr(34) + ability_db(i)\adjustment[j]\attribute_name$ + Chr(34))
EndIf
EndIf
Next
For j = 0 To #MAX_NUMBER_OF_ABILITY_STARTING_EQUIPMENT - 1
If ability_db(i)\starting_equipment[j]\item_name$ <> "" And ability_db(i)\starting_equipment[j]\item = 0
For k = 1 To #MAX_NUMBER_OF_ITEMS - 1
If item_db(k)\name$ = ability_db(i)\starting_equipment[j]\item_name$
ability_db(i)\starting_equipment[j]\item = k
EndIf
Next
If ability_db(i)\starting_equipment[j]\item = 0
error_message("ability_resolve_names(): could not find item " + Chr(34) + ability_db(i)\starting_equipment[j]\item_name$ + Chr(34))
EndIf
EndIf
Next
Next
EndProcedure
; load abilities into abilities db
Procedure load_abilities_db()
Protected filename$ ="data\abilities.xml"
Protected id.w, val$, val2$, name$, description$, tile.w, attribute_start_value.w, color.l
Protected depletable.b, percentage.b, main_screen.b, displayed_as_bonus.b, bonus.w
Protected randomizer_ability.w, attribute.b, attribute_bonus_idx.b, attribute_idx.w
Protected ability_cap_idx.w, ability_idx.w, divisor.b, multiplier.w, xp.b, displayed.b
Protected ability_req_idx.w, req_val.w, bonus_min_damage_in_melee.b
Protected bonus_max_damage_in_melee.b, not_shown_if_zero.b, minimum.w, change_per_turn.w
Protected display_idx.w, display_start_value.w, display_end_value.w, display_message$
Protected display_message_color.l, display_main_display.b, game_ends.w, game_ends_val.w
Protected game_ends_message$, critical_hit_melee.b, attack_melee.b, defense_melee.b
Protected modify_with_each_kill.w, damage_in_melee.b, randomizer_ability_name$, lightradius.b
Protected modify_per_point_of_damage.b, damage_buffer.b, sneaking.b, backstab.b, perception_tile_class$
Protected new_ability.ability_db_struct, new_adjustment.ability_attribute_adjustment_struct
Protected adjustment_idx.b, *mainnode, *node, *childnode, display_language$
Protected new_ability_display.ability_display_struct
Protected starting_equipment_item_id.w, starting_equipment_item_amount.w
Protected starting_equipment_idx.w, starting_equipment_item_name$
If CreateXML(0) = 0
error_message("load_abilities_db(): could not create xml structure in memory!")
EndIf
If LoadXML(0, filename$) = 0
error_message("load_abilities_db(): could not open abilites xml file: " + Chr(34) + filename$ + Chr(34))
EndIf
If XMLStatus(0) <> 0
error_message("load_abilities_db(): error in xml structure of abilities file " + Chr(34) + filename$ + Chr(34) + ": " + XMLError(0))
EndIf
reset_ability_db()
*mainnode = MainXMLNode(0)
If *mainnode
*node = ChildXMLNode(*mainnode)
While *node <> 0
Select GetXMLNodeName(*node)
Case "ability":
id = -1
reset_ability(@new_ability)
attribute_bonus_idx = 0
ability_cap_idx = 0
ability_req_idx = 0
display_idx = 0
adjustment_idx = 0
starting_equipment_idx = 0
If ExamineXMLAttributes(*node)
While NextXMLAttribute(*node)
val$ = XMLAttributeValue(*node)
Select XMLAttributeName(*node)
Case "id":
id = Val(val$)
Case "name":
new_ability\name$ = val$
Case "description":
new_ability\description$ = val$
Case "tile":
new_ability\tile = Val(val$)
Case "attribute_start_value":
new_ability\attribute_start_value = Val(val$)
Case "color":
new_ability\color = Val(val$)
Case "depletable":
If val$ = "yes"
new_ability\depletable = 1
EndIf
Case "percentage":
If val$ = "yes"
new_ability\percentage = 1
EndIf
Case "main_screen":
If val$ = "yes"
new_ability\main_screen = 1
EndIf
Case "displayed_as_bonus":
If val$= "yes"
new_ability\displayed_as_bonus = 1
EndIf
Case "randomizer_ability":
new_ability\randomizer_ability = Val(val$)
Case "attribute":
If val$ = "yes"
new_ability\attribute = 1
EndIf
Case "xp":
If val$ = "yes"
new_ability\xp = 1
EndIf
Case "not_shown_if_zero":
If val$ = "yes"
new_ability\not_shown_if_zero = 1
EndIf
Case "minimum":
new_ability\minimum = Val(val$)
Case "change_per_turn_chance":
new_ability\change_per_turn_chance = Val(val$)
Case "change_per_turn":
new_ability\change_per_turn = Val(val$)
Case "change_per_move":
new_ability\change_per_move = Val(val$)
Case "turn_ends_if_lower":
new_ability\turn_ends_if_lower = Val(val$)
Case "restore_at_end_of_turn":
If val$ = "yes"
new_ability\restore_at_end_of_turn = 1
EndIf
Case "game_ends":
If val$="lower"
new_ability\game_ends = 1
EndIf
If val$="higher"
new_ability\game_ends = 2
EndIf
Case "game_ends_val":
new_ability\game_ends_val = Val(val$)
Case "game_ends_message":
new_ability\game_ends_message$ = val$
Case "critical_hit_melee":
If val$ = "yes"
new_ability\critical_hit_melee = 1
EndIf
Case "attack_melee":
If val$ = "yes"
new_ability\attack_melee = 1
EndIf
Case "defense_melee":
If val$ = "yes"
new_ability\defense_melee = 1
EndIf
Case "modify_with_each_kill":
new_ability\modify_with_each_kill = Val(val$)
Case "damage_in_melee":
If val$ = "yes"
new_ability\damage_in_melee = 1
EndIf
Case "randomizer_ability_name":
new_ability\randomizer_ability_name$ = val$
Case "lightradius":
If val$ = "yes"
new_ability\lightradius = 1
EndIf
Case "modify_per_point_of_damage":
new_ability\modify_per_point_of_damage = Val(val$)
Case "sneaking":
If val$ = "yes"
new_ability\sneaking = 1
EndIf
Case "backstab":
If val$ = "yes"
new_ability\backstab = 1
EndIf
Case "perception_tile_class":
new_ability\perception_tile_class$ = val$
Case "modify_atribute":
new_ability\modify_attribute = Val(val$)
Case "modify_attribute_name":
new_ability\modify_attribute_name$ = val$
Case "modify_multiplier":
new_ability\modify_multiplier = Val(val$)
Case "modify_divisor":
new_ability\modify_divisor = Val(val$)
Case "modify_animation":
new_ability\modify_animation$ = val$
Case "modify_sound":
new_ability\modify_sound$ = val$
Case "armor":
If val$ = "yes"
new_ability\armor = 1
EndIf
Case "movement":
If val$ = "yes"
new_ability\movement = 1
EndIf
Case "buffer_for_attribute":
new_ability\buffer_for_attribute = Val(val$)
Case "buffer_for_attribute_name":
new_ability\buffer_for_attribute_name$ = val$
Case "buffer_animation":
new_ability\buffer_animation$ = val$
Case "hit_multiplier":
new_ability\hit_multiplier = Val(val$)
Case "hit_attribute":
new_ability\hit_attribute = Val(val$)
Case "hit_attribute_name":
new_ability\hit_attribute_name$ = val$
Default:
error_message("load_abilities_db(): wrong attribute " + Chr(34) + XMLAttributeName(*node) + Chr(34) + " in ability tag in file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
EndIf
If id < 1
error_message("load_abilities_db(): error in abilities file " + Chr(34) + filename$ + Chr(34) + ": unique ability id < 1")
EndIf
If id >= #MAX_NUMBER_OF_ABILITIES
error_message("load_abilities_db(): error in abilities file " + Chr(34) + filename$ + Chr(34) + ": ability id > " + Str(#MAX_NUMBER_OF_ABILITIES-1))
EndIf
If ability_db(id)\name$ <> ""
error_message("load_abilities_db(): ability id " + Str(id) + " not unique in abilities file " + Chr(34) + filename$ + Chr(34))
EndIf
With ability_db(id)
\name$ = new_ability\name$
\name_display$ = new_ability\name$
\description$ = new_ability\description$
\tile = new_ability\tile
\color = new_ability\color
\attribute_start_value = new_ability\attribute_start_value
\depletable = new_ability\depletable
\percentage = new_ability\percentage
\main_screen = new_ability\main_screen
\displayed_as_bonus = new_ability\displayed_as_bonus
\randomizer_ability = new_ability\randomizer_ability
\randomizer_ability_name$ = new_ability\randomizer_ability_name$
\attribute = new_ability\attribute
\xp = new_ability\xp
\not_shown_if_zero = new_ability\not_shown_if_zero
\minimum = new_ability\minimum
\change_per_turn_chance = new_ability\change_per_turn_chance
\change_per_turn = new_ability\change_per_turn
\change_per_move = new_ability\change_per_move
\turn_ends_if_lower = new_ability\turn_ends_if_lower
\restore_at_end_of_turn = new_ability\restore_at_end_of_turn
\game_ends = new_ability\game_ends
\game_ends_val = new_ability\game_ends_val
\game_ends_message$ = new_ability\game_ends_message$
\critical_hit_melee = new_ability\critical_hit_melee
\attack_melee = new_ability\attack_melee
\defense_melee = new_ability\defense_melee
\modify_with_each_kill = new_ability\modify_with_each_kill
\damage_in_melee = new_ability\damage_in_melee
\lightradius = new_ability\lightradius
\modify_per_point_of_damage = new_ability\modify_per_point_of_damage
\sneaking = new_ability\sneaking
\backstab = new_ability\backstab
\perception_tile_class$ = new_ability\perception_tile_class$
\modify_attribute = new_ability\modify_attribute
\modify_attribute_name$ = new_ability\modify_attribute_name$
\modify_multiplier = new_ability\modify_multiplier
\modify_divisor = new_ability\modify_divisor
\modify_animation$ = new_ability\modify_animation$
\modify_sound$ = new_ability\modify_sound$
\armor = new_ability\armor
\movement = new_ability\movement
\buffer_for_attribute = new_ability\buffer_for_attribute
\buffer_for_attribute_name$ = new_ability\buffer_for_attribute_name$
\buffer_animation$ = new_ability\buffer_animation$
\hit_multiplier = new_ability\hit_multiplier
\hit_attribute = new_ability\hit_attribute
\hit_attribute_name$ = new_ability\hit_attribute_name$
EndWith
*childnode = ChildXMLNode(*node)
While *childnode <> 0
Select GetXMLNodeName(*childnode)
Case "attribute_bonus":
If attribute_bonus_idx >= #MAX_NUMBER_OF_ATTRIBUTE_BONI
error_message("load_abilities_db(): too many attribute boni in attribute db file " + Chr(34) + filename$ + Chr(34))
EndIf
attribute_idx = 0
bonus = 0
displayed = 0
name$ = ""
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "attribute":
attribute_idx = Val(val2$)
If attribute_idx < 1 Or attribute_idx >= #MAX_NUMBER_OF_ABILITIES
error_message("load_abilities_db(): wrong attribute ID in attribute_bonus tag in file " + Chr(34) + filename$ + Chr(34))
EndIf
Case "bonus":
bonus = Val(val2$)
Case "displayed":
If val2$ = "yes"
displayed = 1
EndIf
Case "name":
name$ = val2$
Default:
error_message("load_abilities_db(): wrong attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in attribute_bonus tag in file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
EndIf
If attribute_idx > 0 Or name$ <> ""
ability_db(id)\attribute_bonus[attribute_bonus_idx]\attribute = attribute_idx
ability_db(id)\attribute_bonus[attribute_bonus_idx]\bonus = bonus
ability_db(id)\attribute_bonus[attribute_bonus_idx]\displayed = displayed
ability_db(id)\attribute_bonus[attribute_bonus_idx]\name$ = name$
attribute_bonus_idx = attribute_bonus_idx + 1
EndIf
Case "cap":
If ability_cap_idx >= #MAX_NUMBER_OF_ABILITY_CAPS
error_message("load_abilities_db(): too many ability caps (>" + Str(#MAX_NUMBER_OF_ABILITY_CAPS) + ") for a single ability in file " + Chr(34) + filename$ + Chr(34))
EndIf
ability_idx = 0
divisor = 1
bonus = 0
multiplier = 1
name$ = ""
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "ability":
ability_idx = Val(val2$)
If ability_idx < 1 Or ability_idx >= #MAX_NUMBER_OF_ABILITIES
error_message("load_abilities_db(): wrong ability ID " + Chr(34) + val2$ + Chr(34) + " in cap tag in file " + Chr(34) + filename$ + Chr(34))
EndIf
Case "name":
name$ = val2$
Case "bonus":
bonus = Val(val2$)
Case "divisor":
divisor = Val(val2$)
Case "multiplier":
multiplier = Val(val2$)
Default:
error_message("load_abilities_db(): wrong attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in cap tag in file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
EndIf
If ability_idx > 0 Or name$ <> ""
ability_db(id)\ability_cap[ability_cap_idx]\ability = ability_idx
ability_db(id)\ability_cap[ability_cap_idx]\name$ = name$
ability_db(id)\ability_cap[ability_cap_idx]\bonus = bonus
ability_db(id)\ability_cap[ability_cap_idx]\multiplier = multiplier
ability_db(id)\ability_cap[ability_cap_idx]\divisor = divisor
ability_cap_idx = ability_cap_idx + 1
EndIf
Case "requirement":
If ability_req_idx >= #MAX_NUMBER_OF_ABILITY_CAPS
error_message("load_abilities_db(): too many ability caps (>" + Str(#MAX_NUMBER_OF_ABILITY_CAPS) + ") for a single ability in ability file " + Chr(34) + filename$ + Chr(34))
EndIf
attribute_idx = 0
name$ = ""
req_val = 0
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "attribute":
attribute_idx = Val(val2$)
If attribute_idx < 1 Or attribute_idx >= #MAX_NUMBER_OF_ABILITIES
error_message("load_abilities_db(): wrong ability ID " + Chr(34) + val2$ + Chr(34) + " in requirement tag in file " + Chr(34) + filename$ + Chr(34))
EndIf
Case "name":
name$ = val2$
Case "value":
req_val = Val(val2$)
Default:
error_message("load_abilities_db(): wrong attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in requirement tag in file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
EndIf
If attribute_idx > 0 Or name$ <> ""
ability_db(id)\ability_requirement[ability_req_idx]\attribute = attribute_idx
ability_db(id)\ability_requirement[ability_req_idx]\name$ = name$
ability_db(id)\ability_requirement[ability_req_idx]\value = req_val
ability_req_idx = ability_req_idx + 1
EndIf
Case "display":
With new_ability_display
\type = 0
\start_value = 0
\end_value = 0
\message$ = ""
\message2$ = ""
\color = $ffffff
\expanded_value_display = 0
EndWith
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "type":
Select val2$
Case "main screen status panel":
new_ability_display\type = 1
Case "character info":
new_ability_display\type = 2
Default:
error_message("load_abilities_db(): unknown display type " + Chr(34) + val2$ + Chr(34) + " in ability display tag in ability xml file " + Chr(34) + filename$ + Chr(34))
EndSelect
Case "start_value"
new_ability_display\start_value = Val(val2$)
Case "end_value":
new_ability_display\end_value = Val(val2$)
Case "message":
new_ability_display\message$ = val2$
Case "message2":
new_ability_display\message2$ = val2$
Case "color":
new_ability_display\color = Val(val2$)
Case "language":
display_language$ = val2$
Case "expanded_value_display":
If val2$ = "yes"
new_ability_display\expanded_value_display = 1
EndIf
Default:
error_message("load_abilities_db(): unknown attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in ability display tag in abilities xml file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
If new_ability_display\message$ <> "" And display_language$ <> "" And display_language$ = preferences\language$
If display_idx >= #MAX_NUMBER_OF_ABILITY_DISPLAYS
error_message("load_abilities_db(): too many display entries (>" + Str(#MAX_NUMBER_OF_ABILITY_DISPLAYS) + ") for a single ability in ability file " + Chr(34) + filename$ + Chr(34))
EndIf
With ability_db(id)\display[display_idx]
\type = new_ability_display\type
\start_value = new_ability_display\start_value
\end_value = new_ability_display\end_value
\message$ = new_ability_display\message$
\message2$ = new_ability_display\message2$
\color = new_ability_display\color
\expanded_value_display = new_ability_display\expanded_value_display
EndWith
display_idx = display_idx + 1
EndIf
EndIf
Case "name":
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "language":
If val2$ = preferences\language$
ability_db(id)\name_display$ = GetXMLNodeText(*childnode)
EndIf
Default:
error_message("load_abilities_db(): unknown attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in name tag in ability xml file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
EndIf
Case "description":
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "language":
If val2$ = preferences\language$
ability_db(id)\description$ = GetXMLNodeText(*childnode)
EndIf
Default:
error_message("load_abilities_db(): unknown attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in description tag in ability xml file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
EndIf
Case "game_ends_message"
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "language":
If val2$ = preferences\language$
ability_db(id)\game_ends_message$ = GetXMLNodeText(*childnode)
EndIf
Default:
error_message("load_abilities_db(): unknown attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in game_ends_message tag in ability xml file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
EndIf
Case "adjustment":
With new_adjustment
\attribute = 0
\attribute_name$ = ""
\value = 0
\percentage = 100
\percentage_attribute_multiplier = 0
EndWith
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "attribute":
new_adjustment\attribute = Val(val2$)
Case "attribute_name":
new_adjustment\attribute_name$ = val2$
Case "value":
new_adjustment\value = Val(val2$)
Case "percentage":
new_adjustment\percentage = Val(val2$)
Case "percentage_attribute_multiplier":
new_adjustment\percentage_attribute_multiplier = Val(val2$)
Case "percentage_bonus":
new_adjustment\percentage_bonus = Val(val2$)
Default:
error_message("load_abilities_db(): unknown attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in adjustment tag in ability xml file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
If adjustment_idx >= #MAX_NUMBER_OF_ABILITY_ADJUSTMENTS
error_message("load_abilities_db(): too many adjustments for one ability in ability xml file " + Chr(34) + filename$ + Chr(34))
EndIf
With ability_db(id)\adjustment[adjustment_idx]
\attribute = new_adjustment\attribute
\attribute_name$ = new_adjustment\attribute_name$
\value = new_adjustment\value
\percentage = new_adjustment\percentage
\percentage_attribute_multiplier = new_adjustment\percentage_attribute_multiplier
\percentage_bonus = new_adjustment\percentage_bonus
EndWith
adjustment_idx = adjustment_idx + 1
EndIf
Case "starting_equipment":
starting_equipment_item_id = 0
starting_equipment_item_name$ = ""
starting_equipment_item_amount = 1
If ExamineXMLAttributes(*childnode)
While NextXMLAttribute(*childnode)
val2$ = XMLAttributeValue(*childnode)
Select XMLAttributeName(*childnode)
Case "item":
starting_equipment_item_id = Val(val2$)
Case "item_name":
starting_equipment_item_name$ = val2$
Case "amount":
starting_equipment_item_amount = Val(val2$)
Default:
error_message("load_abilities_db(): unknown attribute " + Chr(34) + XMLAttributeName(*childnode) + Chr(34) + " in starting_equipment tag in ability xml file " + Chr(34) + filename$ + Chr(34))
EndSelect
Wend
If starting_equipment_idx >= #MAX_NUMBER_OF_ABILITY_STARTING_EQUIPMENT
error_message("load_abilities_db(): too many starting equipment for one ability (" + Chr(34) + ability_db(id)\name$ + Chr(34) + ") in ability xml file " + Chr(34) + filename$ + Chr(34))
EndIf
If starting_equipment_item_id > 0 Or starting_equipment_item_name$ <> ""
With ability_db(id)\starting_equipment[starting_equipment_idx]
\item = starting_equipment_item_id
\item_name$ = starting_equipment_item_name$
\amount = starting_equipment_item_amount
EndWith
starting_equipment_idx = starting_equipment_idx + 1
EndIf
EndIf
Default:
error_message("load_abilities_db(): wrong tag " + Chr(34) + GetXMLNodeName(*childnode) + Chr(34) + " in file " + Chr(34) + filename$ + Chr(34))
EndSelect
*childnode = NextXMLNode(*childnode)
Wend
Default:
error_message("load_abilities_db(): wrong tag " + Chr(34) + GetXMLNodeName(*node) + Chr(34) + " in file " + Chr(34) + filename$ + Chr(34))
EndSelect
*node = NextXMLNode(*node)
Wend
EndIf
FreeXML(0)
;ability_db_resolve_names()
EndProcedure
; saves character data
Procedure save_character(*char.char_struct, filename$ = "savegame\character.xml")
Protected i.w, *mainnode, *node
If CreateXML(0) = 0
error_message("save_character(): could not create xml structure in memory!")
EndIf
*mainnode = CreateXMLNode(RootXMLNode(0),"")
SetXMLNodeName(*mainnode, "character")
SetXMLAttribute(*mainnode, "Lost_Labyrinth_version", version_number$)
SetXMLAttribute(*mainnode, "name", *char\name$)
SetXMLAttribute(*mainnode, "xpos", Str(*char\xpos))
SetXMLAttribute(*mainnode, "ypos", Str(*char\ypos))
SetXMLAttribute(*mainnode, "facing", Str(*char\facing))
SetXMLAttribute(*mainnode, "frame", Str(*char\frame))
SetXMLAttribute(*mainnode, "map_filename", GetFilePart(*char\map_filename$))
SetXMLAttribute(*mainnode, "inventory_cursor_x", Str(*char\inventory_cursor_x))
SetXMLAttribute(*mainnode, "inventory_cursor_y", Str(*char\inventory_cursor_y))
For i=1 To #MAX_NUMBER_OF_ABILITIES - 1
If ability_db(i)\name$ <> ""
*node = CreateXMLNode(*mainnode,"")
SetXMLNodeName(*node, "ability")
SetXMLAttribute(*node, "id", Str(i))
If *char\ability[i]\ability_value <> 0
SetXMLAttribute(*node, "ability_value", Str(*char\ability[i]\ability_value))
EndIf
If *char\ability[i]\attribute_max_value <> 0
SetXMLAttribute(*node, "attribute_max_value", Str(*char\ability[i]\attribute_max_value))
EndIf
If *char\ability[i]\attribute_current_value <> 0
SetXMLAttribute(*node, "attribute_current_value", Str(*char\ability[i]\attribute_current_value))
EndIf
If *char\ability[i]\power_adjustment <> 0
SetXMLAttribute(*node, "power_adjustment", Str(*char\ability[i]\power_adjustment))
EndIf
If *char\ability[i]\adjustment_duration <> 0
SetXMLAttribute(*node, "adjustment_duration", Str(*char\ability[i]\adjustment_duration))
EndIf
If *char\ability[i]\adjustment_name$ <> ""
SetXMLAttribute(*node, "adjustment_name", *char\ability[i]\adjustment_name$)
EndIf
If *char\ability[i]\adjustment_power_id <> 0
SetXMLAttribute(*node, "adjustment_power_id", Str(*char\ability[i]\adjustment_power_id))
EndIf
If *char\ability[i]\adjustment_item_id <> 0
SetXMLAttribute(*node, "adjustment_item_id", Str(*char\ability[i]\adjustment_item_id))
EndIf
If *char\ability[i]\item_bonus <> 0
SetXMLAttribute(*node, "item_bonus", Str(*char\ability[i]\item_bonus))
EndIf
If *char\ability[i]\activated = 1
SetXMLAttribute(*node, "activated", "yes")
EndIf
If *char\ability[i]\adjustment_other <> 0
SetXMLAttribute(*node, "adjustment_other", Str(*char\ability[i]\adjustment_other))
EndIf
If *char\ability[i]\adjustment_percentage <> 100