Fix transition state pop, Gen 2 Bide/Sleep Talk/exp bugs, pp repair, TM pocket capacity and Bill's PC arrows

CLOSES #1663, CLOSES #1664, CLOSES #1665, CLOSES #1666, CLOSES #1667, CLOSES #1668, CLOSES #1670, CLOSES #1672
This commit is contained in:
bryanthaboi
2026-08-21 21:21:59 -04:00
parent 15fc04e067
commit c23f82efdd
20 changed files with 1164 additions and 48 deletions
@@ -0,0 +1,171 @@
-- BIDE on the real Gold battle screen: the PP counter in the move list, and
-- the lock that keeps a storing mon on the move it started (#1664, #1665).
--
-- POKEPORT_GAME=gold POKEPORT_DRIVER=tests/drivers/gold_bide_lock_bug1664_1665.lua \
-- POKEPORT_SHOT_DIR=/tmp/gold-bide love .
--
-- data/moves/effects.asm:795-800 puts `storeenergy` ahead of `doturn`, and
-- BattleCommand_DoTurn masks SUBSTATUS_BIDE out of the PP spend
-- (engine/battle/effect_commands.asm:977-979), so the whole three-turn Bide
-- costs the one PP the opening turn paid. The shots are the point: the
-- number beside BIDE in the move list must read the same on 01, 02 and 03.
--
-- The lock is ParsePlayerAction's own arm (engine/battle/core.asm:569-576),
-- which sits INSIDE the FIGHT branch and skips MoveSelectionScreen only -- so
-- the 2x2 menu still opens, a switch is still legal, and using an item runs
-- .reset_bide (:627-629) and CANCELS the store. Block 2 submits TACKLE in
-- the middle of a Bide on purpose: the engine has to answer with the Bide.
--
-- NOT covered here, and deliberately: src/ui/gen2/BattleState.lua still draws
-- the move list on a storing turn. The cart jumps past it. That half is a
-- screen change and is called out in the fix report rather than faked.
local U = require("tests.drivers.util")
local Mon = require("src.battle.gen2.Mon")
local function battleScreen(game)
for _ = 1, 900 do
local top = game.stack:top()
if top and top.battle then return top end
U.wait(1)
end
error("battle screen never came up")
end
local function drain(game, screen, frames)
for _ = 1, (frames or 400) do
if screen.phase == "menu" and #screen.queue == 0 and not screen.anim then
return true
end
U.tap(game, "a")
U.wait(3)
end
return false
end
local function giveMoves(mon, game, moves)
mon.moves = {}
for i, id in ipairs(moves) do
local def = assert(game.data.moves[id], id .. " is not in moves.lua")
mon.moves[i] = { id = id, pp = def.pp, maxPp = def.pp }
end
return mon
end
local function newWild(game, species, level, moves)
local mon = Mon.new(game.data, species, level)
if moves then giveMoves(mon, game, moves) end
return mon
end
return function(game)
local out = os.getenv("POKEPORT_SHOT_DIR") or "/tmp/gold-bide"
U.wait(45)
local world = game.world
assert(world and world.map, "gold world did not boot")
local failures = {}
local function check(ok, what)
print((ok and "[ok] " or "[FAIL] ") .. what)
if not ok then failures[#failures + 1] = what end
end
local function pp(mon, slot) return mon.moves[slot].pp end
-- ------------------------------------------------------------------ 1
-- One Bide, start to finish, with the move list open between turns. The
-- foe is a SPLASH-only RATTATA so nothing interrupts the store.
local player = Mon.new(game.data, "SNORLAX", 40)
giveMoves(player, game, { "BIDE", "TACKLE" })
game.save.party = { player }
game.save.inventory = { POTION = 5 }
local foe = newWild(game, "RATTATA", 20, { "TACKLE" })
assert(world:startBattle({ wild = foe }), "startBattle failed")
local screen = battleScreen(game)
drain(game, screen, 200)
local opening = pp(player, 1)
print(("[driver] BIDE opens at %d PP"):format(opening))
screen:submit({ kind = "move", move = "BIDE" })
drain(game, screen, 400)
U.shot(game, out .. "/01-selected.png")
local afterSelect = pp(player, 1)
print(("[driver] after the SELECTION turn: %d PP"):format(afterSelect))
check(afterSelect == opening - 1,
"the opening turn pays its one PP through doturn")
check(screen.battle:forcedMove(player) == "BIDE",
"and ParsePlayerAction's bide arm holds the FIGHT choice")
-- The middle of the store, with TACKLE deliberately submitted: the cart
-- never re-reads the move list, so wCurPlayerMove is still the BIDE.
local tackleBefore = pp(player, 2)
screen:submit({ kind = "move", move = "TACKLE" })
drain(game, screen, 400)
U.shot(game, out .. "/02-storing.png")
print(("[driver] after a STORING turn: BIDE %d PP, TACKLE %d PP")
:format(pp(player, 1), pp(player, 2)))
check(pp(player, 1) == afterSelect, "a storing turn spends no PP at all")
check(pp(player, 2) == tackleBefore,
"and the move the menu offered was never run")
-- The release. Whatever the roll, the store is two or three turns
-- (UnleashEnergy's `BattleRandom / and 1 / inc a / inc a`,
-- move_effects/bide.asm:88-92), so keep pressing FIGHT until it lets go.
local foeBefore = foe.hp
for _ = 1, 3 do
if not screen.battle:forcedMove(player) then break end
screen:submit({ kind = "move", move = "BIDE" })
drain(game, screen, 400)
end
U.shot(game, out .. "/03-unleashed.png")
print(("[driver] after the RELEASE: %d PP, foe %d -> %d HP")
:format(pp(player, 1), foeBefore, foe.hp))
check(pp(player, 1) == afterSelect,
"the whole Bide cost exactly one PP, the way the cart charges it")
check(screen.battle:forcedMove(player) == nil, "and the lock is released")
for _ = 1, 400 do
if not game.stack:top() or not game.stack:top().battle then break end
U.tap(game, "a")
U.wait(3)
end
U.wait(60)
-- ------------------------------------------------------------------ 2
-- .reset_bide: a nonzero wBattlePlayerAction that is not
-- BATTLEPLAYERACTION_SWITCH clears SUBSTATUS_BIDE (core.asm:572-573,
-- :627-629), so opening the PACK mid-store throws the stored damage away.
local bider = Mon.new(game.data, "SNORLAX", 40)
giveMoves(bider, game, { "BIDE", "TACKLE" })
bider.hp = math.max(1, bider.hp - 30)
game.save.party = { bider }
game.save.inventory = { POTION = 5 }
local foe2 = newWild(game, "RATTATA", 20, { "TACKLE" })
assert(world:startBattle({ wild = foe2 }), "startBattle failed")
screen = battleScreen(game)
drain(game, screen, 200)
screen:submit({ kind = "move", move = "BIDE" })
drain(game, screen, 400)
check(screen.battle:forcedMove(bider) == "BIDE", "the second Bide is up")
screen:useItem("POTION")
drain(game, screen, 400)
U.shot(game, out .. "/04-item-cancelled.png")
print("[driver] after the PACK: forcedMove="
.. tostring(screen.battle:forcedMove(bider)))
check(screen.battle:forcedMove(bider) == nil,
"using an item cancels the Bide, as .reset_bide does")
check(screen.battle:volatile(bider).bideStored == nil,
"and the damage it had banked goes with it")
for _ = 1, 400 do
if not game.stack:top() or not game.stack:top().battle then break end
U.tap(game, "a")
U.wait(3)
end
print("[driver] NOTE: the move list is still drawn on a storing turn; the "
.. "cart's bide arm skips MoveSelectionScreen and that half lives in "
.. "src/ui/gen2/BattleState.lua")
if #failures > 0 then
for _, what in ipairs(failures) do print("[FAIL] " .. what) end
error(#failures .. " bide checks failed")
end
print("[driver] all bide checks passed")
print("[driver] shots in " .. out)
end
@@ -0,0 +1,113 @@
-- #1672: Bill's PC MOVE screen -- the box-name arrows.
--
-- POKEPORT_IDENTITY=gold-dev POKEPORT_GAME=gold POKEPORT_TOUCH=0 \
-- POKEPORT_DRIVER=tests/drivers/gold_billspc_arrows_bug1672.lua \
-- perl -e 'alarm 420; exec @ARGV' \
-- python3 -c "import pty; pty.spawn(['love','.'])"
-- POKEPORT_SHOT_DIR=/tmp/gold-bug1672-arrows (default)
--
-- BillsPC_MoveMonWOMail_BoxNameAndArrows writes $5f at hlcoord 8, 1 and $5e at
-- hlcoord 19, 1 (engine/pokemon/bills_pc.asm:957-963), replacing the box-name
-- Textbox's own side borders. Only _MovePKMNWithoutMail calls it: .Init (:545)
-- and .PrepInsertCursor (:698). The withdraw (:299) and deposit (:56) inits
-- call bare BillsPC_BoxName (:965) and are the negative controls here.
--
-- What to look for in each shot: a solid LEFT-pointing triangle in the left
-- border of the name box and a solid RIGHT-pointing one in the right border,
-- both level with the name, on every move-mode shot and on neither of the last
-- two. Getting them the wrong way round is the failure this exists to catch.
--
-- The run ends with the MOVE screen open so a human takes the controls there.
local U = require("tests.drivers.util")
local Boxes = require("src.core.gen2.Boxes")
local Mon = require("src.battle.gen2.Mon")
local Screens = require("src.ui.Screens")
return function(game)
local out = os.getenv("POKEPORT_SHOT_DIR") or "/tmp/gold-bug1672-arrows"
local function tap(button, frames)
game.input.pressQueue[#game.input.pressQueue + 1] = button
game.input.state[button] = true
U.wait(2)
game.input.state[button] = false
U.wait(frames or 6)
end
U.wait(45)
assert(game.world and game.world.map, "gold world did not boot")
local save, data = game.save, game.data
local function mon(species, level) return Mon.new(data, species, level) end
-- IsAnyMonHoldingMail refuses the whole screen (src/ui/gen2/PcMenu.lua:303),
-- so the seeded party carries no mail.
save.party = {}
for _, species in ipairs({ "CYNDAQUIL", "PIDGEY", "SENTRET" }) do
save.party[#save.party + 1] = mon(species, 12)
end
local stored = Boxes.box(save, 1)
for i = #stored, 1, -1 do stored[i] = nil end
for i, species in ipairs({ "GEODUDE", "ZUBAT", "RATTATA" }) do
stored[i] = mon(species, 10 + i)
end
Boxes.rename(save, 1, "GRASS")
save.currentBox = 1
local function openBox(mode)
Screens.push(game, "Gen2BoxMenu", {
save = save, mode = mode,
onClose = function() game.stack:pop() end,
})
U.wait(8)
return game.stack:top()
end
local function close()
while game.stack:top() and game.stack:top().submenuRows do
game.stack:pop()
end
U.wait(4)
end
-- ---- 1. the move list on a renamed box -----------------------------------
local menu = openBox("move")
U.log("01 move, box GRASS:", "want both arrows flanking GRASS on row 1")
U.shot(game, out .. "/01-move-box.png")
-- ---- 2. LEFT onto the PARTY ----------------------------------------------
-- BillsPC_BoxName's `.party` arm; only the move screen ever loads box 0.
tap("left")
U.log("02 move, PARTY:", "boxIndex " .. tostring(menu.boxIndex) ..
", want 0 and both arrows still up")
U.shot(game, out .. "/02-move-party.png")
tap("right")
-- ---- 3. the MOVE / STATS / CANCEL submenu --------------------------------
tap("a")
U.log("03 submenu:", "phase " .. tostring(menu.phase) ..
", want submenu and both arrows still up")
U.shot(game, out .. "/03-move-submenu.png")
-- ---- 4. the insert cursor (.PrepInsertCursor rewrites them) --------------
tap("a", 10)
U.log("04 insert:", "phase " .. tostring(menu.phase) ..
", want insert and both arrows still up")
U.shot(game, out .. "/04-move-insert.png")
close()
-- ---- 5/6. the negative controls ------------------------------------------
openBox("withdraw")
U.log("05 withdraw:", "want plain border tiles, NO arrows")
U.shot(game, out .. "/05-withdraw-none.png")
close()
openBox("deposit")
U.log("06 deposit:", "want plain border tiles, NO arrows")
U.shot(game, out .. "/06-deposit-none.png")
close()
openBox("move")
U.log("done -- the MOVE screen is open; the controls are yours")
end
+5
View File
@@ -252,6 +252,11 @@ return function(game)
dep.index = 2 -- the mon holding FLOWER MAIL
show("23b-pc-deposit-mail", dep)
-- Only the move list gets the box-name arrows, $5f left and $5e right
-- (engine/pokemon/bills_pc.asm:957-963); 22 and 23 above are the controls.
local mv = BoxMenu.new(game, { save = save, mode = "move" })
show("23c-pc-move-arrows", mv)
-- The two clock screens NEW GAME and Mom open (timeset.asm InitClock and
-- SetDayOfWeek), each at its picker rather than at its opening page.
local clock = InitClock.new(game, { save = save })
+1 -1
View File
@@ -2,7 +2,7 @@
--
-- Gen 1's party_struct carries one Special word (macros/ram.asm:28-37) and
-- PrintStatsBox reads four fixed cells, wLoadedMonAttack/Defense/Speed/Special
-- (engine/pokemon/status_screen.asm:255-296). Gen 2 splits that word into
-- (engine/pokemon/status_screen.asm:238-287). Gen 2 splits that word into
-- SpclAtk/SpclDef (pokegold macros/ram.asm:29-42), so a mod that wrote a Gen 2
-- block over a Yellow party leaves the port with no `special` to print.
--
@@ -0,0 +1,80 @@
-- data/maps/force_bike_surf.asm:5 / engine/overworld/player_state.asm:34-72,
-- home/overworld.asm:690-703 (the map-change fade has no fade back in).
-- POKEPORT_DRIVER=tests/drivers/warp_midpoint_box_bug1663_test.lua \
-- POKEPORT_IDENTITY=bug1663 POKEPORT_TOUCH=0 POKEPORT_VERSION=red love .
-- Ride into the Route 16 gate, drop the BICYCLE inside, then walk back out
-- the west door. The warp lands on a forced-bike tile, so the refusal box
-- opens from inside the fade's midpoint: it must be on screen when the fade
-- ends (#1663 ate it), and dismissing it must leave the player on Route 16's
-- (17,10), not shoved into the gate wall at (18,10) (#1548).
return function(game)
local U = dofile("tests/drivers/util.lua")
local Pokemon = require("src.pokemon.Pokemon")
local TextBox = require("src.render.TextBox")
local SHOT_DIR = os.getenv("SHOT_DIR") or "/tmp/shots"
local ok = true
local function check(label, pass)
U.log(pass and "PASS" or "FAIL", label)
if not pass then ok = false end
return pass
end
local function where()
local ow = game.overworld
return ow.map.id, ow.player.cellX, ow.player.cellY
end
local function bikeless()
game.save.inventory.BICYCLE = nil
game.save.onBike, game.save.forcedBike = false, nil
end
game.save.player.name = "PROBE"
game.save.party = { Pokemon.new(game.data, "CHARIZARD", 50) }
game.save.inventory.BICYCLE = 1
game.save.onBike, game.save.forcedBike = false, nil
-- (16,10) is the open cell west of the gate door; (17,10) is the forced
-- tile the door sits on, so the step onto it mounts and then warps
U.teleport(game, "ROUTE_16", 16, 10, "right")
U.wait(20)
U.hold(game, "right", 40)
U.wait(40)
local map, x, y = where()
U.log(("rode east into the gate -> %s (%d,%d)"):format(map, x, y))
check("the bike carried the player into the gate",
map == "ROUTE_16_GATE_1F")
bikeless()
U.hold(game, "left", 40)
-- the map-change fade is 32 frames and hands back with no fade in
U.wait(50)
map, x, y = where()
local top = game.stack:top()
U.log(("walked back out -> %s (%d,%d), top=%s"):format(map, x, y,
tostring(getmetatable(top) == TextBox and "TextBox" or top)))
check("the west door lands back on Route 16", map == "ROUTE_16")
check("on the forced tile the gate exit warps to", x == 17 and y == 10)
check("the refusal box the warp opened is on screen",
getmetatable(top) == TextBox)
U.shot(game, SHOT_DIR .. "/bug1663_refusal.png")
-- close it: the shove back east is refused by collision, (18,10) is wall
for _ = 1, 12 do
if game.stack:top() == game.overworld then break end
U.tap(game, "a")
U.wait(25)
end
U.wait(30)
map, x, y = where()
local walkable = game.overworld.map:isWalkableCell(x, y)
U.log(("after the refusal -> %s (%d,%d) walkable=%s")
:format(map, x, y, tostring(walkable)))
check("dismissing it leaves the player on a walkable cell", walkable)
check("and not inside the gate wall at (18,10)", not (x == 18 and y == 10))
U.shot(game, SHOT_DIR .. "/bug1663_after.png")
U.log(ok and "all clear" or "a check failed")
while true do coroutine.yield() end
end
@@ -0,0 +1,172 @@
-- A Gen 1 move slot stores current PP in six bits of one byte and the PP Up
-- count in the other two (constants/pokemon_data_constants.asm:101-102), and
-- the status screen reads it back with `and PP_MASK` before PrintNumber
-- (engine/pokemon/status_screen.asm:357-365), so "not a number" is not a state
-- the hardware record can hold and the load-time repair must normalize it.
-- Max PP follows GetMaxPP/AddBonusPP (engine/items/item_effects.asm:2467,
-- 2418). #1668
package.path = "./?.lua;./?/init.lua;" .. package.path
local T = require("tests.harness")
local check, eq = T.check, T.eq
love = love or require("tests.love_stub")
local SaveData = require("src.core.SaveData")
local data = {
pokemon = { FIXMON_A = { id = "FIXMON_A", name = "FIXMON A", types = { "GRASS" },
baseStats = { hp = 45, attack = 49, defense = 49, speed = 45, special = 65 } } },
moves = {
FIX_TACKLE = { id = "FIX_TACKLE", name = "TACKLE", pp = 35 },
FIX_GROWL = { id = "FIX_GROWL", name = "GROWL", pp = 40 },
},
items = {}, maps = { FIXMAP = { id = "FIXMAP" } },
constants = { fallbackMove = "FIX_TACKLE" },
}
local function saveWith(moves)
return {
party = { { species = "FIXMON_A", level = 21, hp = 62, exp = 9000,
dvs = { hp = 15, attack = 9, defense = 8, speed = 8, special = 8 },
statExp = {}, moves = moves } },
boxes = {}, inventory = {}, pcItems = {},
player = { map = "FIXMAP", x = 1, y = 1, name = "RED", id = 1 },
}
end
local function scrub(moves)
local save = saveWith(moves)
SaveData.validate(save, data)
return save.party[1].moves
end
-- SummaryMenu page 2 and every battle reader index the save's own slot table
local function readers(mv)
local mdef = data.moves[mv.id]
local maxPP = mdef.pp + (mv.ppUps or 0) * math.floor(mdef.pp / 5)
local okFmt = pcall(string.format, "%2d/%2d", mv.pp, maxPP)
local okCmp = pcall(function() return mv.pp > 0 end)
return okFmt, okCmp, maxPP
end
do -- every non-numeric pp shape the tree can be handed
local moves = scrub({
{ id = "FIX_TACKLE" },
{ id = "FIX_TACKLE", pp = {} },
{ id = "FIX_TACKLE", pp = "35" },
{ id = "FIX_TACKLE", pp = 0 / 0 },
})
eq(#moves, 4, "all four slots survive")
for i = 1, 4 do
local mv = moves[i]
check(type(mv.pp) == "number", "slot " .. i .. " carries a numeric pp")
local okFmt, okCmp, maxPP = readers(mv)
check(okFmt, "slot " .. i .. ": SummaryMenu's ('%2d/%2d'):format no longer raises")
check(okCmp, "slot " .. i .. ": playerHasPP's `mv.pp > 0` no longer raises")
check(type(mv.pp) == "number" and mv.pp >= 0 and mv.pp <= maxPP,
"slot " .. i .. " sits inside 0..maxPP")
end
eq(moves[1].pp, 35, "a missing pp heals to full, not to Struggle")
eq(moves[2].pp, 35, "a table pp heals to full")
eq(moves[3].pp, 35, "a numeric string becomes the number it spells")
eq(moves[4].pp, 35, "a nan pp heals to full")
end
do -- numeric, but not a value the unsigned byte field can express
local moves = scrub({
{ id = "FIX_TACKLE", pp = -4 },
{ id = "FIX_TACKLE", pp = 1.7 },
{ id = "FIX_TACKLE", pp = math.huge },
{ id = "FIX_TACKLE", pp = -math.huge },
})
eq(moves[1].pp, 0, "a negative pp clamps up to zero")
eq(moves[2].pp, 1, "a fractional pp floors to an integer")
eq(moves[3].pp, 35, "an infinite pp heals to full")
eq(moves[4].pp, 35, "so does a negative infinity")
end
-- MimicEffect writes the copied move id into the slot and never touches the
-- PP byte (engine/battle/effects.asm:1261-1266), and this port's battler reads
-- mon.moves by identity, so a mid-battle save legitimately carries a PP count
-- above the slot's current move's max. Clamping it down corrupts a battle
-- checkpoint, which is why the repair only replaces values that are not
-- numbers at all.
do
local moves = scrub({
{ id = "FIX_TACKLE", pp = 40, mimic = true },
{ id = "FIX_TACKLE", pp = 999 },
{ id = "FIX_GROWL", pp = 40, ppUps = 0 },
})
eq(moves[1].pp, 40, "a Mimic'd slot keeps the 40 PP the GROWL it replaced had")
check(moves[1].mimic == true, "and the battler's own restore marker survives")
eq(moves[2].pp, 999, "an over-max pp is left alone, not clamped")
eq(moves[3].pp, 40, "and a full slot is unchanged")
end
do -- the PP Up count is two bits, so 0..3
local moves = scrub({
{ id = "FIX_TACKLE", pp = 5, ppUps = "x" },
{ id = "FIX_TACKLE", pp = 5, ppUps = 9 },
{ id = "FIX_TACKLE", pp = 49, ppUps = 2 },
{ id = "FIX_TACKLE", pp = 5 },
})
eq(moves[1].ppUps, 0, "a non-numeric ppUps becomes zero")
eq(moves[2].ppUps, 3, "an over-max ppUps clamps to three")
eq(moves[3].ppUps, 2, "a legal ppUps is kept")
eq(moves[3].pp, 49, "and its PP-Upped count is untouched: 35 + 2 * 7")
eq(moves[4].ppUps, nil, "a slot without a ppUps does not grow one")
for i = 1, 4 do
local okFmt = pcall(string.format, "%2d/%2d", moves[i].pp, 35)
check(okFmt, "slot " .. i .. " formats after a ppUps repair")
local mdef = data.moves[moves[i].id]
local ok = pcall(function()
return mdef.pp + (moves[i].ppUps or 0) * math.floor(mdef.pp / 5)
end)
check(ok, "slot " .. i .. ": SummaryMenu's maxPP arithmetic no longer raises")
end
end
-- A scalar move slot is a shape the id filter has always tolerated, and
-- tests/modkit/cases/checkpoints.lua treats one as valid content that
-- SaveData.validate must not rewrite. It stays out of the repair; the
-- SummaryMenu.lua:206 crash it causes is a separate defect.
do
local moves = scrub({ "FIX_TACKLE", { id = "FIX_GROWL" } })
eq(#moves, 2, "the scalar slot survives the id filter, as before")
eq(moves[1], "FIX_TACKLE", "and is left exactly as the save stored it")
eq(moves[2].pp, 40, "while its table-shaped neighbour is still repaired")
end
do -- the moveless-mon fallback slot goes through the same normalization
local moves = scrub({ { id = "NOT_A_MOVE", pp = "junk" } })
eq(#moves, 1, "the unknown move is replaced by the fallback")
eq(moves[1].id, "FIX_TACKLE", "which is data.constants.fallbackMove")
check(type(moves[1].pp) == "number", "and carries a numeric pp")
eq(moves[1].pp, 35, "at full")
end
do -- a vanilla slot passes through byte-identical
local moves = scrub({
{ id = "FIX_TACKLE", pp = 20 },
{ id = "FIX_GROWL", pp = 0 },
{ id = "FIX_GROWL", pp = 64, ppUps = 3 },
})
eq(moves[1].pp, 20, "a mid-fight pp is left alone")
eq(moves[2].pp, 0, "an exhausted move is left on zero, not healed")
eq(moves[3].pp, 64, "and a PP-Upped slot agrees with SummaryMenu's own maxPP")
eq(moves[3].ppUps, 3, "with its PP Up count intact")
end
do -- box mons are reached by the same pass
local save = saveWith({ { id = "FIX_TACKLE", pp = 20 } })
save.boxes = { { { species = "FIXMON_A", level = 21, hp = 62,
dvs = {}, statExp = {},
moves = { { id = "FIX_TACKLE", pp = "nonsense" } } } } }
SaveData.validate(save, data)
local mv = save.boxes[1][1].moves[1]
check(type(mv.pp) == "number", "a box mon's move slot is repaired too")
eq(mv.pp, 35, "to full PP")
end
T.finish()
@@ -0,0 +1,133 @@
-- home/overworld.asm:690-703 (PlayMapChangeSound tail-calls GBFadeOutToBlack)
-- and home/fade.asm:43-46: the map-change fade has no matching fade in, so the
-- warp shape ends in the same frame its midpoint runs. The midpoint is where
-- setMap opens things (the Cycling Road refusal box, a map script's onEnter),
-- and a fade that popped the top of the stack after that ate them and then
-- finished a second time (#1663).
-- luajit tests/engine/transition_identity_pop_bug1663.lua
package.path = "./?.lua;./?/init.lua;" .. package.path
local T = require("tests.harness")
local check, eq = T.check, T.eq
love = love or require("tests.love_stub")
local StateStack = require("src.core.StateStack")
local Transition = require("src.render.Transition")
local Timing = require("src.core.Timing")
local function overworld() return { name = "overworld", isOpaque = true } end
-- ------------------------------------------------ the warp shape (#1663)
do
StateStack:init()
local ow = overworld()
StateStack:push(ow)
local box = { name = "refusal" }
local entered, depthAtMidpoint, topAtMidpoint = 0, nil, nil
function box:enter() entered = entered + 1 end
local dones = 0
local fade
fade = Transition.new({ stack = StateStack }, function()
depthAtMidpoint = #StateStack.states
topAtMidpoint = StateStack:top()
StateStack:push(box)
end, function() dones = dones + 1 end, true)
StateStack:push(fade)
local finishedOn
for frame = 1, 120 do
StateStack:update(1 / 60)
if dones > 0 and not finishedOn then finishedOn = frame end
end
eq(finishedOn, Timing.WARP_FADE_OUT, "the warp hands back at the end of the fade")
eq(dones, 1, "and hands back exactly once")
eq(depthAtMidpoint, 1, "the fade is off the stack before the midpoint runs")
check(topAtMidpoint == ow, "so the map switch sees the overworld on top")
eq(entered, 1, "the state the midpoint pushed entered once")
eq(#StateStack.states, 2, "the fade is gone and the pushed state is not")
check(StateStack.states[1] == ow, "the overworld is still the base")
check(StateStack:top() == box, "the box the midpoint opened owns the screen")
end
-- a midpoint that pushes nothing still leaves exactly the overworld behind
do
StateStack:init()
local ow = overworld()
StateStack:push(ow)
local mids, dones = 0, 0
local fade = Transition.new({ stack = StateStack },
function() mids = mids + 1 end,
function() dones = dones + 1 end, true)
StateStack:push(fade)
for _ = 1, 120 do StateStack:update(1 / 60) end
eq(mids, 1, "the map switched once")
eq(dones, 1, "the plain warp still hands back exactly once")
eq(#StateStack.states, 1, "and pops nothing but itself")
check(StateStack:top() == ow, "leaving the overworld on top")
end
-- ------------------------------------------ the script fade is unchanged
-- ViridianGym.asm .afterBeat / RocketHideoutB4F BeatGiovanniScript bracket
-- their HideObject with GBFadeOutToBlack -> GBFadeInFromBlack, so those keep
-- a real fade in and wait under whatever the midpoint opened.
do
StateStack:init()
local ow = overworld()
StateStack:push(ow)
local box = { name = "script box" }
local dones = 0
local fade = Transition.new({ stack = StateStack },
function() StateStack:push(box) end,
function() dones = dones + 1 end, false)
StateStack:push(fade)
for _ = 1, Timing.WARP_FADE_OUT + 8 do StateStack:update(1 / 60) end
eq(dones, 0, "a fade with a fade-in waits under what its midpoint opened")
check(StateStack:top() == box, "the pushed state is on top")
check(StateStack.states[2] == fade, "with the fade still underneath it")
StateStack:pop()
for _ = 1, Timing.FADE_IN_FROM_BLACK + 8 do StateStack:update(1 / 60) end
eq(dones, 1, "and finishes once the box is gone")
eq(#StateStack.states, 1, "leaving the overworld alone on the stack")
check(StateStack:top() == ow, "and nothing else came off with it")
end
-- ------------------------------------------------- finish is idempotent
do
StateStack:init()
local ow = overworld()
StateStack:push(ow)
local dones = 0
local fade = Transition.new({ stack = StateStack }, nil,
function() dones = dones + 1 end, true)
StateStack:push(fade)
fade:finish()
fade:finish()
eq(dones, 1, "a second finish does not hand back a second time")
eq(#StateStack.states, 1, "and takes nothing else off the stack")
check(StateStack:top() == ow, "the overworld survives the second call")
end
-- a mod record may still ask a warp for a fade in; framesIn 0 is truthy in
-- Lua, so the built-in warp keeps its 0 and the retimed one keeps its own
do
local retimed = { transitions = { warp_fade = { kind = "fade", frames = 32,
framesIn = 16 } } }
local fade = Transition.new({ data = retimed, stack = StateStack }, nil,
nil, true)
eq(fade.framesIn, 16, "a retimed warp record keeps its fade in")
local vanilla = Transition.new({ stack = StateStack }, nil, nil, true)
eq(vanilla.framesIn, Timing.WARP_FADE_IN, "the built-in warp has none")
end
StateStack:clear()
T.finish("transition_identity_pop_bug1663")
+242
View File
@@ -89,6 +89,15 @@ local MOVES = {
accuracy = 100, pp = 10, effect = "EFFECT_ENDURE" },
RAGE = { id = "RAGE", name = "RAGE", power = 20, type = "NORMAL",
accuracy = 100, pp = 20, effect = "EFFECT_RAGE" },
-- data/moves/moves.asm:133, :230, :189 and :92 rows, unedited.
BIDE = { id = "BIDE", name = "BIDE", power = 0, type = "NORMAL",
accuracy = 100, pp = 10, effect = "EFFECT_BIDE" },
SLEEP_TALK = { id = "SLEEP_TALK", name = "SLEEP TALK", power = 0,
type = "NORMAL", accuracy = 100, pp = 10, effect = "EFFECT_SLEEP_TALK" },
SNORE = { id = "SNORE", name = "SNORE", power = 40, type = "NORMAL",
accuracy = 100, pp = 15, effect = "EFFECT_SNORE", effectChance = 30 },
SOLARBEAM = { id = "SOLARBEAM", name = "SOLARBEAM", power = 120,
type = "GRASS", accuracy = 100, pp = 10, effect = "EFFECT_SOLARBEAM" },
}
local GROWTH = {
@@ -2790,6 +2799,239 @@ end)()
check("and its user reappears", b:volatile(player).vanished, nil)
end)()
-- ------------------------------------------------------------------- Bide
--
-- data/moves/effects.asm:795-800 runs `storeenergy` ahead of `doturn`, and
-- BattleCommand_DoTurn's mask drops SUBSTATUS_BIDE outright
-- (engine/battle/effect_commands.asm:977-979), so the whole Bide costs the
-- one PP its opening turn spent. The lock is ParsePlayerAction's own arm
-- (engine/battle/core.asm:569-576) for the player and CheckEnemyLockedIn
-- (:5650) for the foe.
;(function()
local function said(events, text)
for _, e in ipairs(events) do
if e.kind == "message" and e.text == text then return true end
end
return false
end
local player = Mon.new(DATA, "CYNDAQUIL", 20, { dvs = perfect })
player.moves = { { id = "BIDE", pp = 10, maxPp = 10 },
{ id = "TACKLE", pp = 35, maxPp = 35 } }
player.hp, player.maxHp = 999, 999
local wild = Mon.new(DATA, "PIDGEY", 20, { dvs = perfect })
wild.moves = { { id = "TACKLE", pp = 35, maxPp = 35 } }
wild.hp, wild.maxHp = 9999, 9999
local b = Battle.new({ data = DATA, party = { player }, wild = wild,
random = zeroRandom })
b:takeEvents()
check("nothing forces the first BIDE", b:forcedMove(player), nil)
b:useMove(player, wild, "BIDE")
b:takeEvents()
check("the opening turn spends one PP", player.moves[1].pp, 9)
check("and the FIGHT menu is locked into it", b:forcedMove(player), "BIDE")
check("with the move list narrowed to the one",
#b:usableMoves(player), 1)
-- BattleCommand_StoreEnergy banks wPlayerDamageTaken while the bit is up.
b:dealDamage(wild, player, 5, {})
b:takeEvents()
b:useMove(player, wild, "BIDE")
check("a storing turn spends no PP", player.moves[1].pp, 9)
check("and stays locked", b:forcedMove(player), "BIDE")
check("`.still_storing` prints rather than attacking",
said(b:takeEvents(), "CYNDAQUIL is storing energy!"), true)
-- A dry BIDE keeps running: the bide arm jumps past MoveSelectionScreen,
-- where .CheckPlayerHasUsableMoves lives (engine/battle/core.asm:5058).
player.moves[1].pp = 0
check("a spent BIDE is still offered", #b:usableMoves(player), 1)
check("...and it is the BIDE", b:usableMoves(player)[1].id, "BIDE")
player.moves[1].pp = 9
local hpBefore = wild.hp
b:useMove(player, wild, "BIDE")
b:takeEvents()
check("the release spends no PP either", player.moves[1].pp, 9)
check("UnleashEnergy pays back double", wild.hp, hpBefore - 10)
check("and the lock is gone", b:forcedMove(player), nil)
-- CheckEnemyLockedIn holds SUBSTATUS_BIDE, so the AI is never asked.
local es = b:volatile(b.enemy)
es.bideTurns, es.bideMove, es.bideStored = 2, "BIDE", 0
check("a biding foe re-uses its Bide", b:enemyMove(), "BIDE")
es.bideTurns, es.bideMove, es.bideStored = nil, nil, nil
-- .reset_bide (engine/battle/core.asm:572-573, :627-629): the PACK cancels
-- a Bide, a switch does not.
b:useMove(player, wild, "BIDE")
b:takeEvents()
check("locked again", b:forcedMove(player), "BIDE")
b:takeTurn({ kind = "item", item = "POTION" })
b:takeEvents()
check("using an item cancels the Bide", b:forcedMove(player), nil)
check("and drops the bank", b:volatile(player).bideStored, nil)
end)()
-- --------------------------------------------------- Snore and Sleep Talk
--
-- `.fast_asleep` prints FastAsleepText and then falls into `.not_asleep` for
-- those two moves instead of `call CantMove / jp EndTurn`
-- (engine/battle/effect_commands.asm:188-200). BattleCommand_SleepTalk opens
-- on ClearLastMove and ends in ResetTurn (move_effects/sleep_talk.asm:2, :61).
;(function()
local function said(events, text)
for _, e in ipairs(events) do
if e.kind == "message" and e.text == text then return true end
end
return false
end
local function sleeper(moves)
local player = Mon.new(DATA, "CYNDAQUIL", 20, { dvs = perfect })
player.moves = moves
player.hp, player.maxHp = 999, 999
local wild = Mon.new(DATA, "PIDGEY", 20, { dvs = perfect })
wild.moves = { { id = "TACKLE", pp = 35, maxPp = 35 } }
wild.hp, wild.maxHp = 9999, 9999
local b = Battle.new({ data = DATA, party = { player }, wild = wild,
random = zeroRandom })
b:takeEvents()
return b, player, wild
end
local b, player, wild = sleeper({
{ id = "SLEEP_TALK", pp = 10, maxPp = 10 },
{ id = "TACKLE", pp = 35, maxPp = 35 } })
player.status, player.statusTurns = "sleep", 3
check("an ordinary move still loses the turn to sleep",
b:canAct(player, "TACKLE"), false)
check("and the counter was spent", player.statusTurns, 2)
check("FastAsleepText still goes up",
said(b:takeEvents(), "CYNDAQUIL is fast asleep!"), true)
player.statusTurns = 3
check("SLEEP TALK is let through", b:canAct(player, "SLEEP_TALK"), true)
check("...and still spends its sleep turn", player.statusTurns, 2)
check("...and still prints the line",
said(b:takeEvents(), "CYNDAQUIL is fast asleep!"), true)
player.statusTurns = 3
check("SNORE is let through too", b:canAct(player, "SNORE"), true)
b:takeEvents()
-- The wake-up arm is not a bypass: it answers for the whole turn.
player.statusTurns = 1
check("the last sleep turn wakes up", b:canAct(player, "SLEEP_TALK"), true)
check("and clears the status", player.status, nil)
player.status, player.statusTurns = "sleep", 5
local hpBefore = wild.hp
b:useMove(player, wild, "SLEEP_TALK")
b:takeEvents()
check("SLEEP TALK pays its own PP through doturn", player.moves[1].pp, 9)
check("but the move it calls pays none (ResetTurn)", player.moves[2].pp, 35)
check("and that move really landed", wild.hp < hpBefore, true)
check("ClearLastMove leaves no last move (used_move_text.asm:30-36)",
b:volatile(player).lastMove, nil)
-- .check_two_turn_move (sleep_talk.asm:117-141) drops the five charge
-- effects and EFFECT_BIDE, so a mon with nothing else fails.
local b2, player2, wild2 = sleeper({
{ id = "SLEEP_TALK", pp = 10, maxPp = 10 },
{ id = "SOLARBEAM", pp = 10, maxPp = 10 } })
player2.status, player2.statusTurns = "sleep", 5
b2:useMove(player2, wild2, "SLEEP_TALK")
check("a two-turn move is never sampled",
said(b2:takeEvents(), "But it failed!"), true)
check("and nothing was called", b2:volatile(player2).chargeMove, nil)
-- BattleCommand_SleepTalk's own `and SLP_MASK / jr z, .fail` (:16-19).
local b3, player3, wild3 = sleeper({
{ id = "SLEEP_TALK", pp = 10, maxPp = 10 },
{ id = "TACKLE", pp = 35, maxPp = 35 } })
b3:useMove(player3, wild3, "SLEEP_TALK")
check("an awake SLEEP TALK fails",
said(b3:takeEvents(), "But it failed!"), true)
-- BattleCommand_Snore (move_effects/snore.asm:1-9) is the same refusal.
local b4, player4, wild4 = sleeper({ { id = "SNORE", pp = 15, maxPp = 15 } })
local snoreBefore = wild4.hp
b4:useMove(player4, wild4, "SNORE")
check("an awake SNORE fails", said(b4:takeEvents(), "But it failed!"), true)
check("and deals nothing", wild4.hp, snoreBefore)
player4.status, player4.statusTurns = "sleep", 5
b4:useMove(player4, wild4, "SNORE")
b4:takeEvents()
check("a sleeping SNORE hits", wild4.hp < snoreBefore, true)
end)()
-- ------------------------------------------- fainted mons stop participating
--
-- UpdateFaintedPlayerMon RESET_FLAGs wBattleParticipantsNotFainted
-- (engine/battle/core.asm:2551-2556) and .EvenlyDivideExpAmongParticipants
-- divides by the count of set bits (:7118-7130), so the survivor of a lost
-- lead collects a whole share, not half of one.
;(function()
local function twoMonBattle()
local one = Mon.new(DATA, "CYNDAQUIL", 20, { dvs = perfect })
one.moves = { { id = "TACKLE", pp = 35, maxPp = 35 } }
local two = Mon.new(DATA, "CYNDAQUIL", 20, { dvs = perfect })
two.moves = { { id = "TACKLE", pp = 35, maxPp = 35 } }
local wild = Mon.new(DATA, "PIDGEY", 20, { dvs = perfect })
wild.moves = { { id = "TACKLE", pp = 35, maxPp = 35 } }
local b = Battle.new({ data = DATA, party = { one, two }, wild = wild,
random = zeroRandom })
b:takeEvents()
return b, one, two, wild
end
local b, one, two, wild = twoMonBattle()
check("the lead starts as a participant", b.participants[1], true)
one.hp = 0
b:resolveFaints()
b:takeEvents()
check("a fainted participant drops out", b.participants[1], nil)
-- The clear is one-shot: GiveExperiencePoints' `.done` falls through
-- ResetBattleParticipants into AddBattleParticipant (:7116, :3033-3037) and
-- puts the dead slot's bit back, and nothing takes it off again.
local oneShot = twoMonBattle()
oneShot.player.hp = 0
oneShot:resolveFaints()
oneShot:takeEvents()
oneShot:resetParticipants()
oneShot:resolveFaints()
oneShot:takeEvents()
check("and the cart's own re-add survives a second pass",
oneShot.participants[1], true)
b:switch(2)
b:takeEvents()
check("the replacement is a participant", b.participants[2], true)
check("...and the fainted lead is not", b.participants[1], nil)
local before = two.experience
wild.hp = 0
b:resolveFaints()
b:takeEvents()
local shared = two.experience - before
-- The control: the same KO with the same mon as the only party member.
local solo = Mon.new(DATA, "CYNDAQUIL", 20, { dvs = perfect })
solo.moves = { { id = "TACKLE", pp = 35, maxPp = 35 } }
local soloWild = Mon.new(DATA, "PIDGEY", 20, { dvs = perfect })
soloWild.moves = { { id = "TACKLE", pp = 35, maxPp = 35 } }
local soloBattle = Battle.new({ data = DATA, party = { solo },
wild = soloWild, random = zeroRandom })
soloBattle:takeEvents()
local soloBefore = solo.experience
soloWild.hp = 0
soloBattle:resolveFaints()
soloBattle:takeEvents()
check("the survivor gets a whole share, not half",
shared, solo.experience - soloBefore)
check("and the share is a real number", shared > 0, true)
end)()
print(("gen2 battle: %d checks, %d failures"):format(checks, failures))
-- Raise rather than os.exit: tests/run_tests.lua dofiles this file, so an
+27
View File
@@ -549,6 +549,33 @@ do
check("but the ITEM pocket still arms", tmPack.switching, 1)
end
-- item_data_constants.asm:47 MAX_ITEMS / MAX_BALLS / MAX_KEY_ITEMS, and the
-- TM/HM pocket is wTMsHMs (ram/wram.asm:2421), NUM_TMS + NUM_HMS = 57 bytes:
-- 50 add_tm rows and 7 add_hm rows in constants/item_constants.asm:220-293.
do
local Bag = require("src.inventory.Bag")
check("ITEM pocket is MAX_ITEMS", Bag.capacity(packGame.data, "ITEM"), 20)
check("BALL pocket is MAX_BALLS", Bag.capacity(packGame.data, "BALL"), 12)
check("KEY_ITEM pocket is MAX_KEY_ITEMS",
Bag.capacity(packGame.data, "KEY_ITEM"), 25)
check("TM/HM pocket is NUM_TMS + NUM_HMS",
Bag.capacity(packGame.data, "TM_HM"), 57)
-- Bag.add tests the cap before inserting, so all 57 cart TM/HMs fit.
local tmData = { items = {}, constants = { bagSize = 2 } }
for i = 1, 58 do
tmData.items["TM_FIX_" .. i] = { id = "TM_FIX_" .. i, name = "TM" .. i,
pocket = "TM_HM", index = 200 + i }
end
check("a mod's bagSize resizes the ITEM pocket only",
Bag.capacity(tmData, "TM_HM"), 57)
local tmSave = { inventory = {}, bagOrder = {} }
for i = 1, 57 do Bag.add(tmSave, "TM_FIX_" .. i, 1, tmData) end
check("all 57 of them fit", Bag.slots(tmSave, tmData, "TM_HM"), 57)
check("and a 58th TM/HM id has no byte to live in",
Bag.add(tmSave, "TM_FIX_58", 1, tmData), false)
end
-- CANCEL sits one past the last row.
check("cancel is past the end", pack:total(), #pack.rows + 1)
pack.index = pack:total()