1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
The `root` table contains functions that reference the game's currently loaded assets and don't relate to any more specific context such as a particular world or universe.
---
#### `Json` root.assetJson(`String` assetPath)
Returns the contents of the specified JSON asset file.
---
#### `Json` root.makeCurrentVersionedJson(`String` versioningIdentifier, `Json` content)
Returns a versioned JSON representation of the given JSON content with the given identifier and the most recent version as specified in `versioning.config`.
---
#### `Json` root.loadVersionedJson(`Json` versionedContent, `String` versioningIdentifier)
Returns the given JSON content and identifier after applying appropriate versioning scripts to bring it up to the most recent version as specified in `versioning.config`.
---
#### `double` root.evalFunction(`String` functionName, `double` input)
Returns the evaluation of the specified univariate function (as defined in a `.functions` file) for the given input value.
---
#### `double` root.evalFunction2(`String` functionName, `double` input1, `double` input2)
Returns the evaluation of the specified bivariate function (as defined in a `.2functions` file) for the given input values.
---
#### `Vec2U` root.imageSize(`String` imagePath)
Returns the pixel dimensions of the specified image asset.
---
#### `List<Vec2I>` root.imageSpaces(`String` imagePath, `Vec2F` worldPosition, `float` spaceScan, `bool` flip)
Returns a list of the world tile spaces the image would occupy if placed at the given position using the specified spaceScan value (the portion of a space that must be non-transparent for that space to count as filled).
---
#### `RectU` root.nonEmptyRegion(`String` imagePath)
Returns the rectangle containing the portion of the specified asset image that is non-transparent.
---
#### `Json` root.npcConfig(`String` npcType)
Returns a representation of the generated JSON configuration for an NPC of the given type.
---
#### `Json` root.npcVariant(`String` species, `String` npcType, `float` level, [`unsigned` seed], [`Json` parameters])
Generates an NPC with the specified species, type, level, seed and parameters, and returns its configuration.
---
#### `float` root.projectileGravityMultiplier(`String` projectileName)
Returns the gravity multiplier of the given projectile's movement controller configuration as configured in `physics.config`.
---
#### `Json` root.projectileConfig(`String` projectileName)
Returns a representation of the JSON configuration for the given projectile.
---
#### `Json` root.itemDescriptorsMatch(`ItemDescriptor` descriptor1, `ItemDescriptor` descriptor2, [`bool` exactMatch])
Returns `true` if the given item descriptors match. If exactMatch is `true` then both names and parameters will be compared, otherwise only names.
---
#### `JsonArray` root.recipesForItem(`String` itemName)
Returns a list of JSON configurations of all recipes which output the given item.
---
#### `String` root.itemType(`String` itemName)
Returns the item type name for the specified item.
---
#### `JsonArray` root.itemTags(`String` itemName)
Returns a list of the tags applied to the specified item.
---
#### `bool` root.itemHasTag(`String` itemName, `String` tagName)
Returns true if the given item's tags include the specified tag and false otherwise.
---
#### `Json` root.itemConfig(`ItemDescriptor` descriptor, [`float` level], [`unsigned` seed])
Generates an item from the specified descriptor, level and seed and returns a JSON object containing the `directory`, `config` and `parameters` for that item.
---
#### `ItemDescriptor` root.createItem(`ItemDescriptor` descriptor, [`float` level], [`unsigned` seed])
Generates an item from the specified descriptor, level and seed and returns a new item descriptor for the resulting item.
---
#### `Json` root.tenantConfig(`String` tenantName)
Returns the JSON configuration for the given tenant.
---
#### `JsonArray` root.getMatchingTenants(`map<String, unsigned>` colonyTags)
Returns an array of JSON configurations of tenants matching the given map of colony tags and corresponding object counts.
---
#### `JsonArray` root.liquidStatusEffects(`LiquidId` liquid)
Returns an array of status effects applied by the given liquid.
---
#### `String` root.generateName(`String` assetPath, [`unsigned` seed])
Returns a randomly generated name using the specified name gen config and seed.
---
#### `Json` root.questConfig(`String` questTemplateId)
Returns the JSON configuration of the specified quest template.
---
#### `JsonArray` root.npcPortrait(`String` portraitMode, `String` species, `String` npcType, `float` level, [`unsigned` seed], [`Json` parameters])
Generates an NPC with the specified type, level, seed and parameters and returns a portrait in the given portraitMode as a list of drawables.
---
#### `JsonArray` root.monsterPortrait(`String` typeName, [`Json` parameters])
Generates a monster of the given type with the given parameters and returns its portrait as a list of drawables.
---
#### `bool` root.isTreasurePool(`String` poolName)
Returns true if the given treasure pool exists and false otherwise. Can be used to guard against errors attempting to generate invalid treasure.
---
#### `JsonArray` root.createTreasure(`String` poolName, `float` level, [`unsigned` seed])
Generates an instance of the specified treasure pool, level and seed and returns the contents as a list of item descriptors.
---
#### `String` root.materialMiningSound(`String` materialName, [`String` modName])
Returns the path of the mining sound asset for the given material and mod combination, or `nil` if no mining sound is set.
---
#### `String` root.materialFootstepSound(`String` materialName, [`String` modName])
Returns the path of the footstep sound asset for the given material and mod combination, or `nil` if no footstep sound is set.
---
#### `float` root.materialHealth(`String` materialName)
Returns the configured health value for the specified material.
---
#### `Json` root.materialConfig(`String` materialName)
Returns a JSON object containing the `path` and base `config` for the specified material if it is a real material, or `nil` if it is a metamaterial or invalid.
---
#### `Json` root.modConfig(`String` modName)
Returns a JSON object containing the `path` and base `config` for the specified mod if it is a real mod, or `nil` if it is a metamod or invalid.
---
#### `Json` root.liquidConfig(`LiquidId` liquidId)
#### `Json` root.liquidConfig(`String` liquidName)
Returns a JSON object containing the `path` and base `config` for the specified liquid name or id if it is a real liquid, or `nil` if the liquid is empty or invalid.
---
#### `String` root.liquidName(`LiquidId` liquidId)
Returns the string name of the liquid with the given ID.
---
#### `LiquidId` root.liquidId(`String` liquidName)
Returns the numeric ID of the liquid with the given name.
---
#### `Json` root.monsterSkillParameter(`String` skillName, `String` parameterName)
Returns the value of the specified parameter for the specified monster skill.
---
#### `Json` root.monsterParameters(`String` monsterType, [uint64_t seed])
Returns the parameters for a monster type.
---
#### `ActorMovementParameters` root.monsterMovementSettings(`String` monsterType, [uint64_t seed])
Returns the configured base movement parameters for the specified monster type.
---
#### `Json` root.createBiome(`String` biomeName, `unsigned` seed, `float` verticalMidPoint, `float` threatLevel)
Generates a biome with the specified name, seed, vertical midpoint and threat level, and returns a JSON object containing the configuration for the generated biome.
---
#### `String` root.hasTech(`String` techName)
Returns `true` if a tech with the specified name exists and `false` otherwise.
---
#### `String` root.techType(`String` techName)
Returns the type (tech slot) of the specified tech.
---
#### `Json` root.techConfig(`String` techName)
Returns the JSON configuration for the specified tech.
---
#### `String` root.treeStemDirectory(`String` stemName)
Returns the path within assets from which the specified tree stem type was loaded.
---
#### `String` root.treeFoliageDirectory(`String` foliageName)
Returns the path within assets from which the specified tree foliage type was loaded.
---
#### `Collection` root.collection(`String` collectionName)
Returns the metadata for the specified collection.
---
#### `List<Collectable>` root.collectables(`String` collectionName)
Returns a list of collectables for the specified collection.
---
#### `String` root.elementalResistance(`String` elementalType)
Returns the name of the stat used to calculate elemental resistance for the specified elemental type.
---
#### `Json` root.dungeonMetadata(`String` dungeonName)
Returns the metadata for the specified dungeon definition.
---
#### `BehaviorState` root.behavior(`LuaTable` context, `Json` config, `JsonObject` parameters)
Loads a behavior and returns the behavior state as userdata.
context is the current lua context called from, in almost all cases _ENV.
config can be either the `String` name of a behavior tree, or an entire behavior tree configuration to be built.
parameters is overrides for parameters for the behavior tree.
BehaviorState contains 2 methods:
behavior:init(_ENV) -- initializes the behavior, loads required scripts, and returns a new behavior state
behavior:run(state, dt) -- runs the behavior, takes a behavior state for the first argument
behavior:clear(state) -- resets the internal state of the behavior
Example:
```lua
function init()
self.behavior = root.behavior("monster", {})
self.behaviorState = self.behavior:init(_ENV)
end
function update(dt)
self.behavior:run(self.behaviorState, dt)
end
```
|