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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* Based on the Reverse Engineering work of Christophe Fontanel,
* maintainer of the Dungeon Master Encyclopaedia (http://dmweb.free.fr/)
*/
#include "dm/menus.h"
#include "dm/gfx.h"
#include "dm/champion.h"
#include "dm/dungeonman.h"
#include "dm/objectman.h"
#include "dm/inventory.h"
#include "dm/text.h"
#include "dm/eventman.h"
#include "dm/timeline.h"
#include "dm/movesens.h"
#include "dm/group.h"
#include "dm/projexpl.h"
#include "dm/sounds.h"
namespace DM {
void MenuMan::initConstants() {
static unsigned char actionSkillIndex[44] = { // @ G0496_auc_Graphic560_ActionSkillIndex
0, /* N */
7, /* BLOCK */
6, /* CHOP */
0, /* X */
14, /* BLOW HORN */
12, /* FLIP */
9, /* PUNCH */
9, /* KICK */
7, /* WAR CRY Atari ST Versions 1.0 1987-12-08 1987-12-11 1.1: 14 */
9, /* STAB */
8, /* CLIMB DOWN */
14, /* FREEZE LIFE */
9, /* HIT */
4, /* SWING */
5, /* STAB */
5, /* THRUST */
5, /* JAB */
7, /* PARRY */
4, /* HACK */
4, /* BERZERK */
16, /* FIREBALL */
17, /* DISPELL */
14, /* CONFUSE */
17, /* LIGHTNING */
17, /* DISRUPT */
6, /* MELEE */
8, /* X */
3, /* INVOKE */
4, /* SLASH */
4, /* CLEAVE */
6, /* BASH */
6, /* STUN */
11, /* SHOOT */
15, /* SPELLSHIELD */
15, /* FIRESHIELD */
3, /* FLUXCAGE */
13, /* HEAL */
14, /* CALM */
17, /* LIGHT */
18, /* WINDOW */
16, /* SPIT */
14, /* BRANDISH */
10, /* THROW */
3 /* FUSE */
};
static unsigned char actionDisabledTicks[44] = {
0, /* N */
6, /* BLOCK */
8, /* CHOP */
0, /* X */
6, /* BLOW HORN */
3, /* FLIP */
1, /* PUNCH */
5, /* KICK */
3, /* WAR CRY */
5, /* STAB */
35, /* CLIMB DOWN */
20, /* FREEZE LIFE */
4, /* HIT */
6, /* SWING */
10, /* STAB */
16, /* THRUST */
2, /* JAB */
18, /* PARRY */
8, /* HACK */
30, /* BERZERK */
42, /* FIREBALL */
31, /* DISPELL */
10, /* CONFUSE */
38, /* LIGHTNING */
9, /* DISRUPT */
20, /* MELEE */
10, /* X */
16, /* INVOKE */
4, /* SLASH */
12, /* CLEAVE */
20, /* BASH */
7, /* STUN */
14, /* SHOOT */
30, /* SPELLSHIELD */
35, /* FIRESHIELD */
2, /* FLUXCAGE */
19, /* HEAL */
9, /* CALM */
10, /* LIGHT */
15, /* WINDOW */
22, /* SPIT */
10, /* BRANDISH */
0, /* THROW */
2 /* FUSE */
};
_boxActionArea1ActionMenu = Box(224, 319, 77, 97); // @ G0501_s_Graphic560_Box_ActionArea1ActionMenu
_boxActionArea2ActionMenu = Box(224, 319, 77, 109); // @ G0500_s_Graphic560_Box_ActionArea2ActionsMenu
_boxActionArea3ActionMenu = Box(224, 319, 77, 121); // @ G0499_s_Graphic560_Box_ActionArea3ActionsMenu
_boxActionArea = Box(224, 319, 77, 121); // @ G0001_s_Graphic562_Box_ActionArea
_boxSpellArea = Box(224, 319, 42, 74);
for (int i = 0; i < 44; i++) {
_actionSkillIndex[i] = actionSkillIndex[i];
_actionDisabledTicks[i] = actionDisabledTicks[i];
}
}
MenuMan::MenuMan(DMEngine *vm) : _vm(vm) {
_refreshActionArea = false;
_actionAreaContainsIcons = false;
_actionDamage = 0;
_actionList.resetToZero();
_bitmapSpellAreaLine = new byte[96 * 12];
_bitmapSpellAreaLines = new byte[3 * 96 * 12];
_actionTargetGroupThing = Thing(0);
_actionCount = 0;
initConstants();
}
MenuMan::~MenuMan() {
delete[] _bitmapSpellAreaLine;
delete[] _bitmapSpellAreaLines;
}
void MenuMan::drawMovementArrows() {
_vm->_eventMan->showMouse();
_vm->_displayMan->blitToScreen(_vm->_displayMan->getNativeBitmapOrGraphic(kDMGraphicIdxMovementArrows),
&_vm->_displayMan->_boxMovementArrows, k48_byteWidth, kDMColorNoTransparency, 45);
_vm->_eventMan->hideMouse();
}
void MenuMan::clearActingChampion() {
ChampionMan &cm = *_vm->_championMan;
if (cm._actingChampionOrdinal) {
cm._actingChampionOrdinal--;
cm._champions[cm._actingChampionOrdinal].setAttributeFlag(kDMAttributeActionHand, true);
cm.drawChampionState((ChampionIndex)cm._actingChampionOrdinal);
cm._actingChampionOrdinal = _vm->indexToOrdinal(kDMChampionNone);
_refreshActionArea = true;
}
}
void MenuMan::drawActionIcon(ChampionIndex championIndex) {
static byte palChangesActionAreaObjectIcon[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0}; // @ G0498_auc_Graphic560_PaletteChanges_ActionAreaObjectIcon
if (!_actionAreaContainsIcons)
return;
DisplayMan &dm = *_vm->_displayMan;
Champion &champion = _vm->_championMan->_champions[championIndex];
Box box;
box._rect.left = championIndex * 22 + 233;
box._rect.right = box._rect.left + 19;
box._rect.top = 86;
box._rect.bottom = 120;
dm._useByteBoxCoordinates = false;
if (!champion._currHealth) {
dm.fillScreenBox(box, kDMColorBlack);
return;
}
byte *bitmapIcon = dm._tmpBitmap;
Thing thing = champion.getSlot(kDMSlotActionHand);
IconIndice iconIndex;
if (thing == Thing::_none) {
iconIndex = kDMIconIndiceActionEmptyHand;
} else if (_vm->_dungeonMan->_objectInfos[_vm->_dungeonMan->getObjectInfoIndex(thing)]._actionSetIndex) {
iconIndex = _vm->_objectMan->getIconIndex(thing);
} else {
dm.fillBitmap(bitmapIcon, kDMColorCyan, 16, 16);
goto T0386006;
}
_vm->_objectMan->extractIconFromBitmap(iconIndex, bitmapIcon);
dm.blitToBitmapShrinkWithPalChange(bitmapIcon, bitmapIcon, 16, 16, 16, 16, palChangesActionAreaObjectIcon);
T0386006:
dm.fillScreenBox(box, kDMColorCyan);
Box box2;
box2._rect.left = box._rect.left + 2;
box2._rect.right = box._rect.right - 2;
box2._rect.top = 95;
box2._rect.bottom = 110;
dm.blitToScreen(bitmapIcon, &box2, k8_byteWidth, kDMColorNoTransparency, 16);
if (champion.getAttributes(kDMAttributeDisableAction) || _vm->_championMan->_candidateChampionOrdinal || _vm->_championMan->_partyIsSleeping) {
_vm->_displayMan->shadeScreenBox(&box, kDMColorBlack);
}
}
void MenuMan::drawDisabledMenu() {
if (!_vm->_championMan->_partyIsSleeping) {
_vm->_eventMan->highlightBoxDisable();
_vm->_displayMan->_useByteBoxCoordinates = false;
if (_vm->_inventoryMan->_inventoryChampionOrdinal) {
if (_vm->_inventoryMan->_panelContent == kDMPanelContentChest) {
_vm->_inventoryMan->closeChest();
}
} else {
_vm->_displayMan->shadeScreenBox(&_vm->_displayMan->_boxMovementArrows, kDMColorBlack);
}
_vm->_displayMan->shadeScreenBox(&_boxSpellArea, kDMColorBlack);
_vm->_displayMan->shadeScreenBox(&_boxActionArea, kDMColorBlack);
_vm->_eventMan->setMousePointerToNormal(k0_pointerArrow);
}
}
void MenuMan::refreshActionAreaAndSetChampDirMaxDamageReceived() {
ChampionMan &champMan = *_vm->_championMan;
if (!champMan._partyChampionCount)
return;
Champion *champ = nullptr;
if (champMan._partyIsSleeping || champMan._candidateChampionOrdinal) {
if (champMan._actingChampionOrdinal) {
clearActingChampion();
return;
}
if (!champMan._candidateChampionOrdinal)
return;
} else {
champ = champMan._champions;
int16 champIndex = kDMChampionFirst;
do {
if ((champIndex != champMan._leaderIndex)
&& (_vm->indexToOrdinal(champIndex) != champMan._actingChampionOrdinal)
&& (champ->_maximumDamageReceived)
&& (champ->_dir != champ->_directionMaximumDamageReceived)) {
champ->_dir = (Direction)champ->_directionMaximumDamageReceived;
champ->setAttributeFlag(kDMAttributeIcon, true);
champMan.drawChampionState((ChampionIndex)champIndex);
}
champ->_maximumDamageReceived = 0;
champ++;
champIndex++;
} while (champIndex < champMan._partyChampionCount);
}
if (_refreshActionArea) {
if (!champMan._actingChampionOrdinal) {
if (_actionDamage) {
drawActionDamage(_actionDamage);
_actionDamage = 0;
} else {
_actionAreaContainsIcons = true;
drawActionArea();
}
} else {
_actionAreaContainsIcons = false;
champ->setAttributeFlag(kDMAttributeActionHand, true);
champMan.drawChampionState((ChampionIndex)_vm->ordinalToIndex(champMan._actingChampionOrdinal));
drawActionArea();
}
}
}
#define k7_ChampionNameMaximumLength 7 // @ C007_CHAMPION_NAME_MAXIMUM_LENGTH
#define k12_ActionNameMaximumLength 12 // @ C012_ACTION_NAME_MAXIMUM_LENGTH
void MenuMan::drawActionArea() {
DisplayMan &dispMan = *_vm->_displayMan;
ChampionMan &champMan = *_vm->_championMan;
TextMan &textMan = *_vm->_textMan;
_vm->_eventMan->hideMouse();
dispMan._useByteBoxCoordinates = false;
dispMan.fillScreenBox(_boxActionArea, kDMColorBlack);
if (_actionAreaContainsIcons) {
for (uint16 champIndex = kDMChampionFirst; champIndex < champMan._partyChampionCount; ++champIndex)
drawActionIcon((ChampionIndex)champIndex);
} else if (champMan._actingChampionOrdinal) {
Box box = _boxActionArea3ActionMenu;
if (_actionList._actionIndices[2] == kDMActionNone)
box = _boxActionArea2ActionMenu;
if (_actionList._actionIndices[1] == kDMActionNone)
box = _boxActionArea1ActionMenu;
dispMan.blitToScreen(_vm->_displayMan->getNativeBitmapOrGraphic(kDMGraphicIdxMenuActionArea),
&box, k48_byteWidth, kDMColorNoTransparency, 45);
textMan.printWithTrailingSpaces(dispMan._bitmapScreen, k160_byteWidthScreen,
235, 83, kDMColorBlack, kDMColorCyan, champMan._champions[_vm->ordinalToIndex(champMan._actingChampionOrdinal)]._name,
k7_ChampionNameMaximumLength, k200_heightScreen);
for (uint16 actionListIndex = 0; actionListIndex < 3; actionListIndex++) {
textMan.printWithTrailingSpaces(dispMan._bitmapScreen, k160_byteWidthScreen, 241, 93 + actionListIndex * 12, kDMColorCyan, kDMColorBlack,
getActionName(_actionList._actionIndices[actionListIndex]),
k12_ActionNameMaximumLength, k200_heightScreen);
}
}
_vm->_eventMan->showMouse();
_refreshActionArea = false;
}
const char *MenuMan::getActionName(ChampionAction actionIndex) {
const char *championActionNames[44] = { // @ G0490_ac_Graphic560_ActionNames
"N", "BLOCK", "CHOP", "X", "BLOW HORN", "FLIP", "PUNCH",
"KICK", "WAR CRY", "STAB", "CLIMB DOWN", "FREEZE LIFE",
"HIT", "SWING", "STAB", "THRUST", "JAB", "PARRY", "HACK",
"BERZERK", "FIREBALL", "DISPELL", "CONFUSE", "LIGHTNING",
"DISRUPT", "MELEE", "X", "INVOKE", "SLASH", "CLEAVE",
"BASH", "STUN", "SHOOT", "SPELLSHIELD", "FIRESHIELD",
"FLUXCAGE", "HEAL", "CALM", "LIGHT", "WINDOW", "SPIT",
"BRANDISH", "THROW", "FUSE"
};
return (actionIndex == kDMActionNone) ? "" : championActionNames[actionIndex];
}
void MenuMan::drawSpellAreaControls(ChampionIndex champIndex) {
static Box boxSpellAreaControls(233, 319, 42, 49); // @ G0504_s_Graphic560_Box_SpellAreaControls
Champion *champ = &_vm->_championMan->_champions[champIndex];
_vm->_displayMan->_useByteBoxCoordinates = false;
int16 champHP0 = _vm->_championMan->_champions[0]._currHealth;
int16 champHP1 = _vm->_championMan->_champions[1]._currHealth;
int16 champHP2 = _vm->_championMan->_champions[2]._currHealth;
int16 champHP3 = _vm->_championMan->_champions[3]._currHealth;
_vm->_eventMan->showMouse();
_vm->_displayMan->fillScreenBox(boxSpellAreaControls, kDMColorBlack);
switch (champIndex) {
case 0:
_vm->_eventMan->highlightScreenBox(233, 277, 42, 49);
_vm->_textMan->printToLogicalScreen(235, 48, kDMColorBlack, kDMColorCyan, champ->_name);
if (_vm->_championMan->_partyChampionCount > 1) {
if (champHP1)
_vm->_eventMan->highlightScreenBox(280, 291, 42, 48);
if (_vm->_championMan->_partyChampionCount > 2) {
if (champHP2)
_vm->_eventMan->highlightScreenBox(294, 305, 42, 48);
if ((_vm->_championMan->_partyChampionCount > 3) && champHP3)
_vm->_eventMan->highlightScreenBox(308, 319, 42, 48);
}
}
break;
case 1:
if (champHP0)
_vm->_eventMan->highlightScreenBox(233, 244, 42, 48);
_vm->_eventMan->highlightScreenBox(247, 291, 42, 49);
_vm->_textMan->printToLogicalScreen(249, 48, kDMColorBlack, kDMColorCyan, champ->_name);
if (_vm->_championMan->_partyChampionCount > 2) {
if (champHP2)
_vm->_eventMan->highlightScreenBox(294, 305, 42, 48);
if ((_vm->_championMan->_partyChampionCount > 3) && champHP3)
_vm->_eventMan->highlightScreenBox(308, 319, 42, 48);
}
break;
case 2:
if (champHP0)
_vm->_eventMan->highlightScreenBox(233, 244, 42, 48);
if (champHP1)
_vm->_eventMan->highlightScreenBox(247, 258, 42, 48);
_vm->_eventMan->highlightScreenBox(261, 305, 42, 49);
_vm->_textMan->printToLogicalScreen(263, 48, kDMColorBlack, kDMColorCyan, champ->_name);
if ((_vm->_championMan->_partyChampionCount > 3) && champHP3)
_vm->_eventMan->highlightScreenBox(308, 319, 42, 48);
break;
case 3:
if (champHP0)
_vm->_eventMan->highlightScreenBox(233, 244, 42, 48);
if (champHP1)
_vm->_eventMan->highlightScreenBox(247, 258, 42, 48);
if (champHP2)
_vm->_eventMan->highlightScreenBox(261, 272, 42, 48);
_vm->_eventMan->highlightScreenBox(275, 319, 42, 49);
_vm->_textMan->printToLogicalScreen(277, 48, kDMColorBlack, kDMColorCyan, champ->_name);
break;
default:
break;
}
_vm->_eventMan->hideMouse();
}
void MenuMan::buildSpellAreaLine(int16 spellAreaBitmapLine) {
static Box boxSpellAreaLine(0, 95, 0, 11); // @ K0074_s_Box_SpellAreaLine
char spellSymbolString[2] = {'\0', '\0'};
Champion *magicChampion = &_vm->_championMan->_champions[_vm->_championMan->_magicCasterChampionIndex];
if (spellAreaBitmapLine == kDMSpellAreaAvailableSymbols) {
_vm->_displayMan->_useByteBoxCoordinates = false;
_vm->_displayMan->blitToBitmap(_bitmapSpellAreaLines, _bitmapSpellAreaLine, boxSpellAreaLine, 0, 12, k48_byteWidth, k48_byteWidth, kDMColorNoTransparency, 36, 12);
int16 x = 1;
char character = 96 + (6 * magicChampion->_symbolStep);
for (uint16 symbolIndex = 0; symbolIndex < 6; symbolIndex++) {
spellSymbolString[0] = character++;
x += 14;
_vm->_textMan->printTextToBitmap(_bitmapSpellAreaLine, 48, x, 8, kDMColorCyan, kDMColorBlack, spellSymbolString, 12);
}
} else if (spellAreaBitmapLine == kDMSpellAreaChampionSymbols) {
_vm->_displayMan->_useByteBoxCoordinates = false;
_vm->_displayMan->blitToBitmap(_bitmapSpellAreaLines, _bitmapSpellAreaLine, boxSpellAreaLine, 0, 24, k48_byteWidth, k48_byteWidth, kDMColorNoTransparency, 36, 12);
int16 x = 8;
for (uint16 symbolIndex = 0; symbolIndex < 4; symbolIndex++) {
if ((spellSymbolString[0] = magicChampion->_symbols[symbolIndex]) == '\0')
break;
x += 9;
_vm->_textMan->printTextToBitmap(_bitmapSpellAreaLine, 48, x, 8, kDMColorCyan, kDMColorBlack, spellSymbolString, 12);
}
}
}
void MenuMan::setMagicCasterAndDrawSpellArea(ChampionIndex champIndex) {
static Box boxSpellAreaLine2(224, 319, 50, 61); // @ K0075_s_Box_SpellAreaLine2
static Box boxSpellAreaLine3(224, 319, 62, 73); // @ K0076_s_Box_SpellAreaLine3
if ((champIndex == _vm->_championMan->_magicCasterChampionIndex)
|| ((champIndex != kDMChampionNone) && !_vm->_championMan->_champions[champIndex]._currHealth))
return;
if (_vm->_championMan->_magicCasterChampionIndex == kDMChampionNone) {
_vm->_eventMan->showMouse();
_vm->_displayMan->blitToScreen(_vm->_displayMan->getNativeBitmapOrGraphic(kDMGraphicIdxMenuSpellAreaBackground), &_boxSpellArea, k48_byteWidth, kDMColorNoTransparency, 33);
_vm->_eventMan->hideMouse();
}
if (champIndex == kDMChampionNone) {
_vm->_championMan->_magicCasterChampionIndex = kDMChampionNone;
_vm->_eventMan->showMouse();
_vm->_displayMan->_useByteBoxCoordinates = false;
_vm->_displayMan->fillScreenBox(_boxSpellArea, kDMColorBlack);
_vm->_eventMan->hideMouse();
return;
}
_vm->_championMan->_magicCasterChampionIndex = champIndex;
buildSpellAreaLine(kDMSpellAreaAvailableSymbols);
_vm->_eventMan->showMouse();
drawSpellAreaControls(champIndex);
_vm->_displayMan->blitToScreen(_bitmapSpellAreaLine, &boxSpellAreaLine2, k48_byteWidth, kDMColorNoTransparency, 12);
buildSpellAreaLine(kDMSpellAreaChampionSymbols);
_vm->_displayMan->blitToScreen(_bitmapSpellAreaLine, &boxSpellAreaLine3, k48_byteWidth, kDMColorNoTransparency, 12);
_vm->_eventMan->hideMouse();
}
void MenuMan::drawEnabledMenus() {
if (_vm->_championMan->_partyIsSleeping) {
_vm->_eventMan->drawSleepScreen();
_vm->_displayMan->drawViewport(k0_viewportNotDungeonView);
} else {
ChampionIndex casterChampionIndex = _vm->_championMan->_magicCasterChampionIndex;
_vm->_championMan->_magicCasterChampionIndex = kDMChampionNone; /* Force next function to draw the spell area */
setMagicCasterAndDrawSpellArea(casterChampionIndex);
if (!_vm->_championMan->_actingChampionOrdinal)
_actionAreaContainsIcons = true;
drawActionArea();
int16 AL1462_i_InventoryChampionOrdinal = _vm->_inventoryMan->_inventoryChampionOrdinal;
if (AL1462_i_InventoryChampionOrdinal) {
_vm->_inventoryMan->_inventoryChampionOrdinal = _vm->indexToOrdinal(kDMChampionNone);
_vm->_inventoryMan->toggleInventory((ChampionIndex)_vm->ordinalToIndex(AL1462_i_InventoryChampionOrdinal));
} else {
_vm->_displayMan->drawFloorAndCeiling();
drawMovementArrows();
}
_vm->_eventMan->setMousePointer();
}
}
int16 MenuMan::getClickOnSpellCastResult() {
Champion *casterChampion = &_vm->_championMan->_champions[_vm->_championMan->_magicCasterChampionIndex];
_vm->_eventMan->showMouse();
_vm->_eventMan->highlightBoxDisable();
int16 spellCastResult = getChampionSpellCastResult(_vm->_championMan->_magicCasterChampionIndex);
if (spellCastResult != kDMSpellCastFailureNeedsFlask) {
casterChampion->_symbols[0] = '\0';
drawAvailableSymbols(casterChampion->_symbolStep = 0);
drawChampionSymbols(casterChampion);
} else
spellCastResult = kDMSpellCastFailure;
_vm->_eventMan->hideMouse();
return spellCastResult;
}
int16 MenuMan::getChampionSpellCastResult(uint16 champIndex) {
if (champIndex >= _vm->_championMan->_partyChampionCount)
return kDMSpellCastFailure;
Champion *curChampion = &_vm->_championMan->_champions[champIndex];
if (!curChampion->_currHealth)
return kDMSpellCastFailure;
Spell *curSpell = getSpellFromSymbols((unsigned char *)curChampion->_symbols);
if (!curSpell) {
menusPrintSpellFailureMessage(curChampion, kDMSpellCastSuccess, 0);
return kDMSpellCastFailure;
}
int16 powerSymbolOrdinal = curChampion->_symbols[0] - '_'; /* Values 1 to 6 */
uint16 requiredSkillLevel = curSpell->_baseRequiredSkillLevel + powerSymbolOrdinal;
uint16 experience = _vm->getRandomNumber(8) + (requiredSkillLevel << 4) + ((_vm->ordinalToIndex(powerSymbolOrdinal) * curSpell->_baseRequiredSkillLevel) << 3) + (requiredSkillLevel * requiredSkillLevel);
uint16 skillLevel = _vm->_championMan->getSkillLevel(champIndex, curSpell->_skillIndex);
if (skillLevel < requiredSkillLevel) {
int16 missingSkillLevelCount = requiredSkillLevel - skillLevel;
while (missingSkillLevelCount--) {
if (_vm->getRandomNumber(128) > MIN(curChampion->_statistics[kDMStatWisdom][kDMStatCurrent] + 15, 115)) {
_vm->_championMan->addSkillExperience(champIndex, curSpell->_skillIndex, experience >> (requiredSkillLevel - skillLevel));
menusPrintSpellFailureMessage(curChampion, kDMFailureNeedsMorePractice, curSpell->_skillIndex);
return kDMSpellCastFailure;
}
}
}
switch (curSpell->getKind()) {
case kDMSpellKindPotion: {
Thing newObject;
Potion *newPotion = getEmptyFlaskInHand(curChampion, &newObject);
if (!newPotion) {
menusPrintSpellFailureMessage(curChampion, kDMFailureNeedsFlaskInHand, 0);
return kDMSpellCastFailureNeedsFlask;
}
uint16 emptyFlaskWeight = _vm->_dungeonMan->getObjectWeight(newObject);
newPotion->setType((PotionType)curSpell->getType());
newPotion->setPower(_vm->getRandomNumber(16) + (powerSymbolOrdinal * 40));
curChampion->_load += _vm->_dungeonMan->getObjectWeight(newObject) - emptyFlaskWeight;
_vm->_championMan->drawChangedObjectIcons();
if (_vm->_inventoryMan->_inventoryChampionOrdinal == _vm->indexToOrdinal(champIndex)) {
setFlag(curChampion->_attributes, kDMAttributeLoad);
_vm->_championMan->drawChampionState((ChampionIndex)champIndex);
}
}
break;
case kDMSpellKindProjectile:
if (curChampion->_dir != _vm->_dungeonMan->_partyDir) {
curChampion->_dir = _vm->_dungeonMan->_partyDir;
setFlag(curChampion->_attributes, kDMAttributeIcon);
_vm->_championMan->drawChampionState((ChampionIndex)champIndex);
}
if (curSpell->getType() == kDMSpellTypeProjectileOpenDoor)
skillLevel <<= 1;
_vm->_championMan->isProjectileSpellCast(champIndex, Thing(curSpell->getType() + Thing::_firstExplosion.toUint16()), CLIP(21, (powerSymbolOrdinal + 2) * (4 + (skillLevel << 1)), 255), 0);
break;
case kDMSpellKindOther: {
TimelineEvent newEvent;
newEvent._priority = 0;
uint16 spellPower = (powerSymbolOrdinal + 1) << 2;
uint16 ticks;
switch (curSpell->getType()) {
case kDMSpellTypeOtherLight: {
ticks = 10000 + ((spellPower - 8) << 9);
uint16 lightPower = (spellPower >> 1);
lightPower--;
_vm->_championMan->_party._magicalLightAmount += _vm->_championMan->_lightPowerToLightAmount[lightPower];
createEvent70_light(-lightPower, ticks);
}
break;
case kDMSpellTypeOtherMagicTorch: {
ticks = 2000 + ((spellPower - 3) << 7);
uint16 lightPower = (spellPower >> 2);
lightPower++;
_vm->_championMan->_party._magicalLightAmount += _vm->_championMan->_lightPowerToLightAmount[lightPower];
createEvent70_light(-lightPower, ticks);
}
break;
case kDMSpellTypeOtherDarkness: {
uint16 lightPower = (spellPower >> 2);
_vm->_championMan->_party._magicalLightAmount -= _vm->_championMan->_lightPowerToLightAmount[lightPower];
createEvent70_light(lightPower, 98);
}
break;
case kDMSpellTypeOtherThievesEye: {
newEvent._type = kDMEventTypeThievesEye;
_vm->_championMan->_party._event73Count_ThievesEye++;
spellPower = (spellPower >> 1);
uint16 spellTicks = spellPower * spellPower;
newEvent._mapTime = _vm->setMapAndTime(_vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
}
break;
case kDMSpellTypeOtherInvisibility: {
newEvent._type = kDMEventTypeInvisibility;
_vm->_championMan->_party._event71Count_Invisibility++;
uint16 spellTicks = spellPower;
newEvent._mapTime = _vm->setMapAndTime(_vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
}
break;
case kDMSpellTypeOtherPartyShield: {
newEvent._type = kDMEventTypePartyShield;
newEvent._Bu._defense = spellPower;
if (_vm->_championMan->_party._shieldDefense > 50)
newEvent._Bu._defense >>= 2;
_vm->_championMan->_party._shieldDefense += newEvent._Bu._defense;
_vm->_timeline->refreshAllChampionStatusBoxes();
uint16 spellTicks = spellPower * spellPower;
newEvent._mapTime = _vm->setMapAndTime(_vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
}
break;
case kDMSpellTypeOtherFootprints: {
newEvent._type = kDMEventTypeFootprints;
_vm->_championMan->_party._event79Count_Footprints++;
_vm->_championMan->_party._firstScentIndex = _vm->_championMan->_party._scentCount;
if (powerSymbolOrdinal < 3)
_vm->_championMan->_party._lastScentIndex = _vm->_championMan->_party._firstScentIndex;
else
_vm->_championMan->_party._lastScentIndex = 0;
uint16 spellTicks = spellPower * spellPower;
newEvent._mapTime = _vm->setMapAndTime(_vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
}
break;
case kDMSpellTypeOtherZokathra: {
Thing unusedObject = _vm->_dungeonMan->getUnusedThing(kDMThingTypeJunk);
if (unusedObject == Thing::_none)
break;
Junk *junkData = (Junk *)_vm->_dungeonMan->getThingData(unusedObject);
junkData->setType(kDMJunkTypeZokathra);
ChampionSlot slotIndex;
if (curChampion->_slots[kDMSlotReadyHand] == Thing::_none)
slotIndex = kDMSlotReadyHand;
else if (curChampion->_slots[kDMSlotActionHand] == Thing::_none)
slotIndex = kDMSlotActionHand;
else
slotIndex = kDMSlotLeaderHand;
if ((slotIndex == kDMSlotReadyHand) || (slotIndex == kDMSlotActionHand)) {
_vm->_championMan->addObjectInSlot((ChampionIndex)champIndex, unusedObject, slotIndex);
_vm->_championMan->drawChampionState((ChampionIndex)champIndex);
} else
_vm->_moveSens->getMoveResult(unusedObject, kDMMapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
}
break;
case kDMSpellTypeOtherFireshield:
isPartySpellOrFireShieldSuccessful(curChampion, false, (spellPower * spellPower) + 100, false);
break;
default:
break;
}
}
}
_vm->_championMan->addSkillExperience(champIndex, curSpell->_skillIndex, experience);
_vm->_championMan->disableAction(champIndex, curSpell->getDuration());
return kDMSpellCastSuccess;
}
Spell *MenuMan::getSpellFromSymbols(byte *symbols) {
static Spell SpellsArray[25] = {
/* { Symbols, BaseRequiredSkillLevel, SkillIndex, Attributes } */
Spell(0x00666F00, 2, 15, 0x7843),
Spell(0x00667073, 1, 18, 0x4863),
Spell(0x00686D77, 3, 17, 0xB433),
Spell(0x00686C00, 3, 19, 0x6C72),
Spell(0x00686D76, 3, 18, 0x8423),
Spell(0x00686E76, 4, 17, 0x7822),
Spell(0x00686F76, 4, 17, 0x5803),
Spell(0x00690000, 1, 16, 0x3C53),
Spell(0x00696F00, 3, 16, 0xA802),
Spell(0x00697072, 4, 13, 0x3C71),
Spell(0x00697075, 4, 15, 0x7083),
Spell(0x006A6D00, 1, 18, 0x5032),
Spell(0x006A6C00, 1, 19, 0x4062),
Spell(0x006A6F77, 1, 15, 0x3013),
Spell(0x006B0000, 1, 17, 0x3C42),
Spell(0x00667000, 2, 15, 0x64C1),
Spell(0x00660000, 2, 13, 0x3CB1),
Spell(0x00667074, 4, 13, 0x3C81),
Spell(0x00667075, 4, 13, 0x3C91),
Spell(0x00670000, 1, 13, 0x80E1),
Spell(0x00677000, 1, 13, 0x68A1),
Spell(0x00687073, 4, 13, 0x3C61),
Spell(0x006B7076, 3, 2, 0xFCD1),
Spell(0x006B6C00, 2, 19, 0x7831),
Spell(0x006B6E76, 0, 3, 0x3C73)
};
if (*(symbols + 1)) {
int16 bitShiftCount = 24;
int32 curSymbols = 0;
do
curSymbols |= (long)*symbols++ << bitShiftCount;
while (*symbols && ((bitShiftCount -= 8) >= 0));
Spell *curSpell = SpellsArray;
int16 spellIndex = 25;
while (spellIndex--) {
if (curSpell->_symbols & 0xFF000000) { /* If byte 1 of spell is not 0 then the spell includes the power symbol */
if (curSymbols == curSpell->_symbols) { /* Compare champion symbols, including power symbol, with spell (never used with actual spells) */
return curSpell;
}
} else if ((curSymbols & 0x00FFFFFF) == curSpell->_symbols) /* Compare champion symbols, except power symbol, with spell */
return curSpell;
curSpell++;
}
}
return nullptr;
}
void MenuMan::menusPrintSpellFailureMessage(Champion *champ, uint16 failureType, uint16 skillIndex) {
Common::String messagesEN[4] = {
" NEEDS MORE PRACTICE WITH THIS ",
" SPELL.",
" MUMBLES A MEANINGLESS SPELL.",
" NEEDS AN EMPTY FLASK IN HAND FOR POTION."
};
Common::String messagesDE[4] = {
" BRAUCHT MEHR UEBUNG MIT DIESEM ",
" ZAUBERSPRUCH.",
" MURMELT EINEN SINNLOSEN ZAUBERSPRUCH.",
" MUSS FUER DEN TRANK EINE LEERE FLASCHE BEREITHALTEN."
};
Common::String messagesFR[5] = {
" DOIT PRATIQUER DAVANTAGE SON ",
"ENVOUTEMENT.",
" MARMONNE UNE CONJURATION IMCOMPREHENSIBLE.",
" DOIT AVOIR UN FLACON VIDE EN MAIN POUR LA POTION.",
"EXORCISME."
};
if (skillIndex > kDMSkillWizard)
skillIndex = (skillIndex - 4) / 4;
_vm->_textMan->printLineFeed();
_vm->_textMan->printMessage(kDMColorCyan, champ->_name);
Common::String *messages;
switch (_vm->getGameLanguage()) { // localized
case Common::DE_DEU:
messages = messagesDE;
break;
case Common::FR_FRA:
messages = messagesFR;
break;
default:
messages = messagesEN;
break;
}
Common::String message;
switch (failureType) {
case kDMFailureNeedsMorePractice:
_vm->_textMan->printMessage(kDMColorCyan, messages[0].c_str());
_vm->_textMan->printMessage(kDMColorCyan, _vm->_championMan->_baseSkillName[skillIndex]);
if (_vm->getGameLanguage() != Common::FR_FRA || skillIndex == kDMSkillWizard)
message = messages[1];
else
message = messages[4];
break;
case kDMFailureMeaninglessSpell:
message = messages[2];
break;
case kDMFailureNeedsFlaskInHand:
message = messages[3];
break;
default:
break;
}
_vm->_textMan->printMessage(kDMColorCyan, message.c_str());
}
Potion *MenuMan::getEmptyFlaskInHand(Champion *champ, Thing *potionThing) {
for (int16 slotIndex = kDMSlotHead; --slotIndex >= kDMSlotReadyHand; ) {
Thing curThing = champ->_slots[slotIndex];
if ((curThing != Thing::_none) && (_vm->_objectMan->getIconIndex(curThing) == kDMIconIndicePotionEmptyFlask)) {
*potionThing = curThing;
return (Potion *)_vm->_dungeonMan->getThingData(curThing);
}
}
return nullptr;
}
void MenuMan::createEvent70_light(int16 lightPower, int16 ticks) {
TimelineEvent newEvent;
newEvent._type = kDMEventTypeLight;
newEvent._Bu._lightPower = lightPower;
newEvent._mapTime = _vm->setMapAndTime(_vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + ticks);
newEvent._priority = 0;
_vm->_timeline->addEventGetEventIndex(&newEvent);
_vm->_inventoryMan->setDungeonViewPalette();
}
bool MenuMan::isPartySpellOrFireShieldSuccessful(Champion *champ, bool spellShield, uint16 ticks, bool useMana) {
bool isPartyMagicShieldSuccessful = true;
if (useMana) {
if (champ->_currMana == 0)
return false;
if (champ->_currMana < 4) {
ticks >>= 1;
champ->_currMana = 0;
isPartyMagicShieldSuccessful = false;
} else
champ->_currMana -= 4;
}
TimelineEvent newEvent;
newEvent._Bu._defense = ticks >> 5;
if (spellShield) {
newEvent._type = kDMEventTypeSpellShield;
if (_vm->_championMan->_party._spellShieldDefense > 50)
newEvent._Bu._defense >>= 2;
_vm->_championMan->_party._spellShieldDefense += newEvent._Bu._defense;
} else {
newEvent._type = kDMEventTypeFireShield;
if (_vm->_championMan->_party._fireShieldDefense > 50)
newEvent._Bu._defense >>= 2;
_vm->_championMan->_party._fireShieldDefense += newEvent._Bu._defense;
}
newEvent._priority = 0;
newEvent._mapTime = _vm->setMapAndTime(_vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + ticks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
_vm->_timeline->refreshAllChampionStatusBoxes();
return isPartyMagicShieldSuccessful;
}
void MenuMan::drawAvailableSymbols(uint16 symbolStep) {
char displayBuffer[2];
displayBuffer[1] = '\0';
char curCharacter = 96 + 6 * symbolStep;
int16 textPosX = 225;
for (uint16 L1214_ui_Counter = 0; L1214_ui_Counter < 6; L1214_ui_Counter++) {
displayBuffer[0] = curCharacter++;
textPosX += 14;
_vm->_textMan->printToLogicalScreen(textPosX, 58, kDMColorCyan, kDMColorBlack, displayBuffer);
}
}
void MenuMan::drawChampionSymbols(Champion *champ) {
uint16 symbolCount = strlen(champ->_symbols);
int16 textPosX = 232;
char displayBuffer[2];
displayBuffer[1] = '\0';
for (uint16 symbolIndex = 0; symbolIndex < 4; symbolIndex++) {
if (symbolIndex >= symbolCount)
displayBuffer[0] = ' ';
else
displayBuffer[0] = champ->_symbols[symbolIndex];
textPosX += 9;
_vm->_textMan->printToLogicalScreen(textPosX, 70, kDMColorCyan, kDMColorBlack, displayBuffer);
}
}
void MenuMan::addChampionSymbol(int16 symbolIndex) {
static byte symbolBaseManaCost[4][6] = {
{1, 2, 3, 4, 5, 6}, /* Power 1 */
{2, 3, 4, 5, 6, 7}, /* Power 2 */
{4, 5, 6, 7, 7, 9}, /* Power 3 */
{2, 2, 3, 4, 6, 7} /* Power 4 */
};
static byte symbolManaCostMultiplier[6] = {8, 12, 16, 20, 24, 28};
Champion *casterChampion = &_vm->_championMan->_champions[_vm->_championMan->_magicCasterChampionIndex];
uint16 symbolStep = casterChampion->_symbolStep;
uint16 manaCost = symbolBaseManaCost[symbolStep][symbolIndex];
if (symbolStep) {
uint16 symbolIndex1 = casterChampion->_symbols[0] - 96;
manaCost = (manaCost * symbolManaCostMultiplier[symbolIndex1]) >> 3;
}
if (manaCost <= casterChampion->_currMana) {
casterChampion->_currMana -= manaCost;
setFlag(casterChampion->_attributes, kDMAttributeStatistics);
casterChampion->_symbols[symbolStep] = 96 + (symbolStep * 6) + symbolIndex;
casterChampion->_symbols[symbolStep + 1] = '\0';
casterChampion->_symbolStep = symbolStep = _vm->turnDirRight(symbolStep);
_vm->_eventMan->showMouse();
drawAvailableSymbols(symbolStep);
drawChampionSymbols(casterChampion);
_vm->_championMan->drawChampionState(_vm->_championMan->_magicCasterChampionIndex);
_vm->_eventMan->hideMouse();
}
}
void MenuMan::deleteChampionSymbol() {
Champion *casterChampion = &_vm->_championMan->_champions[_vm->_championMan->_magicCasterChampionIndex];
if (!strlen(casterChampion->_symbols))
return;
int16 symbolStep = _vm->turnDirLeft(casterChampion->_symbolStep);
casterChampion->_symbolStep = symbolStep;
casterChampion->_symbols[symbolStep] = '\0';
_vm->_eventMan->showMouse();
drawAvailableSymbols(symbolStep);
drawChampionSymbols(casterChampion);
_vm->_eventMan->hideMouse();
}
bool MenuMan::didClickTriggerAction(int16 actionListIndex) {
bool retVal = false;
if (!_vm->_championMan->_actingChampionOrdinal || (actionListIndex != -1 && (_actionList._actionIndices[actionListIndex] == kDMActionNone)))
return retVal;
uint16 championIndex = _vm->ordinalToIndex(_vm->_championMan->_actingChampionOrdinal);
Champion *curChampion = &_vm->_championMan->_champions[championIndex];
if (actionListIndex == -1)
retVal = true;
else {
uint16 actionIndex = _actionList._actionIndices[actionListIndex];
// Fix original bug - When disabled ticks is equal to zero, increasing the defense leads
// to a permanent increment.
if (_actionDisabledTicks[actionIndex])
curChampion->_actionDefense += _vm->_timeline->_actionDefense[actionIndex];
setFlag(curChampion->_attributes, kDMAttributeStatistics);
retVal = isActionPerformed(championIndex, actionIndex);
curChampion->_actionIndex = (ChampionAction)actionIndex;
}
clearActingChampion();
return retVal;
}
bool MenuMan::isActionPerformed(uint16 champIndex, int16 actionIndex) {
static unsigned char actionStaminaArray[44] = {
0, /* N */
4, /* BLOCK */
10, /* CHOP */
0, /* X */
1, /* BLOW HORN */
0, /* FLIP */
1, /* PUNCH */
3, /* KICK */
1, /* WAR CRY */
3, /* STAB */
40, /* CLIMB DOWN */
3, /* FREEZE LIFE */
3, /* HIT */
2, /* SWING */
4, /* STAB */
17, /* THRUST */
3, /* JAB */
1, /* PARRY */
6, /* HACK */
40, /* BERZERK */
5, /* FIREBALL */
2, /* DISPELL */
2, /* CONFUSE */
4, /* LIGHTNING */
5, /* DISRUPT */
25, /* MELEE */
1, /* X */
2, /* INVOKE */
2, /* SLASH */
10, /* CLEAVE */
9, /* BASH */
2, /* STUN */
3, /* SHOOT */
1, /* SPELLSHIELD */
2, /* FIRESHIELD */
6, /* FLUXCAGE */
1, /* HEAL */
1, /* CALM */
3, /* LIGHT */
2, /* WINDOW */
3, /* SPIT */
2, /* BRANDISH */
0, /* THROW */
2 /* FUSE */
};
static unsigned char actionExperienceGainArray[44] = {
0, /* N */
8, /* BLOCK */
10, /* CHOP */
0, /* X */
0, /* BLOW HORN */
0, /* FLIP */
8, /* PUNCH */
13, /* KICK */
7, /* WAR CRY */
15, /* STAB */
15, /* CLIMB DOWN */
22, /* FREEZE LIFE */
10, /* HIT */
6, /* SWING */
12, /* STAB */
19, /* THRUST */
11, /* JAB */
17, /* PARRY */
9, /* HACK */
40, /* BERZERK */
35, /* FIREBALL */
25, /* DISPELL */
0, /* CONFUSE */
30, /* LIGHTNING */
10, /* DISRUPT */
24, /* MELEE */
0, /* X */
25, /* INVOKE */
9, /* SLASH */
12, /* CLEAVE */
11, /* BASH */
10, /* STUN */
20, /* SHOOT Atari ST Versions 1.0 1987-12-08 1987-12-11: 9 */
20, /* SPELLSHIELD */
20, /* FIRESHIELD */
12, /* FLUXCAGE */
0, /* HEAL */
0, /* CALM */
20, /* LIGHT */
30, /* WINDOW */
25, /* SPIT */
0, /* BRANDISH */
5, /* THROW */
1 /* FUSE */
};
if (champIndex >= _vm->_championMan->_partyChampionCount)
return false;
Champion *curChampion = &_vm->_championMan->_champions[champIndex];
if (!curChampion->_currHealth)
return false;
Weapon *weaponInHand = (Weapon *)_vm->_dungeonMan->getThingData(curChampion->_slots[kDMSlotActionHand]);
int16 nextMapX = _vm->_dungeonMan->_partyMapX;
int16 nextMapY = _vm->_dungeonMan->_partyMapY;
nextMapX += _vm->_dirIntoStepCountEast[curChampion->_dir];
nextMapY += _vm->_dirIntoStepCountNorth[curChampion->_dir];
_actionTargetGroupThing = _vm->_groupMan->groupGetThing(nextMapX, nextMapY);
uint16 actionDisabledTicks = _actionDisabledTicks[actionIndex];
int16 actionSkillIndex = _actionSkillIndex[actionIndex];
int16 actionStamina = actionStaminaArray[actionIndex] + _vm->getRandomNumber(2);
int16 actionExperienceGain = actionExperienceGainArray[actionIndex];
uint16 targetSquare = _vm->_dungeonMan->getSquare(nextMapX, nextMapY).toByte();
int16 requiredManaAmount = 0;
if (((actionSkillIndex >= kDMSkillFire) && (actionSkillIndex <= kDMSkillWater)) || (actionSkillIndex == kDMSkillWizard))
requiredManaAmount = 7 - MIN<uint16>(6, _vm->_championMan->getSkillLevel(champIndex, actionSkillIndex));
bool setDirectionFl = false;
int16 kineticEnergy = 0;
Thing explosionThing = Thing::_none;
bool actionPerformed = true;
switch (actionIndex) {
case kDMActionLightning:
kineticEnergy = 180;
explosionThing = Thing::_explLightningBolt;
setDirectionFl = true;
break;
case kDMActionDispel:
kineticEnergy = 150;
explosionThing = Thing::_explHarmNonMaterial;
setDirectionFl = true;
break;
case kDMActionFireball:
kineticEnergy = 150;
explosionThing = Thing::_explFireBall;
setDirectionFl = true;
break;
case kDMActionSpit:
kineticEnergy = 250;
explosionThing = Thing::_explFireBall;
setDirectionFl = true;
break;
case kDMActionBash:
case kDMActionHack:
case kDMActionBerzerk:
case kDMActionKick:
case kDMActionSwing:
case kDMActionChop:
if ((Square(targetSquare).getType() == kDMElementTypeDoor) && (Square(targetSquare).getDoorState() == kDMDoorStateClosed)) {
_vm->_sound->requestPlay(kDMSoundIndexAttackSkelettonAnimatedArmorDethKnight, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, kDMSoundModePlayIfPrioritized);
actionDisabledTicks = 6;
_vm->_groupMan->groupIsDoorDestoryedByAttack(nextMapX, nextMapY, _vm->_championMan->getStrength(champIndex, kDMSlotActionHand), false, 2);
_vm->_sound->requestPlay(kDMSoundIndexWoodenThudAttackTrolinAntmanStoneGolem, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, kDMSoundModePlayOneTickLater);
break;
}
case kDMActionDisrupt:
case kDMActionJab:
case kDMActionParry:
case kDMActionStab14:
case kDMActionStab9:
case kDMActionStun:
case kDMActionThrust:
case kDMActionMelee:
case kDMActionSlash:
case kDMActionCleave:
case kDMActionPunch:
if (!(actionPerformed = isMeleeActionPerformed(champIndex, curChampion, actionIndex, nextMapX, nextMapY, actionSkillIndex))) {
actionExperienceGain >>= 1;
actionDisabledTicks >>= 1;
}
break;
case kDMActionConfuse:
decrementCharges(curChampion);
// No break on purpose
case kDMActionWarCry:
case kDMActionCalm:
case kDMActionBrandish:
case kDMActionBlowHorn:
if (actionIndex == kDMActionWarCry)
_vm->_sound->requestPlay(kDMSoundIndexWarCry, nextMapX, nextMapY, kDMSoundModePlayImmediately);
else if (actionIndex == kDMActionBlowHorn)
_vm->_sound->requestPlay(kDMSoundIndexBlowHorn, nextMapX, nextMapY, kDMSoundModePlayImmediately);
actionPerformed = isGroupFrightenedByAction(champIndex, actionIndex, nextMapX, nextMapY);
break;
case kDMActionShoot: {
if (Thing(curChampion->_slots[kDMSlotReadyHand]).getType() != kDMThingTypeWeapon) {
_actionDamage = kDMDamageNoAmmunition;
actionExperienceGain = 0;
actionPerformed = false;
break;
}
WeaponInfo *weaponInfoActionHand = &_vm->_dungeonMan->_weaponInfos[weaponInHand->getType()];
WeaponInfo *weaponInfoReadyHand = _vm->_dungeonMan->getWeaponInfo(curChampion->_slots[kDMSlotReadyHand]);
int16 actionHandWeaponClass = weaponInfoActionHand->_class;
int16 readyHandWeaponClass = weaponInfoReadyHand->_class;
int16 stepEnergy = actionHandWeaponClass;
if ((actionHandWeaponClass >= kDMWeaponClassFirstBow) && (actionHandWeaponClass <= kDMWeaponClassLastBow)) {
if (readyHandWeaponClass != kDMWeaponClassBowAmmunition) {
_actionDamage = kDMDamageNoAmmunition;
actionExperienceGain = 0;
actionPerformed = false;
break;
}
stepEnergy -= kDMWeaponClassFirstBow;
} else if ((actionHandWeaponClass >= kDMWeaponClassFirstSling) && (actionHandWeaponClass <= kDMWeaponClassLastSling)) {
if (readyHandWeaponClass != kDMWeaponClassSlingAmmunition) {
_actionDamage = kDMDamageNoAmmunition;
actionExperienceGain = 0;
actionPerformed = false;
break;
}
stepEnergy -= kDMWeaponClassFirstSling;
}
setChampionDirectionToPartyDirection(curChampion);
Thing removedObject = _vm->_championMan->getObjectRemovedFromSlot(champIndex, kDMSlotReadyHand);
_vm->_sound->requestPlay(kDMSoundIndexAttackSkelettonAnimatedArmorDethKnight, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, kDMSoundModePlayIfPrioritized);
_vm->_championMan->championShootProjectile(curChampion, removedObject, weaponInfoActionHand->_kineticEnergy + weaponInfoReadyHand->_kineticEnergy, (weaponInfoActionHand->getShootAttack() + _vm->_championMan->getSkillLevel(champIndex, kDMSkillShoot)) << 1, stepEnergy);
}
break;
case kDMActionFlip: {
const char *messagesEN[2] = {"IT COMES UP HEADS.", "IT COMES UP TAILS."};
const char *messagesDE[2] = {"DIE KOPFSEITE IST OBEN.", "DIE ZAHL IST OBEN."};
const char *messagesFR[2] = {"C'EST FACE.", "C'EST PILE."};
const char **message;
switch (_vm->getGameLanguage()) { // localized
default:
case Common::EN_ANY:
message = messagesEN;
break;
case Common::DE_DEU:
message = messagesDE;
break;
case Common::FR_FRA:
message = messagesFR;
break;
}
if (_vm->getRandomNumber(2))
printMessageAfterReplacements(message[0]);
else
printMessageAfterReplacements(message[1]);
}
break;
case kDMActionSpellshield:
case kDMActionFireshield:
if (!isPartySpellOrFireShieldSuccessful(curChampion, actionIndex == kDMActionSpellshield, 280, true)) {
actionExperienceGain >>= 2;
actionDisabledTicks >>= 1;
} else
decrementCharges(curChampion);
break;
case kDMActionInvoke:
kineticEnergy = _vm->getRandomNumber(128) + 100;
switch (_vm->getRandomNumber(6)) {
case 0:
explosionThing = Thing::_explPoisonBolt;
break;
case 1:
explosionThing = Thing::_explPoisonCloud;
break;
case 2:
explosionThing = Thing::_explHarmNonMaterial;
break;
default:
explosionThing = Thing::_explFireBall;
break;
}
setDirectionFl = true;
break;
case kDMActionFluxcage:
setChampionDirectionToPartyDirection(curChampion);
_vm->_groupMan->fluxCageAction(nextMapX, nextMapY);
break;
case kDMActionFuse:
setChampionDirectionToPartyDirection(curChampion);
nextMapX = _vm->_dungeonMan->_partyMapX;
nextMapY = _vm->_dungeonMan->_partyMapY;
nextMapX += _vm->_dirIntoStepCountEast[_vm->_dungeonMan->_partyDir], nextMapY += _vm->_dirIntoStepCountNorth[_vm->_dungeonMan->_partyDir];
_vm->_groupMan->fuseAction(nextMapX, nextMapY);
break;
case kDMActionHeal: {
/* CHANGE2_17_IMPROVEMENT Heal action is much more effective
Heal cycles occur as long as the champion has missing health and enough mana. Cycle count = Min(Current Mana / 2, Missing health / Min(10, Heal skill level))
Healing amount is Min(Missing health, Min(10, Heal skill level)) * heal cycle count
Mana cost is 2 * heal cycle count
Experience gain is 2 + 2 * heal cycle count */
int16 missingHealth = curChampion->_maxHealth - curChampion->_currHealth;
if ((missingHealth > 0) && curChampion->_currMana) {
int16 healingCapability = MIN((uint16)10, _vm->_championMan->getSkillLevel(champIndex, kDMSkillHeal));
actionExperienceGain = 2;
uint16 healingAmount;
do {
healingAmount = MIN(missingHealth, healingCapability);
curChampion->_currHealth += healingAmount;
actionExperienceGain += 2;
curChampion->_currMana = curChampion->_currMana - 2;
if (curChampion->_currMana > 0)
missingHealth -= healingAmount;
} while ((curChampion->_currMana > 0) && missingHealth);
if (curChampion->_currMana < 0)
curChampion->_currMana = 0;
setFlag(curChampion->_attributes, kDMAttributeStatistics);
actionPerformed = true;
}
}
break;
case kDMActionWindow: {
int16 windowTicks = _vm->getRandomNumber(_vm->_championMan->getSkillLevel(champIndex, actionSkillIndex) + 8) + 5;
TimelineEvent newEvent;
newEvent._priority = 0;
newEvent._type = kDMEventTypeThievesEye;
newEvent._mapTime = _vm->setMapAndTime(_vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + windowTicks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
_vm->_championMan->_party._event73Count_ThievesEye++;
decrementCharges(curChampion);
}
break;
case kDMActionClimbDown:
nextMapX = _vm->_dungeonMan->_partyMapX;
nextMapY = _vm->_dungeonMan->_partyMapY;
nextMapX += _vm->_dirIntoStepCountEast[_vm->_dungeonMan->_partyDir];
nextMapY += _vm->_dirIntoStepCountNorth[_vm->_dungeonMan->_partyDir];
/* CHANGE6_00_FIX The presence of a group over the pit is checked so that you cannot climb down a pit with the rope if there is a group levitating over it */
if ((_vm->_dungeonMan->getSquare(nextMapX, nextMapY).getType() == kDMElementTypePit) && (_vm->_groupMan->groupGetThing(nextMapX, nextMapY) == Thing::_endOfList)) {
/* BUG0_77 The party moves forward when using the rope in front of a closed pit. The engine does not check whether
the pit is open before moving the party over the pit. This is not consistent with the behavior when using the
rope in front of a corridor where nothing happens */
_vm->_moveSens->_useRopeToClimbDownPit = true;
_vm->_moveSens->getMoveResult(Thing::_party, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, nextMapX, nextMapY);
_vm->_moveSens->_useRopeToClimbDownPit = false;
} else {
actionDisabledTicks = 0;
}
break;
case kDMActionFreezeLife: {
int16 freezeTicks;
if (weaponInHand->getType() == (int)kDMJunkTypeMagicalBoxBlue) {
freezeTicks = 30;
_vm->_championMan->getObjectRemovedFromSlot(champIndex, kDMSlotActionHand);
weaponInHand->setNextThing(Thing::_none);
} else if (weaponInHand->getType() == (int)kDMJunkTypeMagicalBoxGreen) {
freezeTicks = 125;
_vm->_championMan->getObjectRemovedFromSlot(champIndex, kDMSlotActionHand);
weaponInHand->setNextThing(Thing::_none);
} else {
freezeTicks = 70;
decrementCharges(curChampion);
}
_vm->_championMan->_party._freezeLifeTicks = MIN(200, _vm->_championMan->_party._freezeLifeTicks + freezeTicks);
}
break;
case kDMActionLight:
_vm->_championMan->_party._magicalLightAmount += _vm->_championMan->_lightPowerToLightAmount[2];
createEvent70_light(-2, 2500);
decrementCharges(curChampion);
break;
case kDMActionThrow:
setChampionDirectionToPartyDirection(curChampion);
actionPerformed = _vm->_championMan->isObjectThrown(champIndex, kDMSlotActionHand, (curChampion->_cell == (ViewCell)_vm->turnDirRight(_vm->_dungeonMan->_partyDir)) || (curChampion->_cell == (ViewCell)_vm->returnOppositeDir(_vm->_dungeonMan->_partyDir)));
if (actionPerformed)
_vm->_timeline->_events[curChampion->_enableActionEventIndex]._Bu._slotOrdinal = _vm->indexToOrdinal(kDMSlotActionHand);
break;
}
if (setDirectionFl) {
setChampionDirectionToPartyDirection(curChampion);
if (curChampion->_currMana < requiredManaAmount) {
// Fix potential divide by zero
if (!requiredManaAmount)
requiredManaAmount = 1;
kineticEnergy = MAX(2, curChampion->_currMana * kineticEnergy / requiredManaAmount);
requiredManaAmount = curChampion->_currMana;
}
actionPerformed = _vm->_championMan->isProjectileSpellCast(champIndex, explosionThing, kineticEnergy, requiredManaAmount);
if (!actionPerformed)
actionExperienceGain >>= 1;
decrementCharges(curChampion);
}
if (actionDisabledTicks)
_vm->_championMan->disableAction(champIndex, actionDisabledTicks);
if (actionStamina)
_vm->_championMan->decrementStamina(champIndex, actionStamina);
if (actionExperienceGain)
_vm->_championMan->addSkillExperience(champIndex, actionSkillIndex, actionExperienceGain);
_vm->_championMan->drawChampionState((ChampionIndex)champIndex);
return actionPerformed;
}
void MenuMan::setChampionDirectionToPartyDirection(Champion *champ) {
if (champ->_dir != _vm->_dungeonMan->_partyDir) {
champ->_dir = _vm->_dungeonMan->_partyDir;
setFlag(champ->_attributes, kDMAttributeIcon);
}
}
void MenuMan::decrementCharges(Champion *champ) {
Thing slotActionThing = champ->_slots[kDMSlotActionHand];
Junk *slotActionData = (Junk *)_vm->_dungeonMan->getThingData(slotActionThing);
switch (slotActionThing.getType()) {
case kDMThingTypeWeapon:
if (((Weapon *)slotActionData)->getChargeCount()) {
((Weapon *)slotActionData)->setChargeCount(((Weapon *)slotActionData)->getChargeCount() - 1);
}
break;
case kDMThingTypeArmour:
if (((Armour *)slotActionData)->getChargeCount()) {
((Armour *)slotActionData)->setChargeCount(((Armour *)slotActionData)->getChargeCount() - 1);
}
break;
case kDMThingTypeJunk:
if (slotActionData->getChargeCount()) {
slotActionData->setChargeCount(slotActionData->getChargeCount() - 1);
}
break;
default:
break;
}
_vm->_championMan->drawChangedObjectIcons();
}
bool MenuMan::isMeleeActionPerformed(int16 champIndex, Champion *champ, int16 actionIndex, int16 targetMapX, int16 targetMapY, int16 skillIndex) {
static unsigned char actionDamageFactorArray[44] = {
0, /* N */
15, /* BLOCK */
48, /* CHOP */
0, /* X */
0, /* BLOW HORN */
0, /* FLIP */
32, /* PUNCH */
48, /* KICK */
0, /* WAR CRY */
48, /* STAB */
0, /* CLIMB DOWN */
0, /* FREEZE LIFE */
20, /* HIT */
16, /* SWING */
60, /* STAB */
66, /* THRUST */
8, /* JAB */
8, /* PARRY */
25, /* HACK */
96, /* BERZERK */
0, /* FIREBALL */
0, /* DISPELL */
0, /* CONFUSE */
0, /* LIGHTNING */
55, /* DISRUPT */
60, /* MELEE */
0, /* X */
0, /* INVOKE */
16, /* SLASH */
48, /* CLEAVE */
50, /* BASH */
16, /* STUN */
0, /* SHOOT */
0, /* SPELLSHIELD */
0, /* FIRESHIELD */
0, /* FLUXCAGE */
0, /* HEAL */
0, /* CALM */
0, /* LIGHT */
0, /* WINDOW */
0, /* SPIT */
0, /* BRANDISH */
0, /* THROW */
0 /* FUSE */
};
static unsigned char actionHitProbabilityArray[44] = {
0, /* N */
22, /* BLOCK */
48, /* CHOP */
0, /* X */
0, /* BLOW HORN */
0, /* FLIP */
38, /* PUNCH */
28, /* KICK */
0, /* WAR CRY */
30, /* STAB */
0, /* CLIMB DOWN */
0, /* FREEZE LIFE */
20, /* HIT */
32, /* SWING */
42, /* STAB */
57, /* THRUST */
70, /* JAB */
18, /* PARRY */
27, /* HACK */
46, /* BERZERK */
0, /* FIREBALL */
0, /* DISPELL */
0, /* CONFUSE */
0, /* LIGHTNING */
46, /* DISRUPT */
64, /* MELEE */
0, /* X */
0, /* INVOKE */
26, /* SLASH */
40, /* CLEAVE */
32, /* BASH */
50, /* STUN */
0, /* SHOOT */
0, /* SPELLSHIELD */
0, /* FIRESHIELD */
0, /* FLUXCAGE */
0, /* HEAL */
0, /* CALM */
0, /* LIGHT */
0, /* WINDOW */
0, /* SPIT */
0, /* BRANDISH */
0, /* THROW */
0 /* FUSE */
};
_vm->_sound->requestPlay(kDMSoundIndexAttackSkelettonAnimatedArmorDethKnight, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, kDMSoundModePlayIfPrioritized);
if (_actionTargetGroupThing == Thing::_endOfList)
return false;
uint16 championCell = champ->_cell;
int16 targetCreatureOrdinal = _vm->_groupMan->getMeleeTargetCreatureOrdinal(targetMapX, targetMapY, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, championCell);
if (targetCreatureOrdinal) {
uint16 viewCell = _vm->normalizeModulo4(championCell + 4 - champ->_dir);
switch (viewCell) {
case kDMViewCellBackRight: /* Champion is on the back right of the square and tries to attack a creature in the front right of its square */
case kDMViewCellBackLeft: /* Champion is on the back left of the square and tries to attack a creature in the front left of its square */
uint16 cellDelta = (viewCell == kDMViewCellBackRight) ? 3 : 1;
/* Check if there is another champion in front */
if (_vm->_championMan->getIndexInCell(_vm->normalizeModulo4(championCell + cellDelta)) != kDMChampionNone) {
_actionDamage = kDMDamageCantReach;
return false;
}
break;
}
if ((actionIndex == kDMActionDisrupt) && !getFlag(_vm->_dungeonMan->getCreatureAttributes(_actionTargetGroupThing), kDMCreatureMaskNonMaterial))
return false;
uint16 actionHitProbability = actionHitProbabilityArray[actionIndex];
uint16 actionDamageFactor = actionDamageFactorArray[actionIndex];
if ((_vm->_objectMan->getIconIndex(champ->_slots[kDMSlotActionHand]) == kDMIconIndiceWeaponVorpalBlade) || (actionIndex == kDMActionDisrupt)) {
setFlag(actionHitProbability, kDMActionMaskHitNonMaterialCreatures);
}
_actionDamage = _vm->_groupMan->getMeleeActionDamage(champ, champIndex, (Group *)_vm->_dungeonMan->getThingData(_actionTargetGroupThing), _vm->ordinalToIndex(targetCreatureOrdinal), targetMapX, targetMapY, actionHitProbability, actionDamageFactor, skillIndex);
return true;
}
return false;
}
bool MenuMan::isGroupFrightenedByAction(int16 champIndex, uint16 actionIndex, int16 mapX, int16 mapY) {
bool retVal = false;
if (_actionTargetGroupThing == Thing::_endOfList)
return retVal;
uint16 experience = 0;
int16 frightAmount = 0;
switch (actionIndex) {
case kDMActionWarCry:
frightAmount = 3;
experience = 12; /* War Cry gives experience in priest skill k14_ChampionSkillInfluence below. The War Cry action also has an experience gain of 7 defined in G0497_auc_Graphic560_ActionExperienceGain in the same skill (versions 1.1 and below) or in the fighter skill k7_ChampionSkillParry (versions 1.2 and above). In versions 1.2 and above, this is the only action that gives experience in two skills */
break;
case kDMActionCalm:
frightAmount = 7;
experience = 35;
break;
case kDMActionBrandish:
frightAmount = 6;
experience = 30;
break;
case kDMActionBlowHorn:
frightAmount = 6;
experience = 20;
break;
case kDMActionConfuse:
frightAmount = 12;
experience = 45;
break;
}
frightAmount += _vm->_championMan->getSkillLevel(champIndex, kDMSkillInfluence);
Group *targetGroup = (Group *)_vm->_dungeonMan->getThingData(_actionTargetGroupThing);
CreatureInfo *creatureInfo = &_vm->_dungeonMan->_creatureInfos[targetGroup->_type];
uint16 fearResistance = creatureInfo->getFearResistance();
if ((fearResistance > _vm->getRandomNumber(frightAmount)) || (fearResistance == kDMImmuneToFear)) {
experience >>= 1;
} else {
ActiveGroup *activeGroup = &_vm->_groupMan->_activeGroups[targetGroup->getActiveGroupIndex()];
if (targetGroup->getBehaviour() == kDMBehaviorAttack) {
_vm->_groupMan->stopAttacking(activeGroup, mapX, mapY);
_vm->_groupMan->startWandering(mapX, mapY);
}
targetGroup->setBehaviour(kDMBehaviorFlee);
activeGroup->_delayFleeingFromTarget = ((16 - fearResistance) << 2) / creatureInfo->_movementTicks;
retVal = true;
}
_vm->_championMan->addSkillExperience(champIndex, kDMSkillInfluence, experience);
return retVal;
}
void MenuMan::printMessageAfterReplacements(const char *str) {
char outputString[128];
char *curCharacter = outputString;
*curCharacter++ = '\n'; /* New line */
const char *replacementString = "";
do {
if (*str == '@') {
str++;
if (*(curCharacter - 1) != '\n') /* New line */
*curCharacter++ = ' ';
if (*str == 'p') /* '@p' in the source string is replaced by the champion name followed by a space */
replacementString = _vm->_championMan->_champions[_vm->ordinalToIndex(_vm->_championMan->_actingChampionOrdinal)]._name;
*curCharacter = '\0';
strcat(outputString, replacementString);
curCharacter += strlen(replacementString);
*curCharacter++ = ' ';
} else {
*curCharacter++ = *str;
}
} while (*str++);
*curCharacter = '\0';
if (outputString[1]) /* If the string is not empty (the first character is a new line \n) */
_vm->_textMan->printMessage(kDMColorCyan, outputString);
}
void MenuMan::processCommands116To119_setActingChampion(uint16 champIndex) {
static ActionSet actionSets[44] = {
/* { ActionIndices[0], ActionIndices[1], ActionIndices[2], ActionProperties[0], ActionProperties[1], Useless } */
ActionSet(255, 255, 255, 0x00, 0x00),
ActionSet(27, 43, 35, 0x00, 0x00),
ActionSet(6, 7, 8, 0x00, 0x00),
ActionSet(0, 0, 0, 0x00, 0x00),
ActionSet(0, 0, 0, 0x00, 0x00),
ActionSet(13, 255, 255, 0x00, 0x00),
ActionSet(13, 20, 255, 0x87, 0x00),
ActionSet(13, 23, 255, 0x83, 0x00),
ActionSet(28, 41, 22, 0x02, 0x83),
ActionSet(16, 2, 23, 0x00, 0x84),
ActionSet(2, 25, 20, 0x02, 0x86),
ActionSet(17, 41, 34, 0x03, 0x05),
ActionSet(42, 9, 28, 0x00, 0x02),
ActionSet(13, 17, 2, 0x02, 0x03),
ActionSet(16, 17, 15, 0x01, 0x05),
ActionSet(28, 17, 25, 0x01, 0x05),
ActionSet(2, 25, 15, 0x05, 0x06),
ActionSet(9, 2, 29, 0x02, 0x05),
ActionSet(16, 29, 24, 0x02, 0x04),
ActionSet(13, 15, 19, 0x05, 0x07),
ActionSet(13, 2, 25, 0x00, 0x05),
ActionSet(2, 29, 19, 0x03, 0x08),
ActionSet(13, 30, 31, 0x02, 0x04),
ActionSet(13, 31, 25, 0x03, 0x06),
ActionSet(42, 30, 255, 0x00, 0x00),
ActionSet(0, 0, 0, 0x00, 0x00),
ActionSet(42, 9, 255, 0x00, 0x00),
ActionSet(32, 255, 255, 0x00, 0x00),
ActionSet(37, 33, 36, 0x82, 0x03),
ActionSet(37, 33, 34, 0x83, 0x84),
ActionSet(17, 38, 21, 0x80, 0x83),
ActionSet(13, 21, 34, 0x83, 0x84),
ActionSet(36, 37, 41, 0x02, 0x03),
ActionSet(13, 23, 39, 0x82, 0x84),
ActionSet(13, 17, 40, 0x00, 0x83),
ActionSet(17, 36, 38, 0x03, 0x84),
ActionSet(4, 255, 255, 0x00, 0x00),
ActionSet(5, 255, 255, 0x00, 0x00),
ActionSet(11, 255, 255, 0x00, 0x00),
ActionSet(10, 255, 255, 0x00, 0x00),
ActionSet(42, 9, 255, 0x00, 0x00),
ActionSet(1, 12, 255, 0x02, 0x00),
ActionSet(42, 255, 255, 0x00, 0x00),
ActionSet(6, 11, 255, 0x80, 0x00)
};
Champion *curChampion = &_vm->_championMan->_champions[champIndex];
if (getFlag(curChampion->_attributes, kDMAttributeDisableAction) || !curChampion->_currHealth)
return;
uint16 actionSetIndex;
Thing slotActionThing = curChampion->_slots[kDMSlotActionHand];
if (slotActionThing == Thing::_none)
actionSetIndex = 2; /* Actions Punch, Kick and War Cry */
else {
actionSetIndex = _vm->_dungeonMan->_objectInfos[_vm->_dungeonMan->getObjectInfoIndex(slotActionThing)]._actionSetIndex;
if (actionSetIndex == 0)
return;
}
ActionSet *actionSet = &actionSets[actionSetIndex];
_vm->_championMan->_actingChampionOrdinal = _vm->indexToOrdinal(champIndex);
setActionList(actionSet);
_actionAreaContainsIcons = false;
setFlag(curChampion->_attributes, kDMAttributeActionHand);
_vm->_championMan->drawChampionState((ChampionIndex)champIndex);
drawActionArea();
drawActionArea();
}
void MenuMan::setActionList(ActionSet *actionSet) {
_actionList._actionIndices[0] = (ChampionAction)actionSet->_actionIndices[0];
_actionList._minimumSkillLevel[0] = 1;
uint16 nextAvailableActionListIndex = 1;
for (uint16 idx = 1; idx < 3; idx++) {
uint16 actionIndex = actionSet->_actionIndices[idx];
if (actionIndex == kDMActionNone)
continue;
uint16 minimumSkillLevel = actionSet->_actionProperties[idx - 1];
if (getFlag(minimumSkillLevel, kDMActionMaskRequiresCharge) && !getActionObjectChargeCount())
continue;
clearFlag(minimumSkillLevel, kDMActionMaskRequiresCharge);
if (_vm->_championMan->getSkillLevel(_vm->ordinalToIndex(_vm->_championMan->_actingChampionOrdinal), _actionSkillIndex[actionIndex]) >= minimumSkillLevel) {
_actionList._actionIndices[nextAvailableActionListIndex] = (ChampionAction)actionIndex;
_actionList._minimumSkillLevel[nextAvailableActionListIndex] = minimumSkillLevel;
nextAvailableActionListIndex++;
}
}
_actionCount = nextAvailableActionListIndex;
for (uint16 idx = nextAvailableActionListIndex; idx < 3; idx++)
_actionList._actionIndices[idx] = kDMActionNone;
}
int16 MenuMan::getActionObjectChargeCount() {
Thing slotActionThing = _vm->_championMan->_champions[_vm->ordinalToIndex(_vm->_championMan->_actingChampionOrdinal)]._slots[kDMSlotActionHand];
Junk *junkData = (Junk *)_vm->_dungeonMan->getThingData(slotActionThing);
switch (slotActionThing.getType()) {
case kDMThingTypeWeapon:
return ((Weapon *)junkData)->getChargeCount();
case kDMThingTypeArmour:
return ((Armour *)junkData)->getChargeCount();
case kDMThingTypeJunk:
return junkData->getChargeCount();
default:
return 1;
}
}
void MenuMan::drawActionDamage(int16 damage) {
static const Box actionAreaMediumDamage(242, 305, 81, 117);
static const Box actionAreaSmallDamage(251, 292, 81, 117);
_vm->_eventMan->showMouse();
_vm->_displayMan->_useByteBoxCoordinates = false;
_vm->_displayMan->fillScreenBox(_boxActionArea, kDMColorBlack);
if (damage < 0) {
static const char *messagesEN[2] = {"CAN'T REACH", "NEED AMMO"};
static const char *messagesDE[2] = {"ZU WEIT WEG", "MEHR MUNITION"};
static const char *messagesFR[2] = {"TROP LOIN", "SANS MUNITION"};
static int16 posEN[2] = {242, 248};
static int16 posDE[2] = {242, 236};
static int16 posFR[2] = {248, 236};
const char **message;
int16 *pos;
switch (_vm->getGameLanguage()) { // localized
case Common::DE_DEU:
message = messagesDE;
pos = posDE;
break;
case Common::FR_FRA:
message = messagesFR;
pos = posFR;
break;
default:
message = messagesEN;
pos = posEN;
break;
}
const char *displayString;
int16 textPosX;
if (damage == kDMDamageCantReach) {
textPosX = pos[0];
displayString = message[0];
} else {
textPosX = pos[1];
displayString = message[1];
}
_vm->_textMan->printToLogicalScreen(textPosX, 100, kDMColorCyan, kDMColorBlack, displayString);
} else {
int16 byteWidth;
byte *blitBitmap;
const Box *blitBox;
int16 displayHeight;
if (damage > 40) {
blitBox = &_boxActionArea3ActionMenu;
blitBitmap = _vm->_displayMan->getNativeBitmapOrGraphic(kDMGraphicIdxDamageToCreature);
byteWidth = k48_byteWidth;
displayHeight = 45;
} else {
uint16 derivedBitmapIndex;
int16 destPixelWidth;
if (damage > 15) {
derivedBitmapIndex = kDMDerivedBitmapDamageToCreatureMedium;
destPixelWidth = 64;
byteWidth = k32_byteWidth;
blitBox = &actionAreaMediumDamage;
} else {
derivedBitmapIndex = kDMDerivedBitmapDamageToCreatureSmall;
destPixelWidth = 42;
byteWidth = k24_byteWidth;
blitBox = &actionAreaSmallDamage;
}
displayHeight = 37;
if (!_vm->_displayMan->isDerivedBitmapInCache(derivedBitmapIndex)) {
byte *nativeBitmap = _vm->_displayMan->getNativeBitmapOrGraphic(kDMGraphicIdxDamageToCreature);
blitBitmap = _vm->_displayMan->getDerivedBitmap(derivedBitmapIndex);
_vm->_displayMan->blitToBitmapShrinkWithPalChange(nativeBitmap, blitBitmap, 96, 45, destPixelWidth, 37, _vm->_displayMan->_palChangesNoChanges);
_vm->_displayMan->addDerivedBitmap(derivedBitmapIndex);
} else {
blitBitmap = _vm->_displayMan->getDerivedBitmap(derivedBitmapIndex);
}
}
_vm->_displayMan->blitToScreen(blitBitmap, blitBox, byteWidth, kDMColorNoTransparency, displayHeight);
/* Convert damage value to string */
uint16 charIndex = 5;
int16 textPosX = 274;
char scoreString[6];
scoreString[5] = '\0';
do {
scoreString[--charIndex] = '0' + (damage % 10);
textPosX -= 3;
} while (damage /= 10);
_vm->_textMan->printToLogicalScreen(textPosX, 100, kDMColorCyan, kDMColorBlack, &scoreString[charIndex]);
}
_vm->_eventMan->hideMouse();
}
}
|