Clubhouse and shopping centre grow a storey per stage, the car park grows along the road, the restaurant gets a second storey and the lounge a wider, second row of glass. A crane stands while a stage is built. The card of a building names its stage, what it brings and what the next one costs, and orders it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
548 lines
45 KiB
C++
548 lines
45 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#pragma once
|
|
// The ground and what stands around it as a model of card on one base plate, seen from a
|
|
// fixed oblique angle: eight stands as deep as they have places, the stadium's equipment,
|
|
// the fourteen objects of the surroundings, trees, cars and people. The picture is built from
|
|
// the stadium overview alone, so the same input always gives the same picture.
|
|
//
|
|
// World: x to the lower right, y to the lower left, z up; the centre spot is the origin and
|
|
// lengths are roughly metres. A point lands on the picture through `project`; the picture is
|
|
// 1244 x 672 units. Next to the picture the scene lists, for every part one can choose, the
|
|
// faces it shows, as parallelograms in world coordinates.
|
|
#include "modern/ui/catalog.hpp"
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace bmh::modern_ui::stadium_scene {
|
|
struct Vec { double x = 0, y = 0, z = 0; };
|
|
struct Point { double x = 0, y = 0; };
|
|
constexpr double unit = 2.2, origin_x = 622, origin_y = 322, width = 1244, height = 672;
|
|
inline Point project(const Vec &p) { return {origin_x + (p.x - p.y) * unit * .866, origin_y + (p.x + p.y) * unit * .5 - p.z * unit * .82}; }
|
|
// A parallelogram: a corner and the two corners next to it.
|
|
struct Quad { Vec a, b, d; };
|
|
struct Hot {
|
|
std::string id; // "block:3", "facility:0", "periphery:12"
|
|
double depth = 0;
|
|
std::vector<Quad> quads;
|
|
};
|
|
struct Letter { std::string text; Point at; };
|
|
struct Scene {
|
|
std::string svg;
|
|
std::vector<Hot> hots; // sorted from the back to the front
|
|
std::vector<Letter> letters; // the stands' letters
|
|
};
|
|
|
|
namespace detail {
|
|
inline std::string num(double v) { char text[32]; std::snprintf(text, sizeof text, "%.1f", v); return text; }
|
|
inline std::string pt(const Vec &p) { const auto q = project(p); return num(q.x) + "," + num(q.y); }
|
|
inline std::string pts(const std::vector<Vec> &all) { std::string out; for (const auto &p : all) out += (out.empty() ? "" : " ") + pt(p); return out; }
|
|
inline std::array<int, 3> rgb(const std::string &hex) { return {std::stoi(hex.substr(1, 2), nullptr, 16), std::stoi(hex.substr(3, 2), nullptr, 16), std::stoi(hex.substr(5, 2), nullptr, 16)}; }
|
|
inline std::string mix(const std::string &a, const std::string &b, double t) {
|
|
const auto x = rgb(a), y = rgb(b); char text[16];
|
|
std::snprintf(text, sizeof text, "#%02x%02x%02x", int(std::lround(x[0] + (y[0] - x[0]) * t)), int(std::lround(x[1] + (y[1] - x[1]) * t)), int(std::lround(x[2] + (y[2] - x[2]) * t)));
|
|
return text;
|
|
}
|
|
// the colour of a face under the model's light: the top brightest, the side to the left darkest
|
|
inline std::string lit(const std::vector<Vec> &f, const std::string &base) {
|
|
const Vec u{f[1].x - f[0].x, f[1].y - f[0].y, f[1].z - f[0].z}, v{f[2].x - f[0].x, f[2].y - f[0].y, f[2].z - f[0].z};
|
|
const double nx = std::abs(u.y * v.z - u.z * v.y), ny = std::abs(u.z * v.x - u.x * v.z), nz = std::abs(u.x * v.y - u.y * v.x), sum = nx + ny + nz;
|
|
const double bright = sum > 0 ? (nz + nx * .66 + ny * .4) / sum : 1;
|
|
return mix(base, "#4a3c2e", (1 - bright) * .55);
|
|
}
|
|
inline Vec lerp(const Vec &a, const Vec &b, double t) { return {a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t}; }
|
|
inline const char *ink = "#3a332b";
|
|
inline std::string line(const Vec &a, const Vec &b, const std::string &colour, double w = 1, const std::string &more = "") {
|
|
const auto p = project(a), q = project(b);
|
|
return "<line x1=\"" + num(p.x) + "\" y1=\"" + num(p.y) + "\" x2=\"" + num(q.x) + "\" y2=\"" + num(q.y) + "\" stroke=\"" + colour + "\" stroke-width=\"" + num(w) + "\" stroke-linecap=\"round\" " + more + "/>";
|
|
}
|
|
inline const char *edge = "stroke=\"#3a332b\" stroke-opacity=\".55\" stroke-width=\".8\" stroke-linejoin=\"round\"";
|
|
inline std::string poly(const std::vector<Vec> &all, const std::string &fill, const std::string &more = edge) { return "<polygon points=\"" + pts(all) + "\" fill=\"" + fill + "\" " + more + "/>"; }
|
|
struct Face {
|
|
std::vector<Vec> p;
|
|
std::string colour, deco; // deco is drawn right after the face
|
|
bool raw = false; // keep the colour as it is
|
|
std::string more; // its own stroke attributes
|
|
double bias = 0;
|
|
};
|
|
// faces are painted from the back to the front
|
|
inline std::string paint(std::vector<Face> faces) {
|
|
const auto depth = [](const Face &f) { double sum = 0; for (const auto &p : f.p) sum += p.x + p.y + p.z * .9; return sum / double(f.p.size()) + f.bias; };
|
|
std::stable_sort(faces.begin(), faces.end(), [&](const Face &a, const Face &b) { return depth(a) < depth(b); });
|
|
std::string out;
|
|
for (const auto &f : faces) out += poly(f.p, f.raw ? f.colour : lit(f.p, f.colour), f.more.empty() ? edge : f.more) + f.deco;
|
|
return out;
|
|
}
|
|
struct BoxLook { std::string top, side_x, side_y, deco_top, deco_x, deco_y; };
|
|
inline std::vector<Face> box(double x0, double y0, double x1, double y1, double z0, double z1, const std::string &c, const BoxLook &o = {}) {
|
|
return {{{{x0, y0, z1}, {x1, y0, z1}, {x1, y1, z1}, {x0, y1, z1}}, o.top.empty() ? c : o.top, o.deco_top, false, "", .5},
|
|
{{{x1, y0, z0}, {x1, y1, z0}, {x1, y1, z1}, {x1, y0, z1}}, o.side_x.empty() ? c : o.side_x, o.deco_x},
|
|
{{{x0, y1, z0}, {x1, y1, z0}, {x1, y1, z1}, {x0, y1, z1}}, o.side_y.empty() ? c : o.side_y, o.deco_y}};
|
|
}
|
|
inline std::vector<Quad> box_quads(double x0, double y0, double x1, double y1, double z0, double z1) {
|
|
return {{{x0, y0, z1}, {x1, y0, z1}, {x0, y1, z1}}, {{x1, y0, z0}, {x1, y1, z0}, {x1, y0, z1}}, {{x0, y1, z0}, {x1, y1, z0}, {x0, y1, z1}}};
|
|
}
|
|
inline Quad ground(double x0, double y0, double x1, double y1) { return {{x0, y0, 0}, {x1, y0, 0}, {x0, y1, 0}}; }
|
|
inline const char *pane = "stroke=\"#3a332b\" stroke-opacity=\".5\" stroke-width=\".6\"";
|
|
// windows or panels on the face towards +x and on the one towards +y
|
|
inline std::string windows_x(double x, double y0, double y1, double z0, double z1, int n, const std::string &colour, double gap = .22) {
|
|
std::string out; const double w = (y1 - y0) / n;
|
|
for (int i = 0; i < n; ++i) { const double a = y0 + w * (i + gap), b = y0 + w * (i + 1 - gap); out += poly({{x, a, z0}, {x, b, z0}, {x, b, z1}, {x, a, z1}}, colour, pane); }
|
|
return out;
|
|
}
|
|
inline std::string windows_y(double y, double x0, double x1, double z0, double z1, int n, const std::string &colour, double gap = .22) {
|
|
std::string out; const double w = (x1 - x0) / n;
|
|
for (int i = 0; i < n; ++i) { const double a = x0 + w * (i + gap), b = x0 + w * (i + 1 - gap); out += poly({{a, y, z0}, {b, y, z0}, {b, y, z1}, {a, y, z1}}, colour, pane); }
|
|
return out;
|
|
}
|
|
inline std::string xml(const std::string &text) {
|
|
std::string out;
|
|
for (const char c : text) out += c == '&' ? "&" : c == '<' ? "<" : c == '>' ? ">" : c == '"' ? """ : std::string(1, c);
|
|
return out;
|
|
}
|
|
inline const char *lettering = "Georgia, 'Times New Roman', 'Liberation Serif', serif";
|
|
// writing on a face towards +y, and on one towards +x
|
|
inline std::string sign_y(double x, double y, double z, const std::string &text, double size, const std::string &fill = ink) {
|
|
const auto q = project({x, y, z});
|
|
return "<text transform=\"matrix(.866,.5,0,1," + num(q.x) + "," + num(q.y) + ")\" font-family=\"" + lettering + "\" font-size=\"" + num(size) + "\" fill=\"" + fill + "\">" + xml(text) + "</text>";
|
|
}
|
|
inline std::string sign_x(double x, double y, double z, const std::string &text, double size, const std::string &fill = ink) {
|
|
const auto q = project({x, y, z});
|
|
return "<text transform=\"matrix(.866,-.5,0,1," + num(q.x) + "," + num(q.y) + ")\" font-family=\"" + lettering + "\" font-size=\"" + num(size) + "\" fill=\"" + fill + "\">" + xml(text) + "</text>";
|
|
}
|
|
inline std::vector<std::array<double, 2>> hull(std::vector<std::array<double, 2>> all) {
|
|
std::sort(all.begin(), all.end());
|
|
const auto cross = [](const auto &o, const auto &a, const auto &b) { return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]); };
|
|
std::vector<std::array<double, 2>> lower, upper;
|
|
for (const auto &p : all) { while (lower.size() > 1 && cross(lower[lower.size() - 2], lower.back(), p) <= 0) lower.pop_back(); lower.push_back(p); }
|
|
for (auto p = all.rbegin(); p != all.rend(); ++p) { while (upper.size() > 1 && cross(upper[upper.size() - 2], upper.back(), *p) <= 0) upper.pop_back(); upper.push_back(*p); }
|
|
lower.pop_back(); upper.pop_back();
|
|
lower.insert(lower.end(), upper.begin(), upper.end());
|
|
return lower;
|
|
}
|
|
// the shadow a body of that height throws on the plate
|
|
inline std::string shadow(double x0, double y0, double x1, double y1, double tall) {
|
|
const double dx = -tall * .5, dy = tall * .22;
|
|
std::vector<std::array<double, 2>> all{{x0, y0}, {x1, y0}, {x1, y1}, {x0, y1}};
|
|
for (int i = 0; i < 4; ++i) all.push_back({all[size_t(i)][0] + dx, all[size_t(i)][1] + dy});
|
|
std::vector<Vec> outline;
|
|
for (const auto &p : hull(all)) outline.push_back({p[0], p[1], 0});
|
|
return poly(outline, "#4a3c2e", "fill-opacity=\".16\"");
|
|
}
|
|
inline std::string tree(double x, double y, double size, int tone) {
|
|
static constexpr std::array<std::array<const char *, 3>, 3> greens{{{"#5f7d4a", "#7f9b5c", "#a3ba7c"}, {"#56764f", "#74935f", "#98b183"}, {"#6c8444", "#8ea458", "#b3c47c"}}};
|
|
const auto q = project({x, y, 0}); const double r = 5.2 * size; const auto &g = greens[size_t(tone % 3)];
|
|
return "<ellipse cx=\"" + num(q.x - r * .7) + "\" cy=\"" + num(q.y + 1) + "\" rx=\"" + num(r * 1.1) + "\" ry=\"" + num(r * .42) + "\" fill=\"#4a3c2e\" opacity=\".16\"/><rect x=\"" + num(q.x - .9) + "\" y=\"" + num(q.y - r * 1.5) +
|
|
"\" width=\"1.8\" height=\"" + num(r * 1.5) + "\" fill=\"#7a5a3a\"/><circle cx=\"" + num(q.x) + "\" cy=\"" + num(q.y - r * 2.1) + "\" r=\"" + num(r) + "\" fill=\"" + g[0] + "\" stroke=\"" + ink +
|
|
"\" stroke-opacity=\".5\" stroke-width=\".7\"/><circle cx=\"" + num(q.x + r * .2) + "\" cy=\"" + num(q.y - r * 2.35) + "\" r=\"" + num(r * .72) + "\" fill=\"" + g[1] + "\"/><circle cx=\"" + num(q.x + r * .36) + "\" cy=\"" +
|
|
num(q.y - r * 2.6) + "\" r=\"" + num(r * .4) + "\" fill=\"" + g[2] + "\"/>";
|
|
}
|
|
inline std::string car(double x, double y, const std::string &colour, bool along) {
|
|
const double l = 4.6, w = 2.3;
|
|
auto faces = along ? box(x, y, x + l, y + w, 0, 1.1, colour) : box(x, y, x + w, y + l, 0, 1.1, colour);
|
|
const auto cabin = along ? box(x + 1, y + .2, x + l - 1.1, y + w - .2, 1.1, 2, "#dfe9ee") : box(x + .2, y + 1, x + w - .2, y + l - 1.1, 1.1, 2, "#dfe9ee");
|
|
faces.insert(faces.end(), cabin.begin(), cabin.end());
|
|
return paint(faces);
|
|
}
|
|
// poles and boards in front of the faces that are being built
|
|
inline std::string scaffold(const std::vector<Face> &faces) {
|
|
std::string out;
|
|
for (const auto &f : faces) {
|
|
if (f.p.size() < 4) continue;
|
|
const auto &a = f.p[0], &b = f.p[1], &c = f.p[2], &d = f.p[3];
|
|
for (int i = 0; i <= 6; ++i) out += line(lerp(a, b, i / 6.), lerp(d, c, i / 6.), "#a8782e", 1);
|
|
for (int j = 0; j <= 3; ++j) out += line(lerp(a, d, j / 3.), lerp(b, c, j / 3.), "#a8782e", 1);
|
|
for (int i = 0; i < 6; i += 2) out += line(lerp(a, b, i / 6.), lerp(d, c, (i + 1) / 6.), "#c79a4e", .7);
|
|
}
|
|
return out;
|
|
}
|
|
inline std::string crane(double x, double y, double tall) {
|
|
const auto a = project({x, y, 0}), b = project({x, y, tall});
|
|
return "<line x1=\"" + num(a.x) + "\" y1=\"" + num(a.y) + "\" x2=\"" + num(b.x) + "\" y2=\"" + num(b.y) + "\" stroke=\"#d08a1e\" stroke-width=\"2.4\"/><path d=\"M" + num(a.x - 5) + " " + num(a.y) + "h10\" stroke=\"" + ink +
|
|
"\" stroke-width=\"2\"/><path d=\"M" + num(b.x - 16) + " " + num(b.y + 3) + "L" + num(b.x) + " " + num(b.y - 7) + "L" + num(b.x + 46) + " " + num(b.y + 2) + "M" + num(b.x - 16) + " " + num(b.y + 3) + "H" + num(b.x + 46) +
|
|
"\" fill=\"none\" stroke=\"#d08a1e\" stroke-width=\"2\"/><rect x=\"" + num(b.x - 18) + "\" y=\"" + num(b.y + 3) + "\" width=\"8\" height=\"6\" fill=\"#7a6a58\"/><path d=\"M" + num(b.x + 34) + " " + num(b.y + 3) + "v20\" stroke=\"" + ink +
|
|
"\" stroke-width=\".8\"/><rect x=\"" + num(b.x + 30) + "\" y=\"" + num(b.y + 23) + "\" width=\"8\" height=\"5\" fill=\"#c9b28a\" stroke=\"" + ink + "\" stroke-width=\".6\"/>";
|
|
}
|
|
// the outline of a plot nothing stands on yet
|
|
inline std::string plot(double x0, double y0, double x1, double y1) {
|
|
return poly({{x0, y0, 0}, {x1, y0, 0}, {x1, y1, 0}, {x0, y1, 0}}, "none", "stroke=\"#645c50\" stroke-width=\"1.3\" stroke-dasharray=\"5 4\" stroke-linejoin=\"round\"");
|
|
}
|
|
// a small generator of its own: the scatter of cars, trees and people never changes
|
|
struct Random {
|
|
uint32_t state;
|
|
double next() { state = state * 1664525u + 1013904223u; return double(state >> 8) / 16777216.; }
|
|
int between(int lo, int hi) { return lo + int(next() * (hi - lo + 1)); }
|
|
};
|
|
} // namespace detail
|
|
|
|
// `sign` is written over the gate. With `future`, what is being built stands finished.
|
|
inline Scene build(const Json &overview, bool future, const std::string &sign) {
|
|
using namespace detail;
|
|
Scene scene;
|
|
struct Item { double depth; std::string svg; };
|
|
std::vector<Item> items;
|
|
const auto hot = [&](const std::string &id, double depth, std::vector<Quad> quads) {
|
|
for (auto &h : scene.hots)
|
|
if (h.id == id) { h.depth = std::max(h.depth, depth); h.quads.insert(h.quads.end(), quads.begin(), quads.end()); return; }
|
|
scene.hots.push_back({id, depth, std::move(quads)});
|
|
};
|
|
static const Json none = Json::object();
|
|
const auto &blocks = overview.contains("blocks") ? overview.at("blocks") : Json::array();
|
|
const auto &facilities = overview.contains("facilities") ? overview.at("facilities") : Json::array();
|
|
const auto &periphery = overview.contains("periphery") ? overview.at("periphery") : Json::array();
|
|
const auto facility = [&](size_t i) -> const Json & { return i < facilities.size() ? facilities[i] : none; };
|
|
const auto around = [&](size_t i) -> const Json & { return i < periphery.size() ? periphery[i] : none; };
|
|
// levels count from 1; the model draws from 0
|
|
const auto grade = [&](size_t i) { const auto &f = facility(i); return std::clamp(f.value("display_level", f.value("level", 1)) - 1, 0, 3); };
|
|
// a building that Modern extends in stages (stage 1 = as built) is drawn by its stage; in the
|
|
// view of the future the stage under construction counts as finished
|
|
const auto stage_of = [&](const Json &row) { return row.contains("stage") ? row.value("stage", 0) + (future && row.value("expanding", false) && row.value("stage", 0) > 0 ? 1 : 0) : -1; };
|
|
const auto level = [&](size_t i) {
|
|
const auto &p = around(i);
|
|
const int built = std::max(0, p.value("display_level", p.value("level", 0)));
|
|
return stage_of(p) >= 0 && built > 0 ? std::max(1, stage_of(p)) : built;
|
|
};
|
|
const auto most = [&](size_t i) { return std::max(1, around(i).contains("stages") ? around(i).value("stages", 1) : around(i).value("max_level", 1)); };
|
|
const auto busy = [&](const Json &row) { return !future && (row.value("building", false) || row.value("expanding", false)); };
|
|
|
|
// ---- the stands: the four with the most room are the long and short sides ----
|
|
constexpr double G = 40, G2 = 58.5, H0 = 1.6;
|
|
struct Stand { size_t index; int place; double places, limit; bool seats, roof, building; };
|
|
std::vector<Stand> stands;
|
|
double even = 0, odd = 0;
|
|
for (size_t i = 0; i < 8 && i < blocks.size(); ++i) (i % 2 ? odd : even) += blocks[i].value("max_places", 0.0);
|
|
for (size_t i = 0; i < 8 && i < blocks.size(); ++i) {
|
|
const auto &b = blocks[i];
|
|
const double shown = b.value("display_places", 0.0), stands_now = b.value("places", shown);
|
|
stands.push_back({i, int(even >= odd ? i : (i + 7) % 8), !future && b.value("building", false) ? stands_now : shown, std::max(1.0, b.value("max_places", 1.0)), b.value("display_seats", false), b.value("display_roof", false), busy(b)});
|
|
}
|
|
const auto deep = [&](const Stand &s, double places) { return s.place % 2 == 0 ? 8 + places / s.limit * (s.limit > 12000 ? 24 : 20) : 7 + places / s.limit * 15; };
|
|
const auto on_side = [&](int side, double u, double v, double z) -> Vec { return side == 0 ? Vec{u, -G - v, z} : side == 2 ? Vec{u, G + v, z} : side == 1 ? Vec{G2 + v, u, z} : Vec{-G2 - v, u, z}; };
|
|
double depth_west = 8, depth_north = 8;
|
|
for (const auto &s : stands) {
|
|
const double d = deep(s, s.places), full = deep(s, s.limit), tall = 2.5 + d * .6;
|
|
if (s.place == 6) depth_west = d;
|
|
if (s.place == 0) depth_north = d;
|
|
const std::string id = "block:" + std::to_string(s.index), seat = s.seats ? "#c8733c" : "#cfc7b6", wall = "#efe6d2", row_ink = s.seats ? "#8c491a" : "#8a8274";
|
|
std::vector<Face> faces, roof; std::vector<Quad> quads; std::string before, after; Vec centre, crane_at; std::vector<Face> worked;
|
|
const int rows = std::max(3, int(std::lround(d / 3)));
|
|
if (s.place % 2 == 0) {
|
|
const int side = s.place / 2; const double half = side == 0 || side == 2 ? G2 : G;
|
|
const auto m = [&](double u, double v, double z) { return on_side(side, u, v, z); };
|
|
const int n = int(std::lround(half / 7.3));
|
|
const Vec in0 = m(-half, 0, H0), in1 = m(half, 0, H0), o0 = m(-half, d, tall), o1 = m(half, d, tall);
|
|
std::string deco;
|
|
for (int i = 1; i < rows; ++i) deco += line(lerp(in0, o0, double(i) / rows), lerp(in1, o1, double(i) / rows), row_ink, .7, "stroke-opacity=\".7\"");
|
|
for (int i = 1; i < n * 2; ++i) deco += line(lerp(in0, in1, i / (n * 2.)), lerp(o0, o1, i / (n * 2.)), s.seats ? "#f3d9c2" : "#f3eee2", i % 2 ? .5 : 1.6);
|
|
// the crush barriers of a terrace
|
|
if (!s.seats)
|
|
for (int i = 0; i < n * 2; ++i)
|
|
for (int r = 1; r < rows; r += 2) {
|
|
const Vec a = lerp(lerp(in0, in1, (i + .3) / (n * 2.)), lerp(o0, o1, (i + .3) / (n * 2.)), double(r) / rows), c = lerp(lerp(in0, in1, (i + .7) / (n * 2.)), lerp(o0, o1, (i + .7) / (n * 2.)), double(r) / rows);
|
|
deco += line({a.x, a.y, a.z + .9}, {c.x, c.y, c.z + .9}, "#6f6a60", .9);
|
|
}
|
|
std::string back; const Vec b0 = m(-half, d, 0), b1 = m(half, d, 0), t0 = m(-half, d, tall), t1 = m(half, d, tall);
|
|
for (int i = 0; i <= n * 2; ++i) back += line(lerp(b0, b1, i / (n * 2.)), lerp(t0, t1, i / (n * 2.)), "#b9ad94", i % 2 ? .6 : 1.3);
|
|
back += poly({lerp(b0, t0, .72), lerp(b1, t1, .72), lerp(b1, t1, .9), lerp(b0, t0, .9)}, "#c8733c", "stroke=\"none\"");
|
|
for (int i = 1; i < n * 2; i += 2) {
|
|
const Vec a = lerp(b0, b1, (i - .28) / (n * 2.)), c = lerp(b0, b1, (i + .28) / (n * 2.)); const double door = std::min(4.5, tall * .4);
|
|
back += poly({a, c, {c.x, c.y, door}, {a.x, a.y, door}}, "#6b5a48", "stroke=\"none\"");
|
|
}
|
|
faces = {{{in0, in1, o1, o0}, seat, deco, true}, {{m(-half, 0, 0), m(half, 0, 0), in1, in0}, wall}, {{m(-half, 0, 0), m(-half, d, 0), o0, in0}, wall}, {{m(half, 0, 0), m(half, d, 0), o1, in1}, wall}, {{b0, b1, t1, t0}, wall, back}};
|
|
quads = {{in0, in1, o0}, {b0, b1, t0}, {m(-half, 0, 0), m(-half, d, 0), in0}, {m(half, 0, 0), m(half, d, 0), in1}};
|
|
worked = {faces[3], faces[4]};
|
|
if (s.roof) {
|
|
const Vec r0 = m(-half - 1, d + 1, tall + 5), r1 = m(half + 1, d + 1, tall + 5), r2 = m(half + 1, d * .18, tall + 7.5), r3 = m(-half - 1, d * .18, tall + 7.5);
|
|
std::string trusses;
|
|
for (int i = 0; i <= n; ++i) { trusses += line(lerp(r0, r1, double(i) / n), lerp(r3, r2, double(i) / n), "#8f8778", 1); trusses += line(lerp(t0, t1, double(i) / n), lerp(r0, r1, double(i) / n), "#8f8778", 1.4); }
|
|
trusses += line(lerp(r0, r3, .5), lerp(r1, r2, .5), "#8f8778", .7);
|
|
roof.push_back({{r0, r1, r2, r3}, "#fbf7ee", trusses, true, std::string("fill-opacity=\"") + (side == 0 || side == 3 ? ".58" : ".9") + "\" stroke=\"#3a332b\" stroke-opacity=\".6\" stroke-width=\"1\" stroke-linejoin=\"round\""});
|
|
quads.push_back({r0, r1, r3});
|
|
}
|
|
centre = m(0, d / 2, 0); crane_at = m(half * .5, d + 6, 0);
|
|
// how far the stand may grow
|
|
if (!future && s.places < s.limit)
|
|
before = poly({m(-half, d, 0), m(half, d, 0), m(half, full, 0), m(-half, full, 0)}, "#ffffff", "fill-opacity=\".18\" stroke=\"#645c50\" stroke-width=\"1.2\" stroke-dasharray=\"5 4\" stroke-linejoin=\"round\"");
|
|
} else {
|
|
const int sx = s.place == 1 || s.place == 3 ? 1 : -1, sy = s.place == 3 || s.place == 5 ? 1 : -1;
|
|
const auto m = [&](double a, double c, double z) -> Vec { return {sx * (G2 + a), sy * (G + c), z}; };
|
|
const Vec inner = m(0, 0, H0), a = m(d, 0, tall), corner = m(d, d, tall), b = m(0, d, tall);
|
|
std::string first, second;
|
|
for (int i = 1; i < rows; ++i) {
|
|
first += line(lerp(inner, a, double(i) / rows), lerp(inner, corner, double(i) / rows), row_ink, .7, "stroke-opacity=\".7\"");
|
|
second += line(lerp(inner, corner, double(i) / rows), lerp(inner, b, double(i) / rows), row_ink, .7, "stroke-opacity=\".7\"");
|
|
}
|
|
const auto band = [&](const Vec &p, const Vec &q) { return poly({{p.x, p.y, tall * .72}, {q.x, q.y, tall * .72}, {q.x, q.y, tall * .9}, {p.x, p.y, tall * .9}}, "#c8733c", "stroke=\"none\""); };
|
|
faces = {{{inner, a, corner}, seat, first, true}, {{inner, corner, b}, mix(seat, "#4a3c2e", .08), second, true}, {{m(d, 0, 0), m(d, d, 0), corner, a}, wall, band(m(d, 0, 0), m(d, d, 0))},
|
|
{{m(0, d, 0), m(d, d, 0), corner, b}, wall, band(m(0, d, 0), m(d, d, 0))}, {{m(0, 0, 0), m(d, 0, 0), a, inner}, wall}, {{m(0, 0, 0), m(0, d, 0), b, inner}, wall}};
|
|
quads = {{m(0, 0, tall * .55), m(d, 0, tall * .55), m(0, d, tall * .55)}, {m(d, 0, 0), m(d, d, 0), a}, {m(0, d, 0), m(d, d, 0), b}};
|
|
worked = {faces[2], faces[3]};
|
|
if (s.roof) {
|
|
const Vec peak = m(d * .2, d * .2, tall + 7.5);
|
|
roof.push_back({{m(d + 1, 0, tall + 5), m(d + 1, d + 1, tall + 5), m(0, d + 1, tall + 5), peak}, "#fbf7ee", "", true, "fill-opacity=\".75\" stroke=\"#3a332b\" stroke-opacity=\".6\" stroke-width=\"1\" stroke-linejoin=\"round\""});
|
|
quads.push_back({m(0, 0, tall + 6), m(d + 1, 0, tall + 6), m(0, d + 1, tall + 6)});
|
|
}
|
|
centre = m(d / 2, d / 2, 0); crane_at = m(d + 5, d + 5, 0);
|
|
if (!future && s.places < s.limit)
|
|
before = poly({m(d, 0, 0), m(full, 0, 0), m(full, full, 0), m(0, full, 0), m(0, d, 0), m(d, d, 0)}, "#ffffff", "fill-opacity=\".18\" stroke=\"#645c50\" stroke-width=\"1.2\" stroke-dasharray=\"5 4\" stroke-linejoin=\"round\"");
|
|
}
|
|
if (s.building) after = scaffold(worked) + crane(crane_at.x, crane_at.y, tall + 16);
|
|
const double depth = centre.x + centre.y;
|
|
if (s.places <= 0) faces.clear(), roof.clear();
|
|
items.push_back({depth, before + paint(faces) + after});
|
|
if (!roof.empty()) items.push_back({depth + 1.2, paint(roof)});
|
|
hot(id, depth, quads);
|
|
scene.letters.push_back({blocks[s.index].value("letter", std::string(1, char('A' + s.index))), project({centre.x, centre.y, tall + (s.roof ? 9 : 3)})});
|
|
}
|
|
|
|
// ---- the pitch: its green tells the state of the turf, dots the heating under it ----
|
|
{
|
|
static constexpr std::array<const char *, 4> light{"#b8b279", "#a9bd7a", "#93b46a", "#7fae5c"}, dark{"#aba56c", "#9db06e", "#86a95f", "#6f9f50"};
|
|
const int turf = grade(4);
|
|
std::string pitch = poly({{-52.5, -34, 0}, {52.5, -34, 0}, {52.5, 34, 0}, {-52.5, 34, 0}}, light[size_t(turf)], "stroke=\"none\"");
|
|
for (int i = 0; i < 10; i += 2) pitch += poly({{-52.5 + i * 10.5, -34, 0}, {-42 + i * 10.5, -34, 0}, {-42 + i * 10.5, 34, 0}, {-52.5 + i * 10.5, 34, 0}}, dark[size_t(turf)], "stroke=\"none\"");
|
|
if (turf == 0)
|
|
for (const auto &worn : std::array<std::array<double, 3>, 5>{{{-20, 5, 7}, {14, -12, 5}, {38, 10, 6}, {-40, -18, 4}, {0, 22, 5}}}) {
|
|
const auto q = project({worn[0], worn[1], 0});
|
|
pitch += "<ellipse cx=\"" + num(q.x) + "\" cy=\"" + num(q.y) + "\" rx=\"" + num(worn[2] * unit * 1.1) + "\" ry=\"" + num(worn[2] * unit * .6) + "\" fill=\"#a58f5c\" opacity=\".6\"/>";
|
|
}
|
|
if (facility(2).value("display_level", facility(2).value("level", 1)) >= 2)
|
|
for (double y = -30; y <= 30; y += 6) pitch += line({-50, y, 0}, {50, y, 0}, "#d9824a", .8, "stroke-opacity=\".5\" stroke-dasharray=\"1 5\"");
|
|
const std::string chalk = "stroke=\"#fdfbf4\" stroke-width=\"1.3\" stroke-linejoin=\"round\"";
|
|
std::vector<Vec> circle;
|
|
for (int i = 0; i < 28; ++i) circle.push_back({std::cos(i / 28. * 6.283) * 9.15, std::sin(i / 28. * 6.283) * 9.15, 0});
|
|
pitch += poly({{-50, -31, 0}, {50, -31, 0}, {50, 31, 0}, {-50, 31, 0}}, "none", chalk) + line({0, -31, 0}, {0, 31, 0}, "#fdfbf4", 1.3) + poly(circle, "none", chalk);
|
|
for (const double k : {-1.0, 1.0}) {
|
|
pitch += poly({{k * 50, -20, 0}, {k * 33.5, -20, 0}, {k * 33.5, 20, 0}, {k * 50, 20, 0}}, "none", chalk) + poly({{k * 50, -9, 0}, {k * 44.5, -9, 0}, {k * 44.5, 9, 0}, {k * 50, 9, 0}}, "none", chalk);
|
|
pitch += line({k * 50, -3.7, 0}, {k * 50, -3.7, 2.6}, "#ffffff", 1.4) + line({k * 50, 3.7, 0}, {k * 50, 3.7, 2.6}, "#ffffff", 1.4) + line({k * 50, -3.7, 2.6}, {k * 50, 3.7, 2.6}, "#ffffff", 1.4) +
|
|
poly({{k * 50, -3.7, 2.6}, {k * 50, 3.7, 2.6}, {k * 52.3, 3.7, 0}, {k * 52.3, -3.7, 0}}, "#ffffff", "fill-opacity=\".35\" stroke=\"#ffffff\" stroke-width=\".5\"");
|
|
}
|
|
items.push_back({-9999, pitch});
|
|
hot("facility:4", -9999, {ground(-52.5, -34, 52.5, 34)});
|
|
// the two benches
|
|
items.push_back({-30, paint(box(-9, -38.4, -2, -36.4, 0, 2, "#f3ede0")) + paint(box(2, -38.4, 9, -36.4, 0, 2, "#f3ede0"))});
|
|
}
|
|
|
|
// ---- the stadium's equipment ----
|
|
{
|
|
const int lights = grade(0), lamps_across = lights + 2; const double mast = std::array<double, 4>{16, 24, 32, 42}[size_t(lights)];
|
|
for (const auto &at : std::array<std::array<double, 2>, 4>{{{-90, -72}, {90, -72}, {90, 72}, {-90, 72}}}) {
|
|
const double x = at[0], y = at[1]; const auto top = project({x, y, mast});
|
|
const double head_w = lamps_across * 3.4 + 3, head_h = (lamps_across - 1) * 3.5 + 5;
|
|
std::string lamps;
|
|
for (int i = 0; i < lamps_across; ++i)
|
|
for (int j = 0; j < lamps_across - 1; ++j)
|
|
lamps += "<circle cx=\"" + num(top.x + (i - (lamps_across - 1) / 2.) * 3.4) + "\" cy=\"" + num(top.y - head_h + 4.2 + j * 3.5) + "\" r=\"1.5\" fill=\"#fff6c9\" stroke=\"" + ink + "\" stroke-width=\".5\"/>";
|
|
items.push_back({x + y, poly({{x - 1.2, y - 1.2, 0}, {x + 1.2, y - 1.2, 0}, {x + 1.2, y + 1.2, 0}, {x - 1.2, y + 1.2, 0}}, "#bdb4a0") + line({x, y, 0}, {x, y, mast}, "#8f8778", 3) + line({x, y, 0}, {x, y, mast}, "#d9d2c2", 1.2) +
|
|
"<rect x=\"" + num(top.x - head_w / 2) + "\" y=\"" + num(top.y - head_h) + "\" width=\"" + num(head_w) + "\" height=\"" + num(head_h) + "\" rx=\"2\" fill=\"#5d5648\" stroke=\"" + ink + "\" stroke-width=\".8\"/>" + lamps +
|
|
(busy(facility(0)) ? crane(x + 5, y + 5, mast + 8) : std::string())});
|
|
hot("facility:0", x + y, {{{x - 3.5, y + 3.5, 0}, {x + 3.5, y - 3.5, 0}, {x - 3.5, y + 3.5, mast + head_h / 2 + 2}}});
|
|
}
|
|
// the scoreboard behind the west stand
|
|
const int board = grade(1); const double bw = std::array<double, 4>{9, 13, 17, 22}[size_t(board)], bh = std::array<double, 4>{5, 7, 9, 12}[size_t(board)];
|
|
const double bx = -G2 - depth_west - 5, bz = 2.5 + depth_west * .6 + 3;
|
|
BoxLook screen;
|
|
screen.deco_x = poly({{bx, -bw + 1.2, bz + 1.2}, {bx, bw - 1.2, bz + 1.2}, {bx, bw - 1.2, bz + bh * 1.6 - 1.2}, {bx, -bw + 1.2, bz + bh * 1.6 - 1.2}}, "#2f3a2c", "stroke=\"none\"") + sign_x(bx, bw * .45, bz + bh * .55, "2 : 1", bh * 1.25, "#ffd98a");
|
|
items.push_back({bx - 1, line({bx - 1, -bw + 3, 0}, {bx - 1, -bw + 3, bz}, "#8f8778", 2.2) + line({bx - 1, bw - 3, 0}, {bx - 1, bw - 3, bz}, "#8f8778", 2.2) + paint(box(bx - 2, -bw, bx, bw, bz, bz + bh * 1.6, "#4c463c", screen)) +
|
|
(busy(facility(1)) ? crane(bx + 4, bw + 4, bz + bh * 1.6 + 8) : std::string())});
|
|
hot("facility:1", bx - 1, box_quads(bx - 2, -bw, bx, bw, bz, bz + bh * 1.6));
|
|
// the lounge in the main stand; where there is none, its place is only marked
|
|
const bool lounge = facility(3).value("max_level", 2) > 2 || facility(3).value("display_level", facility(3).value("level", 1)) >= 2;
|
|
const int lounge_stage = lounge ? std::clamp(stage_of(facility(3)), 0, 4) : 0; // 0: not staged (the demo, an older engine)
|
|
const int lounge_size = facility(3).value("max_level", 2) <= 2 ? 2 : grade(3);
|
|
const double lounge_rise = lounge_stage > 1 ? (lounge_stage - 1) * 1.5 : 0;
|
|
const double north_tall = 2.5 + depth_north * .6, vw = lounge_stage ? std::array<double, 5>{24, 20, 25, 30, 35}[size_t(lounge_stage)] : std::array<double, 5>{10, 16, 24, 34, 34}[size_t(std::clamp(lounge_size, 0, 4))], vy = -G - depth_north * .62, vz = H0 + (north_tall - H0) * .62;
|
|
BoxLook glass; glass.deco_y = windows_y(vy, -vw, vw, vz + .4, vz + 3, int(std::lround(vw / 2.2)), "#bfe0ea", .1) + (lounge_rise > 0 ? windows_y(vy, -vw, vw, vz + 3.5, vz + 3.2 + lounge_rise, int(std::lround(vw / 2.2)), "#d7ecf2", .1) : std::string()); glass.top = "#e9dfc9";
|
|
items.push_back({-G - depth_north / 2 + .6, lounge ? paint(box(-vw, vy - 3.4, vw, vy, vz - .5, vz + 3.6 + lounge_rise, "#f6f0e2", glass)) + (busy(facility(3)) && facility(3).value("expanding", false) ? crane(vw + 4, vy - 2, vz + 14) : std::string())
|
|
: poly({{-vw, vy, vz - .5}, {vw, vy, vz - .5}, {vw, vy, vz + 3.6}, {-vw, vy, vz + 3.6}}, "#ffffff", "fill-opacity=\".25\" stroke=\"#645c50\" stroke-width=\"1.1\" stroke-dasharray=\"4 3\"")});
|
|
hot("facility:3", -G - depth_north / 2 + .6, box_quads(-vw, vy - 3.4, vw, vy, vz - .5, vz + 3.6));
|
|
// three small houses in the corners of the forecourt: heating, comfort, upkeep
|
|
const auto hut = [&](size_t index, bool built, double x0, double y0, double x1, double y1, double tall, const std::string &colour, const BoxLook &look, const std::string &extra) {
|
|
items.push_back({(x0 + x1 + y0 + y1) / 2, (built ? shadow(x0, y0, x1, y1, tall) + paint(box(x0, y0, x1, y1, 0, tall, colour, look)) + extra : plot(x0, y0, x1, y1)) + (busy(facility(index)) ? crane(x1 + 3, y1 + 3, tall + 12) : std::string())});
|
|
hot("facility:" + std::to_string(index), (x0 + x1 + y0 + y1) / 2, built ? box_quads(x0, y0, x1, y1, 0, tall) : std::vector<Quad>{ground(x0, y0, x1, y1)});
|
|
};
|
|
{
|
|
BoxLook look; look.top = "#c8733c"; look.deco_y = windows_y(74, 84, 94, 1, 4.2, 2, "#bfe0ea");
|
|
const auto s1 = project({92, 67, 13}), s2 = project({92, 67, 16});
|
|
hut(2, facility(2).value("display_level", facility(2).value("level", 1)) >= 2, 84, 64, 94, 74, 6, "#e9dfc9", look,
|
|
paint(box(91, 66, 93, 68, 6, 11, "#b9ad94")) + "<circle cx=\"" + num(s1.x) + "\" cy=\"" + num(s1.y) + "\" r=\"3\" fill=\"#ffffff\" opacity=\".7\"/><circle cx=\"" + num(s2.x + 3) + "\" cy=\"" + num(s2.y) + "\" r=\"4\" fill=\"#ffffff\" opacity=\".5\"/>");
|
|
}
|
|
{
|
|
const int comfort = grade(5); BoxLook look;
|
|
look.top = std::array<const char *, 4>{"#b9ad94", "#c9b28a", "#d9a05e", "#c8733c"}[size_t(comfort)]; look.deco_y = windows_y(74, -95, -83, 1, 3.4, 3, "#bfe0ea"); look.deco_x = windows_x(-83, 62, 74, 1, 3.4, 2, "#6b5a48");
|
|
hut(5, true, -95, 62, -83, 74, 4 + comfort, "#f6f0e2", look, sign_y(-94.5, 74, 4.2 + comfort * .2, "WC · Kiosk", 4.2));
|
|
}
|
|
{
|
|
const int upkeep = grade(6); BoxLook look; look.top = "#8fa073"; look.deco_y = windows_y(-66, 84, 94, .6, 3.8, 2, "#7a6a58", .12);
|
|
hut(6, true, 84, -76, 94, -66, 5, std::array<const char *, 4>{"#c9c0ad", "#ddd3bd", "#ebe2cd", "#f6f0e2"}[size_t(upkeep)], look,
|
|
line({95.5, -68, 0}, {94.2, -68, 5}, "#a8782e", 1.2) + line({95.5, -70, 0}, {94.2, -70, 5}, "#a8782e", 1.2) + paint(box(96, -74, 98, -72, 0, 1.6, "#c8733c")));
|
|
}
|
|
// safety: the fence along the forecourt and the gate with the ground's name
|
|
{
|
|
const int safety = grade(7); std::string fence;
|
|
for (double x = -96; x < 96; x += 6)
|
|
if (std::abs(x + 3) > 12) fence += line({x, 78, 0}, {x, 78, 2 + safety * .5}, "#6f6a60", .9) + line({x, 78, 2 + safety * .5}, {x + 6, 78, 2 + safety * .5}, "#6f6a60", .9);
|
|
BoxLook lintel; lintel.deco_y = sign_y(-9.5, 80, 7.5, sign, 4.4, "#fff8ea");
|
|
auto gate = box(-12, 77, -8, 80, 0, 7, "#efe6d2"); const auto right = box(8, 77, 12, 80, 0, 7, "#efe6d2"), over = box(-12, 77, 12, 80, 7, 9.5, "#c8733c", lintel);
|
|
gate.insert(gate.end(), right.begin(), right.end()); gate.insert(gate.end(), over.begin(), over.end());
|
|
items.push_back({80, fence + paint(gate) + windows_y(80, -8, 8, 0, 2.6, 4 + safety, "#6f6a60", .35) +
|
|
(safety > 1 ? line({14, 79, 0}, {14, 79, 12}, "#8f8778", 1.6) + paint(box(13, 78.4, 15.5, 79.6, 12, 13.2, "#4c463c")) : std::string()) + (busy(facility(7)) ? crane(18, 82, 20) : std::string())});
|
|
hot("facility:7", 80, box_quads(-12, 77, 12, 80, 0, 9.5));
|
|
}
|
|
}
|
|
|
|
// ---- around the ground ----
|
|
const auto name = [](size_t i) { return "periphery:" + std::to_string(i); };
|
|
const auto works = [&](size_t i, double x, double y, double tall) { return busy(around(i)) ? crane(x, y, tall) : std::string(); };
|
|
{
|
|
// roads; from the third stage of the transport links a tram runs along them
|
|
const int links = level(0);
|
|
std::string road = poly({{-160, 104, 0}, {160, 104, 0}, {160, 122, 0}, {-160, 122, 0}}, "#cfc9bd", "stroke=\"#3a332b\" stroke-opacity=\".35\" stroke-width=\".8\"");
|
|
for (double x = -154; x < 156; x += 12) road += line({x, 109, 0}, {x + 6, 109, 0}, "#fbf7ee", 1.1);
|
|
road += poly({{112, -128, 0}, {124, -128, 0}, {124, 104, 0}, {112, 104, 0}}, "#cfc9bd", "stroke=\"none\"") + poly({{-6, 82, 0}, {6, 82, 0}, {6, 104, 0}, {-6, 104, 0}}, "#e6dcc6", "stroke=\"none\"");
|
|
if (links >= 3) {
|
|
road += line({-160, 115, 0}, {160, 115, 0}, "#6f6a60", 1) + line({-160, 117.4, 0}, {160, 117.4, 0}, "#6f6a60", 1);
|
|
for (double x = -158; x < 160; x += 5) road += line({x, 114.4, 0}, {x, 118, 0}, "#8a8274", .6);
|
|
}
|
|
road += car(-70, 105.5, "#c8733c", true) + car(-20, 105.5, "#7a8a5e", true) + car(52, 110.5, "#f3ede0", true) + car(96, 105.5, "#5d7f96", true) + car(115, -60, "#d9b24a", false) + car(115, 30, "#b9ad94", false);
|
|
items.push_back({-9000, road});
|
|
hot(name(0), -9000, {ground(-160, 104, 160, 122)});
|
|
if (links >= 2) {
|
|
// a bus stop with its bus
|
|
auto shelter = box(-124, 98, -108, 101.5, 4.6, 5.2, "#c8733c"); const auto post_a = box(-124, 98, -123.4, 101.5, 0, 4.6, "#d9d2c2"), post_b = box(-108.6, 98, -108, 101.5, 0, 4.6, "#d9d2c2");
|
|
shelter.insert(shelter.end(), post_a.begin(), post_a.end()); shelter.insert(shelter.end(), post_b.begin(), post_b.end());
|
|
BoxLook bus; bus.deco_y = windows_y(109, -100, -84, 2.6, 4.6, 5, "#dfe9ee", .12);
|
|
items.push_back({-16, shadow(-124, 98, -108, 101.5, 5) + paint(shelter) + paint(box(-121, 99.4, -111, 100.4, 0, 1.2, "#8a6a4a")) + sign_y(-122, 101.5, 5.4, "H", 5, "#2f6b2f") + paint(box(-100, 105, -84, 109, .8, 5.2, "#d9b24a", bus))});
|
|
hot(name(0), -16, box_quads(-124, 98, -108, 101.5, 0, 5.2));
|
|
}
|
|
if (links >= 3) {
|
|
BoxLook tram; tram.top = "#f3ede0";
|
|
tram.deco_y = windows_y(117.8, 40, 66, 2.6, 4.8, 8, "#dfe9ee", .12) + poly({{40, 117.8, 1.4}, {66, 117.8, 1.4}, {66, 117.8, 2.2}, {40, 117.8, 2.2}}, "#f6ecd8", "stroke=\"none\"");
|
|
items.push_back({176, paint(box(40, 114.6, 66, 117.8, .8, 5.4, "#c8733c", tram)) + line({53, 116.2, 5.4}, {53, 116.2, 8.5}, ink, .8) + line({46, 116.2, 8.5}, {60, 116.2, 8.5}, ink, .8)});
|
|
}
|
|
// the station is the last stage; until then its plot is marked
|
|
if (links >= 4) {
|
|
const auto clock = project({74, 99, 11.6});
|
|
BoxLook hall; hall.top = "#b9ad94"; hall.deco_y = windows_y(99, 44, 104, 2, 7, 10, "#bfe0ea", .18) + sign_y(62, 99, 9.6, "BAHNHOF", 6.5);
|
|
BoxLook tower; tower.top = "#c8733c"; tower.deco_y = "<circle cx=\"" + num(clock.x) + "\" cy=\"" + num(clock.y) + "\" r=\"3.4\" fill=\"#fbf7ee\" stroke=\"" + std::string(ink) + "\" stroke-width=\".8\"/>";
|
|
auto station = box(44, 86, 104, 99, 0, 9, "#efe6d2", hall); const auto upper = box(68, 84, 80, 99, 9, 14, "#efe6d2", tower);
|
|
station.insert(station.end(), upper.begin(), upper.end());
|
|
items.push_back({173, shadow(44, 86, 104, 99, 10) + paint(station) + works(0, 108, 100, 24)});
|
|
hot(name(0), 173, box_quads(44, 86, 104, 99, 0, 9));
|
|
} else if (most(0) >= 4) {
|
|
items.push_back({173, plot(44, 86, 104, 99) + works(0, 108, 100, 24)});
|
|
hot(name(0), 173, {ground(44, 86, 104, 99)});
|
|
}
|
|
}
|
|
{
|
|
// the car park grows along the road with every stage
|
|
const int stage = level(4) <= 0 ? 0 : std::clamp(int(std::lround(double(level(4)) / most(4) * 4)), 1, 4);
|
|
const double half = std::array<double, 5>{0, 14, 24, 36, 46}[size_t(stage)];
|
|
std::string park = (stage < 4 && !future ? plot(128, -46, 156, 46) : std::string()) + (stage ? poly({{128, -half, 0}, {156, -half, 0}, {156, half, 0}, {128, half, 0}}, "#d6d0c4", "stroke=\"#3a332b\" stroke-opacity=\".4\" stroke-width=\".8\"") : std::string());
|
|
Random random{5};
|
|
static constexpr std::array<const char *, 7> paints{"#c8733c", "#7a8a5e", "#f3ede0", "#5d7f96", "#d9b24a", "#8f8778", "#a8452f"};
|
|
for (double y = -half + 2; y < half - 3; y += 3.6) {
|
|
park += line({129, y - .6, 0}, {136, y - .6, 0}, "#fbf7ee", .7) + line({148, y - .6, 0}, {155, y - .6, 0}, "#fbf7ee", .7);
|
|
if (random.next() < .7) park += car(130, y, paints[size_t(random.between(0, 6))], true);
|
|
if (random.next() < .6) park += car(149.5, y, paints[size_t(random.between(0, 6))], true);
|
|
}
|
|
if (stage) {
|
|
const auto q = project({128.6, 0, 10.5});
|
|
park += paint(box(128, -1.5, 129.2, 1.5, 0, 8, "#8f8778")) + "<rect x=\"" + num(q.x - 6) + "\" y=\"" + num(q.y - 6) + "\" width=\"12\" height=\"12\" rx=\"2.5\" fill=\"#2f5f9e\" stroke=\"#ffffff\" stroke-width=\"1.2\"/><text x=\"" + num(q.x) + "\" y=\"" +
|
|
num(q.y + 4.2) + "\" text-anchor=\"middle\" font-family=\"" + lettering + "\" font-size=\"11\" fill=\"#ffffff\">P</text>";
|
|
}
|
|
items.push_back({142, park + works(4, 158, 0, 22)});
|
|
hot(name(4), 142, {ground(128, -46, 156, 46)});
|
|
}
|
|
// a house on its plot, or the plot alone
|
|
const auto house = [&](size_t index, double x0, double y0, double x1, double y1, double tall, const std::vector<Face> &faces, const std::string &extra) {
|
|
const bool built = level(index) > 0; const double depth = (x0 + x1 + y0 + y1) / 2;
|
|
items.push_back({depth, (built ? shadow(x0, y0, x1, y1, tall) + paint(faces) + extra : plot(x0, y0, x1, y1)) + works(index, x1 + 4, y1 + 4, tall + 14)});
|
|
hot(name(index), depth, built ? box_quads(x0, y0, x1, y1, 0, tall) : std::vector<Quad>{ground(x0, y0, x1, y1)});
|
|
};
|
|
const auto storeys = [&](size_t index, int tallest) { return level(index) <= 0 ? 0 : most(index) > 1 ? std::clamp(level(index), 1, tallest) : std::min(2, tallest); };
|
|
{
|
|
// the club house with its flag
|
|
const double z = 5 + storeys(3, 3) * 3.2;
|
|
BoxLook look; look.top = "#c8733c"; look.deco_x = windows_x(-116, -34, 10, 1.4, z - 1.2, 7, "#bfe0ea", .2) + sign_x(-116, 6, z + .6, "CLUBHAUS", 6); look.deco_y = windows_y(10, -152, -116, 1.4, z - 1.2, 6, "#bfe0ea", .2);
|
|
BoxLook porch; porch.top = "#8fa073";
|
|
auto faces = box(-152, -34, -116, 10, 0, z, "#f1e7d2", look); const auto front = box(-116, -18, -108, -4, 0, 3.4, "#e6dcc6", porch);
|
|
faces.insert(faces.end(), front.begin(), front.end());
|
|
house(3, -152, -34, -116, 10, z, faces, line({-140, -20, z}, {-140, -20, z + 9}, ink, .9) + poly({{-140, -20, z + 9}, {-140, -14, z + 7.6}, {-140, -20, z + 6.2}}, "#c8733c") + (busy(around(3)) ? scaffold({faces[1], faces[2]}) : std::string()));
|
|
}
|
|
{
|
|
BoxLook look; look.top = "#f1c94b"; look.side_x = "#6b3a96"; look.side_y = "#6b3a96";
|
|
look.deco_x = windows_x(-120, 34, 66, 1, 5, 5, "#f6d54a", .2) + sign_x(-120, 62, 6.2, "ARCADE", 7, "#ffe9a0"); look.deco_y = windows_y(66, -150, -120, 1, 5, 5, "#f6d54a", .2);
|
|
house(1, -150, 34, -120, 66, 9, box(-150, 34, -120, 66, 0, 9, "#5a2d82", look), "");
|
|
}
|
|
{
|
|
const double z = 7 + storeys(2, 3) * 4;
|
|
BoxLook look; look.top = "#d9d2c2"; look.deco_y = windows_y(-92, -46, 44, 1.2, z - 2, 12, "#bfe0ea", .14) + sign_y(-22, -92, z + .8, "EINKAUFSZENTRUM", 7); look.deco_x = windows_x(44, -124, -92, 1.2, z - 2, 4, "#bfe0ea", .14);
|
|
BoxLook dome; dome.top = "#dff0f4";
|
|
auto faces = box(-46, -124, 44, -92, 0, z, "#f1e7d2", look); const auto light = box(-10, -116, 14, -100, z, z + 3, "#bfe0ea", dome);
|
|
faces.insert(faces.end(), light.begin(), light.end());
|
|
house(2, -46, -124, 44, -92, z, faces, "");
|
|
}
|
|
{
|
|
const double rz = level(5) >= 2 ? 12 : 7; // stage two adds a storey
|
|
BoxLook look; look.top = "#a8452f"; look.deco_y = windows_y(-96, 66, 100, 1.2, 5, 6, "#bfe0ea", .2) + (rz > 7 ? windows_y(-96, 66, 100, 6.4, 10.4, 6, "#bfe0ea", .2) : std::string()) + sign_y(72, -96, rz + .6, "RESTAURANT", 5.4); look.deco_x = windows_x(100, -122, -96, 1.2, 5, 4, "#bfe0ea", .2) + (rz > 7 ? windows_x(100, -122, -96, 6.4, 10.4, 4, "#bfe0ea", .2) : std::string());
|
|
// tables under parasols in front of it
|
|
std::string terrace = paint(box(66, -96, 100, -86, 0, .6, "#d9b98a"));
|
|
for (const double x : {70.0, 78.0, 86.0, 94.0}) {
|
|
const auto q = project({x, -91, 3});
|
|
terrace += "<circle cx=\"" + num(q.x) + "\" cy=\"" + num(q.y) + "\" r=\"5\" fill=\"" + (int(x) % 16 > 7 ? "#c8733c" : "#f6ecd8") + "\" stroke=\"" + ink + "\" stroke-width=\".6\"/>" + line({x, -91, .6}, {x, -91, 3}, ink, .7);
|
|
}
|
|
house(5, 66, -122, 100, -96, rz, box(66, -122, 100, -96, 0, rz, "#f6f0e2", look), terrace);
|
|
}
|
|
{
|
|
const auto stall = [&](size_t index, double x, double y) {
|
|
BoxLook look; look.top = "#c8733c";
|
|
look.deco_y = poly({{x, y + 7, 2.6}, {x + 9, y + 7, 2.6}, {x + 9, y + 9.2, 2.1}, {x, y + 9.2, 2.1}}, "#f6d9a8", "stroke=\"#3a332b\" stroke-width=\".5\"") + windows_y(y + 7, x, x + 9, .8, 2.4, 1, "#6b5a48", .14);
|
|
house(index, x, y, x + 9, y + 7, 4, box(x, y, x + 9, y + 7, 0, 4, "#f6ecd8", look), sign_y(x + .6, y + 7, 4.4, "Imbiss", 3.4));
|
|
};
|
|
stall(6, -112, -94); stall(7, 100, -92); stall(8, 96, 84); stall(9, -110, 82);
|
|
const auto shop = [&](size_t index, double x, double y) {
|
|
BoxLook look; look.top = "#b5562a";
|
|
look.deco_y = windows_y(y + 10, x, x + 16, .8, 3.6, 3, "#bfe0ea", .14) + poly({{x, y + 10, 4}, {x + 16, y + 10, 4}, {x + 16, y + 12.4, 3.3}, {x, y + 12.4, 3.3}}, "#c8733c", "stroke=\"#3a332b\" stroke-width=\".5\"");
|
|
look.deco_x = windows_x(x + 16, y, y + 10, .8, 3.6, 2, "#bfe0ea", .14);
|
|
house(index, x, y, x + 16, y + 10, 6, box(x, y, x + 16, y + 10, 0, 6, "#f6ecd8", look), sign_y(x + 1.4, y + 10, 6.6, "FAN-SHOP", 3.8));
|
|
};
|
|
shop(10, -84, 84); shop(11, -52, 84); shop(12, 126, -76); shop(13, -136, -72);
|
|
}
|
|
{
|
|
Random random{11};
|
|
static constexpr std::array<std::array<double, 2>, 32> trees{{{-156, -120}, {-140, -112}, {-120, -122}, {-96, -116}, {-70, -122}, {58, -110}, {140, -118}, {152, -100}, {150, -84}, {-156, -50}, {-158, 22},
|
|
{-156, 76}, {-140, 90}, {-96, 92}, {-70, 100}, {-30, 98}, {20, 96}, {30, 86}, {118, 96}, {150, 98}, {156, 60}, {-108, -50},
|
|
{-104, 30}, {106, -40}, {104, 50}, {-158, 126}, {-90, 126}, {-10, 126}, {70, 126}, {150, 126}, {-126, 20}, {-112, 56}}};
|
|
for (size_t i = 0; i < trees.size(); ++i) items.push_back({trees[i][0] + trees[i][1], tree(trees[i][0], trees[i][1], .8 + random.next() * .5, int(i))});
|
|
// people on the forecourt
|
|
Random crowd{3}; std::string people;
|
|
static constexpr std::array<const char *, 4> coats{"#c8733c", "#3a332b", "#f6ecd8", "#7a8a5e"};
|
|
for (int i = 0; i < 46; ++i) {
|
|
const double x = crowd.between(-40, 40) + (i % 3 ? 0 : 50 * (crowd.next() - .5)), y = 84 + crowd.next() * 18 - (i % 4 ? 0 : 4); const auto q = project({x, y, 0});
|
|
people += "<path d=\"M" + num(q.x) + " " + num(q.y) + "v-3.2\" stroke=\"" + coats[size_t(crowd.between(0, 3))] + "\" stroke-width=\"1.5\" stroke-linecap=\"round\"/><circle cx=\"" + num(q.x) + "\" cy=\"" + num(q.y - 4.3) + "\" r=\".9\" fill=\"#e8b88f\"/>";
|
|
}
|
|
items.push_back({-8000, people});
|
|
}
|
|
|
|
// ---- the base plate of card under it all ----
|
|
std::stable_sort(items.begin(), items.end(), [](const Item &a, const Item &b) { return a.depth < b.depth; });
|
|
std::stable_sort(scene.hots.begin(), scene.hots.end(), [](const Hot &a, const Hot &b) { return a.depth < b.depth; });
|
|
constexpr double X = 160, Y = 128;
|
|
std::string body = poly({{-X, Y, -7}, {X, Y, -7}, {X, -Y, -7}, {X + 10, -Y + 6, -7}, {X + 10, Y + 10, -7}, {-X + 6, Y + 10, -7}}, "#2e2b25", "fill-opacity=\".14\"");
|
|
body += poly({{X, -Y, 0}, {X, Y, 0}, {X, Y, -7}, {X, -Y, -7}}, "#c9ad80") + poly({{-X, Y, 0}, {X, Y, 0}, {X, Y, -7}, {-X, Y, -7}}, "#b99a6c");
|
|
for (double i = -Y + 3; i < Y; i += 3.2) body += line({X, i, -1.5}, {X, i + 1.6, -5.5}, "#9a7c4e", .6);
|
|
for (double i = -X + 3; i < X; i += 3.2) body += line({i, Y, -1.5}, {i + 1.6, Y, -5.5}, "#8a6c40", .6);
|
|
body += poly({{-X, -Y, 0}, {X, -Y, 0}, {X, Y, 0}, {-X, Y, 0}}, "#dde6c6", "stroke=\"#3a332b\" stroke-opacity=\".5\" stroke-width=\"1\"");
|
|
body += poly({{-98, -80, 0}, {98, -80, 0}, {98, 80, 0}, {-98, 80, 0}}, "#efe7d4", "stroke=\"#3a332b\" stroke-opacity=\".3\" stroke-width=\".8\"") + poly({{-58.5, -40, 0}, {58.5, -40, 0}, {58.5, 40, 0}, {-58.5, 40, 0}}, "#d9c9a4", "stroke=\"none\"") +
|
|
poly({{-100, -8, 0}, {-116, -8, 0}, {-116, 4, 0}, {-100, 4, 0}}, "#e6dcc6", "stroke=\"none\"");
|
|
for (const auto &item : items) body += item.svg;
|
|
scene.svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 " + num(width) + " " + num(height) + "\">" + body + "</svg>";
|
|
return scene;
|
|
}
|
|
} // namespace bmh::modern_ui::stadium_scene
|