Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
SuperBlock.c
Go to the documentation of this file.
1#include "common.h"
2#include "vars_access.h"
3#include "effects.h"
4#include "ld_addrs.h"
5#include "entity.h"
6
7#if VERSION_JP // TODO remove once segments are split
8extern Addr entity_model_SuperBlockContent_ROM_END;
9extern Addr entity_model_SuperBlockContent_ROM_START;
10extern Addr entity_model_SuperBlock_ROM_END;
11extern Addr entity_model_SuperBlock_ROM_START;
12extern Addr entity_model_UltraBlockContent_ROM_END;
13extern Addr entity_model_UltraBlockContent_ROM_START;
14extern Addr entity_model_UltraBlock_ROM_END;
15extern Addr entity_model_UltraBlock_ROM_START;
16#endif
17
19
20extern Gfx Entity_SuperBlock_Render[];
21extern Gfx Entity_UltraBlock_Render[];
26extern unsigned char D_0A000200_E4A8A0[];
27extern unsigned char D_0A000220_E4A8C0[];
28extern unsigned char D_0A000240_E4A8E0[];
29extern unsigned char D_0A000260_E4A900[];
30
32 s32 bufIdx = data->yawBufferPos - lagTime;
33
34 if (bufIdx < 0) {
35 bufIdx += ARRAY_COUNT(data->yawBuffer);
36 }
37 return data->yawBuffer[bufIdx];
38}
39
40void entity_upgrade_block_hide_content(s32 entityIndex) {
41 Entity* entity = get_entity_by_index(entityIndex);
42 BlockData* data = entity->dataBuf.block;
43
44 if (data->childEntityIndex >= 0) {
45 Entity* childEntity = get_entity_by_index(data->childEntityIndex);
46 SuperBlockContentData* childEntityData = childEntity->dataBuf.superBlockContent;
47 childEntityData->isHidden = TRUE;
48 }
49}
50
52 return entity_base_block_idle(entity);
53}
54
56 BlockData* parentData = entity->dataBuf.block;
57
58 if (parentData->gameFlagIndex != 0xFFFF && !get_global_flag(parentData->gameFlagIndex)) {
59 Entity* childEntity;
60 SuperBlockContentData* childData;
61
62 parentData->childEntityIndex = create_entity(&Entity_SuperBlockContent, (s32)entity->pos.x, (s32)entity->pos.y, (s32)entity->pos.z, 0, MAKE_ENTITY_END);
63 childEntity = get_entity_by_index(parentData->childEntityIndex);
64 childData = childEntity->dataBuf.superBlockContent;
65 childData->parentEntityIndex = entity->listIndex;
66 }
67}
68
70 BlockData* data = entity->dataBuf.block;
71
73 entity->rot.y += 180.0f;
74 data->gameFlagIndex = 0xFFFF;
75 data->childEntityIndex = -1;
76}
77
81
85
88 Entity* parentEntity = get_entity_by_index(data->parentEntityIndex);
89
90 entity->pos.x = parentEntity->pos.x;
91 entity->pos.y = parentEntity->pos.y + 14.0f;
92 entity->pos.z = parentEntity->pos.z;
93}
94
107
114
116 20, 0,
117 2, 1,
118 2, 2,
119 20, 3,
120 2, 2,
121 1, 2,
122 -1, -1,
123};
124
126 Gfx* gfxPos = gMainGfxPos;
127 Gfx* dlist;
128 u8* palette;
129 Entity* entity = get_entity_by_index(entityIndex);
131 s32 alpha;
132 Matrix4f sp18;
133
134 if (data->paletteTimer == 0) {
135 s32 temp = data->paletteArrOffset;
136 temp += 2;
137 if (Entity_SuperBlock_PalData[temp] > 0) {
139 data->paletteArrOffset = temp;
140 } else {
142 data->paletteArrOffset = 0;
143 }
144 } else {
145 data->paletteTimer--;
146 }
147
149 dlist = data->gfx2;
150
151 gDPPipeSync(gfxPos++);
152 guRotateF(sp18, entity_SuperBlockContent_get_previous_yaw(data, 1), 0.0f, 1.0f, 0.0f);
153 guMtxF2L(sp18, &data->unk_10);
155 gSPMatrix(gfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
156 gDPSetRenderMode(gfxPos++, G_RM_AA_ZB_TEX_EDGE, G_RM_AA_ZB_TEX_EDGE2);
157 gDPSetCombineMode(gfxPos++, G_CC_MODULATEIA, G_CC_MODULATEIA);
158 gDPLoadTLUT_pal16(gfxPos++, 0, palette);
159 gSPDisplayList(gfxPos++, dlist);
160 gSPPopMatrix(gfxPos++, G_MTX_MODELVIEW);
161
162 alpha = 120;
163 if (entity->alpha < alpha) {
164 alpha = entity->alpha;
165 }
166
167 gDPPipeSync(gfxPos++);
168 guRotateF(sp18, entity_SuperBlockContent_get_previous_yaw(data, 6), 0.0f, 1.0f, 0.0f);
169 guMtxF2L(sp18, &data->unk_50);
171 gSPMatrix(gfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
172 gDPSetRenderMode(gfxPos++, AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA), AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA));
173 gDPSetCombineMode(gfxPos++, PM_CC_01, PM_CC_02);
174 gDPSetPrimColor(gfxPos++, 0, 0, 0, 0, 0, alpha);
175 gSPDisplayList(gfxPos++, dlist);
176 gSPPopMatrix(gfxPos++, G_MTX_MODELVIEW);
177
178 alpha = 80;
179 if (entity->alpha < alpha) {
180 alpha = entity->alpha;
181 }
182
183 gDPPipeSync(gfxPos++);
184 guRotateF(sp18, entity_SuperBlockContent_get_previous_yaw(data, 10), 0.0f, 1.0f, 0.0f);
185 guMtxF2L(sp18, &data->unk_90);
187 gSPMatrix(gfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
188 gDPSetRenderMode(gfxPos++, AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA), AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA));
189 gDPSetCombineMode(gfxPos++, PM_CC_01, PM_CC_02);
190 gDPSetPrimColor(gfxPos++, 0, 0, 0, 0, 0, alpha);
191 gSPDisplayList(gfxPos++, dlist);
192 gSPPopMatrix(gfxPos++, G_MTX_MODELVIEW);
193
194 gMainGfxPos = gfxPos;
195}
196
199
201 if (data->isHidden) {
202 entity->renderSetupFunc = NULL;
203 }
204
205 entity->rot.y = clamp_angle(entity->rot.y + 3.0);
206 data->yawBuffer[data->yawBufferPos] = entity->rot.y;
207
208 data->yawBufferPos++;
209 if (data->yawBufferPos > ARRAY_COUNT(data->yawBuffer)) {
210 data->yawBufferPos = 0;
211 }
212
213 if (!data->isHidden && gOverrideFlags == 0) {
214 if (--data->effectTimer <= 0) {
215 data->effectTimer = 50;
216 fx_stars_shimmer(3, entity->pos.x, entity->pos.y, entity->pos.z, 22.0f, 8.0f, 4, 20);
217 }
218 }
219}
220
228
236
237extern Gfx Entity_RenderNone[];
238
247
252
255 .typeDataSize = sizeof(BlockData),
256 .renderCommandList = Entity_SuperBlock_RenderScript,
257 .modelAnimationNodes = 0,
258 .fpInit = entity_SuperBlock_init,
259 .updateEntityScript = Entity_SuperBlock_Script,
260 .fpHandleCollision = entity_block_handle_collision,
261 { .dma = ENTITY_ROM(SuperBlock) },
262 .entityType = ENTITY_TYPE_SUPER_BLOCK,
263 .aabbSize = { 25, 25, 25 }
264};
265
268 .typeDataSize = sizeof(SuperBlockContentData),
269 .renderCommandList = Entity_SuperBlockContent_RenderScript,
270 .modelAnimationNodes = 0,
272 .updateEntityScript = Entity_SuperBlockContent_Script,
273 .fpHandleCollision = NULL,
274 { .dma = ENTITY_ROM(SuperBlockContent) },
276 .aabbSize = { 18, 6, 18 }
277};
278
281 .typeDataSize = sizeof(BlockData),
282 .renderCommandList = Entity_UltraBlock_RenderScript,
283 .modelAnimationNodes = 0,
284 .fpInit = entity_UltraBlock_init,
285 .updateEntityScript = Entity_SuperBlock_Script,
286 .fpHandleCollision = entity_block_handle_collision,
287 { .dma = ENTITY_ROM(UltraBlock) },
288 .entityType = ENTITY_TYPE_ULTRA_BLOCK,
289 .aabbSize = { 25, 25, 25 }
290};
291
294 .typeDataSize = sizeof(SuperBlockContentData),
295 .renderCommandList = Entity_UltraBlockContent_RenderScript,
296 .modelAnimationNodes = 0,
298 .updateEntityScript = Entity_UltraBlockContent_Script,
299 .fpHandleCollision = NULL,
300 { .dma = ENTITY_ROM(UltraBlockContent) },
302 .aabbSize = { 18, 6, 18 }
303};
void entity_init_SuperBlockContent(Entity *entity)
Definition SuperBlock.c:221
EntityBlueprint Entity_UltraBlockContent
Definition SuperBlock.c:292
EntityScript Entity_UltraBlockContent_Script
Definition SuperBlock.c:243
void entity_upgrade_block_check_if_inactive(Entity *entity)
Definition SuperBlock.c:55
s32 entity_upgrade_block_idle(Entity *entity)
Definition SuperBlock.c:51
EntityModelScript Entity_SuperBlock_RenderScript
Definition SuperBlock.c:248
void entity_SuperBlockContent_setupGfx(s32 entityIndex)
Definition SuperBlock.c:125
unsigned char D_0A000260_E4A900[]
Gfx Entity_UltraBlock_Render[]
Definition UltraBlock.c:121
void entity_upgrade_block_init(Entity *entity)
Definition SuperBlock.c:69
EntityBlueprint Entity_UltraBlock
Definition SuperBlock.c:279
void entity_upgrade_block_hide_content(s32 entityIndex)
Definition SuperBlock.c:40
unsigned char D_0A000200_E4A8A0[]
f32 entity_SuperBlockContent_get_previous_yaw(SuperBlockContentData *data, s32 lagTime)
Definition SuperBlock.c:31
EntityModelScript Entity_UltraBlockContent_RenderScript
Definition SuperBlock.c:251
EntityModelScript Entity_UltraBlock_RenderScript
Definition SuperBlock.c:250
Gfx Entity_SuperBlockContent_Render2[]
EntityBlueprint Entity_SuperBlockContent
Definition SuperBlock.c:266
EntityScript Entity_SuperBlockContent_Script
Definition SuperBlock.c:239
void entity_SuperBlockContent_attach_to_parent(Entity *entity)
Definition SuperBlock.c:86
unsigned char * Entity_SuperBlock_Palettes[]
Definition SuperBlock.c:108
Gfx Entity_SuperBlockContent_Render[]
void entity_init_UltraBlockContent(Entity *entity)
Definition SuperBlock.c:229
EntityModelScript Entity_SuperBlockContent_RenderScript
Definition SuperBlock.c:249
void entity_SuperBlock_init(Entity *entity)
Definition SuperBlock.c:78
unsigned char D_0A000240_E4A8E0[]
Gfx Entity_UltraBlockContent_Render[]
Gfx Entity_SuperBlock_Render[]
Definition SuperBlock.c:127
unsigned char D_0A000220_E4A8C0[]
void entity_SuperBlockContent_idle(Entity *entity)
Definition SuperBlock.c:197
Gfx Entity_RenderNone[]
Definition Shadow.c:69
Gfx Entity_UltraBlockContent_Render2[]
EntityScript Entity_SuperBlock_Script
Definition SuperBlock.c:95
void entity_UltraBlock_init(Entity *entity)
Definition SuperBlock.c:82
EntityBlueprint Entity_SuperBlock
Definition SuperBlock.c:253
s8 Entity_SuperBlock_PalData[]
Definition SuperBlock.c:115
Mtx matrixStack[0x200]
struct SuperBlockContentData * superBlockContent
struct BlockData * block
f32 Matrix4f[4][4]
#define guRotateF
#define guMtxF2L
#define clamp_angle
s32 EntityModelScript[]
Definition entity.h:7
#define es_Call(func)
Definition entity.h:37
#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
#define es_Label(labelId)
Definition entity.h:41
#define es_Goto(labelId)
Definition entity.h:39
s32 EntityScript[]
Definition entity.h:6
s16 childEntityIndex
Definition entity.h:120
#define es_End
Definition entity.h:35
#define es_PlaySound(soundId)
Definition entity.h:45
u16 gameFlagIndex
Definition entity.h:116
@ ENTITY_TYPE_SUPER_BLOCK
Definition enums.h:2577
@ ENTITY_TYPE_ULTRA_BLOCK_HIT_EFFECT
Definition enums.h:2600
@ ENTITY_TYPE_ULTRA_BLOCK
Definition enums.h:2578
@ ENTITY_TYPE_SUPER_BLOCK_HIT_EFFECT
Definition enums.h:2599
@ SOUND_HIT_BLOCK
Definition enums.h:768
@ RENDER_MODE_SURFACE_XLU_LAYER2
Definition enums.h:3287
@ RENDER_MODE_ALPHATEST
Definition enums.h:3276
@ ENTITY_FLAG_FIXED_SHADOW_SIZE
Definition enums.h:2622
@ ENTITY_FLAG_4000
Definition enums.h:2627
@ ENTITY_FLAG_DISABLE_COLLISION
Definition enums.h:2618
#define MAKE_ENTITY_END
Definition evt.h:107
Entity * get_entity_by_index(s32 index)
Definition entity.c:530
void entity_block_hit_animate_scale(Entity *entity)
Definition Block.c:90
s32 entity_start_script(Entity *entity)
Definition entity.c:560
s32 entity_base_block_idle(Entity *entity)
Definition Block.c:195
void entity_base_block_init(Entity *entity)
Definition Block.c:213
f32 entity_block_hit_init_scale(Entity *entity)
Definition Block.c:75
s32 create_entity(EntityBlueprint *bp,...)
Definition entity.c:1195
s32 entity_block_handle_collision(Entity *entity)
Definition Block.c:334
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define PM_CC_01
Definition macros.h:276
#define PM_CC_02
Definition macros.h:277
void(* renderSetupFunc)(s32)
EntityData dataBuf
u8 Addr[]
Linker symbol address, as in ld_addrs.h.
Definition types.h:16
s32 gOverrideFlags
Definition main_loop.c:11
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16
s32 get_global_flag(s32 index)
Definition vars_access.c:89