diff options
author | ProjectRevoTPP <projectrevotpp@hotmail.com> | 2017-02-11 00:38:59 -0500 |
---|---|---|
committer | YamaArashi <YamaArashi@users.noreply.github.com> | 2017-02-10 21:38:59 -0800 |
commit | f21587ea9eb1190ac2136d72deb7929c1e1169eb (patch) | |
tree | bf39287a8b3906a6e2b47197e323047272b3d5a4 /src | |
parent | c78e787f934f03bfffcf93ac69d92271d7d8036d (diff) |
misc labels and memcpy/set cleanups (#232)
* some labels and enumerate player speeds
* clear up speed enums
* GetPlayerSpeed
* oops
* start decompiling mauville_old_man.c
* formatting
* decompile more of mauville_old_man.c
* someone fix this please
* formatting
* make ROM build again
* formatting again
* make ROM match again
* label, document, reorganize, and clean up battle_ai.c
* move stuff to battle.h and get rid of battle_2000000
* various changes
* labeling
* minor labels and formatting
* contest ai labels and misc stuff
Diffstat (limited to 'src')
-rw-r--r-- | src/battle_ai.c | 280 | ||||
-rw-r--r-- | src/berry.c | 12 | ||||
-rw-r--r-- | src/event_data.c | 15 | ||||
-rw-r--r-- | src/field_player_avatar.c | 2 | ||||
-rw-r--r-- | src/link.c | 4 | ||||
-rw-r--r-- | src/matsuda_debug_menu.c | 5 | ||||
-rw-r--r-- | src/naming_screen.c | 2 | ||||
-rw-r--r-- | src/rom3.c | 2 | ||||
-rw-r--r-- | src/rom4.c | 5 | ||||
-rw-r--r-- | src/rom_800D42C.c | 8 | ||||
-rw-r--r-- | src/rom_8094928.c | 14 | ||||
-rw-r--r-- | src/wild_encounter.c | 1 |
12 files changed, 148 insertions, 202 deletions
diff --git a/src/battle_ai.c b/src/battle_ai.c index 6058068f0..ceab60ca0 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -14,14 +14,7 @@ #define AIScriptRead8(ptr) ((ptr)[0]) #define AIScriptReadPtr(ptr) (u8*) AIScriptRead32(ptr) -// to do: maybe try to reduce the defines needed to match? -#define BATTLE_STRUCT ((struct BattleStruct *)(unk_2000000)) -#define AI_THINKING_STRUCT ((struct AI_ThinkingStruct *)(unk_2000000 + 0x16800)) -#define UNK_2016A00_STRUCT ((struct UnknownStruct1 *)(unk_2000000 + 0x16A00)) -#define AI_ARRAY_160CC ((struct SmallItemStruct *)(unk_2000000 + 0x160CC)) - extern void sub_801CAF8(u8, u8); -extern u8 sub_8109908(void); enum { @@ -66,9 +59,6 @@ extern struct Trainer gTrainers[]; extern struct BattleMove gBattleMoves[]; extern struct BaseStats gBaseStats[]; -// needed to match the hack that is get_item, thanks cam, someone else clean this up later. -extern u8 unk_2000000[]; - /* gAIScriptPtr is a pointer to the next battle AI cmd command to read. when a command finishes processing, gAIScriptPtr is incremented by @@ -78,30 +68,6 @@ AI scripts. */ extern u8 *gAIScriptPtr; -struct UnknownStruct3 -{ - u8 *ptr[8]; - u8 unk20; -}; - -struct UnknownStruct4 -{ - u8 filler0[0x3]; - u16 unk4; - u16 unk6; - u8 unk8; - u8 unk9; - u8 fillerA[0x9]; - u8 taunt:4; - u8 unkC:4; - u8 fillerD[0x2]; - u8 unk16; - u8 filler17[0x4]; -}; - -extern struct UnknownStruct3 unk_2016C00; -extern struct UnknownStruct4 gUnknown_02024CA8[]; - static void BattleAICmd_if_random_less_than(void); static void BattleAICmd_if_random_greater_than(void); static void BattleAICmd_if_random_equal(void); @@ -193,7 +159,7 @@ static void BattleAICmd_nullsub_57(void); static void BattleAICmd_call(void); static void BattleAICmd_jump(void); static void BattleAICmd_end(void); -static void BattleAICmd_if_level_cond(void); +static void BattleAICmd_if_level_compare(void); static void BattleAICmd_if_taunted(void); static void BattleAICmd_if_not_taunted(void); @@ -292,7 +258,7 @@ static const BattleAICmdFunc sBattleAICmdTable[] = BattleAICmd_call, BattleAICmd_jump, BattleAICmd_end, - BattleAICmd_if_level_cond, + BattleAICmd_if_level_compare, BattleAICmd_if_taunted, BattleAICmd_if_not_taunted, }; @@ -320,26 +286,28 @@ const u16 sDiscouragedPowerfulMoveEffects[] = void BattleAI_SetupAIData(void); void BattleAI_DoAIProcessing(void); void sub_810745C(void); -void sub_81098C4(u8 *); +void AIStackPushVar(u8 *); +u8 AIStackPop(void); // if the AI is a Link battle, safari, battle tower, or ereader, it will ignore considering item uses. void BattleAI_HandleItemUseBeforeAISetup(void) { s32 i; - u8 *data = (u8 *)&unk_2016A00; + u8 *data = (u8 *)UNK_2016A00_STRUCT; - for (i = 0; (u32)i < 48; i++) + for (i = 0; (u32)i < sizeof(struct UnknownStruct1); i++) data[i] = 0; + if ((gBattleTypeFlags & BATTLE_TYPE_TRAINER) && gTrainerBattleOpponent != 0x400 && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_SAFARI | BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_EREADER_TRAINER))) { - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_TRAINER_ITEMS; i++) { if (gTrainers[gTrainerBattleOpponent].items[i] != 0) { - unk_2016A00.items[unk_2016A00.unk8] = gTrainers[gTrainerBattleOpponent].items[i]; - unk_2016A00.unk8++; + UNK_2016A00_STRUCT->items[UNK_2016A00_STRUCT->numOfItems] = gTrainers[gTrainerBattleOpponent].items[i]; + UNK_2016A00_STRUCT->numOfItems++; } } } @@ -356,24 +324,22 @@ void BattleAI_SetupAIData(void) // clear AI data and set default move score to 100. strange that they didn't use memset here. for (i = 0; (u32)i < sizeof(struct AI_ThinkingStruct); i++) data[i] = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) AI_THINKING_STRUCT->score[i] = 100; r7 = sub_8015A98(gUnknown_02024A60, 0, 0xFF); - // probably sets up the moves to consider and ignores non-valid moves such as NO_MOVE or glitch moves. - for (i = 0; i < 4; i++) + // probably sets up the moves to consider and ignores non-valid moves such as NO_MOVE or glitch moves. + for (i = 0; i < MAX_MON_MOVES; i++) { - u16 rand; - if (gBitTable[i] & r7) AI_THINKING_STRUCT->score[i] = 0; - rand = Random(); - AI_THINKING_STRUCT->unk18[i] = 100 - (rand & 0xF); + AI_THINKING_STRUCT->simulatedRNG[i] = 100 - (Random() % 16); } - unk_2016C00.unk20 = 0; + // clear AI stack. + AI_STACK->size = 0; gPlayerMonIndex = gUnknown_02024A60; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) @@ -399,8 +365,8 @@ void BattleAI_SetupAIData(void) u8 BattleAI_GetAIActionToUse(void) { - u8 currentMoveArray[4]; - u8 consideredMoveArray[4]; + u8 currentMoveArray[MAX_MON_MOVES]; + u8 consideredMoveArray[MAX_MON_MOVES]; u8 numOfBestMoves; s32 i; @@ -418,16 +384,16 @@ u8 BattleAI_GetAIActionToUse(void) } // special flee or watch cases for safari. - if (AI_THINKING_STRUCT->aiAction & (AI_ACTION_UNK2)) // flee + if (AI_THINKING_STRUCT->aiAction & (AI_ACTION_FLEE)) // flee return 4; - if (AI_THINKING_STRUCT->aiAction & (AI_ACTION_UNK3)) // watch + if (AI_THINKING_STRUCT->aiAction & (AI_ACTION_WATCH)) // watch return 5; numOfBestMoves = 1; currentMoveArray[0] = AI_THINKING_STRUCT->score[0]; consideredMoveArray[0] = 0; - for (i = 1; i < 4; i++) + for (i = 1; i < MAX_MON_MOVES; i++) { if (currentMoveArray[0] < AI_THINKING_STRUCT->score[i]) { @@ -471,17 +437,17 @@ void BattleAI_DoAIProcessing(void) else { AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] = 0; // definitely do not consider any move that has 0 PP. - AI_THINKING_STRUCT->aiAction |= AI_ACTION_UNK1; + AI_THINKING_STRUCT->aiAction |= AI_ACTION_DONE; } - if (AI_THINKING_STRUCT->aiAction & AI_ACTION_UNK1) + if (AI_THINKING_STRUCT->aiAction & AI_ACTION_DONE) { AI_THINKING_STRUCT->movesetIndex++; - if (AI_THINKING_STRUCT->movesetIndex < 4 && !(AI_THINKING_STRUCT->aiAction & AI_ACTION_UNK4)) + if (AI_THINKING_STRUCT->movesetIndex < MAX_MON_MOVES && (AI_THINKING_STRUCT->aiAction & AI_ACTION_DO_NOT_ATTACK) == 0) AI_THINKING_STRUCT->aiState = AIState_SettingUp; // as long as their are more moves to process, keep setting this to setup state. else AI_THINKING_STRUCT->aiState++; // done processing. - AI_THINKING_STRUCT->aiAction &= (AI_ACTION_UNK2 | AI_ACTION_UNK3 | AI_ACTION_UNK4 | - AI_ACTION_UNK5 | AI_ACTION_UNK6 | AI_ACTION_UNK7 | AI_ACTION_UNK8); // disable UNK1. + AI_THINKING_STRUCT->aiAction &= (AI_ACTION_FLEE | AI_ACTION_WATCH | AI_ACTION_DO_NOT_ATTACK | + AI_ACTION_UNK5 | AI_ACTION_UNK6 | AI_ACTION_UNK7 | AI_ACTION_UNK8); // disable AI_ACTION_DONE. } break; } @@ -494,9 +460,9 @@ void sub_810745C(void) for (i = 0; i < 8; i++) { - if (unk_2016A00.unk0[gEnemyMonIndex >> 1][i] == 0) + if (UNK_2016A00_STRUCT->movesUsed[gEnemyMonIndex >> 1][i] == 0) { - unk_2016A00.unk0[gEnemyMonIndex >> 1][i] = gUnknown_02024C34[gEnemyMonIndex]; + UNK_2016A00_STRUCT->movesUsed[gEnemyMonIndex >> 1][i] = gUnknown_02024C34[gEnemyMonIndex]; return; } } @@ -507,26 +473,24 @@ void unref_sub_81074A0(u8 a) s32 i; for (i = 0; i < 8; i++) - unk_2016A00.unk0[a / 2][i] = 0; + UNK_2016A00_STRUCT->movesUsed[a / 2][i] = 0; } void sub_81074C4(u8 a, u8 b) { if (battle_side_get_owner(a) == 0) - unk_2016A00.unk20[battle_get_per_side_status(a) & 1] = b; + UNK_2016A00_STRUCT->unk20[battle_get_per_side_status(a) & 1] = b; } void sub_81074F8(u8 a, u8 b) { if (battle_side_get_owner(a) == 0) - unk_2016A00.unk22[battle_get_per_side_status(a) & 1] = b; + UNK_2016A00_STRUCT->unk22[battle_get_per_side_status(a) & 1] = b; } static void BattleAICmd_if_random_less_than(void) { - u16 random = Random(); - - if (random % 256 < gAIScriptPtr[1]) + if (Random() % 256 < gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -534,29 +498,23 @@ static void BattleAICmd_if_random_less_than(void) static void BattleAICmd_if_random_greater_than(void) { - u16 random = Random(); - - if (random % 256 > gAIScriptPtr[1]) + if (Random() % 256 > gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_if_random_equal(void) // if RNG Value equal to +static void BattleAICmd_if_random_equal(void) { - u16 random = Random(); - - if (random % 256 == gAIScriptPtr[1]) + if (Random() % 256 == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_if_random_not_equal(void) // if RNG value not equal to +static void BattleAICmd_if_random_not_equal(void) { - u16 random = Random(); - - if (random % 256 != gAIScriptPtr[1]) + if (Random() % 256 != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -564,7 +522,7 @@ static void BattleAICmd_if_random_not_equal(void) // if RNG value not equal to static void BattleAICmd_score(void) { - AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] += gAIScriptPtr[1]; // add the result to the array of the move consider's score. + AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] += gAIScriptPtr[1]; // add the result to the array of the move consider's score. if (AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] < 0) // if the score is negative, flatten it to 0. AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] = 0; @@ -938,13 +896,13 @@ static void BattleAICmd_if_user_can_damage(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].power != 0) break; } - if (i == 4) + if (i == MAX_MON_MOVES) gAIScriptPtr += 5; else gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); @@ -954,13 +912,13 @@ static void BattleAICmd_if_user_cant_damage(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].power != 0) break; } - if (i != 4) + if (i != MAX_MON_MOVES) gAIScriptPtr += 5; else gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); @@ -974,9 +932,7 @@ static void BattleAICmd_get_turn_count(void) static void BattleAICmd_get_type(void) { - u8 typeVar = gAIScriptPtr[1]; - - switch (typeVar) + switch (gAIScriptPtr[1]) { case 1: // player primary type AI_THINKING_STRUCT->funcResult = gBattleMons[gPlayerMonIndex].type1; @@ -1007,7 +963,7 @@ static void BattleAICmd_get_move_power(void) static void BattleAICmd_is_most_powerful_move(void) { int i, j; - s32 damages[4]; + s32 damages[MAX_MON_MOVES]; for (i = 0; sDiscouragedPowerfulMoveEffects[i] != 0xFFFF; i++) if (gBattleMoves[AI_THINKING_STRUCT->moveConsidered].effect == sDiscouragedPowerfulMoveEffects[i]) @@ -1017,12 +973,12 @@ static void BattleAICmd_is_most_powerful_move(void) && sDiscouragedPowerfulMoveEffects[i] == 0xFFFF) { gUnknown_02024DEC = 0; - unk_2000000[0x1601C] = 0; // why is this a manual array? - unk_2000000[0x1601F] = 1; + unk_2000000[0x1601C] = 0; // why is this a manual array? + unk_2000000[0x1601F] = 1; gBattleMoveFlags = 0; gCritMultiplier = 1; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { for (j = 0; sDiscouragedPowerfulMoveEffects[j] != 0xFFFF; j++) { // _08108276 @@ -1030,7 +986,7 @@ static void BattleAICmd_is_most_powerful_move(void) break; } - // _081082BA + // _081082BA if (gBattleMons[gPlayerMonIndex].moves[i] && sDiscouragedPowerfulMoveEffects[j] == 0xFFFF && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].power > 1) @@ -1038,7 +994,8 @@ static void BattleAICmd_is_most_powerful_move(void) gUnknown_02024BE6 = gBattleMons[gPlayerMonIndex].moves[i]; sub_801CAF8(gPlayerMonIndex, gEnemyMonIndex); move_effectiveness_something(gUnknown_02024BE6, gPlayerMonIndex, gEnemyMonIndex); - damages[i] = (gBattleMoveDamage * AI_THINKING_STRUCT->unk18[i]) / 100; + damages[i] = (gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[i]) / 100; + if (damages[i] == 0) // moves always do at least 1 damage. damages[i] = 1; } @@ -1048,11 +1005,11 @@ static void BattleAICmd_is_most_powerful_move(void) } } - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) if (damages[i] > damages[AI_THINKING_STRUCT->movesetIndex]) break; - if (i == 4) + if (i == MAX_MON_MOVES) AI_THINKING_STRUCT->funcResult = 2; else AI_THINKING_STRUCT->funcResult = 1; @@ -1362,10 +1319,10 @@ static void BattleAICmd_nullsub_2B(void) static void BattleAICmd_count_alive_pokemon(void) { - u8 index; - u8 var, var2; struct Pokemon *party; int i; + u8 index; + u8 var, var2; AI_THINKING_STRUCT->funcResult = 0; @@ -1439,7 +1396,9 @@ static void BattleAICmd_get_ability(void) } // abilities that prevent fleeing. - if (gBattleMons[index].ability == ABILITY_SHADOW_TAG || gBattleMons[index].ability == ABILITY_MAGNET_PULL || gBattleMons[index].ability == ABILITY_ARENA_TRAP) + if (gBattleMons[index].ability == ABILITY_SHADOW_TAG + || gBattleMons[index].ability == ABILITY_MAGNET_PULL + || gBattleMons[index].ability == ABILITY_ARENA_TRAP) { AI_THINKING_STRUCT->funcResult = gBattleMons[index].ability; gAIScriptPtr += 2; @@ -1450,41 +1409,32 @@ static void BattleAICmd_get_ability(void) { if (gBaseStats[gBattleMons[index].species].ability2 != ABILITY_NONE) { - // AI has no knowledge of opponent, so it guesses which ability. In Emerald, it has knowledge of the opponent's ability when it is invoked at least once. - if (Random() & 1) + // AI has no knowledge of opponent, so it guesses which ability. + if (Random() % 2) { AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability1; - gAIScriptPtr += 2; - return; } else { AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability2; - gAIScriptPtr += 2; - return; } } else { AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability1; // it's definitely ability 1. - gAIScriptPtr += 2; - return; } } else { AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability2; // AI cant actually reach this part since every mon has at least 1 ability. - gAIScriptPtr += 2; - return; } } else { // The AI knows its own ability. AI_THINKING_STRUCT->funcResult = gBattleMons[index].ability; - gAIScriptPtr += 2; - return; } + gAIScriptPtr += 2; } static void BattleAICmd_get_highest_possible_damage(void) @@ -1498,7 +1448,7 @@ static void BattleAICmd_get_highest_possible_damage(void) gCritMultiplier = 1; AI_THINKING_STRUCT->funcResult = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { gBattleMoveDamage = 40; gUnknown_02024BE6 = gBattleMons[gPlayerMonIndex].moves[i]; @@ -1574,7 +1524,7 @@ static void BattleAICmd_nullsub_33(void) static void BattleAICmd_if_status_in_party(void) { struct Pokemon *party; - struct Pokemon *partyPtr; + struct Pokemon *partyPtr; int i; u32 statusToCompareTo; @@ -1598,10 +1548,10 @@ static void BattleAICmd_if_status_in_party(void) u32 status = GetMonData(&party[i], MON_DATA_STATUS); if (species != SPECIES_NONE && species != SPECIES_EGG && hp != 0 && status == statusToCompareTo) - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); // WHAT. why is this being merged into the above switch - return; - } + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); // WHAT. why is this being merged into the above switch + return; + } } gAIScriptPtr += 10; @@ -1611,7 +1561,7 @@ static void BattleAICmd_if_status_in_party(void) static void BattleAICmd_if_status_not_in_party(void) { struct Pokemon *party; - struct Pokemon *partyPtr; + struct Pokemon *partyPtr; int i; u32 statusToCompareTo; @@ -1643,13 +1593,13 @@ static void BattleAICmd_if_status_not_in_party(void) static void BattleAICmd_get_weather(void) { if (gBattleWeather & 7) - AI_THINKING_STRUCT->funcResult = 1; + AI_THINKING_STRUCT->funcResult = WEATHER_RAIN; if (gBattleWeather & 0x18) - AI_THINKING_STRUCT->funcResult = 2; + AI_THINKING_STRUCT->funcResult = WEATHER_SANDSTORM; if (gBattleWeather & 0x60) - AI_THINKING_STRUCT->funcResult = 0; + AI_THINKING_STRUCT->funcResult = WEATHER_SUN; if (gBattleWeather & 0x80) - AI_THINKING_STRUCT->funcResult = 3; + AI_THINKING_STRUCT->funcResult = WEATHER_HAIL; gAIScriptPtr += 1; } @@ -1737,6 +1687,7 @@ static void BattleAICmd_if_can_faint(void) gAIScriptPtr += 5; return; } + gUnknown_02024DEC = 0; BATTLE_STRUCT->unk.unk1 = 0; BATTLE_STRUCT->unk.unk4 = 1; @@ -1746,7 +1697,7 @@ static void BattleAICmd_if_can_faint(void) sub_801CAF8(gPlayerMonIndex, gEnemyMonIndex); move_effectiveness_something(gUnknown_02024BE6, gPlayerMonIndex, gEnemyMonIndex); - gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->unk18[AI_THINKING_STRUCT->movesetIndex] / 100; + gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[AI_THINKING_STRUCT->movesetIndex] / 100; // moves always do at least 1 damage. if (gBattleMoveDamage == 0) @@ -1775,7 +1726,7 @@ static void BattleAICmd_if_cant_faint(void) sub_801CAF8(gPlayerMonIndex, gEnemyMonIndex); move_effectiveness_something(gUnknown_02024BE6, gPlayerMonIndex, gEnemyMonIndex); - gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->unk18[AI_THINKING_STRUCT->movesetIndex] / 100; + gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[AI_THINKING_STRUCT->movesetIndex] / 100; // this macro is missing the damage 0 = 1 assumption. @@ -1794,38 +1745,28 @@ static void BattleAICmd_if_has_move(void) { case 1: case 3: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gPlayerMonIndex].moves[i] == *temp_ptr) break; } - if (i == 4) - { + if (i == MAX_MON_MOVES) gAIScriptPtr += 8; - return; - } else - { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); - return; - } + break; case 0: case 2: for (i = 0; i < 8; i++) { - if (unk_2016A00.unk0[gEnemyMonIndex >> 1][i] == *temp_ptr) + if (UNK_2016A00_STRUCT->movesUsed[gEnemyMonIndex >> 1][i] == *temp_ptr) break; } if (i == 8) - { gAIScriptPtr += 8; - return; - } - else - { + else gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); - return; - } + break; } } @@ -1838,38 +1779,28 @@ static void BattleAICmd_if_dont_have_move(void) { case 1: case 3: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gPlayerMonIndex].moves[i] == *temp_ptr) break; } - if (i != 4) - { + if (i != MAX_MON_MOVES) gAIScriptPtr += 8; - return; - } else - { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); - return; - } + break; case 0: case 2: for (i = 0; i < 8; i++) { - if (unk_2016A00.unk0[gEnemyMonIndex >> 1][i] == *temp_ptr) + if (UNK_2016A00_STRUCT->movesUsed[gEnemyMonIndex >> 1][i] == *temp_ptr) break; } if (i != 8) - { gAIScriptPtr += 8; - return; - } else - { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); - return; - } + break; } } @@ -1881,12 +1812,12 @@ static void BattleAICmd_if_move_effect(void) { case 1: case 3: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].effect == gAIScriptPtr[2]) break; } - if (i != 4) + if (i != MAX_MON_MOVES) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -1895,7 +1826,7 @@ static void BattleAICmd_if_move_effect(void) case 2: for (i = 0; i < 8; i++) { - if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[unk_2016A00.unk0[gEnemyMonIndex >> 1][i]].effect == gAIScriptPtr[2]) + if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[UNK_2016A00_STRUCT->movesUsed[gEnemyMonIndex >> 1][i]].effect == gAIScriptPtr[2]) break; } gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); @@ -1910,12 +1841,12 @@ static void BattleAICmd_if_not_move_effect(void) { case 1: case 3: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].effect == gAIScriptPtr[2]) break; } - if (i != 4) + if (i != MAX_MON_MOVES) gAIScriptPtr += 7; else gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); @@ -1924,7 +1855,7 @@ static void BattleAICmd_if_not_move_effect(void) case 2: for (i = 0; i < 8; i++) { - if (unk_2016A00.unk0[gEnemyMonIndex >> 1][i] != 0 && gBattleMoves[unk_2016A00.unk0[gEnemyMonIndex >> 1][i]].effect == gAIScriptPtr[2]) + if (UNK_2016A00_STRUCT->movesUsed[gEnemyMonIndex >> 1][i] != 0 && gBattleMoves[UNK_2016A00_STRUCT->movesUsed[gEnemyMonIndex >> 1][i]].effect == gAIScriptPtr[2]) break; } gAIScriptPtr += 7; @@ -1991,7 +1922,7 @@ static void BattleAICmd_if_encored(void) static void BattleAICmd_flee(void) { - AI_THINKING_STRUCT->aiAction |= (AI_ACTION_UNK1 | AI_ACTION_UNK2 | AI_ACTION_UNK4); // what matters is UNK2 being enabled. + AI_THINKING_STRUCT->aiAction |= (AI_ACTION_DONE | AI_ACTION_FLEE | AI_ACTION_DO_NOT_ATTACK); // what matters is AI_ACTION_FLEE being enabled. } static void BattleAICmd_if_random_100(void) @@ -2006,7 +1937,7 @@ static void BattleAICmd_if_random_100(void) static void BattleAICmd_watch(void) { - AI_THINKING_STRUCT->aiAction |= (AI_ACTION_UNK1 | AI_ACTION_UNK3 | AI_ACTION_UNK4); // what matters is UNK3 being enabled. + AI_THINKING_STRUCT->aiAction |= (AI_ACTION_DONE | AI_ACTION_WATCH | AI_ACTION_DO_NOT_ATTACK); // what matters is AI_ACTION_WATCH being enabled. } static void BattleAICmd_get_hold_effect(void) @@ -2155,7 +2086,7 @@ static void BattleAICmd_nullsub_57(void) static void BattleAICmd_call(void) { - sub_81098C4(gAIScriptPtr + 5); + AIStackPushVar(gAIScriptPtr + 5); gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } @@ -2166,11 +2097,11 @@ static void BattleAICmd_jump(void) static void BattleAICmd_end(void) { - if (sub_8109908() == 0) - AI_THINKING_STRUCT->aiAction |= AI_ACTION_UNK1; + if (AIStackPop() == FALSE) + AI_THINKING_STRUCT->aiAction |= AI_ACTION_DONE; } -static void BattleAICmd_if_level_cond(void) +static void BattleAICmd_if_level_compare(void) { switch (gAIScriptPtr[1]) { @@ -2217,22 +2148,23 @@ static void BattleAICmd_if_not_taunted(void) gAIScriptPtr += 5; } -void sub_81098C4(u8 *var) +void AIStackPushVar(u8 *var) { - unk_2016C00.ptr[unk_2016C00.unk20++] = var; + AI_STACK->ptr[AI_STACK->size++] = var; } -void unref_sub_81098E4(void) +// unused +void AIStackPushAIPtr(void) { - unk_2016C00.ptr[unk_2016C00.unk20++] = gAIScriptPtr; + AI_STACK->ptr[AI_STACK->size++] = gAIScriptPtr; } -bool8 sub_8109908(void) +bool8 AIStackPop(void) { - if (unk_2016C00.unk20 != 0) + if (AI_STACK->size != 0) { - --unk_2016C00.unk20; - gAIScriptPtr = unk_2016C00.ptr[unk_2016C00.unk20]; + --AI_STACK->size; + gAIScriptPtr = AI_STACK->ptr[AI_STACK->size]; return TRUE; } else diff --git a/src/berry.c b/src/berry.c index 7932fafea..2f8f6a799 100644 --- a/src/berry.c +++ b/src/berry.c @@ -7,6 +7,8 @@ #include "rng.h" #include "text.h" +#define BERRY_NAME_LENGTH 6 + #define FIRST_BERRY ITEM_CHERI_BERRY #define LAST_BERRY ITEM_ENIGMA_BERRY @@ -917,7 +919,7 @@ void ClearBerryTrees(void) struct SaveBlock1 *saveBlock1 = &gSaveBlock1; struct BerryTree berryTree = gBlankBerryTree; - for (i = 0; i < 128; i++) + for (i = 0; i < (u8)ARRAY_COUNT(saveBlock1->berryTrees); i++) // casting to u8 fixes a mismatched signed compare. what saveBlock1->berryTrees[i] = berryTree; } @@ -955,7 +957,7 @@ void BerryTreeTimeUpdate(int time) int i; struct BerryTree *tree; - for (i = 0; i < 128; i++) + for (i = 0; i < (u8)ARRAY_COUNT(gSaveBlock1.berryTrees); i++) { tree = &gSaveBlock1.berryTrees[i]; @@ -1044,8 +1046,8 @@ u16 BerryTypeToItemId(u16 berry) void GetBerryNameByBerryType(u8 berry, u8 *string) { - memcpy(string, GetBerryInfo(berry)->name, 6); - string[6] = EOS; + memcpy(string, GetBerryInfo(berry)->name, BERRY_NAME_LENGTH); + string[BERRY_NAME_LENGTH] = EOS; } void ResetBerryTreeSparkleFlag(u8 id) @@ -1185,7 +1187,7 @@ void ResetBerryTreeSparkleFlags(void) top = cam_top + 3; right = cam_left + 14; bottom = top + 8; - for (i = 0; i < 16; i++) + for (i = 0; i < (u8)ARRAY_COUNT(gSaveBlock1.mapObjects); i++) { if (gMapObjects[i].active && gMapObjects[i].animPattern == 12) { diff --git a/src/event_data.c b/src/event_data.c index b1c0632ec..c6aecf13c 100644 --- a/src/event_data.c +++ b/src/event_data.c @@ -2,29 +2,34 @@ #include "event_data.h" #include "pokedex.h" -extern u8 gUnknown_0202E8E2[]; +#define TEMP_FLAGS_SIZE 0x4 +#define TEMP_UPPER_FLAGS_SIZE 0x8 +#define TEMP_VARS_SIZE 0x20 + +extern u8 gUnknown_0202E8E2[16]; extern u16 *gSpecialVars[]; void InitEventData(void) { memset(gSaveBlock1.flags, 0, sizeof(gSaveBlock1.flags)); memset(gSaveBlock1.vars, 0, sizeof(gSaveBlock1.vars)); - memset(gUnknown_0202E8E2, 0, 16); + memset(gUnknown_0202E8E2, 0, sizeof(gUnknown_0202E8E2)); } void ClearTempFieldEventData(void) { - memset(gSaveBlock1.flags, 0, 4); - memset(gSaveBlock1.vars, 0, 32); + memset(gSaveBlock1.flags, 0, TEMP_FLAGS_SIZE); + memset(gSaveBlock1.vars, 0, TEMP_VARS_SIZE); FlagReset(SYS_ENC_UP_ITEM); FlagReset(SYS_ENC_DOWN_ITEM); FlagReset(SYS_USE_STRENGTH); FlagReset(SYS_CTRL_OBJ_DELETE); } +// probably had different flag splits at one point. void ClearUpperFlags(void) { - memset(gSaveBlock1.flags + 0x118, 0, 8); + memset(gSaveBlock1.flags + 0x118, 0, TEMP_UPPER_FLAGS_SIZE); } void DisableNationalPokedex(void) diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index 51a2d8089..d52a68271 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -1126,7 +1126,7 @@ bool8 IsPlayerFacingSurfableFishableWater(void) void ClearPlayerAvatarInfo(void) { //TODO: 0x24 should be the size of gPlayerAvatar - memset(&gPlayerAvatar, 0, 0x24); + memset(&gPlayerAvatar, 0, sizeof(struct PlayerAvatar)); } void SetPlayerAvatarStateMask(u8 a) diff --git a/src/link.c b/src/link.c index dc6559fa2..3a3e9eebf 100644 --- a/src/link.c +++ b/src/link.c @@ -475,8 +475,8 @@ static void ProcessRecvCmds(u8 unusedParam) case 0x2222: InitLocalLinkPlayer(); localLinkPlayerBlock.linkPlayer = localLinkPlayer; - memcpy(localLinkPlayerBlock.magic1, sMagic, 15); - memcpy(localLinkPlayerBlock.magic2, sMagic, 15); + memcpy(localLinkPlayerBlock.magic1, sMagic, sizeof(localLinkPlayerBlock.magic1) - 1); + memcpy(localLinkPlayerBlock.magic2, sMagic, sizeof(localLinkPlayerBlock.magic2) - 1); InitBlockSend(&localLinkPlayerBlock, sizeof(localLinkPlayerBlock)); break; case 0x5555: diff --git a/src/matsuda_debug_menu.c b/src/matsuda_debug_menu.c index 316ece197..66e865ed6 100644 --- a/src/matsuda_debug_menu.c +++ b/src/matsuda_debug_menu.c @@ -1017,15 +1017,18 @@ void sub_80AAF30(void) gUnknown_0203856C = 1; gContestPlayerMonIndex = 3; sub_80AE098(0); + for (i = 3; i > -1; i--) gUnknown_02038690[i] = 3 - i; + for (i = 0; i < 3; i++) { gUnknown_02038670[i] = 0; gUnknown_02038680[i] = 0; gUnknown_02038678[i] = 0; - memcpy(&gContestMons[i], &gContestMons[3], 0x40); + memcpy(&gContestMons[i], &gContestMons[3], sizeof(struct ContestPokemon)); } + gUnknown_02038670[3] = 0x12C; gUnknown_02038680[3] = 0x190; gUnknown_02038678[3] = 0x190; diff --git a/src/naming_screen.c b/src/naming_screen.c index 568fdf092..aa8066eb5 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -398,7 +398,7 @@ static void NamingScreen_Init(void) namingScreenData.currentPage = namingScreenData.template->unk4; namingScreenData.unk2 = 14 - namingScreenData.template->maxChars / 2; namingScreenData.unk3C = gKeyRepeatStartDelay; - memset(namingScreenData.textBuffer, 0xFF, 0x10); + memset(namingScreenData.textBuffer, 0xFF, sizeof(namingScreenData.textBuffer)); if (namingScreenData.template->unk0 != 0) StringCopy(namingScreenData.textBuffer, namingScreenData.destBuffer); gKeyRepeatStartDelay = 16; diff --git a/src/rom3.c b/src/rom3.c index 84032c933..2d00b647f 100644 --- a/src/rom3.c +++ b/src/rom3.c @@ -748,7 +748,7 @@ void dp01_build_cmdbuf_x0F_aa_b_cc_dddd_e_mlc_weather_00_x1Cbytes(u8 a, u16 b, u } gUnknown_03004040[14] = 0; gUnknown_03004040[15] = 0; - memcpy(gUnknown_03004040 + 16, g, 0x1C); + memcpy(&gUnknown_03004040[16], g, 0x1C); dp01_prepare_buffer(a, gUnknown_03004040, 0x2C); } diff --git a/src/rom4.c b/src/rom4.c index 05396cfc3..37c6b84ad 100644 --- a/src/rom4.c +++ b/src/rom4.c @@ -55,7 +55,7 @@ extern struct WarpData gUnknown_02029808; extern struct UnkPlayerStruct gUnknown_02029810; extern u16 gUnknown_02029814; extern bool8 gUnknown_02029816; -extern struct LinkPlayerMapObject gLinkPlayerMapObjects[]; +extern struct LinkPlayerMapObject gLinkPlayerMapObjects[4]; extern u8 gUnknown_03000580[]; extern u16 (*gUnknown_03000584)(u32); @@ -104,7 +104,6 @@ extern const struct WarpData gDummyWarpData; extern s32 gUnknown_0839ACE8; extern u32 gUnknown_08216694[]; - void DoWhiteOut(void) { ScriptContext2_RunNewScript(EventScript_LeagueWhiteOut); @@ -2304,7 +2303,7 @@ void ZeroLinkPlayerMapObject(struct LinkPlayerMapObject *linkPlayerMapObj) void strange_npc_table_clear(void) { - memset(gLinkPlayerMapObjects, 0, 16); + memset(gLinkPlayerMapObjects, 0, sizeof(gLinkPlayerMapObjects)); } void ZeroMapObject(struct MapObject *mapObj) diff --git a/src/rom_800D42C.c b/src/rom_800D42C.c index f41aa560a..7b572ba73 100644 --- a/src/rom_800D42C.c +++ b/src/rom_800D42C.c @@ -43,7 +43,7 @@ void sub_800DC24(void) { // lp_field_18 = player position? - switch (gLinkPlayers[battle_2000000.linkPlayerIndex].lp_field_18) + switch (gLinkPlayers[BATTLE_STRUCT->linkPlayerIndex].lp_field_18) { case 0: case 2: PRINT_MESSAGE_LEFT(BattleText_Win, 160); @@ -59,7 +59,7 @@ void sub_800DC24(void) else { - switch (gLinkPlayers[battle_2000000.linkPlayerIndex].lp_field_18) + switch (gLinkPlayers[BATTLE_STRUCT->linkPlayerIndex].lp_field_18) { case 1: case 3: PRINT_MESSAGE_LEFT(BattleText_Win, 160); @@ -79,7 +79,7 @@ void sub_800DC24(void) if (gUnknown_02024D26 == 1) { - if (gLinkPlayers[battle_2000000.linkPlayerIndex].lp_field_18 != 0) + if (gLinkPlayers[BATTLE_STRUCT->linkPlayerIndex].lp_field_18 != 0) { PRINT_MESSAGE_RIGHT(BattleText_Win, 160); PRINT_MESSAGE_LEFT(BattleText_Loss, 168); @@ -92,7 +92,7 @@ void sub_800DC24(void) } else { - if (gLinkPlayers[battle_2000000.linkPlayerIndex].lp_field_18 != 0) + if (gLinkPlayers[BATTLE_STRUCT->linkPlayerIndex].lp_field_18 != 0) { PRINT_MESSAGE_LEFT(BattleText_Win, 160); PRINT_MESSAGE_RIGHT(BattleText_Loss, 168); diff --git a/src/rom_8094928.c b/src/rom_8094928.c index 95847eda4..74daec64d 100644 --- a/src/rom_8094928.c +++ b/src/rom_8094928.c @@ -1,6 +1,10 @@ #include "global.h" #include "pokemon.h" +#define UNK_201606C_ARRAY (unk_2000000 + 0x1606C) // lazy define but whatever. + +extern u8 unk_2000000[]; + extern struct PokemonStorage gPokemonStorage; extern u8 IsLinkDoubleBattle(void); extern u8 IsDoubleBattle(void); @@ -13,14 +17,14 @@ extern u8 gUnknown_02038470[3]; extern u8 sub_803FBBC(void); extern u16 gUnknown_02024A6A[]; -void unref_sub_8094928(void *ptr) +void unref_sub_8094928(struct PokemonStorage *ptr) { - memcpy(ptr, &gPokemonStorage, 0x83d0); + *ptr = gPokemonStorage; } -void unref_sub_8094940(void *ptr) +void unref_sub_8094940(struct PokemonStorage *ptr) { - memcpy(&gPokemonStorage, ptr, 0x83d0); + gPokemonStorage = *ptr; } void sub_8094958(void) @@ -30,7 +34,7 @@ void sub_8094958(void) void sub_8094978(u8 arg1, u8 arg2) { - sub_8094A74((((u8(*)[3]) 0x0201606c))[arg1], arg2, arg1); + sub_8094A74((UNK_201606C_ARRAY) + arg1 * 3, arg2, arg1); } void sub_8094998(u8 arg[3], u8 player_number) diff --git a/src/wild_encounter.c b/src/wild_encounter.c index f848873bb..408dc69ce 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -2999,6 +2999,7 @@ static bool8 CheckFeebas(void) if (Random() % 100 > 49) //50% chance of encountering Feebas return FALSE; + FeebasSeedRng(gSaveBlock1.easyChatPairs[0].unk2); for (i = 0; i != NUM_FEEBAS_SPOTS;) { |