/
menus.cpp
1804 lines (1667 loc) · 63 KB
/
menus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* 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;
}
void MenuMan::drawMovementArrows() {
_vm->_eventMan->showMouse();
_vm->_displayMan->blitToScreen(_vm->_displayMan->getNativeBitmapOrGraphic(k13_MovementArrowsIndice),
&_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(k10_MenuActionAreaIndice),
&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(k9_MenuSpellAreaBackground), &_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 = k73_TMEventTypeThievesEye;
_vm->_championMan->_party._event73Count_ThievesEye++;
spellPower = (spellPower >> 1);
uint16 spellTicks = spellPower * spellPower;
_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
}
break;
case kDMSpellTypeOtherInvisibility: {
newEvent._type = k71_TMEventTypeInvisibility;
_vm->_championMan->_party._event71Count_Invisibility++;
uint16 spellTicks = spellPower;
_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
}
break;
case kDMSpellTypeOtherPartyShield: {
newEvent._type = k74_TMEventTypePartyShield;
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;
_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + spellTicks);
_vm->_timeline->addEventGetEventIndex(&newEvent);
}
break;
case kDMSpellTypeOtherFootprints: {
newEvent._type = k79_TMEventTypeFootprints;
_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;
_vm->setMapAndTime(newEvent._mapTime, _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 = k70_TMEventTypeLight;
newEvent._Bu._lightPower = lightPower;
_vm->setMapAndTime(newEvent._mapTime, _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 = k77_TMEventTypeSpellShield;
if (_vm->_championMan->_party._spellShieldDefense > 50)
newEvent._Bu._defense >>= 2;
_vm->_championMan->_party._spellShieldDefense += newEvent._Bu._defense;
} else {
newEvent._type = k78_TMEventTypeFireShield;
if (_vm->_championMan->_party._fireShieldDefense > 50)
newEvent._Bu._defense >>= 2;
_vm->_championMan->_party._fireShieldDefense += newEvent._Bu._defense;
}
newEvent._priority = 0;
_vm->setMapAndTime(newEvent._mapTime, _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 */