pioneerspacesim / pioneer

A game of lonely space adventure
https://pioneerspacesim.net
1.64k stars 380 forks source link

Missile firing during paused game #5926

Open dr-pegasus opened 1 month ago

dr-pegasus commented 1 month ago

Observed behaviour

Missiles can be fired (spawned) when the game is paused. Instead of seeing a swarm of missiles flying toward the target, there is very high risk of blowing up the player's own ship.

My version of Pioneer: pioneer-20240710-win

This probably is just an unhappy behavior, rather than a legit bug. However, I recommend adding pause check like this, in \data\libs\Ship.lua

function Ship:FireMissileAt(which_missile, target)
    local missile_object = false
    local game_paused = (Game.GetTimeAcceleration() == "paused") and true or false
    if type(which_missile) == "number" and (not game_paused) then
        local missile_equip = self:GetEquip("missile", which_missile)
        if missile_equip then
            missile_object = self:SpawnMissile(missile_equip.missile_type)
            if missile_object ~= nil then
                self:SetEquip("missile", which_missile)
            end
        end
    elseif (not game_paused) then
        for i,m in pairs(self:GetEquip("missile")) do
            if which_missile == "any" then
                missile_object = self:SpawnMissile(m.missile_type)
                if missile_object ~= nil then
                    self:SetEquip("missile", i)
                    break
                end
            end
        end
    end
...
end
impaktor commented 1 month ago

Care to do a pull request?

Web-eWorks commented 1 month ago

A better solution would be to fix this in the UI code which implements the missile button. Simply checking for game paused before calling Ship:FireMissileAt() would be fine.

Given that Ship:FireMissileAt() is mid-refactor in #5734 any changes to that function directly are going to cause merge conflicts one way or another.