Skip to content

Commit

Permalink
Fixes to nuclear alert
Browse files Browse the repository at this point in the history
Fixes #295
  • Loading branch information
Arch-Shaman committed Jun 14, 2021
1 parent 7cedc55 commit 57c358d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 13 additions & 3 deletions LuaRules/Gadgets/unit_gamerules_events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,33 @@ end

if not gadgetHandler:IsSyncedCode() then
local warningframes = -5
local playsound = -181
local frame = -1
local lastplayed = -5

local function NukeLaunched(_, allyteam)
local myallyteam = Spring.GetMyAllyTeamID()
if myallyteam ~= allyteam then
if Script.LuaUI.NukeAlert then
if Script.LuaUI('NukeAlert') then
Script.LuaUI.NukeAlert(true)
warningframes = Spring.GetGameFrame() + 150 + 50*math.random()
warningframes = frame + 100 + math.ceil(50*math.random())
if playsound + 36 < frame then
playsound = frame + 35
end
end
end
end

function gadget:GameFrame(f)
frame = f
if f == warningframes then
if Script.LuaUI.NukeAlert then
if Script.LuaUI('NukeAlert') then
Script.LuaUI.NukeAlert(false)
end
end
if playsound == f then
Spring.PlaySoundFile("sounds/reply/advisor/nuclearthreat.wav", 100)
end
end

function gadget:Initialize()
Expand Down
11 changes: 6 additions & 5 deletions LuaUI/Widgets/gui_chili_nuke_warning.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function widget:GetInfo()
date = "15 August 2015",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true
enabled = true,
}
end

Expand Down Expand Up @@ -141,7 +141,7 @@ end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function languageChanged ()
local function languageChanged()
if not mainWindow then return end
mainWindow.label:SetCaption(WG.Translate ("interface", "nuclear_launch_detected"))
end
Expand Down Expand Up @@ -171,24 +171,25 @@ function widget:Update(dt)
end
end

local function SetWantedShown(t)
local function NukeAlert(t)
if t then
wantedShown = true
ShowWindow()
Spring.PlaySound("sounds/reply/advisor/nuclearthreat.wav", 20)
else
wantedShown = false
HideWindow()
end
end

function widget:Initialize()
widgetHandler:RegisterGlobal("NukeAlert", NukeAlert)
Chili = WG.Chili
screen0 = Chili.Screen0
if (not Chili) then
widgetHandler:RemoveWidget()
return
end
WG.InitializeTranslation (languageChanged, GetInfo().name)
widgetHandler:RegisterGlobal(widget, "NukeAlert", SetWantedShown)
end


Expand Down

0 comments on commit 57c358d

Please sign in to comment.