failed nonmatch attempt, better arg names given I guess

This commit is contained in:
DizzyEggg 2017-09-08 18:19:20 +02:00
parent ba1c066d57
commit 8544804758
2 changed files with 108 additions and 65 deletions

View File

@ -329,7 +329,55 @@ struct BattleStruct
u8 field_18[0x63]; // TODO: expand u8 field_18[0x63]; // TODO: expand
u8 field_7B; u8 field_7B;
u8 field_7C; u8 field_7C;
u8 field_7D[60]; u8 field_7D;
u8 field_7E;
u8 formToChangeInto;
u8 chosenMovesIds[4];
u8 field_84;
u8 field_85;
u8 field_86;
u8 field_87;
u8 field_88;
u8 field_89;
u8 field_8A;
u8 field_8B;
u8 field_8C;
u8 field_8D;
u8 field_8E;
u8 expGetterBank;
u8 field_90;
u8 field_91;
u8 field_92;
u8 field_93;
u8 field_94;
u8 field_95;
u8 field_96;
u8 field_97;
u8 field_98;
u8 field_99;
u8 field_9A;
u8 field_9B;
u8 field_9C;
u8 field_9D;
u8 field_9E;
u8 field_9F;
u8 field_A0;
u8 field_A1;
u8 field_A2;
u8 field_A3;
u8 field_A4;
u8 field_A5;
u8 field_A6;
u8 field_A7;
u16 hpOnSwitchout[4];
u8 field_B0;
u8 hpScale;
u8 synchronizeMoveEffect;
u8 field_B3;
u8 field_B4;
u8 field_B5;
u8 field_B6;
u8 field_B7;
u16 usedHeldItems[4]; u16 usedHeldItems[4];
}; };

View File

@ -444,10 +444,10 @@ static u8 BattleAI_ChooseMoveOrAction_Singles(void)
AI_THINKING_STRUCT->movesetIndex = 0; AI_THINKING_STRUCT->movesetIndex = 0;
} }
// special flags for safari watch/flee. // special flags for safari
if (AI_THINKING_STRUCT->aiAction & 2) if (AI_THINKING_STRUCT->aiAction & AI_ACTION_FLEE)
return 4; return 4;
if (AI_THINKING_STRUCT->aiAction & 4) if (AI_THINKING_STRUCT->aiAction & AI_ACTION_WATCH)
return 5; return 5;
numOfBestMoves = 1; numOfBestMoves = 1;
@ -480,33 +480,29 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void)
{ {
s32 i; s32 i;
s32 j; s32 j;
//s32 r4_2; s32 scriptsToRun;
#define r4_2 r4 s16 mostMovePoints;
s32 r5; s16 bestMovePointsForTarget[4];
s16 r5_2; s8 mostViableTargetsArray[4];
s32 r4; u8 actionOrMoveIndex[4];
s16 sp0[4]; u8 mostViableMovesScores[4];
s8 sp8[4]; u8 mostViableMovesIndices[4];
s8 spC[4]; s32 mostViableTargetsNo;
u8 sp10[4]; // definitely unsigned s32 mostViableMovesNo;
u8 sp14[4];
//u8 *sp1C = spC;
//u8 *sp18 = sp8;
//u8 *sp20 = spC;
for (i = 0; i < 4; i++) //_08130D14 for (i = 0; i < 4; i++) //08130D14
{ {
if (i == sBank_AI || gBattleMons[i].hp == 0) if (i == sBank_AI || gBattleMons[i].hp == 0)
{ {
//_08130D2E //_08130D2E
spC[i] = -1; actionOrMoveIndex[i] = -1;
sp0[i] = -1; bestMovePointsForTarget[i] = -1;
} }
//_08130D48 //_08130D48
else else
{ {
if (gBattleTypeFlags & 0x20000) if (gBattleTypeFlags & BATTLE_TYPE_PALACE)
BattleAI_SetupAIData(gBattleStruct[0x92] >> 4); BattleAI_SetupAIData(gBattleStruct->field_92 >> 4);
else else
BattleAI_SetupAIData(0xF); BattleAI_SetupAIData(0xF);
//_08130D76 //_08130D76
@ -514,84 +510,83 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void)
if ((i & 1) != (sBank_AI & 1)) if ((i & 1) != (sBank_AI & 1))
RecordLastUsedMoveByTarget(); RecordLastUsedMoveByTarget();
//_08130D90 //_08130D90
AI_THINKING_STRUCT->unk11 = 0; AI_THINKING_STRUCT->aiLogicId = 0;
AI_THINKING_STRUCT->unk1 = 0; AI_THINKING_STRUCT->movesetIndex = 0;
r4 = AI_THINKING_STRUCT->aiFlags; scriptsToRun = AI_THINKING_STRUCT->aiFlags;
while (r4 != 0) while (scriptsToRun != 0)
{ {
if (r4 & 1) if (scriptsToRun & 1)
{ {
AI_THINKING_STRUCT->aiState = AIState_SettingUp; AI_THINKING_STRUCT->aiState = AIState_SettingUp;
BattleAI_DoAIProcessing(); BattleAI_DoAIProcessing();
} }
r4 >>= 1; scriptsToRun >>= 1;
AI_THINKING_STRUCT->unk11++; AI_THINKING_STRUCT->aiLogicId++;
AI_THINKING_STRUCT->unk1 = 0; AI_THINKING_STRUCT->movesetIndex = 0;
} }
//_08130DD8 //_08130DD8
if (AI_THINKING_STRUCT->unk10 & 2) if (AI_THINKING_STRUCT->aiAction & AI_ACTION_FLEE)
spC[i] = 4; actionOrMoveIndex[i] = 4;
else if (AI_THINKING_STRUCT->unk10 & 4) else if (AI_THINKING_STRUCT->aiAction & AI_ACTION_WATCH)
spC[i] = 5; actionOrMoveIndex[i] = 5;
else else
{ {
//_08130E10 //_08130E10
sp10[0] = AI_THINKING_STRUCT->score[0]; mostViableMovesScores[0] = AI_THINKING_STRUCT->score[0];
sp14[0] = 0; mostViableMovesIndices[0] = 0;
r5 = 1; mostViableMovesNo = 1;
for (j = 1; j < 4; j++) for (j = 1; j < 4; j++)
{ {
if (gBattleMons[sBank_AI].moves[j] != 0) if (gBattleMons[sBank_AI].moves[j] != 0)
{ {
if (sp10[0] == AI_THINKING_STRUCT->score[j]) if (mostViableMovesScores[0] == AI_THINKING_STRUCT->score[j])
{ {
sp10[r5] = AI_THINKING_STRUCT->score[j]; mostViableMovesScores[mostViableMovesNo] = AI_THINKING_STRUCT->score[j];
sp14[r5] = j; mostViableMovesIndices[mostViableMovesNo] = j;
r5++; mostViableMovesNo++;
} }
if (sp10[0] < AI_THINKING_STRUCT->score[j]) if (mostViableMovesScores[0] < AI_THINKING_STRUCT->score[j])
{ {
sp10[0] = AI_THINKING_STRUCT->score[j]; mostViableMovesScores[0] = AI_THINKING_STRUCT->score[j];
sp14[0] = j; mostViableMovesIndices[0] = j;
r5 = 1; mostViableMovesNo = 1;
} }
} }
//_08130E72 //_08130E72
} }
spC[i] = sp14[Random() % r5]; actionOrMoveIndex[i] = mostViableMovesIndices[Random() % mostViableMovesNo];
//asm("":::"r3"); bestMovePointsForTarget[i] = mostViableMovesScores[0];
sp0[i] = sp10[0];
if (i == (sBank_AI ^ 2) && sp0[i] < 100) // don't use a move against ally if it has less than 100 pts
sp0[i] = -1; if (i == (sBank_AI ^ 2) && bestMovePointsForTarget[i] < 100)
bestMovePointsForTarget[i] = -1;
} }
} }
//_08130EAE //_08130EAE
} }
//#define i r5 //08130EC4
mostMovePoints = bestMovePointsForTarget[0];
//_08130EC4 mostViableTargetsArray[0] = 0;
r5_2 = sp0[0]; mostViableTargetsNo = 1;
sp8[0] = 0;
r4_2 = 1;
for (i = 1; i < 4; i++) for (i = 1; i < 4; i++)
{ {
//_08130EDA //_08130EDA
if (r5_2 == sp0[i]) if (mostMovePoints == bestMovePointsForTarget[i])
{ {
sp8[r4_2] = i; mostViableTargetsArray[mostViableTargetsNo] = i;
r4_2++; mostViableTargetsNo++;
} }
//_08130EEE //_08130EEE
if (r5_2 < sp0[i]) if (mostMovePoints < bestMovePointsForTarget[i])
{ {
r5_2 = sp0[i]; mostMovePoints = bestMovePointsForTarget[i];
sp8[0] = i; mostViableTargetsArray[0] = i;
r4_2 = 1; mostViableTargetsNo = 1;
} }
} }
gBankTarget = sp8[Random() % r4_2]; gBankTarget = mostViableTargetsArray[Random() % mostViableTargetsNo];
return spC[gBankTarget]; return actionOrMoveIndex[gBankTarget];
} }
#else #else
__attribute__((naked)) __attribute__((naked))