5 const float SP_LMS_LIVES = 4;
6 const float SP_LMS_RANK = 5;
9 float lms_lowest_lives;
11 float LMS_NewPlayerLives();
17 #include "../../campaign.qh"
18 #include "../../command/cmd.qh"
20 int autocvar_g_lms_extra_lives;
21 bool autocvar_g_lms_join_anytime;
22 int autocvar_g_lms_last_join;
23 #define autocvar_g_lms_lives_override cvar("g_lms_lives_override")
24 bool autocvar_g_lms_regenerate;
27 float LMS_NewPlayerLives()
30 fl = autocvar_fraglimit;
34 // first player has left the game for dying too much? Nobody else can get in.
35 if(lms_lowest_lives < 1)
38 if(!autocvar_g_lms_join_anytime)
39 if(lms_lowest_lives < fl - autocvar_g_lms_last_join)
42 return bound(1, lms_lowest_lives, fl);
46 MUTATOR_HOOKFUNCTION(lms, reset_map_global)
48 lms_lowest_lives = 999;
49 lms_next_place = player_count;
54 MUTATOR_HOOKFUNCTION(lms, reset_map_players)
57 if(restart_mapalreadyrestarted || (time < game_starttime))
61 WITH(entity, self, e, PlayerScore_Add(e, SP_LMS_LIVES, LMS_NewPlayerLives()));
67 MUTATOR_HOOKFUNCTION(lms, PutClientInServer)
69 // player is dead and becomes observer
70 // FIXME fix LMS scoring for new system
71 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
73 self.classname = "observer";
74 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_LMS_NOLIVES);
80 MUTATOR_HOOKFUNCTION(lms, PlayerDies)
82 self.respawn_flags |= RESPAWN_FORCE;
87 void lms_RemovePlayer(entity player)
89 // Only if the player cannot play at all
90 if(PlayerScore_Add(player, SP_LMS_RANK, 0) == 666)
91 player.frags = FRAGS_SPECTATOR;
93 player.frags = FRAGS_LMS_LOSER;
95 if(player.killcount != -666)
96 if(PlayerScore_Add(player, SP_LMS_RANK, 0) > 0 && player.lms_spectate_warning != 2)
97 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_NOLIVES, player.netname);
99 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_FORFEIT, player.netname);
102 MUTATOR_HOOKFUNCTION(lms, ClientDisconnect)
104 lms_RemovePlayer(self);
108 MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver)
110 lms_RemovePlayer(self);
114 MUTATOR_HOOKFUNCTION(lms, ClientConnect)
116 self.classname = "player";
117 campaign_bots_may_start = 1;
119 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
121 PlayerScore_Add(self, SP_LMS_RANK, 666);
122 self.frags = FRAGS_SPECTATOR;
128 MUTATOR_HOOKFUNCTION(lms, PlayerPreThink)
130 if(self.deadflag == DEAD_DYING)
131 self.deadflag = DEAD_RESPAWNING;
136 MUTATOR_HOOKFUNCTION(lms, PlayerRegen)
138 if(autocvar_g_lms_regenerate)
143 MUTATOR_HOOKFUNCTION(lms, ForbidThrowCurrentWeapon)
149 MUTATOR_HOOKFUNCTION(lms, GiveFragsForKill)
153 tl = PlayerScore_Add(frag_target, SP_LMS_LIVES, -1);
154 if(tl < lms_lowest_lives)
155 lms_lowest_lives = tl;
159 lms_next_place = player_count;
161 lms_next_place = min(lms_next_place, player_count);
162 PlayerScore_Add(frag_target, SP_LMS_RANK, lms_next_place); // won't ever spawn again
170 MUTATOR_HOOKFUNCTION(lms, SetStartItems)
172 start_items &= ~IT_UNLIMITED_AMMO;
173 start_health = warmup_start_health = cvar("g_lms_start_health");
174 start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
175 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
176 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
177 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
178 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
179 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
180 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
185 MUTATOR_HOOKFUNCTION(lms, ForbidPlayerScore_Clear)
187 // don't clear player score
191 MUTATOR_HOOKFUNCTION(lms, FilterItem)
193 if(autocvar_g_lms_extra_lives)
194 if(self.itemdef == ITEM_HealthMega)
203 MUTATOR_HOOKFUNCTION(lms, ItemTouch)
205 // give extra lives for mega health
206 if (self.items & ITEM_HealthMega.m_itemid)
208 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
209 PlayerScore_Add(other, SP_LMS_LIVES, autocvar_g_lms_extra_lives);
212 return MUT_ITEMTOUCH_CONTINUE;
215 MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
218 FOR_EACH_REALCLIENT(head)
220 ++bot_activerealplayers;
227 MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate)
229 if(self.lms_spectate_warning)
231 // for the forfeit message...
232 self.lms_spectate_warning = 2;
233 // mark player as spectator
234 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
238 self.lms_spectate_warning = 1;
239 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");
240 return MUT_SPECCMD_RETURN;
242 return MUT_SPECCMD_CONTINUE;
245 MUTATOR_HOOKFUNCTION(lms, CheckRules_World)
247 ret_float = WinningCondition_LMS();
251 MUTATOR_HOOKFUNCTION(lms, WantWeapon)
257 MUTATOR_HOOKFUNCTION(lms, GetPlayerStatus)
262 MUTATOR_HOOKFUNCTION(lms, AddPlayerScore)
265 if(score_field == SP_LMS_RANK)
266 return true; // allow writing to this field in intermission as it is needed for newly joining players
271 void lms_ScoreRules()
273 ScoreRules_basics(0, 0, 0, false);
274 ScoreInfo_SetLabel_PlayerScore(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY);
275 ScoreInfo_SetLabel_PlayerScore(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE);
276 ScoreRules_basics_end();
279 void lms_Initialize()
281 lms_lowest_lives = 9999;
287 REGISTER_MUTATOR(lms, IS_GAMETYPE(LMS))
289 SetLimits(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override), 0, -1, -1);
293 if(time > 1) // game loads at time 1
294 error("This is a game type and it cannot be added at runtime.");
298 MUTATOR_ONROLLBACK_OR_REMOVE
300 // we actually cannot roll back lms_Initialize here
301 // BUT: we don't need to! If this gets called, adding always
307 LOG_INFO("This is a game type and it cannot be removed at runtime.");