summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/battle_ai.c203
-rw-r--r--src/field_control_avatar.c229
-rw-r--r--src/pokemon_2.c8
3 files changed, 316 insertions, 124 deletions
diff --git a/src/battle_ai.c b/src/battle_ai.c
index e60bf478f..7c9b7f17e 100644
--- a/src/battle_ai.c
+++ b/src/battle_ai.c
@@ -4,6 +4,7 @@
#include "pokemon.h"
#include "rng.h"
#include "abilities.h"
+#include "species.h"
#define AIScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24)
#define AIScriptRead16(ptr) ((ptr)[0] | (ptr)[1] << 8)
@@ -20,6 +21,7 @@ extern void move_effectiveness_something(u16, u8, u8);
extern u16 gBattleTypeFlags;
extern u8 gUnknown_02024A60;
+extern u8 gUnknown_02024A6A[][2];
extern u16 gUnknown_02024BE6;
extern u32 gUnknown_02024BEC;
extern u8 gUnknown_02024C07; // something player?
@@ -1042,128 +1044,52 @@ void BattleAICmd_unk_2A(void)
void BattleAICmd_unk_2B(void)
{}
-__attribute__((naked))
void BattleAICmd_count_alive_pokemon(void)
{
- asm(".syntax unified\n\
- push {r4-r7,lr}\n\
- mov r7, r9\n\
- mov r6, r8\n\
- push {r6,r7}\n\
- ldr r1, _08108550 @ =0x02016800\n\
- movs r0, 0\n\
- str r0, [r1, 0x8]\n\
- ldr r0, _08108554 @ =gAIScriptPtr\n\
- ldr r0, [r0]\n\
- ldrb r0, [r0, 0x1]\n\
- cmp r0, 0x1\n\
- bne _0810855C\n\
- ldr r0, _08108558 @ =gUnknown_02024C07\n\
- b _0810855E\n\
- .align 2, 0\n\
-_08108550: .4byte 0x02016800\n\
-_08108554: .4byte gAIScriptPtr\n\
-_08108558: .4byte gUnknown_02024C07\n\
-_0810855C:\n\
- ldr r0, _081085A8 @ =gUnknown_02024C08\n\
-_0810855E:\n\
- ldrb r5, [r0]\n\
- adds r0, r5, 0\n\
- bl battle_side_get_owner\n\
- lsls r0, 24\n\
- ldr r1, _081085AC @ =gEnemyParty\n\
- mov r9, r1\n\
- cmp r0, 0\n\
- bne _08108574\n\
- ldr r0, _081085B0 @ =gPlayerParty\n\
- mov r9, r0\n\
-_08108574:\n\
- ldr r0, _081085B4 @ =gBattleTypeFlags\n\
- ldrh r1, [r0]\n\
- movs r0, 0x1\n\
- ands r0, r1\n\
- cmp r0, 0\n\
- beq _081085BC\n\
- ldr r4, _081085B8 @ =gUnknown_02024A6A\n\
- lsls r0, r5, 1\n\
- adds r0, r4\n\
- ldrb r0, [r0]\n\
- mov r8, r0\n\
- adds r0, r5, 0\n\
- bl battle_get_per_side_status\n\
- movs r1, 0x2\n\
- eors r0, r1\n\
- lsls r0, 24\n\
- lsrs r0, 24\n\
- bl battle_get_side_with_given_state\n\
- lsls r0, 24\n\
- lsrs r0, 23\n\
- adds r0, r4\n\
- ldrb r6, [r0]\n\
- b _081085C6\n\
- .align 2, 0\n\
-_081085A8: .4byte gUnknown_02024C08\n\
-_081085AC: .4byte gEnemyParty\n\
-_081085B0: .4byte gPlayerParty\n\
-_081085B4: .4byte gBattleTypeFlags\n\
-_081085B8: .4byte gUnknown_02024A6A\n\
-_081085BC:\n\
- ldr r1, _08108624 @ =gUnknown_02024A6A\n\
- lsls r0, r5, 1\n\
- adds r0, r1\n\
- ldrb r6, [r0]\n\
- mov r8, r6\n\
-_081085C6:\n\
- movs r5, 0\n\
- ldr r7, _08108628 @ =0x02016800\n\
-_081085CA:\n\
- cmp r5, r8\n\
- beq _08108608\n\
- cmp r5, r6\n\
- beq _08108608\n\
- movs r0, 0x64\n\
- muls r0, r5\n\
- mov r1, r9\n\
- adds r4, r1, r0\n\
- adds r0, r4, 0\n\
- movs r1, 0x39\n\
- bl GetMonData\n\
- cmp r0, 0\n\
- beq _08108608\n\
- adds r0, r4, 0\n\
- movs r1, 0x41\n\
- bl GetMonData\n\
- cmp r0, 0\n\
- beq _08108608\n\
- adds r0, r4, 0\n\
- movs r1, 0x41\n\
- bl GetMonData\n\
- movs r1, 0xCE\n\
- lsls r1, 1\n\
- cmp r0, r1\n\
- beq _08108608\n\
- ldr r0, [r7, 0x8]\n\
- adds r0, 0x1\n\
- str r0, [r7, 0x8]\n\
-_08108608:\n\
- adds r5, 0x1\n\
- cmp r5, 0x5\n\
- ble _081085CA\n\
- ldr r1, _0810862C @ =gAIScriptPtr\n\
- ldr r0, [r1]\n\
- adds r0, 0x2\n\
- str r0, [r1]\n\
- pop {r3,r4}\n\
- mov r8, r3\n\
- mov r9, r4\n\
- pop {r4-r7}\n\
- pop {r0}\n\
- bx r0\n\
- .align 2, 0\n\
-_08108624: .4byte gUnknown_02024A6A\n\
-_08108628: .4byte 0x02016800\n\
-_0810862C: .4byte gAIScriptPtr\n\
- .syntax divided");
+ u8 index;
+ struct Pokemon *party;
+ struct AI_ThinkingStruct *ai = &battle_2000000.ai;
+ int i;
+ u8 var, var2;
+
+ ai->unk8 = 0;
+
+ if (gAIScriptPtr[1] == USER)
+ index = gUnknown_02024C07;
+ else
+ index = gUnknown_02024C08;
+
+ if (battle_side_get_owner(index) == 0)
+ party = gPlayerParty;
+ else
+ party = gEnemyParty;
+
+ if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
+ {
+ u32 status;
+ var = gUnknown_02024A6A[index][0];
+ status = battle_get_per_side_status(index) ^ 2;
+ var2 = gUnknown_02024A6A[battle_get_side_with_given_state(status)][0];
+ }
+ else
+ {
+ var = gUnknown_02024A6A[index][0];
+ var2 = gUnknown_02024A6A[index][0];
+ }
+
+ 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->unk8++;
+ }
+ }
+
+ gAIScriptPtr += 2;
}
void BattleAICmd_unk_2D(void)
@@ -1403,3 +1329,40 @@ void BattleAICmd_unk_32(void)
void BattleAICmd_unk_33(void)
{}
+
+void BattleAICmd_if_status_in_party(void)
+{
+ struct Pokemon *party;
+ 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
+ {
+ party = gPlayerParty;
+ }
+
+ 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);
+
+ if (species != SPECIES_NONE && species != SPECIES_EGG && hp != 0 && status == statusToCompareTo)
+ goto follow_jump;
+ }
+
+ gAIScriptPtr += 10;
+}
diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c
new file mode 100644
index 000000000..495327b9b
--- /dev/null
+++ b/src/field_control_avatar.c
@@ -0,0 +1,229 @@
+#include "global.h"
+#include "asm.h"
+#include "field_player_avatar.h"
+#include "metatile_behavior.h"
+#include "rom4.h"
+#include "script.h"
+#include "sound.h"
+#include "trainer_see.h"
+
+extern u8 gUnknown_0815281E[];
+extern u8 gUnknown_08152C39[];
+extern u8 gUnknown_0815F36C[];
+extern u8 gUnknown_0815F43A[];
+extern u8 gUnknown_081A0009[];
+
+__attribute__((naked))
+void sub_8067EEC(struct UnkInputStruct *s)
+{
+ asm(".syntax unified\n\
+ push {r4,r5,lr}\n\
+ movs r1, 0x2\n\
+ negs r1, r1\n\
+ movs r3, 0x3\n\
+ negs r3, r3\n\
+ movs r4, 0x5\n\
+ negs r4, r4\n\
+ movs r5, 0x9\n\
+ negs r5, r5\n\
+ movs r2, 0\n\
+ strb r2, [r0]\n\
+ ldrb r2, [r0, 0x1]\n\
+ ands r1, r2\n\
+ ands r1, r3\n\
+ ands r1, r4\n\
+ ands r1, r5\n\
+ strb r1, [r0, 0x1]\n\
+ movs r1, 0\n\
+ strb r1, [r0, 0x2]\n\
+ pop {r4,r5}\n\
+ pop {r0}\n\
+ bx r0\n\
+ .syntax divided\n");
+}
+
+extern u16 cur_mapdata_block_role_at_player_pos(int);
+
+void process_overworld_input(struct UnkInputStruct *pStruct, u16 keys, u16 heldKeys)
+{
+ u8 r6 = gPlayerAvatar.running1;
+ u8 r9 = gPlayerAvatar.running2;
+ bool8 r7 = MetatileBehavior_IsMoveTile(cur_mapdata_block_role_at_player_pos(r9));
+
+ if ((r6 == 2 && r7 == FALSE) || r6 == 0)
+ {
+ if (sub_80E6034() != 4)
+ {
+ if (keys & START_BUTTON)
+ pStruct->input_field_0_2 = TRUE;
+ if (keys & SELECT_BUTTON)
+ pStruct->input_field_0_3 = TRUE;
+ if (keys & A_BUTTON)
+ pStruct->input_field_0_0 = TRUE;
+ if (keys & B_BUTTON)
+ pStruct->input_field_0_7 = TRUE;
+ }
+ if (heldKeys & (DPAD_UP | DPAD_DOWN | DPAD_LEFT | DPAD_RIGHT))
+ {
+ pStruct->input_field_0_4 = TRUE;
+ pStruct->input_field_0_5 = TRUE;
+ }
+ }
+ if (r7 == FALSE)
+ {
+ if (r6 == 2 && r9 == 2)
+ pStruct->input_field_0_6 = TRUE;
+ if (r7 == FALSE && r6 == 2)
+ pStruct->input_field_0_1 = TRUE;
+ }
+ if (heldKeys & DPAD_UP)
+ pStruct->input_field_2 = 2;
+ else if (heldKeys & DPAD_DOWN)
+ pStruct->input_field_2 = 1;
+ else if (heldKeys & DPAD_LEFT)
+ pStruct->input_field_2 = 3;
+ else if (heldKeys & DPAD_RIGHT)
+ pStruct->input_field_2 = 4;
+}
+
+struct MapPosition
+{
+ s16 x;
+ s16 y;
+ u8 height;
+};
+
+void player_get_pos_to_and_height(struct MapPosition *);
+extern u8 mapheader_run_first_tag2_script_list_match(void);
+extern int sub_80687A4(void);
+extern u8 sub_80687E4();
+extern u8 is_it_battle_time_3();
+extern u8 mapheader_run_first_tag2_script_list_match_conditionally();
+void player_get_next_pos_and_height(struct MapPosition *);
+u8 sub_80681F0(struct MapPosition *position, u16 b, u8 c);
+extern u8 map_warp_consider_2_to_inside();
+extern int sub_8068770(void);
+extern void sub_8071310(void);
+extern int sub_80A6D1C(void);
+
+int sub_8068024(struct UnkInputStruct *s)
+{
+ struct MapPosition position;
+ u8 r6;
+ u16 r4;
+
+ r6 = player_get_direction_lower_nybble();
+ player_get_pos_to_and_height(&position);
+ r4 = MapGridGetMetatileBehaviorAt(position.x, position.y);
+ if (CheckTrainers() == TRUE)
+ return 1;
+ if (mapheader_run_first_tag2_script_list_match() == 1)
+ return 1;
+ if (s->input_field_0_7 && sub_80687A4() == 1)
+ return 1;
+ if (s->input_field_0_6)
+ {
+ IncrementGameStat(5);
+ if (sub_80687E4(&position, r4, r6) == 1)
+ return 1;
+ }
+ if (s->input_field_0_1 && is_it_battle_time_3(r4) == 1)
+ return 1;
+ if (s->input_field_0_4 && s->input_field_2 == r6)
+ {
+ if (mapheader_run_first_tag2_script_list_match_conditionally(&position, r4, r6) == 1)
+ return 1;
+ }
+ player_get_next_pos_and_height(&position);
+ r4 = MapGridGetMetatileBehaviorAt(position.x, position.y);
+ if (s->input_field_0_0 && sub_80681F0(&position, r4, r6) == 1)
+ return 1;
+ if (s->input_field_0_5 && s->input_field_2 == r6)
+ {
+ if (map_warp_consider_2_to_inside(&position, r4, r6) == 1)
+ return 1;
+ }
+ if (s->input_field_0_0 && sub_8068770() == 1)
+ return 1;
+ if (s->input_field_0_2)
+ {
+ PlaySE(6);
+ sub_8071310();
+ return 1;
+ }
+ //_08068154
+ if (s->input_field_0_3 && sub_80A6D1C() == 1)
+ return 1;
+ return FALSE;
+}
+
+void player_get_pos_to_and_height(struct MapPosition *position)
+{
+ PlayerGetDestCoords(&position->x, &position->y);
+ position->height = PlayerGetZCoord();
+}
+
+void player_get_next_pos_and_height(struct MapPosition *position)
+{
+ s16 x, y;
+
+ GetXYCoordsOneStepInFrontOfPlayer(&position->x, &position->y);
+ PlayerGetDestCoords(&x, &y);
+ if (MapGridGetZCoordAt(x, y) != 0)
+ position->height = PlayerGetZCoord();
+ else
+ position->height = 0;
+}
+
+u16 cur_mapdata_block_role_at_player_pos(int unused)
+{
+ s16 x, y;
+
+ PlayerGetDestCoords(&x, &y);
+ return MapGridGetMetatileBehaviorAt(x, y);
+}
+
+u8 *TryGetScriptOnPressingA(struct MapPosition *position, u8 b, u8 c);
+
+u8 sub_80681F0(struct MapPosition *position, u16 b, u8 c)
+{
+ u8 *script = TryGetScriptOnPressingA(position, b, c);
+
+ if (script == NULL)
+ return FALSE;
+
+ if (script != gUnknown_0815281E
+ && script != gUnknown_08152C39
+ && script != gUnknown_0815F36C
+ && script != gUnknown_0815F43A
+ && script != gUnknown_081A0009)
+ PlaySE(5);
+
+ ScriptContext1_SetupScript(script);
+ return TRUE;
+}
+
+u8 *sub_8068364();
+u8 *TryGetInvisibleMapObjectScript();
+u8 *sub_8068500();
+u8 *TryGetFieldMoveScript();
+
+u8 *TryGetScriptOnPressingA(struct MapPosition *position, u8 b, u8 c)
+{
+ u8 *script;
+
+ script = sub_8068364(position, b, c);
+ if (script != NULL)
+ return script;
+ script = TryGetInvisibleMapObjectScript(position, b, c);
+ if (script != NULL)
+ return script;
+ script = sub_8068500(position, b, c);
+ if (script != NULL)
+ return script;
+ script = TryGetFieldMoveScript(position, b, c);
+ if (script != NULL)
+ return script;
+
+ return NULL;
+}
diff --git a/src/pokemon_2.c b/src/pokemon_2.c
index 8b55baaba..f6bd432c7 100644
--- a/src/pokemon_2.c
+++ b/src/pokemon_2.c
@@ -484,7 +484,7 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
retVal = boxMon->unknown;
break;
case MON_DATA_SPECIES:
- retVal = boxMon->isBadEgg ? 412 : substruct0->species;
+ retVal = boxMon->isBadEgg ? SPECIES_EGG : substruct0->species;
break;
case MON_DATA_HELD_ITEM:
retVal = substruct0->heldItem;
@@ -645,7 +645,7 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
case MON_DATA_SPECIES2:
retVal = substruct0->species;
if (substruct0->species && (substruct3->isEgg || boxMon->isBadEgg))
- retVal = 412;
+ retVal = SPECIES_EGG;
break;
case MON_DATA_IVS:
retVal = substruct3->hpIV | (substruct3->attackIV << 5) | (substruct3->defenseIV << 10) | (substruct3->speedIV << 15) | (substruct3->spAttackIV << 20) | (substruct3->spDefenseIV << 25);
@@ -1130,7 +1130,7 @@ u8 sub_803DAA0(void)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0
&& GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_NONE
- && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != 412)
+ && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_EGG)
aliveCount++;
}
@@ -1232,7 +1232,7 @@ void GetSpeciesName(u8 *name, u16 species)
for (i = 0; i <= POKEMON_NAME_LENGTH; i++)
{
- if (species > 412)
+ if (species > NUM_SPECIES)
name[i] = gSpeciesNames[0][i];
else
name[i] = gSpeciesNames[species][i];