Mario Kart 64
Loading...
Searching...
No Matches
update.inc.c
Go to the documentation of this file.
1#include <actors.h>
2#include <code_800029B0.h>
3#include <defines.h>
4#include <main.h>
5
11void update_actor_banana(struct BananaActor* banana) {
12 UNUSED f32 pad;
13 Player* player;
14 struct BananaActor* elderBanana;
15 struct Controller* controller;
16 Vec3f someOtherVelocity;
17 Vec3f someVelocity;
18 f32 temp_f0;
19 UNUSED f32 var_f8;
20 UNUSED f32 pad2;
21 UNUSED f32 pad3;
22 UNUSED f32 pad4[2];
23 f32 temp_f12;
24 f32 temp_f2;
25 f32 temp_f14;
26 f32 temp_f16;
27 f32 unkX;
28 f32 unkY;
29 f32 unkZ;
30
31 player = &gPlayers[banana->rot[0]];
32 switch (banana->state) {
33 case HELD_BANANA:
34 temp_f2 = player->pos[0] - banana->pos[0];
35 temp_f14 = player->pos[1] - banana->pos[1];
36 temp_f16 = player->pos[2] - banana->pos[2];
37 temp_f12 = sqrtf((temp_f2 * temp_f2) + (temp_f14 * temp_f14) + (temp_f16 * temp_f16)) / 10.0f;
38 if (temp_f12 == 0.0f) {
39 banana->pos[0] = player->pos[0] + 0.2f;
40 banana->pos[1] = player->pos[1] + 0.2f;
41 banana->pos[2] = player->pos[2] + 0.2f;
42 } else {
43 temp_f2 /= temp_f12;
44 temp_f14 /= temp_f12;
45 temp_f16 /= temp_f12;
46 banana->pos[0] = player->pos[0] - temp_f2;
47 banana->pos[1] = player->pos[1] - temp_f14 - 2.0f;
48 banana->pos[2] = player->pos[2] - temp_f16;
49 }
50 check_bounding_collision(&banana->unk30, banana->boundingBoxSize + 1.0f, banana->pos[0], banana->pos[1],
51 banana->pos[2]);
52 func_802B4E30((struct Actor*) banana);
53 if ((player->type & PLAYER_HUMAN) != 0) {
54 if (gDemoMode) {
55 controller = gControllerOne;
56 } else {
57 controller = &gControllers[banana->rot[0]];
58 }
59 if ((controller->buttonDepressed & Z_TRIG) != 0) {
60 controller->buttonDepressed &= ~Z_TRIG;
61 banana->state = 1;
62 banana->unk_04 = 0x00B4;
63 player->soundEffects &= ~HOLD_BANANA_SOUND_EFFECT;
64 func_800C9060(player - gPlayerOne, SOUND_ARG_LOAD(0x19, 0x00, 0x80, 0x12));
65 pad3 = controller->rawStickY;
66 if ((pad3 > 30.0f) && (controller->rawStickX < 10) && (controller->rawStickX >= -9)) {
67 pad3 = pad3 - ((f32) 30);
68 pad3 = (pad3 / 20.0f) + 0.5f;
69 if (player->unk_094 < 2.0f) {
70 temp_f0 = 4.0f;
71 } else {
72 temp_f0 = (player->unk_094 * 0.75f) + 3.5f + pad3;
73 }
74 vec3f_set(someVelocity, 0, pad3, temp_f0);
75 func_802B64C4(someVelocity, player->rotation[1] + player->unk_0C0);
76 banana->velocity[0] = someVelocity[0];
77 banana->velocity[1] = someVelocity[1];
78 banana->velocity[2] = someVelocity[2];
79 } else {
80 banana->velocity[0] = 0;
81 banana->velocity[1] = 1.5f;
82 banana->velocity[2] = 0;
83 }
84 }
85 }
86 break;
87 case DROPPED_BANANA:
88 if (banana->unk_04 != 0) {
89 banana->unk_04 -= 1;
90 if (banana->unk_04 == 0) {
91 banana->flags &= ~0x1000;
92 }
93 }
94 banana->pos[0] += banana->velocity[0];
95 banana->pos[2] += banana->velocity[2];
96 if (banana->velocity[1] > -1.0f) {
97 banana->velocity[1] -= 0.15f;
98 }
99 banana->pos[1] += banana->velocity[1];
100 if ((banana->pos[2] < (f32) gCourseMinZ) || ((f32) gCourseMaxZ < banana->pos[2]) ||
101 (banana->pos[0] < (f32) gCourseMinX) || ((f32) gCourseMaxX < banana->pos[0]) ||
102 (banana->pos[1] < (f32) gCourseMinY)) {
103 destroy_destructable_actor((struct Actor*) banana);
104 } else {
105 check_bounding_collision(&banana->unk30, banana->boundingBoxSize + 1.0f, banana->pos[0], banana->pos[1],
106 banana->pos[2]);
107 banana->unk30.unk34 = 1;
108 if ((banana->unk30.unk34 != 0) && (banana->unk30.surfaceDistance[2] < 0.0f)) {
109 someOtherVelocity[0] = -banana->unk30.orientationVector[0];
110 someOtherVelocity[1] = -banana->unk30.orientationVector[1];
111 someOtherVelocity[2] = -banana->unk30.orientationVector[2];
112 banana->pos[0] += someOtherVelocity[0] * banana->unk30.surfaceDistance[2];
113 banana->pos[1] += someOtherVelocity[1] * banana->unk30.surfaceDistance[2];
114 banana->pos[2] += someOtherVelocity[2] * banana->unk30.surfaceDistance[2];
115 banana->flags &= ~0x1000;
116 banana->state = 4;
117 }
118 }
119 break;
121 someVelocity[0] = 0.0f;
122 someVelocity[1] = 0.0f;
123 someVelocity[2] = -5.0f;
124 func_802B64C4(someVelocity, player->rotation[1] + player->unk_0C0);
125 unkX = player->pos[0] + someVelocity[0];
126 unkY = player->pos[1] + someVelocity[1];
127 unkZ = player->pos[2] + someVelocity[2];
128 temp_f2 = unkX - banana->pos[0];
129 temp_f14 = unkY - banana->pos[1];
130 temp_f16 = unkZ - banana->pos[2];
131 temp_f0 = sqrtf((temp_f2 * temp_f2) + (temp_f14 * temp_f14) + (temp_f16 * temp_f16));
132 if (temp_f0 == 0.0f) {
133 banana->pos[0] = player->pos[0] + 0.2f;
134 banana->pos[1] = player->pos[1] + 0.2f;
135 banana->pos[2] = player->pos[2] + 0.2f;
136 } else {
137 temp_f2 /= temp_f0;
138 temp_f14 /= temp_f0;
139 temp_f16 /= temp_f0;
140 banana->pos[0] = someVelocity[0] + (unkX - temp_f2);
141 banana->pos[1] = unkY - temp_f14 - 2.0f;
142 banana->pos[2] = unkZ - temp_f16;
143 }
144 check_bounding_collision(&banana->unk30, banana->boundingBoxSize + 1.0f, banana->pos[0], banana->pos[1],
145 banana->pos[2]);
146 func_802B4E30((struct Actor*) banana);
147 break;
149 elderBanana = (struct BananaActor*) &gActorList[banana->elderIndex];
150 temp_f2 = elderBanana->pos[0] - banana->pos[0];
151 temp_f14 = elderBanana->pos[1] - banana->pos[1];
152 temp_f16 = elderBanana->pos[2] - banana->pos[2];
153 temp_f12 = sqrtf((temp_f2 * temp_f2) + (temp_f14 * temp_f14) + (temp_f16 * temp_f16)) / 5.0f;
154 if (temp_f12 == 0.0f) {
155 banana->pos[0] = elderBanana->pos[0] + 0.2f;
156 banana->pos[1] = elderBanana->pos[1] + 0.2f;
157 banana->pos[2] = elderBanana->pos[2] + 0.2f;
158 } else {
159 temp_f2 /= temp_f12;
160 temp_f14 /= temp_f12;
161 temp_f16 /= temp_f12;
162 banana->pos[0] = elderBanana->pos[0] - temp_f2;
163 banana->pos[1] = elderBanana->pos[1] - temp_f14 - 2.0f;
164 banana->pos[2] = elderBanana->pos[2] - temp_f16;
165 }
166 var_f8 = banana->pos[2];
167 check_bounding_collision(&banana->unk30, banana->boundingBoxSize + 1.0f, banana->pos[0], banana->pos[1],
168 banana->pos[2]);
169 func_802B4E30((struct Actor*) banana);
170 break;
171 case DESTROYED_BANANA:
172 banana->velocity[1] -= 0.3f;
173 if (banana->velocity[1] < -5.0f) {
174 banana->velocity[1] = -5.0f;
175 }
176 banana->pos[1] += banana->velocity[1];
177 banana->rot[0] += 0x16C;
178 banana->rot[1] -= 0x5B0;
179 banana->rot[2] += 0x38E;
180 banana->unk_04 -= 1;
181 if (banana->unk_04 == 0) {
182 destroy_actor((struct Actor*) banana);
183 }
184 break;
185 case BANANA_ON_GROUND:
186 banana->flags |= 0xC000;
187 banana->flags &= ~0x1000;
188 break;
189 default:
190 break;
191 }
192}
@ BANANA_ON_GROUND
Definition actor_types.h:111
@ DROPPED_BANANA
Definition actor_types.h:108
@ DESTROYED_BANANA
Definition actor_types.h:112
@ HELD_BANANA
Definition actor_types.h:107
@ BANANA_BUNCH_BANANA
Definition actor_types.h:110
@ FIRST_BANANA_BUNCH_BANANA
Definition actor_types.h:109
void destroy_destructable_actor(struct Actor *actor)
Definition actors.c:1841
void destroy_actor(struct Actor *actor)
Definition actors.c:1313
void func_802B4E30(struct Actor *arg0)
Definition actors_extended.c:972
void update_actor_banana(struct BananaActor *banana)
Update the banana actor.
Definition update.inc.c:11
s16 gCourseMinZ
Definition code_800029B0.c:93
s16 gCourseMaxZ
Definition code_800029B0.c:92
s16 gCourseMinX
Definition code_800029B0.c:87
struct Actor gActorList[ACTOR_LIST_SIZE]
Definition code_800029B0.c:148
s16 gCourseMinY
Definition code_800029B0.c:90
s16 gCourseMaxX
Definition code_800029B0.c:86
u16 check_bounding_collision(Collision *collision, f32 boundingBoxSize, f32 posX, f32 posY, f32 posZ)
Definition collision.c:1356
f32 Vec3f[3]
Definition common_structs.h:6
#define PLAYER_HUMAN
Definition defines.h:101
void func_800C9060(u8 playerId, u32 soundBits)
Definition external.c:2862
#define UNUSED
Definition macros.h:23
Player * gPlayerOne
Definition main.c:72
Player gPlayers[NUM_PLAYERS]
Definition main.c:71
struct Controller gControllers[NUM_PLAYERS]
Definition main.c:61
u16 gDemoMode
Definition main.c:172
struct Controller * gControllerOne
Definition main.c:62
float sqrtf(float)
void func_802B64C4(Vec3f arg0, s16 arg1)
Definition math_util.c:606
void vec3f_set(Vec3f arg0, f32 arg1, f32 arg2, f32 arg3)
Definition math_util.c:103
#define Z_TRIG
Definition os.h:393
#define SOUND_ARG_LOAD(sound_bank, byte2, byte3, sound_id)
Definition sounds.h:14
Definition actor_types.h:120
s16 state
Definition actor_types.h:124
Vec3s rot
Definition actor_types.h:127
Vec3f velocity
Definition actor_types.h:130
Collision unk30
Definition actor_types.h:131
s16 unk_04
Definition actor_types.h:123
s16 flags
Definition actor_types.h:122
Vec3f pos
Definition actor_types.h:129
f32 boundingBoxSize
Definition actor_types.h:126
Definition actor_types.h:380
Vec3s rot
Definition actor_types.h:389
Collision unk30
Definition actor_types.h:399
f32 boundingBoxSize
Definition actor_types.h:387
Vec3f pos
Definition actor_types.h:397
s16 state
Definition actor_types.h:384
Vec3f surfaceDistance
Definition common_structs.h:140
Vec3f orientationVector
Definition common_structs.h:143
u16 unk34
Definition common_structs.h:135
Definition common_structs.h:62
s16 rawStickY
Definition common_structs.h:64
s16 rawStickX
Definition common_structs.h:63
u16 buttonDepressed
Definition common_structs.h:67
Definition common_structs.h:249
s16 unk_0C0
Definition common_structs.h:299
f32 unk_094
Definition common_structs.h:284
Vec3s rotation
Definition common_structs.h:261
u16 type
Definition common_structs.h:250
s32 soundEffects
Definition common_structs.h:256
Vec3f pos
Definition common_structs.h:259
float f32
Definition ultratypes.h:34