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

Renaming variables and functions related to overworld poison damage and FieldOverworldState #307

Merged
merged 7 commits into from
Nov 23, 2024

Conversation

Viperio19
Copy link
Contributor

First commit: Renaming sub_02054B04 to Pokemon_DoPoisonDamage and renamng all the variables in that function and related functions.
Second and third commit: Renaming various functions and variables in field_overworld_state.c and related files.
Fourth commit: Renaming variables in unk_02054884.c.

There's one function name in field_overworld_state.c and some in unk_02054884.c which I wasn't sure what to name, so I left those as they are. Also, let me know if this PR was too all over the place, I just started from somewhere and then one renamed variable lead me to other variables to be renamed.

Copy link
Collaborator

@ravepossum ravepossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few thoughts on names, and a variety of small style stuff we're working on cleaning up. For the style matters, I only commented on the first occurrence of each that I noticed. Thanks for another contribution :)

void FieldTask_ChangeMapByLocation(FieldTask *param0, const Location *param1);
void FieldTask_ChangeMapToLocation(FieldTask *param0, int param1, int param2, int param3, int param4, int param5);
void FieldTask_StartMapChangeFull(FieldTask *param0, int param1, int param2, int param3, int param4, int param5);
void FieldSystem_StartChangeMapTask(FieldTask *taskMan, const Location *param1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: we're kind of all over the place with this in the repo at the moment - I'm seeing task, taskMan, and taskManager. Maybe something we should look into, but doesn't need to be solved with this PR or anything.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's being normalized to task for FieldTask, because there's no "management" aspect to it. There is a light call-stack, but that doesn't totally qualify it as a "manager" to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I change all of them to task then? I can just immediately do it in other files as well, if this is something that you want to normalize across the whole repo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ones in this PR would be nice, but I wouldn't sweat the whole repo unless you're just enthusiastic to do so. I'd probably do that as a follow-up PR if you did though.

@@ -18,10 +18,10 @@ void FieldOverworldState_Init(FieldOverworldState *param0);
Location *FieldOverworldState_GetPlayerLocation(FieldOverworldState *param0);
Location *FieldOverworldState_GetEntranceLocation(FieldOverworldState *param0);
Location *FieldOverworldState_GetPrevLocation(FieldOverworldState *param0);
Location *sub_0203A72C(FieldOverworldState *param0);
Location *FieldOverworldState_GetExitLocation(FieldOverworldState *param0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: The declarations' parameter names should match the definitions' ones. (same with the one in unk_02054884.h)

@@ -905,14 +905,14 @@ static BOOL Field_UpdatePoison(FieldSystem *fieldSystem)
return FALSE;
}

switch (sub_02054B04(party, MapHeader_GetMapLabelTextID(fieldSystem->location->mapId))) {
switch (Pokemon_DoPoisonDamage(party, MapHeader_GetMapLabelTextID(fieldSystem->location->mapId))) {
case 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: It would be good to add descriptive constants for these cases (and the corresponding return values in Pokemon_DoPoisonDamage().

u32 v1;
int v2, v3;
FieldOverworldState *v4;
u32 mapId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: We're working on cleaning up C89-style declarations to be more concise and declared when needed, as long as it matches. For example:

-    u32 mapId;
...
-    mapId = fieldSystem->location->mapId;
+    u32 mapId = fieldSystem->location->mapId;

I think these should match.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately that doesn't seem to match

@@ -426,10 +426,10 @@ static BOOL FieldMap_ChangeZone(FieldSystem *fieldSystem)
}

{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: We're also working on cleaning up unnecessary scope blocks like these.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's still a couple pesky extra scope blocks in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be taken care of now

if (Pokemon_CanBattle(v4)) {
if (Pokemon_GetValue(v4, MON_DATA_STATUS_CONDITION, NULL) & (MON_CONDITION_TOXIC | MON_CONDITION_POISON)) {
u32 v5 = Pokemon_GetValue(v4, MON_DATA_CURRENT_HP, NULL);
if (Pokemon_CanBattle(mon)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think you can collapse these two if statements into one with a conjunction and it'll still match.

@@ -119,23 +119,23 @@ void sub_020553DC()
return;
}

void sub_020553F0(FieldSystem *fieldSystem, u16 param1)
void Sound_SetSpecialBGM(FieldSystem *fieldSystem, u16 param1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think param1 here is a SDAT ID. For all the invocations of this function that pass a constant, you should be able to find a matching constant in the SDAT consts file. I would recommend just ctrl+Fing for the number in the generated file build/consts/sdat.h.

{
u16 *v0 = sub_0203A748(SaveData_GetFieldOverworldState(fieldSystem->saveData));
u16 *v0 = FieldOverworldState_GetSpecialBGM(SaveData_GetFieldOverworldState(fieldSystem->saveData));

*v0 = param1;
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: This return can be removed.

BOOL result;
TrainerInfo *trainerInfo = SaveData_GetTrainerInfo(param1);
Party *party = Party_GetFromSavedata(param1);
Pokemon *mon = Pokemon_New(32);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: The 32 here is a heap ID - HEAP_ID_FIELD_TASK.

@@ -31,55 +31,55 @@ BOOL Pokemon_CanBattle(Pokemon *mon)

BOOL sub_020548B0(int param0, SaveData *param1, u16 param2, u8 param3, u16 param4, int param5, int param6)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I wonder if this and the function below are documented enough to name at this point. Looks like this particular one is only invoked in the script command ScrCmd_096, which DSPRE has named GivePokemon. The one below still has a bit more mystique in how it's invoked, so maybe just this one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree that we should aim to name scripting commands as we finish documenting functions which they invoke.

@Viperio19
Copy link
Contributor Author

Viperio19 commented Nov 19, 2024

A few thoughts on names, and a variety of small style stuff we're working on cleaning up. For the style matters, I only commented on the first occurrence of each that I noticed. Thanks for another contribution :)

Thanks for all the feedback, I've processed most it in the new commit (and also got carried away again with some new additions, whoops), let me know if there's anything else (or new) to improve.

@ravepossum ravepossum merged commit 73de609 into pret:main Nov 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants