diff options
| author | xolatile | 2025-08-06 22:54:55 +0200 |
|---|---|---|
| committer | xolatile | 2025-08-06 22:54:55 +0200 |
| commit | 0a1172b75f571685c264a8b9d8ee224bbf11381f (patch) | |
| tree | d041fdc68a60f0ebb48a3852bbcce6d9432f83d5 /src/fpsgame/scoreboard.cpp | |
| parent | affde05dc07a94643f1fd2751b2b441f57f73d7d (diff) | |
| download | xolatile-badassbug-0a1172b75f571685c264a8b9d8ee224bbf11381f.tar.xz xolatile-badassbug-0a1172b75f571685c264a8b9d8ee224bbf11381f.tar.zst | |
Please do not hate me, it makes sense...
Diffstat (limited to 'src/fpsgame/scoreboard.cpp')
| -rw-r--r-- | src/fpsgame/scoreboard.cpp | 263 |
1 files changed, 68 insertions, 195 deletions
diff --git a/src/fpsgame/scoreboard.cpp b/src/fpsgame/scoreboard.cpp index 96f8868..81f93a1 100644 --- a/src/fpsgame/scoreboard.cpp +++ b/src/fpsgame/scoreboard.cpp @@ -1,8 +1,7 @@ // creation of scoreboard #include "game.h" -namespace game -{ +namespace game { VARP(scoreboard2d, 0, 1, 1); VARP(showservinfo, 0, 1, 1); VARP(showclientnum, 0, 1, 1); @@ -15,25 +14,17 @@ namespace game VARP(hidefrags, 0, 0, 1); VARP(showdeaths, 0, 1, 1); VARP(showdamagedealt, 0, 1, 1); - static hashset<teaminfo> teaminfos; - - void clearteaminfo() - { + void clearteaminfo() { teaminfos.clear(); } - - void setteaminfo(const char *team, int frags) - { + void setteaminfo(const char *team, int frags) { teaminfo *t = teaminfos.access(team); if(!t) { t = &teaminfos[team]; copystring(t->team, team, sizeof(t->team)); } t->frags = frags; } - - static inline bool playersort(const fpsent *a, const fpsent *b) - { - if(a->state==CS_SPECTATOR) - { + static inline bool playersort(const fpsent *a, const fpsent *b) { + if(a->state==CS_SPECTATOR) { if(b->state==CS_SPECTATOR) return strcmp(a->name, b->name) < 0; else return false; } @@ -42,51 +33,38 @@ namespace game if(a->frags < b->frags) return false; return strcmp(a->name, b->name) < 0; } - - void getbestplayers(vector<fpsent *> &best) - { - loopv(players) - { + void getbestplayers(vector<fpsent *> &best) { + loopv(players) { fpsent *o = players[i]; if(o->state!=CS_SPECTATOR) best.add(o); } best.sort(playersort); while(best.length() > 1 && best.last()->frags < best[0]->frags) best.drop(); } - - void getbestteams(vector<const char *> &best) - { - if(!hidefrags) - { + void getbestteams(vector<const char *> &best) { + if(!hidefrags) { vector<teamscore> teamscores; teamscores.sort(teamscore::compare); while(teamscores.length() > 1 && teamscores.last().score < teamscores[0].score) teamscores.drop(); loopv(teamscores) best.add(teamscores[i].team); } - else - { + else { int bestfrags = INT_MIN; enumerate(teaminfos, teaminfo, t, bestfrags = max(bestfrags, t.frags)); - if(bestfrags <= 0) loopv(players) - { + if(bestfrags <= 0) loopv(players) { fpsent *o = players[i]; if(o->state!=CS_SPECTATOR && !teaminfos.access(o->team) && best.htfind(o->team) < 0) { bestfrags = 0; best.add(o->team); } } enumerate(teaminfos, teaminfo, t, if(t.frags >= bestfrags) best.add(t.team)); } } - - struct scoregroup : teamscore - { + struct scoregroup : teamscore { vector<fpsent *> players; }; static vector<scoregroup *> groups; static vector<fpsent *> spectators; - - static inline bool scoregroupcmp(const scoregroup *x, const scoregroup *y) - { - if(!x->team) - { + static inline bool scoregroupcmp(const scoregroup *x, const scoregroup *y) { + if(!x->team) { if(y->team) return false; } else if(!y->team) return true; @@ -96,20 +74,16 @@ namespace game if(x->players.length() < y->players.length()) return false; return x->team && y->team && strcmp(x->team, y->team) < 0; } - - static int groupplayers() - { + static int groupplayers() { int numgroups = 0; spectators.setsize(0); - loopv(players) - { + loopv(players) { fpsent *o = players[i]; if(!showconnecting && !o->name[0]) continue; if(o->state==CS_SPECTATOR) { spectators.add(o); continue; } const char *team = m_teammode && o->team[0] ? o->team : NULL; bool found = false; - loopj(numgroups) - { + loopj(numgroups) { scoregroup &g = *groups[j]; if(team!=g.team && (!team || !g.team || strcmp(team, g.team))) continue; g.players.add(o); @@ -129,31 +103,23 @@ namespace game groups.sort(scoregroupcmp, 0, numgroups); return numgroups; } - - int statuscolor(fpsent *d, int color) - { - if(d->privilege) - { + int statuscolor(fpsent *d, int color) { + if(d->privilege) { color = d->privilege>=PRIV_ADMIN ? 0xFF8000 : (d->privilege>=PRIV_AUTH ? 0xC040C0 : 0x40FF80); if(d->state==CS_DEAD) color = (color>>1)&0x7F7F7F; } else if(d->state==CS_DEAD) color = 0x606060; return color; } - - void renderscoreboard(g3d_gui &g, bool firstpass) - { + void renderscoreboard(g3d_gui &g, bool firstpass) { const ENetAddress *address = connectedpeer(); - if(showservinfo && address) - { + if(showservinfo && address) { string hostname; - if(enet_address_get_host_ip(address, hostname, sizeof(hostname)) >= 0) - { + if(enet_address_get_host_ip(address, hostname, sizeof(hostname)) >= 0) { if(servinfo[0]) g.titlef("%.25s", 0xFFFF80, NULL, servinfo); else g.titlef("%s:%d", 0xFFFF80, NULL, hostname, address->port); } } - g.pushlist(); g.spring(); g.text(server::modename(gamemode), 0xFFFF80); @@ -162,12 +128,10 @@ namespace game g.text(mname[0] ? mname : "[new map]", 0xFFFF80); extern int gamespeed; if(gamespeed != 100) { g.separator(); g.textf("%d.%02dx", 0xFFFF80, NULL, gamespeed/100, gamespeed%100); } - if(m_timed && mname[0] && (maplimit >= 0 || intermission)) - { + if(m_timed && mname[0] && (maplimit >= 0 || intermission)) { g.separator(); if(intermission) g.text("intermission", 0xFFFF80); - else - { + else { int secs = max(maplimit-lastmillis+999, 0)/1000, mins = secs/60; secs %= 60; g.pushlist(); @@ -179,41 +143,31 @@ namespace game if(ispaused()) { g.separator(); g.text("paused", 0xFFFF80); } g.spring(); g.poplist(); - g.separator(); - int numgroups = groupplayers(); - loopk(numgroups) - { + loopk(numgroups) { if((k%2)==0) g.pushlist(); // horizontal - scoregroup &sg = *groups[k]; int bgcolor = sg.team && m_teammode ? (isteam(player1->team, sg.team) ? 0x3030C0 : 0xC03030) : 0, fgcolor = 0xFFFF80; - g.pushlist(); // vertical g.pushlist(); // horizontal - #define loopscoregroup(o, b) \ - loopv(sg.players) \ - { \ + loopv(sg.players) { \ + \ fpsent *o = sg.players[i]; \ b; \ } - g.pushlist(); - if(sg.team && m_teammode) - { + if(sg.team && m_teammode) { g.pushlist(); g.background(bgcolor, numgroups>1 ? 3 : 5); g.strut(1); g.poplist(); } g.text("", 0, " "); - loopscoregroup(o, - { - if(o==player1 && highlightscore && (multiplayer(false) || demoplayback || players.length() > 1)) - { + loopscoregroup(o, { + if(o==player1 && highlightscore && (multiplayer(false) || demoplayback || players.length() > 1)) { g.pushlist(); g.background(0x808080, numgroups>1 ? 3 : 5); } @@ -223,104 +177,79 @@ namespace game if(o==player1 && highlightscore && (multiplayer(false) || demoplayback || players.length() > 1)) g.poplist(); }); g.poplist(); - - if(sg.team && m_teammode) - { + if(sg.team && m_teammode) { g.pushlist(); // vertical - if(sg.score>=10000) g.textf("%s: WIN", fgcolor, NULL, sg.team); else g.textf("%s: %d", fgcolor, NULL, sg.team, sg.score); - g.pushlist(); // horizontal } - - if(!hidefrags) - { + if(!hidefrags) { g.pushlist(); g.strut(6); g.text("frags", fgcolor); loopscoregroup(o, g.textf("%d", 0xFFFFDD, NULL, o->frags)); g.poplist(); } - - if(showdeaths) - { + if(showdeaths) { g.pushlist(); g.strut(6); g.text("deaths", fgcolor); loopscoregroup(o, g.textf("%d", 0xFFFFDD, NULL, o->deaths)); g.poplist(); } - - if(showdamagedealt) - { + if(showdamagedealt) { g.pushlist(); g.strut(7); g.text("damage", fgcolor); loopscoregroup(o, g.textf("%d", 0xFFFFDD, NULL, o->totaldamage)); g.poplist(); } - g.pushlist(); g.text("name", fgcolor); g.strut(12); loopscoregroup(o, { g.textf("%s ", statuscolor(o, 0xFFFFDD), NULL, colorname(o)); }); g.poplist(); - - if(multiplayer(false) || demoplayback) - { + if(multiplayer(false) || demoplayback) { if(showpj || showping) g.space(1); - - if(showpj && showping <= 1) - { + if(showpj && showping <= 1) { g.pushlist(); g.strut(6); g.text("pj", fgcolor); - loopscoregroup(o, - { + loopscoregroup(o, { if(o->state==CS_LAGGED) g.text("LAG", 0xFFFFDD); else g.textf("%d", 0xFFFFDD, NULL, o->plag); }); g.poplist(); } - - if(showping > 1) - { + if(showping > 1) { g.pushlist(); g.strut(6); - g.pushlist(); g.text("ping", fgcolor); g.space(1); g.spring(); g.text("pj", fgcolor); g.poplist(); - - loopscoregroup(o, - { + loopscoregroup(o, { fpsent *p = o->ownernum >= 0 ? getclient(o->ownernum) : o; if(!p) p = o; g.pushlist(); if(p->state==CS_LAGGED) g.text("LAG", 0xFFFFDD); - else - { + else { g.textf("%d", 0xFFFFDD, NULL, p->ping); g.space(1); g.spring(); g.textf("%d", 0xFFFFDD, NULL, o->plag); } g.poplist(); - }); g.poplist(); } - else if(showping) - { + else if(showping) { g.pushlist(); g.text("ping", fgcolor); g.strut(6); - loopscoregroup(o, - { + loopscoregroup(o, { fpsent *p = o->ownernum >= 0 ? getclient(o->ownernum) : o; if(!p) p = o; if(!showpj && p->state==CS_LAGGED) g.text("LAG", 0xFFFFDD); @@ -329,43 +258,31 @@ namespace game g.poplist(); } } - - if(showclientnum || player1->privilege>=PRIV_MASTER) - { + if(showclientnum || player1->privilege>=PRIV_MASTER) { g.space(1); g.pushlist(); g.text("cn", fgcolor); loopscoregroup(o, g.textf("%d", 0xFFFFDD, NULL, o->clientnum)); g.poplist(); } - - if(sg.team && m_teammode) - { + if(sg.team && m_teammode) { g.poplist(); // horizontal g.poplist(); // vertical } - g.poplist(); // horizontal g.poplist(); // vertical - if(k+1<numgroups && (k+1)%2) g.space(2); else g.poplist(); // horizontal } - - if(showspectators && spectators.length()) - { - if(showclientnum || player1->privilege>=PRIV_MASTER) - { + if(showspectators && spectators.length()) { + if(showclientnum || player1->privilege>=PRIV_MASTER) { g.pushlist(); - g.pushlist(); g.text("spectator", 0xFFFF80, " "); g.strut(12); - loopv(spectators) - { + loopv(spectators) { fpsent *o = spectators[i]; - if(o==player1 && highlightscore) - { + if(o==player1 && highlightscore) { g.pushlist(); g.background(0x808080, 3); } @@ -373,15 +290,12 @@ namespace game if(o==player1 && highlightscore) g.poplist(); } g.poplist(); - - if((multiplayer(false) || demoplayback) && showspectatorping) - { + if((multiplayer(false) || demoplayback) && showspectatorping) { g.space(1); g.pushlist(); g.text("ping", 0xFFFF80); g.strut(6); - loopv(spectators) - { + loopv(spectators) { fpsent *o = spectators[i]; fpsent *p = o->ownernum >= 0 ? getclient(o->ownernum) : o; if(!p) p = o; @@ -390,28 +304,22 @@ namespace game } g.poplist(); } - g.space(1); g.pushlist(); g.text("cn", 0xFFFF80); loopv(spectators) g.textf("%d", 0xFFFFDD, NULL, spectators[i]->clientnum); g.poplist(); - g.poplist(); } - else - { + else { g.textf("%d spectator%s", 0xFFFF80, " ", spectators.length(), spectators.length()!=1 ? "s" : ""); - loopv(spectators) - { - if((i%3)==0) - { + loopv(spectators) { + if((i%3)==0) { g.pushlist(); g.text("", 0xFFFFDD, "spectator"); } fpsent *o = spectators[i]; - if(o==player1 && highlightscore) - { + if(o==player1 && highlightscore) { g.pushlist(); g.background(0x808080); } @@ -422,7 +330,6 @@ namespace game } } } - /// PW g.separator(); g.pushlist(); @@ -445,53 +352,36 @@ namespace game g.textf(" x %d ", 0xffffff, "quad_damage.png", pwitemspicked[6]); g.poplist(); } - - struct scoreboardgui : g3d_callback - { + struct scoreboardgui : g3d_callback { bool showing; vec menupos; int menustart; - scoreboardgui() : showing(false) {} - - void show(bool on) - { - if(!showing && on) - { + void show(bool on) { + if(!showing && on) { menupos = menuinfrontofplayer(); menustart = starttime(); } showing = on; } - - void gui(g3d_gui &g, bool firstpass) - { + void gui(g3d_gui &g, bool firstpass) { g.start(menustart, 0.03f, NULL, false); renderscoreboard(g, firstpass); g.end(); } - - void render() - { + void render() { if(showing) g3d_addgui(this, menupos, (scoreboard2d ? GUI_FORCE_2D : GUI_2D | GUI_FOLLOW) | GUI_BOTTOM); } - } scoreboard; - - void g3d_gamemenus() - { + void g3d_gamemenus() { scoreboard.render(); } - VARFN(scoreboard, showscoreboard, 0, 0, 1, scoreboard.show(showscoreboard!=0)); - - void showscores(bool on) - { + void showscores(bool on) { showscoreboard = on ? 1 : 0; scoreboard.show(on); } ICOMMAND(showscores, "D", (int *down), showscores(*down!=0)); - VARP(hudscore, 0, 0, 1); FVARP(hudscorescale, 1e-3f, 1.0f, 1e3f); VARP(hudscorealign, -1, 0, 1); @@ -501,61 +391,48 @@ namespace game HVARP(hudscoreenemycolour, 0, 0xFF4040, 0xFFFFFF); VARP(hudscorealpha, 0, 255, 255); VARP(hudscoresep, 0, 200, 1000); - - void drawhudscore(int w, int h) - { + void drawhudscore(int w, int h) { int numgroups = groupplayers(); if(!numgroups) return; - scoregroup *g = groups[0]; int score = INT_MIN, score2 = INT_MIN; bool best = false; - if(m_teammode) - { + if(m_teammode) { score = g->score; best = isteam(player1->team, g->team); - if(numgroups > 1) - { + if(numgroups > 1) { if(best) score2 = groups[1]->score; else for(int i = 1; i < groups.length(); ++i) if(isteam(player1->team, groups[i]->team)) { score2 = groups[i]->score; break; } - if(score2 == INT_MIN) - { + if(score2 == INT_MIN) { fpsent *p = followingplayer(player1); if(p->state==CS_SPECTATOR) score2 = groups[1]->score; } } } - else - { + else { fpsent *p = followingplayer(player1); score = g->players[0]->frags; best = p == g->players[0]; - if(g->players.length() > 1) - { + if(g->players.length() > 1) { if(best || p->state==CS_SPECTATOR) score2 = g->players[1]->frags; else score2 = p->frags; } } if(score == score2 && !best) best = true; - score = clamp(score, -999, 9999); defformatstring(buf, "%d", score); int tw = 0, th = 0; text_bounds(buf, tw, th); - string buf2; int tw2 = 0, th2 = 0; - if(score2 > INT_MIN) - { + if(score2 > INT_MIN) { score2 = clamp(score2, -999, 9999); formatstring(buf2, "%d", score2); text_bounds(buf2, tw2, th2); } - int fw = 0, fh = 0; text_bounds("00", fw, fh); fw = max(fw, max(tw, tw2)); - vec2 offset = vec2(hudscorex, hudscorey).mul(vec2(w, h).div(hudscorescale)); if(hudscorealign == 1) offset.x -= 2*fw + hudscoresep; else if(hudscorealign == 0) offset.x -= (2*fw + hudscoresep) / 2.0f; @@ -564,17 +441,13 @@ namespace game offset.y -= th/2.0f; offset2.x += fw + hudscoresep + (fw-tw2)/2.0f; offset2.y -= th2/2.0f; - pushhudmatrix(); hudmatrix.scale(hudscorescale, hudscorescale, 1); flushhudmatrix(); - int color = hudscoreplayercolour, color2 = hudscoreenemycolour; if(!best) swap(color, color2); - draw_text(buf, int(offset.x), int(offset.y), (color>>16)&0xFF, (color>>8)&0xFF, color&0xFF, hudscorealpha); if(score2 > INT_MIN) draw_text(buf2, int(offset2.x), int(offset2.y), (color2>>16)&0xFF, (color2>>8)&0xFF, color2&0xFF, hudscorealpha); - pophudmatrix(); } } |
