-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisit.H
executable file
·393 lines (340 loc) · 14 KB
/
Visit.H
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
#pragma once
#include <data.h>
#include <rpg_map.h>
#include <algorithm>
#include "Exception.H"
#include "MapCache.H"
#include "Location.H"
class VisitStopException : public Exception {
public:
VisitStopException() : Exception("Visit Interrupted") {}
};
template <typename F>
void visitTreeMap(F&& f) {
auto& maps = Data::treemap.maps;
auto& tree_order= Data::treemap.tree_order;
for (auto& map_id: tree_order) {
auto iter = std::lower_bound(maps.begin(), maps.end(), map_id,
[](const auto& map_info, int map_id) { return map_info.ID < map_id; });
if (iter == maps.end() || iter->ID != map_id) {
die("Invalid MapID (", map_id, ") in the tree map?? Corruption??");
}
f(*iter);
}
}
//Inherit from this and implement the methods for things you want to visit.
//Note this class is not virtual for performance reasons.
//You can override for const or non-const as you like.
class VisitorBase {
public:
void onDatabase(const RPG::Database& db) const {}
void onActors(const std::vector<RPG::Actor>& actor) const {}
void onActor(const RPG::Actor& actor) const {}
void onSkills(const std::vector<RPG::Skill>& skills) const {}
void onSkill(const RPG::Skill& skill) const {}
void onItems(const std::vector<RPG::Item>& items) const {}
void onItem(const RPG::Item& item) const {}
void onCommonEvents(const std::vector<RPG::CommonEvent>& ces) const {}
void onCommonEvent(const RPG::CommonEvent& ce) const {}
void onCommonEventCmds(const RPG::CommonEvent& ce, const std::vector<RPG::EventCommand>& cmds) const {}
//onEventCmds(cmds) called after this..
void onCommonEventCmd(const RPG::CommonEvent& ce, const RPG::EventCommand& cmd) const {}
//onEventCmd(cmds) called after this..
void onEnemies(const std::vector<RPG::Enemy>& enemies) const {}
void onEnemy(const RPG::Enemy& enemy) const {}
void onEnemyActions(const RPG::Enemy& enemy, const std::vector<RPG::EnemyAction>& actions) const {}
void onEnemyAction(const RPG::Enemy& enemy, const RPG::EnemyAction& action) const {}
void onTroops(const std::vector<RPG::Troop>& troops) const {}
void onTroop(const RPG::Troop& troop) const {}
void onTroopMembers(const RPG::Troop& troop, const std::vector<RPG::TroopMember>& members) const {}
void onTroopMember(const RPG::Troop& troop, const RPG::TroopMember& member) const {}
void onTroopPages(const RPG::Troop& troop, const std::vector<RPG::TroopPage>& page) const {}
void onTroopPage(const RPG::Troop& troop, const RPG::TroopPage& page) const {}
void onTroopPageCmds(const RPG::Troop& troop, const RPG::TroopPage& page, const std::vector<RPG::EventCommand>& cmds) const {}
//onEventCmds(cmds) called after this..
void onTroopPageCmd(const RPG::Troop& troop, const RPG::TroopPage& page, const RPG::EventCommand& cmd) const {}
//onEventCmd(cmd) called after this..
void onTerrains(const std::vector<RPG::Terrain>& terrains) const {}
void onTerrain(const RPG::Terrain& terrain) const {}
void onAttributes(const std::vector<RPG::Attribute>& attrs) const {}
void onAttribute(const RPG::Attribute& attr) const {}
void onStates(const std::vector<RPG::State>& state) const {}
void onState(const RPG::State& state) const {}
void onAnimations(const std::vector<RPG::Animation>& anims) const {}
void onAnimation(const RPG::Animation& anim) const {}
void onChipsets(const std::vector<RPG::Chipset>& chipsets) const {}
void onChipset(const RPG::Chipset& chipset) const {}
void onBattleCommands(const RPG::BattleCommands& batcmds) const {}
void onBattleCommandsCmds(const RPG::BattleCommands& batcmds, const std::vector<RPG::BattleCommand>& cmds) const {}
void onBattleCommand(const RPG::BattleCommands& batcmds, const RPG::BattleCommand& batcmd) const {}
void onClasses(const std::vector<RPG::Class>& classes) const {}
void onClass(const RPG::Class& cls) const {}
void onBattlerAnimations(const std::vector<RPG::BattlerAnimation>& batanims) const {}
void onBattlerAnimation(const RPG::BattlerAnimation& batanim) const {}
void onTerms(const RPG::Terms& terms) const {}
void onSystem(const RPG::System& sys) const {}
void onSwitches(const std::vector<RPG::Switch>& sws) const {}
void onSwitch(const RPG::Switch& sw) const {}
void onVariables(const std::vector<RPG::Variable>& vars) const {}
void onVariable(const RPG::Variable& var) const {}
void onTreeMap(const RPG::TreeMap& tm) const {}
void onMapInfo(const RPG::MapInfo& map_info) const {}
void onMapRoot(const RPG::MapInfo& map_info) const {}
void onMap(const RPG::MapInfo& map_info, const RPG::Map& map) const {}
void onMapEvents(const RPG::MapInfo& map_info, const RPG::Map& map, const std::vector<RPG::Event>& events) const {}
void onMapEvent(const RPG::MapInfo& map_info, const RPG::Map& map, const RPG::Event& event) const {}
void onMapEventPages(const RPG::MapInfo& map_info, const RPG::Map& map, const RPG::Event& event, const std::vector<RPG::EventPage>& pages) const {}
void onMapEventPage(const RPG::MapInfo& map_info, const RPG::Map& map, const RPG::Event& event, const RPG::EventPage& page) const {}
void onMapEventPageCmds(const RPG::MapInfo& map_info, const RPG::Map& map,
const RPG::Event& event, const RPG::EventPage& page,
const std::vector<RPG::EventCommand>& cmds) const {}
//onEventCmds(cmds) called after this..
void onMapEventPageCmd(const RPG::MapInfo& map_info, const RPG::Map& map,
const RPG::Event& event, const RPG::EventPage& page,
const RPG::EventCommand& cmd) const {}
//onEventCmd(cmds) called after this..
void onAreaMap(const RPG::MapInfo& map_info) const {}
void onEventCommands(const std::vector<RPG::EventCommand>& cmds) const {}
void onEventCommand(const RPG::EventCommand& cmds) const {}
Location& loc() { return _loc; }
const Location& loc() const { return _loc; }
void stopThisBranch() { throw VisitStopException(); }
private:
Location _loc;
public:
bool do_database = true;
bool do_actors = true;
bool do_skills = true;
bool do_items = true;
bool do_commonevents = true;
bool do_enemies = true;
bool do_troops = true;
bool do_terrains = true;
bool do_attributes = true;
bool do_states = true;
bool do_animations = true;
bool do_chipsets = true;
bool do_battlecmds = true;
bool do_classes = true;
bool do_battleranims = true;
bool do_terms = true;
bool do_system = true;
bool do_switches = true;
bool do_variables = true;
bool do_maps = true;
};
//Visit the entire game.
template <typename V>
void visitRPG(V&& v) {
if (v.do_database) {
v.loc() = Location(LocPath(&Data::data));
v.onDatabase(Data::data);
}
if (v.do_actors) {
v.loc() = {};
v.onActors(Data::actors);
for (auto& actor: Data::actors) {
v.loc() = Location(LocPath(&actor));
v.onActor(actor);
}
}
if (v.do_skills) {
v.loc() = {};
v.onSkills(Data::skills);
for (auto& skill: Data::skills) {
v.loc() = Location(LocPath(&skill));
v.onSkill(skill);
}
}
if (v.do_items) {
v.loc() = {};
v.onItems(Data::items);
for (auto& item: Data::items) {
v.loc() = Location(LocPath(&item));
v.onItem(item);
}
}
if (v.do_commonevents) {
v.loc() = {};
v.onCommonEvents(Data::commonevents);
for (auto& ce: Data::commonevents) {
v.loc() = Location(LocPath(&ce));
v.onCommonEvent(ce);
v.onCommonEventCmds(ce, ce.event_commands);
v.onEventCommands(ce.event_commands);
for (auto& cmd: ce.event_commands) {
v.loc() = Location(LocPath(&ce, &cmd));
v.onCommonEventCmd(ce, cmd);
v.onEventCommand(cmd);
}
}
}
if (v.do_enemies) {
v.loc() = {};
v.onEnemies(Data::enemies);
for (auto& e: Data::enemies) {
v.loc() = Location(LocPath(&e));
v.onEnemy(e);
v.onEnemyActions(e, e.actions);
for (auto& a: e.actions) {
v.loc() = Location(LocPath(&e, &a));
v.onEnemyAction(e, a);
}
}
}
if (v.do_troops) {
v.loc() = {};
v.onTroops(Data::troops);
for (auto& t: Data::troops) {
v.loc() = Location(LocPath(&t));
v.onTroop(t);
v.onTroopMembers(t, t.members);
for (auto& m: t.members) {
v.loc() = Location(LocPath(&t, &m));
v.onTroopMember(t, m);
}
v.onTroopPages(t, t.pages);
for (auto& p: t.pages) {
v.loc() = Location(LocPath(&t, &p));
v.onTroopPage(t, p);
v.onTroopPageCmds(t, p, p.event_commands);
v.onEventCommands(p.event_commands);
for (auto& cmd: p.event_commands) {
v.loc() = Location(LocPath(&t, &p, &cmd));
v.onTroopPageCmd(t, p, cmd);
v.onEventCommand(cmd);
}
}
}
}
if (v.do_terrains) {
v.loc() = {};
v.onTerrains(Data::terrains);
for (auto& t: Data::terrains) {
v.loc() = Location(LocPath(&t));
v.onTerrain(t);
}
}
if (v.do_attributes) {
v.loc() = {};
v.onAttributes(Data::attributes);
for (auto& a: Data::attributes) {
v.loc() = Location(LocPath(&a));
v.onAttribute(a);
}
}
if (v.do_states) {
v.loc() = {};
v.onStates(Data::states);
for (auto& s: Data::states) {
v.loc() = Location(LocPath(&s));
v.onState(s);
}
}
if (v.do_animations) {
v.loc() = {};
v.onAnimations(Data::animations);
for (auto& a: Data::animations) {
v.loc() = Location(LocPath(&a));
v.onAnimation(a);
}
}
if (v.do_chipsets) {
v.loc() = {};
v.onChipsets(Data::chipsets);
for (auto& c: Data::chipsets) {
v.loc() = Location(LocPath(&c));
v.onChipset(c);
}
}
if (v.do_battlecmds) {
v.loc() = Location(LocPath(&Data::battlecommands));
v.onBattleCommands(Data::battlecommands);
v.onBattleCommandsCmds(Data::battlecommands, Data::battlecommands.commands);
for (auto& c: Data::battlecommands.commands) {
v.loc() = Location(LocPath(&Data::battlecommands, &c));
v.onBattleCommand(Data::battlecommands, c);
}
}
if (v.do_classes) {
v.loc() = {};
v.onClasses(Data::classes);
for (auto& c: Data::classes) {
v.loc() = Location(LocPath(&c));
v.onClass(c);
}
}
if (v.do_battleranims) {
v.loc() = {};
v.onBattlerAnimations(Data::battleranimations);
for (auto& ba: Data::battleranimations) {
v.loc() = { LocPath(&ba) };
v.onBattlerAnimation(ba);
}
}
if (v.do_terms) {
v.loc() = { LocPath(&Data::terms) };
v.onTerms(Data::terms);
}
if (v.do_system) {
v.loc() = { LocPath(&Data::system) };
v.onSystem(Data::system);
}
if (v.do_switches) {
v.loc() = {};
v.onSwitches(Data::switches);
for (auto& sw: Data::switches) {
v.loc() = { LocPath(&sw) };
v.onSwitch(sw);
}
}
if (v.do_variables) {
v.loc() = {};
v.onVariables(Data::variables);
for (auto& var: Data::variables) {
v.loc() = { LocPath(&var) };
v.onVariable(var);
}
}
if (v.do_maps) {
v.loc() = { LocPath(&Data::treemap) };
v.onTreeMap(Data::treemap);
visitTreeMap([&](RPG::MapInfo& map_info) {
v.loc() = { LocPath(&map_info) };
v.onMapInfo(map_info);
switch(map_info.type) {
case RPG::TreeMap::MapType_root:
v.onMapRoot(map_info);
break;
case RPG::TreeMap::MapType_map: {
auto& map = MapCache::loadMap(map_info);
v.loc() = { LocPath(&map_info, &map) };
v.onMap(map_info, map);
v.onMapEvents(map_info, map, map.events);
for (auto& event: map.events) {
v.loc() = { LocPath(&map_info, &map, &event) };
v.onMapEvent(map_info, map, event);
v.onMapEventPages(map_info, map, event, event.pages);
for (auto& page: event.pages) {
v.loc() = { LocPath(&map_info, &map, &event, &page) };
v.onMapEventPage(map_info, map, event, page);
v.onMapEventPageCmds(map_info, map, event, page, page.event_commands);
v.onEventCommands(page.event_commands);
for (auto& cmd: page.event_commands) {
v.loc() = { LocPath(&map_info, &map, &event, &page, &cmd) };
v.onMapEventPageCmd(map_info, map, event, page, cmd);
v.onEventCommand(cmd);
}
}
}
break;
}
case RPG::TreeMap::MapType_area:
v.onAreaMap(map_info);
break;
}
});
}
v.loc() = {};
}
extern template void visitRPG<VisitorBase&>(VisitorBase& v);