Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pret merge Friday #2998

Merged
merged 9 commits into from
May 14, 2023
Binary file modified graphics/bag/select_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion include/constants/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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
Expand Down
1 change: 1 addition & 0 deletions include/constants/tv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions src/event_object_movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,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;
}
Expand Down Expand Up @@ -2856,7 +2856,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;
}
Expand Down Expand Up @@ -2908,7 +2908,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;
}
Expand Down Expand Up @@ -2976,7 +2976,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;
}
Expand Down Expand Up @@ -3196,7 +3196,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;
}
Expand Down Expand Up @@ -3246,7 +3246,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;
}
Expand Down Expand Up @@ -3296,7 +3296,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;
}
Expand Down Expand Up @@ -3346,7 +3346,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;
}
Expand Down Expand Up @@ -3396,7 +3396,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;
}
Expand Down Expand Up @@ -3446,7 +3446,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;
}
Expand Down Expand Up @@ -3496,7 +3496,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;
}
Expand Down Expand Up @@ -3546,7 +3546,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;
}
Expand Down Expand Up @@ -3596,7 +3596,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;
}
Expand Down Expand Up @@ -3646,7 +3646,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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/item_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static const struct ListMenuTemplate sItemListMenu =
.itemPrintFunc = BagMenu_ItemPrintCallback,
.totalItems = 0,
.maxShowed = 0,
.windowId = 0,
.windowId = WIN_ITEM_LIST,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
Expand Down
37 changes: 25 additions & 12 deletions src/overworld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,23 +1284,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++)
Expand All @@ -1312,18 +1323,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;
}
}
Expand Down
20 changes: 12 additions & 8 deletions tools/mapjson/mapjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -461,26 +464,27 @@ 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<Json> map_ids;
vector<string> map_ids;
size_t max_length = 0;

int map_count = 0; //DEBUG

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();
map_count++; //DEBUG
}

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";
Expand Down