21 lines
880 B
C
21 lines
880 B
C
// One finite response per delivered observation at this battery. Cancellation
|
|
// does not turn the same radio message into new ammunition authorization.
|
|
class ERR_MortarReportLedger
|
|
{
|
|
protected ref map<int, float> m_Attempts = new map<int, float>();
|
|
|
|
bool Available(int messageId, float observedAt, float now)
|
|
{
|
|
if (messageId <= 0 || observedAt < 0 || now < observedAt || now - observedAt > ERR_MortarPrediction.MAX_REPORT_AGE_MS) return false;
|
|
for (int i = m_Attempts.Count() - 1; i >= 0; i--)
|
|
if (now - m_Attempts.GetElement(i) > ERR_MortarPrediction.MAX_REPORT_AGE_MS) m_Attempts.Remove(m_Attempts.GetKey(i));
|
|
return !m_Attempts.Contains(messageId) && m_Attempts.Count() < 128;
|
|
}
|
|
bool Claim(int messageId, float observedAt, float now)
|
|
{
|
|
if (!Available(messageId, observedAt, now)) return false;
|
|
m_Attempts.Insert(messageId, observedAt);
|
|
return true;
|
|
}
|
|
}
|