Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
ItemBlock.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects.h"
3#include "vars_access.h"
4#include "ld_addrs.h"
5#include "animation_script.h"
6#include "entity.h"
7#include "model.h"
8
9#if VERSION_JP // TODO remove once segments are split
10extern Addr entity_model_HitFloatingYellowBlock_anim_ROM_END;
11extern Addr entity_model_HitFloatingYellowBlock_anim_ROM_START;
12extern Addr entity_model_HitFloatingYellowBlock_gfx_ROM_END;
13extern Addr entity_model_HitFloatingYellowBlock_gfx_ROM_START;
14extern Addr entity_model_HitRedBlock_anim_ROM_END;
15extern Addr entity_model_HitRedBlock_anim_ROM_START;
16extern Addr entity_model_HitRedBlock_gfx_ROM_END;
17extern Addr entity_model_HitRedBlock_gfx_ROM_START;
18extern Addr entity_model_HitYellowBlock_anim_ROM_END;
19extern Addr entity_model_HitYellowBlock_anim_ROM_START;
20extern Addr entity_model_HitYellowBlock_gfx_ROM_END;
21extern Addr entity_model_HitYellowBlock_gfx_ROM_START;
22extern Addr entity_model_RedBlock_ROM_END;
23extern Addr entity_model_RedBlock_ROM_START;
24extern Addr entity_model_YellowBlock_ROM_END;
25extern Addr entity_model_YellowBlock_ROM_START;
26#endif
27
28extern Gfx Entity_YellowBlock_Render[];
29extern Gfx Entity_RedBlock_Render[];
37
38extern s32 D_802EA310[];
39
43
45
50
53}
54
56 s32 alpha = entity->alpha;
57
59 alpha += 32;
60 if (alpha > 192) {
61 alpha = 192;
62 }
63 entity->alpha = alpha;
64 } else {
65 alpha -= 32;
66 if (alpha <= 0) {
67 alpha = 0;
68 }
69 entity->alpha = alpha;
70 }
71}
72
74 if (entity->alpha < 255) {
75 entity->alpha += (entity->alpha == 0 ? 31 : 32);
76 }
77}
78
80 BlockData* data = entity->dataBuf.block;
81 s32 angle;
82
83 if (data->item == ITEM_NONE || (entity->flags & ENTITY_FLAG_USED)) {
84 return;
85 }
86
88 entity->flags |= ENTITY_FLAG_USED;
89
90 if (data->item == ITEM_COIN) {
91 make_item_entity(ITEM_COIN, entity->pos.x, entity->pos.y + 28.0, entity->pos.z,
93 } else {
94 angle += 360;
95 make_item_entity(data->item, entity->pos.x, entity->pos.y + 20.0, entity->pos.z,
97 0, angle, data->gameFlagIndex);
98 }
99
100}
101
105
107 TriggerBlockVanishEffect = fx_cold_breath(0, entity->pos.x, entity->pos.y, entity->pos.z, 1.0f, 0x3C);
108}
109
119
121 Entity* inertEntity;
122 Shadow* inertShadow;
123 BlockData* data = entity->dataBuf.block;
124
125 inertEntity = get_entity_by_index(data->childEntityIndex);
126 inertEntity->flags &= ~ENTITY_FLAG_HIDDEN;
127 inertShadow = get_shadow_by_index(inertEntity->shadowIndex);
128 inertShadow->flags &= ~ENTITY_FLAG_HIDDEN;
129}
130
132 BlockData* data = entity->dataBuf.block;
133
134 if ((data->gameFlagIndex != 0xFFFF) && get_global_flag(data->gameFlagIndex)) {
135 EntityBlueprint* bp;
136
139 } else {
141 }
142 create_entity(bp, (s32)entity->pos.x, (s32)entity->pos.y, (s32)entity->pos.z, (s32)entity->rot.y, MAKE_ENTITY_END);
144 } else {
146 }
147}
148
149// when an item block is hit, it spawns two subsidiary entities: a dummy item block which performs a 'hit' animation
150// followed by an inert version of the block.
152 s32 entityType = get_entity_type(entity->listIndex);
154 s32 childEntityIndex;
155 s32 isBlockOnGround;
156 s32 parentEntityType;
157 BlockData* childData;
158 Entity* childEntity;
159 Shadow* shadow;
160
161 if (entityType < ENTITY_TYPE_HAMMER1_BLOCK) {
163 if (entityType >= ENTITY_TYPE_HIDDEN_RED_BLOCK) {
165 }
166 }
167
168 // this child entity is the inert block
169 childEntityIndex = create_entity(bp, (s32)entity->pos.x, (s32)entity->pos.y, (s32)entity->pos.z, (s32)entity->rot.y, MAKE_ENTITY_END);
170 childEntity = get_entity_by_index(childEntityIndex);
171 childEntity->flags |= ENTITY_FLAG_HIDDEN;
172
175 }
176
179 }
180
181 shadow = get_shadow_by_index(childEntity->shadowIndex);
183 isBlockOnGround = is_block_on_ground(entity);
184
185 parentEntityType = get_entity_type(entity->listIndex);
186 if (parentEntityType == ENTITY_TYPE_HIDDEN_RED_BLOCK || parentEntityType == ENTITY_TYPE_RED_BLOCK) {
187 bp = &Entity_HitRedBlock;
188 } else if (isBlockOnGround != 0) {
190 } else {
192 }
193
194 // child entity is now the animated block which appears before it turns inert
195 childEntity = get_entity_by_index(create_entity(bp, (s32)entity->pos.x, (s32)entity->pos.y, (s32)entity->pos.z, (s32)entity->rot.y, MAKE_ENTITY_END));
196 childEntity->alpha = entity->alpha;
197 if ((entity->flags & ENTITY_FLAG_HIDDEN) || (entity->alpha < 255)) {
198 childEntity->alpha = 32;
199 }
200
203 }
204
205 childData = childEntity->dataBuf.block;
206 childData->childEntityIndex = childEntityIndex;
207
210 }
211
212 entity->flags &= ~ENTITY_FLAG_HAS_SHADOW;
213 shadow = get_shadow_by_index(entity->shadowIndex);
215 shadow = get_shadow_by_index(childEntity->shadowIndex);
217}
218
220 entity->flags |= ENTITY_FLAG_HIDDEN;
221 entity->flags &= ~ENTITY_FLAG_HAS_SHADOW;
223}
224
226 if (entity->boundScriptBytecode != NULL) {
228 return TRUE;
229 }
230 return FALSE;
231}
232
240
244
245void entity_ItemBlock_setupGfx(s32 entityIndex) {
246 Gfx* gfx = gMainGfxPos;
247 Entity* entity = get_entity_by_index(entityIndex);
248
249 gDPSetTextureLUT(gfx++, G_TT_NONE);
250 gSPTexture(gfx++, -1, -1, 0, G_TX_RENDERTILE, G_ON);
251
252 if (entity->alpha >= 255) {
253 gDPSetRenderMode(gfx++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
254 gDPSetCombineMode(gfx++, G_CC_MODULATEIA, G_CC_MODULATEIA);
255 } else {
256 gDPSetCombineMode(gfx++, PM_CC_01, PM_CC_02);
257 gDPSetPrimColor(gfx++, 0, 0, 0, 0, 0, entity->alpha);
258 }
259
260 gMainGfxPos = gfx;
261}
262
264 BlockData* data;
265
267 data = entity->dataBuf.block;
269 data->gameFlagIndex = 0xFFFF;
271}
272
274 entity_ItemBlock_init(entity);
275 entity->alpha = 0;
276}
277
279 ModelAnimator* animator;
280
283 animator = get_animator_by_index(entity->virtualModelIndex);
284 animator->renderMode = 0x11;
285 animator->flags |= 0x10000;
286}
287
293
348
349DmaEntry Entity_HitYellowBlock_dma[] = { ENTITY_ROM(HitYellowBlock_gfx), ENTITY_ROM(HitYellowBlock_anim) };
350DmaEntry Entity_HitFloatinYellowBlock_dma[] = { ENTITY_ROM(HitFloatingYellowBlock_gfx), ENTITY_ROM(HitFloatingYellowBlock_anim) };
351DmaEntry Entity_HitRedBlock_dma[] = { ENTITY_ROM(HitRedBlock_gfx), ENTITY_ROM(HitRedBlock_anim) };
352
357
360 .typeDataSize = sizeof(BlockData),
361 .renderCommandList = Entity_YellowBlock_RenderScript,
362 .modelAnimationNodes = 0,
363 .fpInit = entity_ItemBlock_init,
364 .updateEntityScript = Entity_ItemBlock_Script,
365 .fpHandleCollision = entity_block_handle_collision,
366 { .dma = ENTITY_ROM(YellowBlock) },
367 .entityType = ENTITY_TYPE_YELLOW_BLOCK,
368 .aabbSize = { 25, 25, 25 }
369};
370
373 .typeDataSize = sizeof(BlockData),
374 .renderCommandList = Entity_HiddenYellowBlock_RenderScript,
375 .modelAnimationNodes = 0,
377 .updateEntityScript = Entity_HiddenItemBlock_Script,
378 .fpHandleCollision = entity_block_handle_collision,
379 { .dma = ENTITY_ROM(YellowBlock) },
381 .aabbSize = { 25, 25, 25 }
382};
383
386 .typeDataSize = sizeof(BlockData),
387 .renderCommandList = Entity_RedBlock_RenderScript,
388 .modelAnimationNodes = 0,
389 .fpInit = entity_ItemBlock_init,
390 .updateEntityScript = Entity_ItemBlock_Script,
391 .fpHandleCollision = entity_block_handle_collision,
392 { .dma = ENTITY_ROM(RedBlock) },
393 .entityType = ENTITY_TYPE_RED_BLOCK,
394 .aabbSize = { 25, 25, 25 }
395};
396
399 .typeDataSize = sizeof(BlockData),
400 .renderCommandList = Entity_HiddenRedBlock_RenderScript,
401 .modelAnimationNodes = 0,
403 .updateEntityScript = Entity_HiddenItemBlock_Script,
404 .fpHandleCollision = entity_block_handle_collision,
405 { .dma = ENTITY_ROM(RedBlock) },
406 .entityType = ENTITY_TYPE_HIDDEN_RED_BLOCK,
407 .aabbSize = { 25, 25, 25 }
408};
409
412 .typeDataSize = sizeof(BlockData),
413 .renderCommandList = Entity_HitYellowBlock_AnimationIdle,
414 .modelAnimationNodes = Entity_HitYellowBlock_Mesh,
416 .updateEntityScript = Entity_TriggerBlock_Script,
417 .fpHandleCollision = entity_block_handle_collision,
418 { .dmaList = Entity_HitYellowBlock_dma },
420 .aabbSize = { 25, 25, 25 }
421};
422
425 .typeDataSize = sizeof(BlockData),
426 .renderCommandList = Entity_HitYellowBlock_AnimationIdle,
427 .modelAnimationNodes = Entity_HitYellowBlock_Mesh,
429 .updateEntityScript = Entity_HitBlock_Script,
430 .fpHandleCollision = NULL,
431 { .dmaList = Entity_HitYellowBlock_dma },
432 .entityType = ENTITY_TYPE_YELLOW_BLOCK,
433 .aabbSize = { 25, 25, 25 }
434};
435
438 .typeDataSize = sizeof(BlockData),
440 .modelAnimationNodes = Entity_HitFloatingYellowBlock_Mesh,
442 .updateEntityScript = Entity_HitBlock_Script,
443 .fpHandleCollision = NULL,
445 .entityType = ENTITY_TYPE_YELLOW_BLOCK,
446 .aabbSize = { 25, 25, 25 }
447};
448
451 .typeDataSize = sizeof(BlockData),
452 .renderCommandList = Entity_HitRedBlock_AnimationHit,
453 .modelAnimationNodes = Entity_HitRedBlock_Mesh,
455 .updateEntityScript = Entity_HitBlock_Script,
456 .fpHandleCollision = NULL,
457 { .dmaList = Entity_HitRedBlock_dma },
458 .entityType = ENTITY_TYPE_RED_BLOCK,
459 .aabbSize = { 25, 25, 25 }
460};
void entity_HitItemBlock_play_anim(Entity *entity)
Definition ItemBlock.c:110
void entity_ItemBlock_init(Entity *entity)
Definition ItemBlock.c:263
f32 player_get_camera_facing_angle(void)
Definition 7BB60.c:1191
s32 D_802EA310[]
Definition ItemBlock.c:288
AnimScript Entity_HitYellowBlock_AnimationIdle
void entity_TriggerBlock_disable_player_input(void)
Definition ItemBlock.c:233
void entity_HiddenItemBlock_init(Entity *entity)
Definition ItemBlock.c:273
DmaEntry Entity_HitRedBlock_dma[]
Definition ItemBlock.c:351
EntityScript Entity_TriggerBlock_Script
Definition ItemBlock.c:331
DmaEntry Entity_HitYellowBlock_dma[]
Definition ItemBlock.c:349
void entity_ItemBlock_spawn_item(Entity *entity)
Definition ItemBlock.c:79
EntityBlueprint Entity_HitRedBlock
Definition ItemBlock.c:449
EntityModelScript Entity_HiddenYellowBlock_RenderScript
Definition ItemBlock.c:354
StaticAnimatorNode * Entity_HitYellowBlock_Mesh[]
AnimScript Entity_HitFloatingYellowBlock_AnimationIdle
EntityBlueprint Entity_HiddenRedBlock
Definition ItemBlock.c:397
EntityModelScript Entity_YellowBlock_RenderScript
Definition ItemBlock.c:353
StaticAnimatorNode * Entity_HitRedBlock_Mesh[]
EntityBlueprint Entity_TriggerBlock
Definition ItemBlock.c:410
EntityBlueprint Entity_HiddenYellowBlock
Definition ItemBlock.c:371
Gfx Entity_YellowBlock_Render[]
Definition YellowBlock.c:44
DmaEntry Entity_HitFloatinYellowBlock_dma[]
Definition ItemBlock.c:350
AnimScript Entity_HitRedBlock_AnimationHit
void entity_inactive_block_hit_init(Entity *)
Definition Block.c:222
EntityScript Entity_HiddenItemBlock_Script
Definition ItemBlock.c:307
BSS EffectInstance * TriggerBlockVanishEffect
Definition ItemBlock.c:44
EntityBlueprint Entity_HitGroundedYellowBlock
Definition ItemBlock.c:423
EntityBlueprint Entity_YellowBlock
Definition ItemBlock.c:358
Gfx Entity_RedBlock_Render[]
Definition RedBlock.c:44
EntityScript Entity_HitBlock_Script
Definition ItemBlock.c:320
void entity_HitItemBlock_hide(Entity *entity)
Definition ItemBlock.c:219
EntityScript Entity_ItemBlock_Script
Definition ItemBlock.c:294
void entity_ItemBlock_replace_with_inactive(Entity *entity)
Definition ItemBlock.c:151
void entity_ItemBlock_idle(Entity *entity)
Definition ItemBlock.c:51
void entity_HitItemBlock_appear(Entity *entity)
Definition ItemBlock.c:73
s32 entity_TriggerBlock_start_bound_script(Entity *entity)
Definition ItemBlock.c:225
void entity_ItemlessBlock_init(Entity *entity)
Definition ItemBlock.c:278
void entity_HiddenItemBlock_idle(Entity *entity)
Definition ItemBlock.c:55
void entity_ItemBlock_check_if_inactive(Entity *entity)
Definition ItemBlock.c:131
EntityModelScript Entity_HiddenRedBlock_RenderScript
Definition ItemBlock.c:356
EntityBlueprint Entity_HitFloatingYellowBlock
Definition ItemBlock.c:436
AnimScript Entity_HitYellowBlock_AnimationHit
void entity_inactive_block_recoil_anim(Entity *)
Definition Block.c:242
void entity_inactive_block_hit_anim(Entity *)
Definition Block.c:228
EntityBlueprint Entity_RedBlock
Definition ItemBlock.c:384
void entity_TriggerBlock_play_vanish_effect(Entity *entity)
Definition ItemBlock.c:106
EntityModelScript Entity_RedBlock_RenderScript
Definition ItemBlock.c:355
StaticAnimatorNode * Entity_HitFloatingYellowBlock_Mesh[]
void entity_HitItemBlock_show_inactive(Entity *entity)
Definition ItemBlock.c:120
void entity_TriggerBlock_enable_player_input(void)
Definition ItemBlock.c:241
void entity_ItemBlock_setupGfx(s32 entityIndex)
Definition ItemBlock.c:245
void entity_TriggerBlock_start_bound_script_2(Entity *entity)
Definition ItemBlock.c:102
s16 AnimScript[]
struct BlockData * block
s32 CreateEntityVarArgBuffer[]
Definition entity.c:35
s32 EntityModelScript[]
Definition entity.h:7
#define es_Call(func)
Definition entity.h:37
EntityBlueprint Entity_InertRedBlock
Definition Block.c:591
#define STANDARD_ENTITY_MODEL_SCRIPT(gfx, renderMode)
Definition entity.h:56
#define es_SetCallback(func, time)
Definition entity.h:38
#define es_SetFlags(flags)
Definition entity.h:43
#define ENTITY_ROM(name)
Definition entity.h:65
EntityBlueprint Entity_InertYellowBlock
Definition Block.c:578
s32 EntityScript[]
Definition entity.h:6
s16 childEntityIndex
Definition entity.h:120
#define es_End
Definition entity.h:35
s16 item
Definition entity.h:119
#define es_PlaySound(soundId)
Definition entity.h:45
u16 gameFlagIndex
Definition entity.h:116
@ ITEM_SPAWN_MODE_ITEM_BLOCK_ITEM
Definition enums.h:2301
@ ITEM_SPAWN_MODE_ITEM_BLOCK_COIN
Definition enums.h:2312
@ ITEM_SPAWN_MODE_ITEM_BLOCK_BADGE
Definition enums.h:2302
@ PS_FLAG_SCRIPTED_FALL
Definition enums.h:3071
@ ITEM_TYPE_FLAG_BADGE
Definition enums.h:1839
@ ENTITY_TYPE_HAMMER1_BLOCK
Definition enums.h:2564
@ ENTITY_TYPE_SINGLE_TRIGGER_BLOCK
Definition enums.h:2559
@ ENTITY_TYPE_HIDDEN_RED_BLOCK
Definition enums.h:2561
@ ENTITY_TYPE_HIDDEN_YELLOW_BLOCK
Definition enums.h:2560
@ ENTITY_TYPE_RED_BLOCK
Definition enums.h:2563
@ ENTITY_TYPE_YELLOW_BLOCK
Definition enums.h:2558
@ PA_FLAG_USING_WATT
Definition enums.h:3090
@ SOUND_HIT_BLOCK
Definition enums.h:768
@ RENDER_MODE_SURFACE_XLU_LAYER2
Definition enums.h:3287
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3264
@ ENTITY_FLAG_8000
Definition enums.h:2628
@ ENTITY_FLAG_HAS_ANIMATED_MODEL
Definition enums.h:2616
@ ENTITY_FLAG_SHADOW_POS_DIRTY
Definition enums.h:2635
@ ENTITY_FLAG_DRAW_IF_CLOSE_HIDE_MODE2
Definition enums.h:2631
@ ENTITY_FLAG_HAS_DYNAMIC_SHADOW
Definition enums.h:2615
@ ENTITY_FLAG_FIXED_SHADOW_SIZE
Definition enums.h:2622
@ ENTITY_FLAG_HIDDEN
Definition enums.h:2613
@ ENTITY_FLAG_BOUND_SCRIPT_DIRTY
Definition enums.h:2637
@ ENTITY_FLAG_4000
Definition enums.h:2627
@ ENTITY_FLAG_USED
Definition enums.h:2633
@ ENTITY_FLAG_PENDING_INSTANCE_DELETE
Definition enums.h:2642
@ ENTITY_FLAG_DISABLE_COLLISION
Definition enums.h:2618
@ ENTITY_FLAG_FADING_AWAY
Definition enums.h:2641
@ ENTITY_FLAG_PENDING_FULL_DELETE
Definition enums.h:2639
@ ACTION_STATE_FALLING
Definition enums.h:2435
#define MAKE_ENTITY_END
Definition evt.h:107
Entity * get_entity_by_index(s32 index)
Definition entity.c:530
void play_model_animation(s32, s16 *)
Definition animator.c:1101
s32 disable_player_input(void)
Definition 77480.c:990
Shadow * get_shadow_by_index(s32 index)
Definition entity.c:534
s32 entity_start_script(Entity *entity)
Definition entity.c:560
s32 enable_player_input(void)
Definition 77480.c:998
void gravity_use_fall_parms(void)
Definition 7BB60.c:302
u32 get_entity_type(s32 arg0)
Definition entity.c:568
s32 make_item_entity(s32 itemID, f32 x, f32 y, f32 z, s32 itemSpawnMode, s32 pickupDelay, s32 angle, s32 pickupVar)
void set_action_state(s32 actionState)
Definition 7E9D0.c:209
s32 entity_base_block_idle(Entity *entity)
Definition Block.c:195
void set_entity_commandlist(Entity *entity, s32 *entityScript)
Definition entity.c:235
void exec_entity_commandlist(Entity *entity)
Definition entity.c:313
void entity_base_block_init(Entity *entity)
Definition Block.c:213
s32 create_entity(EntityBlueprint *bp,...)
Definition entity.c:1195
s32 entity_block_handle_collision(Entity *entity)
Definition Block.c:334
s32 is_block_on_ground(Entity *block)
Definition entity.c:1736
ModelAnimator * get_animator_by_index(s32 animModelID)
Definition animator.c:1041
#define BSS
Definition macros.h:7
#define PM_CC_01
Definition macros.h:276
#define PM_CC_02
Definition macros.h:277
s16 virtualModelIndex
void(* renderSetupFunc)(s32)
EntityData dataBuf
EvtScript * boundScriptBytecode
s16 shadowIndex
u8 Addr[]
Linker symbol address, as in ld_addrs.h.
Definition types.h:16
ItemData gItemTable[]
Gfx * gMainGfxPos
Definition cam_main.c:15
PlayerStatus gPlayerStatus
Definition 77480.c:39
s32 get_global_flag(s32 index)
Definition vars_access.c:89