Commit 0f385b13 by Phil Hagelberg

Fix some orb scripts which need new rpcs.

parent 59adfd7f
......@@ -36,9 +36,10 @@ check:
ssh_get_connection rover_operate tetris \
-- $(IN_SHIP_LUA)
luacheck --no-color --std luajit --ignore 21/_.* --exclude-files=*.lsp \
--globals lume orb station buy_user ship cargo_transfer refuel pps \
--globals lume orb station buy_user ship cargo_transfer pps \
accept_mission get_prompt set_prompt buy_upgrade sell_upgrade \
subnet logout upgrade_help port loan \
list_upgrades subnet logout upgrade_help port loan \
cargo_prices cargo_amounts cargo_hold refuel fuel_price \
-- $(IN_OS_LUA)
luacheck --no-color --std luajit --ignore 21/_.* --globals love lume term \
-- $(DATA_LUA)
......
local base_prices = require("data.prices")
local utils = require("utils")
local hostname = function(body_name)
......@@ -104,6 +105,45 @@ return {
end
end,
seed_cargo = function(b)
if(not b.os or b.os ~= "orb") then return end
local equipment_factor = (math.log(b.remote / 2) + 4) *
(3 / (b.industry + b.tech)) + 0.5
b.fuel_price = math.ceil(base_prices.fuel *
(math.log(b.remote / 2) + 1) * (5 / b.industry))
b.account_price = math.floor(base_prices.account *
(math.log(math.max(b.remote, 2) * 0.5) + 1))
b.upgrade_prices = { life_support = 512 } -- everyone sells this
for _,u in ipairs(b.upgrades) do
b.upgrade_prices[u] = math.floor(base_prices.upgrades[u] *
equipment_factor)
end
b.prices = {}
local price_difference = 1.2 -- should be dynamic?
local price = function(good, base)
b.prices[good] = { buy = base, sell = math.ceil(base * price_difference) }
end
price("ore", math.floor(base_prices.ore * (math.log(10 - b.mineral) +1)))
price("food", math.floor(base_prices.food * (math.log(10 - b.agri) +1)))
price("medicine", math.floor(base_prices.medicine *
(math.log(b.pop / 4 + b.remote + 2) + 1)))
price("equipment", math.floor(base_prices.equipment * equipment_factor))
b.cargo = {}
for _,name in ipairs({"ore", "food", "equipment", "medicine"}) do
b.cargo[name] = love.math.random(20)
end
-- print("\n" .. b.name, equipment_factor)
-- for k,v in pairs(b.prices) do print(k,v) end
-- print("fuel", b.fuel_price)
-- print("account", b.account_price)
-- for k,v in pairs(b.upgrade_prices) do print(k,v) end
end,
find = function(bodies,name)
for _,b in pairs(bodies) do if(b.name == name) then return b end end
end,
......
......@@ -94,8 +94,10 @@ return {
ship.api.editor.with_current_buffer("*console*",
disconnect, ship)
elseif(msg.op == "rpc") then
msg.chan:push({rpcs[msg.fn](ship, session.port,
unpack(msg.args or {}))})
local resp = {rpcs[msg.fn](ship, session.port,
unpack(msg.args or {}))}
dbg(">", require("serpent").block(resp))
msg.chan:push(resp)
end
end
end
......
......@@ -2,7 +2,9 @@
local _env, args = ...
if(not station.prices) then
local prices = cargo_prices()
if(not prices) then
print("This station does not sell cargo.")
return
end
......@@ -10,17 +12,17 @@ end
-- TODO: better message when amount is missing
if(args[1] == "list") then
print("Prices: (buy/sell)")
for good, prices in pairs(station.prices) do
print(" " .. good .. ": " .. prices.buy .. "/" .. prices.sell)
for good, price in pairs(prices) do
print(" " .. good .. ": " .. price.buy .. "/" .. price.sell)
end
print("Stock:")
for good, amount in pairs(station.cargo) do
for good, amount in pairs(cargo_amounts()) do
print(" " .. good .. ": " .. amount)
end
print("Your hold:")
for good, amount in pairs(ship.status.cargo) do
for good, amount in pairs(cargo_hold()) do
print(" " .. good .. ": " .. amount)
end
elseif(args[1] == "buy" or args[1] == "sell") then
......
......@@ -10,8 +10,9 @@ else
print("Purchase fuel for your ship.\n")
print("Usage:")
print(" refuel AMOUNT")
if(station.fuel_price) then
print("Fuel here is sold for " .. station.fuel_price)
local price = fuel_price()
if(price) then
print("Fuel here is sold for " .. price)
else
print("This station does not sell fuel.")
end
......
......@@ -4,7 +4,7 @@ local _env, args = ...
if(args[1] == "list" and #args == 1) then
print("Prices:")
for name,price in pairs(station.upgrade_prices or {}) do
for name,price in pairs(list_upgrades()) do
print(" " .. name .. ": " .. price)
end
print("\nRun `upgrade manual NAME` to read the manual for an upgrade before buying.")
......
......@@ -2,5 +2,6 @@
return {
"get_prompt", "set_prompt",
"cargo_transfer", "loan", "fine", "port",
"buy_upgrade", "sell_upgrade", "buy_users", "refuel"
"buy_upgrade", "sell_upgrade", "list_upgrades", "buy_users",
"refuel", "fuel_price", "cargo_prices", "cargo_amounts", "cargo_hold",
}
......@@ -125,6 +125,26 @@ return {
end
end,
list_upgrades = function(_, port)
return port.upgrade_prices or {}
end,
fuel_price = function(_, port)
return port.fuel_price or 0
end,
cargo_prices = function(_, port)
return port.prices
end,
cargo_amounts = function(_, port)
return port.cargo
end,
cargo_hold = function(ship, _)
return ship.cargo
end,
port = function(ship, _, command)
if(command ~= "fine") then
return "Unknown command"
......
......@@ -210,6 +210,7 @@ local ship = {
asteroid.populate(ship.systems[ship.system_name])
for _,b in pairs(ship.bodies) do
body.seed_pos(b, ship.bodies[1])
body.seed_cargo(b)
end
local portal = lume.match(ship.bodies,
......@@ -469,6 +470,10 @@ ship.api = {
persist = {"persist", "scale", "src", "docs"},
persist_buffers = {"*console*"},
reload_file = function(name)
ship.api.src[name] = love.filesystem.read("data/src/" .. name)
end,
-- added by loading config
controls = {},
updaters = {},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment