Fix mega indicator sprite overwriting ram

This commit is contained in:
DizzyEggg 2020-06-24 12:55:08 +02:00
parent d5ffdbf896
commit f19ba68cb9
4 changed files with 30 additions and 21 deletions

View file

@ -425,7 +425,6 @@ struct MegaEvolutionData
u8 battlerId; u8 battlerId;
bool8 playerSelect; bool8 playerSelect;
u8 triggerSpriteId; u8 triggerSpriteId;
u8 indicatorSpriteIds[MAX_BATTLERS_COUNT];
}; };
struct Illusion struct Illusion

View file

@ -66,6 +66,7 @@ enum
HEALTHBOX_SAFARI_BALLS_TEXT HEALTHBOX_SAFARI_BALLS_TEXT
}; };
u8 GetMegaIndicatorSpriteId(u32 healthboxSpriteId);
u8 CreateBattlerHealthboxSprites(u8 battler); u8 CreateBattlerHealthboxSprites(u8 battler);
u8 CreateSafariPlayerHealthboxSprites(void); u8 CreateSafariPlayerHealthboxSprites(void);
void SetBattleBarStruct(u8 battler, u8 healthboxSpriteId, s32 maxVal, s32 currVal, s32 receivedValue); void SetBattleBarStruct(u8 battler, u8 healthboxSpriteId, s32 maxVal, s32 currVal, s32 receivedValue);
@ -83,7 +84,7 @@ bool32 IsMegaTriggerSpriteActive(void);
void HideMegaTriggerSprite(void); void HideMegaTriggerSprite(void);
void DestroyMegaTriggerSprite(void); void DestroyMegaTriggerSprite(void);
u32 CreateMegaIndicatorSprite(u32 battlerId, u32 which); u32 CreateMegaIndicatorSprite(u32 battlerId, u32 which);
void DestroyMegaIndicatorSprite(u8 battlerId); void DestroyMegaIndicatorSprite(u32 healthboxSpriteId);
u8 CreatePartyStatusSummarySprites(u8 battler, struct HpAndStatus *partyInfo, u8 arg2, bool8 isBattleStart); u8 CreatePartyStatusSummarySprites(u8 battler, struct HpAndStatus *partyInfo, u8 arg2, bool8 isBattleStart);
void Task_HidePartyStatusSummary(u8 taskId); void Task_HidePartyStatusSummary(u8 taskId);
void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elementId); void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elementId);

View file

@ -710,11 +710,20 @@ static const struct SpriteTemplate sSpriteTemplate_MegaIndicator =
// data fields for healthboxRight // data fields for healthboxRight
#define hOther_HealthBoxSpriteId data[5] #define hOther_HealthBoxSpriteId data[5]
#define hOther_IndicatorSpriteId data[6] // For Mega Evo
// data fields for healthbar // data fields for healthbar
#define hBar_HealthBoxSpriteId data[5] #define hBar_HealthBoxSpriteId data[5]
#define hBar_Data6 data[6] #define hBar_Data6 data[6]
u8 GetMegaIndicatorSpriteId(u32 healthboxSpriteId)
{
u8 spriteId = gSprites[healthboxSpriteId].oam.affineParam;
if (spriteId >= MAX_SPRITES)
return 0xFF;
return gSprites[spriteId].hOther_IndicatorSpriteId;
}
u8 CreateBattlerHealthboxSprites(u8 battlerId) u8 CreateBattlerHealthboxSprites(u8 battlerId)
{ {
s16 data6 = 0; s16 data6 = 0;
@ -791,6 +800,7 @@ u8 CreateBattlerHealthboxSprites(u8 battlerId)
gSprites[healthboxLeftSpriteId].invisible = TRUE; gSprites[healthboxLeftSpriteId].invisible = TRUE;
gSprites[healthboxRightSpriteId].invisible = TRUE; gSprites[healthboxRightSpriteId].invisible = TRUE;
gSprites[healthboxRightSpriteId].hOther_IndicatorSpriteId = 0xFF;
healthBarSpritePtr->hBar_HealthBoxSpriteId = healthboxLeftSpriteId; healthBarSpritePtr->hBar_HealthBoxSpriteId = healthboxLeftSpriteId;
healthBarSpritePtr->hBar_Data6 = data6; healthBarSpritePtr->hBar_Data6 = data6;
@ -860,7 +870,7 @@ static void SpriteCB_HealthBar(struct Sprite *sprite)
static void SpriteCB_HealthBoxOther(struct Sprite *sprite) static void SpriteCB_HealthBoxOther(struct Sprite *sprite)
{ {
u8 healthboxMainSpriteId = sprite->hOther_HealthBoxSpriteId; u8 healthboxMainSpriteId = sprite->hOther_HealthBoxSpriteId;
u8 megaSpriteId = gBattleStruct->mega.indicatorSpriteIds[gSprites[healthboxMainSpriteId].hMain_Battler]; u8 megaSpriteId = sprite->hOther_IndicatorSpriteId;
sprite->pos1.x = gSprites[healthboxMainSpriteId].pos1.x + 64; sprite->pos1.x = gSprites[healthboxMainSpriteId].pos1.x + 64;
sprite->pos1.y = gSprites[healthboxMainSpriteId].pos1.y; sprite->pos1.y = gSprites[healthboxMainSpriteId].pos1.y;
@ -886,7 +896,7 @@ void SetBattleBarStruct(u8 battlerId, u8 healthboxSpriteId, s32 maxVal, s32 oldV
void SetHealthboxSpriteInvisible(u8 healthboxSpriteId) void SetHealthboxSpriteInvisible(u8 healthboxSpriteId)
{ {
DestroyMegaIndicatorSprite(gSprites[healthboxSpriteId].hMain_Battler); DestroyMegaIndicatorSprite(healthboxSpriteId);
gSprites[healthboxSpriteId].invisible = TRUE; gSprites[healthboxSpriteId].invisible = TRUE;
gSprites[gSprites[healthboxSpriteId].hMain_HealthBarSpriteId].invisible = TRUE; gSprites[gSprites[healthboxSpriteId].hMain_HealthBarSpriteId].invisible = TRUE;
gSprites[gSprites[healthboxSpriteId].oam.affineParam].invisible = TRUE; gSprites[gSprites[healthboxSpriteId].oam.affineParam].invisible = TRUE;
@ -901,8 +911,9 @@ void SetHealthboxSpriteVisible(u8 healthboxSpriteId)
gSprites[gSprites[healthboxSpriteId].oam.affineParam].invisible = FALSE; gSprites[gSprites[healthboxSpriteId].oam.affineParam].invisible = FALSE;
if (gBattleStruct->mega.evolvedPartyIds[GetBattlerSide(battlerId)] & gBitTable[gBattlerPartyIndexes[battlerId]]) if (gBattleStruct->mega.evolvedPartyIds[GetBattlerSide(battlerId)] & gBitTable[gBattlerPartyIndexes[battlerId]])
{ {
if (gBattleStruct->mega.indicatorSpriteIds[battlerId] != 0xFF) u8 spriteId = GetMegaIndicatorSpriteId(healthboxSpriteId);
gSprites[gBattleStruct->mega.indicatorSpriteIds[battlerId]].invisible = FALSE; if (spriteId != 0xFF)
gSprites[spriteId].invisible = FALSE;
else else
CreateMegaIndicatorSprite(battlerId, 0); CreateMegaIndicatorSprite(battlerId, 0);
} }
@ -916,7 +927,7 @@ static void UpdateSpritePos(u8 spriteId, s16 x, s16 y)
void DestoryHealthboxSprite(u8 healthboxSpriteId) void DestoryHealthboxSprite(u8 healthboxSpriteId)
{ {
DestroyMegaIndicatorSprite(gSprites[healthboxSpriteId].hMain_Battler); DestroyMegaIndicatorSprite(healthboxSpriteId);
DestroySprite(&gSprites[gSprites[healthboxSpriteId].oam.affineParam]); DestroySprite(&gSprites[gSprites[healthboxSpriteId].oam.affineParam]);
DestroySprite(&gSprites[gSprites[healthboxSpriteId].hMain_HealthBarSpriteId]); DestroySprite(&gSprites[gSprites[healthboxSpriteId].hMain_HealthBarSpriteId]);
DestroySprite(&gSprites[healthboxSpriteId]); DestroySprite(&gSprites[healthboxSpriteId]);
@ -936,12 +947,13 @@ void UpdateOamPriorityInAllHealthboxes(u8 priority)
u8 healthboxLeftSpriteId = gHealthboxSpriteIds[i]; u8 healthboxLeftSpriteId = gHealthboxSpriteIds[i];
u8 healthboxRightSpriteId = gSprites[gHealthboxSpriteIds[i]].oam.affineParam; u8 healthboxRightSpriteId = gSprites[gHealthboxSpriteIds[i]].oam.affineParam;
u8 healthbarSpriteId = gSprites[gHealthboxSpriteIds[i]].hMain_HealthBarSpriteId; u8 healthbarSpriteId = gSprites[gHealthboxSpriteIds[i]].hMain_HealthBarSpriteId;
u8 indicatorSpriteId = GetMegaIndicatorSpriteId(healthboxLeftSpriteId);
gSprites[healthboxLeftSpriteId].oam.priority = priority; gSprites[healthboxLeftSpriteId].oam.priority = priority;
gSprites[healthboxRightSpriteId].oam.priority = priority; gSprites[healthboxRightSpriteId].oam.priority = priority;
gSprites[healthbarSpriteId].oam.priority = priority; gSprites[healthbarSpriteId].oam.priority = priority;
if (gBattleStruct->mega.indicatorSpriteIds[i] != 0xFF) if (indicatorSpriteId != 0xFF)
gSprites[gBattleStruct->mega.indicatorSpriteIds[i]].oam.priority = priority; gSprites[indicatorSpriteId].oam.priority = priority;
} }
} }
@ -1491,26 +1503,26 @@ u32 CreateMegaIndicatorSprite(u32 battlerId, u32 which)
y += sIndicatorPosSingles[position][1]; y += sIndicatorPosSingles[position][1];
} }
spriteId = CreateSpriteAtEnd(&sSpriteTemplate_MegaIndicator, x, y, 0); spriteId = CreateSpriteAtEnd(&sSpriteTemplate_MegaIndicator, x, y, 0);
gBattleStruct->mega.indicatorSpriteIds[battlerId] = spriteId; gSprites[gSprites[gHealthboxSpriteIds[battlerId]].oam.affineParam].hOther_IndicatorSpriteId = spriteId;
gSprites[spriteId].tBattler = battlerId; gSprites[spriteId].tBattler = battlerId;
return spriteId; return spriteId;
} }
void DestroyMegaIndicatorSprite(u8 battlerId) void DestroyMegaIndicatorSprite(u32 healthboxSpriteId)
{ {
u32 i; u32 i;
s16 *spriteId = &gSprites[gSprites[healthboxSpriteId].oam.affineParam].hOther_IndicatorSpriteId;
if (gBattleStruct->mega.indicatorSpriteIds[battlerId] != 0xFF) if (*spriteId != 0xFF)
{ {
if (gBattleStruct->mega.indicatorSpriteIds[battlerId] != 0) // If called before initialized to 0xFF. DestroySprite(&gSprites[*spriteId]);
DestroySprite(&gSprites[gBattleStruct->mega.indicatorSpriteIds[battlerId]]); *spriteId = 0xFF;
gBattleStruct->mega.indicatorSpriteIds[battlerId] = 0xFF;
} }
for (i = 0; i < MAX_BATTLERS_COUNT; i++) for (i = 0; i < MAX_BATTLERS_COUNT; i++)
{ {
if (gBattleStruct->mega.indicatorSpriteIds[i] != 0xFF) if (gSprites[gSprites[gHealthboxSpriteIds[i]].oam.affineParam].hOther_IndicatorSpriteId != 0xFF)
break; break;
} }
// Free Sprite pal/tiles only if no indicator sprite is active for all battlers. // Free Sprite pal/tiles only if no indicator sprite is active for all battlers.
@ -1523,8 +1535,7 @@ void DestroyMegaIndicatorSprite(u8 battlerId)
static void SpriteCb_MegaIndicator(struct Sprite *sprite) static void SpriteCb_MegaIndicator(struct Sprite *sprite)
{ {
if (gBattleStruct->mega.indicatorSpriteIds[sprite->tBattler] == 0xFF)
DestroySprite(sprite);
} }
#undef tBattler #undef tBattler

View file

@ -2811,7 +2811,7 @@ static void SpriteCB_BounceEffect(struct Sprite *sprite)
gSprites[bouncerSpriteId].pos2.y = y; gSprites[bouncerSpriteId].pos2.y = y;
sprite->sSinIndex = (sprite->sSinIndex + sprite->sDelta) & 0xFF; sprite->sSinIndex = (sprite->sSinIndex + sprite->sDelta) & 0xFF;
bouncerSpriteId = gBattleStruct->mega.indicatorSpriteIds[sprite->sBattler]; bouncerSpriteId = GetMegaIndicatorSpriteId(sprite->sBouncerSpriteId);
if (sprite->sWhich == BOUNCE_HEALTHBOX && bouncerSpriteId != 0xFF) if (sprite->sWhich == BOUNCE_HEALTHBOX && bouncerSpriteId != 0xFF)
gSprites[bouncerSpriteId].pos2.y = y; gSprites[bouncerSpriteId].pos2.y = y;
} }
@ -2964,8 +2964,6 @@ static void BattleStartClearSetData(void)
gBattleStruct->arenaLostOpponentMons = 0; gBattleStruct->arenaLostOpponentMons = 0;
gBattleStruct->mega.triggerSpriteId = 0xFF; gBattleStruct->mega.triggerSpriteId = 0xFF;
for (i = 0; i < MAX_BATTLERS_COUNT; i++)
gBattleStruct->mega.indicatorSpriteIds[i] = 0xFF;
} }
void SwitchInClearSetData(void) void SwitchInClearSetData(void)