forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArticleStateTFTDItem.cpp
More file actions
186 lines (164 loc) · 5.23 KB
/
Copy pathArticleStateTFTDItem.cpp
File metadata and controls
186 lines (164 loc) · 5.23 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
/*
* 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 <sstream>
#include <algorithm>
#include "Ufopaedia.h"
#include "ArticleStateTFTDItem.h"
#include "../Mod/Mod.h"
#include "../Mod/ArticleDefinition.h"
#include "../Mod/RuleItem.h"
#include "../Engine/Game.h"
#include "../Engine/Palette.h"
#include "../Engine/LocalizedText.h"
#include "../Engine/Unicode.h"
#include "../Interface/TextList.h"
namespace OpenXcom
{
ArticleStateTFTDItem::ArticleStateTFTDItem(ArticleDefinitionTFTD *defs) : ArticleStateTFTD(defs)
{
RuleItem *item = _game->getMod()->getItem(defs->id, true);
std::vector<std::string> *ammo_data = item->getCompatibleAmmo();
// SHOT STATS TABLE (for firearms only)
if (item->getBattleType() == BT_FIREARM)
{
_txtShotType = new Text(53, 17, 8, 157);
add(_txtShotType);
_txtShotType->setColor(Palette::blockOffset(0)+2);
_txtShotType->setWordWrap(true);
_txtShotType->setText(tr("STR_SHOT_TYPE"));
_txtAccuracy = new Text(57, 17, 61, 157);
add(_txtAccuracy);
_txtAccuracy->setColor(Palette::blockOffset(0)+2);
_txtAccuracy->setWordWrap(true);
_txtAccuracy->setText(tr("STR_ACCURACY_UC"));
_txtTuCost = new Text(56, 17, 118, 157);
add(_txtTuCost);
_txtTuCost->setColor(Palette::blockOffset(0)+2);
_txtTuCost->setWordWrap(true);
_txtTuCost->setText(tr("STR_TIME_UNIT_COST"));
_lstInfo = new TextList(140, 55, 8, 170);
add(_lstInfo);
_lstInfo->setColor(Palette::blockOffset(15)+4); // color for %-data!
_lstInfo->setColumns(3, 70, 40, 30);
int current_row = 0;
if (item->getTUAuto()>0)
{
std::string tu = Unicode::formatPercentage(item->getTUAuto());
if (item->getFlatRate())
{
tu.erase(tu.end() - 1);
}
_lstInfo->addRow(3,
tr("STR_SHOT_TYPE_AUTO").c_str(),
Unicode::formatPercentage(item->getAccuracyAuto()).c_str(),
tu.c_str());
_lstInfo->setCellColor(current_row, 0, Palette::blockOffset(0)+2);
current_row++;
}
if (item->getTUSnap()>0)
{
std::string tu = Unicode::formatPercentage(item->getTUSnap());
if (item->getFlatRate())
{
tu.erase(tu.end() - 1);
}
_lstInfo->addRow(3,
tr("STR_SHOT_TYPE_SNAP").c_str(),
Unicode::formatPercentage(item->getAccuracySnap()).c_str(),
tu.c_str());
_lstInfo->setCellColor(current_row, 0, Palette::blockOffset(0)+2);
current_row++;
}
if (item->getTUAimed()>0)
{
std::string tu = Unicode::formatPercentage(item->getTUAimed());
if (item->getFlatRate())
{
tu.erase(tu.end() - 1);
}
_lstInfo->addRow(3,
tr("STR_SHOT_TYPE_AIMED").c_str(),
Unicode::formatPercentage(item->getAccuracyAimed()).c_str(),
tu.c_str());
_lstInfo->setCellColor(current_row, 0, Palette::blockOffset(0)+2);
current_row++;
}
}
// AMMO column
std::ostringstream ss;
for (int i = 0; i<3; ++i)
{
_txtAmmoType[i] = new Text(120, 9, 168, 144 + i*10);
add(_txtAmmoType[i]);
_txtAmmoType[i]->setColor(Palette::blockOffset(0)+2);
_txtAmmoType[i]->setWordWrap(true);
_txtAmmoDamage[i] = new Text(20, 9, 300, 144 + i*10);
add(_txtAmmoDamage[i]);
_txtAmmoDamage[i]->setColor(Palette::blockOffset(3)+6);
}
switch (item->getBattleType())
{
case BT_FIREARM:
if (ammo_data->empty())
{
_txtAmmoType[0]->setText(tr(getDamageTypeText(item->getDamageType())));
ss.str("");ss.clear();
ss << item->getPower();
if (item->getShotgunPellets())
{
ss << "x" << item->getShotgunPellets();
}
_txtAmmoDamage[0]->setText(ss.str());
}
else
{
for (size_t i = 0; i < std::min(ammo_data->size(), (size_t)3); ++i)
{
ArticleDefinition *ammo_article = _game->getMod()->getUfopaediaArticle((*ammo_data)[i], true);
if (Ufopaedia::isArticleAvailable(_game->getSavedGame(), ammo_article))
{
RuleItem *ammo_rule = _game->getMod()->getItem((*ammo_data)[i], true);
_txtAmmoType[i]->setText(tr(getDamageTypeText(ammo_rule->getDamageType())));
ss.str("");ss.clear();
ss << ammo_rule->getPower();
if (ammo_rule->getShotgunPellets())
{
ss << "x" << ammo_rule->getShotgunPellets();
}
_txtAmmoDamage[i]->setText(ss.str());
}
}
}
break;
case BT_AMMO:
case BT_GRENADE:
case BT_PROXIMITYGRENADE:
case BT_MELEE:
_txtAmmoType[0]->setText(tr(getDamageTypeText(item->getDamageType())));
ss.str("");ss.clear();
ss << item->getPower();
_txtAmmoDamage[0]->setText(ss.str());
break;
default: break;
}
centerAllSurfaces();
}
ArticleStateTFTDItem::~ArticleStateTFTDItem()
{}
}