-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathroom_describe.cpp
369 lines (335 loc) · 9.09 KB
/
room_describe.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
#include "ai.h"
#include "plan.h"
#include "df/abstract_building_templest.h"
#include "df/building_civzonest.h"
#include "df/historical_entity.h"
#include "df/historical_figure.h"
#include "df/squad.h"
#include "df/unit.h"
#include "df/world_site.h"
std::string AI::describe_room(room *r, bool html)
{
if (!r)
{
return "(unknown room)";
}
std::ostringstream s;
s << r->type;
switch (r->type)
{
case room_type::cistern:
s << " (" << r->cistern_type << ")";
break;
case room_type::corridor:
if (r->corridor_type != corridor_type::corridor)
{
s << " (" << r->corridor_type << ")";
}
break;
case room_type::farmplot:
s << " (" << r->farm_type << ")";
break;
case room_type::furnace:
if (r->furnace_type == furnace_type::Custom)
{
s << " (\"" << maybe_escape(r->raw_type, html) << "\")";
}
else
{
s << " (" << enum_item_key(r->furnace_type) << ")";
}
break;
case room_type::location:
switch (r->location_type)
{
case location_type::guildhall:
s << " (" << toLower(enum_item_key(df::profession(r->data1))) << " guildhall)";
break;
case location_type::temple:
switch (df::temple_deity_type(r->data1))
{
case temple_deity_type::None:
s << " (temple)";
break;
case temple_deity_type::Deity:
s << " (temple to ";
if (html)
{
s << "<a href=\"fig-" << r->data2 << "\">";
}
if (auto hf = df::historical_figure::find(r->data2))
{
s << maybe_escape(AI::describe_name(hf->name, false), html) << " \"" << maybe_escape(AI::describe_name(hf->name, true), html) << "\"";
}
else
{
s << "[unknown deity]";
}
if (html)
{
s << "</a>";
}
s << ")";
break;
case temple_deity_type::Religion:
s << " (temple of ";
if (html)
{
s << "<a href=\"ent-" << r->data2 << "\">";
}
if (auto ent = df::historical_entity::find(r->data2))
{
s << maybe_escape(AI::describe_name(ent->name, false), html) << " \"" << maybe_escape(AI::describe_name(ent->name, true), html) << "\"";
}
else
{
s << "[unknown religion]";
}
if (html)
{
s << "</a>";
}
s << ")";
break;
}
break;
default:
s << " (" << r->location_type << ")";
break;
}
if (auto civzone = virtual_cast<df::building_civzonest>(r->dfbuilding()))
{
if (auto site = df::world_site::find(civzone->site_id))
{
if (auto loc = binsearch_in_vector(site->buildings, civzone->location_id))
{
if (auto name = loc->getName())
{
s << " (";
if (html)
{
s << "<a href=\"site-" << civzone->site_id << "/bld-" << loc->id << "\">";
}
s << maybe_escape(AI::describe_name(*name, false), html) << " \"" << maybe_escape(AI::describe_name(*name, true), html) << "\"";
if (html)
{
s << "</a>";
}
s << ")";
}
}
}
}
break;
case room_type::nobleroom:
s << " (" << r->nobleroom_type << ")";
break;
case room_type::outpost:
s << " (" << r->outpost_type << ")";
break;
case room_type::stockpile:
s << " (" << r->stockpile_type << ")";
break;
case room_type::workshop:
if (r->workshop_type == workshop_type::Custom)
{
s << " (\"" << maybe_escape(r->raw_type, html) << "\")";
}
else
{
s << " (" << enum_item_key(r->workshop_type) << ")";
}
break;
default:
break;
}
if (r->required_value > 0)
{
int32_t value = r->compute_value();
if (value >= 0)
{
s << " (value " << value << " / " << r->required_value << ")";
}
else
{
s << " (required value " << r->required_value << ")";
}
}
if (!r->comment.empty())
{
s << " (" << maybe_escape(r->comment, html) << ")";
}
if (df::unit *u = df::unit::find(r->owner))
{
s << " (owned by " << AI::describe_unit(u, html) << ")";
}
if (r->noblesuite != -1)
{
s << " (noble suite " << r->noblesuite << ")";
}
if (df::squad *squad = df::squad::find(r->squad_id))
{
s << " (used by " << maybe_escape(AI::describe_name(squad->name, true), html) << ")";
}
if (r->level != -1)
{
s << " (level " << r->level << ")";
}
if (r->workshop)
{
s << " (" << describe_room(r->workshop, html) << ")";
}
if (r->has_users)
{
size_t users_count = r->users.size();
if (r->users.count(-1))
{
users_count--;
}
s << " (" << users_count << " users)";
}
if (r->status != room_status::finished)
{
s << " (" << r->status << ")";
}
return s.str();
}
std::string AI::describe_furniture(furniture *f, bool html)
{
if (!f)
{
return "(unknown furniture)";
}
std::ostringstream s;
if (f->type != layout_type::none)
{
s << f->type;
}
else
{
s << "[no furniture]";
}
if (f->construction != construction_type::NONE)
{
s << " (construct " << ENUM_KEY_STR(construction_type, f->construction) << ")";
}
if (f->dig != tile_dig_designation::Default)
{
s << " (dig " << ENUM_KEY_STR(tile_dig_designation, f->dig) << ")";
}
if (!f->comment.empty())
{
if (html)
{
s << " (" << html_escape(f->comment) << ")";
}
else
{
s << " (" << f->comment << ")";
}
}
if (f->has_users)
{
size_t users_count = f->users.size();
if (f->users.count(-1))
{
users_count--;
}
s << " (" << users_count << " users)";
}
if (f->ignore)
{
s << " (ignored)";
}
if (f->makeroom)
{
s << " (main)";
}
if (f->internal)
{
s << " (internal)";
}
s << " (" << f->pos.x << ", " << f->pos.y << ", " << f->pos.z << ")";
if (f->target != nullptr)
{
s << " (" << describe_furniture(f->target, html) << ")";
}
return s.str();
}
bool Plan::find_building(df::building *bld, room * & r, furniture * & f)
{
if (!bld)
{
return false;
}
if (room_by_z.empty())
{
for (auto r_ : rooms_and_corridors)
{
if (bld->getType() == building_type::Construction)
{
for (auto f_ : r_->layout)
{
if (r_->min.z + f_->pos.z == bld->z && f_->construction == bld->getSubtype() && r_->min.x + f_->pos.x == bld->x1 && r_->min.y + f_->pos.y == bld->y1)
{
r = r_;
f = f_;
return true;
}
}
continue;
}
if (r_->bld_id == bld->id)
{
r = r_;
return true;
}
for (auto f_ : r_->layout)
{
if (f_->bld_id == bld->id)
{
r = r_;
f = f_;
return true;
}
}
}
return false;
}
auto by_z = room_by_z.find(bld->z);
if (by_z == room_by_z.end())
{
return false;
}
for (auto r_ : by_z->second)
{
if (bld->getType() == building_type::Construction)
{
for (auto f_ : r_->layout)
{
if (f_->construction == bld->getSubtype() && r_->min.x + f_->pos.x == bld->x1 && r_->min.y + f_->pos.y == bld->y1)
{
r = r_;
f = f_;
return true;
}
}
continue;
}
if (r_->bld_id == bld->id)
{
r = r_;
return true;
}
for (auto f_ : r_->layout)
{
if (f_->bld_id == bld->id)
{
r = r_;
f = f_;
return true;
}
}
}
return false;
}