-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrender_site.cpp
149 lines (133 loc) · 3.93 KB
/
render_site.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
#include "weblegends.h"
#include "helpers.h"
#include "df/creature_raw.h"
#include "df/entity_population.h"
#include "df/entity_site_link.h"
#include "df/historical_entity.h"
#include "df/nemesis_record.h"
#include "df/world.h"
#include "df/world_data.h"
#include "df/world_site.h"
#include "df/world_site_inhabitant.h"
REQUIRE_GLOBAL(world);
bool WebLegends::render_site(Layout & l, int32_t id, int32_t page)
{
CoreSuspender suspend;
auto site = df::world_site::find(id);
if (site == nullptr)
{
return false;
}
auto owner = df::historical_entity::find(site->cur_owner_id);
simple_header(l, site);
auto & s = l.content;
df::coord2d_path coords;
for (int32_t x = site->global_min_x; x <= site->global_max_x; x++)
{
for (int32_t y = site->global_min_y; y <= site->global_max_y; y++)
{
coords.push_back(df::coord2d(uint16_t(x), uint16_t(y)));
}
}
render_map_coords(s, coords, 16);
s << "<p>";
categorize(s, site);
s << "</p>";
render_world_populations(s, site->name, site->unk_1.animals, "site", site->id);
if (!site->unk_1.nemesis.empty() || !site->unk_1.inhabitants.empty())
{
s << "<h2>Inhabitants</h2><ul class=\"multicol\">";
for (auto id : site->unk_1.nemesis)
{
auto nemesis = df::nemesis_record::find(id);
if (!nemesis)
{
s << "<li>(unknown)</li>";
continue;
}
s << "<li>";
link(s, nemesis->figure);
s << ",";
categorize(s, nemesis->figure);
s << "</li>";
}
for (auto inhabitant : site->unk_1.inhabitants)
{
if (inhabitant->count == 0)
{
continue;
}
auto creature = df::creature_raw::find(inhabitant->race);
s << "<li>" << inhabitant->count << " ";
s << creature->name[inhabitant->count == 1 ? 0 : 1];
auto pop = df::entity_population::find(inhabitant->population_id);
auto outcast = df::historical_entity::find(inhabitant->entity_id);
if (pop || outcast)
{
s << " (";
if (outcast)
{
link(s, outcast);
if (pop)
{
s << ", ";
}
}
if (pop)
{
link(s, df::historical_entity::find(pop->civ_id));
}
s << ")";
}
s << "</li>";
}
s << "</ul>";
}
if (!site->unk_1.artifacts.empty())
{
s << "<h2>Artifacts</h2><ul class=\"multicol\">";
for (auto art : site->unk_1.artifacts)
{
s << "<li>";
link(s, art);
s << ",";
categorize(s, art);
s << "</li>";
}
s << "</ul>";
}
if (!site->entity_links.empty())
{
s << "<h2 id=\"related-entities\">Related Entities</h2><ul class=\"multicol\">";
for (auto l : site->entity_links)
{
auto entity = df::historical_entity::find(l->entity_id);
s << "<li>";
link(s, entity);
s << ",";
categorize(s, entity, false, false, owner ? owner->race : -1);
s << "</li>";
}
s << "</ul>";
}
if (!site->buildings.empty())
{
s << "<h2 id=\"structures\">Structures</h2><ul class=\"multicol\">";
for (auto b : site->buildings)
{
s << "<li>";
link(s, b);
s << ",";
categorize(s, b);
s << "</li>";
}
s << "</ul>";
}
int32_t last_page;
if (!history(s, site, page, last_page))
{
return false;
}
pagination(s, stl_sprintf("site-%d", id), "", "?page=", page, last_page);
return true;
}