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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
/*
* File: z_en_wood02.c
* Overlay: ovl_En_Wood02
* Description: Trees, bushes, leaves
*/
#include "z_en_wood02.h"
#include "libc64/qrand.h"
#include "attributes.h"
#include "gfx.h"
#include "gfx_setupdl.h"
#include "ichain.h"
#include "rand.h"
#include "sfx.h"
#include "sys_matrix.h"
#include "z_en_item00.h"
#include "z_lib.h"
#include "play_state.h"
#include "player.h"
#include "skin_matrix.h"
#include "assets/objects/object_wood02/object_wood02.h"
#define FLAGS 0
void EnWood02_Init(Actor* thisx, PlayState* play2);
void EnWood02_Destroy(Actor* thisx, PlayState* play);
void EnWood02_Update(Actor* thisx, PlayState* play2);
void EnWood02_Draw(Actor* thisx, PlayState* play);
/**
* WOOD_SPAWN_SPAWNER is also used by some individual trees: EnWood02_Update also checks for parent before running any
* despawning code.
* */
typedef enum WoodSpawnType {
/* 0 */ WOOD_SPAWN_NORMAL,
/* 1 */ WOOD_SPAWN_SPAWNED,
/* 2 */ WOOD_SPAWN_SPAWNER
} WoodSpawnType;
typedef enum WoodDrawType {
/* 0 */ WOOD_DRAW_TREE_CONICAL,
/* 1 */ WOOD_DRAW_TREE_OVAL,
/* 2 */ WOOD_DRAW_TREE_KAKARIKO_ADULT,
/* 3 */ WOOD_DRAW_BUSH_GREEN,
/* 4 */ WOOD_DRAW_4, // Used for black bushes and green leaves
/* 5 */ WOOD_DRAW_LEAF_YELLOW
} WoodDrawType;
ActorProfile En_Wood02_Profile = {
/**/ ACTOR_EN_WOOD02,
/**/ ACTORCAT_PROP,
/**/ FLAGS,
/**/ OBJECT_WOOD02,
/**/ sizeof(EnWood02),
/**/ EnWood02_Init,
/**/ EnWood02_Destroy,
/**/ EnWood02_Update,
/**/ EnWood02_Draw,
};
static ColliderCylinderInit sCylinderInit = {
{
COL_MATERIAL_TREE,
AT_NONE,
AC_ON | AC_HARD | AC_TYPE_PLAYER,
OC1_ON | OC1_TYPE_ALL,
OC2_TYPE_1,
COLSHAPE_CYLINDER,
},
{
ELEM_MATERIAL_UNK5,
{ 0x00000000, HIT_SPECIAL_EFFECT_NONE, 0x00 },
{ 0x0FC0074A, HIT_BACKLASH_NONE, 0x00 },
ATELEM_NONE,
ACELEM_ON,
OCELEM_ON,
},
{ 18, 60, 0, { 0, 0, 0 } },
};
static f32 sSpawnDistance[] = { 707.0f, 525.0f, 510.0f, 500.0f, 566.0f, 141.0f };
static s16 sSpawnAngle[] = { 0x1FFF, 0x4C9E, 0x77F5, 0xA5C9, 0xD6C3, 0xA000 };
static InitChainEntry sInitChain[] = {
ICHAIN_F32(lockOnArrowOffset, 5600, ICHAIN_STOP),
};
static Gfx* D_80B3BF54[] = {
object_wood02_DL_0078D0, object_wood02_DL_007CA0, object_wood02_DL_0080D0, object_wood02_DL_000090,
object_wood02_DL_000340, object_wood02_DL_000340, object_wood02_DL_000700,
};
static Gfx* D_80B3BF70[] = {
object_wood02_DL_007968,
object_wood02_DL_007D38,
object_wood02_DL_0081A8,
NULL,
NULL,
NULL,
object_wood02_DL_007AD0,
object_wood02_DL_007E20,
object_wood02_DL_008350,
object_wood02_DL_000160,
object_wood02_DL_000440,
object_wood02_DL_000700,
};
static f32 sSpawnCos;
static f32 sSpawnSin;
s32 EnWood02_SpawnZoneCheck(EnWood02* this, PlayState* play, Vec3f* pos) {
f32 phi_f12;
SkinMatrix_Vec3fMtxFMultXYZW(&play->viewProjectionMtxF, pos, &this->actor.projectedPos, &this->actor.projectedW);
phi_f12 = ((this->actor.projectedW == 0.0f) ? 1000.0f : fabsf(1.0f / this->actor.projectedW));
if ((-this->actor.cullingVolumeScale < this->actor.projectedPos.z) &&
(this->actor.projectedPos.z < (this->actor.cullingVolumeDistance + this->actor.cullingVolumeScale)) &&
(((fabsf(this->actor.projectedPos.x) - this->actor.cullingVolumeScale) * phi_f12) < 1.0f) &&
(((this->actor.projectedPos.y + this->actor.cullingVolumeDownward) * phi_f12) > -1.0f) &&
(((this->actor.projectedPos.y - this->actor.cullingVolumeScale) * phi_f12) < 1.0f)) {
return true;
}
return false;
}
/** Spawns similar-looking trees or bushes only when the player is sufficiently close. Presumably done this way to keep
* memory usage down in Hyrule Field. */
void EnWood02_SpawnOffspring(EnWood02* this, PlayState* play) {
EnWood02* childWood;
s16* childSpawnAngle;
Vec3f childPos;
s16 extraRot;
s16 childParams;
s32 i;
for (i = 4; i >= 0; i--) {
if ((this->unk_14E[i] & 0x7F) == 0) {
extraRot = 0;
if (this->actor.params == WOOD_BUSH_GREEN_LARGE_SPAWNER) {
extraRot = 0x4000;
}
childSpawnAngle = &sSpawnAngle[i];
sSpawnCos = Math_CosS(*childSpawnAngle + this->actor.world.rot.y + extraRot);
sSpawnSin = Math_SinS(*childSpawnAngle + this->actor.world.rot.y + extraRot);
childPos.x = (sSpawnDistance[i] * sSpawnSin) + this->actor.home.pos.x;
childPos.y = this->actor.home.pos.y;
childPos.z = (sSpawnDistance[i] * sSpawnCos) + this->actor.home.pos.z;
if (EnWood02_SpawnZoneCheck(this, play, &childPos)) {
if ((this->unk_14E[i] & 0x80) != 0) {
childParams = (0xFF00 | (this->actor.params + 1));
} else {
childParams = (((this->drawType & 0xF0) << 4) | (this->actor.params + 1));
}
childWood = (EnWood02*)Actor_SpawnAsChild(&play->actorCtx, &this->actor, play, ACTOR_EN_WOOD02,
childPos.x, childPos.y, childPos.z, this->actor.world.rot.x,
*childSpawnAngle, 0, childParams);
if (childWood != NULL) {
childWood->unk_14E[0] = i;
this->unk_14E[i] |= 1;
childWood->actor.projectedPos = this->actor.projectedPos;
} else {
this->unk_14E[i] &= 0x80;
}
}
}
}
}
void EnWood02_Init(Actor* thisx, PlayState* play2) {
s16 spawnType;
f32 actorScale;
PlayState* play = play2;
EnWood02* this = (EnWood02*)thisx;
CollisionPoly* poly;
s32 bgId;
f32 floorY;
s16 extraRot;
spawnType = WOOD_SPAWN_NORMAL;
actorScale = 1.0f;
this->unk_14C = PARAMS_GET_U(this->actor.params, 8, 8);
if (this->actor.home.rot.z != 0) {
this->actor.home.rot.z = (this->actor.home.rot.z << 8) | this->unk_14C;
this->unk_14C = -1;
this->actor.world.rot.z = this->actor.shape.rot.z = 0;
} else if (this->unk_14C & 0x80) {
this->unk_14C = -1;
}
this->actor.params &= 0xFF;
Actor_ProcessInitChain(&this->actor, sInitChain);
if (this->actor.params <= WOOD_TREE_KAKARIKO_ADULT) {
Collider_InitCylinder(play, &this->collider);
Collider_SetCylinder(play, &this->collider, &this->actor, &sCylinderInit);
}
switch (this->actor.params) {
case WOOD_BUSH_GREEN_LARGE_SPAWNER:
case WOOD_BUSH_BLACK_LARGE_SPAWNER:
spawnType = 1;
FALLTHROUGH;
case WOOD_BUSH_GREEN_LARGE_SPAWNED:
case WOOD_BUSH_BLACK_LARGE_SPAWNED:
spawnType++;
FALLTHROUGH;
case WOOD_TREE_CONICAL_LARGE:
case WOOD_BUSH_GREEN_LARGE:
case WOOD_BUSH_BLACK_LARGE:
actorScale = 1.5f;
this->actor.cullingVolumeDistance = 4000.0f;
this->actor.cullingVolumeScale = 2000.0f;
this->actor.cullingVolumeDownward = 2400.0f;
break;
case WOOD_TREE_CONICAL_SPAWNER:
case WOOD_TREE_OVAL_YELLOW_SPAWNER:
case WOOD_TREE_OVAL_GREEN_SPAWNER:
case WOOD_BUSH_GREEN_SMALL_SPAWNER:
case WOOD_BUSH_BLACK_SMALL_SPAWNER:
spawnType = 1;
FALLTHROUGH;
case WOOD_TREE_CONICAL_SPAWNED:
case WOOD_TREE_OVAL_YELLOW_SPAWNED:
case WOOD_TREE_OVAL_GREEN_SPAWNED:
case WOOD_BUSH_GREEN_SMALL_SPAWNED:
case WOOD_BUSH_BLACK_SMALL_SPAWNED:
spawnType++;
FALLTHROUGH;
case WOOD_TREE_CONICAL_MEDIUM:
case WOOD_TREE_OVAL_GREEN:
case WOOD_TREE_KAKARIKO_ADULT:
case WOOD_BUSH_GREEN_SMALL:
case WOOD_BUSH_BLACK_SMALL:
this->actor.cullingVolumeDistance = 4000.0f;
this->actor.cullingVolumeScale = 800.0f;
this->actor.cullingVolumeDownward = 1800.0f;
break;
case WOOD_TREE_CONICAL_SMALL:
actorScale = 0.6f;
this->actor.cullingVolumeDistance = 4000.0f;
this->actor.cullingVolumeScale = 400.0f;
this->actor.cullingVolumeDownward = 1000.0f;
break;
case WOOD_LEAF_GREEN:
case WOOD_LEAF_YELLOW:
this->unk_14E[0] = 0x4B;
actorScale = 0.02f;
this->actor.velocity.x = Rand_CenteredFloat(6.0f);
this->actor.velocity.z = Rand_CenteredFloat(6.0f);
this->actor.velocity.y = (Rand_ZeroOne() * 1.25f) + -3.1f;
break;
}
if (this->actor.params <= WOOD_TREE_CONICAL_SPAWNED) {
this->drawType = WOOD_DRAW_TREE_CONICAL;
} else if (this->actor.params <= WOOD_TREE_OVAL_GREEN_SPAWNED) {
this->drawType = WOOD_DRAW_TREE_OVAL;
} else if (this->actor.params <= WOOD_TREE_KAKARIKO_ADULT) {
this->drawType = WOOD_DRAW_TREE_KAKARIKO_ADULT;
} else if (this->actor.params <= WOOD_BUSH_GREEN_LARGE_SPAWNED) {
this->drawType = WOOD_DRAW_BUSH_GREEN;
} else if (this->actor.params <= WOOD_LEAF_GREEN) { // Black bushes and green leaves
this->drawType = WOOD_DRAW_4;
} else {
this->drawType = WOOD_DRAW_LEAF_YELLOW;
}
Actor_SetScale(&this->actor, actorScale);
this->spawnType = spawnType;
if (spawnType != WOOD_SPAWN_NORMAL) {
extraRot = 0;
if (this->actor.params == WOOD_BUSH_GREEN_LARGE_SPAWNER) {
extraRot = 0x4000;
}
if (spawnType == WOOD_SPAWN_SPAWNER) {
this->drawType |= this->unk_14C << 4;
EnWood02_SpawnOffspring(this, play);
sSpawnCos = Math_CosS(sSpawnAngle[5] + this->actor.world.rot.y + extraRot);
sSpawnSin = Math_SinS(sSpawnAngle[5] + this->actor.world.rot.y + extraRot);
this->actor.world.pos.x += (sSpawnSin * sSpawnDistance[5]);
this->actor.world.pos.z += (sSpawnCos * sSpawnDistance[5]);
} else {
this->actor.flags |= ACTOR_FLAG_UPDATE_CULLING_DISABLED;
}
// Snap to floor, or remove if over void
this->actor.world.pos.y += 200.0f;
floorY = BgCheck_EntityRaycastDown4(&play->colCtx, &poly, &bgId, &this->actor, &this->actor.world.pos);
if (floorY > BGCHECK_Y_MIN) {
this->actor.world.pos.y = floorY;
} else {
Actor_Kill(&this->actor);
return;
}
}
ActorShape_Init(&this->actor.shape, 0.0f, NULL, 0.0f);
this->actor.home.rot.y = 0;
this->actor.colChkInfo.mass = MASS_IMMOVABLE;
}
void EnWood02_Destroy(Actor* thisx, PlayState* play) {
EnWood02* this = (EnWood02*)thisx;
if (this->actor.params <= WOOD_TREE_KAKARIKO_ADULT) {
Collider_DestroyCylinder(play, &this->collider);
}
}
void EnWood02_Update(Actor* thisx, PlayState* play2) {
PlayState* play = play2;
EnWood02* this = (EnWood02*)thisx;
f32 wobbleAmplitude;
// Despawn extra trees in a group if out of range
if ((this->spawnType == WOOD_SPAWN_SPAWNED) && (this->actor.parent != NULL)) {
if (!(this->actor.flags & ACTOR_FLAG_INSIDE_CULLING_VOLUME)) {
u8 new_var = this->unk_14E[0];
u8 phi_v0 = 0;
s32 pad;
if (this->unk_14C < 0) {
phi_v0 = 0x80;
}
((EnWood02*)this->actor.parent)->unk_14E[new_var] = phi_v0;
Actor_Kill(&this->actor);
return;
}
} else if (this->spawnType == WOOD_SPAWN_SPAWNER) {
EnWood02_SpawnOffspring(this, play);
}
if (this->actor.params <= WOOD_TREE_KAKARIKO_ADULT) {
if (this->collider.base.acFlags & AC_HIT) {
this->collider.base.acFlags &= ~AC_HIT;
Actor_PlaySfx(&this->actor, NA_SE_IT_REFLECTION_WOOD);
}
if (this->actor.home.rot.y != 0) {
Vec3f dropsSpawnPt = this->actor.world.pos;
dropsSpawnPt.y += 200.0f;
if ((this->unk_14C >= 0) && (this->unk_14C < 0x64)) {
Item_DropCollectibleRandom(play, &this->actor, &dropsSpawnPt,
COLLECTIBLE_DROP_RANDOM_PARAMS(this->unk_14C, false));
} else {
if (this->actor.home.rot.z != 0) {
this->actor.home.rot.z &= 0x1FFF;
this->actor.home.rot.z |= 0xE000;
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_SW, dropsSpawnPt.x, dropsSpawnPt.y, dropsSpawnPt.z, 0,
this->actor.world.rot.y, 0, this->actor.home.rot.z);
this->actor.home.rot.z = 0;
}
}
// Spawn falling leaves
if (this->unk_14C >= -1) {
s32 i;
s32 leavesParams = WOOD_LEAF_GREEN;
if ((this->actor.params == WOOD_TREE_OVAL_YELLOW_SPAWNER) ||
(this->actor.params == WOOD_TREE_OVAL_YELLOW_SPAWNED)) {
leavesParams = WOOD_LEAF_YELLOW;
}
Actor_PlaySfx(&this->actor, NA_SE_EV_TREE_SWING);
for (i = 3; i >= 0; i--) {
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_WOOD02, dropsSpawnPt.x, dropsSpawnPt.y, dropsSpawnPt.z,
0, Rand_CenteredFloat(65535.0f), 0, leavesParams);
}
}
this->unk_14C = -0x15;
this->actor.home.rot.y = 0;
}
if (this->actor.xzDistToPlayer < 600.0f) {
Collider_UpdateCylinder(&this->actor, &this->collider);
CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base);
CollisionCheck_SetOC(play, &play->colChkCtx, &this->collider.base);
}
} else if (this->actor.params < 0x17) { // Bush
Player* player = GET_PLAYER(play);
if (this->unk_14C >= -1) {
if (((player->rideActor == NULL) && (sqrt(this->actor.xyzDistToPlayerSq) < 20.0) &&
(player->speedXZ != 0.0f)) ||
((player->rideActor != NULL) && (sqrt(this->actor.xyzDistToPlayerSq) < 60.0) &&
(player->rideActor->speed != 0.0f))) {
if ((this->unk_14C >= 0) && (this->unk_14C < 0x64)) {
Item_DropCollectibleRandom(play, &this->actor, &this->actor.world.pos,
COLLECTIBLE_DROP_RANDOM_PARAMS(this->unk_14C, true));
}
this->unk_14C = -0x15;
Actor_PlaySfx(&this->actor, NA_SE_EV_TREE_SWING);
}
}
} else { // Leaves
this->unk_14C++;
Math_ApproachF(&this->actor.velocity.x, 0.0f, 1.0f, 5 * 0.01f);
Math_ApproachF(&this->actor.velocity.z, 0.0f, 1.0f, 5 * 0.01f);
Actor_UpdatePos(&this->actor);
this->actor.shape.rot.z = Math_SinS(3000 * this->unk_14C) * 0x4000;
this->unk_14E[0]--;
if (this->unk_14E[0] == 0) {
Actor_Kill(&this->actor);
}
}
// Wobble from impact
if (this->unk_14C < -1) {
this->unk_14C++;
wobbleAmplitude = Math_SinS((this->unk_14C ^ 0xFFFF) * 0x3332) * 250.0f;
this->actor.shape.rot.x = (Math_CosS(this->actor.yawTowardsPlayer - this->actor.shape.rot.y) * wobbleAmplitude);
this->actor.shape.rot.z = (Math_SinS(this->actor.yawTowardsPlayer - this->actor.shape.rot.y) * wobbleAmplitude);
}
}
void EnWood02_Draw(Actor* thisx, PlayState* play) {
EnWood02* this = (EnWood02*)thisx;
s16 type;
GraphicsContext* gfxCtx = play->state.gfxCtx;
u8 red;
u8 green;
u8 blue;
OPEN_DISPS(gfxCtx, "../z_en_wood02.c", 775);
type = this->actor.params;
if ((type == WOOD_TREE_OVAL_GREEN_SPAWNER) || (type == WOOD_TREE_OVAL_GREEN_SPAWNED) ||
(type == WOOD_TREE_OVAL_GREEN) || (type == WOOD_LEAF_GREEN)) {
red = 50;
green = 170;
blue = 70;
} else if ((type == WOOD_TREE_OVAL_YELLOW_SPAWNER) || (type == WOOD_TREE_OVAL_YELLOW_SPAWNED) ||
(type == WOOD_LEAF_YELLOW)) {
red = 180;
green = 155;
blue = 0;
} else {
red = green = blue = 255;
}
Gfx_SetupDL_25Xlu(gfxCtx);
if ((this->actor.params == WOOD_LEAF_GREEN) || (this->actor.params == WOOD_LEAF_YELLOW)) {
Gfx_SetupDL_25Opa(gfxCtx);
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, red, green, blue, 127);
Gfx_DrawDListOpa(play, object_wood02_DL_000700);
} else if (D_80B3BF70[this->drawType & 0xF] != NULL) {
Gfx_DrawDListOpa(play, D_80B3BF54[this->drawType & 0xF]);
gDPSetEnvColor(POLY_XLU_DISP++, red, green, blue, 0);
MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, gfxCtx, "../z_en_wood02.c", 808);
gSPDisplayList(POLY_XLU_DISP++, D_80B3BF70[this->drawType & 0xF]);
} else {
Gfx_SetupDL_25Xlu(gfxCtx);
MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, gfxCtx, "../z_en_wood02.c", 814);
gSPDisplayList(POLY_XLU_DISP++, D_80B3BF54[this->drawType & 0xF]);
}
CLOSE_DISPS(gfxCtx, "../z_en_wood02.c", 840);
}
|