Repository navigation
Expand file tree
/
Copy pathBattlescapeState.cpp
More file actions
2343 lines (2106 loc) · 72.5 KB
/
Copy pathBattlescapeState.cpp
File metadata and controls
2343 lines (2106 loc) · 72.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2010-2016 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom 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 3 of the License, or
* (at your option) any later version.
*
* OpenXcom 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 OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <SDL_gfxPrimitives.h>
#include "Map.h"
#include "Camera.h"
#include "BattlescapeState.h"
#include "AbortMissionState.h"
#include "TileEngine.h"
#include "ActionMenuState.h"
#include "UnitInfoState.h"
#include "InventoryState.h"
#include "Pathfinding.h"
#include "BattlescapeGame.h"
#include "WarningMessage.h"
#include "DebriefingState.h"
#include "MiniMapState.h"
#include "BattlescapeGenerator.h"
#include "BriefingState.h"
#include "../lodepng.h"
#include "../fmath.h"
#include "../Engine/Game.h"
#include "../Engine/Options.h"
#include "../Engine/LocalizedText.h"
#include "../Engine/Palette.h"
#include "../Engine/Surface.h"
#include "../Engine/SurfaceSet.h"
#include "../Engine/Screen.h"
#include "../Engine/Sound.h"
#include "../Engine/Action.h"
#include "../Engine/Logger.h"
#include "../Engine/Timer.h"
#include "../Engine/CrossPlatform.h"
#include "../Interface/Cursor.h"
#include "../Interface/Text.h"
#include "../Interface/Bar.h"
#include "../Interface/BattlescapeButton.h"
#include "../Interface/NumberText.h"
#include "../Menu/CutsceneState.h"
#include "../Menu/PauseState.h"
#include "../Menu/LoadGameState.h"
#include "../Menu/SaveGameState.h"
#include "../Mod/Mod.h"
#include "../Mod/RuleItem.h"
#include "../Mod/AlienDeployment.h"
#include "../Mod/Armor.h"
#include "../Mod/RuleUfo.h"
#include "../Savegame/SavedGame.h"
#include "../Savegame/SavedBattleGame.h"
#include "../Savegame/Tile.h"
#include "../Savegame/BattleUnit.h"
#include "../Savegame/Soldier.h"
#include "../Savegame/BattleItem.h"
#include "../Savegame/Ufo.h"
#include "../Mod/RuleInterface.h"
namespace OpenXcom
{
/**
* Initializes all the elements in the Battlescape screen.
* @param game Pointer to the core game.
*/
BattlescapeState::BattlescapeState() : _reserve(0), _firstInit(true), _isMouseScrolling(false), _isMouseScrolled(false), _xBeforeMouseScrolling(0), _yBeforeMouseScrolling(0), _totalMouseMoveX(0), _totalMouseMoveY(0), _mouseMovedOverThreshold(0), _mouseOverIcons(false), _autosave(false)
{
std::fill_n(_visibleUnit, 10, (BattleUnit*)(0));
const int screenWidth = Options::baseXResolution;
const int screenHeight = Options::baseYResolution;
const int iconsWidth = _game->getMod()->getInterface("battlescape")->getElement("icons")->w;
const int iconsHeight = _game->getMod()->getInterface("battlescape")->getElement("icons")->h;
const int visibleMapHeight = screenHeight - iconsHeight;
const int x = screenWidth/2 - iconsWidth/2;
const int y = screenHeight - iconsHeight;
// Create buttonbar - this should be on the centerbottom of the screen
_icons = new InteractiveSurface(iconsWidth, iconsHeight, x, y);
// Create the battlemap view
// the actual map height is the total height minus the height of the buttonbar
_map = new Map(_game, screenWidth, screenHeight, 0, 0, visibleMapHeight);
_numLayers = new NumberText(3, 5, x + 232, y + 6);
_rank = new Surface(26, 23, x + 107, y + 33);
// Create buttons
_btnUnitUp = new BattlescapeButton(32, 16, x + 48, y);
_btnUnitDown = new BattlescapeButton(32, 16, x + 48, y + 16);
_btnMapUp = new BattlescapeButton(32, 16, x + 80, y);
_btnMapDown = new BattlescapeButton(32, 16, x + 80, y + 16);
_btnShowMap = new BattlescapeButton(32, 16, x + 112, y);
_btnKneel = new BattlescapeButton(32, 16, x + 112, y + 16);
_btnInventory = new BattlescapeButton(32, 16, x + 144, y);
_btnCenter = new BattlescapeButton(32, 16, x + 144, y + 16);
_btnNextSoldier = new BattlescapeButton(32, 16, x + 176, y);
_btnNextStop = new BattlescapeButton(32, 16, x + 176, y + 16);
_btnShowLayers = new BattlescapeButton(32, 16, x + 208, y);
_btnHelp = new BattlescapeButton(32, 16, x + 208, y + 16);
_btnEndTurn = new BattlescapeButton(32, 16, x + 240, y);
_btnAbort = new BattlescapeButton(32, 16, x + 240, y + 16);
_btnStats = new InteractiveSurface(164, 23, x + 107, y + 33);
_btnReserveNone = new BattlescapeButton(17, 11, x + 60, y + 33);
_btnReserveSnap = new BattlescapeButton(17, 11, x + 78, y + 33);
_btnReserveAimed = new BattlescapeButton(17, 11, x + 60, y + 45);
_btnReserveAuto = new BattlescapeButton(17, 11, x + 78, y + 45);
_btnReserveKneel = new BattlescapeButton(10, 23, x + 96, y + 33);
_btnZeroTUs = new BattlescapeButton(10, 23, x + 49, y + 33);
_btnLeftHandItem = new InteractiveSurface(32, 48, x + 8, y + 4);
_numAmmoLeft = new NumberText(30, 5, x + 8, y + 4);
_btnRightHandItem = new InteractiveSurface(32, 48, x + 280, y + 4);
_numAmmoRight = new NumberText(30, 5, x + 280, y + 4);
const int visibleUnitX = _game->getMod()->getInterface("battlescape")->getElement("visibleUnits")->x;
const int visibleUnitY = _game->getMod()->getInterface("battlescape")->getElement("visibleUnits")->y;
for (int i = 0; i < VISIBLE_MAX; ++i)
{
_btnVisibleUnit[i] = new InteractiveSurface(15, 12, x + visibleUnitX, y + visibleUnitY - (i * 13));
_numVisibleUnit[i] = new NumberText(15, 12, _btnVisibleUnit[i]->getX() + 6 , _btnVisibleUnit[i]->getY() + 4);
}
_numVisibleUnit[9]->setX(_numVisibleUnit[9]->getX() - 2); // center number 10
_warning = new WarningMessage(224, 24, x + 48, y + 32);
_btnLaunch = new BattlescapeButton(32, 24, screenWidth - 32, 0); // we need screenWidth, because that is independent of the black bars on the screen
_btnLaunch->setVisible(false);
_btnPsi = new BattlescapeButton(32, 24, screenWidth - 32, 25); // we need screenWidth, because that is independent of the black bars on the screen
_btnPsi->setVisible(false);
// Create soldier stats summary
_txtName = new Text(136, 10, x + 135, y + 32);
_numTimeUnits = new NumberText(15, 5, x + 136, y + 42);
_barTimeUnits = new Bar(102, 3, x + 170, y + 41);
_numEnergy = new NumberText(15, 5, x + 154, y + 42);
_barEnergy = new Bar(102, 3, x + 170, y + 45);
_numHealth = new NumberText(15, 5, x + 136, y + 50);
_barHealth= new Bar(102, 3, x + 170, y + 49);
_numMorale = new NumberText(15, 5, x + 154, y + 50);
_barMorale = new Bar(102, 3, x + 170, y + 53);
_txtDebug = new Text(300, 10, 20, 0);
_txtTooltip = new Text(300, 10, x + 2, y - 10);
// Set palette
_game->getSavedGame()->getSavedBattle()->setPaletteByDepth(this);
if (_game->getMod()->getInterface("battlescape")->getElement("pathfinding"))
{
Element *pathing = _game->getMod()->getInterface("battlescape")->getElement("pathfinding");
Pathfinding::green = pathing->color;
Pathfinding::yellow = pathing->color2;
Pathfinding::red = pathing->border;
}
add(_map);
add(_icons);
// Add in custom reserve buttons
Surface *icons = _game->getMod()->getSurface("ICONS.PCK");
if (_game->getMod()->getSurface("TFTDReserve", false))
{
Surface *tftdIcons = _game->getMod()->getSurface("TFTDReserve");
tftdIcons->setX(48);
tftdIcons->setY(176);
tftdIcons->blit(icons);
}
// there is some cropping going on here, because the icons image is 320x200 while we only need the bottom of it.
SDL_Rect *r = icons->getCrop();
r->x = 0;
r->y = 200 - iconsHeight;
r->w = iconsWidth;
r->h = iconsHeight;
// we need to blit the icons before we add the battlescape buttons, as they copy the underlying parent surface.
icons->blit(_icons);
// this is a hack to fix the single transparent pixel on TFTD's icon panel.
if (_game->getMod()->getInterface("battlescape")->getElement("icons")->TFTDMode)
{
_icons->setPixel(46, 44, 8);
}
add(_rank, "rank", "battlescape", _icons);
add(_btnUnitUp, "buttonUnitUp", "battlescape", _icons);
add(_btnUnitDown, "buttonUnitDown", "battlescape", _icons);
add(_btnMapUp, "buttonMapUp", "battlescape", _icons);
add(_btnMapDown, "buttonMapDown", "battlescape", _icons);
add(_btnShowMap, "buttonShowMap", "battlescape", _icons);
add(_btnKneel, "buttonKneel", "battlescape", _icons);
add(_btnInventory, "buttonInventory", "battlescape", _icons);
add(_btnCenter, "buttonCenter", "battlescape", _icons);
add(_btnNextSoldier, "buttonNextSoldier", "battlescape", _icons);
add(_btnNextStop, "buttonNextStop", "battlescape", _icons);
add(_btnShowLayers, "buttonShowLayers", "battlescape", _icons);
add(_numLayers, "numLayers", "battlescape", _icons);
add(_btnHelp, "buttonHelp", "battlescape", _icons);
add(_btnEndTurn, "buttonEndTurn", "battlescape", _icons);
add(_btnAbort, "buttonAbort", "battlescape", _icons);
add(_btnStats, "buttonStats", "battlescape", _icons);
add(_txtName, "textName", "battlescape", _icons);
add(_numTimeUnits, "numTUs", "battlescape", _icons);
add(_numEnergy, "numEnergy", "battlescape", _icons);
add(_numHealth, "numHealth", "battlescape", _icons);
add(_numMorale, "numMorale", "battlescape", _icons);
add(_barTimeUnits, "barTUs", "battlescape", _icons);
add(_barEnergy, "barEnergy", "battlescape", _icons);
add(_barHealth, "barHealth", "battlescape", _icons);
add(_barMorale, "barMorale", "battlescape", _icons);
add(_btnReserveNone, "buttonReserveNone", "battlescape", _icons);
add(_btnReserveSnap, "buttonReserveSnap", "battlescape", _icons);
add(_btnReserveAimed, "buttonReserveAimed", "battlescape", _icons);
add(_btnReserveAuto, "buttonReserveAuto", "battlescape", _icons);
add(_btnReserveKneel, "buttonReserveKneel", "battlescape", _icons);
add(_btnZeroTUs, "buttonZeroTUs", "battlescape", _icons);
add(_btnLeftHandItem, "buttonLeftHand", "battlescape", _icons);
add(_numAmmoLeft, "numAmmoLeft", "battlescape", _icons);
add(_btnRightHandItem, "buttonRightHand", "battlescape", _icons);
add(_numAmmoRight, "numAmmoRight", "battlescape", _icons);
for (int i = 0; i < VISIBLE_MAX; ++i)
{
add(_btnVisibleUnit[i]);
add(_numVisibleUnit[i]);
}
add(_warning, "warning", "battlescape", _icons);
add(_txtDebug);
add(_txtTooltip, "textTooltip", "battlescape", _icons);
add(_btnLaunch);
_game->getMod()->getSurfaceSet("SPICONS.DAT")->getFrame(0)->blit(_btnLaunch);
add(_btnPsi);
_game->getMod()->getSurfaceSet("SPICONS.DAT")->getFrame(1)->blit(_btnPsi);
// Set up objects
_save = _game->getSavedGame()->getSavedBattle();
_map->init();
_map->onMouseOver((ActionHandler)&BattlescapeState::mapOver);
_map->onMousePress((ActionHandler)&BattlescapeState::mapPress);
_map->onMouseClick((ActionHandler)&BattlescapeState::mapClick, 0);
_map->onMouseIn((ActionHandler)&BattlescapeState::mapIn);
_numLayers->setColor(Palette::blockOffset(1)-2);
_numLayers->setValue(1);
_numAmmoLeft->setValue(999);
_numAmmoRight->setValue(999);
_icons->onMouseIn((ActionHandler)&BattlescapeState::mouseInIcons);
_icons->onMouseOut((ActionHandler)&BattlescapeState::mouseOutIcons);
_btnUnitUp->onMouseClick((ActionHandler)&BattlescapeState::btnUnitUpClick);
_btnUnitUp->setTooltip("STR_UNIT_LEVEL_ABOVE");
_btnUnitUp->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnUnitUp->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnUnitDown->onMouseClick((ActionHandler)&BattlescapeState::btnUnitDownClick);
_btnUnitDown->setTooltip("STR_UNIT_LEVEL_BELOW");
_btnUnitDown->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnUnitDown->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnMapUp->onMouseClick((ActionHandler)&BattlescapeState::btnMapUpClick);
_btnMapUp->onKeyboardPress((ActionHandler)&BattlescapeState::btnMapUpClick, Options::keyBattleLevelUp);
_btnMapUp->setTooltip("STR_VIEW_LEVEL_ABOVE");
_btnMapUp->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnMapUp->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnMapDown->onMouseClick((ActionHandler)&BattlescapeState::btnMapDownClick);
_btnMapDown->onKeyboardPress((ActionHandler)&BattlescapeState::btnMapDownClick, Options::keyBattleLevelDown);
_btnMapDown->setTooltip("STR_VIEW_LEVEL_BELOW");
_btnMapDown->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnMapDown->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnShowMap->onMouseClick((ActionHandler)&BattlescapeState::btnShowMapClick);
_btnShowMap->onKeyboardPress((ActionHandler)&BattlescapeState::btnShowMapClick, Options::keyBattleMap);
_btnShowMap->setTooltip("STR_MINIMAP");
_btnShowMap->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnShowMap->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnKneel->onMouseClick((ActionHandler)&BattlescapeState::btnKneelClick);
_btnKneel->onKeyboardPress((ActionHandler)&BattlescapeState::btnKneelClick, Options::keyBattleKneel);
_btnKneel->setTooltip("STR_KNEEL");
_btnKneel->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnKneel->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnKneel->allowToggleInversion();
_btnInventory->onMouseClick((ActionHandler)&BattlescapeState::btnInventoryClick);
_btnInventory->onKeyboardPress((ActionHandler)&BattlescapeState::btnInventoryClick, Options::keyBattleInventory);
_btnInventory->setTooltip("STR_INVENTORY");
_btnInventory->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnInventory->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnCenter->onMouseClick((ActionHandler)&BattlescapeState::btnCenterClick);
_btnCenter->onKeyboardPress((ActionHandler)&BattlescapeState::btnCenterClick, Options::keyBattleCenterUnit);
_btnCenter->setTooltip("STR_CENTER_SELECTED_UNIT");
_btnCenter->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnCenter->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnNextSoldier->onMouseClick((ActionHandler)&BattlescapeState::btnNextSoldierClick);
_btnNextSoldier->onKeyboardPress((ActionHandler)&BattlescapeState::btnNextSoldierClick, Options::keyBattleNextUnit);
_btnNextSoldier->onKeyboardPress((ActionHandler)&BattlescapeState::btnPrevSoldierClick, Options::keyBattlePrevUnit);
_btnNextSoldier->setTooltip("STR_NEXT_UNIT");
_btnNextSoldier->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnNextSoldier->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnNextStop->onMouseClick((ActionHandler)&BattlescapeState::btnNextStopClick);
_btnNextStop->onKeyboardPress((ActionHandler)&BattlescapeState::btnNextStopClick, Options::keyBattleDeselectUnit);
_btnNextStop->setTooltip("STR_DESELECT_UNIT");
_btnNextStop->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnNextStop->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnShowLayers->onMouseClick((ActionHandler)&BattlescapeState::btnShowLayersClick);
_btnShowLayers->setTooltip("STR_MULTI_LEVEL_VIEW");
_btnShowLayers->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnShowLayers->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnHelp->onMouseClick((ActionHandler)&BattlescapeState::btnHelpClick);
_btnHelp->onKeyboardPress((ActionHandler)&BattlescapeState::btnHelpClick, Options::keyBattleOptions);
_btnHelp->setTooltip("STR_OPTIONS");
_btnHelp->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnHelp->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnEndTurn->onMouseClick((ActionHandler)&BattlescapeState::btnEndTurnClick);
_btnEndTurn->onKeyboardPress((ActionHandler)&BattlescapeState::btnEndTurnClick, Options::keyBattleEndTurn);
_btnEndTurn->setTooltip("STR_END_TURN");
_btnEndTurn->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnEndTurn->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnAbort->onMouseClick((ActionHandler)&BattlescapeState::btnAbortClick);
_btnAbort->onKeyboardPress((ActionHandler)&BattlescapeState::btnAbortClick, Options::keyBattleAbort);
_btnAbort->setTooltip("STR_ABORT_MISSION");
_btnAbort->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnAbort->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnStats->onMouseClick((ActionHandler)&BattlescapeState::btnStatsClick);
_btnStats->onKeyboardPress((ActionHandler)&BattlescapeState::btnStatsClick, Options::keyBattleStats);
_btnStats->setTooltip("STR_UNIT_STATS");
_btnStats->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnStats->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnLeftHandItem->onMouseClick((ActionHandler)&BattlescapeState::btnLeftHandItemClick);
_btnLeftHandItem->onKeyboardPress((ActionHandler)&BattlescapeState::btnLeftHandItemClick, Options::keyBattleUseLeftHand);
_btnLeftHandItem->setTooltip("STR_USE_LEFT_HAND");
_btnLeftHandItem->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnLeftHandItem->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnRightHandItem->onMouseClick((ActionHandler)&BattlescapeState::btnRightHandItemClick);
_btnRightHandItem->onKeyboardPress((ActionHandler)&BattlescapeState::btnRightHandItemClick, Options::keyBattleUseRightHand);
_btnRightHandItem->setTooltip("STR_USE_RIGHT_HAND");
_btnRightHandItem->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnRightHandItem->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnReserveNone->onMouseClick((ActionHandler)&BattlescapeState::btnReserveClick);
_btnReserveNone->onKeyboardPress((ActionHandler)&BattlescapeState::btnReserveClick, Options::keyBattleReserveNone);
_btnReserveNone->setTooltip("STR_DONT_RESERVE_TIME_UNITS");
_btnReserveNone->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnReserveNone->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnReserveSnap->onMouseClick((ActionHandler)&BattlescapeState::btnReserveClick);
_btnReserveSnap->onKeyboardPress((ActionHandler)&BattlescapeState::btnReserveClick, Options::keyBattleReserveSnap);
_btnReserveSnap->setTooltip("STR_RESERVE_TIME_UNITS_FOR_SNAP_SHOT");
_btnReserveSnap->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnReserveSnap->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnReserveAimed->onMouseClick((ActionHandler)&BattlescapeState::btnReserveClick);
_btnReserveAimed->onKeyboardPress((ActionHandler)&BattlescapeState::btnReserveClick, Options::keyBattleReserveAimed);
_btnReserveAimed->setTooltip("STR_RESERVE_TIME_UNITS_FOR_AIMED_SHOT");
_btnReserveAimed->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnReserveAimed->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnReserveAuto->onMouseClick((ActionHandler)&BattlescapeState::btnReserveClick);
_btnReserveAuto->onKeyboardPress((ActionHandler)&BattlescapeState::btnReserveClick, Options::keyBattleReserveAuto);
_btnReserveAuto->setTooltip("STR_RESERVE_TIME_UNITS_FOR_AUTO_SHOT");
_btnReserveAuto->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnReserveAuto->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnReserveKneel->onMouseClick((ActionHandler)&BattlescapeState::btnReserveKneelClick);
_btnReserveKneel->onKeyboardPress((ActionHandler)&BattlescapeState::btnReserveKneelClick, Options::keyBattleReserveKneel);
_btnReserveKneel->setTooltip("STR_RESERVE_TIME_UNITS_FOR_KNEEL");
_btnReserveKneel->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnReserveKneel->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnReserveKneel->allowToggleInversion();
_btnZeroTUs->onMouseClick((ActionHandler)&BattlescapeState::btnZeroTUsClick, SDL_BUTTON_RIGHT);
_btnZeroTUs->onKeyboardPress((ActionHandler)&BattlescapeState::btnZeroTUsClick, Options::keyBattleZeroTUs);
_btnZeroTUs->setTooltip("STR_EXPEND_ALL_TIME_UNITS");
_btnZeroTUs->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnZeroTUs->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_btnZeroTUs->allowClickInversion();
// shortcuts without a specific button
_btnStats->onKeyboardPress((ActionHandler)&BattlescapeState::btnReloadClick, Options::keyBattleReload);
_btnStats->onKeyboardPress((ActionHandler)&BattlescapeState::btnPersonalLightingClick, Options::keyBattlePersonalLighting);
SDLKey buttons[] = {Options::keyBattleCenterEnemy1,
Options::keyBattleCenterEnemy2,
Options::keyBattleCenterEnemy3,
Options::keyBattleCenterEnemy4,
Options::keyBattleCenterEnemy5,
Options::keyBattleCenterEnemy6,
Options::keyBattleCenterEnemy7,
Options::keyBattleCenterEnemy8,
Options::keyBattleCenterEnemy9,
Options::keyBattleCenterEnemy10};
Uint8 color = _game->getMod()->getInterface("battlescape")->getElement("visibleUnits")->color;
for (int i = 0; i < VISIBLE_MAX; ++i)
{
std::ostringstream tooltip;
_btnVisibleUnit[i]->onMouseClick((ActionHandler)&BattlescapeState::btnVisibleUnitClick);
_btnVisibleUnit[i]->onKeyboardPress((ActionHandler)&BattlescapeState::btnVisibleUnitClick, buttons[i]);
tooltip << "STR_CENTER_ON_ENEMY_" << (i+1);
_btnVisibleUnit[i]->setTooltip(tooltip.str());
_btnVisibleUnit[i]->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
_btnVisibleUnit[i]->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
_numVisibleUnit[i]->setColor(color);
_numVisibleUnit[i]->setValue(i+1);
}
_warning->setColor(_game->getMod()->getInterface("battlescape")->getElement("warning")->color2);
_warning->setTextColor(_game->getMod()->getInterface("battlescape")->getElement("warning")->color);
_btnLaunch->onMouseClick((ActionHandler)&BattlescapeState::btnLaunchClick);
_btnPsi->onMouseClick((ActionHandler)&BattlescapeState::btnPsiClick);
_txtName->setHighContrast(true);
_barTimeUnits->setScale(1.0);
_barEnergy->setScale(1.0);
_barHealth->setScale(1.0);
_barMorale->setScale(1.0);
_txtDebug->setColor(Palette::blockOffset(8));
_txtDebug->setHighContrast(true);
_txtTooltip->setHighContrast(true);
_btnReserveNone->setGroup(&_reserve);
_btnReserveSnap->setGroup(&_reserve);
_btnReserveAimed->setGroup(&_reserve);
_btnReserveAuto->setGroup(&_reserve);
// Set music
if (_save->getMusic().empty())
{
_game->getMod()->playMusic("GMTACTIC");
}
else
{
_game->getMod()->playMusic(_save->getMusic());
}
_animTimer = new Timer(DEFAULT_ANIM_SPEED, true);
_animTimer->onTimer((StateHandler)&BattlescapeState::animate);
_gameTimer = new Timer(DEFAULT_ANIM_SPEED, true);
_gameTimer->onTimer((StateHandler)&BattlescapeState::handleState);
_battleGame = new BattlescapeGame(_save, this);
_barHealthColor = _barHealth->getColor();
}
/**
* Deletes the battlescapestate.
*/
BattlescapeState::~BattlescapeState()
{
delete _animTimer;
delete _gameTimer;
delete _battleGame;
}
/**
* Initializes the battlescapestate.
*/
void BattlescapeState::init()
{
if (_save->getAmbientSound() != -1)
{
_game->getMod()->getSoundByDepth(_save->getDepth(), _save->getAmbientSound())->loop();
_game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume);
}
State::init();
_animTimer->start();
_gameTimer->start();
_map->setFocus(true);
_map->cacheUnits();
_map->draw();
_battleGame->init();
updateSoldierInfo();
switch (_save->getTUReserved())
{
case BA_SNAPSHOT:
_reserve = _btnReserveSnap;
break;
case BA_AIMEDSHOT:
_reserve = _btnReserveAimed;
break;
case BA_AUTOSHOT:
_reserve = _btnReserveAuto;
break;
default:
_reserve = _btnReserveNone;
break;
}
if (_firstInit)
{
if (!playableUnitSelected())
{
selectNextPlayerUnit();
}
if (playableUnitSelected())
{
_battleGame->setupCursor();
_map->getCamera()->centerOnPosition(_save->getSelectedUnit()->getPosition());
}
_firstInit = false;
_btnReserveNone->setGroup(&_reserve);
_btnReserveSnap->setGroup(&_reserve);
_btnReserveAimed->setGroup(&_reserve);
_btnReserveAuto->setGroup(&_reserve);
}
_txtTooltip->setText("");
_btnReserveKneel->toggle(_save->getKneelReserved());
_battleGame->setKneelReserved(_save->getKneelReserved());
if (_autosave)
{
_autosave = false;
if (_game->getSavedGame()->isIronman())
{
_game->pushState(new SaveGameState(OPT_BATTLESCAPE, SAVE_IRONMAN, _palette));
}
else if (Options::autosave)
{
_game->pushState(new SaveGameState(OPT_BATTLESCAPE, SAVE_AUTO_BATTLESCAPE, _palette));
}
}
}
/**
* Runs the timers and handles popups.
*/
void BattlescapeState::think()
{
static bool popped = false;
if (_gameTimer->isRunning())
{
if (_popups.empty())
{
State::think();
_battleGame->think();
_animTimer->think(this, 0);
_gameTimer->think(this, 0);
if (popped)
{
_battleGame->handleNonTargetAction();
popped = false;
}
}
else
{
// Handle popups
_game->pushState(*_popups.begin());
_popups.erase(_popups.begin());
popped = true;
return;
}
}
}
/**
* Processes any mouse moving over the map.
* @param action Pointer to an action.
*/
void BattlescapeState::mapOver(Action *action)
{
if (_isMouseScrolling && action->getDetails()->type == SDL_MOUSEMOTION)
{
// The following is the workaround for a rare problem where sometimes
// the mouse-release event is missed for any reason.
// (checking: is the dragScroll-mouse-button still pressed?)
// However if the SDL is also missed the release event, then it is to no avail :(
if ((SDL_GetMouseState(0,0)&SDL_BUTTON(Options::battleDragScrollButton)) == 0)
{ // so we missed again the mouse-release :(
// Check if we have to revoke the scrolling, because it was too short in time, so it was a click
if ((!_mouseMovedOverThreshold) && ((int)(SDL_GetTicks() - _mouseScrollingStartTime) <= (Options::dragScrollTimeTolerance)))
{
_map->getCamera()->setMapOffset(_mapOffsetBeforeMouseScrolling);
}
_isMouseScrolled = _isMouseScrolling = false;
stopScrolling(action);
return;
}
_isMouseScrolled = true;
if (Options::touchEnabled == false)
{
// Set the mouse cursor back
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
SDL_WarpMouse(_game->getScreen()->getWidth() / 2, _game->getScreen()->getHeight() / 2 - _map->getIconHeight() / 2);
SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
}
// Check the threshold
_totalMouseMoveX += action->getDetails()->motion.xrel;
_totalMouseMoveY += action->getDetails()->motion.yrel;
if (!_mouseMovedOverThreshold)
{
_mouseMovedOverThreshold = ((std::abs(_totalMouseMoveX) > Options::dragScrollPixelTolerance) || (std::abs(_totalMouseMoveY) > Options::dragScrollPixelTolerance));
}
// Scrolling
if (Options::battleDragScrollInvert)
{
_map->getCamera()->setMapOffset(_mapOffsetBeforeMouseScrolling);
int scrollX = -(int)((double)_totalMouseMoveX / action->getXScale());
int scrollY = -(int)((double)_totalMouseMoveY / action->getYScale());
Position delta2 = _map->getCamera()->getMapOffset();
_map->getCamera()->scrollXY(scrollX, scrollY, true);
delta2 = _map->getCamera()->getMapOffset() - delta2;
// Keep the limits...
if (scrollX != delta2.x || scrollY != delta2.y)
{
_totalMouseMoveX = -(int) (delta2.x * action->getXScale());
_totalMouseMoveY = -(int) (delta2.y * action->getYScale());
}
if (Options::touchEnabled == false)
{
action->getDetails()->motion.x = _xBeforeMouseScrolling;
action->getDetails()->motion.y = _yBeforeMouseScrolling;
}
_map->setCursorType(CT_NONE);
}
else
{
Position delta = _map->getCamera()->getMapOffset();
_map->getCamera()->setMapOffset(_mapOffsetBeforeMouseScrolling);
int scrollX = (int)((double)_totalMouseMoveX / action->getXScale());
int scrollY = (int)((double)_totalMouseMoveY / action->getYScale());
Position delta2 = _map->getCamera()->getMapOffset();
_map->getCamera()->scrollXY(scrollX, scrollY, true);
delta2 = _map->getCamera()->getMapOffset() - delta2;
delta = _map->getCamera()->getMapOffset() - delta;
// Keep the limits...
if (scrollX != delta2.x || scrollY != delta2.y)
{
_totalMouseMoveX = (int) (delta2.x * action->getXScale());
_totalMouseMoveY = (int) (delta2.y * action->getYScale());
}
int barWidth = _game->getScreen()->getCursorLeftBlackBand();
int barHeight = _game->getScreen()->getCursorTopBlackBand();
int cursorX = _cursorPosition.x + Round(delta.x * action->getXScale());
int cursorY = _cursorPosition.y + Round(delta.y * action->getYScale());
_cursorPosition.x = Clamp(cursorX, barWidth, _game->getScreen()->getWidth() - barWidth - (int)(Round(action->getXScale())));
_cursorPosition.y = Clamp(cursorY, barHeight, _game->getScreen()->getHeight() - barHeight - (int)(Round(action->getYScale())));
if (Options::touchEnabled == false)
{
action->getDetails()->motion.x = _cursorPosition.x;
action->getDetails()->motion.y = _cursorPosition.y;
}
}
// We don't want to look the mouse-cursor jumping :)
_game->getCursor()->handle(action);
}
}
/**
* Processes any presses on the map.
* @param action Pointer to an action.
*/
void BattlescapeState::mapPress(Action *action)
{
// don't handle mouseclicks over the buttons (it overlaps with map surface)
if (_mouseOverIcons) return;
if (action->getDetails()->button.button == Options::battleDragScrollButton)
{
_isMouseScrolling = true;
_isMouseScrolled = false;
SDL_GetMouseState(&_xBeforeMouseScrolling, &_yBeforeMouseScrolling);
_mapOffsetBeforeMouseScrolling = _map->getCamera()->getMapOffset();
if (!Options::battleDragScrollInvert && _cursorPosition.z == 0)
{
_cursorPosition.x = action->getDetails()->motion.x;
_cursorPosition.y = action->getDetails()->motion.y;
// the Z is irrelevant to our mouse position, but we can use it as a boolean to check if the position is set or not
_cursorPosition.z = 1;
}
_totalMouseMoveX = 0; _totalMouseMoveY = 0;
_mouseMovedOverThreshold = false;
_mouseScrollingStartTime = SDL_GetTicks();
}
}
/**
* Processes any clicks on the map to
* command units.
* @param action Pointer to an action.
*/
void BattlescapeState::mapClick(Action *action)
{
// The following is the workaround for a rare problem where sometimes
// the mouse-release event is missed for any reason.
// However if the SDL is also missed the release event, then it is to no avail :(
// (this part handles the release if it is missed and now an other button is used)
if (_isMouseScrolling)
{
if (action->getDetails()->button.button != Options::battleDragScrollButton
&& (SDL_GetMouseState(0,0)&SDL_BUTTON(Options::battleDragScrollButton)) == 0)
{ // so we missed again the mouse-release :(
// Check if we have to revoke the scrolling, because it was too short in time, so it was a click
if ((!_mouseMovedOverThreshold) && ((int)(SDL_GetTicks() - _mouseScrollingStartTime) <= (Options::dragScrollTimeTolerance)))
{
_map->getCamera()->setMapOffset(_mapOffsetBeforeMouseScrolling);
}
_isMouseScrolled = _isMouseScrolling = false;
stopScrolling(action);
}
}
// DragScroll-Button release: release mouse-scroll-mode
if (_isMouseScrolling)
{
// While scrolling, other buttons are ineffective
if (action->getDetails()->button.button == Options::battleDragScrollButton)
{
_isMouseScrolling = false;
stopScrolling(action);
}
else
{
return;
}
// Check if we have to revoke the scrolling, because it was too short in time, so it was a click
if ((!_mouseMovedOverThreshold) && ((int)(SDL_GetTicks() - _mouseScrollingStartTime) <= (Options::dragScrollTimeTolerance)))
{
_isMouseScrolled = false;
stopScrolling(action);
}
if (_isMouseScrolled) return;
}
// right-click aborts walking state
if (action->getDetails()->button.button == SDL_BUTTON_RIGHT)
{
if (_battleGame->cancelCurrentAction())
{
return;
}
}
// don't handle mouseclicks over the buttons (it overlaps with map surface)
if (_mouseOverIcons) return;
// don't accept leftclicks if there is no cursor or there is an action busy
if (_map->getCursorType() == CT_NONE || _battleGame->isBusy()) return;
Position pos;
_map->getSelectorPosition(&pos);
if (_save->getDebugMode())
{
std::ostringstream ss;
ss << "Clicked " << pos;
debug(ss.str());
}
if (_save->getTile(pos) != 0) // don't allow to click into void
{
if ((action->getDetails()->button.button == SDL_BUTTON_RIGHT || (action->getDetails()->button.button == SDL_BUTTON_LEFT && (SDL_GetModState() & KMOD_ALT) != 0)) && playableUnitSelected())
{
_battleGame->secondaryAction(pos);
}
else if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
{
_battleGame->primaryAction(pos);
}
}
}
/**
* Handles mouse entering the map surface.
* @param action Pointer to an action.
*/
void BattlescapeState::mapIn(Action *)
{
_isMouseScrolling = false;
_map->setButtonsPressed(Options::battleDragScrollButton, false);
}
/**
* Moves the selected unit up.
* @param action Pointer to an action.
*/
void BattlescapeState::btnUnitUpClick(Action *)
{
if (playableUnitSelected() && _save->getPathfinding()->validateUpDown(_save->getSelectedUnit(), _save->getSelectedUnit()->getPosition(), Pathfinding::DIR_UP))
{
_battleGame->cancelAllActions();
_battleGame->moveUpDown(_save->getSelectedUnit(), Pathfinding::DIR_UP);
}
}
/**
* Moves the selected unit down.
* @param action Pointer to an action.
*/
void BattlescapeState::btnUnitDownClick(Action *)
{
if (playableUnitSelected() && _save->getPathfinding()->validateUpDown(_save->getSelectedUnit(), _save->getSelectedUnit()->getPosition(), Pathfinding::DIR_DOWN))
{
_battleGame->cancelAllActions();
_battleGame->moveUpDown(_save->getSelectedUnit(), Pathfinding::DIR_DOWN);
}
}
/**
* Shows the next map layer.
* @param action Pointer to an action.
*/
void BattlescapeState::btnMapUpClick(Action *)
{
if (_save->getSide() == FACTION_PLAYER || _save->getDebugMode())
_map->getCamera()->up();
}
/**
* Shows the previous map layer.
* @param action Pointer to an action.
*/
void BattlescapeState::btnMapDownClick(Action *)
{
if (_save->getSide() == FACTION_PLAYER || _save->getDebugMode())
_map->getCamera()->down();
}
/**
* Shows the minimap.
* @param action Pointer to an action.
*/
void BattlescapeState::btnShowMapClick(Action *)
{
//MiniMapState
if (allowButtons())
_game->pushState (new MiniMapState (_map->getCamera(), _save));
}
void BattlescapeState::toggleKneelButton(BattleUnit* unit)
{
if (_btnKneel->isTFTDMode())
{
_btnKneel->toggle(unit && unit->isKneeled());
}
else
{
_game->getMod()->getSurfaceSet("KneelButton")->getFrame((unit && unit->isKneeled()) ? 1 : 0)->blit(_btnKneel);
}
}
/**
* Toggles the current unit's kneel/standup status.
* @param action Pointer to an action.
*/
void BattlescapeState::btnKneelClick(Action *)
{
if (allowButtons())
{
BattleUnit *bu = _save->getSelectedUnit();
if (bu)
{
_battleGame->kneel(bu);
toggleKneelButton(bu);
// update any path preview when unit kneels
if (_battleGame->getPathfinding()->isPathPreviewed())
{
_battleGame->getPathfinding()->calculate(_battleGame->getCurrentAction()->actor, _battleGame->getCurrentAction()->target);
_battleGame->getPathfinding()->removePreview();
_battleGame->getPathfinding()->previewPath();
}
}
}
}
/**
* Goes to the soldier info screen.
* Additionally resets TUs for current side in debug mode.
* @param action Pointer to an action.
*/
void BattlescapeState::btnInventoryClick(Action *)
{
if (_save->getDebugMode())
{
for (std::vector<BattleUnit*>::iterator i = _save->getUnits()->begin(); i != _save->getUnits()->end(); ++i)
if ((*i)->getFaction() == _save->getSide())
(*i)->prepareNewTurn();
updateSoldierInfo();
}
if (playableUnitSelected()
&& (_save->getSelectedUnit()->hasInventory() || _save->getDebugMode()))
{
_battleGame->cancelAllActions();
_game->pushState(new InventoryState(!_save->getDebugMode(), this));
}
}
/**
* Centers on the currently selected soldier.
* @param action Pointer to an action.
*/
void BattlescapeState::btnCenterClick(Action *)
{
if (playableUnitSelected())
{
_map->getCamera()->centerOnPosition(_save->getSelectedUnit()->getPosition());
_map->refreshSelectorPosition();
}
}
/**
* Selects the next soldier.
* @param action Pointer to an action.
*/
void BattlescapeState::btnNextSoldierClick(Action *)
{
if (allowButtons())
{
selectNextPlayerUnit(true, false);
_map->refreshSelectorPosition();
}
}
/**
* Disables reselection of the current soldier and selects the next soldier.
* @param action Pointer to an action.
*/
void BattlescapeState::btnNextStopClick(Action *)
{
if (allowButtons())
{
selectNextPlayerUnit(true, true);
_map->refreshSelectorPosition();
}
}
/**
* Selects next soldier.
* @param action Pointer to an action.
*/
void BattlescapeState::btnPrevSoldierClick(Action *)
{
if (allowButtons())
{
selectPreviousPlayerUnit(true);
_map->refreshSelectorPosition();
}
}
/**
* Selects the next soldier.
* @param checkReselect When true, don't select a unit that has been previously flagged.
* @param setReselect When true, flag the current unit first.
* @param checkInventory When true, don't select a unit that has no inventory.
*/
void BattlescapeState::selectNextPlayerUnit(bool checkReselect, bool setReselect, bool checkInventory, bool checkFOV)
{
if (allowButtons())
{
BattleUnit *unit = _save->selectNextPlayerUnit(checkReselect, setReselect, checkInventory);
updateSoldierInfo(checkFOV);
if (unit) _map->getCamera()->centerOnPosition(unit->getPosition());
_battleGame->cancelAllActions();
_battleGame->getCurrentAction()->actor = unit;