From 60b47551eb41b717e9ce54f8a2e10740a2f09ef2 Mon Sep 17 00:00:00 2001 From: EmeraldLockdown <86802223+EmeraldLoc@users.noreply.github.com> Date: Sun, 10 May 2026 14:41:35 -0500 Subject: [PATCH] Redo fire piranha --- src/game/behaviors/fire_piranha_plant.inc.c | 34 +++++++++++---------- src/game/behaviors/mips.inc.c | 9 +++--- src/game/obj_behaviors_2.c | 4 ++- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/game/behaviors/fire_piranha_plant.inc.c b/src/game/behaviors/fire_piranha_plant.inc.c index 16063e0dd..be8bce92e 100644 --- a/src/game/behaviors/fire_piranha_plant.inc.c +++ b/src/game/behaviors/fire_piranha_plant.inc.c @@ -22,13 +22,24 @@ struct ObjectHitbox sPiranhaPlantFireHitbox = { .hurtboxHeight = 20, }; -s32 sNumActiveFirePiranhaPlants; -s32 sNumKilledFirePiranhaPlants; - inline static u8 is_giant_fire_piranha_plant() { return (o->oBehParams & 0x00FF0000) != 0; } +static u8 active_fire_piranha_plant_count() { + u8 activeCount = 0; + struct Object *obj = obj_get_first_with_behavior_id(id_bhvFirePiranhaPlant); + + while (obj != NULL) { + if (obj->oFirePiranhaPlantActive) { + activeCount++; + } + + obj = obj_get_next_with_same_behavior_id(obj); + } + return activeCount; +} + void bhv_fire_piranha_plant_init(void) { o->oFirePiranhaPlantNeutralScale = (is_giant_fire_piranha_plant() ? 2.f : 0.5f); obj_set_hitbox(o, &sFirePiranhaPlantHitbox); @@ -43,12 +54,9 @@ void bhv_fire_piranha_plant_init(void) { o->oNumLootCoins = 2; } } - sNumActiveFirePiranhaPlants = sNumKilledFirePiranhaPlants = 0; // use standard distance based syncing sync_object_init(o, 4000.0f); - sync_object_init_field(o, sNumActiveFirePiranhaPlants); - sync_object_init_field(o, sNumKilledFirePiranhaPlants); } static void fire_piranha_plant_act_hide(void) { @@ -68,12 +76,11 @@ static void fire_piranha_plant_act_hide(void) { } else if (approach_f32_ptr(&o->oFirePiranhaPlantScale, 0.0f, 0.04f * o->oFirePiranhaPlantNeutralScale)) { cur_obj_become_intangible(); if (o->oFirePiranhaPlantActive) { - sNumActiveFirePiranhaPlants -= 1; o->oFirePiranhaPlantActive = FALSE; if (is_giant_fire_piranha_plant() && o->oHealth == 0) { - if (++sNumKilledFirePiranhaPlants == 5) { - f32* starPos = gLevelValues.starPositions.BigPiranhasStarPos; + if (count_objects_with_behavior(o->behavior) <= 1) { + f32 *starPos = gLevelValues.starPositions.BigPiranhasStarPos; spawn_default_star(starPos[0], starPos[1], starPos[2]); network_send_object(o); } @@ -81,11 +88,10 @@ static void fire_piranha_plant_act_hide(void) { obj_die_if_health_non_positive(); set_object_respawn_info_bits(o, 1); } - } else if (sNumActiveFirePiranhaPlants < 2 && o->oTimer > 100 && distanceToPlayer > 100.0f && distanceToPlayer < 800.0f) { + } else if (active_fire_piranha_plant_count() < 2 && o->oTimer > 100 && distanceToPlayer > 100.0f && distanceToPlayer < 800.0f) { cur_obj_play_sound_2(SOUND_OBJ_PIRANHA_PLANT_APPEAR); o->oFirePiranhaPlantActive = TRUE; - sNumActiveFirePiranhaPlants += 1; cur_obj_unhide(); o->oAction = FIRE_PIRANHA_PLANT_ACT_GROW; @@ -138,11 +144,7 @@ void bhv_fire_piranha_plant_update(void) { } if (obj_check_attacks(&sFirePiranhaPlantHitbox, o->oAction)) { - if (--o->oHealth < 0) { - if (o->oFirePiranhaPlantActive) { - sNumActiveFirePiranhaPlants -= 1; - } - } else { + if (--o->oHealth >= 0) { cur_obj_init_animation_with_sound(2); } diff --git a/src/game/behaviors/mips.inc.c b/src/game/behaviors/mips.inc.c index 3040de4ce..4121bbae2 100644 --- a/src/game/behaviors/mips.inc.c +++ b/src/game/behaviors/mips.inc.c @@ -68,7 +68,7 @@ void bhv_mips_init(void) { cur_obj_init_animation(0); // distance-based standard sync system - struct SyncObject* so = sync_object_init(o, 4000.0f); + struct SyncObject *so = sync_object_init(o, 4000.0f); if (so) { sync_object_init_field(o, o->oMipsStartWaypointIndex); sync_object_init_field(o, o->oForwardVel); @@ -256,8 +256,6 @@ static u8 bhv_mips_held_continue_dialog(void) { * Handles MIPS being held by Mario. */ void bhv_mips_held(void) { - s32 dialogID; - if (o->heldByPlayerIndex >= MAX_PLAYERS) { return; } struct Object *player = gMarioStates[o->heldByPlayerIndex].marioObj; @@ -269,19 +267,20 @@ void bhv_mips_held(void) { // If MIPS hasn't spawned his star yet... if (o->oMipsStarStatus == MIPS_STAR_STATUS_HAVENT_SPAWNED_STAR) { // Choose dialog based on which MIPS encounter this is. + s32 dialogID; if (o->oBehParams2ndByte == 0) { dialogID = gBehaviorValues.dialogs.Mips1Dialog; } else { dialogID = gBehaviorValues.dialogs.Mips2Dialog; } - if (should_start_or_continue_dialog(&gMarioStates[o->heldByPlayerIndex], o) && set_mario_npc_dialog(&gMarioStates[0], 1, bhv_mips_held_continue_dialog) == 2) { + if (should_start_or_continue_dialog(&gMarioStates[o->heldByPlayerIndex], o) && set_mario_npc_dialog(&gMarioStates[o->heldByPlayerIndex], 1, bhv_mips_held_continue_dialog) == 2) { //o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; if (cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogID)) { o->oInteractionSubtype |= INT_SUBTYPE_DROP_IMMEDIATELY; o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP; o->oMipsStarStatus = MIPS_STAR_STATUS_SHOULD_SPAWN_STAR; - set_mario_npc_dialog(&gMarioStates[0], 0, NULL); + set_mario_npc_dialog(&gMarioStates[o->heldByPlayerIndex], 0, NULL); } } } diff --git a/src/game/obj_behaviors_2.c b/src/game/obj_behaviors_2.c index 721edfb35..50f389432 100644 --- a/src/game/obj_behaviors_2.c +++ b/src/game/obj_behaviors_2.c @@ -47,8 +47,10 @@ #include "hardcoded.h" #include "engine/surface_load.h" #include "pc/network/network.h" -#include "pc/lua/utils/smlua_model_utils.h" +#include "pc/lua/smlua.h" #include "pc/lua/smlua_hooks.h" +#include "pc/lua/utils/smlua_model_utils.h" +#include "pc/lua/utils/smlua_obj_utils.h" #define POS_OP_SAVE_POSITION 0 #define POS_OP_COMPUTE_VELOCITY 1