From 0c380862d61a9c4eccd9ed4915e12db6e7ca4310 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 13 Mar 2023 15:37:46 -0400 Subject: [PATCH] Document the trendy saying word group --- data/scripts/mauville_man.inc | 10 ++-- data/specials.inc | 4 +- include/constants/easy_chat.h | 2 +- include/constants/flags.h | 2 +- include/easy_chat.h | 4 +- include/global.h | 6 +-- src/easy_chat.c | 97 +++++++++++++++++++++-------------- src/mauville_old_man.c | 19 +++---- src/mystery_event_script.c | 2 +- 9 files changed, 83 insertions(+), 63 deletions(-) diff --git a/data/scripts/mauville_man.inc b/data/scripts/mauville_man.inc index eda3505bf4..a336360436 100644 --- a/data/scripts/mauville_man.inc +++ b/data/scripts/mauville_man.inc @@ -64,9 +64,9 @@ MauvilleCity_PokemonCenter_1F_EventScript_DeclineWritingLyrics:: MauvilleCity_PokemonCenter_1F_EventScript_Hipster:: lock faceplayer - setflag FLAG_SYS_HIPSTER_MEET + setflag FLAG_UNLOCKED_TRENDY_SAYINGS msgbox MauvilleCity_PokemonCenter_1F_Text_TeachWhatsHipAndHappening, MSGBOX_DEFAULT - special GetHipsterSpokenFlag + special HasHipsterTaughtWord goto_if_eq VAR_RESULT, FALSE, MauvilleCity_PokemonCenter_1F_EventScript_TryTeachWord msgbox MauvilleCity_PokemonCenter_1F_Text_IAlreadyTaughtYou, MSGBOX_DEFAULT release @@ -80,8 +80,8 @@ MauvilleCity_PokemonCenter_1F_EventScript_TryTeachWord:: end MauvilleCity_PokemonCenter_1F_EventScript_TeachWord:: - msgbox MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfPhrase, MSGBOX_DEFAULT - special SetHipsterSpokenFlag + msgbox MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfWord, MSGBOX_DEFAULT + special SetHipsterTaughtWord release end @@ -969,7 +969,7 @@ MauvilleCity_PokemonCenter_1F_Text_IveGotNothingNewToTeach: .string "what's hip and happening.\p" .string "I've got nothing new to teach you!$" -MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfPhrase: +MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfWord: .string "Hey, have you heard about\n" .string "“{STR_VAR_1}”?\p" .string "What's it mean? Well…\n" diff --git a/data/specials.inc b/data/specials.inc index a0dbde8683..52b539a805 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -111,8 +111,8 @@ gSpecials:: def_special Script_GetCurrentMauvilleMan def_special HasBardSongBeenChanged def_special SaveBardSongLyrics - def_special GetHipsterSpokenFlag - def_special SetHipsterSpokenFlag + def_special HasHipsterTaughtWord + def_special SetHipsterTaughtWord def_special HipsterTryTeachWord def_special PlayBardSong def_special SetMauvilleOldManObjEventGfx diff --git a/include/constants/easy_chat.h b/include/constants/easy_chat.h index b5875b8814..b1f38941fc 100644 --- a/include/constants/easy_chat.h +++ b/include/constants/easy_chat.h @@ -1095,7 +1095,7 @@ #define EC_WORD_OLD ((EC_GROUP_TRENDY_SAYING << EC_MASK_BITS) | 30) #define EC_WORD_YOUNG ((EC_GROUP_TRENDY_SAYING << EC_MASK_BITS) | 31) #define EC_WORD_UGLY ((EC_GROUP_TRENDY_SAYING << EC_MASK_BITS) | 32) -#define NUM_ADDITIONAL_PHRASES 33 +#define NUM_TRENDY_SAYINGS 33 // Special Berry Masters Wife phrases #define NOT_SPECIAL_PHRASE 0 diff --git a/include/constants/flags.h b/include/constants/flags.h index 99a8377a75..377f18107d 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -1348,7 +1348,7 @@ #define FLAG_UNUSED_0x863 (SYSTEM_FLAGS + 0x3) // Unused Flag #define FLAG_SYS_GAME_CLEAR (SYSTEM_FLAGS + 0x4) #define FLAG_SYS_CHAT_USED (SYSTEM_FLAGS + 0x5) -#define FLAG_SYS_HIPSTER_MEET (SYSTEM_FLAGS + 0x6) +#define FLAG_UNLOCKED_TRENDY_SAYINGS (SYSTEM_FLAGS + 0x6) // Badges #define FLAG_BADGE01_GET (SYSTEM_FLAGS + 0x7) diff --git a/include/easy_chat.h b/include/easy_chat.h index c9ef4428f7..4bcc7389cd 100644 --- a/include/easy_chat.h +++ b/include/easy_chat.h @@ -128,11 +128,11 @@ void InitializeEasyChatWordArray(u16 *words, u16 length); u8 *ConvertEasyChatWordsToString(u8 *dest, const u16 *src, u16 columns, u16 rows); bool8 IsBardWordInvalid(u16 word); u16 GetRandomEasyChatWordFromGroup(u16 group); -u16 GetNewHipsterPhraseToTeach(void); +u16 UnlockRandomTrendySaying(void); u16 EasyChat_GetNumWordsInGroup(u8); u16 GetRandomEasyChatWordFromUnlockedGroup(u16); void DoEasyChatScreen(u8 type, u16 *words, MainCallback callback, u8 displayedPersonType); void InitQuestionnaireWords(void); -void UnlockAdditionalPhrase(u8 additionalPhraseId); +void UnlockTrendySaying(u8 wordIndex); #endif // GUARD_EASYCHAT_H diff --git a/include/global.h b/include/global.h index e0ff9f0c23..9396a95f7a 100644 --- a/include/global.h +++ b/include/global.h @@ -133,7 +133,7 @@ // values that don't appear in the Pokedex. NATIONAL_DEX_COUNT does not include these values. #define NUM_DEX_FLAG_BYTES ROUND_BITS_TO_BYTES(NUM_SPECIES) #define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT) -#define NUM_ADDITIONAL_PHRASE_BYTES ROUND_BITS_TO_BYTES(NUM_ADDITIONAL_PHRASES) +#define NUM_TRENDY_SAYING_BYTES ROUND_BITS_TO_BYTES(NUM_TRENDY_SAYINGS) // This produces an error at compile-time if expr is zero. // It looks like file.c:line: size of array `id' is negative @@ -673,7 +673,7 @@ struct MauvilleManGiddy struct MauvilleManHipster { u8 id; - bool8 alreadySpoken; + bool8 taughtWord; u8 language; }; @@ -1031,7 +1031,7 @@ struct SaveBlock1 /*0x2BC8*/ u16 easyChatBattleWon[EASY_CHAT_BATTLE_WORDS_COUNT]; /*0x2BD4*/ u16 easyChatBattleLost[EASY_CHAT_BATTLE_WORDS_COUNT]; /*0x2BE0*/ struct Mail mail[MAIL_COUNT]; - /*0x2E20*/ u8 additionalPhrases[NUM_ADDITIONAL_PHRASE_BYTES]; // bitfield for 33 additional phrases in easy chat system + /*0x2E20*/ u8 unlockedTrendySayings[NUM_TRENDY_SAYING_BYTES]; // Bitfield for unlockable Easy Chat words in EC_GROUP_TRENDY_SAYING /*0x2E25*/ //u8 padding5[3]; /*0x2E28*/ OldMan oldMan; /*0x2e64*/ struct DewfordTrend dewfordTrends[SAVED_TRENDS_COUNT]; diff --git a/src/easy_chat.c b/src/easy_chat.c index d08ea4b33d..35ba633cf4 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -5109,7 +5109,7 @@ static bool8 IsEasyChatGroupUnlocked(u8 groupId) switch (groupId) { case EC_GROUP_TRENDY_SAYING: - return FlagGet(FLAG_SYS_HIPSTER_MEET); + return FlagGet(FLAG_UNLOCKED_TRENDY_SAYINGS); case EC_GROUP_EVENTS: case EC_GROUP_MOVE_1: case EC_GROUP_MOVE_2: @@ -5425,80 +5425,99 @@ void BufferDeepLinkPhrase(void) CopyEasyChatWord(gStringVar2, easyChatWord); } -static bool8 IsAdditionalPhraseUnlocked(u8 additionalPhraseId) +/* + ### Trendy Sayings + + Not to be confused with Dewford Town's "trendy phrase". + + This is a group of easy chat words (EC_GROUP_TRENDY_SAYING) that are normally inaccessible. + They can be unlocked either through Mystery Event (where they're referred to as "rare" words) + or from the "Hipster" variety of the Mauville Old Man. The Hipster can unlock one word each + time he is received via record mixing (and once if he is the player's default Old Man). + + Which words have been unlocked is saved in the unlockedTrendySayings bitfield in SaveBlock1 + + Unlocked trendy saying words are only accessible if the flag FLAG_UNLOCKED_TRENDY_SAYINGS is set. + It's set any time the player talks to the Hipster, but is not apparently set by Mystery Event, + meaning trendy saying words unlocked via Mystery Event may not be available until the player has + talked to the Hipster. +*/ +static bool8 IsTrendySayingUnlocked(u8 wordIndex) { - int byteOffset = additionalPhraseId / 8; - int shift = additionalPhraseId % 8; - return (gSaveBlock1Ptr->additionalPhrases[byteOffset] >> shift) & 1; + int byteOffset = wordIndex / 8; + int shift = wordIndex % 8; + return (gSaveBlock1Ptr->unlockedTrendySayings[byteOffset] >> shift) & 1; } -void UnlockAdditionalPhrase(u8 additionalPhraseId) +void UnlockTrendySaying(u8 wordIndex) { - if (additionalPhraseId < NUM_ADDITIONAL_PHRASES) + if (wordIndex < NUM_TRENDY_SAYINGS) { - int byteOffset = additionalPhraseId / 8; - int shift = additionalPhraseId % 8; - gSaveBlock1Ptr->additionalPhrases[byteOffset] |= 1 << shift; + int byteOffset = wordIndex / 8; + int shift = wordIndex % 8; + gSaveBlock1Ptr->unlockedTrendySayings[byteOffset] |= 1 << shift; } } -static u8 GetNumAdditionalPhrasesUnlocked(void) +static u8 GetNumTrendySayingsUnlocked(void) { u8 i; - u8 numAdditionalPhrasesUnlocked; + u8 numUnlocked; - for (i = 0, numAdditionalPhrasesUnlocked = 0; i < NUM_ADDITIONAL_PHRASES; i++) + for (i = 0, numUnlocked = 0; i < NUM_TRENDY_SAYINGS; i++) { - if (IsAdditionalPhraseUnlocked(i)) - numAdditionalPhrasesUnlocked++; + if (IsTrendySayingUnlocked(i)) + numUnlocked++; } - return numAdditionalPhrasesUnlocked; + return numUnlocked; } -u16 GetNewHipsterPhraseToTeach(void) +u16 UnlockRandomTrendySaying(void) { u16 i; - u16 additionalPhraseId; - u8 numAdditionalPhrasesUnlocked = GetNumAdditionalPhrasesUnlocked(); - if (numAdditionalPhrasesUnlocked == NUM_ADDITIONAL_PHRASES) + u16 numToSkip; + u8 numUnlocked = GetNumTrendySayingsUnlocked(); + if (numUnlocked == NUM_TRENDY_SAYINGS) return EC_EMPTY_WORD; - additionalPhraseId = Random() % (NUM_ADDITIONAL_PHRASES - numAdditionalPhrasesUnlocked); - for (i = 0; i < NUM_ADDITIONAL_PHRASES; i++) + numToSkip = Random() % (NUM_TRENDY_SAYINGS - numUnlocked); + for (i = 0; i < NUM_TRENDY_SAYINGS; i++) { - if (!IsAdditionalPhraseUnlocked(i)) + if (!IsTrendySayingUnlocked(i)) { - if (additionalPhraseId) + if (numToSkip) { - additionalPhraseId--; + // Skip the first n locked words, as determined by the Random call above. + numToSkip--; } else { - UnlockAdditionalPhrase(i); + UnlockTrendySaying(i); return EC_WORD(EC_GROUP_TRENDY_SAYING, i); } } } + // Would only be reached if there are no new words to teach, which is handled at the start. return EC_EMPTY_WORD; } // Unused -u16 GetRandomTaughtHipsterPhrase(void) +static u16 GetRandomUnlockedTrendySaying(void) { u16 i; - u16 additionalPhraseId = GetNumAdditionalPhrasesUnlocked(); - if (additionalPhraseId == 0) + u16 n = GetNumTrendySayingsUnlocked(); + if (n == 0) return EC_EMPTY_WORD; - additionalPhraseId = Random() % additionalPhraseId; - for (i = 0; i < NUM_ADDITIONAL_PHRASES; i++) + n = Random() % n; + for (i = 0; i < NUM_TRENDY_SAYINGS; i++) { - if (IsAdditionalPhraseUnlocked(i)) + if (IsTrendySayingUnlocked(i)) { - if (additionalPhraseId) - additionalPhraseId--; + if (n) + n--; else return EC_WORD(EC_GROUP_TRENDY_SAYING, i); } @@ -5569,10 +5588,10 @@ void InitEasyChatPhrases(void) // Mauville old man data is corrupted, which is initialized directly after // this function is called when starting a new game. for (i = 0; i < 64; i++) - gSaveBlock1Ptr->additionalPhrases[i] = 0; + gSaveBlock1Ptr->unlockedTrendySayings[i] = 0; #else - for (i = 0; i < ARRAY_COUNT(gSaveBlock1Ptr->additionalPhrases); i++) - gSaveBlock1Ptr->additionalPhrases[i] = 0; + for (i = 0; i < ARRAY_COUNT(gSaveBlock1Ptr->unlockedTrendySayings); i++) + gSaveBlock1Ptr->unlockedTrendySayings[i] = 0; #endif } @@ -5611,7 +5630,7 @@ static void SetUnlockedEasyChatGroups(void) sWordData->unlockedGroupIds[sWordData->numUnlockedGroups++] = EC_GROUP_MOVE_2; } - if (FlagGet(FLAG_SYS_HIPSTER_MEET)) + if (FlagGet(FLAG_UNLOCKED_TRENDY_SAYINGS)) sWordData->unlockedGroupIds[sWordData->numUnlockedGroups++] = EC_GROUP_TRENDY_SAYING; if (IsNationalPokedexEnabled()) @@ -5800,7 +5819,7 @@ static bool8 IsEasyChatIndexAndGroupUnlocked(u16 wordIndex, u8 groupId) case EC_GROUP_MOVE_2: return TRUE; case EC_GROUP_TRENDY_SAYING: - return IsAdditionalPhraseUnlocked(wordIndex); + return IsTrendySayingUnlocked(wordIndex); default: return gEasyChatGroups[groupId].wordData.words[wordIndex].enabled; } diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index 689dcf6a16..6075bd5d95 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -88,7 +88,7 @@ static void SetupHipster(void) struct MauvilleManHipster *hipster = &gSaveBlock1Ptr->oldMan.hipster; hipster->id = MAUVILLE_MAN_HIPSTER; - hipster->alreadySpoken = FALSE; + hipster->taughtWord = FALSE; hipster->language = gGameLanguage; } @@ -225,27 +225,28 @@ void PlayBardSong(void) ScriptContext_Stop(); } -void GetHipsterSpokenFlag(void) +void HasHipsterTaughtWord(void) { - gSpecialVar_Result = (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken; + gSpecialVar_Result = (&gSaveBlock1Ptr->oldMan.hipster)->taughtWord; } -void SetHipsterSpokenFlag(void) +void SetHipsterTaughtWord(void) { - (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken = TRUE; + (&gSaveBlock1Ptr->oldMan.hipster)->taughtWord = TRUE; } void HipsterTryTeachWord(void) { - u16 phrase = GetNewHipsterPhraseToTeach(); + u16 word = UnlockRandomTrendySaying(); - if (phrase == EC_EMPTY_WORD) + if (word == EC_EMPTY_WORD) { + // All words already unlocked gSpecialVar_Result = FALSE; } else { - CopyEasyChatWord(gStringVar1, phrase); + CopyEasyChatWord(gStringVar1, word); gSpecialVar_Result = TRUE; } } @@ -369,7 +370,7 @@ static void ResetBardFlag(void) static void ResetHipsterFlag(void) { - (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken = FALSE; + (&gSaveBlock1Ptr->oldMan.hipster)->taughtWord = FALSE; } static void ResetTraderFlag(void) diff --git a/src/mystery_event_script.c b/src/mystery_event_script.c index 124ababa45..b146bbab39 100644 --- a/src/mystery_event_script.c +++ b/src/mystery_event_script.c @@ -293,7 +293,7 @@ bool8 MEScrCmd_givenationaldex(struct ScriptContext *ctx) bool8 MEScrCmd_addrareword(struct ScriptContext *ctx) { - UnlockAdditionalPhrase(ScriptReadByte(ctx)); + UnlockTrendySaying(ScriptReadByte(ctx)); StringExpandPlaceholders(gStringVar4, gText_MysteryEventRareWord); ctx->mStatus = MEVENT_STATUS_SUCCESS; return FALSE;