summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorProjectRevoTPP <projectrevotpp@hotmail.com>2018-01-12 18:16:52 -0500
committerProjectRevoTPP <projectrevotpp@hotmail.com>2018-01-12 18:16:52 -0500
commit5d393adfcc1a994f9885a2720f3a0bb29afd5a6e (patch)
tree899158868dd5c91e98a28e475c856398d168444d /src
parent6a2e39eb97db47b542eea76c1e45df37184a0705 (diff)
start decompiling contest_ai
Diffstat (limited to 'src')
-rw-r--r--src/contest.c10
-rwxr-xr-xsrc/contest_ai.c113
2 files changed, 118 insertions, 5 deletions
diff --git a/src/contest.c b/src/contest.c
index 875fe4502..6a8887fb1 100644
--- a/src/contest.c
+++ b/src/contest.c
@@ -36,8 +36,8 @@ extern u8 AreMovesContestCombo(u16, u16); // I don't think this is a bool
extern void sub_80C8A38(u8);
extern void sub_80C8AD0(u8);
extern void sub_80C8C80(u8);
-extern void sub_81288F4();
-extern u8 sub_8128944(void);
+extern void ContestAI_ResetAI();
+extern u8 ContestAI_GetActionToUse(void);
extern struct MusicPlayerInfo gMPlay_SE1;
extern u16 gSpecialVar_ContestCategory;
@@ -391,7 +391,7 @@ void ClearContestVars(void)
}
memset(&shared192D0, 0, sizeof(shared192D0));
- memset(shared192E4, 0, 0x44 * sizeof(*shared192E4));
+ memset(eContestAI, 0, sizeof(struct ContestAIInfo));
memset(&shared19328, 0, sizeof(shared19328));
memset(shared19338, 0, 4 * sizeof(*shared19338));
if (!(gIsLinkContest & 1))
@@ -2629,8 +2629,8 @@ u16 GetChosenMove(u8 a)
{
u8 moveChoice;
- sub_81288F4(a);
- moveChoice = sub_8128944();
+ ContestAI_ResetAI(a);
+ moveChoice = ContestAI_GetActionToUse();
return gContestMons[a].moves[moveChoice];
}
}
diff --git a/src/contest_ai.c b/src/contest_ai.c
new file mode 100755
index 000000000..9dfa6c2b9
--- /dev/null
+++ b/src/contest_ai.c
@@ -0,0 +1,113 @@
+#include "global.h"
+#include "contest.h"
+#include "random.h"
+#include "ewram.h"
+
+enum
+{
+ ContestAI_SettingUp,
+ ContestAI_Processing,
+ ContestAI_FinishedProcessing,
+ ContestAI_DoNotProcess
+};
+
+extern u8 *gAIScriptPtr;
+extern u8 *gContestAIs[];
+
+typedef void (* ContestAICmdFunc)(void);
+
+extern const ContestAICmdFunc sContestAICmdTable[]; // TODO: Move table to C file
+
+void ContestAI_DoAIProcessing(void);
+
+void ContestAI_ResetAI(u8 var)
+{
+ int i;
+ memset(eContestAI, 0, sizeof(struct ContestAIInfo));
+
+ for(i = 0; i < 4; i++)
+ eContestAI->unk5[i] = 100;
+
+ eContestAI->unk41 = var;
+ eContestAI->unk40 = 0;
+ eContestAI->flags = gContestMons[eContestAI->unk41].flags;
+}
+
+u8 ContestAI_GetActionToUse(void)
+{
+ while(eContestAI->flags != 0)
+ {
+ if(eContestAI->flags & 1)
+ {
+ eContestAI->aiState = 0;
+ ContestAI_DoAIProcessing();
+ }
+ eContestAI->flags >>= 1;
+ eContestAI->unk10++;
+ eContestAI->unk4 = 0;
+ }
+
+ while (1)
+ {
+ u8 rval = Random() & 3;
+ u8 r2 = eContestAI->unk5[rval];
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ if (r2 < eContestAI->unk5[i])
+ break;
+ }
+ if (i == 4)
+ return rval;
+ }
+}
+
+void ContestAI_DoAIProcessing(void)
+{
+ while(eContestAI->aiState != ContestAI_FinishedProcessing)
+ {
+ switch(eContestAI->aiState)
+ {
+ case ContestAI_DoNotProcess:
+ break;
+ case ContestAI_SettingUp:
+ gAIScriptPtr = gContestAIs[eContestAI->unk10];
+
+ if(gContestMons[eContestAI->unk41].moves[eContestAI->unk4] == 0)
+ eContestAI->unk2 = 0; // don't process a move that doesn't exist.
+ else
+ eContestAI->unk2 = gContestMons[eContestAI->unk41].moves[eContestAI->unk4];
+ eContestAI->aiState++;
+ break;
+ case ContestAI_Processing:
+ if(eContestAI->unk2 != 0)
+ sContestAICmdTable[*gAIScriptPtr](); // run the command.
+ else
+ {
+ eContestAI->unk5[eContestAI->unk4] = 0; // don't consider a move that doesn't exist.
+ eContestAI->aiAction |= 1;
+ }
+ if(eContestAI->aiAction & 1)
+ {
+ eContestAI->unk4++;
+ if(eContestAI->unk4 < 4)
+ eContestAI->aiState = 0;
+ else
+ eContestAI->aiState++;
+ eContestAI->aiAction &= 0xFE; // TODO: Define action flags
+ }
+ break;
+ }
+ }
+}
+
+u8 sub_8128A7C(u8 var)
+{
+ int i;
+
+ for(i = 0; i < 4; i++)
+ if(shared192D0.unk0[i] == var)
+ break;
+
+ return i;
+}