Correct usage of MysteryEvent to MysteryGift

This commit is contained in:
GriffinR 2021-10-17 03:00:48 -04:00
parent d0455485c3
commit ece7ef3410
48 changed files with 2492 additions and 2492 deletions

View File

@ -956,7 +956,7 @@ gText_LegendaryFlewAway::
.string "The {STR_VAR_1} flew away!$"
.include "data/text/pc_transfer.inc"
.include "data/text/mevent.inc"
.include "data/text/questionnaire.inc"
.include "data/text/abnormal_weather.inc"
EventScript_SelectWithoutRegisteredItem::
@ -1006,7 +1006,7 @@ Common_EventScript_LegendaryFlewAway::
end
.include "data/scripts/pc_transfer.inc"
.include "data/scripts/mevent.inc"
.include "data/scripts/questionnaire.inc"
.include "data/scripts/abnormal_weather.inc"
.include "data/scripts/trainer_script.inc"
.include "data/scripts/berry_tree.inc"

View File

@ -2,7 +2,7 @@
#include "constants/flags.h"
#include "constants/items.h"
#include "constants/map_scripts.h"
#include "constants/mevent.h"
#include "constants/mystery_gift.h"
#include "constants/moves.h"
#include "constants/region_map_sections.h"
#include "constants/songs.h"
@ -15,11 +15,11 @@
.section .rodata
.align 2
.include "data/scripts/mevent_stamp_card.inc"
.include "data/scripts/mevent_pichu.inc"
.include "data/scripts/mevent_trainer.inc"
.include "data/scripts/mevent_battle_card.inc"
.include "data/scripts/mevent_aurora_ticket.inc"
.include "data/scripts/mevent_mystic_ticket.inc"
.include "data/scripts/mevent_altering_cave.inc"
.include "data/scripts/mevent_old_sea_map.inc"
.include "data/scripts/gift_stamp_card.inc"
.include "data/scripts/gift_pichu.inc"
.include "data/scripts/gift_trainer.inc"
.include "data/scripts/gift_battle_card.inc"
.include "data/scripts/gift_aurora_ticket.inc"
.include "data/scripts/gift_mystic_ticket.inc"
.include "data/scripts/gift_altering_cave.inc"
.include "data/scripts/gift_old_sea_map.inc"

View File

@ -40,11 +40,11 @@ CableClub_EventScript_DistributeEonTicket::
compare VAR_RESULT, TRUE
goto_if_eq CableClub_EventScript_AlreadyGotEonTicket
goto_if_set FLAG_ENABLE_SHIP_SOUTHERN_ISLAND, CableClub_EventScript_AlreadyGotEonTicket
msgbox Mevent_Text_TheresATicketForYou, MSGBOX_DEFAULT
msgbox MysteryGift_Text_TheresATicketForYou, MSGBOX_DEFAULT
giveitem ITEM_EON_TICKET
setflag FLAG_ENABLE_SHIP_SOUTHERN_ISLAND
setvar VAR_DISTRIBUTE_EON_TICKET, 0
msgbox Mevent_Text_TryUsingItAtLilycovePort, MSGBOX_DEFAULT
msgbox MysteryGift_Text_TryUsingItAtLilycovePort, MSGBOX_DEFAULT
release
end

View File

@ -1,10 +1,10 @@
MysteryEventScript_AlteringCave::
setvaddress MysteryEventScript_AlteringCave
MysteryGiftScript_AlteringCave::
setvaddress MysteryGiftScript_AlteringCave
addvar VAR_ALTERING_CAVE_WILD_SET, 1
compare VAR_ALTERING_CAVE_WILD_SET, 10
vgoto_if_ne MysteryEventScript_AlteringCave_
vgoto_if_ne MysteryGiftScript_AlteringCave_
setvar VAR_ALTERING_CAVE_WILD_SET, 0
MysteryEventScript_AlteringCave_:
MysteryGiftScript_AlteringCave_:
lock
faceplayer
vmessage sText_MysteryGiftAlteringCave

View File

@ -1,5 +1,5 @@
MysteryEventScript_AuroraTicket::
setvaddress MysteryEventScript_AuroraTicket
MysteryGiftScript_AuroraTicket::
setvaddress MysteryGiftScript_AuroraTicket
lock
faceplayer
vgoto_if_set FLAG_RECEIVED_AURORA_TICKET, AuroraTicket_Obtained

View File

@ -1,10 +1,10 @@
MysteryEventScript_BattleCard::
setvaddress MysteryEventScript_BattleCard
vgoto_if_set FLAG_MYSTERY_GIFT_DONE, MysteryEventScript_BattleCardInfo
MysteryGiftScript_BattleCard::
setvaddress MysteryGiftScript_BattleCard
vgoto_if_set FLAG_MYSTERY_GIFT_DONE, MysteryGiftScript_BattleCardInfo
setorcopyvar VAR_RESULT, GET_CARD_BATTLES_WON
specialvar VAR_0x8008, GetMysteryGiftCardStat
compare VAR_0x8008, REQUIRED_CARD_BATTLES
vgoto_if_ne MysteryEventScript_BattleCardInfo
vgoto_if_ne MysteryGiftScript_BattleCardInfo
lock
faceplayer
vmessage sText_MysteryGiftBattleCountCard_WonPrize
@ -15,7 +15,7 @@ MysteryEventScript_BattleCard::
setflag FLAG_MYSTERY_GIFT_DONE
end
MysteryEventScript_BattleCardInfo:
MysteryGiftScript_BattleCardInfo:
lock
faceplayer
vmessage sText_MysteryGiftBattleCountCard

View File

@ -1,5 +1,5 @@
MysteryEventScript_MysticTicket::
setvaddress MysteryEventScript_MysticTicket
MysteryGiftScript_MysticTicket::
setvaddress MysteryGiftScript_MysticTicket
lock
faceplayer
vgoto_if_set FLAG_RECEIVED_MYSTIC_TICKET, MysticTicket_Obtained

View File

@ -1,5 +1,5 @@
MysteryEventScript_OldSeaMap::
setvaddress MysteryEventScript_OldSeaMap
MysteryGiftScript_OldSeaMap::
setvaddress MysteryGiftScript_OldSeaMap
lock
faceplayer
vgoto_if_set FLAG_RECEIVED_OLD_SEA_MAP, OldSeaMap_Obtained

View File

@ -1,5 +1,5 @@
MysteryEventScript_SurfPichu::
setvaddress MysteryEventScript_SurfPichu
MysteryGiftScript_SurfPichu::
setvaddress MysteryGiftScript_SurfPichu
vgoto_if_unset FLAG_MYSTERY_GIFT_DONE, SurfPichu_GiveIfPossible
returnram

View File

@ -1,5 +1,5 @@
MysteryEventScript_StampCard::
setvaddress MysteryEventScript_StampCard
MysteryGiftScript_StampCard::
setvaddress MysteryGiftScript_StampCard
setorcopyvar VAR_RESULT, GET_MAX_STAMPS
specialvar VAR_0x8008, GetMysteryGiftCardStat
setorcopyvar VAR_RESULT, GET_NUM_STAMPS

View File

@ -1,8 +1,8 @@
MysteryEventScript_VisitingTrainer::
setvaddress MysteryEventScript_VisitingTrainer
MysteryGiftScript_VisitingTrainer::
setvaddress MysteryGiftScript_VisitingTrainer
special ValidateEReaderTrainer
compare VAR_RESULT, 0
vgoto_if_eq MysteryEventScript_VisitingTrainerArrived
vgoto_if_eq MysteryGiftScript_VisitingTrainerArrived
lock
faceplayer
vmessage sText_MysteryGiftVisitingTrainerInstructions
@ -11,7 +11,7 @@ MysteryEventScript_VisitingTrainer::
release
end
MysteryEventScript_VisitingTrainerArrived:
MysteryGiftScript_VisitingTrainerArrived:
lock
faceplayer
vmessage sText_MysteryGiftVisitingTrainerArrived

View File

@ -1,62 +0,0 @@
EventScript_Questionnaire::
lockall
msgbox Mevent_Text_FillOutQuestionnaire, MSGBOX_YESNO
compare VAR_RESULT, NO
goto_if_eq Mevent_EventScript_Release
setvar VAR_0x8004, EASY_CHAT_TYPE_QUESTIONNAIRE
call Common_ShowEasyChatScreen
lock
faceplayer
specialvar VAR_0x8008, GetMartEmployeeObjectEventId
compare VAR_0x8004, 1
goto_if_eq Mevent_EventScript_PlayerInputMysteryEventPhrase
compare VAR_0x8004, 2
goto_if_eq Mevent_EventScript_PlayerInputMysteryGiftPhrase
compare VAR_RESULT, 0
goto_if_eq Mevent_EventScript_Release
compare VAR_RESULT, 1
goto_if_eq Mevent_EventScript_QuestionnaireThankYou
end
Mevent_EventScript_PlayerInputMysteryEventPhrase::
goto_if_unset FLAG_SYS_POKEDEX_GET, Mevent_EventScript_QuestionnaireThankYou
goto_if_set FLAG_SYS_MYSTERY_EVENT_ENABLE, Mevent_EventScript_QuestionnaireThankYou
applymovement VAR_0x8008, Common_Movement_FaceDown
waitmovement 0
playse SE_PIN
applymovement VAR_0x8008, Common_Movement_ExclamationMark
waitmovement 0
applymovement VAR_0x8008, Common_Movement_Delay48
waitmovement 0
msgbox Mevent_Text_YouKnowThoseWordsEvent, MSGBOX_DEFAULT
setflag FLAG_SYS_MYSTERY_EVENT_ENABLE
msgbox Mevent_Text_YouCanAccessMysteryEvent, MSGBOX_DEFAULT
releaseall
end
Mevent_EventScript_PlayerInputMysteryGiftPhrase::
goto_if_unset FLAG_SYS_POKEDEX_GET, Mevent_EventScript_QuestionnaireThankYou
goto_if_set FLAG_SYS_MYSTERY_GIFT_ENABLE, Mevent_EventScript_QuestionnaireThankYou
applymovement VAR_0x8008, Common_Movement_FaceDown
waitmovement 0
playse SE_PIN
applymovement VAR_0x8008, Common_Movement_ExclamationMark
waitmovement 0
applymovement VAR_0x8008, Common_Movement_Delay48
waitmovement 0
msgbox Mevent_Text_YouKnowThoseWordsGift, MSGBOX_DEFAULT
setflag FLAG_SYS_MYSTERY_GIFT_ENABLE
msgbox Mevent_Text_YouCanAccessMysteryGift, MSGBOX_DEFAULT
releaseall
end
Mevent_EventScript_Release::
releaseall
end
Mevent_EventScript_QuestionnaireThankYou::
applymovement VAR_0x8008, Common_Movement_FaceDown
waitmovement 0
msgbox Mevent_Text_QuestionnaireThankYou, MSGBOX_DEFAULT
releaseall
end

View File

@ -0,0 +1,62 @@
EventScript_Questionnaire::
lockall
msgbox Questionnaire_Text_FillOut, MSGBOX_YESNO
compare VAR_RESULT, NO
goto_if_eq Questionnaire_EventScript_Release
setvar VAR_0x8004, EASY_CHAT_TYPE_QUESTIONNAIRE
call Common_ShowEasyChatScreen
lock
faceplayer
specialvar VAR_0x8008, GetMartEmployeeObjectEventId
compare VAR_0x8004, 1
goto_if_eq Questionnaire_EventScript_PlayerInputMysteryEventPhrase
compare VAR_0x8004, 2
goto_if_eq Questionnaire_EventScript_PlayerInputMysteryGiftPhrase
compare VAR_RESULT, 0
goto_if_eq Questionnaire_EventScript_Release
compare VAR_RESULT, 1
goto_if_eq Questionnaire_EventScript_ThankYou
end
Questionnaire_EventScript_PlayerInputMysteryEventPhrase::
goto_if_unset FLAG_SYS_POKEDEX_GET, Questionnaire_EventScript_ThankYou
goto_if_set FLAG_SYS_MYSTERY_EVENT_ENABLE, Questionnaire_EventScript_ThankYou
applymovement VAR_0x8008, Common_Movement_FaceDown
waitmovement 0
playse SE_PIN
applymovement VAR_0x8008, Common_Movement_ExclamationMark
waitmovement 0
applymovement VAR_0x8008, Common_Movement_Delay48
waitmovement 0
msgbox Questionnaire_Text_YouKnowThoseWordsEvent, MSGBOX_DEFAULT
setflag FLAG_SYS_MYSTERY_EVENT_ENABLE
msgbox Questionnaire_Text_YouCanAccessMysteryEvent, MSGBOX_DEFAULT
releaseall
end
Questionnaire_EventScript_PlayerInputMysteryGiftPhrase::
goto_if_unset FLAG_SYS_POKEDEX_GET, Questionnaire_EventScript_ThankYou
goto_if_set FLAG_SYS_MYSTERY_GIFT_ENABLE, Questionnaire_EventScript_ThankYou
applymovement VAR_0x8008, Common_Movement_FaceDown
waitmovement 0
playse SE_PIN
applymovement VAR_0x8008, Common_Movement_ExclamationMark
waitmovement 0
applymovement VAR_0x8008, Common_Movement_Delay48
waitmovement 0
msgbox Questionnaire_Text_YouKnowThoseWordsGift, MSGBOX_DEFAULT
setflag FLAG_SYS_MYSTERY_GIFT_ENABLE
msgbox Questionnaire_Text_YouCanAccessMysteryGift, MSGBOX_DEFAULT
releaseall
end
Questionnaire_EventScript_Release::
releaseall
end
Questionnaire_EventScript_ThankYou::
applymovement VAR_0x8008, Common_Movement_FaceDown
waitmovement 0
msgbox Questionnaire_Text_ThankYou, MSGBOX_DEFAULT
releaseall
end

View File

@ -1,14 +1,14 @@
Mevent_Text_FillOutQuestionnaire::
Questionnaire_Text_FillOut::
.string "There is a questionnaire.\n"
.string "Would you like to fill it out?$"
Mevent_Text_QuestionnaireThankYou::
Questionnaire_Text_ThankYou::
.string "Thank you for taking the time to\n"
.string "fill out our questionnaire.\p"
.string "Your feedback will be used for\n"
.string "future reference.$"
Mevent_Text_YouKnowThoseWordsGift::
Questionnaire_Text_YouKnowThoseWordsGift::
.string "Oh, hello!\n"
.string "You know those words?\p"
.string "That means you must know about\n"
@ -16,27 +16,27 @@ Mevent_Text_YouKnowThoseWordsGift::
.string "From now on, you should be\n"
.string "receiving MYSTERY GIFTS!$"
Mevent_Text_YouCanAccessMysteryGift::
Questionnaire_Text_YouCanAccessMysteryGift::
.string "Once you save your game, you can\n"
.string "access the MYSTERY GIFT.$"
Mevent_Text_YouKnowThoseWordsEvent::
Questionnaire_Text_YouKnowThoseWordsEvent::
.string "Oh, hello!\n"
.string "You know those words?\p"
.string "That means you must know about\n"
.string "the MYSTERY EVENT.$"
Mevent_Text_YouCanAccessMysteryEvent::
Questionnaire_Text_YouCanAccessMysteryEvent::
.string "Once you save your game, you can\n"
.string "access the MYSTERY EVENT.$"
Mevent_Text_TheresATicketForYou::
MysteryGift_Text_TheresATicketForYou::
.string "Thank you for using the MYSTERY\n"
.string "EVENT System.\p"
.string "You must be {PLAYER}.\n"
.string "There is a ticket here for you.$"
Mevent_Text_TryUsingItAtLilycovePort::
MysteryGift_Text_TryUsingItAtLilycovePort::
.string "It appears to be for use at\n"
.string "the LILYCOVE CITY port.\p"
.string "Why not give it a try and see what\n"

View File

@ -1,5 +1,5 @@
#ifndef GUARD_CONSTANTS_MEVENT_H
#define GUARD_CONSTANTS_MEVENT_H
#ifndef GUARD_CONSTANTS_MYSTERY_GIFT_H
#define GUARD_CONSTANTS_MYSTERY_GIFT_H
#define GET_NUM_STAMPS 0
#define GET_MAX_STAMPS 1
@ -44,4 +44,4 @@
#define WONDER_CARD_FLAG_OFFSET 1000
#endif //GUARD_MEVENT_H
#endif //GUARD_CONSTANTS_MYSTERY_GIFT_H

View File

@ -1,57 +0,0 @@
#ifndef GUARD_MEVENT_H
#define GUARD_MEVENT_H
#include "main.h"
#include "constants/mevent.h"
struct MysteryGiftLinkGameData
{
// It's possible these first 5 fields had some other meaningful purpose,
// but they are only ever set when creating this data and read to validate it.
u32 validationVar;
u16 validationFlag1;
u32 validationFlag2;
u16 validationGiftType1;
u32 validationGiftType2;
u16 flagId;
u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS];
struct WonderCardMetadata cardMetadata;
u8 maxStamps;
u8 playerName[PLAYER_NAME_LENGTH];
u8 playerTrainerId[TRAINER_ID_LENGTH];
u16 easyChatProfile[EASY_CHAT_BATTLE_WORDS_COUNT];
u8 romHeaderGameCode[GAME_CODE_LENGTH];
u8 romHeaderSoftwareVersion;
};
void ClearMysteryGift(void);
struct WonderNews *GetSavedWonderNews(void);
struct WonderCard *GetSavedWonderCard(void);
struct WonderCardMetadata *GetSavedWonderCardMetadata(void);
struct WonderNewsMetadata *GetSavedWonderNewsMetadata(void);
u16 *GetQuestionnaireWordsPtr(void);
void ClearSavedWonderNewsAndRelated(void);
void ClearSavedWonderCardAndRelated(void);
bool32 SaveWonderNews(const struct WonderNews *news);
bool32 SaveWonderCard(const struct WonderCard *card);
bool32 ValidateSavedWonderNews(void);
bool32 ValidateSavedWonderCard(void);
bool32 IsWonderNewsSameAsSaved(const u8 *news);
bool32 IsSendingSavedWonderNewsAllowed(void);
bool32 IsSendingSavedWonderCardAllowed(void);
u16 GetWonderCardFlagID(void);
void DisableWonderCardSending(struct WonderCard *card);
bool32 IsSavedWonderCardGiftNotReceived(void);
bool32 MysteryGift_TrySaveStamp(const u16 *stamp);
void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 isWonderNews);
bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 isWonderNews);
u32 MysteryGift_CompareCardFlags(const u16 *flagId, const struct MysteryGiftLinkGameData *data, const void *unused);
u32 MysteryGift_CheckStamps(const u16 *stamp, const struct MysteryGiftLinkGameData *data, const void *unused);
bool32 MysteryGift_DoesQuestionnaireMatch(const struct MysteryGiftLinkGameData *data, const u16 *words);
u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData *data, u32 stat);
u16 MysteryGift_GetCardStat(u32 stat);
void MysteryGift_DisableStats(void);
bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId);
void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId);
#endif //GUARD_MEVENT_H

View File

@ -1,16 +1,16 @@
#ifndef GUARD_MYSTERY_EVENT_MSG_H
#define GUARD_MYSTERY_EVENT_MSG_H
extern const u8 gText_MysteryGiftBerry[];
extern const u8 gText_MysteryGiftBerryTransform[];
extern const u8 gText_MysteryGiftBerryObtained[];
extern const u8 gText_MysteryGiftSpecialRibbon[];
extern const u8 gText_MysteryGiftNationalDex[];
extern const u8 gText_MysteryGiftRareWord[];
extern const u8 gText_MysteryGiftSentOver[];
extern const u8 gText_MysteryGiftFullParty[];
extern const u8 gText_MysteryGiftNewTrainer[];
extern const u8 gText_MysteryGiftNewAdversaryInBattleTower[];
extern const u8 gText_MysteryGiftCantBeUsed[];
extern const u8 gText_MysteryEventBerry[];
extern const u8 gText_MysteryEventBerryTransform[];
extern const u8 gText_MysteryEventBerryObtained[];
extern const u8 gText_MysteryEventSpecialRibbon[];
extern const u8 gText_MysteryEventNationalDex[];
extern const u8 gText_MysteryEventRareWord[];
extern const u8 gText_MysteryEventSentOver[];
extern const u8 gText_MysteryEventFullParty[];
extern const u8 gText_MysteryEventNewTrainer[];
extern const u8 gText_MysteryEventNewAdversaryInBattleTower[];
extern const u8 gText_MysteryEventCantBeUsed[];
#endif // GUARD_MYSTERY_EVENT_MSG_H

View File

@ -1,8 +1,8 @@
#ifndef GUARD_MYSTERY_EVENT_SCRIPT_H
#define GUARD_MYSTERY_EVENT_SCRIPT_H
void InitMysteryGiftScriptContext(u8 *script);
bool32 RunMysteryGiftScriptContextCommand(u32 *script);
void InitMysteryEventScriptContext(u8 *script);
bool32 RunMysteryEventScriptContextCommand(u32 *script);
u32 RunMysteryEventScript(u8 *script);
void SetMysteryEventScriptStatus(u32 val);
u16 GetRecordMixingGift(void);

63
include/mystery_gift.h Normal file → Executable file
View File

@ -1,18 +1,57 @@
#ifndef GUARD_MYSTERY_GIFT_H
#define GUARD_MYSTERY_GIFT_H
extern bool8 gGiftIsFromEReader;
#include "main.h"
#include "constants/mystery_gift.h"
u16 GetMysteryGiftBaseBlock(void);
void CB2_MysteryGiftEReader(void);
void PrintMysteryGiftOrEReaderTopMenu(bool8 isJapanese, bool32 usePickOkCancel);
void MG_DrawCheckerboardPattern(u32 bg);
void MainCB_FreeAllBuffersAndReturnToInitTitleScreen(void);
bool32 PrintMysteryGiftMenuMessage(u8 *textState, const u8 *str);
void AddTextPrinterToWindow1(const u8 *src);
void CB2_InitEReader(void);
void CB2_InitMysteryGift(void);
void MG_DrawTextBorder(u8 windowId);
s8 DoMysteryGiftYesNo(u8 *textState, u16 *windowId, bool8 yesNoBoxPlacement, const u8 *str);
struct MysteryGiftLinkGameData
{
// It's possible these first 5 fields had some other meaningful purpose,
// but they are only ever set when creating this data and read to validate it.
u32 validationVar;
u16 validationFlag1;
u32 validationFlag2;
u16 validationGiftType1;
u32 validationGiftType2;
u16 flagId;
u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS];
struct WonderCardMetadata cardMetadata;
u8 maxStamps;
u8 playerName[PLAYER_NAME_LENGTH];
u8 playerTrainerId[TRAINER_ID_LENGTH];
u16 easyChatProfile[EASY_CHAT_BATTLE_WORDS_COUNT];
u8 romHeaderGameCode[GAME_CODE_LENGTH];
u8 romHeaderSoftwareVersion;
};
void ClearMysteryGift(void);
struct WonderNews *GetSavedWonderNews(void);
struct WonderCard *GetSavedWonderCard(void);
struct WonderCardMetadata *GetSavedWonderCardMetadata(void);
struct WonderNewsMetadata *GetSavedWonderNewsMetadata(void);
u16 *GetQuestionnaireWordsPtr(void);
void ClearSavedWonderNewsAndRelated(void);
void ClearSavedWonderCardAndRelated(void);
bool32 SaveWonderNews(const struct WonderNews *news);
bool32 SaveWonderCard(const struct WonderCard *card);
bool32 ValidateSavedWonderNews(void);
bool32 ValidateSavedWonderCard(void);
bool32 IsWonderNewsSameAsSaved(const u8 *news);
bool32 IsSendingSavedWonderNewsAllowed(void);
bool32 IsSendingSavedWonderCardAllowed(void);
u16 GetWonderCardFlagID(void);
void DisableWonderCardSending(struct WonderCard *card);
bool32 IsSavedWonderCardGiftNotReceived(void);
bool32 MysteryGift_TrySaveStamp(const u16 *stamp);
void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 isWonderNews);
bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 isWonderNews);
u32 MysteryGift_CompareCardFlags(const u16 *flagId, const struct MysteryGiftLinkGameData *data, const void *unused);
u32 MysteryGift_CheckStamps(const u16 *stamp, const struct MysteryGiftLinkGameData *data, const void *unused);
bool32 MysteryGift_DoesQuestionnaireMatch(const struct MysteryGiftLinkGameData *data, const u16 *words);
u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData *data, u32 stat);
u16 MysteryGift_GetCardStat(u32 stat);
void MysteryGift_DisableStats(void);
bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId);
void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId);
#endif //GUARD_MYSTERY_GIFT_H

View File

@ -1,7 +1,7 @@
#ifndef GUARD_MEVENT_CLIENT_H
#define GUARD_MEVENT_CLIENT_H
#ifndef GUARD_MYSTERY_GIFT_CLIENT_H
#define GUARD_MYSTERY_GIFT_CLIENT_H
#include "mevent_server_helpers.h"
#include "mystery_gift_link.h"
// Return values for client functions called by MysteryGiftClient_Run
enum {
@ -31,7 +31,7 @@ enum {
CLI_COPY_MSG,
CLI_ASK_TOSS,
CLI_LOAD_TOSS_RESPONSE,
CLI_RUN_GIFT_SCRIPT,
CLI_RUN_MEVENT_SCRIPT,
CLI_SAVE_STAMP,
CLI_SAVE_RAM_SCRIPT,
CLI_RECV_EREADER_TRAINER,
@ -89,4 +89,4 @@ void MysteryGiftClient_AdvanceState(void);
void * MysteryGiftClient_GetMsg(void);
void MysteryGiftClient_SetParam(u32 value);
#endif //GUARD_MEVENT_CLIENT_H
#endif //GUARD_MYSTERY_GIFT_CLIENT_H

View File

@ -1,5 +1,5 @@
#ifndef GUARD_MEVENT_SERVER_HELPERS_H
#define GUARD_MEVENT_SERVER_HELPERS_H
#ifndef GUARD_MYSTERY_GIFT_LINK_H
#define GUARD_MYSTERY_GIFT_LINK_H
#define MG_LINK_BUFFER_SIZE 0x400
@ -46,4 +46,4 @@ bool32 MysteryGiftLink_Recv(struct MysteryGiftLink * link);
bool32 MysteryGiftLink_Send(struct MysteryGiftLink * link);
void MysteryGiftLink_InitRecv(struct MysteryGiftLink * link, u32 ident, void * dest);
#endif //GUARD_MEVENT_SERVER_HELPERS_H
#endif //GUARD_MYSTERY_GIFT_LINK_H

View File

@ -0,0 +1,18 @@
#ifndef GUARD_MYSTERY_GIFT_MENU_H
#define GUARD_MYSTERY_GIFT_MENU_H
extern bool8 gGiftIsFromEReader;
u16 GetMysteryGiftBaseBlock(void);
void CB2_MysteryGiftEReader(void);
void PrintMysteryGiftOrEReaderTopMenu(bool8 isJapanese, bool32 usePickOkCancel);
void MG_DrawCheckerboardPattern(u32 bg);
void MainCB_FreeAllBuffersAndReturnToInitTitleScreen(void);
bool32 PrintMysteryGiftMenuMessage(u8 *textState, const u8 *str);
void AddTextPrinterToWindow1(const u8 *src);
void CB2_InitEReader(void);
void CB2_InitMysteryGift(void);
void MG_DrawTextBorder(u8 windowId);
s8 DoMysteryGiftYesNo(u8 *textState, u16 *windowId, bool8 yesNoBoxPlacement, const u8 *str);
#endif //GUARD_MYSTERY_GIFT_MENU_H

View File

@ -1,7 +1,7 @@
#ifndef GUARD_MEVENT_SERVER_H
#define GUARD_MEVENT_SERVER_H
#ifndef GUARD_MYSTERY_GIFT_SERVER_H
#define GUARD_MYSTERY_GIFT_SERVER_H
#include "mevent_server_helpers.h"
#include "mystery_gift_link.h"
// Return values for Server_* functions.
// Other than SVR_RET_END, effectively useless (not checked for).
@ -97,4 +97,4 @@ void MysterGiftServer_CreateForCard();
void MysterGiftServer_CreateForNews();
u32 MysterGiftServer_Run(u16 * endVal);
#endif //GUARD_MEVENT_SERVER_H
#endif //GUARD_MYSTERY_GIFT_SERVER_H

View File

@ -1,5 +1,5 @@
#ifndef GUARD_WONDER_TRANSFER_H
#define GUARD_WONDER_TRANSFER_H
#ifndef GUARD_MYSTERY_GIFT_VIEW_H
#define GUARD_MYSTERY_GIFT_VIEW_H
enum {
NEWS_INPUT_A,
@ -21,4 +21,4 @@ u32 WonderNews_GetInput(u16 input);
void WonderNews_AddScrollIndicatorArrowPair(void);
void WonderNews_RemoveScrollIndicatorArrowPair(void);
#endif //GUARD_WONDER_TRANSFER_H
#endif //GUARD_MYSTERY_GIFT_VIEW_H

View File

@ -1,5 +1,5 @@
#ifndef GUARD_MEVENT_NEWS_H
#define GUARD_MEVENT_NEWS_H
#ifndef GUARD_WONDER_NEWS_H
#define GUARD_WONDER_NEWS_H
enum {
WONDER_NEWS_NONE,
@ -12,4 +12,4 @@ enum {
void InitSavedWonderNews(void);
void GenerateRandomWonderNews(u32 newsType);
#endif //GUARD_MEVENT_NEWS_H
#endif //GUARD_WONDER_NEWS_H

View File

@ -63,16 +63,16 @@ SECTIONS {
src/link_rfu_3.o(.text);
src/link_rfu_2.o(.text);
src/union_room.o(.text);
src/mystery_gift.o(.text);
src/mystery_gift_menu.o(.text);
src/union_room_player_avatar.o(.text);
src/wireless_communication_status_screen.o(.text);
src/union_room_battle.o(.text);
src/mevent2.o(.text);
src/wonder_transfer.o(.text);
src/mevent_server.o(.text);
src/mevent_client.o(.text);
src/mevent_server_helpers.o(.text);
src/mevent_news.o(.text);
src/mystery_gift.o(.text);
src/mystery_gift_view.o(.text);
src/mystery_gift_server.o(.text);
src/mystery_gift_client.o(.text);
src/mystery_gift_link.o(.text);
src/wonder_news.o(.text);
src/union_room_chat.o(.text);
src/berry_crush.o(.text);
src/berry_powder.o(.text);
@ -449,15 +449,15 @@ SECTIONS {
src/link_rfu_2.o(.rodata);
src/link_rfu_2.o(.rodata.str1.4);
src/union_room.o(.rodata);
src/mystery_gift.o(.rodata);
src/mystery_gift_menu.o(.rodata);
src/union_room_player_avatar.o(.rodata);
src/wireless_communication_status_screen.o(.rodata);
src/union_room_battle.o(.rodata);
src/mevent2.o(.rodata);
src/wonder_transfer.o(.rodata);
src/mevent_server.o(.rodata);
src/mevent_client.o(.rodata);
src/mevent_scripts.o(.rodata);
src/mystery_gift.o(.rodata);
src/mystery_gift_view.o(.rodata);
src/mystery_gift_server.o(.rodata);
src/mystery_gift_client.o(.rodata);
src/mystery_gift_scripts.o(.rodata);
src/union_room_chat.o(.rodata);
src/berry_crush.o(.rodata);
src/berry_powder.o(.rodata);
@ -688,7 +688,7 @@ SECTIONS {
src/text_input_strings.o(.rodata);
data/fonts.o(.rodata);
src/mystery_event_msg.o(.rodata);
data/mystery_event.o(.rodata);
data/mystery_gift.o(.rodata);
src/m4a_tables.o(.rodata);
data/sound_data.o(.rodata);
} =0

View File

@ -18,7 +18,7 @@
#include "overworld.h"
#include "palette.h"
#include "union_room.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "script.h"
#include "script_pokemon_util.h"
#include "sound.h"

View File

@ -15,7 +15,7 @@
#include "graphics.h"
#include "international_string_util.h"
#include "main.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "menu.h"
#include "overworld.h"
#include "palette.h"

View File

@ -4,7 +4,7 @@
#include "ereader_helpers.h"
#include "link.h"
#include "main.h"
#include "mystery_gift.h"
#include "mystery_gift_menu.h"
#include "save.h"
#include "sound.h"
#include "sprite.h"

View File

@ -22,7 +22,7 @@
#include "link.h"
#include "list_menu.h"
#include "main.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "match_call.h"
#include "menu.h"
#include "overworld.h"
@ -56,7 +56,7 @@
#include "constants/heal_locations.h"
#include "constants/map_types.h"
#include "constants/maps.h"
#include "constants/mevent.h"
#include "constants/mystery_gift.h"
#include "constants/script_menu.h"
#include "constants/slot_machine.h"
#include "constants/songs.h"

View File

@ -16,7 +16,7 @@
#include "task.h"
#include "text.h"
#include "save.h"
#include "mystery_gift.h"
#include "mystery_gift_menu.h"
enum {
RFUSTATE_INIT,

View File

@ -35,7 +35,7 @@
#include "text_window.h"
#include "title_screen.h"
#include "window.h"
#include "mystery_gift.h"
#include "mystery_gift_menu.h"
/*
* Main menu state machine

View File

@ -1,662 +0,0 @@
#include "global.h"
#include "util.h"
#include "main.h"
#include "event_data.h"
#include "easy_chat.h"
#include "script.h"
#include "battle_tower.h"
#include "mevent_news.h"
#include "string_util.h"
#include "new_game.h"
#include "mevent.h"
#include "constants/mevent.h"
static EWRAM_DATA bool32 sStatsEnabled = FALSE;
static void ClearSavedWonderNewsMetadata(void);
static void ClearSavedWonderNews(void);
static void ClearSavedWonderCard(void);
static bool32 ValidateWonderNews(const struct WonderNews *);
static bool32 ValidateWonderCard(const struct WonderCard *);
static void ClearSavedWonderCardMetadata(void);
static void ClearSavedTrainerIds(void);
static void IncrementCardStatForNewTrainer(u32, u32, u32 *, int);
#define CALC_CRC(data) CalcCRC16WithTable((void *)&(data), sizeof(data))
void ClearMysteryGift(void)
{
CpuFill32(0, &gSaveBlock1Ptr->mysteryGift, sizeof(gSaveBlock1Ptr->mysteryGift));
ClearSavedWonderNewsMetadata(); // Clear is redundant, InitSavedWonderNews would be sufficient
InitQuestionnaireWords();
}
struct WonderNews *GetSavedWonderNews(void)
{
return &gSaveBlock1Ptr->mysteryGift.news;
}
struct WonderCard *GetSavedWonderCard(void)
{
return &gSaveBlock1Ptr->mysteryGift.card;
}
struct WonderCardMetadata *GetSavedWonderCardMetadata(void)
{
return &gSaveBlock1Ptr->mysteryGift.cardMetadata;
}
struct WonderNewsMetadata *GetSavedWonderNewsMetadata(void)
{
return &gSaveBlock1Ptr->mysteryGift.newsMetadata;
}
u16 *GetQuestionnaireWordsPtr(void)
{
return gSaveBlock1Ptr->mysteryGift.questionnaireWords;
}
// Equivalent to ClearSavedWonderCardAndRelated, but nothing else to clear
void ClearSavedWonderNewsAndRelated(void)
{
ClearSavedWonderNews();
}
bool32 SaveWonderNews(const struct WonderNews *news)
{
if (!ValidateWonderNews(news))
return FALSE;
ClearSavedWonderNews();
gSaveBlock1Ptr->mysteryGift.news = *news;
gSaveBlock1Ptr->mysteryGift.newsCrc = CALC_CRC(gSaveBlock1Ptr->mysteryGift.news);
return TRUE;
}
bool32 ValidateSavedWonderNews(void)
{
if (CALC_CRC(gSaveBlock1Ptr->mysteryGift.news) != gSaveBlock1Ptr->mysteryGift.newsCrc)
return FALSE;
if (!ValidateWonderNews(&gSaveBlock1Ptr->mysteryGift.news))
return FALSE;
return TRUE;
}
static bool32 ValidateWonderNews(const struct WonderNews *news)
{
if (news->id == 0)
return FALSE;
return TRUE;
}
bool32 IsSendingSavedWonderNewsAllowed(void)
{
const struct WonderNews *news = &gSaveBlock1Ptr->mysteryGift.news;
if (news->sendType == SEND_TYPE_DISALLOWED)
return FALSE;
return TRUE;
}
static void ClearSavedWonderNews(void)
{
CpuFill32(0, GetSavedWonderNews(), sizeof(gSaveBlock1Ptr->mysteryGift.news));
gSaveBlock1Ptr->mysteryGift.newsCrc = 0;
}
static void ClearSavedWonderNewsMetadata(void)
{
CpuFill32(0, GetSavedWonderNewsMetadata(), sizeof(gSaveBlock1Ptr->mysteryGift.newsMetadata));
InitSavedWonderNews();
}
bool32 IsWonderNewsSameAsSaved(const u8 *news)
{
const u8 *savedNews = (const u8 *)&gSaveBlock1Ptr->mysteryGift.news;
u32 i;
if (!ValidateSavedWonderNews())
return FALSE;
for (i = 0; i < sizeof(gSaveBlock1Ptr->mysteryGift.news); i++)
{
if (savedNews[i] != news[i])
return FALSE;
}
return TRUE;
}
void ClearSavedWonderCardAndRelated(void)
{
ClearSavedWonderCard();
ClearSavedWonderCardMetadata();
ClearSavedTrainerIds();
ClearRamScript();
ClearMysteryGiftFlags();
ClearMysteryGiftVars();
ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer);
}
bool32 SaveWonderCard(const struct WonderCard *card)
{
struct WonderCardMetadata *metadata;
if (!ValidateWonderCard(card))
return FALSE;
ClearSavedWonderCardAndRelated();
memcpy(&gSaveBlock1Ptr->mysteryGift.card, card, sizeof(struct WonderCard));
gSaveBlock1Ptr->mysteryGift.cardCrc = CALC_CRC(gSaveBlock1Ptr->mysteryGift.card);
metadata = &gSaveBlock1Ptr->mysteryGift.cardMetadata;
metadata->iconSpecies = (&gSaveBlock1Ptr->mysteryGift.card)->iconSpecies;
return TRUE;
}
bool32 ValidateSavedWonderCard(void)
{
if (gSaveBlock1Ptr->mysteryGift.cardCrc != CALC_CRC(gSaveBlock1Ptr->mysteryGift.card))
return FALSE;
if (!ValidateWonderCard(&gSaveBlock1Ptr->mysteryGift.card))
return FALSE;
if (!ValidateSavedRamScript())
return FALSE;
return TRUE;
}
static bool32 ValidateWonderCard(const struct WonderCard *card)
{
if (card->flagId == 0)
return FALSE;
if (card->type >= CARD_TYPE_COUNT)
return FALSE;
if (!(card->sendType == SEND_TYPE_DISALLOWED
|| card->sendType == SEND_TYPE_ALLOWED
|| card->sendType == SEND_TYPE_ALLOWED_ALWAYS))
return FALSE;
if (card->bgType >= NUM_WONDER_BGS)
return FALSE;
if (card->maxStamps > MAX_STAMP_CARD_STAMPS)
return FALSE;
return TRUE;
}
bool32 IsSendingSavedWonderCardAllowed(void)
{
const struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (card->sendType == SEND_TYPE_DISALLOWED)
return FALSE;
return TRUE;
}
static void ClearSavedWonderCard(void)
{
CpuFill32(0, &gSaveBlock1Ptr->mysteryGift.card, sizeof(gSaveBlock1Ptr->mysteryGift.card));
gSaveBlock1Ptr->mysteryGift.cardCrc = 0;
}
static void ClearSavedWonderCardMetadata(void)
{
CpuFill32(0, GetSavedWonderCardMetadata(), sizeof(gSaveBlock1Ptr->mysteryGift.cardMetadata));
gSaveBlock1Ptr->mysteryGift.cardMetadataCrc = 0;
}
u16 GetWonderCardFlagID(void)
{
if (ValidateSavedWonderCard())
return gSaveBlock1Ptr->mysteryGift.card.flagId;
return 0;
}
void DisableWonderCardSending(struct WonderCard *card)
{
if (card->sendType == SEND_TYPE_ALLOWED)
card->sendType = SEND_TYPE_DISALLOWED;
}
static bool32 IsWonderCardFlagIDInValidRange(u16 flagId)
{
if (flagId >= WONDER_CARD_FLAG_OFFSET && flagId < WONDER_CARD_FLAG_OFFSET + NUM_WONDER_CARD_FLAGS)
return TRUE;
return FALSE;
}
static const u16 sReceivedGiftFlags[] =
{
FLAG_RECEIVED_AURORA_TICKET,
FLAG_RECEIVED_MYSTIC_TICKET,
FLAG_RECEIVED_OLD_SEA_MAP,
FLAG_WONDER_CARD_UNUSED_1,
FLAG_WONDER_CARD_UNUSED_2,
FLAG_WONDER_CARD_UNUSED_3,
FLAG_WONDER_CARD_UNUSED_4,
FLAG_WONDER_CARD_UNUSED_5,
FLAG_WONDER_CARD_UNUSED_6,
FLAG_WONDER_CARD_UNUSED_7,
FLAG_WONDER_CARD_UNUSED_8,
FLAG_WONDER_CARD_UNUSED_9,
FLAG_WONDER_CARD_UNUSED_10,
FLAG_WONDER_CARD_UNUSED_11,
FLAG_WONDER_CARD_UNUSED_12,
FLAG_WONDER_CARD_UNUSED_13,
FLAG_WONDER_CARD_UNUSED_14,
FLAG_WONDER_CARD_UNUSED_15,
FLAG_WONDER_CARD_UNUSED_16,
FLAG_WONDER_CARD_UNUSED_17,
};
bool32 IsSavedWonderCardGiftNotReceived(void)
{
u16 value = GetWonderCardFlagID();
if (!IsWonderCardFlagIDInValidRange(value))
return FALSE;
// If flag is set, player has received gift from this card
if (FlagGet(sReceivedGiftFlags[value - WONDER_CARD_FLAG_OFFSET]) == TRUE)
return FALSE;
return TRUE;
}
static int GetNumStampsInMetadata(const struct WonderCardMetadata *data, int size)
{
int numStamps = 0;
int i;
for (i = 0; i < size; i++)
{
if (data->stampData[STAMP_ID][i] && data->stampData[STAMP_SPECIES][i] != SPECIES_NONE)
numStamps++;
}
return numStamps;
}
static bool32 IsStampInMetadata(const struct WonderCardMetadata *metadata, const u16 *stamp, int maxStamps)
{
int i;
for (i = 0; i < maxStamps; i++)
{
if (metadata->stampData[STAMP_ID][i] == stamp[STAMP_ID])
return TRUE;
if (metadata->stampData[STAMP_SPECIES][i] == stamp[STAMP_SPECIES])
return TRUE;
}
return FALSE;
}
static bool32 ValidateStamp(const u16 *stamp)
{
if (stamp[STAMP_ID] == 0)
return FALSE;
if (stamp[STAMP_SPECIES] == SPECIES_NONE)
return FALSE;
if (stamp[STAMP_SPECIES] >= NUM_SPECIES)
return FALSE;
return TRUE;
}
static int GetNumStampsInSavedCard(void)
{
struct WonderCard *card;
if (!ValidateSavedWonderCard())
return 0;
card = &gSaveBlock1Ptr->mysteryGift.card;
if (card->type != CARD_TYPE_STAMP)
return 0;
return GetNumStampsInMetadata(&gSaveBlock1Ptr->mysteryGift.cardMetadata, card->maxStamps);
}
bool32 MysteryGift_TrySaveStamp(const u16 *stamp)
{
struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
int maxStamps = card->maxStamps;
int i;
if (!ValidateStamp(stamp))
return FALSE;
if (IsStampInMetadata(&gSaveBlock1Ptr->mysteryGift.cardMetadata, stamp, maxStamps))
return FALSE;
for (i = 0; i < maxStamps; i++)
{
if (gSaveBlock1Ptr->mysteryGift.cardMetadata.stampData[STAMP_ID][i] == 0
&& gSaveBlock1Ptr->mysteryGift.cardMetadata.stampData[STAMP_SPECIES][i] == SPECIES_NONE)
{
gSaveBlock1Ptr->mysteryGift.cardMetadata.stampData[STAMP_ID][i] = stamp[STAMP_ID];
gSaveBlock1Ptr->mysteryGift.cardMetadata.stampData[STAMP_SPECIES][i] = stamp[STAMP_SPECIES];
return TRUE;
}
}
return FALSE;
}
#define GAME_DATA_VALID_VAR 0x101
#define GAME_DATA_VALID_GIFT_TYPE_1 (1 << 2)
#define GAME_DATA_VALID_GIFT_TYPE_2 (1 << 9)
void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 isWonderNews)
{
int i;
CpuFill32(0, data, sizeof(*data));
data->validationVar = GAME_DATA_VALID_VAR;
data->validationFlag1 = 1;
data->validationFlag2 = 1;
if (isWonderNews)
{
// Despite setting these for News, they are
// only ever checked for Cards
data->validationGiftType1 = GAME_DATA_VALID_GIFT_TYPE_1 | 1;
data->validationGiftType2 = GAME_DATA_VALID_GIFT_TYPE_2 | 1;
}
else // Wonder Card
{
data->validationGiftType1 = GAME_DATA_VALID_GIFT_TYPE_1;
data->validationGiftType2 = GAME_DATA_VALID_GIFT_TYPE_2;
}
if (ValidateSavedWonderCard())
{
data->flagId = GetSavedWonderCard()->flagId;
data->cardMetadata = *GetSavedWonderCardMetadata();
data->maxStamps = GetSavedWonderCard()->maxStamps;
}
else
{
data->flagId = 0;
}
for (i = 0; i < NUM_QUESTIONNAIRE_WORDS; i++)
data->questionnaireWords[i] = gSaveBlock1Ptr->mysteryGift.questionnaireWords[i];
CopyTrainerId(data->playerTrainerId, gSaveBlock2Ptr->playerTrainerId);
StringCopy(data->playerName, gSaveBlock2Ptr->playerName);
for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++)
data->easyChatProfile[i] = gSaveBlock1Ptr->easyChatProfile[i];
memcpy(data->romHeaderGameCode, RomHeaderGameCode, GAME_CODE_LENGTH);
data->romHeaderSoftwareVersion = RomHeaderSoftwareVersion;
}
bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 isWonderNews)
{
if (data->validationVar != GAME_DATA_VALID_VAR)
return FALSE;
if (!(data->validationFlag1 & 1))
return FALSE;
if (!(data->validationFlag2 & 1))
return FALSE;
if (!isWonderNews)
{
if (!(data->validationGiftType1 & GAME_DATA_VALID_GIFT_TYPE_1))
return FALSE;
if (!(data->validationGiftType2 & (GAME_DATA_VALID_GIFT_TYPE_2 | 0x180)))
return FALSE;
}
return TRUE;
}
u32 MysteryGift_CompareCardFlags(const u16 *flagId, const struct MysteryGiftLinkGameData *data, const void *unused)
{
// Has a Wonder Card already?
if (data->flagId == 0)
return HAS_NO_CARD;
// Has this Wonder Card already?
if (*flagId == data->flagId)
return HAS_SAME_CARD;
// Player has a different Wonder Card
return HAS_DIFF_CARD;
}
// This is referenced by the Mystery Gift server, but the instruction it's referenced in is never used,
// so the return values here are never checked by anything.
u32 MysteryGift_CheckStamps(const u16 *stamp, const struct MysteryGiftLinkGameData *data, const void *unused)
{
int stampsMissing = data->maxStamps - GetNumStampsInMetadata(&data->cardMetadata, data->maxStamps);
// Has full stamp card?
if (stampsMissing == 0)
return 1;
// Already has stamp?
if (IsStampInMetadata(&data->cardMetadata, stamp, data->maxStamps))
return 3;
// Only 1 empty stamp left?
if (stampsMissing == 1)
return 4;
// This is a new stamp
return 2;
}
bool32 MysteryGift_DoesQuestionnaireMatch(const struct MysteryGiftLinkGameData *data, const u16 *words)
{
int i;
for (i = 0; i < NUM_QUESTIONNAIRE_WORDS; i++)
{
if (data->questionnaireWords[i] != words[i])
return FALSE;
}
return TRUE;
}
static int GetNumStampsInLinkData(const struct MysteryGiftLinkGameData *data)
{
return GetNumStampsInMetadata(&data->cardMetadata, data->maxStamps);
}
u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData *data, u32 stat)
{
switch (stat)
{
case CARD_STAT_BATTLES_WON:
return data->cardMetadata.battlesWon;
case CARD_STAT_BATTLES_LOST:
return data->cardMetadata.battlesLost;
case CARD_STAT_NUM_TRADES:
return data->cardMetadata.numTrades;
case CARD_STAT_NUM_STAMPS:
return GetNumStampsInLinkData(data);
case CARD_STAT_MAX_STAMPS:
return data->maxStamps;
default:
AGB_ASSERT(0);
return 0;
}
}
static void IncrementCardStat(u32 statType)
{
struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (card->type == CARD_TYPE_LINK_STAT)
{
u16 *stat = NULL;
switch (statType)
{
case CARD_STAT_BATTLES_WON:
stat = &gSaveBlock1Ptr->mysteryGift.cardMetadata.battlesWon;
break;
case CARD_STAT_BATTLES_LOST:
stat = &gSaveBlock1Ptr->mysteryGift.cardMetadata.battlesLost;
break;
case CARD_STAT_NUM_TRADES:
stat = &gSaveBlock1Ptr->mysteryGift.cardMetadata.numTrades;
break;
case CARD_STAT_NUM_STAMPS: // Unused
case CARD_STAT_MAX_STAMPS: // Unused
break;
}
if (stat == NULL)
AGB_ASSERT(0);
else if (++(*stat) > MAX_WONDER_CARD_STAT)
*stat = MAX_WONDER_CARD_STAT;
}
}
u16 MysteryGift_GetCardStat(u32 stat)
{
switch (stat)
{
case CARD_STAT_BATTLES_WON:
{
struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (card->type == CARD_TYPE_LINK_STAT)
{
struct WonderCardMetadata *metadata = &gSaveBlock1Ptr->mysteryGift.cardMetadata;
return metadata->battlesWon;
}
break;
}
case CARD_STAT_BATTLES_LOST:
{
struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (card->type == CARD_TYPE_LINK_STAT)
{
struct WonderCardMetadata *metadata = &gSaveBlock1Ptr->mysteryGift.cardMetadata;
return metadata->battlesLost;
}
break;
}
case CARD_STAT_NUM_TRADES:
{
struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (card->type == CARD_TYPE_LINK_STAT)
{
struct WonderCardMetadata *metadata = &gSaveBlock1Ptr->mysteryGift.cardMetadata;
return metadata->numTrades;
}
break;
}
case CARD_STAT_NUM_STAMPS:
{
struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (card->type == CARD_TYPE_STAMP)
return GetNumStampsInSavedCard();
break;
}
case CARD_STAT_MAX_STAMPS:
{
struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (card->type == CARD_TYPE_STAMP)
return card->maxStamps;
break;
}
}
AGB_ASSERT(0);
return 0;
}
void MysteryGift_DisableStats(void)
{
sStatsEnabled = FALSE;
}
bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId)
{
sStatsEnabled = FALSE;
if (flagId == 0)
return FALSE;
if (!ValidateSavedWonderCard())
return FALSE;
if (gSaveBlock1Ptr->mysteryGift.card.flagId != flagId)
return FALSE;
sStatsEnabled = TRUE;
return TRUE;
}
void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId)
{
if (sStatsEnabled)
{
switch (stat)
{
case CARD_STAT_NUM_TRADES:
IncrementCardStatForNewTrainer(CARD_STAT_NUM_TRADES,
trainerId,
gSaveBlock1Ptr->mysteryGift.trainerIds[1],
ARRAY_COUNT(gSaveBlock1Ptr->mysteryGift.trainerIds[1]));
break;
case CARD_STAT_BATTLES_WON:
IncrementCardStatForNewTrainer(CARD_STAT_BATTLES_WON,
trainerId,
gSaveBlock1Ptr->mysteryGift.trainerIds[0],
ARRAY_COUNT(gSaveBlock1Ptr->mysteryGift.trainerIds[0]));
break;
case CARD_STAT_BATTLES_LOST:
IncrementCardStatForNewTrainer(CARD_STAT_BATTLES_LOST,
trainerId,
gSaveBlock1Ptr->mysteryGift.trainerIds[0],
ARRAY_COUNT(gSaveBlock1Ptr->mysteryGift.trainerIds[0]));
break;
default:
AGB_ASSERT(0);
break;
}
}
}
static void ClearSavedTrainerIds(void)
{
CpuFill32(0, gSaveBlock1Ptr->mysteryGift.trainerIds, sizeof(gSaveBlock1Ptr->mysteryGift.trainerIds));
}
// Returns TRUE if it's a new trainer id, FALSE if an existing one.
// In either case the given trainerId is saved in element 0
static bool32 RecordTrainerId(u32 trainerId, u32 *trainerIds, int size)
{
int i, j;
for (i = 0; i < size; i++)
{
if (trainerIds[i] == trainerId)
break;
}
if (i == size)
{
// New trainer, shift array and insert new id at front
for (j = size - 1; j > 0; j--)
trainerIds[j] = trainerIds[j - 1];
trainerIds[0] = trainerId;
return TRUE;
}
else
{
// Existing trainer, shift back to old slot and move id to front
for (j = i; j > 0; j--)
trainerIds[j] = trainerIds[j - 1];
trainerIds[0] = trainerId;
return FALSE;
}
}
static void IncrementCardStatForNewTrainer(u32 stat, u32 trainerId, u32 *trainerIds, int size)
{
if (RecordTrainerId(trainerId, trainerIds, size))
IncrementCardStat(stat);
}

View File

@ -1,13 +1,13 @@
#include "global.h"
const u8 gText_MysteryGiftBerry[] = _("Obtained a {STR_VAR_2} BERRY!\nDad has it at PETALBURG GYM.");
const u8 gText_MysteryGiftBerryTransform[] = _("The {STR_VAR_1} BERRY transformed into\none {STR_VAR_2} BERRY.");
const u8 gText_MysteryGiftBerryObtained[] = _("The {STR_VAR_1} BERRY has already been\nobtained.");
const u8 gText_MysteryGiftSpecialRibbon[] = _("A special RIBBON was awarded to\nyour party POKéMON.");
const u8 gText_MysteryGiftNationalDex[] = _("The POKéDEX has been upgraded\nwith the NATIONAL MODE.");
const u8 gText_MysteryGiftRareWord[] = _("A rare word has been added.");
const u8 gText_MysteryGiftSentOver[] = _("{STR_VAR_1} was sent over!");
const u8 gText_MysteryGiftFullParty[] = _("Your party is full.\n{STR_VAR_1} could not be sent over.");
const u8 gText_MysteryGiftNewTrainer[] = _("A new TRAINER has arrived in\nHOENN.");
const u8 gText_MysteryGiftNewAdversaryInBattleTower[] = _("A new adversary has arrived in the\nBATTLE TOWER.");
const u8 gText_MysteryGiftCantBeUsed[] = _("This data can't be used in\nthis version.");
const u8 gText_MysteryEventBerry[] = _("Obtained a {STR_VAR_2} BERRY!\nDad has it at PETALBURG GYM.");
const u8 gText_MysteryEventBerryTransform[] = _("The {STR_VAR_1} BERRY transformed into\none {STR_VAR_2} BERRY.");
const u8 gText_MysteryEventBerryObtained[] = _("The {STR_VAR_1} BERRY has already been\nobtained.");
const u8 gText_MysteryEventSpecialRibbon[] = _("A special RIBBON was awarded to\nyour party POKéMON.");
const u8 gText_MysteryEventNationalDex[] = _("The POKéDEX has been upgraded\nwith the NATIONAL MODE.");
const u8 gText_MysteryEventRareWord[] = _("A rare word has been added.");
const u8 gText_MysteryEventSentOver[] = _("{STR_VAR_1} was sent over!");
const u8 gText_MysteryEventFullParty[] = _("Your party is full.\n{STR_VAR_1} could not be sent over.");
const u8 gText_MysteryEventNewTrainer[] = _("A new TRAINER has arrived in\nHOENN.");
const u8 gText_MysteryEventNewAdversaryInBattleTower[] = _("A new adversary has arrived in the\nBATTLE TOWER.");
const u8 gText_MysteryEventCantBeUsed[] = _("This data can't be used in\nthis version.");

View File

@ -43,7 +43,7 @@ static bool32 CheckCompatibility(u16 a1, u32 a2, u16 a3, u32 a4)
static void SetIncompatible(void)
{
StringExpandPlaceholders(gStringVar4, gText_MysteryGiftCantBeUsed);
StringExpandPlaceholders(gStringVar4, gText_MysteryEventCantBeUsed);
SetMysteryEventScriptStatus(3);
}
@ -65,12 +65,12 @@ static bool32 RunMysteryEventScriptCommand(struct ScriptContext *ctx)
return FALSE;
}
void InitMysteryGiftScriptContext(u8 *script)
void InitMysteryEventScriptContext(u8 *script)
{
InitMysteryEventScript(&sMysteryEventScriptContext, script);
}
bool32 RunMysteryGiftScriptContextCommand(u32 *script)
bool32 RunMysteryEventScriptContextCommand(u32 *script)
{
bool32 ret = RunMysteryEventScriptCommand(&sMysteryEventScriptContext);
*script = sMysteryEventScriptContext.data[2];
@ -229,17 +229,17 @@ bool8 MEScrCmd_setenigmaberry(struct ScriptContext *ctx)
if (!haveBerry)
{
str = gStringVar4;
message = gText_MysteryGiftBerry;
message = gText_MysteryEventBerry;
}
else if (StringCompare(gStringVar1, gStringVar2))
{
str = gStringVar4;
message = gText_MysteryGiftBerryTransform;
message = gText_MysteryEventBerryTransform;
}
else
{
str = gStringVar4;
message = gText_MysteryGiftBerryObtained;
message = gText_MysteryEventBerryObtained;
}
StringExpandPlaceholders(str, message);
@ -259,7 +259,7 @@ bool8 MEScrCmd_giveribbon(struct ScriptContext *ctx)
u8 index = ScriptReadByte(ctx);
u8 ribbonId = ScriptReadByte(ctx);
GiveGiftRibbonToParty(index, ribbonId);
StringExpandPlaceholders(gStringVar4, gText_MysteryGiftSpecialRibbon);
StringExpandPlaceholders(gStringVar4, gText_MysteryEventSpecialRibbon);
ctx->data[2] = 2;
return FALSE;
}
@ -278,7 +278,7 @@ bool8 MEScrCmd_initramscript(struct ScriptContext *ctx)
bool8 MEScrCmd_givenationaldex(struct ScriptContext *ctx)
{
EnableNationalPokedex();
StringExpandPlaceholders(gStringVar4, gText_MysteryGiftNationalDex);
StringExpandPlaceholders(gStringVar4, gText_MysteryEventNationalDex);
ctx->data[2] = 2;
return FALSE;
}
@ -286,7 +286,7 @@ bool8 MEScrCmd_givenationaldex(struct ScriptContext *ctx)
bool8 MEScrCmd_addrareword(struct ScriptContext *ctx)
{
UnlockAdditionalPhrase(ScriptReadByte(ctx));
StringExpandPlaceholders(gStringVar4, gText_MysteryGiftRareWord);
StringExpandPlaceholders(gStringVar4, gText_MysteryEventRareWord);
ctx->data[2] = 2;
return FALSE;
}
@ -320,7 +320,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx)
if (gPlayerPartyCount == PARTY_SIZE)
{
StringExpandPlaceholders(gStringVar4, gText_MysteryGiftFullParty);
StringExpandPlaceholders(gStringVar4, gText_MysteryEventFullParty);
ctx->data[2] = 3;
}
else
@ -340,7 +340,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx)
GiveMailToMon2(&gPlayerParty[PARTY_SIZE - 1], &mail);
CompactPartySlots();
CalculatePlayerPartyCount();
StringExpandPlaceholders(gStringVar4, gText_MysteryGiftSentOver);
StringExpandPlaceholders(gStringVar4, gText_MysteryEventSentOver);
ctx->data[2] = 2;
}
@ -352,7 +352,7 @@ bool8 MEScrCmd_addtrainer(struct ScriptContext *ctx)
u32 data = ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0];
memcpy(&gSaveBlock2Ptr->frontier.ereaderTrainer, (void *)data, sizeof(gSaveBlock2Ptr->frontier.ereaderTrainer));
ValidateEReaderTrainer();
StringExpandPlaceholders(gStringVar4, gText_MysteryGiftNewTrainer);
StringExpandPlaceholders(gStringVar4, gText_MysteryEventNewTrainer);
ctx->data[2] = 2;
return FALSE;
}

2130
src/mystery_gift.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,9 @@
#include "overworld.h"
#include "script.h"
#include "battle_tower.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "mystery_event_script.h"
#include "mevent_client.h"
#include "mystery_gift_client.h"
enum {
FUNC_INIT,
@ -15,8 +15,8 @@ enum {
FUNC_SEND,
FUNC_RUN,
FUNC_WAIT,
FUNC_RUN_GIFT_SCRIPT,
FUNC_RUN_BUFF_SCRIPT,
FUNC_RUN_MEVENT,
FUNC_RUN_BUFFER,
};
EWRAM_DATA static struct MysteryGiftClient * sClient = NULL;
@ -222,8 +222,8 @@ static u32 Client_Run(struct MysteryGiftClient * client)
MysteryGiftClient_InitSendWord(client, MG_LINKID_RESPONSE, TRUE);
}
break;
case CLI_RUN_GIFT_SCRIPT:
client->funcId = FUNC_RUN_GIFT_SCRIPT;
case CLI_RUN_MEVENT_SCRIPT:
client->funcId = FUNC_RUN_MEVENT;
client->funcState = 0;
break;
case CLI_SAVE_STAMP:
@ -238,7 +238,7 @@ static u32 Client_Run(struct MysteryGiftClient * client)
break;
case CLI_RUN_BUFFER_SCRIPT:
memcpy(gDecompressionBuffer, client->recvBuffer, MG_LINK_BUFFER_SIZE);
client->funcId = FUNC_RUN_BUFF_SCRIPT;
client->funcId = FUNC_RUN_BUFFER;
client->funcState = 0;
break;
}
@ -256,16 +256,16 @@ static u32 Client_Wait(struct MysteryGiftClient * client)
return CLI_RET_ACTIVE;
}
static u32 Client_RunGiftScript(struct MysteryGiftClient * client)
static u32 Client_RunMysteryEventScript(struct MysteryGiftClient * client)
{
switch (client->funcState)
{
case 0:
InitMysteryGiftScriptContext(client->recvBuffer);
InitMysteryEventScriptContext(client->recvBuffer);
client->funcState++;
break;
case 1:
if (!RunMysteryGiftScriptContextCommand(&client->param))
if (!RunMysteryEventScriptContextCommand(&client->param))
{
client->funcId = FUNC_RUN;
client->funcState = 0;
@ -296,8 +296,8 @@ static u32 MysteryGiftClient_CallFunc(struct MysteryGiftClient * client)
[FUNC_SEND] = Client_Send,
[FUNC_RUN] = Client_Run,
[FUNC_WAIT] = Client_Wait,
[FUNC_RUN_GIFT_SCRIPT] = Client_RunGiftScript,
[FUNC_RUN_BUFF_SCRIPT] = Client_RunBufferScript
[FUNC_RUN_MEVENT] = Client_RunMysteryEventScript,
[FUNC_RUN_BUFFER] = Client_RunBufferScript
};
return funcs[client->funcId](client);
}

View File

@ -8,8 +8,8 @@
#include "script.h"
#include "battle_tower.h"
#include "mystery_event_script.h"
#include "mevent.h"
#include "mevent_server_helpers.h"
#include "mystery_gift.h"
#include "mystery_gift_link.h"
/*
Handles the link connection functions used by the Mystery Gift client/server.

1618
src/mystery_gift_menu.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
#include "global.h"
#include "mevent_client.h"
#include "mevent_server.h"
#include "mevent.h"
#include "mystery_gift_client.h"
#include "mystery_gift_server.h"
#include "mystery_gift.h"
static const u8 sText_CanceledReadingCard[] = _("Canceled reading\nthe Card.");

View File

@ -1,9 +1,9 @@
#include "global.h"
#include "malloc.h"
#include "script.h"
#include "mevent.h"
#include "mevent_server.h"
#include "mevent_server_helpers.h"
#include "mystery_gift.h"
#include "mystery_gift_server.h"
#include "mystery_gift_link.h"
enum {
FUNC_INIT,

View File

@ -11,11 +11,11 @@
#include "text_window.h"
#include "string_util.h"
#include "link_rfu.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "wonder_transfer.h"
#include "mystery_gift_menu.h"
#include "mystery_gift_view.h"
#include "constants/rgb.h"
#include "constants/mevent.h"
#include "constants/mystery_gift.h"
struct WonderGraphics
{

View File

@ -43,7 +43,7 @@
#include "player_pc.h"
#include "field_specials.h"
#include "berry_powder.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "union_room_chat.h"
extern const u8 EventScript_ResetAllMapFlags[];

View File

@ -1,7 +1,7 @@
#include "global.h"
#include "script.h"
#include "event_data.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "util.h"
#include "constants/maps.h"
#include "constants/map_scripts.h"

View File

@ -19,8 +19,8 @@
#include "load_save.h"
#include "mail.h"
#include "main.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "mystery_gift_menu.h"
#include "overworld.h"
#include "palette.h"
#include "party_menu.h"

View File

@ -23,8 +23,8 @@
#include "load_save.h"
#include "menu.h"
#include "menu_helpers.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "mystery_gift_menu.h"
#include "overworld.h"
#include "palette.h"
#include "party_menu.h"

View File

@ -1,8 +1,8 @@
#include "global.h"
#include "mevent.h"
#include "mystery_gift.h"
#include "random.h"
#include "event_data.h"
#include "mevent_news.h"
#include "wonder_news.h"
/*
Wonder News related functions.

View File

@ -9,14 +9,14 @@
.include "src/link_rfu_3.o"
.include "src/link_rfu_2.o"
.include "src/union_room.o"
.include "src/mystery_gift.o"
.include "src/mystery_gift_menu.o"
.include "src/union_room_player_avatar.o"
.include "src/wireless_communication_status_screen.o"
.include "src/union_room_battle.o"
.include "src/mevent2.o"
.include "src/wonder_transfer.o"
.include "src/mevent_server.o"
.include "src/mevent_client.o"
.include "src/mystery_gift.o"
.include "src/mystery_gift_view.o"
.include "src/mystery_gift_server.o"
.include "src/mystery_gift_client.o"
.include "src/union_room_chat.o"
.include "src/berry_crush.o"
.include "src/berry_powder.o"