summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPikalaxALT <PikalaxALT@gmail.com>2020-03-26 18:29:48 -0400
committerPikalaxALT <PikalaxALT@gmail.com>2020-03-26 18:29:48 -0400
commit84a69bf1404d6d6545c72c39a5b5105fbdb8c36c (patch)
treeb6864eed9f3170a57a446b8ffed326a2077e83a4
parentb9c604b8d2ffe863cf17336a4d956b08438f0f45 (diff)
through Overworld_ResetStateAfterFly
-rw-r--r--asm/overworld.s149
-rw-r--r--data/overworld.s22
-rw-r--r--include/constants/flags.h1
-rw-r--r--include/event_scripts.h4
-rw-r--r--ld_script.txt2
-rw-r--r--src/overworld.c91
6 files changed, 98 insertions, 171 deletions
diff --git a/asm/overworld.s b/asm/overworld.s
index f840e590a..4ac6b79f7 100644
--- a/asm/overworld.s
+++ b/asm/overworld.s
@@ -5,155 +5,6 @@
.text
- thumb_func_start sub_8054BC8
-sub_8054BC8: @ 8054BC8
- push {r4,lr}
- ldr r0, _08054BFC @ =EventScript_ResetEliteFourEnd
- bl ScriptContext2_RunNewScript
- ldr r0, _08054C00 @ =gSaveBlock1Ptr
- ldr r4, [r0]
- movs r0, 0xA4
- lsls r0, 2
- adds r4, r0
- bl ComputeWhiteOutMoneyLoss
- adds r1, r0, 0
- adds r0, r4, 0
- bl RemoveMoney
- bl HealPlayerParty
- bl sub_8054DD8
- bl sub_80554BC
- bl WarpIntoMap
- pop {r4}
- pop {r0}
- bx r0
- .align 2, 0
-_08054BFC: .4byte EventScript_ResetEliteFourEnd
-_08054C00: .4byte gSaveBlock1Ptr
- thumb_func_end sub_8054BC8
-
- thumb_func_start ComputeWhiteOutMoneyLoss
-ComputeWhiteOutMoneyLoss: @ 8054C04
- push {r4,lr}
- bl CountBadgesForOverworldWhiteOutLossCalculation
- adds r4, r0, 0
- lsls r4, 24
- lsrs r4, 24
- bl GetPlayerPartyHighestLevel
- lsls r0, 24
- lsrs r0, 24
- ldr r1, _08054C40 @ =sWhiteOutMoneyLossMultipliers
- adds r4, r1
- ldrb r1, [r4]
- lsls r1, 2
- adds r4, r0, 0
- muls r4, r1
- ldr r0, _08054C44 @ =gSaveBlock1Ptr
- ldr r0, [r0]
- movs r1, 0xA4
- lsls r1, 2
- adds r0, r1
- bl GetMoney
- cmp r4, r0
- bls _08054C38
- adds r4, r0, 0
-_08054C38:
- adds r0, r4, 0
- pop {r4}
- pop {r1}
- bx r1
- .align 2, 0
-_08054C40: .4byte sWhiteOutMoneyLossMultipliers
-_08054C44: .4byte gSaveBlock1Ptr
- thumb_func_end ComputeWhiteOutMoneyLoss
-
- thumb_func_start OverworldWhiteOutGetMoneyLoss
-OverworldWhiteOutGetMoneyLoss: @ 8054C48
- push {r4,r5,lr}
- bl ComputeWhiteOutMoneyLoss
- adds r4, r0, 0
- ldr r5, _08054C6C @ =gStringVar1
- bl CountDigits
- adds r3, r0, 0
- lsls r3, 24
- lsrs r3, 24
- adds r0, r5, 0
- adds r1, r4, 0
- movs r2, 0
- bl ConvertIntToDecimalStringN
- pop {r4,r5}
- pop {r0}
- bx r0
- .align 2, 0
-_08054C6C: .4byte gStringVar1
- thumb_func_end OverworldWhiteOutGetMoneyLoss
-
- thumb_func_start CountBadgesForOverworldWhiteOutLossCalculation
-CountBadgesForOverworldWhiteOutLossCalculation: @ 8054C70
- push {r4-r6,lr}
- movs r6, 0
- movs r5, 0
- ldr r4, _08054C9C @ =sWhiteOutMoneyLossBadgeFlagIDs
-_08054C78:
- ldrh r0, [r4]
- bl FlagGet
- lsls r0, 24
- cmp r0, 0
- beq _08054C8A
- adds r0, r6, 0x1
- lsls r0, 24
- lsrs r6, r0, 24
-_08054C8A:
- adds r4, 0x2
- adds r5, 0x1
- cmp r5, 0x7
- bls _08054C78
- adds r0, r6, 0
- pop {r4-r6}
- pop {r1}
- bx r1
- .align 2, 0
-_08054C9C: .4byte sWhiteOutMoneyLossBadgeFlagIDs
- thumb_func_end CountBadgesForOverworldWhiteOutLossCalculation
-
- thumb_func_start Overworld_ResetStateAfterFly
-Overworld_ResetStateAfterFly: @ 8054CA0
- push {lr}
- bl ResetInitialPlayerAvatarState
- movs r0, 0x83
- lsls r0, 4
- bl FlagClear
- ldr r0, _08054CEC @ =0x0000405e
- movs r1, 0
- bl VarSet
- ldr r0, _08054CF0 @ =0x00000802
- bl FlagClear
- movs r0, 0x80
- lsls r0, 4
- bl FlagClear
- ldr r0, _08054CF4 @ =0x0000406e
- movs r1, 0
- bl VarSet
- ldr r0, _08054CF8 @ =0x00000805
- bl FlagClear
- ldr r0, _08054CFC @ =0x00000806
- bl FlagClear
- ldr r0, _08054D00 @ =0x00000808
- bl FlagClear
- ldr r0, _08054D04 @ =0x0000404d
- movs r1, 0
- bl VarSet
- pop {r0}
- bx r0
- .align 2, 0
-_08054CEC: .4byte 0x0000405e
-_08054CF0: .4byte 0x00000802
-_08054CF4: .4byte 0x0000406e
-_08054CF8: .4byte 0x00000805
-_08054CFC: .4byte 0x00000806
-_08054D00: .4byte 0x00000808
-_08054D04: .4byte 0x0000404d
- thumb_func_end Overworld_ResetStateAfterFly
-
thumb_func_start Overworld_ResetStateAfterTeleport
Overworld_ResetStateAfterTeleport: @ 8054D08
push {lr}
diff --git a/data/overworld.s b/data/overworld.s
index 245ee3696..4bd1f41da 100644
--- a/data/overworld.s
+++ b/data/overworld.s
@@ -5,28 +5,6 @@
.section .rodata
.align 2, 0
-sWhiteOutMoneyLossMultipliers:: @ 826D294
- .byte 2
- .byte 4
- .byte 6
- .byte 9
- .byte 12
- .byte 16
- .byte 20
- .byte 25
- .byte 30
-
- .align 1
-sWhiteOutMoneyLossBadgeFlagIDs:: @ 826D29E
- .2byte FLAG_BADGE01_GET
- .2byte FLAG_BADGE02_GET
- .2byte FLAG_BADGE03_GET
- .2byte FLAG_BADGE04_GET
- .2byte FLAG_BADGE05_GET
- .2byte FLAG_BADGE06_GET
- .2byte FLAG_BADGE07_GET
- .2byte FLAG_BADGE08_GET
-
.align 2
sDummyWarpData:: @ 826D2B0
map MAP_UNDEFINED
diff --git a/include/constants/flags.h b/include/constants/flags.h
index 6fd532a0e..54129cae5 100644
--- a/include/constants/flags.h
+++ b/include/constants/flags.h
@@ -1319,6 +1319,7 @@
#define FLAG_SYS_SAFARI_MODE (SYS_FLAGS + 0x0)
#define FLAG_SYS_VS_SEEKER_CHARGING (SYS_FLAGS + 0x1)
+#define FLAG_SYS_UNK_802 (SYS_FLAGS + 0x2)
#define FLAG_SYS_WHITE_FLUTE_ACTIVE (SYS_FLAGS + 0x3)
#define FLAG_SYS_BLACK_FLUTE_ACTIVE (SYS_FLAGS + 0x4)
#define FLAG_SYS_USE_STRENGTH (SYS_FLAGS + 0x5)
diff --git a/include/event_scripts.h b/include/event_scripts.h
index 9b78854fa..add2da0d1 100644
--- a/include/event_scripts.h
+++ b/include/event_scripts.h
@@ -1259,4 +1259,8 @@ extern const u8 EventScript_FieldPoison[];
extern const u8 EventScript_EggHatch[];
extern const u8 EventScript_1C1361[];
+// overworld
+
+extern const u8 EventScript_ResetEliteFourEnd[];
+
#endif //GUARD_EVENT_SCRIPTS_H
diff --git a/ld_script.txt b/ld_script.txt
index 3012e7066..a91dd536d 100644
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -87,6 +87,7 @@ SECTIONS {
src/trade_scene.o(.text);
src/play_time.o(.text);
src/new_game.o(.text);
+ src/overworld.o(.text);
asm/overworld.o(.text);
src/fieldmap.o(.text);
src/metatile_behavior.o(.text);
@@ -427,6 +428,7 @@ SECTIONS {
src/pokeball.o(.rodata);
src/trade.o(.rodata);
src/trade_scene.o(.rodata);
+ src/overworld.o(.rodata);
data/overworld.o(.rodata);
data/tilesets.o(.rodata);
data/maps.o(.rodata);
diff --git a/src/overworld.c b/src/overworld.c
new file mode 100644
index 000000000..5a065ed92
--- /dev/null
+++ b/src/overworld.c
@@ -0,0 +1,91 @@
+#include "global.h"
+#include "gflib.h"
+#include "event_data.h"
+#include "event_scripts.h"
+#include "field_specials.h"
+#include "money.h"
+#include "overworld.h"
+#include "script.h"
+#include "script_pokemon_util.h"
+#include "constants/maps.h"
+#include "constants/flags.h"
+
+u8 CountBadgesForOverworldWhiteOutLossCalculation(void);
+void sub_8054DD8(void);
+void sub_80554BC(void);
+
+static const u8 sWhiteOutMoneyLossMultipliers[] = {
+ 2,
+ 4,
+ 6,
+ 9,
+ 12,
+ 16,
+ 20,
+ 25,
+ 30
+};
+
+const u16 sWhiteOutMoneyLossBadgeFlagIDs[] = {
+ FLAG_BADGE01_GET,
+ FLAG_BADGE02_GET,
+ FLAG_BADGE03_GET,
+ FLAG_BADGE04_GET,
+ FLAG_BADGE05_GET,
+ FLAG_BADGE06_GET,
+ FLAG_BADGE07_GET,
+ FLAG_BADGE08_GET
+};
+
+void sub_8054BC8(void)
+{
+ ScriptContext2_RunNewScript(EventScript_ResetEliteFourEnd);
+ RemoveMoney(&gSaveBlock1Ptr->money, ComputeWhiteOutMoneyLoss());
+ HealPlayerParty();
+ sub_8054DD8();
+ sub_80554BC();
+ WarpIntoMap();
+}
+
+u32 ComputeWhiteOutMoneyLoss(void)
+{
+ u8 nbadges = CountBadgesForOverworldWhiteOutLossCalculation();
+ u8 toplevel = GetPlayerPartyHighestLevel();
+ u32 losings = toplevel * 4 * sWhiteOutMoneyLossMultipliers[nbadges];
+ u32 money = GetMoney(&gSaveBlock1Ptr->money);
+ if (losings > money)
+ losings = money;
+ return losings;
+}
+
+void OverworldWhiteOutGetMoneyLoss(void)
+{
+ u32 losings = ComputeWhiteOutMoneyLoss();
+ ConvertIntToDecimalStringN(gStringVar1, losings, STR_CONV_MODE_LEFT_ALIGN, CountDigits(losings));
+}
+
+u8 CountBadgesForOverworldWhiteOutLossCalculation(void)
+{
+ int i;
+ u8 nbadges = 0;
+ for (i = 0; i < NELEMS(sWhiteOutMoneyLossBadgeFlagIDs); i++)
+ {
+ if (FlagGet(sWhiteOutMoneyLossBadgeFlagIDs[i]))
+ nbadges++;
+ }
+ return nbadges;
+}
+
+void Overworld_ResetStateAfterFly(void)
+{
+ ResetInitialPlayerAvatarState();
+ FlagClear(FLAG_SYS_ON_CYCLING_ROAD);
+ VarSet(VAR_MAP_SCENE_ROUTE16, 0);
+ FlagClear(FLAG_SYS_UNK_802);
+ FlagClear(FLAG_SYS_SAFARI_MODE);
+ VarSet(VAR_MAP_SCENE_FUCHSIA_CITY_SAFARI_ZONE_ENTRANCE, 0);
+ FlagClear(FLAG_SYS_USE_STRENGTH);
+ FlagClear(FLAG_SYS_FLASH_ACTIVE);
+ FlagClear(FLAG_0x808);
+ VarSet(VAR_0x404D, 0);
+}