Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add merged placeholder text for trainer name with class #5622

Open
wants to merge 2 commits into
base: upcoming
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions charmap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ B_ATK_NAME_WITH_PREFIX2 = FD 3E
B_DEF_NAME_WITH_PREFIX2 = FD 3F
B_EFF_NAME_WITH_PREFIX2 = FD 40
B_SCR_ACTIVE_NAME_WITH_PREFIX2 = FD 41
B_TRAINER1_NAME_WITH_CLASS = FD 42
B_TRAINER2_NAME_WITH_CLASS = FD 43
B_PARTNER_NAME_WITH_CLASS = FD 44
B_ATK_TRAINER_NAME_WITH_CLASS = FD 45

@ indicates the end of a town/city name (before " TOWN" or " CITY")
NAME_END = FC 00
Expand Down
4 changes: 4 additions & 0 deletions include/battle_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
#define B_TXT_DEF_NAME_WITH_PREFIX2 0x3F //lowercase
#define B_TXT_EFF_NAME_WITH_PREFIX2 0x40 //lowercase
#define B_TXT_SCR_ACTIVE_NAME_WITH_PREFIX2 0x41 //lowercase
#define B_TXT_TRAINER1_NAME_WITH_CLASS 0x42
#define B_TXT_TRAINER2_NAME_WITH_CLASS 0x43
#define B_TXT_PARTNER_NAME_WITH_CLASS 0x44
#define B_TXT_ATK_TRAINER_NAME_WITH_CLASS 0x45

#define B_BUFF_STRING 0
#define B_BUFF_NUMBER 1
Expand Down
80 changes: 63 additions & 17 deletions src/battle_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static const u8 sText_ItDoesntAffect[] = _("It doesn't affect {B_DEF_NAME_WITH_P
static const u8 sText_AttackerFainted[] = _("{B_ATK_NAME_WITH_PREFIX} fainted!\p");
static const u8 sText_TargetFainted[] = _("{B_DEF_NAME_WITH_PREFIX} fainted!\p");
static const u8 sText_PlayerGotMoney[] = _("You got ¥{B_BUFF1} for winning!\p");
static const u8 sText_PlayerLostToEnemyTrainer[] = _("You have no more Pokémon that can fight!\pYou lost to {B_TRAINER1_CLASS} {B_TRAINER1_NAME}!{PAUSE_UNTIL_PRESS}");
static const u8 sText_PlayerLostToEnemyTrainer[] = _("You have no more Pokémon that can fight!\pYou lost to {B_TRAINER1_NAME_WITH_CLASS}!{PAUSE_UNTIL_PRESS}");
static const u8 sText_PlayerPaidPrizeMoney[] = _("You gave ¥{B_BUFF1} to the winner…\pYou were overwhelmed by your defeat!{PAUSE_UNTIL_PRESS}");
static const u8 sText_PlayerWhiteout[] = _("You have no more Pokémon that can fight!\p");
#if B_WHITEOUT_MONEY >= GEN_4
Expand Down Expand Up @@ -395,9 +395,9 @@ static const u8 sText_PkmnLoafing[] = _("{B_ATK_NAME_WITH_PREFIX} is loafing aro
static const u8 sText_PkmnWontObey[] = _("{B_ATK_NAME_WITH_PREFIX} won't obey!");
static const u8 sText_PkmnTurnedAway[] = _("{B_ATK_NAME_WITH_PREFIX} turned away!");
static const u8 sText_PkmnPretendNotNotice[] = _("{B_ATK_NAME_WITH_PREFIX} pretended not to notice!");
static const u8 sText_EnemyAboutToSwitchPkmn[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME} is about to send out {B_BUFF2}.\pWill you switch your Pokémon?");
static const u8 sText_EnemyAboutToSwitchPkmn[] = _("{B_TRAINER1_NAME_WITH_CLASS} is about to send out {B_BUFF2}.\pWill you switch your Pokémon?");
static const u8 sText_PkmnLearnedMove2[] = _("{B_ATK_NAME_WITH_PREFIX} learned {B_BUFF1}!");
static const u8 sText_PlayerDefeatedLinkTrainerTrainer1[] = _("You defeated {B_TRAINER1_CLASS} {B_TRAINER1_NAME}!\p");
static const u8 sText_PlayerDefeatedLinkTrainerTrainer1[] = _("You defeated {B_TRAINER1_NAME_WITH_CLASS}!\p");
static const u8 sText_CreptCloser[] = _("{B_PLAYER_NAME} crept closer to {B_OPPONENT_MON1_NAME}!"); //safari
static const u8 sText_CantGetCloser[] = _("{B_PLAYER_NAME} can't get any closer!"); //safari
static const u8 sText_PkmnWatchingCarefully[] = _("{B_OPPONENT_MON1_NAME} is watching carefully!"); //safari
Expand All @@ -411,12 +411,12 @@ static const u8 sText_WildPkmnAppeared[] = _("You encountered a wild {B_OPPONENT
static const u8 sText_LegendaryPkmnAppeared[] = _("You encountered a wild {B_OPPONENT_MON1_NAME}!\p");
static const u8 sText_WildPkmnAppearedPause[] = _("You encountered a wild {B_OPPONENT_MON1_NAME}!{PAUSE 127}");
static const u8 sText_TwoWildPkmnAppeared[] = _("Oh! A wild {B_OPPONENT_MON1_NAME} and {B_OPPONENT_MON2_NAME} appeared!\p");
static const u8 sText_Trainer1WantsToBattle[] = _("You are challenged by {B_TRAINER1_CLASS} {B_TRAINER1_NAME}!\p");
static const u8 sText_Trainer1WantsToBattle[] = _("You are challenged by {B_TRAINER1_NAME_WITH_CLASS}!\p");
static const u8 sText_LinkTrainerWantsToBattle[] = _("You are challenged by {B_LINK_OPPONENT1_NAME}!");
static const u8 sText_TwoLinkTrainersWantToBattle[] = _("You are challenged by {B_LINK_OPPONENT1_NAME} and {B_LINK_OPPONENT2_NAME}!");
static const u8 sText_Trainer1SentOutPkmn[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME} sent out {B_OPPONENT_MON1_NAME}!");
static const u8 sText_Trainer1SentOutTwoPkmn[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME} sent out {B_OPPONENT_MON1_NAME} and {B_OPPONENT_MON2_NAME}!");
static const u8 sText_Trainer1SentOutPkmn2[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME} sent out {B_BUFF1}!");
static const u8 sText_Trainer1SentOutPkmn[] = _("{B_TRAINER1_NAME_WITH_CLASS} sent out {B_OPPONENT_MON1_NAME}!");
static const u8 sText_Trainer1SentOutTwoPkmn[] = _("{B_TRAINER1_NAME_WITH_CLASS} sent out {B_OPPONENT_MON1_NAME} and {B_OPPONENT_MON2_NAME}!");
static const u8 sText_Trainer1SentOutPkmn2[] = _("{B_TRAINER1_NAME_WITH_CLASS} sent out {B_BUFF1}!");
static const u8 sText_LinkTrainerSentOutPkmn[] = _("{B_LINK_OPPONENT1_NAME} sent out {B_OPPONENT_MON1_NAME}!");
static const u8 sText_LinkTrainerSentOutTwoPkmn[] = _("{B_LINK_OPPONENT1_NAME} sent out {B_OPPONENT_MON1_NAME} and {B_OPPONENT_MON2_NAME}!");
static const u8 sText_TwoLinkTrainersSentOutPkmn[] = _("{B_LINK_OPPONENT1_NAME} sent out {B_LINK_OPPONENT_MON1_NAME}! {B_LINK_OPPONENT2_NAME} sent out {B_LINK_OPPONENT_MON2_NAME}!");
Expand All @@ -435,7 +435,7 @@ static const u8 sText_PkmnThatsEnough[] = _("{B_BUFF1}, that's enough! Come back
static const u8 sText_PkmnComeBack[] = _("{B_BUFF1}, come back!");
static const u8 sText_PkmnOkComeBack[] = _("OK, {B_BUFF1}! Come back!");
static const u8 sText_PkmnGoodComeBack[] = _("Good job, {B_BUFF1}! Come back!");
static const u8 sText_Trainer1WithdrewPkmn[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME} withdrew {B_BUFF1}!");
static const u8 sText_Trainer1WithdrewPkmn[] = _("{B_TRAINER1_NAME_WITH_CLASS} withdrew {B_BUFF1}!");
static const u8 sText_LinkTrainer1WithdrewPkmn[] = _("{B_LINK_OPPONENT1_NAME} withdrew {B_BUFF1}!");
static const u8 sText_LinkTrainer2WithdrewPkmn[] = _("{B_LINK_SCR_TRAINER_NAME} withdrew {B_BUFF1}!");
static const u8 sText_WildPkmnPrefix[] = _("The wild ");
Expand Down Expand Up @@ -488,7 +488,7 @@ const u8 *const gPokeblockWasTooXStringTable[FLAVOR_COUNT] =

static const u8 sText_PlayerUsedItem[] = _("You used {B_LAST_ITEM}!");
static const u8 sText_WallyUsedItem[] = _("WALLY used {B_LAST_ITEM}!"); //no decapitalize until it is everywhere
static const u8 sText_Trainer1UsedItem[] = _("{B_ATK_TRAINER_CLASS} {B_ATK_TRAINER_NAME} used {B_LAST_ITEM}!");
static const u8 sText_Trainer1UsedItem[] = _("{B_ATK_TRAINER_NAME_WITH_CLASS} used {B_LAST_ITEM}!");
static const u8 sText_TrainerBlockedBall[] = _("The Trainer blocked your Poké Ball!");
static const u8 sText_DontBeAThief[] = _("Don't be a thief!");
static const u8 sText_ItDodgedBall[] = _("It dodged your thrown Poké Ball! This Pokémon can't be caught!");
Expand Down Expand Up @@ -2182,11 +2182,11 @@ const u8 gText_Mind[] = _("Mind");
const u8 gText_Skill[] = _("Skill");
const u8 gText_Body[] = _("Body");
const u8 gText_Judgment[] = _("{B_BUFF1}{CLEAR 13}Judgment{CLEAR 13}{B_BUFF2}");
static const u8 sText_TwoTrainersSentPkmn[] = _("{B_TRAINER1_CLASS} {B_TRAINER1_NAME} sent out {B_OPPONENT_MON1_NAME}!\p{B_TRAINER2_CLASS} {B_TRAINER2_NAME} sent out {B_OPPONENT_MON2_NAME}!");
static const u8 sText_Trainer2SentOutPkmn[] = _("{B_TRAINER2_CLASS} {B_TRAINER2_NAME} sent out {B_BUFF1}!");
static const u8 sText_TwoTrainersWantToBattle[] = _("You are challenged by {B_TRAINER1_CLASS} {B_TRAINER1_NAME} and {B_TRAINER2_CLASS} {B_TRAINER2_NAME}!\p");
static const u8 sText_InGamePartnerSentOutZGoN[] = _("{B_PARTNER_CLASS} {B_PARTNER_NAME} sent out {B_PLAYER_MON2_NAME}! Go, {B_PLAYER_MON1_NAME}!");
static const u8 sText_TwoInGameTrainersDefeated[] = _("You defeated {B_TRAINER1_CLASS} {B_TRAINER1_NAME} and {B_TRAINER2_CLASS} {B_TRAINER2_NAME}!\p");
static const u8 sText_TwoTrainersSentPkmn[] = _("{B_TRAINER1_NAME_WITH_CLASS} sent out {B_OPPONENT_MON1_NAME}!\p{B_TRAINER2_NAME_WITH_CLASS} sent out {B_OPPONENT_MON2_NAME}!");
static const u8 sText_Trainer2SentOutPkmn[] = _("{B_TRAINER2_NAME_WITH_CLASS} sent out {B_BUFF1}!");
static const u8 sText_TwoTrainersWantToBattle[] = _("You are challenged by {B_TRAINER1_NAME_WITH_CLASS} and {B_TRAINER2_NAME_WITH_CLASS}!\p");
static const u8 sText_InGamePartnerSentOutZGoN[] = _("{B_PARTNER_NAME_WITH_CLASS} sent out {B_PLAYER_MON2_NAME}! Go, {B_PLAYER_MON1_NAME}!");
static const u8 sText_TwoInGameTrainersDefeated[] = _("You defeated {B_TRAINER1_NAME_WITH_CLASS} and {B_TRAINER2_NAME_WITH_CLASS}!\p");
static const u8 sText_Trainer2LoseText[] = _("{B_TRAINER2_LOSE_TEXT}");
static const u8 sText_PkmnIncapableOfPower[] = _("{B_ATK_NAME_WITH_PREFIX} appears incapable of using its power!");
static const u8 sText_GlintAppearsInEye[] = _("A glint appears in {B_SCR_ACTIVE_NAME_WITH_PREFIX2}'s eyes!");
Expand Down Expand Up @@ -2232,9 +2232,9 @@ static const u8 sText_QuestionForfeitMatch[] = _("Would you like to forfeit the
static const u8 sText_ForfeitedMatch[] = _("The match was forfeited.");
static const u8 sText_Trainer1WinText[] = _("{B_TRAINER1_WIN_TEXT}");
static const u8 sText_Trainer2WinText[] = _("{B_TRAINER2_WIN_TEXT}");
static const u8 sText_Trainer1Fled[] = _( "{PLAY_SE SE_FLEE}{B_TRAINER1_CLASS} {B_TRAINER1_NAME} fled!");
static const u8 sText_PlayerLostAgainstTrainer1[] = _("You lost to {B_TRAINER1_CLASS} {B_TRAINER1_NAME}!");
static const u8 sText_PlayerBattledToDrawTrainer1[] = _("You battled to a draw against {B_TRAINER1_CLASS} {B_TRAINER1_NAME}!");
static const u8 sText_Trainer1Fled[] = _( "{PLAY_SE SE_FLEE}{B_TRAINER1_NAME_WITH_CLASS} fled!");
static const u8 sText_PlayerLostAgainstTrainer1[] = _("You lost to {B_TRAINER1_NAME_WITH_CLASS}!");
static const u8 sText_PlayerBattledToDrawTrainer1[] = _("You battled to a draw against {B_TRAINER1_NAME_WITH_CLASS}!");
const u8 gText_RecordBattleToPass[] = _("Would you like to record your battle\non your Frontier Pass?");
const u8 gText_BattleRecordedOnPass[] = _("{B_PLAYER_NAME}'s battle result was recorded\non the Frontier Pass.");
static const u8 sText_LinkTrainerWantsToBattlePause[] = _("You are challenged by {B_LINK_OPPONENT1_NAME}!\p");
Expand Down Expand Up @@ -3538,6 +3538,12 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize)
case B_TXT_TRAINER1_NAME: // trainer1 name
toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT));
break;
case B_TXT_TRAINER1_NAME_WITH_CLASS: // trainer1 name with trainer class
StringCopy(text, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A));
StringAppend(text, gText_Space2);
StringAppend(text, BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)));
toCpy = text;
Comment on lines +3542 to +3545
Copy link
Collaborator

@mrgriffin mrgriffin Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter too much, but I think this would be more efficient if written like:

Suggested change
StringCopy(text, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A));
StringAppend(text, gText_Space2);
StringAppend(text, BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)));
toCpy = text;
toCpy = text;
text = StringCopy(text, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A));
text = StringAppend(text, gText_Space2);
text = StringAppend(text, BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)));

As-is, StringAppend has to scan all of text until it finds the EOS character. The change here is that StringCopy and StringAppend return a pointer to the EOS, so no scanning is necessary.

(toCpy = text; then gets moved to the first thing we do because we're overwriting text)

EDIT: Technically StringCopy and StringAppend are the same thing when *text points at an EOS, but I don't know I'd go so far as to just use StringCopy. (It would be ever so slightly faster)

break;
case B_TXT_LINK_PLAYER_NAME: // link player name
toCpy = gLinkPlayers[multiplayerId].name;
break;
Expand Down Expand Up @@ -3654,6 +3660,12 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize)
case B_TXT_TRAINER2_NAME:
toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT));
break;
case B_TXT_TRAINER2_NAME_WITH_CLASS:
StringCopy(text, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B));
StringAppend(text, gText_Space2);
StringAppend(text, BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)));
toCpy = text;
break;
case B_TXT_TRAINER2_LOSE_TEXT:
if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER)
{
Expand Down Expand Up @@ -3688,6 +3700,12 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize)
case B_TXT_PARTNER_NAME:
toCpy = BattleStringGetPlayerName(text, GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT));
break;
case B_TXT_PARTNER_NAME_WITH_CLASS:
StringCopy(text, gTrainerClasses[GetFrontierOpponentClass(gPartnerTrainerId)].name);
StringAppend(text, gText_Space2);
StringAppend(text, BattleStringGetPlayerName(text, GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT)));
toCpy = text;
break;
case B_TXT_ATK_TRAINER_NAME:
toCpy = BattleStringGetTrainerName(text, multiplayerId, gBattlerAttacker);
break;
Expand All @@ -3709,6 +3727,34 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize)
break;
}
break;
case B_TXT_ATK_TRAINER_NAME_WITH_CLASS:
if (GetBattlerPosition(gBattlerAttacker) == B_POSITION_PLAYER_LEFT)
{
StringCopy(text, BattleStringGetTrainerName(text, multiplayerId, gBattlerAttacker));
}
else
{
switch (GetBattlerPosition(gBattlerAttacker))
{
case B_POSITION_PLAYER_RIGHT:
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
StringCopy(text, gTrainerClasses[GetFrontierOpponentClass(gPartnerTrainerId)].name);
break;
case B_POSITION_OPPONENT_LEFT:
StringCopy(text, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A));
break;
case B_POSITION_OPPONENT_RIGHT:
if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && !BATTLE_TWO_VS_ONE_OPPONENT)
StringCopy(text, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B));
else
StringCopy(text, BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A));
break;
}
StringAppend(text, gText_Space2);
StringAppend(text, BattleStringGetTrainerName(text, multiplayerId, gBattlerAttacker));
}
toCpy = text;
break;
case B_TXT_ATK_TEAM1:
if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER)
toCpy = sText_Your1;
Expand Down
Loading