forked from coop-deluxe/sm64coopdx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbehavior_commands.h
332 lines (262 loc) · 9.92 KB
/
behavior_commands.h
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
329
330
331
332
#ifndef BEHAVIOR_COMMANDS_H
#define BEHAVIOR_COMMANDS_H
#define BC_B(a) _SHIFTL(a, 24, 8)
#define BC_BB(a, b) (_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8))
#define BC_BBBB(a, b, c, d) (_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 8, 8) | _SHIFTL(d, 0, 8))
#define BC_BBH(a, b, c) (_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 0, 16))
#define BC_B0H(a, b) (_SHIFTL(a, 24, 8) | _SHIFTL(b, 0, 16))
#define BC_H(a) _SHIFTL(a, 16, 16)
#define BC_HH(a, b) (_SHIFTL(a, 16, 16) | _SHIFTL(b, 0, 16))
#define BC_W(a) ((uintptr_t)(u32)(a))
#define BC_PTR(a) ((uintptr_t)(a))
// Defines the start of the behavior script as well as the object list the object belongs to.
// Has some special behavior for certain objects.
#define BEGIN(objList) \
BC_BB(0x00, objList)
// Delays the behavior script for a certain number of frames.
#define DELAY(num) \
BC_B0H(0x01, num)
// Jumps to a new behavior command and stores the return address in the object's stack.
#define CALL(addr) \
BC_B(0x02), \
BC_PTR(addr)
// Jumps back to the behavior command stored in the object's stack.
#define RETURN() \
BC_B(0x03)
// Jumps to a new behavior script without saving anything.
#define GOTO(addr) \
BC_B(0x04), \
BC_PTR(addr)
// Marks the start of a loop that will repeat a certain number of times.
#define BEGIN_REPEAT(count) \
BC_B0H(0x05, count)
// Marks the end of a repeating loop.
#define END_REPEAT() \
BC_B(0x06)
// Also marks the end of a repeating loop, but continues executing commands following the loop on the same frame.
#define END_REPEAT_CONTINUE() \
BC_B(0x07)
// Marks the beginning of an infinite loop.
#define BEGIN_LOOP() \
BC_B(0x08)
// Marks the end of an infinite loop.
#define END_LOOP() \
BC_B(0x09)
// Exits the behavior script.
// Often used to end behavior scripts that do not contain an infinite loop.
#define BREAK() \
BC_B(0x0A)
// Exits the behavior script, unused.
#define BREAK_UNUSED() \
BC_B(0x0B)
// Executes a native game function.
#define CALL_NATIVE(func) \
BC_B(0x0C), \
BC_PTR(func)
// Adds a float to the specified field.
#define ADD_FLOAT(field, value) \
BC_BBH(0x0D, field, value)
// Sets the specified field to a float.
#define SET_FLOAT(field, value) \
BC_BBH(0x0E, field, value)
// Adds an integer to the specified field.
#define ADD_INT(field, value) \
BC_BBH(0x0F, field, value)
// Sets the specified field to an integer.
#define SET_INT(field, value) \
BC_BBH(0x10, field, value)
// Performs a bitwise OR with the specified field and the given integer.
// Usually used to set an object's flags.
#define OR_INT(field, value) \
BC_BBH(0x11, field, value)
// Performs a bit clear with the specified short. Unused in favor of the 32-bit version.
#define BIT_CLEAR(field, value) \
BC_BBH(0x12, field, value)
// TODO: this one needs a better name / labelling
// Gets a random short, right shifts it the specified amount and adds min to it, then sets the specified field to that value.
#define SET_INT_RAND_RSHIFT(field, min, rshift) \
BC_BBH(0x13, field, min), \
BC_H(rshift)
// Sets the specified field to a random float in the given range.
#define SET_RANDOM_FLOAT(field, min, range) \
BC_BBH(0x14, field, min), \
BC_H(range)
// Sets the specified field to a random integer in the given range.
#define SET_RANDOM_INT(field, min, range) \
BC_BBH(0x15, field, min), \
BC_H(range)
// Adds a random float in the given range to the specified field.
#define ADD_RANDOM_FLOAT(field, min, range) \
BC_BBH(0x16, field, min), \
BC_H(range)
// TODO: better name (unused anyway)
// Gets a random short, right shifts it the specified amount and adds min to it, then adds the value to the specified field. Unused.
#define ADD_INT_RAND_RSHIFT(field, min, rshift) \
BC_BBH(0x17, field, min), \
BC_H(rshift)
// No operation. Unused.
#define CMD_NOP_1(field) \
BC_BB(0x18, field)
// No operation. Unused.
#define CMD_NOP_2(field) \
BC_BB(0x19, field)
// No operation. Unused.
#define CMD_NOP_3(field) \
BC_BB(0x1A, field)
// Sets the current model ID of the object.
#define SET_MODEL(modelID) \
BC_B0H(0x1B, modelID)
// Spawns a child object with the specified model and behavior.
#define SPAWN_CHILD(modelID, behavior) \
BC_B(0x1C), \
BC_W(modelID), \
BC_PTR(behavior)
// Exits the behavior script and despawns the object.
// Often used to end behavior scripts that do not contain an infinite loop.
#define DEACTIVATE() \
BC_B(0x1D)
// Finds the floor triangle directly under the object and moves the object down to it.
#define DROP_TO_FLOOR() \
BC_B(0x1E)
// Sets the destination float field to the sum of the values of the given float fields.
#define SUM_FLOAT(fieldDst, fieldSrc1, fieldSrc2) \
BC_BBBB(0x1F, fieldDst, fieldSrc1, fieldSrc2)
// Sets the destination integer field to the sum of the values of the given integer fields. Unused.
#define SUM_INT(fieldDst, fieldSrc1, fieldSrc2) \
BC_BBBB(0x20, fieldDst, fieldSrc1, fieldSrc2)
// Billboards the current object, making it always face the camera.
#define BILLBOARD() \
BC_B(0x21)
#define CYLBOARD() \
BC_B(0x38)
// Hides the current object.
#define HIDE() \
BC_B(0x22)
// Sets the size of the object's cylindrical hitbox.
#define SET_HITBOX(radius, height) \
BC_B(0x23), \
BC_HH(radius, height)
// No operation. Unused.
#define CMD_NOP_4(field, value) \
BC_BBH(0x24, field, value)
// Delays the behavior script for the number of frames given by the value of the specified field.
#define DELAY_VAR(field) \
BC_BB(0x25, field)
// Unused. Marks the start of a loop that will repeat a certain number of times.
// Uses a u8 as the argument, instead of a s16 like the other version does.
#define BEGIN_REPEAT_UNUSED(count) \
BC_BB(0x26, count)
// Loads the animations for the object. <field> is always set to oAnimations.
#define LOAD_ANIMATIONS(field, anims) \
BC_BB(0x27, field), \
BC_PTR(anims)
// Begins animation and sets the object's current animation index to the specified value.
#define ANIMATE(animIndex) \
BC_BB(0x28, animIndex)
// Spawns a child object with the specified model and behavior, plus a behavior param.
#define SPAWN_CHILD_WITH_PARAM(bhvParam, modelID, behavior) \
BC_B0H(0x29, bhvParam), \
BC_W(modelID), \
BC_PTR(behavior)
// Loads collision data for the object.
#define LOAD_COLLISION_DATA(collisionData) \
BC_B(0x2A), \
BC_PTR(collisionData)
// Sets the size of the object's cylindrical hitbox, and applies a downwards offset.
#define SET_HITBOX_WITH_OFFSET(radius, height, downOffset) \
BC_B(0x2B), \
BC_HH(radius, height), \
BC_H(downOffset)
// Spawns a new object with the specified model and behavior.
#define SPAWN_OBJ(modelID, behavior) \
BC_B(0x2C), \
BC_W(modelID), \
BC_PTR(behavior)
// Sets the home position of the object to its current position.
#define SET_HOME() \
BC_B(0x2D)
// Sets the size of the object's cylindrical hurtbox.
#define SET_HURTBOX(radius, height) \
BC_B(0x2E), \
BC_HH(radius, height)
// Sets the object's interaction type.
#define SET_INTERACT_TYPE(type) \
BC_B(0x2F), \
BC_W(type)
// Sets various parameters that the object uses for calculating physics.
#define SET_OBJ_PHYSICS(wallHitboxRadius, gravity, bounciness, dragStrength, friction, buoyancy, unused1, unused2) \
BC_B(0x30), \
BC_HH(wallHitboxRadius, gravity), \
BC_HH(bounciness, dragStrength), \
BC_HH(friction, buoyancy), \
BC_HH(unused1, unused2)
// Sets the object's interaction subtype. Unused.
#define SET_INTERACT_SUBTYPE(subtype) \
BC_B(0x31), \
BC_W(subtype)
// Sets the object's size to the specified percentage.
#define SCALE(unusedField, percent) \
BC_BBH(0x32, unusedField, percent)
// Performs a bit clear on the object's parent's field with the specified value.
// Used for clearing active particle flags fron Mario's object.
#define PARENT_BIT_CLEAR(field, flags) \
BC_BB(0x33, field), \
BC_W(flags)
// Animates an object using texture animation. <field> is always set to oAnimState.
#define ANIMATE_TEXTURE(field, rate) \
BC_BBH(0x34, field, rate)
// Disables rendering for the object.
#define DISABLE_RENDERING() \
BC_B(0x35)
// Unused. Sets the specified field to an integer. Wastes 4 bytes of space for no reason at all.
#define SET_INT_UNUSED(field, value) \
BC_BB(0x36, field), \
BC_HH(0, value)
// Spawns a water droplet with the given parameters.
#define SPAWN_WATER_DROPLET(dropletParams) \
BC_B(0x37), \
BC_PTR(dropletParams)
// coop
// Defines the id of the behavior script
#define ID(id) \
BC_B0H(0x39, id)
// Jumps to a new behavior command and stores the return address in the object's stack.
#define CALL_EXT(addr) \
BC_B(0x3A), \
BC_PTR(addr)
// Jumps to a new behavior script without saving anything.
#define GOTO_EXT(addr) \
BC_B(0x3B), \
BC_PTR(addr)
// Executes a native game function.
#define CALL_NATIVE_EXT(func) \
BC_B(0x3C), \
BC_PTR(func)
// Spawns a child object with the specified model and behavior.
#define SPAWN_CHILD_EXT(modelID, behavior) \
BC_B(0x3D), \
BC_W(modelID), \
BC_PTR(behavior)
// Spawns a child object with the specified model and behavior, plus a behavior param.
#define SPAWN_CHILD_WITH_PARAM_EXT(bhvParam, modelID, behavior) \
BC_B0H(0x3E, bhvParam), \
BC_W(modelID), \
BC_PTR(behavior)
// Spawns a new object with the specified model and behavior.
#define SPAWN_OBJ_EXT(modelID, behavior) \
BC_B(0x3F), \
BC_W(modelID), \
BC_PTR(behavior)
// Loads the animations for the object. <field> is always set to oAnimations.
#define LOAD_ANIMATIONS_EXT(field, anims) \
BC_BB(0x40, field), \
BC_PTR(anims)
// Loads collision data for the object.
#define LOAD_COLLISION_DATA_EXT(collisionData) \
BC_B(0x41), \
BC_PTR(collisionData)
// This is a special case for behaviors hooked from LUA.
#define CALL_LUA_FUNC(func) \
BC_B(0x42), \
BC_W(func)
#endif // BEHAVIOR_COMMANDS_H