Skip to content

Commit

Permalink
Merge pull request #199 from red031000/master
Browse files Browse the repository at this point in the history
diamond_dust to field_system_weather
  • Loading branch information
adrienntindall authored Jul 18, 2023
2 parents 084c3f1 + 3b5ab11 commit ba60571
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 63 deletions.
8 changes: 4 additions & 4 deletions include/diamond_dust.h → include/field_system_rtc_weather.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef POKEHEARTGOLD_DIAMOND_DUST_H
#define POKEHEARTGOLD_DIAMOND_DUST_H
#ifndef POKEHEARTGOLD_FIELD_SYSTEM_RTC_WEATHER_H
#define POKEHEARTGOLD_FIELD_SYSTEM_RTC_WEATHER_H

#include "save.h"
#include "sav_system_info.h"
Expand All @@ -25,6 +25,6 @@ typedef struct MonthDay {
u8 day;
} MonthDay;

u32 Fsys_GetWeather_HandleDiamondDust(FieldSystem* fsys, u32 mapId);
u32 FieldSystem_GetWeather_HandleDiamondDust(FieldSystem *fieldSystem, u32 mapId);

#endif //POKEHEARTGOLD_DIAMOND_DUST_H
#endif //POKEHEARTGOLD_FIELD_SYSTEM_RTC_WEATHER_H
42 changes: 21 additions & 21 deletions include/sav_system_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@
#include <nitro/rtc/ARM9/api.h>
#include "save.h"

typedef struct SYSINFO_RTC {
typedef struct SysInfo_RTC {
BOOL initialized;
RTCDate date;
RTCTime time;
s32 days_since_nitro_epoch;
s64 seconds_since_nitro_epoch;
s64 seconds_at_game_clear;
u32 unk34;
} SYSINFO_RTC;
} SysInfo_RTC;

typedef struct SYSINFO {
typedef struct SysInfo {
s64 rtc_offset;
u8 mac_address[6];
u8 birth_month;
u8 birth_day;
SYSINFO_RTC rtc_info;
SysInfo_RTC rtc_info;
u8 mysteryGiftActive;
void* unk4C;
u8 unk50[0xC];
} SYSINFO;
} SysInfo;

u32 Save_SysInfo_sizeof(void);
void Save_SysInfo_Init(SYSINFO* sys_info);
SYSINFO* Save_SysInfo_Get(SaveData* savedata);
SYSINFO_RTC* Save_SysInfo_RTC_Get(SaveData* savedata);
void Save_SysInfo_InitFromSystem(SYSINFO* sys_info);
BOOL Save_SysInfo_MacAddressIsMine(SYSINFO* sys_info);
BOOL Save_SysInfo_RTCOffsetIsMine(SYSINFO* sys_info);
u8 Save_SysInfo_GetBirthMonth(SYSINFO* sys_info);
u8 Save_SysInfo_GetBirthDay(SYSINFO* sys_info);
u8 Save_SysInfo_GetMysteryGiftActive(SYSINFO* sys_info);
void Save_SysInfo_SetMysteryGiftActive(SYSINFO* sys_info, u8);
void* Save_SysInfo_GetField4C(SYSINFO* sys_info);
void Save_SysInfo_SetField4C(SYSINFO* sys_info, void*);
void Save_SysInfo_RTC_Init(SYSINFO_RTC* rtc_info);
BOOL sub_02028E1C(SYSINFO_RTC* rtc_info);
void Save_SysInfo_RTC_SubField34(SYSINFO_RTC* rtc_info, u32);
void SysInfoRTC_HandleContinueOnNewConsole(SYSINFO_RTC* rtc_info);
void Save_SysInfo_Init(SysInfo* sys_info);
SysInfo* Save_SysInfo_Get(SaveData* savedata);
SysInfo_RTC *Save_SysInfo_RTC_Get(SaveData* savedata);
void Save_SysInfo_InitFromSystem(SysInfo* sys_info);
BOOL Save_SysInfo_MacAddressIsMine(SysInfo* sys_info);
BOOL Save_SysInfo_RTCOffsetIsMine(SysInfo* sys_info);
u8 Save_SysInfo_GetBirthMonth(SysInfo* sys_info);
u8 Save_SysInfo_GetBirthDay(SysInfo* sys_info);
u8 Save_SysInfo_GetMysteryGiftActive(SysInfo* sys_info);
void Save_SysInfo_SetMysteryGiftActive(SysInfo* sys_info, u8);
void* Save_SysInfo_GetField4C(SysInfo* sys_info);
void Save_SysInfo_SetField4C(SysInfo* sys_info, void*);
void Save_SysInfo_RTC_Init(SysInfo_RTC *rtc_info);
BOOL sub_02028E1C(SysInfo_RTC *rtc_info);
void Save_SysInfo_RTC_SubField34(SysInfo_RTC *rtc_info, u32);
void SysInfoRTC_HandleContinueOnNewConsole(SysInfo_RTC *rtc_info);

#endif
4 changes: 2 additions & 2 deletions include/unk_02055418.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ typedef struct UnkStruct_020556FC {
} UnkStruct_020556FC; //size 0x60

void FieldSys_StartBugContestTimer(FieldSystem* fsys);
void sub_02055450(FieldSystem* fsys, SYSINFO_RTC* sysinfo, RTCDate* date);
void sub_02055478(FieldSystem* fsys, SYSINFO_RTC* sysinfo, RTCDate* date, RTCTime* time);
void sub_02055450(FieldSystem* fsys, SysInfo_RTC *sysinfo, RTCDate* date);
void sub_02055478(FieldSystem* fsys, SysInfo_RTC *sysinfo, RTCDate* date, RTCTime* time);
void sub_02055508(FieldSystem* fsys, int unkA);
void sub_020555B4(FieldSystem* fsys, u32 unkA, RTCTime* time);
TIMEOFDAY Field_GetTimeOfDay(FieldSystem *fsys);
Expand Down
2 changes: 1 addition & 1 deletion main.lsf
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Static main
Object src/map_events.o
Object src/save_local_field_data.o
Object asm/unk_0203BA5C.o
Object src/diamond_dust.o
Object src/field_system_rtc_weather.o
Object asm/unk_0203BC10.o
Object asm/unk_0203DB6C.o
Object src/field_system.o
Expand Down
9 changes: 4 additions & 5 deletions src/diamond_dust.c → src/field_system_rtc_weather.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "global.h"
#include "diamond_dust.h"
#include "field_system_rtc_weather.h"
#include "map_header.h"
#include "unk_02055418.h"
#include "constants/maps.h"
Expand All @@ -15,19 +15,18 @@ const MonthDay DiamondDustDates[] = {
{ DECEMBER, 31 },
}; //_020FA09C

u32 Fsys_GetWeather_HandleDiamondDust(FieldSystem* fsys, u32 mapId) {
u32 FieldSystem_GetWeather_HandleDiamondDust(FieldSystem *fieldSystem, u32 mapId) {
u8 c;

u32 weatherType = MapHeader_GetWeatherType(mapId);
if (mapId != MAP_D41R0108) {
return weatherType;
}
SYSINFO_RTC* sysinfo_rtc = Save_SysInfo_RTC_Get(fsys->savedata);
SysInfo_RTC *sysinfo_rtc = Save_SysInfo_RTC_Get(fieldSystem->savedata);
for (c = 0; c < NELEMS(DiamondDustDates); c++) {
u8 month = DiamondDustDates[c].month;
u8 day = DiamondDustDates[c].day;
if ((sysinfo_rtc->date.month == month) && (sysinfo_rtc->date.day == day)) {
if (!sub_02055670(fsys)) {
if (!sub_02055670(fieldSystem)) {
weatherType = MAP_WEATHER_DIAMOND_DUST;
}
return weatherType;
Expand Down
4 changes: 2 additions & 2 deletions src/field_warp_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "field_map_object.h"
#include "field_follow_poke.h"
#include "unk_02056D7C.h"
#include "diamond_dust.h"
#include "field_system_rtc_weather.h"
#include "task.h"
#include "unk_02055244.h"
#include "sound.h"
Expand Down Expand Up @@ -185,7 +185,7 @@ void sub_02053038(FieldSystem *fsys, BOOL isConnection) {
SetLakeOfRageWaterLevel(fsys->mapMatrix, ShouldUseAlternateLakeOfRage(fsys->savedata, mapId));
}
varsFlags = Save_VarsFlags_Get(fsys->savedata);
weather = Fsys_GetWeather_HandleDiamondDust(fsys, mapId);
weather = FieldSystem_GetWeather_HandleDiamondDust(fsys, mapId);
if (sub_02066C74(varsFlags, 1) && mapId == MAP_T29) {
weather = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/overlay_36.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ BOOL ov36_App_MainMenu_SelectOption_Continue_AppExec(OVY_MANAGER* man, int* stat
#pragma unused(state)
struct UnkStruct_02111868_sub* unk_work = OverlayManager_GetArgs(man);
SaveData* savedata = unk_work->savedata;
SYSINFO* sys_info = Save_SysInfo_Get(savedata);
SysInfo* sys_info = Save_SysInfo_Get(savedata);

Continue_LoadSaveData_HandleError(HEAPID_OV36, savedata);

Expand Down
38 changes: 19 additions & 19 deletions src/sav_system_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
#include "sav_system_info.h"

u32 Save_SysInfo_sizeof(void) {
return sizeof(SYSINFO);
return sizeof(SysInfo);
}

void Save_SysInfo_Init(SYSINFO* sys_info) {
MI_CpuClearFast(sys_info, sizeof(SYSINFO));
void Save_SysInfo_Init(SysInfo* sys_info) {
MI_CpuClearFast(sys_info, sizeof(SysInfo));
Save_SysInfo_RTC_Init(&sys_info->rtc_info);
}

SYSINFO* Save_SysInfo_Get(SaveData* savedata) {
SysInfo* Save_SysInfo_Get(SaveData* savedata) {
return SaveArray_Get(savedata, SAVE_SYSINFO);
}

SYSINFO_RTC* Save_SysInfo_RTC_Get(SaveData* savedata) {
SYSINFO* sys_info = Save_SysInfo_Get(savedata);
SysInfo_RTC *Save_SysInfo_RTC_Get(SaveData* savedata) {
SysInfo* sys_info = Save_SysInfo_Get(savedata);
return &sys_info->rtc_info;
}

void Save_SysInfo_InitFromSystem(SYSINFO* sys_info) {
void Save_SysInfo_InitFromSystem(SysInfo* sys_info) {
OSOwnerInfo owner_info;

sys_info->rtc_offset = OS_GetOwnerRtcOffset();
Expand All @@ -33,7 +33,7 @@ void Save_SysInfo_InitFromSystem(SYSINFO* sys_info) {
sys_info->birth_day = owner_info.birthday.day;
}

BOOL Save_SysInfo_MacAddressIsMine(SYSINFO* sys_info) {
BOOL Save_SysInfo_MacAddressIsMine(SysInfo* sys_info) {
u8 mac_address[6];
OS_GetMacAddress(mac_address);

Expand All @@ -46,37 +46,37 @@ BOOL Save_SysInfo_MacAddressIsMine(SYSINFO* sys_info) {
return TRUE;
}

BOOL Save_SysInfo_RTCOffsetIsMine(SYSINFO* sys_info) {
BOOL Save_SysInfo_RTCOffsetIsMine(SysInfo* sys_info) {
return sys_info->rtc_offset == OS_GetOwnerRtcOffset();
}

u8 Save_SysInfo_GetBirthMonth(SYSINFO* sys_info) {
u8 Save_SysInfo_GetBirthMonth(SysInfo* sys_info) {
return sys_info->birth_month;
}

u8 Save_SysInfo_GetBirthDay(SYSINFO* sys_info) {
u8 Save_SysInfo_GetBirthDay(SysInfo* sys_info) {
return sys_info->birth_day;
}

u8 Save_SysInfo_GetMysteryGiftActive(SYSINFO* sys_info) {
u8 Save_SysInfo_GetMysteryGiftActive(SysInfo* sys_info) {
return sys_info->mysteryGiftActive;
}

void Save_SysInfo_SetMysteryGiftActive(SYSINFO* sys_info, u8 a1) {
void Save_SysInfo_SetMysteryGiftActive(SysInfo* sys_info, u8 a1) {
sys_info->mysteryGiftActive = a1;
}

void* Save_SysInfo_GetField4C(SYSINFO* sys_info) {
void* Save_SysInfo_GetField4C(SysInfo* sys_info) {
return sys_info->unk4C;
}

void Save_SysInfo_SetField4C(SYSINFO* sys_info, void* a1) {
void Save_SysInfo_SetField4C(SysInfo* sys_info, void* a1) {
if (sys_info->unk4C == NULL) {
sys_info->unk4C = a1;
}
}

void Save_SysInfo_RTC_Init(SYSINFO_RTC* rtc_info) {
void Save_SysInfo_RTC_Init(SysInfo_RTC *rtc_info) {
rtc_info->initialized = TRUE;
GF_RTC_CopyDateTime(&rtc_info->date, &rtc_info->time);
rtc_info->days_since_nitro_epoch = RTC_ConvertDateToDay(&rtc_info->date);
Expand All @@ -85,11 +85,11 @@ void Save_SysInfo_RTC_Init(SYSINFO_RTC* rtc_info) {
rtc_info->unk34 = 0;
}

BOOL sub_02028E1C(SYSINFO_RTC* rtc_info) {
BOOL sub_02028E1C(SysInfo_RTC *rtc_info) {
return rtc_info->unk34 != 0;
}

void Save_SysInfo_RTC_SubField34(SYSINFO_RTC* rtc_info, u32 a1) {
void Save_SysInfo_RTC_SubField34(SysInfo_RTC *rtc_info, u32 a1) {
if (rtc_info->unk34 > 1440) {
rtc_info->unk34 = 1440;
}
Expand All @@ -102,7 +102,7 @@ void Save_SysInfo_RTC_SubField34(SYSINFO_RTC* rtc_info, u32 a1) {
rtc_info->unk34 -= a1;
}

void SysInfoRTC_HandleContinueOnNewConsole(SYSINFO_RTC* rtc_info) {
void SysInfoRTC_HandleContinueOnNewConsole(SysInfo_RTC *rtc_info) {
rtc_info->unk34 = 1440;
GF_RTC_CopyDateTime(&rtc_info->date, &rtc_info->time);
rtc_info->days_since_nitro_epoch = RTC_ConvertDateToDay(&rtc_info->date);
Expand Down
2 changes: 1 addition & 1 deletion src/scrcmd_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -3892,7 +3892,7 @@ BOOL ScrCmd_539(ScriptContext *ctx) {
BOOL ScrCmd_543(ScriptContext *ctx) {
u16 *p_ret = ScriptGetVarPointer(ctx);
FieldSystem *fsys = ctx->fsys;
SYSINFO *sysInfo = Save_SysInfo_Get(fsys->savedata);
SysInfo *sysInfo = Save_SysInfo_Get(fsys->savedata);
if (Save_SysInfo_GetBirthMonth(sysInfo) == Field_GetMonth(fsys) && Save_SysInfo_GetBirthDay(sysInfo) == Field_GetDay(fsys)) {
*p_ret = TRUE;
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/unk_02055418.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
void FieldSys_StartBugContestTimer(FieldSystem* fsys) {
RTCDate date;
RTCTime time;
SYSINFO_RTC* sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
SysInfo_RTC *sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
if (!sysinfo->initialized) {
return;
}
Expand All @@ -33,7 +33,7 @@ void FieldSys_StartBugContestTimer(FieldSystem* fsys) {
sub_02055478(fsys, sysinfo, &date, &time);
}

void sub_02055450(FieldSystem* fsys, SYSINFO_RTC* sysinfo, RTCDate* date) {
void sub_02055450(FieldSystem* fsys, SysInfo_RTC *sysinfo, RTCDate* date) {
u32 day = RTC_ConvertDateToDay(date);
if (day < (u32)(sysinfo->days_since_nitro_epoch)) {
sysinfo->days_since_nitro_epoch = day;
Expand All @@ -46,7 +46,7 @@ void sub_02055450(FieldSystem* fsys, SYSINFO_RTC* sysinfo, RTCDate* date) {
sysinfo->days_since_nitro_epoch = day;
}

void sub_02055478(FieldSystem* fsys, SYSINFO_RTC* sysinfo, RTCDate* date, RTCTime* time) {
void sub_02055478(FieldSystem* fsys, SysInfo_RTC *sysinfo, RTCDate* date, RTCTime* time) {
s64 seconds = RTC_ConvertDateTimeToSecond(date, time);
s64 sys_seconds = RTC_ConvertDateTimeToSecond(&sysinfo->date, &sysinfo->time);
if (seconds < sys_seconds) {
Expand Down Expand Up @@ -116,22 +116,22 @@ u32 Field_GetHour(FieldSystem* fsys) {
}

void sub_02055624(FieldSystem* fsys, RTCDate* date, RTCTime* time) {
SYSINFO_RTC* sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
SysInfo_RTC *sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
RTC_ConvertSecondToDateTime(date, time, sysinfo->seconds_since_nitro_epoch);
}

void FieldSys_GetGameClearTime(FieldSystem* fsys, RTCDate* date, RTCTime* time) {
SYSINFO_RTC* sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
SysInfo_RTC *sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
RTC_ConvertSecondToDateTime(date, time, sysinfo->seconds_at_game_clear);
}

void FieldSys_SetGameClearTime(FieldSystem* fsys) {
SYSINFO_RTC* sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
SysInfo_RTC *sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
sysinfo->seconds_at_game_clear = GF_RTC_DateTimeToSec();
}

BOOL sub_02055670(FieldSystem* fsys) {
SYSINFO_RTC* sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
SysInfo_RTC *sysinfo = Save_SysInfo_RTC_Get(fsys->savedata);
return sub_02028E1C(sysinfo);
}

Expand Down

0 comments on commit ba60571

Please sign in to comment.