Skip to content

Commit

Permalink
scenarios campaign: story missions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pithlit committed Aug 23, 2024
1 parent 9ee6ac5 commit c7c29c2
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 128 deletions.
5 changes: 3 additions & 2 deletions scripts-piglit/plots/campaign.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ function campaign:initScore(difficulty)
sendMessageToCampaignServer("score", toJSON(score))
end

function campaign:victoryScore()
function campaign:victoryScore(progress)
local score = {
time = getScenarioTime(),
progress = 100,
progress = progress or 100,
}
sendMessageToCampaignServer("score", toJSON(score))
end

function campaign:placeArtifact(x,y,name,descr,callback)
-- only first call causes artifact, further calls are ignored
if self.artifacts_init == false then
self.artifacts_init = true
wh_artifacts:init()
Expand Down
4 changes: 2 additions & 2 deletions scripts-piglit/scenario_00_basic.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Name: Skirmish
-- Short Description: A quick and easy battle scenario.
-- Objective: Defend the space stations and destroy all enemy ships.
-- Short Description: A quick and easy battle scenario
-- Objective: Defend the space stations and destroy all enemy ships
-- Duration: 30 minutes time limit
-- Difficulty: normal/selectable
-- Description: A few stations are under attack by enemies, with some terrain around them.
Expand Down
6 changes: 3 additions & 3 deletions scripts-piglit/scenario_02_surrounded.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ function init()
setCirclePos(ship, a, d)

do
local wingman = CpuShip():setTemplate("MT52 Hornet"):setRotation(a + 180)):setFaction(enemy_faction)
local wingman = CpuShip():setTemplate("MT52 Hornet"):setRotation(a + 180):setFaction(enemy_faction)
table.insert(enemyList, wingman)
setCirclePos(wingman, a - 5, d + 100)
wingman:orderFlyFormation(ship, 500, 100)
end
do
local wingman = CpuShip():setTemplate("MT52 Hornet"):setRotation(a + 180)):setFaction(enemy_faction)
local wingman = CpuShip():setTemplate("MT52 Hornet"):setRotation(a + 180):setFaction(enemy_faction)
table.insert(enemyList, wingman)
setCirclePos(wingman, a + 5, d + 100)
wingman:orderFlyFormation(ship, -500, 100)
end
do
local wingman = CpuShip():setTemplate("MT52 Hornet"):setRotation(a + 180)):setFaction(enemy_faction)
local wingman = CpuShip():setTemplate("MT52 Hornet"):setRotation(a + 180):setFaction(enemy_faction)
table.insert(enemyList, wingman)
setCirclePos(wingman, a + random(-5, 5), d - 500)
wingman:orderFlyFormation(ship, 0, 600)
Expand Down
23 changes: 19 additions & 4 deletions scripts-piglit/scenario_03_waves.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
-- Name: Battle: Waves
-- Name: Siege
-- Short Description: A long battle scenario
-- Objective: Destroy all incoming enemy ships
-- Duration: 1 hour
-- Difficulty: normal/selectable
-- Description: Waves of increasingly difficult enemies attack friendly stations. There is no victory. How many waves can you destroy?
---
--- Spawn the player ships you want. The strength of enemy ships is independent of the number and type of player ships.
--- The reputation bonus you will gain here depends on the difficulty and the number of survived enemy waves.
-- Type: Basic
-- Setting[Enemies]: Configures the amount of enemies spawned in the scenario.
-- Enemies[Easy]: Decreases the number of ships in each wave. Good for new players, but takes longer for the players to be overwhelmed.
Expand All @@ -23,6 +28,8 @@ require("utils.lua")
-- setCirclePos(obj, x, y, angle, distance)
-- Returns the object with its position set to the resulting coordinates.

require("plots/campaign.lua")

function randomStationTemplate()
local rnd = random(0, 100)
if rnd < 10 then
Expand All @@ -46,17 +53,24 @@ function init()

--PlayerSpaceship():setFaction("Human Navy"):setTemplate("Atlantis")

-- Give the mission to the (first) player ship
local text = _("goal-shipLog", [[At least one friendly base must survive.
campaign:initScore(getScenarioSetting("Enemies"))
onNewPlayerShip(function(ship)
-- Give the mission to the (first) player ship
local text = _("goal-shipLog", [[At least one friendly base must survive.
Destroy all enemy ships. After a short delay, the next wave will appear. And so on ...
How many waves can you destroy?]])
--getPlayerShip(-1):addToShipLog(text, "white")
ship:addToShipLog(text, "white")
campaign:requestReputation()
end)

-- Random friendly stations
for _ = 1, 2 do
local station = SpaceStation():setTemplate(randomStationTemplate()):setFaction("Human Navy"):setPosition(random(-5000, 5000), random(-5000, 5000))
station:onDestruction(function(station, instigator)
local x,y = station:getPosition()
campaign:placeArtifact(x,y, "Escape Pod", "An escape pod from a destroyed Human Navy station. The station crew managed to evacuate the station just in time and so they could be rescued when a brave Human Navy ship finally arrived.")
table.insert(friendlyList, station)
end

Expand Down Expand Up @@ -389,6 +403,7 @@ end


function spawnWave()
sendProgressToCampaignServer(waveNumber, 100) -- progress equals wave number
waveNumber = waveNumber + 1
ship = getPlayerShip(-1)
if ship ~= nil and ship:isValid() then
Expand Down
18 changes: 14 additions & 4 deletions scripts-piglit/scenario_05_beacon.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
-- Name: Mission: Beacon of light
-- Short Description: A story-based diplomatic mission
-- Objective: Recover the diplomat and finish their task
-- Duration: 1 hour
-- Difficulty: hard on first try
-- Description: Near the far outpost of Orion-5, Exuari attacks are increasing. A diplomat went missing, and your mission will start with recovering him.
-- Type: Mission

Expand All @@ -13,6 +17,7 @@ require("utils.lua")
-- Place random objects in a line, from point x1, y1 to x2, y2 with a random distance of random_amount

require("script_hangar.lua")
require("plots/campaign.lua")

--- Init is run when the scenario is started. Create your initial world
function init()
Expand All @@ -27,6 +32,7 @@ function init()
main_station:setPosition(-25200, 32200):setCallSign("Orion-5")
enemy_station = CpuShip():setTemplate("Ryder"):setFaction("Exuari"):orderStandGround()
enemy_station:setPosition(-45600, -15800):setCallSign("Omega")

neutral_station = SpaceStation():setTemplate("Small Station"):setFaction("Independent")
neutral_station:setPosition(9100, -35400):setCallSign("Refugee-X")

Expand All @@ -37,6 +43,8 @@ function init()
Nebula():setPosition(-24000, -14300)
Nebula():setPosition(-28600, -21900)

campaign:placeArtifact(-32500, -11000, "Broken Exuari Bomber", "A derelict Exuari ship of the 'Ranger' class. One missile of it's arsenal of small nuclar warheads is still stuck in the torpedo tube together with an Exuari technician burned to death by the missiles exhaust plume.")

-- Random nebulae in the system
Nebula():setPosition(-8000, -38300)
Nebula():setPosition(24000, -30700)
Expand Down Expand Up @@ -77,7 +85,8 @@ Our last contact with RT-4 was before it entered the nebula at sector G5. The ne
, player:getCallSign()))
-- Set the initial mission state
mission_state = missionStartState
sendMessageToCampaignServer("setProgress: 0%")
campaign:requestReputation()
campaign:initScore()
end

function missionStartState(delta)
Expand Down Expand Up @@ -179,7 +188,7 @@ To ensure Refugee-X is aware of your peaceful intentions, we have stripped you o
player:setWeaponStorageMax("EMP", 0)

mission_state = missionRetrieveCriminals
sendMessageToCampaignServer("setProgress: 30%")
sendProgressToCampaignServer(1, 4)
end
end
function missionRT4Died(delta)
Expand Down Expand Up @@ -224,7 +233,7 @@ function missionWaitForAmbush(delta)
Your translator has difficulty translating the message, but it seems to come down to the fact that they want you dead and that your death will bring them great fun.]])
)
sendMessageToCampaignServer("setProgress: 50%")
sendProgressToCampaignServer(2, 4)
end
end

Expand Down Expand Up @@ -396,7 +405,7 @@ Lead the assault on the Exuari base in sector E2. Expect heavy resistance.]])
CpuShip():setTemplate("Sentinel"):setFaction("Exuari"):setPosition(-44500, -15000):orderDefendTarget(enemy_station)
CpuShip():setTemplate("Flash"):setFaction("Exuari"):setPosition(-43000, -9000):orderAttack(player)
mission_state = nil
sendMessageToCampaignServer("setProgress:80%")
sendProgressToCampaignServer(3, 4)
end
end

Expand All @@ -410,6 +419,7 @@ function update(delta)

-- If the enemy station is destroyed, the Human Navy wins.
if not enemy_station:isValid() then
campaign:victoryScore()
victory("Human Navy")
return
end
Expand Down
Loading

0 comments on commit c7c29c2

Please sign in to comment.