diff options
| author | xolatile | 2025-07-23 17:33:57 +0200 |
|---|---|---|
| committer | xolatile | 2025-07-23 17:33:57 +0200 |
| commit | a5a051f3356046fcaeaa295272d6859defebb320 (patch) | |
| tree | 2979d7bdbc94296bf4ccd6931bd37a91db4d6436 /src/fpsgame/weapon.cpp | |
| parent | 11a5f448e0f5c423a00103c5d36a776f07a600bd (diff) | |
| download | xolatile-badassbug-a5a051f3356046fcaeaa295272d6859defebb320.tar.xz xolatile-badassbug-a5a051f3356046fcaeaa295272d6859defebb320.tar.zst | |
Alternative GUI, more info in scoreboard, icons, accuracy, pickup state...
Diffstat (limited to 'src/fpsgame/weapon.cpp')
| -rw-r--r-- | src/fpsgame/weapon.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/fpsgame/weapon.cpp b/src/fpsgame/weapon.cpp index ab87ebf..f516c2e 100644 --- a/src/fpsgame/weapon.cpp +++ b/src/fpsgame/weapon.cpp @@ -363,6 +363,8 @@ namespace game if(f->type==ENT_AI || !m_mp(gamemode) || f==at) f->hitpush(damage, vel, at, gun); + pwhit(gun, damage); + if(!m_mp(gamemode)) damaged(damage, f, at); else { @@ -778,6 +780,8 @@ namespace game } if(d->gunselect) d->ammo[d->gunselect]--; + pwshot(d->gunselect); /// PW + vec from = d->o, to = targ, dir = vec(to).sub(from).safenormalize(); float dist = to.dist(from); vec kickback = vec(dir).mul(guns[d->gunselect].kickamount*-2.5f); @@ -807,8 +811,8 @@ namespace game hits.length(), hits.length()*sizeof(hitmsg)/sizeof(int), hits.getbuf()); } - d->gunwait = guns[d->gunselect].attackdelay; - if(d->gunselect == GUN_PISTOL && d->ai) d->gunwait += int(d->gunwait*(((101-d->skill)+rnd(111-d->skill))/100.f)); + d->gunwait = guns[d->gunselect].attackdelay; + if(d->gunselect == GUN_PISTOL && d->ai) d->gunwait += int(d->gunwait*(((101-d->skill)+rnd(111-d->skill))/100.f)); d->totalshots += guns[d->gunselect].damage*(d->quadmillis ? 4 : 1)*guns[d->gunselect].rays; } @@ -955,6 +959,7 @@ namespace game void updateweapons(int curtime) { updateprojectiles(curtime); + pwcalcaccuracy(); if(player1->clientnum>=0 && player1->state==CS_ALIVE) shoot(player1, worldpos); // only shoot when connected to server updatebouncers(curtime); // need to do this after the player shoots so grenades don't end up inside player's BB next frame fpsent *following = followingplayer(); @@ -983,3 +988,36 @@ namespace game } }; +/// Rough accuracy code, client-side only. + +int pwshotsfired [NUMGUNS] = { 0 }; +int pwshotshit [NUMGUNS] = { 0 }; +int pwdamagedealt [NUMGUNS] = { 0 }; +int pwaccuracy [NUMGUNS] = { 0 }; +int pwavgaccuracy = 0; + +void pwshot(int gun) { + pwshotsfired[gun]++; +} + +void pwhit(int gun, int damage) { + pwshotshit[gun]++; + pwdamagedealt[gun] += damage; +} + +void pwcalcaccuracy(void) { + pwavgaccuracy = 0; + loopi(NUMGUNS) + if(pwshotsfired[i]) + pwaccuracy[i] = (pwdamagedealt[i] * 100) / (guns[i].damage * guns[i].rays * pwshotsfired[i]); + else + pwaccuracy[i] = 0; + loopi(NUMGUNS) pwavgaccuracy += pwaccuracy[i]; + pwavgaccuracy /= NUMGUNS; +} + +void pwreset(void) { + loopi(NUMGUNS) pwshotsfired[i] = pwshotshit[i] = pwdamagedealt[i] = pwaccuracy[i] = 0; + loopi(7) pwitemspicked[i] = 0; + pwavgaccuracy = 0; +} |
