4 #define autocvar_g_lms_lives_override cvar("g_lms_lives_override")
7 REGISTER_MUTATOR(lms, false)
9 SetLimits(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override), 0, -1, -1);
13 if (time > 1) // game loads at time 1
14 error("This is a game type and it cannot be added at runtime.");
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);
75 MUTATOR_HOOKFUNCTION(lms, reset_map_global)
77 lms_lowest_lives = 999;
78 lms_next_place = player_count;
83 MUTATOR_HOOKFUNCTION(lms, reset_map_players)
86 if(restart_mapalreadyrestarted || (time < game_starttime))
90 WITH(entity, self, e, PlayerScore_Add(e, SP_LMS_LIVES, LMS_NewPlayerLives()));
96 MUTATOR_HOOKFUNCTION(lms, PutClientInServer)
98 // player is dead and becomes observer
99 // FIXME fix LMS scoring for new system
100 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
102 self.classname = "observer";
103 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_LMS_NOLIVES);
109 MUTATOR_HOOKFUNCTION(lms, PlayerDies)
111 self.respawn_flags |= RESPAWN_FORCE;
116 void lms_RemovePlayer(entity player)
118 // Only if the player cannot play at all
119 if(PlayerScore_Add(player, SP_LMS_RANK, 0) == 666)
120 player.frags = FRAGS_SPECTATOR;
122 player.frags = FRAGS_LMS_LOSER;
124 if(player.killcount != -666)
125 if(PlayerScore_Add(player, SP_LMS_RANK, 0) > 0 && player.lms_spectate_warning != 2)
126 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_NOLIVES, player.netname);
128 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_FORFEIT, player.netname);
131 MUTATOR_HOOKFUNCTION(lms, ClientDisconnect)
133 lms_RemovePlayer(self);
137 MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver)
139 lms_RemovePlayer(self);
143 MUTATOR_HOOKFUNCTION(lms, ClientConnect)
145 self.classname = "player";
146 campaign_bots_may_start = 1;
148 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
150 PlayerScore_Add(self, SP_LMS_RANK, 666);
151 self.frags = FRAGS_SPECTATOR;
157 MUTATOR_HOOKFUNCTION(lms, PlayerPreThink)
159 if(self.deadflag == DEAD_DYING)
160 self.deadflag = DEAD_RESPAWNING;
165 MUTATOR_HOOKFUNCTION(lms, PlayerRegen)
167 if(autocvar_g_lms_regenerate)
172 MUTATOR_HOOKFUNCTION(lms, ForbidThrowCurrentWeapon)
178 MUTATOR_HOOKFUNCTION(lms, GiveFragsForKill)
182 tl = PlayerScore_Add(frag_target, SP_LMS_LIVES, -1);
183 if(tl < lms_lowest_lives)
184 lms_lowest_lives = tl;
188 lms_next_place = player_count;
190 lms_next_place = min(lms_next_place, player_count);
191 PlayerScore_Add(frag_target, SP_LMS_RANK, lms_next_place); // won't ever spawn again
199 MUTATOR_HOOKFUNCTION(lms, SetStartItems)
201 start_items &= ~IT_UNLIMITED_AMMO;
202 start_health = warmup_start_health = cvar("g_lms_start_health");
203 start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
204 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
205 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
206 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
207 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
208 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
209 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
214 MUTATOR_HOOKFUNCTION(lms, ForbidPlayerScore_Clear)
216 // don't clear player score
220 MUTATOR_HOOKFUNCTION(lms, FilterItem)
222 if(autocvar_g_lms_extra_lives)
223 if(self.itemdef == ITEM_HealthMega)
232 MUTATOR_HOOKFUNCTION(lms, ItemTouch)
234 // give extra lives for mega health
235 if (self.items & ITEM_HealthMega.m_itemid)
237 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
238 PlayerScore_Add(other, SP_LMS_LIVES, autocvar_g_lms_extra_lives);
241 return MUT_ITEMTOUCH_CONTINUE;
244 MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
247 FOR_EACH_REALCLIENT(head)
249 ++bot_activerealplayers;
256 MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate)
258 if(self.lms_spectate_warning)
260 // for the forfeit message...
261 self.lms_spectate_warning = 2;
262 // mark player as spectator
263 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
267 self.lms_spectate_warning = 1;
268 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");
269 return MUT_SPECCMD_RETURN;
271 return MUT_SPECCMD_CONTINUE;
274 MUTATOR_HOOKFUNCTION(lms, CheckRules_World)
276 ret_float = WinningCondition_LMS();
280 MUTATOR_HOOKFUNCTION(lms, WantWeapon)
286 MUTATOR_HOOKFUNCTION(lms, GetPlayerStatus)
291 MUTATOR_HOOKFUNCTION(lms, AddPlayerScore)
294 if(score_field == SP_LMS_RANK)
295 return true; // allow writing to this field in intermission as it is needed for newly joining players
300 void lms_ScoreRules()
302 ScoreRules_basics(0, 0, 0, false);
303 ScoreInfo_SetLabel_PlayerScore(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY);
304 ScoreInfo_SetLabel_PlayerScore(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE);
305 ScoreRules_basics_end();
308 void lms_Initialize()
310 lms_lowest_lives = 9999;