From: Daniel R. <dtr...@us...> - 2004-08-12 18:56:17
|
Update of /cvsroot/bzflag/bzflag/src/bzflag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11921/src/bzflag Modified Files: Makefile.am ShotStatistics.h ShotStats.cxx Added Files: ShotStatistics.cxx Log Message: More compact shot statistics display; calculation/display of Favorite Flag / Best Flag --- NEW FILE: ShotStatistics.cxx --- /* bzflag * Copyright (c) 1993 - 2004 Tim Riker * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file * named COPYING that should have accompanied this file. * * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ // BZFlag common header #include "common.h" // System headers #include <vector> #include <utility> // Interface header #include "ShotStatistics.h" // Common implementation headers #include "Flag.h" ShotStatistics::ShotStatistics() : normalFired(0), normalHit(0), guidedMissileFired(0), guidedMissileHit(0), laserFired(0), laserHit(0), superBulletFired(0), superBulletHit(0), shockWaveFired(0), shockWaveHit(0), thiefFired(0), thiefHit(0) { } ShotStatistics::~ShotStatistics() { } int ShotStatistics::getTotalPerc() const { if (getTotalFired() == 0) return 100; return (int)(100 * ((float)getTotalHit() / (float)getTotalFired())); } void ShotStatistics::recordFire(FlagType* flag) { if (flag == Flags::GuidedMissile) guidedMissileFired++; else if (flag == Flags::Laser) laserFired++; else if (flag == Flags::SuperBullet) superBulletFired++; else if (flag == Flags::ShockWave) shockWaveFired++; else if (flag == Flags::Thief) thiefFired++; else normalFired++; } void ShotStatistics::recordHit(FlagType* flag) { if (flag == Flags::GuidedMissile) guidedMissileHit++; else if (flag == Flags::Laser) laserHit++; else if (flag == Flags::SuperBullet) superBulletHit++; else if (flag == Flags::ShockWave) shockWaveHit++; else if (flag == Flags::Thief) thiefHit++; else normalHit++; } typedef std::pair<FlagType*, float> FlagStat; FlagType* ShotStatistics::getFavoriteFlag() const { /* return the flag the player fired most */ std::vector<FlagStat> flags; FlagStat greatest = std::make_pair(Flags::Null, 0.0f); // no entry for none/null - looking for favorite *flag* flags.push_back(std::make_pair(Flags::GuidedMissile, (float)guidedMissileFired)); flags.push_back(std::make_pair(Flags::Laser, (float)laserFired)); flags.push_back(std::make_pair(Flags::SuperBullet, (float)superBulletFired)); flags.push_back(std::make_pair(Flags::ShockWave, (float)shockWaveFired)); flags.push_back(std::make_pair(Flags::Thief, (float)thiefFired)); // we don't deal with the case where there are two "equally favorite" // flags; doesn't really matter for (int i = 0; i < flags.size(); i++) { if (flags[i].second > greatest.second) greatest = flags[i]; } return greatest.first; } FlagType* ShotStatistics::getBestFlag() const { /* return the flag with the best hits/fired ratio */ std::vector<FlagStat> flags; FlagStat greatest = std::make_pair(Flags::Null, 0.0f); // normal shots have the opportunity to be best flags.push_back(std::make_pair(Flags::Null, ((float)normalHit / normalFired))); flags.push_back(std::make_pair(Flags::GuidedMissile, ((float)guidedMissileHit / guidedMissileFired))); flags.push_back(std::make_pair(Flags::Laser, ((float)laserHit / laserFired))); flags.push_back(std::make_pair(Flags::SuperBullet, ((float)superBulletHit / superBulletFired))); flags.push_back(std::make_pair(Flags::ShockWave, ((float)shockWaveHit / shockWaveFired))); flags.push_back(std::make_pair(Flags::Thief, ((float)thiefHit / thiefFired))); // we don't deal with the case where there are two "equally best" // flags; doesn't really matter for (int i = 0; i < flags.size(); i++) { if (flags[i].second > greatest.second) greatest = flags[i]; } return greatest.first; } // Local Variables: *** // mode: C++ *** // tab-width: 8 *** // c-basic-offset: 2 *** // indent-tabs-mode: t *** // End: *** // ex: shiftwidth=2 tabstop=8 Index: Makefile.am =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/Makefile.am,v retrieving revision 1.77 retrieving revision 1.78 diff -w -u -r1.77 -r1.78 --- Makefile.am 6 Aug 2004 02:04:07 -0000 1.77 +++ Makefile.am 12 Aug 2004 18:56:07 -0000 1.78 @@ -119,6 +119,7 @@ ShotStatsDefaultKey.cxx \ ShotStatsDefaultKey.h \ ShotStatistics.h \ + ShotStatistics.cxx \ ShotStrategy.cxx \ ShotStrategy.h \ SilenceDefaultKey.cxx \ Index: ShotStatistics.h =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/ShotStatistics.h,v retrieving revision 1.2 retrieving revision 1.3 diff -w -u -r1.2 -r1.3 --- ShotStatistics.h 6 Aug 2004 22:22:16 -0000 1.2 +++ ShotStatistics.h 12 Aug 2004 18:56:07 -0000 1.3 @@ -23,15 +23,8 @@ class ShotStatistics { public: - ShotStatistics() : - normalFired(0), normalHit(0), - guidedMissileFired(0), guidedMissileHit(0), - laserFired(0), laserHit(0), - superBulletFired(0), superBulletHit(0), - shockWaveFired(0), shockWaveHit(0), - thiefFired(0), thiefHit(0) - {}; - ~ShotStatistics() {}; + ShotStatistics(); + ~ShotStatistics(); // raw stats returns int getNormalFired() const; @@ -51,6 +44,8 @@ int getTotalFired() const; int getTotalHit() const; int getTotalPerc() const; + FlagType* getFavoriteFlag() const; + FlagType* getBestFlag() const; // tally functions void recordFire(FlagType* flag); @@ -130,41 +125,6 @@ shockWaveHit + thiefHit; } -inline int ShotStatistics::getTotalPerc() const { - if (getTotalFired() == 0) - return 100; - return (int)(100 * ((float)getTotalHit() / (float)getTotalFired())); -} - -inline void ShotStatistics::recordFire(FlagType* flag) { - if (flag == Flags::GuidedMissile) - guidedMissileFired++; - else if (flag == Flags::Laser) - laserFired++; - else if (flag == Flags::SuperBullet) - superBulletFired++; - else if (flag == Flags::ShockWave) - shockWaveFired++; - else if (flag == Flags::Thief) - thiefFired++; - else - normalFired++; -} - -inline void ShotStatistics::recordHit(FlagType* flag) { - if (flag == Flags::GuidedMissile) - guidedMissileHit++; - else if (flag == Flags::Laser) - laserHit++; - else if (flag == Flags::SuperBullet) - superBulletHit++; - else if (flag == Flags::ShockWave) - shockWaveHit++; - else if (flag == Flags::Thief) - thiefHit++; - else - normalHit++; -} #endif // __SHOTSTATISTICS_H__ // Local Variables: *** Index: ShotStats.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/ShotStats.cxx,v retrieving revision 1.3 retrieving revision 1.4 diff -w -u -r1.3 -r1.4 --- ShotStats.cxx 6 Aug 2004 05:00:44 -0000 1.3 +++ ShotStats.cxx 12 Aug 2004 18:56:07 -0000 1.4 @@ -46,26 +46,24 @@ // add title createLabel("Shot Statistics", list); - columns = 16; + // key + createLabel("Shots Hit/Fired", list); + + columns = 11; rows = 0; // section headings createLabel("\nPlayer", list); createLabel("\nHit%", list); - createLabel("Total\nFired", list); - createLabel("Total\nHit", list); - createLabel("Norm.\nFired", list); - createLabel("Norm.\nHit", list); - createLabel("GM\nFired", list); - createLabel("GM\nHit", list); - createLabel("Laser\nFired", list); - createLabel("Laser\nHit", list); - createLabel("SB\nFired", list); - createLabel("SB\nHit", list); - createLabel("SW\nFired", list); - createLabel("SW\nHit", list); - createLabel("Thief\nFired", list); - createLabel("Thief\nHit", list); + createLabel("\nTotal", list); + createLabel("\nNorm", list); + createLabel("\nGM", list); + createLabel("\nLaser", list); + createLabel("Super\nBullet", list); + createLabel("Shock\nWave", list); + createLabel("\nThief", list); + createLabel("Fave.\nFlag", list); + createLabel("Best\nFlag", list); ++rows; // my statistics first @@ -101,36 +99,32 @@ const ShotStatistics* stats = player->getShotStatistics(); createLabel(player->getCallSign(), list); + sprintf(buffer, "%2d%%", stats->getTotalPerc()); createLabel(buffer, list); - sprintf(buffer, "%d", stats->getTotalFired()); - createLabel(buffer, list); - sprintf(buffer, "%d", stats->getTotalHit()); - createLabel(buffer, list); - sprintf(buffer, "%d", stats->getNormalFired()); - createLabel(buffer, list); - sprintf(buffer, "%d", stats->getNormalHit()); + sprintf(buffer, "%d/%d", stats->getTotalHit(), stats->getTotalFired()); createLabel(buffer, list); - sprintf(buffer, "%d", stats->getGMFired()); + sprintf(buffer, "%d/%d", stats->getNormalHit(), stats->getNormalFired()); createLabel(buffer, list); - sprintf(buffer, "%d", stats->getGMHit()); + sprintf(buffer, "%d/%d", stats->getGMHit(), stats->getGMFired()); createLabel(buffer, list); - sprintf(buffer, "%d", stats->getLFired()); + sprintf(buffer, "%d/%d", stats->getLHit(), stats->getLFired()); createLabel(buffer, list); - sprintf(buffer, "%d", stats->getLHit()); + sprintf(buffer, "%d/%d", stats->getSBHit(), stats->getSBFired()); createLabel(buffer, list); - sprintf(buffer, "%d", stats->getSBFired()); + sprintf(buffer, "%d/%d", stats->getSWHit(), stats->getSWFired()); createLabel(buffer, list); - sprintf(buffer, "%d", stats->getSBHit()); + sprintf(buffer, "%d/%d", stats->getTHHit(), stats->getTHFired()); createLabel(buffer, list); - sprintf(buffer, "%d", stats->getSWFired()); - createLabel(buffer, list); - sprintf(buffer, "%d", stats->getSWHit()); - createLabel(buffer, list); - sprintf(buffer, "%d", stats->getTHFired()); + + strcpy(buffer, stats->getFavoriteFlag()->flagAbbv); + if (buffer == "") buffer = "None"; createLabel(buffer, list); - sprintf(buffer, "%d", stats->getTHHit()); + + strcpy(buffer, stats->getBestFlag()->flagAbbv); + if (buffer == "") buffer = "None"; createLabel(buffer, list); + ++rows; delete[] buffer; @@ -178,17 +172,27 @@ float y = titleY; title->setPosition(x, y); - for (int i = 1; i < (int)list.size(); ++i) { - // determine row & column (i - 1 to account for title) - int row = (i - 1) / columns; - int column = (i - 1) - (columns * row) + 1; + // center key + HUDuiLabel* key = (HUDuiLabel*)list[1]; + key->setFontSize(fontSize); + const float keyCenter = ((columns / 2) + 4) * columnWidth; + const float keyWidth = fm.getStrLength(getFontFace(), fontSize, key->getString()); + const float keyY = titleY - 2 * fm.getStrHeight(getFontFace(), fontSize, " "); + y = keyY; + x = keyCenter - 0.5f * keyWidth; + key->setPosition(x, y); + + for (int i = 2; i < (int)list.size(); ++i) { + // determine row & column (i - 2 to account for title & key) + int row = (i - 2) / columns; + int column = (i - 2) - (columns * row) + 1; // account for 3 extra columns in player name if (column > 1) column = column + 3; // find coordinates corresponding to this row & column x = column * columnWidth; - y = titleY - (row + 1) * rowHeight; + y = keyY - (row + 1) * rowHeight; // headings take up an additional row (embedded newlines) if (row > 0) y -= rowHeight; |