-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregioninfo.cpp
230 lines (209 loc) · 9.24 KB
/
regioninfo.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
#include "regioninfo.h"
void FXRegionInfo::create()
{
FXMessageList::create();
}
FXRegionInfo::FXRegionInfo(FXComposite* p, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h)
: FXMessageList(p, tgt, sel, opts, x, y, w, h)
{
regionMessages = appendItem(nullptr, "Meldungen");
unitMessages = nullptr;
effects = appendItem(nullptr, "Effekte");
travel = appendItem(nullptr, "Durchreise");
battle = nullptr;
streets = appendItem(nullptr, FXString(L"Stra\u00dfen"));
guards = appendItem(nullptr, "Bewacher");
}
long FXRegionInfo::onMapChange(FXObject * sender, FXSelector sel, void * ptr)
{
datafile::SelectionState* pstate = (datafile::SelectionState*)ptr;
if (selection.fileChange != pstate->fileChange) {
clearChildren(effects);
clearChildren(streets);
clearChildren(travel);
clearChildren(guards);
clearChildren(regionMessages);
clearChildren(battle);
clearChildren(unitMessages);
} else if (selection.selChange != pstate->selChange) {
if (mapFile && mapFile->hasActiveFaction()) {
datablock* regionPtr = nullptr;
datablock* unitPtr = nullptr;
if (pstate->selected & selection.UNIT)
{
unitPtr = &*pstate->unit;
if ((selection.selected & selection.UNIT) == 0)
{
clearChildren(unitMessages);
}
else if (selection.unit != pstate->unit) {
removeItem(unitMessages);
unitMessages = nullptr;
}
else {
unitPtr = nullptr;
}
}
else if (unitMessages) {
removeItem(unitMessages);
unitMessages = nullptr;
}
if (pstate->selected & selection.REGION)
{
if ((selection.selected & selection.REGION) == 0 || selection.region != pstate->region)
{
regionPtr = &*pstate->region;
clearChildren(effects);
clearChildren(streets);
clearChildren(travel);
clearChildren(guards);
clearChildren(regionMessages);
clearChildren(battle);
}
}
if (regionPtr) {
datablock::itor block;
datablock::itor end = mapFile->blocks().end();
std::set<FXint> guard_ids;
if (mapFile->getBattle(block, pstate->sel_x, pstate->sel_y, pstate->sel_plane)) {
datablock::itor message;
if (!battle) {
battle = appendItem(nullptr, "Kampf");
}
if (mapFile->getChild(message, block, block_type::TYPE_MESSAGE)) {
do {
addMessage(battle, *message);
} while (mapFile->getNext(message, block_type::TYPE_MESSAGE));
}
}
else if (battle) {
removeItem(battle);
battle = nullptr;
}
for (block = std::next(pstate->region); block != end && block->depth() > regionPtr->depth(); block++)
{
if (block->type() == block_type::TYPE_MESSAGE) {
/*
MESSAGE 324149248
"von Figo (g351): 'KABUMM *kicher*'";rendered
*/
addMessage(regionMessages, *block);
}
else if (block->depth() > regionPtr->depth() + 1) {
continue;
}
else if (block->type() == block_type::TYPE_UNIT) {
int guard = block->valueInt("bewacht");
if (guard) {
FXint faction = block->valueInt("Partei");
guard_ids.insert(faction);
}
}
else if (block->type() == block_type::TYPE_EFFECTS)
{
/*
EFFECTS
"Untote schrecken vor dieser Region zurueck. (njr4)"
*/
for (datakey::list_type::const_iterator msg = block->data().begin(); msg != block->data().end(); msg++)
appendItem(effects, msg->value());
}
else if (block->type() == block_type::TYPE_BORDER)
{
/*
GRENZE 1
"Stra\u00dfe";typ
1;richtung
100;prozent
*/
const wchar_t* directions[] = { L"Nordwesten", L"Nordosten", L"Osten", L"S\u00fcdosten", L"S\u00fcdwesten", L"Westen", L"-unknown-" };
FXint dir = 0;
if (block->value("richtung").length())
dir = atoi(block->value("richtung").text());
if (dir < 0 || dir > 6)
dir = 6;
FXString typ = block->value("typ");
FXint procent = 0;
if (block->value("prozent").length())
procent = atoi(block->value("prozent").text());
FXString artikel = "eine ";
FXString label;
label = FXString("Im ") + FXString(directions[dir]) + " befindet sich ";
if (procent == 100)
label += artikel + typ + ".";
else
label += artikel + "zu " + FXStringVal(procent) + "% vollendete " + typ + ".";
appendItem(streets, label);
}
else if (block->type() == block_type::TYPE_DURCHREISE || block->type() == block_type::TYPE_DURCHSCHIFFUNG)
{
/*
DURCHREISE
"Fuhrwagenlenker zu Xorlosch (g5te)"
*/
FXString prefix;
if (block->type() == block_type::TYPE_DURCHSCHIFFUNG)
prefix = "Die "; // fuer Schiffe
for (const datakey& msg : block->data()) {
datablock* udata = nullptr;
FXString val = msg.value();
FXint right = val.find_last_of(')', val.length());
if (right >= 0) {
datablock::itor match;
FXint left = val.find_last_of('(', right);
FXString id = val.mid(left + 1, right - left - 1);
FXuint no = FXUIntVal(id, 36);
if (block->type() == block_type::TYPE_DURCHSCHIFFUNG)
{
if (mapFile->getShip(match, no)) {
udata = &*match;
}
}
else if (mapFile->getUnit(match, no)) {
udata = &*match;
}
}
FXTreeItem* item = appendItem(travel, prefix + val);
item->setData(udata);
}
}
}
if (!guard_ids.empty()) {
for (FXint id : guard_ids) {
datablock::itor faction;
if (mapFile->getFaction(faction, id)) {
FXString label = faction->getLabel();
appendItem(guards, label);
}
}
}
}
if (unitPtr) {
FXString name = unitPtr->getLabel();
if (!unitMessages) {
unitMessages = insertItem(battle, nullptr, name);
}
else {
unitMessages->setText(name);
}
}
if (unitPtr || regionPtr)
{
datablock::citor end = mapFile->blocks().end();
datablock::itor block = std::next(mapFile->activefaction());
while (block != end && block->type() != block_type::TYPE_MESSAGE) ++block;
for (; block != end && block->type() == block_type::TYPE_MESSAGE; ++block)
{
const datablock& msg = *block;
if (unitPtr && msg.hasReference(*unitPtr)) {
addMessage(unitMessages, msg);
}
if (regionPtr && msg.hasReference(*regionPtr)) {
addMessage(regionMessages, msg);
}
}
}
}
}
return FXMessageList::onMapChange(sender, sel, ptr);
}