Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
StarBoxLauncher.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects.h"
3#include "entity.h"
4#include "ld_addrs.h"
5
8extern unsigned char D_0A000D08_E56748[];
9extern unsigned char D_0A000508_E55F48[];
10
12 0x00, 0x02,
13 0xE0, 0x02,
14 0xC0, 0x02,
15 0xA0, 0x02,
16 0x00, 0x02,
17 0xE0, 0x02,
18 0xC0, 0x02,
19 0xA0, 0x02,
20 0x00, 0x02,
21 0xE0, 0x02,
22 0xC0, 0x02,
23 0xA0, 0x02,
24 0x00, 0x02,
25 0xE0, 0x02,
26 0xC0, 0x02,
27 0xA0, 0x02,
28 0x00, 0x02,
29 0xFF, 0x00
30};
31
32void entity_StarBoxLauncher_setupGfx(s32 entityIndex) {
33 Gfx* gfxPos = gMainGfxPos;
34 Entity* entity = get_entity_by_index(entityIndex);
36 Matrix4f sp10;
37 Matrix4f sp50;
38
39 guMtxIdentF(sp10);
40 guTranslateF(sp50, entity->pos.x, data->basePosY, entity->pos.z);
41 guMtxCatF(sp50, sp10, sp50);
43 gSPMatrix(gfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
44 gSPDisplayList(gfxPos++, ENTITY_ADDR(entity, Gfx*, Entity_StarBoxLauncher_RenderBottom));
45 gSPPopMatrix(gfxPos++, G_MTX_MODELVIEW);
46
47 gDPPipeSync(gfxPos++);
48 gDPSetTextureLUT(gfxPos++, G_TT_RGBA16);
49 gDPLoadTLUT_pal16(gfxPos++, 0, D_0A000D08_E56748);
50 gSPTexture(gfxPos++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
51 gDPSetCombineMode(gfxPos++, G_CC_MODULATEIA, G_CC_MODULATEIA);
52 gDPSetTextureDetail(gfxPos++, G_TD_CLAMP);
53 gDPSetTextureLOD(gfxPos++, G_TL_TILE);
54 gDPLoadTextureBlock_4b(gfxPos++, D_0A000508_E55F48, G_IM_FMT_CI, 128, 32, 0, G_TX_MIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 7, 5, G_TX_NOLOD, G_TX_NOLOD);
55 gDPSetTexturePersp(gfxPos++, G_TP_PERSP);
56 gDPSetTextureFilter(gfxPos++, G_TF_BILERP);
57 gDPSetTileSize(gfxPos++, G_TX_RENDERTILE, data->faceTexOffset * 4, 0, (data->faceTexOffset + 124) * 4, 31 * 4);
58
59 gMainGfxPos = gfxPos;
60}
61
63 u16 currentFloor = gCollisionStatus.curFloor;
65 PlayerStatus* playerStatus = &gPlayerStatus;
66 s32 actionState = playerStatus->actionState;
67 f32 x,y,z,hitDepth;
68 s32 result = 0;
69
70 if ((currentFloor & COLLISION_WITH_ENTITY_BIT) && (currentFloor & 0xFF) == entity->listIndex && actionState == ACTION_STATE_HAMMER) {
71 x = playerStatus->pos.x;
72 y = playerStatus->pos.y + 5.0f;
73 z = playerStatus->pos.z;
74 hitDepth = 10.0f;
75
76 add_vec2D_polar(&x, &z, 10.0f, player_get_side_angle());
77 if (npc_raycast_down_sides(COLLIDER_FLAG_IGNORE_PLAYER, &x, &y, &z, &hitDepth) != 0) {
80 }
81 }
82 } else if ((entity->collisionFlags & ENTITY_COLLISION_PLAYER_TOUCH_FLOOR) && (actionState == ACTION_STATE_SPIN_POUND || actionState == ACTION_STATE_TORNADO_POUND)) {
83 result = 1;
85 result = -1;
86 }
87
88 if (result != 0) {
89 data->flags &= ~1;
90 fx_damage_stars(FX_DAMAGE_STARS_3, entity->pos.x, entity->pos.y + 35.0f, entity->pos.z, 0, -1.0f, 0, 3);
91 if (result > 0) {
92 data->flags |= 1;
93 }
94 entity->pos.y -= 2.0f;
96 data->timer = 4;
98 playerStatus->camResetDelay = 5;
99 }
100}
101
104 s32 i;
105
106 data->faceAnimTimer--;
107 if (data->faceAnimTimer <= 0) {
108 i = data->faceDataIndex;
109 if (D_802BCAA0_E313F0[i] != 0xFF) {
110 data->faceTexOffset = D_802BCAA0_E313F0[i++];
111 data->faceAnimTimer = D_802BCAA0_E313F0[i++];
112 data->faceDataIndex = i;
113 }
114 }
115}
116
119 entity->pos.x = data->basePosX + (data->timer & 1 ? 1.0f : -1.0f);
120 data->timer--;
121}
122
125 entity->pos.x = data->basePosX;
126 entity->pos.z = data->basePosZ;
127}
128
131 f64 temp;
132
133 switch (data->state) {
134 case 0:
135 data->faceAnimTimer = 0;
136 data->faceDataIndex = 0;
137 data->state++;
138 data->riseSpeedPhase = 90.0f;
142 // fallthrough
143 case 1:
144 temp = entity->pos.y;
145 entity->pos.y = temp + 8.0 * sin_rad(DEG_TO_RAD(data->riseSpeedPhase));
146 data->riseSpeedPhase += 2.0f;
147 if (data->riseSpeedPhase >= 180.0f) {
148 data->riseSpeedPhase = 180.0f;
149 }
150
151 if (entity->pos.y > data->basePosY + 50.0f) {
152 entity->pos.y = data->basePosY + 50.0f;
153 data->maxRotZ = 2.0f;
154 data->state++;
155 data->riseVel = 3.0f;
156 data->rotZPhase = 90.0f;
157 }
158 break;
159 case 2:
160 entity->rot.z = data->maxRotZ * sin_rad(DEG_TO_RAD(data->rotZPhase));
161 clamp_angle(entity->rot.z);
162 data->rotZPhase += 30.0f;
163 if (data->rotZPhase >= 360.0f) {
164 data->rotZPhase -= 360.0f;
165 }
166
167 entity->pos.y += data->riseVel * cos_rad(DEG_TO_RAD(data->riseSpeedPhase));
168 data->riseSpeedPhase += 30.0f;
169 if (data->riseSpeedPhase >= 360.0f) {
170 data->riseSpeedPhase -= 360.0f;
171 }
172
173 data->riseVel -= 0.08;
174 if (data->riseVel < 2.8) {
175 data->state++;
176 }
177 break;
178 case 3:
179 data->maxRotZ -= 0.1;
180 if (data->maxRotZ <= 0.0f) {
181 data->maxRotZ = 0.0f;
182 }
183
184 entity->rot.z = data->maxRotZ * sin_rad(DEG_TO_RAD(data->rotZPhase));
185 clamp_angle(entity->rot.z);
186 data->rotZPhase += 30.0f;
187 if (data->rotZPhase >= 360.0f) {
188 data->rotZPhase -= 360.0f;
189 }
190
192
193 entity->pos.y += data->riseVel * cos_rad(DEG_TO_RAD(data->riseSpeedPhase));
194 data->riseSpeedPhase += 30.0f;
195 if (data->riseSpeedPhase >= 360.0f) {
196 data->riseSpeedPhase -= 360.0f;
197 }
198
199 data->riseVel -= 0.08;
200 if (data->riseVel <= 0.0f) {
201 data->riseVel = 0.0f;
202 data->timer = 8;
203 data->state++;
204 entity->rot.z = 0.0f;
205 }
206 break;
207 case 4:
208 if (--data->timer == 0) {
209 data->state++;
210 }
211 break;
212 case 5:
213 entity->pos.y -= 8.0f;
214 if (entity->pos.y <= data->basePosY) {
215 entity->pos.y = data->basePosY;
216 data->state++;
217 }
218 break;
219 case 6:
221 data->state = 0;
223 break;
224 }
225}
226
228 if (!(entity->flags & ENTITY_FLAG_2000000)) {
230 }
231}
232
235 if (data->flags & 1) {
236 entity_start_script(entity);
237 }
238}
239
243 data->basePosX = entity->pos.x;
244 data->basePosY = entity->pos.y;
245 data->basePosZ = entity->pos.z;
246}
247
260
262
265 .typeDataSize = sizeof(StarBoxLauncherData),
266 .renderCommandList = Entity_StarBoxLauncher_RenderScript,
267 .modelAnimationNodes = 0,
269 .updateEntityScript = Entity_StarBoxLauncher_Script,
270 .fpHandleCollision = NULL,
271 { .dma = ENTITY_ROM(StarBoxLauncher) },
272 .entityType = ENTITY_TYPE_STAR_BOX_LAUNCHER,
273 .aabbSize = { 35, 35, 35 }
274};
struct StarBoxLauncherData * starBoxLauncher
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define npc_raycast_down_sides
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define clamp_angle
@ FX_DAMAGE_STARS_3
Definition effects.h:359
s32 EntityModelScript[]
Definition entity.h:7
#define es_Call(func)
Definition entity.h:37
#define es_Restart
Definition entity.h:40
#define STANDARD_ENTITY_MODEL_SCRIPT(gfx, renderMode)
Definition entity.h:56
#define ENTITY_ADDR(entity, type, data)
Definition entity.h:64
#define es_SetCallback(func, time)
Definition entity.h:38
#define ENTITY_ROM(name)
Definition entity.h:65
s32 EntityScript[]
Definition entity.h:6
#define es_End
Definition entity.h:35
@ COLLIDER_FLAG_IGNORE_PLAYER
Definition enums.h:4696
@ ENTITY_TYPE_STAR_BOX_LAUNCHER
Definition enums.h:2586
@ ENTITY_COLLISION_PLAYER_HAMMER
Definition enums.h:2654
@ ENTITY_COLLISION_PLAYER_TOUCH_FLOOR
Definition enums.h:2648
@ SOUND_STAR_BOX_LAUNCHER
Definition enums.h:1426
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3264
@ ENTITY_FLAG_8000
Definition enums.h:2628
@ ENTITY_FLAG_2000000
Definition enums.h:2638
@ ACTION_STATE_SPIN_POUND
Definition enums.h:2442
@ ACTION_STATE_TORNADO_POUND
Definition enums.h:2444
@ ACTION_STATE_HAMMER
Definition enums.h:2446
Entity * get_entity_by_index(s32 index)
Definition entity.c:530
s32 entity_start_script(Entity *entity)
Definition entity.c:560
s32 disable_player_static_collisions(void)
Definition 77480.c:972
f32 cos_rad(f32 x)
Definition 43F0.c:717
f32 player_get_side_angle(void)
Definition 7BB60.c:1178
u32 get_entity_type(s32 arg0)
Definition entity.c:568
void exec_entity_commandlist(Entity *entity)
Definition entity.c:313
f32 sin_rad(f32 x)
Definition 43F0.c:713
s32 enable_player_static_collisions(void)
Definition 77480.c:980
void add_vec2D_polar(f32 *x, f32 *y, f32 r, f32 theta)
Definition 43F0.c:685
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
void entity_StarBoxLauncher_init(Entity *entity)
Gfx Entity_StarBoxLauncher_RenderTop[]
EntityModelScript Entity_StarBoxLauncher_RenderScript
void entity_StarBoxLauncher_shake_box(Entity *entity)
void entity_StarBoxLauncher_setupGfx(s32 entityIndex)
void func_802BC99C_E312EC(Entity *entity)
void entity_StarBoxLauncher_launch(Entity *entity)
void entity_StarBoxLauncher_update_face_anim(Entity *entity)
void entity_StarBoxLauncher_start_script(Entity *entity)
unsigned char D_0A000508_E55F48[]
u8 D_802BCAA0_E313F0[]
unsigned char D_0A000D08_E56748[]
void entity_StarBoxLauncher_restore_pos(Entity *entity)
EntityScript Entity_StarBoxLauncher_Script
void entity_StarBoxLauncher_check_launch(Entity *entity)
EntityBlueprint Entity_StarBoxLauncher
Gfx Entity_StarBoxLauncher_RenderBottom[]
#define COLLISION_WITH_ENTITY_BIT
Definition macros.h:152
#define DEG_TO_RAD(deg)
Definition macros.h:134
void(* renderSetupFunc)(s32)
EntityData dataBuf
u8 collisionFlags
CollisionStatus gCollisionStatus
Definition 7BB60.c:6
s32 NpcHitQueryColliderID
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
PlayerStatus gPlayerStatus
Definition 77480.c:39
DisplayContext * gDisplayContext
Definition cam_main.c:16
void fx_damage_stars(s32, f32, f32, f32, f32, f32, f32, s32)