@wildshard/shard-format 0.21.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.21.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 }
@@ -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));