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 <server/campaign.qh>
48 #include <server/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 int WinningCondition_LMS()
80 bool have_player = false;
81 bool have_players = false;
83 int l = LMS_NewPlayerLives();
85 head = find(world, classname, STR_PLAYER);
88 head2 = find(head, classname, STR_PLAYER);
94 // we have at least one player
97 // two or more active players - continue with the game
101 // exactly one player?
104 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
108 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
114 // and assign him his first place
115 PlayerScore_Add(head, SP_LMS_RANK, 1);
122 // nobody is playing at all...
125 // wait for players...
129 // SNAFU (maybe a draw game?)
131 LOG_TRACE("No players, ending game.\n");
136 // When we get here, we have at least two players who are actually LIVING,
137 // now check if the top two players have equal score.
138 WinningConditionHelper();
141 if(WinningConditionHelper_winner)
142 WinningConditionHelper_winner.winning = true;
143 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
144 return WINNING_NEVER;
146 // Top two have different scores? Way to go for our beloved TIMELIMIT!
151 MUTATOR_HOOKFUNCTION(lms, reset_map_global)
153 lms_lowest_lives = 999;
154 lms_next_place = player_count;
159 MUTATOR_HOOKFUNCTION(lms, reset_map_players)
161 if(restart_mapalreadyrestarted || (time < game_starttime))
162 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(PlayerScore_Add(it, SP_LMS_LIVES, LMS_NewPlayerLives())));
166 MUTATOR_HOOKFUNCTION(lms, PutClientInServer)
168 // player is dead and becomes observer
169 // FIXME fix LMS scoring for new system
170 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
172 self.classname = STR_OBSERVER;
173 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_LMS_NOLIVES);
179 MUTATOR_HOOKFUNCTION(lms, PlayerDies)
181 self.respawn_flags |= RESPAWN_FORCE;
186 void lms_RemovePlayer(entity player)
188 // Only if the player cannot play at all
189 if(PlayerScore_Add(player, SP_LMS_RANK, 0) == 666)
190 player.frags = FRAGS_SPECTATOR;
192 player.frags = FRAGS_LMS_LOSER;
194 if(player.killcount != FRAGS_SPECTATOR)
195 if(PlayerScore_Add(player, SP_LMS_RANK, 0) > 0 && player.lms_spectate_warning != 2)
196 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_NOLIVES, player.netname);
198 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_FORFEIT, player.netname);
201 MUTATOR_HOOKFUNCTION(lms, ClientDisconnect)
203 lms_RemovePlayer(self);
207 MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver)
209 lms_RemovePlayer(self);
213 MUTATOR_HOOKFUNCTION(lms, ClientConnect)
215 self.classname = STR_PLAYER;
216 campaign_bots_may_start = 1;
218 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
220 PlayerScore_Add(self, SP_LMS_RANK, 666);
221 self.frags = FRAGS_SPECTATOR;
227 MUTATOR_HOOKFUNCTION(lms, PlayerPreThink)
229 if(self.deadflag == DEAD_DYING)
230 self.deadflag = DEAD_RESPAWNING;
235 MUTATOR_HOOKFUNCTION(lms, PlayerRegen)
237 if(autocvar_g_lms_regenerate)
242 MUTATOR_HOOKFUNCTION(lms, ForbidThrowCurrentWeapon)
248 MUTATOR_HOOKFUNCTION(lms, GiveFragsForKill)
252 tl = PlayerScore_Add(frag_target, SP_LMS_LIVES, -1);
253 if(tl < lms_lowest_lives)
254 lms_lowest_lives = tl;
258 lms_next_place = player_count;
260 lms_next_place = min(lms_next_place, player_count);
261 PlayerScore_Add(frag_target, SP_LMS_RANK, lms_next_place); // won't ever spawn again
269 MUTATOR_HOOKFUNCTION(lms, SetStartItems)
271 start_items &= ~IT_UNLIMITED_AMMO;
272 start_health = warmup_start_health = cvar("g_lms_start_health");
273 start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
274 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
275 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
276 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
277 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
278 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
279 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
284 MUTATOR_HOOKFUNCTION(lms, ForbidPlayerScore_Clear)
286 // don't clear player score
290 MUTATOR_HOOKFUNCTION(lms, FilterItem)
292 if(autocvar_g_lms_extra_lives)
293 if(self.itemdef == ITEM_ExtraLife)
301 StartItem(this, ITEM_ExtraLife);
304 MUTATOR_HOOKFUNCTION(lms, OnEntityPreSpawn)
306 if (!autocvar_g_powerups) return false;
307 if (!autocvar_g_lms_extra_lives) return false;
309 // Can't use .itemdef here
310 if (self.classname != "item_health_mega") return false;
313 e.think = lms_extralife;
315 e.nextthink = time + 0.1;
316 e.spawnflags = self.spawnflags;
317 e.noalign = self.noalign;
318 setorigin(e, self.origin);
323 MUTATOR_HOOKFUNCTION(lms, ItemTouch)
325 if(self.itemdef == ITEM_ExtraLife)
327 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
328 PlayerScore_Add(other, SP_LMS_LIVES, autocvar_g_lms_extra_lives);
329 return MUT_ITEMTOUCH_PICKUP;
332 return MUT_ITEMTOUCH_CONTINUE;
335 MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
337 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
338 ++bot_activerealplayers;
345 MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate)
347 if(self.lms_spectate_warning)
349 // for the forfeit message...
350 self.lms_spectate_warning = 2;
351 // mark player as spectator
352 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
356 self.lms_spectate_warning = 1;
357 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");
358 return MUT_SPECCMD_RETURN;
360 return MUT_SPECCMD_CONTINUE;
363 MUTATOR_HOOKFUNCTION(lms, CheckRules_World)
365 ret_float = WinningCondition_LMS();
369 MUTATOR_HOOKFUNCTION(lms, WantWeapon)
375 MUTATOR_HOOKFUNCTION(lms, GetPlayerStatus)
380 MUTATOR_HOOKFUNCTION(lms, AddPlayerScore)
383 if(score_field == SP_LMS_RANK)
384 return true; // allow writing to this field in intermission as it is needed for newly joining players
389 void lms_ScoreRules()
391 ScoreRules_basics(0, 0, 0, false);
392 ScoreInfo_SetLabel_PlayerScore(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY);
393 ScoreInfo_SetLabel_PlayerScore(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE);
394 ScoreRules_basics_end();
397 void lms_Initialize()
399 lms_lowest_lives = 9999;