]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/round_handler.qc
round_handler: be sure to reset the countdown when warmup stage ends
[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.nextthink = time;
42                                 return;
43                         }
44
45                         FOR_EACH_REALCLIENT(e)
46                                 Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f);
47                         self.cnt = self.cnt - 1;
48                 }
49                 else
50                 {
51                         round_handler_Reset(0);
52                 }
53                 self.nextthink = time + 1; // canRoundStart every second
54         }
55         else
56         {
57                 if(self.canRoundEnd())
58                 {
59                         // schedule a new round
60                         self.wait = TRUE;
61                         self.nextthink = time + self.delay;
62                 }
63                 else
64                 {
65                         self.nextthink = time; // canRoundEnd every frame
66                 }
67         }
68 }
69
70 void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, float the_delay, float the_count)
71 {
72         if(round_handler)
73         {
74                 backtrace("Can't spawn round_handler again!");
75                 return;
76         }
77         round_handler = spawn();
78         round_handler.classname = "round_handler";
79
80         round_handler.think = round_handler_Think;
81         round_handler.canRoundStart = canRoundStart_func;
82         round_handler.canRoundEnd = canRoundEnd_func;
83         round_handler.delay = (the_delay > 0) ? the_delay : 0;
84         round_handler.count = fabs(floor(the_count));
85         round_handler.wait = FALSE;
86         round_handler.cnt = round_handler.count + 1;
87         round_handler.nextthink = max(time, game_starttime + 1);
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 void round_handler_Reset(float next_think)
111 {
112         entity e;
113         round_handler.wait = FALSE;
114         if(round_handler.count)
115         if(round_handler.cnt < round_handler.count + 1)
116         {
117                 FOR_EACH_REALCLIENT(e)
118                         Send_CSQC_Centerprint_Generic_Expire(e, CPID_ROUND_STARTING);
119                 round_handler.cnt = round_handler.count + 1;
120         }
121         round_handler.nextthink = next_think;
122 }
123
124 void round_handler_Remove()
125 {
126         remove(round_handler);
127         round_handler = world;
128 }
129