From e83e08f21c2d05c8a844fce17a5da55abb96ccee Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 26 Apr 2023 12:32:43 -0400 Subject: [PATCH 1/5] Add time ranges to UpdateAmbientCry --- src/overworld.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/overworld.c b/src/overworld.c index 70b102fd2..3d46fc500 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1260,23 +1260,34 @@ static void PlayAmbientCry(void) 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) { u8 i, monsCount, divBy; 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) - *state = 4; + *state = AMB_CRY_IDLE; else - *state = 1; + *state = AMB_CRY_FIRST; 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; - *state = 3; + *state = AMB_CRY_WAIT; break; - case 2: + case AMB_CRY_RESET: divBy = 1; monsCount = CalculatePlayerPartyCount(); for (i = 0; i < monsCount; i++) @@ -1288,18 +1299,20 @@ void UpdateAmbientCry(s16 *state, u16 *delayCounter) 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; - *state = 3; + *state = AMB_CRY_WAIT; break; - case 3: - (*delayCounter)--; - if (*delayCounter == 0) + case AMB_CRY_WAIT: + if (--(*delayCounter) == 0) { PlayAmbientCry(); - *state = 2; + *state = AMB_CRY_RESET; } break; - case 4: + case AMB_CRY_IDLE: + // No land/water pokemon on this map break; } } From 36e6981ac0df338f85cb49a3c1d56f4410dbe007 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 26 Apr 2023 16:12:00 -0400 Subject: [PATCH 2/5] Replace some & usage with % --- src/event_object_movement.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 3025e0849..d4b89fbae 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2575,7 +2575,7 @@ bool8 MovementType_WanderAround_Step2(struct ObjectEvent *objectEvent, struct Sp { if (!ObjectEventExecSingleMovementAction(objectEvent, sprite)) return FALSE; - SetMovementDelay(sprite, sMovementDelaysMedium[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysMedium[Random() % ARRAY_COUNT(sMovementDelaysMedium)]); sprite->sTypeFuncId = 3; return TRUE; } @@ -2855,7 +2855,7 @@ bool8 MovementType_LookAround_Step2(struct ObjectEvent *objectEvent, struct Spri { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysMedium[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysMedium[Random() % ARRAY_COUNT(sMovementDelaysMedium)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -2907,7 +2907,7 @@ bool8 MovementType_WanderUpAndDown_Step2(struct ObjectEvent *objectEvent, struct if (!ObjectEventExecSingleMovementAction(objectEvent, sprite)) return FALSE; - SetMovementDelay(sprite, sMovementDelaysMedium[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysMedium[Random() % ARRAY_COUNT(sMovementDelaysMedium)]); sprite->sTypeFuncId = 3; return TRUE; } @@ -2975,7 +2975,7 @@ bool8 MovementType_WanderLeftAndRight_Step2(struct ObjectEvent *objectEvent, str if (!ObjectEventExecSingleMovementAction(objectEvent, sprite)) return FALSE; - SetMovementDelay(sprite, sMovementDelaysMedium[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysMedium[Random() % ARRAY_COUNT(sMovementDelaysMedium)]); sprite->sTypeFuncId = 3; return TRUE; } @@ -3195,7 +3195,7 @@ bool8 MovementType_FaceDownAndUp_Step2(struct ObjectEvent *objectEvent, struct S { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysMedium[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysMedium[Random() % ARRAY_COUNT(sMovementDelaysMedium)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3245,7 +3245,7 @@ bool8 MovementType_FaceLeftAndRight_Step2(struct ObjectEvent *objectEvent, struc { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysMedium[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysMedium[Random() % ARRAY_COUNT(sMovementDelaysMedium)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3295,7 +3295,7 @@ bool8 MovementType_FaceUpAndLeft_Step2(struct ObjectEvent *objectEvent, struct S { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysShort[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysShort[Random() % ARRAY_COUNT(sMovementDelaysShort)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3345,7 +3345,7 @@ bool8 MovementType_FaceUpAndRight_Step2(struct ObjectEvent *objectEvent, struct { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysShort[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysShort[Random() % ARRAY_COUNT(sMovementDelaysShort)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3395,7 +3395,7 @@ bool8 MovementType_FaceDownAndLeft_Step2(struct ObjectEvent *objectEvent, struct { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysShort[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysShort[Random() % ARRAY_COUNT(sMovementDelaysShort)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3445,7 +3445,7 @@ bool8 MovementType_FaceDownAndRight_Step2(struct ObjectEvent *objectEvent, struc { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysShort[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysShort[Random() % ARRAY_COUNT(sMovementDelaysShort)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3495,7 +3495,7 @@ bool8 MovementType_FaceDownUpAndLeft_Step2(struct ObjectEvent *objectEvent, stru { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysShort[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysShort[Random() % ARRAY_COUNT(sMovementDelaysShort)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3545,7 +3545,7 @@ bool8 MovementType_FaceDownUpAndRight_Step2(struct ObjectEvent *objectEvent, str { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysShort[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysShort[Random() % ARRAY_COUNT(sMovementDelaysShort)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3595,7 +3595,7 @@ bool8 MovementType_FaceUpLeftAndRight_Step2(struct ObjectEvent *objectEvent, str { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysShort[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysShort[Random() % ARRAY_COUNT(sMovementDelaysShort)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } @@ -3645,7 +3645,7 @@ bool8 MovementType_FaceDownLeftAndRight_Step2(struct ObjectEvent *objectEvent, s { if (ObjectEventExecSingleMovementAction(objectEvent, sprite)) { - SetMovementDelay(sprite, sMovementDelaysShort[Random() & 3]); + SetMovementDelay(sprite, sMovementDelaysShort[Random() % ARRAY_COUNT(sMovementDelaysShort)]); objectEvent->singleMovementActive = FALSE; sprite->sTypeFuncId = 3; } From c2dad5ac44960f6d7b762c5ebb8199b66c1090df Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 27 Apr 2023 13:59:09 -0400 Subject: [PATCH 3/5] Redefine TV_SHOWS_COUNT --- include/constants/global.h | 1 - include/constants/tv.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/global.h b/include/constants/global.h index 8e40e6378..04f1d548c 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -46,7 +46,6 @@ #define OBJECT_EVENTS_COUNT 16 #define MAIL_COUNT (10 + PARTY_SIZE) #define SECRET_BASES_COUNT 20 -#define TV_SHOWS_COUNT 25 #define POKE_NEWS_COUNT 16 #define PC_ITEMS_COUNT 50 #define BAG_ITEMS_COUNT 30 diff --git a/include/constants/tv.h b/include/constants/tv.h index 87748a31d..13ec88ecd 100644 --- a/include/constants/tv.h +++ b/include/constants/tv.h @@ -74,6 +74,7 @@ // for TV shows from TVGROUP_NORMAL. The remainder are for TV // shows from TVGROUP_RECORD_MIX. #define NUM_NORMAL_TVSHOW_SLOTS 5 +#define TV_SHOWS_COUNT (NUM_NORMAL_TVSHOW_SLOTS + 20) #define PLAYERS_HOUSE_TV_NONE 0 #define PLAYERS_HOUSE_TV_LATI 1 From 8e5347b450f4b655cc58a783de70e14b0fd115e1 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 21 Apr 2023 03:20:36 -0400 Subject: [PATCH 4/5] Fix mapjson misreporting errors when processing map_groups.json --- tools/mapjson/mapjson.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index cfe95c485..e53ac7924 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -75,6 +75,9 @@ string json_to_string(const Json &data, const string &field = "", bool silent = case Json::Type::BOOL: output = value.bool_value() ? "TRUE" : "FALSE"; break; + case Json::Type::NUL: + output = ""; + break; default:{ if (!silent) { string s = !field.empty() ? ("Value for '" + field + "'") : "JSON field"; @@ -459,23 +462,24 @@ string generate_map_constants_text(string groups_filepath, Json groups_data) { for (auto &group : groups_data["group_order"].array_items()) { string groupName = json_to_string(group); text << "// " << groupName << "\n"; - vector map_ids; + vector map_ids; size_t max_length = 0; for (auto &map_name : groups_data[groupName].array_items()) { - string header_filepath = file_dir + json_to_string(map_name) + dir_separator + "map.json"; + string map_filepath = file_dir + json_to_string(map_name) + dir_separator + "map.json"; string err_str; - Json map_data = Json::parse(read_text_file(header_filepath), err_str); - map_ids.push_back(map_data["id"]); - string id = json_to_string(map_data, "id"); + Json map_data = Json::parse(read_text_file(map_filepath), err_str); + if (map_data == Json()) + FATAL_ERROR("%s: %s\n", map_filepath.c_str(), err_str.c_str()); + string id = json_to_string(map_data, "id", true); + map_ids.push_back(id); if (id.length() > max_length) max_length = id.length(); } int map_id_num = 0; - for (Json map_id : map_ids) { - string id = json_to_string(map_id); - text << "#define " << id << string((max_length - id.length() + 1), ' ') + for (string map_id : map_ids) { + text << "#define " << map_id << string((max_length - map_id.length() + 1), ' ') << "(" << map_id_num++ << " | (" << group_num << " << 8))\n"; } text << "\n"; From 8c537ccd727946b81a204c9fe0147ec06c4b4578 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 10 May 2023 00:33:43 -0400 Subject: [PATCH 5/5] Colorize bag select button --- graphics/bag/select_button.png | Bin 135 -> 195 bytes src/item_menu.c | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/bag/select_button.png b/graphics/bag/select_button.png index bded587fd1d071464de8d5b9032433a760c183cf..52cdc1ed5acb5ca9c9164e0db127cee7509eaa83 100644 GIT binary patch delta 162 zcmZo?Jj^&j(uJ9Uf#Dz5qGdqJAiyWYH7ThW$o&8R|JAE!_s)s>&%m%{%NC#r5WG9v z{Qv*iD2D2*S^vF&OrWwUTV54^+dENFIJk*j|L0V8xf8R(r!6z#np!2Sp19#G^J^gu zH?BPgwk+Uy>cPuBJy`F+_LMg7cU!~f{P9S=W@>l+*8F=9_P;pDYIxTptX1s_E65&C LS3j3^P6dXGLHcW-t6b~08)OQE{-7_GfVpn`3@LxF#k*mlRNPsKK0`R^C`