commit 8d9991fb2ed9be8d4868998f9763735387a3e4bc Author: Paul Liverman III Date: Thu Mar 7 13:29:13 2019 -0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d907c43 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.lua diff --git a/images b/images new file mode 100644 index 0000000..40a8f8a --- /dev/null +++ b/images @@ -0,0 +1,23 @@ + abstract-029 -> fuel cell! +USED abstract-045 -> filterpump? + abstract-050 -> vent (for filters/pumps)! + abstract-072 -> thruster! + airtight-hatch -> closed airlock! + airtight-hatch-1 -> open airlock! + ammo-box -> ammo? +USED chemical-tank -> tanks! + circuitry -> computer + convergence-target -> ? + cryo-chamber -> clone bay! + energy-tank -> ? + expanded-rays -> antimatter reactor! + hospital-cross -> medical cabinet? + metal-scales -> ? + paper-tray -> ? +USED person -> you! +USED plain-square -> flooring / internal space! + power-generator -> fabricator! + targeted -> ? + tinker -> repair needed icon ? + triangle-target -> ? + wooden-crate -> cargo space? (or actual cargo?) diff --git a/life-support b/life-support new file mode 100644 index 0000000..998f65f --- /dev/null +++ b/life-support @@ -0,0 +1,60 @@ +21% normal +5% consumption +volume of breath? 6 litres +16 breaths per minute +our units are approximately 1/5 a litre + +6 * 1/5 * 16 / 60 * 0.05 = oxygen per second rate = 0.016 + +co2 +> 0.0008 is unhealthy +> 0.005 is very unhealthy +> 0.05 is dangerous to animal life (becomes uncomfortable as well) +> 0.084 for 60 minutes = death +> 0.1 is immediately dangerous + +o2 below 19.5% is considered dangerous +0.47 pressure at 21% is lowest pressure +- 5 to 8 psi for 100% is tolerable (1 psi = 0.068046 atm) + (should be roughly 0.12 atm (minimum at 100%)) +2.5 atm at 21% should be a safe maximum, short periods in excess of 70 atm are tolerable + +Min Pressure: 0.12 atm with pure oxygen +Max Pressure with pure oxygen: 0.5 atm +Min Pressure w 19.5-21%: 0.47 atm +Max Pressure with 19.5-21%: 2.5 atm +- draw a box, current point has to be in the box? NO +if oxygen < 0.195 -> dying +if pressure < 0.12 -> dying +if pressure < 0.47 + if oxygen < -2.3(pressure) + 1.276 -> dying +if pressure > 0.5 + if oxygen > -.054(pressure) + 0.33 -> oxy toxicity +if pressure > 2.5 -> oxy toxicity + +min pressures: 0.12 and 0.47 +max pressures: 0.5 and 2.5 +min percents: 1 and 1 +max percents + + +feces + 3-8oz per day -> * 0.0295735 / 5 = volume units + = 0.03253085 / 24 / 60 / 60 = 3.7651446759259e-07 per second + 75% water, 25% solid (below list) +0.3 -> bacteria +0.3 -> cellulose (can be burned -> co2 h2o) +0.1-0.2 -> fats +0.1-0.2 -> phosphates (iron/calcium) +0.02-0.03 -> proteins + +(one urination ~ 0.35 / 5 volume) + per day => 0.8 to 2 litres + per second = 3.2407407407407e-06 +urine +~0.04 urea (ammonia/co2) +~0.01 salt, potassium +0.95 water + +0.4 litres of water expelled in breath per day +per second: 0.4 / 5 / 24 / 60 / 60 = 9.2592592592593e-07 diff --git a/notes b/notes new file mode 100644 index 0000000..3e90157 --- /dev/null +++ b/notes @@ -0,0 +1,34 @@ +Survival in ship, console / UI is only interface, must repair broken systems. +Walk around to repair various panels. +Randomly generated ship layout? + +What systems are needed? Toilet, bed, medical cabinet, thrusters, warp drive, + reactor, battery, fuel / fluid storage, airlock, computer, sensors, weapons?, + cargo area, grappling hook / docking system, piping and wiring of course, + filters, pumps, atmospheric sensors, lights, toolbox, locker + +How about a starbase instead? Starting with just a small number of components, +and events come to you. +- Could still implement travel, just through warp drive only. You have station- + keeping thrusters to maintain, but no main engines. +- If you lose thrusters, your orbit starts slowly decaying (you can still just + warp to a higher orbit of course) +- Start to fall into atmosphere? Can scoop from upper atmospheres, but starts to + decay faster. +- Send out mining drones. +- 3D Printing tech? For manufacture? fluid plastic + +Each tile needs to reference a Fluid (atmosphere). Volumes of atmosphere Fluids +are equal to 10 per tile. Volumes of single tanks are 8 per. +Doubles: 4 Triples: 3 + +Start: +- basic life support: bed, toilet, kitchen, atmospheric sensor, filter, pump, + tankage (o2, co2, n2) + (maybe I should use the scuba tanks icon for multiple tanks in one spot?) +- one thruster, uses n2 +- battery, solar panels? (start in orbit close enough to a star?) +- warp drive, barely capable of warping your station +- docking arm / airlock (airlock at end of pylon) +- computer, basic sensors?, filters/pumps?, lights? +- locker w toolbox (locker is our cargo space to start) diff --git a/src/Breach.moon b/src/Breach.moon new file mode 100644 index 0000000..6738564 --- /dev/null +++ b/src/Breach.moon @@ -0,0 +1,24 @@ +class Breach + new: (@high, @low, @volume=1) => + update: (dt) => + a, b = @high\pressure!, @low\pressure! + if b > a + tmp = @high + @high = @low + @low = tmp + tmp = a + a = b + b = tmp + elseif a > b + @active = true + else + @active = false + + -- print "High: #{a}", "Low: #{b}", "Active? #{@active}" + if @active + sum = (a - b) * @volume * dt + for type in pairs @high.contents + tmp = sum * @high\percent type + -- print "Moving #{tmp} #{type}.." + @high\remove type, tmp + @low\add type, tmp diff --git a/src/Filter.moon b/src/Filter.moon new file mode 100644 index 0000000..37c964d --- /dev/null +++ b/src/Filter.moon @@ -0,0 +1,22 @@ +class Filter + new: (@high, @low, @allows={}, @volume=1) => + update: (dt) => + a, b = @high\pressure!, @low\pressure! + if b > a + tmp = @high + @high = @low + @low = tmp + tmp = a + a = b + b = tmp + elseif a > b + @active = true + else + @active = false + + if @active + sum = (a - b) * @volume * dt + for type in pairs @allows + tmp = sum * @high\percent type + @high\remove type, tmp + @low\add type, tmp diff --git a/src/FilterPump.moon b/src/FilterPump.moon new file mode 100644 index 0000000..cfd7ca7 --- /dev/null +++ b/src/FilterPump.moon @@ -0,0 +1,15 @@ +import abs, min from math + +class FilterPump + new: (@source, @destination, @allows={}, @volume=1, @rate=0) => + reverse: => + tmp = @source + @source = @destination + @destination = tmp + update: (dt) => + if @rate > 0 + sum = abs(@source\pressure! - @destination\pressure!) * @rate * @volume * dt + for type, amount in pairs @allows + tmp = sum * @source\percent type + @source\remove type, tmp + @destination\add type, tmp diff --git a/src/Fluid.moon b/src/Fluid.moon new file mode 100644 index 0000000..e8a0c1d --- /dev/null +++ b/src/Fluid.moon @@ -0,0 +1,19 @@ +class Fluid + new: (@volume=1) => + @contents = {} + @sum = 0 + add: (type, amount) => + @contents[type] = 0 unless @contents[type] + @contents[type] += amount + @sum += amount + remove: (type, amount) => + @contents[type] = 0 unless @contents[type] + @contents[type] -= amount + @sum -= amount + pressure: => + return @sum / @volume + percent: (type) => + return 0 unless @contents[type] + return @contents[type] / @sum + amount: => + return @contents[type] or 0 diff --git a/src/Player.moon b/src/Player.moon new file mode 100644 index 0000000..ea7cb05 --- /dev/null +++ b/src/Player.moon @@ -0,0 +1,101 @@ +import max, min from math + +o2_consumption = 0.016 +h2o_production = 9.2592592592593e-07 +co2_production = 0.016 +feces_production = 3.7651446759259e-07 -- want at 0.032, involuntary at 0.06 +urine_production = 3.2407407407407e-06 -- want to urinate at 0.09, involuntary at 0.11 + +class Player + new: (@structure, @x=0, @y=0) => + @state = { + "oxygen starvation": 0 + "oxygen toxicity": 0 + "nitrogen narcosis": 0 + "helium narcosis": 0 + "carbon dioxide poisoning": 0 + } + @feces = 0 + @urine = 0 + @actionTimer = 0 + if row = @structure[@x] + if tile = row[@y] + @atmosphere = tile.atmosphere + + update: (dt, input) => + if not @atmosphere + @state["oxygen starvation"] += dt + else + pressure = @atmosphere\pressure! + o2 = @atmosphere\percent "O2" + if o2 < 0.195 + @state["oxygen starvation"] += dt + else + @state["oxygen starvation"] = max 0, @state["oxygen starvation"] - dt / 2 + @state["oxygen starvation"] += dt if pressure < 0.12 + @state["oxygen starvation"] += dt if pressure < 0.47 and o2 < -2.3 * pressure + 1.276 + if pressure > 2.5 or (pressure > 0.5 and o2 > -0.054 * pressure + 0.33) + @state["oxygen toxicity"] += dt + if o2 > 0.195 + @state["oxygen starvation"] = max 0, @state["oxygen starvation"] - dt * 3 + else + @state["oxygen toxicity"] = max 0, @state["oxygen toxicity"] - dt * 2 + + if pressure > 50 + n2 = @atmosphere\percent "N2" + he = @atmosphere\percent "He" + @state["nitrogen narcosis"] += dt if n2 > 0.5 + @state["helium narcosis"] += dt if pressure > 500 and he > 0.5 and n2 < 0.25 + else + @state["nitrogen narcosis"] = max 0, @state["nitrogen narcosis"] - dt * 4 + @state["helium narcosis"] = max 0, @state["helium narcosis"] - dt * 8 + + co2 = @atmosphere\percent "CO2" + if co2 > 0.005 + @state["carbon dioxide poisoning"] += dt * (220 * co2 - 0.1) + elseif co2 < 0.005 + @state["carbon dioxide poisoning"] = max 0, @state["carbon dioxide poisoning"] - dt + + -- using min garuntees we will not cause a negative oxygen + -- it is assumed co2/h20 output will be stable until death when there is + -- not enough oxygen + @atmosphere\remove "O2", min o2, o2_consumption * dt + @atmosphere\add "CO2", co2_production * dt + @atmosphere\add "H2O", h2o_production * dt + + if @state["oxygen starvation"] >= 2.5 * 60 or + @state["oxygen toxicity"] >= 60 * 60 or + @state["carbon dioxide poisoning"] >= 60 * 60 + print "Dead." + + @actionTimer -= dt + if @actionTimer <= 0 + x, y = input\get "move" + if x != 0 or y != 0 + if x < 0 + x = -1 + elseif x > 0 + x = 1 + if y < 0 + y = -1 + elseif y > 0 + y = 1 + if @getTile! -- if inside + if tile = @getTile x, y + if tile.obj + nil -- TODO access the object (or go through airlock) + else + @actionTimer = 1/6 + @x += x + @y += y + @atmosphere = tile.atmosphere -- assumes atmosphere might be different, but that only happens when passing through an airlock + else -- outside + if tile = @getTile x, y + if tile.obj + nil -- TODO access (or go through airlock) + else + nil -- TODO move + + getTile: (x=0, y=0) => + if row = @structure[@x + x] + return row[@y + y] diff --git a/src/Pump.moon b/src/Pump.moon new file mode 100644 index 0000000..2dc998f --- /dev/null +++ b/src/Pump.moon @@ -0,0 +1,15 @@ +import abs, min from math + +class Pump + new: (@source, @destination, @volume=1, @rate=0) => + reverse: => + tmp = @source + @source = @destination + @destination = tmp + update: (dt) => + if @rate > 0 + sum = abs(@source\pressure! - @destination\pressure!) * @rate * @volume * dt + for type, amount in pairs @source.contents + tmp = sum * @source\percent type + @source\remove type, tmp + @destination\add type, tmp diff --git a/src/Structure.moon b/src/Structure.moon new file mode 100644 index 0000000..8d84209 --- /dev/null +++ b/src/Structure.moon @@ -0,0 +1,66 @@ +import graphics from love + +width, height = graphics.getDimensions! +x_center, y_center = width / 2, height / 2 +x_offset, y_offset = math.floor(width / 4), math.floor(height / 4) + +images = require "images" +colors = require "colors" +Fluid = require "Fluid" +fluids = require "fluids" + +class Structure + new: (tiles_or_size=2) => + @systems = {} + if "table" == type tiles_or_size + for x, row in pairs tiles_or_size + @[x] = {} + for y, tile in pairs row + @[x][y] = tile + if tile.systems + for system in *tile.systems + table.insert @systems, tile.systems + else + volume = 10 * (2 * tiles_or_size + 1) ^ 2 + air = Fluid(volume) + for type, percent in pairs fluids.air + air\add type, volume * percent + for x = -tiles_or_size, tiles_or_size + @[x] = {} + for y = -tiles_or_size, tiles_or_size + @[x][y] = { img: "plain-square.png", color: colors.floor, atmosphere: air } + + -- temporary + system = require("FilterPump")(@[0][0].atmosphere, Fluid(math.huge), { CO2: true }, 8, 1) + @[0][1] = { + img: "plain-square.png" + obj: "abstract-045.png", color: colors.dark + systems: { system } + atmosphere: @[0][0].atmosphere + } + @systems[1] = system + tank = Fluid(8) + tank\add "O2", 100 + tanksys = require("Pump")(tank, @[0][0].atmosphere, 1, 0.0015) + @[1][0] = { + img: "plain-square.png" + obj: "chemical-tank.png", color: colors.blue + systems: { tanksys } + atmosphere: @[0][0].atmosphere + } + @systems[2] = tanksys + + update: (dt) => + for system in *@systems + system\update dt + + draw: (location) => + for x = location.x - x_offset, location.y + x_offset + if row = @[x] + for y = location.y - y_offset, location.y + y_offset + if tile = row[y] + graphics.setColor colors.floor + graphics.draw images[tile.img], (x - location.x) * 32 + x_center, (y - location.y) * 32 + y_center, 0, 1/16, 1/16, 256, 256 + if tile.obj + graphics.setColor tile.color or 1, 1, 1, 1 + graphics.draw images[tile.obj], (x - location.x) * 32 + x_center, (y - location.y) * 32 + y_center, 0, 1/16 * 0.9, 1/16 * 0.9, 256, 256 diff --git a/src/Valve.moon b/src/Valve.moon new file mode 100644 index 0000000..75666c8 --- /dev/null +++ b/src/Valve.moon @@ -0,0 +1,24 @@ +import min from math + +class Valve + new: (@high, @low, @volume=1, @rate=0) => + update: (dt) => + a, b = @high\pressure!, @low\pressure! + if b > a + tmp = @high + @high = @low + @low = tmp + tmp = a + a = b + b = tmp + elseif a > b + @active = true + else + @active = false + + if @active + sum = (a - b) * min(@rate, @volume) * dt + for type in pairs @high.contents + tmp = sum * @high\percent type + @high\remove type, tmp + @low\add type, tmp diff --git a/src/colors.moon b/src/colors.moon new file mode 100644 index 0000000..4af54a0 --- /dev/null +++ b/src/colors.moon @@ -0,0 +1,7 @@ +{ + default: { 1, 1, 1, 1 } + floor: { 2/3, 2/3, 2/3, 1 } + dark: { 1/3, 1/3, 1/3, 1 } + blue: { 0, 0, 1/3, 1 } + player: { 0, 0, 1, 1 } +} diff --git a/src/ecs.moon b/src/ecs.moon new file mode 100644 index 0000000..b9a0f22 --- /dev/null +++ b/src/ecs.moon @@ -0,0 +1,3 @@ +Systems: Valve, Pump, Filter, Player +Components: volume, area, controls, sum, floor, rate, filter +Entities: tile, player diff --git a/src/fluids.moon b/src/fluids.moon new file mode 100644 index 0000000..83ff475 --- /dev/null +++ b/src/fluids.moon @@ -0,0 +1,18 @@ +{ + earth: { A: 0.0069, H2O: 0.0039, CO2: 0.0004, Ne: 0.000015, N2: 0.779885, O2: 0.2089 } + air: { N2: 0.78, O2: 0.22 } + feces: { + H2O: 0.75, organics: 0.25 * 0.335, C6H10O5: 0.25 * 0.335 + phosphates: 0.25 * 0.152, fats: 0.25 * 0.152, proteins: 0.25 * 0.026 + } + urine: { H2O: 0.95, urea: 0.04, salts: 0.01 } -- sodium/potassium salts + organics: { + C: 0.504, O2: 0.202, N2: 0.141, H2: 0.081, P: 0.03, S: 0.01, K: 0.01, Mg: 0.005 + Ca: 0.005, Fe: 0.002, Mn: 0.001, Co: 0.001, Zn: 0.001, Cu: 0.001, Mo: 0.001 + } + -- phosphates: { iron: 0.33, calcium: 0.33, phosphor: 0.34 } + -- FePO4 & Ca3(PO4)2 +} + +-- C6 H10 O5 + 6x 02 -> 6x C 02 + 5x H2 0 +-- 6 oxygen + 1 cellulose -> 6 carbon dioxide + 5 water diff --git a/src/images.moon b/src/images.moon new file mode 100644 index 0000000..420e1f3 --- /dev/null +++ b/src/images.moon @@ -0,0 +1,4 @@ +images = {} +for img in *love.filesystem.getDirectoryItems "img" + images[img] = love.graphics.newImage "img/#{img}" +images diff --git a/src/img/abstract-029.png b/src/img/abstract-029.png new file mode 100644 index 0000000..5c95534 Binary files /dev/null and b/src/img/abstract-029.png differ diff --git a/src/img/abstract-045.png b/src/img/abstract-045.png new file mode 100644 index 0000000..2b2bb74 Binary files /dev/null and b/src/img/abstract-045.png differ diff --git a/src/img/abstract-050.png b/src/img/abstract-050.png new file mode 100644 index 0000000..fb929c5 Binary files /dev/null and b/src/img/abstract-050.png differ diff --git a/src/img/abstract-072.png b/src/img/abstract-072.png new file mode 100644 index 0000000..c3b7384 Binary files /dev/null and b/src/img/abstract-072.png differ diff --git a/src/img/airtight-hatch-1.png b/src/img/airtight-hatch-1.png new file mode 100644 index 0000000..e4060e8 Binary files /dev/null and b/src/img/airtight-hatch-1.png differ diff --git a/src/img/airtight-hatch.png b/src/img/airtight-hatch.png new file mode 100644 index 0000000..2587958 Binary files /dev/null and b/src/img/airtight-hatch.png differ diff --git a/src/img/ammo-box.png b/src/img/ammo-box.png new file mode 100644 index 0000000..5032af2 Binary files /dev/null and b/src/img/ammo-box.png differ diff --git a/src/img/chemical-tank.png b/src/img/chemical-tank.png new file mode 100644 index 0000000..573718c Binary files /dev/null and b/src/img/chemical-tank.png differ diff --git a/src/img/circuitry.png b/src/img/circuitry.png new file mode 100644 index 0000000..5b44ca0 Binary files /dev/null and b/src/img/circuitry.png differ diff --git a/src/img/convergence-target.png b/src/img/convergence-target.png new file mode 100644 index 0000000..c5bedc8 Binary files /dev/null and b/src/img/convergence-target.png differ diff --git a/src/img/cryo-chamber.png b/src/img/cryo-chamber.png new file mode 100644 index 0000000..1f3322f Binary files /dev/null and b/src/img/cryo-chamber.png differ diff --git a/src/img/energy-tank.png b/src/img/energy-tank.png new file mode 100644 index 0000000..3ad9120 Binary files /dev/null and b/src/img/energy-tank.png differ diff --git a/src/img/expanded-rays.png b/src/img/expanded-rays.png new file mode 100644 index 0000000..7caa484 Binary files /dev/null and b/src/img/expanded-rays.png differ diff --git a/src/img/hospital-cross.png b/src/img/hospital-cross.png new file mode 100644 index 0000000..30a3e30 Binary files /dev/null and b/src/img/hospital-cross.png differ diff --git a/src/img/metal-scales.png b/src/img/metal-scales.png new file mode 100644 index 0000000..857ad28 Binary files /dev/null and b/src/img/metal-scales.png differ diff --git a/src/img/paper-tray.png b/src/img/paper-tray.png new file mode 100644 index 0000000..c203bcd Binary files /dev/null and b/src/img/paper-tray.png differ diff --git a/src/img/person.png b/src/img/person.png new file mode 100644 index 0000000..4a31ac4 Binary files /dev/null and b/src/img/person.png differ diff --git a/src/img/plain-square.png b/src/img/plain-square.png new file mode 100644 index 0000000..f29e19e Binary files /dev/null and b/src/img/plain-square.png differ diff --git a/src/img/power-generator.png b/src/img/power-generator.png new file mode 100644 index 0000000..bdbbd6f Binary files /dev/null and b/src/img/power-generator.png differ diff --git a/src/img/targeted.png b/src/img/targeted.png new file mode 100644 index 0000000..1911cbb Binary files /dev/null and b/src/img/targeted.png differ diff --git a/src/img/tinker.png b/src/img/tinker.png new file mode 100644 index 0000000..796b24c Binary files /dev/null and b/src/img/tinker.png differ diff --git a/src/img/triangle-target.png b/src/img/triangle-target.png new file mode 100644 index 0000000..5ea6b35 Binary files /dev/null and b/src/img/triangle-target.png differ diff --git a/src/img/wooden-crate.png b/src/img/wooden-crate.png new file mode 100644 index 0000000..ee4c68e Binary files /dev/null and b/src/img/wooden-crate.png differ diff --git a/src/main.moon b/src/main.moon new file mode 100644 index 0000000..2af3c44 --- /dev/null +++ b/src/main.moon @@ -0,0 +1,87 @@ +lurker = require "lurker" +lurker.quiet = true +debug = true + +baton = require "baton" +input = baton.new { + controls: + left: { 'key:left', 'key:a', 'axis:leftx-', 'button:dpleft' } + right: { 'key:right', 'key:d', 'axis:leftx+', 'button:dpright' } + up: { 'key:up', 'key:w', 'axis:lefty-', 'button:dpup' } + down: { 'key:down', 'key:s', 'axis:lefty+', 'button:dpdown' } + -- action: { 'key:x', 'button:a' } + exit: { 'key:escape' } + pairs: + move: { 'left', 'right', 'up', 'down' } + joystick: love.joystick.getJoysticks![1] +} + +images = require "images" +colors = require "colors" + +-- floor = { img: "plain-square.png", color: colors.floor } + +Structure = require "Structure" +structure = Structure(3) +Player = require "Player" +player = Player(structure) + +love.update = (dt) -> + -- dt *= 100 + require("lovebird").update! + lurker.update! + + input\update! + love.event.quit! if input\pressed "exit" + + player\update(dt, input) + structure\update dt + + if debug + if row = structure[player.x] + if tile = row[player.y] + atmosphere = tile.atmosphere + if love.keyboard.isDown("c") + atmosphere\add "CO2", 1 + if love.keyboard.isDown("n") + atmosphere\add "N2", 10 + if love.keyboard.isDown("o") + atmosphere\add "O2", 1 + if love.keyboard.isDown("h") + atmosphere\add "He", 10 + + -- structure[player.x] = {} unless structure[player.x] + -- structure[player.x][player.y] = { img: "plain-square.png", color: colors.floor } unless structure[player.x][player.y] + +width, height = love.graphics.getDimensions! +love.draw = -> + if debug + -- love.graphics.setColor 1, 1, 1, 1/4 + -- love.graphics.line width / 2, 0, width / 2 , height + -- love.graphics.line 0, height / 2, width, height / 2 + love.graphics.setColor 1, 1/3, 1/3, 1 + love.graphics.line -player.x * 32 + width / 2, 0, -player.x * 32 + width / 2, height + love.graphics.line 0, -player.y * 32 + height / 2, width, -player.y * 32 + height / 2 + + structure\draw player + + love.graphics.setColor colors.player + love.graphics.draw images["person.png"], width / 2, height / 2, 0, 1/16 * 0.9, 1/16 * 0.9, 256, 256 + + if debug + if row = structure[player.x] + if tile = row[player.y] + if atmosphere = tile.atmosphere + love.graphics.setColor 1, 1, 1, 1 + love.graphics.print "Pressure: #{math.floor(10 * atmosphere\pressure!) / 10} atm (#{math.floor(10 * atmosphere.sum) / 10})", 0, 0 + i = 1 + for type, amount in pairs atmosphere.contents + love.graphics.print "#{type}: #{math.floor(1000 * atmosphere\percent type) / 10}% (#{math.floor(100 * amount) / 100})", 0, i * 15 + i += 1 + + i = 0 + love.graphics.setColor 1, 1, 1, 1 + for state, value in pairs player.state + if value > 0 + love.graphics.print "Warning: #{state} (#{math.floor value})", width / 2, i * 15 + i += 1 diff --git a/src/station.moon b/src/station.moon new file mode 100644 index 0000000..b3833c8 --- /dev/null +++ b/src/station.moon @@ -0,0 +1,246 @@ +station = { + player: { x: 0, y: 2 } + { + x: -2, y: -2 + "airlock" + -- connections: { "atmosphere", "vacuum" } + } + { + x: -1, y: -2 + "tank" + connections: { "fabricator" } + } + { + x: 0, y: -2 + "fabricator" + } + { + x: 1, y: -2 + "tank" + } + { + x: 2, y: -2 + "thruster" + } + { + x: -1, y: 0 + "warp drive" + } + { + x: 0, y: 0 + "battery" + } + { + x: 1, y: 0 + "computer" + } + { + x: -1, y: 1 + "tank", "H2", 12.5 + } + { + x: 0, y: 1 + "fuel cell", "H2O", 0.1 + } + { + x: 1, y: 1 + "tank", "O2", 12.5 + } + { + x: 2, y: 0 + "locker" + } + { + x: 2, y: 1 + "bed" + } + { + x: -2, y: 3 + "thruster" + } + { + x: 0, y: 3 + "toilet" + } + { + x: 1, y: 3 + "tank", "organic waste", 0.01 + } + { + x: 2, y: 3 + "water reclamation unit" + } + { + x: -3, y: 0 + "tank", "H20", 0.1 + } + { + x: -3, y: 1 + "tank", "H20", 0.1 + } + { + x: 3, y: 0 + "tank", "N2", 12 + } + { + x: 3, y: 1 + "tank", "N2", 12 + } + { + x: 0, y: -5 + "solar panel" + } + { + x: 0, y: -4 + "solar panel" + } + { + x: 0, y: -3 + "solar panel" + } + { + x: 0, y: 4 + "solar panel" + } + { + x: 0, y: 5 + "solar panel" + } + { + x: 0, y: 6 + "solar panel" + } + -- systems: { + -- { "airlock", "atmosphere" } + -- { "tank:H2", "fuel cell" } + -- { "tank:O2", "fuel cell" } + -- { "thruster", "tank:N2" } + -- } +} + + + + +Fluid = require "Fluid" +fluids = require "fluids" + +vaccum = Fluid(math.huge) +station = { + atmosphere: Fluid() -- volume is corrected by Structure() + systems: { + -- "exterior hatch": Valve() + "airlock": Fluid(10)\fill fluids.air -- TODO write it, needs to return self + "oxygen tank": Fluid(8)\fill "O2", 12.5 + "hydrogen tank": Fluid(8)\fill "H2", 12.5 + "water tank": Fluid(12)\fill "H2O", 1/2 + "water tank 2": Fluid(12)\fill "H2O", 1/2 + "nitrogen tank": Fluid(12)\fill "N2", 10 + "nitrogen tank 2": Fluid(12)\fill "N2", 10 + "waste tank": Fluid(8)\fill "organic waste", 0.01 + "fuel cell": Fluid(5)\fill "H2O", 0.1 + -- "thruster": Thruster("nitrogen tank") + Valve("nitrogen tank", "nitrogen tank 2") + } +} + + + + + + +-- 12.5 atm pressure in oxy tanks + +fluids = require "fluids" + +station = { + atmosphere: Fluid() -- volume to be reassigned later +} + +vaccum_source = Fluid(math.huge) +n2_source = Fluid(12)\fill "N2", 12.5 -- TODO make fill function! + +station[3] = { + [0]: { + img: "chemical-tank.png" + systems: { n2_source } + } + [1]: -> + tank = Fluid(12)\fill "N2", 12.5 + return { + img: "chemical-tank.png" + systems: { tank, Valve(tank, n2_source, 1, 1) } + } +} + +station[-2] = { + [-2]: -> + airlock = Fluid(10)\fill fluids.air -- TODO make fill function, make it return self + exterior = Valve(airlock, vaccum_source, 7.5, 0)\set "name", "exterior hatch" -- TODO make set function + interior = Valve(airlock, station.atmosphere, 8, 0)\set "name", "interior hatch" + return { + img: "airtight-hatch.png" + systems: { airlock, exterior, interior } + } + [3]: -> + thruster = Thruster() + return { + img: "abstract-072.png" + systems: { thruster, Valve(n2_source, thruster, 1, 0)\set "name", "thruster" } + } +} + + + + + +Volume(8)\add "O2", 100 + + + +station = {} +for x = -2, 2 + station[x] = {} + for y = -2, 3 + station[x][y] = { + hull: true -- show floor + } + +airlock = station[-2][-2] +fab_tank = station[-1][-2] +fab = station[0][-2] +fab_tank2 = station[1][-2] +thruster = station[2][-2] + +-- idea, create objects with x/y values, insert them later + +airlock = { + hatch: true +} + +import insert from table +import Volume from require "fluids" + +Tank = (t) -> + if fucked + nil + +o2 = {internal} + +internal = 8 +external = 12 +full = 100 +half = 50 + +o2 = Tank internal, full + +-- systems = { +-- O2: Volume(8)\add "O2", 100 +-- H2: Volume(8)\add "H2", 100 +-- N2: Volume(12)\add "N2", 150 +-- -- N2_2: Volume(12)\add "N2", 150 +-- H2O: Volume(12)\add "H2O", 50 +-- -- H2O_2: Volume(12)\add "H2O", 50 +-- } + +systems = {} +insert Volume(8)\add "O2", 100 diff --git a/systems b/systems new file mode 100644 index 0000000..092dab3 --- /dev/null +++ b/systems @@ -0,0 +1,12 @@ +Systems +- Movement, done. +- Fluid physics, done. +- Fluid handling. + - Filters to allow transferring only one type of fluid at a time, done. + - Pumps to allow transferring from low pressure to high pressure, done. +- Needs (sleep, food, air, water, waste disposal). + - Sleep timer refreshed by skipping some time. Events can interrupt sleep. + Will pass out and not be awoken for a while if you let it get too low. + - Food & Water. (Consumable items.) + - Air. Regularly removing oxygen and adding co2 and h20. + - Waste. Liquid (urea(co2&ammonia)&h2o) and Solid ('organic waste'?) diff --git a/tmp/Fluid.moon b/tmp/Fluid.moon new file mode 100644 index 0000000..ce86e6b --- /dev/null +++ b/tmp/Fluid.moon @@ -0,0 +1,24 @@ +-- what kind of usage do I want? + +tank = Container(volume):add("O2", 400) +o2_control = Valve(tank, atmosphere, 0) -- rate/area/whatever +-- remember, Containers don't need to be updated, everything else does + +fluid = require "fluid" +ls_tank = fluid.Container(volume):add("O2") +fluid.Mix(ls_tank, fluid.vaccum, 0.001) + + + + + + + +a = Container(volume):add('co2', 300):add('o2', 100) +Mix(a, Container.vaccum, 0.01) -- rate/volume/area specified (your choice of meaning lol) +Pump(a, b, 1) --rate/volume/area, your choice +Filter(a, b, 0.1) -- rate/volume/area, whatever + +Mix(a, b, rate, filter) +-- with optional filter / rate (if rate is zero, disabled, if rate is anything +-- else, affects pressure dynamic (like, does it work against pressure?))