diff --git a/asm/mauville_old_man.s b/asm/mauville_old_man.s index b4302e5b1..b8d7f5c72 100644 --- a/asm/mauville_old_man.s +++ b/asm/mauville_old_man.s @@ -5,375 +5,6 @@ .text - thumb_func_start sub_81201C8 -sub_81201C8: @ 81201C8 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00002e28 - adds r0, r1 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_81201C8 - - thumb_func_start sub_81201DC -sub_81201DC: @ 81201DC - push {r4,lr} - ldr r4, =gSpecialVar_Result - bl sub_81201C8 - lsls r0, 24 - lsrs r0, 24 - strh r0, [r4] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81201DC - - thumb_func_start sub_81201F4 -sub_81201F4: @ 81201F4 - ldr r1, =gSpecialVar_Result - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r2, =0x00002e51 - adds r0, r2 - ldrb r0, [r0] - strh r0, [r1] - bx lr - .pool - thumb_func_end sub_81201F4 - - thumb_func_start sub_8120210 -sub_8120210: @ 8120210 - push {r4-r6,lr} - ldr r0, =gSaveBlock1Ptr - ldr r4, [r0] - ldr r0, =0x00002e28 - adds r6, r4, r0 - ldr r1, =0x00002e42 - adds r0, r4, r1 - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - bl StringCopy - movs r2, 0 - ldr r0, =0x00002e4d - adds r4, r0 -_0812022C: - adds r1, r4, r2 - ldr r0, [r5] - adds r0, 0xA - adds r0, r2 - ldrb r0, [r0] - strb r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x3 - bls _0812022C - movs r2, 0 - adds r5, r6, 0 - adds r5, 0x29 - adds r3, r6, 0x2 - adds r4, r6, 0 - adds r4, 0xE -_0812024E: - lsls r0, r2, 1 - adds r1, r3, r0 - adds r0, r4, r0 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0x5 - bls _0812024E - movs r0, 0x1 - strb r0, [r5] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8120210 - - thumb_func_start sub_8120280 -sub_8120280: @ 8120280 - push {r4-r7,lr} - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r0, =gSpecialVar_0x8004 - ldrh r0, [r0] - ldr r2, =0x00002e36 - adds r5, r1, r2 - cmp r0, 0 - bne _08120296 - ldr r0, =0x00002e2a - adds r5, r1, r0 -_08120296: - ldr r2, =gStringVar4 - adds r4, r2, 0 - movs r6, 0 -_0812029C: - ldrh r1, [r5] - adds r5, 0x2 - adds r0, r2, 0 - bl CopyEasyChatWord - adds r2, r0, 0 - adds r7, r6, 0x1 - cmp r2, r4 - beq _081202BE - movs r1, 0x37 -_081202B0: - ldrb r0, [r4] - cmp r0, 0 - bne _081202B8 - strb r1, [r4] -_081202B8: - adds r4, 0x1 - cmp r2, r4 - bne _081202B0 -_081202BE: - adds r4, 0x1 - movs r0, 0 - strb r0, [r2] - adds r2, 0x1 - ldrh r1, [r5] - adds r5, 0x2 - adds r0, r2, 0 - bl CopyEasyChatWord - adds r2, r0, 0 - cmp r2, r4 - beq _081202E6 - movs r1, 0x37 -_081202D8: - ldrb r0, [r4] - cmp r0, 0 - bne _081202E0 - strb r1, [r4] -_081202E0: - adds r4, 0x1 - cmp r2, r4 - bne _081202D8 -_081202E6: - adds r4, 0x1 - movs r0, 0xFE - strb r0, [r2] - adds r2, 0x1 - ldrh r1, [r5] - adds r5, 0x2 - adds r0, r2, 0 - bl CopyEasyChatWord - adds r2, r0, 0 - cmp r2, r4 - beq _0812030E - movs r1, 0x37 -_08120300: - ldrb r0, [r4] - cmp r0, 0 - bne _08120308 - strb r1, [r4] -_08120308: - adds r4, 0x1 - cmp r2, r4 - bne _08120300 -_0812030E: - cmp r6, 0 - bne _0812031E - movs r0, 0xFC - strb r0, [r2] - adds r2, 0x1 - movs r0, 0xF - strb r0, [r2] - adds r2, 0x1 -_0812031E: - lsls r0, r7, 16 - lsrs r6, r0, 16 - cmp r6, 0x1 - bls _0812029C - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8120280 - - thumb_func_start sub_8120340 -sub_8120340: @ 8120340 - push {lr} - ldr r0, =gSpecialVar_0x8004 - ldrb r0, [r0] - bl sub_81206C0 - bl ScriptContext1_Stop - pop {r0} - bx r0 - .pool - thumb_func_end sub_8120340 - - thumb_func_start sub_8120358 -sub_8120358: @ 8120358 - ldr r1, =gSpecialVar_Result - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r2, =0x00002e28 - adds r0, r2 - ldrb r0, [r0, 0x1] - strh r0, [r1] - bx lr - .pool - thumb_func_end sub_8120358 - - thumb_func_start sub_8120374 -sub_8120374: @ 8120374 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00002e28 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0, 0x1] - bx lr - .pool - thumb_func_end sub_8120374 - - thumb_func_start sub_812038C -sub_812038C: @ 812038C - push {lr} - bl sub_811F01C - lsls r0, 16 - lsrs r1, r0, 16 - ldr r0, =0x0000ffff - cmp r1, r0 - bne _081203AC - ldr r1, =gSpecialVar_Result - movs r0, 0 - b _081203B6 - .pool -_081203AC: - ldr r0, =gStringVar1 - bl CopyEasyChatWord - ldr r1, =gSpecialVar_Result - movs r0, 0x1 -_081203B6: - strh r0, [r1] - pop {r0} - bx r0 - .pool - thumb_func_end sub_812038C - - thumb_func_start sub_81203C4 -sub_81203C4: @ 81203C4 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00002e28 - adds r2, r0, r1 - ldrb r0, [r2, 0x1] - cmp r0, 0xA - bne _081203EC - ldr r1, =gSpecialVar_Result - movs r0, 0 - strh r0, [r1] - strb r0, [r2, 0x1] - b _081203F2 - .pool -_081203EC: - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - strh r0, [r1] -_081203F2: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81203C4 - - thumb_func_start sub_81203FC -sub_81203FC: @ 81203FC - push {r4-r6,lr} - ldr r0, =gSaveBlock1Ptr - ldr r4, [r0] - ldr r0, =0x00002e28 - adds r5, r4, r0 - ldrb r0, [r5, 0x1] - cmp r0, 0 - bne _08120410 - bl sub_81204DC -_08120410: - ldrb r0, [r5, 0x1] - lsls r0, 1 - ldr r1, =0x00002e2c - adds r6, r4, r1 - adds r0, r6, r0 - ldrh r1, [r0] - ldr r0, =0x0000ffff - cmp r1, r0 - beq _08120480 - bl Random - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - movs r0, 0x7 - ands r4, r0 - ldr r0, =gStringVar4 - ldrb r1, [r5, 0x1] - lsls r1, 1 - adds r1, r6, r1 - ldrh r1, [r1] - bl CopyEasyChatWord - adds r2, r0, 0 - ldr r1, =gUnknown_082942FD - bl StringCopy - adds r2, r0, 0 - ldr r0, =gUnknown_0859EFF0 - lsls r4, 2 - adds r4, r0 - ldr r1, [r4] - adds r0, r2, 0 - bl StringCopy - adds r2, r0, 0 - ldr r1, =gUnknown_08294301 - bl StringCopy - b _081204A2 - .pool -_08120480: - ldr r0, =gStringVar4 - ldr r3, =gUnknown_0859F010 - ldrb r2, [r5, 0x2] - adds r1, r2, 0x1 - strb r1, [r5, 0x2] - lsls r2, 24 - lsrs r2, 24 - movs r6, 0xB9 - lsls r6, 6 - adds r1, r4, r6 - adds r1, r2 - ldrb r1, [r1] - lsls r1, 2 - adds r1, r3 - ldr r1, [r1] - bl StringCopy -_081204A2: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xA - bl __umodsi3 - lsls r0, 16 - cmp r0, 0 - bne _081204C4 - movs r0, 0xA - b _081204C8 - .pool -_081204C4: - ldrb r0, [r5, 0x1] - adds r0, 0x1 -_081204C8: - strb r0, [r5, 0x1] - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - strh r0, [r1] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81203FC - thumb_func_start sub_81204DC sub_81204DC: @ 81204DC push {r4-r7,lr} diff --git a/data/event_scripts.s b/data/event_scripts.s index 25b0c7b52..c2906e649 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -5887,10 +5887,10 @@ gText_SoAmusing:: @ 82942E3 gText_SoMagical:: @ 82942F0 .string " so magical!$" -gUnknown_082942FD:: @ 82942FD +gOtherText_Is:: @ 82942FD .string " is$" -gUnknown_08294301:: @ 8294301 +gOtherText_DontYouAgree:: @ 8294301 .string "\n" .string "Don’t you agree?$" diff --git a/data/mauville_old_man.s b/data/mauville_old_man.s index 0eee9698a..ae39505ef 100644 --- a/data/mauville_old_man.s +++ b/data/mauville_old_man.s @@ -4,26 +4,6 @@ .section .rodata .align 2, 0 -gUnknown_0859EFF0:: @ 859EFF0 - .4byte gText_SoPretty - .4byte gText_SoDarling - .4byte gText_SoRelaxed - .4byte gText_SoSunny - .4byte gText_SoDesirable - .4byte gText_SoExciting - .4byte gText_SoAmusing - .4byte gText_SoMagical - -gUnknown_0859F010:: @ 859F010 - .4byte gUnknown_08294313 - .4byte gUnknown_08294359 - .4byte gUnknown_08294398 - .4byte gUnknown_082943DA - .4byte gUnknown_0829441C - .4byte gUnknown_08294460 - .4byte gUnknown_082944A0 - .4byte gUnknown_082944D5 - gUnknown_0859F030:: @ 859F030 .4byte 0, 12, 13, 18, 19, 21 diff --git a/include/easy_chat.h b/include/easy_chat.h index e5fdc8bea..ad586d697 100644 --- a/include/easy_chat.h +++ b/include/easy_chat.h @@ -1,40 +1,14 @@ #ifndef GUARD_EASYCHAT_H #define GUARD_EASYCHAT_H -// Taken from Pokeruby, check if it's correct -enum -{ - EC_GROUP_POKEMON, - EC_GROUP_TRAINER, - EC_GROUP_STATUS, - EC_GROUP_BATTLE, - EC_GROUP_GREETINGS, - EC_GROUP_PEOPLE, - EC_GROUP_VOICES, - EC_GROUP_SPEECH, - EC_GROUP_ENDINGS, - EC_GROUP_FEELINGS, - EC_GROUP_CONDITIONS, - EC_GROUP_ACTIONS, - EC_GROUP_LIFESTYLE, - EC_GROUP_HOBBIES, - EC_GROUP_TIME, - EC_GROUP_MISC, - EC_GROUP_ADJECTIVES, - EC_GROUP_EVENTS, - EC_GROUP_MOVE_1, - EC_GROUP_MOVE_2, - EC_GROUP_TRENDY_SAYING, - EC_GROUP_POKEMON_2, -}; - void InitEasyChatPhrases(void); void easy_chat_input_maybe(void); -void CopyEasyChatWord(u8 *dest, u16 word); +u8 * CopyEasyChatWord(u8 *dest, u16 word); bool32 sub_811F8D8(u16 word); void InitializeEasyChatWordArray(u16 *words, u16 length); void ConvertEasyChatWordsToString(u8 *dest, const u16 *src, u16 length1, u16 length2); bool8 ECWord_CheckIfOutsideOfValidRange(u16 word); u16 sub_811EE38(u16 group); +u16 sub_811F01C(void); #endif // GUARD_EASYCHAT_H diff --git a/include/event_scripts.h b/include/event_scripts.h index eb523a487..a964b1a67 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -394,4 +394,24 @@ extern const u8 Route111_EventScript_2907F0[]; extern const u8 LittlerootTown_BrendansHouse_2F_EventScript_1F863F[]; extern const u8 LittlerootTown_MaysHouse_2F_EventScript_1F958F[]; +//mauville_old_man +extern const u8 gOtherText_Is[]; +extern const u8 gOtherText_DontYouAgree[]; +extern const u8 gText_SoPretty[]; +extern const u8 gText_SoDarling[]; +extern const u8 gText_SoRelaxed[]; +extern const u8 gText_SoSunny[]; +extern const u8 gText_SoDesirable[]; +extern const u8 gText_SoExciting[]; +extern const u8 gText_SoAmusing[]; +extern const u8 gText_SoMagical[]; +extern const u8 gUnknown_08294313[]; +extern const u8 gUnknown_08294359[]; +extern const u8 gUnknown_08294398[]; +extern const u8 gUnknown_082943DA[]; +extern const u8 gUnknown_0829441C[]; +extern const u8 gUnknown_08294460[]; +extern const u8 gUnknown_082944A0[]; +extern const u8 gUnknown_082944D5[]; + #endif //GUARD_EVENT_SCRIPTS_H diff --git a/src/bard_music.c b/src/bard_music.c index 6fb1496e5..6c2578071 100644 --- a/src/bard_music.c +++ b/src/bard_music.c @@ -2,6 +2,7 @@ // Includes #include "global.h" #include "bard_music.h" +#include "constants/easy_chat.h" #include "easy_chat.h" #include "data/bard_music/bard_sounds.h" diff --git a/src/mail.c b/src/mail.c index 85ba86974..8fddc7045 100644 --- a/src/mail.c +++ b/src/mail.c @@ -101,7 +101,7 @@ struct MailRead /*0x021c*/ u8 monIconSprite; /*0x021d*/ u8 language; /*0x021e*/ bool8 playerIsSender; - /*0x0220*/ void (*parserSingle)(u8 *dest, u16 word); + /*0x0220*/ u8 * (*parserSingle)(u8 *dest, u16 word); /*0x0224*/ void (*parserMultiple)(u8 *dest, const u16 *src, u16 length1, u16 length2); /*0x0228*/ const struct MailLayout *layout; /*0x022c*/ u8 bg1TilemapBuffer[0x1000]; diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index 592b5c4ce..f39f80ab7 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -2,10 +2,21 @@ #include "main.h" #include "constants/easy_chat.h" #include "mauville_old_man.h" +#include "event_data.h" +#include "string_util.h" +#include "text.h" +#include "easy_chat.h" +#include "script.h" +#include "random.h" +#include "event_scripts.h" + +#define CHAR_SONG_WORD_SEPARATOR 0x37 void sub_8120E08(void); // StorytellerSetup void sub_81339F8(void); // TraderSetup void sub_8120B5C(void); +void sub_81206C0(u8 a0); // StartBardSong +void sub_81204DC(void); static const u16 sDefaultBardSongLyrics[6] = { EC_WORD_SHAKE, @@ -16,6 +27,28 @@ static const u16 sDefaultBardSongLyrics[6] = { EC_WORD_DANCE }; +static const u8 * const sGiddyAdjectives[] = { + gText_SoPretty, + gText_SoDarling, + gText_SoRelaxed, + gText_SoSunny, + gText_SoDesirable, + gText_SoExciting, + gText_SoAmusing, + gText_SoMagical +}; + +static const u8 * const sGiddyQuestions[] = { + gUnknown_08294313, + gUnknown_08294359, + gUnknown_08294398, + gUnknown_082943DA, + gUnknown_0829441C, + gUnknown_08294460, + gUnknown_082944A0, + gUnknown_082944D5 +}; + static void SetupBard(void) { u16 i; @@ -82,3 +115,177 @@ void SetMauvilleOldMan(void) } sub_8120B5C(); } + +u8 sub_81201C8(void) // GetCurrentMauvilleOldMan +{ + struct MauvilleManCommon *common = &gSaveBlock1Ptr->oldMan.common; + + return common->id; +} + +void sub_81201DC(void) // ScrSpecial_GetCurrentMauvilleMan +{ + gSpecialVar_Result = sub_81201C8(); +} + +void sub_81201F4(void) // ScrSpecial_HasBardSongBeenChanged +{ + u16 *scriptResult = &gSpecialVar_Result; // why?? + struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; + + *scriptResult = bard->hasChangedSong; +} + +void sub_8120210(void) // ScrSpecial_SaveBardSongLyrics +{ + u16 i; + struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; + + StringCopy(bard->playerName, gSaveBlock2Ptr->playerName); + + for (i = 0; i < 4; i++) + bard->playerTrainerId[i] = gSaveBlock2Ptr->playerTrainerId[i]; + + for (i = 0; i < 6; i++) + bard->songLyrics[i] = bard->temporaryLyrics[i]; + + bard->hasChangedSong = TRUE; +} + +// Copies lyrics into gStringVar4 +void sub_8120280(void) +{ + struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; + u16 specialVar = gSpecialVar_0x8004; // It's a bit odd to use this temp variable, but it seems needed to match. + u16 *lyrics; + u16 lineNum; + u8 *wordEnd; + u8 *str; + + lyrics = bard->temporaryLyrics; + if (specialVar == 0) + lyrics = bard->songLyrics; + wordEnd = gStringVar4; + str = wordEnd; + // Put three words on each line + for (lineNum = 0; lineNum < 2; lineNum++) + { + wordEnd = CopyEasyChatWord(wordEnd, *(lyrics++)); + while (wordEnd != str) + { + if (*str == CHAR_SPACE) + *str = CHAR_SONG_WORD_SEPARATOR; + str++; + } + + str++; + *(wordEnd++) = CHAR_SPACE; + + wordEnd = CopyEasyChatWord(wordEnd, *(lyrics++)); + while (wordEnd != str) + { + if (*str == CHAR_SPACE) + *str = CHAR_SONG_WORD_SEPARATOR; + str++; + } + + str++; + *(wordEnd++) = CHAR_NEWLINE; + + wordEnd = CopyEasyChatWord(wordEnd, *(lyrics++)); + while (wordEnd != str) + { + if (*str == CHAR_SPACE) + *str = CHAR_SONG_WORD_SEPARATOR; + str++; + } + + if (lineNum == 0) + { + *(wordEnd++) = EXT_CTRL_CODE_BEGIN; + *(wordEnd++) = 15; + } + } +} + +void sub_8120340(void) // ScrSpecial_PlayBardSong +{ + sub_81206C0(gSpecialVar_0x8004); + ScriptContext1_Stop(); +} + +void sub_8120358(void) // ScrSpecial_GetHipsterSpokenFlag +{ + u16 *scriptResult = &gSpecialVar_Result; // again?? + struct MauvilleManHipster *hipster = &gSaveBlock1Ptr->oldMan.hipster; + + *scriptResult = hipster->alreadySpoken; +} + +void sub_8120374(void) // ScrSpecial_SetHipsterSpokenFlag +{ + struct MauvilleManHipster *hipster = &gSaveBlock1Ptr->oldMan.hipster; + + hipster->alreadySpoken = TRUE; +} + +void sub_812038C(void) // ScrSpecial_HipsterTeachWord +{ + u16 var = sub_811F01C(); + + if (var == 0xFFFF) + { + gSpecialVar_Result = FALSE; + } + else + { + CopyEasyChatWord(gStringVar1, var); + gSpecialVar_Result = TRUE; + } +} + +void sub_81203C4(void) // ScrSpecial_GiddyShouldTellAnotherTale +{ + struct MauvilleManGiddy *giddy = &gSaveBlock1Ptr->oldMan.giddy; + + if (giddy->taleCounter == 10) + { + gSpecialVar_Result = FALSE; + giddy->taleCounter = 0; + } + else + { + gSpecialVar_Result = TRUE; + } +} + +void sub_81203FC(void) // ScrSpecial_GenerateGiddyLine +{ + struct MauvilleManGiddy *giddy = &gSaveBlock1Ptr->oldMan.giddy; + + if (giddy->taleCounter == 0) + sub_81204DC(); + + if (giddy->randomWords[giddy->taleCounter] != 0xFFFF) // is not the last element of the array? + { + u8 *stringPtr; + u32 adjective = Random(); + + adjective %= 8; + stringPtr = CopyEasyChatWord(gStringVar4, giddy->randomWords[giddy->taleCounter]); + stringPtr = StringCopy(stringPtr, gOtherText_Is); + stringPtr = StringCopy(stringPtr, sGiddyAdjectives[adjective]); + StringCopy(stringPtr, gOtherText_DontYouAgree); + } + else + { + StringCopy(gStringVar4, sGiddyQuestions[giddy->questionList[giddy->questionNum++]]); + } + + if (!(Random() % 10)) + giddy->taleCounter = 10; + else + giddy->taleCounter++; + + gSpecialVar_Result = TRUE; +}