SpaghettiKart
Loading...
Searching...
No Matches
update.inc.c
Go to the documentation of this file.
1#include <actors.h>
2#include <main.h>
3#include <code_800029B0.h>
4#include <defines.h>
5#include "collision.h"
6#include "port/Game.h"
7
14 Player* player;
15 UNUSED f32 pad9;
16 UNUSED f32 padA;
17 Vec3f somePos2;
18 Vec3f somePosVel;
19 f32 var_f2;
20 struct Controller* controller;
21 TripleShellParent* parent;
22 f32 height;
23 f32 z;
24 UNUSED f32 pad2;
25 UNUSED f32 pad3;
26 UNUSED f32 pad4;
27 UNUSED f32 pad5;
28 f32 y;
29 UNUSED f32 pad7;
30 UNUSED f32 pad8;
31
32 height = shell->pos[0];
33 y = shell->pos[1];
34 z = shell->pos[2];
35 if ((z < gTrackMinZ) || (gTrackMaxZ < z) || (height < gTrackMinX) || (gTrackMaxX < height) ||
36 (y < gTrackMinY)) {
37 destroy_destructable_actor((struct Actor*) shell);
38 }
39 shell->rotVelocity += 0x71C;
40 switch (shell->state) {
41 case HELD_SHELL:
42 player = &gPlayers[shell->playerId];
43 copy_collision(&player->collision, &shell->unk30);
44 somePosVel[0] = 0.0f;
45 somePosVel[1] = player->boundingBoxSize;
46 somePosVel[2] = -(player->boundingBoxSize + shell->boundingBoxSize + 2.0f);
48 shell->pos[0] = player->pos[0] + somePosVel[0];
49 pad2 = player->pos[1] - somePosVel[1];
50 shell->pos[2] = player->pos[2] + somePosVel[2];
51 height = calculate_surface_height(shell->pos[0], pad2, shell->pos[2], player->collision.meshIndexZX);
52 z = pad2 - height;
53 if ((z < 5.0f) && (z > -5.0f)) {
54 shell->pos[1] = shell->boundingBoxSize + height;
55 } else {
56 shell->pos[1] = pad2;
57 }
58 if ((player->type & PLAYER_HUMAN) != 0) {
59 controller = &gControllers[shell->playerId];
60 if ((controller->buttonDepressed & Z_TRIG) != 0) {
61 controller->buttonDepressed &= ~Z_TRIG;
62 if (controller->rawStickY < THROW_SHELL_BACKWARDS) {
63 var_f2 = 8.0f;
64 if (player->speed > 8.0f) {
65 var_f2 = player->speed * 1.2f;
66 }
67 somePosVel[0] = 0.0f;
68 somePosVel[1] = 0.0f;
69 somePosVel[2] = -var_f2;
70 func_802B64C4(somePosVel, player->rotation[1] + player->unk_0C0);
71 shell->velocity[0] = somePosVel[0];
72 shell->velocity[1] = somePosVel[1];
73 shell->velocity[2] = somePosVel[2];
74 shell->state = MOVING_SHELL;
75 func_800C9060(shell->playerId, SOUND_ARG_LOAD(0x19, 0x00, 0x80, 0x04));
77 (player->characterId * 0x10) + SOUND_ARG_LOAD(0x29, 0x00, 0x80, 0x00));
79 return;
80 } else {
81 shell->state = RELEASED_SHELL;
82 if (player->unk_0C0 > 0) {
83 shell->rotAngle = 0x78E3;
84 } else {
85 shell->rotAngle = -0x78E4;
86 }
87 }
88 }
89 }
90 break;
91 case RELEASED_SHELL:
92 player = &gPlayers[shell->playerId];
93 if (shell->rotAngle > 0) {
94 shell->rotAngle -= 0xE38;
95 if (shell->rotAngle < 0) {
96 shell->state = 2;
97 shell->someTimer = 0x001E;
98 func_800C9060(shell->playerId, SOUND_ARG_LOAD(0x19, 0x00, 0x80, 0x04));
100 (player->characterId * 0x10) + SOUND_ARG_LOAD(0x29, 0x00, 0x80, 0x00));
102 }
103 } else {
104 shell->rotAngle += 0xE38;
105 if (shell->rotAngle > 0) {
106 shell->state = 2;
107 shell->someTimer = 0x001E;
108 func_800C9060(shell->playerId, SOUND_ARG_LOAD(0x19, 0x00, 0x80, 0x04));
109 func_800C90F4(shell->playerId,
110 (player->characterId * 0x10) + SOUND_ARG_LOAD(0x29, 0x00, 0x80, 0x00));
112 }
113 }
114 if (shell->state == 2) {
115 var_f2 = 8.0f;
116 if (player->speed > 8.0f) {
117 var_f2 = player->speed * 1.2f;
118 }
119 somePosVel[0] = 0.0f;
120 somePosVel[1] = 0.0f;
121 somePosVel[2] = var_f2;
122 func_802B64C4(somePosVel, player->rotation[1] + player->unk_0C0);
123 shell->velocity[0] = somePosVel[0];
124 shell->velocity[1] = somePosVel[1];
125 shell->velocity[2] = somePosVel[2];
126 } else {
127 somePosVel[0] = sins(shell->rotAngle) * 6.0f;
128 somePosVel[1] = shell->boundingBoxSize - player->boundingBoxSize;
129 somePosVel[2] = coss(shell->rotAngle) * 6.0f;
130 mtxf_translate_vec3f_mat3(somePosVel, player->orientationMatrix);
131 shell->pos[0] = player->pos[0] + somePosVel[0];
132 shell->pos[1] = player->pos[1] + somePosVel[1];
133 shell->pos[2] = player->pos[2] + somePosVel[2];
134 }
135 break;
136 case MOVING_SHELL:
137 if (shell->parentIndex > 0) {
138 shell->parentIndex -= 1;
139 if (shell->parentIndex == 0) {
140 shell->flags &= ~0x1000;
141 }
142 }
143 shell->velocity[1] -= 0.5f;
144 if (shell->velocity[1] < -2.0f) {
145 shell->velocity[1] = -2.0f;
146 }
147 somePos2[0] = shell->pos[0];
148 somePos2[1] = shell->pos[1];
149 somePos2[2] = shell->pos[2];
150 shell->pos[0] += shell->velocity[0];
151 shell->pos[1] += shell->velocity[1];
152 shell->pos[2] += shell->velocity[2];
153 actor_terrain_collision(&shell->unk30, 4.0f, shell->pos[0], shell->pos[1], shell->pos[2], somePos2[0],
154 somePos2[1], somePos2[2]);
155 func_802B4E30((struct Actor*) shell);
156 if ((shell->unk30.surfaceDistance[0] < 0.0f) || (shell->unk30.surfaceDistance[1] < 0.0f)) {
157 shell_collision(&shell->unk30, shell->velocity);
158 func_800C98B8(shell->pos, shell->velocity, SOUND_ARG_LOAD(0x19, 0x00, 0x80, 0x54));
159 shell->flags |= 0x80;
160 }
161 break;
163 player = &gPlayers[shell->playerId];
164 parent = (TripleShellParent*) GET_ACTOR(shell->parentIndex);
165 if (parent->type != ACTOR_TRIPLE_GREEN_SHELL) {
166 destroy_destructable_actor((struct Actor*) shell);
167 } else {
168 shell->rotAngle += parent->rotVelocity;
169 somePosVel[0] = sins(shell->rotAngle) * 8.0f;
170 somePosVel[1] = shell->boundingBoxSize - player->boundingBoxSize;
171 somePosVel[2] = coss(shell->rotAngle) * 8.0f;
172 mtxf_translate_vec3f_mat3(somePosVel, player->orientationMatrix);
173 somePos2[0] = shell->pos[0];
174 somePos2[1] = shell->pos[1];
175 somePos2[2] = shell->pos[2];
176 shell->pos[0] = player->pos[0] + somePosVel[0];
177 shell->pos[1] = player->pos[1] + somePosVel[1];
178 shell->pos[2] = player->pos[2] + somePosVel[2];
179 actor_terrain_collision(&shell->unk30, 4.0f, shell->pos[0], shell->pos[1], shell->pos[2], somePos2[0],
180 somePos2[1], somePos2[2]);
181 func_802B4E30((struct Actor*) shell);
182 }
183 break;
185 // Somehow, this fake match affects stack management up in case 2
186 shell->velocity[1] -= (0, 0.3f);
187 if (shell->velocity[1] < -5.0f) {
188 shell->velocity[1] = -5.0f;
189 }
190 shell->rotAngle += 0x5B0;
191 shell->someTimer -= 1;
192 shell->pos[1] += shell->velocity[1];
193 if (shell->someTimer == 0) {
194 destroy_actor((struct Actor*) shell);
195 }
196 break;
197 default:
198 break;
199 }
200}
size_t CM_FindActorIndex(Actor *actor)
Definition Game.cpp:742
@ ACTOR_TRIPLE_GREEN_SHELL
Definition actor_types.h:60
#define THROW_SHELL_BACKWARDS
Definition actor_types.h:107
@ MOVING_SHELL
Definition actor_types.h:97
@ HELD_SHELL
Definition actor_types.h:95
@ RELEASED_SHELL
Definition actor_types.h:96
@ GREEN_SHELL_HIT_A_RACER
Definition actor_types.h:100
@ TRIPLE_GREEN_SHELL
Definition actor_types.h:99
#define GET_ACTOR(index)
Definition actor_types.h:88
void destroy_destructable_actor(struct Actor *actor)
Definition actors.c:1739
void destroy_actor(struct Actor *actor)
Definition actors.c:1207
void copy_collision(Collision *src, Collision *dest)
Definition actors_extended.c:20
void func_802B4E30(struct Actor *arg0)
Definition actors_extended.c:990
s16 gTrackMinY
Definition code_800029B0.c:100
s16 gTrackMaxX
Definition code_800029B0.c:96
s16 gTrackMinZ
Definition code_800029B0.c:103
s16 gTrackMaxZ
Definition code_800029B0.c:102
s16 gTrackMinX
Definition code_800029B0.c:97
s32 add_green_shell_in_unexpired_actor_list(s32 actorIndex)
Definition code_80005FD0.c:3331
void shell_collision(Collision *collision, Vec3f velocity)
Definition collision.c:533
f32 calculate_surface_height(f32 x, f32 y, f32 z, u16 index)
Definition collision.c:466
u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 newX, f32 newY, f32 newZ, f32 oldX, f32 oldY, f32 oldZ)
Definition collision.c:1181
f32 Vec3f[3]
Definition common_structs.h:10
#define PLAYER_HUMAN
Definition defines.h:114
void func_800C9060(u8 playerId, u32 soundBits)
Definition external.c:2971
void func_800C90F4(u8 playerId, u32 soundBits)
Definition external.c:2984
void func_800C98B8(Vec3f position, Vec3f velocity, u32 soundBits)
Definition external.c:3136
void update_actor_green_shell(struct ShellActor *shell)
Updates the green shell actor.
Definition update.inc.c:13
#define UNUSED
Definition macros.h:40
Player gPlayers[NUM_PLAYERS]
Definition main.c:73
struct Controller gControllers[NUM_PLAYERS]
Definition main.c:63
f32 sins(u16 arg0)
Definition math_util.c:1062
void func_802B64C4(Vec3f arg0, s16 arg1)
Definition math_util.c:588
void mtxf_translate_vec3f_mat3(Vec3f pos, Mat3 mat)
Definition math_util.c:556
f32 coss(u16 arg0)
Definition math_util.c:1066
#define SOUND_ARG_LOAD(sound_bank, byte2, byte3, sound_id)
Definition sounds.h:14
Definition actor_types.h:124
Vec3f velocity
Definition actor_types.h:134
Collision unk30
Definition actor_types.h:135
s16 flags
Definition actor_types.h:126
Vec3f pos
Definition actor_types.h:133
f32 boundingBoxSize
Definition actor_types.h:130
Vec3f surfaceDistance
Definition common_structs.h:155
u16 meshIndexZX
Definition common_structs.h:154
Definition common_structs.h:66
s16 rawStickY
Definition common_structs.h:68
u16 buttonDepressed
Definition common_structs.h:73
Definition common_structs.h:264
s16 unk_0C0
Definition common_structs.h:314
f32 speed
Definition common_structs.h:299
Mat3 orientationMatrix
Definition common_structs.h:341
u16 characterId
Definition common_structs.h:369
Vec3s rotation
Definition common_structs.h:276
Collision collision
Definition common_structs.h:339
f32 boundingBoxSize
Definition common_structs.h:289
u16 type
Definition common_structs.h:265
Vec3f pos
Definition common_structs.h:274
Definition actor_types.h:320
s16 rotAngle
Definition actor_types.h:336
s16 rotVelocity
Definition actor_types.h:334
s16 flags
Definition actor_types.h:322
f32 boundingBoxSize
Definition actor_types.h:333
s16 state
Definition actor_types.h:331
s16 playerId
Definition actor_types.h:340
Vec3f velocity
Definition actor_types.h:343
s16 parentIndex
Definition actor_types.h:326
Vec3f pos
Definition actor_types.h:342
Collision unk30
Definition actor_types.h:344
s16 someTimer
Definition actor_types.h:327
Definition actor_types.h:303
s16 rotVelocity
Definition actor_types.h:310
s16 type
Definition actor_types.h:304