forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 81
/
DebriefingState.cpp
2233 lines (2075 loc) · 71.3 KB
/
DebriefingState.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 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 <climits>
#include "DebriefingState.h"
#include "CannotReequipState.h"
#include "../Engine/Action.h"
#include "../Engine/Game.h"
#include "../Engine/LocalizedText.h"
#include "../Interface/TextButton.h"
#include "../Interface/Text.h"
#include "../Interface/TextList.h"
#include "../Interface/Window.h"
#include "PromotionsState.h"
#include "CommendationState.h"
#include "CommendationLateState.h"
#include "../Mod/Mod.h"
#include "../Mod/RuleCountry.h"
#include "../Mod/RuleCraft.h"
#include "../Mod/RuleItem.h"
#include "../Mod/RuleRegion.h"
#include "../Mod/RuleSoldier.h"
#include "../Mod/RuleUfo.h"
#include "../Mod/Armor.h"
#include "../Savegame/AlienBase.h"
#include "../Savegame/AlienMission.h"
#include "../Savegame/Base.h"
#include "../Savegame/BattleItem.h"
#include "../Savegame/Country.h"
#include "../Savegame/Craft.h"
#include "../Savegame/ItemContainer.h"
#include "../Savegame/Region.h"
#include "../Savegame/SavedBattleGame.h"
#include "../Savegame/Soldier.h"
#include "../Savegame/SoldierDiary.h"
#include "../Savegame/MissionSite.h"
#include "../Savegame/Tile.h"
#include "../Savegame/Ufo.h"
#include "../Savegame/Vehicle.h"
#include "../Savegame/BaseFacility.h"
#include <sstream>
#include "../Menu/ErrorMessageState.h"
#include "../Menu/MainMenuState.h"
#include "../Interface/Cursor.h"
#include "../Engine/Options.h"
#include "../Engine/RNG.h"
#include "../Basescape/ManageAlienContainmentState.h"
#include "../Engine/Screen.h"
#include "../Basescape/SellState.h"
#include "../Menu/SaveGameState.h"
#include "../Mod/RuleStartingCondition.h"
#include "../Mod/AlienDeployment.h"
#include "../Mod/RuleInterface.h"
#include "../Savegame/MissionStatistics.h"
#include "../Savegame/BattleUnitStatistics.h"
namespace OpenXcom
{
/**
* Initializes all the elements in the Debriefing screen.
* @param game Pointer to the core game.
*/
DebriefingState::DebriefingState() : _region(0), _country(0), _positiveScore(true), _destroyBase(false), _showSellButton(true), _pageNumber(0)
{
_missionStatistics = new MissionStatistics();
Options::baseXResolution = Options::baseXGeoscape;
Options::baseYResolution = Options::baseYGeoscape;
_game->getScreen()->resetDisplay(false);
// Restore the cursor in case something weird happened
_game->getCursor()->setVisible(true);
_limitsEnforced = Options::storageLimitsEnforced ? 1 : 0;
// Create objects
_window = new Window(this, 320, 200, 0, 0);
_btnOk = new TextButton(40, 12, 16, 180);
_btnStats = new TextButton(60, 12, 244, 180);
_btnSell = new TextButton(60, 12, 176, 180);
_txtTitle = new Text(300, 17, 16, 8);
_txtItem = new Text(180, 9, 16, 24);
_txtQuantity = new Text(60, 9, 200, 24);
_txtScore = new Text(55, 9, 270, 24);
_txtRecovery = new Text(180, 9, 16, 60);
_txtRating = new Text(200, 9, 64, 180);
_lstStats = new TextList(290, 80, 16, 32);
_lstRecovery = new TextList(290, 80, 16, 32);
_lstTotal = new TextList(290, 9, 16, 12);
// Second page (soldier stats)
_txtSoldier = new Text(90, 9, 16, 24); //16..106 = 90
_txtTU = new Text(18, 9, 106, 24); //106
_txtStamina = new Text(18, 9, 124, 24); //124
_txtHealth = new Text(18, 9, 142, 24); //142
_txtBravery = new Text(18, 9, 160, 24); //160
_txtReactions = new Text(18, 9, 178, 24); //178
_txtFiring = new Text(18, 9, 196, 24); //196
_txtThrowing = new Text(18, 9, 214, 24); //214
_txtMelee = new Text(18, 9, 232, 24); //232
_txtStrength = new Text(18, 9, 250, 24); //250
_txtPsiStrength = new Text(18, 9, 268, 24); //268
_txtPsiSkill = new Text(18, 9, 286, 24); //286..304 = 18
_lstSoldierStats = new TextList(288, 144, 16, 32); // 18 rows
_txtTooltip = new Text(200, 9, 64, 180);
// Third page (recovered items)
_lstRecoveredItems = new TextList(272, 144, 16, 32); // 18 rows
applyVisibility();
// Set palette
setInterface("debriefing");
_ammoColor = _game->getMod()->getInterface("debriefing")->getElement("totals")->color;
add(_window, "window", "debriefing");
add(_btnOk, "button", "debriefing");
add(_btnStats, "button", "debriefing");
add(_btnSell, "button", "debriefing");
add(_txtTitle, "heading", "debriefing");
add(_txtItem, "text", "debriefing");
add(_txtQuantity, "text", "debriefing");
add(_txtScore, "text", "debriefing");
add(_txtRecovery, "text", "debriefing");
add(_txtRating, "text", "debriefing");
add(_lstStats, "list", "debriefing");
add(_lstRecovery, "list", "debriefing");
add(_lstTotal, "totals", "debriefing");
add(_txtSoldier, "text", "debriefing");
add(_txtTU, "text", "debriefing");
add(_txtStamina, "text", "debriefing");
add(_txtHealth, "text", "debriefing");
add(_txtBravery, "text", "debriefing");
add(_txtReactions, "text", "debriefing");
add(_txtFiring, "text", "debriefing");
add(_txtThrowing, "text", "debriefing");
add(_txtMelee, "text", "debriefing");
add(_txtStrength, "text", "debriefing");
add(_txtPsiStrength, "text", "debriefing");
add(_txtPsiSkill, "text", "debriefing");
add(_lstSoldierStats, "list", "debriefing");
add(_txtTooltip, "text", "debriefing");
add(_lstRecoveredItems, "list", "debriefing");
centerAllSurfaces();
// Set up objects
_window->setBackground(_game->getMod()->getSurface("BACK01.SCR"));
_btnOk->setText(tr("STR_OK"));
_btnOk->onMouseClick((ActionHandler)&DebriefingState::btnOkClick);
_btnOk->onKeyboardPress((ActionHandler)&DebriefingState::btnOkClick, Options::keyOk);
_btnOk->onKeyboardPress((ActionHandler)&DebriefingState::btnOkClick, Options::keyCancel);
_btnStats->onMouseClick((ActionHandler)&DebriefingState::btnStatsClick);
_btnSell->setText(tr("STR_SELL"));
_btnSell->onMouseClick((ActionHandler)&DebriefingState::btnSellClick);
_txtTitle->setBig();
_txtItem->setText(tr("STR_LIST_ITEM"));
_txtQuantity->setText(tr("STR_QUANTITY_UC"));
_txtQuantity->setAlign(ALIGN_RIGHT);
_txtScore->setText(tr("STR_SCORE"));
_lstStats->setColumns(3, 224, 30, 64);
_lstStats->setDot(true);
_lstRecovery->setColumns(3, 224, 30, 64);
_lstRecovery->setDot(true);
_lstTotal->setColumns(2, 254, 64);
_lstTotal->setDot(true);
// Second page
_txtSoldier->setText(tr("STR_NAME_UC"));
_txtTU->setAlign(ALIGN_CENTER);
_txtTU->setText(tr("STR_TIME_UNITS_ABBREVIATION"));
_txtTU->setTooltip("STR_TIME_UNITS");
_txtTU->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtTU->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtStamina->setAlign(ALIGN_CENTER);
_txtStamina->setText(tr("STR_STAMINA_ABBREVIATION"));
_txtStamina->setTooltip("STR_STAMINA");
_txtStamina->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtStamina->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtHealth->setAlign(ALIGN_CENTER);
_txtHealth->setText(tr("STR_HEALTH_ABBREVIATION"));
_txtHealth->setTooltip("STR_HEALTH");
_txtHealth->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtHealth->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtBravery->setAlign(ALIGN_CENTER);
_txtBravery->setText(tr("STR_BRAVERY_ABBREVIATION"));
_txtBravery->setTooltip("STR_BRAVERY");
_txtBravery->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtBravery->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtReactions->setAlign(ALIGN_CENTER);
_txtReactions->setText(tr("STR_REACTIONS_ABBREVIATION"));
_txtReactions->setTooltip("STR_REACTIONS");
_txtReactions->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtReactions->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtFiring->setAlign(ALIGN_CENTER);
_txtFiring->setText(tr("STR_FIRING_ACCURACY_ABBREVIATION"));
_txtFiring->setTooltip("STR_FIRING_ACCURACY");
_txtFiring->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtFiring->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtThrowing->setAlign(ALIGN_CENTER);
_txtThrowing->setText(tr("STR_THROWING_ACCURACY_ABBREVIATION"));
_txtThrowing->setTooltip("STR_THROWING_ACCURACY");
_txtThrowing->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtThrowing->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtMelee->setAlign(ALIGN_CENTER);
_txtMelee->setText(tr("STR_MELEE_ACCURACY_ABBREVIATION"));
_txtMelee->setTooltip("STR_MELEE_ACCURACY");
_txtMelee->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtMelee->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtStrength->setAlign(ALIGN_CENTER);
_txtStrength->setText(tr("STR_STRENGTH_ABBREVIATION"));
_txtStrength->setTooltip("STR_STRENGTH");
_txtStrength->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtStrength->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtPsiStrength->setAlign(ALIGN_CENTER);
_txtPsiStrength->setText(tr("STR_PSIONIC_STRENGTH_ABBREVIATION"));
_txtPsiStrength->setTooltip("STR_PSIONIC_STRENGTH");
_txtPsiStrength->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtPsiStrength->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_txtPsiSkill->setAlign(ALIGN_CENTER);
_txtPsiSkill->setText(tr("STR_PSIONIC_SKILL_ABBREVIATION"));
_txtPsiSkill->setTooltip("STR_PSIONIC_SKILL");
_txtPsiSkill->onMouseIn((ActionHandler)&DebriefingState::txtTooltipIn);
_txtPsiSkill->onMouseOut((ActionHandler)&DebriefingState::txtTooltipOut);
_lstSoldierStats->setColumns(13, 90, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 0);
_lstSoldierStats->setAlign(ALIGN_CENTER);
_lstSoldierStats->setAlign(ALIGN_LEFT, 0);
_lstSoldierStats->setDot(true);
// Third page
_lstRecoveredItems->setColumns(2, 254, 18);
_lstRecoveredItems->setAlign(ALIGN_LEFT);
_lstRecoveredItems->setDot(true);
prepareDebriefing();
for (std::vector<SoldierStatsEntry>::iterator i = _soldierStats.begin(); i != _soldierStats.end(); ++i)
{
_lstSoldierStats->addRow(13, (*i).first.c_str(),
makeSoldierString((*i).second.tu).c_str(),
makeSoldierString((*i).second.stamina).c_str(),
makeSoldierString((*i).second.health).c_str(),
makeSoldierString((*i).second.bravery).c_str(),
makeSoldierString((*i).second.reactions).c_str(),
makeSoldierString((*i).second.firing).c_str(),
makeSoldierString((*i).second.throwing).c_str(),
makeSoldierString((*i).second.melee).c_str(),
makeSoldierString((*i).second.strength).c_str(),
makeSoldierString((*i).second.psiStrength).c_str(),
makeSoldierString((*i).second.psiSkill).c_str(),
L"");
// note: final dummy element to cause dot filling until the end of the line
}
// compare stuff from after and before recovery
if (_base)
{
int row = 0;
ItemContainer *origBaseItems = _game->getSavedGame()->getSavedBattle()->getBaseStorageItems();
const std::vector<std::string> &items = _game->getMod()->getItemsList();
for (std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i)
{
int qty = _base->getStorageItems()->getItem(*i);
if (qty > 0 && (Options::canSellLiveAliens || !_game->getMod()->getItem(*i)->isAlien()))
{
RuleItem *rule = _game->getMod()->getItem(*i);
// IGNORE vehicles and their ammo
// Note: because their number in base has been messed up by Base::setupDefenses() already in geoscape :(
if (_game->getMod()->getUnit(*i) && !rule->isAlien())
{
// if this vehicle requires ammo, remember to ignore it later too
if (!rule->getPrimaryCompatibleAmmo()->empty())
{
origBaseItems->addItem(rule->getPrimaryCompatibleAmmo()->front(), 1000000);
}
continue;
}
qty -= origBaseItems->getItem(*i);
_recoveredItems[rule] = qty;
if (qty > 0)
{
std::wostringstream ss;
ss << L'\x01' << qty << L'\x01';
std::wstring item = tr(*i);
if (rule->getBattleType() == BT_AMMO || (rule->getBattleType() == BT_NONE && rule->getClipSize() > 0))
{
item.insert(0, L" ");
_lstRecoveredItems->addRow(2, item.c_str(), ss.str().c_str());
_lstRecoveredItems->setRowColor(row, _ammoColor);
}
else
{
_lstRecoveredItems->addRow(2, item.c_str(), ss.str().c_str());
}
++row;
}
}
}
}
int total = 0, statsY = 0, recoveryY = 0;
int civiliansSaved = 0, civiliansDead = 0;
int aliensKilled = 0, aliensStunned = 0;
for (std::vector<DebriefingStat*>::iterator i = _stats.begin(); i != _stats.end(); ++i)
{
if ((*i)->qty == 0)
continue;
std::wostringstream ss, ss2;
ss << L'\x01' << (*i)->qty << L'\x01';
ss2 << L'\x01' << (*i)->score;
total += (*i)->score;
if ((*i)->recovery)
{
_lstRecovery->addRow(3, tr((*i)->item).c_str(), ss.str().c_str(), ss2.str().c_str());
recoveryY += 8;
}
else
{
_lstStats->addRow(3, tr((*i)->item).c_str(), ss.str().c_str(), ss2.str().c_str());
statsY += 8;
}
if ((*i)->item == "STR_CIVILIANS_SAVED")
{
civiliansSaved = (*i)->qty;
}
if ((*i)->item == "STR_CIVILIANS_KILLED_BY_XCOM_OPERATIVES" || (*i)->item == "STR_CIVILIANS_KILLED_BY_ALIENS")
{
civiliansDead += (*i)->qty;
}
if ((*i)->item == "STR_ALIENS_KILLED")
{
aliensKilled += (*i)->qty;
}
if ((*i)->item == "STR_LIVE_ALIENS_RECOVERED")
{
aliensStunned += (*i)->qty;
}
}
if (civiliansSaved && !civiliansDead && _missionStatistics->success == true)
{
_missionStatistics->valiantCrux = true;
}
std::wostringstream ss3;
ss3 << total;
_lstTotal->addRow(2, tr("STR_TOTAL_UC").c_str(), ss3.str().c_str());
// add the points to our activity score
if (_region)
{
_region->addActivityXcom(total);
}
if (_country)
{
_country->addActivityXcom(total);
}
if (recoveryY > 0)
{
if (_txtRecovery->getText().empty())
{
_txtRecovery->setText(tr("STR_BOUNTY"));
}
_txtRecovery->setY(_lstStats->getY() + statsY + 5);
_lstRecovery->setY(_txtRecovery->getY() + 8);
_lstTotal->setY(_lstRecovery->getY() + recoveryY + 5);
}
else
{
_txtRecovery->setText(L"");
_lstTotal->setY(_lstStats->getY() + statsY + 5);
}
// Calculate rating
std::string rating;
if (total <= -200)
{
rating = "STR_RATING_TERRIBLE";
}
else if (total <= 0)
{
rating = "STR_RATING_POOR";
}
else if (total <= 200)
{
rating = "STR_RATING_OK";
}
else if (total <= 500)
{
rating = "STR_RATING_GOOD";
}
else
{
rating = "STR_RATING_EXCELLENT";
}
if (!_game->getMod()->getMissionRatings()->empty())
{
rating = "";
int temp = INT_MIN;
const std::map<int, std::string> *missionRatings = _game->getMod()->getMissionRatings();
for (std::map<int, std::string>::const_iterator i = missionRatings->begin(); i != missionRatings->end(); ++i)
{
if (i->first > temp && i->first <= total)
{
temp = i->first;
rating = i->second;
}
}
}
_missionStatistics->rating = rating;
_missionStatistics->score = total;
_txtRating->setText(tr("STR_RATING").arg(tr(rating)));
SavedGame *save = _game->getSavedGame();
SavedBattleGame *battle = save->getSavedBattle();
_missionStatistics->daylight = save->getSavedBattle()->getGlobalShade();
_missionStatistics->id = _game->getSavedGame()->getMissionStatistics()->size();
_game->getSavedGame()->getMissionStatistics()->push_back(_missionStatistics);
// Award Best-of commendations.
int bestScoreID[7] = {0, 0, 0, 0, 0, 0, 0};
int bestScore[7] = {0, 0, 0, 0, 0, 0, 0};
int bestOverallScorersID = 0;
int bestOverallScore = 0;
// Check to see if any of the dead soldiers were exceptional.
for (std::vector<BattleUnit*>::iterator deadUnit = battle->getUnits()->begin(); deadUnit != battle->getUnits()->end(); ++deadUnit)
{
if (!(*deadUnit)->getGeoscapeSoldier() || (*deadUnit)->getStatus() != STATUS_DEAD)
{
continue;
}
/// Post-mortem kill award
int killTurn = -1;
for (std::vector<BattleUnit*>::iterator killerUnit = battle->getUnits()->begin(); killerUnit != battle->getUnits()->end(); ++killerUnit)
{
for(std::vector<BattleUnitKills*>::iterator kill = (*killerUnit)->getStatistics()->kills.begin(); kill != (*killerUnit)->getStatistics()->kills.end(); ++kill)
{
if ((*kill)->id == (*deadUnit)->getId())
{
killTurn = (*kill)->turn;
break;
}
}
if (killTurn != -1)
{
break;
}
}
int postMortemKills = 0;
if (killTurn != -1)
{
for(std::vector<BattleUnitKills*>::iterator deadUnitKill = (*deadUnit)->getStatistics()->kills.begin(); deadUnitKill != (*deadUnit)->getStatistics()->kills.end(); ++deadUnitKill)
{
if ((*deadUnitKill)->turn > killTurn && (*deadUnitKill)->faction == FACTION_HOSTILE)
{
postMortemKills++;
}
}
}
(*deadUnit)->getGeoscapeSoldier()->getDiary()->awardPostMortemKill(postMortemKills);
SoldierRank rank = (*deadUnit)->getGeoscapeSoldier()->getRank();
// Rookies don't get this next award. No one likes them.
if (rank == 0)
{
continue;
}
/// Best-of awards
// Find the best soldier per rank by comparing score.
for (std::vector<Soldier*>::iterator j = _game->getSavedGame()->getDeadSoldiers()->begin(); j != _game->getSavedGame()->getDeadSoldiers()->end(); ++j)
{
int score = (*j)->getDiary()->getScoreTotal(_game->getSavedGame()->getMissionStatistics());
// Don't forget this mission's score!
if ((*j)->getId() == (*deadUnit)->getId())
{
score += _missionStatistics->score;
}
if (score > bestScore[rank])
{
bestScoreID[rank] = (*deadUnit)->getId();
bestScore[rank] = score;
if (score > bestOverallScore)
{
bestOverallScorersID = (*deadUnit)->getId();
bestOverallScore = score;
}
}
}
}
// Now award those soldiers commendations!
for (std::vector<BattleUnit*>::iterator deadUnit = battle->getUnits()->begin(); deadUnit != battle->getUnits()->end(); ++deadUnit)
{
if (!(*deadUnit)->getGeoscapeSoldier() || (*deadUnit)->getStatus() != STATUS_DEAD)
{
continue;
}
if ((*deadUnit)->getId() == bestScoreID[(*deadUnit)->getGeoscapeSoldier()->getRank()])
{
(*deadUnit)->getGeoscapeSoldier()->getDiary()->awardBestOfRank(bestScore[(*deadUnit)->getGeoscapeSoldier()->getRank()]);
}
if ((*deadUnit)->getId() == bestOverallScorersID)
{
(*deadUnit)->getGeoscapeSoldier()->getDiary()->awardBestOverall(bestOverallScore);
}
}
for (std::vector<BattleUnit*>::iterator j = battle->getUnits()->begin(); j != battle->getUnits()->end(); ++j)
{
if ((*j)->getGeoscapeSoldier())
{
int soldierAlienKills = 0;
int soldierAlienStuns = 0;
for (std::vector<BattleUnitKills*>::const_iterator k = (*j)->getStatistics()->kills.begin(); k != (*j)->getStatistics()->kills.end(); ++k)
{
if ((*k)->faction == FACTION_HOSTILE && (*k)->status == STATUS_DEAD)
{
soldierAlienKills++;
}
if ((*k)->faction == FACTION_HOSTILE && (*k)->status == STATUS_UNCONSCIOUS)
{
soldierAlienStuns++;
}
}
if (aliensKilled && aliensKilled == soldierAlienKills && _missionStatistics->success == true)
{
(*j)->getStatistics()->nikeCross = true;
}
if (aliensStunned && aliensStunned == soldierAlienStuns && _missionStatistics->success == true)
{
(*j)->getStatistics()->mercyCross = true;
}
(*j)->getStatistics()->daysWounded = (*j)->getGeoscapeSoldier()->getWoundRecovery(0.0f, 0.0f);
_missionStatistics->injuryList[(*j)->getGeoscapeSoldier()->getId()] = (*j)->getGeoscapeSoldier()->getWoundRecovery(0.0f, 0.0f);
// Award Martyr Medal
if ((*j)->getMurdererId() == (*j)->getId() && (*j)->getStatistics()->kills.size() != 0)
{
int martyrKills = 0; // How many aliens were killed on the same turn?
int martyrTurn = -1;
for (std::vector<BattleUnitKills*>::iterator unitKill = (*j)->getStatistics()->kills.begin(); unitKill != (*j)->getStatistics()->kills.end(); ++unitKill)
{
if ( (*unitKill)->id == (*j)->getId() )
{
martyrTurn = (*unitKill)->turn;
break;
}
}
for (std::vector<BattleUnitKills*>::iterator unitKill = (*j)->getStatistics()->kills.begin(); unitKill != (*j)->getStatistics()->kills.end(); ++unitKill)
{
if ((*unitKill)->turn == martyrTurn && (*unitKill)->faction == FACTION_HOSTILE)
{
martyrKills++;
}
}
if (martyrKills > 0)
{
if (martyrKills > 10)
{
martyrKills = 10;
}
(*j)->getStatistics()->martyr = martyrKills;
}
}
// Set the UnitStats delta
(*j)->getStatistics()->delta = *(*j)->getGeoscapeSoldier()->getCurrentStats() - *(*j)->getGeoscapeSoldier()->getInitStats();
(*j)->getGeoscapeSoldier()->getDiary()->updateDiary((*j)->getStatistics(), _game->getSavedGame()->getMissionStatistics(), _game->getMod());
if (!(*j)->getStatistics()->MIA && !(*j)->getStatistics()->KIA && (*j)->getGeoscapeSoldier()->getDiary()->manageCommendations(_game->getMod(), _game->getSavedGame()->getMissionStatistics()))
{
_soldiersCommended.push_back((*j)->getGeoscapeSoldier());
}
else if ((*j)->getStatistics()->MIA || (*j)->getStatistics()->KIA)
{
(*j)->getGeoscapeSoldier()->getDiary()->manageCommendations(_game->getMod(), _game->getSavedGame()->getMissionStatistics());
_deadSoldiersCommended.push_back((*j)->getGeoscapeSoldier());
}
}
}
_positiveScore = (total > 0);
}
/**
*
*/
DebriefingState::~DebriefingState()
{
if (_game->isQuitting())
{
_game->getSavedGame()->setBattleGame(0);
}
for (std::vector<DebriefingStat*>::iterator i = _stats.begin(); i != _stats.end(); ++i)
{
delete *i;
}
for (std::map<int, RecoveryItem*>::iterator i = _recoveryStats.begin(); i != _recoveryStats.end(); ++i)
{
delete i->second;
}
_recoveryStats.clear();
_rounds.clear();
_roundsPainKiller.clear();
_roundsStimulant.clear();
_roundsHeal.clear();
_recoveredItems.clear();
}
std::wstring DebriefingState::makeSoldierString(int stat)
{
if (stat == 0) return L"";
std::wostringstream ss;
ss << L'\x01' << L'+' << stat << L'\x01';
return ss.str();
}
void DebriefingState::applyVisibility()
{
bool showScore = _pageNumber == 0;
bool showStats = _pageNumber == 1;
bool showItems = _pageNumber == 2;
// First page (scores)
_txtItem->setVisible(showScore || showItems);
_txtQuantity->setVisible(showScore);
_txtScore->setVisible(showScore);
_txtRecovery->setVisible(showScore);
_txtRating->setVisible(showScore);
_lstStats->setVisible(showScore);
_lstRecovery->setVisible(showScore);
_lstTotal->setVisible(showScore);
// Second page (soldier stats)
_txtSoldier->setVisible(showStats);
_txtTU->setVisible(showStats);
_txtStamina->setVisible(showStats);
_txtHealth->setVisible(showStats);
_txtBravery->setVisible(showStats);
_txtReactions->setVisible(showStats);
_txtFiring->setVisible(showStats);
_txtThrowing->setVisible(showStats);
_txtMelee->setVisible(showStats);
_txtStrength->setVisible(showStats);
_txtPsiStrength->setVisible(showStats);
_txtPsiSkill->setVisible(showStats);
_lstSoldierStats->setVisible(showStats);
_txtTooltip->setVisible(showStats);
// Third page (recovered items)
_lstRecoveredItems->setVisible(showItems);
// Set text on toggle button accordingly
_btnSell->setVisible(showItems && _showSellButton);
if (showScore)
{
_btnStats->setText(tr("STR_STATS"));
}
else if (showStats)
{
_btnStats->setText(tr("STR_LOOT"));
}
else if (showItems)
{
_btnStats->setText(tr("STR_SCORE"));
}
}
void DebriefingState::init()
{
State::init();
if (_positiveScore)
{
_game->getMod()->playMusic(Mod::DEBRIEF_MUSIC_GOOD);
}
else
{
_game->getMod()->playMusic(Mod::DEBRIEF_MUSIC_BAD);
}
}
/**
* Shows a tooltip for the appropriate text.
* @param action Pointer to an action.
*/
void DebriefingState::txtTooltipIn(Action *action)
{
_currentTooltip = action->getSender()->getTooltip();
_txtTooltip->setText(tr(_currentTooltip));
}
/**
* Clears the tooltip text.
* @param action Pointer to an action.
*/
void DebriefingState::txtTooltipOut(Action *action)
{
if (_currentTooltip == action->getSender()->getTooltip())
{
_txtTooltip->setText(L"");
}
}
/**
* Displays soldiers' stat increases.
* @param action Pointer to an action.
*/
void DebriefingState::btnStatsClick(Action *)
{
_pageNumber = (_pageNumber + 1) % 3;
applyVisibility();
}
/**
* Opens the Sell/Sack UI (for recovered items ONLY).
* @param action Pointer to an action.
*/
void DebriefingState::btnSellClick(Action *)
{
if (!_destroyBase)
{
_game->pushState(new SellState(_base, this, OPT_BATTLESCAPE));
}
}
/**
* Returns to the previous screen.
* @param action Pointer to an action.
*/
void DebriefingState::btnOkClick(Action *)
{
std::vector<Soldier*> participants;
for (std::vector<BattleUnit*>::const_iterator i = _game->getSavedGame()->getSavedBattle()->getUnits()->begin();
i != _game->getSavedGame()->getSavedBattle()->getUnits()->end(); ++i)
{
if ((*i)->getGeoscapeSoldier())
{
participants.push_back((*i)->getGeoscapeSoldier());
}
}
_game->getSavedGame()->setBattleGame(0);
_game->popState();
if (_game->getSavedGame()->getMonthsPassed() == -1)
{
_game->setState(new MainMenuState);
}
else
{
if (!_deadSoldiersCommended.empty())
{
_game->pushState(new CommendationLateState(_deadSoldiersCommended));
}
if (!_soldiersCommended.empty())
{
_game->pushState(new CommendationState(_soldiersCommended));
}
if (!_destroyBase)
{
if (_game->getSavedGame()->handlePromotions(participants, _game->getMod()))
{
_game->pushState(new PromotionsState);
}
if (!_missingItems.empty())
{
_game->pushState(new CannotReequipState(_missingItems));
}
// refresh! (we may have sold some prisoners in the meantime; directly from Debriefing)
for (std::map<int, int>::iterator i = _containmentStateInfo.begin(); i != _containmentStateInfo.end(); ++i)
{
if (i->second == 2)
{
if (_base->getAvailableContainment(i->first) - (_base->getUsedContainment(i->first) * _limitsEnforced) >= 0)
{
_containmentStateInfo[i->first] = 0; // 0 = OK
}
}
}
for (std::map<int, int>::const_iterator i = _containmentStateInfo.begin(); i != _containmentStateInfo.end(); ++i)
{
if (i->second == 2)
{
_game->pushState(new ManageAlienContainmentState(_base, i->first, OPT_BATTLESCAPE));
_game->pushState(new ErrorMessageState(trAlt("STR_CONTAINMENT_EXCEEDED", i->first).arg(_base->getName()), _palette, _game->getMod()->getInterface("debriefing")->getElement("errorMessage")->color, "BACK01.SCR", _game->getMod()->getInterface("debriefing")->getElement("errorPalette")->color));
}
else if (i->second == 1)
{
_game->pushState(new ErrorMessageState(
trAlt("STR_ALIEN_DIES_NO_ALIEN_CONTAINMENT_FACILITY", i->first),
_palette,
_game->getMod()->getInterface("debriefing")->getElement("errorMessage")->color,
"BACK01.SCR",
_game->getMod()->getInterface("debriefing")->getElement("errorPalette")->color));
}
}
if (Options::storageLimitsEnforced && _base->storesOverfull())
{
_game->pushState(new SellState(_base, 0, OPT_BATTLESCAPE));
_game->pushState(new ErrorMessageState(tr("STR_STORAGE_EXCEEDED").arg(_base->getName()), _palette, _game->getMod()->getInterface("debriefing")->getElement("errorMessage")->color, "BACK01.SCR", _game->getMod()->getInterface("debriefing")->getElement("errorPalette")->color));
}
}
// Autosave after mission
if (_game->getSavedGame()->isIronman())
{
_game->pushState(new SaveGameState(OPT_GEOSCAPE, SAVE_IRONMAN, _palette));
}
else if (Options::autosave)
{
_game->pushState(new SaveGameState(OPT_GEOSCAPE, SAVE_AUTO_GEOSCAPE, _palette));
}
}
}
/**
* Adds to the debriefing stats.
* @param name The untranslated name of the stat.
* @param quantity The quantity to add.
* @param score The score to add.
*/
void DebriefingState::addStat(const std::string &name, int quantity, int score)
{
for (std::vector<DebriefingStat*>::iterator i = _stats.begin(); i != _stats.end(); ++i)
{
if ((*i)->item == name)
{
(*i)->qty = (*i)->qty + quantity;
(*i)->score = (*i)->score + score;
break;
}
}
}
/**
* Clears the alien base from supply missions that use it.
*/
class ClearAlienBase: public std::unary_function<AlienMission *, void>
{
public:
/// Remembers the base.
ClearAlienBase(const AlienBase *base) : _base(base) { /* Empty by design. */ }
/// Clears the base if required.
void operator()(AlienMission *am) const;
private:
const AlienBase *_base;
};
/**
* Removes the association between the alien mission and the alien base,
* if one existed.
* @param am Pointer to the alien mission.
*/
void ClearAlienBase::operator()(AlienMission *am) const
{
if (am->getAlienBase() == _base)
{
am->setAlienBase(0);
}
}
/**
* Prepares debriefing: gathers Aliens, Corpses, Artefacts, UFO Components.
* Adds the items to the craft.
* Also calculates the soldiers experience, and possible promotions.
* If aborted, only the things on the exit area are recovered.
*/
void DebriefingState::prepareDebriefing()
{
for (std::vector<std::string>::const_iterator i = _game->getMod()->getItemsList().begin(); i != _game->getMod()->getItemsList().end(); ++i)
{
RuleItem *rule = _game->getMod()->getItem(*i);
if (rule->getSpecialType() > 1)
{
RecoveryItem *item = new RecoveryItem();
item->name = *i;
item->value = rule->getRecoveryPoints();
_recoveryStats[rule->getSpecialType()] = item;
_missionStatistics->lootValue = item->value;
}
}
SavedGame *save = _game->getSavedGame();
SavedBattleGame *battle = save->getSavedBattle();
AlienDeployment *ruleDeploy = _game->getMod()->getDeployment(battle->getMissionType());
// OXCE: Don't forget custom mission overrides
auto alienCustomMission = _game->getMod()->getDeployment(battle->getAlienCustomMission());
if (alienCustomMission)
{
ruleDeploy = alienCustomMission;
}
// OXCE+: Don't forget about UFO landings/crash sites
if (!ruleDeploy)
{
for (std::vector<Ufo*>::iterator ufo = _game->getSavedGame()->getUfos()->begin(); ufo != _game->getSavedGame()->getUfos()->end(); ++ufo)
{
if ((*ufo)->isInBattlescape())
{
ruleDeploy = _game->getMod()->getDeployment((*ufo)->getRules()->getType());
break;
}
}
}
bool aborted = battle->isAborted();
bool success = !aborted || battle->allObjectivesDestroyed();
Craft *craft = 0;
std::vector<Craft*>::iterator craftIterator;
Base *base = 0;
std::string target;
int playersInExitArea = 0; // if this stays 0 the craft is lost...
int playersSurvived = 0; // if this stays 0 the craft is lost...
int playersUnconscious = 0;
int playersInEntryArea = 0;
_stats.push_back(new DebriefingStat("STR_ALIENS_KILLED", false));
_stats.push_back(new DebriefingStat("STR_ALIEN_CORPSES_RECOVERED", false));
_stats.push_back(new DebriefingStat("STR_LIVE_ALIENS_RECOVERED", false));
_stats.push_back(new DebriefingStat("STR_LIVE_ALIENS_SURRENDERED", false));
_stats.push_back(new DebriefingStat("STR_ALIEN_ARTIFACTS_RECOVERED", false));
std::string objectiveCompleteText, objectiveFailedText;
int objectiveCompleteScore = 0, objectiveFailedScore = 0;
if (ruleDeploy)
{
if (ruleDeploy->getObjectiveCompleteInfo(objectiveCompleteText, objectiveCompleteScore))
{
_stats.push_back(new DebriefingStat(objectiveCompleteText, false));
}
if (ruleDeploy->getObjectiveFailedInfo(objectiveFailedText, objectiveFailedScore))
{
_stats.push_back(new DebriefingStat(objectiveFailedText, false));
}
}
_stats.push_back(new DebriefingStat("STR_CIVILIANS_KILLED_BY_ALIENS", false));
_stats.push_back(new DebriefingStat("STR_CIVILIANS_KILLED_BY_XCOM_OPERATIVES", false));
_stats.push_back(new DebriefingStat("STR_CIVILIANS_SAVED", false));
_stats.push_back(new DebriefingStat("STR_XCOM_OPERATIVES_KILLED", false));
//_stats.push_back(new DebriefingStat("STR_XCOM_OPERATIVES_RETIRED_THROUGH_INJURY", false));
_stats.push_back(new DebriefingStat("STR_XCOM_OPERATIVES_MISSING_IN_ACTION", false));
_stats.push_back(new DebriefingStat("STR_TANKS_DESTROYED", false));
_stats.push_back(new DebriefingStat("STR_XCOM_CRAFT_LOST", false));