diff --git a/src/core/game3/pokemon.lua b/src/core/game3/pokemon.lua index 555cdd34..9dd36b35 100644 --- a/src/core/game3/pokemon.lua +++ b/src/core/game3/pokemon.lua @@ -1160,8 +1160,18 @@ function Pokemon.replaceMove(mon, slot, newMoveId) return old end +-- An egg reads as the language's own EGG whatever its nickname holds: pret's +-- GetMonData(MON_DATA_NICKNAME) returns gText_EggNickname for any egg +-- (pokefirered/src/pokemon.c:3020). The stored nickname is only a placeholder +-- -- the cart's daycare writes タマゴ (daycare.c:1100), this engine "EGG". +local function eggName(mon) + if Pokemon.isEgg(mon) then return Strings("EGG") end +end + function Pokemon.displayMonName(mon) if not mon then return "POKéMON" end + local egg = eggName(mon) + if egg then return egg end local nick = mon.nickname if type(nick) == "string" and nick ~= "" then return nick end if mon.name and mon.name ~= "" then return mon.name end @@ -1572,6 +1582,8 @@ end function Pokemon.displayName(mon) if not mon then return "?????" end + local egg = eggName(mon) + if egg then return egg end if mon.nickname and mon.nickname ~= "" then return tostring(mon.nickname) end -- Prefer pack name over host species string when we can resolve. local sp = Pokemon.speciesOf(mon) diff --git a/tests/engine/game3_egg_display_name_test.lua b/tests/engine/game3_egg_display_name_test.lua new file mode 100644 index 00000000..994d3e77 --- /dev/null +++ b/tests/engine/game3_egg_display_name_test.lua @@ -0,0 +1,44 @@ +#!/usr/bin/env luajit +-- An egg is named by the language's own EGG, as pret's GetMonData(MON_DATA_NICKNAME) +-- does for any egg (pokefirered/src/pokemon.c:3020): the party and every screen +-- that names a mon through Pokemon.displayName / displayMonName show it, whatever +-- placeholder the egg's nickname stores. + +package.path = "./?.lua;./?/init.lua;" .. package.path +love = require("tests.love_stub") + +local T = require("tests.harness") +local check = T.check + +local Strings = require("src.core.Strings") +local Pokemon = require("src.core.game3.pokemon") + +-- A minimal pack, so no ROM is needed. +Pokemon._names = { [25] = "PIKACHU", [172] = "PICHU" } + +local egg = { species = 172, isEgg = true, nickname = "EGG", name = "EGG" } +local hatched = { species = 172, isEgg = false, nickname = "", name = "PICHU" } +local named = { species = 25, nickname = "SPARKY" } + +Strings.load({}) +check(Pokemon.displayName(egg) == "EGG", "an egg reads EGG with no catalog") +check(Pokemon.displayMonName(egg) == "EGG", "in both name helpers") + +Strings.load({ strings = { EGG = "OEUF" } }) +check(Pokemon.displayName(egg) == "OEUF", "an egg follows the catalog's EGG") +check(Pokemon.displayMonName(egg) == "OEUF", "in both name helpers") +check(egg.nickname == "EGG", "without its stored nickname being rewritten") + +local bare = { species = 172, isEgg = true, nickname = "" } +check(Pokemon.displayName(bare) == "OEUF", "an egg with no nickname at all is still named EGG") +local species_only = { species = 412, nickname = "" } +check(Pokemon.displayName(species_only) == "OEUF", "and so is one known only by the egg species") + +-- (looking up a species the pack lacks reloads it; put the minimal one back) +Pokemon._names = { [25] = "PIKACHU", [172] = "PICHU" } +check(Pokemon.displayName(hatched) == "PICHU", "a hatched egg goes back to its species name") +check(Pokemon.displayName(named) == "SPARKY", "and a nicknamed mon keeps its nickname") +check(Pokemon.displayMonName(named) == "SPARKY", "in both name helpers") + +Strings.load({}) +T.finish("game3_egg_display_name_test")