From 5154784a8901abccf248a705d7ce92db0bf27891 Mon Sep 17 00:00:00 2001 From: Kyle Coburn Date: Fri, 10 Apr 2015 12:29:44 -0700 Subject: [PATCH] Add failsafe inventory management by tossing Antidote --- ai/red/strategies.lua | 13 +++++++ data/red/paths.lua | 2 +- storage/inventory.lua | 81 +++++++++++++++++++++++-------------------- util/memory.lua | 1 + 4 files changed, 59 insertions(+), 38 deletions(-) diff --git a/ai/red/strategies.lua b/ai/red/strategies.lua index 83d5364..ab83c37 100644 --- a/ai/red/strategies.lua +++ b/ai/red/strategies.lua @@ -1476,6 +1476,19 @@ strategyFunctions.drivebyRareCandy = function() end end +strategyFunctions.tossAntidote = function() + if Inventory.count() <= (Inventory.contains("full_restore") and 18 or 17) then + return true + end + local tossItem = Inventory.contains("antidote", "pokeball") + if Strategies.initialize() then + p("Tossing "..tossItem.." to make space", Inventory.count()) + end + if not Inventory.useItemOption(tossItem, nil, 1) then + Input.press("A") + end +end + strategyFunctions.safariCarbos = function() if Strategies.initialize() then Strategies.setYolo("safari_carbos") diff --git a/data/red/paths.lua b/data/red/paths.lua index 1057a86..9c76975 100644 --- a/data/red/paths.lua +++ b/data/red/paths.lua @@ -288,7 +288,7 @@ local Paths = { -- Safari 1 {220, {15,25}, {s="bicycle"}, {15,16}, {28,16}, {28,11}, {30,11}}, -- Safari 2 - {217, {0,23}, {4,23}, {4,24}, {20,24}, {20,20}, {s="safariCarbos"}, {12,20}, {12,22}, {11,22}, {10,22}, {s="item",item="super_repel",chain=true}, {s="item",item="carbos",poke="nidoking",close=true}, {9,22}, {9,8}, {12,8}, {12,6}, {17,6}, {17,8}, {20,8}, {s="centerSkipFullRestore"}, {20,3}, {7,3}, {7,5}, {-1,5}}, + {217, {0,23}, {4,23}, {4,24}, {20,24}, {20,20}, {s="safariCarbos"}, {12,20}, {12,22}, {11,22}, {10,22}, {s="item",item="super_repel",chain=true}, {s="tossAntidote"}, {s="item",item="carbos",poke="nidoking",close=true}, {9,22}, {9,8}, {12,8}, {12,6}, {17,6}, {17,8}, {20,8}, {s="centerSkipFullRestore"}, {20,3}, {7,3}, {7,5}, {-1,5}}, -- Safari 3 {218, {39,31}, {22,31}, {22,22}, {16,22}, {16,28}, {13,28}, {13,9}, {28,9}, {28,3}, {3,3}, {3,36}}, -- Safari 4 diff --git a/storage/inventory.lua b/storage/inventory.lua index 3b926d9..2056ecb 100644 --- a/storage/inventory.lua +++ b/storage/inventory.lua @@ -68,6 +68,9 @@ function Inventory.indexOf(name) end function Inventory.count(name) + if not name then + return Memory.value("player", "inventory_count") + end local index = Inventory.indexOf(name) if index ~= -1 then return Memory.raw(ITEM_BASE + index * 2 + 1) @@ -125,7 +128,46 @@ function Inventory.teach(item, poke, replaceIdx, altPoke) end function Inventory.isFull() - return Memory.raw(0x131D) == 20 + return Inventory.count() == 20 +end + +function Inventory.useItemOption(item, poke, option) + local main = Memory.value("menu", "main") + local column = Menu.getCol() + if main == 144 then + if Memory.value("battle", "menu") == 95 then + Input.press("B") + else + local idx = 0 + if poke then + idx = Pokemon.indexOf(poke) + end + Menu.select(idx, true) + end + elseif main == 128 or main == 60 then + if column == 5 then + Menu.select(Inventory.indexOf(item), "accelerate", true) + elseif column == 11 then + Menu.select(2, true) + elseif column == 14 then + Menu.select(option, true) + else + local index = 0 + if poke then + index = Pokemon.indexOf(poke) + end + Menu.select(index, true) + end + elseif main == 228 then + if column == 14 and Memory.value("battle", "menu") == 95 then + Input.press("B") + end + elseif main == Menu.pokemon then + Input.press("B") + else + return false + end + return true end function Inventory.use(item, poke, midfight) @@ -159,42 +201,7 @@ function Inventory.use(item, poke, midfight) return end - local main = Memory.value("menu", "main") - local column = Menu.getCol() - if main == 144 then - if Memory.value("battle", "menu") == 95 then - Input.press("B") - else - local idx = 0 - if poke then - idx = Pokemon.indexOf(poke) - end - Menu.select(idx, true) - end - elseif main == 128 or main == 60 then - if column == 5 then - Menu.select(Inventory.indexOf(item), "accelerate", true) - elseif column == 11 then - Menu.select(2, true) - elseif column == 14 then - Menu.select(0, true) - else - local index = 0 - if poke then - index = Pokemon.indexOf(poke) - end - Menu.select(index, true) - end - elseif main == 228 then - if column == 14 and Memory.value("battle", "menu") == 95 then - Input.press("B") - end - elseif main == Menu.pokemon then - Input.press("B") - else - return false - end - return true + return Inventory.useItemOption(item, poke, 0) end return Inventory diff --git a/util/memory.lua b/util/memory.lua index cb54a26..4270d29 100644 --- a/util/memory.lua +++ b/util/memory.lua @@ -34,6 +34,7 @@ local memoryNames = { facing = 0x152A, repel = 0x10DB, party_size = 0x1163, + inventory_count = 0x131D, }, game = { map = 0x135E,