]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/round_handler.qc
CA: newcomer players can only join the game during the countdown to round start;...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / round_handler.qc
1 void round_handler_Think()
2 {
3         float f;
4
5         if(time < game_starttime)
6         {
7                 round_handler_Reset(game_starttime);
8                 return;
9         }
10
11         if(gameover)
12         {
13                 round_handler_Reset(0);
14                 round_handler_Remove();
15                 return;
16         }
17
18         if(self.wait)
19         {
20                 self.wait = FALSE;
21                 self.cnt = self.count + 1; // init countdown
22                 round_starttime = time + self.count;
23                 reset_map(TRUE);
24         }
25
26         if(self.cnt > 0) // countdown running
27         {
28                 if(self.canRoundStart())
29                 {
30                         if(self.cnt == self.count + 1)
31                                 round_starttime = time + self.count;
32                         f = self.cnt - 1;
33                         if(f == 0)
34                         {
35                                 self.cnt = 0;
36                                 self.round_endtime = time + self.round_timelimit;
37                                 self.nextthink = time;
38                                 if(self.roundStart)
39                                         self.roundStart();
40                                 return;
41                         }
42                         self.cnt = self.cnt - 1;
43                 }
44                 else
45                 {
46                         round_handler_Reset(0);
47                 }
48                 self.nextthink = time + 1; // canRoundStart every second
49         }
50         else
51         {
52                 if(self.canRoundEnd())
53                 {
54                         // schedule a new round
55                         self.wait = TRUE;
56                         self.nextthink = time + self.delay;
57                 }
58                 else
59                 {
60                         self.nextthink = time; // canRoundEnd every frame
61                 }
62         }
63 }
64
65 void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func, float the_delay, float the_count, float the_round_timelimit)
66 {
67         if(round_handler)
68         {
69                 backtrace("Can't spawn round_handler again!");
70                 return;
71         }
72         round_handler = spawn();
73         round_handler.classname = "round_handler";
74
75         round_handler.think = round_handler_Think;
76         round_handler.canRoundStart = canRoundStart_func;
77         round_handler.canRoundEnd = canRoundEnd_func;
78         round_handler.roundStart = roundStart_func;
79         round_handler.delay = (the_delay > 0) ? the_delay : 0;
80         round_handler.count = fabs(floor(the_count));
81         round_handler.wait = FALSE;
82         round_handler.cnt = round_handler.count + 1;
83         round_handler.round_timelimit = the_round_timelimit;
84         // if round_handler spawns at time 1 gamestarttime isn't initialized yet
85         //round_handler.nextthink = max(time, game_starttime + 1);
86         round_handler.nextthink = time;
87         round_starttime = time + round_handler.count;
88 }
89
90 float round_handler_IsActive()
91 {
92         return (round_handler != world);
93 }
94
95 float round_handler_AwaitingNextRound()
96 {
97         return (round_handler.wait);
98 }
99
100 float round_handler_CountdownRunning()
101 {
102         return (!round_handler.wait && round_handler.cnt);
103 }
104
105 float round_handler_IsRoundStarted()
106 {
107         return (!round_handler.wait && !round_handler.cnt);
108 }
109
110 float round_handler_GetTimeLeft()
111 {
112         return (round_handler.round_endtime - time);
113 }
114
115 void round_handler_Reset(float next_think)
116 {
117         round_handler.wait = FALSE;
118         if(round_handler.count)
119         if(round_handler.cnt < round_handler.count + 1)
120                 round_handler.cnt = round_handler.count + 1;
121         round_handler.nextthink = next_think;
122         round_starttime = (next_think) ? (next_think + round_handler.count) : -1;
123 }
124
125 void round_handler_Remove()
126 {
127         remove(round_handler);
128         round_handler = world;
129 }
130