From f88eeb607409528dadbf841f2cb8e805d6e86deb Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Tue, 10 Jan 2017 23:17:43 -0500 Subject: more labels and finish decompiling battle_ai.c except for unk_24 (#184) * labels for save_menu_util.c * formatting, i suck at it * fix sub_80712B4 to not use MyTask struct * pls don't kill me * current changes * decompile BattleAICmd_if_damage_bonus * formatting * label thinking struct unk8 * decompile BattleAICMd_if_status_not_in_party * decompile more battle_ai.c functions * Began decompilation of a random file * decompile BattleAICmd_if_can_faint and BattleAICmd_if_cant_faint * decompile unk_3F and unk_40 * decompile if_move_effect and if_not_move_effect * formatting, silly * decompile if_last_move_did_damage and if_encored * decompile unk_45 if_random_2 and unk_47 * decompile get_hold_effect and get_gender * decompile is_first_turn and get_stockpile_count * decompile unk_4C and get_item * decompile unk_4E unk_4F and unk_50 * decompile get_protect_count and the remaining stub macros * decompile call jump and unk_5A * decompile if_level_cond * decompile the last AI macros besides unk_24 * finish decompiling battle_ai.c except for unk_24 --- src/battle_ai.c | 874 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 731 insertions(+), 143 deletions(-) (limited to 'src/battle_ai.c') diff --git a/src/battle_ai.c b/src/battle_ai.c index 7c9b7f17e..4727b2eb0 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -5,12 +5,19 @@ #include "rng.h" #include "abilities.h" #include "species.h" +#include "item.h" #define AIScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) #define AIScriptRead16(ptr) ((ptr)[0] | (ptr)[1] << 8) #define AIScriptRead8(ptr) ((ptr)[0]) #define AIScriptReadPtr(ptr) (u8*) AIScriptRead32(ptr) +#define AI_THINKING_STRUCT ((struct AI_ThinkingStruct *)(&battle_2000000 + 0x16800)) +#define AI_ARRAY_160CC ((&battle_2000000 + 0x160CC)) + +extern void sub_801CAF8(u8, u8); +extern u8 sub_8109908(void); + enum { TARGET, @@ -20,10 +27,11 @@ enum extern void move_effectiveness_something(u16, u8, u8); extern u16 gBattleTypeFlags; +extern u16 gBattleWeather; extern u8 gUnknown_02024A60; extern u8 gUnknown_02024A6A[][2]; extern u16 gUnknown_02024BE6; -extern u32 gUnknown_02024BEC; +extern int gUnknown_02024BEC; extern u8 gUnknown_02024C07; // something player? extern u8 gUnknown_02024C08; // something opponent? extern u8 gUnknown_02024C0C; @@ -33,6 +41,7 @@ extern u16 gUnknown_02024C34[]; extern u32 gUnknown_02024ACC[]; extern u32 gUnknown_02024C98[]; extern u16 gUnknown_02024C7A[]; +extern struct BattlePokemon gBattleMons[]; extern struct BattlePokemon gUnknown_02024A8C[]; extern u8 gUnknown_030042E0[]; extern u8 gCritMultiplier; @@ -40,11 +49,13 @@ extern u16 gTrainerBattleOpponent; extern u32 gBitTable[]; extern u8 *BattleAIs[]; extern struct Trainer gTrainers[]; -extern struct BattlePokemon gBattleMons[]; extern struct BattleMove gBattleMoves[]; extern struct BaseStats gBaseStats[]; extern void (*gBattleAICmdTable[])(void); +// 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 @@ -65,16 +76,34 @@ struct UnknownStruct1 struct UnknownStruct3 { - u8 filler0[0x20]; + u8 *ptr[4]; // might be 8 pointers + u8 filler0[0x10]; 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 UnknownStruct1 unk_2016A00; extern struct UnknownStruct3 unk_2016C00; +extern struct UnknownStruct4 gUnknown_02024CA8[]; void BattleAI_SetupAIData(void); void BattleAI_DoAIProcessing(void); void sub_810745C(void); +void sub_81098C4(u8 *); // if the AI is a Link battle, safari, battle tower, or ereader, it will ignore considering item uses. void BattleAI_HandleItemUseBeforeAISetup(void) @@ -168,13 +197,17 @@ u8 BattleAI_GetAIActionToUse(void) gAIThinkingSpace.aiLogicId++; gAIThinkingSpace.moveConsidered = 0; } + + // will KO, need to use item or switch. if(gAIThinkingSpace.unk10 & 2) return 4; if(gAIThinkingSpace.unk10 & 4) return 5; + r5 = 1; arr1[0] = gAIThinkingSpace.score[0]; arr2[0] = 0; + for(i = 1; i < 4; i++) { if(arr1[0] < (s8)gAIThinkingSpace.score[i]) @@ -189,6 +222,7 @@ u8 BattleAI_GetAIActionToUse(void) arr2[r5++] = i; } } + return arr2[Random() % r5]; } @@ -529,7 +563,7 @@ void BattleAICmd_if_not_status4(void) void BattleAICmd_if_less_than(void) { - if (gAIThinkingSpace.unk8 < gAIScriptPtr[1]) + if (gAIThinkingSpace.funcResult < gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -537,7 +571,7 @@ void BattleAICmd_if_less_than(void) void BattleAICmd_if_more_than(void) { - if (gAIThinkingSpace.unk8 > gAIScriptPtr[1]) + if (gAIThinkingSpace.funcResult > gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -545,7 +579,7 @@ void BattleAICmd_if_more_than(void) void BattleAICmd_if_equal(void) { - if (gAIThinkingSpace.unk8 == gAIScriptPtr[1]) + if (gAIThinkingSpace.funcResult == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -553,7 +587,7 @@ void BattleAICmd_if_equal(void) void BattleAICmd_if_not_equal(void) { - if (gAIThinkingSpace.unk8 != gAIScriptPtr[1]) + if (gAIThinkingSpace.funcResult != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -563,7 +597,7 @@ void BattleAICmd_if_less_than_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); - if (gAIThinkingSpace.unk8 < *temp) + if (gAIThinkingSpace.funcResult < *temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -573,7 +607,7 @@ void BattleAICmd_if_more_than_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); - if (gAIThinkingSpace.unk8 > *temp) + if (gAIThinkingSpace.funcResult > *temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -583,7 +617,7 @@ void BattleAICmd_if_equal_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); - if (gAIThinkingSpace.unk8 == *temp) + if (gAIThinkingSpace.funcResult == *temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -593,7 +627,7 @@ void BattleAICmd_if_not_equal_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); - if (gAIThinkingSpace.unk8 != *temp) + if (gAIThinkingSpace.funcResult != *temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -625,7 +659,7 @@ void BattleAICmd_if_in_bytes(void) while(*ptr != 0xFF) { - if(gAIThinkingSpace.unk8 == *ptr) + if(gAIThinkingSpace.funcResult == *ptr) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); return; @@ -641,7 +675,7 @@ void BattleAICmd_if_not_in_bytes(void) while(*ptr != 0xFF) { - if(gAIThinkingSpace.unk8 == *ptr) + if(gAIThinkingSpace.funcResult == *ptr) { gAIScriptPtr += 9; return; @@ -657,7 +691,7 @@ void BattleAICmd_if_in_words(void) while(*ptr != 0xFFFF) { - if(gAIThinkingSpace.unk8 == *ptr) + if(gAIThinkingSpace.funcResult == *ptr) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); return; @@ -673,7 +707,7 @@ void BattleAICmd_if_not_in_words(void) while(*ptr != 0xFFFF) { - if(gAIThinkingSpace.unk8 == *ptr) + if(gAIThinkingSpace.funcResult == *ptr) { gAIScriptPtr += 9; return; @@ -717,7 +751,7 @@ void BattleAICmd_if_user_cant_damage(void) void BattleAICmd_unk_21(void) { - gAIThinkingSpace.unk8 = gUnknown_030042E0[19]; + gAIThinkingSpace.funcResult = gUnknown_030042E0[19]; gAIScriptPtr += 1; } @@ -728,19 +762,19 @@ void BattleAICmd_get_type(void) switch(typeVar) { case 1: - gAIThinkingSpace.unk8 = gBattleMons[gUnknown_02024C07].type1; + gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C07].type1; break; case 0: - gAIThinkingSpace.unk8 = gBattleMons[gUnknown_02024C08].type1; + gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C08].type1; break; case 3: - gAIThinkingSpace.unk8 = gBattleMons[gUnknown_02024C07].type2; + gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C07].type2; break; case 2: - gAIThinkingSpace.unk8 = gBattleMons[gUnknown_02024C08].type2; + gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C08].type2; break; case 4: - gAIThinkingSpace.unk8 = gBattleMoves[gAIThinkingSpace.unk2].type; + gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].type; break; } gAIScriptPtr += 2; @@ -748,7 +782,7 @@ void BattleAICmd_get_type(void) void BattleAICmd_unk_23(void) { - gAIThinkingSpace.unk8 = gBattleMoves[gAIThinkingSpace.unk2].power; + gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].power; gAIScriptPtr += 1; } @@ -999,16 +1033,16 @@ _081083D0: .4byte gAIScriptPtr\n\ void BattleAICmd_get_move(void) { if (gAIScriptPtr[1] == USER) - gAIThinkingSpace.unk8 = gUnknown_02024C34[gUnknown_02024C07]; + gAIThinkingSpace.funcResult = gUnknown_02024C34[gUnknown_02024C07]; else - gAIThinkingSpace.unk8 = gUnknown_02024C34[gUnknown_02024C08]; + gAIThinkingSpace.funcResult = gUnknown_02024C34[gUnknown_02024C08]; gAIScriptPtr += 2; } void BattleAICmd_if_type(void) { - if ( gAIScriptPtr[1] == gAIThinkingSpace.unk8 ) + if ( gAIScriptPtr[1] == gAIThinkingSpace.funcResult ) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1016,7 +1050,7 @@ void BattleAICmd_if_type(void) void BattleAICmd_unk_27(void) // if_not_type { - if ( gAIScriptPtr[1] != gAIThinkingSpace.unk8 ) + if ( gAIScriptPtr[1] != gAIThinkingSpace.funcResult ) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1052,7 +1086,7 @@ void BattleAICmd_count_alive_pokemon(void) int i; u8 var, var2; - ai->unk8 = 0; + ai->funcResult = 0; if (gAIScriptPtr[1] == USER) index = gUnknown_02024C07; @@ -1085,7 +1119,7 @@ void BattleAICmd_count_alive_pokemon(void) && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG) { - ai2->unk8++; + ai2->funcResult++; } } @@ -1094,13 +1128,13 @@ void BattleAICmd_count_alive_pokemon(void) void BattleAICmd_unk_2D(void) { - gAIThinkingSpace.unk8 = gAIThinkingSpace.unk2; + gAIThinkingSpace.funcResult = gAIThinkingSpace.unk2; gAIScriptPtr += 1; } void BattleAICmd_unk_2E(void) { - gAIThinkingSpace.unk8 = gBattleMoves[gAIThinkingSpace.unk2].effect; + gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].effect; gAIScriptPtr += 1; } @@ -1119,7 +1153,7 @@ void BattleAICmd_get_ability(void) if(unk_2016A00.unk20[unk] != 0) { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 512))->unk8 = unk_2016A00.unk20[unk]; + ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = unk_2016A00.unk20[unk]; gAIScriptPtr += 2; return; } @@ -1127,7 +1161,7 @@ void BattleAICmd_get_ability(void) // abilities that prevent fleeing. if(gBattleMons[var].ability == ABILITY_SHADOW_TAG || gBattleMons[var].ability == ABILITY_MAGNET_PULL || gBattleMons[var].ability == ABILITY_ARENA_TRAP) { - gAIThinkingSpace.unk8 = gBattleMons[var].ability; + gAIThinkingSpace.funcResult = gBattleMons[var].ability; gAIScriptPtr += 2; return; } @@ -1139,27 +1173,27 @@ void BattleAICmd_get_ability(void) // AI is guessing what ability? if(Random() & 1) { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->unk8 = gBaseStats[gBattleMons[var].species].ability1; + ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability1; gAIScriptPtr += 2; return; } else { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->unk8 = gBaseStats[gBattleMons[var].species].ability2; + ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability2; gAIScriptPtr += 2; return; } } else { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->unk8 = gBaseStats[gBattleMons[var].species].ability1; // it's definitely ability 1. + ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability1; // it's definitely ability 1. gAIScriptPtr += 2; return; } } else { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->unk8 = gBaseStats[gBattleMons[var].species].ability2; // AI cant actually reach this part since every mon has at least 1 ability. + ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability2; // AI cant actually reach this part since every mon has at least 1 ability. gAIScriptPtr += 2; return; } @@ -1167,7 +1201,7 @@ void BattleAICmd_get_ability(void) else { // The AI knows its own ability. - gAIThinkingSpace.unk8 = gBattleMons[var].ability; + gAIThinkingSpace.funcResult = gBattleMons[var].ability; gAIScriptPtr += 2; return; } @@ -1185,7 +1219,7 @@ void BattleAICmd_unk_30(void) gUnknown_02024C68 = 0; gCritMultiplier = 1; ai = &battle_2000000.ai; - ai->unk8 = 0; + ai->funcResult = 0; for(i = 0; i < 4; i++) { @@ -1210,118 +1244,47 @@ void BattleAICmd_unk_30(void) gUnknown_02024BEC = 0; ai2 = &battle_2000000.ai; - if (ai2->unk8 < gUnknown_02024BEC) - ai2->unk8 = gUnknown_02024BEC; + if (ai2->funcResult < gUnknown_02024BEC) + ai2->funcResult = gUnknown_02024BEC; } } gAIScriptPtr += 1; } -// same function as above but no for loop. -__attribute__((naked)) void BattleAICmd_if_damage_bonus(void) { - asm(".syntax unified\n\ - push {r4,r5,lr}\n\ - ldr r0, _08108928 @ =gUnknown_02024DEC\n\ - movs r1, 0\n\ - strh r1, [r0]\n\ - ldr r2, _0810892C @ =0x02000000\n\ - ldr r3, _08108930 @ =0x0001601c\n\ - adds r0, r2, r3\n\ - strb r1, [r0]\n\ - adds r3, 0x3\n\ - adds r0, r2, r3\n\ - movs r3, 0x1\n\ - strb r3, [r0]\n\ - ldr r5, _08108934 @ =gUnknown_02024C68\n\ - strb r1, [r5]\n\ - ldr r0, _08108938 @ =gCritMultiplier\n\ - strb r3, [r0]\n\ - ldr r4, _0810893C @ =gUnknown_02024BEC\n\ - movs r0, 0x28\n\ - str r0, [r4]\n\ - ldr r1, _08108940 @ =gUnknown_02024BE6\n\ - movs r0, 0xB4\n\ - lsls r0, 9\n\ - adds r2, r0\n\ - ldrh r0, [r2, 0x2]\n\ - strh r0, [r1]\n\ - ldrh r0, [r1]\n\ - ldr r1, _08108944 @ =gUnknown_02024C07\n\ - ldrb r1, [r1]\n\ - ldr r2, _08108948 @ =gUnknown_02024C08\n\ - ldrb r2, [r2]\n\ - bl move_effectiveness_something\n\ - ldr r0, [r4]\n\ - cmp r0, 0x78\n\ - bne _081088D6\n\ - movs r0, 0x50\n\ - str r0, [r4]\n\ -_081088D6:\n\ - ldr r0, [r4]\n\ - cmp r0, 0xF0\n\ - bne _081088E0\n\ - movs r0, 0xA0\n\ - str r0, [r4]\n\ -_081088E0:\n\ - ldr r0, [r4]\n\ - cmp r0, 0x1E\n\ - bne _081088EA\n\ - movs r0, 0x14\n\ - str r0, [r4]\n\ -_081088EA:\n\ - ldr r0, [r4]\n\ - cmp r0, 0xF\n\ - bne _081088F4\n\ - movs r0, 0xA\n\ - str r0, [r4]\n\ -_081088F4:\n\ - ldrb r1, [r5]\n\ - movs r0, 0x8\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _08108902\n\ - movs r0, 0\n\ - str r0, [r4]\n\ -_08108902:\n\ - ldrb r0, [r4]\n\ - ldr r3, _0810894C @ =gAIScriptPtr\n\ - ldr r2, [r3]\n\ - ldrb r1, [r2, 0x1]\n\ - cmp r0, r1\n\ - bne _08108950\n\ - ldrb r1, [r2, 0x2]\n\ - ldrb r0, [r2, 0x3]\n\ - lsls r0, 8\n\ - orrs r1, r0\n\ - ldrb r0, [r2, 0x4]\n\ - lsls r0, 16\n\ - orrs r1, r0\n\ - ldrb r0, [r2, 0x5]\n\ - lsls r0, 24\n\ - orrs r1, r0\n\ - str r1, [r3]\n\ - b _08108954\n\ - .align 2, 0\n\ -_08108928: .4byte gUnknown_02024DEC\n\ -_0810892C: .4byte 0x02000000\n\ -_08108930: .4byte 0x0001601c\n\ -_08108934: .4byte gUnknown_02024C68\n\ -_08108938: .4byte gCritMultiplier\n\ -_0810893C: .4byte gUnknown_02024BEC\n\ -_08108940: .4byte gUnknown_02024BE6\n\ -_08108944: .4byte gUnknown_02024C07\n\ -_08108948: .4byte gUnknown_02024C08\n\ -_0810894C: .4byte gAIScriptPtr\n\ -_08108950:\n\ - adds r0, r2, 0x6\n\ - str r0, [r3]\n\ -_08108954:\n\ - pop {r4,r5}\n\ - pop {r0}\n\ - bx r0\n\ - .syntax divided\n"); + struct AI_ThinkingStruct *ai; + u8 damageVar; + + gUnknown_02024DEC = 0; + battle_2000000.unk.unk1 = 0; + battle_2000000.unk.unk4 = 1; + gUnknown_02024C68 = 0; + gCritMultiplier = 1; + + gUnknown_02024BEC = 40; + gUnknown_02024BE6 = (ai = &battle_2000000.ai)->unk2; + + move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); + + if (gUnknown_02024BEC == 120) + gUnknown_02024BEC = 80; + if(gUnknown_02024BEC == 240) + gUnknown_02024BEC = 160; + if(gUnknown_02024BEC == 30) + gUnknown_02024BEC = 20; + if(gUnknown_02024BEC == 15) + gUnknown_02024BEC = 10; + + if(gUnknown_02024C68 & 8) + gUnknown_02024BEC = 0; + + // i have to store 2024BEC in a local variable before the comparison or else it will not match. + damageVar = gUnknown_02024BEC; + if(damageVar == gAIScriptPtr[1]) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); + else + gAIScriptPtr += 6; } void BattleAICmd_unk_32(void) @@ -1366,3 +1329,628 @@ void BattleAICmd_if_status_in_party(void) gAIScriptPtr += 10; } + +void BattleAICmd_if_status_not_in_party(void) +{ + struct Pokemon *party; + int i; + u32 statusToCompareTo; + u8 *partyPtr; + + // what weird code. needed to match + switch(gAIScriptPtr[1]) + { + case 1: + partyPtr = (u8 *)gEnemyParty; + party = (struct Pokemon *)partyPtr; + break; + default: + partyPtr = (u8 *)gPlayerParty; + party = (struct Pokemon *)partyPtr; + break; + } + + statusToCompareTo = AIScriptRead32(gAIScriptPtr + 2); + + for (i = 0; i < 6; i++) + { + u16 species = GetMonData(&party[i], MON_DATA_SPECIES); + u16 hp = GetMonData(&party[i], MON_DATA_HP); + u32 status = GetMonData(&party[i], MON_DATA_STATUS); + + // this jump is seemingly bugged. everytime the status is found, the AI's logic jumps further and further past its intended destination. + if (species != SPECIES_NONE && species != SPECIES_EGG && hp != 0 && status == statusToCompareTo) + gAIScriptPtr += 10; // doesnt return? + } + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); +} + +void BattleAICmd_unk_36(void) +{ + if(gBattleWeather & 7) + gAIThinkingSpace.funcResult = 1; + if(gBattleWeather & 0x18) + gAIThinkingSpace.funcResult = 2; + if(gBattleWeather & 0x60) + gAIThinkingSpace.funcResult = 0; + if(gBattleWeather & 0x80) + gAIThinkingSpace.funcResult = 3; + + gAIScriptPtr += 1; +} + +void BattleAICmd_if_effect(void) +{ + if(gBattleMoves[gAIThinkingSpace.unk2].effect == gAIScriptPtr[1]) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); + else + gAIScriptPtr += 6; +} + +void BattleAICmd_if_not_effect(void) +{ + if(gBattleMoves[gAIThinkingSpace.unk2].effect != gAIScriptPtr[1]) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); + else + gAIScriptPtr += 6; +} + +void BattleAICmd_if_stat_level_less_than(void) +{ + u32 party; + + if(gAIScriptPtr[1] == USER) + party = gUnknown_02024C07; + else + party = gUnknown_02024C08; + + if(gBattleMons[party].statStages[gAIScriptPtr[2]] < gAIScriptPtr[3]) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + else + gAIScriptPtr += 8; +} + +void BattleAICmd_if_stat_level_more_than(void) +{ + u32 party; + + if(gAIScriptPtr[1] == USER) + party = gUnknown_02024C07; + else + party = gUnknown_02024C08; + + if(gBattleMons[party].statStages[gAIScriptPtr[2]] > gAIScriptPtr[3]) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + else + gAIScriptPtr += 8; +} + +void BattleAICmd_if_stat_level_equal(void) +{ + u32 party; + + if(gAIScriptPtr[1] == USER) + party = gUnknown_02024C07; + else + party = gUnknown_02024C08; + + if(gBattleMons[party].statStages[gAIScriptPtr[2]] == gAIScriptPtr[3]) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + else + gAIScriptPtr += 8; +} + +void BattleAICmd_if_stat_level_not_equal(void) +{ + u32 party; + + if(gAIScriptPtr[1] == USER) + party = gUnknown_02024C07; + else + party = gUnknown_02024C08; + + if(gBattleMons[party].statStages[gAIScriptPtr[2]] != gAIScriptPtr[3]) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + else + gAIScriptPtr += 8; +} + +void BattleAICmd_if_can_faint(void) +{ + if(gBattleMoves[gAIThinkingSpace.unk2].power < 2) + { + gAIScriptPtr += 5; + return; + } + gUnknown_02024DEC = 0; + ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk1 = 0; + ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk4 = 1; + gUnknown_02024C68 = 0; + gCritMultiplier = 1; + gUnknown_02024BE6 = gAIThinkingSpace.unk2; + sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); + move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); + + gUnknown_02024BEC = gUnknown_02024BEC * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; + + // moves always do at least 1 damage. + if(gUnknown_02024BEC == 0) + gUnknown_02024BEC = 1; + + if(gBattleMons[gUnknown_02024C08].hp <= gUnknown_02024BEC) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); + else + gAIScriptPtr += 5; +} + +void BattleAICmd_if_cant_faint(void) +{ + if(gBattleMoves[gAIThinkingSpace.unk2].power < 2) + { + gAIScriptPtr += 5; + return; + } + + gUnknown_02024DEC = 0; + ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk1 = 0; + ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk4 = 1; + gUnknown_02024C68 = 0; + gCritMultiplier = 1; + gUnknown_02024BE6 = gAIThinkingSpace.unk2; + sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); + move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); + + gUnknown_02024BEC = gUnknown_02024BEC * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; + + // this macro is missing the damage 0 = 1 assumption. + + if(gBattleMons[gUnknown_02024C08].hp > gUnknown_02024BEC) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); + else + gAIScriptPtr += 5; +} + +void BattleAICmd_unk_3F(void) +{ + int i; + u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); + + switch(gAIScriptPtr[1]) + { + case 1: + case 3: + for(i = 0; i < 4; i++) + { + if(gBattleMons[gUnknown_02024C07].moves[i] == *temp_ptr) + break; + } + if(i == 4) + { + gAIScriptPtr += 8; + return; + } + else + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + return; + } + case 0: + case 2: + for(i = 0; i < 8; i++) + { + if(unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == *temp_ptr) + break; + } + if(i == 8) + { + gAIScriptPtr += 8; + return; + } + else + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + return; + } + } +} + +void BattleAICmd_unk_40(void) +{ + int i; + u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); + + switch(gAIScriptPtr[1]) + { + case 1: + case 3: + for(i = 0; i < 4; i++) + { + if(gBattleMons[gUnknown_02024C07].moves[i] == *temp_ptr) + break; + } + if(i != 4) + { + gAIScriptPtr += 8; + return; + } + else + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + return; + } + case 0: + case 2: + for(i = 0; i < 8; i++) + { + if(unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == *temp_ptr) + break; + } + if(i != 8) + { + gAIScriptPtr += 8; + return; + } + else + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + return; + } + } +} + +void BattleAICmd_if_move_effect(void) +{ + int i; + + switch(gAIScriptPtr[1]) + { + case 1: + case 3: + for(i = 0; i < 4; i++) + { + if(gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gAIScriptPtr[2]) + break; + } + if(i != 4) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); + else + gAIScriptPtr += 7; + break; + case 0: + case 2: + for(i = 0; i < 8; i++) + { + if(gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[unk_2016A00.unk0[gUnknown_02024C08 >> 1][i]].effect == gAIScriptPtr[2]) + break; + } + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); + } +} + +void BattleAICmd_if_not_move_effect(void) +{ + int i; + + switch(gAIScriptPtr[1]) + { + case 1: + case 3: + for(i = 0; i < 4; i++) + { + if(gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gAIScriptPtr[2]) + break; + } + if(i != 4) + gAIScriptPtr += 7; + else + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); + break; + case 0: + case 2: + for(i = 0; i < 8; i++) + { + if(unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] != 0 && gBattleMoves[unk_2016A00.unk0[gUnknown_02024C08 >> 1][i]].effect == gAIScriptPtr[2]) + break; + } + gAIScriptPtr += 7; + } +} + +void BattleAICmd_if_last_move_did_damage(void) +{ + u8 var; + + if(gAIScriptPtr[1] == USER) + var = gUnknown_02024C07; + else + var = gUnknown_02024C08; + + if(gAIScriptPtr[2] == 0) + { + if(gUnknown_02024CA8[var].unk4 == 0) + { + gAIScriptPtr += 7; + return; + } + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); + return; + } + else if(gAIScriptPtr[2] != 1) + { + gAIScriptPtr += 7; + return; + } + else if(gUnknown_02024CA8[var].unk6 != 0) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); + return; + } + gAIScriptPtr += 7; +} + +void BattleAICmd_if_encored(void) +{ + switch(gAIScriptPtr[1]) + { + case 0: // _08109348 + if(gUnknown_02024CA8[gUnknown_02024A60].unk4 == gAIThinkingSpace.unk2) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); + return; + } + gAIScriptPtr += 6; + return; + case 1: // _08109370 + if(gUnknown_02024CA8[gUnknown_02024A60].unk6 == gAIThinkingSpace.unk2) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); + return; + } + gAIScriptPtr += 6; + return; + default: + gAIScriptPtr += 6; + return; + } +} + +void BattleAICmd_unk_45(void) +{ + gAIThinkingSpace.unk10 |= 0xB; +} + +void BattleAICmd_if_random_2(void) +{ + u8 var = battle_2000000.unk88 * 5; + + if((u8)(Random() % 100) < var) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); + else + gAIScriptPtr += 5; +} + +void BattleAICmd_unk_47(void) +{ + gAIThinkingSpace.unk10 |= 0xD; +} + +void BattleAICmd_get_hold_effect(void) +{ + u8 var; + u16 status; + u8 *aiPtr; + + if(gAIScriptPtr[1] == USER) + var = gUnknown_02024C07; + else + var = gUnknown_02024C08; + + if(battle_side_get_owner(var) == 0) + { + // weird pointer arithmetic is needed to match. + status = (battle_get_per_side_status(var) & 1); + aiPtr = (u8 *)&gAIThinkingSpace; + gAIThinkingSpace.funcResult = ((struct UnknownStruct1 *)((u8 *)aiPtr + 0x202))->unk20[status]; + } + else + gAIThinkingSpace.funcResult = ItemId_GetHoldEffect(gBattleMons[var].item); + + gAIScriptPtr += 2; +} + +void BattleAICmd_get_gender(void) +{ + u8 var; + + if(gAIScriptPtr[1] == USER) + var = gUnknown_02024C07; + else + var = gUnknown_02024C08; + + gAIThinkingSpace.funcResult = GetGenderFromSpeciesAndPersonality(gBattleMons[var].species, gBattleMons[var].personality); + + gAIScriptPtr += 2; +} + +void BattleAICmd_is_first_turn(void) +{ + u8 var; + + if(gAIScriptPtr[1] == USER) + var = gUnknown_02024C07; + else + var = gUnknown_02024C08; + + gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk16; + + gAIScriptPtr += 2; +} + +void BattleAICmd_get_stockpile_count(void) +{ + u8 var; + + if(gAIScriptPtr[1] == USER) + var = gUnknown_02024C07; + else + var = gUnknown_02024C08; + + gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk9; + + gAIScriptPtr += 2; +} + +void BattleAICmd_unk_4C(void) +{ + gAIThinkingSpace.funcResult = gBattleTypeFlags & 1; + + gAIScriptPtr += 1; +} + +void BattleAICmd_get_item(void) +{ + u8 var; + + if (gAIScriptPtr[1] == USER) + var = gUnknown_02024C07; + else + var = gUnknown_02024C08; + + // this hack and a half matches. whatever. i dont care. someone else fix this mess later. + ((struct AI_ThinkingStruct *)(unk_2000000 + 0x16800))->funcResult = unk_2000000[0x160CC + var * 2]; + + gAIScriptPtr += 2; +} + +void BattleAICmd_unk_4E(void) +{ + gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].type; + + gAIScriptPtr += 1; +} + +void BattleAICmd_unk_4F(void) +{ + gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].power; + + gAIScriptPtr += 1; +} + +void BattleAICmd_unk_50(void) +{ + gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].effect; + + gAIScriptPtr += 1; +} + +void BattleAICmd_get_protect_count(void) +{ + u8 var; + + if(gAIScriptPtr[1] == USER) + var = gUnknown_02024C07; + else + var = gUnknown_02024C08; + + gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk8; + + gAIScriptPtr += 2; +} + +void BattleAICmd_unk_52(void) {} + +void BattleAICmd_unk_53(void) {} + +void BattleAICmd_unk_54(void) {} + +void BattleAICmd_unk_55(void) {} + +void BattleAICmd_unk_56(void) {} + +void BattleAICmd_unk_57(void) {} + +void BattleAICmd_call(void) +{ + sub_81098C4(gAIScriptPtr + 5); + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); +} + +void BattleAICmd_jump(void) +{ + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); +} + +void BattleAICmd_unk_5A(void) +{ + if(sub_8109908() == 0) + gAIThinkingSpace.unk10 |= 1; +} + +void BattleAICmd_if_level_cond(void) +{ + switch(gAIScriptPtr[1]) + { + case 0: + if(gBattleMons[gUnknown_02024C07].level > gBattleMons[gUnknown_02024C08].level) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); + return; + } + gAIScriptPtr += 6; + return; + case 1: + if(gBattleMons[gUnknown_02024C07].level < gBattleMons[gUnknown_02024C08].level) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); + return; + } + gAIScriptPtr += 6; + return; + case 2: + if(gBattleMons[gUnknown_02024C07].level == gBattleMons[gUnknown_02024C08].level) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); + return; + } + gAIScriptPtr += 6; + return; + } +} + +void BattleAICmd_if_taunted(void) +{ + if(gUnknown_02024CA8[gUnknown_02024C08].taunt) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); + else + gAIScriptPtr += 5; +} + +void BattleAICmd_if_not_taunted(void) +{ + if(!(gUnknown_02024CA8[gUnknown_02024C08].taunt)) + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); + else + gAIScriptPtr += 5; +} + +void sub_81098C4(u8 *var) +{ + unk_2016C00.ptr[unk_2016C00.unk20++] = var; +} + +void unref_sub_81098E4(void) +{ + unk_2016C00.ptr[unk_2016C00.unk20++] = gAIScriptPtr; +} + +bool8 sub_8109908(void) +{ + if(unk_2016C00.unk20 != 0) + { + --unk_2016C00.unk20; + gAIScriptPtr = unk_2016C00.ptr[unk_2016C00.unk20]; + return TRUE; + } + else + return FALSE; +} -- cgit v1.2.3 From 159080a2d83630046b30e9a17bc3a324bed0dcc0 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Tue, 10 Jan 2017 21:36:37 -0800 Subject: nonmatching BattleAICmd_unk_24 --- src/battle_ai.c | 153 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 110 insertions(+), 43 deletions(-) (limited to 'src/battle_ai.c') diff --git a/src/battle_ai.c b/src/battle_ai.c index 4727b2eb0..c5e9505af 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -12,7 +12,7 @@ #define AIScriptRead8(ptr) ((ptr)[0]) #define AIScriptReadPtr(ptr) (u8*) AIScriptRead32(ptr) -#define AI_THINKING_STRUCT ((struct AI_ThinkingStruct *)(&battle_2000000 + 0x16800)) +#define AI_THINKING_STRUCT ((struct AI_ThinkingStruct *)((u8 *)&battle_2000000 + 0x16800)) #define AI_ARRAY_160CC ((&battle_2000000 + 0x160CC)) extern void sub_801CAF8(u8, u8); @@ -31,11 +31,11 @@ extern u16 gBattleWeather; extern u8 gUnknown_02024A60; extern u8 gUnknown_02024A6A[][2]; extern u16 gUnknown_02024BE6; -extern int gUnknown_02024BEC; +extern int gBattleMoveDamage; extern u8 gUnknown_02024C07; // something player? extern u8 gUnknown_02024C08; // something opponent? extern u8 gUnknown_02024C0C; -extern u8 gUnknown_02024C68; +extern u8 gBattleMoveFlags; extern u16 gUnknown_02024DEC; extern u16 gUnknown_02024C34[]; extern u32 gUnknown_02024ACC[]; @@ -53,6 +53,8 @@ extern struct BattleMove gBattleMoves[]; extern struct BaseStats gBaseStats[]; extern void (*gBattleAICmdTable[])(void); +extern const u16 gUnknown_083F62BC[]; + // needed to match the hack that is get_item, thanks cam, someone else clean this up later. extern u8 unk_2000000[]; @@ -786,6 +788,70 @@ void BattleAICmd_unk_23(void) gAIScriptPtr += 1; } +#ifdef NONMATCHING +void BattleAICmd_unk_24(void) +{ + int i, j; + s32 damage; + s32 damages[4]; + + for (i = 0; gUnknown_083F62BC[i] != 0xFFFF; i++) + if (gBattleMoves[AI_THINKING_STRUCT->unk2].effect == gUnknown_083F62BC[i]) + break; + + if (gBattleMoves[AI_THINKING_STRUCT->unk2].power > 1 + && gUnknown_083F62BC[i] == 0xFFFF) + { + gUnknown_02024DEC = 0; + *((u8 *)&battle_2000000 + 0x1601C) = 0; + *((u8 *)&battle_2000000 + 0x1601F) = 1; + gBattleMoveFlags = 0; + gCritMultiplier = 1; + + for (i = 0; i < 4; i++) + { + for (j = 0; gUnknown_083F62BC[j] != 0xFFFF; j++) + { + if (gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gUnknown_083F62BC[j]) + break; + } + + if (gBattleMons[gUnknown_02024C07].moves[i] + && gUnknown_083F62BC[j] == 0xFFFF + && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power > 1) + { + gUnknown_02024BE6 = gBattleMons[gUnknown_02024C07].moves[i]; + sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); + move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); + damage = (gBattleMoveDamage * AI_THINKING_STRUCT->unk18[i]) / 100; + damages[i] = damage; + if (!damage) + damages[i] = 1; + } + else + { + damages[i] = 0; + } + } + + for (i = 0; i < 4; i++) + if (damages[i] > damages[AI_THINKING_STRUCT->moveConsidered]) + break; + + if (i == 4) + AI_THINKING_STRUCT->funcResult = 2; + else + AI_THINKING_STRUCT->funcResult = 1; + } + else + { + AI_THINKING_STRUCT->funcResult = 0; + gAIScriptPtr += 1; + } + + gAIScriptPtr += 1; +} +#else __attribute__((naked)) void BattleAICmd_unk_24(void) { @@ -850,7 +916,7 @@ _08108250:\n\ adds r0, r5, r2\n\ movs r2, 0x1\n\ strb r2, [r0]\n\ - ldr r0, _08108340 @ =gUnknown_02024C68\n\ + ldr r0, _08108340 @ =gBattleMoveFlags\n\ strb r1, [r0]\n\ ldr r0, _08108344 @ =gCritMultiplier\n\ strb r2, [r0]\n\ @@ -933,7 +999,7 @@ _081082BA:\n\ bl move_effectiveness_something\n\ mov r4, sp\n\ add r4, r8\n\ - ldr r2, _08108358 @ =gUnknown_02024BEC\n\ + ldr r2, _08108358 @ =gBattleMoveDamage\n\ ldr r0, _08108334 @ =0x02016800\n\ adds r0, 0x18\n\ adds r0, r6, r0\n\ @@ -955,13 +1021,13 @@ _08108330: .4byte gBattleMoves\n\ _08108334: .4byte 0x02016800\n\ _08108338: .4byte gUnknown_02024DEC\n\ _0810833C: .4byte 0xfffff81c\n\ -_08108340: .4byte gUnknown_02024C68\n\ +_08108340: .4byte gBattleMoveFlags\n\ _08108344: .4byte gCritMultiplier\n\ _08108348: .4byte gBattleMons\n\ _0810834C: .4byte gUnknown_02024C07\n\ _08108350: .4byte gUnknown_02024BE6\n\ _08108354: .4byte gUnknown_02024C08\n\ -_08108358: .4byte gUnknown_02024BEC\n\ +_08108358: .4byte gBattleMoveDamage\n\ _0810835C:\n\ mov r1, sp\n\ add r1, r8\n\ @@ -1029,6 +1095,7 @@ _081083B8:\n\ _081083D0: .4byte gAIScriptPtr\n\ .syntax divided\n"); } +#endif // NONMATCHING void BattleAICmd_get_move(void) { @@ -1216,14 +1283,14 @@ void BattleAICmd_unk_30(void) gUnknown_02024DEC = 0; battle_2000000.unk.unk1 = 0; battle_2000000.unk.unk4 = 1; - gUnknown_02024C68 = 0; + gBattleMoveFlags = 0; gCritMultiplier = 1; ai = &battle_2000000.ai; ai->funcResult = 0; for(i = 0; i < 4; i++) { - gUnknown_02024BEC = 40; + gBattleMoveDamage = 40; gUnknown_02024BE6 = gBattleMons[gUnknown_02024C07].moves[i]; if (gUnknown_02024BE6) @@ -1231,21 +1298,21 @@ void BattleAICmd_unk_30(void) move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); // reduce by 1/3. - if (gUnknown_02024BEC == 120) - gUnknown_02024BEC = 80; - if(gUnknown_02024BEC == 240) - gUnknown_02024BEC = 160; - if(gUnknown_02024BEC == 30) - gUnknown_02024BEC = 20; - if(gUnknown_02024BEC == 15) - gUnknown_02024BEC = 10; - - if(gUnknown_02024C68 & 8) - gUnknown_02024BEC = 0; + if (gBattleMoveDamage == 120) + gBattleMoveDamage = 80; + if(gBattleMoveDamage == 240) + gBattleMoveDamage = 160; + if(gBattleMoveDamage == 30) + gBattleMoveDamage = 20; + if(gBattleMoveDamage == 15) + gBattleMoveDamage = 10; + + if(gBattleMoveFlags & 8) + gBattleMoveDamage = 0; ai2 = &battle_2000000.ai; - if (ai2->funcResult < gUnknown_02024BEC) - ai2->funcResult = gUnknown_02024BEC; + if (ai2->funcResult < gBattleMoveDamage) + ai2->funcResult = gBattleMoveDamage; } } gAIScriptPtr += 1; @@ -1259,28 +1326,28 @@ void BattleAICmd_if_damage_bonus(void) gUnknown_02024DEC = 0; battle_2000000.unk.unk1 = 0; battle_2000000.unk.unk4 = 1; - gUnknown_02024C68 = 0; + gBattleMoveFlags = 0; gCritMultiplier = 1; - gUnknown_02024BEC = 40; + gBattleMoveDamage = 40; gUnknown_02024BE6 = (ai = &battle_2000000.ai)->unk2; move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); - if (gUnknown_02024BEC == 120) - gUnknown_02024BEC = 80; - if(gUnknown_02024BEC == 240) - gUnknown_02024BEC = 160; - if(gUnknown_02024BEC == 30) - gUnknown_02024BEC = 20; - if(gUnknown_02024BEC == 15) - gUnknown_02024BEC = 10; + if (gBattleMoveDamage == 120) + gBattleMoveDamage = 80; + if(gBattleMoveDamage == 240) + gBattleMoveDamage = 160; + if(gBattleMoveDamage == 30) + gBattleMoveDamage = 20; + if(gBattleMoveDamage == 15) + gBattleMoveDamage = 10; - if(gUnknown_02024C68 & 8) - gUnknown_02024BEC = 0; + if(gBattleMoveFlags & 8) + gBattleMoveDamage = 0; // i have to store 2024BEC in a local variable before the comparison or else it will not match. - damageVar = gUnknown_02024BEC; + damageVar = gBattleMoveDamage; if(damageVar == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else @@ -1465,19 +1532,19 @@ void BattleAICmd_if_can_faint(void) gUnknown_02024DEC = 0; ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk1 = 0; ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk4 = 1; - gUnknown_02024C68 = 0; + gBattleMoveFlags = 0; gCritMultiplier = 1; gUnknown_02024BE6 = gAIThinkingSpace.unk2; sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); - gUnknown_02024BEC = gUnknown_02024BEC * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; + gBattleMoveDamage = gBattleMoveDamage * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; // moves always do at least 1 damage. - if(gUnknown_02024BEC == 0) - gUnknown_02024BEC = 1; + if(gBattleMoveDamage == 0) + gBattleMoveDamage = 1; - if(gBattleMons[gUnknown_02024C08].hp <= gUnknown_02024BEC) + if(gBattleMons[gUnknown_02024C08].hp <= gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -1494,17 +1561,17 @@ void BattleAICmd_if_cant_faint(void) gUnknown_02024DEC = 0; ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk1 = 0; ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk4 = 1; - gUnknown_02024C68 = 0; + gBattleMoveFlags = 0; gCritMultiplier = 1; gUnknown_02024BE6 = gAIThinkingSpace.unk2; sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); - gUnknown_02024BEC = gUnknown_02024BEC * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; + gBattleMoveDamage = gBattleMoveDamage * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; // this macro is missing the damage 0 = 1 assumption. - if(gBattleMons[gUnknown_02024C08].hp > gUnknown_02024BEC) + if(gBattleMons[gUnknown_02024C08].hp > gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; -- cgit v1.2.3 From 29c7e732e34a423af2649255b870e3717d4e35c3 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Tue, 10 Jan 2017 22:08:32 -0800 Subject: define battle AI rodata in C --- src/battle_ai.c | 437 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 325 insertions(+), 112 deletions(-) (limited to 'src/battle_ai.c') diff --git a/src/battle_ai.c b/src/battle_ai.c index c5e9505af..ca767a3a3 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -6,6 +6,7 @@ #include "abilities.h" #include "species.h" #include "item.h" +#include "battle_move_effects.h" #define AIScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) #define AIScriptRead16(ptr) ((ptr)[0] | (ptr)[1] << 8) @@ -51,9 +52,6 @@ extern u8 *BattleAIs[]; extern struct Trainer gTrainers[]; extern struct BattleMove gBattleMoves[]; extern struct BaseStats gBaseStats[]; -extern void (*gBattleAICmdTable[])(void); - -extern const u16 gUnknown_083F62BC[]; // needed to match the hack that is get_item, thanks cam, someone else clean this up later. extern u8 unk_2000000[]; @@ -102,6 +100,221 @@ extern struct UnknownStruct1 unk_2016A00; extern struct UnknownStruct3 unk_2016C00; extern struct UnknownStruct4 gUnknown_02024CA8[]; +static void BattleAICmd_if_random(void); +static void BattleAICmd_if_not_random(void); +static void BattleAICmd_if_random_1(void); +static void BattleAICmd_if_not_random_1(void); +static void BattleAICmd_score(void); +static void BattleAICmd_if_hp_less_than(void); +static void BattleAICmd_if_hp_more_than(void); +static void BattleAICmd_if_hp_equal(void); +static void BattleAICmd_if_hp_not_equal(void); +static void BattleAICmd_if_status(void); +static void BattleAICmd_if_not_status(void); +static void BattleAICmd_if_status2(void); +static void BattleAICmd_if_not_status2(void); +static void BattleAICmd_if_status3(void); +static void BattleAICmd_if_not_status3(void); +static void BattleAICmd_if_status4(void); +static void BattleAICmd_if_not_status4(void); +static void BattleAICmd_if_less_than(void); +static void BattleAICmd_if_more_than(void); +static void BattleAICmd_if_equal(void); +static void BattleAICmd_if_not_equal(void); +static void BattleAICmd_if_less_than_32(void); +static void BattleAICmd_if_more_than_32(void); +static void BattleAICmd_if_equal_32(void); +static void BattleAICmd_if_not_equal_32(void); +static void BattleAICmd_if_move(void); +static void BattleAICmd_if_not_move(void); +static void BattleAICmd_if_in_bytes(void); +static void BattleAICmd_if_not_in_bytes(void); +static void BattleAICmd_if_in_words(void); +static void BattleAICmd_if_not_in_words(void); +static void BattleAICmd_if_user_can_damage(void); +static void BattleAICmd_if_user_cant_damage(void); +static void BattleAICmd_unk_21(void); +static void BattleAICmd_get_type(void); +static void BattleAICmd_unk_23(void); +static void BattleAICmd_unk_24(void); +static void BattleAICmd_get_move(void); +static void BattleAICmd_if_type(void); +static void BattleAICmd_unk_27(void); +static void BattleAICmd_if_would_go_first(void); +static void BattleAICmd_if_would_not_go_first(void); +static void BattleAICmd_unk_2A(void); +static void BattleAICmd_unk_2B(void); +static void BattleAICmd_count_alive_pokemon(void); +static void BattleAICmd_unk_2D(void); +static void BattleAICmd_unk_2E(void); +static void BattleAICmd_get_ability(void); +static void BattleAICmd_unk_30(void); +static void BattleAICmd_if_damage_bonus(void); +static void BattleAICmd_unk_32(void); +static void BattleAICmd_unk_33(void); +static void BattleAICmd_if_status_in_party(void); +static void BattleAICmd_if_status_not_in_party(void); +static void BattleAICmd_unk_36(void); +static void BattleAICmd_if_effect(void); +static void BattleAICmd_if_not_effect(void); +static void BattleAICmd_if_stat_level_less_than(void); +static void BattleAICmd_if_stat_level_more_than(void); +static void BattleAICmd_if_stat_level_equal(void); +static void BattleAICmd_if_stat_level_not_equal(void); +static void BattleAICmd_if_can_faint(void); +static void BattleAICmd_if_cant_faint(void); +static void BattleAICmd_unk_3F(void); +static void BattleAICmd_unk_40(void); +static void BattleAICmd_if_move_effect(void); +static void BattleAICmd_if_not_move_effect(void); +static void BattleAICmd_if_last_move_did_damage(void); +static void BattleAICmd_if_encored(void); +static void BattleAICmd_unk_45(void); +static void BattleAICmd_if_random_2(void); +static void BattleAICmd_unk_47(void); +static void BattleAICmd_get_hold_effect(void); +static void BattleAICmd_get_gender(void); +static void BattleAICmd_is_first_turn(void); +static void BattleAICmd_get_stockpile_count(void); +static void BattleAICmd_unk_4C(void); +static void BattleAICmd_get_item(void); +static void BattleAICmd_unk_4E(void); +static void BattleAICmd_unk_4F(void); +static void BattleAICmd_unk_50(void); +static void BattleAICmd_get_protect_count(void); +static void BattleAICmd_unk_52(void); +static void BattleAICmd_unk_53(void); +static void BattleAICmd_unk_54(void); +static void BattleAICmd_unk_55(void); +static void BattleAICmd_unk_56(void); +static void BattleAICmd_unk_57(void); +static void BattleAICmd_call(void); +static void BattleAICmd_jump(void); +static void BattleAICmd_unk_5A(void); +static void BattleAICmd_if_level_cond(void); +static void BattleAICmd_if_taunted(void); +static void BattleAICmd_if_not_taunted(void); + +typedef void (*BattleAICmdFunc)(void); + +static const BattleAICmdFunc sBattleAICmdTable[] = +{ + BattleAICmd_if_random, + BattleAICmd_if_not_random, + BattleAICmd_if_random_1, + BattleAICmd_if_not_random_1, + BattleAICmd_score, + BattleAICmd_if_hp_less_than, + BattleAICmd_if_hp_more_than, + BattleAICmd_if_hp_equal, + BattleAICmd_if_hp_not_equal, + BattleAICmd_if_status, + BattleAICmd_if_not_status, + BattleAICmd_if_status2, + BattleAICmd_if_not_status2, + BattleAICmd_if_status3, + BattleAICmd_if_not_status3, + BattleAICmd_if_status4, + BattleAICmd_if_not_status4, + BattleAICmd_if_less_than, + BattleAICmd_if_more_than, + BattleAICmd_if_equal, + BattleAICmd_if_not_equal, + BattleAICmd_if_less_than_32, + BattleAICmd_if_more_than_32, + BattleAICmd_if_equal_32, + BattleAICmd_if_not_equal_32, + BattleAICmd_if_move, + BattleAICmd_if_not_move, + BattleAICmd_if_in_bytes, + BattleAICmd_if_not_in_bytes, + BattleAICmd_if_in_words, + BattleAICmd_if_not_in_words, + BattleAICmd_if_user_can_damage, + BattleAICmd_if_user_cant_damage, + BattleAICmd_unk_21, + BattleAICmd_get_type, + BattleAICmd_unk_23, + BattleAICmd_unk_24, + BattleAICmd_get_move, + BattleAICmd_if_type, + BattleAICmd_unk_27, + BattleAICmd_if_would_go_first, + BattleAICmd_if_would_not_go_first, + BattleAICmd_unk_2A, + BattleAICmd_unk_2B, + BattleAICmd_count_alive_pokemon, + BattleAICmd_unk_2D, + BattleAICmd_unk_2E, + BattleAICmd_get_ability, + BattleAICmd_unk_30, + BattleAICmd_if_damage_bonus, + BattleAICmd_unk_32, + BattleAICmd_unk_33, + BattleAICmd_if_status_in_party, + BattleAICmd_if_status_not_in_party, + BattleAICmd_unk_36, + BattleAICmd_if_effect, + BattleAICmd_if_not_effect, + BattleAICmd_if_stat_level_less_than, + BattleAICmd_if_stat_level_more_than, + BattleAICmd_if_stat_level_equal, + BattleAICmd_if_stat_level_not_equal, + BattleAICmd_if_can_faint, + BattleAICmd_if_cant_faint, + BattleAICmd_unk_3F, + BattleAICmd_unk_40, + BattleAICmd_if_move_effect, + BattleAICmd_if_not_move_effect, + BattleAICmd_if_last_move_did_damage, + BattleAICmd_if_encored, + BattleAICmd_unk_45, + BattleAICmd_if_random_2, + BattleAICmd_unk_47, + BattleAICmd_get_hold_effect, + BattleAICmd_get_gender, + BattleAICmd_is_first_turn, + BattleAICmd_get_stockpile_count, + BattleAICmd_unk_4C, + BattleAICmd_get_item, + BattleAICmd_unk_4E, + BattleAICmd_unk_4F, + BattleAICmd_unk_50, + BattleAICmd_get_protect_count, + BattleAICmd_unk_52, + BattleAICmd_unk_53, + BattleAICmd_unk_54, + BattleAICmd_unk_55, + BattleAICmd_unk_56, + BattleAICmd_unk_57, + BattleAICmd_call, + BattleAICmd_jump, + BattleAICmd_unk_5A, + BattleAICmd_if_level_cond, + BattleAICmd_if_taunted, + BattleAICmd_if_not_taunted, +}; + +#ifdef NONMATCHING +static +#endif +const u16 sDiscouragedPowerfulMoveEffects[] = +{ + EFFECT_EXPLOSION, + EFFECT_DREAM_EATER, + EFFECT_RAZOR_WIND, + EFFECT_SKY_ATTACK, + EFFECT_RECHARGE, + EFFECT_SKULL_BASH, + EFFECT_SOLARBEAM, + EFFECT_SPIT_UP, + EFFECT_FOCUS_PUNCH, + EFFECT_SUPERPOWER, + EFFECT_ERUPTION, + EFFECT_OVERHEAT, + 0xFFFF +}; + void BattleAI_SetupAIData(void); void BattleAI_DoAIProcessing(void); void sub_810745C(void); @@ -250,7 +463,7 @@ void BattleAI_DoAIProcessing(void) break; case 1: if(gAIThinkingSpace.unk2 != 0) - gBattleAICmdTable[*(u8 *)gAIScriptPtr](); // run AI command. + sBattleAICmdTable[*(u8 *)gAIScriptPtr](); // run AI command. else { gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] = 0; @@ -305,7 +518,7 @@ void sub_81074F8(u8 a, u8 b) unk_2016A00.unk22[battle_get_per_side_status(a) & 1] = b; } -void BattleAICmd_if_random(void) +static void BattleAICmd_if_random(void) { u16 random = Random(); @@ -315,7 +528,7 @@ void BattleAICmd_if_random(void) gAIScriptPtr += 6; } -void BattleAICmd_if_not_random(void) +static void BattleAICmd_if_not_random(void) { u16 random = Random(); @@ -325,7 +538,7 @@ void BattleAICmd_if_not_random(void) gAIScriptPtr += 6; } -void BattleAICmd_if_random_1(void) // if RNG Value equal to +static void BattleAICmd_if_random_1(void) // if RNG Value equal to { u16 random = Random(); @@ -335,7 +548,7 @@ void BattleAICmd_if_random_1(void) // if RNG Value equal to gAIScriptPtr += 6; } -void BattleAICmd_if_not_random_1(void) // if RNG value not equal to +static void BattleAICmd_if_not_random_1(void) // if RNG value not equal to { u16 random = Random(); @@ -345,7 +558,7 @@ void BattleAICmd_if_not_random_1(void) // if RNG value not equal to gAIScriptPtr += 6; } -void BattleAICmd_score(void) +static void BattleAICmd_score(void) { gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] += gAIScriptPtr[1]; // add the result to the array of the move consider's score. @@ -355,7 +568,7 @@ void BattleAICmd_score(void) gAIScriptPtr += 2; // AI return. } -void BattleAICmd_if_hp_less_than(void) +static void BattleAICmd_if_hp_less_than(void) { u16 var; @@ -370,7 +583,7 @@ void BattleAICmd_if_hp_less_than(void) gAIScriptPtr += 7; } -void BattleAICmd_if_hp_more_than(void) +static void BattleAICmd_if_hp_more_than(void) { u16 var; @@ -385,7 +598,7 @@ void BattleAICmd_if_hp_more_than(void) gAIScriptPtr += 7; } -void BattleAICmd_if_hp_equal(void) +static void BattleAICmd_if_hp_equal(void) { u16 var; @@ -400,7 +613,7 @@ void BattleAICmd_if_hp_equal(void) gAIScriptPtr += 7; } -void BattleAICmd_if_hp_not_equal(void) +static void BattleAICmd_if_hp_not_equal(void) { u16 var; @@ -415,7 +628,7 @@ void BattleAICmd_if_hp_not_equal(void) gAIScriptPtr += 7; } -void BattleAICmd_if_status(void) +static void BattleAICmd_if_status(void) { u16 var; u32 temp; @@ -433,7 +646,7 @@ void BattleAICmd_if_status(void) gAIScriptPtr += 10; } -void BattleAICmd_if_not_status(void) +static void BattleAICmd_if_not_status(void) { u16 var; u32 temp; @@ -451,7 +664,7 @@ void BattleAICmd_if_not_status(void) gAIScriptPtr += 10; } -void BattleAICmd_if_status2(void) +static void BattleAICmd_if_status2(void) { u8 var; u32 temp; @@ -469,7 +682,7 @@ void BattleAICmd_if_status2(void) gAIScriptPtr += 10; } -void BattleAICmd_if_not_status2(void) +static void BattleAICmd_if_not_status2(void) { u8 var; u32 temp; @@ -487,7 +700,7 @@ void BattleAICmd_if_not_status2(void) gAIScriptPtr += 10; } -void BattleAICmd_if_status3(void) +static void BattleAICmd_if_status3(void) { u8 var; u32 temp; @@ -505,7 +718,7 @@ void BattleAICmd_if_status3(void) gAIScriptPtr += 10; } -void BattleAICmd_if_not_status3(void) +static void BattleAICmd_if_not_status3(void) { u8 var; u32 temp; @@ -523,7 +736,7 @@ void BattleAICmd_if_not_status3(void) gAIScriptPtr += 10; } -void BattleAICmd_if_status4(void) +static void BattleAICmd_if_status4(void) { u8 var; u32 temp; @@ -543,7 +756,7 @@ void BattleAICmd_if_status4(void) gAIScriptPtr += 10; } -void BattleAICmd_if_not_status4(void) +static void BattleAICmd_if_not_status4(void) { u8 var; u32 temp; @@ -563,7 +776,7 @@ void BattleAICmd_if_not_status4(void) gAIScriptPtr += 10; } -void BattleAICmd_if_less_than(void) +static void BattleAICmd_if_less_than(void) { if (gAIThinkingSpace.funcResult < gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -571,7 +784,7 @@ void BattleAICmd_if_less_than(void) gAIScriptPtr += 6; } -void BattleAICmd_if_more_than(void) +static void BattleAICmd_if_more_than(void) { if (gAIThinkingSpace.funcResult > gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -579,7 +792,7 @@ void BattleAICmd_if_more_than(void) gAIScriptPtr += 6; } -void BattleAICmd_if_equal(void) +static void BattleAICmd_if_equal(void) { if (gAIThinkingSpace.funcResult == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -587,7 +800,7 @@ void BattleAICmd_if_equal(void) gAIScriptPtr += 6; } -void BattleAICmd_if_not_equal(void) +static void BattleAICmd_if_not_equal(void) { if (gAIThinkingSpace.funcResult != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -595,7 +808,7 @@ void BattleAICmd_if_not_equal(void) gAIScriptPtr += 6; } -void BattleAICmd_if_less_than_32(void) +static void BattleAICmd_if_less_than_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); @@ -605,7 +818,7 @@ void BattleAICmd_if_less_than_32(void) gAIScriptPtr += 9; } -void BattleAICmd_if_more_than_32(void) +static void BattleAICmd_if_more_than_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); @@ -615,7 +828,7 @@ void BattleAICmd_if_more_than_32(void) gAIScriptPtr += 9; } -void BattleAICmd_if_equal_32(void) +static void BattleAICmd_if_equal_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); @@ -625,7 +838,7 @@ void BattleAICmd_if_equal_32(void) gAIScriptPtr += 9; } -void BattleAICmd_if_not_equal_32(void) +static void BattleAICmd_if_not_equal_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); @@ -635,7 +848,7 @@ void BattleAICmd_if_not_equal_32(void) gAIScriptPtr += 9; } -void BattleAICmd_if_move(void) +static void BattleAICmd_if_move(void) { u16 move = AIScriptRead16(gAIScriptPtr + 1); @@ -645,7 +858,7 @@ void BattleAICmd_if_move(void) gAIScriptPtr += 7; } -void BattleAICmd_if_not_move(void) +static void BattleAICmd_if_not_move(void) { u16 move = AIScriptRead16(gAIScriptPtr + 1); @@ -655,7 +868,7 @@ void BattleAICmd_if_not_move(void) gAIScriptPtr += 7; } -void BattleAICmd_if_in_bytes(void) +static void BattleAICmd_if_in_bytes(void) { u8 *ptr = AIScriptReadPtr(gAIScriptPtr + 1); @@ -671,7 +884,7 @@ void BattleAICmd_if_in_bytes(void) gAIScriptPtr += 9; } -void BattleAICmd_if_not_in_bytes(void) +static void BattleAICmd_if_not_in_bytes(void) { u8 *ptr = AIScriptReadPtr(gAIScriptPtr + 1); @@ -687,7 +900,7 @@ void BattleAICmd_if_not_in_bytes(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); } -void BattleAICmd_if_in_words(void) +static void BattleAICmd_if_in_words(void) { u16 *ptr = (u16 *)AIScriptReadPtr(gAIScriptPtr + 1); @@ -703,7 +916,7 @@ void BattleAICmd_if_in_words(void) gAIScriptPtr += 9; } -void BattleAICmd_if_not_in_words(void) +static void BattleAICmd_if_not_in_words(void) { u16 *ptr = (u16 *)AIScriptReadPtr(gAIScriptPtr + 1); @@ -719,7 +932,7 @@ void BattleAICmd_if_not_in_words(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); } -void BattleAICmd_if_user_can_damage(void) +static void BattleAICmd_if_user_can_damage(void) { s32 i; @@ -735,7 +948,7 @@ void BattleAICmd_if_user_can_damage(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } -void BattleAICmd_if_user_cant_damage(void) +static void BattleAICmd_if_user_cant_damage(void) { s32 i; @@ -751,13 +964,13 @@ void BattleAICmd_if_user_cant_damage(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } -void BattleAICmd_unk_21(void) +static void BattleAICmd_unk_21(void) { gAIThinkingSpace.funcResult = gUnknown_030042E0[19]; gAIScriptPtr += 1; } -void BattleAICmd_get_type(void) +static void BattleAICmd_get_type(void) { u8 typeVar = gAIScriptPtr[1]; @@ -782,25 +995,25 @@ void BattleAICmd_get_type(void) gAIScriptPtr += 2; } -void BattleAICmd_unk_23(void) +static void BattleAICmd_unk_23(void) { gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].power; gAIScriptPtr += 1; } #ifdef NONMATCHING -void BattleAICmd_unk_24(void) +static void BattleAICmd_unk_24(void) { int i, j; s32 damage; s32 damages[4]; - for (i = 0; gUnknown_083F62BC[i] != 0xFFFF; i++) - if (gBattleMoves[AI_THINKING_STRUCT->unk2].effect == gUnknown_083F62BC[i]) + for (i = 0; sDiscouragedPowerfulMoveEffects[i] != 0xFFFF; i++) + if (gBattleMoves[AI_THINKING_STRUCT->unk2].effect == sDiscouragedPowerfulMoveEffects[i]) break; if (gBattleMoves[AI_THINKING_STRUCT->unk2].power > 1 - && gUnknown_083F62BC[i] == 0xFFFF) + && sDiscouragedPowerfulMoveEffects[i] == 0xFFFF) { gUnknown_02024DEC = 0; *((u8 *)&battle_2000000 + 0x1601C) = 0; @@ -810,14 +1023,14 @@ void BattleAICmd_unk_24(void) for (i = 0; i < 4; i++) { - for (j = 0; gUnknown_083F62BC[j] != 0xFFFF; j++) + for (j = 0; sDiscouragedPowerfulMoveEffects[j] != 0xFFFF; j++) { - if (gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gUnknown_083F62BC[j]) + if (gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == sDiscouragedPowerfulMoveEffects[j]) break; } if (gBattleMons[gUnknown_02024C07].moves[i] - && gUnknown_083F62BC[j] == 0xFFFF + && sDiscouragedPowerfulMoveEffects[j] == 0xFFFF && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power > 1) { gUnknown_02024BE6 = gBattleMons[gUnknown_02024C07].moves[i]; @@ -853,7 +1066,7 @@ void BattleAICmd_unk_24(void) } #else __attribute__((naked)) -void BattleAICmd_unk_24(void) +static void BattleAICmd_unk_24(void) { asm(".syntax unified\n\ push {r4-r7,lr}\n\ @@ -863,7 +1076,7 @@ void BattleAICmd_unk_24(void) push {r5-r7}\n\ sub sp, 0x14\n\ movs r3, 0\n\ - ldr r0, _08108328 @ =gUnknown_083F62BC\n\ + ldr r0, _08108328 @ =sDiscouragedPowerfulMoveEffects\n\ ldrh r1, [r0]\n\ ldr r4, _0810832C @ =0x0000ffff\n\ ldr r6, _08108330 @ =gBattleMoves\n\ @@ -876,7 +1089,7 @@ void BattleAICmd_unk_24(void) lsls r0, 2\n\ adds r0, r6\n\ ldrb r2, [r0]\n\ - ldr r1, _08108328 @ =gUnknown_083F62BC\n\ + ldr r1, _08108328 @ =sDiscouragedPowerfulMoveEffects\n\ _0810821E:\n\ ldrh r0, [r1]\n\ cmp r2, r0\n\ @@ -898,7 +1111,7 @@ _0810822E:\n\ b _081083B2\n\ _08108240:\n\ lsls r0, r3, 1\n\ - ldr r1, _08108328 @ =gUnknown_083F62BC\n\ + ldr r1, _08108328 @ =sDiscouragedPowerfulMoveEffects\n\ adds r0, r1\n\ ldrh r3, [r0]\n\ ldr r0, _0810832C @ =0x0000ffff\n\ @@ -922,7 +1135,7 @@ _08108250:\n\ strb r2, [r0]\n\ movs r6, 0\n\ mov r9, r3\n\ - ldr r0, _08108328 @ =gUnknown_083F62BC\n\ + ldr r0, _08108328 @ =sDiscouragedPowerfulMoveEffects\n\ ldrh r0, [r0]\n\ str r0, [sp, 0x10]\n\ _08108276:\n\ @@ -951,7 +1164,7 @@ _08108276:\n\ lsls r0, 2\n\ adds r0, r2\n\ ldrb r2, [r0]\n\ - ldr r1, _08108328 @ =gUnknown_083F62BC\n\ + ldr r1, _08108328 @ =sDiscouragedPowerfulMoveEffects\n\ _081082AA:\n\ ldrh r0, [r1]\n\ cmp r2, r0\n\ @@ -973,7 +1186,7 @@ _081082BA:\n\ cmp r0, 0\n\ beq _0810835C\n\ lsls r0, r3, 1\n\ - ldr r2, _08108328 @ =gUnknown_083F62BC\n\ + ldr r2, _08108328 @ =sDiscouragedPowerfulMoveEffects\n\ adds r0, r2\n\ ldrh r0, [r0]\n\ cmp r0, r9\n\ @@ -1015,7 +1228,7 @@ _081082BA:\n\ str r0, [r4]\n\ b _08108364\n\ .align 2, 0\n\ -_08108328: .4byte gUnknown_083F62BC\n\ +_08108328: .4byte sDiscouragedPowerfulMoveEffects\n\ _0810832C: .4byte 0x0000ffff\n\ _08108330: .4byte gBattleMoves\n\ _08108334: .4byte 0x02016800\n\ @@ -1097,7 +1310,7 @@ _081083D0: .4byte gAIScriptPtr\n\ } #endif // NONMATCHING -void BattleAICmd_get_move(void) +static void BattleAICmd_get_move(void) { if (gAIScriptPtr[1] == USER) gAIThinkingSpace.funcResult = gUnknown_02024C34[gUnknown_02024C07]; @@ -1107,7 +1320,7 @@ void BattleAICmd_get_move(void) gAIScriptPtr += 2; } -void BattleAICmd_if_type(void) +static void BattleAICmd_if_type(void) { if ( gAIScriptPtr[1] == gAIThinkingSpace.funcResult ) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -1115,7 +1328,7 @@ void BattleAICmd_if_type(void) gAIScriptPtr += 6; } -void BattleAICmd_unk_27(void) // if_not_type +static void BattleAICmd_unk_27(void) // if_not_type { if ( gAIScriptPtr[1] != gAIThinkingSpace.funcResult ) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -1123,7 +1336,7 @@ void BattleAICmd_unk_27(void) // if_not_type gAIScriptPtr += 6; } -void BattleAICmd_if_would_go_first(void) +static void BattleAICmd_if_would_go_first(void) { if ( b_first_side(gUnknown_02024C07, gUnknown_02024C08, 1) == gAIScriptPtr[1] ) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -1131,7 +1344,7 @@ void BattleAICmd_if_would_go_first(void) gAIScriptPtr += 6; } -void BattleAICmd_if_would_not_go_first(void) +static void BattleAICmd_if_would_not_go_first(void) { if ( b_first_side(gUnknown_02024C07, gUnknown_02024C08, 1) != gAIScriptPtr[1] ) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -1139,13 +1352,13 @@ void BattleAICmd_if_would_not_go_first(void) gAIScriptPtr += 6; } -void BattleAICmd_unk_2A(void) +static void BattleAICmd_unk_2A(void) {} -void BattleAICmd_unk_2B(void) +static void BattleAICmd_unk_2B(void) {} -void BattleAICmd_count_alive_pokemon(void) +static void BattleAICmd_count_alive_pokemon(void) { u8 index; struct Pokemon *party; @@ -1193,19 +1406,19 @@ void BattleAICmd_count_alive_pokemon(void) gAIScriptPtr += 2; } -void BattleAICmd_unk_2D(void) +static void BattleAICmd_unk_2D(void) { gAIThinkingSpace.funcResult = gAIThinkingSpace.unk2; gAIScriptPtr += 1; } -void BattleAICmd_unk_2E(void) +static void BattleAICmd_unk_2E(void) { gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].effect; gAIScriptPtr += 1; } -void BattleAICmd_get_ability(void) +static void BattleAICmd_get_ability(void) { u8 var; @@ -1274,7 +1487,7 @@ void BattleAICmd_get_ability(void) } } -void BattleAICmd_unk_30(void) +static void BattleAICmd_unk_30(void) { s32 i; struct AI_ThinkingStruct *ai; @@ -1318,7 +1531,7 @@ void BattleAICmd_unk_30(void) gAIScriptPtr += 1; } -void BattleAICmd_if_damage_bonus(void) +static void BattleAICmd_if_damage_bonus(void) { struct AI_ThinkingStruct *ai; u8 damageVar; @@ -1354,13 +1567,13 @@ void BattleAICmd_if_damage_bonus(void) gAIScriptPtr += 6; } -void BattleAICmd_unk_32(void) +static void BattleAICmd_unk_32(void) {} -void BattleAICmd_unk_33(void) +static void BattleAICmd_unk_33(void) {} -void BattleAICmd_if_status_in_party(void) +static void BattleAICmd_if_status_in_party(void) { struct Pokemon *party; int i; @@ -1397,7 +1610,7 @@ void BattleAICmd_if_status_in_party(void) gAIScriptPtr += 10; } -void BattleAICmd_if_status_not_in_party(void) +static void BattleAICmd_if_status_not_in_party(void) { struct Pokemon *party; int i; @@ -1432,7 +1645,7 @@ void BattleAICmd_if_status_not_in_party(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); } -void BattleAICmd_unk_36(void) +static void BattleAICmd_unk_36(void) { if(gBattleWeather & 7) gAIThinkingSpace.funcResult = 1; @@ -1446,7 +1659,7 @@ void BattleAICmd_unk_36(void) gAIScriptPtr += 1; } -void BattleAICmd_if_effect(void) +static void BattleAICmd_if_effect(void) { if(gBattleMoves[gAIThinkingSpace.unk2].effect == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -1454,7 +1667,7 @@ void BattleAICmd_if_effect(void) gAIScriptPtr += 6; } -void BattleAICmd_if_not_effect(void) +static void BattleAICmd_if_not_effect(void) { if(gBattleMoves[gAIThinkingSpace.unk2].effect != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -1462,7 +1675,7 @@ void BattleAICmd_if_not_effect(void) gAIScriptPtr += 6; } -void BattleAICmd_if_stat_level_less_than(void) +static void BattleAICmd_if_stat_level_less_than(void) { u32 party; @@ -1477,7 +1690,7 @@ void BattleAICmd_if_stat_level_less_than(void) gAIScriptPtr += 8; } -void BattleAICmd_if_stat_level_more_than(void) +static void BattleAICmd_if_stat_level_more_than(void) { u32 party; @@ -1492,7 +1705,7 @@ void BattleAICmd_if_stat_level_more_than(void) gAIScriptPtr += 8; } -void BattleAICmd_if_stat_level_equal(void) +static void BattleAICmd_if_stat_level_equal(void) { u32 party; @@ -1507,7 +1720,7 @@ void BattleAICmd_if_stat_level_equal(void) gAIScriptPtr += 8; } -void BattleAICmd_if_stat_level_not_equal(void) +static void BattleAICmd_if_stat_level_not_equal(void) { u32 party; @@ -1522,7 +1735,7 @@ void BattleAICmd_if_stat_level_not_equal(void) gAIScriptPtr += 8; } -void BattleAICmd_if_can_faint(void) +static void BattleAICmd_if_can_faint(void) { if(gBattleMoves[gAIThinkingSpace.unk2].power < 2) { @@ -1550,7 +1763,7 @@ void BattleAICmd_if_can_faint(void) gAIScriptPtr += 5; } -void BattleAICmd_if_cant_faint(void) +static void BattleAICmd_if_cant_faint(void) { if(gBattleMoves[gAIThinkingSpace.unk2].power < 2) { @@ -1577,7 +1790,7 @@ void BattleAICmd_if_cant_faint(void) gAIScriptPtr += 5; } -void BattleAICmd_unk_3F(void) +static void BattleAICmd_unk_3F(void) { int i; u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); @@ -1621,7 +1834,7 @@ void BattleAICmd_unk_3F(void) } } -void BattleAICmd_unk_40(void) +static void BattleAICmd_unk_40(void) { int i; u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); @@ -1665,7 +1878,7 @@ void BattleAICmd_unk_40(void) } } -void BattleAICmd_if_move_effect(void) +static void BattleAICmd_if_move_effect(void) { int i; @@ -1694,7 +1907,7 @@ void BattleAICmd_if_move_effect(void) } } -void BattleAICmd_if_not_move_effect(void) +static void BattleAICmd_if_not_move_effect(void) { int i; @@ -1723,7 +1936,7 @@ void BattleAICmd_if_not_move_effect(void) } } -void BattleAICmd_if_last_move_did_damage(void) +static void BattleAICmd_if_last_move_did_damage(void) { u8 var; @@ -1755,7 +1968,7 @@ void BattleAICmd_if_last_move_did_damage(void) gAIScriptPtr += 7; } -void BattleAICmd_if_encored(void) +static void BattleAICmd_if_encored(void) { switch(gAIScriptPtr[1]) { @@ -1781,12 +1994,12 @@ void BattleAICmd_if_encored(void) } } -void BattleAICmd_unk_45(void) +static void BattleAICmd_unk_45(void) { gAIThinkingSpace.unk10 |= 0xB; } -void BattleAICmd_if_random_2(void) +static void BattleAICmd_if_random_2(void) { u8 var = battle_2000000.unk88 * 5; @@ -1796,12 +2009,12 @@ void BattleAICmd_if_random_2(void) gAIScriptPtr += 5; } -void BattleAICmd_unk_47(void) +static void BattleAICmd_unk_47(void) { gAIThinkingSpace.unk10 |= 0xD; } -void BattleAICmd_get_hold_effect(void) +static void BattleAICmd_get_hold_effect(void) { u8 var; u16 status; @@ -1825,7 +2038,7 @@ void BattleAICmd_get_hold_effect(void) gAIScriptPtr += 2; } -void BattleAICmd_get_gender(void) +static void BattleAICmd_get_gender(void) { u8 var; @@ -1839,7 +2052,7 @@ void BattleAICmd_get_gender(void) gAIScriptPtr += 2; } -void BattleAICmd_is_first_turn(void) +static void BattleAICmd_is_first_turn(void) { u8 var; @@ -1853,7 +2066,7 @@ void BattleAICmd_is_first_turn(void) gAIScriptPtr += 2; } -void BattleAICmd_get_stockpile_count(void) +static void BattleAICmd_get_stockpile_count(void) { u8 var; @@ -1867,14 +2080,14 @@ void BattleAICmd_get_stockpile_count(void) gAIScriptPtr += 2; } -void BattleAICmd_unk_4C(void) +static void BattleAICmd_unk_4C(void) { gAIThinkingSpace.funcResult = gBattleTypeFlags & 1; gAIScriptPtr += 1; } -void BattleAICmd_get_item(void) +static void BattleAICmd_get_item(void) { u8 var; @@ -1889,28 +2102,28 @@ void BattleAICmd_get_item(void) gAIScriptPtr += 2; } -void BattleAICmd_unk_4E(void) +static void BattleAICmd_unk_4E(void) { gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].type; gAIScriptPtr += 1; } -void BattleAICmd_unk_4F(void) +static void BattleAICmd_unk_4F(void) { gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].power; gAIScriptPtr += 1; } -void BattleAICmd_unk_50(void) +static void BattleAICmd_unk_50(void) { gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].effect; gAIScriptPtr += 1; } -void BattleAICmd_get_protect_count(void) +static void BattleAICmd_get_protect_count(void) { u8 var; @@ -1924,36 +2137,36 @@ void BattleAICmd_get_protect_count(void) gAIScriptPtr += 2; } -void BattleAICmd_unk_52(void) {} +static void BattleAICmd_unk_52(void) {} -void BattleAICmd_unk_53(void) {} +static void BattleAICmd_unk_53(void) {} -void BattleAICmd_unk_54(void) {} +static void BattleAICmd_unk_54(void) {} -void BattleAICmd_unk_55(void) {} +static void BattleAICmd_unk_55(void) {} -void BattleAICmd_unk_56(void) {} +static void BattleAICmd_unk_56(void) {} -void BattleAICmd_unk_57(void) {} +static void BattleAICmd_unk_57(void) {} -void BattleAICmd_call(void) +static void BattleAICmd_call(void) { sub_81098C4(gAIScriptPtr + 5); gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } -void BattleAICmd_jump(void) +static void BattleAICmd_jump(void) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } -void BattleAICmd_unk_5A(void) +static void BattleAICmd_unk_5A(void) { if(sub_8109908() == 0) gAIThinkingSpace.unk10 |= 1; } -void BattleAICmd_if_level_cond(void) +static void BattleAICmd_if_level_cond(void) { switch(gAIScriptPtr[1]) { @@ -1984,7 +2197,7 @@ void BattleAICmd_if_level_cond(void) } } -void BattleAICmd_if_taunted(void) +static void BattleAICmd_if_taunted(void) { if(gUnknown_02024CA8[gUnknown_02024C08].taunt) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); @@ -1992,7 +2205,7 @@ void BattleAICmd_if_taunted(void) gAIScriptPtr += 5; } -void BattleAICmd_if_not_taunted(void) +static void BattleAICmd_if_not_taunted(void) { if(!(gUnknown_02024CA8[gUnknown_02024C08].taunt)) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); -- cgit v1.2.3 From c9722602cb47eb5b6ecbccddf13df5f286a8ef7b Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Tue, 17 Jan 2017 14:13:04 +0100 Subject: Sort includes --- src/battle_ai.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/battle_ai.c') diff --git a/src/battle_ai.c b/src/battle_ai.c index ca767a3a3..7b7c80549 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -1,12 +1,12 @@ #include "global.h" -#include "battle.h" +#include "abilities.h" #include "asm.h" +#include "battle.h" +#include "battle_move_effects.h" +#include "item.h" #include "pokemon.h" #include "rng.h" -#include "abilities.h" #include "species.h" -#include "item.h" -#include "battle_move_effects.h" #define AIScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) #define AIScriptRead16(ptr) ((ptr)[0] | (ptr)[1] << 8) -- cgit v1.2.3 From 801877553db80267a62c0c3c0b2805b6716d1ef9 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Tue, 17 Jan 2017 14:38:44 +0100 Subject: Remove trailing whitespace --- src/battle_ai.c | 70 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/battle_ai.c') diff --git a/src/battle_ai.c b/src/battle_ai.c index 7b7c80549..26db24f14 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -1655,7 +1655,7 @@ static void BattleAICmd_unk_36(void) gAIThinkingSpace.funcResult = 0; if(gBattleWeather & 0x80) gAIThinkingSpace.funcResult = 3; - + gAIScriptPtr += 1; } @@ -1683,7 +1683,7 @@ static void BattleAICmd_if_stat_level_less_than(void) party = gUnknown_02024C07; else party = gUnknown_02024C08; - + if(gBattleMons[party].statStages[gAIScriptPtr[2]] < gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); else @@ -1698,7 +1698,7 @@ static void BattleAICmd_if_stat_level_more_than(void) party = gUnknown_02024C07; else party = gUnknown_02024C08; - + if(gBattleMons[party].statStages[gAIScriptPtr[2]] > gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); else @@ -1713,7 +1713,7 @@ static void BattleAICmd_if_stat_level_equal(void) party = gUnknown_02024C07; else party = gUnknown_02024C08; - + if(gBattleMons[party].statStages[gAIScriptPtr[2]] == gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); else @@ -1728,7 +1728,7 @@ static void BattleAICmd_if_stat_level_not_equal(void) party = gUnknown_02024C07; else party = gUnknown_02024C08; - + if(gBattleMons[party].statStages[gAIScriptPtr[2]] != gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); else @@ -1750,13 +1750,13 @@ static void BattleAICmd_if_can_faint(void) gUnknown_02024BE6 = gAIThinkingSpace.unk2; sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); - + gBattleMoveDamage = gBattleMoveDamage * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; - + // moves always do at least 1 damage. if(gBattleMoveDamage == 0) gBattleMoveDamage = 1; - + if(gBattleMons[gUnknown_02024C08].hp <= gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else @@ -1779,7 +1779,7 @@ static void BattleAICmd_if_cant_faint(void) gUnknown_02024BE6 = gAIThinkingSpace.unk2; sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); - + gBattleMoveDamage = gBattleMoveDamage * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; // this macro is missing the damage 0 = 1 assumption. @@ -1794,7 +1794,7 @@ static void BattleAICmd_unk_3F(void) { int i; u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); - + switch(gAIScriptPtr[1]) { case 1: @@ -1838,7 +1838,7 @@ static void BattleAICmd_unk_40(void) { int i; u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); - + switch(gAIScriptPtr[1]) { case 1: @@ -1881,7 +1881,7 @@ static void BattleAICmd_unk_40(void) static void BattleAICmd_if_move_effect(void) { int i; - + switch(gAIScriptPtr[1]) { case 1: @@ -1910,7 +1910,7 @@ static void BattleAICmd_if_move_effect(void) static void BattleAICmd_if_not_move_effect(void) { int i; - + switch(gAIScriptPtr[1]) { case 1: @@ -1939,12 +1939,12 @@ static void BattleAICmd_if_not_move_effect(void) static void BattleAICmd_if_last_move_did_damage(void) { u8 var; - + if(gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; - + if(gAIScriptPtr[2] == 0) { if(gUnknown_02024CA8[var].unk4 == 0) @@ -2002,7 +2002,7 @@ static void BattleAICmd_unk_45(void) static void BattleAICmd_if_random_2(void) { u8 var = battle_2000000.unk88 * 5; - + if((u8)(Random() % 100) < var) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else @@ -2019,12 +2019,12 @@ static void BattleAICmd_get_hold_effect(void) u8 var; u16 status; u8 *aiPtr; - + if(gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; - + if(battle_side_get_owner(var) == 0) { // weird pointer arithmetic is needed to match. @@ -2034,21 +2034,21 @@ static void BattleAICmd_get_hold_effect(void) } else gAIThinkingSpace.funcResult = ItemId_GetHoldEffect(gBattleMons[var].item); - + gAIScriptPtr += 2; } static void BattleAICmd_get_gender(void) { u8 var; - + if(gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; - + gAIThinkingSpace.funcResult = GetGenderFromSpeciesAndPersonality(gBattleMons[var].species, gBattleMons[var].personality); - + gAIScriptPtr += 2; } @@ -2060,9 +2060,9 @@ static void BattleAICmd_is_first_turn(void) var = gUnknown_02024C07; else var = gUnknown_02024C08; - + gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk16; - + gAIScriptPtr += 2; } @@ -2074,66 +2074,66 @@ static void BattleAICmd_get_stockpile_count(void) var = gUnknown_02024C07; else var = gUnknown_02024C08; - + gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk9; - + gAIScriptPtr += 2; } static void BattleAICmd_unk_4C(void) { gAIThinkingSpace.funcResult = gBattleTypeFlags & 1; - + gAIScriptPtr += 1; } static void BattleAICmd_get_item(void) { u8 var; - + if (gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; - + // this hack and a half matches. whatever. i dont care. someone else fix this mess later. ((struct AI_ThinkingStruct *)(unk_2000000 + 0x16800))->funcResult = unk_2000000[0x160CC + var * 2]; - + gAIScriptPtr += 2; } static void BattleAICmd_unk_4E(void) { gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].type; - + gAIScriptPtr += 1; } static void BattleAICmd_unk_4F(void) { gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].power; - + gAIScriptPtr += 1; } static void BattleAICmd_unk_50(void) { gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].effect; - + gAIScriptPtr += 1; } static void BattleAICmd_get_protect_count(void) { u8 var; - + if(gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk8; - + gAIScriptPtr += 2; } -- cgit v1.2.3 From bcaab977727ded65c9eeaef9dbef9e9441d26fb7 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Sat, 21 Jan 2017 16:48:06 -0800 Subject: formatting --- src/battle_ai.c | 694 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 355 insertions(+), 339 deletions(-) (limited to 'src/battle_ai.c') diff --git a/src/battle_ai.c b/src/battle_ai.c index 26db24f14..4509ca8db 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -67,11 +67,11 @@ extern u8 *gAIScriptPtr; struct UnknownStruct1 { -/* 0x00 */ u16 unk0[2][8]; -/* 0x20 */ u8 unk20[2]; -/* 0x22 */ u8 unk22[2]; -/* 0x24 */ u16 items[4]; -/* 0x2C */ u8 unk8; + /*0x00*/ u16 unk0[2][8]; + /*0x20*/ u8 unk20[2]; + /*0x22*/ u8 unk22[2]; + /*0x24*/ u16 items[4]; + /*0x2C*/ u8 unk8; }; struct UnknownStruct3 @@ -352,18 +352,18 @@ void BattleAI_SetupAIData(void) u8 r7; // clear AI data and set default move score to 100. - for(i = 0; (u32)i < 28; i++) + for (i = 0; (u32)i < 28; i++) data[i] = 0; - for(i = 0; i < 4; i++) + for (i = 0; i < 4; i++) gAIThinkingSpace.score[i] = 100; r7 = sub_8015A98(gUnknown_02024A60, 0, 0xFF); - for(i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { u16 rand; - if(gBitTable[i] & r7) + if (gBitTable[i] & r7) gAIThinkingSpace.score[i] = 0; rand = Random(); gAIThinkingSpace.unk18[i] = 100 - (rand & 0xF); @@ -372,22 +372,22 @@ void BattleAI_SetupAIData(void) unk_2016C00.unk20 = 0; gUnknown_02024C07 = gUnknown_02024A60; - if(gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { gUnknown_02024C08 = Random() & 2; - if(gUnknown_02024C0C & gBitTable[gUnknown_02024C08]) + if (gUnknown_02024C0C & gBitTable[gUnknown_02024C08]) gUnknown_02024C08 ^= 2; } else gUnknown_02024C08 = gUnknown_02024A60 ^ 1; // special AI flag cases. - if(gBattleTypeFlags & BATTLE_TYPE_SAFARI) + if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) gAIThinkingSpace.aiFlags = 0x40000000; - else if(gBattleTypeFlags & BATTLE_TYPE_ROAMER) + else if (gBattleTypeFlags & BATTLE_TYPE_ROAMER) gAIThinkingSpace.aiFlags = 0x20000000; - else if(gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) + else if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) gAIThinkingSpace.aiFlags = 0x80000000; else // otherwise, just set aiFlags to whatever flags the trainer has set in their data. gAIThinkingSpace.aiFlags = gTrainers[gTrainerBattleOpponent].aiFlags; @@ -401,9 +401,9 @@ u8 BattleAI_GetAIActionToUse(void) s32 i; sub_810745C(); - while(gAIThinkingSpace.aiFlags != 0) + while (gAIThinkingSpace.aiFlags != 0) { - if(gAIThinkingSpace.aiFlags & 1) + if (gAIThinkingSpace.aiFlags & 1) { gAIThinkingSpace.unk0 = 0; BattleAI_DoAIProcessing(); @@ -414,24 +414,24 @@ u8 BattleAI_GetAIActionToUse(void) } // will KO, need to use item or switch. - if(gAIThinkingSpace.unk10 & 2) + if (gAIThinkingSpace.unk10 & 2) return 4; - if(gAIThinkingSpace.unk10 & 4) + if (gAIThinkingSpace.unk10 & 4) return 5; r5 = 1; arr1[0] = gAIThinkingSpace.score[0]; arr2[0] = 0; - for(i = 1; i < 4; i++) + for (i = 1; i < 4; i++) { - if(arr1[0] < (s8)gAIThinkingSpace.score[i]) + if (arr1[0] < (s8)gAIThinkingSpace.score[i]) { r5 = 1; arr1[0] = gAIThinkingSpace.score[i]; arr2[0] = i; } - if(arr1[0] == (s8)gAIThinkingSpace.score[i]) + if (arr1[0] == (s8)gAIThinkingSpace.score[i]) { arr1[r5] = gAIThinkingSpace.score[i]; arr2[r5++] = i; @@ -443,15 +443,15 @@ u8 BattleAI_GetAIActionToUse(void) void BattleAI_DoAIProcessing(void) { - while(gAIThinkingSpace.unk0 != 2) + while (gAIThinkingSpace.unk0 != 2) { - switch(gAIThinkingSpace.unk0) + switch (gAIThinkingSpace.unk0) { case 3: //Needed to match. break; case 0: gAIScriptPtr = BattleAIs[gAIThinkingSpace.aiLogicId]; - if(gBattleMons[gUnknown_02024C07].pp[gAIThinkingSpace.moveConsidered] == 0) + if (gBattleMons[gUnknown_02024C07].pp[gAIThinkingSpace.moveConsidered] == 0) { gAIThinkingSpace.unk2 = 0; } @@ -462,17 +462,17 @@ void BattleAI_DoAIProcessing(void) gAIThinkingSpace.unk0++; break; case 1: - if(gAIThinkingSpace.unk2 != 0) + if (gAIThinkingSpace.unk2 != 0) sBattleAICmdTable[*(u8 *)gAIScriptPtr](); // run AI command. else { gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] = 0; gAIThinkingSpace.unk10 |= 1; } - if(gAIThinkingSpace.unk10 & 1) + if (gAIThinkingSpace.unk10 & 1) { gAIThinkingSpace.moveConsidered++; - if(gAIThinkingSpace.moveConsidered < 4 && !(gAIThinkingSpace.unk10 & 8)) + if (gAIThinkingSpace.moveConsidered < 4 && !(gAIThinkingSpace.unk10 & 8)) gAIThinkingSpace.unk0 = 0; else gAIThinkingSpace.unk0++; @@ -487,10 +487,10 @@ void sub_810745C(void) { s32 i; - for(i = 0; i < 8; i++) + for (i = 0; i < 8; i++) { // this is the same as dividing it by 2, but for some reason, >> 1 is needed to match the asm. - if(unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == 0) + if (unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == 0) { unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] = gUnknown_02024C34[gUnknown_02024C08]; return; @@ -502,19 +502,19 @@ void unref_sub_81074A0(u8 a) { s32 i; - for(i = 0; i < 8; i++) + for (i = 0; i < 8; i++) unk_2016A00.unk0[a / 2][i] = 0; } void sub_81074C4(u8 a, u8 b) { - if(battle_side_get_owner(a) == 0) + if (battle_side_get_owner(a) == 0) unk_2016A00.unk20[battle_get_per_side_status(a) & 1] = b; } void sub_81074F8(u8 a, u8 b) { - if(battle_side_get_owner(a) == 0) + if (battle_side_get_owner(a) == 0) unk_2016A00.unk22[battle_get_per_side_status(a) & 1] = b; } @@ -562,7 +562,7 @@ static void BattleAICmd_score(void) { gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] += gAIScriptPtr[1]; // add the result to the array of the move consider's score. - if(gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] < 0) // if the score is negative, flatten it to 0. + if (gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] < 0) // if the score is negative, flatten it to 0. gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] = 0; gAIScriptPtr += 2; // AI return. @@ -712,7 +712,7 @@ static void BattleAICmd_if_status3(void) temp = AIScriptRead32(gAIScriptPtr + 2); - if ( gUnknown_02024C98[var] & temp ) + if (gUnknown_02024C98[var] & temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -750,7 +750,7 @@ static void BattleAICmd_if_status4(void) temp = battle_get_per_side_status(var) & 1; temp2 = AIScriptRead32(gAIScriptPtr + 2); - if ( gUnknown_02024C7A[temp] & temp2 ) + if (gUnknown_02024C7A[temp] & temp2) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -872,96 +872,96 @@ static void BattleAICmd_if_in_bytes(void) { u8 *ptr = AIScriptReadPtr(gAIScriptPtr + 1); - while(*ptr != 0xFF) - { - if(gAIThinkingSpace.funcResult == *ptr) - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); - return; - } - ptr++; - } - gAIScriptPtr += 9; + while (*ptr != 0xFF) + { + if (gAIThinkingSpace.funcResult == *ptr) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); + return; + } + ptr++; + } + gAIScriptPtr += 9; } static void BattleAICmd_if_not_in_bytes(void) { u8 *ptr = AIScriptReadPtr(gAIScriptPtr + 1); - while(*ptr != 0xFF) - { - if(gAIThinkingSpace.funcResult == *ptr) - { - gAIScriptPtr += 9; - return; - } - ptr++; - } - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); + while (*ptr != 0xFF) + { + if (gAIThinkingSpace.funcResult == *ptr) + { + gAIScriptPtr += 9; + return; + } + ptr++; + } + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); } static void BattleAICmd_if_in_words(void) { u16 *ptr = (u16 *)AIScriptReadPtr(gAIScriptPtr + 1); - while(*ptr != 0xFFFF) - { - if(gAIThinkingSpace.funcResult == *ptr) - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); - return; - } - ptr++; - } - gAIScriptPtr += 9; + while (*ptr != 0xFFFF) + { + if (gAIThinkingSpace.funcResult == *ptr) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); + return; + } + ptr++; + } + gAIScriptPtr += 9; } static void BattleAICmd_if_not_in_words(void) { u16 *ptr = (u16 *)AIScriptReadPtr(gAIScriptPtr + 1); - while(*ptr != 0xFFFF) - { - if(gAIThinkingSpace.funcResult == *ptr) - { - gAIScriptPtr += 9; - return; - } - ptr++; - } - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); + while (*ptr != 0xFFFF) + { + if (gAIThinkingSpace.funcResult == *ptr) + { + gAIScriptPtr += 9; + return; + } + ptr++; + } + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); } static void BattleAICmd_if_user_can_damage(void) { - s32 i; + s32 i; - for(i = 0; i < 4; i++) - { - if (gBattleMons[gUnknown_02024C07].moves[i] != 0 - && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power != 0) - break; - } - if(i == 4) - gAIScriptPtr += 5; - else - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); + for (i = 0; i < 4; i++) + { + if (gBattleMons[gUnknown_02024C07].moves[i] != 0 + && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power != 0) + break; + } + if (i == 4) + gAIScriptPtr += 5; + else + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } static void BattleAICmd_if_user_cant_damage(void) { - s32 i; + s32 i; - for(i = 0; i < 4; i++) - { - if (gBattleMons[gUnknown_02024C07].moves[i] != 0 - && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power != 0) - break; - } - if(i != 4) - gAIScriptPtr += 5; - else - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); + for (i = 0; i < 4; i++) + { + if (gBattleMons[gUnknown_02024C07].moves[i] != 0 + && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power != 0) + break; + } + if (i != 4) + gAIScriptPtr += 5; + else + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } static void BattleAICmd_unk_21(void) @@ -974,23 +974,23 @@ static void BattleAICmd_get_type(void) { u8 typeVar = gAIScriptPtr[1]; - switch(typeVar) + switch (typeVar) { - case 1: - gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C07].type1; - break; - case 0: - gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C08].type1; - break; - case 3: - gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C07].type2; - break; - case 2: - gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C08].type2; - break; - case 4: - gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].type; - break; + case 1: + gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C07].type1; + break; + case 0: + gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C08].type1; + break; + case 3: + gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C07].type2; + break; + case 2: + gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C08].type2; + break; + case 4: + gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].type; + break; } gAIScriptPtr += 2; } @@ -1322,7 +1322,7 @@ static void BattleAICmd_get_move(void) static void BattleAICmd_if_type(void) { - if ( gAIScriptPtr[1] == gAIThinkingSpace.funcResult ) + if (gAIScriptPtr[1] == gAIThinkingSpace.funcResult) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1330,7 +1330,7 @@ static void BattleAICmd_if_type(void) static void BattleAICmd_unk_27(void) // if_not_type { - if ( gAIScriptPtr[1] != gAIThinkingSpace.funcResult ) + if (gAIScriptPtr[1] != gAIThinkingSpace.funcResult) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1338,7 +1338,7 @@ static void BattleAICmd_unk_27(void) // if_not_type static void BattleAICmd_if_would_go_first(void) { - if ( b_first_side(gUnknown_02024C07, gUnknown_02024C08, 1) == gAIScriptPtr[1] ) + if (b_first_side(gUnknown_02024C07, gUnknown_02024C08, 1) == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1346,17 +1346,19 @@ static void BattleAICmd_if_would_go_first(void) static void BattleAICmd_if_would_not_go_first(void) { - if ( b_first_side(gUnknown_02024C07, gUnknown_02024C08, 1) != gAIScriptPtr[1] ) + if (b_first_side(gUnknown_02024C07, gUnknown_02024C08, 1) != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } static void BattleAICmd_unk_2A(void) -{} +{ +} static void BattleAICmd_unk_2B(void) -{} +{ +} static void BattleAICmd_count_alive_pokemon(void) { @@ -1422,16 +1424,16 @@ static void BattleAICmd_get_ability(void) { u8 var; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; - if(battle_side_get_owner(var) == TARGET) + if (battle_side_get_owner(var) == TARGET) { u16 unk = battle_get_per_side_status(var) & 1; - if(unk_2016A00.unk20[unk] != 0) + if (unk_2016A00.unk20[unk] != 0) { ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = unk_2016A00.unk20[unk]; gAIScriptPtr += 2; @@ -1439,19 +1441,19 @@ static void BattleAICmd_get_ability(void) } // abilities that prevent fleeing. - if(gBattleMons[var].ability == ABILITY_SHADOW_TAG || gBattleMons[var].ability == ABILITY_MAGNET_PULL || gBattleMons[var].ability == ABILITY_ARENA_TRAP) + if (gBattleMons[var].ability == ABILITY_SHADOW_TAG || gBattleMons[var].ability == ABILITY_MAGNET_PULL || gBattleMons[var].ability == ABILITY_ARENA_TRAP) { gAIThinkingSpace.funcResult = gBattleMons[var].ability; gAIScriptPtr += 2; return; } - if(gBaseStats[gBattleMons[var].species].ability1 != ABILITY_NONE) + if (gBaseStats[gBattleMons[var].species].ability1 != ABILITY_NONE) { - if(gBaseStats[gBattleMons[var].species].ability2 != ABILITY_NONE) + if (gBaseStats[gBattleMons[var].species].ability2 != ABILITY_NONE) { // AI is guessing what ability? - if(Random() & 1) + if (Random() & 1) { ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability1; gAIScriptPtr += 2; @@ -1501,7 +1503,7 @@ static void BattleAICmd_unk_30(void) ai = &battle_2000000.ai; ai->funcResult = 0; - for(i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { gBattleMoveDamage = 40; gUnknown_02024BE6 = gBattleMons[gUnknown_02024C07].moves[i]; @@ -1513,14 +1515,14 @@ static void BattleAICmd_unk_30(void) // reduce by 1/3. if (gBattleMoveDamage == 120) gBattleMoveDamage = 80; - if(gBattleMoveDamage == 240) + if (gBattleMoveDamage == 240) gBattleMoveDamage = 160; - if(gBattleMoveDamage == 30) + if (gBattleMoveDamage == 30) gBattleMoveDamage = 20; - if(gBattleMoveDamage == 15) + if (gBattleMoveDamage == 15) gBattleMoveDamage = 10; - if(gBattleMoveFlags & 8) + if (gBattleMoveFlags & 8) gBattleMoveDamage = 0; ai2 = &battle_2000000.ai; @@ -1549,29 +1551,31 @@ static void BattleAICmd_if_damage_bonus(void) if (gBattleMoveDamage == 120) gBattleMoveDamage = 80; - if(gBattleMoveDamage == 240) + if (gBattleMoveDamage == 240) gBattleMoveDamage = 160; - if(gBattleMoveDamage == 30) + if (gBattleMoveDamage == 30) gBattleMoveDamage = 20; - if(gBattleMoveDamage == 15) + if (gBattleMoveDamage == 15) gBattleMoveDamage = 10; - if(gBattleMoveFlags & 8) + if (gBattleMoveFlags & 8) gBattleMoveDamage = 0; // i have to store 2024BEC in a local variable before the comparison or else it will not match. damageVar = gBattleMoveDamage; - if(damageVar == gAIScriptPtr[1]) + if (damageVar == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } static void BattleAICmd_unk_32(void) -{} +{ +} static void BattleAICmd_unk_33(void) -{} +{ +} static void BattleAICmd_if_status_in_party(void) { @@ -1585,7 +1589,7 @@ static void BattleAICmd_if_status_in_party(void) } else if (0) { - // what is going on here? + // what is going on here? follow_jump: gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); return; @@ -1618,16 +1622,16 @@ static void BattleAICmd_if_status_not_in_party(void) u8 *partyPtr; // what weird code. needed to match - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { - case 1: - partyPtr = (u8 *)gEnemyParty; - party = (struct Pokemon *)partyPtr; - break; - default: - partyPtr = (u8 *)gPlayerParty; - party = (struct Pokemon *)partyPtr; - break; + case 1: + partyPtr = (u8 *)gEnemyParty; + party = (struct Pokemon *)partyPtr; + break; + default: + partyPtr = (u8 *)gPlayerParty; + party = (struct Pokemon *)partyPtr; + break; } statusToCompareTo = AIScriptRead32(gAIScriptPtr + 2); @@ -1647,13 +1651,13 @@ static void BattleAICmd_if_status_not_in_party(void) static void BattleAICmd_unk_36(void) { - if(gBattleWeather & 7) + if (gBattleWeather & 7) gAIThinkingSpace.funcResult = 1; - if(gBattleWeather & 0x18) + if (gBattleWeather & 0x18) gAIThinkingSpace.funcResult = 2; - if(gBattleWeather & 0x60) + if (gBattleWeather & 0x60) gAIThinkingSpace.funcResult = 0; - if(gBattleWeather & 0x80) + if (gBattleWeather & 0x80) gAIThinkingSpace.funcResult = 3; gAIScriptPtr += 1; @@ -1661,7 +1665,7 @@ static void BattleAICmd_unk_36(void) static void BattleAICmd_if_effect(void) { - if(gBattleMoves[gAIThinkingSpace.unk2].effect == gAIScriptPtr[1]) + if (gBattleMoves[gAIThinkingSpace.unk2].effect == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1669,7 +1673,7 @@ static void BattleAICmd_if_effect(void) static void BattleAICmd_if_not_effect(void) { - if(gBattleMoves[gAIThinkingSpace.unk2].effect != gAIScriptPtr[1]) + if (gBattleMoves[gAIThinkingSpace.unk2].effect != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1679,12 +1683,12 @@ static void BattleAICmd_if_stat_level_less_than(void) { u32 party; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) party = gUnknown_02024C07; else party = gUnknown_02024C08; - if(gBattleMons[party].statStages[gAIScriptPtr[2]] < gAIScriptPtr[3]) + if (gBattleMons[party].statStages[gAIScriptPtr[2]] < gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); else gAIScriptPtr += 8; @@ -1694,12 +1698,12 @@ static void BattleAICmd_if_stat_level_more_than(void) { u32 party; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) party = gUnknown_02024C07; else party = gUnknown_02024C08; - if(gBattleMons[party].statStages[gAIScriptPtr[2]] > gAIScriptPtr[3]) + if (gBattleMons[party].statStages[gAIScriptPtr[2]] > gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); else gAIScriptPtr += 8; @@ -1709,12 +1713,12 @@ static void BattleAICmd_if_stat_level_equal(void) { u32 party; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) party = gUnknown_02024C07; else party = gUnknown_02024C08; - if(gBattleMons[party].statStages[gAIScriptPtr[2]] == gAIScriptPtr[3]) + if (gBattleMons[party].statStages[gAIScriptPtr[2]] == gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); else gAIScriptPtr += 8; @@ -1724,12 +1728,12 @@ static void BattleAICmd_if_stat_level_not_equal(void) { u32 party; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) party = gUnknown_02024C07; else party = gUnknown_02024C08; - if(gBattleMons[party].statStages[gAIScriptPtr[2]] != gAIScriptPtr[3]) + if (gBattleMons[party].statStages[gAIScriptPtr[2]] != gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); else gAIScriptPtr += 8; @@ -1737,7 +1741,7 @@ static void BattleAICmd_if_stat_level_not_equal(void) static void BattleAICmd_if_can_faint(void) { - if(gBattleMoves[gAIThinkingSpace.unk2].power < 2) + if (gBattleMoves[gAIThinkingSpace.unk2].power < 2) { gAIScriptPtr += 5; return; @@ -1754,10 +1758,10 @@ static void BattleAICmd_if_can_faint(void) gBattleMoveDamage = gBattleMoveDamage * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; // moves always do at least 1 damage. - if(gBattleMoveDamage == 0) + if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; - if(gBattleMons[gUnknown_02024C08].hp <= gBattleMoveDamage) + if (gBattleMons[gUnknown_02024C08].hp <= gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -1765,7 +1769,7 @@ static void BattleAICmd_if_can_faint(void) static void BattleAICmd_if_cant_faint(void) { - if(gBattleMoves[gAIThinkingSpace.unk2].power < 2) + if (gBattleMoves[gAIThinkingSpace.unk2].power < 2) { gAIScriptPtr += 5; return; @@ -1784,7 +1788,7 @@ static void BattleAICmd_if_cant_faint(void) // this macro is missing the damage 0 = 1 assumption. - if(gBattleMons[gUnknown_02024C08].hp > gBattleMoveDamage) + if (gBattleMons[gUnknown_02024C08].hp > gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -1795,42 +1799,42 @@ static void BattleAICmd_unk_3F(void) int i; u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { - case 1: - case 3: - for(i = 0; i < 4; i++) - { - if(gBattleMons[gUnknown_02024C07].moves[i] == *temp_ptr) - break; - } - if(i == 4) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); - return; - } - case 0: - case 2: - for(i = 0; i < 8; i++) - { - if(unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == *temp_ptr) - break; - } - if(i == 8) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); - return; - } + case 1: + case 3: + for (i = 0; i < 4; i++) + { + if (gBattleMons[gUnknown_02024C07].moves[i] == *temp_ptr) + break; + } + if (i == 4) + { + gAIScriptPtr += 8; + return; + } + else + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + return; + } + case 0: + case 2: + for (i = 0; i < 8; i++) + { + if (unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == *temp_ptr) + break; + } + if (i == 8) + { + gAIScriptPtr += 8; + return; + } + else + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + return; + } } } @@ -1839,42 +1843,42 @@ static void BattleAICmd_unk_40(void) int i; u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { - case 1: - case 3: - for(i = 0; i < 4; i++) - { - if(gBattleMons[gUnknown_02024C07].moves[i] == *temp_ptr) - break; - } - if(i != 4) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); - return; - } - case 0: - case 2: - for(i = 0; i < 8; i++) - { - if(unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == *temp_ptr) - break; - } - if(i != 8) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); - return; - } + case 1: + case 3: + for (i = 0; i < 4; i++) + { + if (gBattleMons[gUnknown_02024C07].moves[i] == *temp_ptr) + break; + } + if (i != 4) + { + gAIScriptPtr += 8; + return; + } + else + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + return; + } + case 0: + case 2: + for (i = 0; i < 8; i++) + { + if (unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == *temp_ptr) + break; + } + if (i != 8) + { + gAIScriptPtr += 8; + return; + } + else + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); + return; + } } } @@ -1882,28 +1886,28 @@ static void BattleAICmd_if_move_effect(void) { int i; - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { - case 1: - case 3: - for(i = 0; i < 4; i++) - { - if(gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gAIScriptPtr[2]) - break; - } - if(i != 4) - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); - else - gAIScriptPtr += 7; - break; - case 0: - case 2: - for(i = 0; i < 8; i++) - { - if(gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[unk_2016A00.unk0[gUnknown_02024C08 >> 1][i]].effect == gAIScriptPtr[2]) - break; - } + case 1: + case 3: + for (i = 0; i < 4; i++) + { + if (gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gAIScriptPtr[2]) + break; + } + if (i != 4) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); + else + gAIScriptPtr += 7; + break; + case 0: + case 2: + for (i = 0; i < 8; i++) + { + if (gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[unk_2016A00.unk0[gUnknown_02024C08 >> 1][i]].effect == gAIScriptPtr[2]) + break; + } + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); } } @@ -1911,28 +1915,28 @@ static void BattleAICmd_if_not_move_effect(void) { int i; - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { - case 1: - case 3: - for(i = 0; i < 4; i++) - { - if(gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gAIScriptPtr[2]) - break; - } - if(i != 4) - gAIScriptPtr += 7; - else - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); - break; - case 0: - case 2: - for(i = 0; i < 8; i++) - { - if(unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] != 0 && gBattleMoves[unk_2016A00.unk0[gUnknown_02024C08 >> 1][i]].effect == gAIScriptPtr[2]) - break; - } + case 1: + case 3: + for (i = 0; i < 4; i++) + { + if (gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gAIScriptPtr[2]) + break; + } + if (i != 4) gAIScriptPtr += 7; + else + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); + break; + case 0: + case 2: + for (i = 0; i < 8; i++) + { + if (unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] != 0 && gBattleMoves[unk_2016A00.unk0[gUnknown_02024C08 >> 1][i]].effect == gAIScriptPtr[2]) + break; + } + gAIScriptPtr += 7; } } @@ -1940,14 +1944,14 @@ static void BattleAICmd_if_last_move_did_damage(void) { u8 var; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; - if(gAIScriptPtr[2] == 0) + if (gAIScriptPtr[2] == 0) { - if(gUnknown_02024CA8[var].unk4 == 0) + if (gUnknown_02024CA8[var].unk4 == 0) { gAIScriptPtr += 7; return; @@ -1955,12 +1959,12 @@ static void BattleAICmd_if_last_move_did_damage(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); return; } - else if(gAIScriptPtr[2] != 1) + else if (gAIScriptPtr[2] != 1) { gAIScriptPtr += 7; return; } - else if(gUnknown_02024CA8[var].unk6 != 0) + else if (gUnknown_02024CA8[var].unk6 != 0) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); return; @@ -1970,27 +1974,27 @@ static void BattleAICmd_if_last_move_did_damage(void) static void BattleAICmd_if_encored(void) { - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { - case 0: // _08109348 - if(gUnknown_02024CA8[gUnknown_02024A60].unk4 == gAIThinkingSpace.unk2) - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; - return; - case 1: // _08109370 - if(gUnknown_02024CA8[gUnknown_02024A60].unk6 == gAIThinkingSpace.unk2) - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; + case 0: // _08109348 + if (gUnknown_02024CA8[gUnknown_02024A60].unk4 == gAIThinkingSpace.unk2) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; - default: - gAIScriptPtr += 6; + } + gAIScriptPtr += 6; + return; + case 1: // _08109370 + if (gUnknown_02024CA8[gUnknown_02024A60].unk6 == gAIThinkingSpace.unk2) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; + } + gAIScriptPtr += 6; + return; + default: + gAIScriptPtr += 6; + return; } } @@ -2003,7 +2007,7 @@ static void BattleAICmd_if_random_2(void) { u8 var = battle_2000000.unk88 * 5; - if((u8)(Random() % 100) < var) + if ((u8)(Random() % 100) < var) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -2020,12 +2024,12 @@ static void BattleAICmd_get_hold_effect(void) u16 status; u8 *aiPtr; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; - if(battle_side_get_owner(var) == 0) + if (battle_side_get_owner(var) == 0) { // weird pointer arithmetic is needed to match. status = (battle_get_per_side_status(var) & 1); @@ -2042,7 +2046,7 @@ static void BattleAICmd_get_gender(void) { u8 var; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; @@ -2056,7 +2060,7 @@ static void BattleAICmd_is_first_turn(void) { u8 var; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; @@ -2070,7 +2074,7 @@ static void BattleAICmd_get_stockpile_count(void) { u8 var; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; @@ -2127,7 +2131,7 @@ static void BattleAICmd_get_protect_count(void) { u8 var; - if(gAIScriptPtr[1] == USER) + if (gAIScriptPtr[1] == USER) var = gUnknown_02024C07; else var = gUnknown_02024C08; @@ -2137,17 +2141,29 @@ static void BattleAICmd_get_protect_count(void) gAIScriptPtr += 2; } -static void BattleAICmd_unk_52(void) {} +static void BattleAICmd_unk_52(void) +{ +} -static void BattleAICmd_unk_53(void) {} +static void BattleAICmd_unk_53(void) +{ +} -static void BattleAICmd_unk_54(void) {} +static void BattleAICmd_unk_54(void) +{ +} -static void BattleAICmd_unk_55(void) {} +static void BattleAICmd_unk_55(void) +{ +} -static void BattleAICmd_unk_56(void) {} +static void BattleAICmd_unk_56(void) +{ +} -static void BattleAICmd_unk_57(void) {} +static void BattleAICmd_unk_57(void) +{ +} static void BattleAICmd_call(void) { @@ -2162,44 +2178,44 @@ static void BattleAICmd_jump(void) static void BattleAICmd_unk_5A(void) { - if(sub_8109908() == 0) + if (sub_8109908() == 0) gAIThinkingSpace.unk10 |= 1; } static void BattleAICmd_if_level_cond(void) { - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { - case 0: - if(gBattleMons[gUnknown_02024C07].level > gBattleMons[gUnknown_02024C08].level) - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; + case 0: + if (gBattleMons[gUnknown_02024C07].level > gBattleMons[gUnknown_02024C08].level) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; - case 1: - if(gBattleMons[gUnknown_02024C07].level < gBattleMons[gUnknown_02024C08].level) - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; + } + gAIScriptPtr += 6; + return; + case 1: + if (gBattleMons[gUnknown_02024C07].level < gBattleMons[gUnknown_02024C08].level) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; - case 2: - if(gBattleMons[gUnknown_02024C07].level == gBattleMons[gUnknown_02024C08].level) - { - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; + } + gAIScriptPtr += 6; + return; + case 2: + if (gBattleMons[gUnknown_02024C07].level == gBattleMons[gUnknown_02024C08].level) + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; + } + gAIScriptPtr += 6; + return; } } static void BattleAICmd_if_taunted(void) { - if(gUnknown_02024CA8[gUnknown_02024C08].taunt) + if (gUnknown_02024CA8[gUnknown_02024C08].taunt) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -2207,7 +2223,7 @@ static void BattleAICmd_if_taunted(void) static void BattleAICmd_if_not_taunted(void) { - if(!(gUnknown_02024CA8[gUnknown_02024C08].taunt)) + if (!(gUnknown_02024CA8[gUnknown_02024C08].taunt)) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -2225,7 +2241,7 @@ void unref_sub_81098E4(void) bool8 sub_8109908(void) { - if(unk_2016C00.unk20 != 0) + if (unk_2016C00.unk20 != 0) { --unk_2016C00.unk20; gAIScriptPtr = unk_2016C00.ptr[unk_2016C00.unk20]; -- cgit v1.2.3 From c22eb152ced1fe3bc8f9f0342a47d429bfa4c5a0 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Thu, 2 Feb 2017 00:50:47 -0500 Subject: label, document, reorganize, and clean up battle_ai.c (#228) label, document, reorganize, and clean up battle_ai.c --- src/battle_ai.c | 922 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 455 insertions(+), 467 deletions(-) (limited to 'src/battle_ai.c') diff --git a/src/battle_ai.c b/src/battle_ai.c index 4509ca8db..6058068f0 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -7,14 +7,18 @@ #include "pokemon.h" #include "rng.h" #include "species.h" +#include "moves.h" #define AIScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) #define AIScriptRead16(ptr) ((ptr)[0] | (ptr)[1] << 8) #define AIScriptRead8(ptr) ((ptr)[0]) #define AIScriptReadPtr(ptr) (u8*) AIScriptRead32(ptr) -#define AI_THINKING_STRUCT ((struct AI_ThinkingStruct *)((u8 *)&battle_2000000 + 0x16800)) -#define AI_ARRAY_160CC ((&battle_2000000 + 0x160CC)) +// 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); @@ -25,6 +29,15 @@ enum USER }; +// AI states +enum +{ + AIState_SettingUp, + AIState_Processing, + AIState_FinishedProcessing, + AIState_DoNotProcess +}; + extern void move_effectiveness_something(u16, u8, u8); extern u16 gBattleTypeFlags; @@ -33,8 +46,8 @@ extern u8 gUnknown_02024A60; extern u8 gUnknown_02024A6A[][2]; extern u16 gUnknown_02024BE6; extern int gBattleMoveDamage; -extern u8 gUnknown_02024C07; // something player? -extern u8 gUnknown_02024C08; // something opponent? +extern u8 gPlayerMonIndex; +extern u8 gEnemyMonIndex; extern u8 gUnknown_02024C0C; extern u8 gBattleMoveFlags; extern u16 gUnknown_02024DEC; @@ -65,19 +78,9 @@ AI scripts. */ extern u8 *gAIScriptPtr; -struct UnknownStruct1 -{ - /*0x00*/ u16 unk0[2][8]; - /*0x20*/ u8 unk20[2]; - /*0x22*/ u8 unk22[2]; - /*0x24*/ u16 items[4]; - /*0x2C*/ u8 unk8; -}; - struct UnknownStruct3 { - u8 *ptr[4]; // might be 8 pointers - u8 filler0[0x10]; + u8 *ptr[8]; u8 unk20; }; @@ -96,14 +99,13 @@ struct UnknownStruct4 u8 filler17[0x4]; }; -extern struct UnknownStruct1 unk_2016A00; extern struct UnknownStruct3 unk_2016C00; extern struct UnknownStruct4 gUnknown_02024CA8[]; -static void BattleAICmd_if_random(void); -static void BattleAICmd_if_not_random(void); -static void BattleAICmd_if_random_1(void); -static void BattleAICmd_if_not_random_1(void); +static void BattleAICmd_if_random_less_than(void); +static void BattleAICmd_if_random_greater_than(void); +static void BattleAICmd_if_random_equal(void); +static void BattleAICmd_if_random_not_equal(void); static void BattleAICmd_score(void); static void BattleAICmd_if_hp_less_than(void); static void BattleAICmd_if_hp_more_than(void); @@ -133,28 +135,28 @@ static void BattleAICmd_if_in_words(void); static void BattleAICmd_if_not_in_words(void); static void BattleAICmd_if_user_can_damage(void); static void BattleAICmd_if_user_cant_damage(void); -static void BattleAICmd_unk_21(void); +static void BattleAICmd_get_turn_count(void); static void BattleAICmd_get_type(void); -static void BattleAICmd_unk_23(void); -static void BattleAICmd_unk_24(void); +static void BattleAICmd_get_move_power(void); +static void BattleAICmd_is_most_powerful_move(void); static void BattleAICmd_get_move(void); -static void BattleAICmd_if_type(void); -static void BattleAICmd_unk_27(void); +static void BattleAICmd_if_arg_equal(void); +static void BattleAICmd_if_arg_not_equal(void); static void BattleAICmd_if_would_go_first(void); static void BattleAICmd_if_would_not_go_first(void); -static void BattleAICmd_unk_2A(void); -static void BattleAICmd_unk_2B(void); +static void BattleAICmd_nullsub_2A(void); +static void BattleAICmd_nullsub_2B(void); static void BattleAICmd_count_alive_pokemon(void); -static void BattleAICmd_unk_2D(void); -static void BattleAICmd_unk_2E(void); +static void BattleAICmd_get_considered_move(void); +static void BattleAICmd_get_considered_move_effect(void); static void BattleAICmd_get_ability(void); -static void BattleAICmd_unk_30(void); +static void BattleAICmd_get_highest_possible_damage(void); static void BattleAICmd_if_damage_bonus(void); -static void BattleAICmd_unk_32(void); -static void BattleAICmd_unk_33(void); +static void BattleAICmd_nullsub_32(void); +static void BattleAICmd_nullsub_33(void); static void BattleAICmd_if_status_in_party(void); static void BattleAICmd_if_status_not_in_party(void); -static void BattleAICmd_unk_36(void); +static void BattleAICmd_get_weather(void); static void BattleAICmd_if_effect(void); static void BattleAICmd_if_not_effect(void); static void BattleAICmd_if_stat_level_less_than(void); @@ -163,34 +165,34 @@ static void BattleAICmd_if_stat_level_equal(void); static void BattleAICmd_if_stat_level_not_equal(void); static void BattleAICmd_if_can_faint(void); static void BattleAICmd_if_cant_faint(void); -static void BattleAICmd_unk_3F(void); -static void BattleAICmd_unk_40(void); +static void BattleAICmd_if_has_move(void); +static void BattleAICmd_if_dont_have_move(void); static void BattleAICmd_if_move_effect(void); static void BattleAICmd_if_not_move_effect(void); static void BattleAICmd_if_last_move_did_damage(void); static void BattleAICmd_if_encored(void); -static void BattleAICmd_unk_45(void); -static void BattleAICmd_if_random_2(void); -static void BattleAICmd_unk_47(void); +static void BattleAICmd_flee(void); +static void BattleAICmd_if_random_100(void); +static void BattleAICmd_watch(void); static void BattleAICmd_get_hold_effect(void); static void BattleAICmd_get_gender(void); static void BattleAICmd_is_first_turn(void); static void BattleAICmd_get_stockpile_count(void); -static void BattleAICmd_unk_4C(void); +static void BattleAICmd_is_double_battle(void); static void BattleAICmd_get_item(void); -static void BattleAICmd_unk_4E(void); -static void BattleAICmd_unk_4F(void); -static void BattleAICmd_unk_50(void); +static void BattleAICmd_get_move_type_from_result(void); +static void BattleAICmd_get_move_power_from_result(void); +static void BattleAICmd_get_move_effect_from_result(void); static void BattleAICmd_get_protect_count(void); -static void BattleAICmd_unk_52(void); -static void BattleAICmd_unk_53(void); -static void BattleAICmd_unk_54(void); -static void BattleAICmd_unk_55(void); -static void BattleAICmd_unk_56(void); -static void BattleAICmd_unk_57(void); +static void BattleAICmd_nullsub_52(void); +static void BattleAICmd_nullsub_53(void); +static void BattleAICmd_nullsub_54(void); +static void BattleAICmd_nullsub_55(void); +static void BattleAICmd_nullsub_56(void); +static void BattleAICmd_nullsub_57(void); static void BattleAICmd_call(void); static void BattleAICmd_jump(void); -static void BattleAICmd_unk_5A(void); +static void BattleAICmd_end(void); static void BattleAICmd_if_level_cond(void); static void BattleAICmd_if_taunted(void); static void BattleAICmd_if_not_taunted(void); @@ -199,10 +201,10 @@ typedef void (*BattleAICmdFunc)(void); static const BattleAICmdFunc sBattleAICmdTable[] = { - BattleAICmd_if_random, - BattleAICmd_if_not_random, - BattleAICmd_if_random_1, - BattleAICmd_if_not_random_1, + BattleAICmd_if_random_less_than, + BattleAICmd_if_random_greater_than, + BattleAICmd_if_random_equal, + BattleAICmd_if_random_not_equal, BattleAICmd_score, BattleAICmd_if_hp_less_than, BattleAICmd_if_hp_more_than, @@ -232,28 +234,28 @@ static const BattleAICmdFunc sBattleAICmdTable[] = BattleAICmd_if_not_in_words, BattleAICmd_if_user_can_damage, BattleAICmd_if_user_cant_damage, - BattleAICmd_unk_21, + BattleAICmd_get_turn_count, BattleAICmd_get_type, - BattleAICmd_unk_23, - BattleAICmd_unk_24, + BattleAICmd_get_move_power, + BattleAICmd_is_most_powerful_move, BattleAICmd_get_move, - BattleAICmd_if_type, - BattleAICmd_unk_27, + BattleAICmd_if_arg_equal, + BattleAICmd_if_arg_not_equal, BattleAICmd_if_would_go_first, BattleAICmd_if_would_not_go_first, - BattleAICmd_unk_2A, - BattleAICmd_unk_2B, + BattleAICmd_nullsub_2A, + BattleAICmd_nullsub_2B, BattleAICmd_count_alive_pokemon, - BattleAICmd_unk_2D, - BattleAICmd_unk_2E, + BattleAICmd_get_considered_move, + BattleAICmd_get_considered_move_effect, BattleAICmd_get_ability, - BattleAICmd_unk_30, + BattleAICmd_get_highest_possible_damage, BattleAICmd_if_damage_bonus, - BattleAICmd_unk_32, - BattleAICmd_unk_33, + BattleAICmd_nullsub_32, + BattleAICmd_nullsub_33, BattleAICmd_if_status_in_party, BattleAICmd_if_status_not_in_party, - BattleAICmd_unk_36, + BattleAICmd_get_weather, BattleAICmd_if_effect, BattleAICmd_if_not_effect, BattleAICmd_if_stat_level_less_than, @@ -262,34 +264,34 @@ static const BattleAICmdFunc sBattleAICmdTable[] = BattleAICmd_if_stat_level_not_equal, BattleAICmd_if_can_faint, BattleAICmd_if_cant_faint, - BattleAICmd_unk_3F, - BattleAICmd_unk_40, + BattleAICmd_if_has_move, + BattleAICmd_if_dont_have_move, BattleAICmd_if_move_effect, BattleAICmd_if_not_move_effect, BattleAICmd_if_last_move_did_damage, BattleAICmd_if_encored, - BattleAICmd_unk_45, - BattleAICmd_if_random_2, - BattleAICmd_unk_47, + BattleAICmd_flee, + BattleAICmd_if_random_100, + BattleAICmd_watch, BattleAICmd_get_hold_effect, BattleAICmd_get_gender, BattleAICmd_is_first_turn, BattleAICmd_get_stockpile_count, - BattleAICmd_unk_4C, + BattleAICmd_is_double_battle, BattleAICmd_get_item, - BattleAICmd_unk_4E, - BattleAICmd_unk_4F, - BattleAICmd_unk_50, + BattleAICmd_get_move_type_from_result, + BattleAICmd_get_move_power_from_result, + BattleAICmd_get_move_effect_from_result, BattleAICmd_get_protect_count, - BattleAICmd_unk_52, - BattleAICmd_unk_53, - BattleAICmd_unk_54, - BattleAICmd_unk_55, - BattleAICmd_unk_56, - BattleAICmd_unk_57, + BattleAICmd_nullsub_52, + BattleAICmd_nullsub_53, + BattleAICmd_nullsub_54, + BattleAICmd_nullsub_55, + BattleAICmd_nullsub_56, + BattleAICmd_nullsub_57, BattleAICmd_call, BattleAICmd_jump, - BattleAICmd_unk_5A, + BattleAICmd_end, BattleAICmd_if_level_cond, BattleAICmd_if_taunted, BattleAICmd_if_not_taunted, @@ -348,135 +350,138 @@ void BattleAI_HandleItemUseBeforeAISetup(void) void BattleAI_SetupAIData(void) { s32 i; - u8 *data = (u8 *)&gAIThinkingSpace; + u8 *data = (u8 *)AI_THINKING_STRUCT; u8 r7; - // clear AI data and set default move score to 100. - for (i = 0; (u32)i < 28; i++) + // 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++) - gAIThinkingSpace.score[i] = 100; + 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++) { u16 rand; if (gBitTable[i] & r7) - gAIThinkingSpace.score[i] = 0; + AI_THINKING_STRUCT->score[i] = 0; + rand = Random(); - gAIThinkingSpace.unk18[i] = 100 - (rand & 0xF); + AI_THINKING_STRUCT->unk18[i] = 100 - (rand & 0xF); } unk_2016C00.unk20 = 0; - gUnknown_02024C07 = gUnknown_02024A60; + gPlayerMonIndex = gUnknown_02024A60; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - gUnknown_02024C08 = Random() & 2; + gEnemyMonIndex = Random() & 2; // just pick somebody to target. - if (gUnknown_02024C0C & gBitTable[gUnknown_02024C08]) - gUnknown_02024C08 ^= 2; + if (gUnknown_02024C0C & gBitTable[gEnemyMonIndex]) + gEnemyMonIndex ^= 2; } else - gUnknown_02024C08 = gUnknown_02024A60 ^ 1; + gEnemyMonIndex = gUnknown_02024A60 ^ 1; // special AI flag cases. if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) - gAIThinkingSpace.aiFlags = 0x40000000; + AI_THINKING_STRUCT->aiFlags = 0x40000000; else if (gBattleTypeFlags & BATTLE_TYPE_ROAMER) - gAIThinkingSpace.aiFlags = 0x20000000; + AI_THINKING_STRUCT->aiFlags = 0x20000000; else if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) - gAIThinkingSpace.aiFlags = 0x80000000; + AI_THINKING_STRUCT->aiFlags = 0x80000000; else // otherwise, just set aiFlags to whatever flags the trainer has set in their data. - gAIThinkingSpace.aiFlags = gTrainers[gTrainerBattleOpponent].aiFlags; + AI_THINKING_STRUCT->aiFlags = gTrainers[gTrainerBattleOpponent].aiFlags; } u8 BattleAI_GetAIActionToUse(void) { - u8 arr1[4]; - u8 arr2[4]; - u8 r5; + u8 currentMoveArray[4]; + u8 consideredMoveArray[4]; + u8 numOfBestMoves; s32 i; sub_810745C(); - while (gAIThinkingSpace.aiFlags != 0) + while (AI_THINKING_STRUCT->aiFlags != 0) { - if (gAIThinkingSpace.aiFlags & 1) + if (AI_THINKING_STRUCT->aiFlags & 1) { - gAIThinkingSpace.unk0 = 0; + AI_THINKING_STRUCT->aiState = AIState_SettingUp; BattleAI_DoAIProcessing(); } - gAIThinkingSpace.aiFlags >>= 1; - gAIThinkingSpace.aiLogicId++; - gAIThinkingSpace.moveConsidered = 0; + AI_THINKING_STRUCT->aiFlags >>= 1; + AI_THINKING_STRUCT->aiLogicId++; + AI_THINKING_STRUCT->movesetIndex = 0; } - // will KO, need to use item or switch. - if (gAIThinkingSpace.unk10 & 2) + // special flee or watch cases for safari. + if (AI_THINKING_STRUCT->aiAction & (AI_ACTION_UNK2)) // flee return 4; - if (gAIThinkingSpace.unk10 & 4) + if (AI_THINKING_STRUCT->aiAction & (AI_ACTION_UNK3)) // watch return 5; - r5 = 1; - arr1[0] = gAIThinkingSpace.score[0]; - arr2[0] = 0; + numOfBestMoves = 1; + currentMoveArray[0] = AI_THINKING_STRUCT->score[0]; + consideredMoveArray[0] = 0; for (i = 1; i < 4; i++) { - if (arr1[0] < (s8)gAIThinkingSpace.score[i]) + if (currentMoveArray[0] < AI_THINKING_STRUCT->score[i]) { - r5 = 1; - arr1[0] = gAIThinkingSpace.score[i]; - arr2[0] = i; + numOfBestMoves = 1; + currentMoveArray[0] = AI_THINKING_STRUCT->score[i]; + consideredMoveArray[0] = i; } - if (arr1[0] == (s8)gAIThinkingSpace.score[i]) + if (currentMoveArray[0] == AI_THINKING_STRUCT->score[i]) { - arr1[r5] = gAIThinkingSpace.score[i]; - arr2[r5++] = i; + currentMoveArray[numOfBestMoves] = AI_THINKING_STRUCT->score[i]; + consideredMoveArray[numOfBestMoves++] = i; } } - return arr2[Random() % r5]; + return consideredMoveArray[Random() % numOfBestMoves]; // break any ties that exist. } void BattleAI_DoAIProcessing(void) { - while (gAIThinkingSpace.unk0 != 2) + while (AI_THINKING_STRUCT->aiState != AIState_FinishedProcessing) { - switch (gAIThinkingSpace.unk0) + switch (AI_THINKING_STRUCT->aiState) { - case 3: //Needed to match. + case AIState_DoNotProcess: //Needed to match. break; - case 0: - gAIScriptPtr = BattleAIs[gAIThinkingSpace.aiLogicId]; - if (gBattleMons[gUnknown_02024C07].pp[gAIThinkingSpace.moveConsidered] == 0) + case AIState_SettingUp: + gAIScriptPtr = BattleAIs[AI_THINKING_STRUCT->aiLogicId]; // set the AI ptr. + if (gBattleMons[gPlayerMonIndex].pp[AI_THINKING_STRUCT->movesetIndex] == 0) { - gAIThinkingSpace.unk2 = 0; + AI_THINKING_STRUCT->moveConsidered = MOVE_NONE; // don't consider a move you have 0 PP for, idiot. } else { - gAIThinkingSpace.unk2 = gBattleMons[gUnknown_02024C07].moves[gAIThinkingSpace.moveConsidered]; + AI_THINKING_STRUCT->moveConsidered = gBattleMons[gPlayerMonIndex].moves[AI_THINKING_STRUCT->movesetIndex]; } - gAIThinkingSpace.unk0++; + AI_THINKING_STRUCT->aiState++; break; - case 1: - if (gAIThinkingSpace.unk2 != 0) + case AIState_Processing: + if (AI_THINKING_STRUCT->moveConsidered != MOVE_NONE) sBattleAICmdTable[*(u8 *)gAIScriptPtr](); // run AI command. else { - gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] = 0; - gAIThinkingSpace.unk10 |= 1; + 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; } - if (gAIThinkingSpace.unk10 & 1) + if (AI_THINKING_STRUCT->aiAction & AI_ACTION_UNK1) { - gAIThinkingSpace.moveConsidered++; - if (gAIThinkingSpace.moveConsidered < 4 && !(gAIThinkingSpace.unk10 & 8)) - gAIThinkingSpace.unk0 = 0; + AI_THINKING_STRUCT->movesetIndex++; + if (AI_THINKING_STRUCT->movesetIndex < 4 && !(AI_THINKING_STRUCT->aiAction & AI_ACTION_UNK4)) + AI_THINKING_STRUCT->aiState = AIState_SettingUp; // as long as their are more moves to process, keep setting this to setup state. else - gAIThinkingSpace.unk0++; - gAIThinkingSpace.unk10 &= 0xFE; + 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. } break; } @@ -489,10 +494,9 @@ void sub_810745C(void) for (i = 0; i < 8; i++) { - // this is the same as dividing it by 2, but for some reason, >> 1 is needed to match the asm. - if (unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == 0) + if (unk_2016A00.unk0[gEnemyMonIndex >> 1][i] == 0) { - unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] = gUnknown_02024C34[gUnknown_02024C08]; + unk_2016A00.unk0[gEnemyMonIndex >> 1][i] = gUnknown_02024C34[gEnemyMonIndex]; return; } } @@ -518,41 +522,41 @@ void sub_81074F8(u8 a, u8 b) unk_2016A00.unk22[battle_get_per_side_status(a) & 1] = b; } -static void BattleAICmd_if_random(void) +static void BattleAICmd_if_random_less_than(void) { u16 random = Random(); - if (!(random % 256 >= gAIScriptPtr[1])) // roll a random value. is it less than the parameter of the if_random call? (96 on if_random 80 will return true) + if (random % 256 < gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_if_not_random(void) +static void BattleAICmd_if_random_greater_than(void) { u16 random = Random(); - if (!(random % 256 <= gAIScriptPtr[1])) // roll a random value. is it greater than the parameter of the if_random call? (96 on if_random 80 will return true) + if (random % 256 > gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_if_random_1(void) // if RNG Value equal to +static void BattleAICmd_if_random_equal(void) // if RNG Value equal to { u16 random = Random(); - if (random % 256 == gAIScriptPtr[1]) // roll a random value. is it greater than the parameter of the if_random call? (96 on if_random 80 will return true) + if (random % 256 == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_if_not_random_1(void) // if RNG value not equal to +static void BattleAICmd_if_random_not_equal(void) // if RNG value not equal to { u16 random = Random(); - if (random % 256 != gAIScriptPtr[1]) // roll a random value. is it greater than the parameter of the if_random call? (96 on if_random 80 will return true) + if (random % 256 != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -560,24 +564,24 @@ static void BattleAICmd_if_not_random_1(void) // if RNG value not equal to static void BattleAICmd_score(void) { - gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] += 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 (gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] < 0) // if the score is negative, flatten it to 0. - gAIThinkingSpace.score[gAIThinkingSpace.moveConsidered] = 0; + 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; gAIScriptPtr += 2; // AI return. } static void BattleAICmd_if_hp_less_than(void) { - u16 var; + u16 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - if ((u32)(100 * gBattleMons[var].hp / gBattleMons[var].maxHP) < gAIScriptPtr[2]) + if ((u32)(100 * gBattleMons[index].hp / gBattleMons[index].maxHP) < gAIScriptPtr[2]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -585,14 +589,14 @@ static void BattleAICmd_if_hp_less_than(void) static void BattleAICmd_if_hp_more_than(void) { - u16 var; + u16 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - if ((u32)(100 * gBattleMons[var].hp / gBattleMons[var].maxHP) > gAIScriptPtr[2]) + if ((u32)(100 * gBattleMons[index].hp / gBattleMons[index].maxHP) > gAIScriptPtr[2]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -600,14 +604,14 @@ static void BattleAICmd_if_hp_more_than(void) static void BattleAICmd_if_hp_equal(void) { - u16 var; + u16 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - if ((u32)(100 * gBattleMons[var].hp / gBattleMons[var].maxHP) == gAIScriptPtr[2]) + if ((u32)(100 * gBattleMons[index].hp / gBattleMons[index].maxHP) == gAIScriptPtr[2]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -615,14 +619,14 @@ static void BattleAICmd_if_hp_equal(void) static void BattleAICmd_if_hp_not_equal(void) { - u16 var; + u16 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - if ((u32)(100 * gBattleMons[var].hp / gBattleMons[var].maxHP) != gAIScriptPtr[2]) + if ((u32)(100 * gBattleMons[index].hp / gBattleMons[index].maxHP) != gAIScriptPtr[2]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -630,17 +634,17 @@ static void BattleAICmd_if_hp_not_equal(void) static void BattleAICmd_if_status(void) { - u16 var; - u32 temp; + u16 index; + u32 arg; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - temp = AIScriptRead32(gAIScriptPtr + 2); + arg = AIScriptRead32(gAIScriptPtr + 2); - if (gBattleMons[var].status1 & temp) + if ((gBattleMons[index].status1 & arg) != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -648,17 +652,17 @@ static void BattleAICmd_if_status(void) static void BattleAICmd_if_not_status(void) { - u16 var; - u32 temp; + u16 index; + u32 arg; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - temp = AIScriptRead32(gAIScriptPtr + 2); + arg = AIScriptRead32(gAIScriptPtr + 2); - if (!(gBattleMons[var].status1 & temp)) + if ((gBattleMons[index].status1 & arg) == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -666,17 +670,17 @@ static void BattleAICmd_if_not_status(void) static void BattleAICmd_if_status2(void) { - u8 var; - u32 temp; + u16 index; + u32 arg; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - temp = AIScriptRead32(gAIScriptPtr + 2); + arg = AIScriptRead32(gAIScriptPtr + 2); - if (gBattleMons[var].status2 & temp) + if ((gBattleMons[index].status2 & arg) != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -684,17 +688,17 @@ static void BattleAICmd_if_status2(void) static void BattleAICmd_if_not_status2(void) { - u8 var; - u32 temp; + u16 index; + u32 arg; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - temp = AIScriptRead32(gAIScriptPtr + 2); + arg = AIScriptRead32(gAIScriptPtr + 2); - if (!(gBattleMons[var].status2 & temp)) + if ((gBattleMons[index].status2 & arg) == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -702,17 +706,17 @@ static void BattleAICmd_if_not_status2(void) static void BattleAICmd_if_status3(void) { - u8 var; - u32 temp; + u16 index; + u32 arg; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - temp = AIScriptRead32(gAIScriptPtr + 2); + arg = AIScriptRead32(gAIScriptPtr + 2); - if (gUnknown_02024C98[var] & temp) + if ((gUnknown_02024C98[index] & arg) != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -720,17 +724,17 @@ static void BattleAICmd_if_status3(void) static void BattleAICmd_if_not_status3(void) { - u8 var; - u32 temp; + u16 index; + u32 arg; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - temp = AIScriptRead32(gAIScriptPtr + 2); + arg = AIScriptRead32(gAIScriptPtr + 2); - if (!(gUnknown_02024C98[var] & temp)) + if ((gUnknown_02024C98[index] & arg) == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -738,19 +742,18 @@ static void BattleAICmd_if_not_status3(void) static void BattleAICmd_if_status4(void) { - u8 var; - u32 temp; - u32 temp2; + u16 index; + u32 arg1, arg2; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - temp = battle_get_per_side_status(var) & 1; - temp2 = AIScriptRead32(gAIScriptPtr + 2); + arg1 = battle_get_per_side_status(index) & 1; + arg2 = AIScriptRead32(gAIScriptPtr + 2); - if (gUnknown_02024C7A[temp] & temp2) + if ((gUnknown_02024C7A[arg1] & arg2) != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -758,19 +761,18 @@ static void BattleAICmd_if_status4(void) static void BattleAICmd_if_not_status4(void) { - u8 var; - u32 temp; - u32 temp2; + u16 index; + u32 arg1, arg2; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - temp = battle_get_per_side_status(var) & 1; - temp2 = AIScriptRead32(gAIScriptPtr + 2); + arg1 = battle_get_per_side_status(index) & 1; + arg2 = AIScriptRead32(gAIScriptPtr + 2); - if (!(gUnknown_02024C7A[temp] & temp2)) + if ((gUnknown_02024C7A[arg1] & arg2) == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -778,7 +780,7 @@ static void BattleAICmd_if_not_status4(void) static void BattleAICmd_if_less_than(void) { - if (gAIThinkingSpace.funcResult < gAIScriptPtr[1]) + if (AI_THINKING_STRUCT->funcResult < gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -786,7 +788,7 @@ static void BattleAICmd_if_less_than(void) static void BattleAICmd_if_more_than(void) { - if (gAIThinkingSpace.funcResult > gAIScriptPtr[1]) + if (AI_THINKING_STRUCT->funcResult > gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -794,7 +796,7 @@ static void BattleAICmd_if_more_than(void) static void BattleAICmd_if_equal(void) { - if (gAIThinkingSpace.funcResult == gAIScriptPtr[1]) + if (AI_THINKING_STRUCT->funcResult == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -802,7 +804,7 @@ static void BattleAICmd_if_equal(void) static void BattleAICmd_if_not_equal(void) { - if (gAIThinkingSpace.funcResult != gAIScriptPtr[1]) + if (AI_THINKING_STRUCT->funcResult != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -812,7 +814,7 @@ static void BattleAICmd_if_less_than_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); - if (gAIThinkingSpace.funcResult < *temp) + if (AI_THINKING_STRUCT->funcResult < *temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -822,7 +824,7 @@ static void BattleAICmd_if_more_than_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); - if (gAIThinkingSpace.funcResult > *temp) + if (AI_THINKING_STRUCT->funcResult > *temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -832,7 +834,7 @@ static void BattleAICmd_if_equal_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); - if (gAIThinkingSpace.funcResult == *temp) + if (AI_THINKING_STRUCT->funcResult == *temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -842,7 +844,7 @@ static void BattleAICmd_if_not_equal_32(void) { u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); - if (gAIThinkingSpace.funcResult != *temp) + if (AI_THINKING_STRUCT->funcResult != *temp) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -852,7 +854,7 @@ static void BattleAICmd_if_move(void) { u16 move = AIScriptRead16(gAIScriptPtr + 1); - if (gAIThinkingSpace.unk2 == move) + if (AI_THINKING_STRUCT->moveConsidered == move) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -862,7 +864,7 @@ static void BattleAICmd_if_not_move(void) { u16 move = AIScriptRead16(gAIScriptPtr + 1); - if (gAIThinkingSpace.unk2 != move) + if (AI_THINKING_STRUCT->moveConsidered != move) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -874,7 +876,7 @@ static void BattleAICmd_if_in_bytes(void) while (*ptr != 0xFF) { - if (gAIThinkingSpace.funcResult == *ptr) + if (AI_THINKING_STRUCT->funcResult == *ptr) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); return; @@ -890,7 +892,7 @@ static void BattleAICmd_if_not_in_bytes(void) while (*ptr != 0xFF) { - if (gAIThinkingSpace.funcResult == *ptr) + if (AI_THINKING_STRUCT->funcResult == *ptr) { gAIScriptPtr += 9; return; @@ -906,7 +908,7 @@ static void BattleAICmd_if_in_words(void) while (*ptr != 0xFFFF) { - if (gAIThinkingSpace.funcResult == *ptr) + if (AI_THINKING_STRUCT->funcResult == *ptr) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); return; @@ -922,7 +924,7 @@ static void BattleAICmd_if_not_in_words(void) while (*ptr != 0xFFFF) { - if (gAIThinkingSpace.funcResult == *ptr) + if (AI_THINKING_STRUCT->funcResult == *ptr) { gAIScriptPtr += 9; return; @@ -938,8 +940,8 @@ static void BattleAICmd_if_user_can_damage(void) for (i = 0; i < 4; i++) { - if (gBattleMons[gUnknown_02024C07].moves[i] != 0 - && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power != 0) + if (gBattleMons[gPlayerMonIndex].moves[i] != 0 + && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].power != 0) break; } if (i == 4) @@ -954,8 +956,8 @@ static void BattleAICmd_if_user_cant_damage(void) for (i = 0; i < 4; i++) { - if (gBattleMons[gUnknown_02024C07].moves[i] != 0 - && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power != 0) + if (gBattleMons[gPlayerMonIndex].moves[i] != 0 + && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].power != 0) break; } if (i != 4) @@ -964,9 +966,9 @@ static void BattleAICmd_if_user_cant_damage(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } -static void BattleAICmd_unk_21(void) +static void BattleAICmd_get_turn_count(void) { - gAIThinkingSpace.funcResult = gUnknown_030042E0[19]; + AI_THINKING_STRUCT->funcResult = gUnknown_030042E0[19]; gAIScriptPtr += 1; } @@ -976,69 +978,68 @@ static void BattleAICmd_get_type(void) switch (typeVar) { - case 1: - gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C07].type1; + case 1: // player primary type + AI_THINKING_STRUCT->funcResult = gBattleMons[gPlayerMonIndex].type1; break; - case 0: - gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C08].type1; + case 0: // enemy primary type + AI_THINKING_STRUCT->funcResult = gBattleMons[gEnemyMonIndex].type1; break; - case 3: - gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C07].type2; + case 3: // player secondary type + AI_THINKING_STRUCT->funcResult = gBattleMons[gPlayerMonIndex].type2; break; - case 2: - gAIThinkingSpace.funcResult = gBattleMons[gUnknown_02024C08].type2; + case 2: // enemy secondary type + AI_THINKING_STRUCT->funcResult = gBattleMons[gEnemyMonIndex].type2; break; - case 4: - gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].type; + case 4: // type of move being pointed to + AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->moveConsidered].type; break; } gAIScriptPtr += 2; } -static void BattleAICmd_unk_23(void) +static void BattleAICmd_get_move_power(void) { - gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].power; + AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->moveConsidered].power; gAIScriptPtr += 1; } #ifdef NONMATCHING -static void BattleAICmd_unk_24(void) +static void BattleAICmd_is_most_powerful_move(void) { int i, j; - s32 damage; s32 damages[4]; for (i = 0; sDiscouragedPowerfulMoveEffects[i] != 0xFFFF; i++) - if (gBattleMoves[AI_THINKING_STRUCT->unk2].effect == sDiscouragedPowerfulMoveEffects[i]) + if (gBattleMoves[AI_THINKING_STRUCT->moveConsidered].effect == sDiscouragedPowerfulMoveEffects[i]) break; - if (gBattleMoves[AI_THINKING_STRUCT->unk2].power > 1 + if (gBattleMoves[AI_THINKING_STRUCT->moveConsidered].power > 1 && sDiscouragedPowerfulMoveEffects[i] == 0xFFFF) { gUnknown_02024DEC = 0; - *((u8 *)&battle_2000000 + 0x1601C) = 0; - *((u8 *)&battle_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 (j = 0; sDiscouragedPowerfulMoveEffects[j] != 0xFFFF; j++) - { - if (gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == sDiscouragedPowerfulMoveEffects[j]) + { // _08108276 + if (gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].effect == sDiscouragedPowerfulMoveEffects[j]) break; } - if (gBattleMons[gUnknown_02024C07].moves[i] + // _081082BA + if (gBattleMons[gPlayerMonIndex].moves[i] && sDiscouragedPowerfulMoveEffects[j] == 0xFFFF - && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].power > 1) + && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].power > 1) { - gUnknown_02024BE6 = gBattleMons[gUnknown_02024C07].moves[i]; - sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); - move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); - damage = (gBattleMoveDamage * AI_THINKING_STRUCT->unk18[i]) / 100; - damages[i] = damage; - if (!damage) + 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; + if (damages[i] == 0) // moves always do at least 1 damage. damages[i] = 1; } else @@ -1048,7 +1049,7 @@ static void BattleAICmd_unk_24(void) } for (i = 0; i < 4; i++) - if (damages[i] > damages[AI_THINKING_STRUCT->moveConsidered]) + if (damages[i] > damages[AI_THINKING_STRUCT->movesetIndex]) break; if (i == 4) @@ -1059,14 +1060,13 @@ static void BattleAICmd_unk_24(void) else { AI_THINKING_STRUCT->funcResult = 0; - gAIScriptPtr += 1; } gAIScriptPtr += 1; } #else __attribute__((naked)) -static void BattleAICmd_unk_24(void) +static void BattleAICmd_is_most_powerful_move(void) { asm(".syntax unified\n\ push {r4-r7,lr}\n\ @@ -1142,7 +1142,7 @@ _08108276:\n\ movs r3, 0\n\ ldr r5, _08108348 @ =gBattleMons\n\ lsls r4, r6, 1\n\ - ldr r7, _0810834C @ =gUnknown_02024C07\n\ + ldr r7, _0810834C @ =gPlayerMonIndex\n\ lsls r1, r6, 2\n\ mov r8, r1\n\ adds r2, r6, 0x1\n\ @@ -1203,7 +1203,7 @@ _081082BA:\n\ ldr r5, _08108350 @ =gUnknown_02024BE6\n\ strh r2, [r5]\n\ ldrb r0, [r7]\n\ - ldr r4, _08108354 @ =gUnknown_02024C08\n\ + ldr r4, _08108354 @ =gEnemyMonIndex\n\ ldrb r1, [r4]\n\ bl sub_801CAF8\n\ ldrh r0, [r5]\n\ @@ -1237,9 +1237,9 @@ _0810833C: .4byte 0xfffff81c\n\ _08108340: .4byte gBattleMoveFlags\n\ _08108344: .4byte gCritMultiplier\n\ _08108348: .4byte gBattleMons\n\ -_0810834C: .4byte gUnknown_02024C07\n\ +_0810834C: .4byte gPlayerMonIndex\n\ _08108350: .4byte gUnknown_02024BE6\n\ -_08108354: .4byte gUnknown_02024C08\n\ +_08108354: .4byte gEnemyMonIndex\n\ _08108358: .4byte gBattleMoveDamage\n\ _0810835C:\n\ mov r1, sp\n\ @@ -1313,24 +1313,24 @@ _081083D0: .4byte gAIScriptPtr\n\ static void BattleAICmd_get_move(void) { if (gAIScriptPtr[1] == USER) - gAIThinkingSpace.funcResult = gUnknown_02024C34[gUnknown_02024C07]; + AI_THINKING_STRUCT->funcResult = gUnknown_02024C34[gPlayerMonIndex]; else - gAIThinkingSpace.funcResult = gUnknown_02024C34[gUnknown_02024C08]; + AI_THINKING_STRUCT->funcResult = gUnknown_02024C34[gEnemyMonIndex]; gAIScriptPtr += 2; } -static void BattleAICmd_if_type(void) +static void BattleAICmd_if_arg_equal(void) { - if (gAIScriptPtr[1] == gAIThinkingSpace.funcResult) + if (gAIScriptPtr[1] == AI_THINKING_STRUCT->funcResult) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_unk_27(void) // if_not_type +static void BattleAICmd_if_arg_not_equal(void) { - if (gAIScriptPtr[1] != gAIThinkingSpace.funcResult) + if (gAIScriptPtr[1] != AI_THINKING_STRUCT->funcResult) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1338,7 +1338,7 @@ static void BattleAICmd_unk_27(void) // if_not_type static void BattleAICmd_if_would_go_first(void) { - if (b_first_side(gUnknown_02024C07, gUnknown_02024C08, 1) == gAIScriptPtr[1]) + if (b_first_side(gPlayerMonIndex, gEnemyMonIndex, 1) == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1346,34 +1346,33 @@ static void BattleAICmd_if_would_go_first(void) static void BattleAICmd_if_would_not_go_first(void) { - if (b_first_side(gUnknown_02024C07, gUnknown_02024C08, 1) != gAIScriptPtr[1]) + if (b_first_side(gPlayerMonIndex, gEnemyMonIndex, 1) != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_unk_2A(void) +static void BattleAICmd_nullsub_2A(void) { } -static void BattleAICmd_unk_2B(void) +static void BattleAICmd_nullsub_2B(void) { } static void BattleAICmd_count_alive_pokemon(void) { u8 index; + u8 var, var2; struct Pokemon *party; - struct AI_ThinkingStruct *ai = &battle_2000000.ai; int i; - u8 var, var2; - ai->funcResult = 0; + AI_THINKING_STRUCT->funcResult = 0; if (gAIScriptPtr[1] == USER) - index = gUnknown_02024C07; + index = gPlayerMonIndex; else - index = gUnknown_02024C08; + index = gEnemyMonIndex; if (battle_side_get_owner(index) == 0) party = gPlayerParty; @@ -1395,87 +1394,86 @@ static void BattleAICmd_count_alive_pokemon(void) for (i = 0; i < 6; i++) { - struct AI_ThinkingStruct *ai2 = &battle_2000000.ai; if (i != var && i != var2 && GetMonData(&party[i], MON_DATA_HP) != 0 && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG) { - ai2->funcResult++; + AI_THINKING_STRUCT->funcResult++; } } gAIScriptPtr += 2; } -static void BattleAICmd_unk_2D(void) +static void BattleAICmd_get_considered_move(void) { - gAIThinkingSpace.funcResult = gAIThinkingSpace.unk2; + AI_THINKING_STRUCT->funcResult = AI_THINKING_STRUCT->moveConsidered; gAIScriptPtr += 1; } -static void BattleAICmd_unk_2E(void) +static void BattleAICmd_get_considered_move_effect(void) { - gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.unk2].effect; + AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->moveConsidered].effect; gAIScriptPtr += 1; } static void BattleAICmd_get_ability(void) { - u8 var; + u8 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - if (battle_side_get_owner(var) == TARGET) + if (battle_side_get_owner(index) == TARGET) { - u16 unk = battle_get_per_side_status(var) & 1; + u16 unk = battle_get_per_side_status(index) & 1; - if (unk_2016A00.unk20[unk] != 0) + if (UNK_2016A00_STRUCT->unk20[unk] != 0) { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = unk_2016A00.unk20[unk]; + AI_THINKING_STRUCT->funcResult = UNK_2016A00_STRUCT->unk20[unk]; gAIScriptPtr += 2; return; } // abilities that prevent fleeing. - if (gBattleMons[var].ability == ABILITY_SHADOW_TAG || gBattleMons[var].ability == ABILITY_MAGNET_PULL || gBattleMons[var].ability == ABILITY_ARENA_TRAP) + if (gBattleMons[index].ability == ABILITY_SHADOW_TAG || gBattleMons[index].ability == ABILITY_MAGNET_PULL || gBattleMons[index].ability == ABILITY_ARENA_TRAP) { - gAIThinkingSpace.funcResult = gBattleMons[var].ability; + AI_THINKING_STRUCT->funcResult = gBattleMons[index].ability; gAIScriptPtr += 2; return; } - if (gBaseStats[gBattleMons[var].species].ability1 != ABILITY_NONE) + if (gBaseStats[gBattleMons[index].species].ability1 != ABILITY_NONE) { - if (gBaseStats[gBattleMons[var].species].ability2 != ABILITY_NONE) + if (gBaseStats[gBattleMons[index].species].ability2 != ABILITY_NONE) { - // AI is guessing what ability? + // 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) { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability1; + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability1; gAIScriptPtr += 2; return; } else { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability2; + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability2; gAIScriptPtr += 2; return; } } else { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability1; // it's definitely ability 1. + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability1; // it's definitely ability 1. gAIScriptPtr += 2; return; } } else { - ((struct AI_ThinkingStruct *)((u8 *)&unk_2016A00 - 0x200))->funcResult = gBaseStats[gBattleMons[var].species].ability2; // AI cant actually reach this part since every mon has at least 1 ability. + 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; } @@ -1483,34 +1481,31 @@ static void BattleAICmd_get_ability(void) else { // The AI knows its own ability. - gAIThinkingSpace.funcResult = gBattleMons[var].ability; + AI_THINKING_STRUCT->funcResult = gBattleMons[index].ability; gAIScriptPtr += 2; return; } } -static void BattleAICmd_unk_30(void) +static void BattleAICmd_get_highest_possible_damage(void) { s32 i; - struct AI_ThinkingStruct *ai; - struct AI_ThinkingStruct *ai2; gUnknown_02024DEC = 0; - battle_2000000.unk.unk1 = 0; - battle_2000000.unk.unk4 = 1; + BATTLE_STRUCT->unk.unk1 = 0; + BATTLE_STRUCT->unk.unk4 = 1; gBattleMoveFlags = 0; gCritMultiplier = 1; - ai = &battle_2000000.ai; - ai->funcResult = 0; + AI_THINKING_STRUCT->funcResult = 0; for (i = 0; i < 4; i++) { gBattleMoveDamage = 40; - gUnknown_02024BE6 = gBattleMons[gUnknown_02024C07].moves[i]; + gUnknown_02024BE6 = gBattleMons[gPlayerMonIndex].moves[i]; if (gUnknown_02024BE6) { - move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); + move_effectiveness_something(gUnknown_02024BE6, gPlayerMonIndex, gEnemyMonIndex); // reduce by 1/3. if (gBattleMoveDamage == 120) @@ -1522,12 +1517,11 @@ static void BattleAICmd_unk_30(void) if (gBattleMoveDamage == 15) gBattleMoveDamage = 10; - if (gBattleMoveFlags & 8) + if (gBattleMoveFlags & 8) // if it's a status move, it wont do anything. gBattleMoveDamage = 0; - ai2 = &battle_2000000.ai; - if (ai2->funcResult < gBattleMoveDamage) - ai2->funcResult = gBattleMoveDamage; + if (AI_THINKING_STRUCT->funcResult < gBattleMoveDamage) + AI_THINKING_STRUCT->funcResult = gBattleMoveDamage; } } gAIScriptPtr += 1; @@ -1535,19 +1529,18 @@ static void BattleAICmd_unk_30(void) static void BattleAICmd_if_damage_bonus(void) { - struct AI_ThinkingStruct *ai; u8 damageVar; gUnknown_02024DEC = 0; - battle_2000000.unk.unk1 = 0; - battle_2000000.unk.unk4 = 1; + BATTLE_STRUCT->unk.unk1 = 0; + BATTLE_STRUCT->unk.unk4 = 1; gBattleMoveFlags = 0; gCritMultiplier = 1; gBattleMoveDamage = 40; - gUnknown_02024BE6 = (ai = &battle_2000000.ai)->unk2; + gUnknown_02024BE6 = AI_THINKING_STRUCT->moveConsidered; - move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); + move_effectiveness_something(gUnknown_02024BE6, gPlayerMonIndex, gEnemyMonIndex); if (gBattleMoveDamage == 120) gBattleMoveDamage = 80; @@ -1561,42 +1554,39 @@ static void BattleAICmd_if_damage_bonus(void) if (gBattleMoveFlags & 8) gBattleMoveDamage = 0; - // i have to store 2024BEC in a local variable before the comparison or else it will not match. + // store gBattleMoveDamage in a u8 variable because gAIScriptPtr[1] is a u8. damageVar = gBattleMoveDamage; + if (damageVar == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_unk_32(void) +static void BattleAICmd_nullsub_32(void) { } -static void BattleAICmd_unk_33(void) +static void BattleAICmd_nullsub_33(void) { } static void BattleAICmd_if_status_in_party(void) { struct Pokemon *party; + struct Pokemon *partyPtr; int i; u32 statusToCompareTo; - if (gAIScriptPtr[1] == USER) - { - party = gEnemyParty; - } - else if (0) - { - // what is going on here? - follow_jump: - gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); - return; - } - else + // for whatever reason, game freak put the party pointer into 2 variables instead of 1. it's possible at some point the switch encompassed the whole function and used each respective variable creating largely duplicate code. + switch (gAIScriptPtr[1]) { - party = gPlayerParty; + case 1: + party = partyPtr = gEnemyParty; + break; + default: + party = partyPtr = gPlayerParty; + break; } statusToCompareTo = AIScriptRead32(gAIScriptPtr + 2); @@ -1608,29 +1598,30 @@ 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) - goto follow_jump; + { + gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); // WHAT. why is this being merged into the above switch + return; + } } gAIScriptPtr += 10; } +// bugged, doesnt return properly. also unused static void BattleAICmd_if_status_not_in_party(void) { struct Pokemon *party; + struct Pokemon *partyPtr; int i; u32 statusToCompareTo; - u8 *partyPtr; - // what weird code. needed to match switch (gAIScriptPtr[1]) { case 1: - partyPtr = (u8 *)gEnemyParty; - party = (struct Pokemon *)partyPtr; + party = partyPtr = gEnemyParty; break; default: - partyPtr = (u8 *)gPlayerParty; - party = (struct Pokemon *)partyPtr; + party = partyPtr = gPlayerParty; break; } @@ -1642,30 +1633,30 @@ static void BattleAICmd_if_status_not_in_party(void) u16 hp = GetMonData(&party[i], MON_DATA_HP); u32 status = GetMonData(&party[i], MON_DATA_STATUS); - // this jump is seemingly bugged. everytime the status is found, the AI's logic jumps further and further past its intended destination. + // everytime the status is found, the AI's logic jumps further and further past its intended destination. this results in a broken AI macro and is probably why it is unused. if (species != SPECIES_NONE && species != SPECIES_EGG && hp != 0 && status == statusToCompareTo) gAIScriptPtr += 10; // doesnt return? } gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); } -static void BattleAICmd_unk_36(void) +static void BattleAICmd_get_weather(void) { if (gBattleWeather & 7) - gAIThinkingSpace.funcResult = 1; + AI_THINKING_STRUCT->funcResult = 1; if (gBattleWeather & 0x18) - gAIThinkingSpace.funcResult = 2; + AI_THINKING_STRUCT->funcResult = 2; if (gBattleWeather & 0x60) - gAIThinkingSpace.funcResult = 0; + AI_THINKING_STRUCT->funcResult = 0; if (gBattleWeather & 0x80) - gAIThinkingSpace.funcResult = 3; + AI_THINKING_STRUCT->funcResult = 3; gAIScriptPtr += 1; } static void BattleAICmd_if_effect(void) { - if (gBattleMoves[gAIThinkingSpace.unk2].effect == gAIScriptPtr[1]) + if (gBattleMoves[AI_THINKING_STRUCT->moveConsidered].effect == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1673,7 +1664,7 @@ static void BattleAICmd_if_effect(void) static void BattleAICmd_if_not_effect(void) { - if (gBattleMoves[gAIThinkingSpace.unk2].effect != gAIScriptPtr[1]) + if (gBattleMoves[AI_THINKING_STRUCT->moveConsidered].effect != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1684,9 +1675,9 @@ static void BattleAICmd_if_stat_level_less_than(void) u32 party; if (gAIScriptPtr[1] == USER) - party = gUnknown_02024C07; + party = gPlayerMonIndex; else - party = gUnknown_02024C08; + party = gEnemyMonIndex; if (gBattleMons[party].statStages[gAIScriptPtr[2]] < gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); @@ -1699,9 +1690,9 @@ static void BattleAICmd_if_stat_level_more_than(void) u32 party; if (gAIScriptPtr[1] == USER) - party = gUnknown_02024C07; + party = gPlayerMonIndex; else - party = gUnknown_02024C08; + party = gEnemyMonIndex; if (gBattleMons[party].statStages[gAIScriptPtr[2]] > gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); @@ -1714,9 +1705,9 @@ static void BattleAICmd_if_stat_level_equal(void) u32 party; if (gAIScriptPtr[1] == USER) - party = gUnknown_02024C07; + party = gPlayerMonIndex; else - party = gUnknown_02024C08; + party = gEnemyMonIndex; if (gBattleMons[party].statStages[gAIScriptPtr[2]] == gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); @@ -1729,9 +1720,9 @@ static void BattleAICmd_if_stat_level_not_equal(void) u32 party; if (gAIScriptPtr[1] == USER) - party = gUnknown_02024C07; + party = gPlayerMonIndex; else - party = gUnknown_02024C08; + party = gEnemyMonIndex; if (gBattleMons[party].statStages[gAIScriptPtr[2]] != gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); @@ -1741,27 +1732,27 @@ static void BattleAICmd_if_stat_level_not_equal(void) static void BattleAICmd_if_can_faint(void) { - if (gBattleMoves[gAIThinkingSpace.unk2].power < 2) + if (gBattleMoves[AI_THINKING_STRUCT->moveConsidered].power < 2) { gAIScriptPtr += 5; return; } gUnknown_02024DEC = 0; - ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk1 = 0; - ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk4 = 1; + BATTLE_STRUCT->unk.unk1 = 0; + BATTLE_STRUCT->unk.unk4 = 1; gBattleMoveFlags = 0; gCritMultiplier = 1; - gUnknown_02024BE6 = gAIThinkingSpace.unk2; - sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); - move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); + gUnknown_02024BE6 = AI_THINKING_STRUCT->moveConsidered; + sub_801CAF8(gPlayerMonIndex, gEnemyMonIndex); + move_effectiveness_something(gUnknown_02024BE6, gPlayerMonIndex, gEnemyMonIndex); - gBattleMoveDamage = gBattleMoveDamage * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; + gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->unk18[AI_THINKING_STRUCT->movesetIndex] / 100; // moves always do at least 1 damage. if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; - if (gBattleMons[gUnknown_02024C08].hp <= gBattleMoveDamage) + if (gBattleMons[gEnemyMonIndex].hp <= gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -1769,32 +1760,32 @@ static void BattleAICmd_if_can_faint(void) static void BattleAICmd_if_cant_faint(void) { - if (gBattleMoves[gAIThinkingSpace.unk2].power < 2) + if (gBattleMoves[AI_THINKING_STRUCT->moveConsidered].power < 2) { gAIScriptPtr += 5; return; } gUnknown_02024DEC = 0; - ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk1 = 0; - ((struct BattleStruct *)((u8 *)&gAIThinkingSpace - 0x16800))->unk.unk4 = 1; + BATTLE_STRUCT->unk.unk1 = 0; + BATTLE_STRUCT->unk.unk4 = 1; gBattleMoveFlags = 0; gCritMultiplier = 1; - gUnknown_02024BE6 = gAIThinkingSpace.unk2; - sub_801CAF8(gUnknown_02024C07, gUnknown_02024C08); - move_effectiveness_something(gUnknown_02024BE6, gUnknown_02024C07, gUnknown_02024C08); + gUnknown_02024BE6 = AI_THINKING_STRUCT->moveConsidered; + sub_801CAF8(gPlayerMonIndex, gEnemyMonIndex); + move_effectiveness_something(gUnknown_02024BE6, gPlayerMonIndex, gEnemyMonIndex); - gBattleMoveDamage = gBattleMoveDamage * gAIThinkingSpace.unk18[gAIThinkingSpace.moveConsidered] / 100; + gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->unk18[AI_THINKING_STRUCT->movesetIndex] / 100; // this macro is missing the damage 0 = 1 assumption. - if (gBattleMons[gUnknown_02024C08].hp > gBattleMoveDamage) + if (gBattleMons[gEnemyMonIndex].hp > gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; } -static void BattleAICmd_unk_3F(void) +static void BattleAICmd_if_has_move(void) { int i; u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); @@ -1805,7 +1796,7 @@ static void BattleAICmd_unk_3F(void) case 3: for (i = 0; i < 4; i++) { - if (gBattleMons[gUnknown_02024C07].moves[i] == *temp_ptr) + if (gBattleMons[gPlayerMonIndex].moves[i] == *temp_ptr) break; } if (i == 4) @@ -1822,7 +1813,7 @@ static void BattleAICmd_unk_3F(void) case 2: for (i = 0; i < 8; i++) { - if (unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == *temp_ptr) + if (unk_2016A00.unk0[gEnemyMonIndex >> 1][i] == *temp_ptr) break; } if (i == 8) @@ -1838,7 +1829,7 @@ static void BattleAICmd_unk_3F(void) } } -static void BattleAICmd_unk_40(void) +static void BattleAICmd_if_dont_have_move(void) { int i; u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); @@ -1849,7 +1840,7 @@ static void BattleAICmd_unk_40(void) case 3: for (i = 0; i < 4; i++) { - if (gBattleMons[gUnknown_02024C07].moves[i] == *temp_ptr) + if (gBattleMons[gPlayerMonIndex].moves[i] == *temp_ptr) break; } if (i != 4) @@ -1866,7 +1857,7 @@ static void BattleAICmd_unk_40(void) case 2: for (i = 0; i < 8; i++) { - if (unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] == *temp_ptr) + if (unk_2016A00.unk0[gEnemyMonIndex >> 1][i] == *temp_ptr) break; } if (i != 8) @@ -1892,7 +1883,7 @@ static void BattleAICmd_if_move_effect(void) case 3: for (i = 0; i < 4; i++) { - if (gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gAIScriptPtr[2]) + if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].effect == gAIScriptPtr[2]) break; } if (i != 4) @@ -1904,7 +1895,7 @@ static void BattleAICmd_if_move_effect(void) case 2: for (i = 0; i < 8; i++) { - if (gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[unk_2016A00.unk0[gUnknown_02024C08 >> 1][i]].effect == gAIScriptPtr[2]) + if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[unk_2016A00.unk0[gEnemyMonIndex >> 1][i]].effect == gAIScriptPtr[2]) break; } gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); @@ -1921,7 +1912,7 @@ static void BattleAICmd_if_not_move_effect(void) case 3: for (i = 0; i < 4; i++) { - if (gBattleMons[gUnknown_02024C07].moves[i] != 0 && gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == gAIScriptPtr[2]) + if (gBattleMons[gPlayerMonIndex].moves[i] != 0 && gBattleMoves[gBattleMons[gPlayerMonIndex].moves[i]].effect == gAIScriptPtr[2]) break; } if (i != 4) @@ -1933,7 +1924,7 @@ static void BattleAICmd_if_not_move_effect(void) case 2: for (i = 0; i < 8; i++) { - if (unk_2016A00.unk0[gUnknown_02024C08 >> 1][i] != 0 && gBattleMoves[unk_2016A00.unk0[gUnknown_02024C08 >> 1][i]].effect == gAIScriptPtr[2]) + if (unk_2016A00.unk0[gEnemyMonIndex >> 1][i] != 0 && gBattleMoves[unk_2016A00.unk0[gEnemyMonIndex >> 1][i]].effect == gAIScriptPtr[2]) break; } gAIScriptPtr += 7; @@ -1942,16 +1933,16 @@ static void BattleAICmd_if_not_move_effect(void) static void BattleAICmd_if_last_move_did_damage(void) { - u8 var; + u8 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; if (gAIScriptPtr[2] == 0) { - if (gUnknown_02024CA8[var].unk4 == 0) + if (gUnknown_02024CA8[index].unk4 == 0) { gAIScriptPtr += 7; return; @@ -1959,12 +1950,12 @@ static void BattleAICmd_if_last_move_did_damage(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); return; } - else if (gAIScriptPtr[2] != 1) + else if (gAIScriptPtr[2] != 1) // ignore the macro if its not 0 or 1. { gAIScriptPtr += 7; return; } - else if (gUnknown_02024CA8[var].unk6 != 0) + else if (gUnknown_02024CA8[index].unk6 != 0) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); return; @@ -1977,7 +1968,7 @@ static void BattleAICmd_if_encored(void) switch (gAIScriptPtr[1]) { case 0: // _08109348 - if (gUnknown_02024CA8[gUnknown_02024A60].unk4 == gAIThinkingSpace.unk2) + if (gUnknown_02024CA8[gUnknown_02024A60].unk4 == AI_THINKING_STRUCT->moveConsidered) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; @@ -1985,7 +1976,7 @@ static void BattleAICmd_if_encored(void) gAIScriptPtr += 6; return; case 1: // _08109370 - if (gUnknown_02024CA8[gUnknown_02024A60].unk6 == gAIThinkingSpace.unk2) + if (gUnknown_02024CA8[gUnknown_02024A60].unk6 == AI_THINKING_STRUCT->moveConsidered) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; @@ -1998,170 +1989,167 @@ static void BattleAICmd_if_encored(void) } } -static void BattleAICmd_unk_45(void) +static void BattleAICmd_flee(void) { - gAIThinkingSpace.unk10 |= 0xB; + AI_THINKING_STRUCT->aiAction |= (AI_ACTION_UNK1 | AI_ACTION_UNK2 | AI_ACTION_UNK4); // what matters is UNK2 being enabled. } -static void BattleAICmd_if_random_2(void) +static void BattleAICmd_if_random_100(void) { - u8 var = battle_2000000.unk88 * 5; + u8 safariFleeRate = BATTLE_STRUCT->safariFleeRate * 5; // safari flee rate, from 0-20 - if ((u8)(Random() % 100) < var) + if ((u8)(Random() % 100) < safariFleeRate) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; } -static void BattleAICmd_unk_47(void) +static void BattleAICmd_watch(void) { - gAIThinkingSpace.unk10 |= 0xD; + AI_THINKING_STRUCT->aiAction |= (AI_ACTION_UNK1 | AI_ACTION_UNK3 | AI_ACTION_UNK4); // what matters is UNK3 being enabled. } static void BattleAICmd_get_hold_effect(void) { - u8 var; + u8 index; u16 status; - u8 *aiPtr; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - if (battle_side_get_owner(var) == 0) + if (battle_side_get_owner(index) == 0) { - // weird pointer arithmetic is needed to match. - status = (battle_get_per_side_status(var) & 1); - aiPtr = (u8 *)&gAIThinkingSpace; - gAIThinkingSpace.funcResult = ((struct UnknownStruct1 *)((u8 *)aiPtr + 0x202))->unk20[status]; + status = (battle_get_per_side_status(index) & 1); + AI_THINKING_STRUCT->funcResult = UNK_2016A00_STRUCT->unk22[status]; } else - gAIThinkingSpace.funcResult = ItemId_GetHoldEffect(gBattleMons[var].item); + AI_THINKING_STRUCT->funcResult = ItemId_GetHoldEffect(gBattleMons[index].item); gAIScriptPtr += 2; } static void BattleAICmd_get_gender(void) { - u8 var; + u8 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - gAIThinkingSpace.funcResult = GetGenderFromSpeciesAndPersonality(gBattleMons[var].species, gBattleMons[var].personality); + AI_THINKING_STRUCT->funcResult = GetGenderFromSpeciesAndPersonality(gBattleMons[index].species, gBattleMons[index].personality); gAIScriptPtr += 2; } static void BattleAICmd_is_first_turn(void) { - u8 var; + u8 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk16; + AI_THINKING_STRUCT->funcResult = gUnknown_02024CA8[index].unk16; gAIScriptPtr += 2; } static void BattleAICmd_get_stockpile_count(void) { - u8 var; + u8 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk9; + AI_THINKING_STRUCT->funcResult = gUnknown_02024CA8[index].unk9; gAIScriptPtr += 2; } -static void BattleAICmd_unk_4C(void) +static void BattleAICmd_is_double_battle(void) { - gAIThinkingSpace.funcResult = gBattleTypeFlags & 1; + AI_THINKING_STRUCT->funcResult = gBattleTypeFlags & BATTLE_TYPE_DOUBLE; gAIScriptPtr += 1; } static void BattleAICmd_get_item(void) { - u8 var; + u8 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - // this hack and a half matches. whatever. i dont care. someone else fix this mess later. - ((struct AI_ThinkingStruct *)(unk_2000000 + 0x16800))->funcResult = unk_2000000[0x160CC + var * 2]; + // this hack and a half matches. whatever. i dont care. someone else fix this mess later. PS: still cant fix this. + AI_THINKING_STRUCT->funcResult = unk_2000000[0x160CC + (index * 2)]; gAIScriptPtr += 2; } -static void BattleAICmd_unk_4E(void) +static void BattleAICmd_get_move_type_from_result(void) { - gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].type; + AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->funcResult].type; gAIScriptPtr += 1; } -static void BattleAICmd_unk_4F(void) +static void BattleAICmd_get_move_power_from_result(void) { - gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].power; + AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->funcResult].power; gAIScriptPtr += 1; } -static void BattleAICmd_unk_50(void) +static void BattleAICmd_get_move_effect_from_result(void) { - gAIThinkingSpace.funcResult = gBattleMoves[gAIThinkingSpace.funcResult].effect; + AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->funcResult].effect; gAIScriptPtr += 1; } static void BattleAICmd_get_protect_count(void) { - u8 var; + u8 index; if (gAIScriptPtr[1] == USER) - var = gUnknown_02024C07; + index = gPlayerMonIndex; else - var = gUnknown_02024C08; + index = gEnemyMonIndex; - gAIThinkingSpace.funcResult = gUnknown_02024CA8[var].unk8; + AI_THINKING_STRUCT->funcResult = gUnknown_02024CA8[index].unk8; gAIScriptPtr += 2; } -static void BattleAICmd_unk_52(void) +static void BattleAICmd_nullsub_52(void) { } -static void BattleAICmd_unk_53(void) +static void BattleAICmd_nullsub_53(void) { } -static void BattleAICmd_unk_54(void) +static void BattleAICmd_nullsub_54(void) { } -static void BattleAICmd_unk_55(void) +static void BattleAICmd_nullsub_55(void) { } -static void BattleAICmd_unk_56(void) +static void BattleAICmd_nullsub_56(void) { } -static void BattleAICmd_unk_57(void) +static void BattleAICmd_nullsub_57(void) { } @@ -2176,34 +2164,34 @@ static void BattleAICmd_jump(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } -static void BattleAICmd_unk_5A(void) +static void BattleAICmd_end(void) { if (sub_8109908() == 0) - gAIThinkingSpace.unk10 |= 1; + AI_THINKING_STRUCT->aiAction |= AI_ACTION_UNK1; } static void BattleAICmd_if_level_cond(void) { switch (gAIScriptPtr[1]) { - case 0: - if (gBattleMons[gUnknown_02024C07].level > gBattleMons[gUnknown_02024C08].level) + case 0: // greater than + if (gBattleMons[gPlayerMonIndex].level > gBattleMons[gEnemyMonIndex].level) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; } gAIScriptPtr += 6; return; - case 1: - if (gBattleMons[gUnknown_02024C07].level < gBattleMons[gUnknown_02024C08].level) + case 1: // less than + if (gBattleMons[gPlayerMonIndex].level < gBattleMons[gEnemyMonIndex].level) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; } gAIScriptPtr += 6; return; - case 2: - if (gBattleMons[gUnknown_02024C07].level == gBattleMons[gUnknown_02024C08].level) + case 2: // equal + if (gBattleMons[gPlayerMonIndex].level == gBattleMons[gEnemyMonIndex].level) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; @@ -2215,7 +2203,7 @@ static void BattleAICmd_if_level_cond(void) static void BattleAICmd_if_taunted(void) { - if (gUnknown_02024CA8[gUnknown_02024C08].taunt) + if (gUnknown_02024CA8[gEnemyMonIndex].taunt != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -2223,7 +2211,7 @@ static void BattleAICmd_if_taunted(void) static void BattleAICmd_if_not_taunted(void) { - if (!(gUnknown_02024CA8[gUnknown_02024C08].taunt)) + if (gUnknown_02024CA8[gEnemyMonIndex].taunt == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; -- cgit v1.2.3 From f21587ea9eb1190ac2136d72deb7929c1e1169eb Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 11 Feb 2017 00:38:59 -0500 Subject: 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 --- src/battle_ai.c | 280 +++++++++++++++++++++----------------------------------- 1 file changed, 106 insertions(+), 174 deletions(-) (limited to 'src/battle_ai.c') 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 -- cgit v1.2.3 From 6035511c139549a0291b6b3d43b9b080f792b2b6 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 18 Mar 2017 04:00:15 +0100 Subject: reorganize and add new headers for many files --- src/battle_ai.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'src/battle_ai.c') diff --git a/src/battle_ai.c b/src/battle_ai.c index ceab60ca0..07f319e40 100644 --- a/src/battle_ai.c +++ b/src/battle_ai.c @@ -8,29 +8,10 @@ #include "rng.h" #include "species.h" #include "moves.h" - -#define AIScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) -#define AIScriptRead16(ptr) ((ptr)[0] | (ptr)[1] << 8) -#define AIScriptRead8(ptr) ((ptr)[0]) -#define AIScriptReadPtr(ptr) (u8*) AIScriptRead32(ptr) +#include "battle_ai.h" extern void sub_801CAF8(u8, u8); -enum -{ - TARGET, - USER -}; - -// AI states -enum -{ - AIState_SettingUp, - AIState_Processing, - AIState_FinishedProcessing, - AIState_DoNotProcess -}; - extern void move_effectiveness_something(u16, u8, u8); extern u16 gBattleTypeFlags; @@ -283,12 +264,6 @@ const u16 sDiscouragedPowerfulMoveEffects[] = 0xFFFF }; -void BattleAI_SetupAIData(void); -void BattleAI_DoAIProcessing(void); -void sub_810745C(void); -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) { -- cgit v1.2.3