Skip to content

Commit

Permalink
display accuracy on player stats
Browse files Browse the repository at this point in the history
  • Loading branch information
siecvi committed Aug 9, 2024
1 parent b3b15b2 commit 7ce9c70
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 38 deletions.
17 changes: 11 additions & 6 deletions Resources/Locales/es/openspades.po
Original file line number Diff line number Diff line change
Expand Up @@ -2344,32 +2344,37 @@ msgstr ""
"Sincronización vertical:Sincroniza las actualizaciones de la pantalla con la "
"frecuencia de actualización del monitor.|Off|On|Adaptativo"

#: Sources/Client/Client_Draw.cpp:771
#: Sources/Client/Client_Draw.cpp:860
msgctxt "Client"
msgid "Accuracy: {0}%"
msgstr "Precisión: {0}%"

#: Sources/Client/Client_Draw.cpp:864
msgctxt "Client"
msgid "K/D Ratio: {0}"
msgstr "Ratio de muertes: {0}"

#: Sources/Client/Client_Draw.cpp:772
#: Sources/Client/Client_Draw.cpp:866
msgctxt "Client"
msgid "Kill Streak: {0}"
msgstr "Racha de muertes: {0}"

#: Sources/Client/Client_Draw.cpp:773
#: Sources/Client/Client_Draw.cpp:867
msgctxt "Client"
msgid "Best Streak: {0}"
msgstr "Mejor racha: {0}"

#: Sources/Client/Client_Draw.cpp:774
#: Sources/Client/Client_Draw.cpp:868
msgctxt "Client"
msgid "Melee Kills: {0}"
msgstr "Muertes cuerpo a cuerpo: {0}"

#: Sources/Client/Client_Draw.cpp:775
#: Sources/Client/Client_Draw.cpp:869
msgctxt "Client"
msgid "Grenade Kills: {0}"
msgstr "Muertes por granada: {0}"

#: Sources/Client/Client_Draw.cpp:778
#: Sources/Client/Client_Draw.cpp:870
msgctxt "Client"
msgid "Blocks Placed: {0}"
msgstr "Bloques colocados: {0}"
Expand Down
17 changes: 11 additions & 6 deletions Resources/Locales/pot/openspades.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2266,32 +2266,37 @@ msgid ""
"On|Adaptive"
msgstr ""

#: Sources/Client/Client_Draw.cpp:771
#: Sources/Client/Client_Draw.cpp:860
msgctxt "Client"
msgid "Accuracy: {0}%"
msgstr ""

#: Sources/Client/Client_Draw.cpp:864
msgctxt "Client"
msgid "K/D Ratio: {0}"
msgstr ""

#: Sources/Client/Client_Draw.cpp:772
#: Sources/Client/Client_Draw.cpp:866
msgctxt "Client"
msgid "Kill Streak: {0}"
msgstr ""

#: Sources/Client/Client_Draw.cpp:773
#: Sources/Client/Client_Draw.cpp:867
msgctxt "Client"
msgid "Best Streak: {0}"
msgstr ""

#: Sources/Client/Client_Draw.cpp:774
#: Sources/Client/Client_Draw.cpp:868
msgctxt "Client"
msgid "Melee Kills: {0}"
msgstr ""

#: Sources/Client/Client_Draw.cpp:775
#: Sources/Client/Client_Draw.cpp:869
msgctxt "Client"
msgid "Grenade Kills: {0}"
msgstr ""

#: Sources/Client/Client_Draw.cpp:778
#: Sources/Client/Client_Draw.cpp:870
msgctxt "Client"
msgid "Blocks Placed: {0}"
msgstr ""
Expand Down
6 changes: 6 additions & 0 deletions Sources/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ namespace spades {
meleeKills(0),
grenadeKills(0),
placedBlocks(0),
rifleHits(0),
smgHits(0),
shotgunHits(0),
rifleShots(0),
smgShots(0),
shotgunShots(0),
localFireVibrationTime(-1.0F),
grenadeVibration(0.0F),
grenadeVibrationSlow(0.0F),
Expand Down
7 changes: 7 additions & 0 deletions Sources/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ namespace spades {
int meleeKills;
int grenadeKills;
int placedBlocks;
int rifleHits;
int smgHits;
int shotgunHits;
int rifleShots;
int smgShots;
int shotgunShots;
float worldSetTime;

bool reloadKeyPressed;
Expand Down Expand Up @@ -527,6 +533,7 @@ namespace spades {

void BulletHitPlayer(Player& hurtPlayer, HitType, Vector3 hitPos, Player& by,
std::unique_ptr<IBulletHitScanState>& stateCell) override;
void BulletNearPlayer(Player& by) override;
void BulletHitBlock(Vector3, IntVector3 blockPos, IntVector3 normal) override;
void AddBulletTracer(Player& player, Vector3 muzzlePos, Vector3 hitPos) override;
void GrenadeExploded(const Grenade&) override;
Expand Down
26 changes: 23 additions & 3 deletions Sources/Client/Client_Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,9 @@ namespace spades {
// draw damaged portion
if (hurtTime > 0.0F) {
Vector4 dmgColor = red + (white - red) * hurtTime;
float dmgBarH = damageTaken * (barW / maxHealth) * hurtTime;
for (float x2 = barPrg; x2 < barPrg + dmgBarH; x2 += 1.0F) {
float per = 1.0F - ((x2 - barPrg) / dmgBarH);
float dmgBarW = damageTaken * (barW / maxHealth) * hurtTime;
for (float x2 = barPrg; x2 < barPrg + dmgBarW; x2 += 1.0F) {
float per = 1.0F - ((x2 - barPrg) / dmgBarW);
renderer->SetColorAlphaPremultiplied(dmgColor * per);
renderer->DrawImage(img, AABB2(barX + x2 - 1.0F, barY, 1.0F, barH));
}
Expand Down Expand Up @@ -821,6 +821,8 @@ namespace spades {
void Client::DrawPlayerStats() {
SPADES_MARK_FUNCTION();

Player& p = GetWorld()->GetLocalPlayer().value();

IFont& font = cg_smallFont
? fontManager->GetSmallFont()
: fontManager->GetGuiFont();
Expand All @@ -839,6 +841,24 @@ namespace spades {
MakeVector4(0, 0, 0, 0.8F));
};

int hits, shots;
switch (p.GetWeaponType()) {
case RIFLE_WEAPON:
hits = rifleHits;
shots = rifleShots;
break;
case SMG_WEAPON:
hits = smgHits;
shots = smgShots;
break;
case SHOTGUN_WEAPON:
hits = shotgunHits;
shots = shotgunShots;
break;
}
int accPerc = int(100.0F * (float(hits) / float(std::max(1, shots))));
addLine(_Tr("Client", "Accuracy: {0}%", accPerc));

char buf[64];
sprintf(buf, "%.3g", curKills / float(std::max(1, curDeaths)));
addLine(_Tr("Client", "K/D Ratio: {0}", std::string(buf)));
Expand Down
61 changes: 42 additions & 19 deletions Sources/Client/Client_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,27 +1075,30 @@ namespace spades {

auto& hitScanState = dynamic_cast<BulletHitScanState&>(*stateCell);

if (!IsMuted() && !hitScanState.hasPlayedNormalHitSound) {
if (!hitScanState.hasPlayedNormalHitSound) {
Handle<IAudioChunk> c;
AudioParam param;
if (type == HitTypeMelee) {
c = audioDevice->RegisterSound("Sounds/Weapons/Spade/HitPlayer.opus");
audioDevice->Play(c.GetPointerOrNull(), hitPos, param);
} else {
switch (SampleRandomInt(0, 2)) {
case 0:
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Flesh1.opus");
break;
case 1:
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Flesh2.opus");
break;
case 2:
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Flesh3.opus");
break;
}

param.volume = 4.0F;
audioDevice->Play(c.GetPointerOrNull(), hitPos, param);
if (!IsMuted()) {
if (type == HitTypeMelee) {
c = audioDevice->RegisterSound("Sounds/Weapons/Spade/HitPlayer.opus");
audioDevice->Play(c.GetPointerOrNull(), hitPos, param);
} else {
switch (SampleRandomInt(0, 2)) {
case 0:
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Flesh1.opus");
break;
case 1:
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Flesh2.opus");
break;
case 2:
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Flesh3.opus");
break;
}

param.volume = 4.0F;
audioDevice->Play(c.GetPointerOrNull(), hitPos, param);
}
}

if (byLocalPlayer && type != HitTypeHead) {
Expand All @@ -1110,6 +1113,15 @@ namespace spades {
if (byLocalPlayer) {
net->SendHit(hurtPlayer.GetId(), type);

// register bullet hits
if (type != HitTypeMelee) {
switch (by.GetWeaponType()) {
case RIFLE_WEAPON: rifleHits++; break;
case SMG_WEAPON: smgHits++; break;
case SHOTGUN_WEAPON: shotgunHits++; break;
}
}

if ((bool)cg_damageIndicators && type != HitTypeMelee) {
DamageIndicator damages;
damages.damage = by.GetWeapon().GetDamage(type);
Expand Down Expand Up @@ -1158,7 +1170,7 @@ namespace spades {
chatWindow->AddMessage(s);
}

if (type == HitTypeHead && !hitScanState.hasPlayedHeadshotSound) {
if (!hitScanState.hasPlayedHeadshotSound && type == HitTypeHead) {
Handle<IAudioChunk> c =
audioDevice->RegisterSound("Sounds/Feedback/HeadshotFeedback.opus");
AudioParam param;
Expand All @@ -1174,6 +1186,17 @@ namespace spades {
}
}

void Client::BulletNearPlayer(spades::client::Player& by) {
SPADES_MARK_FUNCTION();

// register near shots
switch (by.GetWeaponType()) {
case RIFLE_WEAPON: rifleShots++; break;
case SMG_WEAPON: smgShots++; break;
case SHOTGUN_WEAPON: shotgunShots++; break;
}
}

void Client::BulletHitBlock(Vector3 hitPos, IntVector3 blockPos, IntVector3 normal) {
SPADES_MARK_FUNCTION();

Expand Down
1 change: 1 addition & 0 deletions Sources/Client/IWorldListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace spades {
virtual void BulletHitPlayer(Player& hurtPlayer, HitType hitType, Vector3 hitPos,
Player& by,
std::unique_ptr<IBulletHitScanState>& stateCell) = 0;
virtual void BulletNearPlayer(Player& by) = 0;
virtual void BulletHitBlock(Vector3 hitPos, IntVector3 blockPos, IntVector3 normal) = 0;
virtual void AddBulletTracer(Player& player, Vector3 muzzlePos, Vector3 hitPos) = 0;

Expand Down
17 changes: 13 additions & 4 deletions Sources/Client/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,12 @@ namespace spades {
return false;

// |P-A|^2
float sq = sqDist2D + diff.z * diff.z;
float sqDist3D = sqDist2D + diff.z * diff.z;

// |P-A| * sin(theta)
float dist = sqrtf(sq - c * c);
float dist = sqDist3D - (c * c);

return dist < tolerance;
return dist < (tolerance * tolerance);
}

enum class HitBodyPart { None, Head, Torso, Leg1, Leg2, Arms };
Expand Down Expand Up @@ -547,6 +547,7 @@ namespace spades {
GameMap::RayCastResult mapResult;
mapResult = map->CastRay2(muzzle, dir, 256);

bool nearPlayer = false;
stmp::optional<Player&> hitPlayer;
float hitPlayerDist2D = 0.0F; // disregarding Z coordinate
float hitPlayerDist3D = 0.0F;
Expand All @@ -563,8 +564,11 @@ namespace spades {
Player& other = maybeOther.value();
if (!other.IsAlive() || other.IsSpectator())
continue; // filter deads/spectators
if (!other.RayCastApprox(muzzle, dir))
if (other.RayCastApprox(muzzle, dir)) {
nearPlayer = true;
} else {
continue; // quickly reject players unlikely to be hit
}

Vector3 hitPos;
HitBoxes hb = other.GetHitBoxes();
Expand Down Expand Up @@ -712,6 +716,10 @@ namespace spades {
hitType, finalHitPos, *this, stateCell);
}

// register near shots
if (listener && nearPlayer && IsLocalPlayer())
listener->BulletNearPlayer(*this);

if (listener)
listener->AddBulletTracer(*this, muzzle, finalHitPos);
} // one pellet done
Expand All @@ -722,6 +730,7 @@ namespace spades {
if (debugger && !playerHits.empty())
debugger->SaveImage(playerHits, bulletVectors);

// do weapon recoil
Vector2 rec = weapon->GetRecoil();

// vanilla's horizontial recoil is driven by a triangular wave generator.
Expand Down

0 comments on commit 7ce9c70

Please sign in to comment.