diff --git a/asm/cable_club.s b/asm/cable_club.s index 611b87eef..64d6088b1 100644 --- a/asm/cable_club.s +++ b/asm/cable_club.s @@ -1808,7 +1808,7 @@ _080B32E0: _080B32F8: movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r1, =gLinkType ldr r2, =0x00002211 adds r0, r2, 0 @@ -1921,7 +1921,7 @@ _080B33E8: _080B3408: movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r0, =gLinkType ldr r2, =0x00002211 adds r1, r2, 0 @@ -2399,7 +2399,7 @@ _080B382E: bl ScriptContext2_Enable movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen bl sub_8009FAC b _080B3864 _080B3840: @@ -2470,7 +2470,7 @@ _080B38C6: bl ScriptContext2_Enable movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen bl Rfu_set_zero b _080B38FC _080B38D8: diff --git a/asm/easy_chat.s b/asm/easy_chat.s index 86c78d2cf..db2ffac14 100644 --- a/asm/easy_chat.s +++ b/asm/easy_chat.s @@ -652,7 +652,7 @@ sub_811A7E4: @ 811A7E4 _0811A804: movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen b _0811A840 _0811A80E: ldr r0, =gPaletteFade diff --git a/asm/field_screen.s b/asm/field_screen.s index 6b49b9c7c..5e9452d71 100644 --- a/asm/field_screen.s +++ b/asm/field_screen.s @@ -1625,8 +1625,8 @@ _080ABCBC: .pool thumb_func_end sub_80ABC7C - thumb_func_start fade_screen -fade_screen: @ 80ABCD0 + thumb_func_start FadeScreen +FadeScreen: @ 80ABCD0 push {r4,r5,lr} sub sp, 0x4 lsls r0, 24 @@ -1762,7 +1762,7 @@ _080ABDE4: pop {r0} bx r0 .pool - thumb_func_end fade_screen + thumb_func_end FadeScreen thumb_func_start sub_80ABDFC sub_80ABDFC: @ 80ABDFC @@ -2472,15 +2472,15 @@ _080AC3B6: bx r0 thumb_func_end play_some_sound - thumb_func_start sub_80AC3BC -sub_80AC3BC: @ 80AC3BC + thumb_func_start IsWeatherChangeComplete +IsWeatherChangeComplete: @ 80AC3BC ldr r0, =gUnknown_02038454 ldr r1, =0x000006d3 adds r0, r1 ldrb r0, [r0] bx lr .pool - thumb_func_end sub_80AC3BC + thumb_func_end IsWeatherChangeComplete thumb_func_start sub_80AC3D0 sub_80AC3D0: @ 80AC3D0 @@ -7537,8 +7537,8 @@ GetSav1Weather: @ 80AEDAC .pool thumb_func_end GetSav1Weather - thumb_func_start sub_80AEDBC -sub_80AEDBC: @ 80AEDBC + thumb_func_start SetSav1WeatherFromCurrMapHeader +SetSav1WeatherFromCurrMapHeader: @ 80AEDBC push {r4,r5,lr} ldr r4, =gSaveBlock1Ptr ldr r0, [r4] @@ -7559,7 +7559,7 @@ sub_80AEDBC: @ 80AEDBC pop {r0} bx r0 .pool - thumb_func_end sub_80AEDBC + thumb_func_end SetSav1WeatherFromCurrMapHeader thumb_func_start sub_80AEDF0 sub_80AEDF0: @ 80AEDF0 @@ -7872,13 +7872,13 @@ _080AF06A: bl palette_bg_faded_fill_black movs r0, 0 movs r1, 0 - bl fade_screen + bl FadeScreen b _080AF084 _080AF078: bl palette_bg_faded_fill_white movs r0, 0x2 movs r1, 0 - bl fade_screen + bl FadeScreen _080AF084: pop {r4} pop {r0} @@ -7891,7 +7891,7 @@ sub_80AF08C: @ 80AF08C bl palette_bg_faded_fill_white movs r0, 0x2 movs r1, 0x8 - bl fade_screen + bl FadeScreen pop {r0} bx r0 thumb_func_end sub_80AF08C @@ -7902,7 +7902,7 @@ pal_fill_black: @ 80AF0A0 bl palette_bg_faded_fill_black movs r0, 0 movs r1, 0 - bl fade_screen + bl FadeScreen pop {r0} bx r0 thumb_func_end pal_fill_black @@ -7928,12 +7928,12 @@ sub_80AF0B4: @ 80AF0B4 _080AF0DA: movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen b _080AF0EC _080AF0E4: movs r0, 0x3 movs r1, 0 - bl fade_screen + bl FadeScreen _080AF0EC: pop {r4} pop {r0} @@ -8761,7 +8761,7 @@ sub_80AF79C: @ 80AF79C bl music_something movs r0, 0x3 movs r1, 0x8 - bl fade_screen + bl FadeScreen bl play_some_sound ldr r0, =gFieldCallback ldr r1, =sub_80AF3B0 @@ -8990,7 +8990,7 @@ _080AF99A: bl sub_8009FAC movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen bl music_something movs r0, 0x9 bl PlaySE diff --git a/asm/item_use.s b/asm/item_use.s index 0d9f30ec3..8c9e854c7 100644 --- a/asm/item_use.s +++ b/asm/item_use.s @@ -1482,7 +1482,7 @@ _080FDBC8: str r1, [r0] movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r0, =sub_80FDC00 str r0, [r5] _080FDBDA: diff --git a/asm/link.s b/asm/link.s index 1ad160340..76c6521cf 100644 --- a/asm/link.s +++ b/asm/link.s @@ -21684,7 +21684,7 @@ _080148CC: bne _080149B2 movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen movs r0, 0x2 strh r0, [r7] b _080149B2 diff --git a/asm/overworld.s b/asm/overworld.s index 2858fb6d3..3e041d25f 100644 --- a/asm/overworld.s +++ b/asm/overworld.s @@ -1383,7 +1383,7 @@ _080850C8: adds r1, r5, 0 bl TryUpdateRandomTrainerRematches bl DoTimeBasedEvents - bl sub_80AEDBC + bl SetSav1WeatherFromCurrMapHeader bl sub_8085B2C bl update_sav1_flash_used_on_map bl Overworld_ClearSavedMusic @@ -1483,7 +1483,7 @@ _080851A2: beq _080851EE bl DoTimeBasedEvents _080851EE: - bl sub_80AEDBC + bl SetSav1WeatherFromCurrMapHeader bl sub_8085B2C cmp r5, 0 beq _08085200 diff --git a/asm/party_menu.s b/asm/party_menu.s index 429b629ea..0dc03a1e2 100644 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -17171,7 +17171,7 @@ sub_81B9404: @ 81B9404 bl ScriptContext2_Enable movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r0, =sub_81B9424 movs r1, 0xA bl CreateTask @@ -17247,7 +17247,7 @@ sub_81B94B0: @ 81B94B0 bl ScriptContext2_Enable movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r0, =sub_81B94D0 movs r1, 0xA bl CreateTask @@ -17297,7 +17297,7 @@ sub_81B951C: @ 81B951C bl ScriptContext2_Enable movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r0, =sub_81B953C movs r1, 0xA bl CreateTask @@ -17418,7 +17418,7 @@ sub_81B9620: @ 81B9620 bl ScriptContext2_Enable movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r0, =sub_81B9640 movs r1, 0xA bl CreateTask diff --git a/asm/player_pc.s b/asm/player_pc.s index 3f08d3f5c..5d9314f80 100644 --- a/asm/player_pc.s +++ b/asm/player_pc.s @@ -552,7 +552,7 @@ sub_816B2C8: @ 816B2C8 str r0, [r1] movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen pop {r0} bx r0 .pool @@ -1221,7 +1221,7 @@ sub_816B878: @ 816B878 lsrs r4, 24 movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r1, =gTasks lsls r0, r4, 2 adds r0, r4 @@ -1494,7 +1494,7 @@ sub_816BABC: @ 816BABC _0816BAD4: movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r0, =gTasks lsls r1, r4, 2 adds r1, r4 diff --git a/asm/pokemon_storage_system.s b/asm/pokemon_storage_system.s index c105c7781..8fc10ba29 100644 --- a/asm/pokemon_storage_system.s +++ b/asm/pokemon_storage_system.s @@ -406,7 +406,7 @@ _080C7428: _080C745C: movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen movs r0, 0x4 strh r0, [r5, 0x8] b _080C756A diff --git a/asm/pokemon_summary_screen.s b/asm/pokemon_summary_screen.s index 2817b55b1..a04939c12 100644 --- a/asm/pokemon_summary_screen.s +++ b/asm/pokemon_summary_screen.s @@ -2049,7 +2049,7 @@ sub_81C4F24: @ 81C4F24 bl ScriptContext2_Enable movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen ldr r0, =sub_81C4F44 movs r1, 0xA bl CreateTask diff --git a/asm/pokenav.s b/asm/pokenav.s index 896d9aae0..52fe65d65 100644 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -44,7 +44,7 @@ sub_81C72A4: @ 81C72A4 bl SetMainCallback2 movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen pop {r0} bx r0 .pool diff --git a/asm/shop.s b/asm/shop.s index eacef5837..70429c7cf 100644 --- a/asm/shop.s +++ b/asm/shop.s @@ -188,7 +188,7 @@ HandleShopMenuBuy: @ 80DFBD0 str r0, [r1] movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen pop {r4} pop {r0} bx r0 @@ -216,7 +216,7 @@ HandleShopMenuSell: @ 80DFC0C str r0, [r1] movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen pop {r4} pop {r0} bx r0 diff --git a/asm/start_menu.s b/asm/start_menu.s index 518b46f76..93bef1ef2 100644 --- a/asm/start_menu.s +++ b/asm/start_menu.s @@ -449,7 +449,7 @@ _0809FB34: beq _0809FBA0 movs r0, 0x1 movs r1, 0 - bl fade_screen + bl FadeScreen b _0809FBA0 .pool _0809FB98: diff --git a/asm/time_events.s b/asm/time_events.s deleted file mode 100644 index de2d2d165..000000000 --- a/asm/time_events.s +++ /dev/null @@ -1,225 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start GetMirageRnd -GetMirageRnd: @ 8137890 - push {r4,lr} - ldr r0, =0x00004024 - bl VarGet - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - ldr r0, =0x00004025 - bl VarGet - lsls r0, 16 - lsrs r0, 16 - lsls r4, 16 - orrs r4, r0 - adds r0, r4, 0 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end GetMirageRnd - - thumb_func_start SetMirageRnd -SetMirageRnd: @ 81378BC - push {r4,lr} - adds r4, r0, 0 - ldr r0, =0x00004024 - lsrs r1, r4, 16 - bl VarSet - ldr r0, =0x00004025 - lsls r4, 16 - lsrs r4, 16 - adds r1, r4, 0 - bl VarSet - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end SetMirageRnd - - thumb_func_start InitMirageRnd -InitMirageRnd: @ 81378E4 - push {r4,lr} - bl Random - adds r4, r0, 0 - bl Random - lsls r4, 16 - lsls r0, 16 - lsrs r0, 16 - orrs r4, r0 - adds r0, r4, 0 - bl SetMirageRnd - pop {r4} - pop {r0} - bx r0 - thumb_func_end InitMirageRnd - - thumb_func_start UpdateMirageRnd -UpdateMirageRnd: @ 8137904 - push {r4,lr} - lsls r0, 16 - lsrs r4, r0, 16 - bl GetMirageRnd - adds r1, r0, 0 - cmp r4, 0 - beq _08137928 - ldr r3, =0x41c64e6d - ldr r2, =0x00003039 -_08137918: - adds r0, r1, 0 - muls r0, r3 - adds r1, r0, r2 - subs r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0 - bne _08137918 -_08137928: - adds r0, r1, 0 - bl SetMirageRnd - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end UpdateMirageRnd - - thumb_func_start IsMirageIslandPresent -IsMirageIslandPresent: @ 813793C - push {r4-r6,lr} - bl GetMirageRnd - lsrs r6, r0, 16 - movs r5, 0 -_08137946: - movs r0, 0x64 - adds r1, r5, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - adds r0, r4, 0 - movs r1, 0xB - bl GetMonData - cmp r0, 0 - beq _08137978 - adds r0, r4, 0 - movs r1, 0 - bl GetMonData - ldr r1, =0x0000ffff - ands r1, r0 - cmp r1, r6 - bne _08137978 - movs r0, 0x1 - b _08137980 - .pool -_08137978: - adds r5, 0x1 - cmp r5, 0x5 - ble _08137946 - movs r0, 0 -_08137980: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end IsMirageIslandPresent - - thumb_func_start UpdateShoalTideFlag -UpdateShoalTideFlag: @ 8137988 - push {lr} - bl get_map_light_from_warp0 - lsls r0, 24 - lsrs r0, 24 - bl is_light_level_1_2_3_5_or_6 - lsls r0, 24 - cmp r0, 0 - beq _081379CE - bl RtcCalcLocalTime - ldr r1, =gUnknown_085B2B44 - ldr r0, =gLocalTime - ldrb r0, [r0, 0x2] - lsls r0, 24 - asrs r0, 24 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0 - beq _081379C8 - ldr r0, =0x0000089a - bl FlagSet - b _081379CE - .pool -_081379C8: - ldr r0, =0x0000089a - bl FlagClear -_081379CE: - pop {r0} - bx r0 - .pool - thumb_func_end UpdateShoalTideFlag - - thumb_func_start Task_WaitWeather -Task_WaitWeather: @ 81379D8 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - bl sub_80AC3BC - lsls r0, 24 - cmp r0, 0 - beq _081379F2 - bl EnableBothScriptContexts - adds r0, r4, 0 - bl DestroyTask -_081379F2: - pop {r4} - pop {r0} - bx r0 - thumb_func_end Task_WaitWeather - - thumb_func_start WaitWeather -WaitWeather: @ 81379F8 - push {lr} - ldr r0, =Task_WaitWeather - movs r1, 0x50 - bl CreateTask - pop {r0} - bx r0 - .pool - thumb_func_end WaitWeather - - thumb_func_start InitBirchState -InitBirchState: @ 8137A0C - push {lr} - ldr r0, =0x00004049 - bl GetVarPointer - movs r1, 0 - strh r1, [r0] - pop {r0} - bx r0 - .pool - thumb_func_end InitBirchState - - thumb_func_start UpdateBirchState -UpdateBirchState: @ 8137A20 - push {r4,r5,lr} - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - ldr r0, =0x00004049 - bl GetVarPointer - adds r5, r0, 0 - ldrh r0, [r5] - adds r4, r0 - strh r4, [r5] - ldrh r0, [r5] - movs r1, 0x7 - bl __umodsi3 - strh r0, [r5] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end UpdateBirchState diff --git a/data/time_events.s b/data/time_events.s deleted file mode 100644 index 7a543fff5..000000000 --- a/data/time_events.s +++ /dev/null @@ -1,7 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gUnknown_085B2B44:: @ 85B2B44 - .byte 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 diff --git a/include/field_weather.h b/include/field_weather.h index e12107e70..5d1aa5ac2 100644 --- a/include/field_weather.h +++ b/include/field_weather.h @@ -1,12 +1,175 @@ #ifndef GUARD_WEATHER_H #define GUARD_WEATHER_H -void fade_screen(u8, s8); +#include "sprite.h" +// Controls how the weather should be changing the screen palettes. +enum { + WEATHER_PAL_STATE_CHANGING_WEATHER, + WEATHER_PAL_STATE_SCREEN_FADING_IN, + WEATHER_PAL_STATE_SCREEN_FADING_OUT, + WEATHER_PAL_STATE_IDLE, +}; + +struct Weather +{ + union + { + struct + { + struct Sprite *rainSprites[24]; + struct Sprite *snowflakeSprites[101]; + struct Sprite *cloudSprites[3]; + } s1; + struct + { + u8 filler0[0xA0]; + struct Sprite *fog1Sprites[20]; + struct Sprite *ashSprites[20]; + struct Sprite *fog2Sprites[20]; + struct Sprite *sandstormSprites1[20]; + struct Sprite *sandstormSprites2[5]; + } s2; + } sprites; + u8 gammaShifts[19][32]; + u8 altGammaShifts[19][32]; + s8 gammaIndex; + s8 gammaTargetIndex; + u8 gammaStepDelay; + u8 gammaStepFrameCounter; + u16 fadeDestColor; + u8 palProcessingState; + u8 fadeScreenCounter; + bool8 readyForInit; + u8 taskId; + u8 unknown_6CA; + u8 unknown_6CB; + u16 initStep; + u16 finishStep; + u8 currWeather; + u8 nextWeather; + u8 weatherGfxLoaded; + bool8 weatherChangeComplete; + u8 weatherPicSpritePalIndex; + u8 altGammaSpritePalIndex; + u16 unknown_6D6; + u8 unknown_6D8; + u8 unknown_6D9; + u8 rainSpriteCount; + u8 unknown_6DB; + u8 unknown_6DC; + u8 rainStrength; + /*0x6DE*/ u8 cloudSpritesCreated; + u8 filler_6DF[1]; + u16 unknown_6E0; + u16 unknown_6E2; + u8 snowflakeSpriteCount; + u8 unknown_6E5; + u16 unknown_6E6; + u16 thunderCounter; + u8 unknown_6EA; + u8 unknown_6EB; + u8 unknown_6EC; + u8 unknown_6ED; + u16 fog1ScrollPosX; + u16 unknown_6F0; + u16 unknown_6F2; + u8 lightenedFogSpritePals[6]; + u8 lightenedFogSpritePalsCount; + u8 fog1SpritesCreated; + u16 unknown_6FC; + u16 unknown_6FE; + u8 ashSpritesCreated; + u8 filler_701[3]; + u32 unknown_704; + u32 unknown_708; + u8 filler_70C[2]; + u16 unknown_70E; + u16 unknown_710; + u16 unknown_712; + u16 unknown_714; + u8 sandstormSprites1Created; + u8 sandstormSprites2Created; + u16 unknown_718; + u16 unknown_71A; + u16 unknown_71C; + u16 unknown_71E; + u16 unknown_720; + u16 unknown_722; + u8 fog2SpritesCreated; + u8 filler_725[1]; + u16 unknown_726; + u16 unknown_728; + u16 unknown_72A; + u16 unknown_72C; + u8 unknown_72E; + u8 filler_72F; + u16 currBlendEVA; + u16 currBlendEVB; + u16 targetBlendEVA; + u16 targetBlendEVB; + u8 blendUpdateCounter; + u8 blendFrameCounter; + u8 blendDelay; + u8 filler_73B[0x3C-0x3B]; + s16 unknown_73C; + s16 unknown_73E; + s16 unknown_740; + s16 unknown_742; + u8 filler_744[0xD-4]; + s8 loadDroughtPalsIndex; + u8 loadDroughtPalsOffset; +}; + +void StartWeather(void); +void ChangeWeather(u8 weather); +void sub_807C988(u8 effect); +void sub_807C9B4(u8 effect); +void Task_WeatherInit(u8); +void Task_WeatherMain(u8); +void sub_807CAE8(void); +void nullsub_38(void); +void SetWeatherScreenFadeOut(void); + +enum +{ + FADE_FROM_BLACK, + FADE_TO_BLACK, + FADE_FROM_WHITE, + FADE_TO_WHITE, +}; + +void FadeScreen(u8, s8); +// ... +void UpdateSpritePaletteWithWeather(u8 tag); +void ApplyWeatherGammaShiftToPal(u8); +// ... +void Weather_SetBlendCoeffs(u8, u8); +// ... +void PlayRainSoundEffect(void); +// ... void SetSav1Weather(u32); u8 GetSav1Weather(void); -void sub_80AEDBC(void); - +void SetSav1WeatherFromCurrMapHeader(void); +// ... void DoCurrentWeather(void); +void sub_8080750(); + +bool8 IsWeatherNotFadingIn(void); +bool8 IsWeatherChangeComplete(void); +void SetWeather(u32); +void UpdateWeatherPerDay(u16); +void PreservePaletteInWeather(u8 index); +void ResetPreservedPalettesInWeather(void); +extern void ResetDroughtWeatherPaletteLoading(void); +void ResetDroughtWeatherPaletteLoading(void); +bool8 LoadDroughtWeatherPalettes(void); +u8 GetCurrentWeather(void); +void LoadCustomWeatherSpritePalette(const u16 *palette); + + +extern struct Weather gWeather; + +extern struct Weather *const gWeatherPtr; #endif // GUARD_WEATHER_H diff --git a/include/overworld.h b/include/overworld.h index 597a160ed..974f8f091 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -70,6 +70,8 @@ void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpNum); void c2_load_new_map(void); void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); void mapldr_default(void); +u8 get_map_light_from_warp0(void); +bool8 is_light_level_1_2_3_5_or_6(u8 a1); void IncrementGameStat(u8); u32 GetGameStat(u8); diff --git a/include/time_events.h b/include/time_events.h new file mode 100644 index 000000000..fd6d29f39 --- /dev/null +++ b/include/time_events.h @@ -0,0 +1,8 @@ +#ifndef GUARD_TIME_EVENTS_H +#define GUARD_TIME_EVENTS_H + +void UpdateMirageRnd(u16); +u8 IsMirageIslandPresent(void); +void UpdateBirchState(u16); + +#endif // GUARD_TIME_EVENTS_H diff --git a/ld_script.txt b/ld_script.txt index 314ad0e62..c275fddce 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -185,7 +185,7 @@ SECTIONS { src/pokeblock.o(.text); asm/fldeff_flash.o(.text); asm/post_battle_event_funcs.o(.text); - asm/time_events.o(.text); + src/time_events.o(.text); asm/birch_pc.o(.text); src/hof_pc.o(.text); asm/field_specials.o(.text); @@ -472,7 +472,7 @@ SECTIONS { src/wallclock.o(.rodata); src/pokeblock.o(.rodata); data/fldeff_flash.o(.rodata); - data/time_events.o(.rodata); + src/time_events.o(.rodata); data/field_specials.o(.rodata); data/battle_records.o(.rodata); data/pokedex_area_screen.o(.rodata); diff --git a/src/decoration.c b/src/decoration.c index a9777c86f..68a455285 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -529,7 +529,7 @@ void SecretBasePC_PutAway(u8 taskId) { sub_8126A58(0); sub_8197434(0, 0); - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_8129ABC; } @@ -1247,7 +1247,7 @@ void sub_8127F68(u8 taskId) { if (sub_8127F38() == TRUE) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_8128060; } @@ -1661,7 +1661,7 @@ void sub_8128BA0(u8 taskId) void sub_8128BBC(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = c1_overworld_prev_quest; } @@ -2635,7 +2635,7 @@ void sub_812A1A0(u8 taskId) void sub_812A1C0(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_81298EC; } @@ -2654,7 +2654,7 @@ void sub_812A210(u8 taskId) void sub_812A22C(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_812A25C; } diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 435886638..e8f22e903 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -61,7 +61,7 @@ extern u8 sav1_map_get_name(void); extern s8 ProcessMenuInputNoWrap_(void); extern void TVShowConvertInternationalString(u8* str1, u8* str2, u8); extern void sub_806A068(u16, u8); -extern void fade_screen(u8, u8); +extern void FadeScreen(u8, u8); extern void overworld_free_bg_tilemaps(void); extern void sub_80AF168(void); extern void AllocateMonSpritesGfx(void); @@ -465,7 +465,7 @@ void EggHatch(void) { ScriptContext2_Enable(); CreateTask(Task_EggHatch, 10); - fade_screen(1, 0); + FadeScreen(1, 0); } static void Task_EggHatch(u8 taskID) diff --git a/src/scrcmd.c b/src/scrcmd.c index 0557cd95e..1768f0d4c 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -638,7 +638,7 @@ static bool8 IsPaletteNotActive(void) bool8 ScrCmd_fadescreen(struct ScriptContext *ctx) { - fade_screen(ScriptReadByte(ctx), 0); + FadeScreen(ScriptReadByte(ctx), 0); SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; } @@ -648,7 +648,7 @@ bool8 ScrCmd_fadescreenspeed(struct ScriptContext *ctx) u8 mode = ScriptReadByte(ctx); u8 speed = ScriptReadByte(ctx); - fade_screen(mode, speed); + FadeScreen(mode, speed); SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; } @@ -662,12 +662,12 @@ bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx) case 1: default: CpuCopy32(gPlttBufferUnfaded, gPaletteDecompressionBuffer, PLTT_DECOMP_BUFFER_SIZE); - fade_screen(mode, 0); + FadeScreen(mode, 0); break; case 0: case 2: CpuCopy32(gPaletteDecompressionBuffer, gPlttBufferUnfaded, PLTT_DECOMP_BUFFER_SIZE); - fade_screen(mode, 0); + FadeScreen(mode, 0); break; } @@ -726,7 +726,7 @@ bool8 ScrCmd_setweather(struct ScriptContext *ctx) bool8 ScrCmd_resetweather(struct ScriptContext *ctx) { - sub_80AEDBC(); + SetSav1WeatherFromCurrMapHeader(); return FALSE; } diff --git a/src/secret_base.c b/src/secret_base.c index bf6bec1f8..61c2511b7 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -394,7 +394,7 @@ void sub_80E8FD0(u8 taskId) void sub_80E9068(void) { CreateTask(sub_80E8FD0, 0); - fade_screen(1, 0); + FadeScreen(1, 0); saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } @@ -451,7 +451,7 @@ void sub_80E916C(u8 taskId) void sub_80E91F8(void) { CreateTask(sub_80E916C, 0); - fade_screen(1, 0); + FadeScreen(1, 0); } bool8 CurrentMapIsSecretBase(void) @@ -651,7 +651,7 @@ void sub_80E96A4(u8 taskId) void sub_80E9728(void) { CreateTask(sub_80E96A4, 0); - fade_screen(1, 0); + FadeScreen(1, 0); } void sub_80E9744(void) diff --git a/src/time_events.c b/src/time_events.c new file mode 100644 index 000000000..1f169a5c6 --- /dev/null +++ b/src/time_events.c @@ -0,0 +1,118 @@ +#include "global.h" +#include "time_events.h" +#include "event_data.h" +#include "field_weather.h" +#include "pokemon.h" +#include "random.h" +#include "overworld.h" +#include "rtc.h" +#include "script.h" +#include "task.h" + +static u32 GetMirageRnd(void) +{ + u32 hi = VarGet(VAR_MIRAGE_RND_H); + u32 lo = VarGet(VAR_MIRAGE_RND_L); + return (hi << 16) | lo; +} + +static void SetMirageRnd(u32 rnd) +{ + VarSet(VAR_MIRAGE_RND_H, rnd >> 16); + VarSet(VAR_MIRAGE_RND_L, rnd); +} + +// unused +void InitMirageRnd(void) +{ + SetMirageRnd((Random() << 16) | Random()); +} + +void UpdateMirageRnd(u16 days) +{ + s32 rnd = GetMirageRnd(); + while (days) + { + rnd = 1103515245 * rnd + 12345; + days--; + } + SetMirageRnd(rnd); +} + +bool8 IsMirageIslandPresent(void) +{ + u16 rnd = GetMirageRnd() >> 16; + int i; + + for (i = 0; i < PARTY_SIZE; i++) + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && (GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY) & 0xFFFF) == rnd) + return TRUE; + + return FALSE; +} + +void UpdateShoalTideFlag(void) +{ + static const u8 tide[] = + { + 1, // 00 + 1, // 01 + 1, // 02 + 0, // 03 + 0, // 04 + 0, // 05 + 0, // 06 + 0, // 07 + 0, // 08 + 1, // 09 + 1, // 10 + 1, // 11 + 1, // 12 + 1, // 13 + 1, // 14 + 0, // 15 + 0, // 16 + 0, // 17 + 0, // 18 + 0, // 19 + 0, // 20 + 1, // 21 + 1, // 22 + 1, // 23 + }; + + if (is_light_level_1_2_3_5_or_6(get_map_light_from_warp0())) + { + RtcCalcLocalTime(); + if (tide[gLocalTime.hours]) + FlagSet(FLAG_SYS_SHOAL_TIDE); + else + FlagClear(FLAG_SYS_SHOAL_TIDE); + } +} + +static void Task_WaitWeather(u8 taskId) +{ + if (IsWeatherChangeComplete()) + { + EnableBothScriptContexts(); + DestroyTask(taskId); + } +} + +void WaitWeather(void) +{ + CreateTask(Task_WaitWeather, 80); +} + +void InitBirchState(void) +{ + *GetVarPointer(VAR_BIRCH_STATE) = 0; +} + +void UpdateBirchState(u16 days) +{ + u16 *state = GetVarPointer(VAR_BIRCH_STATE); + *state += days; + *state %= 7; +}