-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbattle_interface.cpp
4621 lines (3934 loc) · 129 KB
/
battle_interface.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
/***************************************************************************
* Copyright (C) 2010 by Andrey Afletdinov <[email protected]> *
* *
* Part of the Free Heroes2 Engine: *
* http://sourceforge.net/projects/fheroes2 *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <cmath>
#include <algorithm>
#include "icn.h"
#include "cursor.h"
#include "agg.h"
#include "settings.h"
#include "kingdom.h"
#include "world.h"
#include "dialog.h"
#include "game.h"
#include "race.h"
#include "ground.h"
#include "pocketpc.h"
#include "interface_list.h"
#include "battle_arena.h"
#include "battle_troop.h"
#include "battle_tower.h"
#include "battle_bridge.h"
#include "battle_catapult.h"
#include "battle_interface.h"
#include "battle_command.h"
#include "m82.h"
#include "rand.h"
#include "audio_mixer.h"
#include "battle_army.h"
#include <functional>
#define ARMYORDERW 40
namespace Battle
{
int GetIndexIndicator(const Unit&);
int GetSwordCursorDirection(int);
int GetDirectionFromCursorSword(uint32_t);
int GetCursorFromSpell(int);
struct CursorPosition
{
CursorPosition() : index(-1)
{
}
Point coord;
s32 index;
};
class StatusListBox : public ::Interface::ListBox<string>
{
public:
StatusListBox() : openlog(false)
{
}
void SetPosition(uint32_t px, uint32_t py)
{
const uint32_t mx = 6;
const uint32_t sw = 640;
const uint32_t sh = mx * 20;
border.SetPosition(px, py - sh - 2, sw - 30, sh - 30);
const Rect& area = border.GetArea();
const uint32_t ax = area.x + area.w - 20;
SetTopLeft(area);
SetAreaMaxItems(mx);
SetScrollButtonUp(ICN::DROPLISL, 6, 7, Point(ax, area.y));
SetScrollButtonDn(ICN::DROPLISL, 8, 9, Point(ax, area.y + area.h - 20));
SetScrollSplitter(AGG::GetICN(ICN::DROPLISL, 13),
Rect(ax + 5, buttonPgUp.y + buttonPgUp.h + 3, 12,
buttonPgDn.y - (buttonPgUp.y + buttonPgUp.h) - 6));
splitter.HideCursor();
SetAreaItems(Rect(area.x, area.y, area.w - 10, area.h));
SetListContent(messages);
splitter.ShowCursor();
}
const Rect& GetArea() const
{
return border.GetRect();
}
void AddMessage(const string& str)
{
messages.push_back(str);
SetListContent(messages);
SetCurrent(messages.size() - 1);
}
void RedrawItem(const string& str, s32 px, s32 py, bool f)
{
Text text(str, Font::BIG);
text.Blit(px, py);
}
void RedrawBackground(const Point& pt)
{
const Sprite& sp1 = AGG::GetICN(ICN::DROPLISL, 10);
const Sprite& sp2 = AGG::GetICN(ICN::DROPLISL, 12);
const Sprite& sp3 = AGG::GetICN(ICN::DROPLISL, 11);
const Sprite& sp4 = AGG::GetICN(ICN::TEXTBAK2, 0);
const uint32_t ax = buttonPgUp.x;
const uint32_t ah = buttonPgDn.y - (buttonPgUp.y + buttonPgUp.h);
Dialog::FrameBorder::RenderOther(sp4, border.GetRect());
for (uint32_t ii = 0; ii < ah / sp3.h(); ++ii)
sp3.Blit(ax, buttonPgUp.y + buttonPgUp.h + sp3.h() * ii);
sp1.Blit(ax, buttonPgUp.y + buttonPgUp.h);
sp2.Blit(ax, buttonPgDn.y - sp2.h());
}
void ActionCurrentUp()
{
}
void ActionCurrentDn()
{
}
void ActionListDoubleClick(string&)
{
}
void ActionListSingleClick(string&)
{
}
void ActionListPressRight(string&)
{
}
void SetOpenLog(bool f)
{
openlog = f;
}
bool isOpenLog() const
{
return openlog;
}
private:
Dialog::FrameBorder border;
vector<string> messages;
bool openlog;
};
bool AnimateInfrequentDelay(int dl)
{
//return true;
return Game::AnimateInfrequentDelay(dl);
}
}
bool CursorAttack(uint32_t theme)
{
switch (theme)
{
case Cursor::WAR_ARROW:
case Cursor::WAR_BROKENARROW:
case Cursor::SWORD_TOPRIGHT:
case Cursor::SWORD_RIGHT:
case Cursor::SWORD_BOTTOMRIGHT:
case Cursor::SWORD_BOTTOMLEFT:
case Cursor::SWORD_LEFT:
case Cursor::SWORD_TOPLEFT:
case Cursor::SWORD_TOP:
case Cursor::SWORD_BOTTOM:
return true;
default:
break;
}
return false;
}
Surface DrawHexagon(const RGBA& color)
{
int r = 22;
int l = 13;
int w = CELLW;
int h = CELLH;
Surface sf(Size(w, h), false);
sf.DrawLineAa(Point(r, 0), Point(0, l), color);
sf.DrawLineAa(Point(r, 0), Point(w - 1, l), color);
sf.DrawLineAa(Point(0, l + 1), Point(0, h - l - 1), color);
sf.DrawLineAa(Point(w - 1, l + 1), Point(w - 1, h - l - 1), color);
sf.DrawLineAa(Point(r, h - 1), Point(0, h - l - 1), color);
sf.DrawLineAa(Point(r, h - 1), Point(w - 1, h - l - 1), color);
return sf;
}
Surface DrawHexagonShadow()
{
int l = 13;
int w = 45;
int h = 52;
Surface sf(Size(w, h), true);
RGBA shadow = RGBA(0, 0, 0, 0x30);
Rect rt(0, l, w, 2 * l);
sf.FillRect(rt, shadow);
for (int i = 1; i < w / 2; i += 2)
{
--rt.y;
rt.h += 2;
rt.x += 2;
rt.w -= 4;
sf.FillRect(rt, shadow);
}
return sf;
}
bool Battle::TargetInfo::isFinishAnimFrame() const
{
return defender && defender->isFinishAnimFrame();
}
int Battle::GetCursorFromSpell(int spell)
{
switch (spell)
{
case Spell::SLOW:
return Cursor::SP_SLOW;
case Spell::CURSE:
return Cursor::SP_CURSE;
case Spell::CURE:
return Cursor::SP_CURE;
case Spell::BLESS:
return Cursor::SP_BLESS;
case Spell::FIREBALL:
return Cursor::SP_FIREBALL;
case Spell::FIREBLAST:
return Cursor::SP_FIREBLAST;
case Spell::TELEPORT:
return Cursor::SP_TELEPORT;
case Spell::RESURRECT:
return Cursor::SP_RESURRECT;
case Spell::HASTE:
return Cursor::SP_HASTE;
case Spell::SHIELD:
return Cursor::SP_SHIELD;
case Spell::ARMAGEDDON:
return Cursor::SP_ARMAGEDDON;
case Spell::ANTIMAGIC:
return Cursor::SP_ANTIMAGIC;
case Spell::BERSERKER:
return Cursor::SP_BERSERKER;
case Spell::PARALYZE:
return Cursor::SP_PARALYZE;
case Spell::BLIND:
return Cursor::SP_BLIND;
case Spell::LIGHTNINGBOLT:
return Cursor::SP_LIGHTNINGBOLT;
case Spell::CHAINLIGHTNING:
return Cursor::SP_CHAINLIGHTNING;
case Spell::ELEMENTALSTORM:
return Cursor::SP_ELEMENTALSTORM;
case Spell::RESURRECTTRUE:
return Cursor::SP_RESURRECTTRUE;
case Spell::DISPEL:
return Cursor::SP_DISPEL;
case Spell::HOLYWORD:
return Cursor::SP_HOLYWORD;
case Spell::HOLYSHOUT:
return Cursor::SP_HOLYSHOUT;
case Spell::METEORSHOWER:
return Cursor::SP_METEORSHOWER;
case Spell::ANIMATEDEAD:
return Cursor::SP_ANIMATEDEAD;
case Spell::MIRRORIMAGE:
return Cursor::SP_MIRRORIMAGE;
case Spell::BLOODLUST:
return Cursor::SP_BLOODLUST;
case Spell::DEATHRIPPLE:
return Cursor::SP_DEATHRIPPLE;
case Spell::DEATHWAVE:
return Cursor::SP_DEATHWAVE;
case Spell::STEELSKIN:
return Cursor::SP_STEELSKIN;
case Spell::STONESKIN:
return Cursor::SP_STONESKIN;
case Spell::DRAGONSLAYER:
return Cursor::SP_DRAGONSLAYER;
case Spell::EARTHQUAKE:
return Cursor::SP_EARTHQUAKE;
case Spell::DISRUPTINGRAY:
return Cursor::SP_DISRUPTINGRAY;
case Spell::COLDRING:
return Cursor::SP_COLDRING;
case Spell::COLDRAY:
return Cursor::SP_COLDRAY;
case Spell::HYPNOTIZE:
return Cursor::SP_HYPNOTIZE;
case Spell::ARROW:
return Cursor::SP_ARROW;
default:
break;
}
return Cursor::WAR_NONE;
}
int Battle::GetSwordCursorDirection(int dir)
{
switch (dir)
{
case BOTTOM_RIGHT:
return Cursor::SWORD_TOPLEFT;
case BOTTOM_LEFT:
return Cursor::SWORD_TOPRIGHT;
case RIGHT:
return Cursor::SWORD_LEFT;
case TOP_RIGHT:
return Cursor::SWORD_BOTTOMLEFT;
case TOP_LEFT:
return Cursor::SWORD_BOTTOMRIGHT;
case LEFT:
return Cursor::SWORD_RIGHT;
default:
break;
}
return 0;
}
int Battle::GetDirectionFromCursorSword(uint32_t sword)
{
switch (sword)
{
case Cursor::SWORD_TOPLEFT:
return BOTTOM_RIGHT;
case Cursor::SWORD_TOPRIGHT:
return BOTTOM_LEFT;
case Cursor::SWORD_LEFT:
return RIGHT;
case Cursor::SWORD_BOTTOMLEFT:
return TOP_RIGHT;
case Cursor::SWORD_BOTTOMRIGHT:
return TOP_LEFT;
case Cursor::SWORD_RIGHT:
return LEFT;
default:
break;
}
return UNKNOWN;
}
Battle::OpponentSprite::OpponentSprite(const Rect& area, const HeroBase* b, bool r) : base(b),
icn(ICN::UNKNOWN), animframe(0),
animframe_start(0),
animframe_count(0), reflect(r)
{
ResetAnimFrame(OP_IDLE);
if (reflect)
{
pos.x = area.x + area.w - 60;
pos.y = area.y + 50;
}
else
{
pos.x = area.x + 5;
pos.y = area.y + 50;
}
const Sprite& sprite = AGG::GetICN(icn, animframe, reflect);
pos.w = sprite.w();
pos.h = sprite.h();
}
int Battle::OpponentSprite::GetColor() const
{
return base ? base->GetColor() : 0;
}
const HeroBase* Battle::OpponentSprite::GetHero() const
{
return base;
}
void Battle::OpponentSprite::IncreaseAnimFrame(bool loop)
{
if (animframe < animframe_start + animframe_count - 1)
++animframe;
else if (loop)
animframe = animframe_start;
}
void Battle::OpponentSprite::ResetAnimFrame(int rule)
{
if (base->isHeroes())
{
switch (base->GetRace())
{
case Race::BARB:
icn = ICN::CMBTHROB;
switch (rule)
{
case OP_IDLE:
animframe_start = 15;
animframe_count = 4;
break;
case OP_SRRW:
animframe_start = 1;
animframe_count = 5;
break;
case OP_CAST:
animframe_start = 6;
animframe_count = 9;
break;
default:
break;
}
break;
case Race::KNGT:
icn = ICN::CMBTHROK;
switch (rule)
{
case OP_IDLE:
animframe_start = 15;
animframe_count = 5;
break;
case OP_SRRW:
animframe_start = 1;
animframe_count = 5;
break;
case OP_CAST:
animframe_start = 6;
animframe_count = 9;
break;
default:
break;
}
break;
case Race::NECR:
icn = ICN::CMBTHRON;
switch (rule)
{
case OP_IDLE:
animframe_start = 16;
animframe_count = 2;
break;
case OP_SRRW:
animframe_start = 1;
animframe_count = 5;
break;
case OP_CAST:
animframe_start = 6;
animframe_count = 9;
break;
default:
break;
}
break;
case Race::SORC:
icn = ICN::CMBTHROS;
switch (rule)
{
case OP_IDLE:
animframe_start = 13;
animframe_count = 4;
break;
case OP_SRRW:
animframe_start = 1;
animframe_count = 5;
break;
case OP_CAST:
animframe_start = 6;
animframe_count = 7;
break;
default:
break;
}
break;
case Race::WRLK:
icn = ICN::CMBTHROW;
switch (rule)
{
case OP_IDLE:
animframe_start = 14;
animframe_count = 3;
break;
case OP_SRRW:
animframe_start = 1;
animframe_count = 5;
break;
case OP_CAST:
animframe_start = 6;
animframe_count = 8;
break;
default:
break;
}
break;
case Race::WZRD:
icn = ICN::CMBTHROZ;
switch (rule)
{
case OP_IDLE:
animframe_start = 16;
animframe_count = 3;
break;
case OP_SRRW:
animframe_start = 1;
animframe_count = 5;
break;
case OP_CAST:
animframe_start = 12;
animframe_count = 7;
break;
default:
break;
}
break;
default:
break;
}
animframe = animframe_start;
}
else if (base->isCaptain())
{
icn = ICN::CMBTCAPB;
switch (base->GetRace())
{
case Race::BARB:
icn = ICN::CMBTCAPB;
break;
case Race::KNGT:
icn = ICN::CMBTCAPK;
break;
case Race::NECR:
icn = ICN::CMBTCAPN;
break;
case Race::SORC:
icn = ICN::CMBTCAPS;
break;
case Race::WRLK:
icn = ICN::CMBTCAPW;
break;
case Race::WZRD:
icn = ICN::CMBTCAPZ;
break;
default:
break;
}
switch (rule)
{
case OP_IDLE:
animframe_start = 1;
animframe_count = 1;
break;
case OP_SRRW:
animframe_start = 1;
animframe_count = 1;
break;
case OP_CAST:
animframe_start = 3;
animframe_count = 6;
break;
default:
break;
}
animframe = animframe_start;
}
}
bool Battle::OpponentSprite::isFinishFrame() const
{
return !animframe_count || animframe >= animframe_start + animframe_count - 1;
}
bool Battle::OpponentSprite::isStartFrame() const
{
return animframe_count && animframe == animframe_start;
}
const Rect& Battle::OpponentSprite::GetArea() const
{
return pos;
}
void Battle::OpponentSprite::Redraw() const
{
AGG::GetICN(icn, animframe, reflect).Blit(pos.x, pos.y);
}
Battle::Status::Status() : back1(AGG::GetICN(ICN::TEXTBAR, 8)), back2(AGG::GetICN(ICN::TEXTBAR, 9)), listlog(nullptr)
{
w = back1.w();
h = back1.h() + back2.h();
bar1.Set(Font::BIG);
bar2.Set(Font::BIG);
}
void Battle::Status::SetPosition(s32 cx, s32 cy)
{
x = cx;
y = cy;
}
void Battle::Status::SetMessage(const string& str, bool top)
{
if (top)
{
bar1.Set(str);
if (listlog) listlog->AddMessage(str);
}
else if (str != message)
{
bar2.Set(str);
message = str;
}
}
void Battle::Status::Redraw() const
{
back1.Blit(x, y);
back2.Blit(x, y + back1.h());
if (bar1.Size()) bar1.Blit(x + (back1.w() - bar1.w()) / 2, y + 3);
if (bar2.Size()) bar2.Blit(x + (back2.w() - bar2.w()) / 2, y + back1.h() + 0);
}
const string& Battle::Status::GetMessage() const
{
return message;
}
Battle::ArmiesOrder::ArmiesOrder() : orders(nullptr), army_color2(0)
{
const RGBA yellow = RGBA(0xe0, 0xe0, 0);
const RGBA orange = RGBA(0xe0, 0x48, 0);
const RGBA green = RGBA(0x90, 0xc0, 0);
const Size sz(ARMYORDERW, ARMYORDERW);
sf_color[0].Set(sz.w, sz.h, true);
sf_color[0].DrawBorder(yellow);
sf_color[1].Set(sz.w, sz.h, true);
sf_color[1].DrawBorder(orange);
sf_color[2].Set(sz.w, sz.h, true);
sf_color[2].DrawBorder(green);
}
void Battle::ArmiesOrder::Set(const Rect& rt, const Units* units, int color)
{
area = rt;
orders = units;
army_color2 = color;
if (units) rects.reserve(units->_items.size());
}
void Battle::ArmiesOrder::QueueEventProcessing(string& msg)
{
LocalEvent& le = LocalEvent::Get();
for (auto& rect : rects)
{
if (!rect.first)
continue;
if (le.MouseCursor(rect.second))
{
msg = _("View %{monster} info.");
StringReplace(msg, "%{monster}", rect.first->GetName());
}
if (le.MouseClickLeft(rect.second))
Dialog::ArmyInfo(*rect.first, Dialog::READONLY | Dialog::BUTTONS);
else if (le.MousePressRight(rect.second))
ArmyInfo(*rect.first, Dialog::READONLY);
}
}
void Battle::ArmiesOrder::RedrawUnit(const Rect& pos, const Unit& unit, bool revert, bool current) const
{
Display& display = Display::Get();
const Sprite& mons32 = AGG::GetICN(ICN::MONS32, unit._monster.GetSpriteIndex(), revert);
// background
display.FillRect(pos, RGBA(0x33, 0x33, 0x13));
// mons32 sprite
mons32.Blit(pos.x + (pos.w - mons32.w()) / 2, pos.y + pos.h - mons32.h() - (mons32.h() + 3 < pos.h ? 3 : 0),
display);
// window
if (current)
sf_color[0].Blit(pos.x + 1, pos.y + 1, display);
else if (unit.Modes(TR_MOVED))
sf_color[1].Blit(pos.x + 1, pos.y + 1, display);
else
sf_color[2].Blit(pos.x + 1, pos.y + 1, display);
// number
Text number(Int2Str(unit.GetCount()), Font::SMALL);
number.Blit(pos.x + 2, pos.y + 2);
}
void Battle::ArmiesOrder::Redraw(const Unit* current)
{
if (!orders)
return;
const uint32_t ow = ARMYORDERW + 2;
uint32_t ox = area.x + (area.w - ow * count_if(orders->_items.begin(), orders->_items.end(),
[&](const Unit* it) { return it->isValid(); })) / 2;
uint32_t oy = area.y;
x = ox;
y = oy;
h = ow;
rects.clear();
for (auto order : orders->_items)
{
if (!order || !order->isValid()) continue;
rects.emplace_back(order, Rect(ox, oy, ow, ow));
RedrawUnit(rects.back().second, *order, (*order).GetColor() == army_color2, current == order);
ox += ow;
w += ow;
}
}
Battle::Interface::Interface(Arena& a, s32 center) : arena(a), icn_cbkg(ICN::UNKNOWN), icn_frng(ICN::UNKNOWN),
humanturn_spell(Spell::NONE), humanturn_exit(true),
humanturn_redraw(true), animation_flags_frame(0),
catapult_frame(0),
b_current(nullptr), b_move(nullptr), b_fly(nullptr),
b_current_sprite(nullptr),
b_current_alpha(255), index_pos(-1), teleport_src(-1),
listlog(nullptr), turn(0)
{
const Settings& conf = Settings::Get();
bool pda = false;
Cursor::Get().Hide();
// border
Display& display = Display::Get();
const uint32_t arenaw = pda ? 320 : 640;
const uint32_t arenah = pda ? (display.h() < 240 ? display.h() : 240) : 480;
border.SetPosition((display.w() - arenaw) / 2 - BORDERWIDTH, (display.h() - arenah) / 2 - BORDERWIDTH, arenaw,
arenah);
// cover
MapsIndexes treeIndices;
Maps::ScanAroundObject(center, MP2::OBJ_TREES, treeIndices);
bool trees = !treeIndices.empty();
const Maps::Tiles& tile = world.GetTiles(center);
bool grave = MP2::OBJ_GRAVEYARD == tile.GetObject(false);
bool light = true;
switch (tile.GetGround())
{
case Maps::Ground::DESERT:
icn_cbkg = ICN::CBKGDSRT;
light = false;
icn_frng = ICN::FRNG0004;
break;
case Maps::Ground::SNOW:
icn_cbkg = trees ? ICN::CBKGSNTR : ICN::CBKGSNMT;
light = false;
icn_frng = trees ? ICN::FRNG0006 : ICN::FRNG0007;
break;
case Maps::Ground::SWAMP:
icn_cbkg = ICN::CBKGSWMP;
icn_frng = ICN::FRNG0008;
break;
case Maps::Ground::WASTELAND:
icn_cbkg = ICN::CBKGCRCK;
light = false;
icn_frng = ICN::FRNG0003;
break;
case Maps::Ground::BEACH:
icn_cbkg = ICN::CBKGBEAC;
light = false;
icn_frng = ICN::FRNG0002;
break;
case Maps::Ground::LAVA:
icn_cbkg = ICN::CBKGLAVA;
icn_frng = ICN::FRNG0005;
break;
case Maps::Ground::DIRT:
icn_cbkg = trees ? ICN::CBKGDITR : ICN::CBKGDIMT;
icn_frng = trees ? ICN::FRNG0010 : ICN::FRNG0009;
break;
case Maps::Ground::GRASS:
icn_cbkg = trees ? ICN::CBKGGRTR : ICN::CBKGGRMT;
icn_frng = trees ? ICN::FRNG0011 : ICN::FRNG0012;
break;
case Maps::Ground::WATER:
icn_cbkg = ICN::CBKGWATR;
icn_frng = ICN::FRNG0013;
break;
default:
break;
}
if (grave)
{
icn_cbkg = ICN::CBKGGRAV;
light = true;
icn_frng = ICN::FRNG0001;
}
// hexagon
sf_hexagon = DrawHexagon(light ? RGBA(0x78, 0x94, 0) : RGBA(0x38, 0x48, 0));
sf_cursor = DrawHexagon(RGBA(0xb0, 0x0c, 0));
sf_shadow = DrawHexagonShadow();
// buttons
const Rect& area = border.GetArea();
btn_auto.SetSprite(ICN::TEXTBAR, 4, 5);
btn_settings.SetSprite(ICN::TEXTBAR, 6, 7);
btn_auto.SetPos(area.x, area.y + area.h - btn_settings.h - btn_auto.h);
btn_settings.SetPos(area.x, area.y + area.h - btn_settings.h);
if (conf.ExtBattleSoftWait())
{
btn_wait.SetSprite(ICN::BATTLEWAIT, 0, 1);
btn_skip.SetSprite(ICN::BATTLESKIP, 0, 1);
btn_wait.SetPos(area.x + area.w - btn_wait.w, area.y + area.h - btn_skip.h - btn_wait.h);
btn_skip.SetPos(area.x + area.w - btn_skip.w, area.y + area.h - btn_skip.h);
}
else
{
btn_skip.SetSprite(ICN::TEXTBAR, 0, 1);
btn_skip.SetPos(area.x + area.w - btn_skip.w, area.y + area.h - btn_skip.h);
}
status.SetPosition(area.x + btn_settings.w, btn_auto.y);
listlog = std::make_unique<StatusListBox>();
if (listlog)
listlog->SetPosition(area.x, area.y + area.h - 36);
status.SetLogs(listlog.get());
// opponents
opponent1 = arena.GetCommander1()
? std::make_unique<OpponentSprite>(area, arena.GetCommander1(), false)
: nullptr;
opponent2 = arena.GetCommander2()
? std::make_unique<OpponentSprite>(area, arena.GetCommander2(), true)
: nullptr;
if (Arena::GetCastle())
main_tower = Rect(area.x + 570, area.y + 145, 70, 70);
}
Battle::Interface::~Interface() = default;
void Battle::Interface::SetArmiesOrder(const Units* units)
{
armies_order.Set(border.GetArea(), units, arena.GetArmyColor2());
}
const Rect& Battle::Interface::GetArea() const
{
return border.GetArea();
}
void Battle::Interface::SetStatus(const string& msg, bool top)
{
if (top)
{
status.SetMessage(msg, true);
status.SetMessage("", false);
}
else
{
status.SetMessage(msg);
}
humanturn_redraw = true;
}
void Battle::Interface::Redraw()
{
const Castle* castle = Arena::GetCastle();
RedrawBorder();
RedrawCover();
RedrawOpponents();
if (castle) RedrawCastle3(*castle);
RedrawArmies();
RedrawInterface();
armies_order.Redraw(b_current);
}
void Battle::Interface::RedrawInterface()
{
const Settings& conf = Settings::Get();
status.Redraw();
btn_auto.Draw();
btn_settings.Draw();
if (conf.ExtBattleSoftWait()) btn_wait.Draw();
btn_skip.Draw();
popup.Redraw(rectBoard.x + rectBoard.w + 60, rectBoard.y + rectBoard.h);
if (listlog && listlog->isOpenLog())
listlog->Redraw();
}
void Battle::Interface::RedrawArmies() const
{
const Castle* castle = Arena::GetCastle();
for (s32 ii = 0; ii < ARENASIZE; ++ii)
{
RedrawHighObjects(ii);
if (castle)
if (8 == ii || 19 == ii || 29 == ii || 40 == ii ||
50 == ii || 62 == ii || 85 == ii || 73 == ii || 77 == ii)
RedrawCastle2(*castle, ii);
const Cell* cell = Board::GetCell(ii);
const Unit* b = cell->GetUnit();
if (b && b_fly != b && ii != b->GetTailIndex())
{
RedrawTroopSprite(*b);
if (b_move != b)
RedrawTroopCount(*b);
}
}
if (castle)
{
RedrawCastle2(*castle, 96);
const Unit* b = Board::GetCell(96)->GetUnit();
if (b) RedrawTroopSprite(*b);
}
if (b_fly)
{
RedrawTroopSprite(*b_fly);
}
}
void Battle::Interface::RedrawOpponents() const
{
if (opponent1) opponent1->Redraw();
if (opponent2) opponent2->Redraw();
RedrawOpponentsFlags();
}
void Battle::Interface::RedrawOpponentsFlags() const
{
if (opponent1 != nullptr)
{
int icn = ICN::UNKNOWN;