4 #define autocvar_g_lms_lives_override cvar("g_lms_lives_override")
7 REGISTER_MUTATOR(lms, false)
11 if (time > 1) // game loads at time 1
12 error("This is a game type and it cannot be added at runtime.");
15 SetLimits(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override), 0, -1, -1);
18 MUTATOR_ONROLLBACK_OR_REMOVE
20 // we actually cannot roll back lms_Initialize here
21 // BUT: we don't need to! If this gets called, adding always
27 LOG_INFO("This is a game type and it cannot be removed at runtime.");
35 const float SP_LMS_LIVES = 4;
36 const float SP_LMS_RANK = 5;
39 float lms_lowest_lives;
41 float LMS_NewPlayerLives();
47 #include "../../campaign.qh"
48 #include "../../command/cmd.qh"
50 int autocvar_g_lms_extra_lives;
51 bool autocvar_g_lms_join_anytime;
52 int autocvar_g_lms_last_join;
53 bool autocvar_g_lms_regenerate;
56 float LMS_NewPlayerLives()
59 fl = autocvar_fraglimit;
63 // first player has left the game for dying too much? Nobody else can get in.
64 if(lms_lowest_lives < 1)
67 if(!autocvar_g_lms_join_anytime)
68 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
71 return bound(1, lms_lowest_lives, fl);
74 // LMS winning condition: game terminates if and only if there's at most one
75 // one player who's living lives. Top two scores being equal cancels the time
77 float WinningCondition_LMS()
86 l = LMS_NewPlayerLives();
88 head = find(world, classname, "player");
91 head2 = find(head, classname, "player");
97 // we have at least one player
100 // two or more active players - continue with the game
104 // exactly one player?
107 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
111 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
117 // and assign him his first place
118 PlayerScore_Add(head, SP_LMS_RANK, 1);
125 // nobody is playing at all...
128 // wait for players...
132 // SNAFU (maybe a draw game?)
134 LOG_TRACE("No players, ending game.\n");
139 // When we get here, we have at least two players who are actually LIVING,
140 // now check if the top two players have equal score.
141 WinningConditionHelper();
144 if(WinningConditionHelper_winner)
145 WinningConditionHelper_winner.winning = true;
146 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
147 return WINNING_NEVER;
149 // Top two have different scores? Way to go for our beloved TIMELIMIT!
154 MUTATOR_HOOKFUNCTION(lms, reset_map_global)
156 lms_lowest_lives = 999;
157 lms_next_place = player_count;
162 MUTATOR_HOOKFUNCTION(lms, reset_map_players)
165 if(restart_mapalreadyrestarted || (time < game_starttime))
169 WITH(entity, self, e, PlayerScore_Add(e, SP_LMS_LIVES, LMS_NewPlayerLives()));
175 MUTATOR_HOOKFUNCTION(lms, PutClientInServer)
177 // player is dead and becomes observer
178 // FIXME fix LMS scoring for new system
179 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
181 self.classname = STR_OBSERVER;
182 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_LMS_NOLIVES);
188 MUTATOR_HOOKFUNCTION(lms, PlayerDies)
190 self.respawn_flags |= RESPAWN_FORCE;
195 void lms_RemovePlayer(entity player)
197 // Only if the player cannot play at all
198 if(PlayerScore_Add(player, SP_LMS_RANK, 0) == 666)
199 player.frags = FRAGS_SPECTATOR;
201 player.frags = FRAGS_LMS_LOSER;
203 if(player.killcount != FRAGS_SPECTATOR)
204 if(PlayerScore_Add(player, SP_LMS_RANK, 0) > 0 && player.lms_spectate_warning != 2)
205 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_NOLIVES, player.netname);
207 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_FORFEIT, player.netname);
210 MUTATOR_HOOKFUNCTION(lms, ClientDisconnect)
212 lms_RemovePlayer(self);
216 MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver)
218 lms_RemovePlayer(self);
222 MUTATOR_HOOKFUNCTION(lms, ClientConnect)
224 self.classname = STR_PLAYER;
225 campaign_bots_may_start = 1;
227 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
229 PlayerScore_Add(self, SP_LMS_RANK, 666);
230 self.frags = FRAGS_SPECTATOR;
236 MUTATOR_HOOKFUNCTION(lms, PlayerPreThink)
238 if(self.deadflag == DEAD_DYING)
239 self.deadflag = DEAD_RESPAWNING;
244 MUTATOR_HOOKFUNCTION(lms, PlayerRegen)
246 if(autocvar_g_lms_regenerate)
251 MUTATOR_HOOKFUNCTION(lms, ForbidThrowCurrentWeapon)
257 MUTATOR_HOOKFUNCTION(lms, GiveFragsForKill)
261 tl = PlayerScore_Add(frag_target, SP_LMS_LIVES, -1);
262 if(tl < lms_lowest_lives)
263 lms_lowest_lives = tl;
267 lms_next_place = player_count;
269 lms_next_place = min(lms_next_place, player_count);
270 PlayerScore_Add(frag_target, SP_LMS_RANK, lms_next_place); // won't ever spawn again
278 MUTATOR_HOOKFUNCTION(lms, SetStartItems)
280 start_items &= ~IT_UNLIMITED_AMMO;
281 start_health = warmup_start_health = cvar("g_lms_start_health");
282 start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
283 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
284 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
285 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
286 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
287 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
288 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
293 MUTATOR_HOOKFUNCTION(lms, ForbidPlayerScore_Clear)
295 // don't clear player score
299 MUTATOR_HOOKFUNCTION(lms, FilterItem)
301 if(autocvar_g_lms_extra_lives)
302 if(self.itemdef == ITEM_HealthMega)
311 MUTATOR_HOOKFUNCTION(lms, ItemTouch)
313 // give extra lives for mega health
314 if (self.items & ITEM_HealthMega.m_itemid)
316 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
317 PlayerScore_Add(other, SP_LMS_LIVES, autocvar_g_lms_extra_lives);
320 return MUT_ITEMTOUCH_CONTINUE;
323 MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
326 FOR_EACH_REALCLIENT(head)
328 ++bot_activerealplayers;
335 MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate)
337 if(self.lms_spectate_warning)
339 // for the forfeit message...
340 self.lms_spectate_warning = 2;
341 // mark player as spectator
342 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
346 self.lms_spectate_warning = 1;
347 sprint(self, "WARNING: you won't be able to enter the game again after spectating in LMS. Use the same command again to spectate anyway.\n");
348 return MUT_SPECCMD_RETURN;
350 return MUT_SPECCMD_CONTINUE;
353 MUTATOR_HOOKFUNCTION(lms, CheckRules_World)
355 ret_float = WinningCondition_LMS();
359 MUTATOR_HOOKFUNCTION(lms, WantWeapon)
365 MUTATOR_HOOKFUNCTION(lms, GetPlayerStatus)
370 MUTATOR_HOOKFUNCTION(lms, AddPlayerScore)
373 if(score_field == SP_LMS_RANK)
374 return true; // allow writing to this field in intermission as it is needed for newly joining players
379 void lms_ScoreRules()
381 ScoreRules_basics(0, 0, 0, false);
382 ScoreInfo_SetLabel_PlayerScore(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY);
383 ScoreInfo_SetLabel_PlayerScore(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE);
384 ScoreRules_basics_end();
387 void lms_Initialize()
389 lms_lowest_lives = 9999;