forked from Henne/Bright-Eyes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seg099.cpp
1020 lines (803 loc) · 26.3 KB
/
seg099.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
/*
* Rewrite of DSA1 v3.02_de functions of seg099 (spells 1/3)
* Spells: Dispell / Domination / Demonology / Elements /
* Movement / Healing / Clairvoyance
* Functions rewritten: 39/39 (complete)
*
* Borlandified and identical
* Compiler: Borland C++ 3.1
* Call: BCC.EXE -mlarge -O- -c -1 -Yo seg099.cpp
*
*/
#include <stdio.h>
#include <string.h>
#include "v302de.h"
#include "seg000.h"
#include "seg002.h"
#include "seg006.h"
#include "seg007.h"
#include "seg039.h"
#include "seg047.h"
#include "seg074.h"
#include "seg075.h"
#include "seg096.h"
#include "seg097.h"
#include "seg098.h"
#include "seg105.h"
#if !defined(__BORLANDC__)
namespace M302de {
#endif
void spell_beherrschung(void)
{
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + (host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1) * SIZEOF_HERO));
if (!hero_cursed(get_spelltarget())) {
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
if (get_spelltarget() == get_spelluser()) {
strcpy((char*)Real2Host(ds_readd(DTP2)), (char*)get_tx(0));
ds_writew(SPELL_SPECIAL_AECOST, 0);
} else {
ds_writew(SPELL_SPECIAL_AECOST, random_interval(2, 5) * 4);
if (host_readws(get_spelluser() + HERO_AE) < ds_readws(SPELL_SPECIAL_AECOST)) {
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
and_ptr_bs(get_spelltarget() + HERO_STATUS1, 0xdf);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(1),
(char*)get_spelltarget() + HERO_NAME2);
}
}
}
}
void spell_destructibo(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Destructibo\" ist nicht implementiert\n");
#endif
ds_writew(SPELL_SPECIAL_AECOST, -2);
}
void spell_gardanium(void)
{
signed short answer;
/* prepare a question */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(2), (char*)(get_spelluser() + HERO_NAME2));
/* ask and get the answer */
answer = GUI_input(Real2Host(ds_readd(DTP2)), 2);
/* clear the textbuffer */
host_writeb(Real2Host(ds_readd(DTP2)), 0);
if (answer > 0) {
if (host_readws(get_spelluser() + HERO_AE) >= answer) {
/* enough AE */
/* TODO: this adds the AE to a variable no one reads */
add_ds_ws(GARDANIUM_USED_AE, answer);
/* set AE costs */
ds_writew(SPELL_SPECIAL_AECOST, answer);
/* prepare the message */
strcpy((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(7));
} else {
/* not enough AE */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_ttx(607), (char*)get_spelluser() + HERO_NAME2);
/* set AE costs */
ds_writew(SPELL_SPECIAL_AECOST, 0);
}
} else {
ds_writew(SPELL_SPECIAL_AECOST, 0);
}
}
void spell_illusionen(void)
{
/* Set pointer to enemy target */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
/* check if enemy is an illusion */
if (enemy_illusion(get_spelltarget_e())) {
/* AEcosts = enemy level - spelluser_level */
ds_writew(SPELL_SPECIAL_AECOST,
(host_readbs(get_spelltarget_e() + ENEMY_SHEET_LEVEL)
-host_readbs(get_spelluser() + HERO_LEVEL)) * 2);
/* AEcost are at least 5 */
if (ds_readws(SPELL_SPECIAL_AECOST) < 5)
ds_writew(SPELL_SPECIAL_AECOST, 5);
/* check if spelluser has enough AE */
if (host_readws(get_spelluser() + HERO_AE) < ds_readws(SPELL_SPECIAL_AECOST)) {
/* NO: spell has no effect */
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
/* YES: spell has effect */
ds_writew(SPELL_ILLUSIONEN, 1);
/* kill enemy */
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS1, 1);
}
} else {
/* print a failure message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(3),
(char*)Real2Host(GUI_names_grammar((signed short)0x8000, host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
/* costs 2 AE */
ds_writew(SPELL_SPECIAL_AECOST, 2);
}
}
void spell_verwandlung(void)
{
signed short i;
/* set spelltarget */
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + (host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1) * SIZEOF_HERO));
if (hero_petrified(get_spelltarget())) {
/* set AEcosts */
ds_writew(SPELL_SPECIAL_AECOST, random_schick(10) * 5);
/* check if spelluser has enough AE */
if (host_readws(get_spelluser() + HERO_AE) < ds_readws(SPELL_SPECIAL_AECOST)) {
/* NO: spell has no effect */
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
/* YES: spell has effect */
/* unset petrified bit */
and_ptr_bs(get_spelltarget() + HERO_STATUS1, 0xfb);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(4),
(char*)get_spelltarget() + HERO_NAME2);
}
} else {
if (hero_transformed(get_spelltarget())) {
and_ptr_bs(get_spelltarget() + HERO_STATUS2, 0xbf);
/* increase attributes */
for (i = 0; i <= 6; i++)
inc_ptr_bs(get_spelltarget() + HERO_ATTRIB + i * 3);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_ttx(565),
(char*)get_spelltarget() + HERO_NAME2);
} else {
#ifdef M302de_ORIGINAL_BUGFIX
/* Broken format string, %S must be %s */
host_writeb(get_tx(5) + 5, 's');
#endif
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(5),
(char*)get_spelltarget() + HERO_NAME2);
ds_writew(SPELL_SPECIAL_AECOST, 0);
}
}
}
void spell_band(void)
{
if (host_readbs(get_spelluser() + HERO_ENEMY_ID) >= 10) {
/* cast enemy */
/* Set pointer to enemy target */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
if (host_readbs(get_spelltarget_e() + ENEMY_SHEET_GFX_ID) == 0x1c) {
/* does not work on skeletons */
ds_writew(SPELL_SPECIAL_AECOST, -2);
return;
}
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS1, 0x20);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(6),
Real2Host(GUI_names_grammar((signed short)0x8000,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
} else {
/* cast hero */
/* Set pointer to hero target */
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + (host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1) * SIZEOF_HERO));
if (get_spelltarget() == get_spelluser()) {
/* don't cast yourself */
/* set AE costs */
ds_writew(SPELL_SPECIAL_AECOST, 0);
/* prepare message */
strcpy((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(112));
} else {
/* set status bit */
or_ptr_bs(get_spelltarget() + HERO_STATUS1, 0x80);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(6),
(char*)get_spelltarget() + HERO_NAME2);
}
}
}
void spell_bannbaladin(void)
{
/* Set pointer to enemy target */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
if (host_readbs(get_spelltarget_e() + ENEMY_SHEET_FLAGS) != 0) {
/* spell does not work on animals */
ds_writew(SPELL_SPECIAL_AECOST, 0);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(8),
Real2Host(GUI_names_grammar(0,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
} else {
if (host_readbs(get_spelltarget_e() + ENEMY_SHEET_GFX_ID) == 0x1c) {
/* spell does not work on skeletons */
ds_writew(SPELL_SPECIAL_AECOST, -2);
return;
}
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS2, 1);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(9),
Real2Host(GUI_names_grammar((signed short)0x8000,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
}
}
void spell_boeser_blick(void)
{
/* set attacked foe */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
/* this spell does not work on all kind of skeletons */
if (host_readb(get_spelltarget_e() + ENEMY_SHEET_GFX_ID) == 0x1c) {
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
/* set "Boeser Blick" Flag */
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS2, 2);
/* set number of attacks to 2 */
host_writeb(get_spelltarget_e() + ENEMY_SHEET_ATTACKS, 2);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(10),
(char*)Real2Host(GUI_names_grammar((signed short)0x8000, host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
}
}
void spell_grosse_gier(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Grosse Gier\" ist nicht implementiert\n");
#endif
ds_writew(SPELL_SPECIAL_AECOST, -2);
}
void spell_grosse_ver(void)
{
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
/* this spell does not work on all kind of skeletons */
if (host_readb(get_spelltarget_e() + ENEMY_SHEET_GFX_ID) == 0x1c) {
ds_writew(SPELL_SPECIAL_AECOST, -2);
return;
} else {
/* cost is 8 AP */
ds_writew(SPELL_SPECIAL_AECOST, 8);
}
/* Sub -2 from AT */
host_writeb(get_spelltarget_e() + ENEMY_SHEET_AT,
host_readb(get_spelltarget_e() + ENEMY_SHEET_AT) - 2);
/* Sub -2 from PA */
host_writeb(get_spelltarget_e() + ENEMY_SHEET_PA,
host_readb(get_spelltarget_e() + ENEMY_SHEET_PA) - 2);
}
void spell_herrdertiere(void)
{
/* Set pointer to enemy target */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
if (!host_readbs(get_spelltarget_e() + ENEMY_SHEET_FLAGS)) {
ds_writew(SPELL_SPECIAL_AECOST, 0);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(11),
Real2Host(GUI_names_grammar(0,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
} else {
ds_writew(SPELL_SPECIAL_AECOST, host_readbs(get_spelltarget_e() + ENEMY_SHEET_FIRSTAP));
if (host_readws(get_spelluser() + HERO_AE) < ds_readws(SPELL_SPECIAL_AECOST)) {
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS2, 1);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(9),
Real2Host(GUI_names_grammar((signed short)0x8000,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
}
}
}
void spell_horriphobus(void)
{
/* Set pointer to enemy target */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
/* this spell does not work on all kind of skeletons */
if (host_readb(get_spelltarget_e() + ENEMY_SHEET_GFX_ID) == 0x1c) {
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS2, 4);
and_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS2, 0xfd);
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(12),
Real2Host(GUI_names_grammar((signed short)0x8000,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
}
}
void spell_magischerraub(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Magischer Raub\" ist nicht implementiert\n");
#endif
}
void spell_respondami(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Respondami\" ist nicht implementiert\n");
#endif
}
void spell_sanftmut(void)
{
spell_herrdertiere();
}
void spell_somnigravis(void)
{
if (host_readbs(get_spelluser() + HERO_ENEMY_ID) >= 10) {
/* cast an enemy */
/* Set pointer to enemy target */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
/* this spell does not work on all kind of skeletons */
if (host_readb(get_spelltarget_e() + ENEMY_SHEET_GFX_ID) == 0x1c) {
ds_writew(SPELL_SPECIAL_AECOST, -2);
return;
}
/* set the flag */
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS1, 2);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(13),
Real2Host(GUI_names_grammar((signed short)0x8000,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
return;
}
/* cast hero */
/* Set pointer to hero target */
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + (host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1) * SIZEOF_HERO));
if (get_spelltarget() == get_spelluser()) {
/* don't cast yourself */
/* set AE costs */
ds_writew(SPELL_SPECIAL_AECOST, 0);
/* prepare message */
strcpy((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(112));
} else {
/* set the flag */
or_ptr_bs(get_spelltarget() + HERO_STATUS1, 2);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(13),
(char*)get_spelltarget() + HERO_NAME2);
}
}
void spell_zwingtanz(void)
{
/* Set pointer to enemy target */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
/* this spell does not work on all kind of skeletons */
if (host_readb(get_spelltarget_e() + ENEMY_SHEET_GFX_ID) == 0x1c) {
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
/* set the flag */
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS2, 8);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(14),
Real2Host(GUI_names_grammar((signed short)0x8000,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
}
}
/* Demonologie / Demonology */
void spell_furor_blut(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Furor Blut\" ist nicht implementiert\n");
#endif
ds_writew(SPELL_SPECIAL_AECOST, -2);
}
void spell_geister_bannen(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Geister bannen\" ist nicht implementiert\n");
#endif
}
void spell_geister_rufen(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Geister rufen\" ist nicht implementiert\n");
#endif
ds_writew(SPELL_SPECIAL_AECOST, -2);
}
void spell_heptagon(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Heptagon\" ist nicht implementiert\n");
#endif
ds_writew(SPELL_SPECIAL_AECOST, -2);
}
void spell_kraehenruf(void)
{
signed short caster_level;
signed short pa_value;
signed short i;
signed short damage;
caster_level = host_readbs(get_spelluser() + HERO_LEVEL) + 2;
pa_value = get_attackee_parade();
damage = 0;
for (i = 0; i < caster_level; i++) {
/* only 40 % chance of success */
if (random_schick(20) <= 8) {
if (random_schick(20) > pa_value) {
damage++;
}
}
}
FIG_do_spell_damage(damage);
}
void spell_skelettarius(void)
{
Bit8u *enemy;
signed short x;
signed short y;
signed char unk;
/* Set pointer to enemy target */
ds_writed(SPELLTARGET_E,
(Bit32u)RealMake(datseg, host_readbs(get_spelluser() + HERO_ENEMY_ID) * SIZEOF_ENEMY_SHEET + (ENEMY_SHEETS - 10*SIZEOF_ENEMY_SHEET)));
/* check if the enemy is dead */
if (!enemy_dead(get_spelltarget_e())) {
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(15),
Real2Host(GUI_names_grammar((signed short)0x8000,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
/* set ae costs */
ds_writew(SPELL_SPECIAL_AECOST, 0);
} else {
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(16),
Real2Host(GUI_names_grammar((signed short)0x8000,
host_readbs(get_spelltarget_e() + ENEMY_SHEET_MON_ID), 1)));
enemy = Real2Host(FIG_get_ptr(host_readbs(get_spelltarget_e() + ENEMY_SHEET_FIGHTER_ID)));
x = host_readbs(enemy + 3);
y = host_readbs(enemy + 4);
if (host_readbs(enemy + ENEMY_SHEET_LE) != -1) {
FIG_remove_from_list(ds_readbs(FIG_TWOFIELDED_TABLE + host_readbs(enemy + ENEMY_SHEET_LE)), 0);
}
FIG_remove_from_list(host_readbs(get_spelltarget_e() + ENEMY_SHEET_FIGHTER_ID), 0);
unk = host_readbs(get_spelltarget_e() + ENEMY_SHEET_DUMMY2);
fill_enemy_sheet(host_readbs(get_spelluser() + HERO_ENEMY_ID) - 10, 0x10, 0);
FIG_load_enemy_sprites(get_spelltarget_e() + ENEMY_SHEET_MON_ID, x, y);
or_ptr_bs(get_spelltarget_e() + ENEMY_SHEET_STATUS2, 2);
host_writebs(get_spelltarget_e() + ENEMY_SHEET_DUMMY2, unk);
}
}
/* Elemente / Elements */
void spell_elementare(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Elementare\" ist nicht implementiert\n");
#endif
ds_writew(SPELL_SPECIAL_AECOST, -2);
}
void spell_nihilatio(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Nihilatio\" ist nicht implementiert\n");
#endif
}
void spell_solidirid(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Solidirid\" ist nicht implementiert\n");
#endif
}
/* Bewegung / Movement */
void spell_axxeleratus(void)
{
signed short hero_pos;
signed short slot;
hero_pos = host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1;
/* Set pointer to hero target */
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + hero_pos * SIZEOF_HERO));
if (!host_readbs(get_spelltarget() + HERO_AXXELERATUS)) {
/* AT-bonus for the current weapon */
slot = get_free_mod_slot();
set_mod_slot(slot, MINUTES(1),
get_spelltarget() + HERO_AT + host_readbs(get_spelltarget() + HERO_WP_CLASS),
2, (signed char)hero_pos);
/* PA-bonus for the current weapon */
slot = get_free_mod_slot();
set_mod_slot(slot, MINUTES(1),
get_spelltarget() + HERO_PA + host_readbs(get_spelltarget() + HERO_WP_CLASS),
2, (signed char)hero_pos);
/* axxeleratus active flag */
slot = get_free_mod_slot();
set_mod_slot(slot, MINUTES(1),
get_spelltarget() + HERO_AXXELERATUS,
1, (signed char)hero_pos);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(17),
(char*)get_spelltarget() + HERO_NAME2);
} else {
/* axxeleratus already active */
ds_writew(SPELL_SPECIAL_AECOST, -2);
}
}
void spell_foramen(void)
{
signed short x;
signed short y;
if (ds_readws(DNG_EXTRA_ACTION) != 5) {
return;
}
x = ds_readws(X_TARGET);
y = ds_readws(Y_TARGET);
switch (ds_readbs(DIRECTION)) {
case 0: y--; break;
case 1: x++; break;
case 2: y++; break;
case 3: x--; break;
}
and_ptr_bs(Real2Host(ds_readd(DNG_MAP_PTR)) + y * 16 + x, 0x0f);
or_ptr_bs(Real2Host(ds_readd(DNG_MAP_PTR)) + y * 16 + x, 0x20);
ds_writeb(STEPTARGET_FRONT, host_readbs(Real2Host(ds_readd(DNG_MAP_PTR)) + y * 16 + x));
DNG_open_door();
add_hero_ap(get_spelluser(), 1);
ds_writebs((NEW_MENU_ICONS + 6), ds_writebs((NEW_MENU_ICONS + 7), ds_writebs((NEW_MENU_ICONS + 8), -1)));
ds_writew(REDRAW_MENUICONS, 1);
}
void spell_motoricus(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Motoricus\" ist nicht implementiert\n");
#endif
}
void spell_spurlos(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Spurlos\" ist nicht implementiert\n");
#endif
}
void spell_transversalis(void)
{
if (!ds_readbs(DUNGEON_INDEX) && !ds_readbs(CURRENT_TOWN)) {
/* prepare message */
strcpy((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(18));
} else {
/* set spell costs */
ds_writew(SPELL_SPECIAL_AECOST, select_teleport_dest());
if (ds_readws(SPELL_SPECIAL_AECOST) > 0) {
/* check AE */
if (host_readws(get_spelluser() + HERO_AE) < ds_readws(SPELL_SPECIAL_AECOST)) {
/* abort */
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
/* play sound */
play_voc(ARCHIVE_FILE_FX16_VOC);
/* set new coordinates */
ds_writew(X_TARGET, ds_readws(AUTOMAP_SELX));
ds_writew(Y_TARGET, ds_readws(AUTOMAP_SELY));
}
}
}
ds_writew(AUTOMAP_SELX, ds_writew(AUTOMAP_SELY, -1));
}
void spell_ueber_eis(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Ueber Eis\" ist nicht implementiert\n");
#endif
ds_writew(SPELL_SPECIAL_AECOST, -2);
}
/* Heilung / Healing */
void spell_balsam(void)
{
signed short le;
/* Set pointer to hero target */
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + (host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1) * SIZEOF_HERO));
ds_writew(SPELL_SPECIAL_AECOST, 0);
if ((ds_readw(AUTOFIGHT) != 0) ||
((host_readbs(get_spelluser() + HERO_NPC_ID) != 0) && ds_readws(IN_FIGHT) != 0))
{
/* automatic */
le = (host_readws(get_spelltarget() + HERO_LE_ORIG) - host_readws(get_spelltarget() + HERO_LE)) / 2;
} else {
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(19),
(char*)get_spelluser() + HERO_NAME2,
(char*)get_spelltarget() + HERO_NAME2);
/* ask question */
le = GUI_input(Real2Host(ds_readd(DTP2)), 2);
/* terminate string */
host_writeb(Real2Host(ds_readd(DTP2)), 0);
}
if (le != -1) {
if (le < 7) {
/* costs are at least 7 */
ds_writew(SPELL_SPECIAL_AECOST, 7);
} else {
if (host_readws(get_spelltarget() + HERO_LE_ORIG) - host_readws(get_spelltarget() + HERO_LE) < le) {
ds_writew(SPELL_SPECIAL_AECOST, host_readws(get_spelltarget() + HERO_LE_ORIG) - host_readws(get_spelltarget() + HERO_LE));
le = ds_readws(SPELL_SPECIAL_AECOST);
} else {
ds_writew(SPELL_SPECIAL_AECOST, le);
}
}
if (host_readws(get_spelluser() + HERO_AE) < ds_readws(SPELL_SPECIAL_AECOST)) {
ds_writew(SPELL_SPECIAL_AECOST, host_readws(get_spelluser() + HERO_AE));
le = ds_readws(SPELL_SPECIAL_AECOST);
}
add_hero_le(get_spelltarget(), le);
}
}
void spell_hexenspeichel(void)
{
signed short le;
/* Set pointer to hero target */
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + (host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1) * SIZEOF_HERO));
/* set costs to 0 */
ds_writew(SPELL_SPECIAL_AECOST, 0);
if (get_spelltarget() == get_spelluser()) {
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(20),
(char*)get_spelluser() + HERO_NAME2);
return;
}
/* prepare question */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(19),
(char*)get_spelluser() + HERO_NAME2,
(char*)get_spelltarget() + HERO_NAME2);
le = GUI_input(Real2Host(ds_readd(DTP2)), 2);
host_writeb(Real2Host(ds_readd(DTP2)), 0);
if (le != -1) {
if (host_readws(get_spelltarget() + HERO_LE_ORIG) - host_readws(get_spelltarget() + HERO_LE) < le * 2) {
ds_writew(SPELL_SPECIAL_AECOST,
(host_readws(get_spelltarget() + HERO_LE_ORIG) - host_readws(get_spelltarget() + HERO_LE)) * 2);
} else {
if (host_readws(get_spelluser() + HERO_AE ) < ds_readws(SPELL_SPECIAL_AECOST)) {
ds_writew(SPELL_SPECIAL_AECOST, host_readws(get_spelluser() + HERO_AE));
} else {
ds_writew(SPELL_SPECIAL_AECOST, le * 2);
}
}
add_hero_le(get_spelltarget(), ds_readws(SPELL_SPECIAL_AECOST) / 2);
}
}
void spell_klarum_purum(void)
{
signed short poison;
/* Set pointer to hero target */
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + (host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1) * SIZEOF_HERO));
poison = hero_is_poisoned(get_spelltarget());
if (!poison) {
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(21),
(char*)get_spelltarget() + HERO_NAME2);
ds_writew(SPELL_SPECIAL_AECOST, 0);
return;
}
/* AE-cost = poison cost */
ds_writew(SPELL_SPECIAL_AECOST, ds_readws(POISON_PRICES + poison * 2));
if (host_readws(get_spelluser() + HERO_AE) < ds_readws(SPELL_SPECIAL_AECOST)) {
/* not enough AE */
ds_writew(SPELL_SPECIAL_AECOST, -2);
} else {
/* reset poison */
host_writeb(get_spelltarget() + poison * 5 + 0xd7, 0);
host_writeb(get_spelltarget() + poison * 5 + 0xd6, 1);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(22),
(char*)get_spelltarget() + HERO_NAME2);
}
}
void spell_ruhe_koerper(void)
{
/* Set pointer to hero target */
ds_writed(SPELLTARGET,
(Bit32u)((RealPt)ds_readd(HEROS) + (host_readbs(get_spelluser() + HERO_ENEMY_ID) - 1) * SIZEOF_HERO));
/* set the flag */
host_writeb(get_spelltarget() + HERO_RUHE_KOERPER, 1);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(51),
(char*)get_spelltarget() + HERO_NAME2);
}
void spell_tiere_heilen(void)
{
#if !defined(__BORLANDC__)
D1_INFO("Zauberspruch \"Tiere heilen\" ist nicht implementiert und dient nur zum AE ausgeben.\n");
#endif
signed short ae;
/* set AE costs to 0 */
ds_writew(SPELL_SPECIAL_AECOST, 0);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(23),
(char*)get_spelluser() + HERO_NAME2);
/* ask how many AE should be spent */
ae = GUI_input(Real2Host(ds_readd(DTP2)), 2);
/* terminate string */
host_writebs(Real2Host(ds_readd(DTP2)), 0);
if (ae != -1) {
/* set AE costs to AE */
ds_writew(SPELL_SPECIAL_AECOST, ae);
}
}
/* Hellsicht / Clarvoyance */
void spell_adleraug(void)
{
signed short slot;
signed short hero_pos;
hero_pos = get_hero_index(get_spelluser());
slot = get_free_mod_slot();
/* Perception / Sinnesschaerfe + 7 */
set_mod_slot(slot, MINUTES(6), get_spelluser() + (HERO_TA_INTUITION + 1), 7, (signed char)hero_pos);
/* prepare message */
sprintf((char*)Real2Host(ds_readd(DTP2)),
(char*)get_tx(24),
(char*)get_spelluser() + HERO_NAME2);
}
RealPt spell_analues(void)
{
signed short item_id;
signed short i;
signed short item_pos;
/* set analyzation capabilities */
if (ds_readw(IN_ACADEMY) == 99) {
ds_writew(SPELLTEST_RESULT, 99);
}
item_pos = select_item_to_drop(get_spelluser());
#ifdef M302de_ORIGINAL_BUGFIX
/* If the player cancels item selection or has no items select_item_to_drop() returns -1.
The original uses the return value to calculate an index, whithout checking for this. */
if (item_pos == -1) item_id = 0;
else item_id = host_readws(get_spelluser() + 14 * item_pos + HERO_ITEM_HEAD);
#else
item_id = host_readws(get_spelluser() + 14 * item_pos + HERO_ITEM_HEAD);
#endif
strcpy((char*)Real2Host(ds_readd(TEXT_OUTPUT_BUF)), (char*)get_tx(52));
if (item_id) {
for (i = 0; ds_readws(ANALUES_ITEMS + i * 5) != -1; i++) {
if (ds_readws(ANALUES_ITEMS + i * 5) == item_id) {
/* check if the spellcaster is able to analyze this item */
if (ds_readws((ANALUES_ITEMS + 2) + i * 5) <= ds_readws(SPELLTEST_RESULT)) {
/* copy the matching result string */
strcpy((char*)Real2Host(ds_readd(TEXT_OUTPUT_BUF)),
(char*)get_tx(ds_readbs((ANALUES_ITEMS + 4) + i * 5)));
/* set the magic flag */
or_ptr_bs(get_spelluser() + item_pos * 14 + (HERO_ITEM_HEAD + 4), 0x80);
break;
} else {
/* nothing found string */
strcpy((char*)Real2Host(ds_readd(TEXT_OUTPUT_BUF)),
(char*)get_tx(55));
break;