Mario Kart 64
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
13 Player* player;
14 UNUSED f32 pad9;
15 UNUSED f32 padA;
16 Vec3f somePos2;
17 Vec3f somePosVel;
18 f32 var_f2;
19 struct Controller* controller;
20 TripleShellParent* parent;
21 f32 height;
22 f32 z;
23 UNUSED f32 pad2;
24 UNUSED f32 pad3;
25 UNUSED f32 pad4;
26 UNUSED f32 pad5;
27 f32 y;
28 UNUSED f32 pad7;
29 UNUSED f32 pad8;
30
31 height = shell->pos[0];
32 y = shell->pos[1];
33 z = shell->pos[2];
34 if ((z < gCourseMinZ) || (gCourseMaxZ < z) || (height < gCourseMinX) || (gCourseMaxX < height) ||
35 (y < gCourseMinY)) {
36 destroy_destructable_actor((struct Actor*) shell);
37 }
38 shell->rotVelocity += DEGREES(10);
39 switch (shell->state) {
40 case HELD_SHELL:
41 player = &gPlayers[shell->playerId];
42 copy_collision(&player->collision, &shell->unk30);
43 somePosVel[0] = 0.0f;
44 somePosVel[1] = player->boundingBoxSize;
45 somePosVel[2] = -(player->boundingBoxSize + shell->boundingBoxSize + 2.0f);
47 shell->pos[0] = player->pos[0] + somePosVel[0];
48 pad2 = player->pos[1] - somePosVel[1];
49 shell->pos[2] = player->pos[2] + somePosVel[2];
50 height = calculate_surface_height(shell->pos[0], pad2, shell->pos[2], player->collision.meshIndexZX);
51 z = pad2 - height;
52 if ((z < 5.0f) && (z > -5.0f)) {
53 shell->pos[1] = shell->boundingBoxSize + height;
54 } else {
55 shell->pos[1] = pad2;
56 }
57 if ((player->type & PLAYER_HUMAN) != 0) {
58 controller = &gControllers[shell->playerId];
59 if ((controller->buttonDepressed & Z_TRIG) != 0) {
60 controller->buttonDepressed &= ~Z_TRIG;
61 if (controller->rawStickY < -0x2D) {
62 var_f2 = 8.0f;
63 if (player->speed > 8.0f) {
64 var_f2 = player->speed * 1.2f;
65 }
66 somePosVel[0] = 0.0f;
67 somePosVel[1] = 0.0f;
68 somePosVel[2] = -var_f2;
69 vec3f_rotate_y(somePosVel, player->rotation[1] + player->unk_0C0);
70 shell->velocity[0] = somePosVel[0];
71 shell->velocity[1] = somePosVel[1];
72 shell->velocity[2] = somePosVel[2];
73 shell->state = 2;
74 func_800C9060(shell->playerId, SOUND_ARG_LOAD(0x19, 0x00, 0x80, 0x04));
76 (player->characterId * 0x10) + SOUND_ARG_LOAD(0x29, 0x00, 0x80, 0x00));
78 return;
79 } else {
80 shell->state = 1;
81 if (player->unk_0C0 > 0) {
82 shell->rotAngle = DEGREES(170);
83 } else {
84 // The minus 1 is almost certainly just due to rounding the other way
85 shell->rotAngle = -DEGREES(170) - 1;
86 }
87 }
88 }
89 }
90 break;
91 case RELEASED_SHELL:
92 player = &gPlayers[shell->playerId];
93 if (shell->rotAngle > 0) {
94 shell->rotAngle -= DEGREES(20);
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 += DEGREES(20);
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 vec3f_rotate_y(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_transform_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*) &gActorList[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_transform_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 += DEGREES(8);
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}
@ ACTOR_TRIPLE_GREEN_SHELL
Definition actor_types.h:59
@ MOVING_SHELL
Definition actor_types.h:95
@ HELD_SHELL
Definition actor_types.h:93
@ RELEASED_SHELL
Definition actor_types.h:94
@ GREEN_SHELL_HIT_A_RACER
Definition actor_types.h:98
@ TRIPLE_GREEN_SHELL
Definition actor_types.h:97
void destroy_destructable_actor(struct Actor *actor)
Definition actors.c:1849
void destroy_actor(struct Actor *actor)
Definition actors.c:1321
void copy_collision(Collision *src, Collision *dest)
Definition actors_extended.c:19
void func_802B4E30(struct Actor *arg0)
Definition actors_extended.c:973
s16 gCourseMinZ
Definition code_800029B0.c:95
s16 gCourseMaxZ
Definition code_800029B0.c:94
s16 gCourseMinX
Definition code_800029B0.c:89
struct Actor gActorList[ACTOR_LIST_SIZE]
Definition code_800029B0.c:150
s16 gCourseMinY
Definition code_800029B0.c:92
s16 gCourseMaxX
Definition code_800029B0.c:88
void shell_collision(Collision *collision, Vec3f velocity)
Definition collision.c:596
f32 calculate_surface_height(f32 x, f32 y, f32 z, u16 index)
Definition collision.c:529
u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 newX, f32 newY, f32 newZ, f32 oldX, f32 oldY, f32 oldZ)
Definition collision.c:1238
f32 Vec3f[3]
Definition common_structs.h:6
s32 add_green_shell_in_unexpired_actor_list(s32)
Definition actor_utils.inc.c:30
#define DEGREES(degree)
Definition defines.h:347
#define PLAYER_HUMAN
Definition defines.h:105
void func_800C9060(u8 playerId, u32 soundBits)
Definition external.c:2922
void func_800C90F4(u8 playerId, u32 soundBits)
Definition external.c:2935
void func_800C98B8(Vec3f position, Vec3f velocity, u32 soundBits)
Definition external.c:3089
void update_actor_green_shell(struct ShellActor *shell)
Updates the green shell actor.
Definition update.inc.c:12
#define UNUSED
Definition macros.h:23
Player gPlayers[NUM_PLAYERS]
Definition main.c:68
struct Controller gControllers[NUM_PLAYERS]
Definition main.c:58
void mtxf_transform_vec3f_mat3(Vec3f vec, Mat3 mtx)
Definition math_util.c:706
f32 coss(u16 angle)
Definition math_util.c:1319
void vec3f_rotate_y(Vec3f vec, s16 rotAngleY)
Definition math_util.c:747
f32 sins(u16 angle)
Definition math_util.c:1310
#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
Vec3f velocity
Definition actor_types.h:130
Collision unk30
Definition actor_types.h:131
s16 flags
Definition actor_types.h:122
Vec3f pos
Definition actor_types.h:129
f32 boundingBoxSize
Definition actor_types.h:126
Vec3f surfaceDistance
Definition common_structs.h:140
u16 meshIndexZX
Definition common_structs.h:139
Definition common_structs.h:62
s16 rawStickY
Definition common_structs.h:64
u16 buttonDepressed
Definition common_structs.h:67
Definition common_structs.h:249
s16 unk_0C0
Definition common_structs.h:299
f32 speed
Definition common_structs.h:284
Mat3 orientationMatrix
Definition common_structs.h:326
u16 characterId
Definition common_structs.h:354
Vec3s rotation
Definition common_structs.h:261
Collision collision
Definition common_structs.h:324
f32 boundingBoxSize
Definition common_structs.h:274
u16 type
Definition common_structs.h:250
Vec3f pos
Definition common_structs.h:259
Definition actor_types.h:304
s16 rotAngle
Definition actor_types.h:320
s16 rotVelocity
Definition actor_types.h:318
s16 flags
Definition actor_types.h:306
f32 boundingBoxSize
Definition actor_types.h:317
s16 state
Definition actor_types.h:315
s16 playerId
Definition actor_types.h:324
Vec3f velocity
Definition actor_types.h:327
s16 parentIndex
Definition actor_types.h:310
Vec3f pos
Definition actor_types.h:326
Collision unk30
Definition actor_types.h:328
s16 someTimer
Definition actor_types.h:311
Definition actor_types.h:288
s16 rotVelocity
Definition actor_types.h:295
s16 type
Definition actor_types.h:289
float f32
Definition ultratypes.h:34