From 4858e9db752780b0326cf3b339beec0b53442016 Mon Sep 17 00:00:00 2001 From: aurhat Date: Sat, 13 Aug 2016 17:14:41 +0200 Subject: [PATCH] Fix displaying stats of previous weapon on the HUD Earlier if player held grenade in the hands and other player connected to server and started to spectate him, then this second player always saw assault rifle stats on the HUD as previously selected weapon. It happens, because new client doesn't know, what was previous weapon of players on the server, which didn't switch yet weapon after its connection, so GUN_ASSAULT is set by default. So if first player used for e.g. sniper rifle, then displayed ammo stats were 0/0. Now then are displayed stats of primary weapon. --- source/src/renderhud.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index b4795633..c93aea5e 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -311,6 +311,11 @@ void drawktfindicator(playerent *p) extern int oldfashionedgunstats; +int getprevweaponsel(playerent *p) // get previous weapon or, if we don't know it, get the primary +{ + return p->prevweaponsel->type == GUN_ASSAULT && p->primweap->type != GUN_ASSAULT ? p->primweap->type : p->prevweaponsel->type; +} + void drawequipicons(playerent *p) { glDisable(GL_BLEND); @@ -323,7 +328,7 @@ void drawequipicons(playerent *p) if(p->mag[GUN_GRENADE]) drawequipicon(oldfashionedgunstats ? (HUDPOS_GRENADE + 25)*2 : HUDPOS_GRENADE*2, 1650, 3, 1); // weapons - int c = p->weaponsel->type != GUN_GRENADE ? p->weaponsel->type : p->prevweaponsel->type, r = 0; + int c = p->weaponsel->type != GUN_GRENADE ? p->weaponsel->type : getprevweaponsel(p), r = 0; if(c==GUN_AKIMBO || c==GUN_CPISTOL) c = GUN_PISTOL; // same icon for akimb & pistol if(c>3) { c -= 4; r = 1; } @@ -1053,7 +1058,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glMatrixMode(GL_MODELVIEW); if (p->weaponsel->type!=GUN_GRENADE) p->weaponsel->renderstats(); else if (p->prevweaponsel->type==GUN_AKIMBO || p->prevweaponsel->type==GUN_PISTOL) p->weapons[p->akimbo ? GUN_AKIMBO : GUN_PISTOL]->renderstats(); - else p->prevweaponsel->renderstats(); + else p->weapons[getprevweaponsel(p)]->renderstats(); if(p->mag[GUN_GRENADE]) p->weapons[GUN_GRENADE]->renderstats(); glMatrixMode(GL_PROJECTION); }