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