Merge branch 'master' into terencehill/ca_bots_fix 389/head
authorterencehill <piuntn@gmail.com>
Tue, 29 Nov 2016 18:22:07 +0000 (19:22 +0100)
committerterencehill <piuntn@gmail.com>
Tue, 29 Nov 2016 18:22:07 +0000 (19:22 +0100)
Conflicts:
qcsrc/server/mutators/mutator/gamemode_lms.qc

1  2 
qcsrc/server/bot/default/scripting.qc
qcsrc/server/mutators/mutator/gamemode_lms.qc

Simple merge
@@@ -141,14 -168,46 +168,48 @@@ MUTATOR_HOOKFUNCTION(lms, PlayerDies
  
  void lms_RemovePlayer(entity player)
  {
-       // Only if the player cannot play at all
-       if(PlayerScore_Add(player, SP_LMS_RANK, 0) == 666)
-               player.frags = FRAGS_SPECTATOR;
-       else
+       static int quitters = 0;
+       float player_rank = PlayerScore_Add(player, SP_LMS_RANK, 0);
+       if (!player_rank)
        {
-               if(IS_BOT_CLIENT(player))
-                       bot_clear(player);
-               player.frags = FRAGS_LMS_LOSER;
+               int pl_cnt = 0;
+               FOREACH_CLIENT(IS_PLAYER(it), { pl_cnt++; });
+               if (player.lms_spectate_warning != 2)
+               {
++                      if(IS_BOT_CLIENT(player))
++                              bot_clear(player);
+                       player.frags = FRAGS_LMS_LOSER;
+                       PlayerScore_Add(player, SP_LMS_RANK, pl_cnt + 1);
+               }
+               else
+               {
+                       lms_lowest_lives = 999;
+                       FOREACH_CLIENT(true, {
+                               if (it.frags == FRAGS_LMS_LOSER)
+                               {
+                                       float it_rank = PlayerScore_Add(it, SP_LMS_RANK, 0);
+                                       if (it_rank > player_rank && it_rank <= 256)
+                                               PlayerScore_Add(it, SP_LMS_RANK, -1);
+                                       lms_lowest_lives = 0;
+                               }
+                               else if (it.frags != FRAGS_SPECTATOR)
+                               {
+                                       float tl = PlayerScore_Add(it, SP_LMS_LIVES, 0);
+                                       if(tl < lms_lowest_lives)
+                                               lms_lowest_lives = tl;
+                               }
+                       });
+                       PlayerScore_Add(player, SP_LMS_RANK, 665 - quitters); // different from 666
+                       if(!warmup_stage)
+                       {
+                               PlayerScore_Add(player, SP_LMS_LIVES, -PlayerScore_Add(player, SP_LMS_LIVES, 0));
+                               ++quitters;
+                       }
+                       player.frags = FRAGS_LMS_LOSER;
+                       TRANSMUTE(Observer, player);
+               }
+               if (pl_cnt == 2 && !warmup_stage) // a player is forfeiting leaving only one player
+                       lms_lowest_lives = 0; // end the game now!
        }
  
        if(player.killcount != FRAGS_SPECTATOR)
@@@ -212,21 -271,21 +273,23 @@@ MUTATOR_HOOKFUNCTION(lms, GiveFragsForK
  {
        entity frag_target = M_ARGV(1, entity);
  
-       // remove a life
-       float tl;
-       tl = PlayerScore_Add(frag_target, SP_LMS_LIVES, -1);
-       if(tl < lms_lowest_lives)
-               lms_lowest_lives = tl;
-       if(tl <= 0)
+       if (!warmup_stage)
        {
-               if(!lms_next_place)
-                       lms_next_place = player_count;
-               else
-                       lms_next_place = min(lms_next_place, player_count);
-               PlayerScore_Add(frag_target, SP_LMS_RANK, lms_next_place); // won't ever spawn again
-               --lms_next_place;
+               // remove a life
+               int tl = PlayerScore_Add(frag_target, SP_LMS_LIVES, -1);
+               if(tl < lms_lowest_lives)
+                       lms_lowest_lives = tl;
+               if(tl <= 0)
+               {
+                       int pl_cnt = 0;
+                       FOREACH_CLIENT(IS_PLAYER(it), { pl_cnt++; });
++                      if(IS_BOT_CLIENT(frag_target))
++                              bot_clear(frag_target);
+                       frag_target.frags = FRAGS_LMS_LOSER;
+                       PlayerScore_Add(frag_target, SP_LMS_RANK, pl_cnt);
+               }
        }
-       M_ARGV(2, float) = 0;
+       M_ARGV(2, float) = 0; // frag score
  
        return true;
  }