1 //////////////////////////////////////////////////////////////////////////////// 2 // Scorched3D (c) 2000-2011 3 // 4 // This file is part of Scorched3D. 5 // 6 // Scorched3D is free software; you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation; either version 2 of the License, or 9 // (at your option) any later version. 10 // 11 // Scorched3D is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License along 17 // with this program; if not, write to the Free Software Foundation, Inc., 18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 //////////////////////////////////////////////////////////////////////////////// 20 21 #if !defined(__INCLUDE_StatsLoggerh_INCLUDE__) 22 #define __INCLUDE_StatsLoggerh_INCLUDE__ 23 24 #include <tank/Tank.h> 25 #include <weapons/Weapon.h> 26 #include <list> 27 28 class StatsLogger 29 { 30 public: 31 static StatsLogger *instance(); 32 33 struct TankRank 34 { TankRankTankRank35 TankRank(unsigned int playerId) : 36 playerId_(playerId), rank_(-1), skill_(-1) {} TankRankTankRank37 TankRank(unsigned int playerId, int rank, int skill) : 38 playerId_(playerId), rank_(rank), skill_(skill) {} 39 getRankTankRank40 int getRank() { return rank_; } getSkillTankRank41 int getSkill() { return skill_; } getPlayerIdTankRank42 unsigned int getPlayerId() { return playerId_; } 43 setRankTankRank44 void setRank(int rank) { rank_ = rank; } setSkillTankRank45 void setSkill(int skill) { skill_ = skill; } setPlayerIdTankRank46 void setPlayerId(int playerId) { playerId_ = playerId; } 47 48 protected: 49 unsigned int playerId_; 50 int rank_; 51 int skill_; 52 }; 53 54 StatsLogger(); 55 virtual ~StatsLogger(); 56 57 virtual int getKillCount(const char *uniqueId) = 0; 58 virtual void gameStart(std::list<Tank *> &tanks) = 0; 59 virtual void roundStart(std::list<Tank *> &tanks) = 0; 60 61 virtual std::list<std::string> getAliases(const char *unqiueId) = 0; 62 virtual std::list<std::string> getIpAliases(const char *unqiueId) = 0; 63 virtual TankRank tankRank(Tank *tank) = 0; 64 virtual void updateStats(Tank *tank) = 0; 65 virtual void periodicUpdate() = 0; 66 virtual std::string allocateId() = 0; 67 virtual unsigned int getStatsId(const char *uniqueId) = 0; 68 virtual std::string getTopRanks() = 0; 69 virtual std::string getPlayerInfo(const char *player) = 0; 70 virtual void combinePlayers(unsigned int player1, unsigned int player2) = 0; 71 72 virtual void tankConnected(Tank *tank) = 0; 73 virtual void tankDisconnected(Tank *tank) = 0; 74 virtual void tankJoined(Tank *tank) = 0; 75 76 virtual void tankFired(Tank *firedTank, Weapon *weapon) = 0; 77 virtual void tankResigned(Tank *resignedTank) = 0; 78 79 virtual void tankKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon) = 0; 80 virtual void tankTeamKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon) = 0; 81 virtual void tankSelfKilled(Tank *firedTank, Weapon *weapon) = 0; 82 83 virtual void tankWon(Tank *tank) = 0; 84 virtual void tankOverallWinner(Tank *tank) = 0; 85 86 virtual void weaponFired(Weapon *weapon, bool deathAni) = 0; 87 virtual void weaponKilled(Weapon *weapon, bool deathAni) = 0; 88 89 protected: 90 static StatsLogger *instance_; 91 92 }; 93 94 class StatsLoggerNone : public StatsLogger 95 { 96 public: StatsLoggerNone()97 StatsLoggerNone() {} ~StatsLoggerNone()98 virtual ~StatsLoggerNone() {} 99 getKillCount(const char * uniqueId)100 virtual int getKillCount(const char *uniqueId) { return 0; } gameStart(std::list<Tank * > & tanks)101 virtual void gameStart(std::list<Tank *> &tanks) {} roundStart(std::list<Tank * > & tanks)102 virtual void roundStart(std::list<Tank *> &tanks) {} 103 getAliases(const char * unqiueId)104 virtual std::list<std::string> getAliases(const char *unqiueId) 105 { std::list<std::string> result; return result; } getIpAliases(const char * unqiueId)106 virtual std::list<std::string> getIpAliases(const char *unqiueId) 107 { std::list<std::string> result; return result; } tankRank(Tank * tank)108 virtual TankRank tankRank(Tank *tank) { return TankRank(tank->getPlayerId()); } updateStats(Tank * tank)109 virtual void updateStats(Tank *tank) {} periodicUpdate()110 virtual void periodicUpdate() {} allocateId()111 virtual std::string allocateId() { return ""; } getStatsId(const char * uniqueId)112 virtual unsigned int getStatsId(const char *uniqueId) { return 0; } getTopRanks()113 virtual std::string getTopRanks() { return ""; } getPlayerInfo(const char * player)114 virtual std::string getPlayerInfo(const char *player) { return ""; } combinePlayers(unsigned int player1,unsigned int player2)115 virtual void combinePlayers(unsigned int player1, unsigned int player2) {} 116 tankConnected(Tank * tank)117 virtual void tankConnected(Tank *tank) {} tankDisconnected(Tank * tank)118 virtual void tankDisconnected(Tank *tank) {} tankJoined(Tank * tank)119 virtual void tankJoined(Tank *tank) {} 120 tankFired(Tank * firedTank,Weapon * weapon)121 virtual void tankFired(Tank *firedTank, Weapon *weapon) {} tankResigned(Tank * resignedTank)122 virtual void tankResigned(Tank *resignedTank) {} 123 tankKilled(Tank * firedTank,Tank * deadTank,Weapon * weapon)124 virtual void tankKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon) {} tankTeamKilled(Tank * firedTank,Tank * deadTank,Weapon * weapon)125 virtual void tankTeamKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon) {} tankSelfKilled(Tank * firedTank,Weapon * weapon)126 virtual void tankSelfKilled(Tank *firedTank, Weapon *weapon) {} 127 tankWon(Tank * tank)128 virtual void tankWon(Tank *tank) {} tankOverallWinner(Tank * tank)129 virtual void tankOverallWinner(Tank *tank) {} 130 weaponFired(Weapon * weapon,bool deathAni)131 virtual void weaponFired(Weapon *weapon, bool deathAni) {} weaponKilled(Weapon * weapon,bool deathAni)132 virtual void weaponKilled(Weapon *weapon, bool deathAni) {} 133 }; 134 135 #endif 136 137