From cf356f5a88856c734081e508f4380b505d233706 Mon Sep 17 00:00:00 2001 From: Kyle Coburn Date: Fri, 24 Apr 2015 21:34:49 -0700 Subject: [PATCH] Cleanup --- ai/control.lua | 17 ++++++++--------- ai/red/strategies.lua | 10 ++++++---- ai/strategies.lua | 4 ++-- ai/yellow/strategies.lua | 2 +- external/json.lua | 1 - 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ai/control.lua b/ai/control.lua index 8589c0a..2652ebd 100644 --- a/ai/control.lua +++ b/ai/control.lua @@ -4,13 +4,14 @@ local Battle local Combat = require "ai.combat" local Strategies +local Data = require "data.data" + local Bridge = require "util.bridge" local Memory = require "util.memory" local Menu = require "util.menu" local Paint = require "util.paint" local Utils = require "util.utils" -local Data = require "data.data" local Inventory = require "storage.inventory" local Pokemon = require "storage.pokemon" @@ -23,8 +24,6 @@ local extraEncounter, maxEncounters local battleYolo local encountersSection -local yellow = YELLOW - Control.areaName = "Unknown" Control.getMoonExp = true Control.yolo = false @@ -96,7 +95,7 @@ local controlFunctions = { startMtMoon = function() Control.canDie(false) - Control.getMoonExp = not yellow + Control.getMoonExp = not Data.yellow end, moon1Exp = function() @@ -208,9 +207,9 @@ function Control.canCatch(partySize) partySize = Memory.value("player", "party_size") end local pokeballs = Inventory.count("pokeball") - local minimumCount = (yellow and 3 or 4) - partySize + local minimumCount = (Data.yellow and 3 or 4) - partySize if pokeballs < minimumCount then - if yellow and Pokemon.inParty("nidoran", "nidorino", "nidoking") and Pokemon.inParty("pidgey", "spearow") then + if Data.yellow and Pokemon.inParty("nidoran", "nidorino", "nidoking") and Pokemon.inParty("pidgey", "spearow") then return false end Strategies.reset("pokeballs", "Not enough PokeBalls", pokeballs) @@ -230,7 +229,7 @@ function Control.shouldCatch(partySize) if not shouldCatch then return false end - if yellow and not Inventory.contains("pokeball") then + if Data.yellow and not Inventory.contains("pokeball") then return false end if not partySize then @@ -274,7 +273,7 @@ function Control.set(data) if controlFunction then controlFunction(data) else - p("INVALID CONTROL", data.c, GAME_NAME) + p("INVALID CONTROL", data.c, Data.gameName) end end @@ -384,7 +383,7 @@ end function Control.init() Battle = require("action.battle") - Strategies = require("ai."..GAME_NAME..".strategies") + Strategies = require("ai."..Data.gameName..".strategies") end return Control diff --git a/ai/red/strategies.lua b/ai/red/strategies.lua index a7ebf89..919e184 100644 --- a/ai/red/strategies.lua +++ b/ai/red/strategies.lua @@ -8,6 +8,8 @@ local Shop = require "action.shop" local Textbox = require "action.textbox" local Walk = require "action.walk" +local Data = require "data.data" + local Bridge = require "util.bridge" local Input = require "util.input" local Memory = require "util.memory" @@ -15,7 +17,6 @@ local Menu = require "util.menu" local Player = require "util.player" local Utils = require "util.utils" -local Data = require "data.data" local Inventory = require "storage.inventory" local Pokemon = require "storage.pokemon" @@ -338,7 +339,7 @@ strategyFunctions.fightBulbasaur = function() end if Battle.isActive() and Battle.opponentAlive() then local resetMessage, customReason - if Memory.double("battle", "our_attack") < 2 then + if Memory.double("battle", "our_attack") <= 2 then resetMessage = "Growled to death." customReason = true else @@ -368,7 +369,8 @@ strategyFunctions.catchNidoran = function() if not Control.canCatch() then return true end - local catchableNidoran = Pokemon.isOpponent("nidoran") and Memory.value("battle", "opponent_level") > 2 + local opponent = Battle.opponent() + local catchableNidoran = opponent == "nidoran" and Memory.value("battle", "opponent_level") > 2 local pokeballs = Inventory.count("pokeball") local caught = Memory.value("player", "party_size") - 1 if pokeballs < (catchableNidoran and 5 or 6) - caught * 2 then @@ -2028,7 +2030,7 @@ end function Strategies.initGame(midGame) if midGame then - Strategies.setYolo("bulbasaur") + Strategies.setYolo("bulbasaur", true) stats.squirtle = { attack = 11, defense = 11, diff --git a/ai/strategies.lua b/ai/strategies.lua index 0b540a9..94f4a21 100644 --- a/ai/strategies.lua +++ b/ai/strategies.lua @@ -122,8 +122,8 @@ function Strategies.resetTime(timeLimit, explanation, custom) end end -function Strategies.setYolo(name) - if not RESET_FOR_TIME then +function Strategies.setYolo(name, forced) + if not forced and not RESET_FOR_TIME then return false end local minimumTime = Strategies.getTimeRequirement(name) diff --git a/ai/yellow/strategies.lua b/ai/yellow/strategies.lua index 2683f2b..18a1aef 100644 --- a/ai/yellow/strategies.lua +++ b/ai/yellow/strategies.lua @@ -923,7 +923,7 @@ end function Strategies.initGame(midGame) if midGame then - -- Strategies.setYolo("") + -- Strategies.setYolo("", true) if Pokemon.inParty("nidoking") then local attDV, defDV, spdDV, sclDV = Pokemon.getDVs("nidoking") p(attDV, defDV, spdDV, sclDV) diff --git a/external/json.lua b/external/json.lua index d9eb25f..2e93f42 100644 --- a/external/json.lua +++ b/external/json.lua @@ -108,7 +108,6 @@ function json.encode (v) assert(false,'encode attempt to encode unsupported type ' .. vtype .. ':' .. tostring(v)) end - --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. -- @param s The string to scan. -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1.