Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local appearanceToFile = {}
- local fileToAppearance = {}
- local nounToFile = {}
- local fileToNoun = {}
- local dirObjects = {}
- math.randomseed(os.clock())
- local executableObjects = {
- "lever",
- "screen",
- "button",
- "console",
- "terminal",
- "dial",
- "switch",
- "keyboard",
- "mouse",
- "joystick",
- "machine",
- "radio",
- "printer",
- "drive",
- "computer",
- "modem",
- "screen",
- "TARDIS",
- "compiler",
- "robot",
- "spaceship",
- "turtle",
- "cyborg",
- "car",
- "microphone",
- "teleporter",
- --"pirate ninja zombie robot assassin",
- "laser",
- }
- local nonexecutableObjects = {
- "box",
- "ball",
- "block",
- "drawer",
- "chest",
- "wire",
- "sword",
- "shovel",
- "pick",
- "axe",
- "table",
- "bed",
- "bookshelf",
- "cabinet",
- "picture",
- "antenna",
- "boiler",
- "furnace",
- "table",
- "sheep",
- "flashdrive",
- "pirate",
- "ninja",
- "zombie",
- "cat",
- "sandwich",
- "bukkit",
- "bucket",
- "wrench",
- "shoe",
- "cow",
- "shark",
- "kidney",
- "bean",
- "dictionary",
- "scripter",
- "lunatic",
- "girl",
- "boy",
- "man",
- "woman",
- "dwarf",
- "elf",
- "concept",
- }
- local adjectives = {
- "wonderous",
- "milky",
- "translucent",
- "mysterious",
- "brilliant",
- "fiery",
- "burning",
- "icy",
- "frozen",
- "old",
- "ancient",
- "sandy",
- "monochrome",
- "clear",
- "distorted",
- "shifting",
- "talking",
- "purple",
- "chartreuse",
- "murderous",
- "menacing",
- "sapphire",
- "violet",
- "light blue",
- "red",
- "green",
- "blue",
- "grey",
- "gold",
- "Advanced",
- }
- local function generateAppearance(dir, appearance, executable)
- local descStr = ""
- local object = "object"
- math.randomseed(os.clock()+math.random(1,1000))
- local scpRand = math.random(1, 100)
- math.randomseed(os.clock()+math.random(1,1000))
- if executable then
- object = executableObjects[math.random(1,#executableObjects)]
- else
- object = nonexecutableObjects[math.random(1,#nonexecutableObjects)]
- end
- math.randomseed(os.clock()+math.random(1,1000))
- local adjective = adjectives[math.random(1,#adjectives)]
- if scpRand == 52 then
- object = "[DATA EXPUNGED]"
- end
- descStr = appearance..adjective.." "..object
- if appearanceToFile[dir][descStr] or nounToFile[dir][object] then
- return generateAppearance(dir,appearance,executable)
- else
- return descStr, object
- end
- end
- local function generateObject(base, name)
- local file = fs.combine(base, name)
- local size = fs.getSize(file)
- local func, err = loadfile(file)
- local executable = false
- local appearance = ""
- if func then
- executable = true
- end
- if size > 10240 then -- 10 kb
- appearance = "a colossal "
- elseif size >= 9216 and size < 10240 then
- appearance = "a huge "
- elseif size >= 8192 and size < 9216 then
- appearance = "a bulky "
- elseif size >= 7168 and size < 8192 then
- appearance = "a large "
- elseif size >= 2048 and size < 7168 then
- appearance = "a medium-sized "
- elseif size >= 1024 and size < 2048 then
- appearance = "a small "
- elseif size < 1024 then
- appearance = "a tiny "
- else
- appearance = ""
- end
- appearance, noun = generateAppearance(base, appearance, executable)
- if dirObjects[base] then
- dirObjects[base][file] = appearance
- dirObjects[base][appearance] = file
- else
- dirObjects[base] = {[file] = appearance, [appearance] = file}
- end
- if fileToAppearance[base] then
- fileToAppearance[base][file] = appearance
- else
- fileToAppearance[base] = {[file] = appearance}
- end
- if appearanceToFile[base] then
- appearanceToFile[base][appearance] = file
- else
- appearanceToFile[base] = {[appearance] = file}
- end
- if nounToFile[base] then
- nounToFile[base][noun] = file
- else
- nounToFile[base] = {[noun] = file}
- end
- if fileToNoun[base] then
- fileToNoun[base][file] = noun
- else
- fileToNoun[base] = {[file] = noun}
- end
- end
- local function generateRoom(dir, showFileNames)
- term.clear()
- term.setCursorPos(1,1)
- print("You see:")
- local files = fs.list(dir)
- local newGen = (dirObjects[dir] == nil)
- if newGen then
- dirObjects[dir] = {}
- appearanceToFile[dir] = {}
- fileToAppearance[dir] = {}
- nounToFile[dir] = {}
- fileToNoun[dir] = {}
- end
- local filesInDir = {}
- for i,v in ipairs(files) do
- filesInDir[fs.combine(dir, v)] = true
- end
- for i,v in ipairs(files) do
- if dirObjects[dir][fs.combine(dir, v)] == nil then
- if not fs.isDir(fs.combine(dir, v)) then
- generateObject(dir, v)
- else
- if v == "underworld" then
- fileToAppearance[dir][fs.combine(dir, v)] = "a door to the land of dead files"
- appearanceToFile[dir]["a door to the land of dead files"] = fs.combine(dir, v)
- elseif v == "rom" then
- fileToAppearance[dir][fs.combine(dir, v)] = "a door to the land of unchanging files"
- appearanceToFile[dir]["a door to the land of unchanging files"] = fs.combine(dir, v)
- else
- fileToAppearance[dir][fs.combine(dir, v)] = "a door labeled \""..v.."\""
- appearanceToFile[dir]["a door labeled \""..v.."\""] = fs.combine(dir, v)
- end
- nounToFile[dir][v] = fs.combine(dir, v)
- fileToNoun[dir][fs.combine(dir, v)] = v
- end
- end
- end
- if not newGen then
- local oldObjects = fileToAppearance[dir]
- for i,v in pairs(oldObjects) do
- if not filesInDir[i] then
- dirObjects[dir][i] = nil
- end
- end
- for i,v in pairs(oldObjects) do
- if not filesInDir[i] then
- appearanceToFile[dir][fileToAppearance[dir][i]] = nil
- fileToAppearance[dir][i] = nil
- end
- end
- local oldNouns = fileToNoun[dir]
- for i,v in pairs(oldNouns) do
- if not filesInDir[i] then
- nounToFile[dir][fileToNoun[dir][i]] = nil
- fileToNoun[dir][i] = nil
- end
- end
- end
- for i,v in pairs(fileToAppearance[dir]) do
- if showFileNames then
- print(i..": "..v)
- else
- print(v)
- end
- end
- end
- local function parseCommand(cmd)
- local words = {}
- for word in string.gmatch(cmd, "%S+") do
- table.insert(words, word)
- end
- if words[1] == nil then
- words[1] = "help"
- end
- if words[2] == nil then
- words[2] = "me"
- end
- local verb = string.lower(words[1])
- local target = words[2]
- for i=3, #words do
- target = target.." "..words[i]
- end
- if verb == "slay" or verb == "destroy" or verb == "kill" then
- print("Before "..verb.."ing this poor "..target..", maybe you should think if this is a wise option.")
- write("Do you want to do this? >")
- local yn = string.lower(string.sub(read(), 1,1))
- if yn == "y" then
- if not fs.exists("underworld") then
- fs.makeDir("underworld")
- end
- fs.move(nounToFile[shell.dir()][target], fs.combine("underworld", nounToFile[shell.dir()][target]))
- else
- print("After thinking carefully, you lower your weapon.")
- end
- elseif verb == "use" then
- local programArgs = {}
- print("How do you want to use this "..target.."?")
- print("(OOC): program parameters, please:")
- local argStr = read()
- for word in string.gmatch(argStr, "%S+") do
- table.insert(programArgs, word)
- end
- print("You hear the whirrr of unknown machinery in the distance...")
- os.sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- shell.run(nounToFile[shell.dir()][target], unpack(programArgs))
- elseif verb == "copy" or verb == "duplicate" then
- print("What should the duplication look like?")
- print("(OOC): filename, please:")
- local fileName = read()
- fs.copy(nounToFile[shell.dir()][target], fs.combine(shell.dir(), fileName))
- elseif verb == "move" or verb == "transmute" then
- print("What should you transmute this to?")
- print("(OOC): filename, please:")
- local fileName = read()
- fs.move(nounToFile[shell.dir()][target], fs.combine(shell.dir(), fileName))
- elseif verb == "exit" then
- shell.setDir("")
- error("Suddenly, the dungeon collapses!")
- elseif verb == "walk" or verb == "run" then
- if target == "back" then
- shell.setDir("/")
- print("You quickly "..verb.." back to where you started.")
- return
- end
- if fs.isDir(nounToFile[shell.dir()][target]) then
- shell.setDir(fs.combine(shell.dir(), nounToFile[shell.dir()][target]))
- print("You walk through the door...")
- else
- print("You walk straight into the "..target..".")
- end
- elseif verb == "examine" or verb == "look" then
- if target == nil then
- print("This room looks familiar.")
- print("You decide to call it: "..fs.getName(shell.dir()))
- else
- print("When you think about it, this looks familiar.")
- print("You decide to call it "..nounToFile[shell.dir()][target]..".")
- end
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Commands:")
- print("slay/destroy/kill: delete")
- print("use: run")
- print("move/transmute: move")
- print("walk/run: change directory")
- print("copy/duplicate: copy")
- print("examine/look: Find an object's filename")
- print("exit: self-explanatory")
- print("of note are the walk/run commands; instead of taking a noun as a parameter, they take a folder name.")
- print("you can also \"run back\", which is the same as \"cd \\\".")
- print("Files are objects; folders are doors.")
- print("A machine is an executable file; anything else (besides a \"door\") is a data (non-executable) file.")
- end
- end
- shell.setDir("/")
- local args = {...}
- local fNames = true
- if args[1] == "--no-file-names" then
- fNames = false
- end
- while true do
- generateRoom(shell.dir(), fNames)
- write("What do you do? >")
- parseCommand(read())
- while true do
- local event, key = os.pullEvent("key")
- if key ~= 1 then
- break
- end
- end
- end
Add Comment
Please, Sign In to add comment