Add time ranges to UpdateAmbientCry

This commit is contained in:
GriffinR 2023-04-26 12:32:43 -04:00
parent 8d67bebd51
commit e83e08f21c

View File

@ -1260,23 +1260,34 @@ static void PlayAmbientCry(void)
PlayCry_NormalNoDucking(sAmbientCrySpecies, pan, volume, CRY_PRIORITY_AMBIENT); PlayCry_NormalNoDucking(sAmbientCrySpecies, pan, volume, CRY_PRIORITY_AMBIENT);
} }
// States for UpdateAmbientCry
enum {
AMB_CRY_INIT,
AMB_CRY_FIRST,
AMB_CRY_RESET,
AMB_CRY_WAIT,
AMB_CRY_IDLE,
};
void UpdateAmbientCry(s16 *state, u16 *delayCounter) void UpdateAmbientCry(s16 *state, u16 *delayCounter)
{ {
u8 i, monsCount, divBy; u8 i, monsCount, divBy;
switch (*state) switch (*state)
{ {
case 0: case AMB_CRY_INIT:
// This state will be revisited whenever ResetFieldTasksArgs is called (which happens on map transition)
if (sAmbientCrySpecies == SPECIES_NONE) if (sAmbientCrySpecies == SPECIES_NONE)
*state = 4; *state = AMB_CRY_IDLE;
else else
*state = 1; *state = AMB_CRY_FIRST;
break; break;
case 1: case AMB_CRY_FIRST:
// It takes between 1200-3599 frames (~20-60 seconds) to play the first ambient cry after entering a map
*delayCounter = (Random() % 2400) + 1200; *delayCounter = (Random() % 2400) + 1200;
*state = 3; *state = AMB_CRY_WAIT;
break; break;
case 2: case AMB_CRY_RESET:
divBy = 1; divBy = 1;
monsCount = CalculatePlayerPartyCount(); monsCount = CalculatePlayerPartyCount();
for (i = 0; i < monsCount; i++) for (i = 0; i < monsCount; i++)
@ -1288,18 +1299,20 @@ void UpdateAmbientCry(s16 *state, u16 *delayCounter)
break; break;
} }
} }
// Ambient cries after the first one take between 1200-2399 frames (~20-40 seconds)
// If the player has a pokemon with the ability Swarm in their party, the time is halved to 600-1199 frames (~10-20 seconds)
*delayCounter = ((Random() % 1200) + 1200) / divBy; *delayCounter = ((Random() % 1200) + 1200) / divBy;
*state = 3; *state = AMB_CRY_WAIT;
break; break;
case 3: case AMB_CRY_WAIT:
(*delayCounter)--; if (--(*delayCounter) == 0)
if (*delayCounter == 0)
{ {
PlayAmbientCry(); PlayAmbientCry();
*state = 2; *state = AMB_CRY_RESET;
} }
break; break;
case 4: case AMB_CRY_IDLE:
// No land/water pokemon on this map
break; break;
} }
} }