Permalink
Browse files

Fixed failed construction of timers during inheritance, which caused …

…hunting rifle limiting to break quite often.
  • Loading branch information...
1 parent b99fe23 commit fd6c81ba40e7143d26d807958625be8095f926ac @ProdigySim committed Jul 5, 2012
@@ -18,7 +18,7 @@ if(getroottable().rawin("CompLite"))
return;
}
-Msg("Activating Mutation CompLite\n");
+Msg("Activating Mutation CompLite v3.0\n");
::CompLite <- {
Globals = {
@@ -59,7 +59,7 @@ Msg("Activating Mutation CompLite\n");
}
DirectorOptions <- ::CompLite.ChallengeScript.DirectorOptions;
-Update <- CompLite.ChallengeScript.Update;
+Update <- ::CompLite.ChallengeScript.Update;
@@ -81,7 +81,9 @@ Modules <- ::CompLite.Modules;
g_MapInfo.IdentifyMap(Entities);
-g_GSC.AddListener(Modules.MsgGSL());
+// Uncomment to add a debug event listener
+//g_GSC.AddListener(Modules.MsgGSL());
+
g_GSC.AddListener(Modules.SpitterControl(Director, DirectorOptions));
g_GSC.AddListener(Modules.MobControl(g_MobResetti));
@@ -76,7 +76,6 @@ class ::CompLite.GameState.GameStateModel
m_bHeardCWS = false;
m_bHeardGDI = false;
m_iRoundStartTime = 0;
- m_bLastUpdateTankInPlay = false;
m_bLastUpdateSafeAreaOpened = false;
}
@@ -47,6 +47,11 @@ class ::CompLite.Timers.TimerCallback
class ::CompLite.Timers.GlobalTimer
{
+ constructor()
+ {
+ m_callbacks = array(0);
+ m_cbtimes = array(0);
+ }
// Returns the current time in some format that supports arithmetic operations
// Overload this in your final class
function GetCurrentTime() { assert(null) }
@@ -58,9 +63,11 @@ class ::CompLite.Timers.GlobalTimer
{
while(m_cbtimes.len() && m_cbtimes[0] < GetCurrentTime())
{
- m_callbacks[0].OnTimerElapsed();
+ //Msg("Executing timer at "+GetCurrentTime()+" ("+Time()+") elapsed "+m_cbtimes[0]+"\n");
+ local cb = m_callbacks[0];
m_callbacks.remove(0);
m_cbtimes.remove(0);
+ cb.OnTimerElapsed();
}
}
@@ -72,6 +79,7 @@ class ::CompLite.Timers.GlobalTimer
function AddTimer(time, timer)
{
local cbtime = GetCurrentTime() + time;
+ //Msg("Adding time at "+GetCurrentTime()+" ("+Time()+") for "+cbtime+"\n");
// Insert sorted Ascending by end timestamp (cbtime) into callbacks list
local i = 0;
// TODO: Binary search
@@ -88,8 +96,8 @@ class ::CompLite.Timers.GlobalTimer
}
}
- m_callbacks = [];
- m_cbtimes = [];
+ m_callbacks = null;
+ m_cbtimes = null;
}
class ::CompLite.Timers.GlobalSecondsTimer extends ::CompLite.Timers.GlobalTimer
@@ -277,27 +277,48 @@ class ::CompLite.Modules.HRControl extends ::CompLite.GameState.GameStateListene
m_pEntities = entlist;
m_pTimer = gtimer;
}
- function OnGetDefaultItem(idx)
+
+ function QueueCheck()
{
- local round = ::CompLite.Utils.GetCurrentRound();
- if(round > 0 && !m_bTriggeredThisRound[round-1])
+ if(!m_bCheckInProgress)
+ {
+ // 2 seconds after any GDI or rstart
+ m_bCheckInProgress = true;
+ //Msg("Queueing HR Check at "+Time()+"\n");
+ m_pTimer.AddTimer(2,this);
+ }
+ else
{
- // Process HRs 2s after they're handed out
- m_pTimer.AddTimer(2,this);
- m_bTriggeredThisRound[round-1] = true;
+ m_bCheckQueued = true;
}
}
+ function OnGetDefaultItem(idx)
+ {
+ local round = ::CompLite.Utils.GetCurrentRound();
+ if(round > 0 && m_bPostRoundStart[round-1]) QueueCheck();
+ }
+ function OnRoundStart(roundNumber)
+ {
+ QueueCheck();
+ m_bPostRoundStart[roundNumber-1] = true;
+ }
// Not actually inherited but it doesn't need to be.
function OnTimerElapsed()
{
+ m_bCheckInProgress = false;
+ if(m_bCheckQueued)
+ {
+ m_bCheckQueued = false;
+ QueueCheck();
+ }
local ent = null;
local hrList = [];
while((ent = m_pEntities.FindByClassname(ent, "weapon_hunting_rifle")) != null)
{
hrList.push(ent);
}
- Msg("Found "+hrList.len()+" HRs this check\n");
+ //Msg("Found "+hrList.len()+" HRs this check at "+Time()+"\n");
if(!::CompLite.Globals.MapInfo.isIntro)
{
@@ -306,6 +327,8 @@ class ::CompLite.Modules.HRControl extends ::CompLite.GameState.GameStateListene
// Save 1 HR at random
hrList.remove(RandomInt(0,hrList.len()-1));
}
+
+ //Msg("Still have "+hrList.len()+"!\n");
// Delete the rest
foreach(hr in hrList)
@@ -315,5 +338,7 @@ class ::CompLite.Modules.HRControl extends ::CompLite.GameState.GameStateListene
}
m_pEntities = null;
m_pTimer = null;
- m_bTriggeredThisRound = [false, false];
+ m_bCheckInProgress = false;
+ m_bPostRoundStart = [false,false];
+ m_bCheckQueued = false;
}

0 comments on commit fd6c81b

Please sign in to comment.