4 .entity spawnqueue_next;
5 .entity spawnqueue_prev;
7 entity spawnqueue_first;
8 entity spawnqueue_last;
10 void Spawnqueue_Insert(entity e)
14 dprint(strcat("Into queue: ", e.netname, "\n"));
15 e.spawnqueue_in = TRUE;
16 e.spawnqueue_prev = spawnqueue_last;
17 e.spawnqueue_next = world;
19 spawnqueue_last.spawnqueue_next = e;
25 void Spawnqueue_Remove(entity e)
29 dprint(strcat("Out of queue: ", e.netname, "\n"));
30 e.spawnqueue_in = FALSE;
31 if(e == spawnqueue_first)
32 spawnqueue_first = e.spawnqueue_next;
33 if(e == spawnqueue_last)
34 spawnqueue_last = e.spawnqueue_prev;
36 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
38 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
39 e.spawnqueue_next = world;
40 e.spawnqueue_prev = world;
43 void Spawnqueue_Unmark(entity e)
48 numspawned = numspawned - 1;
51 void Spawnqueue_Mark(entity e)
56 numspawned = numspawned + 1;
59 float Arena_CheckWinner()
63 if(round_handler_GetTimeLeft() <= 0)
65 FOR_EACH_REALCLIENT(e)
66 centerprint(e, "Round over, there's no winner");
67 bprint("Round over, there's no winner\n");
78 if(e.spawned && e.classname == "player")
84 FOR_EACH_REALCLIENT(e)
85 centerprint(e, strcat("The Champion is ", champion.netname));
86 bprint("The Champion is ", champion.netname, "\n");
87 UpdateFrags(champion, +1);
91 FOR_EACH_REALCLIENT(e)
92 centerprint(e, "Round tied");
93 bprint("Round tied\n");
98 void Arena_AddChallengers()
102 while(numspawned < maxspawned && spawnqueue_first)
104 self = spawnqueue_first;
106 bprint ("^4", self.netname, "^4 is the next challenger\n");
108 Spawnqueue_Remove(self);
109 Spawnqueue_Mark(self);
111 self.classname = "player";
117 float prev_numspawned;
118 float Arena_CheckPlayers()
122 Arena_AddChallengers();
126 if(prev_numspawned != -1)
128 FOR_EACH_REALCLIENT(e)
129 Send_CSQC_Centerprint_Generic_Expire(e, CPID_WAITING_PLAYERS);
131 prev_numspawned = -1;
135 if(prev_numspawned != numspawned && numspawned == 1)
137 FOR_EACH_REALCLIENT(e)
138 Send_CSQC_Centerprint_Generic(e, CPID_WAITING_PLAYERS, "Waiting for players to join...", -1, 0);
139 prev_numspawned = numspawned;
145 void Arena_RoundStart()
149 e.player_blocked = 0;
152 MUTATOR_HOOKFUNCTION(arena_ClientDisconnect)
154 Spawnqueue_Unmark(self);
155 Spawnqueue_Remove(self);
159 MUTATOR_HOOKFUNCTION(arena_reset_map_players)
161 FOR_EACH_CLIENT(self)
166 self.player_blocked = 1;
169 PutObserverInServer();
174 MUTATOR_HOOKFUNCTION(arena_MakePlayerObserver)
176 if(self.version_mismatch)
178 self.frags = FRAGS_SPECTATOR;
179 Spawnqueue_Unmark(self);
180 Spawnqueue_Remove(self);
184 self.frags = FRAGS_LMS_LOSER;
185 Spawnqueue_Insert(self);
190 MUTATOR_HOOKFUNCTION(arena_PutClientInServer)
193 self.classname = "observer";
197 MUTATOR_HOOKFUNCTION(arena_ClientConnect)
199 self.classname = "observer";
200 Spawnqueue_Insert(self);
204 MUTATOR_HOOKFUNCTION(arena_PlayerSpawn)
206 Spawnqueue_Remove(self);
207 Spawnqueue_Mark(self);
209 self.player_blocked = 1;
213 MUTATOR_HOOKFUNCTION(arena_PlayerPreThink)
215 self.stat_respawn_time = 0;
217 // put dead players in the spawn queue
219 if(self.deadflag && time - self.death_time >= 1.5)
225 MUTATOR_HOOKFUNCTION(arena_ForbidPlayerScore_Clear)
230 MUTATOR_HOOKFUNCTION(arena_GiveFragsForKill)
233 frag_score = 0; // score will be given to the champion when the round ends
237 MUTATOR_HOOKFUNCTION(arena_PlayerDies)
239 Spawnqueue_Unmark(self);
243 MUTATOR_HOOKFUNCTION(arena_SV_StartFrame)
245 if(arena_roundbased) return 1;
246 if(time <= game_starttime) return 1;
247 if(gameover) return 1;
249 Arena_AddChallengers();
253 void arena_Initialize()
255 maxspawned = max(2, autocvar_g_arena_maxspawned);
256 arena_roundbased = autocvar_g_arena_roundbased;
258 round_handler_Spawn(Arena_CheckPlayers, Arena_CheckWinner, Arena_RoundStart, 5, autocvar_g_arena_warmup, autocvar_g_arena_round_timelimit);
261 MUTATOR_DEFINITION(gamemode_arena)
263 MUTATOR_HOOK(ClientDisconnect, arena_ClientDisconnect, CBC_ORDER_ANY);
264 MUTATOR_HOOK(reset_map_players, arena_reset_map_players, CBC_ORDER_ANY);
265 MUTATOR_HOOK(MakePlayerObserver, arena_MakePlayerObserver, CBC_ORDER_ANY);
266 MUTATOR_HOOK(PutClientInServer, arena_PutClientInServer, CBC_ORDER_ANY);
267 MUTATOR_HOOK(ClientConnect, arena_ClientConnect, CBC_ORDER_ANY);
268 MUTATOR_HOOK(PlayerSpawn, arena_PlayerSpawn, CBC_ORDER_ANY);
269 MUTATOR_HOOK(PlayerPreThink, arena_PlayerPreThink, CBC_ORDER_ANY);
270 MUTATOR_HOOK(ForbidPlayerScore_Clear, arena_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
271 MUTATOR_HOOK(GiveFragsForKill, arena_GiveFragsForKill, CBC_ORDER_ANY);
272 MUTATOR_HOOK(PlayerDies, arena_PlayerDies, CBC_ORDER_ANY);
273 MUTATOR_HOOK(SV_StartFrame, arena_SV_StartFrame, CBC_ORDER_ANY);
277 if(time > 1) // game loads at time 1
278 error("This is a game type and it cannot be added at runtime.");
284 print("This is a game type and it cannot be removed at runtime.");