CyberCity/w/west.js
MiguelCarino b62b368034 Draw the city in high definition, still in text
The payload splits per world: index.html keeps the engine and the city,
and w/west.js, w/jp.js and w/moon.js carry the other worlds, each loaded
with a content-hash cache-buster and isolated so one failing chunk only
loses its own world.

Under the glyphs sits a per-world underpainting (CC.Compose.UNDER, with
0 as a kill switch for the frame data and glyph layer), glyphs print
through a pixel path on small cells, optics are sized for denser grids,
and the default bands reach about 300 columns at 1920 px and 360 at
2560, stepping back down on a slow machine.

The photosensitivity probes now see the composite, at 200x60 and
400x120, weighted by ink-compensated coverage for the real cell size.
27 of 28 runs pass; lum-mode west-flicker at 400x120 (3.25/s against
the city's 3.16/s) is documented in CONTRACT as still open.

Also carries the share card: og.jpg, its og/twitter meta and sitemap.
2026-10-21 21:32:38 -06:00

2744 lines
94 KiB
JavaScript

/* CyberCity — west world. Generated by build.js from src/; loaded by index.html, which
* calls each function below back at its place in the build order. Do not edit by hand. */
(function (W) {
W["surf_west.js"] = function (CC) {
'use strict';
/* src/surf_west.js */
(function (CC) {
var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise, smooth = CC.smooth;
var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"),
G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_TILDE = g('~'),
G_PIPE = g('|'), G_SLASH = g('/'), G_PCT = g('%'), G_AMP = g('&'), G_8 = g('8'),
G_0 = g('0'), G_o = g('o'), G_HASH = g('#'), G_PLUS = g('+'), G_STAR = g('*'),
G_CARET = g('^'), G_DQ = g('"');
function cfg() { return CC.Surf ? CC.Surf.cfg : null; }
var SUN_AZ = -0.5;
var SUN_X = Math.sin(SUN_AZ), SUN_Z = Math.cos(SUN_AZ), SUN_ALT = 0.16;
function dayAt(t) {
if (t === dT) return;
dT = t;
var D = CC.Daylight;
if (!D) return;
SUN_AZ = D.P.az; SUN_ALT = D.P.alt;
SUN_X = Math.sin(SUN_AZ); SUN_Z = Math.cos(SUN_AZ);
dSun = D.P.sun; dSky = D.P.sky; dWarm = D.P.warm; dLamp = D.P.lamp; dStar = D.P.star;
dFill = smooth(clamp((dSky - 0.70) / 0.30, 0, 1));
}
var dT = 1 / 0, dSun = 0.64, dSky = 0.66, dWarm = 0.74, dLamp = 1, dStar = 0, dFill = 0;
function dAlt() { return SUN_ALT; }
var MAT_SUN = [
P.sand, P.white, P.ember, P.moss,
P.stone, P.white, P.ember, P.stone,
P.sand, P.white, P.white, P.stone,
P.stone, P.sand, P.sand, P.jade,
P.sand, P.gold, P.moss, P.stone
];
var MAT_MID = [
P.sand, P.stone, P.timber, P.moss,
P.indigo, P.sand, P.timber, P.stone,
P.sand, P.stone, P.sand, P.timber,
P.stone, P.stone, P.timber, P.moss,
P.timber, P.sand, P.moss, P.indigo
];
var MAT_SHD = [
P.timber, P.indigo, P.timber, P.moss,
P.indigo, P.stone, P.timber, P.indigo,
P.timber, P.stone, P.stone, P.indigo,
P.indigo, P.timber, P.stone, P.indigo,
P.timber, P.timber, P.moss, P.indigo
];
var SUN_FRONT = 1.00, SUN_BACK = 0.10, SUN_SIDE = 0.42;
function sunOf(cell) {
var floor = 0.05 + 0.16 * dSky;
if (!cell || cell.faceX === undefined) return floor + (SUN_SIDE - 0.10) * dSun;
var nx = cell.faceX ? -cell.side : 0, nz = cell.faceX ? 0 : -cell.side;
var d = nx * SUN_X + nz * SUN_Z;
var split = 1 - 0.65 * clamp(SUN_ALT / 0.95, 0, 1);
var f = clamp(0.5 + 0.62 * d * split, 0, 1);
var direct = (SUN_FRONT - SUN_BACK) * f * f * (3 - 2 * f) * Math.sqrt(dSun);
return clamp(floor + direct * (0.42 + 0.58 * (1 - clamp(SUN_ALT / 0.95, 0, 1))) +
dSun * 0.34 * clamp(SUN_ALT / 0.95, 0, 1), 0, 1.25);
}
var wT = 1 / 0, wWet = 1, wRain = 1, wWind = 1, wDust = 0.3, wCloud = 0.1;
function weatherAt(t) {
if (t === wT) return;
wT = t;
var W = CC.Weather;
if (!W) return;
wWet = W.rel('wet'); wRain = W.rel('rain'); wWind = W.rel('wind');
wDust = W.P.haze; wCloud = W.P.cloud;
}
function seedOf(cell) {
if (!cell || typeof cell !== 'object') return 0;
if (cell.seed !== undefined) return cell.seed | 0;
return 0;
}
var STYLE_W = [
{ lap: 0.34, bay: 4.4, gnd: 2.90, up: 2.55, winW: 1.05, winH: 1.35,
shopW: 2.30, shopH: 1.75, rough: 0, vert: 0 },
{ lap: 0.62, bay: 5.2, gnd: 3.20, up: 2.70, winW: 0.90, winH: 1.20,
shopW: 1.90, shopH: 1.60, rough: 0, vert: 1 },
{ lap: 0.28, bay: 4.0, gnd: 3.05, up: 2.60, winW: 1.20, winH: 1.50,
shopW: 2.60, shopH: 1.95, rough: 0, vert: 0 },
{ lap: 0.90, bay: 5.0, gnd: 2.60, up: 2.30, winW: 0.75, winH: 0.95,
shopW: 1.10, shopH: 1.20, rough: 1, vert: 0 },
{ lap: 0.50, bay: 4.6, gnd: 2.85, up: 2.45, winW: 0.85, winH: 1.10,
shopW: 1.40, shopH: 1.45, rough: 1, vert: 0 },
{ lap: 0.42, bay: 5.6, gnd: 2.70, up: 2.40, winW: 0.80, winH: 1.05,
shopW: 1.30, shopH: 1.35, rough: 0, vert: 0 }
];
var INK = [G_TICK, G_DOT, G_UNDER, G_DASH, G_COLON, G_TILDE, G_DQ, G_PLUS, G_EQ, G_HASH, G_PCT];
function ink(t) {
var i = (t * 11) | 0;
return INK[i < 0 ? 0 : (i > 10 ? 10 : i)];
}
var FOUT = { ch: 0, col: 0, lum: 0 };
function fset(ch, col, lum) {
FOUT.ch = ch; FOUT.col = col;
FOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0);
return FOUT;
}
function grain(u, v, sd, lod) {
if (lod < 2) return 1;
var h = hash2(Math.floor(u * 11), Math.floor(v * 11), sd ^ 0x6A11);
return h < 0.14 ? 0.34 : 0.72 + h * 0.56;
}
function rockFace(u, v, cell, dist, sd) {
var h = cell && cell.h ? cell.h : 12;
var lod = dist < 26 ? 2 : (dist < 60 ? 1 : 0);
var sun = sunOf(cell);
var wob = vnoise(u * 0.10 + sd * 0.017, 0x7A) * 1.3;
var bandF = (v + wob) / 1.55;
var band = Math.floor(bandF), inB = bandF - band;
var bh = hash2(band, sd & 1023, 0x51C);
var chan = hash2(Math.floor(u * 0.55), 0, sd ^ 0x2C4);
var shade = chan < 0.22 ? 0.42 : (chan < 0.36 ? 0.72 : 1);
var crest = h - v;
if (crest < 0.9) {
var k = 1 - crest / 0.9;
return fset(inB < 0.5 ? G_PCT : G_AMP, sun > 0.6 ? P.amber : P.ember,
(26 + 88 * k) * (0.5 + 0.5 * sun) * shade);
}
if (inB < 0.13) {
return fset(bh < 0.5 ? G_DASH : G_UNDER, P.slate,
(13 + bh * 15) * shade * (0.55 + 0.45 * sun));
}
var rd = 0.20 + 0.12 * bh;
rd += (0.95 - rd) * dFill;
if (lod > 0 && hash2(Math.floor(u * 3.1), Math.floor(v * 2.7), sd ^ 0x9B) < rd) {
var rn = (10 + bh * 16) * shade * (0.5 + 0.5 * sun);
var rday = (30 + 150 * sun * sun + bh * 40) * shade;
var rcol = P.slate;
if (dFill > 0.002 && hash2(Math.floor(u * 1.9), Math.floor(v * 1.9), sd ^ 0x7D3) < dFill)
rcol = sun > 0.66 && bh > 0.55 ? (bh > 0.80 ? P.sand : P.ember)
: (bh < 0.30 ? P.timber : P.stone);
else if (sun > 0.6 && bh > 0.6) rcol = P.ember;
return fset(bh < 0.4 ? G_COLON : (bh < 0.75 ? G_PCT : G_AMP), rcol,
rn + (rday - rn) * dFill);
}
return fset(0, P.shadow, 0);
}
function facade(u, v, cell, dist, t) {
if (v < 0) v = 0;
weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t);
var sd = seedOf(cell);
if (cell && cell.style === 6) return rockFace(u, v, cell, dist, sd);
var st = STYLE_W[cell ? (((cell.style | 0) % 6 + 6) % 6) : 0];
var h = cell && cell.h ? cell.h : 6;
var lit = cell && typeof cell.litRate === 'number' ? cell.litRate : 0.1;
var hue = cell && typeof cell.hue === 'number' ? cell.hue : P.slate;
var accent = cell && typeof cell.accent === 'number' ? cell.accent : P.warm;
var sun = sunOf(cell);
var lod = dist < 20 ? 2 : (dist < 46 ? 1 : 0);
var gr = grain(u, v, sd, lod);
var mh = hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x1D5);
var dayMat = mh < dFill;
var ms = dFill > 0.002 ? mh / dFill : 0;
var k = clamp((sun - 0.22) / 0.52, 0, 1);
var mat = ms < 0.72 * k * k ? MAT_SUN[hue]
: (ms < 0.72 * k * k + 0.24 + 0.20 * k ? MAT_MID[hue] : MAT_SHD[hue]);
var litHue = dayMat ? mat
: ((hue === P.warm || hue === P.white || hue === P.ember) ? hue : P.amber);
var sunHue = dayMat ? mat : (sun >= 0.62 ? P.amber : litHue);
var shdHue = dayMat ? MAT_SHD[hue] : P.slate;
if (h - v < 0.34) {
return fset(G_EQ, sun >= 0.62 ? sunHue : (sun > 0.30 ? litHue : shdHue),
(sun >= 0.62 ? 214 : (sun > 0.30 ? 82 : 32)) * gr);
}
if (h - v < 0.62) {
if (dFill <= 0.002) return fset(0, P.shadow, 0);
var wr = hash2(Math.floor(u * 4.3), 0, sd ^ 0x3E9);
if (wr > 0.86 * dFill) return fset(0, P.shadow, 0);
return fset(wr < 0.30 ? G_PIPE : G_COLON, wr < 0.50 ? P.timber : shdHue,
(12 + 54 * sun) * gr);
}
var bay = Math.floor(u / st.bay), fu = u / st.bay - bay;
var bh = hash2(bay, sd, 0x3F1);
if (v > st.gnd && v < st.gnd + 0.30) {
if (dFill <= 0.002) return fset(0, P.shadow, 0);
var pz = hash2(Math.floor(u * 3.3), Math.floor(v * 6), sd ^ 0x91);
if (pz > 0.82 * dFill) return fset(0, P.shadow, 0);
return fset(pz < 0.5 ? G_UNDER : G_DASH, P.indigo, (14 + 38 * dSky) * gr);
}
if (v > st.gnd + 0.30 && v < st.gnd + 0.52)
return fset(G_DASH, sun >= 0.62 ? sunHue : shdHue, (sun >= 0.62 ? 74 : 22) * gr);
if (v <= st.gnd) {
var doorL = bh < 0.5;
var dw = 0.34, ww = st.shopW / st.bay;
var d0 = doorL ? 0.10 : 0.86 - dw, d1 = d0 + dw;
var w0 = doorL ? 0.52 : 0.10, w1 = w0 + ww; if (w1 > 0.90) w1 = 0.90;
var open = hash2(bay, sd, 0x5E1) < clamp(lit * 3.1, 0.05, 0.62);
if (v < 2.15 && fu > d0 && fu < d1) {
if (fu - d0 < 0.05 || d1 - fu < 0.05 || v > 2.02)
return fset(G_PIPE, shdHue, (20 + 44 * dFill * sun) * gr);
if (open && dFill > 0.002 &&
hash2(Math.floor(u * 3.9), Math.floor(v * 3.9), sd ^ 0x2E7) < dFill) {
var dv2 = 1 - v / 2.15;
return fset(v < 0.30 ? G_EQ : (dv2 > 0.62 ? G_COLON : G_DOT),
v < 0.30 ? P.timber : P.indigo,
v < 0.30 ? 96 : (34 + 44 * dv2) * (0.5 + 0.5 * dSky));
}
if (!open) {
if (dFill <= 0.002) return fset(0, P.shadow, 0);
var dz = (fu - d0) / dw * 5;
return fset(Math.abs(v - 1.18) < 0.09 ? G_EQ : (dz - Math.floor(dz) < 0.16 ? G_PIPE : G_UNDER),
P.timber, (16 + 66 * sun) * gr);
}
var dk = 1 - v / 2.15;
return fset(v < 0.35 ? G_UNDER : G_8, P.warm, (96 + 74 * dk) * (0.7 + 0.5 * gr));
}
var wv0 = 0.80, wv1 = wv0 + st.shopH;
if (v > wv0 && v < wv1 && fu > w0 && fu < w1) {
if (v - wv0 < 0.14 || wv1 - v < 0.14 || fu - w0 < 0.04 || w1 - fu < 0.04)
return fset(G_EQ, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate),
((sun >= 0.62 ? 66 : 26) + 78 * dFill * sun) * gr);
if (!open) {
var bd = Math.floor((v * 1.6 + fu * 2.2) * 2.4);
if (bd & 1) return fset(G_SLASH, dayMat ? P.timber : P.slate,
(15 + 74 * dFill * sun) * gr);
return dFill <= 0.002 ? fset(0, P.shadow, 0)
: fset(G_DOT, P.indigo, (10 + 44 * dSky) * gr);
}
var mull = Math.abs(fu - (w0 + w1) * 0.5) < 0.022;
if (mull) return fset(G_PIPE, shdHue, 30 + 52 * dFill * sun);
var gl = hash2(Math.floor(u * 2.6), Math.floor(v * 2.6), sd ^ 0x77);
if (dFill > 0.002 &&
hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x6A3) < dFill) {
var rv = (v - wv0) / st.shopH;
if (rv > 0.58) {
var rk = (rv - 0.58) / 0.42;
return fset(ink(0.44 + 0.38 * rk + 0.14 * (gl - 0.5)),
gl < 0.62 ? P.white : P.ice, (108 + 84 * rk) * (0.5 + 0.5 * dSky));
}
if (gl > 0.86) return fset(G_UNDER, P.sand, (86 + 54 * gl) * (0.4 + 0.6 * dSky));
return fset(gl < 0.34 ? G_HASH : (gl < 0.66 ? G_COLON : G_DOT),
gl < 0.34 ? P.timber : P.indigo,
(52 + 78 * gl) * (0.5 + 0.5 * dSky));
}
if (gl < 0.17) return fset(G_0, P.shadow, 0);
if (gl > 0.62) return fset(gl > 0.90 ? G_o : G_8, P.amber, (208 + gl * 46) * gr);
return fset(gl < 0.42 ? G_8 : G_0, gl > 0.56 ? accent : P.warm, (120 + gl * 96) * gr);
}
return board(u, v, st, sd, lod, gr, sun * (0.42 + 0.20 * dFill), sunHue, shdHue, dayMat, dist);
}
var uy = v - (st.gnd + 0.52);
var storey = Math.floor(uy / st.up);
var sv = uy - storey * st.up;
if (storey >= 0 && storey < 2 && sv > 0.55 && sv < 0.55 + st.winH) {
var cw = st.winW / st.bay, c0 = 0.5 - cw * 0.5, c1 = 0.5 + cw * 0.5;
if (fu > c0 && fu < c1) {
var wh = hash2(bay * 7 + storey, sd, 0x8D2);
if (sv - 0.55 < 0.11 || 0.55 + st.winH - sv < 0.11 || fu - c0 < 0.05 || c1 - fu < 0.05)
return fset(G_DASH, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate),
((sun >= 0.62 ? 58 : 22) + 82 * dFill * sun) * gr);
if (wh < lit) {
var lg = hash2(Math.floor(u * 3.4), Math.floor(v * 3.4), sd ^ 0xA3);
if (dFill > 0.002 &&
hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x6A3) < dFill) {
if (Math.abs(sv - (0.55 + st.winH * 0.5)) < 0.06)
return fset(G_DASH, P.white, (30 + 96 * sun) * gr);
if (lg > 0.80) return fset(G_UNDER, P.white, (96 + 60 * lg) * (0.4 + 0.6 * dSky));
return fset(lg < 0.40 ? G_COLON : G_DOT, P.indigo,
(34 + 62 * dSky + lg * 34) * gr);
}
if (lg < 0.16) return fset(G_o, P.shadow, 0);
if (lg > 0.66) return fset(lg > 0.92 ? G_o : G_8, P.amber, (204 + lg * 50) * gr);
return fset(G_8, P.warm, (112 + lg * 84) * gr);
}
var dg = hash2(Math.floor(u * 2.2), Math.floor(v * 2.2), sd ^ 0xB5);
if (dg < 0.30) return fset(G_COLON, P.ice, (20 + 46 * dFill) * gr);
if (dFill <= 0.002) return fset(0, P.shadow, 0);
if (Math.abs(sv - (0.55 + st.winH * 0.5)) < 0.06)
return fset(G_DASH, P.white, (30 + 96 * sun) * gr);
return fset(dg < 0.62 ? G_COLON : G_DOT, P.indigo, (18 + 50 * dSky + dg * 26) * gr);
}
if (st.rough === 0 && (sv - 0.55 < 0.10 || 0.55 + st.winH - sv < 0.10) && bh > 0.62)
return fset(G_DASH, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate),
((sun >= 0.62 ? 50 : 18) + 76 * dFill * sun) * gr);
}
var gs = hash2(sd, 0x51, 0x6C7);
if (dFill > 0.002 && gs < 0.17 && h > 6.2) {
var gy0 = st.gnd + 1.35, gy1 = gy0 + 1.60;
if (v > gy0 && v < gy1 && h - v > 1.10) {
var gu = u / 0.62, fgu = gu - Math.floor(gu);
var gvb = Math.floor((v - gy0) / 0.40);
var gw = hash2(Math.floor(gu), gvb, sd ^ 0x5A3);
var inkP = (gvb === 0 || gvb === 3) ? 0.80 : 0.42;
if (fgu < 0.58 && gw < inkP &&
hash2(Math.floor(u * 3.4), Math.floor(v * 3.4), sd ^ 0x9E1) < 0.74 * dFill)
return fset(gw < 0.34 ? G_HASH : G_8,
gs < 0.085 ? P.ember : P.white, (54 + 128 * sun + gw * 30) * gr);
}
}
return board(u, v, st, sd, lod, gr, sun, sunHue, shdHue, dayMat, dist);
}
function board(u, v, st, sd, lod, gr, sun, sunHue, shdHue, dayMat, dist) {
if (st.rough) {
var m = hash2(Math.floor(u * 2.4), Math.floor(v * 2.4), sd ^ 0x4C1);
var mdens = 0.10 + 0.26 * sun;
mdens += (0.94 - mdens) * dFill;
if (m > mdens) return fset(0, P.shadow, 0);
var mn = 10 + 62 * sun + m * 40;
var md = 40 + 44 * dSky + 184 * sun * sun + 44 * m;
return fset(dayMat ? ink(0.32 + 0.76 * sun * sun + 0.26 * (m / mdens - 0.5))
: (m < mdens * (0.40 - 0.12 * dFill) ? G_QUOTE
: (m < mdens * (1 - 0.38 * dFill) ? G_COLON : G_DOT)),
sun >= 0.62 ? sunHue : shdHue, (mn + (md - mn) * dFill) * gr);
}
var lap = st.lap * (lod === 2 ? 1 : (lod === 1 ? 2 : 4));
if (st.vert) {
var bx = u / (lap * 1.4), fbx = bx - Math.floor(bx);
if (fbx > 0.14) {
return (sun >= 0.62 && hash2(Math.floor(u * 1.7), Math.floor(v * 1.7), sd ^ 0x2A) < 0.12)
? fset(G_QUOTE, sunHue, 26 * gr)
: fillCell(u, v, sd, gr, sun, sun >= 0.62 ? sunHue : shdHue, lod);
}
var dark = fbx > 0.085 && dFill > 0.002 && lod === 2;
return fset(G_PIPE, sun >= 0.62 && !dark ? sunHue : shdHue,
((12 + 58 * sun) + ((dark ? 30 : 128) + 110 * sun * sun - 12 - 58 * sun) * dFill) * gr);
}
var bv = v / lap, fbv = bv - Math.floor(bv);
var wob = hash2(Math.floor(u * 1.3), Math.floor(v / lap), sd ^ 0x31);
if (lod === 2 && dFill > 0.002) {
var course = Math.floor(v / lap);
var ju = (u + hash2(course, sd, 0x4B7) * 3.7) / 4.1;
var fju = ju - Math.floor(ju);
if (fju < 0.045 && hash2(Math.floor(ju), course, sd ^ 0x7C1) < dFill)
return fset(G_PIPE, shdHue, (26 + 74 * sun * sun) * gr);
var stud = u / 0.61, fst = stud - Math.floor(stud);
if (fst < 0.10 && fbv > 0.30 && fbv < 0.52 &&
hash2(Math.floor(stud), course, sd ^ 0x2B9) < 0.44 * dFill)
return fset(G_COLON, P.timber, (22 + 62 * sun) * gr);
}
if (sun >= 0.62) {
var body = hash2(Math.floor(u * 2.4), Math.floor(v * 2.4), sd ^ 0x66);
if (fbv <= 0.30) {
var lapN = 176 + wob * 68;
var lapD = 42 + 96 * sun * sun + wob * 30;
return fset(wob < 0.22 ? G_UNDER : G_DASH,
dFill > 0.5 ? shdHue : sunHue, (lapN + (lapD - lapN) * dFill) * gr);
}
if (body < 0.62)
return fset(dayMat ? ink(0.34 + 0.72 * sun * sun + 0.28 * (body / 0.62 - 0.5))
: (body < 0.20 ? G_DASH : (body < 0.44 ? G_UNDER : G_TICK)), sunHue,
((124 + body * 74) +
((58 + 46 * dSky + 168 * sun * sun + body * 40) - 124 - body * 74) * dFill) * gr);
return fillCell(u, v, sd, gr, sun, sunHue, lod);
}
if (fbv > 0.30) {
if (lod === 2 && hash2(Math.floor(u * 2.8), Math.floor(v * 2.8), sd ^ 0x66) < 0.10)
return fset(G_DOT, shdHue, (10 + 46 * sun) * gr);
return fillCell(u, v, sd, gr, sun, shdHue, lod);
}
return fset(wob < 0.22 ? G_UNDER : G_DASH, shdHue,
((13 + 74 * sun + wob * 22) +
((22 + 88 * sun * sun + wob * 24) - 13 - 74 * sun - wob * 22) * dFill) * gr);
}
function fillCell(u, v, sd, gr, sun, hue, lod) {
if (dFill <= 0.002) return fset(0, P.shadow, 0);
var h = hash2(Math.floor(u * 3.7), Math.floor(v * 3.7), sd ^ 0xC13);
var cov = 0.93 * dFill;
if (h > cov) return fset(0, P.shadow, 0);
var q = h / cov;
return fset(ink(0.34 + 0.72 * sun * sun + 0.30 * (q - 0.5)),
hue, (34 + 46 * dSky + 178 * sun * sun + 40 * q) * gr);
}
var ROUT = { ch: 0, col: 0, lum: 0, mir: 0, rip: 0, wch: 0 };
var mirNow = 0, ripNow = 0, wchNow = 0;
function rset(ch, col, lum) {
ROUT.ch = ch; ROUT.col = col;
ROUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0);
ROUT.mir = mirNow; ROUT.rip = ripNow; ROUT.wch = wchNow;
return ROUT;
}
var BOARDWALK = 1.72;
function inCross(C, wz) {
if (!C.xn) return 0;
var i = Math.round((wz - C.xz0) / (C.xpitch || 26));
if (i < 0) i = 0; else if (i >= C.xn) i = C.xn - 1;
var d = wz - C.xc[i]; if (d < 0) d = -d;
if (d <= C.xw[i] + 1.1) return 1;
if (i > 0) { d = wz - C.xc[i - 1]; if (d < 0) d = -d; if (d <= C.xw[i - 1] + 1.1) return 1; }
if (i < C.xn - 1) { d = wz - C.xc[i + 1]; if (d < 0) d = -d; if (d <= C.xw[i + 1] + 1.1) return 1; }
return 0;
}
function floorTex(wx, wz, dist, t) {
weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t);
var C = cfg();
var half = C ? C.half : 3.1;
var lane = wx - (C ? C.streetX : 4.0);
var al = lane < 0 ? -lane : lane;
var lod = dist < 20 ? 2 : (dist < 46 ? 1 : 0);
mirNow = 0; ripNow = 0; wchNow = 0;
var comp = (C && C.swap) ? SUN_Z : SUN_X;
var lit = -lane * comp;
var sunSide = lit > 0.4 ? 1 : (lit < -0.4 ? 0 : (Math.abs(comp) < 0.35 ? 1 : 0));
if (al > half && al < half + BOARDWALK) {
if (inCross(C, wz)) {
} else {
var into = al - half;
if (into < 0.16)
return rset(G_UNDER, sunSide ? P.amber : P.white, (sunSide ? 214 : 60) * (0.8 + 0.4 * hash2((wz * 3) | 0, 0, 0x11)));
var pj = wz / 0.92, fpj = pj - Math.floor(pj);
var pw = hash2(Math.floor(pj), (al * 2) | 0, 0x5B);
if (fpj < 0.10)
return rset(G_DASH, P.slate, (14 + pw * 12));
if (lod === 2 && pw < 0.10)
return rset(pw < 0.04 ? G_COMMA : G_DOT, P.slate, 12 + pw * 60);
if (dFill > 0.002 && hash2(Math.floor(wz * 4.1), (al * 3) | 0, 0x2F7) < 0.94 * dFill)
return rset(ink((sunSide ? 0.60 : 0.36) + 0.26 * (pw - 0.5)),
sunSide ? P.sand : P.timber,
(sunSide ? 150 : 78) + pw * 52);
if (sunSide) return rset(G_UNDER, P.white, (62 + pw * 40));
return (pw < 0.30) ? rset(G_UNDER, P.slate, 12 + pw * 20) : rset(0, P.shadow, 0);
}
}
if (al >= half + BOARDWALK) {
if (lod === 0) return rset(0, P.shadow, 0);
var og = hash2(Math.floor(wx * 1.6), Math.floor(wz * 1.6), 0x2D9);
var od = 0.14 + (0.82 - 0.14) * dFill;
if (og > od) return rset(0, P.shadow, 0);
if (dFill > 0.002 && og < od * dFill)
return rset(ink(0.30 + 0.24 * (og / od - 0.5)), P.timber, 46 + og * 90);
return rset(og < 0.05 ? G_COMMA : G_DOT, P.slate, 10 + og * 60);
}
var n = al / half;
var wet = wWet * 1.05;
var rut = 0;
if (lod > 0) {
var rc = 0.44 + vnoise(wz * 0.055, 0x3B) * 0.10;
var dr = Math.abs(n - rc);
rut = dr < 0.075 ? 1 - dr / 0.075 : 0;
}
if (rut > 0.25 && wet > 0.45) {
var wsurf = rut * clamp(wet - 0.4, 0, 1);
if (wsurf > 0.12) {
mirNow = clamp(wsurf * 1.25, 0, 1);
ripNow = CC.reducedMotion ? 0 : Math.sin(wz * 1.7 + t * 1.4) * 0.9 * wWind;
wchNow = G_TILDE;
var ws = hash2(Math.floor(wx * 3), Math.floor(wz * 3), 0x71C);
return rset(ws < 0.5 ? G_TILDE : G_SEMI, P.slate, 12 + ws * 22);
}
}
if (rut > 0.22) {
var rs = hash2(Math.floor(wx * (lod === 2 ? (dist < 9 ? 6.2 : 3.0) : 1.7)),
Math.floor(wz * (lod === 2 ? (dist < 9 ? 6.2 : 3.0) : 1.7)), 0x18F);
var rd = (0.34 + 0.42 * rut) * (lod === 2 ? 1 : 0.8);
rd += (0.96 - rd) * dFill;
if (rs < rd) {
var rk = rs / rd;
var rn = (26 + rs * 150) * rut * (sunSide ? 1.15 : 0.72);
var rdy = (108 + rk * 104) * (0.55 + 0.45 * rut) * (sunSide ? 1.10 : 0.80);
return rset(dFill > 0.002 && hash2(Math.floor(wx * 2.7), Math.floor(wz * 2.7), 0x3C8) < dFill
? ink((sunSide ? 0.66 : 0.50) + 0.26 * (rk - 0.5))
: (rs < 0.14 ? G_UNDER : (rs < 0.34 ? G_COMMA : G_DOT)),
sunSide ? (dFill > 0.5 ? P.sand : P.white) : (dFill > 0.5 ? P.timber : P.slate),
rn + (rdy - rn) * dFill);
}
if (lod === 2 && dist > 8 && rs > 0.988) return rset(G_o, P.slate, 30 + (1 - rs) * 3200);
return rset(0, P.shadow, 0);
}
var sideK = 0.25 + 0.75 * clamp(1 - dAlt() / 0.95, 0, 1);
var lightK = clamp(0.18 + 0.62 * dSky + 0.26 * dSun, 0, 1.0);
var sideBias = sunSide ? (1 + 0.25 * sideK) : (1 - 0.28 * sideK);
var lodQ = lod === 2 ? 1 : (lod === 1 ? 0.82 : 0.6);
var dnight = (0.42 - 0.20 * n * n) * sideBias * lightK * lodQ;
var dday = (0.94 - 0.22 * n * n) * sideBias * (lod === 2 ? 1 : (lod === 1 ? 0.92 : 0.82));
var dens = dnight + (dday - dnight) * dFill;
dens *= (0.82 + 0.5 * wDust) * (1 - (0.45 - 0.27 * dFill) * clamp(wet - 0.3, 0, 1));
var q = lod === 2 ? (dist < 9 ? 5.6 : 2.6) : (lod === 1 ? 1.5 : 0.85);
var d1 = hash2(Math.floor(wx * q), Math.floor(wz * q), 0x4A7);
if (d1 < dens) {
var hot = d1 < dens * 0.16 && sunSide;
var k1 = d1 / dens;
var sc = hash2(Math.floor(wx * q * 1.7), Math.floor(wz * q * 1.7), 0x1C5);
var dayGround = dSun > 0.55;
var gn = (hot ? 132 : 22 + k1 * 128);
var gd = (hot ? 176 : 88 + k1 * 96);
var gsc = sunSide ? 0.62 : 0.44;
var lightMul = 0.6 + 0.7 * lightK + 0.9 * dSun;
lightMul += (1.40 - lightMul) * dFill;
return rset(sc < dFill * 0.86
? ink(gsc + 0.30 * (k1 - 0.5) + 0.16 * dSun)
: (k1 < 0.3 ? G_DOT : (k1 < 0.62 ? G_COMMA : G_TICK)),
hot ? P.amber
: (sc < dFill * 0.86 ? P.sand : ((sunSide || dayGround) ? P.white : P.slate)),
(gn + (gd - gn) * dFill) * (sunSide ? 1 : 0.78) * lightMul);
}
if (lod === 2) {
var d2 = hash2(Math.floor(wx * q * 0.5), Math.floor(wz * q * 0.5), 0x6E3);
if (d2 < 0.014) return rset(G_o, P.slate, 26 + d2 * 1300);
if (d2 > 0.990) return rset(G_QUOTE, P.spring, 22 + (1 - d2) * 1300);
}
return rset(0, P.shadow, 0);
}
var SOUT = { ch: 0, col: 0, lum: 0 };
function sset(ch, col, lum) {
SOUT.ch = ch; SOUT.col = col;
SOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0);
return SOUT;
}
function sky(sx, sy, t) {
weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t);
var C = cfg();
var rows = C && C.rows ? C.rows : 60;
var hor = C ? C.horizon : rows * 0.56;
var vs = C && C.skyVScale ? C.skyVScale : 1;
var kk = C && C.skyK ? C.skyK : (rows / 0.7);
var ey = Math.floor((hor - sy) * vs);
var a = ey / rows;
if (a < 0) a = 0;
var bear = sx / kk;
var da = bear - SUN_AZ;
da = Math.atan2(Math.sin(da), Math.cos(da));
var away = Math.abs(da) / Math.PI;
var west = 1 - away; west = west * west * (0.55 + 0.45 * west);
var lift = 0.90 + 0.50 * wDust;
var cap = 1 - 0.52 * wCloud * (1 - 0.80 * dFill);
var warmK = dWarm;
var efold = 0.50 + 0.95 * (1 - warmK);
var e = Math.exp(-a / efold) * (0.30 + 0.70 * (warmK * west + (1 - warmK) * 0.55)) *
lift * cap * (0.10 + 1.05 * dSky);
var hs = hash2(sx, ey, C ? C.skySeed : 0x5EED);
var hs2 = hash2(sx, ey, (C ? C.skySeed : 0x5EED) ^ 0x11);
var band = a > 0.16 && a < 0.44 ? 1 - Math.abs(a - 0.30) / 0.14 : 0;
if (band > 0) {
var ve = band * away * away * cap * lift;
if (hs < 0.075 * ve) return sset(G_DOT, P.violet, (70 + 96 * ve) * (0.7 + 0.5 * hs2));
}
var covr = 0.05 + 1.18 * e;
covr += (0.96 - covr) * dFill;
if (hs < covr) {
if (warmK > 0.42) {
if (e > 0.80) return sset(G_EQ, P.pure, 168 * (0.7 + 0.4 * hs2));
if (e > 0.58) return sset(G_EQ, P.amber, 248 * (0.72 + 0.32 * e) * (0.86 + 0.22 * hs2));
if (e > 0.32) return sset(e > 0.46 ? G_EQ : G_DASH, P.ember,
204 * (0.50 + 0.72 * e) * (0.78 + 0.40 * hs2));
if (e > 0.13) return sset(G_TICK, P.slate, 138 * (0.52 + 0.78 * e) * (0.78 + 0.38 * hs2));
return sset(G_DOT, P.azure, (16 + 46 * e) * (0.7 + 0.6 * hs2));
}
var dayHz = 1 - 0.65 * dFill;
if (e > 0.80) return sset(G_EQ, P.white, dayHz * 214 * (0.80 + 0.24 * e) * (0.88 + 0.18 * hs2));
if (e > 0.62) return sset(G_DASH, P.white, dayHz * 176 * (0.72 + 0.32 * e) * (0.86 + 0.22 * hs2));
if (e > 0.38) return sset(G_TICK, P.ice, 168 * (0.62 + 0.50 * e) * (0.82 + 0.30 * hs2));
return sset(hs2 > 0.6 ? G_COLON : G_DOT, P.ice, (54 + 150 * e) * (0.78 + 0.36 * hs2));
}
return sset(0, P.shadow, 0);
}
var FOG_START_W = 20.0, FOG_END_W = 210.0, FOG_POW_W = 1.25;
CC.SurfWest = { id: 'west',
facade: facade, floorTex: floorTex, sky: sky, STYLE: STYLE_W,
fogEnd: FOG_END_W,
sunOf: sunOf, BOARDWALK: BOARDWALK };
Object.defineProperty(CC.SurfWest, 'fogStart',
{ get: function () { return FOG_START_W + 20.0 * dFill; } });
Object.defineProperty(CC.SurfWest, 'fogPow',
{ get: function () { return FOG_POW_W - 0.53 * dFill; } });
Object.defineProperty(CC.SurfWest, 'SUN_AZ', { get: function () { return SUN_AZ; } });
Object.defineProperty(CC.SurfWest, 'SUN_X', { get: function () { return SUN_X; } });
Object.defineProperty(CC.SurfWest, 'SUN_Z', { get: function () { return SUN_Z; } });
Object.defineProperty(CC.SurfWest, 'SUN_ALT', { get: function () { return SUN_ALT; } });
Object.defineProperty(CC.SurfWest, 'dayFill', { get: function () { return dFill; } });
CC.SurfWest.dayAt = dayAt;
if (!CC.SURFACES) CC.SURFACES = {};
CC.SurfWest.SKY_RGB = [3,4,12,26,28,48, 74,122,186,180,170,148, 48,52,96,232,132,60];
CC.SURFACES.west = CC.SurfWest;
})(CC);
};
W["elements/west_desert.js"] = function (CC) {
'use strict';
/* src/elements/west_desert.js */
(function (CC) {
var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ;
var project = PR.project, emit = PR.emit, column = PR.column, litFace = PR.litFace;
var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp;
var G_DOT = CC.g('.'), G_COMMA = CC.g(','), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"),
G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_TILDE = CC.g('~'),
G_PIPE = CC.g('|'), G_SLASH = CC.g('/'), G_BSL = CC.g('\\'), G_STAR = CC.g('*'),
G_PCT = CC.g('%'), G_AMP = CC.g('&'), G_o = CC.g('o'), G_8 = CC.g('8');
var TAU = 6.283185307;
var CITY = null, BASE = 0, Surf = null, WEST = null;
function boot(city) {
CITY = (city && city.aveX && city.world === 'west') ? city : null;
BASE = CITY ? ((Math.imul(CITY.seed | 0, 52711) >>> 6) & 0x3fffff) : 0;
}
var W_WIND = 1, W_HAZE = 1, W_RAIN = 0;
var D_SKY = 0.66, D_SUN = 0.64, D_WARM = 0.74;
function view(f, cam, t) {
PR.view(f, cam, t);
if (!Surf) Surf = CC.Surf;
if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null;
var Wm = CC.Weather;
W_WIND = Wm && Wm.rel ? Wm.rel('wind') : 1;
W_HAZE = Wm && Wm.rel ? Wm.rel('haze') : 1;
W_RAIN = Wm && Wm.P ? Wm.P.rain : 0;
var Dm = CC.Daylight;
D_SKY = Dm ? Dm.P.sky : 0.66;
D_SUN = Dm ? Dm.P.sun : 0.64;
D_WARM = Dm ? Dm.P.warm : 0.74;
}
function far(f, x, y, ch, col, lum, d) {
if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return;
put(f, x, y, ch, col, lum, d, 3);
}
function strand(f, x0, z0, y0, x1, z1, y1, ch, col, lum) {
var n = 9, lx = -1, ly = 0, ld = 0, i;
for (i = 0; i <= n; i++) {
var u = i / n, k = u * u;
if (!project(x0 + (x1 - x0) * k, y0 + (y1 - y0) * u, z0 + (z1 - z0) * k)) { lx = -1; continue; }
var px = Math.floor(PJ.x), py = Math.floor(PJ.y), pd = PJ.d;
if (lx >= 0 && (pd > ld * 2 || ld > pd * 2)) lx = -1;
if (lx >= 0) {
var dx = px - lx, dy = py - ly;
var st = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy);
if (st > V.rows * 3) st = 0;
for (var q = 1; q < st; q++) {
var tq = q / st;
emit(f, lx + Math.round(dx * tq), ly + Math.round(dy * tq), ch, col, lum,
ld + (pd - ld) * tq);
}
}
emit(f, px, py, ch, col, lum, pd);
lx = px; ly = py; ld = pd;
}
}
function onRoad(px, pz, pad) {
var i = Math.round(px / CITY.AVE), j = Math.round(pz / CITY.CROSS), k;
for (k = -1; k <= 1; k++) {
var c = CITY.aveX(i + k) + 0.5, hw = CITY.aveW(i + k) + pad;
if (px > c - hw && px < c + hw) return 1;
var c2 = CITY.crossZ(j + k) + 0.5, hw2 = CITY.crossW(j + k) + pad;
if (pz > c2 - hw2 && pz < c2 + hw2) return 1;
}
return 0;
}
function standing(px, pz, clear, near, far2) {
if (CITY.height(px, pz) > 0.1) return 0;
if (clear > 0 && (CITY.height(px + clear, pz) > 0.1 || CITY.height(px - clear, pz) > 0.1 ||
CITY.height(px, pz + clear) > 0.1 || CITY.height(px, pz - clear) > 0.1)) return 0;
var rx = px - V.ox, rz = pz - V.oz;
var w = rx * V.fwx + rz * V.fwz;
if (w < near || w > far2) return 0;
var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 8;
if (s < -lim || s > lim) return 0;
return w;
}
var MB_N = [45, 29];
var MB_H0 = [0.030, 0.105];
var MB_HS = [0.115, 0.150];
var MB_P = [0.62, 0.30];
var MB_TONE = [1.00, 0.72];
var MB_D = [8.8e4, 8.6e4];
var MB_PITCH = [TAU / MB_N[0], TAU / MB_N[1]];
function step(dd) {
if (dd < 0.55) return 1.0;
if (dd < 0.78) return 0.66;
if (dd < 1.00) return 0.34;
return 0;
}
var MF_SIDE = 0;
function ridge(bear, b) {
var pitch = MB_PITCH[b], n = MB_N[b];
var k0 = Math.floor(bear / pitch), best = 0, bestSide = 0, kk;
for (kk = k0 - 1; kk <= k0 + 1; kk++) {
var slot = ((kk % n) + n) % n;
if (hash2(slot, b, BASE + 0x71) > MB_P[b]) continue;
var c = (kk + 0.5 + (hash2(slot, b, BASE + 0x72) - 0.5) * 0.60) * pitch;
var w = pitch * (0.26 + 0.36 * hash2(slot, b, BASE + 0x73));
var hh = hash2(slot, b, BASE + 0x74);
var top = MB_H0[b] + hh * hh * hh * MB_HS[b];
var off = bear - c;
var s = step((off < 0 ? -off : off) / w);
if (s <= 0) continue;
var e = top * s;
if (e > best) { best = e; bestSide = off < 0 ? -1 : 1; }
}
MF_SIDE = bestSide;
if (b === 0) {
var base = 0.0055 + 0.0115 * vnoise(bear * 2.6 + 31.7, BASE + 0x75);
if (base > best) { best = base; MF_SIDE = 0; }
}
return best;
}
function drawMesas(f) {
var sunX = WEST ? WEST.SUN_X : -0.479, sunZ = WEST ? WEST.SUN_Z : 0.878;
var cols = V.cols, hp = V.hp, scale = V.scale;
var horiz = V.horizon, hrow = Math.floor(horiz);
if (hrow < 0) return;
if (hrow > V.rows - 1) hrow = V.rows - 1;
var airlight = (4 + 190 * D_SKY) * clamp(0.42 + 0.46 * W_HAZE, 0.34, 1.30);
var x, r;
for (x = 0; x < cols; x++) {
var sp = ((x + 0.5) * 2 / cols - 1) * hp;
var dirx = V.fwx + V.rgx * sp, dirz = V.fwz + V.rgz * sp;
var il = 1 / Math.sqrt(dirx * dirx + dirz * dirz);
var nx = dirx * il, nz = dirz * il;
var bear = V.yaw + Math.atan(sp);
var toSun = nx * sunX + nz * sunZ;
var rgtSun = nz * sunX - nx * sunZ;
var b;
for (b = 0; b < 2; b++) {
var elev = ridge(bear, b);
if (elev <= 0) continue;
var yTop = horiz - Math.tan(elev) * scale;
var r0 = Math.floor(yTop);
if (r0 > hrow) continue;
if (r0 < 0) r0 = 0;
var d = MF_SIDE * rgtSun;
var kk = clamp(0.5 + 0.62 * d, 0, 1);
var lit = 0.10 + 0.90 * kk * kk * (3 - 2 * kk);
lit = 0.35 + 0.65 * lit * D_SUN;
var backlit = clamp(toSun, 0, 1) * D_WARM;
var tone = MB_TONE[b];
var body = airlight * tone * (0.34 + 0.58 * lit) * (1 - 0.42 * backlit);
var dist = MB_D[b];
for (r = r0; r <= hrow; r++) {
if (r === r0) {
var cl = body * 1.5 + airlight * tone * 0.30 +
190 * backlit * clamp(toSun - 0.30, 0, 0.7) * 1.4;
var ccol = (D_WARM > 0.35 && (backlit > 0.18 || lit > 0.72)) ? P.amber
: (D_SKY > 0.42 ? P.white : P.slate);
far(f, x, r, elev > 0.030 ? G_UNDER : G_DASH, ccol, cl, dist - 1);
continue;
}
var dens = 0.16 + 0.40 * D_SKY;
var h = hash2(Math.floor(bear * 240), (hrow - r) * 3 + b, BASE + 0x76);
if (h > dens || body < 4) { far(f, x, r, 0, P.shadow, 0, dist); continue; }
far(f, x, r, h < dens * 0.42 ? G_DASH : (h < dens * 0.78 ? G_UNDER : G_TICK),
D_SKY > 0.55 ? P.white : (D_WARM > 0.40 ? P.ember : P.slate),
body * (0.62 + 0.70 * (h / dens)), dist);
}
}
}
}
var YUC_LAT = 6.7, MES_LAT = 11.3, OCO_LAT = 13.9, WASH_LAT = 9.7;
function drawPlants(f) {
var i, j, w, x, y, dd;
var sunX = (WEST && WEST.SUN_X < 0) ? -1 : 1;
var sunA = litFace(1, 0), sunB = litFace(0, 1);
var sun = sunA > sunB ? sunA : sunB;
var day = clamp(0.14 + 0.86 * D_SUN, 0, 1);
var hot = sun > 0.6 && D_SUN > 0.35;
var dF = dayFill();
var lo = Math.floor((V.ox - 46) / YUC_LAT), hi = Math.floor((V.ox + 46) / YUC_LAT);
var lo2 = Math.floor((V.oz - 46) / YUC_LAT), hi2 = Math.floor((V.oz + 46) / YUC_LAT);
for (j = lo2; j <= hi2; j++) {
for (i = lo; i <= hi; i++) {
var yh = hash2(i, j, BASE + 0x21);
if (yh > 0.28) continue;
var yx = i * YUC_LAT + hash2(i, j, BASE + 0x22) * YUC_LAT;
var yz = j * YUC_LAT + hash2(i, j, BASE + 0x23) * YUC_LAT;
if (onRoad(yx, yz, 2.4)) continue;
w = standing(yx, yz, 1.3, 1.0, 52);
if (!w) continue;
var stalk = 1.5 + (yh / 0.28) * 1.0;
column(f, yx, yz, 0, 0.55, G_STAR, leafC(yh, dF), 24 + 30 * day + 84 * dF, 0);
if (w < 22) {
if (project(yx - 0.34, 0.42, yz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_SLASH, P.slate, 20 + 26 * day, PJ.d);
if (project(yx + 0.34, 0.42, yz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_BSL, P.slate, 20 + 26 * day, PJ.d);
}
column(f, yx, yz, 0.5, stalk, G_PIPE, P.slate, 18 + 34 * day, 0);
if (project(yx, stalk + 0.12, yz)) {
x = Math.floor(PJ.x); y = Math.floor(PJ.y); dd = PJ.d;
emit(f, x, y, G_8, hot ? P.white : P.slate, (hot ? 128 : 40) * (0.6 + 0.5 * day), dd);
if (w < 26) emit(f, x, y + 1, G_o, hot ? P.white : P.slate, (hot ? 92 : 30) * (0.6 + 0.5 * day), dd);
}
}
}
lo = Math.floor((V.ox - 62) / MES_LAT); hi = Math.floor((V.ox + 62) / MES_LAT);
lo2 = Math.floor((V.oz - 62) / MES_LAT); hi2 = Math.floor((V.oz + 62) / MES_LAT);
for (j = lo2; j <= hi2; j++) {
for (i = lo; i <= hi; i++) {
var mh = hash2(i, j, BASE + 0x31);
if (mh > 0.46) continue;
var mx = i * MES_LAT + hash2(i, j, BASE + 0x32) * MES_LAT;
var mz = j * MES_LAT + hash2(i, j, BASE + 0x33) * MES_LAT;
if (onRoad(mx, mz, 2.8)) continue;
w = standing(mx, mz, 2.0, 1.4, 62);
if (!w) continue;
var top = 2.0 + (mh / 0.46) * 1.0;
var half = 0.9 + mh * 1.8;
if (!project(mx, 0.10, mz)) continue;
var bcx = PJ.x, bry = PJ.y, bd = PJ.d;
if (!project(mx, top, mz)) continue;
var trY = PJ.y;
var rw = half * V.colK / w;
var iw = Math.ceil(rw); if (iw > 30) iw = 30;
var q, r2;
for (q = -iw; q <= iw; q++) {
var u = rw > 0.5 ? q / rw : 0;
if (u < -1 || u > 1) continue;
var qh = hash2(i * 31 + q, j, BASE + 0x34);
var prof = Math.sqrt(1 - u * u) * (0.72 + 0.34 * qh);
var rTop = Math.floor(bry + (trY - bry) * (0.34 + 0.66 * prof));
var rBot = Math.floor(bry);
var cx2 = Math.floor(bcx + q);
var side = (q * sunX > 0) ? 1 : 0;
var mcol = hot && side ? (dF > 0.5 ? P.moss : P.amber) : leafC(mh / 0.46, dF);
var mlum = (hot && side ? 68 + 92 * dF : 24 + 74 * dF) * (0.55 + 0.60 * day);
for (r2 = rTop; r2 <= rBot; r2++) {
var deep = r2 - rTop;
if (deep > 1 && hash2(cx2 * 3 + deep, i * 5 + j, BASE + 0x35) > 0.26) continue;
emit(f, cx2, r2, deep === 0 ? G_AMP : (qh < 0.6 ? G_PCT : G_STAR),
mcol, mlum * (deep === 0 ? 1.25 : 0.8) * (0.7 + 0.5 * qh), bd);
}
}
if (w < 24 && project(mx, 0.05, mz))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, P.slate, 12, PJ.d);
}
}
lo = Math.floor((V.ox - 58) / OCO_LAT); hi = Math.floor((V.ox + 58) / OCO_LAT);
lo2 = Math.floor((V.oz - 58) / OCO_LAT); hi2 = Math.floor((V.oz + 58) / OCO_LAT);
for (j = lo2; j <= hi2; j++) {
for (i = lo; i <= hi; i++) {
var oh = hash2(i, j, BASE + 0x41);
if (oh > 0.32) continue;
var ox = i * OCO_LAT + hash2(i, j, BASE + 0x42) * OCO_LAT;
var oz = j * OCO_LAT + hash2(i, j, BASE + 0x43) * OCO_LAT;
if (onRoad(ox, oz, 2.6)) continue;
w = standing(ox, oz, 1.8, 1.6, 58);
if (!w) continue;
var nw = 4 + Math.floor(hash2(i, j, BASE + 0x44) * 3);
var bloom = hash2(i, j, BASE + 0x45) < 0.22;
var q2;
for (q2 = 0; q2 < nw; q2++) {
var a = (q2 / nw) * TAU + hash2(i * 17 + q2, j, BASE + 0x46) * 0.9;
var wh2 = hash2(i, j * 13 + q2, BASE + 0x47);
var len = 2.0 + wh2 * 2.0;
var spread = 0.55 + wh2 * 0.85;
strand(f, ox, oz, 0.05,
ox + Math.cos(a) * spread, oz + Math.sin(a) * spread, len,
Math.abs(Math.cos(a)) > 0.72 ? (Math.cos(a) > 0 ? G_SLASH : G_BSL) : G_PIPE,
P.slate, (16 + 40 * day) * (0.7 + 0.5 * wh2));
if (bloom && project(ox + Math.cos(a) * spread, len + 0.1, oz + Math.sin(a) * spread))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_STAR, P.ember, 58 + 90 * day, PJ.d);
}
}
}
lo = Math.floor((V.ox - 40) / WASH_LAT); hi = Math.floor((V.ox + 40) / WASH_LAT);
lo2 = Math.floor((V.oz - 40) / WASH_LAT); hi2 = Math.floor((V.oz + 40) / WASH_LAT);
for (j = lo2; j <= hi2; j++) {
for (i = lo; i <= hi; i++) {
var gh = hash2(i, j, BASE + 0x51);
if (gh > 0.34) continue;
var gx = i * WASH_LAT + hash2(i, j, BASE + 0x52) * WASH_LAT;
var gz = j * WASH_LAT + hash2(i, j, BASE + 0x53) * WASH_LAT;
if (onRoad(gx, gz, 3.0)) continue;
w = standing(gx, gz, 1.6, 1.2, 40);
if (!w) continue;
var ba = hash2(i, j, BASE + 0x54) * TAU;
var bx = Math.cos(ba), bz = Math.sin(ba);
var q3, N = w < 16 ? 15 : 9;
for (q3 = 0; q3 < N; q3++) {
var u2 = (q3 / (N - 1)) * 2 - 1;
var jit = hash2(i * 7 + q3, j * 3, BASE + 0x55) - 0.5;
var wxp = gx + bx * u2 * 3.6 - bz * jit * 1.1;
var wzp = gz + bz * u2 * 3.6 + bx * jit * 1.1;
if (CITY.height(wxp, wzp) > 0.1) continue;
var g2 = hash2(i * 11 + q3, j * 5, BASE + 0x56);
if (project(wxp, 0.02, wzp))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), g2 < 0.5 ? G_UNDER : G_TILDE,
hot ? P.white : leafC(oh / 0.32, dF), (18 + 66 * day + 76 * dF) * (0.6 + 0.6 * g2), PJ.d);
if (g2 > 0.62 && (u2 < -0.35 || u2 > 0.35) && project(wxp, 0.10 + g2 * 0.34, wzp))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), g2 > 0.86 ? G_QUOTE : G_TICK,
P.amber, (26 + 76 * day) * (0.6 + 0.5 * g2), PJ.d);
}
}
}
}
var DU_MAX = 3600, DU_AT_REF = 420, DU_REF_CELLS = 200 * 60;
var DU_BOX_N = 24, DU_BOX_F = 68;
var duOx = null, duOz = null, duY = null, duSpd = null, duHue = null;
function initDust(rng) {
var r = CC.mulberry(((rng() * 4294967296) | 0) ^ 0x5C1E), i;
duOx = new Float32Array(DU_MAX); duOz = new Float32Array(DU_MAX);
duY = new Float32Array(DU_MAX); duSpd = new Float32Array(DU_MAX);
duHue = new Uint8Array(DU_MAX);
for (i = 0; i < DU_MAX; i++) {
var near = (i & 1) === 0;
var b = near ? DU_BOX_N : DU_BOX_F;
duOx[i] = r() * b; duOz[i] = r() * b;
var u = r(); u = u * u; u = u * u;
duY[i] = near ? u * 1.45 : u * 3.40;
duSpd[i] = 0.62 + r() * 0.76;
var h = r();
duHue[i] = h < 0.52 ? P.slate : (h < 0.82 ? P.white : P.amber);
}
}
function dayFill() {
return (CC.SurfWest && CC.SurfWest.dayFill !== undefined) ? CC.SurfWest.dayFill : 0;
}
function leafC(seedH, dF) {
if (seedH >= dF) return P.slate;
return seedH < dF * 0.42 ? P.timber : P.moss;
}
function wrap(v, b) { return v - b * Math.floor(v / b + 0.5); }
function veilCell(f, x, y, ch, col, lum, d, alpha) {
if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return;
if (lum > 0 && CC.Surf) { lum = CC.Surf.fog(lum, d); if (lum <= 0) ch = 0; }
if (alpha < 0.999) {
var i = y * V.cols + x;
var dl = f.lum[i];
lum = dl + (lum - dl) * alpha;
if (f.ch[i] !== 0) col = f.col[i];
var dc = f.dist[i];
if (d < dc && dc < 1 / 0) d = dc * 0.99999;
}
put(f, x, y, ch, col, lum > 255 ? 255 : (lum < 0 ? 0 : lum | 0), d, 3);
}
function drawDust(f) {
if (!duOx || !CITY) return;
var settle = 1 - clamp(W_RAIN * 1.5, 0, 1);
if (settle <= 0.02) return;
var amt = Math.pow(clamp(W_HAZE, 0.15, 2.6), 1.45) *
(0.30 + 0.70 * clamp(W_WIND, 0, 2.0)) * settle;
var use = (DU_AT_REF * clamp(amt, 0, 2.2) * V.cols * V.rows / DU_REF_CELLS) | 0;
if (use > DU_MAX) use = DU_MAX; else if (use < 6) return;
var Wd = CC.Weather ? CC.Weather.wind : null;
var wdx, wdz, wspd;
if (Wd) { wdx = Wd.dirX; wdz = Wd.dirZ; wspd = Wd.speed; }
else { wdx = 0.92; wdz = 0.39; wspd = 2.4 * (0.35 + 0.65 * clamp(W_WIND, 0, 1.85)); }
var tt = CC.reducedMotion ? 7.0 : V.t;
var travX = wdx * wspd * tt, travZ = wdz * wspd * tt;
var crossV = (wdx * V.rgx + wdz * V.rgz) * wspd;
var dirSign = crossV < 0 ? -1 : 1;
var lift = (0.06 + 0.94 * D_SKY) * (1 + 0.55 * D_WARM * D_SUN);
var dk = dayFill(); dk = dk * (2 - dk);
var dAlpha = 1 - 0.58 * dk;
var nCap = (5 - 3 * dk) | 0;
var farUse = use * clamp(0.34 + 0.46 * amt, 0.22, 1);
var rows = V.rows, cols = V.cols, i;
for (i = 0; i < use; i++) {
var near = (i & 1) === 0;
if (!near && i >= farUse) continue;
var b = near ? DU_BOX_N : DU_BOX_F;
var wx = V.ox + wrap(duOx[i] + travX * duSpd[i] - V.ox, b);
var wz = V.oz + wrap(duOz[i] + travZ * duSpd[i] - V.oz, b);
var rx = wx - V.ox, rz = wz - V.oz;
var w = rx * V.fwx + rz * V.fwz;
if (w < 0.8) continue;
var rr = rx * V.rgx + rz * V.rgz;
if (rr > V.hp * 1.3 * w || rr < -V.hp * 1.3 * w) continue;
var gh = CITY.height(wx, wz);
if (gh > 0.4) continue;
if (!project(wx, gh + duY[i], wz)) continue;
var px = PJ.x, py = Math.floor(PJ.y), d = PJ.d;
var n = (Math.abs(crossV) * duSpd[i] * 0.028 * V.colK / w) | 0;
if (n > nCap) n = nCap;
var base = (near ? 74 : 46) * lift *
(1 - clamp(w / (near ? DU_BOX_N * 0.82 : DU_BOX_F * 0.85), 0, 0.72));
if (base < 5) continue;
var g = hash2(i, 0, BASE + 0x61);
base *= 0.55 + 0.72 * g;
var hue = duHue[i];
if (hue === P.amber && D_WARM < 0.30) hue = P.white;
var gl = n >= 3 ? G_DASH : (n >= 1 ? G_TILDE : (d > 18 ? G_DOT : G_COMMA));
var k;
for (k = 0; k <= n; k++) {
var sx = Math.floor(px - dirSign * k);
if (sx < 0 || sx >= cols) continue;
if (py < 0 || py >= rows) continue;
var lm = base * (1 - k * 0.17);
if (lm < 4) continue;
veilCell(f, sx, py, k === 0 ? gl : (n >= 3 ? G_DASH : G_TICK), hue, lm, d, dAlpha);
}
}
if (W_HAZE < 1.55 || CC.reducedMotion) return;
var veil = clamp((W_HAZE - 1.55) / 0.75, 0, 1) * settle;
var vl = (10 + 40 * lift + 168 * (1 - dAlpha) / 0.58) * veil;
if (vl < 5) return;
var top = Math.floor(V.horizon - V.rows * 0.10);
if (top < 0) top = 0;
var drift = tt * wspd * 0.055, vy, vx2;
for (vy = top; vy < rows; vy++) {
var band = (vy - top) / (rows - top);
var dv = 0.10 + 0.34 * band * veil;
for (vx2 = 0; vx2 < cols; vx2++) {
var sp2 = ((vx2 + 0.5) * 2 / cols - 1) * V.hp;
var hv = vnoise((V.yaw + sp2) * 9.0 + (vy - top) * 0.37 + drift, BASE + 0x62);
if (hv > dv) continue;
veilCell(f, vx2, vy, band > 0.55 ? G_DOT : G_TICK, P.white,
vl * (0.6 + 0.7 * band), 44, dAlpha);
}
}
}
function mk(name, layer, fn) {
return {
name: name, layer: layer, world: 'west',
init: function (city) { boot(city); },
draw: function (f, cam, t) {
if (!CITY) return;
view(f, cam, t === undefined ? (cam.t || 0) : t);
fn(f);
}
};
}
CC.ELEMENTS.push(mk('west-mesas', 10, drawMesas));
CC.ELEMENTS.push(mk('west-desert-plants', 16, drawPlants));
CC.ELEMENTS.push({
name: 'west-dust',
layer: 22,
world: 'west',
init: function (city, rng) { boot(city); initDust(rng); },
draw: function (f, cam, t) {
if (!CITY) return;
view(f, cam, t === undefined ? (cam.t || 0) : t);
drawDust(f);
}
});
})(CC);
};
W["elements/west_range.js"] = function (CC) {
'use strict';
/* src/elements/west_range.js */
(function (CC) {
var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ;
var project = PR.project, emit = PR.emit, column = PR.column, litFace = PR.litFace;
var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp;
var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_DOT = CC.g('.'),
G_COMMA = CC.g(','), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_STAR = CC.g('*'),
G_o = CC.g('o');
var CITY = null, BASE = 0, Surf = null, WEST = null;
function boot(city) {
CITY = (city && city.aveX && city.world === 'west') ? city : null;
BASE = CITY ? ((Math.imul(CITY.seed | 0, 26417) >>> 7) & 0x3fffff) : 0;
}
var W_WIND = 1, W_RAIN = 0, W_DUST = 0.3;
function view(f, cam, t) {
PR.view(f, cam, t);
if (!Surf) Surf = CC.Surf;
if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null;
W_WIND = CC.Weather ? CC.Weather.rel('wind') : 1;
W_RAIN = CC.Weather ? CC.Weather.P.rain : 0;
W_DUST = CC.Weather ? CC.Weather.P.haze : 0.3;
}
function wx(axis, along, cross) { return axis ? along : cross; }
function wz(axis, along, cross) { return axis ? cross : along; }
function nearIdx(axis) {
return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE));
}
var POLE_PITCH = 27.0, POLE_H = 7.4;
function drawTelegraph(f, axis, idx) {
var c, hw;
if (axis) { c = CITY.crossZ(idx); hw = CITY.crossW(idx); }
else { c = CITY.aveX(idx); hw = CITY.aveW(idx); }
var side = hash2(idx, axis, BASE + 0x11) < 0.5 ? -1 : 1;
var cross = c + 0.5 + side * (hw + 0.75);
var here = axis ? V.ox : V.oz;
var lo = Math.floor((here - 90) / POLE_PITCH), hi = Math.floor((here + 90) / POLE_PITCH);
if (hi - lo > 12) hi = lo + 12;
var sunA = litFace(axis ? 1 : 0, axis ? 0 : 1);
var sunB = litFace(axis ? -1 : 0, axis ? 0 : -1);
var sun = sunA > sunB ? sunA : sunB;
var dF = (CC.SurfWest && CC.SurfWest.dayFill !== undefined) ? CC.SurfWest.dayFill : 0;
var day = hash2(idx, axis, BASE + 0x14) < dF;
var pcol = day ? (sun > 0.6 ? P.timber : P.stone) : (sun > 0.6 ? P.amber : P.slate);
var plum = day ? (sun > 0.6 ? 120 : 86) : (sun > 0.6 ? 96 : 26);
for (var k = lo; k <= hi; k++) {
var a0 = k * POLE_PITCH + hash2(k, idx, BASE + 0x12) * 3.0;
var a1 = (k + 1) * POLE_PITCH + hash2(k + 1, idx, BASE + 0x12) * 3.0;
var hgt = POLE_H + hash2(k, idx, BASE + 0x13) * 1.2;
if (CITY.height(wx(axis, a0, cross), wz(axis, a0, cross)) > 0.5) continue;
column(f, wx(axis, a0, cross), wz(axis, a0, cross), 0, hgt, G_PIPE, pcol, plum, 0);
var ay = hgt - 0.55;
var i;
if (day && PJ.d < 26) {
for (i = -1; i <= 1; i += 2) {
if (project(wx(axis, a0, cross + i * 0.9), ay + 0.22, wz(axis, a0, cross + i * 0.9)))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_o,
sun > 0.6 ? P.white : P.stone, sun > 0.6 ? 176 : 108, PJ.d);
}
}
for (i = -1; i <= 1; i++) {
if (!i) continue;
var ax2 = wx(axis, a0, cross + i * 0.9), az2 = wz(axis, a0, cross + i * 0.9);
if (project(ax2, ay, az2))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, pcol, plum, PJ.d);
}
var span = a1 - a0, sag = 0.9;
var lx = -1, ly = 0, ld = 0;
for (i = 0; i <= 16; i++) {
var u = i / 16, a = a0 + span * u;
var yy = hgt - 0.2 - sag * 4 * u * (1 - u);
if (!project(wx(axis, a, cross), yy, wz(axis, a, cross))) { lx = -1; continue; }
var px = Math.floor(PJ.x), py = Math.floor(PJ.y), pd = PJ.d;
if (lx >= 0 && (pd > ld * 2 || ld > pd * 2)) lx = -1;
if (lx >= 0) {
var dx = px - lx, dy = py - ly;
var st = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy);
if (st > V.cols * 2) st = 0;
for (var q = 1; q < st; q++) {
var tq = q / st;
emit(f, lx + Math.round(dx * tq), ly + Math.round(dy * tq), G_DOT,
day ? P.timber : P.slate, day ? 96 : (sun > 0.6 ? 40 : 18),
ld + (pd - ld) * tq);
}
}
emit(f, px, py, G_DOT, day ? P.timber : P.slate,
day ? 96 : (sun > 0.6 ? 40 : 18), pd);
lx = px; ly = py; ld = pd;
}
}
}
var SAGE_LAT = 3.1, CACTUS_LAT = 17.0, BRUSH_R = 52;
function drawBrush(f) {
var lo0 = Math.floor((V.ox - BRUSH_R) / SAGE_LAT), hi0 = Math.floor((V.ox + BRUSH_R) / SAGE_LAT);
var lo1 = Math.floor((V.oz - BRUSH_R) / SAGE_LAT), hi1 = Math.floor((V.oz + BRUSH_R) / SAGE_LAT);
var i, j;
for (j = lo1; j <= hi1; j++) {
for (i = lo0; i <= hi0; i++) {
var h = hash2(i, j, BASE + 0x21);
if (h > 0.16) continue;
var px = i * SAGE_LAT + hash2(i, j, BASE + 0x22) * SAGE_LAT;
var pz = j * SAGE_LAT + hash2(i, j, BASE + 0x23) * SAGE_LAT;
if (CITY.height(px, pz) > 0.1) continue;
if (CITY.height(px + 2.4, pz) <= 0.1 && CITY.height(px - 2.4, pz) <= 0.1 &&
CITY.height(px, pz + 2.4) <= 0.1 && CITY.height(px, pz - 2.4) <= 0.1 &&
hash2(i, j, BASE + 0x24) > 0.45) continue;
var rx = px - V.ox, rz = pz - V.oz;
var w = rx * V.fwx + rz * V.fwz;
if (w < 0.9 || w > 60) continue;
var hh = 0.30 + h * 2.6;
if (!project(px, hh, pz)) continue;
var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d;
if (x < -1 || x >= V.cols + 1) continue;
var lum = 30 + h * 260;
emit(f, x, y, h < 0.06 ? G_STAR : G_TICK, P.spring, lum, d);
if (d < 16) {
emit(f, x - 1, y, G_QUOTE, P.spring, lum * 0.6, d);
emit(f, x + 1, y, G_TICK, P.spring, lum * 0.6, d);
if (project(px, hh * 0.4, pz))
emit(f, x, Math.floor(PJ.y), G_COMMA, P.slate, 22, PJ.d);
}
}
}
var c0 = Math.floor((V.ox - 70) / CACTUS_LAT), c1 = Math.floor((V.ox + 70) / CACTUS_LAT);
var c2 = Math.floor((V.oz - 70) / CACTUS_LAT), c3 = Math.floor((V.oz + 70) / CACTUS_LAT);
for (j = c2; j <= c3; j++) {
for (i = c0; i <= c1; i++) {
var ch2 = hash2(i, j, BASE + 0x31);
if (ch2 > 0.34) continue;
var qx = i * CACTUS_LAT + hash2(i, j, BASE + 0x32) * CACTUS_LAT;
var qz = j * CACTUS_LAT + hash2(i, j, BASE + 0x33) * CACTUS_LAT;
if (CITY.height(qx, qz) > 0.1) continue;
if (CITY.height(qx + 3, qz) > 0.1 || CITY.height(qx - 3, qz) > 0.1) continue;
var rx2 = qx - V.ox, rz2 = qz - V.oz;
var w2 = rx2 * V.fwx + rz2 * V.fwz;
if (w2 < 1.2 || w2 > 78) continue;
var th = 2.6 + ch2 * 7.0;
var sunX = (WEST && WEST.SUN_X < 0) ? -1 : 1;
column(f, qx, qz, 0, th, G_PIPE, P.spring, 98, 0);
if (w2 < 18) column(f, qx - sunX * 0.30, qz, 0, th * 0.96, G_PIPE, P.slate, 26, 0);
var col = P.spring, lum = 98;
var ah = th * (0.42 + ch2 * 0.4);
column(f, qx - 0.55, qz, ah, ah + th * 0.34, G_PIPE, col, lum, 0);
if (project(qx - 0.28, ah, qz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, col, lum, PJ.d);
if (ch2 < 0.20) {
column(f, qx + 0.55, qz, ah * 0.8, ah * 0.8 + th * 0.28, G_PIPE, col, lum, 0);
if (project(qx + 0.28, ah * 0.8, qz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, col, lum, PJ.d);
}
}
}
}
var NWEED = 3;
var wdX, wdZ, wdVX, wdVZ, wdPh, wdR, wdLife;
function respawn(i, rnd) {
var a = rnd * 6.2831853;
wdX[i] = V.ox + Math.cos(a) * 46;
wdZ[i] = V.oz + Math.sin(a) * 46;
var b = a + 3.14159 + (rnd - 0.5) * 1.5;
var sp = 2.4 + rnd * 3.0;
wdVX[i] = Math.cos(b) * sp; wdVZ[i] = Math.sin(b) * sp;
wdPh[i] = rnd * 6.28;
wdR[i] = 0.30 + rnd * 0.34;
wdLife[i] = 26 + rnd * 30;
}
CC.ELEMENTS.push({
name: 'west-tumbleweed',
layer: 23,
world: 'west',
init: function (city, rng) {
boot(city);
wdX = new Float64Array(NWEED); wdZ = new Float64Array(NWEED);
wdVX = new Float64Array(NWEED); wdVZ = new Float64Array(NWEED);
wdPh = new Float64Array(NWEED); wdR = new Float64Array(NWEED);
wdLife = new Float64Array(NWEED);
V.ox = city && city.startX !== undefined ? city.startX : 0;
V.oz = city && city.startZ !== undefined ? city.startZ : 0;
for (var i = 0; i < NWEED; i++) respawn(i, rng());
},
update: function (dt, t, cam) {
if (!CITY) return;
V.ox = cam.x; V.oz = cam.z;
var gust = 0.55 + 0.9 * W_WIND;
var damp = CC.reducedMotion ? 0.3 : 1;
for (var i = 0; i < NWEED; i++) {
wdLife[i] -= dt;
var nx = wdX[i] + wdVX[i] * dt * gust * damp;
var nz = wdZ[i] + wdVZ[i] * dt * gust * damp;
if (CITY.height(nx, wdZ[i]) > 0.1) { wdVX[i] = -wdVX[i] * 0.7; nx = wdX[i]; }
if (CITY.height(wdX[i], nz) > 0.1) { wdVZ[i] = -wdVZ[i] * 0.7; nz = wdZ[i]; }
wdX[i] = nx; wdZ[i] = nz;
wdPh[i] += dt * (2.0 + 1.6 * W_WIND) * damp;
var dx = nx - cam.x, dz = nz - cam.z;
if (wdLife[i] < 0 || dx * dx + dz * dz > 4900)
respawn(i, hash2(i, (t * 3) | 0, BASE + 0x41));
}
},
draw: function (f, cam, t) {
if (!CITY) return;
view(f, cam, t === undefined ? (cam.t || 0) : t);
if (W_RAIN > 0.5) return;
for (var i = 0; i < NWEED; i++) {
var r = wdR[i];
var bounce = Math.abs(Math.sin(wdPh[i] * 0.5)) * r * 1.5;
if (!project(wdX[i], r + bounce, wdZ[i])) continue;
var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d;
var rw = r * V.colK / (d * 0.85), rh = r * V.scale / (d * 0.85);
var lum = 74 + 24 * Math.abs(Math.sin(wdPh[i]));
if (rw < 1.1) { emit(f, x, y, G_STAR, P.slate, lum, d); continue; }
var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy;
if (iw > 9) iw = 9; if (ih > 9) ih = 9;
for (dy = -ih; dy <= ih; dy++) {
for (dx = -iw; dx <= iw; dx++) {
var u = dx / rw, v = dy / rh, r2 = u * u + v * v;
if (r2 > 1.05) continue;
var ca = Math.cos(wdPh[i]), sa = Math.sin(wdPh[i]);
var ru = u * ca - v * sa, rv = u * sa + v * ca;
if (hash2(Math.round(ru * 5), Math.round(rv * 5), BASE + 0x42) > 0.42) continue;
emit(f, x + dx, y + dy, r2 > 0.6 ? G_TICK : G_STAR, P.slate, lum * (1 - 0.3 * r2), d);
}
}
}
}
});
function mk(name, layer, fn) {
return {
name: name, layer: layer, world: 'west',
init: function (city) { boot(city); },
draw: function (f, cam, t) {
if (!CITY) return;
view(f, cam, t === undefined ? (cam.t || 0) : t);
fn(f);
}
};
}
CC.ELEMENTS.push(mk('west-brush', 15, drawBrush));
CC.ELEMENTS.push(mk('west-telegraph', 19, function (f) {
var i;
for (i = -1; i <= 1; i++) drawTelegraph(f, 0, nearIdx(0) + i);
for (i = -1; i <= 1; i++) drawTelegraph(f, 1, nearIdx(1) + i);
}));
})(CC);
};
W["elements/west_sky.js"] = function (CC) {
'use strict';
/* src/elements/west_sky.js */
(function (CC) {
var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2, vnoise = CC.vnoise, clamp = CC.clamp;
var G_DOT = g('.'), G_TICK = g('`'), G_QUOTE = g("'"), G_DASH = g('-'), G_EQ = g('='),
G_o = g('o'), G_8 = g('8'), G_TILDE = g('~'), G_PLUS = g('+'), G_DQ = g('"'),
G_HASH = g('#'), G_COLON = g(':'), G_UNDER = g('_'), G_PCT = g('%');
var D_SUN = 1.02e5, D_CLOUD = 9.6e4, D_BIRD = 8.0e4;
var D_CLOUD_DAY = 9.4e4;
function dayFill() {
if (!CC.SurfWest) return 0;
return CC.SurfWest.dayFill;
}
var INK = [G_TICK, G_DOT, G_UNDER, G_DASH, G_COLON, G_TILDE, G_DQ, G_PLUS, G_EQ, G_HASH, G_PCT];
function ink(t) { var i = (t * 11) | 0; return INK[i < 0 ? 0 : (i > 10 ? 10 : i)]; }
var W_CLOUD = 0.1, W_HAZE = 0.3, W_WIND = 0.2, W_RAIN = 0;
function bindWeather() {
var p = CC.Weather ? CC.Weather.P : null;
W_CLOUD = p ? p.cloud : 0.1;
W_HAZE = p ? p.haze : 0.3;
W_WIND = p ? p.wind : 0.2;
W_RAIN = p ? p.rain : 0;
}
var CB = { fwx: 0, fwz: 1, rgx: 1, rgz: 0, half: 0.71, cols: 0, rows: 0,
horizon: 0, eyeY: 1.7, scale: 1, colsPerTan: 1 };
function setup(frame, cam) {
bindWeather();
var yaw = cam.yaw || 0, fov = cam.fov || 1.25;
CB.fwx = Math.sin(yaw); CB.fwz = Math.cos(yaw);
CB.rgx = Math.cos(yaw); CB.rgz = -Math.sin(yaw);
CB.half = Math.tan(fov * 0.5);
CB.cols = frame.cols; CB.rows = frame.rows;
CB.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56;
CB.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7;
CB.colsPerTan = frame.cols / (2 * CB.half);
CB.scale = cam.scaleY !== undefined ? cam.scaleY : CB.colsPerTan * (cam.cellAspect || 0.5625);
}
var VP = { ok: 0, x: 0, y: 0, w: 0 };
function proj(dx, dy, dz) {
var w = dx * CB.fwx + dz * CB.fwz;
if (w <= 0.02) { VP.ok = 0; return VP; }
var s = dx * CB.rgx + dz * CB.rgz;
VP.ok = 1; VP.w = w;
VP.x = (s / w) * CB.colsPerTan + CB.cols * 0.5;
VP.y = CB.horizon - (dy / w) * CB.scale;
return VP;
}
function plot(frame, x, y, ch, col, lum, d) {
x = Math.round(x); y = Math.round(y);
if (x < 0 || y < 0 || x >= CB.cols || y >= CB.rows) return;
if (lum < 3) return;
put(frame, x, y, ch, col, lum > 255 ? 255 : lum | 0, d, 3);
}
function sunAz() { return CC.SurfWest ? CC.SurfWest.SUN_AZ : -0.5; }
var SUN_ALT = 0.16, SUN_R = 0.030;
function drawAlt() {
var live = CC.SurfWest ? CC.SurfWest.SUN_ALT : SUN_ALT;
return SUN_ALT + (live - SUN_ALT) * dayFill();
}
CC.ELEMENTS.push({
name: 'west-sun',
layer: 5,
world: 'west',
draw: function (frame, cam) {
setup(frame, cam);
var al = drawAlt(), az = sunAz(), ca = Math.cos(al);
var p = proj(Math.sin(az) * ca, Math.sin(al), Math.cos(az) * ca);
if (!p.ok) return;
var cx = p.x, cy = p.y;
var rw = SUN_R * CB.colsPerTan / p.w, rh = SUN_R * CB.scale / p.w;
if (rw < 0.6) return;
var disc = 1.20 - 1.25 * W_CLOUD; if (disc > 1) disc = 1; if (disc < 0) disc = 0;
var halo = clamp(0.35 + 0.85 * W_HAZE + 0.5 * W_CLOUD, 0, 1.35) * (0.35 + 0.65 * disc);
var hr = 4.4, hiw = Math.ceil(rw * hr), hih = Math.ceil(rh * hr), hx, hy, hu, hv, h2;
if (hiw > CB.cols) hiw = CB.cols;
if (hih > CB.rows) hih = CB.rows;
for (hy = -hih; hy <= hih; hy++) {
for (hx = -hiw; hx <= hiw; hx++) {
hu = hx / rw; hv = hy / rh; h2 = hu * hu + hv * hv;
if (h2 < 0.98 || h2 > hr * hr) continue;
var fall = 1 - (Math.sqrt(h2) - 1) / (hr - 1);
fall = fall * fall;
if (hash2(hx, hy, 0x5A17) > 0.30 + 0.62 * fall) continue;
plot(frame, cx + hx, cy + hy,
fall > 0.6 ? G_EQ : (fall > 0.3 ? G_DASH : G_TICK),
fall > 0.55 ? P.amber : P.ember,
(166 * fall + 20) * halo, D_SUN);
}
}
if (disc <= 0.03) return;
var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy;
for (dy = -ih; dy <= ih; dy++) {
for (dx = -iw; dx <= iw; dx++) {
var u = dx / rw, v = dy / rh, r2 = u * u + v * v;
if (r2 > 1.02) continue;
var bandK = hash2(0, Math.floor(dy * 1.3), 0x77) < 0.22 ? 0.42 : 1;
plot(frame, cx + dx, cy + dy, r2 > 0.78 ? G_o : G_8,
r2 > 0.86 ? P.amber : P.pure, (236 - 40 * r2) * disc * bandK, D_SUN);
}
}
}
});
var NBAR = 7;
CC.ELEMENTS.push({
name: 'west-cloudbars',
layer: 6,
world: 'west',
draw: function (frame, cam, t) {
setup(frame, cam);
if (W_CLOUD < 0.03) return;
var dF = dayFill();
var tt = CC.reducedMotion ? 0 : t * (0.004 + 0.016 * W_WIND);
var az0 = sunAz();
var x, y, y0 = 0, y1 = Math.floor(CB.horizon);
if (y1 > CB.rows) y1 = CB.rows;
for (x = 0; x < CB.cols; x++) {
var sp = (2 * (x + 0.5) / CB.cols - 1) * CB.half;
var bear = (cam.yaw || 0) + Math.atan(sp);
var da = bear - az0;
da = Math.atan2(Math.sin(da), Math.cos(da));
var west = 1 - Math.abs(da) / Math.PI;
for (y = y0; y < y1; y++) {
var el = (CB.horizon - y - 0.5) / CB.scale;
if (el < 0.02 || el > 0.62) continue;
var lad = Math.log(el * 14 + 1) * NBAR + vnoise(bear * 1.7 + tt * 3, 0x81) * 1.4;
var fb = lad - Math.floor(lad);
var body = vnoise(Math.floor(lad) * 3.1 + bear * 2.0 + tt * 3, 0x9C1);
if (body > 0.22 + 0.68 * W_CLOUD) continue;
var d = hash2(Math.floor(bear * 220), Math.floor(el * 900), 0x33B);
if (fb > 0.66) continue;
var isDay = hash2(Math.floor(bear * 111), Math.floor(el * 640), 0x6B2) < dF;
if (isDay) {
if (d > 0.86) continue;
if (fb > 0.50) {
plot(frame, x, y, ink(0.30 + 0.26 * d), d > 0.55 ? P.stone : P.indigo,
(54 + 46 * d) * (0.5 + 0.5 * W_CLOUD), D_CLOUD_DAY);
} else {
var top = 1 - fb / 0.50;
plot(frame, x, y, ink(0.52 + 0.34 * top + 0.14 * (d - 0.5)),
top > 0.45 ? P.white : P.sand,
(104 + 72 * top) * (0.76 + 0.30 * d), D_CLOUD_DAY);
}
continue;
}
if (fb > 0.50) {
if (d > 0.72) continue;
plot(frame, x, y, G_DASH, west > 0.68 ? P.amber : P.ember,
(86 + 132 * west) * (0.7 + 0.5 * d), D_CLOUD);
} else {
if (d > 0.34 - 0.18 * fb) continue;
plot(frame, x, y, fb > 0.28 ? G_TICK : G_DOT, P.slate,
(26 + 30 * (1 - fb)) * (0.6 + 0.6 * d), D_CLOUD);
}
}
}
}
});
CC.ELEMENTS.push({
name: 'west-daysky',
layer: 7,
world: 'west',
draw: function (frame, cam) {
var dF = dayFill();
if (dF <= 0.002) return;
setup(frame, cam);
var cols = frame.cols, col = frame.col, lum = frame.lum, dist = frame.dist, kind = frame.kind;
var maxRow = Math.floor(CB.horizon); if (maxRow > CB.rows - 1) maxRow = CB.rows - 1;
var x, y, i, h;
for (y = 0; y <= maxRow; y++) {
for (x = 0; x < cols; x++) {
i = y * cols + x;
if (kind[i] !== 3 || col[i] !== P.shadow || dist[i] < 9.0e4) continue;
h = hash2((x + (cam.yaw || 0) * CB.colsPerTan) | 0, y, 0x4D77);
if (h > dF) continue;
var up = 1 - y / (maxRow + 1);
plot(frame, x, y, ink(0.30 + 0.26 * up + 0.20 * h),
h < 0.60 ? P.white : (up > 0.45 ? P.ice : P.stone),
(96 + 74 * up) * (0.80 + 0.34 * h), dist[i] - 1);
}
}
}
});
var NBIRD = 3;
var bSeed = 0;
CC.ELEMENTS.push({
name: 'west-birds',
layer: 9,
world: 'west',
init: function (city, rng) {
bSeed = (rng() * 4294967296) | 0;
},
draw: function (frame, cam, t) {
setup(frame, cam);
if (W_RAIN > 0.35) return;
var tt = CC.reducedMotion ? 12.0 : t;
for (var i = 0; i < NBIRD; i++) {
var ph = tt * (0.055 + 0.014 * i) + i * 2.3 + (bSeed & 255) * 0.01;
var az = -1.1 + (bSeed >> 8 & 255) * 0.012 + Math.sin(ph) * 0.30;
var alt = 0.30 + 0.09 * i + Math.cos(ph * 0.7) * 0.05;
var ca = Math.cos(alt);
var p = proj(Math.sin(az) * ca, Math.sin(alt), Math.cos(az) * ca);
if (!p.ok) continue;
var asp = Math.abs(Math.cos(ph));
var x = p.x, y = p.y;
var dF = dayFill();
var bc = dF > 0.5 ? P.timber : P.slate, bl = 62 - 22 * dF;
plot(frame, x, y, dF > 0.5 ? G_TILDE : G_DOT, bc, bl, D_BIRD);
if (asp > 0.45) {
plot(frame, x - 1, y - (asp > 0.8 ? 1 : 0), G_TICK, bc, bl - 8, D_BIRD);
plot(frame, x + 1, y - (asp > 0.8 ? 1 : 0), G_QUOTE, bc, bl - 8, D_BIRD);
}
}
}
});
})(CC);
};
W["elements/west_stock.js"] = function (CC) {
'use strict';
/* src/elements/west_stock.js */
(function (CC) {
var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ;
var project = PR.project, emit = PR.emit, column = PR.column, litFace = PR.litFace;
var P = CC.P, hash2 = CC.hash2, put = CC.put, clamp = CC.clamp;
var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_DOT = CC.g('.'),
G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_UNDER = CC.g('_'), G_o = CC.g('o'),
G_HASH = CC.g('#'), G_SLASH = CC.g('/'), G_BSLASH = CC.g('\\'), G_CARET = CC.g('^'),
G_COMMA = CC.g(',');
var CITY = null, BASE = 0, RAIL_BASE = 0, Surf = null, WEST = null;
function boot(city) {
CITY = (city && city.aveX && city.world === 'west') ? city : null;
RAIL_BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 8) & 0x3fffff) : 0;
BASE = CITY ? ((Math.imul(CITY.seed | 0, 19477) >>> 6) & 0x3fffff) : 0;
}
var SUN = 0.64, LAMP = 1.00, WARM = 0.90;
function view(f, cam, t) {
PR.view(f, cam, t);
var Dm = CC.Daylight;
SUN = Dm ? Dm.P.sun : 0.64;
LAMP = Dm ? Dm.P.lamp : 1.00;
WARM = Dm ? Dm.P.warm : 0.90;
if (!Surf) Surf = CC.Surf;
if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null;
}
var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 };
function streetSpan(axis, idx) {
var c, h;
if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); }
else { c = CITY.aveX(idx); h = CITY.aveW(idx); }
SPAN.c0 = c - h; SPAN.c1 = c + h + 1;
SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0;
}
function wx(axis, along, cross) { return axis ? along : cross; }
function wz(axis, along, cross) { return axis ? cross : along; }
function paveOf(spanW) {
var p = CC.PAVE, avail = spanW * 0.5 - 1.7;
return avail < p ? avail : p;
}
function frontage(axis, a0, len, cross, dirIn) {
var i, a, c = cross - dirIn * 0.7;
for (i = 0; i <= 3; i++) {
a = a0 + len * (i / 3);
if (CITY.height(wx(axis, a, c), wz(axis, a, c)) < 2.5) return 0;
}
return 1;
}
function objVisible(axis, along, cross, near) {
var px = wx(axis, along, cross), pz = wz(axis, along, cross);
var rx = px - V.ox, rz = pz - V.oz;
var w = rx * V.fwx + rz * V.fwz;
if (w < near || w > V.far) return 0;
var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14;
if (s < -lim || s > lim) return 0;
return w;
}
function nearIdx(axis) {
return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE));
}
function beam(f, axis, a0, a1, cross, y, ch, col, lum) {
var n = 20, i, a, lx = -1, ly = 0, ld = 0;
for (i = 0; i <= n; i++) {
a = a0 + (a1 - a0) * (i / n);
if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) { lx = -1; continue; }
var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d;
if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1;
if (lx >= 0) {
var dx = x - lx, dy = r - ly;
var steps = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy);
if (steps > 4 * V.cols) steps = 0;
for (var q = 1; q < steps; q++) {
var t2 = q / steps;
emit(f, lx + Math.round(dx * t2), ly + Math.round(dy * t2), ch, col, lum,
ld + (d - ld) * t2);
}
}
emit(f, x, r, ch, col, lum, d);
lx = x; ly = r; ld = d;
}
}
var B = {
x: 0, z: 0,
ux: 0, uz: 1,
len: 2.0, wy: 1.6,
head: 0,
tail: 0,
lift: 0,
fill: 0, fillLum: 0,
rim: 0, rimLum: 0,
legW: 0
};
function topF(u, head) {
if (u <= 0.72) {
if (u < 0.14) return 0.88 + (0.92 - 0.88) * (u / 0.14);
if (u < 0.45) return 0.92 + (0.86 - 0.92) * ((u - 0.14) / 0.31);
return 0.86 + (0.98 - 0.86) * ((u - 0.45) / 0.27);
}
var q, up, dn;
if (u <= 1.06) {
q = (u - 0.72) / 0.34;
up = 0.98 + 0.34 * q;
dn = 0.98 - 0.30 * q;
} else {
q = (u - 1.06) / 0.20; if (q > 1) q = 1;
up = 1.32 - 0.12 * q;
dn = 0.68 - 0.08 * q;
}
return up + (dn - up) * head;
}
function botF(u, head) {
if (u <= 0.72) {
if (u < 0.25) return 0.60 + (0.55 - 0.60) * (u / 0.25);
return 0.55 + (0.62 - 0.55) * ((u - 0.25) / 0.47);
}
var d;
if (u <= 1.06) d = 0.36 - 0.18 * ((u - 0.72) / 0.34);
else { d = (u - 1.06) / 0.20; if (d > 1) d = 1; d = 0.18 + 0.06 * d; }
return topF(u, head) - d;
}
function wideF(u, len) {
var k;
if (u < 0.06) k = 0.20 + 0.08 * (u / 0.06);
else if (u <= 0.70) k = 0.28;
else k = 0.28 - 0.17 * ((u - 0.70) / 0.54);
if (k < 0.11) k = 0.11;
return k * len;
}
var CB_N = 1024;
var CB_TOP = new Int16Array(CB_N), CB_BOT = new Int16Array(CB_N),
CB_D = new Float32Array(CB_N), CB_END = new Uint8Array(CB_N),
CB_BAR = new Uint8Array(CB_N), CB_G = new Int32Array(CB_N), CB_GEN = 0;
function beast(f) {
var lx = B.ux, lz = B.uz;
var px = lz, pz = -lx;
if (!project(B.x - lx * 0.5 * B.len, B.wy * 0.85, B.z - lz * 0.5 * B.len)) return;
var sx0 = PJ.x;
if (!project(B.x + lx * 0.7 * B.len, B.wy * 0.85, B.z + lz * 0.7 * B.len)) return;
var span = PJ.x - sx0; if (span < 0) span = -span;
var n = (span + 4) | 0; if (n < 8) n = 8; if (n > 140) n = 140;
var rumpL = litFace(-lx, -lz), chestL = litFace(lx, lz);
var endLit = rumpL > chestL ? 0 : 1;
var endStr = (rumpL > chestL ? rumpL : chestL) * SUN;
CB_GEN++;
var lo = 1e9, hi = -1e9;
var i, u, y0, y1, wxp, wzp, cx, rt, rb, dd, hw, r, q;
for (i = 0; i <= n; i++) {
u = -0.06 + 1.32 * (i / n);
y0 = topF(u, B.head) * B.wy + B.lift;
y1 = botF(u, B.head) * B.wy + B.lift;
wxp = B.x + lx * (u - 0.5) * B.len; wzp = B.z + lz * (u - 0.5) * B.len;
if (!project(wxp, y0, wzp)) continue;
cx = PJ.x; rt = Math.floor(PJ.y); dd = PJ.d;
if (!project(wxp, y1, wzp)) continue;
rb = Math.floor(PJ.y);
if (rb < rt) { r = rt; rt = rb; rb = r; }
hw = wideF(u, B.len) * 0.5 * V.colK / dd;
if (hw > 20) hw = 20;
var q0 = Math.round(cx - hw), q1 = Math.round(cx + hw);
if (q0 < 0) q0 = 0;
if (q1 > V.cols - 1) q1 = V.cols - 1;
if (q1 >= CB_N) q1 = CB_N - 1;
var isEnd = endStr > 0.30 &&
((endLit === 0 && u < 0.11) || (endLit === 1 && u > 1.02));
var isBar = u > 0.02 && u < 0.74;
for (q = q0; q <= q1; q++) {
if (CB_G[q] !== CB_GEN) {
CB_G[q] = CB_GEN; CB_TOP[q] = rt; CB_BOT[q] = rb; CB_D[q] = dd;
CB_END[q] = 0; CB_BAR[q] = 0;
} else {
if (rt < CB_TOP[q]) CB_TOP[q] = rt;
if (rb > CB_BOT[q]) CB_BOT[q] = rb;
if (dd < CB_D[q]) CB_D[q] = dd;
}
if (isEnd) CB_END[q] = 1;
if (isBar) CB_BAR[q] = 1;
if (q < lo) lo = q;
if (q > hi) hi = q;
}
}
if (hi < lo) return;
var el = 24 + 82 * endStr, elCol = WARM > 0.45 ? P.amber : P.white;
var headEnd = (lx * V.rgx + lz * V.rgz) > 0 ? hi : lo;
for (q = lo; q <= hi; q++) {
if (CB_G[q] !== CB_GEN) continue;
rt = CB_TOP[q]; rb = CB_BOT[q]; dd = CB_D[q];
for (r = rt; r <= rb; r++) emit(f, q, r, G_HASH, B.fill, B.fillLum, dd);
if (CB_END[q] && el >= 5) {
var eb = rt + (((rb - rt) * 0.66) | 0);
for (r = rt + 1; r <= eb; r++)
emit(f, q, r, G_o, elCol, el * (r === rt + 1 ? 1 : 0.60), dd * 0.988);
}
if (B.rimLum >= 4) {
var gl = G_DASH, drop = 0;
if (q > lo && CB_G[q - 1] === CB_GEN) drop = rt - CB_TOP[q - 1];
if (drop > 1) gl = G_BSLASH;
else if (drop < -1) gl = G_SLASH;
if (q === headEnd) gl = G_o;
emit(f, q, rt, gl, B.rim, B.rimLum, dd * 0.988);
if (CB_BAR[q] && B.rimLum >= 12)
emit(f, q, rb, G_UNDER, B.rim, B.rimLum * 0.22, dd * 0.988);
}
}
var lat, uL, k2;
for (k2 = 0; k2 < 4; k2++) {
uL = (k2 < 2) ? 0.66 : 0.10;
lat = (k2 & 1) ? 0.16 : -0.16;
column(f, B.x + lx * (uL - 0.5) * B.len + px * lat * B.len * 0.5,
B.z + lz * (uL - 0.5) * B.len + pz * lat * B.len * 0.5,
0, botF(uL, B.head) * B.wy + B.lift + 0.04,
G_PIPE, B.fill, B.fillLum, B.legW);
}
var tx = B.x - lx * 0.56 * B.len, tz = B.z - lz * 0.56 * B.len;
if (B.tail > 0.5)
column(f, tx, tz, topF(0.02, B.head) * B.wy + B.lift,
(topF(0.02, B.head) + 0.30) * B.wy + B.lift, G_QUOTE, B.rim, B.rimLum * 0.7, 0);
else
column(f, tx, tz, 0.30 * B.wy + B.lift, topF(0.02, B.head) * B.wy + B.lift,
G_PIPE, B.fill, B.fillLum, 0);
}
function hideLight() {
B.rimLum = 30 + 128 * SUN + (1 - SUN) * (72 * LAMP);
B.rim = WARM > 0.45 ? P.amber : P.white;
B.fill = P.ember;
B.fillLum = SUN > 0.33 ? (12 + 34 * (SUN - 0.33) / 0.67) : 0;
}
var RAIL_PITCH = 15.0;
function drawHitched(f, axis, idx) {
streetSpan(axis, idx);
var pave = paveOf(SPAN.w);
var lo = Math.floor(((axis ? V.ox : V.oz) - 48) / RAIL_PITCH);
var hi = Math.floor(((axis ? V.ox : V.oz) + 48) / RAIL_PITCH);
for (var s = 0; s < 2; s++) {
var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1;
var edge = face + dirIn * (pave + 0.15);
var hx = axis ? 0 : -dirIn, hz = axis ? -dirIn : 0;
for (var k = lo; k <= hi; k++) {
var h0 = hash2(k, idx * 2 + s, RAIL_BASE + 0x61);
if (h0 > 0.62) continue;
var along = k * RAIL_PITCH + h0 * 9;
if (!objVisible(axis, along, edge, 0.8)) continue;
if (!frontage(axis, along, 5.2, face, dirIn)) continue;
var kind = hash2(k, idx * 2 + s, RAIL_BASE + 0x62);
if (kind >= 0.52) continue;
var L = 3.6 + kind * 3.2;
var occ = hash2(k, idx * 2 + s, BASE + 0x11);
var nH = occ < 0.70 ? 1 : (occ < 0.94 ? 2 : 3);
for (var j = 0; j < nH; j++) {
var a = along + 0.72 + j * 1.45;
if (a > along + L - 0.5) break;
var hA = hash2(k * 5 + j, idx * 2 + s, BASE + 0x12);
var hB = hash2(k * 5 + j, idx * 2 + s, BASE + 0x13);
var cross = edge + dirIn * 1.50;
var w = objVisible(axis, a, cross, 0.9);
if (!w) continue;
B.x = wx(axis, a, cross); B.z = wz(axis, a, cross);
B.ux = hx; B.uz = hz;
B.len = 1.92 + hA * 0.22;
B.wy = 1.52 + hB * 0.16;
B.head = hA < 0.34 ? 1 : 0;
B.tail = 0;
B.lift = CC.reducedMotion ? 0
: 0.035 * Math.sin(V.t * 0.50 + (hA + hB) * 6.283);
B.legW = w < 16 ? 1 : 0;
hideLight();
beast(f);
if (w < 15) {
var muzz = topF(1.16, B.head) * B.wy - 0.10;
var mc = cross - dirIn * 1.30;
var rx2 = wx(axis, a, mc), rz2 = wz(axis, a, mc);
if (muzz > 1.16 && project(rx2, muzz, rz2)) {
var rcx = Math.floor(PJ.x), rr0 = Math.floor(PJ.y), rdd = PJ.d;
if (project(rx2, 1.04, rz2)) {
var rr1 = Math.floor(PJ.y), rr;
for (rr = rr0; rr <= rr1; rr++)
emit(f, rcx, rr, G_QUOTE, B.rim, B.rimLum * 0.34, rdd * 0.97);
}
}
}
}
}
}
}
var COR = { axis: 0, ctr: 0, along: 0, dir: 1 };
function corridor() {
var k = Math.round(V.ox / CITY.AVE), m = Math.round(V.oz / CITY.CROSS);
var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d;
for (i = k - 1; i <= k + 1; i++) {
c = CITY.aveX(i) + 0.5; d = V.ox - c; if (d < 0) d = -d;
if (d < bA) { bA = d; aC = c; aW = CITY.aveW(i) + 0.5; }
}
for (i = m - 1; i <= m + 1; i++) {
c = CITY.crossZ(i) + 0.5; d = V.oz - c; if (d < 0) d = -d;
if (d < bC) { bC = d; cC = c; cW = CITY.crossW(i) + 0.5; }
}
var afz = V.fwz < 0 ? -V.fwz : V.fwz, afx = V.fwx < 0 ? -V.fwx : V.fwx;
if (bC <= cW && (bA > aW || afx > afz)) {
COR.axis = 1; COR.ctr = cC; COR.along = V.ox; COR.dir = V.fwx < 0 ? -1 : 1;
} else {
COR.axis = 0; COR.ctr = aC; COR.along = V.oz; COR.dir = V.fwz < 0 ? -1 : 1;
}
}
function wheel(f, px, pz, cy, rad, col, lum) {
if (!project(px, cy, pz)) return;
var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d;
var rw = rad * V.colK / d, rh = rad * V.scale / d;
if (rw < 1.1 || rh < 0.8) {
emit(f, x, y, G_o, col, lum, d);
emit(f, x, y + 1, G_COMMA, col, lum * 0.6, d);
return;
}
var iw = Math.ceil(rw); if (iw > 26) iw = 26;
var i, r;
for (i = -iw; i < iw; i++) {
var u0 = i / rw, u1 = (i + 1) / rw;
if (u0 < -1) u0 = -1; if (u0 > 1) u0 = 1;
if (u1 < -1) u1 = -1; if (u1 > 1) u1 = 1;
var a0 = Math.sqrt(1 - u0 * u0) * rh, a1 = Math.sqrt(1 - u1 * u1) * rh;
var t0 = Math.round(y - a0), t1 = Math.round(y - a1);
if (t1 < t0) { r = t0; t0 = t1; t1 = r; }
var g = (t1 - t0) > 1 ? G_PIPE : G_DASH;
for (r = t0; r <= t1; r++) emit(f, x + i, r, g, col, lum, d * 0.99);
var b0 = Math.round(y + a0), b1 = Math.round(y + a1);
if (b1 < b0) { r = b0; b0 = b1; b1 = r; }
g = (b1 - b0) > 1 ? G_PIPE : G_DASH;
for (r = b0; r <= b1; r++) emit(f, x + i, r, g, col, lum * 0.45, d * 0.99);
}
emit(f, x, y, G_o, col, lum * 0.7, d * 0.99);
}
var WAG_SPAN = 40.0;
function drawWagons(f) {
corridor();
var wA = 1 - COR.axis;
var period = wA ? CITY.CROSS : CITY.AVE;
var i0 = Math.round(COR.along / period), m;
for (m = i0 - 3; m <= i0 + 3; m++) {
var jc = (wA ? CITY.crossZ(m) : CITY.aveX(m)) + 0.5;
var ahead = (jc - COR.along) * COR.dir;
if (ahead < 11 || ahead > 78) continue;
var T = 42 + hash2(m, wA, BASE + 0x21) * 44;
var uu = V.t / T + hash2(m, wA, BASE + 0x22);
var cyc = Math.floor(uu), ph = uu - cyc;
if (CC.reducedMotion) ph = 0.44;
var go = hash2(m, cyc, BASE + 0x23) < 0.5 ? -1 : 1;
var off = (ph * 2 - 1) * WAG_SPAN * go;
streetSpan(wA, m);
var road = SPAN.w * 0.5 - paveOf(SPAN.w);
if (road < 1.7) road = 1.7;
var lane = road * 0.42; if (lane > 1.5) lane = 1.5;
var cross = SPAN.mid - go * lane;
var aw = COR.ctr + off;
var w = objVisible(wA, aw, cross, 2.0);
if (!w) continue;
drawWagon(f, wA, aw, cross, go, m, cyc);
}
}
function drawWagon(f, axis, a, cross, go, m, cyc) {
var rear = a - go * 1.6, front = a + go * 1.6;
var wcx = wx(axis, a, cross), wcz = wz(axis, a, cross);
var nx = axis ? 0 : 1, nz = axis ? 1 : 0;
if (nx * (V.ox - wcx) + nz * (V.oz - wcz) < 0) { nx = -nx; nz = -nz; }
var side = litFace(nx, nz);
var boardLum = (14 + 92 * side * SUN + 26 * LAMP * (1 - SUN)) | 0;
var boardCol = WARM > 0.45 ? P.amber : P.white;
var deck = 1.02, capY = 1.48;
var n = Math.round(26 * (f.D || 1)), i;
for (i = 0; i <= n; i++) {
var aa = rear + (front - rear) * (i / n);
column(f, wx(axis, aa, cross), wz(axis, aa, cross), deck, capY - 0.06,
G_HASH, boardCol, boardLum * 0.55, 0);
column(f, wx(axis, aa, cross), wz(axis, aa, cross), deck - 0.20, deck,
G_HASH, P.shadow, 0, 0);
}
beam(f, axis, rear, front, cross, capY, G_EQ, boardCol, boardLum);
var seatA = front - go * 0.42;
column(f, wx(axis, seatA, cross), wz(axis, seatA, cross), capY, 1.72, G_HASH, P.shadow, 0, 1);
column(f, wx(axis, seatA, cross - 0.1), wz(axis, seatA, cross - 0.1), 1.72, 2.34,
G_PIPE, P.shadow, 0, 1);
if (project(wx(axis, seatA, cross - 0.1), 2.36, wz(axis, seatA, cross - 0.1))) {
var dx0 = Math.floor(PJ.x), dy0 = Math.floor(PJ.y), dd0 = PJ.d;
emit(f, dx0, dy0, G_CARET, boardCol, boardLum * 1.2, dd0 * 0.98);
emit(f, dx0 - 1, dy0, G_DASH, boardCol, boardLum * 0.7, dd0 * 0.98);
emit(f, dx0 + 1, dy0, G_DASH, boardCol, boardLum * 0.7, dd0 * 0.98);
}
var wl = 0.62;
var rw = 0.725, fw = 0.50;
var wheelLum = 30 + 96 * side * SUN + 30 * LAMP * (1 - SUN);
var wheelCol = WARM > 0.45 ? P.amber : P.white;
var rA = rear + go * 0.75, fA = front - go * 0.30;
wheel(f, wx(axis, rA, cross - wl), wz(axis, rA, cross - wl), rw, rw, wheelCol, wheelLum);
wheel(f, wx(axis, rA, cross + wl), wz(axis, rA, cross + wl), rw, rw, wheelCol, wheelLum * 0.7);
wheel(f, wx(axis, fA, cross - wl), wz(axis, fA, cross - wl), fw, fw, wheelCol, wheelLum);
wheel(f, wx(axis, fA, cross + wl), wz(axis, fA, cross + wl), fw, fw, wheelCol, wheelLum * 0.7);
beam(f, axis, front, front + go * 2.6, cross, 0.74, G_DASH, boardCol, boardLum * 0.34);
if (LAMP > 0.12) {
var lanA = front - go * 0.15;
if (project(wx(axis, lanA, cross - 0.66), capY + 0.16, wz(axis, lanA, cross - 0.66))) {
var lx2 = Math.floor(PJ.x), ly2 = Math.floor(PJ.y), ld2 = PJ.d;
emit(f, lx2, ly2, G_o, P.amber, 210 * LAMP, ld2 * 0.97);
emit(f, lx2, ly2 - 1, G_DOT, P.warm, 128 * LAMP, ld2 * 0.97);
if (ld2 < 26) {
emit(f, lx2 - 1, ly2, G_TICK, P.warm, 90 * LAMP, ld2 * 0.97);
emit(f, lx2 + 1, ly2, G_TICK, P.warm, 90 * LAMP, ld2 * 0.97);
}
}
}
var hx2 = axis ? go : 0, hz2 = axis ? 0 : go;
var teamA = front + go * 2.05;
var h;
for (h = 0; h < 2; h++) {
var lat2 = h ? 0.55 : -0.55;
B.x = wx(axis, teamA, cross + lat2); B.z = wz(axis, teamA, cross + lat2);
B.ux = hx2; B.uz = hz2;
B.len = 1.98 + hash2(m + h, cyc, BASE + 0x24) * 0.18;
B.wy = 1.56 + hash2(m + h, cyc, BASE + 0x25) * 0.14;
B.head = 0;
B.tail = 0;
B.lift = 0;
B.legW = objVisible(axis, teamA, cross + lat2, 0.5) < 18 * (f.D || 1) ? 1 : 0;
hideLight();
beast(f);
}
}
var DOG_PITCH = 31.0;
function drawDogs(f, axis, idx) {
streetSpan(axis, idx);
var here = axis ? V.ox : V.oz;
var lo = Math.floor((here - 22) / DOG_PITCH), hi = Math.floor((here + 44) / DOG_PITCH);
for (var k = lo; k <= hi; k++) {
var slot = idx * 2 + axis;
var g0 = hash2(k, slot, BASE + 0x31);
if (g0 > 0.60) continue;
var along = k * DOG_PITCH + g0 * 22;
var f0 = frontage(axis, along - 1.0, 2.0, SPAN.c0, 1);
var f1 = frontage(axis, along - 1.0, 2.0, SPAN.c1, -1);
if (!f0 && !f1) continue;
var T = 24 + hash2(k, slot, BASE + 0x32) * 26;
var uu = V.t / T + hash2(k, slot, BASE + 0x33);
var cyc = Math.floor(uu), ph = uu - cyc;
if (CC.reducedMotion) ph = 0.11;
if (ph > 0.26) continue;
var q = ph / 0.26;
var go = (f0 && f1) ? (hash2(k, cyc, BASE + 0x34) < 0.5 ? 1 : -1) : (f0 ? 1 : -1);
var c0 = SPAN.c0 - 0.9, c1 = SPAN.c1 + 0.9;
var cross = go > 0 ? c0 + (c1 - c0) * q : c1 - (c1 - c0) * q;
var w = objVisible(axis, along, cross, 0.9);
if (!w) continue;
B.x = wx(axis, along, cross); B.z = wz(axis, along, cross);
B.ux = axis ? 0 : go; B.uz = axis ? go : 0;
B.len = 0.80; B.wy = 0.56;
B.head = 0.25;
B.tail = 1;
B.lift = 0;
B.legW = 0;
hideLight();
B.rimLum *= 0.85;
beast(f);
}
}
function eachStreet(f, fn) {
var i;
for (i = -1; i <= 1; i++) fn(f, 0, nearIdx(0) + i);
for (i = -1; i <= 1; i++) fn(f, 1, nearIdx(1) + i);
}
function mk(name, layer, fn) {
return {
name: name, layer: layer, world: 'west',
init: function (city) { boot(city); },
draw: function (f, cam, t) {
if (!CITY) return;
view(f, cam, t === undefined ? (cam.t || 0) : t);
fn(f);
}
};
}
CC.ELEMENTS.push(mk('west-hitched', 20, function (f) { eachStreet(f, drawHitched); }));
CC.ELEMENTS.push(mk('west-wagon', 22, drawWagons));
CC.ELEMENTS.push(mk('west-dog', 22, function (f) { eachStreet(f, drawDogs); }));
})(CC);
};
W["elements/west_town.js"] = function (CC) {
'use strict';
/* src/elements/west_town.js */
(function (CC) {
var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ;
var project = PR.project, emit = PR.emit, column = PR.column, litFace = PR.litFace;
var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp;
var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_DOT = CC.g('.'),
G_COLON = CC.g(':'), G_TICK = CC.g('`'), G_CARET = CC.g('^'), G_STAR = CC.g('*'),
G_0 = CC.g('0'), G_O = CC.g('O'), G_o = CC.g('o'), G_HASH = CC.g('#'), G_PLUS = CC.g('+'),
G_TILDE = CC.g('~'), G_UNDER = CC.g('_'), G_SLASH = CC.g('/'), G_PCT = CC.g('%'),
G_DQ = CC.g('"');
function dayF() {
var W = CC.SurfWest;
return W && W.dayFill !== undefined ? W.dayFill : 0;
}
function woodC(sun, day) {
return day ? (sun > 0.6 ? P.sand : P.timber) : (sun > 0.6 ? P.amber : P.slate);
}
var CITY = null, BASE = 0, Surf = null, WEST = null;
function boot(city) {
CITY = (city && city.aveX && city.world === 'west') ? city : null;
BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 8) & 0x3fffff) : 0;
}
var W_WIND = 1, W_WET = 1;
function view(f, cam, t) {
PR.view(f, cam, t);
if (!Surf) Surf = CC.Surf;
if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null;
W_WIND = CC.Weather ? CC.Weather.rel('wind') : 1;
W_WET = CC.Weather ? CC.Weather.rel('wet') : 1;
}
var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 };
function streetSpan(axis, idx) {
var c, h;
if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); }
else { c = CITY.aveX(idx); h = CITY.aveW(idx); }
SPAN.c0 = c - h; SPAN.c1 = c + h + 1;
SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0;
}
function wx(axis, along, cross) { return axis ? along : cross; }
function wz(axis, along, cross) { return axis ? cross : along; }
function nX(axis, s) { return axis ? 0 : (s ? -1 : 1); }
function nZ(axis, s) { return axis ? (s ? -1 : 1) : 0; }
function paveOf(spanW) {
var p = CC.PAVE, avail = spanW * 0.5 - 1.7;
return avail < p ? avail : p;
}
function frontage(axis, a0, len, cross, dirIn) {
var i, a, c = cross - dirIn * 0.7;
for (i = 0; i <= 3; i++) {
a = a0 + len * (i / 3);
if (CITY.height(wx(axis, a, c), wz(axis, a, c)) < 2.5) return 0;
}
return 1;
}
function objVisible(axis, along, cross, near) {
var px = wx(axis, along, cross), pz = wz(axis, along, cross);
var rx = px - V.ox, rz = pz - V.oz;
var w = rx * V.fwx + rz * V.fwz;
if (w < near || w > V.far) return 0;
var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14;
if (s < -lim || s > lim) return 0;
return w;
}
function beam(f, axis, a0, a1, cross, y, ch, col, lum) {
var n = 22, i, a, lx = -1, ly = 0, ld = 0;
for (i = 0; i <= n; i++) {
a = a0 + (a1 - a0) * (i / n);
if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) { lx = -1; continue; }
var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d;
if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1;
if (lx >= 0) {
var dx = x - lx, dy = r - ly;
var steps = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy);
if (steps > 4 * V.cols) steps = 0;
for (var q = 1; q < steps; q++) {
var t2 = q / steps;
emit(f, lx + Math.round(dx * t2), ly + Math.round(dy * t2), ch, col, lum,
ld + (d - ld) * t2);
}
}
emit(f, x, r, ch, col, lum, d);
lx = x; ly = r; ld = d;
}
}
var POST = 2.6;
var AWN_Y = 2.94;
function drawVeranda(f, axis, idx) {
streetSpan(axis, idx);
var pave = paveOf(SPAN.w);
if (pave < 1.1) return;
var pitch = axis ? CITY.AVE : CITY.CROSS;
var lo = Math.floor(((axis ? V.ox : V.oz) - 60) / POST);
var hi = Math.floor(((axis ? V.ox : V.oz) + 60) / POST);
if (hi - lo > 60) hi = lo + 60;
for (var s = 0; s < 2; s++) {
var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1;
var postC = face + dirIn * (pave - 0.34);
var nx = nX(axis, s), nz = nZ(axis, s);
var sun = litFace(nx, nz);
var dF = dayF();
for (var k = lo; k <= hi; k++) {
var along = k * POST + 0.5;
var w = objVisible(axis, along, postC, 0.7);
if (!w) continue;
if (!frontage(axis, along - POST * 0.5, POST, face, dirIn)) continue;
var hh = hash2(k, idx * 2 + s, BASE + (axis ? 0x51 : 0x52));
var day = hash2(k, idx * 2 + s, BASE + 0x54) < dF;
var pcol = woodC(sun, day);
var plum = day ? (sun > 0.6 ? 168 : 92) : (sun > 0.6 ? 74 : 20);
column(f, wx(axis, along, postC), wz(axis, along, postC), 0.0, AWN_Y,
G_PIPE, pcol, plum, w < 12 ? 1 : 0);
if (day && w < 14) {
if (project(wx(axis, along, postC), 0.10, wz(axis, along, postC)))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER,
sun > 0.6 ? P.stone : P.timber, sun > 0.6 ? 132 : 74, PJ.d);
var bq, by2, bc2;
for (bq = 0; bq < 3; bq++) {
by2 = AWN_Y - 0.30 - bq * 0.22;
bc2 = postC + dirIn * (0.22 + bq * 0.20);
if (project(wx(axis, along, bc2), by2, wz(axis, along, bc2)))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_SLASH,
sun > 0.6 ? P.sand : P.timber, sun > 0.6 ? 118 : 66, PJ.d);
}
}
beam(f, axis, along - POST, along, postC, AWN_Y + 0.06, G_EQ,
day ? (sun > 0.6 ? P.sand : P.stone) : (sun > 0.6 ? P.amber : P.slate),
day ? (sun > 0.6 ? 196 : 112) : (sun > 0.6 ? 96 : 26));
beam(f, axis, along - POST, along, postC, AWN_Y - 0.12, G_DASH,
day ? P.indigo : P.shadow, day ? 58 : 0);
if (day && hh < 0.34) {
var stripe = (k & 1) === 0;
beam(f, axis, along - POST, along, postC + dirIn * 0.30, AWN_Y + 0.20, G_HASH,
stripe ? P.white : P.ember, sun > 0.6 ? (stripe ? 190 : 150) : (stripe ? 104 : 84));
beam(f, axis, along - POST, along, postC + dirIn * 0.62, AWN_Y + 0.34, G_EQ,
stripe ? P.ember : P.white, sun > 0.6 ? (stripe ? 150 : 190) : (stripe ? 84 : 104));
}
if (hh < 0.30 && hash2(k + 1, idx * 2 + s, BASE + 0x53) > 0.30) {
var ly = AWN_Y - 0.42;
if (project(wx(axis, along, postC), ly, wz(axis, along, postC))) {
var lx = Math.floor(PJ.x), lr = Math.floor(PJ.y), ld = PJ.d;
var lk = 1 - dF;
if (lk > 0.02) {
emit(f, lx, lr, G_o, P.amber, 236 * lk, ld);
emit(f, lx, lr - 1, G_DOT, P.warm, 150 * lk, ld);
if (ld < 22) {
emit(f, lx + 1, lr, G_TICK, P.warm, 108 * lk, ld);
emit(f, lx - 1, lr, G_TICK, P.warm, 108 * lk, ld);
}
}
if (dF > 0.02) {
emit(f, lx, lr, G_0, sun > 0.6 ? P.gold : P.timber,
(sun > 0.6 ? 150 : 84) * dF, ld);
emit(f, lx, lr - 1, G_CARET, sun > 0.6 ? P.gold : P.timber,
(sun > 0.6 ? 122 : 66) * dF, ld);
}
}
}
}
}
}
var RAIL_PITCH = 15.0;
function drawStreetProps(f, axis, idx) {
streetSpan(axis, idx);
var pave = paveOf(SPAN.w);
var lo = Math.floor(((axis ? V.ox : V.oz) - 48) / RAIL_PITCH);
var hi = Math.floor(((axis ? V.ox : V.oz) + 48) / RAIL_PITCH);
var dF = dayF();
for (var s = 0; s < 2; s++) {
var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1;
var sun = litFace(nX(axis, s), nZ(axis, s));
var edge = face + dirIn * (pave + 0.15);
for (var k = lo; k <= hi; k++) {
var day = hash2(k, idx * 2 + s, BASE + 0x64) < dF;
var h0 = hash2(k, idx * 2 + s, BASE + 0x61);
if (h0 > 0.62) continue;
var along = k * RAIL_PITCH + h0 * 9;
var w = objVisible(axis, along, edge, 0.8);
if (!w) continue;
if (!frontage(axis, along, 5.2, face, dirIn)) continue;
var kind = hash2(k, idx * 2 + s, BASE + 0x62);
if (kind < 0.52) {
var L = 3.6 + kind * 3.2;
var rc = woodC(sun, day), rl = day ? (sun > 0.6 ? 148 : 80) : (sun > 0.6 ? 62 : 18);
column(f, wx(axis, along, edge), wz(axis, along, edge), 0, 1.28, G_PIPE, rc, rl, 0);
column(f, wx(axis, along + L, edge), wz(axis, along + L, edge), 0, 1.28, G_PIPE, rc, rl, 0);
beam(f, axis, along, along + L, edge, 1.06, G_DASH, rc,
day ? (sun > 0.6 ? 162 : 88) : (sun > 0.6 ? 72 : 20));
if (day && objVisible(axis, along, edge, 0.8) < 20)
beam(f, axis, along + 0.5, along + L + 0.5, edge - dirIn * 1.15, 0.02, G_DASH,
P.timber, sun > 0.6 ? 62 : 34);
} else if (kind < 0.74) {
var TL = 2.5;
beam(f, axis, along, along + TL, edge, 0.62, G_EQ,
day ? (sun > 0.6 ? P.sand : P.stone) : (sun > 0.6 ? P.white : P.slate),
day ? (sun > 0.6 ? 172 : 96) : (sun > 0.6 ? 76 : 24));
beam(f, axis, along, along + TL, edge, 0.30, G_HASH,
day ? P.timber : P.shadow, day ? 66 : 0);
beam(f, axis, along + 0.15, along + TL - 0.15, edge - dirIn * 0.02, 0.55,
G_TILDE, day ? (sun > 0.6 ? P.pure : P.ice) : P.ember,
day ? (sun > 0.6 ? 196 : 150) : 128);
} else {
var bc = face + dirIn * 0.55;
for (var b = 0; b < 3; b++) {
var bh = hash2(k * 7 + b, idx * 2 + s, BASE + 0x63);
if (bh > 0.66) continue;
var ba = along + b * 0.95;
if (!objVisible(axis, ba, bc, 0.8)) continue;
var tall = 0.42 + bh * 0.62;
column(f, wx(axis, ba, bc), wz(axis, ba, bc), 0.18, 0.18 + tall,
bh < 0.33 ? G_O : G_HASH, woodC(sun, day),
day ? (sun > 0.6 ? 142 : 78) : (sun > 0.6 ? 56 : 16), 1);
if (day && objVisible(axis, ba, bc, 0.8) < 13 &&
project(wx(axis, ba, bc), 0.18 + tall * 0.62, wz(axis, ba, bc)))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), bh < 0.33 ? G_DASH : G_EQ,
sun > 0.6 ? P.stone : P.timber, sun > 0.6 ? 168 : 92, PJ.d);
}
}
}
}
}
function drawCrowns(f) {
var R = 74;
var gx0 = Math.floor(V.ox - R), gx1 = Math.floor(V.ox + R);
var gz0 = Math.floor(V.oz - R), gz1 = Math.floor(V.oz + R);
for (var gz = gz0; gz <= gz1; gz += 4) {
for (var gx = gx0; gx <= gx1; gx += 4) {
var h = CITY.height(gx, gz);
if (h < 3) continue;
var rec = CITY.cell(gx, gz);
if (!rec || !rec.crown || rec.rock) continue;
var cx = rec.lotX + 1.6 + rec.seed * 2.2, cz = rec.lotZ + 1.4 + rec.face * 2.4;
if (Math.abs(cx - gx) > 4 || Math.abs(cz - gz) > 4) continue;
var w = objVisible(0, cz, cx, 2.0);
if (!w) continue;
var sun = litFace(WEST ? WEST.SUN_X : -1, WEST ? WEST.SUN_Z : 0);
var dF = dayF();
var day = rec.seed < dF;
var lum = 66, col = P.amber;
if (rec.crown === 1) {
var ch2 = 1.1 + rec.seed * 0.9;
column(f, cx, cz, h, h + ch2, G_HASH, day ? (sun > 0.6 ? P.stone : P.timber) : P.slate,
day ? (sun > 0.6 ? 156 : 88) : 30, 1);
emit2smoke(f, cx, cz, h + ch2, rec);
} else if (rec.crown === 2) {
var ty = h + 1.5, td = 1.5 + rec.seed * 0.8;
var lc = day ? P.timber : P.slate, ll = day ? 82 : 24;
column(f, cx - 0.7, cz - 0.7, h, ty, G_PIPE, lc, ll, 0);
column(f, cx + 0.7, cz - 0.7, h, ty, G_PIPE, lc, ll, 0);
column(f, cx - 0.7, cz + 0.7, h, ty, G_PIPE, lc, ll, 0);
column(f, cx + 0.7, cz + 0.7, h, ty, G_PIPE, lc, ll, 0);
for (var q = 0; q < 5; q++) {
var qx = cx - 0.9 + q * 0.45;
var qq = q / 4;
column(f, qx, cz, ty, ty + td, G_0,
day ? (sun > 0.6 ? (qq < 0.55 ? P.sand : P.stone) : P.timber)
: (sun > 0.6 ? P.amber : P.slate),
day ? (sun > 0.6 ? 190 - 60 * qq : 92) : (sun > 0.6 ? 86 : 26), 0);
}
beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td, G_EQ,
day ? (sun > 0.6 ? P.sand : P.stone) : P.amber, day ? 176 : 96);
if (day) {
beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td * 0.62, G_DASH, P.timber, 68);
beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td * 0.22, G_DASH, P.timber, 68);
}
} else {
var mill = rec.seed > 0.55;
var sy = h + 2.2 + rec.face * 3.4;
column(f, cx, cz, h, sy, G_PIPE, woodC(sun, day),
day ? (sun > 0.6 ? 162 : 88) : (sun > 0.6 ? 72 : 22), 0);
if (mill) {
if (project(cx, sy, cz)) {
var mx = Math.floor(PJ.x), my = Math.floor(PJ.y), md = PJ.d;
for (var b2 = 0; b2 < 12; b2++) {
var an = b2 * Math.PI / 6;
emit(f, mx + Math.round(Math.cos(an) * 2.2), my + Math.round(Math.sin(an) * 1.2),
G_PLUS, day ? P.stone : P.slate, day ? 92 : 54, md);
}
emit(f, mx, my, G_O, day ? P.timber : P.amber, day ? 96 : 120, md);
var sp = CC.reducedMotion ? 0.9 : V.t * 0.5 * (0.3 + 0.5 * W_WIND);
emit(f, mx + Math.round(Math.cos(sp) * 2.2), my + Math.round(Math.sin(sp) * 1.2),
G_STAR, P.amber, 128, md);
}
} else {
column(f, cx, cz, sy, sy + 1.2, G_CARET, P.white, day ? 190 : 84, 0);
if (project(cx, sy + 1.5, cz))
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_PLUS,
day ? (sun > 0.6 ? P.gold : P.stone) : P.amber, day ? 168 : 148, PJ.d);
}
}
}
}
}
function emit2smoke(f, cx, cz, y0, rec) {
var lean = 1.5 * W_WIND;
var tt = CC.reducedMotion ? 4.0 : V.t;
var sway = vnoise(tt * 0.33 + rec.seed * 7, 0x2A) - 0.5;
var N = 16;
for (var i = 0; i < N; i++) {
var u = i / (N - 1);
var yy = y0 + 0.15 + u * 3.8;
var dx = (lean * u * u + sway * 0.9 * u) * 1.6;
if (!project(cx + dx, yy, cz + dx * 0.35)) continue;
var dF = dayF();
var lum = (104 + 22 * dF) * (1 - u) * (1 - u * 0.5);
if (lum < 6) continue;
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), u < 0.35 ? G_HASH : (u < 0.7 ? G_COLON : G_DOT),
dF > 0.5 ? P.stone : P.slate, lum, PJ.d);
}
}
function nearIdx(axis) {
return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE));
}
function eachStreet(f, fn) {
var i;
for (i = -1; i <= 1; i++) fn(f, 0, nearIdx(0) + i);
for (i = -1; i <= 1; i++) fn(f, 1, nearIdx(1) + i);
}
function mk(name, layer, fn) {
return {
name: name, layer: layer, world: 'west',
init: function (city) { boot(city); },
draw: function (f, cam, t) {
if (!CITY) return;
view(f, cam, t === undefined ? (cam.t || 0) : t);
fn(f);
}
};
}
CC.ELEMENTS.push(mk('west-props', 17, function (f) { eachStreet(f, drawStreetProps); }));
CC.ELEMENTS.push(mk('west-veranda', 18, function (f) { eachStreet(f, drawVeranda); }));
CC.ELEMENTS.push(mk('west-crowns', 21, drawCrowns));
})(CC);
};
})(self.CCW || (self.CCW = {}));