From 2e3453c61083e1fbab98d3b04578e9344d2ff66b Mon Sep 17 00:00:00 2001 From: Rafael Barreto Date: Sat, 29 May 2010 20:46:25 +0000 Subject: [PATCH] extras, hudextras, points, and scoreboard (thanks to Franz) git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5102 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clients2c.cpp | 30 ++++++++++++++++-------------- source/src/entity.h | 4 ++-- source/src/main.cpp | 6 +++--- source/src/protocol.h | 2 +- source/src/scoreboard.cpp | 22 +++++++++++++--------- source/src/server.cpp | 7 ++++++- source/src/server.h | 4 ++-- source/src/serverchecks.h | 4 ++-- 8 files changed, 45 insertions(+), 34 deletions(-) diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index cb2c0df2..b6dc3fb3 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -241,21 +241,10 @@ void showhudextras(char hudextras, char value){ case HE_COMBO4: case HE_COMBO5: { - int n = value+1 - HE_COMBO; - if (n > 4) outf("\f3%s",SSPAM("monster combo!!!")); + int n = value - HE_COMBO; + if (n > 3) outf("\f3%s",SSPAM("monster combo!!!")); else if (!n) outf("\f5%s",SSPAM("combo")); - else outf("\f5%s x%d",SSPAM("multi combo"),n); - break; - } - case HE_KILL2: - case HE_KILL3: - case HE_KILL4: - case HE_KILL5: - { - int n = value - HE_KILL2; - if (n > 4) outf("\f3%s",SSPAM("monster kill!!!")); - else if (!n) outf("\f5%s",SSPAM("double kill")); - else outf("\f5%s x%d",SSPAM("multi kill"),n+1); + else outf("\f5%s x%d",SSPAM("multi combo"),n+1); break; } case HE_TEAMWORK: @@ -635,6 +624,19 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) break; } + case SV_POINTS: + { + int count = getint(p); + loopi(count){ + int pcn = getint(p); int score = getint(p); + playerent *ppl = pcn == getclientnum() ? player1 : getclient(pcn); + if (!ppl) break; + ppl->points = score; +// printf("POINTS RECEIVED: %s %d\n",ppl->name,score); + } + break; + } + case SV_HUDEXTRAS: { char value = getint(p); diff --git a/source/src/entity.h b/source/src/entity.h index e6888641..28eee232 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -346,7 +346,7 @@ private: public: int clientnum, lastupdate, plag, ping; int lifesequence; // sequence id for each respawn, used in damage test - int frags, flagscore, deaths; + int frags, flagscore, deaths, points; int lastaction, lastmove, lastpain, lastvoicecom; int clientrole; bool attacking; @@ -373,7 +373,7 @@ public: bool ignored, muted; - playerent() : curskin(0), clientnum(-1), lastupdate(0), plag(0), ping(0), lifesequence(0), frags(0), flagscore(0), deaths(0), lastpain(0), lastvoicecom(0), clientrole(CR_DEFAULT), + playerent() : curskin(0), clientnum(-1), lastupdate(0), plag(0), ping(0), lifesequence(0), frags(0), flagscore(0), deaths(0), points(0), lastpain(0), lastvoicecom(0), clientrole(CR_DEFAULT), team(TEAM_SPECT), spectatemode(SM_NONE), followplayercn(FPCN_VOID), eardamagemillis(0), respawnoffset(0), prevweaponsel(NULL), weaponsel(NULL), nextweaponsel(NULL), primweap(NULL), nextprimweap(NULL), lastattackweapon(NULL), smoothmillis(-1), diff --git a/source/src/main.cpp b/source/src/main.cpp index 3ac30296..0d446559 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -845,9 +845,9 @@ int main(int argc, char **argv) initlog("cfg"); extern void *scoremenu, *teammenu, *ctfmenu, *servmenu, *searchmenu, *serverinfomenu, *kickmenu, *banmenu, *forceteammenu, *giveadminmenu, *docmenu, *applymenu; - scoremenu = addmenu("score", "frags\tdeath\tratio\tpj\tping\tcn\tname", false, renderscores, NULL, false, true); - teammenu = addmenu("team score", "frags\tdeath\tratio\tpj\tping\tcn\tname", false, renderscores, NULL, false, true); - ctfmenu = addmenu("ctf score", "flags\tfrags\tdeath\tratio\tpj\tping\tcn\tname", false, renderscores, NULL, false, true); + scoremenu = addmenu("score", "frags\tdeath\tratio\tpoints\tpj\tping\tcn\tname", false, renderscores, NULL, false, true); + teammenu = addmenu("team score", "frags\tdeath\tratio\tpoints\tpj\tping\tcn\tname", false, renderscores, NULL, false, true); + ctfmenu = addmenu("ctf score", "flags\tfrags\tdeath\tratio\tpoints\tpj\tping\tcn\tname", false, renderscores, NULL, false, true); servmenu = addmenu("server", NULL, true, refreshservers, serverskey); searchmenu = addmenu("search", NULL, true, refreshservers, serverskey); serverinfomenu = addmenu("serverinfo", NULL, true, refreshservers, serverinfokey); diff --git a/source/src/protocol.h b/source/src/protocol.h index 74933dfc..f9cc685d 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -61,7 +61,7 @@ enum { FM_PICKUP = 0, FM_DROP, FM_LOST, FM_RETURN, FM_SCORE, FM_KTFSCORE, FM_SCO enum { LMSITEM_CLEAR = 0, LMSITEM_ANNOUNCE, LMSITEM_SPAWN, LMSITEM_NUM }; enum { FTR_INFO = 0, FTR_PLAYERWISH, FTR_AUTOTEAM, FTR_SILENTFORCE, FTR_NUM }; // forceteam-reasons enum { SP_OK = 0, SP_REFILLMATCH, SP_OK_NUM, SP_WRONGMAP, SP_SPECT, SP_NUM }; // spawn permission ( discscores; struct teamscore { - int team, frags, deaths, flagscore; + int team, frags, deaths, flagscore, points; vector teammembers; - teamscore(int t) : team(t), frags(0), deaths(0), flagscore(0) {} + teamscore(int t) : team(t), frags(0), deaths(0), flagscore(0), points(0) {} void addplayer(playerent *d) { @@ -39,6 +39,7 @@ struct teamscore teammembers.add(d); frags += d->frags; deaths += d->deaths; + points += d->points; if(m_flags) flagscore += d->flagscore; } @@ -46,6 +47,7 @@ struct teamscore { frags += d.frags; deaths += d.deaths; +// points += d.points; if(m_flags) flagscore += d.flags; } }; @@ -92,7 +94,7 @@ const char *scoreratio(int frags, int deaths) float ratio = (float)(frags >= 0 ? frags : 0) / (float)(deaths > 0 ? deaths : 1); int precision = 0; if(ratio<10.0f) precision = 2; - else if(ratio>=10.0f && ratio<100.0f) precision = 1; + else if(ratio<100.0f) precision = 1; formatstring(res)("%.*f", precision, ratio); return res; } @@ -118,15 +120,16 @@ void renderscore(playerent *d) if(d->clientrole==CR_ADMIN) status = d->state==CS_DEAD ? "\f7" : "\f3"; else if(d->state==CS_DEAD) status = "\f4"; const char *spect = team_isspect(d->team) ? "\f4" : ""; - const char *sr = scoreratio(d->frags, d->deaths); +// const char *sr = scoreratio(d->frags, d->deaths); + float ratio = (float)(d->frags >= 0 ? d->frags : 0) / (float)(d->deaths > 0 ? d->deaths : 1); const char *clag = team_isspect(d->team) ? "SPECT" : (d->state==CS_LAGGED ? "LAG" : colorpj(d->plag)); const char *cping = colorping(d->ping); const char *ign = d->ignored ? " (ignored)" : (d->muted ? " (muted)" : ""); sline &line = scorelines.add(); line.bgcolor = d==player1 ? &localplayerc : NULL; string &s = line.s; - if(m_flags) formatstring(s)("%s%d\t%d\t%d\t%s\t%s\t%s\t%d\t%s%s%s", spect, d->flagscore, d->frags, d->deaths, sr, clag, cping, d->clientnum, status, colorname(d), ign); - else formatstring(s)("%s%d\t%d\t%s\t%s\t%s\t%d\t%s%s%s", spect, d->frags, d->deaths, sr, clag, cping, d->clientnum, status, colorname(d), ign); + if(m_flags) formatstring(s)("%s%d\t%d\t%d\t%.1f\t%.1f\t%s\t%s\t%d\t%s%s%s", spect, d->flagscore, d->frags, d->deaths, ratio, 0.1f * d->points, clag, cping, d->clientnum, status, colorname(d), ign); + else formatstring(s)("%s%d\t%d\t%.1f\t%.1f\t%s\t%s\t%d\t%s%s%s", spect, d->frags, d->deaths, ratio, 0.1f * d->points, clag, cping, d->clientnum, status, colorname(d), ign); } void renderteamscore(teamscore *t) @@ -138,9 +141,10 @@ void renderteamscore(teamscore *t) } sline &line = scorelines.add(); defformatstring(plrs)("(%d %s)", t->teammembers.length(), t->teammembers.length() == 1 ? "player" : "players"); - const char *sr = scoreratio(t->frags, t->deaths); - if(m_flags) formatstring(line.s)("%d\t%d\t%d\t%s\t\t\t\t%s\t\t%s", t->flagscore, t->frags, t->deaths, sr, team_string(t->team), plrs); - else formatstring(line.s)("%d\t%d\t%s\t\t\t\t%s\t\t%s", t->frags, t->deaths, sr, team_string(t->team), plrs); +// const char *sr = scoreratio(t->frags, t->deaths); + float ratio = (float)(t->frags >= 0 ? t->frags : 0) / (float)(t->deaths > 0 ? t->deaths : 1); + if(m_flags) formatstring(line.s)("%d\t%d\t%d\t%.1f\t%.1f\t\t\t\t%s\t\t%s", t->flagscore, t->frags, t->deaths, ratio, 0.1f * t->points, team_string(t->team), plrs); + else formatstring(line.s)("%d\t%d\t%.1f\t%.1f\t\t\t\t%s\t\t%s", t->frags, t->deaths, ratio, 0.1f * t->points, team_string(t->team), plrs); static color teamcolors[2] = { color(1.0f, 0, 0, 0.2f), color(0, 0, 1.0f, 0.2f) }; line.bgcolor = &teamcolors[team_base(t->team)]; loopv(t->teammembers) renderscore(t->teammembers[i]); diff --git a/source/src/server.cpp b/source/src/server.cpp index 25635702..696c8676 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -356,10 +356,14 @@ void sendextras() loopv(clients) { client &c = *clients[i]; if ( c.type!=ST_TCPIP || !c.isauthed || !(c.md.updated && c.md.upmillis < gamemillis) ) continue; + if ( c.md.combosend ) { + sendf(c.clientnum, 1, "ri2", SV_HUDEXTRAS, c.md.combo-1 + HE_COMBO); + c.md.combosend = false; + } list[count] = i; count++; } - nextsendscore = gamemillis + (interm ? 10000 : 200); + nextsendscore = gamemillis + 200; if ( !count ) return; packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE); @@ -3221,6 +3225,7 @@ void serverslice(uint timeout) // main server update, called from cube main lo if(m_ktf && !ktfflagingame) flagaction(rnd(2), FA_RESET, -1); // ktf flag watchdog if(m_arena) arenacheck(); // if(m_lms) lmscheck(); + sendextras(); } if(curvote) diff --git a/source/src/server.h b/source/src/server.h index bd82834d..b617bece 100644 --- a/source/src/server.h +++ b/source/src/server.h @@ -197,13 +197,13 @@ struct medals { int points, lasthit, lastgun, combohits, combo, combotime, combodamage, ncombos, ncovers, nhs; int ask, askmillis, linked, linkmillis, linkreason, upmillis; - bool updated; + bool updated, combosend; void reset() { points = lasthit = lastgun = combohits = combo = combotime = combodamage = ncombos = ncovers = nhs = 0; askmillis = linkmillis = upmillis = 0; linkreason = linked = ask = -1; - updated = false; + updated = combosend = false; } }; diff --git a/source/src/serverchecks.h b/source/src/serverchecks.h index 29b10361..030ec81b 100644 --- a/source/src/serverchecks.h +++ b/source/src/serverchecks.h @@ -128,7 +128,7 @@ void checkcombo (client *target, client *actor, int damage, int gun) case GUN_KNIFE: case GUN_PISTOL: if ( guns[actor->md.lastgun].isauto ) break; - case GUN_GRENADE: + default: actor->md.combohits++; actor->md.combotime+=diffhittime; actor->md.combodamage+=damage; @@ -319,7 +319,7 @@ void checkfrag (client *target, client *actor, int gun, bool gib) } else addpt(actor, 10); - if ( actor->md.combo ) sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, actor->md.combo-1 + HE_COMBO); + if ( actor->md.combo ) actor->md.combosend = true; } else {