]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/round_handler.qc
Fix FL_WEAPON flag overlapping FL_JUMPRELEASED. This unintentional change was introdu...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / round_handler.qc
1 #include "round_handler.qh"
2
3 #include <common/mapobjects/triggers.qh>
4 #include <common/util.qh>
5 #include <server/campaign.qh>
6 #include <server/command/vote.qh>
7 #include <server/world.qh>
8
9 void round_handler_Think(entity this)
10 {
11         if (intermission_running)
12         {
13                 round_handler_Reset(0);
14                 round_handler_Remove();
15                 return;
16         }
17
18         if (time < game_starttime)
19         {
20                 round_handler_Reset(game_starttime);
21                 return;
22         }
23
24         game_stopped = false;
25
26         if (this.wait)
27         {
28                 this.wait = false;
29                 this.cnt = this.count + 1;  // init countdown
30                 round_starttime = time + this.count;
31                 reset_map(true, false);
32         }
33
34         if (this.cnt > 0)  // countdown running
35         {
36                 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
37                 {
38                         if (this.cnt == this.count + 1) round_starttime = time + this.count;
39                         int f = this.cnt - 1;
40                         if (f == 0)
41                         {
42                                 this.cnt = 0;
43                                 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
44                                 this.nextthink = time;
45                                 rounds_played++;
46                                 if (this.roundStart) this.roundStart();
47                                 return;
48                         }
49                         this.cnt = this.cnt - 1;
50                 }
51                 else
52                 {
53                         round_handler_Reset(0);
54                         round_starttime = -1; // can't start
55                 }
56                 this.nextthink = time + 1;  // canRoundStart every second
57         }
58         else
59         {
60                 if (this.canRoundEnd())
61                 {
62                         // schedule a new round
63                         this.wait = true;
64                         this.nextthink = time + this.delay;
65                 }
66                 else
67                 {
68                         this.nextthink = time;  // canRoundEnd every frame
69                 }
70         }
71 }
72
73 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
74 {
75         entity this = round_handler;
76         this.delay = (the_delay > 0) ? the_delay : 0;
77         this.count = fabs(floor(the_count));
78         this.cnt = this.count + 1;
79         this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
80         round_limit = the_round_timelimit;
81 }
82
83 // NOTE: this is only needed because if round_handler spawns at time 1
84 // game_starttime isn't initialized yet
85 void round_handler_FirstThink(entity this)
86 {
87         round_starttime = max(time, game_starttime) + this.count;
88         setthink(this, round_handler_Think);
89         this.nextthink = max(time, game_starttime);
90 }
91
92 void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
93 {
94         if (round_handler)
95         {
96                 backtrace("Can't spawn round_handler again!");
97                 return;
98         }
99         entity this = round_handler = new_pure(round_handler);
100
101         setthink(this, round_handler_FirstThink);
102         this.canRoundStart = canRoundStart_func;
103         this.canRoundEnd = canRoundEnd_func;
104         this.roundStart = roundStart_func;
105         this.wait = false;
106         round_handler_Init(5, 5, 180);
107         this.nextthink = time;
108 }
109
110 void round_handler_Reset(float next_think)
111 {
112         entity this = round_handler;
113         this.wait = false;
114         if (this.count)
115                 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
116         this.nextthink = next_think;
117         if (next_think)
118         {
119                 if (next_think <= game_starttime) rounds_played = 0;
120                 round_starttime = next_think + this.count;
121         }
122 }
123
124 void round_handler_Remove()
125 {
126         delete(round_handler);
127         round_handler = NULL;
128 }