@v12-engine/engine 0.0.0-stage → 0.1.1

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.
Files changed (341) hide show
  1. package/LICENSE +21 -0
  2. package/dist/abilities/buffs.d.ts +83 -0
  3. package/dist/abilities/castTold.d.ts +12 -0
  4. package/dist/abilities/charges.d.ts +28 -0
  5. package/dist/abilities/dispel.d.ts +9 -0
  6. package/dist/abilities/effectFields.d.ts +10 -0
  7. package/dist/abilities/effects/buff.d.ts +8 -0
  8. package/dist/abilities/effects/core.d.ts +1 -0
  9. package/dist/abilities/effects/damage.d.ts +1 -0
  10. package/dist/abilities/effects/heal.d.ts +2 -0
  11. package/dist/abilities/effects/missile.d.ts +1 -0
  12. package/dist/abilities/effects/moves.d.ts +11 -0
  13. package/dist/abilities/effects/passives.d.ts +15 -0
  14. package/dist/abilities/effects/sight.d.ts +4 -0
  15. package/dist/abilities/effects/spawn.d.ts +2 -0
  16. package/dist/abilities/effects/timed.d.ts +4 -0
  17. package/dist/abilities/effects/trade.d.ts +1 -0
  18. package/dist/abilities/effects.d.ts +122 -0
  19. package/dist/abilities/land.d.ts +21 -0
  20. package/dist/abilities/scaled.d.ts +21 -0
  21. package/dist/abilities/text.d.ts +113 -0
  22. package/dist/ai/area.d.ts +53 -0
  23. package/dist/ai/brain.d.ts +528 -0
  24. package/dist/ai/budget.d.ts +67 -0
  25. package/dist/ai/checks.d.ts +115 -0
  26. package/dist/ai/computer.d.ts +166 -0
  27. package/dist/ai/defence.d.ts +108 -0
  28. package/dist/ai/define.d.ts +21 -0
  29. package/dist/ai/economy.d.ts +129 -0
  30. package/dist/ai/geometry.d.ts +35 -0
  31. package/dist/ai/goals.d.ts +360 -0
  32. package/dist/ai/index.d.ts +38 -0
  33. package/dist/ai/knowledge.d.ts +418 -0
  34. package/dist/ai/lanes.d.ts +232 -0
  35. package/dist/ai/melee/build.d.ts +61 -0
  36. package/dist/ai/melee/goals.d.ts +299 -0
  37. package/dist/ai/melee/heroes.d.ts +27 -0
  38. package/dist/ai/melee/index.d.ts +14 -0
  39. package/dist/ai/melee/production.d.ts +8 -0
  40. package/dist/ai/melee/surrender.d.ts +24 -0
  41. package/dist/ai/micro.d.ts +278 -0
  42. package/dist/ai/mission.d.ts +195 -0
  43. package/dist/ai/missionRules.d.ts +18 -0
  44. package/dist/ai/module.d.ts +116 -0
  45. package/dist/ai/options.d.ts +61 -0
  46. package/dist/ai/plans/build.d.ts +280 -0
  47. package/dist/ai/plans/placement.d.ts +82 -0
  48. package/dist/ai/plans/plans.d.ts +105 -0
  49. package/dist/ai/plans/production.d.ts +210 -0
  50. package/dist/ai/plans/purse.d.ts +73 -0
  51. package/dist/ai/plans/tech.d.ts +37 -0
  52. package/dist/ai/profiles.d.ts +204 -0
  53. package/dist/ai/reach.d.ts +4 -0
  54. package/dist/ai/report.d.ts +203 -0
  55. package/dist/ai/roles.d.ts +133 -0
  56. package/dist/ai/rules.d.ts +288 -0
  57. package/dist/ai/scouting.d.ts +98 -0
  58. package/dist/ai/settings.d.ts +73 -0
  59. package/dist/ai/squads.d.ts +429 -0
  60. package/dist/ai/strength.d.ts +167 -0
  61. package/dist/ai/task.d.ts +118 -0
  62. package/dist/ai/tasks/attack.d.ts +7 -0
  63. package/dist/ai/tasks/capture.d.ts +21 -0
  64. package/dist/ai/tasks/creep.d.ts +16 -0
  65. package/dist/ai/tasks/defend.d.ts +29 -0
  66. package/dist/ai/tasks/drop.d.ts +34 -0
  67. package/dist/ai/tasks/escort.d.ts +16 -0
  68. package/dist/ai/tasks/gather.d.ts +23 -0
  69. package/dist/ai/tasks/harass.d.ts +7 -0
  70. package/dist/ai/tasks/hold.d.ts +20 -0
  71. package/dist/ai/tasks/index.d.ts +32 -0
  72. package/dist/ai/tasks/move.d.ts +19 -0
  73. package/dist/ai/tasks/patrol.d.ts +8 -0
  74. package/dist/ai/tasks/retreat.d.ts +20 -0
  75. package/dist/ai/tasks/scout.d.ts +29 -0
  76. package/dist/ai/tasks/shared.d.ts +74 -0
  77. package/dist/ai/team.d.ts +155 -0
  78. package/dist/ai/threat.d.ts +91 -0
  79. package/dist/ai/view.d.ts +366 -0
  80. package/dist/ai/waves.d.ts +126 -0
  81. package/dist/ai.js +6239 -0
  82. package/dist/ai.js.map +1 -0
  83. package/dist/aiTesting.d.ts +179 -0
  84. package/dist/areas.d.ts +149 -0
  85. package/dist/attacks.d.ts +66 -0
  86. package/dist/attributes.d.ts +66 -0
  87. package/dist/brain-BvVdUhX8.js +7659 -0
  88. package/dist/brain-BvVdUhX8.js.map +1 -0
  89. package/dist/builds-C6LfgvEU.js +460 -0
  90. package/dist/builds-C6LfgvEU.js.map +1 -0
  91. package/dist/bytes.d.ts +6 -0
  92. package/dist/camps.d.ts +95 -0
  93. package/dist/capture.d.ts +131 -0
  94. package/dist/cellLayers.d.ts +75 -0
  95. package/dist/cinematics.d.ts +194 -0
  96. package/dist/clock.d.ts +32 -0
  97. package/dist/commands.d.ts +235 -0
  98. package/dist/components.d.ts +184 -0
  99. package/dist/computers.d.ts +108 -0
  100. package/dist/concealment.d.ts +61 -0
  101. package/dist/coreComponents-syuh2fPG.js +5149 -0
  102. package/dist/coreComponents-syuh2fPG.js.map +1 -0
  103. package/dist/coreComponents.d.ts +1 -0
  104. package/dist/dashing.d.ts +8 -0
  105. package/dist/debug.d.ts +36 -0
  106. package/dist/debug.js +3 -0
  107. package/dist/debugCommands-CzjrSm66.js +14739 -0
  108. package/dist/debugCommands-CzjrSm66.js.map +1 -0
  109. package/dist/debugCommands.d.ts +213 -0
  110. package/dist/debugging.d.ts +10 -0
  111. package/dist/definitions.d.ts +43 -0
  112. package/dist/defs.d.ts +1162 -0
  113. package/dist/denying.d.ts +81 -0
  114. package/dist/destructibles.d.ts +27 -0
  115. package/dist/determinism-BCymQwiE.js +518 -0
  116. package/dist/determinism-BCymQwiE.js.map +1 -0
  117. package/dist/determinism.d.ts +121 -0
  118. package/dist/dialog.d.ts +94 -0
  119. package/dist/effectRefs.d.ts +16 -0
  120. package/dist/effects.d.ts +80 -0
  121. package/dist/endings.d.ts +22 -0
  122. package/dist/engagement.d.ts +108 -0
  123. package/dist/engineEvents.d.ts +710 -0
  124. package/dist/entity.d.ts +409 -0
  125. package/dist/entityIndex.d.ts +50 -0
  126. package/dist/errors.d.ts +85 -0
  127. package/dist/events.d.ts +97 -0
  128. package/dist/exactMath.d.ts +63 -0
  129. package/dist/features.d.ts +10 -0
  130. package/dist/fields.d.ts +114 -0
  131. package/dist/fixture.d.ts +17 -0
  132. package/dist/fog.d.ts +110 -0
  133. package/dist/formation.d.ts +111 -0
  134. package/dist/friendlyFire.d.ts +26 -0
  135. package/dist/game-DiJEN-Ks.js +5800 -0
  136. package/dist/game-DiJEN-Ks.js.map +1 -0
  137. package/dist/game.d.ts +501 -0
  138. package/dist/gameData.d.ts +325 -0
  139. package/dist/gameFiles.d.ts +26 -0
  140. package/dist/gates.d.ts +28 -0
  141. package/dist/generate.d.ts +403 -0
  142. package/dist/generateWorker.d.ts +39 -0
  143. package/dist/grid.d.ts +53 -0
  144. package/dist/ground.d.ts +127 -0
  145. package/dist/groundSpeed.d.ts +22 -0
  146. package/dist/hero.d.ts +177 -0
  147. package/dist/home.d.ts +14 -0
  148. package/dist/hooks.d.ts +780 -0
  149. package/dist/hotReload.d.ts +76 -0
  150. package/dist/ids.d.ts +26 -0
  151. package/dist/index.d.ts +227 -0
  152. package/dist/index.js +4701 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/inspect-D9dWHmZ0.js +491 -0
  155. package/dist/inspect-D9dWHmZ0.js.map +1 -0
  156. package/dist/inspect.d.ts +176 -0
  157. package/dist/inventory.d.ts +18 -0
  158. package/dist/items.d.ts +91 -0
  159. package/dist/lanes.d.ts +213 -0
  160. package/dist/life.d.ts +53 -0
  161. package/dist/local-Dkovq42k.js +1379 -0
  162. package/dist/local-Dkovq42k.js.map +1 -0
  163. package/dist/log.d.ts +140 -0
  164. package/dist/manaBurn.d.ts +39 -0
  165. package/dist/map/file.d.ts +114 -0
  166. package/dist/map/images.d.ts +18 -0
  167. package/dist/map/look.d.ts +47 -0
  168. package/dist/map/pathProfile.d.ts +13 -0
  169. package/dist/map/resize.d.ts +54 -0
  170. package/dist/map/schema.d.ts +10 -0
  171. package/dist/map/terrain.d.ts +32 -0
  172. package/dist/map/types.d.ts +613 -0
  173. package/dist/map.d.ts +7 -0
  174. package/dist/mapCheck/cells.d.ts +19 -0
  175. package/dist/mapCheck/rule.d.ts +30 -0
  176. package/dist/mapCheck/rules/names.d.ts +3 -0
  177. package/dist/mapCheck/rules/objects.d.ts +3 -0
  178. package/dist/mapCheck/rules/paths.d.ts +3 -0
  179. package/dist/mapCheck/rules/players.d.ts +3 -0
  180. package/dist/mapCheck/rules/races.d.ts +3 -0
  181. package/dist/mapCheck/rules/random.d.ts +3 -0
  182. package/dist/mapCheck/rules/regions.d.ts +3 -0
  183. package/dist/mapCheck/rules/targets.d.ts +3 -0
  184. package/dist/mapCheck/rules/walking.d.ts +3 -0
  185. package/dist/mapCheck.d.ts +23 -0
  186. package/dist/mapFields.d.ts +364 -0
  187. package/dist/mapFile.d.ts +23 -0
  188. package/dist/mapMeasure.d.ts +95 -0
  189. package/dist/mapMerge.d.ts +19 -0
  190. package/dist/mapObjectives.d.ts +82 -0
  191. package/dist/mapObjects.d.ts +1 -0
  192. package/dist/math.d.ts +44 -0
  193. package/dist/messages.d.ts +150 -0
  194. package/dist/missionRules-C-bGxm0Q.js +523 -0
  195. package/dist/missionRules-C-bGxm0Q.js.map +1 -0
  196. package/dist/missionRules.d.ts +179 -0
  197. package/dist/mods.d.ts +146 -0
  198. package/dist/names.d.ts +93 -0
  199. package/dist/navigation/agentParams.d.ts +4 -0
  200. package/dist/navigation/air.d.ts +89 -0
  201. package/dist/navigation/builds.d.ts +140 -0
  202. package/dist/navigation/groundAreas.d.ts +23 -0
  203. package/dist/navigation/navigation.d.ts +127 -0
  204. package/dist/navigation/recast.d.ts +214 -0
  205. package/dist/navigation/sidePaths.d.ts +69 -0
  206. package/dist/navigation/sized.d.ts +1 -0
  207. package/dist/navigation-worker.js +11 -0
  208. package/dist/navigation-worker.js.map +1 -0
  209. package/dist/nearest.d.ts +8 -0
  210. package/dist/noise.d.ts +12 -0
  211. package/dist/objectives.d.ts +93 -0
  212. package/dist/orders/basic.d.ts +96 -0
  213. package/dist/orders/build.d.ts +91 -0
  214. package/dist/orders/cast.d.ts +105 -0
  215. package/dist/orders/facts.d.ts +14 -0
  216. package/dist/orders/harvest.d.ts +94 -0
  217. package/dist/orders/idle.d.ts +7 -0
  218. package/dist/orders/items.d.ts +14 -0
  219. package/dist/orders/queue.d.ts +24 -0
  220. package/dist/pack.schema.json +6621 -0
  221. package/dist/packs/director/index.d.ts +81 -0
  222. package/dist/packs/heroes/campaign.d.ts +137 -0
  223. package/dist/packs/heroes/carry.d.ts +59 -0
  224. package/dist/packs/heroes/commands.d.ts +6 -0
  225. package/dist/packs/heroes/hire.d.ts +9 -0
  226. package/dist/packs/heroes/index.d.ts +12 -0
  227. package/dist/packs/heroes/making.d.ts +16 -0
  228. package/dist/packs/heroes/respawn.d.ts +42 -0
  229. package/dist/packs/moba/index.d.ts +34 -0
  230. package/dist/packs/pack.d.ts +84 -0
  231. package/dist/packs-g5thvmGn.js +3199 -0
  232. package/dist/packs-g5thvmGn.js.map +1 -0
  233. package/dist/packs.d.ts +84 -0
  234. package/dist/paths.d.ts +51 -0
  235. package/dist/plain.d.ts +17 -0
  236. package/dist/player.d.ts +117 -0
  237. package/dist/portals.d.ts +66 -0
  238. package/dist/prefabs.d.ts +139 -0
  239. package/dist/presetBuildings.d.ts +52 -0
  240. package/dist/presetGround.d.ts +22 -0
  241. package/dist/profiles-B3NS9jwk.js +335 -0
  242. package/dist/profiles-B3NS9jwk.js.map +1 -0
  243. package/dist/races.d.ts +136 -0
  244. package/dist/randomGroups.d.ts +2 -0
  245. package/dist/registry.d.ts +464 -0
  246. package/dist/remains.d.ts +119 -0
  247. package/dist/replication.d.ts +103 -0
  248. package/dist/rng.d.ts +17 -0
  249. package/dist/rules.d.ts +395 -0
  250. package/dist/rulesCheck.d.ts +37 -0
  251. package/dist/runes.d.ts +41 -0
  252. package/dist/save.d.ts +277 -0
  253. package/dist/scenario.d.ts +56 -0
  254. package/dist/scheduler.d.ts +67 -0
  255. package/dist/score.d.ts +306 -0
  256. package/dist/sequences.d.ts +132 -0
  257. package/dist/server/doorman.d.ts +21 -0
  258. package/dist/server/gameServer.d.ts +346 -0
  259. package/dist/server/index.d.ts +24 -0
  260. package/dist/server/lobby.d.ts +1 -0
  261. package/dist/server/log.d.ts +13 -0
  262. package/dist/server/match.d.ts +24 -0
  263. package/dist/server/mode.d.ts +168 -0
  264. package/dist/server/navigation-worker.d.ts +1 -0
  265. package/dist/server/navigation.d.ts +11 -0
  266. package/dist/server/ops.d.ts +78 -0
  267. package/dist/server/packs.d.ts +15 -0
  268. package/dist/server/ratings.d.ts +62 -0
  269. package/dist/server/relay.d.ts +34 -0
  270. package/dist/server/rooms.d.ts +162 -0
  271. package/dist/server/seat.d.ts +2 -0
  272. package/dist/server/seatSettings.d.ts +15 -0
  273. package/dist/server/secret.d.ts +5 -0
  274. package/dist/server/start.d.ts +54 -0
  275. package/dist/server/websocket.d.ts +74 -0
  276. package/dist/server.js +2861 -0
  277. package/dist/server.js.map +1 -0
  278. package/dist/session/can.d.ts +20 -0
  279. package/dist/session/commandReplay.d.ts +92 -0
  280. package/dist/session/debug.d.ts +65 -0
  281. package/dist/session/delay.d.ts +15 -0
  282. package/dist/session/delta.d.ts +98 -0
  283. package/dist/session/entityState.d.ts +1 -0
  284. package/dist/session/local.d.ts +214 -0
  285. package/dist/session/memory.d.ts +27 -0
  286. package/dist/session/protocol.d.ts +1155 -0
  287. package/dist/session/remote.d.ts +530 -0
  288. package/dist/session/replay.d.ts +114 -0
  289. package/dist/session/seed.d.ts +7 -0
  290. package/dist/session/share.d.ts +78 -0
  291. package/dist/session/socket.d.ts +8 -0
  292. package/dist/session/wire.d.ts +153 -0
  293. package/dist/session/worker.d.ts +227 -0
  294. package/dist/shared.d.ts +171 -0
  295. package/dist/sides.d.ts +75 -0
  296. package/dist/sight.d.ts +27 -0
  297. package/dist/simulate-oXBiw1Ff.js +167 -0
  298. package/dist/simulate-oXBiw1Ff.js.map +1 -0
  299. package/dist/simulate-worker.d.ts +1 -0
  300. package/dist/simulate-worker.js +28 -0
  301. package/dist/simulate-worker.js.map +1 -0
  302. package/dist/simulate.d.ts +154 -0
  303. package/dist/smart.d.ts +9 -0
  304. package/dist/spatial.d.ts +62 -0
  305. package/dist/spawning.d.ts +33 -0
  306. package/dist/stances.d.ts +76 -0
  307. package/dist/start.d.ts +71 -0
  308. package/dist/stats.d.ts +122 -0
  309. package/dist/summons.d.ts +63 -0
  310. package/dist/systems/abilities.d.ts +3 -0
  311. package/dist/systems/combat.d.ts +71 -0
  312. package/dist/systems/combatTold.d.ts +14 -0
  313. package/dist/systems/construction.d.ts +34 -0
  314. package/dist/systems/economy.d.ts +21 -0
  315. package/dist/systems/fog.d.ts +19 -0
  316. package/dist/systems/life.d.ts +3 -0
  317. package/dist/systems/movement.d.ts +105 -0
  318. package/dist/systems/orders.d.ts +7 -0
  319. package/dist/systems/production.d.ts +49 -0
  320. package/dist/systems/productionQueue.d.ts +40 -0
  321. package/dist/systems/victory.d.ts +14 -0
  322. package/dist/talk.d.ts +65 -0
  323. package/dist/tech.d.ts +62 -0
  324. package/dist/techTree.d.ts +38 -0
  325. package/dist/terrain.d.ts +173 -0
  326. package/dist/terrainSave.d.ts +29 -0
  327. package/dist/testing.d.ts +58 -0
  328. package/dist/testing.js +822 -0
  329. package/dist/testing.js.map +1 -0
  330. package/dist/tiles.d.ts +34 -0
  331. package/dist/timers.d.ts +146 -0
  332. package/dist/tomes.d.ts +48 -0
  333. package/dist/trade.d.ts +28 -0
  334. package/dist/transport.d.ts +76 -0
  335. package/dist/tunables.d.ts +45 -0
  336. package/dist/upkeep.d.ts +16 -0
  337. package/dist/veterancy.d.ts +80 -0
  338. package/dist/walls.d.ts +86 -0
  339. package/dist/world.d.ts +1118 -0
  340. package/package.json +80 -5
  341. package/README.md +0 -3
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The maths the simulation does, the same to the last bit in every engine (determinism D3). JavaScript says exactly
3
+ * what `+`, `-`, `*`, `/` and `Math.sqrt` give, but not `Math.sin`, `Math.cos`, `Math.atan`, `Math.atan2` or
4
+ * `Math.hypot`: V8, SpiderMonkey and JavaScriptCore each have their own, and two versions of one can differ (Node 22's
5
+ * `atan2` and Chromium's do, in the last bit). These are fdlibm's (FreeBSD's msun), written with what is exact
6
+ * everywhere, so a world run in a page, in a worker, on a server or in a replay comes out the same.
7
+ *
8
+ * Within a unit in the last place of `Math`'s; they are not faster. What only draws (a view, an effect) has no need of
9
+ * them: what decides does
10
+ */
11
+ /**
12
+ * The sine, the same in every engine (fdlibm's)
13
+ *
14
+ * @beta
15
+ */
16
+ export declare function sin(x: number): number;
17
+ /**
18
+ * The cosine, the same in every engine (fdlibm's)
19
+ *
20
+ * @beta
21
+ */
22
+ export declare function cos(x: number): number;
23
+ /**
24
+ * The arctangent, the same in every engine (fdlibm's)
25
+ *
26
+ * @beta
27
+ */
28
+ export declare function atan(x: number): number;
29
+ /**
30
+ * The angle of a point from the x axis, `atan2(y, x)`, the same in every engine (fdlibm's)
31
+ *
32
+ * @beta
33
+ */
34
+ export declare function atan2(y: number, x: number): number;
35
+ /**
36
+ * The length of `(x, y)`, `√(x² + y²)`, the same in every engine (`Math.hypot` is not: it scales its arguments as each
37
+ * engine likes). For the lengths of a game, which are neither near 1e154 nor near 1e-154
38
+ *
39
+ * @beta
40
+ */
41
+ export declare const hypot: (x: number, y: number) => number;
42
+ /**
43
+ * e^x, the same in every engine (`Math.exp` is not: each has its own): `x` is split into a count of ln 2 and a
44
+ * remainder under half of one, the remainder's exponential is its Taylor series (adding and multiplying alone, which
45
+ * are exact everywhere), and the result is that doubled or halved the count of times. Within a few units in the last
46
+ * place of `Math.exp`'s; the point is sameness, not speed. What a response curve of the computer player's is made of
47
+ * (`curve.saturate`, AI plan B1)
48
+ */
49
+ export declare function exp(x: number): number;
50
+ /**
51
+ * The simulation's maths, the same in every engine: what a game's rules use in the place of `Math`'s, so that its
52
+ * worlds come out the same in a page, on a server and in a replay (`sin`, `cos`, `atan`, `atan2`, `hypot`, `exp`)
53
+ *
54
+ * @beta
55
+ */
56
+ export declare const exactMath: {
57
+ readonly sin: typeof sin;
58
+ readonly cos: typeof cos;
59
+ readonly atan: typeof atan;
60
+ readonly atan2: typeof atan2;
61
+ readonly hypot: typeof hypot;
62
+ readonly exp: typeof exp;
63
+ };
@@ -0,0 +1,10 @@
1
+ import { type HookDef } from './hooks';
2
+ /**
3
+ * The rules the engine brings along, written as hook handlers like any game module's. A module can leave any
4
+ * of them out by id (`GameModule.withoutHooks`), or put its own in place of one by giving a handler the same id.
5
+ *
6
+ * @beta
7
+ */
8
+ export declare const coreHooks: HookDef[];
9
+ /** A bounty, to whoever got it */
10
+ export declare const toldBounty: import("./replication").ReplicatedEvent;
@@ -0,0 +1,114 @@
1
+ import type { Vec2 } from './math';
2
+ /**
3
+ * Checkers for what comes in from the outside, like the commands of a player. On a server that is whatever
4
+ * anyone sends, so nothing is taken on trust: a checker either hands back the value as the type it promises,
5
+ * or throws `Invalid` saying what is wrong with it, and where (`td.intro.lanes[2].items[0].at is a number`): the
6
+ * commands of a player, a cinematic's file, a lane's own items and the game's other files are checked by these alike.
7
+ *
8
+ * ```ts
9
+ * const fields = { building: id, unitType: string, queue: optional(bool) }
10
+ * type Fields = Checked<typeof fields> // { building: number; unitType: string; queue?: boolean }
11
+ * ```
12
+ *
13
+ * @beta
14
+ */
15
+ export type Check<T> = (value: unknown, path: string) => T;
16
+ /**
17
+ * A set of named checkers: what an object must have
18
+ *
19
+ * @beta
20
+ */
21
+ export type Fields = Record<string, Check<unknown>>;
22
+ type Out<C> = C extends Check<infer T> ? T : never;
23
+ /** The fields a checker lets be left out: the ones it may hand back `undefined` for */
24
+ type OptionalKeys<F extends Fields> = {
25
+ [K in keyof F]: undefined extends Out<F[K]> ? K : never;
26
+ }[keyof F];
27
+ /**
28
+ * The type a set of checkers hands back. Fields that may be left out are optional
29
+ *
30
+ * @beta
31
+ */
32
+ export type Checked<F extends Fields> = {
33
+ [K in keyof F as K extends OptionalKeys<F> ? never : K]: Out<F[K]>;
34
+ } & {
35
+ [K in OptionalKeys<F>]?: Exclude<Out<F[K]>, undefined>;
36
+ };
37
+ /** @beta */
38
+ export declare class Invalid extends Error {
39
+ }
40
+ /**
41
+ * Whether a value is a plain object (not a list, not null): what most of a file's fields are
42
+ *
43
+ * @beta
44
+ */
45
+ export declare const isObject: (value: unknown) => value is Record<string, unknown>;
46
+ /** @beta */
47
+ export declare const bool: Check<boolean>;
48
+ /**
49
+ * Any finite number
50
+ *
51
+ * @beta
52
+ */
53
+ export declare const number: Check<number>;
54
+ /**
55
+ * A whole number, 0 or more
56
+ *
57
+ * @beta
58
+ */
59
+ export declare const index: Check<number>;
60
+ /**
61
+ * The id of an entity or a player
62
+ *
63
+ * @beta
64
+ */
65
+ export declare const id: Check<number>;
66
+ /**
67
+ * Any number of seconds: a finite number, not below 0
68
+ *
69
+ * @beta
70
+ */
71
+ export declare const seconds: Check<number>;
72
+ /**
73
+ * Words of any length: what a file says (a line of dialog, a name), not what a player sends (`string`)
74
+ *
75
+ * @beta
76
+ */
77
+ export declare const text: Check<string>;
78
+ /**
79
+ * A colour as the client draws it: `[r, g, b]`, each a number
80
+ *
81
+ * @beta
82
+ */
83
+ export declare const rgb: Check<[number, number, number]>;
84
+ /**
85
+ * A list of anything, or none for one left out: each of its values checked by the caller, by its own path
86
+ *
87
+ * @beta
88
+ */
89
+ export declare const list: Check<unknown[]>;
90
+ /** @beta */
91
+ export declare const string: Check<string>;
92
+ /** @beta */
93
+ export declare const ids: Check<number[]>;
94
+ /** @beta */
95
+ export declare const point: Check<Vec2>;
96
+ /**
97
+ * What may be left out
98
+ *
99
+ * @beta
100
+ */
101
+ export declare function optional<T>(check: Check<T>): Check<T | undefined>;
102
+ /**
103
+ * One of a few fixed values
104
+ *
105
+ * @beta
106
+ */
107
+ export declare function oneOf<const T extends readonly (string | number)[]>(...values: T): Check<T[number]>;
108
+ /**
109
+ * An object with these fields. Fields that are not asked for are dropped, so nothing unchecked gets through
110
+ *
111
+ * @beta
112
+ */
113
+ export declare function object<F extends Fields>(fields: F): Check<Checked<F>>;
114
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { GameModule } from './game';
2
+ import { type GameMap } from './map';
3
+ /**
4
+ * The fixture game (see the top of this file): every role of the kit, with round numbers. Gold and lumber, 1000 of each
5
+ * to start with; a hall and five workers at each start; heroes on (`withHeroes`); no fog explored at the start. A new
6
+ * one each time, for a test to change
7
+ *
8
+ * @beta
9
+ */
10
+ export declare function fixtureGame(): GameModule;
11
+ /**
12
+ * A map of the fixture game, 64 cells a side: two players, starting at opposite corners (12, 12 and 52, 52), a gold
13
+ * mine and a row of trees by each start, and a camp of three creeps in the middle
14
+ *
15
+ * @beta
16
+ */
17
+ export declare function fixtureMap(): GameMap;
package/dist/fog.d.ts ADDED
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Per team visibility of the map, one cell per world unit.
3
+ *
4
+ * Each team has two grids. `visible` is what the team sees right now and is cleared and drawn again
5
+ * on every update. `explored` only ever gets set: ground the team has looked at at least once, which
6
+ * is drawn as the dimmed "explored" fog and lets players build there.
7
+ */
8
+ /** The fog in a save, see `FogOfWar.save` */
9
+ export interface FogSave {
10
+ version: number;
11
+ revealed: number[];
12
+ /** Cells of each team, packed */
13
+ teams: Record<number, {
14
+ visible: string;
15
+ explored: string;
16
+ }>;
17
+ /**
18
+ * Each team's bit in the masks entities keep (`Entity.seenBy`): in the order teams first had fog, which a world loaded
19
+ * from the save would not know otherwise once a player has moved to another team. Saves from before it numbered them
20
+ * from the teams the world was made with
21
+ */
22
+ bits?: Record<number, number>;
23
+ /** Whether the map is explored from the start, for the teams to come too (`FogOfWar.exploredFromStart`) */
24
+ exploredFromStart?: true;
25
+ }
26
+ /** @beta */
27
+ export declare class FogOfWar {
28
+ readonly width: number;
29
+ readonly depth: number;
30
+ private readonly visible;
31
+ private readonly explored;
32
+ private readonly revealed;
33
+ /**
34
+ * One bit per team, for per-entity bitmasks like `Entity.seenBy`. Team ids come from the map and can be
35
+ * any number (the creeps are team 1000), so they are numbered 0, 1, 2... here instead of being used as
36
+ * bit positions directly: `1 << 1000` is `1 << 8` in JavaScript and would mix up two teams.
37
+ */
38
+ private readonly bits;
39
+ private readonly levels;
40
+ /**
41
+ * What is being lit during an update (`beginUpdate`), a bit a cell, a row of the map `words` of 32 bits: a row of a
42
+ * circle is a word or two, not hundreds of cells. Written into the grids as the update ends
43
+ */
44
+ private readonly lit;
45
+ private readonly words;
46
+ private updating;
47
+ /** The cells at or under each level, as bits: what a viewer on that level sees of what it lights. Made as they are first asked for */
48
+ private readonly levelMasks;
49
+ /** The highest level of the ground: a viewer on it or above sees everything it lights. -1 until worked out */
50
+ private top;
51
+ /** Bumped every time visibility is recomputed */
52
+ version: number;
53
+ constructor(width: number, depth: number, teams: number[],
54
+ /** Level of every cell: nobody sees up a cliff. All on the ground floor when left out */
55
+ levels?: Uint8Array);
56
+ /** Gives a team that has none yet fog of its own: a player moved to a new team mid-game. Nothing for one there is */
57
+ addTeam(team: number): void;
58
+ /**
59
+ * Whether the whole map is explored from the start (`FogRules.startExplored`, `MapDef.explored`): every team's, and
60
+ * the teams' made from now on. What stands on it and is no player's is then known to every team from the first moment
61
+ * (the sessions' `TeamMemory.startKnown`). Set with `exploreFromStart`
62
+ */
63
+ exploredFromStart: boolean;
64
+ /** Grids for a team, and the first bit no other team has */
65
+ private makeTeam;
66
+ private freeBit;
67
+ /** The team's bit in per-entity team masks. 0 for a team without fog (neutral), which then never shows up in one */
68
+ /** What each team sees and has explored, for a save, with each team's bit */
69
+ save(): FogSave;
70
+ restore(save: FogSave): void;
71
+ teamBit(team: number): number;
72
+ get teams(): number[];
73
+ /** Debug switch: the team sees everything */
74
+ setRevealed(team: number, revealed: boolean): void;
75
+ isRevealed(team: number): boolean;
76
+ /**
77
+ * Starts working out what is seen: what is lit from here to `endUpdate` is collected as bits, and the grids
78
+ * are written when it ends, so `visible` and `explored` say what they did before until then
79
+ */
80
+ beginUpdate(): void;
81
+ endUpdate(): void;
82
+ /**
83
+ * Says the ground's levels changed (`Terrain.levels` written to while the world runs): what a viewer on a level sees
84
+ * is worked out from them once, and again after this
85
+ *
86
+ * @beta
87
+ */
88
+ levelsChanged(): void;
89
+ private highest;
90
+ private maskOf;
91
+ /** Lights up what a viewer at the point sees. Ground above the viewer's `level` stays dark, so a flyer passes Infinity */
92
+ reveal(team: number, x: number, z: number, radius: number, level?: number): void;
93
+ stateAt(team: number, x: number, z: number): number;
94
+ isVisible(team: number, x: number, z: number): boolean;
95
+ isExplored(team: number, x: number, z: number): boolean;
96
+ /** A team has seen every cell once: the map starts explored for it */
97
+ exploreAll(team: number): void;
98
+ /**
99
+ * The whole map explored from the start, for every team and the teams to come (`exploredFromStart`), or no longer:
100
+ * then each team has explored what it sees now, and no more (a debug switch, mid-game)
101
+ *
102
+ * @beta
103
+ */
104
+ exploreFromStart(on: boolean): void;
105
+ /** Raw per cell state for rendering */
106
+ cells(team: number): {
107
+ visible: Uint8Array;
108
+ explored: Uint8Array;
109
+ } | null;
110
+ }
@@ -0,0 +1,111 @@
1
+ import type { Entity, EntityId } from './entity';
2
+ import type { Vec2 } from './math';
3
+ import type { Navigation } from './navigation/navigation';
4
+ import type { World } from './world';
5
+ /**
6
+ * What a formation lays units out with: the group, where it is sent, the way there, and the room each unit takes.
7
+ * Points are in the world; `right` and `forward` are the formation's own axes, each a unit long, for a shape that is
8
+ * drawn facing the way of travel: a place `right * x + forward * z` from the target
9
+ *
10
+ * @beta
11
+ */
12
+ export interface FormationContext {
13
+ readonly world: World;
14
+ /** The units laid out: those that walk, or those that fly, apart */
15
+ readonly units: readonly Entity[];
16
+ readonly target: Vec2;
17
+ /** The navigation they go on, to find where they can stand */
18
+ readonly nav: Navigation;
19
+ /** The middle of where the units are */
20
+ readonly centre: Vec2;
21
+ /** The way from where they are to the target, a unit long (forward, where they face at the end) */
22
+ readonly forward: Vec2;
23
+ /** To the right of `forward`, a unit long */
24
+ readonly right: Vec2;
25
+ /** Room a unit takes: twice the biggest radius among them, and a gap of `FORMATION_GAP` */
26
+ readonly spacing: number;
27
+ /** A point in the world, `x` to the right of the target and `z` forward of it */
28
+ place(x: number, z: number): Vec2;
29
+ /** The nearest point a unit can stand on, or the target where there is none within 4 */
30
+ snap(point: Vec2): Vec2;
31
+ }
32
+ /**
33
+ * How units ordered to a point together are laid out around it (`OrderInit.formation`, `GameRules.movement.formation`): a
34
+ * shape, which the engine fits the units to, or the places themselves. The engine's own are `rows`, `circle`,
35
+ * `square` and `none` (`coreFormations`); a game adds its own (`GameModule.formations`), and changes any laid out
36
+ * with the `formation` hook
37
+ *
38
+ * @beta
39
+ */
40
+ export interface FormationDef {
41
+ id: string;
42
+ /** What the player sees it called */
43
+ name: string;
44
+ /**
45
+ * The shape, as `count` places `spacing` apart, in the formation's own space: `x` to the right, `z` forward, the
46
+ * first places at the front. Units are fitted to them so that their ways cross as little as can be
47
+ * (`fitToPlaces`): those ahead to the places at the front
48
+ */
49
+ shape?(count: number, spacing: number, context: FormationContext): Vec2[];
50
+ /**
51
+ * The places themselves, by the unit's id, when the shape is not enough: one that goes by who the units are, or
52
+ * where they stand. A unit given none goes to the target itself. Over `shape` where both are given
53
+ */
54
+ points?(context: FormationContext): Map<EntityId, Vec2>;
55
+ }
56
+ /**
57
+ * The gap between two units standing next to each other in a formation
58
+ *
59
+ * @beta
60
+ */
61
+ export declare const FORMATION_GAP = 0.35;
62
+ /**
63
+ * Fits units to places so that their ways cross as little as can be: the places in order, the front first, each to
64
+ * the unit nearest it, measured from where the group is to where it goes (the unit's place in the group against the
65
+ * place's in the formation). A unit left without a place goes to the target
66
+ *
67
+ * @beta
68
+ */
69
+ export declare function fitToPlaces(context: FormationContext, places: readonly Vec2[]): Map<EntityId, Vec2>;
70
+ /**
71
+ * The engine's usual formation: a tight group keeps its shape as it is, and a scattered one lines up in rows across
72
+ * the way of travel, as many across as there are rows, the units ahead in the front rows
73
+ *
74
+ * @beta
75
+ */
76
+ export declare const rowsFormation: FormationDef;
77
+ /**
78
+ * A circle: a ring around the target, the first place at the front, and rings within it where one is not enough for
79
+ * them all. The rings are a `spacing` apart, the first a `spacing` out: as many as it takes, the outer ones full
80
+ *
81
+ * @beta
82
+ */
83
+ export declare const circleFormation: FormationDef;
84
+ /**
85
+ * A square: units along the edges of one around the target, the first place at the front's middle, and squares
86
+ * within it where one is not enough for them all. The squares are a `spacing` apart, the first a `spacing` out: as
87
+ * many as it takes, the outer ones full
88
+ *
89
+ * @beta
90
+ */
91
+ export declare const squareFormation: FormationDef;
92
+ /**
93
+ * No formation: every unit to the point itself, as units sent one by one go
94
+ *
95
+ * @beta
96
+ */
97
+ export declare const noneFormation: FormationDef;
98
+ /**
99
+ * The engine's formations: `rows` (the usual), `circle`, `square` and `none`
100
+ *
101
+ * @beta
102
+ */
103
+ export declare const coreFormations: readonly FormationDef[];
104
+ /**
105
+ * Individual destinations for a group ordered to the same point, in a formation (`rowsFormation` when none is
106
+ * given), and what the `formation` hook makes of them. Units that walk and units that fly are laid out apart, each
107
+ * on their own navigation (`world.navFor`)
108
+ *
109
+ * @beta
110
+ */
111
+ export declare function formationPoints(world: World, units: readonly Entity[], target: Vec2, formation?: FormationDef): Map<EntityId, Vec2>;
@@ -0,0 +1,26 @@
1
+ import type { Entity } from './entity';
2
+ import type { GamePack } from './packs/pack';
3
+ import type { World } from './world';
4
+ /**
5
+ * The friendly fire pack's id
6
+ *
7
+ * @beta
8
+ */
9
+ export declare const FRIENDLY_FIRE = "core.friendlyFire";
10
+ /**
11
+ * What the friendly fire pack is made with (`withFriendlyFire`)
12
+ *
13
+ * @beta
14
+ */
15
+ export interface FriendlyFireOptions {
16
+ /** What of its own side's, and its allies', a unit may be told to attack: anything its attack reaches when left out */
17
+ attacks?: (world: World, attacker: Entity, target: Entity) => boolean;
18
+ }
19
+ /**
20
+ * Friendly fire, as in classic RTS games: a unit told to attack (the attack command, never a right click) one of its own or
21
+ * an ally's attacks it. Never of its own accord: units do not pick their own side to attack, nor fight back at it.
22
+ * Nothing of a neutral player's (a rock, a critter) is made a target by it
23
+ *
24
+ * @beta
25
+ */
26
+ export declare function withFriendlyFire(options?: FriendlyFireOptions): GamePack;