]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator/gamemode_lms.qc
Merge branch 'master' into terencehill/min_spec_time
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_lms.qc
index cd8fb390d4726744ee117bbad21fffe5a2fcaa62..eaacc0fb813ffc3604258466c058f4d4f9a220da 100644 (file)
@@ -35,25 +35,29 @@ void ClearWinners();
 // limit.
 int WinningCondition_LMS()
 {
-       entity head, head2;
-       bool have_player = false;
-       bool have_players = false;
-
-       int l = LMS_NewPlayerLives();
-
-       head = find(NULL, classname, STR_PLAYER);
-       if(head)
-               have_player = true;
-       head2 = find(head, classname, STR_PLAYER);
-       if(head2)
-               have_players = true;
+       entity first_player = NULL;
+       int total_players = 0;
+       FOREACH_CLIENT(IS_PLAYER(it), {
+               if (!total_players)
+                       first_player = it;
+               ++total_players;
+       });
 
-       if(have_player)
+       if (total_players)
        {
-               // we have at least one player
-               if(have_players)
+               if (total_players > 1)
                {
                        // two or more active players - continue with the game
+
+                       if (autocvar_g_campaign)
+                       {
+                               FOREACH_CLIENT(IS_REAL_CLIENT(it), {
+                                       float pl_lives = GameRules_scoring_add(it, LMS_LIVES, 0);
+                                       if (!pl_lives)
+                                               return WINNING_YES; // human player lost, game over
+                                       break;
+                               });
+                       }
                }
                else
                {
@@ -62,7 +66,7 @@ int WinningCondition_LMS()
                        ClearWinners();
                        SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
 
-                       if(l)
+                       if (LMS_NewPlayerLives())
                        {
                                // game still running (that is, nobody got removed from the game by a frag yet)? then continue
                                return WINNING_NO;
@@ -71,7 +75,7 @@ int WinningCondition_LMS()
                        {
                                // a winner!
                                // and assign him his first place
-                               GameRules_scoring_add(head, LMS_RANK, 1);
+                               GameRules_scoring_add(first_player, LMS_RANK, 1);
                                if(warmup_stage)
                                        return WINNING_NO;
                                else
@@ -82,7 +86,7 @@ int WinningCondition_LMS()
        else
        {
                // nobody is playing at all...
-               if(l)
+               if (LMS_NewPlayerLives())
                {
                        // wait for players...
                }
@@ -228,7 +232,10 @@ MUTATOR_HOOKFUNCTION(lms, ClientDisconnect)
 
 MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver)
 {
-    entity player = M_ARGV(0, entity);
+       entity player = M_ARGV(0, entity);
+
+       if (!IS_PLAYER(player))
+               return true;
 
        lms_RemovePlayer(player);
        return true;  // prevent team reset
@@ -238,9 +245,6 @@ MUTATOR_HOOKFUNCTION(lms, ClientConnect)
 {
        entity player = M_ARGV(0, entity);
 
-       TRANSMUTE(Player, player);
-       campaign_bots_may_start = true;
-
        if(GameRules_scoring_add(player, LMS_LIVES, LMS_NewPlayerLives()) <= 0)
        {
                GameRules_scoring_add(player, LMS_RANK, 666); // mark as forced spectator for the hud code
@@ -248,6 +252,13 @@ MUTATOR_HOOKFUNCTION(lms, ClientConnect)
        }
 }
 
+MUTATOR_HOOKFUNCTION(lms, AutoJoinOnConnection)
+{
+       if(autocvar_g_campaign)
+               return false;
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(lms, PlayerPreThink)
 {
        entity player = M_ARGV(0, entity);
@@ -313,14 +324,14 @@ MUTATOR_HOOKFUNCTION(lms, ForbidPlayerScore_Clear)
        return true;
 }
 
-MUTATOR_HOOKFUNCTION(lms, FilterItem)
+MUTATOR_HOOKFUNCTION(lms, FilterItemDefinition)
 {
-       entity item = M_ARGV(0, entity);
+       entity definition = M_ARGV(0, entity);
 
-       if(autocvar_g_lms_extra_lives)
-       if(item.itemdef == ITEM_ExtraLife)
+       if (autocvar_g_lms_extra_lives && definition == ITEM_ExtraLife)
+       {
                return false;
-
+       }
        return true;
 }
 
@@ -377,7 +388,7 @@ MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
 
 MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate)
 {
-    entity player = M_ARGV(0, entity);
+       entity player = M_ARGV(0, entity);
 
        if(warmup_stage || player.lms_spectate_warning)
        {