Skip to content

[Payload] A series of ECS-related fixes for Payload scenario #2303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions scripts/scenario_31_payload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,8 @@ function init()
Mine():setPosition(x, y)
end

-- Unspawn some asteroids and mines
local clearRadius = 5000
ClearHazardsNear(FactionStation.startX, FactionStation.startY, clearRadius)
ClearHazardsNear(KraylorStation.startX, KraylorStation.startY, clearRadius)
ClearHazardsNear(PayloadShip.startX, PayloadShip.startY, clearRadius)
ThinPath(FactionStation, KraylorStation)
-- Unspawn some asteroids and mines (moved this to update() as hackaround for a limitation in ECS branch)
FirstTickClearHazards = true

-- Spawn some nebulas
local nebulaNum = 15 --15
Expand Down Expand Up @@ -246,13 +242,13 @@ function ClearHazardsNear(centerX, centerY, radius, maxRoids, maxMines)

-- Destroy any hazards beyond the limits
for _, potentialHazard in ipairs(objects) do
if potentialHazard.typeName == "Asteroid" then
if potentialHazard.components.explode_on_touch ~= nil then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this can include missiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine since this is just used to clear up mines and asteroids before the mission starts.

roidCount = roidCount + 1
if roidCount > maxRoids then
potentialHazard:destroy()
end
end
if potentialHazard.typeName == "Mine" then
if potentialHazard.components.delayed_explode_on_touch ~= nil then
mineCount = mineCount + 1
if mineCount > maxMines then
potentialHazard:destroy()
Expand Down Expand Up @@ -304,7 +300,7 @@ function SpawnWeaponPickups()
artifact:onCollision(function(self, collider)
-- "Note that the callback function must reference something global, otherwise you get an error like "??[convert<ScriptSimpleCallback>::param] Upvalue 1 of function is not a table..."
local __ = math.abs(0)
if collider.typeName == "PlayerSpaceship" then
if collider.components.player_control then
collider:setWeaponStorage(weaponType, collider:getWeaponStorage(weaponType) + 1)
self:destroy()
collider:addToShipLog(_("artifacts", "Picked up a ") .. weaponType, "green")
Expand Down Expand Up @@ -337,7 +333,7 @@ function CheckPayloadControl(target, faction1, faction2)
local allShips = getObjectsInRadius(payloadX, payloadY, PayloadDistanceThreshold)

for _, ship in ipairs(allShips) do
if ship.typeName ~= "CpuShip" and ship.typeName ~= "PlayerSpaceship" then
if ship.components.ai_controller == nil and ship.components.player_control == nil then
goto continue
end
if ship:isValid() and ship:getFaction() == faction1 then
Expand Down Expand Up @@ -658,7 +654,7 @@ function SpawnWave(faction)
if i == queenIndex and WaveSize > 1 then
enemyTemplate = "Phobos M3"
end
local enemy = CpuShip():setTemplate(enemyTemplate):setFaction("Kraylor"):setPosition(enemyX, enemyY)
local enemy = CpuShip():setTemplate(enemyTemplate):setFaction("Kraylor"):setPosition(enemyX, enemyY):orderIdle()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That idle isn't the default should be a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I'll see if I can implement a fix on the engine side, but this may also fix another edge case for me so might as well stay.

enemy:setWarpDrive(true)
enemy:setWeaponStorage("Homing", 4)
enemy:setWeaponStorage("Nuke", 0)
Expand All @@ -671,7 +667,7 @@ function SpawnWave(faction)

if (faction == "Human Navy" or faction == "Both") and spawnHumanCount > 0 then
spawnHumanCount = spawnHumanCount - 1
local human = CpuShip():setTemplate("Adder MK".. irandom(3,8)):setFaction("Human Navy"):setPosition(humanX, humanY)
local human = CpuShip():setTemplate("Adder MK".. irandom(3,8)):setFaction("Human Navy"):setPosition(humanX, humanY):orderIdle()
human:setWarpDrive(true)
human:setScannedByFaction("Human Navy", true)
human:onTakingDamage(OnDamaged)
Expand All @@ -692,23 +688,28 @@ end
--

function CheckWinCondition()
if PayloadShip:isDocked(FactionStation) then
victory("Kraylor")
elseif PayloadShip:isDocked(KraylorStation) then
victory("Human Navy")
end
if not (Player:isValid()
and PayloadShip:isValid()
and FactionStation:isValid()
and KraylorStation:isValid())
then
victory("Kraylor")
return true
end
if PayloadShip:isDocked(FactionStation) then
victory("Kraylor")
return true
elseif PayloadShip:isDocked(KraylorStation) then
victory("Human Navy")
return true
end
if TimeLimit > 0 and getScenarioTime() >= TimeLimit then
globalMessage(_("payload-comms","You are out of time!"))
Player:addToShipLog(_("payload-comms", "You are out of time!"), "red")
victory("Kraylor")
return true
end
return false
end

-- Update the Payload's target based on proximities and scan status
Expand Down Expand Up @@ -958,7 +959,19 @@ end
-- Main update function
---@diagnostic disable-next-line: lowercase-global
function update(delta)
CheckWinCondition()

if(FirstTickClearHazards and #(getObjectsInRadius(FactionStation.startX, FactionStation.startY, 1)) > 0) then
FirstTickClearHazards = false
local clearRadius = 5000
ClearHazardsNear(FactionStation.startX, FactionStation.startY, clearRadius)
ClearHazardsNear(KraylorStation.startX, KraylorStation.startY, clearRadius)
ClearHazardsNear(PayloadShip.startX, PayloadShip.startY, clearRadius)
ThinPath(FactionStation, KraylorStation)
end

if CheckWinCondition() then
return
end
DeterminePayloadTarget()
HandleNPCs(delta)
HandleNPCWaves(delta)
Expand Down
Loading