diff --git a/README.md b/README.md index 8b23217..41f1ac1 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,10 @@ Cave Story Randomizer Todo ---- -- Specifically replace first chest in Pole.tsc so that you always get a weapon. - Provide modified Cave.pxm. (When Bubbline or Fireball) -- Trade Sequence Step A: Only weapons are acquired through trades. - Print Warning/Error Count - Supress Hell Music Error +- Write log - Test Getting Super Missiles Before Missiles - Trade Sequence Step B: Require random obtainable weapon, instead of always polar star and fireball. - Randomize Booster v0.8 / v2.0 diff --git a/src/main.lua b/src/main.lua index 562270f..4f179c0 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,5 +1,7 @@ require 'lib.strict' +local VERSION = '0.1' + Class = require 'lib.classic' _ = require 'lib.moses' Serpent = require 'lib.serpent' @@ -57,7 +59,7 @@ end local function _draw() lg.draw(background, 0, 0) - _print('Cave Story Randomizer v0.1.0', 0, 10) + _print('Cave Story Randomizer v' .. VERSION, 0, 10) _print('by shru', 0, 22) _print(status, 10, 65) _print('shru.itch.io', 10, 220, 'left') diff --git a/src/randomizer.lua b/src/randomizer.lua index b8656a4..b5d8e87 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -72,11 +72,19 @@ function C:_shuffleItems(tscFiles) local itemDeck = ItemDeck() -- Place random weapon in either First Cave or Hermit Gunsmith. - local firstArea = _.sample({'Cave.tsc', 'Pole.tsc'}) - firstArea = 'Cave.tsc' -- TEMP until we specifically place weapon in chest in Pole.tsc, see TODO - tscFiles[firstArea]:replaceItem(itemDeck:getWeapon()) + local firstArea, firstItemKey = unpack(_.sample({ + {'Cave.tsc', 'lFirstCave'}, + {'Pole.tsc', 'wPolarStar'}, + })) + tscFiles[firstArea]:replaceSpecificItem(firstItemKey, itemDeck:getWeapon()) - -- Replace all items. + -- Replace all weapon trades with random weapons + tscFiles['Curly.tsc']:replaceSpecificItem('wMachineGun', itemDeck:getWeapon()) + tscFiles['MazeA.tsc']:replaceSpecificItem('wSnake', itemDeck:getWeapon()) + tscFiles['Pole.tsc']:replaceSpecificItem('wSpur', itemDeck:getWeapon()) + tscFiles['Little.tsc']:replaceSpecificItem('wNemesis', itemDeck:getWeapon()) + + -- Replace the rest of the items. for _, tscFile in pairs(tscFiles) do while tscFile:hasUnreplacedItems() do tscFile:replaceItem(itemDeck:getAny()) diff --git a/src/tsc_file.lua b/src/tsc_file.lua index 2b915bc..6586446 100644 --- a/src/tsc_file.lua +++ b/src/tsc_file.lua @@ -27,6 +27,7 @@ function C:new(path) break -- continue end local item = _.clone(v) + item.key = k table.insert(self._unreplaced, item) until true end self._unreplaced = _.shuffle(self._unreplaced) @@ -38,11 +39,27 @@ end function C:replaceItem(replacement) assert(self:hasUnreplacedItems()) - local original = table.remove(self._unreplaced) + local key = self._unreplaced[#self._unreplaced].key + self:replaceSpecificItem(key, replacement) +end +function C:replaceSpecificItem(originalKey, replacement) + -- Fetch item with key matching originalKey. + local original + for index, item in ipairs(self._unreplaced) do + if item.key == originalKey then + original = item + table.remove(self._unreplaced, index) + break + end + end + assert(original, 'No unreplaced item with key: ' .. originalKey) + + -- Log change local template = "[%s] %s -> %s" logNotice(template:format(self._mapName, original.name, replacement.name)) + -- Replace before if original.replaceBefore then for needle, replacement in pairs(original.replaceBefore) do self._text = self:_stringReplace(self._text, needle, replacement) @@ -60,6 +77,7 @@ function C:replaceItem(replacement) end end + -- Replace attributes. self:_replaceAttribute(original, replacement, 'command') self:_replaceAttribute(original, replacement, 'getText') self:_replaceAttribute(original, replacement, 'displayCmd')