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 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
66 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
67 round_handler_Init(5, autocvar_g_arena_warmup, autocvar_g_arena_round_timelimit);
78 if(e.spawned && IS_PLAYER(e))
84 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_PLAYER_WIN, champion.netname);
85 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_PLAYER_WIN, champion.netname);
86 UpdateFrags(champion, +1);
90 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
91 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
93 round_handler_Init(5, autocvar_g_arena_warmup, autocvar_g_arena_round_timelimit);
97 void Arena_AddChallengers()
101 while(numspawned < maxspawned && spawnqueue_first)
103 self = spawnqueue_first;
105 bprint ("^4", self.netname, "^4 is the next challenger\n");
107 Spawnqueue_Remove(self);
108 Spawnqueue_Mark(self);
110 self.classname = "player";
116 float prev_numspawned;
117 float Arena_CheckPlayers()
119 Arena_AddChallengers();
123 if(prev_numspawned > 0)
124 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_PLAYERS);
125 prev_numspawned = -1;
129 if(prev_numspawned != numspawned && numspawned == 1)
131 if(maxspawned - numspawned > 0)
132 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_PLAYERS, maxspawned - numspawned);
133 prev_numspawned = numspawned;
139 void Arena_RoundStart()
143 e.player_blocked = 0;
146 MUTATOR_HOOKFUNCTION(arena_ClientDisconnect)
148 Spawnqueue_Unmark(self);
149 Spawnqueue_Remove(self);
153 MUTATOR_HOOKFUNCTION(arena_reset_map_players)
155 FOR_EACH_CLIENT(self)
160 self.player_blocked = 1;
163 PutObserverInServer();
168 MUTATOR_HOOKFUNCTION(arena_MakePlayerObserver)
170 if(self.version_mismatch)
172 self.frags = FRAGS_SPECTATOR;
173 Spawnqueue_Unmark(self);
174 Spawnqueue_Remove(self);
178 self.frags = FRAGS_LMS_LOSER;
179 Spawnqueue_Insert(self);
184 MUTATOR_HOOKFUNCTION(arena_PutClientInServer)
187 self.classname = "observer";
191 MUTATOR_HOOKFUNCTION(arena_ClientConnect)
193 self.classname = "observer";
194 Spawnqueue_Insert(self);
198 MUTATOR_HOOKFUNCTION(arena_PlayerSpawn)
200 Spawnqueue_Remove(self);
201 Spawnqueue_Mark(self);
203 self.player_blocked = 1;
207 MUTATOR_HOOKFUNCTION(arena_ForbidPlayerScore_Clear)
212 MUTATOR_HOOKFUNCTION(arena_GiveFragsForKill)
215 frag_score = 0; // score will be given to the champion when the round ends
219 MUTATOR_HOOKFUNCTION(arena_PlayerDies)
221 // put dead players in the spawn queue
223 self.respawn_flags = (RESPAWN_FORCE | RESPAWN_SILENT);
225 self.respawn_flags = RESPAWN_SILENT;
226 Spawnqueue_Unmark(self);
230 MUTATOR_HOOKFUNCTION(arena_SV_StartFrame)
232 if(gameover) return 1;
233 if(time <= game_starttime || !arena_roundbased)
234 Arena_AddChallengers();
238 void arena_Initialize()
240 maxspawned = max(2, autocvar_g_arena_maxspawned);
241 arena_roundbased = autocvar_g_arena_roundbased;
244 round_handler_Spawn(Arena_CheckPlayers, Arena_CheckWinner, Arena_RoundStart);
245 round_handler_Init(5, autocvar_g_arena_warmup, autocvar_g_arena_round_timelimit);
249 MUTATOR_DEFINITION(gamemode_arena)
251 MUTATOR_HOOK(ClientDisconnect, arena_ClientDisconnect, CBC_ORDER_ANY);
252 MUTATOR_HOOK(reset_map_players, arena_reset_map_players, CBC_ORDER_ANY);
253 MUTATOR_HOOK(MakePlayerObserver, arena_MakePlayerObserver, CBC_ORDER_ANY);
254 MUTATOR_HOOK(PutClientInServer, arena_PutClientInServer, CBC_ORDER_ANY);
255 MUTATOR_HOOK(ClientConnect, arena_ClientConnect, CBC_ORDER_ANY);
256 MUTATOR_HOOK(PlayerSpawn, arena_PlayerSpawn, CBC_ORDER_ANY);
257 MUTATOR_HOOK(ForbidPlayerScore_Clear, arena_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
258 MUTATOR_HOOK(GiveFragsForKill, arena_GiveFragsForKill, CBC_ORDER_ANY);
259 MUTATOR_HOOK(PlayerDies, arena_PlayerDies, CBC_ORDER_ANY);
260 MUTATOR_HOOK(SV_StartFrame, arena_SV_StartFrame, CBC_ORDER_ANY);
264 if(time > 1) // game loads at time 1
265 error("This is a game type and it cannot be added at runtime.");
271 print("This is a game type and it cannot be removed at runtime.");