@wildshard/shard-format 0.20.0 → 0.22.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -107,6 +107,7 @@
|
|
|
107
107
|
"./creaturePerch": "./src/format/creature-perch.ts",
|
|
108
108
|
"./creatureLayers": "./src/format/creature-layers.ts",
|
|
109
109
|
"./creatureVolumes": "./src/format/creature-volumes.ts",
|
|
110
|
+
"./creatureSizes": "./src/format/creature-sizes.ts",
|
|
110
111
|
"./creatureSkeletons": "./src/format/creature-skeletons.ts",
|
|
111
112
|
"./crowdPresentation": "./src/format/crowdPresentation.ts",
|
|
112
113
|
"./crowds": "./src/format/crowds.ts",
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { CreatureBody, CreatureSize } from './creature-layers.ts'
|
|
2
|
+
|
|
3
|
+
interface CreatureSizePolicy {
|
|
4
|
+
readonly scale: number
|
|
5
|
+
readonly stride: number
|
|
6
|
+
readonly aggro: number
|
|
7
|
+
readonly cellWeight: number
|
|
8
|
+
readonly maxHeight?: number
|
|
9
|
+
}
|
|
10
|
+
const GIANT_HEIGHT = 15
|
|
11
|
+
const DEFAULT_SCALE = 1
|
|
12
|
+
const BODY_HEIGHT_FACTOR = 2
|
|
13
|
+
const MAX_VARIANT_SCALE = 1
|
|
14
|
+
/** Medium preserves the authored model units. Free body and spawn scales apply
|
|
15
|
+
* after the class; stride/aggro are independent multipliers, not extra geometry. */
|
|
16
|
+
const CREATURE_SIZES: Readonly<Record<CreatureSize, CreatureSizePolicy>> = {
|
|
17
|
+
tiny: { scale: 0.25, stride: 0.5, aggro: 0.5, cellWeight: 0.25 },
|
|
18
|
+
small: { scale: 0.5, stride: 0.75, aggro: 0.75, cellWeight: 0.5 },
|
|
19
|
+
medium: { scale: 1, stride: 1, aggro: 1, cellWeight: 1 },
|
|
20
|
+
large: { scale: 2, stride: 1.5, aggro: 1.5, cellWeight: 4 },
|
|
21
|
+
giant: {
|
|
22
|
+
scale: 4,
|
|
23
|
+
stride: 2,
|
|
24
|
+
aggro: 2,
|
|
25
|
+
cellWeight: 16,
|
|
26
|
+
maxHeight: GIANT_HEIGHT,
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
type SizeBody = Pick<CreatureBody, 'size' | 'scale'>
|
|
30
|
+
interface CreatureDimensions {
|
|
31
|
+
readonly bodyY: number
|
|
32
|
+
readonly bodyRadius: number
|
|
33
|
+
readonly headRadius: number
|
|
34
|
+
}
|
|
35
|
+
interface SizedSpecies {
|
|
36
|
+
readonly id: string
|
|
37
|
+
readonly body?: SizeBody
|
|
38
|
+
readonly dims: CreatureDimensions
|
|
39
|
+
readonly variants: readonly { readonly scale: readonly [number, number] }[]
|
|
40
|
+
}
|
|
41
|
+
interface SizedSpawn {
|
|
42
|
+
readonly id: string
|
|
43
|
+
readonly species: string
|
|
44
|
+
readonly scale: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function creatureScale(
|
|
48
|
+
body: SizeBody | undefined,
|
|
49
|
+
spawnScale: number = DEFAULT_SCALE,
|
|
50
|
+
): number {
|
|
51
|
+
return (
|
|
52
|
+
spawnScale *
|
|
53
|
+
(body === undefined
|
|
54
|
+
? DEFAULT_SCALE
|
|
55
|
+
: CREATURE_SIZES[body.size].scale * body.scale)
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
/** The declared dimensions' conservative upright envelope. Rig/mesh admission
|
|
59
|
+
* checks its actual transformed bounds separately; dimensions cannot waive it. */
|
|
60
|
+
function creatureHeight(
|
|
61
|
+
body: SizeBody,
|
|
62
|
+
dims: CreatureDimensions,
|
|
63
|
+
spawnScale: number,
|
|
64
|
+
): number {
|
|
65
|
+
const modelHeight = Math.max(
|
|
66
|
+
dims.bodyY * BODY_HEIGHT_FACTOR + dims.headRadius,
|
|
67
|
+
dims.bodyY + dims.bodyRadius,
|
|
68
|
+
)
|
|
69
|
+
return modelHeight * creatureScale(body, spawnScale)
|
|
70
|
+
}
|
|
71
|
+
function speciesSizeRules(
|
|
72
|
+
row: SizedSpecies,
|
|
73
|
+
spawns: readonly SizedSpawn[],
|
|
74
|
+
): string[] {
|
|
75
|
+
const { body } = row
|
|
76
|
+
if (body === undefined) {
|
|
77
|
+
return []
|
|
78
|
+
}
|
|
79
|
+
const cap = CREATURE_SIZES[body.size].maxHeight
|
|
80
|
+
if (cap === undefined) {
|
|
81
|
+
return []
|
|
82
|
+
}
|
|
83
|
+
const oversized = row.variants.some(
|
|
84
|
+
(variant): boolean =>
|
|
85
|
+
creatureHeight(body, row.dims, variant.scale[MAX_VARIANT_SCALE]) > cap,
|
|
86
|
+
)
|
|
87
|
+
const errors = oversized ? [`species ${row.id}: giant exceeds ${cap} m`] : []
|
|
88
|
+
return [
|
|
89
|
+
...errors,
|
|
90
|
+
...spawns.flatMap((spawn): string[] =>
|
|
91
|
+
spawn.species === row.id &&
|
|
92
|
+
creatureHeight(body, row.dims, spawn.scale) > cap
|
|
93
|
+
? [`spawn ${spawn.id}: giant exceeds ${cap} m`]
|
|
94
|
+
: [],
|
|
95
|
+
),
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
function creatureSizeRules(
|
|
99
|
+
species: readonly SizedSpecies[],
|
|
100
|
+
spawns: readonly SizedSpawn[] = [],
|
|
101
|
+
): string[] {
|
|
102
|
+
return species.flatMap((row): string[] => speciesSizeRules(row, spawns))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { CREATURE_SIZES, creatureScale, creatureHeight, creatureSizeRules }
|
|
106
|
+
export type { CreatureSizePolicy }
|
|
@@ -39,6 +39,10 @@ const STEER_BOOST_MIN = 1;
|
|
|
39
39
|
const STEER_LEAST = 0.005;
|
|
40
40
|
const STEER_SPEED_MAX = 60;
|
|
41
41
|
const STEER_TURN_MAX = Math.PI + Math.PI;
|
|
42
|
+
const STEER_PUSH_LEAST = 0;
|
|
43
|
+
const STEER_PUSH_MAX = 20;
|
|
44
|
+
/** SS-MS2a2: the look's wind on a sail, the ground direction it blows toward ([x, z], any length above 0) and the m/s a full sail adds straight downwind. */
|
|
45
|
+
const steerWind = v.strictObject({ toward: v.pipe(v.tuple([finite, finite]), v.someItem((axis: number): boolean => axis !== STEER_PUSH_LEAST, 'a wind push needs a direction')), push: bounded(STEER_PUSH_LEAST, STEER_PUSH_MAX) });
|
|
42
46
|
/** Numeric fixed policies compiled to the session's existing fenced guest driver. */
|
|
43
47
|
export const MoverDriverSchema: v.GenericSchema<MoverDriverRowsInput, MoverDriverRows> = v.variant('kind', [
|
|
44
48
|
v.strictObject({ kind: v.literal('waves'), damping: bounded(0, 1), waves: v.tuple([wave, wave, wave, wave]) }),
|
|
@@ -49,8 +53,8 @@ export const MoverDriverSchema: v.GenericSchema<MoverDriverRowsInput, MoverDrive
|
|
|
49
53
|
v.strictObject({ kind: v.literal('track') }),
|
|
50
54
|
v.strictObject({ kind: v.literal('pendulum'), axis: v.picklist(['x', 'y', 'z']), amplitude: bounded(0, Math.PI), period: bounded(0.005, 3600) }),
|
|
51
55
|
// SS-MS2a1: a vehicle its rider steers. Top speed (m/s), turn rate (rad/s), the boost multiplier, acceleration (m/s²),
|
|
52
|
-
// and whether it follows the ground under it or keeps its rest height. Board and leave are its carry's prompts.
|
|
53
|
-
v.strictObject({ kind: v.literal('steer'), speed: bounded(STEER_LEAST, STEER_SPEED_MAX), turn: bounded(STEER_LEAST, STEER_TURN_MAX), boost: bounded(STEER_BOOST_MIN, STEER_BOOST_MAX), accel: bounded(STEER_LEAST, STEER_ACCEL_MAX), ground: v.boolean() }),
|
|
56
|
+
// and whether it follows the ground under it or keeps its rest height. Board and leave are its carry's prompts; a wind push (SS-MS2a2) is optional.
|
|
57
|
+
v.strictObject({ kind: v.literal('steer'), speed: bounded(STEER_LEAST, STEER_SPEED_MAX), turn: bounded(STEER_LEAST, STEER_TURN_MAX), boost: bounded(STEER_BOOST_MIN, STEER_BOOST_MAX), accel: bounded(STEER_LEAST, STEER_ACCEL_MAX), ground: v.boolean(), wind: v.exactOptional(steerWind) }),
|
|
54
58
|
]);
|
|
55
59
|
/** Stop track, activation and fixed driver before ABI lowering. */
|
|
56
60
|
export const MoverMotionSchema: v.GenericSchema<MoverMotionRowsInput, MoverMotionRows> = v.strictObject({
|
|
@@ -99,7 +103,8 @@ export function lowerMoverMotion(input: unknown, rest: { at: { x: number; y: num
|
|
|
99
103
|
}
|
|
100
104
|
if (driver.kind === 'steer') {
|
|
101
105
|
if (trigger.kind !== 'interact' || Boolean(trigger.permission) || track !== undefined) { throw new Error('Steer driver requires an ungated board press without a clip'); }
|
|
102
|
-
|
|
106
|
+
const { wind } = driver, push = wind === undefined ? [] : [...wind.toward.map((axis: number): number => axis / Math.hypot(...wind.toward)), wind.push];
|
|
107
|
+
return { module: MOVER_DRIVER_MODULES.steer, input: [driver.speed, driver.turn, driver.boost, driver.accel, Number(driver.ground), rest.at.x, rest.at.y, rest.at.z, rest.euler.y, ...push] };
|
|
103
108
|
}
|
|
104
109
|
if (driver.kind === 'static') {
|
|
105
110
|
if (trigger.kind !== 'always' || track !== undefined) throw new Error('Static mover cannot consume a clip or interaction');
|
|
@@ -220,6 +225,7 @@ export type MoverDriverRows = ({
|
|
|
220
225
|
boost: number;
|
|
221
226
|
accel: number;
|
|
222
227
|
ground: boolean;
|
|
228
|
+
wind?: { toward: [number, number]; push: number };
|
|
223
229
|
});
|
|
224
230
|
interface MoverMotionRowsInputFields {
|
|
225
231
|
track?: MoverTrackRowsInput;
|
package/src/format/rows.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { sketchReference } from './sketch.ts';
|
|
|
9
9
|
import { JournalRowSchema, journalRowRules } from './compendiumRows.ts';
|
|
10
10
|
import { CreatureTypeSchema, CreatureBodySchema, CreatureTemperamentSchema, CreatureSensesSchema, CreatureAbilitySchema, CreaturePresentationSchema } from './creature-layers.ts';
|
|
11
11
|
import type { CreatureLayers } from './creature-layers.ts';
|
|
12
|
+
import { creatureSizeRules } from './creature-sizes.ts';
|
|
12
13
|
|
|
13
14
|
const id = v.pipe(v.string(), v.regex(/^[a-z][a-zA-Z0-9.:-]*$/u), v.maxLength(128));
|
|
14
15
|
const text = v.pipe(v.string(), v.maxLength(4096));
|
|
@@ -75,7 +76,7 @@ function rowRules(rows: ShardRows): string[] {
|
|
|
75
76
|
}
|
|
76
77
|
for (const d of rows.days) if (d.schedule[0]?.from !== 0 || d.schedule.at(-1)?.to !== 24 || d.schedule.some((s, i) => s.from >= s.to || (i > 0 && d.schedule[i - 1]?.to !== s.from))) errors.push('complete ordered day schedule');
|
|
77
78
|
const speciesIds = new Set(rows.species.map((s) => s.id));
|
|
78
|
-
errors.push(...strikeDebrisCatalogueRules(rows));
|
|
79
|
+
errors.push(...strikeDebrisCatalogueRules(rows), ...creatureSizeRules(rows.species));
|
|
79
80
|
for (const s of rows.species) if (new Set(s.variants.map((r) => r.id)).size !== s.variants.length || s.variants.some((r) => r.scale[1] > 10)) errors.push('species variants');
|
|
80
81
|
const strikeIds = new Set<string>();
|
|
81
82
|
for (const strikeRow of rows.strikes) { strikeIds.add(strikeRow.id); }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { creatureSizeRules } from './creature-sizes.ts';
|
|
1
2
|
import { readSpeciesPrograms } from './speciesPrograms.ts';
|
|
2
3
|
import type { StrikeDebrisPolicy } from './strike-debris.ts';
|
|
3
4
|
import { strikeDebrisCatalogueRules } from './strike-debris.ts';
|
|
@@ -367,6 +368,7 @@ export function shardfileRules(s: Shardfile, sections?: ReadonlyMap<string, unkn
|
|
|
367
368
|
if (crowdMembers > 4096) errors.push('declared crowd member capacity');
|
|
368
369
|
if (s.crowds.some(row => Math.abs(row.x) > CHUNK_HALF || Math.abs(row.z) > CHUNK_HALF)) errors.push('declared crowd home in cell');
|
|
369
370
|
if (s.creatures.spawns.length + crowdMembers > s.serverBudget.entities) errors.push('declared entity capacity');
|
|
371
|
+
errors.push(...creatureSizeRules(s.rows.species, s.creatures.spawns));
|
|
370
372
|
for (const spawn of s.creatures.spawns) if (!species.get(spawn.species)?.variants.some((row) => row.id === spawn.variant) || (spawn.strike !== null && !strikes.has(spawn.strike))) errors.push('declared spawn species/variant/strike');
|
|
371
373
|
errors.push(...encounterRules(s.encounters, s.creatures.spawns.map((spawn) => spawn.id), s.ui.filter((row) => row.kind === 'bossPanel')));
|
|
372
374
|
const controlled = new Set(s.encounters.map((row) => row.entity));
|