forked from daid/EmptyEpsilon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scenario wormhole: add plots and terrain
- Loading branch information
Showing
6 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--[[ Spawns and manages the Fleet Command station | ||
-- Upgrades allow to repair ships | ||
--]] | ||
wh_fleetcommand = {} | ||
|
||
require "ee.lua" | ||
|
||
function wh_fleetcommand:init() | ||
local posx, posy = -280000, 0 | ||
local fc = PlayerSpaceship():setTemplate("Targaryen"):setCallSign("Der Ball"):setPosition(posx, posy) | ||
fc:setJumpDrive(false):setSharesEnergyWithDocked(false):setRestocksScanProbes(false):setRepairDocked(false) | ||
fc:setResourceAmount("Artifacts", 0) | ||
fc:setResourceDescription("Artifacts", "You can spend Artifacts for upgrades") | ||
local name = "Energy Coupling" | ||
fc:setResourceAmount(name, -1) | ||
fc:setResourceCategory(name, "Dock Upgrades") | ||
fc:setResourceDescription(name, "Allows the station to share it's energy with docked ships.") | ||
name = "Hull Repair Scaffold" | ||
fc:setResourceAmount(name, -1) | ||
fc:setResourceCategory(name, "Dock Upgrades") | ||
fc:setResourceDescription(name, "Allows the station to repair the hull of docked ships.") | ||
name = "Science Probe Factory" | ||
fc:setResourceAmount(name, -2) | ||
fc:setResourceCategory(name, "Dock Upgrades") | ||
fc:setResourceDescription(name, "Allows the station to restock docked ships with probes.") | ||
name = "Torpedo Armory" | ||
fc:setResourceAmount(name, -3) | ||
fc:setResourceCategory(name, "Dock Upgrades") | ||
fc:setResourceDescription(name, "Allows the station to restock docked ships with torpedos.") | ||
name = "Repair Crew Medical Bay" | ||
fc:setResourceAmount(name, -2) | ||
fc:setResourceCategory(name, "Dock Upgrades") | ||
fc:setResourceDescription(name, "Lost engineering damcon teams of docked ships will be healed.") | ||
name = "Systems Repair Drydock" | ||
fc:setResourceAmount(name, -2) | ||
fc:setResourceCategory(name, "Dock Upgrades") | ||
fc:setResourceDescription(name, "Damaged systems of docked ships will be repaired.") | ||
name = "Coolant Refill Tanks" | ||
fc:setResourceAmount(name, -2) | ||
fc:setResourceCategory(name, "Dock Upgrades") | ||
fc:setResourceDescription(name, "Lost coolant of docked ships will be replenished.") | ||
name = "Drive Refit Workshop" | ||
fc:setResourceAmount(name, -3) | ||
fc:setResourceCategory(name, "Dock Upgrades") | ||
fc:setResourceDescription(name, "Allows the station to chance the drive of docked ships.") | ||
|
||
self.station = fc | ||
local storage = getScriptStorage() | ||
storage.wh_fleetcommand = self | ||
|
||
sendMessageToCampaignServer("fleetcommand", fc:getCallSign()) -- notify campaign server on where the fleet command is and what it's name is. | ||
end | ||
|
||
|
||
function wh_fleetcommand:update(delta) | ||
-- repair docked ships | ||
local fc = self.station | ||
if fc == nil or not fc:isValid() then | ||
return | ||
end | ||
|
||
for _,ps in ipairs(getActivePlayerShips()) do | ||
if ps:isValid() and ps:isDocked(fc) then | ||
-- Repair crew | ||
if fc:getResourceAmount("Repair Crew Medical Bay") > 0 then | ||
local max_repair_crew = 3 | ||
if ps:getHullMax() < 100 then | ||
max_repair_crew = 1 | ||
end | ||
if ps:getRepairCrewCount() < max_repair_crew then | ||
ps:setRepairCrewCount(max_repair_crew) | ||
end | ||
end | ||
-- Repair systems | ||
if fc:getResourceAmount("Systems Repair Drydock") > 0 then | ||
for idx, system in ipairs(SYSTEMS) do | ||
ps:setSystemHealth(system, ps:getSystemHealth() + delta) | ||
end | ||
end | ||
-- Refill Coolant | ||
if fc:getResourceAmount("Coolant Refill Tanks") > 0 then | ||
if ps:getMaxCoolant() < 10 then | ||
ps:setMaxCoolant(math.min(ps:getMaxCoolant() + delta/10, 10)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--[[ Wormhole Expedition Terrain | ||
-- Creates a black hole surrounded by nebulae | ||
-- The nebulae slowly orbit the black hole | ||
--]] | ||
|
||
wh_terrain = {} | ||
|
||
require "utils.lua" | ||
require "plots/wh_util_rota.lua" | ||
|
||
function wh_terrain:init() | ||
-- create system | ||
local center_x, center_y = 100000,0 | ||
self.blackhole = BlackHole():setPosition(center_x, center_y) | ||
self.center = {center_x, center_y} | ||
|
||
self.nebulae = placeRandomAroundPoint(Nebula,50,10000,100000,center_x,center_y) | ||
for _,o in ipairs(self.nebulae) do | ||
wh_rota:add_object(o, random(400, 2000), self.blackhole) | ||
o.speed = o.speed / o.distance | ||
end | ||
|
||
local storage = getScriptStorage() | ||
storage.wh_terrain = self | ||
end | ||
|
||
function wh_terrain:update(delta) | ||
-- move nebulae happens in rota | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
wh_rota = {} | ||
|
||
require "utils.lua" | ||
|
||
function wh_rota:init() | ||
self.objects = {} | ||
end | ||
|
||
function wh_rota:add_object(object, speed, center, center_y) | ||
if type(center) == "number" and type(center_y) == "number" then | ||
center = {center, center_y} | ||
center.getPosition = function(self) | ||
return self[1], self[2] | ||
end | ||
elseif type(center) == "table" and center_y == nil and center.getPosition ~= nil then | ||
--OK | ||
else | ||
print(type(object), type(speed), type(center), type(center_y)) | ||
error("wh_rota:add_object() function used incorrectly", 2) | ||
end | ||
object.center = center | ||
object.angle = angleRotation(object, center) | ||
object.distance = distance(object, center) | ||
object.speed = speed | ||
table.insert(self.objects, object) | ||
end | ||
|
||
function wh_rota:update(delta) | ||
-- move nebulae | ||
for i=1,#self.objects do | ||
local obj = self.objects[i] | ||
if obj ~= nil and obj:isValid() then | ||
obj.angle = obj.angle + obj.speed * delta | ||
if obj.angle >= 360 then | ||
obj.angle = 0 | ||
end | ||
local pmx, pmy = vectorFromAngle(obj.angle, obj.distance) | ||
local cx, cy = obj.center:getPosition() | ||
obj:setPosition(cx+pmx, cy+pmy) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
wh_wormhole = {} | ||
|
||
require "utils.lua" | ||
|
||
function wh_wormhole:init() | ||
self.a_center = {-280000, 0} | ||
self.b_center = {100000, 0} | ||
|
||
-- speed means degree per second | ||
local distance = 30000 | ||
local speed = 90/1800 -- 90 degree in 30 minutes | ||
|
||
self.wormhole_a = WormHole():setPosition(self.a_center[1], self.a_center[2]+distance) | ||
self.wormhole_a:setTargetPosition(self.b_center[1], self.b_center[2]-distance-5000) | ||
wh_rota:add_object(self.wormhole_a, speed, self.a_center[1], self.a_center[2]) | ||
|
||
self.wormhole_b = WormHole():setPosition(self.b_center[1], self.b_center[2]+distance) | ||
self.wormhole_b:setTargetPosition(self.a_center[1], self.a_center[2]+distance-5000) | ||
wh_rota:add_object(self.wormhole_b, -speed, self.b_center[1], self.b_center[2]) -- b rotates counter-clockwise | ||
|
||
-- asteroids around the entries | ||
self.asteroids_a = placeRandomAroundPoint(Asteroid,20,300,5000,self.a_center[1],self.a_center[2]+distance) | ||
self.asteroids_b = placeRandomAroundPoint(Asteroid,20,300,5000,self.b_center[1],self.b_center[2]+distance) | ||
for _,obj in ipairs(self.asteroids_a) do | ||
wh_rota:add_object(obj, random(0.2,0.8), self.wormhole_a) | ||
end | ||
for _,obj in ipairs(self.asteroids_b) do | ||
wh_rota:add_object(obj, random(0.2,0.8), self.wormhole_b) | ||
end | ||
|
||
local storage = getScriptStorage() | ||
storage.wh_wormhole = self | ||
end | ||
|
||
function wh_wormhole:update(delta) | ||
-- set targets | ||
-- a teleports outwards | ||
-- b teleports inwards | ||
local ax, ay = vectorFromAngle(self.wormhole_b.angle, 35000) | ||
local bx, by = vectorFromAngle(self.wormhole_a.angle, 25000) | ||
self.wormhole_a:setTargetPosition(self.b_center[1]+ax, self.b_center[2]+ay) | ||
self.wormhole_b:setTargetPosition(self.a_center[1]+bx, self.a_center[2]+by) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- Name: Wormhole Expedition | ||
-- Type: Development | ||
|
||
require "plots/wh_util_rota.lua" | ||
require "plots/wh_terrain.lua" | ||
require "plots/wh_fleetcommand.lua" | ||
require "plots/wh_wormhole.lua" | ||
--require "sandbox_error.lua" | ||
|
||
function init() | ||
plots = { | ||
wh_rota, | ||
wh_terrain, | ||
wh_fleetcommand, | ||
wh_wormhole, | ||
} | ||
|
||
for i,plot in ipairs(plots) do | ||
assert(plot.init ~= nil, "plot "..i.." must have init()") | ||
plot:init() | ||
-- errorHandling:callWithErrorHandling(plot:init) -- from sandbox_library | ||
end | ||
end | ||
|
||
function update(delta) | ||
for i,plot in ipairs(plots) do | ||
assert(plot.init ~= nil, "plot "..i.." must have update()") | ||
plot:update(delta) | ||
-- errorHandling:callWithErrorHandling(plot:update,delta) -- from sandbox_library | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters