-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAttack.cpp
More file actions
2431 lines (2349 loc) · 71.1 KB
/
Attack.cpp
File metadata and controls
2431 lines (2349 loc) · 71.1 KB
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
#include "stdafx.h"
#include "UI.h"
#include <stdio.h>
#include "Dispatch.h"
#include "CSB.h"
#include "Data.h"
extern ui32 *pDSAparameters;
extern bool overlayActive;
//#define pauseAwhile(milliseconds) {};
//#define pauseAwhile(milliseconds) UI_Sleep(milliseconds)
#define MS2VBL(milliseconds) ((milliseconds)/16)
static i32 testdelay = 500;
// TAG00ac9e
i16 DetermineAttackOrdinal(
i32 attackX,
i32 attackY,
i32 partyX,
i32 partyY,
i32 charPos)
{
dReg D6;
RN objD5;
DB4 *DB4A3;
ui8 attackedAbsPos[4];
i32 i, pos;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
objD5 = FindFirstMonster(attackX, attackY);
if (objD5 == RNeof)
{
return 0;
};
DB4A3 = GetRecordAddressDB4(objD5);
DetermineAttackOrder(attackedAbsPos,
attackX, attackY,
partyX, partyY, charPos);
for (i=0;;i++)
{
pos = attackedAbsPos[i];
D6W = sw(OrdinalOfMonsterAtPosition(DB4A3, pos));
if (D6W != 0) return D6W;
};
}
//*********************************************************
//
//*********************************************************
// TAG00f058
bool IsCellFluxcage(i32 mapX, i32 mapY)
{
dReg D0;
ROOMTYPE rtD6;
RN objD7;
DB15 *DB15A0;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
rtD6 = (ROOMTYPE)(GetCellFlags(mapX, mapY) >> 5);//room type
if ((rtD6==roomSTONE) || (rtD6==roomSTAIRS))
{
return false;
};
for (objD7 = FindFirstObject(mapX, mapY);
objD7 != RNeof;
objD7 = GetDBRecordLink(objD7) )
{
if (objD7.dbType() != dbCLOUD) continue;
DB15A0 = GetRecordAddressDB15(objD7);
D0W = sw(DB15A0->cloudType());
if (D0W == CT_FLUXCAGE) return true;
//
//
};
return false;
}
//*********************************************************
//
//*********************************************************
// TAG00f0e8
RN IsLordChaosHere(i32 mapX, i32 mapY)
{
RN objD7;
DB4 *DB4A3;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
objD7 = FindFirstMonster(mapX, mapY);
if (objD7 == RNeof) return RNempty;
DB4A3 = GetRecordAddressDB4(objD7);
if (DB4A3->monsterType() != mon_LordChaos) return RNempty;
return objD7;
}
bool legalXY(i32 x, i32 y)
{
if ( (y < 0) || (y >= d.height) ) return false;
if ( (x < 0) || (x >= d.width) ) return false;
return true;
};
bool IsCellWall(i32 x, i32 y)
{
i32 cf;
cf = (GetCellFlags(x, y) & 255) >> 5;
return (cf==roomSTONE) || (cf==roomFALSEWALL);
}
bool IsCellOpenOrPit(i32 x, i32 y)
{
i32 cf;
cf = (GetCellFlags(x, y) & 255) >> 5;
return (cf == roomOPEN) ||(cf == roomPIT);
}
bool IsCellOccupied(i32 x, i32 y)
{
if (FindFirstMonster(x, y) != RNeof) return true;
if ( (d.LoadedLevel == d.partyLevel)
&& (d.partyX == x)
&& (d.partyY == y) ) return true;
return false;
}
//*********************************************************
//
//*********************************************************
// TAG00f340
RESTARTABLE _Fusion(const i32 attackX, const i32 attackY)
{//()
static dReg D0, D4, D5, D6, D7;
static RN obj_16;
static i32 i_14[4];
static i16 w_6;
static i16 w_4;
static i16 w_2;
i32 i, j, temp;
i32 direction[4], x1[4], y1[4], x2[4], y2[4];
bool fluxCageOrWall[4], empty1[4], empty2[4];
RESTARTMAP
RESTART(3)
END_RESTARTMAP
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
D7W = sw(attackX);
D6W = sw(attackY);
if (D7W < 0) RETURN;
//I think this is what the programmer
//wanted. But it appears that the variable
//was unsigned and therefore impossible to
//be less than zero.
if (D7W >= d.width) RETURN;
if (D6W < 0) RETURN;
if (D6W >= d.height) RETURN;
CreateCloud(RN(RNDispellMissile), 0xff, D7W, D6W, D7W, D6W, 0xff, NULL);
obj_16 = IsLordChaosHere(D7W, D6W);
if (obj_16 == RNempty) RETURN;
#define NewFusion
#ifdef NewFusion
for (i=0; i<4; i++) direction[i] = i; // Initially north, east, south, west
// Now scramble the four directions
for (i=3; i>0; i--)
{
j = STRandom(i+1);
temp = direction[i];
direction[i] = direction[j];
direction[j] = temp;
};
for (i=0; i<4; i++) //for each direction in scrambled order
{
x1[i] = D7W + d.DeltaX[direction[i]];
y1[i] = D6W + d.DeltaY[direction[i]];
x2[i] = D7W + 2*d.DeltaX[direction[i]];
y2[i] = D6W + 2*d.DeltaY[direction[i]];
fluxCageOrWall[i]
= IsCellFluxcage(x1[i], y1[i]) || IsCellWall(x1[i], y1[i]);
empty1[i] = IsCellOpenOrPit(x1[i], y1[i])
&& !IsCellOccupied(x1[i], y1[i]);
empty2[i] = legalXY(x2[i], y2[i])
&& IsCellOpenOrPit(x2[i], y2[i])
&& !IsCellOccupied(x2[i], y2[i])
&& !IsCellFluxcage(x2[i], y2[i]);
};
// Now try to move Lord Chaos to an immediately adjacent cell.
for (i=0; i<4; i++)
{
if (!fluxCageOrWall[i] && empty1[i])
{
D0W = MoveObject(obj_16, D7W, D6W, x1[i], y1[i], NULL, NULL);
if (D0W == 0)
{
StartMonsterMovementTimers(x1[i], y1[i]);
RETURN;
};
};
};
// If no fluxcage or wall is in the way try moving him two squares.
for (i=0; i<4; i++)
{
if (!fluxCageOrWall[i] && empty2[i])
{
D0W = MoveObject(obj_16, D7W, D6W, x2[i], y2[i], NULL, NULL);
if (D0W == 0)
{
StartMonsterMovementTimers(x2[i], y2[i]);
RETURN;
};
};
};
// Sorry, Mr. Chaos. You are toast.
#else // OldFusion
i_14[0] = IsCellFluxcage(D7W-1, D6W) ? 1 : 0;
i_14[1] = IsCellFluxcage(D7W+1, D6W) ? 1 : 0;
i_14[2] = IsCellFluxcage(D7W, D6W-1) ? 1 : 0;
i_14[3] = IsCellFluxcage(D7W, D6W+1) ? 1 : 0;
for (w_2 = sw(i_14[0] + i_14[1] + i_14[2] + i_14[3]);
w_2 < 4;
w_2++) // Examine each non-fluxcage cells in random order.
{
D5W = D7W;
D4W = D6W;
w_4 = (i16)STRandom0_3();
for (w_6 = 4; w_6!=0; w_6--)
{ // Look in four directions from Lord Chaos starting with random direction in w_4.
D0L = i_14[w_4];
if (D0W == 0)
{
i_14[w_4] = 1;
switch (w_4)
{
case 0: D5W--; break; //west
case 1: D5W++; break; //east
case 2: D4W--; break; //north
case 3: D4W++; break; //south
}; //switch
break;
};
w_4 = sw((w_4 + 1) & 3);
//
};
if (OpenTeleporterPitOrDoor(D5W, D4W))
if ( (D5W != d.partyX) || (D4W != d.partyY) )
if (FindFirstMonster(D5W, D4W) == RNeof) // Don't put Lord Chaos on top
// of another monster!
{
D0W = MoveObject(obj_16, D7W, D6W, D5W, D4W);
if (D0W == 0)
{
StartMonsterMovementTimers(D5W, D4W);
RETURN;
};
};
//
};
#endif // NewFusion
FusionSequence(_3_); //TAG01fefc
RETURN;
}
enum ATTACKDATATYPE
{
ADT_WarCry = 1,
ADT_Physical = 2,
ADT_Spell = 3,
ADT_HitDoor = 4,
ADT_Shoot = 5,
ADT_Flip = 6,
ADT_Shield = 7,
ADT_FluxCage = 8,
ADT_Fusion = 9,
ADT_Heal = 10,
ADT_Window = 11,
ADT_ClimbDown = 12,
ADT_FreezeLife = 13,
ADT_Light = 14,
ADT_Throw = 15,
ADT_Default = 16 //Block, Hit
};
struct SHIELD // dataType = ADT_Shield
{
// atk_SPELLSHIELD
// atk_FIRESHIELD
i32 mustHaveMana;
i32 strength;
};
struct FLIP // dataType = ADT_Flip
{
// atk_FLIP
i32 heads;
};
struct SHOOT //dataType = ADT_Shoot
{
// atk_SHOOT
i32 success;
i32 range;
i32 damage;
i32 decayRate;
};
struct HITDOOR //dataType = ADT_HitDoor
{
// atk_BASH:
// atk_HACK:
// atk_BERZERK:
// atk_KICK:
// atk_SWING:
// atk_CHOP:
i32 strength;
};
struct WARCRYETC //dataType = ADT_WarCry
// atk_CONFUSE:
// atk_WARCRY:
// atk_CALM:
// atk_BRANDISH:
// atk_BLOWHORN:
{
i32 mastery;
i32 skillIncrement;
i32 effectiveMastery;
i32 requiredMastery;
};
struct PHYSICALATTACK //dataType = ADT_Physical
{
// atk_BASH:
// atk_HACK:
// atk_BERZERK:
// atk_KICK:
// atk_SWING:
// atk_CHOP:
// atk_DISRUPT:
// atk_JAB:
// atk_PARRY:
// atk_STAB2:
// atk_STAB1:
// atk_STUN:
// atk_THRUST:
// atk_MELEE:
// atk_SLASH:
// atk_CLEAVE:
// atk_PUNCH:
i32 monsterDamage;
i32 staminaAdjust;
i32 skillAdjust;
i32 attackedMonsterOrdinal;
};
struct SPELLATTACK //dataType = ADT_Spell
{
// atk_LIGHTNING:
// atk_DISPELL:
// atk_FIREBALL:
// atk_SPIT:
// atk_INVOKE
i32 spellRange;
i32 spellType;
i32 decrementCharges; // if non-zero (default = 1)
};
struct HEAL
{
// atk_HEAL
i32 HPIncrement;
};
struct FREEZELIFE
{
i32 oldTime;
i32 deltaTime;
};
struct LIGHT
{
i32 deltaLight;
i32 decayRate;
i32 time;
};
struct THROW
{
i32 side;
i32 abort;
i32 facing;
i32 range;
i32 damage;
i32 decayRate;
};
union ATTDEP
{
WARCRYETC warcryetc;
PHYSICALATTACK physicalAttack;
SPELLATTACK spellAttack;
HITDOOR hitDoor;
SHOOT shoot;
FLIP flip;
SHIELD shield;
HEAL heal;
FREEZELIFE freezeLife;
LIGHT light;
THROW thro; // Cannot say 'throw'; it is reserved!
};
struct ATTACKPARAMETERS
{
i32 charIdx; //pre-attack
i32 attackType; //pre-attack
i32 attackX; //pre-attack
i32 attackY; //pre-attack
i32 monsterUnderAttack; //0 if none //pre-attack
i32 monsterType; //pre-attack
i32 skillNumber; //pre-attack
i32 staminaCost; //pre-attack
i32 experienceGained; //pre-attack
i32 disableTime; //pre-attack
i32 neededMana; //pre-attack
i32 unused; //damageToMonster;
i32 decrementCharges;
i32 activateMonster;
i32 userInfo[10];
i32 dataType; // = ADT_*****
ATTDEP attdep;
//ATTACKPARAMETERS(){memset(this, 0, sizeof(*this));};
};
struct FILTER
{
LOCATIONREL locrFilter;
TIMER timer;
RN DSAobj;
};
void PartyAttackFilterError(ui8& flag, const char* msg)
{
char message[500];
if (flag != 0) return;
strcpy(message, "Party attack Filter error\n");
strcat(message, msg);
strcat(message, "We will try to proceed quietly.");
UI_MessageBox(message, "Party Attack Error",MESSAGE_OK);
flag = 1;
}
void CallAttackFilter(FILTER *pFilter, ATTACKPARAMETERS *pParam, i32 msg)
{
i32 currentLevel;
DSAVARS dsaVars;
static ui8 characterMsg = 0;
if (pFilter->locrFilter.l < 0) return;
currentLevel = d.LoadedLevel;
if (pFilter->locrFilter.l != d.LoadedLevel)
{
LoadLevel(pFilter->locrFilter.l);
};
pFilter->timer.timerUByte9((ui8)msg);
ProcessDSAFilter(pFilter->DSAobj, &pFilter->timer, pFilter->locrFilter, NULL, &dsaVars);
if (pParam->charIdx >= d.NumCharacter)
{
PartyAttackFilterError(characterMsg,"Set illegal character index");
pParam->charIdx = 0;
};
if (currentLevel != d.LoadedLevel)
{
LoadLevel(currentLevel);
};
}
void PhysicalAttackFilter(ATTACKPARAMETERS *pParam, FILTER *pFilter, const char *traceID)
{
MONSTER_DAMAGE_RESULT monsterDamageResult;
RN objMon;
pParam->dataType = ADT_Physical;
CallAttackFilter(pFilter, pParam, 1);
if (pParam->monsterUnderAttack == 0) return;
objMon.ConstructFromInteger(pParam->monsterUnderAttack);
if (pParam->attdep.physicalAttack.staminaAdjust != 0)
{
AdjustStamina(pParam->charIdx,
pParam->attdep.physicalAttack.staminaAdjust);
};
if (pParam->attdep.physicalAttack.skillAdjust != 0)
{
AdjustSkills(pParam->charIdx,
pParam->skillNumber,
pParam->attdep.physicalAttack.skillAdjust,
ASW_PhysicalAttack);
};
monsterDamageResult = DamageMonster(GetRecordAddressDB4(objMon),//DB4A2,
pParam->attdep.physicalAttack.attackedMonsterOrdinal-1, //monsterPosIndex,
pParam->attackX,
pParam->attackY,
pParam->attdep.physicalAttack.monsterDamage, //D7W,
1,
false,
NULL);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sw_2 = DamageMonster() --> %d\n",
traceID,
pParam->attdep.physicalAttack.monsterDamage);
};
if (monsterDamageResult != NO_MONSTER_DIED) // If one or more of the monster group died.
{
pParam->activateMonster = 1;
//ProcessTimers29to41(pParam->attackX,
// pParam->attackY,
// TT_M1,
// 0);
};
}
//*********************************************************
// Called when we hit monster with sword
//*********************************************************
// TAG00f930
i32 DeterminePhysicalAttackDamage(
ATTACKPARAMETERS *pParam,
FILTER *pFilter,
//CHARDESC *pChar,
//i32 chIdx,
//DB4 *pMonster,
i16 monsterPosIndex,
//i32 attackX,
//i32 attackY,
i16 P7,
i16 P8,
//i32 skillNumber,
bool vorpalOrDisrupt,
const char *traceID)
{
dReg D0, D1, D3, D4, D6, D7;
CHARDESC *pchA3;
RN objMon;
//DB4 *DB4A2;
MONSTERDESC *pmtDesc;
OBJ_NAME_INDEX objNI_attackWeapon;
//i16 w_2;
bool luckyHit = false;
i32 throwingDistance;
//i32 StaminaDec;
i32 ranResult;
i32 levelDifficulty;
// D6L = 0x1ccccccc; // Avoid compiler warning.
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),
"%sEntering DeterminePhysicalAttackDamage(char=%d,monster,P4=%d,P7=%d,P8=%d,skillNumber=%d)\n",
traceID, pParam->charIdx, monsterPosIndex, P7, P8, pParam->skillNumber);
};
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pchA3 = &d.CH16482[pParam->charIdx];
objMon.ConstructFromInteger(pParam->monsterUnderAttack);
//DB4A2 = pMonster;
if (pParam->charIdx >= d.NumCharacter)
{
PhysicalAttackFilter(pParam, pFilter, traceID);
return 0;
};
if (pchA3->HP() == 0)
{
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sCharacter is dead. Return 0\n",traceID);
};
PhysicalAttackFilter(pParam, pFilter, traceID);
return 0;
};
levelDifficulty = d.pCurLevelDesc->experienceMultiplier();
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%slevelDifficulty = %d\n",
traceID, levelDifficulty);
};
pmtDesc = &d.MonsterDescriptor[GetRecordAddressDB4(objMon)->monsterType()];
objNI_attackWeapon = pchA3->Possession(1).NameIndex(); //weapon hand
// We modified the calling sequence to separate the
// vorpalOrDisrupt parameter from parameter P7
if ( (!pmtDesc->nonMaterial())
|| vorpalOrDisrupt )
{
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%spi26 word2 &0x40 == 0 or vorpalOrDisrupt\n",traceID);
};
D0L = Quickness(pchA3,nextTracePrefix(traceID));
D1L = STRandom(32);
D3W = pmtDesc->dexterity12; // uByte8[4];
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%scharacter's quickenss = %d\n",traceID,D0L);
fprintf(GETFILE(TraceFile),"%srequired quickness = (pi26.uByte8[4]=%d) + (random(32)=%d) + (levelDifficulty=%d) - 16 = %d\n",
traceID, D3W, D1W, levelDifficulty, D1W+D3W+levelDifficulty-16);
};
D1W = sw(D1W + D3W + levelDifficulty - 16);
if ( (D0W <= D1W) // if quickness too small
&& ((luckyHit = (STRandom0_3() == 0)) == false) // and no luck
&& !IsCharacterLucky(pchA3, 75 - P7, nextTracePrefix(traceID)) )
{
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sAttack failed. Quickness too small. Luck(1/4) failed. TAG16476(75-(P7=%d) returned false. Return 0\n",traceID, P7);
};
//AdjustStamina(pParam->charIdx, StaminaDec=STRandomBool() + 2);
pParam->attdep.physicalAttack.staminaAdjust = 2 + STRandomBool();
PhysicalAttackFilter(pParam, pFilter, traceID);
if (traceID!=NULL)
{
fprintf(
GETFILE(TraceFile),
"%sDecrementStamina(2+random(1)=%d)\n",
traceID,
pParam->attdep.physicalAttack.staminaAdjust);
fprintf(GETFILE(TraceFile),"%sPhysicalAttack Returning 0\n",traceID);
};
DrawCharacterState(pParam->charIdx);
return 0;
};
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sAttack was successful because ",traceID);
if (D0W>D1W)
{
fprintf(GETFILE(TraceFile), "Character's quickness is great enough\n");
}
else if (luckyHit)
{
fprintf(GETFILE(TraceFile),"Lucky Hit (1 chance in 4)\n");
}
else
{
fprintf(GETFILE(TraceFile),"IsCharacterLucky returned true\n");
};
};
// It is good to get here, I think
throwingDistance = DetermineThrowingDistance(pParam->charIdx, 1);
D7W = sw(throwingDistance);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile), "%sD7W = Throwing distance=%d\n",traceID,D7W);
};
if (throwingDistance != 0) /////goto tag00faa2;
{
D7W = sw(D7W + (STRandom() & 0xffff) % (D7W/2 + 1));
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD7W = D7W+random(D7W/2+1) = %d\n",traceID,D7W);
};
D7W = sw(D7W * P8 / 32);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD7W = D7W*(P8=%d)/32 = %d\n",traceID,P8,D7W);
};
D4W = sw((ranResult=STRandom(32)) + pmtDesc->defense08 + levelDifficulty);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD4W = (i26->uByte8[0]=%d) + (levelDifficulty=%d) + (random(32)=%d) = %d\n",
traceID,pmtDesc->defense08,levelDifficulty,ranResult,D4W);
};
if (objNI_attackWeapon == objNI_DiamondEdge)
{
D4W = sw(D4W - D4W/4);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sDiamond Edge so subtract 25%% from D4W --> %d\n",traceID,D4W);
};
}
else
{
if (objNI_attackWeapon == objNI_Executioner)
{
D4W = sw(D4W - D4W/8);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sExecutioner so subtract 12.5%% from D4W --> %d\n",traceID,D4W);
};
};
};
// D4 is perhaps like the monster's Armor effectiveness???
D7W = sw(D7W + (ranResult=STRandom(32)) - D4W);
D6W = D7W; // chance of hitting?????
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD7W = D7W + (random(32)=%d) - (D4W=%d) = %d\n",
traceID,ranResult, D4W, D7W);
fprintf(GETFILE(TraceFile),"%sD6W = D7W = %d\n", traceID, D6W);
};
}
else
{/// }}}}}}
D6W = 0; //Added 23Jun2004. Tiggy 'Bashing' with a stone
//club resulted in throwingDistance==0 and D6W
//never got set.
};
if ((throwingDistance==0)||(D6W <= 1))
{
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sAttack may fail because ",traceID);
if (throwingDistance==0)
{
fprintf(GETFILE(TraceFile), "throwingDistance = 0.\n");
}
else
{
fprintf(GETFILE(TraceFile),"D6W < 2.\n");
};
};
D7W = (i16)STRandom0_3();
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD7W = random(4) = %d\n",traceID,D7W);
};
if (D7W == 0)
{
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sAttack failed because ",traceID);
fprintf(GETFILE(TraceFile)," we were not Lucky (D7W==0)\n");
};
//AdjustStamina(pParam->charIdx, StaminaDec=STRandomBool() + 2);
pParam->attdep.physicalAttack.staminaAdjust = 2 + STRandomBool();
PhysicalAttackFilter(pParam, pFilter, traceID);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),
"%sDecrementStamina(2+random(1)=%d)\n",
traceID,
pParam->attdep.physicalAttack.staminaAdjust);
fprintf(GETFILE(TraceFile),"%sPhysicalAttack Returning 0\n",traceID);
};
DrawCharacterState(pParam->charIdx);
return 0;
};
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sWe were lucky. D7W is non-zero\n",traceID);
};
D1W = sw(STRandom(16));
//ASSERT(D6L != 0x1ccccccc);
D6W = sw(D6W + D1W);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD6W += (random(16)=%d) --> %d\n",
traceID, D1W, D6W);
};
if ( (D6W > 0)
|| (STRandomBool() != 0) )
{
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sWe are going to recompute D7W because ",traceID);
if (D6W>0)
{
fprintf(GETFILE(TraceFile), "D6W > 0\n");
}
else
{
fprintf(GETFILE(TraceFile),"we got lucky (1/2)\n");
};
};
D7W = sw(D7W + (ranResult=STRandom0_3()));
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD7W += (random(3)=%d) --> %d\n",
traceID, ranResult, D7W);
};
if (STRandom0_3() == 0)
{
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sWe are going to recompute D7W because we got lucky(1/4)\n",traceID);
};
D7W = sw(D7W + Larger(0, (ranResult=STRandom(16)) + D6W));
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD7W += max((D6W=%d),(random(16)=%d))-->%d\n",
traceID,D6W, ranResult,D7W);
};
};
};
};
D7W /= 2;
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sDivide D7W by 2 --> %d\n",traceID,D7W);
};
if (D7W == 0) D0W = 0;
else D0W = sw((STRandom() & 0xffff) % D7W);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD0W=random(D7W) --> %d\n", traceID, D0W);
};
D1W = (i16)(ranResult=STRandom0_3());
D7W = sw(D7W + D1W + D0W);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile), "%sD7W += (random(4)=%d) + (D0W=%d) --> %d\n",
traceID, ranResult, D0W, D7W);
};
if (D7W != 0) D7W = sw(D7W + (ranResult=(STRandom() & 0xffff) % D7W));
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile), "%sD7W += (random(D7W)=%d)--> %d\n",
traceID, ranResult, D7W);
};
D7W /= 4;
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sDivide D7W by 4 --> %d\n", traceID, D7W);
};
D7W = sw(D7W + (ranResult=STRandom0_3()) + 1);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD7W += (random(4)=%d) + 1 --> %d\n",
traceID, ranResult, D7W);
};
//
//
if (traceID!=NULL)
{
if ( (objNI_attackWeapon == objNI_VorpalBlade)
&& !pmtDesc->nonMaterial() )
{
fprintf(GETFILE(TraceFile),"%sDivide D7W by 2 because VorpalBlade and i26 Word2 bit 6 = 0 --> %d\n",
traceID, D7W/2);
};
};
if ( (objNI_attackWeapon == objNI_VorpalBlade )
&& (!pmtDesc->nonMaterial() )
&& ((D7W = sw(D7W/2)) == 0) )
{
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sAttack failed because Vorpal, i26 word 2 bit 6=0, and D7W=0\n",traceID);
};
//AdjustStamina(pParam->charIdx, StaminaDec=STRandomBool() + 2);
pParam->attdep.physicalAttack.staminaAdjust = 2 + STRandomBool();
PhysicalAttackFilter(pParam, pFilter, traceID);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),
"%sDecrementStamina(2+random(1)=%d)\n",
traceID,
pParam->attdep.physicalAttack.staminaAdjust);
fprintf(GETFILE(TraceFile),"%sPhysicalAttack Returning 0\n",traceID);
};
DrawCharacterState(pParam->charIdx);
return 0;
};
D0W = sw((ranResult=STRandom(64)));
D1W = sw(DetermineMastery(pParam->charIdx, pParam->skillNumber, traceID==NULL?NULL:traceID-2));
if (D0W < D1W)
{
D7W += 10;
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sAdd 10 to D7W because (Mastery(skill=%d)=%d) > (random(64)=%d) --> %d\n",
traceID,pParam->skillNumber,D1W, ranResult, D7W);
};
};
if (D7W < 0) D7W = 0;
pParam->attdep.physicalAttack.monsterDamage = D7W;
//w_2 = DamageMonster(GetRecordAddressDB4(objMon),
// monsterPosIndex,
// pParam->attackX,
// pParam->attackY,
// D7W,
// 1,
// false);
D0W = sw((D7W * pmtDesc->word16_8_11() / 16) + 3);
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD0W = ((D7W=%d) * (Bits8_11(i26.word16)=%d)/16) + 3 --> %d\n",
traceID,D7W, pmtDesc->word16_8_11(),D0W);
};
//AdjustSkills(pParam->charIdx, pParam->skillNumber, D0W);
pParam->attdep.physicalAttack.skillAdjust = D0W;
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sAdjustSkills((skill=%d), (D0W=%d))\n",
traceID,pParam->skillNumber, D0W);
};
//AdjustStamina(pParam->charIdx, (ranResult=STRandom0_3()) + 4);
pParam->attdep.physicalAttack.staminaAdjust = 4 + STRandom0_3();
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sDecrement Stamina by random(4)+4 = %d\n",
traceID, pParam->attdep.physicalAttack.staminaAdjust);
};
PhysicalAttackFilter(pParam, pFilter, traceID);
}
else
{ // Non-material and Not (Vorpal or Disrupt)
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%spi26 word2 &0x40 != 0 and w_4 == 0\n",traceID);
};
D7W = 0;
pParam->attdep.physicalAttack.monsterDamage = D7W; //Should already be zero but
//let us be explicit.
//w_2 = 0;
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sD7W = 0\n+++w_2 = 0\n",traceID);
};
//AdjustStamina(pParam->charIdx, (ranResult=STRandomBool()) + 2);
pParam->attdep.physicalAttack.staminaAdjust = 2 + STRandomBool();
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sDecrement Stamina by random(2)+2 = %d\n",
traceID, pParam->attdep.physicalAttack.staminaAdjust);
};
PhysicalAttackFilter(pParam, pFilter, traceID);
};
DrawCharacterState(pParam->charIdx);
//if (w_2 != 0)
//{
// ProcessTimers29to41(pParam->attackX, pParam->attackY, TT_M1, 0);
//};
if (traceID!=NULL)
{
fprintf(GETFILE(TraceFile),"%sPhysicalAttack returning D7W = %d\n",traceID,D7W);
};
return pParam->attdep.physicalAttack.monsterDamage;
}
//*********************************************************
//
//*********************************************************
// TAG01adaa
RESTARTABLE _FlashAttackDamage(const i32 value)
{//()
static dReg D0, D5, D6, D7;
static const char* A2;
static aReg A3;
static RectPos *pR_10;
static i8 b_6[6];
static i32 damage;
RESTARTMAP
RESTART(1)
END_RESTARTMAP
damage = value;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
STHideCursor(HC1);
d.UseByteCoordinates = 0;
FillRectangle(d.LogicalScreenBase,
(RectPos *)d.Word20,
0,
160);
if (damage < 0)
{
if (damage == -1)
{
D5W = 242;
A2 = "CAN'T REACH";
}
else
{
D5W = 248;
A2 = "NEED AMMO";
};
TextOutToScreen(D5W, 100, 4, 0, A2, true);
}
else
{
if (damage > 40)
{
pR_10 = &d.wRectPos20202;
A3 = (i8 *)GetBasicGraphicAddress(14);
D6W = 48;
}
else
{
if (damage > 15)
{
D7W = 2;
D5W = 64;
D6W = 32;
pR_10 = &d.wRectPos20226;
}
else
{