Slight refactor
This commit is contained in:
parent
95b4e08ebd
commit
250d614338
|
@ -15,8 +15,8 @@ function widget:GetInfo()
|
|||
return {
|
||||
name = "Music Player",
|
||||
desc = "Plays music based on situation",
|
||||
author = "cake, trepan, Smoth, Licho, xponen",
|
||||
date = "Mar 01, 2008, Aug 20 2009, Nov 23 2011",
|
||||
author = "cake, trepan, Smoth, Licho, xponen, Birdulon",
|
||||
date = "Mar 01, 2008, Aug 20 2009, Nov 23 2011, June 2020",
|
||||
license = "GNU GPL, v2 or later",
|
||||
layer = 0,
|
||||
enabled = true -- loaded by default?
|
||||
|
@ -62,16 +62,40 @@ options = {
|
|||
desc = "Music switches to Winning when recent attrition ratio rises above this value",
|
||||
noHotkey = true,
|
||||
},
|
||||
war1Threshold = {
|
||||
name = "War Threshold 1",
|
||||
type = "number",
|
||||
value = 30000,
|
||||
min = 10000,
|
||||
max = 100000,
|
||||
step = 100,
|
||||
desc = "Music switches to War when recent war points rise above this value",
|
||||
noHotkey = true,
|
||||
},
|
||||
war2Threshold = {
|
||||
name = "War Threshold 2",
|
||||
type = "number",
|
||||
value = 300000,
|
||||
min = 20000,
|
||||
max = 1000000,
|
||||
step = 100,
|
||||
desc = "Music switches to War2 when recent war points rise above this value",
|
||||
noHotkey = true,
|
||||
},
|
||||
}
|
||||
|
||||
local unitExceptions = include("Configs/snd_music_exception.lua")
|
||||
|
||||
local windows = {}
|
||||
|
||||
local moodPriorities = {peace=0, war=1, war2=2, winning=4, losing=4, briefing=10, victory=10, defeat=10} -- Determines which music moods will instantly interrupt others, and which will wait for playing track to finish
|
||||
local moodDynamic = {peace=true, war=true, war2=true, winning=true, losing=true, briefing=false, victory=false, defeat=false} -- Determines which music moods will instantly interrupt others, and which will wait for playing track to finish
|
||||
local war2Threshold = 400000
|
||||
local warThreshold = 50000
|
||||
|
||||
local spAreTeamsAllied = Spring.AreTeamsAllied
|
||||
|
||||
local MOODS = {"peace", "war", "war2", "winning", "losing", "briefing", "victory", "defeat"}
|
||||
local moodPriorities = {peace=0, war=1, war2=2, winning=4, losing=4, briefing=10, victory=10, defeat=10, [""]=0} -- Determines which music moods will instantly interrupt others, and which will wait for playing track to finish
|
||||
local moodDynamic = {peace=true, war=true, war2=true, winning=true, losing=true, briefing=false, victory=false, defeat=false, [""]=true} -- Determines which music moods will instantly interrupt others, and which will wait for playing track to finish
|
||||
local war2Threshold = 300000
|
||||
local warThreshold = 30000
|
||||
local peaceThreshold = 10000
|
||||
local PLAYLIST_FILE = "sounds/music/playlist.lua"
|
||||
local LOOP_BUFFER = 0.015 -- if looping track is this close to the end, go ahead and loop
|
||||
|
@ -202,24 +226,21 @@ end
|
|||
|
||||
function InitializeTracks()
|
||||
Spring.Echo("Initializing music tracks")
|
||||
if VFS.FileExists(PLAYLIST_FILE, VFS.RAW_FIRST) then
|
||||
local plTracks = VFS.Include(PLAYLIST_FILE, nil, VFS.RAW_FIRST)
|
||||
tracks.war = plTracks.war
|
||||
tracks.peace = plTracks.peace
|
||||
tracks.briefing = plTracks.briefing
|
||||
tracks.victory = plTracks.victory
|
||||
tracks.defeat = plTracks.defeat
|
||||
end
|
||||
-- if VFS.FileExists(PLAYLIST_FILE, VFS.RAW_FIRST) then
|
||||
-- local plTracks = VFS.Include(PLAYLIST_FILE, nil, VFS.RAW_FIRST)
|
||||
-- tracks.war = plTracks.war
|
||||
-- tracks.peace = plTracks.peace
|
||||
-- tracks.briefing = plTracks.briefing
|
||||
-- tracks.victory = plTracks.victory
|
||||
-- tracks.defeat = plTracks.defeat
|
||||
-- end
|
||||
|
||||
local vfsMode = (options.useIncludedTracks.value and VFS.RAW_FIRST) or VFS.RAW
|
||||
tracks.war = tracks.war or VFS.DirList("sounds/music/war/", "*.ogg", vfsMode)
|
||||
tracks.war2 = tracks.war2 or VFS.DirList("sounds/music/war2/", "*.ogg", vfsMode)
|
||||
tracks.winning = tracks.winning or VFS.DirList("sounds/music/winning/", "*.ogg", vfsMode)
|
||||
tracks.losing = tracks.losing or VFS.DirList("sounds/music/losing/", "*.ogg", vfsMode)
|
||||
tracks.peace = tracks.peace or VFS.DirList("sounds/music/peace/", "*.ogg", vfsMode)
|
||||
tracks.briefing = tracks.briefing or VFS.DirList("sounds/music/briefing/", "*.ogg", vfsMode)
|
||||
tracks.victory = tracks.victory or VFS.DirList("sounds/music/victory/", "*.ogg", vfsMode)
|
||||
tracks.defeat = tracks.defeat or VFS.DirList("sounds/music/defeat/", "*.ogg", vfsMode)
|
||||
for i=1,#MOODS do
|
||||
local mood = MOODS[i]
|
||||
tracks[mood] = VFS.DirList("sounds/music/" .. mood .. "/", "*.ogg", vfsMode)
|
||||
-- tracks[mood] = tracks[mood] or VFS.DirList("sounds/music/" .. mood .. "/", "*.ogg", vfsMode)
|
||||
end
|
||||
end
|
||||
|
||||
function CheckLoop()
|
||||
|
@ -278,16 +299,17 @@ function EvaluateMood()
|
|||
deathPointsHostile[iNext] = deathPointsHostile[warPointsIter] % warPointsRollover
|
||||
warPointsIter = iNext
|
||||
|
||||
local warPoints = totalKilled + totalDmg
|
||||
if moodDynamic[musicType] then
|
||||
if (totalKilled >= warThreshold) then
|
||||
if (warPoints >= options.war1Threshold.value) then
|
||||
musicType = "war"
|
||||
if (totalKilled >= war2Threshold) then musicType = "war2" end
|
||||
if attritionRatio < options.attritionRatioLosing then
|
||||
if (warPoints >= options.war2Threshold.value) then musicType = "war2" end
|
||||
if attritionRatio < options.attritionRatioLosing.value then
|
||||
musicType = "losing"
|
||||
elseif attritionRatio > options.attritionRatioWinning then
|
||||
elseif attritionRatio > options.attritionRatioWinning.value then
|
||||
musicType = "winning"
|
||||
end
|
||||
else --if (totalKilled <= peaceThreshold) then
|
||||
else --if (warPoints <= peaceThreshold) then
|
||||
musicType = "peace"
|
||||
end
|
||||
end
|
||||
|
@ -377,7 +399,7 @@ function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer)
|
|||
if (UnitDefs[unitDefID] == nil) then return end
|
||||
if paralyzer then return end
|
||||
|
||||
if (teamID == myTeam) then
|
||||
if spAreTeamsAllied(unitTeam or 0, myTeam) then
|
||||
dmgPointsFriendly[warPointsIter] = dmgPointsFriendly[warPointsIter] + damage
|
||||
else
|
||||
dmgPointsHostile[warPointsIter] = dmgPointsHostile[warPointsIter] + damage
|
||||
|
@ -388,7 +410,7 @@ function widget:UnitDestroyed(unitID, unitDefID, teamID)
|
|||
if unitExceptions[unitDefID] then return end
|
||||
local unitCost = UnitDefs[unitDefID].metalCost
|
||||
|
||||
if (teamID == myTeam) then
|
||||
if spAreTeamsAllied(teamID or 0, myTeam) then
|
||||
deathPointsFriendly[warPointsIter] = deathPointsFriendly[warPointsIter] + unitCost
|
||||
else
|
||||
deathPointsHostile[warPointsIter] = deathPointsHostile[warPointsIter] + unitCost
|
||||
|
@ -414,7 +436,7 @@ local function PlayGameOverMusic(gameWon)
|
|||
end
|
||||
looping = false
|
||||
Spring.StopSoundStream()
|
||||
Spring.PlaySoundStream(track,WG.music_volume or 0.5)
|
||||
Spring.PlaySoundStream(track, WG.music_volume or 0.5)
|
||||
WG.music_start_volume = WG.music_volume
|
||||
end
|
||||
|
||||
|
@ -438,7 +460,7 @@ function widget:Initialize()
|
|||
--math.randomseed(os.clock()* 101.01)--lurker wants you to burn in hell rgn
|
||||
-- for i=1,20 do Spring.Echo(math.random()) end
|
||||
|
||||
for i = 1, warPointsSize do
|
||||
for i=1,warPointsSize do
|
||||
dmgPointsFriendly[i] = 0
|
||||
dmgPointsHostile[i] = 0
|
||||
deathPointsFriendly[i] = 0
|
||||
|
|
Loading…
Reference in New Issue