Improve accuracy info and some elements of the HUD

Accuracy will be displayed only then, if scoreboard will be enabled, and
only for current weapon - in order to focus attention of players more on
gameplay/work for team than personal stats.
Added "accuracyinfo" command to see accuracy of all used weapons in
output console.
Added some cleanups and fixed memory leak.
This commit is contained in:
aurhat
2015-12-31 22:57:16 +01:00
parent cc2ac85dd5
commit e4d5c2d361
3 changed files with 50 additions and 32 deletions
+3 -1
View File
@@ -658,8 +658,10 @@ extern void restoreeditundo(ucharbuf &q);
extern int backupeditundo(vector<uchar> &buf, int undolimit, int redolimit);
// renderhud
#define HUDPOS_X_BOTTOMLEFT 20
#define HUDPOS_Y_BOTTOMLEFT 1570
#define HUDPOS_ICONSPACING 235
#define HUDPOS_HEALTH 10
#define HUDPOS_HEALTH (HUDPOS_X_BOTTOMLEFT / 2)
#define HUDPOS_ARMOUR (HUDPOS_HEALTH + HUDPOS_ICONSPACING)
#define HUDPOS_WEAPON (HUDPOS_ARMOUR + HUDPOS_ICONSPACING)
#define HUDPOS_GRENADE (HUDPOS_WEAPON + HUDPOS_ICONSPACING)
+9 -7
View File
@@ -815,16 +815,18 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat
}
char *infostr = editinfo();
int commandh = 1570 + FONTH;
if(command) commandh -= rendercommand(-1, 1570, VIRTW - FONTH); // dryrun to get height
else if(infostr) draw_text(infostr, 20, 1570);
else if(targetplayer && showtargetname) draw_text(colorname(targetplayer), 20, 1570);
int commandh = HUDPOS_Y_BOTTOMLEFT + FONTH;
if(command) commandh -= rendercommand(-1, HUDPOS_Y_BOTTOMLEFT, VIRTW - FONTH); // dryrun to get height
else if(infostr) draw_text(infostr, HUDPOS_X_BOTTOMLEFT, HUDPOS_Y_BOTTOMLEFT);
else if(targetplayer && showtargetname) draw_text(colorname(targetplayer), HUDPOS_X_BOTTOMLEFT, HUDPOS_Y_BOTTOMLEFT);
glLoadIdentity();
glOrtho(0, VIRTW*2, VIRTH*2, 0, -1, 1);
extern int tsens(int x);
tsens(-2000);
extern void r_accuracy(int h);
if (!is_spect) r_accuracy(commandh);
extern void *scoremenu;
extern gmenu *curmenu;
if(!is_spect && !editmode && !watchingdemo && !command && curmenu == scoremenu) r_accuracy(commandh);
if(!hideconsole) renderconsole();
formatstring(enginestateinfo)("%d %d %d %d %d", curfps, lod_factor(), nquads, curvert, xtraverts);
@@ -939,7 +941,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat
if(curvote && curvote->millis >= totalmillis && !(hidevote == 1 && curvote->localplayervoted && curvote->result == VOTE_NEUTRAL))
{
const int left = 20*2, top = VIRTH;
const int left = 2 * HUDPOS_X_BOTTOMLEFT, top = VIRTH;
defformatstring(str)("%s called a vote:", curvote->owner ? colorname(curvote->owner) : "");
draw_text(str, left, top + 240, 255, 255, 255, votealpha);
draw_text(curvote->desc, left, top + 320, 255, 255, 255, votealpha);
@@ -1071,7 +1073,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat
glLoadIdentity();
glOrtho(0, VIRTW, VIRTH, 0, -1, 1);
if(command) commandh -= rendercommand(20, 1570, VIRTW - FONTH);
if(command) commandh -= rendercommand(HUDPOS_X_BOTTOMLEFT, HUDPOS_Y_BOTTOMLEFT, VIRTW - FONTH);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
+38 -24
View File
@@ -596,7 +596,7 @@ void raydamage(vec &from, vec &to, playerent *d)
int hitzone = -1;
playerent *o = NULL;
float dist, hitdist = 0.0f;
bool hitted=false;
bool hit = false;
int rayscount = 0, hitscount = 0;
if(d->weaponsel->type==GUN_SHOTGUN)
{
@@ -658,7 +658,7 @@ void raydamage(vec &from, vec &to, playerent *d)
int info = (withBONUS ? SGDMGBONUS : 0) | (numhits_c << 8) | (numhits_m << 16) | (numhits_o << 24);
if(numhits) hitpush(dmgreal, o, d, from, to, d->weaponsel->type, numhits == SGRAYS * 3, info);
if(d==player1) hitted = true;
if(d == player1) hit = true;
hitscount+=numhits;
}
}
@@ -675,7 +675,7 @@ void raydamage(vec &from, vec &to, playerent *d)
}
bool info = gib;
hitpush(dam, o, d, from, to, d->weaponsel->type, gib, info ? 1 : 0);
if(d==player1) hitted=true;
if(d == player1) hit = true;
shorten(from, to, dist);
hitscount++;
}
@@ -683,7 +683,7 @@ void raydamage(vec &from, vec &to, playerent *d)
if(d==player1)
{
if(!rayscount) rayscount = 1;
if(hitted) accuracym[d->weaponsel->type].hits+=(float)hitscount/rayscount;
if(hit) accuracym[d->weaponsel->type].hits += (float)hitscount / rayscount;
accuracym[d->weaponsel->type].shots++;
}
}
@@ -697,13 +697,13 @@ const char *weapstr(unsigned int i)
case GUN_PISTOL:
return "Pistol";
case GUN_ASSAULT:
return "MTP-57";
return "MTP-57 AR";
case GUN_SUBGUN:
return "A-ARD/10";
return "A-ARD/10 SMG";
case GUN_SNIPER:
return "AD-81 SR";
case GUN_SHOTGUN:
return "V-19 SG";
return "V-19 CS";
case GUN_KNIFE:
return "Knife";
case GUN_CARBINE:
@@ -718,41 +718,55 @@ VARP(accuracy,0,0,1);
void r_accuracy(int h)
{
if(!accuracy) return;
vector <char*>lines;
int rows = 0, cols = 0;
float spacing = curfont->defaultw*2, x_offset = curfont->defaultw, y_offset = float(2*h) - 2*spacing;
loopi(NUMGUNS) if(i != GUN_CPISTOL && accuracym[i].shots)
int i = player1->weaponsel->type;
if(accuracy && i >= 0 && i < NUMGUNS && i != GUN_CPISTOL)
{
float acc = 100.0f*accuracym[i].hits/(float)accuracym[i].shots;
int x_offset = 2 * HUDPOS_X_BOTTOMLEFT, y_offset = 2 * (h - 1.75 * FONTH);
string line;
rows++;
float acc = accuracym[i].shots ? 100.0 * accuracym[i].hits / (float)accuracym[i].shots : 0;
if(i == GUN_GRENADE || i == GUN_SHOTGUN)
{
formatstring(line)("\f5%5.1f%s (%.1f/%d) :\f0%s", acc, "%", accuracym[i].hits, (int)accuracym[i].shots, weapstr(i));
formatstring(line)("\f5%5.1f%% (%.1f/%d): \f0%s", acc, accuracym[i].hits, (int)accuracym[i].shots, weapstr(i));
}
else
{
formatstring(line)("\f5%5.1f%s (%d/%d) :\f0%s", acc, "%", (int)accuracym[i].hits, (int)accuracym[i].shots, weapstr(i));
formatstring(line)("\f5%5.1f%% (%d/%d): \f0%s", acc, (int)accuracym[i].hits, accuracym[i].shots, weapstr(i));
}
blendbox(x_offset, y_offset + FONTH, x_offset + text_width(line) + 2 * FONTH, y_offset - FONTH, false, -1);
draw_textf("%s", x_offset + FONTH, y_offset - 0.5 * FONTH, line);
}
}
void accuracyinfo()
{
vector <char*>lines;
loopi(NUMGUNS) if(i != GUN_CPISTOL && accuracym[i].shots)
{
float acc = 100.0 * accuracym[i].hits / (float)accuracym[i].shots;
string line;
if(i == GUN_GRENADE || i == GUN_SHOTGUN)
{
formatstring(line)("\f0%-10s\t\f5 %.1f%% (%.1f/%d)", weapstr(i), acc, accuracym[i].hits, (int)accuracym[i].shots);
}
else
{
formatstring(line)("\f0%-10s\t\f5 %.1f%% (%d/%d)", weapstr(i), acc, (int)accuracym[i].hits, accuracym[i].shots);
}
cols=max(cols,(int)strlen(line));
lines.add(newstring(line));
}
if(rows<1) return;
cols++;
blendbox(x_offset, spacing+y_offset, spacing+x_offset+curfont->defaultw*cols, y_offset-curfont->defaulth*rows, true, -1);
int x = spacing * 0.5 + x_offset, y = y_offset - 0.5 * spacing;
loopv(lines) draw_textf("%s", x, y - i * curfont->defaulth, lines[i]);
loopv(lines) conoutf("%s", lines[i]);
lines.deletearrays();
}
COMMAND(accuracyinfo, "");
void accuracyreset()
{
loopi(NUMGUNS)
{
accuracym[i].hits=accuracym[i].shots=0;
}
conoutf("Your accuracy has been reset.");
conoutf("Your accuracy has been reset");
}
COMMAND(accuracyreset, "");
// weapon