lots of rewrite

This commit is contained in:
Paul Liverman
2015-05-06 23:13:50 -07:00
parent 013e24e285
commit da9e427512
10 changed files with 916 additions and 189 deletions

View File

@@ -1,11 +1,35 @@
return function(x, y, rotation)
local self = {}
local class = require "lib.middleclass"
local Node = class('Node')
function Node:initialize(x, y, rotation)
self.x = x or 0
self.y = y or 0
self.rotation = rotation or 0
self.docked = false
return self
self.dockedShip = false
end
--TODO docking needs to check distance between ships and only allow
-- docking when close enough
function Node:dock(Ship)
if self.dockedShip or Ship.dockedTo then
error("Attempted to dock to Node with something already docked to it!")
else
self.dockedShip = Ship
Ship.dockedTo = self
Ship:setPosition(self.x, self.y, self.rotation)
end
end
function Node:undock()
if not self.dockedShip then
error("Attempted to undock a ship from a Node with no docked ship.")
else
self.dockedShip.dockedTo = false
self.dockedShip = false
end
end
return Node

50
src/ships/Resources.lua Normal file
View File

@@ -0,0 +1,50 @@
local class = require "lib.middleclass"
local Resources = class('Resources')
function Resources:initialize()
self.ammo = 0
self.fuel = 0
self.supplies = 0
self.water = 0
self.food = 0
self.metal = 0
self.ore = 0
self.crew = 0
self.missiles = 0
self.nukes = 0
self.maxAmmo = 0
self.maxFuel = 0
self.maxSupplies = 0
self.maxWater = 0
self.maxFood = 0
self.maxMetal = 0
self.maxOre = 0
self.maxCrew = 0
self.ammoUse = 0
self.fuelUseIdle = 0
self.fuelUseMoving = 0
self.fuelUseJump = 0
self.suppliesUse = 0
self.waterUse = 0
self.foodUse = 0
self.metalUse = 0
self.oreUse = 0
self.crewUse = 0
end
function Resources:maxEverything()
self.ammo = self.maxAmmo
self.fuel = self.maxFuel
self.supplies = self.maxSupplies
self.water = self.maxWater
self.food = self.maxFood
self.metal = self.maxMetal
self.ore = self.maxOre
self.crew = self.maxCrew
end
return Resources

84
src/ships/Ship.lua Normal file
View File

@@ -0,0 +1,84 @@
local class = require "lib.middleclass"
local Resources = require "ships.Resources"
local Ship = class('Ship')
function Ship:initialize(x, y, rotation)
self.img = ""
--offsets
self.ox = 0
self.oy = 0
self.x = x or 0
self.y = y or 0
self.destination = {
x = x or 0,
y = y or 0
}
self.rotation = rotation or 0
self.selection = {}
self.node = {}
self.dockedTo = false
self.Resources = Resources()
end
function Ship:dock(targetShip, nodeIndex)
if self.node[nodeIndex] then
self.node[nodeIndex]:dock(targetShip)
else
error("Ship attempted to dock to non-existent Node.")
end
end
function Ship:undock(nodeIndex)
if self.node[nodeIndex] then
self.node[nodeIndex]:undock()
else
--find which node "nodeIndex" is docked to
for i=1,#self.node do
if self.node[i].dockedShip == nodeIndex then
self.node[i]:undock()
return
end
end
error("Ship attempted to undock from non-existent Node.")
end
end
function Ship:dockTo(targetShip, nodeIndex)
if targetShip.node[nodeIndex] then
targetShip.node[nodeIndex]:dock(self)
else
error("Ship attempted to dock to non-existent Node.")
end
end
function Ship:undockFromParent()
self.dockedTo:undock(self)
end
function Ship:setPosition(x, y, rotation)
self.x = x or self.x
self.y = y or self.y
self.rotation = rotation or self.rotation
end
function Ship:moveTo(x, y)
if self.dockedTo then
self:undockFromParent()
end
self.destination.x = x
self.destination.y = y
end
function Ship:update(dt)
--check our speed, see how far along the "line" we can go, go there
-- if reached destination ... WELL SHIT DEST NEEDS TO BE ABLE TO KNOW IF IS SHIP OR WHATEVER
end
return Ship

View File

@@ -1,18 +1,21 @@
local Node = require "ships.Node"
math.randomseed(os.time())
math.random() math.random()
local class = require "lib.middleclass"
local Ship = require "ships.Ship"
local Node = require "ships.Node"
local ninety = 90 * math.pi / 180
return function(x, y, rotation)
local self = {}
local BSG = class('BSG', Ship)
function BSG:initialize(x, y, rotation)
Ship.initialize(self, x, y, rotation)
self.img = "bsg"
--offsets
self.ox = 31.5
self.oy = 67
self.x = x or 0
self.y = y or 0
self.rotation = rotation or 0
--[[
self.selection = {
w = 54,
@@ -34,33 +37,50 @@ return function(x, y, rotation)
Node(-23, 16.5, -ninety)
}
self.dock = function(self, ship, node)
if self.node[node].docked or ship.isDocked then return false end
self.Resources.maxAmmo = 1000000
self.Resources.maxFuel = 1300000
self.Resources.maxSupplies = 40000
--what the fuck are jp's ?
-- http://www.traditionaloven.com/culinary-arts/cooking/shortening/convert-japanese-cup-measure-of-shortening-to-fluid-ounce-floz-shortening.html
-- From show "10 mil JPs water lost, almost 60%"
self.Resources.maxWater = 16000000
self.Resources.maxFood = 51000
self.Resources.maxMetal = 80000
--self.Resources.maxOre = 0
self.Resources.maxCrew = 5100
ship.x = self.node[node].x
ship.y = self.node[node].y
ship.rotation = self.node[node].rotation
self.Resources.ammo = math.random(100, 1300)
self.Resources.fuel = math.random(496000, 512000)
self.Resources.supplies = math.random(18000,21000)
self.Resources.water = math.random(14186500, 14989900)
self.Resources.food = math.random(34700, 39200)
self.Resources.metal = math.random(19200,21600)
--self.Resources.ore = 0
self.Resources.crew = math.random(2870, 2960)
self.node[node].docked = ship
ship.isDocked = true
ship.dockedTo = self
ship.dockedNode = node
return true
end
self.Resources.missiles = math.random(5, 11)
--self.Resources.nukes = 0
self.undock = function(self, node)
if not self.node[node].docked then return false end
local ship = self.node[node].docked
ship.isDocked = false
ship.dockedTo = false
ship.dockedNode = false
self.node[node].docked = false
return ship
end
self.moveTo = function() end
return self
--self.Resources.ammoUse = 0
-- a year is 31,556,900 seconds
-- for 17 mil water to last ?
-- How about 1 water per second?
-- 195 days
self.Resources.fuelUseIdle = 0.04
self.Resources.fuelUseMoving = 0.54
self.Resources.fuelUseJump = 4000
self.Resources.suppliesUse = 0.0013
self.Resources.waterUse = 1
-- 45k civs = 82+85+119+304 (590) tons food
-- 2.5 mil JPs water
-- these are per week numbers
-- 604800 seconds, 4.13 water per second
-- 1 ton = 2000 pounds
-- 1180000 pounds / sec = 1.95 food per second
self.Resources.foodUse = 0.099
--self.Resources.metalUse = 0.002 -- this # assumes normal repairs, which I'm ignoring for this
--self.Resources.oreUse = 0
--self.Resources.crewUse = 0
end
return BSG

View File

@@ -1,20 +1,16 @@
return function(x, y, rotation)
local self = {}
local class = require "lib.middleclass"
local Ship = require "ships.Ship"
local Viper = class('Viper', Ship)
function Viper:initialize(x, y, rotation)
Ship.initialize(self, x, y, rotation)
self.img = "viper"
--offsets
self.ox = 4.5
self.oy = 7.5
self.x = x or 0
self.y = y or 0
self.rotation = rotation or 0
self.destination = {
x = x or 0,
y = y or 0
}
self.isMoving = false
--[[
self.selection = {
w = 9,
@@ -25,24 +21,15 @@ return function(x, y, rotation)
r = 5
}
--self.node = false
self.isDocked = false
self.dockedTo = false
self.dockedNode = false
self.Resources.maxAmmo = 1800 --10 shots per second? 5s per barrel
self.Resources.maxFuel = 30000 --86400s = 1day, x = 1/2 day's thrust
self.Resources.maxCrew = 1
self.moveTo = function(self, x, y)
if self.isDocked then
self.dockedTo:undock(self.dockedNode)
end
self.destination.x = x
self.destination.y = y
self.isMoving = true
end
self.Resources.ammo = math.random(0, 20)
self.Resources.fuel = math.random(120, 1500)
self.update = function(self, dt)
-- check if moving, check our speed, see how far along the "line" we can go, go there
-- if reached destination ... WELL SHIT DEST NEEDS TO BE ABLE TO KNOW IF IS SHIP OR WHATEVER
end
return self
self.Resources.fuelUseIdle = 0.09
self.Resources.fuelUseMoving = 0.76
end
return Viper