Differentiate Strategy status variable names

This commit is contained in:
Kyle Coburn 2015-04-08 01:39:29 -07:00
parent 962d825712
commit 477fcf8d4d
2 changed files with 67 additions and 70 deletions

View File

@ -498,12 +498,12 @@ strategyFunctions.fightBrock = function()
local onixHP = Memory.double("battle", "opponent_hp") local onixHP = Memory.double("battle", "opponent_hp")
if not status.canProgress then if not status.canProgress then
status.canProgress = onixHP status.canProgress = onixHP
status.tempDir = bideTurns status.startBide = bideTurns
end end
if turnsToKill then if turnsToKill then
local forced local forced
if turnsToDie < 2 or turnsToKill < 2 or status.tempDir - bideTurns > 1 then if turnsToDie < 2 or turnsToKill < 2 or status.startBide - bideTurns > 1 then
-- elseif turnsToKill < 3 and status.tempDir == bideTurns then -- elseif turnsToKill < 3 and status.startBide == bideTurns then
elseif onixHP == status.canProgress then elseif onixHP == status.canProgress then
forced = "tail_whip" forced = "tail_whip"
end end
@ -622,11 +622,10 @@ strategyFunctions.bugCatcher = function()
if Battle.isActive() then if Battle.isActive() then
status.canProgress = true status.canProgress = true
local isWeedle = Pokemon.isOpponent("weedle") local isWeedle = Pokemon.isOpponent("weedle")
if isWeedle and not status.tempDir then if isWeedle and not status.secondCaterpie then
status.tempDir = true status.secondCaterpie = true
end end
secondCaterpie = status.tempDir if not isWeedle and status.secondCaterpie then
if not isWeedle and secondCaterpie then
if stats.nidoran.level4 and stats.nidoran.speed >= 14 and Pokemon.index(0, "attack") >= 19 then if stats.nidoran.level4 and stats.nidoran.speed >= 14 and Pokemon.index(0, "attack") >= 19 then
-- print("IA "..Pokemon.index(0, "attack")) -- print("IA "..Pokemon.index(0, "attack"))
Battle.automate() Battle.automate()
@ -647,16 +646,16 @@ strategyFunctions.shortsKid = function()
local wrapping = Memory.value("battle", "turns") > 0 local wrapping = Memory.value("battle", "turns") > 0
if wrapping then if wrapping then
local curr_hp = Memory.double("battle", "our_hp") local curr_hp = Memory.double("battle", "our_hp")
if not status.tempDir then if not status.wrappedAt then
status.tempDir = curr_hp status.wrappedAt = curr_hp
end end
local wrapDamage = status.tempDir - curr_hp local wrapDamage = status.wrappedAt - curr_hp
if wrapDamage > 0 and wrapDamage < 7 and curr_hp < 14 and not Strategies.opponentDamaged() then if wrapDamage > 0 and wrapDamage < 7 and curr_hp < 14 and not Strategies.opponentDamaged() then
Inventory.use("potion", nil, true) Inventory.use("potion", nil, true)
return false return false
end end
elseif status.tempDir then else
status.tempDir = nil status.wrappedAt = nil
end end
end end
Control.battlePotion(fightingEkans or Strategies.damaged(2)) Control.battlePotion(fightingEkans or Strategies.damaged(2))
@ -882,15 +881,15 @@ strategyFunctions.fightMisty = function()
if Battle.isActive() then if Battle.isActive() then
status.canProgress = true status.canProgress = true
if Battle.redeployNidoking() then if Battle.redeployNidoking() then
if status.tempDir == false then if status.swappedOut == false then
status.tempDir = true status.swappedOut = true
end end
return false return false
end end
local swappedOut = status.tempDir local forced
if not swappedOut and Combat.isConfused() then if not status.swappedOut and Combat.isConfused() then
status.tempDir = false status.swappedOut = false
if Battle.sacrifice("pidgey", "spearow", "paras") then if Battle.sacrifice("squirtle", "pidgey", "spearow", "paras") then
return false return false
end end
end end
@ -950,9 +949,9 @@ strategyFunctions.catchOddish = function()
else else
local path local path
if caught then if caught then
if not status.tempDir then if not status.caught then
Bridge.caught(Pokemon.inParty("oddish")) Bridge.caught(Pokemon.inParty("oddish"))
status.tempDir = true status.caught = true
end end
if py < 21 then if py < 21 then
py = 21 py = 21
@ -1080,15 +1079,15 @@ strategyFunctions.trashcans = function()
Down = "Up", Down = "Up",
Left = "Right" Left = "Right"
} }
Player.interact(inverse[status.tempDir]) Player.interact(inverse[status.direction])
else else
local trashPath = {{2,11},{"Left"},{2,11}, {2,12},{4,12},{4,11},{"Right"},{4,11}, {4,9},{"Left"},{4,9}, {4,7},{"Right"},{4,7}, {4,6},{2,6},{2,7},{"Left"},{2,7}, {2,6},{4,6},{4,8},{9,8},{"Up"},{9,8}, {8,8},{8,9},{"Left"},{8,9}, {8,10},{9,10},{"Down"},{9,10},{8,10}} local trashPath = {{2,11},{"Left"},{2,11}, {2,12},{4,12},{4,11},{"Right"},{4,11}, {4,9},{"Left"},{4,9}, {4,7},{"Right"},{4,7}, {4,6},{2,6},{2,7},{"Left"},{2,7}, {2,6},{4,6},{4,8},{9,8},{"Up"},{9,8}, {8,8},{8,9},{"Left"},{8,9}, {8,10},{9,10},{"Down"},{9,10},{8,10}}
if status.tempDir and type(status.tempDir) == "number" then if status.direction and type(status.direction) == "number" then
local px, py = Player.position() local px, py = Player.position()
local dx, dy = px, py local dx, dy = px, py
if py < 12 then if py < 12 then
dy = 12 dy = 12
elseif status.tempDir == 1 then elseif status.direction == 1 then
dx = 2 dx = 2
else else
dx = 8 dx = 8
@ -1097,9 +1096,9 @@ strategyFunctions.trashcans = function()
Walk.step(dx, dy) Walk.step(dx, dy)
return return
end end
status.tempDir = nil status.direction = nil
end end
status.tempDir = Walk.custom(trashPath, status.canProgress) status.direction = Walk.custom(trashPath, status.canProgress)
status.canProgress = false status.canProgress = false
end end
end end
@ -1817,20 +1816,19 @@ end
strategyFunctions.fightGiovanni = function() strategyFunctions.fightGiovanni = function()
if Battle.isActive() then if Battle.isActive() then
if Strategies.initialize() then if Strategies.initialize() then
status.tempDir = Battle.pp("earthquake") status.startEqPP = Battle.pp("earthquake")
status.canProgress = true status.canProgress = true
end end
local forced, needsXSpecial local forced, needsXSpecial
local startEqPP = status.tempDir
if riskGiovanni then if riskGiovanni then
if startEqPP < 5 then if status.startEqPP < 5 then
needsXSpecial = true needsXSpecial = true
end end
if needsXSpecial or Battle.pp("earthquake") < 4 then if needsXSpecial or Battle.pp("earthquake") < 4 then
forced = "ice_beam" forced = "ice_beam"
end end
else else
needsXSpecial = startEqPP < 2 needsXSpecial = status.startEqPP < 2
if Pokemon.isOpponent("rhydon") then if Pokemon.isOpponent("rhydon") then
forced = "ice_beam" forced = "ice_beam"
end end
@ -1852,13 +1850,13 @@ strategyFunctions.viridianRival = function()
if Battle.isActive() then if Battle.isActive() then
if not status.canProgress then if not status.canProgress then
if riskGiovanni or stats.nidoran.special < 45 or Pokemon.index(0, "speed") < 134 then if riskGiovanni or stats.nidoran.special < 45 or Pokemon.index(0, "speed") < 134 then
status.tempDir = "x_special" status.xItem = "x_special"
else else
print("Skip X Special strats!") print("Skip X Special strats!")
end end
status.canProgress = true status.canProgress = true
end end
if Strategies.prepare("x_accuracy", status.tempDir) then if Strategies.prepare("x_accuracy", status.xItem) then
local forced local forced
if Pokemon.isOpponent("pidgeot") then if Pokemon.isOpponent("pidgeot") then
forced = "thunderbolt" forced = "thunderbolt"
@ -1882,13 +1880,13 @@ end
strategyFunctions.ether = function(data) strategyFunctions.ether = function(data)
local main = Memory.value("menu", "main") local main = Memory.value("menu", "main")
data.item = status.tempDir data.item = status.item
if status.tempDir and Strategies.completedMenuFor(data) then if status.item and Strategies.completedMenuFor(data) then
if Strategies.closeMenuFor(data) then if Strategies.closeMenuFor(data) then
return true return true
end end
else else
if not status.tempDir then if not status.item then
if data.max then if data.max then
-- TODO don't skip center if not in redbar -- TODO don't skip center if not in redbar
maxEtherSkip = stats.nidoran.attack > 53 and Battle.pp("earthquake") > 0 and Battle.pp("horn_drill") > 3 maxEtherSkip = stats.nidoran.attack > 53 and Battle.pp("earthquake") > 0 and Battle.pp("horn_drill") > 3
@ -1897,11 +1895,11 @@ strategyFunctions.ether = function(data)
end end
Bridge.chat("Grabbing the Max Ether to skip the Elite 4 Center") Bridge.chat("Grabbing the Max Ether to skip the Elite 4 Center")
end end
status.tempDir = Inventory.contains("ether", "max_ether") status.item = Inventory.contains("ether", "max_ether")
if not status.tempDir then if not status.item then
return true return true
end end
status.tries = Inventory.count(status.tempDir) --TODO remove? status.tries = Inventory.count(status.item) --TODO remove?
end end
if Memory.value("menu", "main") == 144 and Menu.getCol() == 5 then if Memory.value("menu", "main") == 144 and Menu.getCol() == 5 then
if Memory.value("battle", "menu") ~= 95 then if Memory.value("battle", "menu") ~= 95 then
@ -2134,23 +2132,23 @@ strategyFunctions.blue = function()
if not status.canProgress then if not status.canProgress then
status.canProgress = true status.canProgress = true
if stats.nidoran.special >= 45 and stats.nidoran.speed >= 52 and Inventory.contains("x_special") then if stats.nidoran.special >= 45 and stats.nidoran.speed >= 52 and Inventory.contains("x_special") then
status.tempDir = "x_special" status.xItem = "x_special"
else else
status.tempDir = "x_speed" status.xItem = "x_speed"
end end
if not STREAMING_MODE then if not STREAMING_MODE then
status.tempDir = "x_speed" status.xItem = "x_speed"
end end
end end
local boostFirst = Pokemon.index(0, "hp") < 55 local boostFirst = Pokemon.index(0, "hp") < 55
local firstItem, secondItem local firstItem, secondItem
if boostFirst then if boostFirst then
firstItem = status.tempDir firstItem = status.xItem
secondItem = "x_accuracy" secondItem = "x_accuracy"
else else
firstItem = "x_accuracy" firstItem = "x_accuracy"
secondItem = status.tempDir secondItem = status.xItem
end end
local forced = "horn_drill" local forced = "horn_drill"
@ -2159,7 +2157,7 @@ strategyFunctions.blue = function()
local skyDamage = Combat.healthFor("BlueSky") local skyDamage = Combat.healthFor("BlueSky")
local healCutoff = skyDamage * 0.825 local healCutoff = skyDamage * 0.825
if Strategies.initialize() then if Strategies.initialize() then
if not Strategies.isPrepared("x_accuracy", status.tempDir) then if not Strategies.isPrepared("x_accuracy", status.xItem) then
local msg = "Uh oh... First-turn Sky Attack could end the run here, " local msg = "Uh oh... First-turn Sky Attack could end the run here, "
if Pokemon.index(0, "hp") > skyDamage then if Pokemon.index(0, "hp") > skyDamage then
msg = msg.."no criticals pls D:" msg = msg.."no criticals pls D:"
@ -2184,18 +2182,18 @@ strategyFunctions.blue = function()
return false return false
end end
end end
if Strategies.prepare("x_accuracy", status.tempDir) then if Strategies.prepare("x_accuracy", status.xItem) then
Battle.automate(forced) Battle.automate(forced)
end end
end end
else else
if Strategies.prepare(firstItem, secondItem) then if Strategies.prepare(firstItem, secondItem) then
if Pokemon.isOpponent("alakazam") then if Pokemon.isOpponent("alakazam") then
if status.tempDir == "x_speed" then if status.xItem == "x_speed" then
forced = "earthquake" forced = "earthquake"
end end
elseif Pokemon.isOpponent("rhydon") then elseif Pokemon.isOpponent("rhydon") then
if status.tempDir == "x_special" then if status.xItem == "x_special" then
forced = "ice_beam" forced = "ice_beam"
end end
end end

View File

@ -21,7 +21,7 @@ local yellow = YELLOW
local splitNumber, splitTime = 0, 0 local splitNumber, splitTime = 0, 0
local resetting local resetting
local status = {tries = 0, tempDir = nil, canProgress = nil, initialized = false} local status = {tries = 0, canProgress = nil, initialized = false}
local stats = {} local stats = {}
Strategies.status = status Strategies.status = status
Strategies.stats = stats Strategies.stats = stats
@ -240,23 +240,24 @@ end
function Strategies.completedMenuFor(data) function Strategies.completedMenuFor(data)
local count = Inventory.count(data.item) local count = Inventory.count(data.item)
if count == 0 or count + (data.amount or 1) <= status.tries then if count == 0 or (status.startCount and count + (data.amount or 1) <= status.startCount) then
return true return true
end end
return false return false
end end
function Strategies.closeMenuFor(data) function Strategies.closeMenuFor(data)
if (not status.tempDir and not data.close) or data.chain or Menu.close() then if (not status.menuOpened and not data.close) or data.chain then
return true return true
end end
return Menu.close()
end end
function Strategies.useItem(data) function Strategies.useItem(data)
local main = Memory.value("menu", "main") local main = Memory.value("menu", "main")
if status.tries == 0 then if not status.startCount then
status.tries = Inventory.count(data.item) status.startCount = Inventory.count(data.item)
if status.tries == 0 then if status.startCount == 0 then
if Strategies.closeMenuFor(data) then if Strategies.closeMenuFor(data) then
return true return true
end end
@ -267,12 +268,9 @@ function Strategies.useItem(data)
if Strategies.closeMenuFor(data) then if Strategies.closeMenuFor(data) then
return true return true
end end
else elseif Menu.pause() then
if Inventory.use(data.item, data.poke) then status.menuOpened = true
status.tempDir = true Inventory.use(data.item, data.poke)
else
Menu.pause()
end
end end
end end
@ -297,13 +295,13 @@ local function completedSkillFor(data)
end end
function Strategies.isPrepared(...) function Strategies.isPrepared(...)
if status.tries == 0 then if not status.preparing then
status.tries = {} return false
end end
for i,name in ipairs(arg) do for i,name in ipairs(arg) do
local currentCount = Inventory.count(name) local currentCount = Inventory.count(name)
if currentCount > 0 then if currentCount > 0 then
local previousCount = status.tries[name] local previousCount = status.preparing[name]
if previousCount == nil or currentCount == previousCount then if previousCount == nil or currentCount == previousCount then
return false return false
end end
@ -313,16 +311,16 @@ function Strategies.isPrepared(...)
end end
function Strategies.prepare(...) function Strategies.prepare(...)
if status.tries == 0 then if not status.preparing then
status.tries = {} status.preparing = {}
end end
local item local item
for idx,name in ipairs(arg) do for idx,name in ipairs(arg) do
local currentCount = Inventory.count(name) local currentCount = Inventory.count(name)
local needsItem = currentCount > 0 local needsItem = currentCount > 0
local previousCount = status.tries[name] local previousCount = status.preparing[name]
if previousCount == nil then if previousCount == nil then
status.tries[name] = currentCount status.preparing[name] = currentCount
elseif needsItem then elseif needsItem then
needsItem = currentCount == previousCount needsItem = currentCount == previousCount
end end
@ -460,7 +458,7 @@ Strategies.functions = {
if toPotion then if toPotion then
if Menu.pause() then if Menu.pause() then
Inventory.use(toPotion) Inventory.use(toPotion)
status.tempDir = true status.menuOpened = true
end end
return false return false
end end
@ -504,7 +502,7 @@ Strategies.functions = {
replacement = 0 replacement = 0
end end
if Inventory.teach(itemName, data.poke, replacement, data.alt) then if Inventory.teach(itemName, data.poke, replacement, data.alt) then
status.tempDir = true status.menuOpened = true
else else
Menu.pause() Menu.pause()
end end
@ -897,13 +895,14 @@ Strategies.functions = {
pos = data.x pos = data.x
end end
local newP = Memory.raw(pos) local newP = Memory.raw(pos)
if status.tries == 0 then if not status.startPosition then
status.tries = {start=newP} status.startPosition = newP
elseif status.tries.start ~= newP then elseif status.startPosition ~= newP then
return true return true
end end
Input.press(data.dir, 0) Input.press(data.dir, 0)
end, end,
} }
strategyFunctions = Strategies.functions strategyFunctions = Strategies.functions