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