@its-not-rocket-science/ananke 0.1.14 → 0.1.16
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/CHANGELOG.md +44 -1
- package/dist/as/injury.wasm +0 -0
- package/dist/as/injury.wat +382 -0
- package/dist/as/push.wasm +0 -0
- package/dist/as/push.wat +326 -0
- package/dist/as/units.wasm +0 -0
- package/dist/as/units.wat +290 -0
- package/dist/src/battle-bridge.d.ts +94 -0
- package/dist/src/battle-bridge.js +126 -0
- package/dist/src/wasm-kernel.d.ts +58 -0
- package/dist/src/wasm-kernel.js +96 -0
- package/package.json +15 -2
package/dist/as/push.wat
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
(module
|
|
2
|
+
(type $0 (func (param i32) (result i32)))
|
|
3
|
+
(type $1 (func (param i32 i32 i32 i32)))
|
|
4
|
+
(type $2 (func (param i32 i32) (result i32)))
|
|
5
|
+
(type $3 (func (param i32 i32 i32)))
|
|
6
|
+
(global $as/push/MAX_ENTITIES i32 (i32.const 64))
|
|
7
|
+
(global $as/push/OFFSET_POS_X i32 (i32.const 0))
|
|
8
|
+
(global $as/push/OFFSET_POS_Y i32 (i32.const 256))
|
|
9
|
+
(global $as/push/OFFSET_ALIVE i32 (i32.const 512))
|
|
10
|
+
(global $as/push/OFFSET_DV_X i32 (i32.const 768))
|
|
11
|
+
(global $as/push/OFFSET_DV_Y i32 (i32.const 1024))
|
|
12
|
+
(memory $0 1)
|
|
13
|
+
(export "MAX_ENTITIES" (global $as/push/MAX_ENTITIES))
|
|
14
|
+
(export "OFFSET_POS_X" (global $as/push/OFFSET_POS_X))
|
|
15
|
+
(export "OFFSET_POS_Y" (global $as/push/OFFSET_POS_Y))
|
|
16
|
+
(export "OFFSET_ALIVE" (global $as/push/OFFSET_ALIVE))
|
|
17
|
+
(export "OFFSET_DV_X" (global $as/push/OFFSET_DV_X))
|
|
18
|
+
(export "OFFSET_DV_Y" (global $as/push/OFFSET_DV_Y))
|
|
19
|
+
(export "writeEntity" (func $as/push/writeEntity))
|
|
20
|
+
(export "readDvX" (func $as/push/readDvX))
|
|
21
|
+
(export "readDvY" (func $as/push/readDvY))
|
|
22
|
+
(export "approxDist" (func $as/push/approxDist))
|
|
23
|
+
(export "stepRepulsionPairs" (func $as/push/stepRepulsionPairs))
|
|
24
|
+
(export "memory" (memory $0))
|
|
25
|
+
(func $as/push/writeEntity (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
|
|
26
|
+
local.get $0
|
|
27
|
+
i32.const 2
|
|
28
|
+
i32.shl
|
|
29
|
+
local.tee $0
|
|
30
|
+
local.get $1
|
|
31
|
+
i32.store
|
|
32
|
+
local.get $0
|
|
33
|
+
local.get $2
|
|
34
|
+
i32.store offset=256
|
|
35
|
+
local.get $0
|
|
36
|
+
local.get $3
|
|
37
|
+
i32.store offset=512
|
|
38
|
+
)
|
|
39
|
+
(func $as/push/readDvX (param $0 i32) (result i32)
|
|
40
|
+
local.get $0
|
|
41
|
+
i32.const 2
|
|
42
|
+
i32.shl
|
|
43
|
+
i32.load offset=768
|
|
44
|
+
)
|
|
45
|
+
(func $as/push/readDvY (param $0 i32) (result i32)
|
|
46
|
+
local.get $0
|
|
47
|
+
i32.const 2
|
|
48
|
+
i32.shl
|
|
49
|
+
i32.const 1024
|
|
50
|
+
i32.add
|
|
51
|
+
i32.load
|
|
52
|
+
)
|
|
53
|
+
(func $as/push/approxDist (param $0 i32) (param $1 i32) (result i32)
|
|
54
|
+
i32.const 0
|
|
55
|
+
local.get $0
|
|
56
|
+
i32.sub
|
|
57
|
+
local.get $0
|
|
58
|
+
local.get $0
|
|
59
|
+
i32.const 0
|
|
60
|
+
i32.lt_s
|
|
61
|
+
select
|
|
62
|
+
local.tee $0
|
|
63
|
+
i32.const 0
|
|
64
|
+
local.get $1
|
|
65
|
+
i32.sub
|
|
66
|
+
local.get $1
|
|
67
|
+
local.get $1
|
|
68
|
+
i32.const 0
|
|
69
|
+
i32.lt_s
|
|
70
|
+
select
|
|
71
|
+
local.tee $1
|
|
72
|
+
i32.const 1
|
|
73
|
+
i32.shr_s
|
|
74
|
+
i32.add
|
|
75
|
+
local.get $1
|
|
76
|
+
local.get $0
|
|
77
|
+
i32.const 1
|
|
78
|
+
i32.shr_s
|
|
79
|
+
i32.add
|
|
80
|
+
local.get $0
|
|
81
|
+
local.get $1
|
|
82
|
+
i32.gt_s
|
|
83
|
+
select
|
|
84
|
+
)
|
|
85
|
+
(func $as/push/stepRepulsionPairs (param $0 i32) (param $1 i32) (param $2 i32)
|
|
86
|
+
(local $3 i32)
|
|
87
|
+
(local $4 i64)
|
|
88
|
+
(local $5 i32)
|
|
89
|
+
(local $6 i32)
|
|
90
|
+
(local $7 i32)
|
|
91
|
+
(local $8 i64)
|
|
92
|
+
(local $9 i32)
|
|
93
|
+
(local $10 i32)
|
|
94
|
+
(local $11 i64)
|
|
95
|
+
(local $12 i32)
|
|
96
|
+
(local $13 i64)
|
|
97
|
+
(local $14 i64)
|
|
98
|
+
(local $15 i32)
|
|
99
|
+
loop $for-loop|0
|
|
100
|
+
local.get $0
|
|
101
|
+
local.get $3
|
|
102
|
+
i32.gt_s
|
|
103
|
+
if
|
|
104
|
+
local.get $3
|
|
105
|
+
i32.const 2
|
|
106
|
+
i32.shl
|
|
107
|
+
local.tee $5
|
|
108
|
+
i32.const 0
|
|
109
|
+
i32.store offset=768
|
|
110
|
+
local.get $5
|
|
111
|
+
i32.const 1024
|
|
112
|
+
i32.add
|
|
113
|
+
i32.const 0
|
|
114
|
+
i32.store
|
|
115
|
+
local.get $3
|
|
116
|
+
i32.const 1
|
|
117
|
+
i32.add
|
|
118
|
+
local.set $3
|
|
119
|
+
br $for-loop|0
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
local.get $1
|
|
123
|
+
i64.extend_i32_s
|
|
124
|
+
local.tee $4
|
|
125
|
+
local.get $4
|
|
126
|
+
i64.mul
|
|
127
|
+
local.set $4
|
|
128
|
+
i32.const 0
|
|
129
|
+
local.set $3
|
|
130
|
+
loop $for-loop|1
|
|
131
|
+
local.get $3
|
|
132
|
+
local.get $0
|
|
133
|
+
i32.const 1
|
|
134
|
+
i32.sub
|
|
135
|
+
i32.lt_s
|
|
136
|
+
if
|
|
137
|
+
local.get $3
|
|
138
|
+
i32.const 2
|
|
139
|
+
i32.shl
|
|
140
|
+
local.tee $5
|
|
141
|
+
i32.load offset=512
|
|
142
|
+
if
|
|
143
|
+
local.get $5
|
|
144
|
+
i32.load
|
|
145
|
+
local.set $6
|
|
146
|
+
local.get $5
|
|
147
|
+
i32.load offset=256
|
|
148
|
+
local.set $7
|
|
149
|
+
local.get $3
|
|
150
|
+
i32.const 1
|
|
151
|
+
i32.add
|
|
152
|
+
local.set $5
|
|
153
|
+
loop $for-loop|2
|
|
154
|
+
local.get $0
|
|
155
|
+
local.get $5
|
|
156
|
+
i32.gt_s
|
|
157
|
+
if
|
|
158
|
+
block $for-continue|2
|
|
159
|
+
local.get $5
|
|
160
|
+
i32.const 2
|
|
161
|
+
i32.shl
|
|
162
|
+
local.tee $9
|
|
163
|
+
i32.load offset=512
|
|
164
|
+
i32.eqz
|
|
165
|
+
br_if $for-continue|2
|
|
166
|
+
local.get $9
|
|
167
|
+
i32.load
|
|
168
|
+
local.get $6
|
|
169
|
+
i32.sub
|
|
170
|
+
local.tee $10
|
|
171
|
+
i64.extend_i32_s
|
|
172
|
+
local.tee $11
|
|
173
|
+
local.get $11
|
|
174
|
+
i64.mul
|
|
175
|
+
local.get $9
|
|
176
|
+
i32.load offset=256
|
|
177
|
+
local.get $7
|
|
178
|
+
i32.sub
|
|
179
|
+
local.tee $12
|
|
180
|
+
i64.extend_i32_s
|
|
181
|
+
local.tee $13
|
|
182
|
+
local.get $13
|
|
183
|
+
i64.mul
|
|
184
|
+
i64.add
|
|
185
|
+
local.tee $8
|
|
186
|
+
i64.eqz
|
|
187
|
+
local.get $4
|
|
188
|
+
local.get $8
|
|
189
|
+
i64.le_s
|
|
190
|
+
i32.or
|
|
191
|
+
br_if $for-continue|2
|
|
192
|
+
local.get $1
|
|
193
|
+
i32.const 0
|
|
194
|
+
local.get $10
|
|
195
|
+
i32.sub
|
|
196
|
+
local.get $10
|
|
197
|
+
local.get $10
|
|
198
|
+
i32.const 0
|
|
199
|
+
i32.lt_s
|
|
200
|
+
select
|
|
201
|
+
local.tee $10
|
|
202
|
+
i32.const 0
|
|
203
|
+
local.get $12
|
|
204
|
+
i32.sub
|
|
205
|
+
local.get $12
|
|
206
|
+
local.get $12
|
|
207
|
+
i32.const 0
|
|
208
|
+
i32.lt_s
|
|
209
|
+
select
|
|
210
|
+
local.tee $12
|
|
211
|
+
i32.const 1
|
|
212
|
+
i32.shr_s
|
|
213
|
+
i32.add
|
|
214
|
+
local.get $12
|
|
215
|
+
local.get $10
|
|
216
|
+
i32.const 1
|
|
217
|
+
i32.shr_s
|
|
218
|
+
i32.add
|
|
219
|
+
local.get $10
|
|
220
|
+
local.get $12
|
|
221
|
+
i32.gt_s
|
|
222
|
+
select
|
|
223
|
+
local.tee $10
|
|
224
|
+
i32.sub
|
|
225
|
+
local.tee $12
|
|
226
|
+
i32.const 0
|
|
227
|
+
i32.le_s
|
|
228
|
+
br_if $for-continue|2
|
|
229
|
+
i32.const 10000
|
|
230
|
+
local.get $12
|
|
231
|
+
i32.const 10000
|
|
232
|
+
i32.mul
|
|
233
|
+
local.get $1
|
|
234
|
+
i32.div_s
|
|
235
|
+
local.tee $12
|
|
236
|
+
local.get $12
|
|
237
|
+
i32.const 10000
|
|
238
|
+
i32.gt_s
|
|
239
|
+
select
|
|
240
|
+
local.tee $12
|
|
241
|
+
i32.const 0
|
|
242
|
+
local.get $12
|
|
243
|
+
i32.const 0
|
|
244
|
+
i32.ge_s
|
|
245
|
+
select
|
|
246
|
+
i64.extend_i32_s
|
|
247
|
+
local.tee $14
|
|
248
|
+
local.get $2
|
|
249
|
+
i64.extend_i32_s
|
|
250
|
+
local.tee $8
|
|
251
|
+
local.get $11
|
|
252
|
+
i64.mul
|
|
253
|
+
i64.mul
|
|
254
|
+
i32.const 1
|
|
255
|
+
local.get $10
|
|
256
|
+
local.get $10
|
|
257
|
+
i32.const 0
|
|
258
|
+
i32.le_s
|
|
259
|
+
select
|
|
260
|
+
i64.extend_i32_s
|
|
261
|
+
i64.const 10000
|
|
262
|
+
i64.mul
|
|
263
|
+
local.tee $11
|
|
264
|
+
i64.div_s
|
|
265
|
+
i32.wrap_i64
|
|
266
|
+
local.set $10
|
|
267
|
+
local.get $8
|
|
268
|
+
local.get $13
|
|
269
|
+
i64.mul
|
|
270
|
+
local.get $14
|
|
271
|
+
i64.mul
|
|
272
|
+
local.get $11
|
|
273
|
+
i64.div_s
|
|
274
|
+
i32.wrap_i64
|
|
275
|
+
local.set $12
|
|
276
|
+
local.get $3
|
|
277
|
+
i32.const 2
|
|
278
|
+
i32.shl
|
|
279
|
+
local.tee $15
|
|
280
|
+
local.get $15
|
|
281
|
+
i32.load offset=768
|
|
282
|
+
local.get $10
|
|
283
|
+
i32.sub
|
|
284
|
+
i32.store offset=768
|
|
285
|
+
local.get $15
|
|
286
|
+
i32.const 1024
|
|
287
|
+
i32.add
|
|
288
|
+
local.tee $15
|
|
289
|
+
local.get $15
|
|
290
|
+
i32.load
|
|
291
|
+
local.get $12
|
|
292
|
+
i32.sub
|
|
293
|
+
i32.store
|
|
294
|
+
local.get $9
|
|
295
|
+
local.get $9
|
|
296
|
+
i32.load offset=768
|
|
297
|
+
local.get $10
|
|
298
|
+
i32.add
|
|
299
|
+
i32.store offset=768
|
|
300
|
+
local.get $9
|
|
301
|
+
i32.const 1024
|
|
302
|
+
i32.add
|
|
303
|
+
local.tee $9
|
|
304
|
+
local.get $9
|
|
305
|
+
i32.load
|
|
306
|
+
local.get $12
|
|
307
|
+
i32.add
|
|
308
|
+
i32.store
|
|
309
|
+
end
|
|
310
|
+
local.get $5
|
|
311
|
+
i32.const 1
|
|
312
|
+
i32.add
|
|
313
|
+
local.set $5
|
|
314
|
+
br $for-loop|2
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
local.get $3
|
|
319
|
+
i32.const 1
|
|
320
|
+
i32.add
|
|
321
|
+
local.set $3
|
|
322
|
+
br $for-loop|1
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
)
|
|
326
|
+
)
|
|
Binary file
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
(module
|
|
2
|
+
(type $0 (func (param f64) (result i32)))
|
|
3
|
+
(type $1 (func (param i32) (result f64)))
|
|
4
|
+
(type $2 (func (param i32 i32 i32) (result i32)))
|
|
5
|
+
(type $3 (func (param i32 i32) (result i32)))
|
|
6
|
+
(type $4 (func (param i32) (result i32)))
|
|
7
|
+
(global $as/units/SCALE_Q i32 (i32.const 10000))
|
|
8
|
+
(global $as/units/SCALE_m i32 (i32.const 10000))
|
|
9
|
+
(global $as/units/SCALE_s i32 (i32.const 10000))
|
|
10
|
+
(global $as/units/SCALE_kg i32 (i32.const 1000))
|
|
11
|
+
(global $as/units/SCALE_N i32 (i32.const 100))
|
|
12
|
+
(global $as/units/SCALE_W i32 (i32.const 1))
|
|
13
|
+
(global $as/units/SCALE_J i32 (i32.const 1))
|
|
14
|
+
(global $as/units/SCALE_mps i32 (i32.const 10000))
|
|
15
|
+
(global $as/units/SCALE_mps2 i32 (i32.const 10000))
|
|
16
|
+
(global $as/units/G_mps2 i32 (i32.const 98067))
|
|
17
|
+
(memory $0 0)
|
|
18
|
+
(export "SCALE_Q" (global $as/units/SCALE_Q))
|
|
19
|
+
(export "SCALE_m" (global $as/units/SCALE_m))
|
|
20
|
+
(export "SCALE_s" (global $as/units/SCALE_s))
|
|
21
|
+
(export "SCALE_kg" (global $as/units/SCALE_kg))
|
|
22
|
+
(export "SCALE_N" (global $as/units/SCALE_N))
|
|
23
|
+
(export "SCALE_W" (global $as/units/SCALE_W))
|
|
24
|
+
(export "SCALE_J" (global $as/units/SCALE_J))
|
|
25
|
+
(export "SCALE_mps" (global $as/units/SCALE_mps))
|
|
26
|
+
(export "SCALE_mps2" (global $as/units/SCALE_mps2))
|
|
27
|
+
(export "G_mps2" (global $as/units/G_mps2))
|
|
28
|
+
(export "q" (func $as/units/q))
|
|
29
|
+
(export "clampQ" (func $as/units/clampQ))
|
|
30
|
+
(export "qMul" (func $as/units/qMul))
|
|
31
|
+
(export "qDiv" (func $as/units/qDiv))
|
|
32
|
+
(export "mulDiv" (func $as/units/mulDiv))
|
|
33
|
+
(export "to_m" (func $as/units/q))
|
|
34
|
+
(export "to_s" (func $as/units/q))
|
|
35
|
+
(export "to_kg" (func $as/units/to_kg))
|
|
36
|
+
(export "to_N" (func $as/units/to_N))
|
|
37
|
+
(export "to_W" (func $as/units/to_W))
|
|
38
|
+
(export "to_J" (func $as/units/to_W))
|
|
39
|
+
(export "to_mps" (func $as/units/q))
|
|
40
|
+
(export "to_mps2" (func $as/units/q))
|
|
41
|
+
(export "from_m" (func $as/units/from_m))
|
|
42
|
+
(export "from_s" (func $as/units/from_m))
|
|
43
|
+
(export "from_kg" (func $as/units/from_kg))
|
|
44
|
+
(export "from_N" (func $as/units/from_N))
|
|
45
|
+
(export "from_W" (func $as/units/from_W))
|
|
46
|
+
(export "from_J" (func $as/units/from_W))
|
|
47
|
+
(export "from_mps" (func $as/units/from_m))
|
|
48
|
+
(export "from_mps2" (func $as/units/from_m))
|
|
49
|
+
(export "sqrtQ" (func $as/units/sqrtQ))
|
|
50
|
+
(export "cbrtQ" (func $as/units/cbrtQ))
|
|
51
|
+
(export "memory" (memory $0))
|
|
52
|
+
(func $as/units/q (param $0 f64) (result i32)
|
|
53
|
+
(local $1 f64)
|
|
54
|
+
local.get $0
|
|
55
|
+
f64.const 1e4
|
|
56
|
+
f64.mul
|
|
57
|
+
local.tee $1
|
|
58
|
+
f64.ceil
|
|
59
|
+
local.tee $0
|
|
60
|
+
local.get $0
|
|
61
|
+
f64.const -1
|
|
62
|
+
f64.add
|
|
63
|
+
local.get $0
|
|
64
|
+
f64.const -0.5
|
|
65
|
+
f64.add
|
|
66
|
+
local.get $1
|
|
67
|
+
f64.le
|
|
68
|
+
select
|
|
69
|
+
i32.trunc_sat_f64_s
|
|
70
|
+
)
|
|
71
|
+
(func $as/units/clampQ (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
|
|
72
|
+
local.get $1
|
|
73
|
+
local.get $2
|
|
74
|
+
local.get $0
|
|
75
|
+
local.get $0
|
|
76
|
+
local.get $2
|
|
77
|
+
i32.gt_s
|
|
78
|
+
select
|
|
79
|
+
local.tee $0
|
|
80
|
+
local.get $0
|
|
81
|
+
local.get $1
|
|
82
|
+
i32.lt_s
|
|
83
|
+
select
|
|
84
|
+
)
|
|
85
|
+
(func $as/units/qMul (param $0 i32) (param $1 i32) (result i32)
|
|
86
|
+
local.get $0
|
|
87
|
+
i64.extend_i32_s
|
|
88
|
+
local.get $1
|
|
89
|
+
i64.extend_i32_s
|
|
90
|
+
i64.mul
|
|
91
|
+
i64.const 10000
|
|
92
|
+
i64.div_s
|
|
93
|
+
i32.wrap_i64
|
|
94
|
+
)
|
|
95
|
+
(func $as/units/qDiv (param $0 i32) (param $1 i32) (result i32)
|
|
96
|
+
local.get $0
|
|
97
|
+
i64.extend_i32_s
|
|
98
|
+
i64.const 10000
|
|
99
|
+
i64.mul
|
|
100
|
+
local.get $1
|
|
101
|
+
i64.extend_i32_s
|
|
102
|
+
i64.div_s
|
|
103
|
+
i32.wrap_i64
|
|
104
|
+
)
|
|
105
|
+
(func $as/units/mulDiv (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
|
|
106
|
+
local.get $0
|
|
107
|
+
i64.extend_i32_s
|
|
108
|
+
local.get $1
|
|
109
|
+
i64.extend_i32_s
|
|
110
|
+
i64.mul
|
|
111
|
+
local.get $2
|
|
112
|
+
i64.extend_i32_s
|
|
113
|
+
i64.div_s
|
|
114
|
+
i32.wrap_i64
|
|
115
|
+
)
|
|
116
|
+
(func $as/units/to_kg (param $0 f64) (result i32)
|
|
117
|
+
(local $1 f64)
|
|
118
|
+
local.get $0
|
|
119
|
+
f64.const 1e3
|
|
120
|
+
f64.mul
|
|
121
|
+
local.tee $1
|
|
122
|
+
f64.ceil
|
|
123
|
+
local.tee $0
|
|
124
|
+
local.get $0
|
|
125
|
+
f64.const -1
|
|
126
|
+
f64.add
|
|
127
|
+
local.get $0
|
|
128
|
+
f64.const -0.5
|
|
129
|
+
f64.add
|
|
130
|
+
local.get $1
|
|
131
|
+
f64.le
|
|
132
|
+
select
|
|
133
|
+
i32.trunc_sat_f64_s
|
|
134
|
+
)
|
|
135
|
+
(func $as/units/to_N (param $0 f64) (result i32)
|
|
136
|
+
(local $1 f64)
|
|
137
|
+
local.get $0
|
|
138
|
+
f64.const 100
|
|
139
|
+
f64.mul
|
|
140
|
+
local.tee $1
|
|
141
|
+
f64.ceil
|
|
142
|
+
local.tee $0
|
|
143
|
+
local.get $0
|
|
144
|
+
f64.const -1
|
|
145
|
+
f64.add
|
|
146
|
+
local.get $0
|
|
147
|
+
f64.const -0.5
|
|
148
|
+
f64.add
|
|
149
|
+
local.get $1
|
|
150
|
+
f64.le
|
|
151
|
+
select
|
|
152
|
+
i32.trunc_sat_f64_s
|
|
153
|
+
)
|
|
154
|
+
(func $as/units/to_W (param $0 f64) (result i32)
|
|
155
|
+
(local $1 f64)
|
|
156
|
+
local.get $0
|
|
157
|
+
f64.ceil
|
|
158
|
+
local.tee $1
|
|
159
|
+
local.get $1
|
|
160
|
+
f64.const -1
|
|
161
|
+
f64.add
|
|
162
|
+
local.get $1
|
|
163
|
+
f64.const -0.5
|
|
164
|
+
f64.add
|
|
165
|
+
local.get $0
|
|
166
|
+
f64.le
|
|
167
|
+
select
|
|
168
|
+
i32.trunc_sat_f64_s
|
|
169
|
+
)
|
|
170
|
+
(func $as/units/from_m (param $0 i32) (result f64)
|
|
171
|
+
local.get $0
|
|
172
|
+
f64.convert_i32_s
|
|
173
|
+
f64.const 1e4
|
|
174
|
+
f64.div
|
|
175
|
+
)
|
|
176
|
+
(func $as/units/from_kg (param $0 i32) (result f64)
|
|
177
|
+
local.get $0
|
|
178
|
+
f64.convert_i32_s
|
|
179
|
+
f64.const 1e3
|
|
180
|
+
f64.div
|
|
181
|
+
)
|
|
182
|
+
(func $as/units/from_N (param $0 i32) (result f64)
|
|
183
|
+
local.get $0
|
|
184
|
+
f64.convert_i32_s
|
|
185
|
+
f64.const 100
|
|
186
|
+
f64.div
|
|
187
|
+
)
|
|
188
|
+
(func $as/units/from_W (param $0 i32) (result f64)
|
|
189
|
+
local.get $0
|
|
190
|
+
f64.convert_i32_s
|
|
191
|
+
)
|
|
192
|
+
(func $as/units/sqrtQ (param $0 i32) (result i32)
|
|
193
|
+
(local $1 i64)
|
|
194
|
+
(local $2 i64)
|
|
195
|
+
(local $3 i32)
|
|
196
|
+
(local $4 i64)
|
|
197
|
+
i32.const 1
|
|
198
|
+
local.get $0
|
|
199
|
+
local.get $0
|
|
200
|
+
i32.const 0
|
|
201
|
+
i32.le_s
|
|
202
|
+
select
|
|
203
|
+
i64.extend_i32_s
|
|
204
|
+
i64.const 10000
|
|
205
|
+
i64.mul
|
|
206
|
+
local.set $4
|
|
207
|
+
i64.const 10000
|
|
208
|
+
local.set $1
|
|
209
|
+
loop $for-loop|0
|
|
210
|
+
local.get $3
|
|
211
|
+
i32.const 10
|
|
212
|
+
i32.lt_s
|
|
213
|
+
if
|
|
214
|
+
local.get $1
|
|
215
|
+
local.get $1
|
|
216
|
+
local.get $4
|
|
217
|
+
local.get $1
|
|
218
|
+
i64.div_s
|
|
219
|
+
i64.add
|
|
220
|
+
i64.const 2
|
|
221
|
+
i64.div_s
|
|
222
|
+
local.tee $2
|
|
223
|
+
i64.ne
|
|
224
|
+
if
|
|
225
|
+
local.get $2
|
|
226
|
+
local.set $1
|
|
227
|
+
local.get $3
|
|
228
|
+
i32.const 1
|
|
229
|
+
i32.add
|
|
230
|
+
local.set $3
|
|
231
|
+
br $for-loop|0
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
local.get $1
|
|
236
|
+
i32.wrap_i64
|
|
237
|
+
)
|
|
238
|
+
(func $as/units/cbrtQ (param $0 i32) (result i32)
|
|
239
|
+
(local $1 i64)
|
|
240
|
+
(local $2 i32)
|
|
241
|
+
(local $3 i64)
|
|
242
|
+
i32.const 1
|
|
243
|
+
local.get $0
|
|
244
|
+
local.get $0
|
|
245
|
+
i32.const 0
|
|
246
|
+
i32.le_s
|
|
247
|
+
select
|
|
248
|
+
i64.extend_i32_s
|
|
249
|
+
i64.const 100000000
|
|
250
|
+
i64.mul
|
|
251
|
+
local.set $3
|
|
252
|
+
i64.const 10000
|
|
253
|
+
local.set $1
|
|
254
|
+
loop $for-loop|0
|
|
255
|
+
local.get $2
|
|
256
|
+
i32.const 12
|
|
257
|
+
i32.lt_s
|
|
258
|
+
if
|
|
259
|
+
block $for-break0
|
|
260
|
+
local.get $3
|
|
261
|
+
local.get $1
|
|
262
|
+
local.get $1
|
|
263
|
+
i64.mul
|
|
264
|
+
i64.div_s
|
|
265
|
+
local.get $1
|
|
266
|
+
i64.const 1
|
|
267
|
+
i64.shl
|
|
268
|
+
i64.add
|
|
269
|
+
i64.const 3
|
|
270
|
+
i64.div_s
|
|
271
|
+
local.tee $1
|
|
272
|
+
i64.const 0
|
|
273
|
+
i64.le_s
|
|
274
|
+
if
|
|
275
|
+
i64.const 1
|
|
276
|
+
local.set $1
|
|
277
|
+
br $for-break0
|
|
278
|
+
end
|
|
279
|
+
local.get $2
|
|
280
|
+
i32.const 1
|
|
281
|
+
i32.add
|
|
282
|
+
local.set $2
|
|
283
|
+
br $for-loop|0
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
local.get $1
|
|
288
|
+
i32.wrap_i64
|
|
289
|
+
)
|
|
290
|
+
)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { TechEra } from "./sim/tech.js";
|
|
2
|
+
import type { Polity } from "./polity.js";
|
|
3
|
+
/** Equipment loadout inferred from a polity's tech era. */
|
|
4
|
+
export interface EraLoadout {
|
|
5
|
+
archetype: string;
|
|
6
|
+
weaponId: string;
|
|
7
|
+
armourId: string;
|
|
8
|
+
}
|
|
9
|
+
/** Configuration for a single tactical battle between two polities. */
|
|
10
|
+
export interface BattleConfig {
|
|
11
|
+
/** Deterministic seed: combines world seed + day + polity ids. */
|
|
12
|
+
seed: number;
|
|
13
|
+
polityAId: string;
|
|
14
|
+
polityBId: string;
|
|
15
|
+
teamASize: number;
|
|
16
|
+
teamBSize: number;
|
|
17
|
+
loadoutA: EraLoadout;
|
|
18
|
+
loadoutB: EraLoadout;
|
|
19
|
+
/** Tick limit — battle is a draw if neither side wins by this tick. */
|
|
20
|
+
maxTicks: number;
|
|
21
|
+
}
|
|
22
|
+
/** Result reported by the caller after the battle completes. */
|
|
23
|
+
export interface BattleOutcome {
|
|
24
|
+
/** 1 = team A won, 2 = team B won, 0 = draw (timeout or mutual annihilation). */
|
|
25
|
+
winner: 0 | 1 | 2;
|
|
26
|
+
ticksElapsed: number;
|
|
27
|
+
teamACasualties: number;
|
|
28
|
+
teamBCasualties: number;
|
|
29
|
+
}
|
|
30
|
+
/** Per-polity state changes to apply after a battle. */
|
|
31
|
+
export interface PolityImpact {
|
|
32
|
+
polityId: string;
|
|
33
|
+
moraleDelta_Q: number;
|
|
34
|
+
stabilityDelta_Q: number;
|
|
35
|
+
populationLost: number;
|
|
36
|
+
}
|
|
37
|
+
/** Summary record written to the battle log. */
|
|
38
|
+
export interface BattleRecord {
|
|
39
|
+
day: number;
|
|
40
|
+
polityAId: string;
|
|
41
|
+
polityBId: string;
|
|
42
|
+
winner: 0 | 1 | 2;
|
|
43
|
+
teamACasualties: number;
|
|
44
|
+
teamBCasualties: number;
|
|
45
|
+
ticksElapsed: number;
|
|
46
|
+
}
|
|
47
|
+
/** Minimum and maximum combatants per side. */
|
|
48
|
+
export declare const MIN_TEAM_SIZE = 2;
|
|
49
|
+
export declare const MAX_TEAM_SIZE = 16;
|
|
50
|
+
/** Battle ends after this many ticks regardless of outcome (prevents infinite loops). */
|
|
51
|
+
export declare const DEFAULT_MAX_TICKS = 6000;
|
|
52
|
+
/** Morale bonus for winning a battle (Q units). */
|
|
53
|
+
export declare const WIN_MORALE_BONUS: number;
|
|
54
|
+
/** Morale penalty for losing a battle (Q units). */
|
|
55
|
+
export declare const LOSS_MORALE_PENALTY: number;
|
|
56
|
+
/** Stability penalty per 10% casualties above 20% casualty rate. */
|
|
57
|
+
export declare const CASUALTY_STABILITY_RATE: number;
|
|
58
|
+
/** Population lost per combatant casualty (polity headcount, not Q). */
|
|
59
|
+
export declare const POP_PER_CASUALTY = 50;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the best available weapon and armour for a given tech era.
|
|
62
|
+
* Prehistoric → club + none; Ancient → knife + leather; Medieval+ → longsword + mail/plate.
|
|
63
|
+
*/
|
|
64
|
+
export declare function techEraToLoadout(era: TechEra): EraLoadout;
|
|
65
|
+
/**
|
|
66
|
+
* Converts a polity's military strength (Q) to a team size.
|
|
67
|
+
* q(0) → MIN_TEAM_SIZE; q(1.0) → MAX_TEAM_SIZE. Linear interpolation.
|
|
68
|
+
*/
|
|
69
|
+
export declare function militaryStrengthToTeamSize(militaryStrength_Q: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* Produces a deterministic battle seed from the world seed, day, and polity ids.
|
|
72
|
+
* Ensures each polity pair on each day gets a unique, reproducible seed.
|
|
73
|
+
*/
|
|
74
|
+
export declare function battleSeed(worldSeed: number, day: number, polityAId: string, polityBId: string): number;
|
|
75
|
+
/**
|
|
76
|
+
* Builds a BattleConfig for a war between two polities.
|
|
77
|
+
* Team sizes scale with militaryStrength_Q; loadouts reflect each side's tech era.
|
|
78
|
+
*/
|
|
79
|
+
export declare function battleConfigFromPolities(polityA: Polity, polityB: Polity, worldSeed: number, day: number, maxTicks?: number): BattleConfig;
|
|
80
|
+
/**
|
|
81
|
+
* Derives the per-polity state changes to apply after a battle.
|
|
82
|
+
*
|
|
83
|
+
* Win: +WIN_MORALE_BONUS morale.
|
|
84
|
+
* Loss: −LOSS_MORALE_PENALTY morale.
|
|
85
|
+
* Draw: no morale change.
|
|
86
|
+
* Both sides: stability penalty proportional to casualties above 20%.
|
|
87
|
+
* Population: POP_PER_CASUALTY headcount lost per casualty.
|
|
88
|
+
*/
|
|
89
|
+
export declare function polityImpactFromBattle(outcome: BattleOutcome, config: BattleConfig): PolityImpact[];
|
|
90
|
+
/**
|
|
91
|
+
* Apply a PolityImpact to a polity in-place.
|
|
92
|
+
* Clamps morale and stability to [0, SCALE.Q].
|
|
93
|
+
*/
|
|
94
|
+
export declare function applyPolityImpact(polity: Polity, impact: PolityImpact): void;
|