summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/battle_ai.c572
-rw-r--r--src/braille_puzzles.c262
-rw-r--r--src/field_control_avatar.c158
-rw-r--r--src/fldeff_teleport.c50
-rw-r--r--src/map_name_popup.c106
-rw-r--r--src/name_string_util.c39
-rw-r--r--src/rom4.c8
-rw-r--r--src/string_util.c85
-rw-r--r--src/unknown_debug_menu.c52
9 files changed, 1021 insertions, 311 deletions
diff --git a/src/battle_ai.c b/src/battle_ai.c
index 4727b2eb0..ca767a3a3 100644
--- a/src/battle_ai.c
+++ b/src/battle_ai.c
@@ -6,13 +6,14 @@
#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)
#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 +32,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[];
@@ -51,7 +52,6 @@ extern u8 *BattleAIs[];
extern struct Trainer gTrainers[];
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[];
@@ -100,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);
@@ -248,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;
@@ -303,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();
@@ -313,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();
@@ -323,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();
@@ -333,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();
@@ -343,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.
@@ -353,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;
@@ -368,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;
@@ -383,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;
@@ -398,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;
@@ -413,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;
@@ -431,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;
@@ -449,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;
@@ -467,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;
@@ -485,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;
@@ -503,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;
@@ -521,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;
@@ -541,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;
@@ -561,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);
@@ -569,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);
@@ -577,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);
@@ -585,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);
@@ -593,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);
@@ -603,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);
@@ -613,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);
@@ -623,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);
@@ -633,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);
@@ -643,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);
@@ -653,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);
@@ -669,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);
@@ -685,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);
@@ -701,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);
@@ -717,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;
@@ -733,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;
@@ -749,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];
@@ -780,14 +995,78 @@ 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
+static void BattleAICmd_unk_24(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])
+ break;
+
+ if (gBattleMoves[AI_THINKING_STRUCT->unk2].power > 1
+ && sDiscouragedPowerfulMoveEffects[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; sDiscouragedPowerfulMoveEffects[j] != 0xFFFF; j++)
+ {
+ if (gBattleMoves[gBattleMons[gUnknown_02024C07].moves[i]].effect == sDiscouragedPowerfulMoveEffects[j])
+ break;
+ }
+
+ if (gBattleMons[gUnknown_02024C07].moves[i]
+ && sDiscouragedPowerfulMoveEffects[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)
+static void BattleAICmd_unk_24(void)
{
asm(".syntax unified\n\
push {r4-r7,lr}\n\
@@ -797,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\
@@ -810,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\
@@ -832,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\
@@ -850,13 +1129,13 @@ _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\
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\
@@ -885,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\
@@ -907,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\
@@ -933,7 +1212,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\
@@ -949,19 +1228,19 @@ _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\
_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,8 +1308,9 @@ _081083B8:\n\
_081083D0: .4byte gAIScriptPtr\n\
.syntax divided\n");
}
+#endif // NONMATCHING
-void BattleAICmd_get_move(void)
+static void BattleAICmd_get_move(void)
{
if (gAIScriptPtr[1] == USER)
gAIThinkingSpace.funcResult = gUnknown_02024C34[gUnknown_02024C07];
@@ -1040,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);
@@ -1048,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);
@@ -1056,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);
@@ -1064,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);
@@ -1072,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;
@@ -1126,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;
@@ -1207,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;
@@ -1216,14 +1496,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,27 +1511,27 @@ 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;
}
-void BattleAICmd_if_damage_bonus(void)
+static void BattleAICmd_if_damage_bonus(void)
{
struct AI_ThinkingStruct *ai;
u8 damageVar;
@@ -1259,41 +1539,41 @@ 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
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;
@@ -1330,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;
@@ -1365,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;
@@ -1379,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);
@@ -1387,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);
@@ -1395,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;
@@ -1410,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;
@@ -1425,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;
@@ -1440,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;
@@ -1455,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)
{
@@ -1465,25 +1745,25 @@ 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;
}
-void BattleAICmd_if_cant_faint(void)
+static void BattleAICmd_if_cant_faint(void)
{
if(gBattleMoves[gAIThinkingSpace.unk2].power < 2)
{
@@ -1494,23 +1774,23 @@ 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;
}
-void BattleAICmd_unk_3F(void)
+static void BattleAICmd_unk_3F(void)
{
int i;
u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2);
@@ -1554,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);
@@ -1598,7 +1878,7 @@ void BattleAICmd_unk_40(void)
}
}
-void BattleAICmd_if_move_effect(void)
+static void BattleAICmd_if_move_effect(void)
{
int i;
@@ -1627,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;
@@ -1656,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;
@@ -1688,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])
{
@@ -1714,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;
@@ -1729,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;
@@ -1758,7 +2038,7 @@ void BattleAICmd_get_hold_effect(void)
gAIScriptPtr += 2;
}
-void BattleAICmd_get_gender(void)
+static void BattleAICmd_get_gender(void)
{
u8 var;
@@ -1772,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;
@@ -1786,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;
@@ -1800,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;
@@ -1822,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;
@@ -1857,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])
{
@@ -1917,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);
@@ -1925,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);
diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c
new file mode 100644
index 000000000..1493f1793
--- /dev/null
+++ b/src/braille_puzzles.c
@@ -0,0 +1,262 @@
+#include "global.h"
+#include "event_data.h"
+#include "flags.h"
+#include "asm.h"
+#include "field_camera.h"
+#include "field_effect.h"
+#include "map_obj_lock.h"
+#include "sound.h"
+#include "script.h"
+#include "songs.h"
+#include "species.h"
+#include "task.h"
+#include "menu.h"
+
+extern u8 gPlayerPartyCount;
+extern u8 gUnknown_03005CE0;
+
+extern u32 gUnknown_0202FF84[];
+
+extern u8 gUnknown_0815EF19[];
+
+void UseFlyAncientTomb_Callback(void);
+void UseFlyAncientTomb_Finish(void);
+void Task_BrailleWait(u8 taskId);
+bool32 BrailleWait_CheckButtonPress(void);
+void SealedChamberShakingEffect(u8 taskId);
+
+bool8 ShouldDoBrailleDigEffect(void)
+{
+ if(!FlagGet(SYS_BRAILLE_DIG) && (gSaveBlock1.location.mapGroup == 0x18 && gSaveBlock1.location.mapNum == 0x47))
+ {
+ if(gSaveBlock1.pos.x == 10 && gSaveBlock1.pos.y == 3)
+ return TRUE;
+ else if(gSaveBlock1.pos.x == 9 && gSaveBlock1.pos.y == 3)
+ return TRUE;
+ else if(gSaveBlock1.pos.x == 11 && gSaveBlock1.pos.y == 3)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void DoBrailleDigEffect(void)
+{
+ MapGridSetMetatileIdAt(16, 8, 554);
+ MapGridSetMetatileIdAt(17, 8, 555);
+ MapGridSetMetatileIdAt(18, 8, 556);
+ MapGridSetMetatileIdAt(16, 9, 3634);
+ MapGridSetMetatileIdAt(17, 9, 563);
+ MapGridSetMetatileIdAt(18, 9, 3636);
+ DrawWholeMapView();
+ PlaySE(SE_BAN);
+ FlagSet(SYS_BRAILLE_DIG);
+ ScriptContext2_Disable();
+}
+
+bool8 CheckRelicanthWailord(void)
+{
+ if(GetMonData(&gPlayerParty, MON_DATA_SPECIES2, 0) == SPECIES_RELICANTH)
+ {
+ CalculatePlayerPartyCount();
+
+ if(GetMonData(&gPlayerParty[gPlayerPartyCount - 1], MON_DATA_SPECIES2, 0) == SPECIES_WAILORD)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+bool8 ShouldDoBrailleStrengthEffect(void)
+{
+ if(!FlagGet(SYS_BRAILLE_STRENGTH) && (gSaveBlock1.location.mapGroup == 0x18 && gSaveBlock1.location.mapNum == 0x6))
+ {
+ if(gSaveBlock1.pos.x == 10 && gSaveBlock1.pos.y == 23)
+ return TRUE;
+ else if(gSaveBlock1.pos.x == 9 && gSaveBlock1.pos.y == 23)
+ return TRUE;
+ else if(gSaveBlock1.pos.x == 11 && gSaveBlock1.pos.y == 23)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void DoBrailleStrengthEffect(void)
+{
+ FieldEffectActiveListRemove(0x28);
+ MapGridSetMetatileIdAt(14, 26, 554);
+ MapGridSetMetatileIdAt(15, 26, 555);
+ MapGridSetMetatileIdAt(16, 26, 556);
+ MapGridSetMetatileIdAt(14, 27, 3634);
+ MapGridSetMetatileIdAt(15, 27, 563);
+ MapGridSetMetatileIdAt(16, 27, 3636);
+ DrawWholeMapView();
+ PlaySE(SE_BAN);
+ FlagSet(SYS_BRAILLE_STRENGTH);
+ ScriptContext2_Disable();
+}
+
+bool8 ShouldDoBrailleFlyEffect(void)
+{
+ if(!FlagGet(SYS_BRAILLE_FLY) && (gSaveBlock1.location.mapGroup == 0x18 && gSaveBlock1.location.mapNum == 0x44))
+ {
+ if(gSaveBlock1.pos.x == 8 && gSaveBlock1.pos.y == 25)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void DoBrailleFlyEffect(void)
+{
+ gUnknown_0202FF84[0] = gUnknown_03005CE0;
+ FieldEffectStart(0x3C);
+}
+
+bool8 FldEff_UseFlyAncientTomb(void)
+{
+ u8 taskId = oei_task_add();
+
+ gTasks[taskId].data[8] = (u32)UseFlyAncientTomb_Callback >> 16;
+ gTasks[taskId].data[9] = (u32)UseFlyAncientTomb_Callback;
+ return FALSE;
+}
+
+void UseFlyAncientTomb_Callback(void)
+{
+ FieldEffectActiveListRemove(0x3C);
+ UseFlyAncientTomb_Finish();
+}
+
+void UseFlyAncientTomb_Finish(void)
+{
+ MapGridSetMetatileIdAt(14, 26, 554);
+ MapGridSetMetatileIdAt(15, 26, 555);
+ MapGridSetMetatileIdAt(16, 26, 556);
+ MapGridSetMetatileIdAt(14, 27, 3634);
+ MapGridSetMetatileIdAt(15, 27, 563);
+ MapGridSetMetatileIdAt(16, 27, 3636);
+ DrawWholeMapView();
+ PlaySE(SE_BAN);
+ FlagSet(SYS_BRAILLE_FLY);
+ ScriptContext2_Disable();
+}
+
+void DoBrailleWait(void)
+{
+ if(!FlagGet(SYS_BRAILLE_WAIT))
+ CreateTask(Task_BrailleWait, 0x50);
+}
+
+void Task_BrailleWait(u8 taskId)
+{
+ s16 *data = gTasks[taskId].data;
+
+ switch(data[0])
+ {
+ case 0:
+ data[1] = 7200;
+ data[0] = 1;
+ break;
+ case 1:
+ if(BrailleWait_CheckButtonPress() != FALSE)
+ {
+ MenuZeroFillScreen();
+ PlaySE(5);
+ data[0] = 2;
+ }
+ else
+ {
+ data[1] = data[1] - 1;
+ if(data[1] == 0)
+ {
+ MenuZeroFillScreen();
+ data[0] = 3;
+ data[1] = 30;
+ }
+ }
+ break;
+ case 2:
+ if(BrailleWait_CheckButtonPress() == FALSE)
+ {
+ data[1] = data[1] - 1;
+ if(data[1] == 0)
+ data[0] = 4;
+ break;
+ }
+ sub_8064E2C();
+ DestroyTask(taskId);
+ ScriptContext2_Disable();
+ break;
+ case 3:
+ data[1] = data[1] - 1;
+ if(data[1] == 0)
+ data[0] = 4;
+ break;
+ case 4:
+ sub_8064E2C();
+ ScriptContext1_SetupScript(gUnknown_0815EF19);
+ DestroyTask(taskId);
+ break;
+ }
+}
+
+bool32 BrailleWait_CheckButtonPress(void)
+{
+ u16 var = 0xFF;
+
+ if(gSaveBlock2.optionsButtonMode == 1)
+ var |= 0x300;
+ if(gSaveBlock2.optionsButtonMode == 2)
+ var |= 0x200;
+
+ if((var & gMain.newKeys) != FALSE)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+void DoSealedChamberShakingEffect1(void)
+{
+ u8 taskId = CreateTask(SealedChamberShakingEffect, 0x9);
+
+ gTasks[taskId].data[1] = 0;
+ gTasks[taskId].data[2] = 0;
+ gTasks[taskId].data[4] = 2;
+ gTasks[taskId].data[5] = 5;
+ gTasks[taskId].data[6] = 50;
+ SetCameraPanningCallback(0);
+}
+
+void DoSealedChamberShakingEffect2(void)
+{
+ u8 taskId = CreateTask(SealedChamberShakingEffect, 0x9);
+
+ gTasks[taskId].data[1] = 0;
+ gTasks[taskId].data[2] = 0;
+ gTasks[taskId].data[4] = 3;
+ gTasks[taskId].data[5] = 5;
+ gTasks[taskId].data[6] = 2;
+ SetCameraPanningCallback(0);
+}
+
+void SealedChamberShakingEffect(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+
+ task->data[1]++;
+
+ if(!(task->data[1] % task->data[5]))
+ {
+ task->data[1] = 0;
+ task->data[2]++;
+ task->data[4] = -task->data[4];
+ SetCameraPanning(0, task->data[4]);
+ if(task->data[2] == task->data[6])
+ {
+ DestroyTask(taskId);
+ EnableBothScriptContexts();
+ InstallCameraPanAheadCallback();
+ }
+ }
+}
diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c
index 4b75c7a32..c68976cf9 100644
--- a/src/field_control_avatar.c
+++ b/src/field_control_avatar.c
@@ -112,33 +112,21 @@ extern void sub_8080F58(void);
extern void sub_80BC038();
extern void DoCoordEventWeather(u8);
-__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");
+ s->input_field_0_0 = 0;
+ s->input_field_0_1 = 0;
+ s->input_field_0_2 = 0;
+ s->input_field_0_3 = 0;
+ s->input_field_0_4 = 0;
+ s->input_field_0_5 = 0;
+ s->input_field_0_6 = 0;
+ s->input_field_0_7 = 0;
+ s->input_field_1_0 = 0;
+ s->input_field_1_1 = 0;
+ s->input_field_1_2 = 0;
+ s->input_field_1_3 = 0;
+ s->input_field_2 = 0;
}
void process_overworld_input(struct UnkInputStruct *pStruct, u16 keys, u16 heldKeys)
@@ -146,7 +134,7 @@ void process_overworld_input(struct UnkInputStruct *pStruct, u16 keys, u16 heldK
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)
@@ -242,7 +230,7 @@ static void player_get_pos_to_and_height(struct MapPosition *position)
static 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)
@@ -254,7 +242,7 @@ static void player_get_next_pos_and_height(struct MapPosition *position)
static u16 cur_mapdata_block_role_at_player_pos(int unused)
{
s16 x, y;
-
+
PlayerGetDestCoords(&x, &y);
return MapGridGetMetatileBehaviorAt(x, y);
}
@@ -262,17 +250,17 @@ static u16 cur_mapdata_block_role_at_player_pos(int unused)
static bool8 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;
}
@@ -280,7 +268,7 @@ static bool8 sub_80681F0(struct MapPosition *position, u16 b, u8 c)
static u8 *TryGetScriptOnPressingA(struct MapPosition *position, u8 b, u8 c)
{
u8 *script;
-
+
script = sub_8068364(position, b, c);
if (script != NULL)
return script;
@@ -293,7 +281,7 @@ static u8 *TryGetScriptOnPressingA(struct MapPosition *position, u8 b, u8 c)
script = TryGetFieldMoveScript(position, b, c);
if (script != NULL)
return script;
-
+
return NULL;
}
@@ -301,7 +289,7 @@ u8 *sub_80682A8(struct MapPosition *position, u8 unused, u8 c)
{
u8 r3;
s32 i;
-
+
if (!MetatileBehavior_IsCounter(MapGridGetMetatileBehaviorAt(position->x, position->y)))
r3 = GetFieldObjectIdByXYZ(position->x, position->y, position->height);
else
@@ -323,7 +311,7 @@ static u8 *sub_8068364(struct MapPosition *position, u8 b, u8 c)
{
u8 r3;
u8 *script;
-
+
r3 = GetFieldObjectIdByXYZ(position->x, position->y, position->height);
if (r3 == 16 || gMapObjects[r3].localId == 0xFF)
{
@@ -345,7 +333,7 @@ static u8 *sub_8068364(struct MapPosition *position, u8 b, u8 c)
static u8 *TryGetInvisibleMapObjectScript(struct MapPosition *position, u8 unused, u8 c)
{
struct BgEvent *bgEvent = FindInvisibleMapObjectByPosition(&gMapHeader, position->x - 7, position->y - 7, position->height);
-
+
if (bgEvent == NULL)
return NULL;
if (bgEvent->script == NULL)
@@ -394,7 +382,7 @@ static u8 *TryGetInvisibleMapObjectScript(struct MapPosition *position, u8 unuse
static u8 *sub_8068500(struct MapPosition *position, u8 b, u8 c)
{
s8 height;
-
+
if (MetatileBehavior_IsPlayerFacingTVScreen(b, c) == TRUE)
return Event_TV;
if (MetatileBehavior_IsPC(b) == TRUE)
@@ -474,69 +462,25 @@ static bool32 sub_80687A4(void)
return FALSE;
}
-#ifdef NONMATCHING
static bool8 sub_80687E4(struct MapPosition *position, u16 b, u16 unused)
{
- if (mapheader_trigger_activate_at__run_now(position) != TRUE
- && sub_8068A64(position, b) != TRUE && sub_8068870(b) != TRUE
- && sub_8068894() != TRUE && UpdateRepelCounter() != TRUE)
- return FALSE;
- return TRUE;
+ if (mapheader_trigger_activate_at__run_now(position) == TRUE)
+ return TRUE;
+ if (sub_8068A64(position, b) == TRUE)
+ return TRUE;
+ if (sub_8068870(b) == TRUE)
+ return TRUE;
+ if (sub_8068894() == TRUE)
+ return TRUE;
+ if (UpdateRepelCounter() == TRUE)
+ return TRUE;
+ return FALSE;
}
-#else
-__attribute__((naked))
-static bool8 sub_80687E4(struct MapPosition *position, u16 b, u16 unused)
-{
- asm(".syntax unified\n\
- push {r4-r6,lr}\n\
- adds r5, r0, 0\n\
- lsls r1, 16\n\
- lsrs r4, r1, 16\n\
- adds r6, r4, 0\n\
- bl mapheader_trigger_activate_at__run_now\n\
- lsls r0, 24\n\
- lsrs r0, 24\n\
- cmp r0, 0x1\n\
- beq _08068834\n\
- adds r0, r5, 0\n\
- adds r1, r4, 0\n\
- bl sub_8068A64\n\
- lsls r0, 24\n\
- lsrs r0, 24\n\
- cmp r0, 0x1\n\
- beq _08068834\n\
- adds r0, r6, 0\n\
- bl sub_8068870\n\
- lsls r0, 24\n\
- lsrs r0, 24\n\
- cmp r0, 0x1\n\
- beq _08068834\n\
- bl sub_8068894\n\
- lsls r0, 24\n\
- lsrs r0, 24\n\
- cmp r0, 0x1\n\
- beq _08068834\n\
- bl UpdateRepelCounter\n\
- lsls r0, 24\n\
- lsrs r0, 24\n\
- cmp r0, 0x1\n\
- beq _08068834\n\
- movs r0, 0\n\
- b _08068836\n\
-_08068834:\n\
- movs r0, 0x1\n\
-_08068836:\n\
- pop {r4-r6}\n\
- pop {r1}\n\
- bx r1\n\
- .syntax divided\n");
-}
-#endif
bool8 mapheader_trigger_activate_at__run_now(struct MapPosition *position)
{
u8 *script = mapheader_trigger_activate_at(&gMapHeader, position->x - 7, position->y - 7, position->height);
-
+
if (script == NULL)
return FALSE;
ScriptContext1_SetupScript(script);
@@ -588,13 +532,13 @@ static void happiness_algorithm_step(void)
{
u16 *ptr = GetVarPointer(VAR_HAPPINESS_STEP_COUNTER);
int i;
-
+
(*ptr)++;
(*ptr) %= 128;
if (*ptr == 0)
{
struct Pokemon *pkmn = gPlayerParty;
-
+
for (i = 5; i >= 0; i--)
{
AdjustFriendship(pkmn, 5);
@@ -611,7 +555,7 @@ void overworld_poison_timer_set(void)
static bool8 overworld_poison_step(void)
{
u16 *ptr;
-
+
if (gMapHeader.mapType != 9)
{
ptr = GetVarPointer(VAR_POISON_STEP_COUNTER);
@@ -662,7 +606,7 @@ static bool8 is_it_battle_time_3(u16 a)
static bool8 mapheader_run_first_tag2_script_list_match_conditionally(struct MapPosition *position, u16 b, u8 c)
{
s8 r6 = map_warp_check_packed(&gMapHeader, position);
-
+
if (is_non_stair_warp_tile(b, c) == TRUE && r6 != -1)
{
walkrun_find_lowest_active_bit_in_bitfield();
@@ -676,7 +620,7 @@ static bool8 mapheader_run_first_tag2_script_list_match_conditionally(struct Map
bool8 sub_8068A64(struct MapPosition *position, u16 b)
{
s8 r4 = map_warp_check_packed(&gMapHeader, position);
-
+
if (r4 != -1 && sub_8068B30(b) == TRUE)
{
walkrun_find_lowest_active_bit_in_bitfield();
@@ -750,7 +694,7 @@ static s8 map_warp_check_packed(struct MapHeader *mapHeader, struct MapPosition
static void sub_8068C30(struct MapHeader *unused, s8 b, struct MapPosition *position)
{
struct WarpEvent *warpEvent = &gMapHeader.events->warps[b];
-
+
if (warpEvent->mapNum == 0x7F)
{
copy_saved_warp2_bank_and_enter_x_to_warp1(warpEvent->mapGroup);
@@ -758,7 +702,7 @@ static void sub_8068C30(struct MapHeader *unused, s8 b, struct MapPosition *posi
else
{
struct MapHeader *mapHeader;
-
+
warp1_set_2(warpEvent->unk7, warpEvent->mapNum, warpEvent->mapGroup);
sub_80535C4(position->x, position->y);
mapHeader = get_mapheader_by_bank_and_number(warpEvent->unk7, warpEvent->mapNum);
@@ -770,7 +714,7 @@ static void sub_8068C30(struct MapHeader *unused, s8 b, struct MapPosition *posi
static bool8 map_warp_consider_2_to_inside(struct MapPosition *position, u16 b, u8 c)
{
s8 r4;
-
+
if (c == 2)
{
if (sub_80571C0(b) == TRUE)
@@ -798,7 +742,7 @@ static s8 map_warp_check(struct MapHeader *mapHeader, u16 b, u16 c, u8 d)
s32 i;
struct WarpEvent *warpEvent = mapHeader->events->warps;
u8 warpCount = mapHeader->events->warpCount;
-
+
for (i = 0; i < warpCount; i++, warpEvent++)
{
if ((u16)warpEvent->x == b && (u16)warpEvent->y == c)
@@ -836,7 +780,7 @@ static u8 *mapheader_trigger_activate_at(struct MapHeader *mapHeader, u16 b, u16
struct CoordEvent *coordEvents = mapHeader->events->coordEvents;
u8 coordEventCount = mapHeader->events->coordEventCount;
u8 *script;
-
+
for (i = 0; i < coordEventCount; i++)
{
if ((u16)coordEvents[i].x == b && (u16)coordEvents[i].y == c)
@@ -862,7 +806,7 @@ static struct BgEvent *FindInvisibleMapObjectByPosition(struct MapHeader *mapHea
u8 i;
struct BgEvent *bgEvents = mapHeader->events->bgEvents;
u8 bgEventCount = mapHeader->events->bgEventCount;
-
+
for (i = 0; i < bgEventCount; i++)
{
if ((u16)bgEvents[i].x == b && (u16)bgEvents[i].y == c)
@@ -903,7 +847,7 @@ u8 sub_8068F18(void)
{
s16 x, y;
u8 r5;
-
+
PlayerGetDestCoords(&x, &y);
r5 = MapGridGetMetatileBehaviorAt(x, y);
if (gMapHeader.mapType == 5 && sub_805750C(r5) == 0)
@@ -923,7 +867,7 @@ u8 *GetFieldObjectScriptPointerForComparison(void)
{
u8 r4;
struct MapPosition position;
-
+
r4 = player_get_direction_upper_nybble();
player_get_next_pos_and_height(&position);
return sub_8068364(&position, MapGridGetMetatileBehaviorAt(position.x, position.y), r4);
@@ -932,7 +876,7 @@ u8 *GetFieldObjectScriptPointerForComparison(void)
int sub_8068FEC(void)
{
struct MapPosition position;
-
+
player_get_direction_upper_nybble(); //unnecessary
player_get_pos_to_and_height(&position);
MapGridGetMetatileBehaviorAt(position.x, position.y); //unnecessary
diff --git a/src/fldeff_teleport.c b/src/fldeff_teleport.c
new file mode 100644
index 000000000..906832766
--- /dev/null
+++ b/src/fldeff_teleport.c
@@ -0,0 +1,50 @@
+#include "global.h"
+#include "field_effect.h"
+#include "rom4.h"
+#include "asm.h"
+#include "field_player_avatar.h"
+
+extern void sub_8087BA8(void);
+
+extern u32 gUnknown_0202FF84;
+
+extern void (*gUnknown_0300485C)(void);
+extern u8 gUnknown_03005CE0;
+extern void (*gUnknown_03005CE4)(void);
+
+void hm_teleport_run_dp02scr(void);
+void sub_814A404(void);
+
+bool8 SetUpFieldMove_Teleport(void)
+{
+ if (is_light_level_1_2_3_or_6(gMapHeader.mapType) == TRUE)
+ {
+ gUnknown_0300485C = sub_808AB90;
+ gUnknown_03005CE4 = hm_teleport_run_dp02scr;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void hm_teleport_run_dp02scr(void)
+{
+ new_game();
+ FieldEffectStart(63);
+ gUnknown_0202FF84 = gUnknown_03005CE0;
+}
+
+bool8 FldEff_UseTeleport(void)
+{
+ u8 taskId = oei_task_add();
+ gTasks[taskId].data[8] = (u32)sub_814A404 >> 16;
+ gTasks[taskId].data[9] = (u32)sub_814A404;
+ SetPlayerAvatarTransitionFlags(1);
+ return 0;
+}
+
+void sub_814A404(void)
+{
+ FieldEffectActiveListRemove(63);
+ sub_8087BA8();
+}
diff --git a/src/map_name_popup.c b/src/map_name_popup.c
new file mode 100644
index 000000000..65766c130
--- /dev/null
+++ b/src/map_name_popup.c
@@ -0,0 +1,106 @@
+#include "global.h"
+#include "menu.h"
+#include "event_data.h"
+#include "task.h"
+#include "asm.h"
+
+EWRAM_DATA static u8 sTaskId = 0;
+
+static void Task_MapNamePopup(u8);
+static void DrawMapNamePopup(void);
+
+bool8 unref_sub_80A2F44(void)
+{
+ CloseMenu();
+ ShowMapNamePopup();
+ return 1;
+}
+
+void ShowMapNamePopup(void)
+{
+ if (FlagGet(0x4000) != TRUE)
+ {
+ if (!FuncIsActiveTask(Task_MapNamePopup))
+ {
+ sTaskId = CreateTask(Task_MapNamePopup, 90);
+ REG_BG0VOFS = 32;
+ DrawMapNamePopup();
+ gTasks[sTaskId].data[0] = 0;
+ gTasks[sTaskId].data[2] = 32;
+ }
+ else
+ {
+ if (gTasks[sTaskId].data[0] != 2)
+ gTasks[sTaskId].data[0] = 2;
+ gTasks[sTaskId].data[3] = 1;
+ }
+ }
+}
+
+void Task_MapNamePopup(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+
+ switch (task->data[0])
+ {
+ case 0:
+ task->data[2] -= 2;
+ if (task->data[2] <= 0 )
+ {
+ task->data[0] = 1;
+ gTasks[sTaskId].data[1] = 0;
+ }
+ break;
+ case 1:
+ task->data[1]++;
+ if (task->data[1] > 120 )
+ {
+ task->data[1] = 0;
+ task->data[0] = 2;
+ }
+ break;
+ case 2:
+ task->data[2] += 2;
+ if (task->data[2] > 31)
+ {
+ if (task->data[3])
+ {
+ DrawMapNamePopup();
+ task->data[0] = 0;
+ task->data[3] = 0;
+ }
+ else
+ {
+ task->data[0] = 4;
+ return;
+ }
+ }
+ break;
+ case 4:
+ HideMapNamePopup();
+ return;
+ }
+
+ REG_BG0VOFS = task->data[2];
+}
+
+void HideMapNamePopup(void)
+{
+ if (FuncIsActiveTask(Task_MapNamePopup))
+ {
+ MenuLoadTextWindowGraphics();
+ MenuZeroFillWindowRect(0, 0, 13, 3);
+ REG_BG0VOFS = 0;
+ DestroyTask(sTaskId);
+ }
+}
+
+void DrawMapNamePopup(void)
+{
+ u8 name[20];
+
+ MenuLoadTextWindowGraphics_OverrideFrameType(0);
+ sub_80FBFB4(name, gMapHeader.name, 0);
+ MenuDrawTextWindow(0, 0, 13, 3);
+ sub_8072BD8(name, 1, 1, 0x60);
+}
diff --git a/src/name_string_util.c b/src/name_string_util.c
new file mode 100644
index 000000000..27e6d99d0
--- /dev/null
+++ b/src/name_string_util.c
@@ -0,0 +1,39 @@
+#include "global.h"
+#include "text.h"
+#include "string_util.h"
+
+void PadNameString(u8 *a1, u8 a2)
+{
+ u8 i;
+
+ StripExtCtrlCodes(a1);
+ i = StringLength(a1);
+
+ if (a2 == 0xFC)
+ {
+ while (i < 6)
+ {
+ a1[i] = 0xFC;
+ a1[i + 1] = 7;
+ i += 2;
+ }
+ }
+ else
+ {
+ while (i < 6)
+ {
+ a1[i] = a2;
+ i++;
+ }
+ }
+
+ a1[i] = EOS;
+}
+
+void SanitizeNameString(u8 *a1)
+{
+ if (StringLength(a1) < 6)
+ ConvertInternationalString(a1, 1);
+ else
+ StripExtCtrlCodes(a1);
+}
diff --git a/src/rom4.c b/src/rom4.c
index f711a5a0e..521f07a48 100644
--- a/src/rom4.c
+++ b/src/rom4.c
@@ -539,7 +539,7 @@ void sub_80538F0(u8 mapGroup, u8 mapNum)
DoCurrentWeather();
ResetFieldTasksArgs();
mapheader_run_script_with_tag_x5();
- AddMapNamePopUpWindowTask();
+ ShowMapNamePopup();
}
void sub_8053994(u32 a1)
@@ -1029,7 +1029,7 @@ void c1_overworld_normal(u16 newKeys, u16 heldKeys)
if (sub_8068024(&inputStruct) == 1)
{
ScriptContext2_Enable();
- HideMapNamePopUpWindow();
+ HideMapNamePopup();
}
else
{
@@ -1254,7 +1254,7 @@ void sub_80546F0(void)
void sub_805470C(void)
{
if (gMapHeader.flags == 1 && sub_80BBB24() == 1)
- AddMapNamePopUpWindowTask();
+ ShowMapNamePopup();
sub_8080B60();
}
@@ -1449,7 +1449,7 @@ bool32 sub_805493C(u8 *a1, u32 a2)
break;
case 11:
if (gMapHeader.flags == 1 && sub_80BBB24() == 1)
- AddMapNamePopUpWindowTask();
+ ShowMapNamePopup();
(*a1)++;
break;
case 12:
diff --git a/src/string_util.c b/src/string_util.c
index a7f9c3d1f..258077c9f 100644
--- a/src/string_util.c
+++ b/src/string_util.c
@@ -2,23 +2,6 @@
#include "string_util.h"
#include "text.h"
-#define MAX_PLACEHOLDER_ID 0xD
-
-static u8 *ExpandPlaceholder_UnknownStringVar(void);
-static u8 *ExpandPlaceholder_PlayerName(void);
-static u8 *ExpandPlaceholder_StringVar1(void);
-static u8 *ExpandPlaceholder_StringVar2(void);
-static u8 *ExpandPlaceholder_StringVar3(void);
-static u8 *ExpandPlaceholder_KunChan(void);
-static u8 *ExpandPlaceholder_RivalName(void);
-static u8 *ExpandPlaceholder_Version(void);
-static u8 *ExpandPlaceholder_EvilTeam(void);
-static u8 *ExpandPlaceholder_GoodTeam(void);
-static u8 *ExpandPlaceholder_EvilLeader(void);
-static u8 *ExpandPlaceholder_GoodLeader(void);
-static u8 *ExpandPlaceholder_EvilLegendary(void);
-static u8 *ExpandPlaceholder_GoodLegendary(void);
-
u8 gUnknownStringVar[16];
const u8 gEmptyString_81E72B0[] = _"";
@@ -40,29 +23,6 @@ static const s32 sPowersOfTen[] =
1000000000,
};
-static const u8 sSetBrailleFont[] = { 0xFC, 0x06, 0x06, 0xFF };
-static const u8 sGotoLine2[] = { 0xFE, 0xFC, 0x0E, 0x02, 0xFF };
-
-typedef u8 *(*ExpandPlaceholderFunc)(void);
-
-static const ExpandPlaceholderFunc sExpandPlaceholderFuncs[] =
-{
- ExpandPlaceholder_UnknownStringVar,
- ExpandPlaceholder_PlayerName,
- ExpandPlaceholder_StringVar1,
- ExpandPlaceholder_StringVar2,
- ExpandPlaceholder_StringVar3,
- ExpandPlaceholder_KunChan,
- ExpandPlaceholder_RivalName,
- ExpandPlaceholder_Version,
- ExpandPlaceholder_EvilTeam,
- ExpandPlaceholder_GoodTeam,
- ExpandPlaceholder_EvilLeader,
- ExpandPlaceholder_GoodLeader,
- ExpandPlaceholder_EvilLegendary,
- ExpandPlaceholder_GoodLegendary,
-};
-
extern u8 gExpandedPlaceholder_Empty[];
extern u8 gExpandedPlaceholder_Kun[];
extern u8 gExpandedPlaceholder_Chan[];
@@ -445,11 +405,8 @@ u8 *StringExpandPlaceholders(u8 *dest, const u8 *src)
u8 *StringBraille(u8 *dest, const u8 *src)
{
- u8 setBrailleFont[4];
- u8 gotoLine2[5];
-
- memcpy(setBrailleFont, sSetBrailleFont, 4);
- memcpy(gotoLine2, sGotoLine2, 5);
+ u8 setBrailleFont[] = { 0xFC, 0x06, 0x06, 0xFF };
+ u8 gotoLine2[] = { 0xFE, 0xFC, 0x0E, 0x02, 0xFF };
dest = StringCopy(dest, setBrailleFont);
@@ -473,32 +430,32 @@ u8 *StringBraille(u8 *dest, const u8 *src)
}
}
-u8 *ExpandPlaceholder_UnknownStringVar(void)
+static u8 *ExpandPlaceholder_UnknownStringVar(void)
{
return gUnknownStringVar;
}
-u8 *ExpandPlaceholder_PlayerName(void)
+static u8 *ExpandPlaceholder_PlayerName(void)
{
return gSaveBlock2.playerName;
}
-u8 *ExpandPlaceholder_StringVar1(void)
+static u8 *ExpandPlaceholder_StringVar1(void)
{
return gStringVar1;
}
-u8 *ExpandPlaceholder_StringVar2(void)
+static u8 *ExpandPlaceholder_StringVar2(void)
{
return gStringVar2;
}
-u8 *ExpandPlaceholder_StringVar3(void)
+static u8 *ExpandPlaceholder_StringVar3(void)
{
return gStringVar3;
}
-u8 *ExpandPlaceholder_KunChan(void)
+static u8 *ExpandPlaceholder_KunChan(void)
{
if (gSaveBlock2.playerGender == MALE)
return gExpandedPlaceholder_Kun;
@@ -506,7 +463,7 @@ u8 *ExpandPlaceholder_KunChan(void)
return gExpandedPlaceholder_Chan;
}
-u8 *ExpandPlaceholder_RivalName(void)
+static u8 *ExpandPlaceholder_RivalName(void)
{
if (gSaveBlock2.playerGender == MALE)
return gExpandedPlaceholder_May;
@@ -537,10 +494,30 @@ VERSION_DEPENDENT_PLACEHOLDER_LIST
u8 *GetExpandedPlaceholder(u32 id)
{
- if (id > MAX_PLACEHOLDER_ID)
+ typedef u8 *(*ExpandPlaceholderFunc)(void);
+
+ static const ExpandPlaceholderFunc funcs[] =
+ {
+ ExpandPlaceholder_UnknownStringVar,
+ ExpandPlaceholder_PlayerName,
+ ExpandPlaceholder_StringVar1,
+ ExpandPlaceholder_StringVar2,
+ ExpandPlaceholder_StringVar3,
+ ExpandPlaceholder_KunChan,
+ ExpandPlaceholder_RivalName,
+ ExpandPlaceholder_Version,
+ ExpandPlaceholder_EvilTeam,
+ ExpandPlaceholder_GoodTeam,
+ ExpandPlaceholder_EvilLeader,
+ ExpandPlaceholder_GoodLeader,
+ ExpandPlaceholder_EvilLegendary,
+ ExpandPlaceholder_GoodLegendary,
+ };
+
+ if (id >= ARRAY_COUNT(funcs))
return gExpandedPlaceholder_Empty;
else
- return sExpandPlaceholderFuncs[id]();
+ return funcs[id]();
}
u8 *StringFill(u8 *dest, u8 c, u16 n)
diff --git a/src/unknown_debug_menu.c b/src/unknown_debug_menu.c
new file mode 100644
index 000000000..bbaeef63a
--- /dev/null
+++ b/src/unknown_debug_menu.c
@@ -0,0 +1,52 @@
+#include "global.h"
+#include "menu.h"
+
+extern u8 gUnknown_02024D1E[];
+
+extern u8 (*gCallback_03004AE8)(void);
+
+extern const struct MenuAction gUnknown_0842C29C[];
+
+u8 sub_814A464(void);
+
+int unref_sub_814A414(void)
+{
+ MenuZeroFillScreen();
+ MenuDrawTextWindow(0, 0, 16, 18);
+ PrintMenuItems(2, 1, 8, gUnknown_0842C29C);
+ InitMenu(0, 1, 1, 8, 0, 15);
+ gCallback_03004AE8 = sub_814A464;
+ return 0;
+}
+
+u8 sub_814A464(void)
+{
+ s8 result = ProcessMenuInput();
+ if (result == -2)
+ {
+ return 0;
+ }
+ else if (result == -1)
+ {
+ CloseMenu();
+ return 1;
+ }
+ else
+ {
+ gUnknown_02024D1E[0] = result;
+ gCallback_03004AE8 = gUnknown_0842C29C[result].func;
+ return 0;
+ }
+}
+
+u8 sub_814A4B8(void)
+{
+ gSaveBlock2.filler_A8.var_4AE = 3;
+ gSaveBlock2.filler_A8.var_4AF = 3;
+ gSaveBlock2.filler_A8.var_4B4 = gUnknown_02024D1E[0] + 1;
+ gSaveBlock2.filler_A8.var_4B6 = gUnknown_02024D1E[0] + 1;
+ gSaveBlock2.filler_A8.var_4B0 = 1;
+ gSaveBlock2.filler_A8.var_4B2 = 1;
+ CloseMenu();
+ return 1;
+}