From d42b289aff8629c502ec44690fcff2e670b2cbaa Mon Sep 17 00:00:00 2001 From: Kyle Coburn Date: Thu, 9 Apr 2015 16:47:41 -0700 Subject: [PATCH] Add miss message, ensure immediate escape for DSum --- ai/control.lua | 89 ++++++++++++++++++++++++++----------------- ai/red/strategies.lua | 4 +- ai/strategies.lua | 4 +- main.lua | 6 +-- util/memory.lua | 3 ++ 5 files changed, 64 insertions(+), 42 deletions(-) diff --git a/ai/control.lua b/ai/control.lua index 0e66496..c87cf03 100644 --- a/ai/control.lua +++ b/ai/control.lua @@ -273,47 +273,68 @@ function Control.encounters() return encounters end -function Control.encounter(wildBattle) - local isCritical - local battleMenu = Memory.value("battle", "menu") - if battleMenu == 94 then - isCritical = false - elseif Memory.double("battle", "our_hp") == 0 then - if Memory.value("battle", "critical") == 1 then - isCritical = true - end - end - if isCritical ~= nil and isCritical ~= Control.criticaled then - Control.criticaled = isCritical - end - if wildBattle then - local opponentHP = Memory.double("battle", "opponent_hp") - if not Control.inBattle then - if opponentHP > 0 then - Control.killedCatch = false - Control.inBattle = true - encounters = encounters + 1 - Paint.wildEncounters(encounters) - Bridge.encounter() - if Control.moonEncounters then - Control.moonEncounters = Control.moonEncounters + 1 +function Control.encounter(battleState) + if battleState > 0 then + local wildBattle = battleState == 1 + local isCritical + local battleMenu = Memory.value("battle", "menu") + if battleMenu == 94 then + isCritical = false + Control.missed = false + elseif Memory.double("battle", "our_hp") == 0 then + if Memory.value("battle", "critical") == 1 then + isCritical = true + end + elseif not Control.missed then + local turnMarker = Memory.value("battle", "our_turn") + if turnMarker == 100 or turnMarker == 128 then + local isMiss = Memory.value("battle", "miss") == 1 + if isMiss then + if Battle.accurateAttack and Memory.value("battle", "accuracy") == 7 then + Bridge.chat("Gen 1 missed! (1 in 256 chance.)") + end + Control.missed = true end end - else - if opponentHP == 0 and shouldCatch and not Control.killedCatch then - local gottaCatchEm = {"pidgey", "spearow", "paras", "oddish"} - local opponent = Battle.opponent() - for i,catch in ipairs(gottaCatchEm) do - if opponent == catch then - if not Pokemon.inParty(catch) then - Bridge.chat("Noo, we accidentally killed "..Utils.capitalize(catch).." with a "..(isCritical and "critical" or "high damage range").." :(") - Control.killedCatch = true + end + if isCritical ~= nil and isCritical ~= Control.criticaled then + Control.criticaled = isCritical + end + if wildBattle then + local opponentHP = Memory.double("battle", "opponent_hp") + if not Control.inBattle then + Control.escaped = false + if opponentHP > 0 then + Control.killedCatch = false + Control.inBattle = true + encounters = encounters + 1 + Paint.wildEncounters(encounters) + Bridge.encounter() + if Control.moonEncounters then + Control.moonEncounters = Control.moonEncounters + 1 + end + end + else + if opponentHP == 0 and shouldCatch and not Control.killedCatch then + local gottaCatchEm = {"pidgey", "spearow", "paras", "oddish"} + local opponent = Battle.opponent() + for i,catch in ipairs(gottaCatchEm) do + if opponent == catch then + if not Pokemon.inParty(catch) then + Bridge.chat("Noo, we accidentally killed "..Utils.capitalize(catch).." with a "..(isCritical and "critical" or "high damage range").." :(") + Control.killedCatch = true + end + break end - break end end end end + elseif Control.inBattle then + if Memory.value("battle", "turns") == 0 then + Control.escaped = true + end + Control.inBattle = false end end diff --git a/ai/red/strategies.lua b/ai/red/strategies.lua index 694673c..862dec4 100644 --- a/ai/red/strategies.lua +++ b/ai/red/strategies.lua @@ -125,7 +125,7 @@ Strategies.timeRequirements = { local function nidoranDSum(disabled) local sx, sy = Player.position() - if not disabled and status.tries == nil then + if not disabled and status.tries == nil and Control.escaped then local opponentName = Battle.opponent() local opLevel = Memory.value("battle", "opponent_level") if opponentName == "rattata" then @@ -156,7 +156,7 @@ local function nidoranDSum(disabled) status.tries = 0 end end - if not disabled and status.tries ~= 0 then + if not disabled and status.tries ~= 0 and Control.escaped then if status.tries[status.tries.idx] == 0 then status.tries.idx = status.tries.idx + 1 if status.tries.idx > 3 then diff --git a/ai/strategies.lua b/ai/strategies.lua index 558dd0b..cf35b3e 100644 --- a/ai/strategies.lua +++ b/ai/strategies.lua @@ -75,7 +75,9 @@ end function Strategies.death(extra) local reason - if Control.criticaled then + if Control.missed then + reason = "Missed" + elseif Control.criticaled then reason = "Critical'd" elseif Control.yolo then reason = "Yolo strats" diff --git a/main.lua b/main.lua index 34870a0..bc7770b 100644 --- a/main.lua +++ b/main.lua @@ -147,11 +147,7 @@ while true do end else local battleState = Memory.value("game", "battle") - if battleState > 0 then - Control.encounter(battleState == 1) - else - Control.inBattle = false - end + Control.encounter(battleState) local curr_hp = Pokemon.index(0, "hp") -- if curr_hp ~= lastHP then -- Bridge.hp(curr_hp, Pokemon.index(0, "max_hp")) diff --git a/util/memory.lua b/util/memory.lua index 4dc89f5..247f13b 100644 --- a/util/memory.lua +++ b/util/memory.lua @@ -63,6 +63,9 @@ local memoryNames = { opponent_move = 0x0FEE, critical = 0x105E, + miss = 0x105F, + our_turn = 0x1FF1, + turns = 0x0CD5, opponent_bide = 0x106F, opponent_id = 0x0FE5,