]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/arena.qc
DP_QC_URI_ESCAPE
[divverent/nexuiz.git] / data / qcsrc / server / arena.qc
1 float maxspawned;
2 float numspawned;
3 float arena_roundbased;
4 .float spawned;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
7 .float spawnqueue_in;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
10 entity champion;
11 float warmup;
12
13 void PutObserverInServer();
14 void PutClientInServer();
15 void(entity e) DropFlag;
16 void(entity e) ReturnFlag;
17 void(entity e) removedecor;
18 void dom_controlpoint_setup();
19
20 void reset_map()
21 {
22         if(g_arena)
23         if(cvar("g_arena_warmup"))
24                 warmup = time + cvar("g_arena_warmup");
25         
26         lms_lowest_lives = 999;
27         lms_next_place = player_count;
28
29         self = nextent(world);
30         while(self)
31         {
32                 if(self.flags & FL_CLIENT)                              // reset all players
33                 {
34                         if(time < restart_countdown)
35                         {
36                                 self.frags = (g_lms)?LMS_NewPlayerLives():0;
37                                 self.deaths = 0;
38                                 self.killcount = 0;
39                                 self.classname = "player";
40                                 PutClientInServer();
41                         }
42                         else if(g_arena)
43                         {
44                                 if(self.spawned)
45                                         PutClientInServer();
46                                 else
47                                         PutObserverInServer();
48                         }
49                 }
50                 else if(self.classname == STR_ITEM_KH_KEY)
51                 {
52                         kh_Key_AssignTo(self, world);
53                         //if(self.owner)
54                         //      kh_Key_DropAll(self.owner, TRUE);
55                         kh_Key_Remove(self);
56                 }
57                 else if(self.classname == "droppedweapon"               // cleanup
58                                 || self.classname == "gib"
59                                 || self.classname == "body")
60                 {
61                         remove(self);
62                 }
63                 else if(self.items & (IT_KEY1 | IT_KEY2))
64                 {
65                         DropFlag(self);
66                         ReturnFlag(self);
67                 }
68                 else if(self.classname == "rune")
69                 {
70                         if(self.owner)
71                         if(self.owner.classname != "runematch_spawn_point")
72                                 DropAllRunes(self.owner);
73                         rune_respawn();
74                 }
75                 else if(self.classname == "sprite_waypoint")
76                 {
77                         if(self.health | g_keyhunt)
78                                 WaypointSprite_Kill(self);
79                 }
80                 else if(self.classname == "dom_controlpoint")
81                 {
82                         dom_controlpoint_setup();
83                 }
84                 else if(self.classname == "info_player_deathmatch")
85                 {
86                         self.team = self.team_saved; // reset spawns to their original state too!
87                 }
88                 else if(self.flags & FL_ITEM)                   // reset items
89                 {
90                         self.model = self.mdl;
91                         self.solid = SOLID_TRIGGER;
92                         setorigin (self, self.origin);
93                         self.think = SUB_Null;
94                         self.nextthink = 0;
95                 }
96                 else if(self.flags & FL_PROJECTILE)             // remove any projectiles left
97                 {
98                         sound(self, CHAN_BODY, "misc/null.wav", 1, ATTN_NORM);
99                         remove(self);
100                 }
101                 else if(self.isdecor)
102                 {
103                         removedecor(self);
104                 }
105                 // TODO properly reset Onslaught
106                 // TODO properly reset Assault
107                 self = nextent(self);
108         }
109
110         if(g_keyhunt)
111                 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+RESTART_COUNTDOWN, "", kh_StartRound);
112
113         if(g_arena)
114         if(champion)
115                 UpdateFrags(champion, +1);
116 }
117
118 void Spawnqueue_Insert(entity e)
119 {
120         if(e.spawnqueue_in)
121                 return;
122         dprint(strcat("Into queue: ", e.netname, "\n"));
123         e.spawnqueue_in = TRUE;
124         e.spawnqueue_prev = spawnqueue_last;
125         e.spawnqueue_next = world;
126         if(spawnqueue_last)
127                 spawnqueue_last.spawnqueue_next = e;
128         spawnqueue_last = e;
129         if(!spawnqueue_first)
130                 spawnqueue_first = e;
131 }
132
133 void Spawnqueue_Remove(entity e)
134 {
135         if(!e.spawnqueue_in)
136                 return;
137         dprint(strcat("Out of queue: ", e.netname, "\n"));
138         e.spawnqueue_in = FALSE;
139         if(e == spawnqueue_first)
140                 spawnqueue_first = e.spawnqueue_next;
141         if(e == spawnqueue_last)
142                 spawnqueue_last = e.spawnqueue_prev;
143         if(e.spawnqueue_prev)
144                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
145         if(e.spawnqueue_next)
146                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
147         e.spawnqueue_next = world;
148         e.spawnqueue_prev = world;
149 }
150
151 void Spawnqueue_Unmark(entity e)
152 {
153         if(!e.spawned)
154                 return;
155         e.spawned = FALSE;
156         numspawned = numspawned - 1;
157 }
158
159 void Spawnqueue_Mark(entity e)
160 {
161         if(e.spawned)
162                 return;
163         e.spawned = TRUE;
164         numspawned = numspawned + 1;
165 }
166
167 void Arena_Warmup()
168 {
169         float f;
170         string msg;
171
172         if(!g_arena || !arena_roundbased || (time < restart_countdown))
173                 return;
174
175         f = rint(warmup - time);
176
177         msg = NEWLINES;
178         if(time < warmup && self.spawned)
179         {
180                 if(champion)
181                         msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
182
183                 if(f)
184                         msg = strcat(msg, "Round will start in ", ftos(f));
185                 else
186                 {
187                         if(self.spawned)
188                                 msg = strcat(msg, "^1Fight!");
189                 }
190
191                 centerprint(self, msg);
192
193                 if(self.spawned)
194                         self.movetype = MOVETYPE_NONE;
195
196                 self.velocity = '0 0 0';
197                 self.avelocity = '0 0 0';
198                 self.movement = '0 0 0';
199                 //self.fixangle = TRUE;
200         }
201         else if(self.movetype == MOVETYPE_NONE)
202         {
203                 self.movetype = MOVETYPE_WALK;
204                 centerprint(self, "\n");
205         }
206
207 }
208
209 float next_round;
210 void Spawnqueue_Check()
211 {
212         if(time < warmup + 1)
213                 return;
214
215         if(!next_round)
216         if(numspawned < 2)
217                 next_round = time + 3;
218
219         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
220         {
221                 next_round = 0;
222
223                 if(arena_roundbased)
224                 {
225                         champion = find(world, classname, "player");
226                         while(champion && champion.deadflag)
227                                 champion = find(champion, classname, "player");
228                         reset_map();
229                 }
230
231                 while(numspawned < maxspawned && spawnqueue_first)
232                 {
233                         self = spawnqueue_first;
234
235                         bprint ("^4", self.netname, "^4 is the next challenger\n");
236
237                         Spawnqueue_Remove(self);
238                         Spawnqueue_Mark(self);
239
240                         self.classname = "player";
241                         PutClientInServer();
242                 }
243         }
244 }