256 lines
12 KiB
TypeScript
256 lines
12 KiB
TypeScript
/** Vector airfield for edition 00475. Positions share the engine's slot IDs. */
|
|
type Point = { x: number; y: number; angle: number; label: string };
|
|
type Geometry = {
|
|
ab_stands: number;
|
|
b_stands: number;
|
|
ac_stands: number;
|
|
queue_capacity: number;
|
|
runways: string[];
|
|
};
|
|
type Marker = {
|
|
key: string;
|
|
caption: string;
|
|
color: string;
|
|
size: number;
|
|
name: string;
|
|
};
|
|
type MapView = {
|
|
geometry: Geometry;
|
|
markers: Record<string, Marker>;
|
|
pickable: Set<string>;
|
|
destinations: Set<string>;
|
|
selected: string;
|
|
weather: string | null;
|
|
piles?: { deck: number; discard: string; weather: string };
|
|
};
|
|
const width = 1080,
|
|
height = 548;
|
|
const laneY = (lane: string) => (lane === "31R" ? 57 : 491);
|
|
const queueY = (lane: string) => (lane === "31R" ? 129 : 419);
|
|
const spread = (i: number, n: number, from: number, to: number) =>
|
|
n <= 1 ? (from + to) / 2 : from + ((to - from) * i) / (n - 1);
|
|
|
|
function geometry(b: Geometry) {
|
|
const points: Record<string, Point> = {};
|
|
const add = (
|
|
id: string,
|
|
x: number,
|
|
y: number,
|
|
angle: number,
|
|
label: string,
|
|
) => (points[id] = { x, y, angle, label });
|
|
for (const lane of b.runways) {
|
|
const sy = laneY(lane),
|
|
qy = queueY(lane);
|
|
add("D:" + lane + ":0", 987, sy, -90, "D");
|
|
for (let n = 1; n < b.queue_capacity; n++)
|
|
add(
|
|
"D:" + lane + ":" + n,
|
|
spread(n - 1, b.queue_capacity - 1, 949, 670),
|
|
qy,
|
|
90,
|
|
"D" + n,
|
|
);
|
|
}
|
|
for (let n = 0; n < b.ab_stands; n++) {
|
|
const upper = n < Math.ceil(b.ab_stands / 2),
|
|
count = upper ? Math.ceil(b.ab_stands / 2) : Math.floor(b.ab_stands / 2);
|
|
add(
|
|
"A:B" + (n + 1),
|
|
spread(upper ? n : n - Math.ceil(b.ab_stands / 2), count, 440, 600),
|
|
upper ? 215 : 332,
|
|
upper ? 180 : 0,
|
|
"A" + (n + 1),
|
|
);
|
|
}
|
|
for (let n = 0; n < b.b_stands; n++)
|
|
add(
|
|
"B:B" + (n + 1),
|
|
spread(n, b.b_stands, 410, 638),
|
|
n % 2 ? 371 : 176,
|
|
90,
|
|
"B" + (n + 1),
|
|
);
|
|
for (let n = 0; n < b.ac_stands; n++) {
|
|
const x = spread(n, b.ac_stands, 116, 258);
|
|
add("A:C" + (n + 1), x, 260, 0, "A" + (n + 1));
|
|
add("C:C" + (n + 1), x, 311, 180, "C" + (n + 1));
|
|
}
|
|
for (const lane of b.runways) {
|
|
const upper = lane === "31R";
|
|
add("V1:" + lane, 834, upper ? 231 : 317, 90, "VIP1");
|
|
add("V2:" + lane, 914, upper ? 231 : 317, 90, "VIP2");
|
|
}
|
|
return points;
|
|
}
|
|
|
|
function runway(lane: string, weather: string | null) {
|
|
const y = laneY(lane);
|
|
const bars = Array.from(
|
|
{ length: 6 },
|
|
(_, i) =>
|
|
'<path d="M54 ' +
|
|
(y - 13 + i * 5) +
|
|
"h31 M1026 " +
|
|
(y - 13 + i * 5) +
|
|
'h-30"/>',
|
|
).join("");
|
|
const lights = Array.from(
|
|
{ length: 24 },
|
|
(_, i) => '<path d="M' + (44 + i * 43) + " " + (y - 22) + 'v2 m0 40v2"/>',
|
|
).join("");
|
|
return `<g><rect x="28" y="${y - 25}" width="1024" height="50" rx="5" fill="#687773" stroke="#92a492" stroke-width="5"/>
|
|
<rect x="34" y="${y - 19}" width="1012" height="38" fill="url(#asphalt)" stroke="#c5cdc0" stroke-width="1.4"/>
|
|
<g stroke="#ecebdd" stroke-width="2.6">${bars}<path d="M171 ${y}H920" stroke-dasharray="20 16"/></g>
|
|
<path d="M225 ${y - 10}h35 m0 20h-35 M785 ${y - 10}h35 m0 20h-35" stroke="#d1d7cb" stroke-width="4"/>
|
|
<g stroke="#e5dfad" stroke-width="3">${lights}</g>
|
|
<text x="106" y="${y + 8}" class="rw-number">${lane}</text>
|
|
${weather === lane || weather === "FG" ? '<path d="M930 ' + (y - 12) + 'l23 24m0 -24l-23 24" stroke="#ff9c64" stroke-width="5"/>' : ""}</g>`;
|
|
}
|
|
const fieldDefs = `<defs>
|
|
<pattern id="grass" width="21" height="17" patternUnits="userSpaceOnUse"><rect width="21" height="17" fill="#9aa780"/><path d="M2 3h4m8 7h3m-8 4h3" stroke="#718765" stroke-width=".9" opacity=".38"/></pattern>
|
|
<pattern id="roof" width="8" height="8" patternUnits="userSpaceOnUse"><rect width="8" height="8" fill="#c5d3cb"/><path d="M1 0v8" stroke="#a3b8ad"/></pattern>
|
|
<pattern id="asphalt" width="23" height="16" patternUnits="userSpaceOnUse"><rect width="23" height="16" fill="#515e60"/><path d="M0 0h23m-17 0v16" stroke="#657073" stroke-width=".7"/></pattern>
|
|
<pattern id="apron" width="30" height="28" patternUnits="userSpaceOnUse"><rect width="30" height="28" fill="#bdc4ae"/><path d="M0 28V0h30" fill="none" stroke="#9ca896" stroke-width="1.4"/></pattern>
|
|
<g id="tree"><path d="M-6 4l1-8 4-5 6 2 4 6-3 7-7 1z" fill="#546f54"/><path d="M-6 1l1-7 5-4 5 3 1 6-5 5z" fill="#71885e"/><path d="M-4-4l4-4 3 3" fill="#889967"/></g>
|
|
<g id="vent"><rect width="12" height="9" rx="1" fill="#82988d"/><circle cx="6" cy="4.5" r="3" fill="#a5b5a9" stroke="#506a62"/><path d="M3 4.5h6m-3-3v6" stroke="#657d72"/></g>
|
|
<g id="jet1"><path d="M0-15Q3-13 2-2L14 1v3L2 3l-1 8 5 3v2l-6-2-6 2v-2l5-3-1-8-12 1V1l12-3Q-3-13 0-15Z"/></g>
|
|
<g id="jet2"><path d="M0-19Q3-18 3-6L19 4v4L3 3l-1 10 6 4v2l-8-3-8 3v-2l6-4-1-10-16 5V4L-3-6Q-3-18 0-19Z"/><path d="M-9-2v7m18-7v7" stroke-width="3"/></g>
|
|
<g id="jet3"><path d="M0-22Q4-20 3.8-7L23 4v5L4 4l-2 11 8 5v3l-10-4-10 4v-3l8-5-2-11-19 5V4L-3.8-7Q-4-20 0-22Z"/><path d="M-15 0v7m7-10v8m16-8v8m7-5v7" stroke-width="3.6"/></g>
|
|
</defs>`;
|
|
function building(x: number, y: number, w: number, h: number) {
|
|
const vents = Array.from(
|
|
{ length: Math.max(1, Math.floor(w / 44)) },
|
|
(_, i) => `<use href="#vent" x="${x + 8 + 35 * i}" y="${y + 5}"/>`,
|
|
).join("");
|
|
return `<g><rect x="${x + 4}" y="${y + 5}" width="${w}" height="${h}" rx="3" fill="#54685c" opacity=".5"/>
|
|
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="3" fill="url(#roof)" stroke="#667d72" stroke-width="2"/>
|
|
<path d="M${x + 4} ${y + h - 3}h${w - 8}" stroke="#73979a" stroke-width="4" stroke-dasharray="8 3"/>${vents}</g>`;
|
|
}
|
|
|
|
function apronEquipment() {
|
|
const carts = (
|
|
x: number,
|
|
y: number,
|
|
angle: number,
|
|
) => `<g transform="translate(${x} ${y}) rotate(${angle})"><path d="M0 0h28" stroke="#58675b" stroke-width="2"/>
|
|
<rect x="-3" y="-3" width="8" height="6" rx="1" fill="#bc7643" stroke="#687168"/><path d="M1-2v4" stroke="#cbdfe0"/>
|
|
${[9, 18, 27].map((x) => `<rect x="${x}" y="-2.6" width="6" height="5" rx=".7" fill="#d6d4bb" stroke="#677269" stroke-width=".8"/>`).join("")}</g>`;
|
|
const hatches = Array.from(
|
|
{ length: 9 },
|
|
(_, i) => `<path d="M${383 + i * 7} 294l6-8 M${591 + i * 7} 248l6-8"/>`,
|
|
).join("");
|
|
return `<g fill="none" stroke="#f7f3d5" stroke-width="1.1">${hatches}
|
|
<path d="M374 239h33v26h-33z M662 249h22v59h-22z" stroke-dasharray="4 3"/>
|
|
<path d="M95 240h183 M95 329h183" stroke="#c9a651" stroke-width="2"/></g>
|
|
${carts(374, 317, 0)}${carts(626, 288, 90)}${carts(786, 299, -90)}
|
|
<g transform="translate(701 289)"><ellipse cx="6" cy="10" rx="10" ry="3" fill="#899980"/>
|
|
<path d="M0 9v-25" stroke="#53675b" stroke-width="2"/><path d="M0-17l18 3-2 4-16-1z" fill="#ce693d" stroke="#765f47"/><path d="M5-16v5m6-4v4" stroke="#fff3d5" stroke-width="2.5"/></g>
|
|
<g transform="translate(287 348)"><path d="M-4 13l2-22h5l3 22z" fill="#d4ddd1" stroke="#6d8278"/><path d="M-7-12h15l-2 6h-11z" fill="#76959a" stroke="#4a6360"/><path d="M-8-12l3-3h11l3 3z" fill="#c5cfc2"/></g>`;
|
|
}
|
|
function terrain(points: Record<string, Point>) {
|
|
let seed = 49075;
|
|
function rand() {
|
|
seed = (1664525 * seed + 1013904223) >>> 0;
|
|
return seed / 4294967296;
|
|
}
|
|
const trees = [
|
|
[45, 172, 34, 202],
|
|
[65, 91, 265, 22],
|
|
[69, 447, 270, 18],
|
|
[383, 96, 200, 15],
|
|
[361, 442, 214, 12],
|
|
[1012, 187, 31, 161],
|
|
]
|
|
.map(([x, y, w, h]) =>
|
|
Array.from(
|
|
{ length: Math.ceil((w * h) / 180) },
|
|
() =>
|
|
`<use href="#tree" transform="translate(${Math.round(x + rand() * w)} ${Math.round(y + rand() * h)}) scale(${(0.48 + rand() * 0.48).toFixed(2)})"/>`,
|
|
).join(""),
|
|
)
|
|
.join("");
|
|
const routes: string[] = [
|
|
"M91 129H938Q987 129 987 90V57",
|
|
"M91 419H938Q987 419 987 458V491",
|
|
"M91 129Q72 129 72 151V397Q72 419 91 419",
|
|
"M350 129V419",
|
|
"M350 176H680Q722 176 752 129",
|
|
"M350 371H680Q722 371 752 419",
|
|
"M776 129Q758 170 758 202V342Q758 374 776 419",
|
|
"M758 231H914Q955 231 955 265V283Q955 317 914 317H758",
|
|
];
|
|
for (const [id, p] of Object.entries(points)) {
|
|
if (id.startsWith("A:B"))
|
|
routes.push(`M${p.x} ${p.y}V${p.y < 274 ? 176 : 371}`);
|
|
if (id.startsWith("A:C")) routes.push(`M${p.x} 129V419`);
|
|
}
|
|
const line = routes.map((d) => `<path d="${d}"/>`).join("");
|
|
const apron =
|
|
'<path d="M89 156H302L320 177V365L298 389H89Z M364 162H670L710 196V350L676 382H364Z M778 192H926L969 221V321L935 351H778Z" fill="url(#apron)" stroke="#a2ac95" stroke-width="3"/>';
|
|
const fingers = Object.entries(points)
|
|
.filter(([k]) => k.startsWith("A:B"))
|
|
.map(([, p]) => {
|
|
const top = p.y < 274,
|
|
y = top ? 235 : 296;
|
|
return `<g><path d="M${p.x + 10} ${top ? 252 : 296}v${top ? -13 : 12}l-9 ${top ? -7 : 7}" stroke="#667e75" stroke-width="8" fill="none"/><rect x="${p.x - 5}" y="${top ? y - 8 : y + 12}" width="10" height="9" fill="#e1e4d4" stroke="#748777"/></g>`;
|
|
})
|
|
.join("");
|
|
return `<rect width="${width}" height="${height}" fill="url(#grass)"/><path d="M-30 125L370 0H615L-10 187ZM483 548L1080 342V399L671 548Z" fill="#b1b58a" opacity=".38"/>
|
|
${trees}${apron}<g fill="none" stroke-linecap="round" stroke-linejoin="round"><g stroke="#798879" stroke-width="23">${line}</g><g stroke="#a9b1a2" stroke-width="19">${line}</g><g stroke="#e4cd7e" stroke-width="1.7">${line}</g></g>
|
|
${apronEquipment()}${fingers}${building(399, 251, 259, 45)}${building(441, 244, 114, 16)}
|
|
<text x="533" y="281" class="roof-title" text-anchor="middle">ТЕРМИНАЛ</text>
|
|
${building(805, 259, 99, 36)}<text x="857" y="285" text-anchor="middle" class="roof-title">VIP</text>
|
|
${building(239, 179, 45, 27)}${building(286, 312, 28, 55)}${building(350, 254, 23, 41)}
|
|
<path d="M98 226h177m-177 114h177" stroke="#e4dfba" stroke-width="2" stroke-dasharray="4 5"/>
|
|
<text x="180" y="209" text-anchor="middle" class="ground-title">ПЕРРОН A / C</text>
|
|
|
|
`;
|
|
}
|
|
|
|
function cardBays(v: MapView) {
|
|
const items = [
|
|
["ПОГОДА", v.piles?.weather ?? "—"],
|
|
["КОЛОДА", String(v.piles?.deck ?? "—")],
|
|
["СБРОС", v.piles?.discard ?? "—"],
|
|
];
|
|
return items
|
|
.map(
|
|
(
|
|
[label, value],
|
|
i,
|
|
) => `<g transform="translate(${107 + 132 * i} 91)"><rect x="2" y="2" width="119" height="24" rx="3" fill="#4f6554"/>
|
|
<rect width="119" height="24" rx="3" fill="#d9dfc9" stroke="#657860"/>
|
|
<path d="M6 5h12v14H6zm2-2h12v14" fill="none" stroke="#6c806a"/>
|
|
<text x="24" y="16" class="bay-name">${label}</text><text x="111" y="16" text-anchor="end" class="bay-value">${value}</text></g>`,
|
|
)
|
|
.join("");
|
|
}
|
|
export function airfield(v: MapView) {
|
|
const pts = geometry(v.geometry);
|
|
const markers = Object.entries(pts)
|
|
.map(([id, p]) => {
|
|
const m = v.markers[id],
|
|
dest = v.destinations.has(id),
|
|
canPick = m && v.pickable.has(m.key);
|
|
const picked = !!m && m.key === v.selected;
|
|
const title = m ? m.name + " · " + p.label : p.label + " · " + id;
|
|
const action = canPick ? "pick" : dest ? "mapdest" : "";
|
|
const attr = action
|
|
? `role="button" tabindex="0" data-act="${action}" data-val="${canPick ? m.key : id}"`
|
|
: "";
|
|
const label = p.label === "D" ? "СТАРТ" : p.label;
|
|
return `<g transform="translate(${p.x} ${p.y})" data-position="${id}" class="map-slot ${dest ? "legal" : ""} ${picked ? "picked" : ""}" ${attr} aria-label="${title}"><title>${title}</title><circle r="24" fill="transparent"/>
|
|
<circle class="spot" r="${m ? 18 : 14}" fill="${id.startsWith("D") ? "#f1d977" : "#e7e8d6"}" fill-opacity=".93" stroke="#465b51" stroke-width="1.8"/>
|
|
${dest || picked ? '<circle class="focus-ring" r="21" fill="none" stroke="' + (picked ? "#fff" : "#075842") + '" stroke-width="3" stroke-dasharray="5 3"/>' : ""}
|
|
${
|
|
m
|
|
? `<use href="#jet${m.size}" transform="rotate(${p.angle})" fill="${m.color}" stroke="#26382e" stroke-linejoin="round" stroke-width="1.2"/>
|
|
<rect x="-20" y="18" width="40" height="15" rx="4" fill="#233d33"/><text y="29" class="jet-id">${m.caption}</text>`
|
|
: `<text y="4" class="spot-label">${label}</text>`
|
|
}</g>`;
|
|
})
|
|
.join("");
|
|
return `<svg class="airfield" viewBox="0 0 ${width} ${height}" xmlns="http://www.w3.org/2000/svg" role="group" aria-label="Аэродром, полосы 31R и 31L, терминал и стоянки">${fieldDefs}${terrain(pts)}${v.geometry.runways.map((l) => runway(l, v.weather)).join("")}${markers}${cardBays(v)}</svg>`;
|
|
}
|