@adatechnology/game-urban 0.3.13 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,13 +23,15 @@ const scene = b.scene() // { parts, items, windows: {
23
23
  | id | shape | what it is |
24
24
  |---|---|---|
25
25
  | `led_double` | `double_arm` | 9 m mast, two arms with white LED heads (avenue) |
26
- | `concrete_arm` | `single_arm` | 8 m concrete mast, one arm, sodium lamp, optional transformer drum (`dir` -1 mirrors the arm) |
26
+ | `concrete_arm` | `single_arm` | 8 m concrete mast, one arm, sodium lamp, optional transformer drum (`dir` -1 mirrors the arm; `ry` turns the pole, so a pole by a street along x reaches over the road with `ry = ±π/2`; the crossarm and the lantern turn too) |
27
27
  | `cast_iron` | `lantern` | 4 m iron post, lantern box and pointed cap |
28
28
  | `wood_crossarm` | `crossarm` | 7 m wooden pole with a crossarm and a hanging lamp |
29
29
  | `flood_tower` | `flood_tower` | 12 m four-legged tower with three floodlights |
30
30
 
31
31
  A pole that is `on` has a glowing lens and, while the **light budget** lasts, a real point light (white LED 1.3 / 24 m, sodium 1.3 / 20 m, lantern 1 / 14 m, crossarm 0.9 / 16 m, floodlight 1.6 / 34 m). The budget is the Galeria's counter: 16 by default, `take()` is `left-- > 0`, so `left` keeps falling below zero when more lamps ask than the budget had, and the lamps that did not get a light keep their lens. `flicker: true` marks the light of a failing lamp; the drawer animates it.
32
32
 
33
+ `lampStateOf({ seed, x, z, shares: { lit, flicker } })` says whether the lamp at a spot works, flickers or is burnt out (`{ on, flicker }`, for the pole's options): `lit` is the share of lamps that work, `flicker` the share of all lamps that fail (a part of `lit`, so `0 <= flicker <= lit <= 1`). The choice is a hash of the seed and the spot, not a draw from `b.random`: the same street with the same seed keeps the same dark and failing lamps, and the rest of the scene keeps its draw order. A pole built with `flicker: true` gives its lens and its light the same `flickerPhase` (`flickerPhaseOf(x, z)`), so a drawer blinks them together.
34
+
33
35
  Every number of a pole is data. A game patches one by id, adds a pole or takes one out, and a pole of a new shape brings its builder:
34
36
 
35
37
  ```ts
@@ -136,6 +138,90 @@ createUrban({
136
138
  })
137
139
  ```
138
140
 
141
+ ## Utility networks (`@adatechnology/game-urban/networks`)
142
+
143
+ The networks of a district as data, with no three.js: medium and low voltage, street lighting, telecom, sewer, drainage and water. A network is
144
+ `nodes` (feed, pole, transformer, light, manhole, inlet, outfall, valve, hydrant, reservoir, treatment, connection...) and `edges` in the direction
145
+ of the flow (spans and drops in the air with their `sag` and fixing `heights`; pipes under the ground with their `diameter` and `inverts`), plus
146
+ the `rules`, every number of which a game patches. The lot side is the `UtilityConnection` of `@adatechnology/game-contracts`: the house says
147
+ where it takes each network, the network links it, and neither imports the other.
148
+
149
+ ```ts
150
+ import { DEFAULT_NETWORK_RULES, resolveNetworkRules, validateNetworks } from '@adatechnology/game-urban/networks'
151
+
152
+ const networks = { nodes, edges, seed: 7, rules: resolveNetworkRules({ power: { maxLoading: 0.9 } }) }
153
+ const violations = validateNetworks(networks, {
154
+ connections, // UtilityConnection[], frame 'world' only
155
+ buildings, // { id, lot?, outline, height }: no span crosses one
156
+ obstacles: { crowns }, // { x, z, radius, bottom, top } from the scene's plant provider
157
+ surfaceAt: (x, z) => 'road' | 'sidewalk' | 'lot',
158
+ groundAt: (x, z) => height,
159
+ })
160
+ // [{ code: 'clearance', id: 'lv:1', detail: 'sidewalk', value: 4.3, limit: 4.5 }, ...]
161
+ ```
162
+
163
+ - **Graph** (`buildNetworkGraph`, `connectedNodes`, `circuitOf`): edges in and out of each node per network; each network reached from its source
164
+ (feed, reservoir) or back from its destination (treatment, outfall). The low voltage starts only at a transformer the medium voltage reaches, and
165
+ the lighting at the low voltage; a lot's `power` connection is low voltage, never medium.
166
+ - **Violations** (`NETWORK_VIOLATION`, stable codes): duplicate ids, missing nodes, edge on a node that does not carry its network, a node fed twice
167
+ or flowing two ways, a node cut from its source, a loop through a source or a destination, a lot in the plan frame, declaring a network twice,
168
+ unlinked, linked twice or moved, a connection node no lot declared; a drop longer than 30 m; a span with no
169
+ sag, under the clearance of its class (medium voltage 7 / 6 m and never over a lot; low voltage and drops 5.5 / 4.5 / 3.5; telecom 5 / 4.5 / 3
170
+ over road, sidewalk, lot), lower than the roof of a building it passes over (a drop may end over the house of its own lot, never cross it) or
171
+ through a crown; a pipe without inverts or diameter, flatter than its least slope (sewer main
172
+ 0.5 %, lateral 1 %, drainage 0.5 %), out of its cover range (a sewer main 1.8 m under a street with a storm gallery), a sewer deeper than 4.5 m, a
173
+ sewer main longer than 80 m between manholes, a lateral deeper than 0.85 m where it crosses the gallery, two pipes crossing closer than 0.2 m or in the wrong
174
+ order (water, sewer lateral, drainage, sewer main from the top); a transformer of an unknown rating, loaded over 80 % by the diversified demand
175
+ of its consumers (`diversifiedDemand`, by count of consumers and installed load; an unknown load counts in the lower column) plus its lamps, or
176
+ with more than 200 m of low voltage line from it (service drops not counted).
177
+ - **Pole slots** (`DEFAULT_POLE_SLOTS`, `checkPoleSlots`): the bands of a distribution pole over the ground, top down: medium voltage 9-9.25 m,
178
+ transformer 7.7-8.7, low voltage 7.1-7.4, lamp 6.5-6.8, telecom 5.7-6.1, on the 11 m pole with 1.7 m buried. A registry pole whose spec has
179
+ `slots` (`DistributionPoleDef`, `DistributionSpec`) is read by `slotsOfPole`. The registry ships `concrete_distribution` (shape `distribution`, drawn
180
+ as its single arm until the crossarm and insulators get their drawing).
181
+
182
+ ### The generator
183
+
184
+ ```ts
185
+ import { generateNetworks, validateNetworks } from '@adatechnology/game-urban/networks'
186
+
187
+ const { networks, connections, surfaceAt, warnings } = generateNetworks({
188
+ plan, // CityPlanInput: streets along x or z, rivers, districts
189
+ lots: site.lots, // { id, rect }: each takes the networks from the street it faces
190
+ connections, // optional UtilityConnection[] the houses declared (frame 'world'); the rest get the default point of the lot
191
+ seed: site.seed, // hookups and telecom bundles: hash of the seed and an id, never the scene's random
192
+ avoid, // optional PlanRect[]: no pole in front of a gate, a door or by a meter post
193
+ rules, // optional DeepPartial<NetworkRules>; the layout numbers live in `rules.layout` (DEFAULT_NETWORK_LAYOUT)
194
+ pole, // optional { id, spec: DistributionSpec }: the bands and the lamp's reach come from the pole's spec
195
+ })
196
+ // warnings: what it laid against its own rules because nothing else fit (a pole with no free ground but in front of a gate,
197
+ // a pole whose own consumers no transformer takes); [] for a plan it can lay
198
+ validateNetworks(networks, { connections, surfaceAt }) // [] for a plan the generator can lay
199
+ ```
200
+
201
+ - **Poles** on one side of each street (the side with more lots; on a tie north or west), 0.4 m from the kerb, 30 to 40 m apart on lot
202
+ boundaries when one is in reach, slid clear of `avoid` (else the next boundary in reach, never past 40 m); a guyed pole at each corner (the
203
+ end of a street at another, a T, is a corner too) and each end of line, the corners of two streets joined by a span; an in-line pole at
204
+ least 5 m from a cross street's roadway. A lot out of a drop's reach gets an in-line pole at its station, and service poles into it when it
205
+ stands farther back. Each street pole carries a lamp on its arm over the road (`light_feed` from its low voltage).
206
+ - **Power**: one system per feed where a street leaves the map (no span over a river); circuits cut on the pole tree so that the line each way
207
+ from the transformer stays within 200 m and the diversified demand (plus the lamps) within the largest rating; each transformer on its
208
+ circuit's centre, sized by `pickTransformer`, a circuit over the largest rating split into more; medium voltage only from the feed to the
209
+ transformers; a drop from the nearest pole to every lot.
210
+ Lots of the periphery (`layout.periphery.kinds`) get a few hookups with no meter (`spec: 'unmetered'`), counted in the load.
211
+ - **Telecom** on every pole from its own feed, 1-2 cables in the centre and 3-5 in the periphery, a splice box with its reserve coil every 4 spans.
212
+ - **Sewer**: DN 150 under the axis, a manhole at every crossing and at most 80 m apart, a cleanout at each dry head, falling at least 0.5 %
213
+ to the river bank, then an interceptor along the bank to a `treatment` node where the river leaves the map (with no river, from the line's
214
+ end to the border); a `pumping_station` where a main would go deeper than 4.5 m; each lateral perpendicular, from
215
+ the inspection box over the gallery (or under the water main) to a drop and a saddle on the main; mains laid under every drainage pipe they cross.
216
+ - **Drainage**: a DN 600 gallery 2 m off the axis on the side of the poles, to a headwall on the bank above the river's level (a lift where it
217
+ would reach under it, or deeper than a sewer could pass under); inlets on both
218
+ kerbs at each corner and at most 60 m apart, each with a lateral; the downspout of every lot down the gutter (`storm_gutter`, an open channel of
219
+ diameter 0) to the nearest inlet of its kerb.
220
+ - **Water**: DN 75 under the sidewalk opposite the poles from a reservoir at the border, a valve and a pillar hydrant at every crossing, a
221
+ DN 20 service from a tee to every lot.
222
+ - Limits: straight streets along x or z only (another stretch throws); the ground defaults to flat (`groundAt` for terrain). The pole tree
223
+ and the line trees are plain Dijkstra (tens of nodes a system); the nearest pole and the crossings are found by 20-40 m cells.
224
+
139
225
  ## Terrain
140
226
 
141
227
  `urban.terrain(options)` is a ground made of layers, as the Galeria's Vale: a rolling base (waves), masked relief (mountains, hills: `mask · (level + waves)`), cities levelled flat, rivers carved to a bed, lakes carved to a level, a forest density, and a colour for every point by ordered rules (low ground, ellipses such as a bog, city rectangles, high rock, forest, then open fields picked by a hash of the map cell). It answers `heightAt(px, py)`, `forestAt`, `colorAt`, `nearRiver` and `toWorld`/`fromWorld` (the frame maps the plan to metres: `world = plan · scale + origin`), and hands a drawer `grid(segments)`: the 32-bit coordinates, heights and colours of the square mesh, rows along z. `urban.drawTerrain(b, terrain)` adds the mesh part and the water plane. `custom(px, py, h)` has the last word on a height.