module LinkedListNode
readonly static thistype array first
readonly static thistype array last
readonly thistype next
readonly thistype prev
readonly integer list
public static method addNode takes integer list returns thistype
local thistype this
if list == 0 then
return 0
endif
set this = .allocate()
set .list = list
set .last[list].next = this
set .prev = .last[list]
set .last[list] = this
if .first[list] == 0 then
set .first[list] = this
endif
return this
endmethod
public static method insertNode takes integer list, thistype node returns thistype
local thistype this
if list == 0 then
return 0
elseif node == 0 then
return .addNode(list)
elseif node.list != list then
return 0
endif
set this = .allocate()
set .list = list
set .prev = node.prev
set node.prev.next = this
set node.prev = this
set .next = node
if .first[list] == node then
set .first[list] = this
endif
return this
endmethod
public method removeNode takes nothing returns nothing
set .next.prev = .prev
set .prev.next = .next
if this == .last[list] then
set .last[list] = .prev
endif
if this == .first[list] then
set .first[list] = .next
endif
set .list = 0
set .next = 0
set .prev = 0
call .deallocate()
endmethod
endmodule
struct DamageTrackingNode
implement LinkedListNode
readonly real value
readonly real timestamp
public static method add takes integer list, real value returns thistype
local thistype this = .addNode(list)
if this == 0 then
return this
endif
set .value = value
set .timestamp = GetElapsedGameTime()
return this
endmethod
public static method insert takes integer list, thistype node, real value returns thistype
local thistype this = .insertNode(list, node)
if this == 0 then
return this
endif
set .value = value
set .timestamp = GetElapsedGameTime()
return this
endmethod
public method remove takes nothing returns nothing
call .removeNode()
//set .value = 0.
//set .timestamp = 0.
endmethod
endstruct
struct DamageTrackingList
public static method create takes nothing returns thistype
return .allocate()
endmethod
public method add takes real value returns DamageTrackingNode
return DamageTrackingNode.add(this, value)
endmethod
public method insert takes thistype node, real value returns DamageTrackingNode
return DamageTrackingNode.insert(this, node, value)
endmethod
public method first takes nothing returns DamageTrackingNode
return DamageTrackingNode.first[this]
endmethod
endstruct
struct DamageTracking
private static constant integer PLAYER_MAX = 8
private static constant real TIMEOUT = 7.00
readonly static thistype array get
private DamageTrackingList array damagesList[.PLAYER_MAX]
private static method create takes nothing returns thistype
local thistype this = .allocate()
local integer i = 0
loop
exitwhen i >= .PLAYER_MAX
set .damagesList[i] = DamageTrackingList.create()
set i = i +1
endloop
return this
endmethod
public method addDamage takes integer playerId, real damage returns nothing
call .damagesList[playerId].add(damage)
endmethod
public method getDamage takes integer playerId returns real
local DamageTrackingNode curr
local DamageTrackingNode next = .damagesList[playerId].first()
local real result = 0
local real timestamp = GetElapsedGameTime() - .TIMEOUT
loop
exitwhen next == 0
set curr = next
set next = curr.next
if curr.timestamp < timestamp then
call curr.remove()
else
set result = result + curr.value
endif
endloop
return result
endmethod
private static method onInit takes nothing returns nothing
local integer i = 0
loop
exitwhen i >= .PLAYER_MAX
set .get[i] = .create()
set i = i +1
endloop
endmethod
endstruct