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