]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Round handler: fix null function crash
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 28 Oct 2015 02:09:47 +0000 (13:09 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 28 Oct 2015 02:09:47 +0000 (13:09 +1100)
qcsrc/server/round_handler.qc

index e6a1334f88426fec87ff6b2a95ae312391dcfd24..8fb1a787be1904edee99e5e3bd93831fb7f7194d 100644 (file)
 #include "../common/util.qh"
 
 void round_handler_Think()
-{SELFPARAM();
-       float f;
+{
+       SELFPARAM();
 
-       if(time < game_starttime)
+       if (time < game_starttime)
        {
                round_handler_Reset(game_starttime);
                return;
        }
 
-       if(gameover)
+       if (gameover)
        {
                round_handler_Reset(0);
                round_handler_Remove();
                return;
        }
 
-       if(self.wait)
+       if (this.wait)
        {
-               self.wait = false;
-               self.cnt = self.count + 1; // init countdown
-               round_starttime = time + self.count;
+               this.wait = false;
+               this.cnt = this.count + 1;  // init countdown
+               round_starttime = time + this.count;
                reset_map(true);
        }
 
-       if(self.cnt > 0) // countdown running
+       if (this.cnt > 0)  // countdown running
        {
-               if(self.canRoundStart())
+               if (this.canRoundStart())
                {
-                       if(self.cnt == self.count + 1)
-                               round_starttime = time + self.count;
-                       f = self.cnt - 1;
-                       if(f == 0)
+                       if (this.cnt == this.count + 1) round_starttime = time + this.count;
+                       int f = this.cnt - 1;
+                       if (f == 0)
                        {
-                               self.cnt = 0;
-                               self.round_endtime = (self.round_timelimit) ? time + self.round_timelimit : 0;
-                               self.nextthink = time;
-                               if(self.roundStart)
-                                       self.roundStart();
+                               this.cnt = 0;
+                               this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
+                               this.nextthink = time;
+                               if (this.roundStart) this.roundStart();
                                return;
                        }
-                       self.cnt = self.cnt - 1;
+                       this.cnt = this.cnt - 1;
                }
                else
                {
                        round_handler_Reset(0);
                }
-               self.nextthink = time + 1; // canRoundStart every second
+               this.nextthink = time + 1;  // canRoundStart every second
        }
        else
        {
-               if(self.canRoundEnd())
+               if (this.canRoundEnd())
                {
                        // schedule a new round
-                       self.wait = true;
-                       self.nextthink = time + self.delay;
+                       this.wait = true;
+                       this.nextthink = time + this.delay;
                }
                else
                {
-                       self.nextthink = time; // canRoundEnd every frame
+                       this.nextthink = time;  // canRoundEnd every frame
                }
        }
 }
 
 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
 {
-       round_handler.delay = (the_delay > 0) ? the_delay : 0;
-       round_handler.count = fabs(floor(the_count));
-       round_handler.cnt = round_handler.count + 1;
-       round_handler.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
+       entity this = round_handler;
+       this.delay = (the_delay > 0) ? the_delay : 0;
+       this.count = fabs(floor(the_count));
+       this.cnt = this.count + 1;
+       this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
 }
 
 // NOTE: this is only needed because if round_handler spawns at time 1
 // gamestarttime isn't initialized yet
 void round_handler_FirstThink()
 {
-       round_starttime = max(time, game_starttime) + round_handler.count;
-       round_handler.think = round_handler_Think;
-       round_handler.nextthink = max(time, game_starttime);
+       SELFPARAM();
+       round_starttime = max(time, game_starttime) + this.count;
+       this.think = round_handler_Think;
+       this.nextthink = max(time, game_starttime);
 }
 
 void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func)
 {
-       if(round_handler)
+       if (round_handler)
        {
                backtrace("Can't spawn round_handler again!");
                return;
        }
-       round_handler = spawn();
-       round_handler.classname = "round_handler";
+       entity this = round_handler = new(round_handler);
 
-       round_handler.think = round_handler_FirstThink;
-       round_handler.canRoundStart = canRoundStart_func;
-       round_handler.canRoundEnd = canRoundEnd_func;
-       round_handler.roundStart = roundStart_func;
-       round_handler.wait = false;
+       this.think = round_handler_FirstThink;
+       this.canRoundStart = canRoundStart_func;
+       this.canRoundEnd = canRoundEnd_func;
+       this.roundStart = roundStart_func;
+       this.wait = false;
        round_handler_Init(5, 5, 180);
-       round_handler.nextthink = time;
+       this.nextthink = time;
 }
 
 void round_handler_Reset(float next_think)
 {
-       round_handler.wait = false;
-       if(round_handler.count)
-       if(round_handler.cnt < round_handler.count + 1)
-               round_handler.cnt = round_handler.count + 1;
-       round_handler.nextthink = next_think;
-       round_starttime = (next_think) ? (next_think + round_handler.count) : -1;
+       entity this = round_handler;
+       this.wait = false;
+       if (this.count)
+               if (this.cnt < this.count + 1) this.cnt = this.count + 1;
+       this.nextthink = next_think;
+       round_starttime = (next_think) ? (next_think + this.count) : -1;
 }
 
 void round_handler_Remove()
@@ -118,4 +117,3 @@ void round_handler_Remove()
        remove(round_handler);
        round_handler = world;
 }
-