]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
LMS: show in the HUD the smallest difference between lives of leaders and lives of...
authorterencehill <piuntn@gmail.com>
Mon, 6 Dec 2021 11:17:20 +0000 (12:17 +0100)
committerterencehill <piuntn@gmail.com>
Mon, 6 Dec 2021 11:17:20 +0000 (12:17 +0100)
qcsrc/common/gamemodes/gamemode/lms/cl_lms.qc
qcsrc/common/gamemodes/gamemode/lms/sv_lms.qc

index 91713eb47cd8c9ff9bae6c1f22244121d547c70c..ea622ec824ed7c4852936fe40105bc14d31ad500 100644 (file)
@@ -33,21 +33,41 @@ MUTATOR_HOOKFUNCTION(cl_lms, DrawInfoMessages)
 
 void HUD_Mod_LMS_Draw(vector myPos, vector mySize)
 {
-       int stat = STAT(REDALIVE); // number of leaders
-       if(!stat)
+       int leaders_count = STAT(REDALIVE); // recycled stat
+       if(!leaders_count)
        {
                mod_active = 0;
                return;
        }
 
+       int rows, columns;
+       float aspect_ratio = 2;
+       rows = HUD_GetRowCount(2, mySize, aspect_ratio);
+       columns = ceil(2 / rows);
+
+       vector pos = myPos;
+       vector itemSize = vec2(mySize.x / columns, mySize.y / rows);
+
        bool visible_leaders = STAT(OBJECTIVE_STATUS);
-       string pic = "player_neutral";
-       vector color = '1 1 1';
 
        if (visible_leaders)
-               drawpic_aspect_skin(myPos, "flag_stalemate", vec2(0.5 * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-       drawpic_aspect_skin(myPos, pic, vec2(0.5 * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-       drawstring_aspect(myPos + eX * 0.5 * mySize.x, ftos(stat), vec2(0.5 * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawpic_aspect_skin(pos, "flag_stalemate", vec2(0.5 * itemSize.x, itemSize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+       drawpic_aspect_skin(pos, "player_neutral", vec2(0.5 * itemSize.x, itemSize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+       drawstring_aspect(pos + eX * 0.5 * itemSize.x, ftos(leaders_count), vec2(0.5 * itemSize.x, itemSize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+
+       if (rows > 1)
+               pos.y = myPos.y + itemSize.y;
+       else
+               pos.x = myPos.x + itemSize.x;
+
+       int lives_diff = STAT(BLUEALIVE); // recycled stat
+       vector color = '1 1 0';
+       if (lives_diff >= 4)
+               color = '1 0 0';
+       else if (lives_diff == 3)
+               color = '1 0.5 0';
+       float scale = 0.75;
+       drawstring_aspect(pos + itemSize * (1 - scale) * 0.5, strcat("+", ftos(lives_diff)), itemSize * scale, color, panel_fg_alpha, DRAWFLAG_NORMAL);
 }
 
 void HUD_Mod_LMS(vector myPos, vector mySize)
index e229cc98bbe42603785832376f43acd22e92a759..571528c069475d37736086cbe57d84d528b5125c 100644 (file)
@@ -147,6 +147,7 @@ bool lms_waypointsprite_visible_for_player(entity this, entity player, entity vi
        return true;
 }
 
+int lms_leaders_lives_diff;
 void lms_UpdateLeaders()
 {
        int max_lives = 0;
@@ -168,8 +169,10 @@ void lms_UpdateLeaders()
                        second_max_lives = lives;
        });
 
+       lms_leaders_lives_diff = max_lives - second_max_lives;
+
        int lives_diff = autocvar_g_lms_leader_lives_diff;
-       if (max_lives - second_max_lives >= lives_diff && pl_cnt_with_max_lives <= pl_cnt * autocvar_g_lms_leader_minpercent)
+       if (lms_leaders_lives_diff >= lives_diff && pl_cnt_with_max_lives <= pl_cnt * autocvar_g_lms_leader_minpercent)
                FOREACH_CLIENT(IS_PLAYER(it) && it.frags != FRAGS_PLAYER_OUT_OF_GAME, {
                        int lives = GameRules_scoring_add(it, LMS_LIVES, 0);
                        if (lives == max_lives)
@@ -415,8 +418,9 @@ MUTATOR_HOOKFUNCTION(lms, PlayerPreThink)
 {
        entity player = M_ARGV(0, entity);
 
-       // recycled REDALIVE to avoid adding a dedicated stat
+       // recycled REDALIVE and BLUEALIVE to avoid adding a dedicated stat
        STAT(REDALIVE, player) = lms_leaders;
+       STAT(BLUEALIVE, player) = lms_leaders_lives_diff;
 
        if(player.deadflag == DEAD_DYING)
                player.deadflag = DEAD_RESPAWNING;