-
Notifications
You must be signed in to change notification settings - Fork 1
/
ship_props.cpp
162 lines (144 loc) · 5.82 KB
/
ship_props.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
#include <vector>
#include "fxhelper.h"
#include "ship_props.h"
// *********************************************************************************************************
// *** FXStatistics implementation
FXDEFMAP(FXShipProperties) MessageMap[]=
{
//________Message_Type_____________________ID_______________Message_Handler_______
FXMAPFUNC(SEL_DOUBLECLICKED, 0, FXShipProperties::onDoubleClicked),
FXMAPFUNC(SEL_COMMAND, FXShipProperties::ID_UPDATE, FXShipProperties::onMapChange),
FXMAPFUNC(SEL_QUERY_HELP, 0, FXShipProperties::onQueryHelp),
FXMAPFUNC(SEL_RIGHTBUTTONRELEASE, 0, FXShipProperties::onPopup),
};
FXIMPLEMENT(FXShipProperties, FXProperties, MessageMap, ARRAYNUMBER(MessageMap))
FXShipProperties::FXShipProperties(FXComposite* p, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h)
: FXProperties(p, tgt, sel, opts, x, y, w, h)
{
}
void FXShipProperties::makeItems()
{
// clear list and build new
clearItems();
if (selection.selected & selection.SHIP)
{
datablock::itor ship = selection.ship;
datablock::itor end = mapFile->blocks().end();
FXString name, type;
FXString aura, auramax, hero;
FXint captainId = -1, coast = -1, size = -1, cargo = -1, damage = -1, capacity = -1;
std::vector<datakey::list_type::const_iterator> unhandled;
for (datakey::list_type::const_iterator key = ship->data().begin(); key != ship->data().end(); ++key)
{
switch (key->type()) {
case TYPE_NAME:
name = key->value();
break;
case TYPE_CAPTAIN:
captainId = atoi(key->value().text());
break;
case TYPE_TYPE:
type = key->value();
break;
case TYPE_SIZE:
size = key->getInt();
break;
case TYPE_DAMAGE:
damage = key->getInt();
break;
case TYPE_COAST:
coast = key->getInt();
break;
case TYPE_CARGO:
cargo = key->getInt();
break;
case TYPE_CAPACITY:
capacity = key->getInt();
break;
case TYPE_FACTION:
case TYPE_DESCRIPTION:
case TYPE_NOTES:
/* ignore */
break;
default:
if (key->type() != TYPE_LOAD && key->type() != TYPE_MAXLOAD)
unhandled.push_back(key);
break;
}
}
FXString label;
label.format("%s (%s)", name.text(), ship->id().text());
if (!type.empty()) {
label += ", " + type;
}
if (size >= 0) {
label += FXString(L", Gr\u00f6\u00dfe ") + FXStringVal(size);
}
FXTreeItem* root = appendItem(nullptr, label);
root->setExpanded(true);
datablock::itor unit = std::next(selection.region);
if (captainId > 0)
{
if (mapFile->getUnit(unit, captainId)) {
label.assign(L"Kapit\u00e4n: ");
label += mapFile->unitName(*unit, true);
FXTreeItem* item = appendItem(root, makeItem(label, &*unit));
}
}
// Kueste
const wchar_t* coasts[] = { L"Nordwestk\u00fcste", L"Nordostk\u00fcste", L"Ostk\u00fcste", L"S\u00fcdostk\u00fcste", L"S\u00fcdwestk\u00fcste", L"Westk\u00fcste" };
if (coast >= 0 && coast < 6) {
appendItem(root, coastToString(coast));
}
// Beladung (cargo/capacity)
if (cargo > 0 || capacity > 0)
{
FXString car = weightToString(cargo);
FXString cap = weightToString(capacity);
appendItem(root, "Beladung: " + car + " von " + cap + " GE");
}
// Schaden
if (damage >= 0)
appendItem(root, FXStringVal(damage) + FXString(L"% besch\u00e4digt"));
// list unhandled keys
for (std::vector<datakey::list_type::const_iterator>::const_iterator itag = unhandled.begin(); itag != unhandled.end(); ++itag)
{
label.format("%s: %s", (*itag)->translatedKey().text(), (*itag)->value().text());
appendItem(root, label);
}
// find the EFFECTS block, if it exists
for (datablock::itor block = std::next(ship); block != end && block->depth() > ship->depth(); ++block)
{
if (block->type() == block_type::TYPE_EFFECTS) {
makeStringList(root, "Effekte", *block);
break;
}
}
// List units, if any:
FXTreeItem *unitList = makeUnitList(root, "Einheiten", unit, end, TYPE_SHIP, ship->info());
if (unitList) {
int totalSkill = 0;
for (FXTreeItem *item = unitList->getFirst(); item; item = item->getNext())
{
FXProperty *prop = static_cast<FXProperty *>(item->getData());
if (prop && prop->block)
{
int id = prop->block->info();
datablock::itor unit;
if (mapFile->getUnit(unit, id)) {
datablock::itor block;
int number = unit->valueInt(key_type::TYPE_NUMBER);
if (number > 0 && mapFile->getChild(block, unit, block_type::TYPE_TALENTS))
{
int skill = block->valueSkill("Segeln");
totalSkill += skill * number;
}
}
}
}
if (totalSkill > 0) {
insertItem(unitList, root, label.format("Segeltalent: %d", totalSkill));
}
}
}
}