Skip to content

Commit

Permalink
scenario-plots: artifacts and more terrain
Browse files Browse the repository at this point in the history
  • Loading branch information
Pithlit committed Jul 16, 2024
1 parent 8dcff2e commit ec2ec79
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 9 deletions.
66 changes: 66 additions & 0 deletions scripts-piglit/plots/wh_artifacts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
wh_artifacts = {}

function wh_artifacts:init()
self.callsign_counter = 1000

end

function wh_artifacts:placeArtifact(x,y,name,info)
local freq = math.floor(random(20, 40)) * 20
self.callsign_counter = self.callsign_counter + math.floor(random(1,200))
local callsign = self.callsign_counter
debris = Artifact():setPosition(x, y):setDescriptions(_("A piece of space junk. Scan to find out the capturing frequency"), name.._("\nCapturing frequency:").." "..freq.. ".\nCalibrate your shields to this frequency and activate them to capture it.")
debris:setScanningParameters(4, 1)
debris.freq=freq
if freq < 595 then
debris:setModel("debris-cubesat")
else
debris:setModel("debris-blob")
end
debris:allowPickup(true)
debris:setCallSign(callsign):setRadarTraceColor(255,235,170)
if name ~= nil then
debris.resource_name = name
debris.info_collected = "Collected "..name.."."
debris.info_destroyed = name .. " was destroyed.\n\nTo collect artifacts you need to have shields active and calibrated to the capturing frequency of the artifact."
if info ~= nil then
debris.resource_descr = info
debris.info_collected = debris.info_collected .. "\n\n"..info.."\n\nDeliver it to the fleet command station to upload strategic information for the fleet.\nEach recovered artifact can be used to upgrade the fleet command station."
debris.info_destroyed = debris.info_destroyed .. "\n\nYou may still deliver the broken thing to the fleet command station, so they can recover strategic information from it."
end
end

debris:onPickUp(function(art, player)
shieldfreq = 400+(player:getShieldsFrequency())*20
local ax, ay = art:getPosition()
local x, y = player:getPosition()
if shieldfreq == art.freq and player:getShieldsActive() == true then
ElectricExplosionEffect():setPosition(x,y):setSize(200)
player:takeDamage(1, "kinetic", ax, ay)
player:addReputationPoints(20)
player:increaseResourceAmount("Artifacts", 1)
player:setResourceDescription("Artifacts", "Deliver Artifacts to the fleet command station.")
if art.resource_name ~= nil and art.resource_descr ~= nil then
player:increaseResourceAmount(art.resource_name, 1)
player:setResourceCategory(art.resource_name, "Strategic Information")
player:setResourceDescription(art.resource_name, art.resource_descr)
end
player:addCustomMessage("science", "artifact_gathered", art.info_collected)
player:addCustomMessage("operations", "artifact_gathered", art.info_collected)
player:addCustomMessage("single", "artifact_gathered", art.info_collected)
player:addToShipLog(art.info_collected.."\n(Reputation +20)", "magenta")
else
ExplosionEffect():setPosition(ax,ay):setSize(200)
player:takeDamage(50, "kinetic", ax, ay)
player:addCustomMessage("science", "artifact_destroyed", art.info_destroyed)
player:addCustomMessage("operations", "artifact_destroyed", art.info_destroyed)
player:addCustomMessage("single", "artifact_destroyed", art.info_destroyed)
player:addToShipLog(art.info_destroyed, "magenta")
end
end)

end

function wh_artifacts:update()

end
41 changes: 41 additions & 0 deletions scripts-piglit/plots/wh_fleetcommand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function wh_fleetcommand:init()
fc:setResourceDescription(name, "Allows the station to chance the drive of docked ships.")

self.station = fc
self.strategic_db = ScienceDatabase():setName("Strategic Information"):setLongDescription("Ships of the fleet can gather strategic information by collecting artifacts or completing missions. When a ship with strategic information docks with the fleet command station, the strategic information gets uploaded to all ship databases.")

local storage = getScriptStorage()
storage.wh_fleetcommand = self

Expand Down Expand Up @@ -83,6 +85,45 @@ function wh_fleetcommand:update(delta)
ps:setMaxCoolant(math.min(ps:getMaxCoolant() + delta/10, 10))
end
end

-- Artifact handling
local arts = ps:getResourceAmount("Artifacts")
if arts > 0 then
local msg = tostring(arts) .. " Artifact"
if arts > 1 then
msg = msg.."s"
end
local msg_ps = "Transferred " .. msg .. " to the station. The fleet command may use them for upgrades."
ps:addReputationPoints(20 * arts)
ps:tranferResource("Artifacts", arts, fc)
ps:addCustomMessage("relay", "artifact_delivered", mgs_ps)
ps:addCustomMessage("operations", "artifact_delivered", msg_ps)
ps:addCustomMessage("single", "artifact_delivered", msg_ps)
msg_ps = msg_ps .. "\n(Reputation +"..(20*arts)..")"
ps:addToShipLog(msg_ps, "magenta")
local msg_fc = "Received " .. msg .. " from ".. ps:getCallSign() .. "."
fc:addToShipLog(msg_fc, "magenta")
-- TODO notify fleet command - which station?
end
local sis = ps:getResources("Strategic Information")
for _,si in ipairs(sis) do
local info = ps:getResourceDescription(si)
if self.strategic_db():getEntryByName(si) == nil then
self.strategic_db():addEntry(si):setLongDescription(info)
fc:addToShipLog("Received strategic information from "..ps:getCallSign()..": "..si, "cyan")
end
ps:setResourceAmount(si, 0)
end
if #sis > 0 then
ps:addReputationPoints(5 * #sis)
local msg = "Strategic information was uploaded to the fleet's databases."
ps:addCustomMessage("science", "upload", mgs)
ps:addCustomMessage("operations", "upload", msg)
ps:addCustomMessage("single", "upload", msg)
msg = msg .. "\n(Reputation +"..(5*sis)..")"
ps:addToShipLog(msg, "magenta")
fc:addCustomMessage("database", "upload_db", "Strategic Information from "..ps:getCallSign().."has been uploaded.\n\n(Click on 'Strategic Information' to refresh the list.)")
end
end
end
end
1 change: 1 addition & 0 deletions scripts-piglit/plots/wh_locusts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function wh_locusts:init()
ship:setTypeName("Locust")
ship:setImpulseMaxSpeed(300)
ship:setRotationMaxSpeed(30)
ship:setScanningParameters(1,1)
ship:orderStandGround()
table.insert(self.swarm_ships,ship)
end
Expand Down
158 changes: 153 additions & 5 deletions scripts-piglit/plots/wh_terrain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,167 @@ 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}

-- create rotating system
self.blackhole = BlackHole():setPosition(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
-- create POIs
local common_scattered_objects = 0
local common_obj_type_sizes = {
{typ = "WarpJammer", siz = 5000},
{typ = "mineblob", siz = 4000},
{typ = "asteroidblob", siz = 3500},
{typ = "Mine", siz = 2000},
{typ = "Asteroid", siz = 1000},
}
repeat
local dist = random(2000,50000) + random(2000,50000) + random(2000,50000)
-- avoid wormhole path
if dist < 25000 or dist > 35000 then
local ox, oy = vectorFromAngle(random(0,360), dist)
ox = ox + center_x
oy = oy + center_y
local obj_list = getObjectsInRadius(ox, oy, 5000)
local closest_distance = 5000
local closest_obj = nil
for i,obj in ipairs(obj_list) do
local obj_dist = distance(obj,ox,oy)
if obj_dist < closest_distance then
closest_distance = obj_dist
closest_obj = obj
end
end
local type_list = {}
for i,type_size in ipairs(common_obj_type_sizes) do
if type_size.siz < closest_distance then
table.insert(type_list,type_size.typ)
end
end
if #type_list > 0 then
local insert_type = type_list[math.random(1,#type_list)]
if insert_type == "WarpJammer" then
closest_distance = math.min(closest_distance * .95,20000)
WarpJammer():setPosition(ox,oy):setRange(closest_distance)
elseif insert_type == "mineblob" then
closest_distance = math.min(closest_distance,15000)
self:placeMinefieldBlob(ox,oy,closest_distance*.37)
elseif insert_type == "asteroidblob" then
closest_distance = math.min(closest_distance,15000)
self:placeAsteroidBlob(ox,oy,closest_distance*.37)
elseif insert_type == "Mine" then
Mine():setPosition(ox,oy)
elseif insert_type == "Asteroid" then
Asteroid():setPosition(ox,oy):setSize(random(20,950))
end
end
common_scattered_objects = common_scattered_objects + 1
end
until(common_scattered_objects > 100)

getScriptStorage().wh_terrain = self
end

function wh_terrain:placeAsteroidBlob(x,y,field_radius)
-- TODO: origin point should be an artefact
local asteroid_list = {}
local a = Asteroid():setPosition(x,y)
local size = random(10,400) + random(10,400)
a:setSize(size)
table.insert(asteroid_list,a)
local visual_angle = random(0,360)
local vx, vy = vectorFromAngle(visual_angle,random(0,field_radius))
local va = VisualAsteroid():setPosition(x + vx, y + vy)
va:setSize(random(10,300) + random(5,300))
visual_angle = visual_angle + random(120,240)
vx, vy = vectorFromAngle(visual_angle,random(0,field_radius))
va = VisualAsteroid():setPosition(x + vx, y + vy)
va:setSize(random(10,300) + random(5,300))
local reached_the_edge = false
repeat
local overlay = false
local nax = nil
local nay = nil
repeat
overlay = false
local base_asteroid_index = math.random(1,#asteroid_list)
local base_asteroid = asteroid_list[base_asteroid_index]
local bax, bay = base_asteroid:getPosition()
local angle = random(0,360)
size = random(10,400) + random(10,400)
local asteroid_space = (base_asteroid:getSize() + size)*random(1.05,1.25)
nax, nay = vectorFromAngleNorth(angle,asteroid_space)
nax = nax + bax
nay = nay + bay
for i,asteroid in ipairs(asteroid_list) do
if i ~= base_asteroid_index then
local cax, cay = asteroid:getPosition()
local asteroid_distance = distance(cax,cay,nax,nay)
if asteroid_distance < asteroid_space then
overlay = true
break
end
end
end
until(not overlay)
a = Asteroid():setPosition(nax,nay)
a:setSize(size)
table.insert(asteroid_list,a)
visual_angle = random(0,360)
vx, vy = vectorFromAngle(visual_angle,random(0,field_radius))
va = VisualAsteroid():setPosition(nax + vx,nay + vy)
va:setSize(random(10,300) + random(5,300))
visual_angle = visual_angle + random(120,240)
vx, vy = vectorFromAngle(visual_angle,random(0,field_radius))
va = VisualAsteroid():setPosition(nax + vx, nay + vy)
va:setSize(random(10,300) + random(5,300))
if distance(x,y,nax,nay) > field_radius then
reached_the_edge = true
end
until(reached_the_edge)
return asteroid_list
end
function wh_terrain:placeMinefieldBlob(x,y,mine_blob_radius)
-- TODO: origin point should be an artefact
local mine_list = {}
table.insert(mine_list,Mine():setPosition(x,y))
local reached_the_edge = false
local mine_space = 1400
repeat
local overlay = false
local nmx = nil
local nmy = nil
repeat
overlay = false
local base_mine_index = math.random(1,#mine_list)
local base_mine = mine_list[base_mine_index]
local bmx, bmy = base_mine:getPosition()
local angle = random(0,360)
nmx, nmy = vectorFromAngleNorth(angle,mine_space)
nmx = nmx + bmx
nmy = nmy + bmy
for i, mine in ipairs(mine_list) do
if i ~= base_mine_index then
local cmx, cmy = mine:getPosition()
local mine_distance = distance(cmx, cmy, nmx, nmy)
if mine_distance < mine_space then
overlay = true
break
end
end
end
until(not overlay)
table.insert(mine_list,Mine():setPosition(nmx,nmy))
if distance(x, y, nmx, nmy) > mine_blob_radius then
reached_the_edge = true
end
until(reached_the_edge)
return mine_list
end

function wh_terrain:update(delta)
Expand Down
9 changes: 5 additions & 4 deletions scripts-piglit/scenario_99_wormhole_expedition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- Type: Development

require "plots/wh_util_rota.lua"
require "plots/wh_artifacts.lua"
require "plots/wh_terrain.lua"
require "plots/wh_fleetcommand.lua"
require "plots/wh_wormhole.lua"
Expand All @@ -11,6 +12,7 @@ require "plots/wh_locusts.lua"
function init()
plots = {
wh_rota,
wh_artifacts,
wh_terrain,
wh_fleetcommand,
wh_wormhole,
Expand All @@ -20,15 +22,14 @@ function init()
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
if plot.update ~= nil then
plot:update(delta)
end
end
end

0 comments on commit ec2ec79

Please sign in to comment.