Provide modified Cave.pxm when first weapon can not break blocks.

This commit is contained in:
shru 2018-12-19 15:15:26 -05:00
parent e48419431f
commit 4145e06bef
7 changed files with 50 additions and 17 deletions

View file

@ -4,7 +4,6 @@ Cave Story Randomizer
Todo
----
- Provide modified Cave.pxm. (When Bubbline or Fireball)
- Print Warning/Error Count
- Supress Hell Music Error
- Write log

BIN
src/database/Cave.pxm Normal file

Binary file not shown.

View file

@ -103,7 +103,7 @@ function missiles(t)
}
end
return {
local data = {
-------------
-- WEAPONS --
-------------
@ -326,7 +326,7 @@ return {
map = "EggR2",
label = "0302",
}),
wSuperMissileLauncher = {
mSuperMissileLauncher = {
name = "Super Missile Launcher",
map = "MazeS",
getText = {
@ -350,6 +350,12 @@ return {
-- concealing a chest containing this massive expansion of 24 Misisles.
}
for k, t in pairs(data) do
t.key = k
end
return data
--[[
-- Weapons

View file

@ -10,6 +10,8 @@ Terebi = require 'lib.terebi'
lf = love.filesystem
lg = love.graphics
U = require 'util'
local LOG_LEVEL = 3
local function _log(level, prefix, text, ...)
if LOG_LEVEL >= level then

View file

@ -14,6 +14,12 @@ do
end
end
local WEAPONS_WHICH_CAN_NOT_BREAK_BLOCKS = {
'wBubbline',
'wFireball',
'wSnake',
}
function C:randomize(path)
local success, dirStage = self:_mountDirectory(path)
if not success then
@ -21,8 +27,11 @@ function C:randomize(path)
end
self:_seedRngesus()
local tscFiles = self:_createTscFiles(dirStage)
self:_shuffleItems(tscFiles)
local canNotBreakBlocks = self:_shuffleItems(tscFiles)
self:_writeModifiedData(tscFiles)
if canNotBreakBlocks then
self:_copyModifiedFirstCave()
end
self:_unmountDirectory(path)
return [[Randomized data successfully created!
@ -76,7 +85,8 @@ function C:_shuffleItems(tscFiles)
{'Cave.tsc', 'lFirstCave'},
{'Pole.tsc', 'wPolarStar'},
}))
tscFiles[firstArea]:replaceSpecificItem(firstItemKey, itemDeck:getWeapon())
local firstWeapon = itemDeck:getWeapon()
tscFiles[firstArea]:replaceSpecificItem(firstItemKey, firstWeapon)
-- Replace all weapon trades with random weapons
tscFiles['Curly.tsc']:replaceSpecificItem('wMachineGun', itemDeck:getWeapon())
@ -90,6 +100,8 @@ function C:_shuffleItems(tscFiles)
tscFile:replaceItem(itemDeck:getAny())
end
end
return _.contains(WEAPONS_WHICH_CAN_NOT_BREAK_BLOCKS, firstWeapon.key)
end
function C:_writeModifiedData(tscFiles)
@ -106,6 +118,13 @@ function C:_writeModifiedData(tscFiles)
end
end
function C:_copyModifiedFirstCave()
local cavePxmPath = lf.getSourceBaseDirectory() .. '/data/Stage/Cave.pxm'
local data = lf.read('database/Cave.pxm')
assert(data)
U.writeFile(cavePxmPath, data)
end
function C:_unmountDirectory(path)
assert(lf.unmount(path))
print("\n")

View file

@ -1,10 +1,5 @@
local C = Class:extend()
-- https://www.lua.org/manual/5.1/manual.html#5.7
-- w+: Update mode, all previous data is erased;
-- b: Binary mode, forces Windows to save with Unix endings.
MODE_WRITE_ERASE_EXISTING = 'w+b'
local ITEM_DATA = require 'database.items'
function C:new(path)
@ -27,7 +22,6 @@ 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)
@ -130,13 +124,8 @@ end
function C:writeTo(path)
logInfo('writing TSC to: ' .. path)
local file, err = io.open(path, MODE_WRITE_ERASE_EXISTING)
assert(err == nil, err)
local encoded = self:_codec(self._text, 'encode')
file:write(encoded)
file:flush()
file:close()
U.writeFile(path, encoded)
end
function C:_codec(text, mode)

18
src/util.lua Normal file
View file

@ -0,0 +1,18 @@
local U = {}
-- https://www.lua.org/manual/5.1/manual.html#5.7
-- w+: Update mode, all previous data is erased;
-- b: Binary mode, forces Windows to save with Unix endings.
MODE_WRITE_ERASE_EXISTING = 'w+b'
function U.writeFile(path, data)
logDebug('writing file: ' .. path)
local file, err = io.open(path, MODE_WRITE_ERASE_EXISTING)
assert(err == nil, err)
file:write(data)
file:flush()
file:close()
end
return U