Refactor war state points counting for later additions
This commit is contained in:
parent
9ceaa67267
commit
5d7d2606d5
|
@ -55,7 +55,11 @@ local LOOP_BUFFER = 0.015 -- if looping track is this close to the end, go ahead
|
||||||
local UPDATE_PERIOD = 1
|
local UPDATE_PERIOD = 1
|
||||||
|
|
||||||
local musicType = 'peace'
|
local musicType = 'peace'
|
||||||
local dethklok = {} -- keeps track of the number of doods killed in each time frame
|
local warPointsIter = 1 -- Position in circular buffer. 1-indexed because L[ew]a
|
||||||
|
local warPointsSize = 30 -- Size of circular buffer. Sampling is currently hardcoded but might change later.
|
||||||
|
local warPointsFriendly = {} -- keeps track of the number of doods killed in each time frame
|
||||||
|
local warPointsHostile = {}
|
||||||
|
local warPointsRollover = 4000000000 -- Roll back to zero after this many have accumulated
|
||||||
local timeframetimer = 0
|
local timeframetimer = 0
|
||||||
local timeframetimer_short = 0
|
local timeframetimer_short = 0
|
||||||
local loopTrack = ''
|
local loopTrack = ''
|
||||||
|
@ -64,8 +68,8 @@ local previousTrackType = ''
|
||||||
local newTrackWait = 1000
|
local newTrackWait = 1000
|
||||||
local numVisibleEnemy = 0
|
local numVisibleEnemy = 0
|
||||||
local fadeVol
|
local fadeVol
|
||||||
local curTrack = "no name"
|
local curTrac = "no name"
|
||||||
local songText = "no name"
|
local songText = "no name"
|
||||||
local haltMusic = false
|
local haltMusic = false
|
||||||
local looping = false
|
local looping = false
|
||||||
local paused = false
|
local paused = false
|
||||||
|
@ -227,11 +231,12 @@ function widget:Update(dt)
|
||||||
timeframetimer_short = 0
|
timeframetimer_short = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- (Spring.GetGameRulesParam("recentNukeLaunch") == 1) -- Might need this for superweapon music later
|
||||||
|
|
||||||
timeframetimer = timeframetimer + dt
|
timeframetimer = timeframetimer + dt
|
||||||
if (timeframetimer > UPDATE_PERIOD) then -- every second
|
if (timeframetimer > UPDATE_PERIOD) then -- every second
|
||||||
timeframetimer = 0
|
timeframetimer = 0
|
||||||
newTrackWait = newTrackWait + 1
|
newTrackWait = newTrackWait + 1
|
||||||
local PlayerTeam = Spring.GetMyTeamID()
|
|
||||||
numVisibleEnemy = 0
|
numVisibleEnemy = 0
|
||||||
local doods = Spring.GetVisibleUnits(-1, nil, true)
|
local doods = Spring.GetVisibleUnits(-1, nil, true)
|
||||||
for i=1,#doods do
|
for i=1,#doods do
|
||||||
|
@ -240,19 +245,21 @@ function widget:Update(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local totalKilled = 0
|
local totalKilled, friendliesKilled, hostilesKilled = 0, 0, 0
|
||||||
for i = 1, 10, 1 do --calculate the first half of the table (1-15)
|
local iLast = ((warPointsIter-11) % warPointsSize) + 1 -- Look back 10 periods.
|
||||||
totalKilled = totalKilled + (dethklok[i] * 2)
|
local iLast2 = ((warPointsIter-21) % warPointsSize) + 1 -- Look back 20 periods.
|
||||||
end
|
-- Last 10 seconds count for double
|
||||||
|
friendliesKilled = friendliesKilled + ((warPointsFriendly[warPointsIter] - warPointsFriendly[iLast]) % warPointsRollover)
|
||||||
|
friendliesKilled = friendliesKilled + ((warPointsFriendly[warPointsIter] - warPointsFriendly[iLast2]) % warPointsRollover)
|
||||||
|
hostilesKilled = hostilesKilled + ((warPointsHostile[warPointsIter] - warPointsHostile[iLast]) % warPointsRollover)
|
||||||
|
hostilesKilled = hostilesKilled + ((warPointsHostile[warPointsIter] - warPointsHostile[iLast2]) % warPointsRollover)
|
||||||
|
totalKilled = (friendliesKilled * 1.5) + hostilesKilled
|
||||||
|
|
||||||
for i = 11, 20, 1 do -- calculate the second half of the table (16-45)
|
-- Roll to next index in the circular buffers, continue cumulative sum
|
||||||
totalKilled = totalKilled + dethklok[i]
|
local iNext = (warPointsIter % warPointsSize) + 1
|
||||||
end
|
warPointsFriendly[iNext] = warPointsFriendly[warPointsIter] % warPointsRollover
|
||||||
|
warPointsHostile[iNext] = warPointsHostile[warPointsIter] % warPointsRollover
|
||||||
for i = 20, 1, -1 do -- shift value(s) to the end of table
|
warPointsIter = iNext
|
||||||
dethklok[i+1] = dethklok[i]
|
|
||||||
end
|
|
||||||
dethklok[1] = 0 -- empty the first row
|
|
||||||
|
|
||||||
if (musicType == 'war' or musicType == 'peace') then
|
if (musicType == 'war' or musicType == 'peace') then
|
||||||
if (totalKilled >= warThreshold) then
|
if (totalKilled >= warThreshold) then
|
||||||
|
@ -264,7 +271,7 @@ function widget:Update(dt)
|
||||||
|
|
||||||
if (not firstTime) then
|
if (not firstTime) then
|
||||||
StartTrack()
|
StartTrack()
|
||||||
firstTime = true -- pop this cherry
|
firstTime = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local playedTime, totalTime = Spring.GetSoundStreamTime()
|
local playedTime, totalTime = Spring.GetSoundStreamTime()
|
||||||
|
@ -324,33 +331,25 @@ function widget:GameFrame()
|
||||||
end
|
end
|
||||||
|
|
||||||
function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer)
|
function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer)
|
||||||
if unitExceptions[unitDefID] then
|
if unitExceptions[unitDefID] then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if (damage < 1.5) then return end
|
if (damage < 1.5) then return end
|
||||||
local PlayerTeam = Spring.GetMyTeamID()
|
|
||||||
|
|
||||||
if (UnitDefs[unitDefID] == nil) then return end
|
if (UnitDefs[unitDefID] == nil) then return end
|
||||||
|
if paralyzer then return end
|
||||||
|
|
||||||
if paralyzer then
|
local multifactor = 1
|
||||||
return
|
if (numVisibleEnemy > 3) then
|
||||||
|
multifactor = math.log(numVisibleEnemy)
|
||||||
|
end
|
||||||
|
if (teamID == myTeam) then
|
||||||
|
warPointsFriendly[warPointsIter] = warPointsFriendly[warPointsIter] + (damage * multifactor);
|
||||||
else
|
else
|
||||||
if (teamID == PlayerTeam) then
|
warPointsHostile[warPointsIter] = warPointsHostile[warPointsIter] + (damage * multifactor);
|
||||||
damage = damage * 1.5
|
|
||||||
end
|
|
||||||
local multifactor = 1
|
|
||||||
if (numVisibleEnemy > 3) then
|
|
||||||
multifactor = math.log(numVisibleEnemy)
|
|
||||||
end
|
|
||||||
dethklok[1] = dethklok[1] + (damage * multifactor);
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function widget:UnitDestroyed(unitID, unitDefID, teamID)
|
function widget:UnitDestroyed(unitID, unitDefID, teamID)
|
||||||
if unitExceptions[unitDefID] then
|
if unitExceptions[unitDefID] then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
local unitWorth = 50
|
local unitWorth = 50
|
||||||
if (UnitDefs[unitDefID].metalCost > 500) then
|
if (UnitDefs[unitDefID].metalCost > 500) then
|
||||||
unitWorth = 200
|
unitWorth = 200
|
||||||
|
@ -364,14 +363,16 @@ function widget:UnitDestroyed(unitID, unitDefID, teamID)
|
||||||
if (UnitDefs[unitDefID].metalCost > 8000) then
|
if (UnitDefs[unitDefID].metalCost > 8000) then
|
||||||
unitWorth = 700
|
unitWorth = 700
|
||||||
end
|
end
|
||||||
if (teamID == PlayerTeam) then
|
|
||||||
unitWorth = unitWorth * 1.5
|
|
||||||
end
|
|
||||||
local multifactor = 1
|
local multifactor = 1
|
||||||
if (numVisibleEnemy > 3) then
|
if (numVisibleEnemy > 3) then
|
||||||
multifactor = math.log(numVisibleEnemy)
|
multifactor = math.log(numVisibleEnemy)
|
||||||
end
|
end
|
||||||
dethklok[1] = dethklok[1] + (unitWorth*multifactor);
|
if (teamID == myTeam) then
|
||||||
|
warPointsFriendly[warPointsIter] = warPointsFriendly[warPointsIter] + (unitWorth*multifactor);
|
||||||
|
else
|
||||||
|
warPointsHostile[warPointsIter] = warPointsHostile[warPointsIter] + (unitWorth*multifactor);
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function widget:TeamDied(team)
|
function widget:TeamDied(team)
|
||||||
|
@ -420,8 +421,10 @@ function widget:Initialize()
|
||||||
--math.randomseed(os.clock()* 101.01)--lurker wants you to burn in hell rgn
|
--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,20 do Spring.Echo(math.random()) end
|
||||||
|
|
||||||
for i = 1, 30, 1 do
|
for i = 1, warPointsSize do
|
||||||
dethklok[i]=0
|
warPoints[i] = 0
|
||||||
|
warPointsFriendly[i] = 0
|
||||||
|
warPointsHostile[i] = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue