1 // ==============================================================
2 //	This file is part of Glest (www.glest.org)
3 //
4 //	Copyright (C) 2001-2008 Martiño Figueroa
5 //
6 //	You can redistribute this code and/or modify it under
7 //	the terms of the GNU General Public License as published
8 //	by the Free Software Foundation; either version 2 of the
9 //	License, or (at your option) any later version
10 // ==============================================================
11 
12 #ifndef _GLEST_GAME_STATS_H_
13 #define _GLEST_GAME_STATS_H_
14 
15 #ifdef WIN32
16     #include <winsock2.h>
17     #include <winsock.h>
18 #endif
19 
20 #include <string>
21 #include "game_constants.h"
22 #include "faction.h"
23 #include "faction_type.h"
24 #include "vec.h"
25 #include "leak_dumper.h"
26 
27 using std::string;
28 using namespace Shared::Graphics;
29 
30 namespace Glest{ namespace Game{
31 
32 class PlayerStats {
33 public:
34 	PlayerStats();
35 
36 	ControlType control;
37 	float resourceMultiplier;
38 	string factionTypeName;
39 	FactionPersonalityType personalityType;
40 	int teamIndex;
41 	bool victory;
42 	int kills;
43 	int enemykills;
44 	int deaths;
45 	int unitsProduced;
46 	int resourcesHarvested;
47 	string playerName;
48 	bool playerLeftBeforeEnd;
49 	int timePlayerLeft;
50 	Vec3f playerColor;
51 
52 	string getStats() const;
53 };
54 
55 // =====================================================
56 // 	class Stats
57 //
58 ///	Player statistics that are shown after the game ends
59 // =====================================================
60 
61 class Stats {
62 private:
63 	PlayerStats playerStats[GameConstants::maxPlayers];
64 
65 	string description;
66 	int factionCount;
67 	int thisFactionIndex;
68 
69 	float worldTimeElapsed;
70 	int framesPlayed;
71 	int framesToCalculatePlaytime;
72 	int maxConcurrentUnitCount;
73 	int totalEndGameConcurrentUnitCount;
74 	bool isMasterserverMode;
75 	string techName;
76 
77 public:
78 
Stats()79 	Stats() {
80 		//description 		= "";
81 		factionCount 		= 0;
82 		thisFactionIndex 	= 0;
83 
84 		worldTimeElapsed				= 0.0;
85 		framesPlayed					= 0;
86 		framesToCalculatePlaytime		= 0;
87 		maxConcurrentUnitCount			= 0;
88 		totalEndGameConcurrentUnitCount	= 0;
89 		isMasterserverMode				= false;
90 		//techName						= "";
91 	}
92 
93 	void init(int factionCount, int thisFactionIndex, const string &description,
94 			const string &techName);
95 
getDescription()96 	string getDescription() const	{return description;}
getThisFactionIndex()97 	int getThisFactionIndex() const	{return thisFactionIndex;}
getFactionCount()98 	int getFactionCount() const		{return factionCount;}
99 
getWorldTimeElapsed()100 	float getWorldTimeElapsed() const 				{return worldTimeElapsed;}
getFramesPlayed()101 	int getFramesPlayed() const 					{return framesPlayed; }
getFramesToCalculatePlaytime()102 	int getFramesToCalculatePlaytime() const 		{return framesToCalculatePlaytime; }
getMaxConcurrentUnitCount()103 	int getMaxConcurrentUnitCount() const 			{return maxConcurrentUnitCount; }
getTotalEndGameConcurrentUnitCount()104 	int getTotalEndGameConcurrentUnitCount() const 	{return totalEndGameConcurrentUnitCount; }
105 
getFactionTypeName(int factionIndex)106 	const string &getFactionTypeName(int factionIndex) const	{return playerStats[factionIndex].factionTypeName;}
getPersonalityType(int factionIndex)107 	FactionPersonalityType getPersonalityType(int factionIndex) const { return playerStats[factionIndex].personalityType;}
getControl(int factionIndex)108 	ControlType getControl(int factionIndex) const				{return playerStats[factionIndex].control;}
getResourceMultiplier(int factionIndex)109 	float getResourceMultiplier(int factionIndex) const			{return playerStats[factionIndex].resourceMultiplier;}
getVictory(int factionIndex)110 	bool getVictory(int factionIndex) const						{return playerStats[factionIndex].victory;}
getTeam(int factionIndex)111 	int getTeam(int factionIndex) const							{return playerStats[factionIndex].teamIndex;}
getKills(int factionIndex)112 	int getKills(int factionIndex) const						{return playerStats[factionIndex].kills;}
getEnemyKills(int factionIndex)113 	int getEnemyKills(int factionIndex) const					{return playerStats[factionIndex].enemykills;}
getDeaths(int factionIndex)114 	int getDeaths(int factionIndex) const						{return playerStats[factionIndex].deaths;}
getUnitsProduced(int factionIndex)115 	int getUnitsProduced(int factionIndex) const				{return playerStats[factionIndex].unitsProduced;}
getResourcesHarvested(int factionIndex)116 	int getResourcesHarvested(int factionIndex) const			{return playerStats[factionIndex].resourcesHarvested;}
getPlayerName(int factionIndex)117 	string getPlayerName(int factionIndex) const				{return playerStats[factionIndex].playerName;}
getPlayerLeftBeforeEnd(int factionIndex)118 	bool getPlayerLeftBeforeEnd(int factionIndex) const			{return playerStats[factionIndex].playerLeftBeforeEnd;}
setPlayerLeftBeforeEnd(int factionIndex,bool value)119 	void setPlayerLeftBeforeEnd(int factionIndex, bool value) 	{playerStats[factionIndex].playerLeftBeforeEnd = value; }
getPlayerColor(int factionIndex)120 	Vec3f getPlayerColor(int factionIndex) const				{ return playerStats[factionIndex].playerColor;}
121 
getTimePlayerLeft(int factionIndex)122 	int getTimePlayerLeft(int factionIndex) const			{return playerStats[factionIndex].timePlayerLeft;}
setTimePlayerLeft(int factionIndex,int value)123 	void setTimePlayerLeft(int factionIndex, int value) 	{playerStats[factionIndex].timePlayerLeft = value; }
124 
125 
getIsMasterserverMode()126 	bool getIsMasterserverMode() const							{ return isMasterserverMode; }
setIsMasterserverMode(bool value)127 	void setIsMasterserverMode(bool value) 						{ isMasterserverMode = value; }
128 
setDescription(const string & description)129 	void setDescription(const string& description)							{this->description = description;}
setWorldTimeElapsed(float value)130 	void setWorldTimeElapsed(float value)  				{this->worldTimeElapsed = value;}
setFramesPlayed(int value)131 	void setFramesPlayed(int value)  					{this->framesPlayed = value; }
setMaxConcurrentUnitCount(int value)132 	void setMaxConcurrentUnitCount(int value)  			{this->maxConcurrentUnitCount = value; }
setTotalEndGameConcurrentUnitCount(int value)133 	void setTotalEndGameConcurrentUnitCount(int value) 	{this->totalEndGameConcurrentUnitCount = value; }
134 
setFactionTypeName(int playerIndex,const string & factionTypeName)135 	void setFactionTypeName(int playerIndex, const string& factionTypeName)	{playerStats[playerIndex].factionTypeName= factionTypeName;}
setPersonalityType(int playerIndex,FactionPersonalityType value)136 	void setPersonalityType(int playerIndex, FactionPersonalityType value)  {playerStats[playerIndex].personalityType = value;}
setControl(int playerIndex,ControlType control)137 	void setControl(int playerIndex, ControlType control)					{playerStats[playerIndex].control= control;}
setResourceMultiplier(int playerIndex,float resourceMultiplier)138 	void setResourceMultiplier(int playerIndex, float resourceMultiplier)	{playerStats[playerIndex].resourceMultiplier= resourceMultiplier;}
setTeam(int playerIndex,int teamIndex)139 	void setTeam(int playerIndex, int teamIndex)							{playerStats[playerIndex].teamIndex= teamIndex;}
140 	void setVictorious(int playerIndex);
141 	void kill(int killerFactionIndex, int killedFactionIndex, bool isEnemy, bool isDeathCounted, bool isKillCounted);
142 	void die(int diedFactionIndex, bool isDeathCounted);
143 	void produce(int producerFactionIndex, bool isProductionCounted);
144 	void harvest(int harvesterFactionIndex, int amount);
setPlayerName(int playerIndex,string value)145 	void setPlayerName(int playerIndex, string value) 	{playerStats[playerIndex].playerName = value; }
setPlayerColor(int playerIndex,Vec3f value)146 	void setPlayerColor(int playerIndex, Vec3f value)	{playerStats[playerIndex].playerColor = value; }
147 
addFramesToCalculatePlaytime()148 	void addFramesToCalculatePlaytime()  		{this->framesToCalculatePlaytime++; }
149 
setTechName(string name)150 	void setTechName(string name) { techName = name; }
getTechName()151 	string getTechName() const { return techName; }
152 
153 	string getStats() const;
154 
155 	void saveGame(XmlNode *rootNode);
156 	void loadGame(const XmlNode *rootNode);
157 };
158 
159 }}//end namespace
160 
161 #endif
162