1 #pragma once 2 3 #include "common.h" 4 5 #include "TinyXML/tinyxml.h" 6 7 /** Handles the players, including all the AI. 8 */ 9 10 class Sector; 11 class PlayingGameState; 12 13 using std::stringstream; 14 15 class PlayerType { 16 public: 17 enum PlayerTypeID { 18 PLAYER_RED = 0, 19 PLAYER_GREEN = 1, 20 PLAYER_YELLOW = 2, 21 PLAYER_BLUE = 3 22 }; 23 static const char *getName(PlayerTypeID id); 24 static void getColour(int *r,int *g,int *b,PlayerTypeID id); 25 }; 26 27 class Player { 28 int index; // saved 29 bool dead; // saved 30 31 int n_births; // saved 32 int n_deaths; // saved 33 int n_men_for_this_island; // saved 34 int n_suspended; // saved 35 36 bool is_human; 37 38 void doSectorAI(int client_player, PlayingGameState *gamestate, Sector *sector); 39 static bool alliances[n_players_c][n_players_c]; 40 static int alliance_last_asked[n_players_c][n_players_c]; 41 42 int alliance_last_asked_human; // time we last asked human player, to avoid continually asking // aved 43 44 static void setAllianceLastAsked(int a, int b,int time); 45 static int allianceLastAsked(int a, int b); 46 public: 47 //Player(int index, char *name); 48 //Player(int index, int personality); 49 Player(bool is_human, int index); 50 ~Player(); 51 isHuman()52 bool isHuman() const { 53 return this->is_human; 54 } 55 //int getShieldIndex(); 56 static int getShieldIndex(bool allied[n_players_c]); 57 /*int getPersonality() { 58 return personality; 59 }*/ 60 void doAIUpdate(int client_player, PlayingGameState *gamestate); 61 int getFinalMen() const; isDead()62 bool isDead() const { 63 return this->dead; 64 } 65 void kill(PlayingGameState *gamestate); 66 bool askHuman(); 67 bool requestAlliance(int player); 68 getNBirths()69 int getNBirths() const { 70 return this->n_births; 71 } getNDeaths()72 int getNDeaths() const { 73 return this->n_deaths; 74 } getNMenForThisIsland()75 int getNMenForThisIsland() const { 76 return this->n_men_for_this_island; 77 } getNSuspended()78 int getNSuspended() const { 79 return this->n_suspended; 80 } 81 registerBirths(int n)82 void registerBirths(int n) { 83 this->n_births += n; 84 } setNDeaths(int n)85 void setNDeaths(int n) { 86 this->n_deaths = n; 87 } addNDeaths(int n)88 void addNDeaths(int n) { 89 this->n_deaths += n; 90 } setNMenForThisIsland(int n)91 void setNMenForThisIsland(int n) { 92 this->n_men_for_this_island = n; 93 } setNSuspended(int n)94 void setNSuspended(int n) { 95 this->n_suspended = n; 96 } addNSuspended(int n)97 void addNSuspended(int n) { 98 this->n_suspended += n; 99 } 100 101 void saveState(stringstream &stream) const; 102 void loadStateParseXMLNode(const TiXmlNode *parent); 103 static void saveStateAlliances(stringstream &stream); 104 static void loadStateParseXMLNodeAlliances(const TiXmlNode *parent); 105 106 static void setAlliance(int a, int b, bool alliance); 107 static bool isAlliance(int a, int b); 108 static void resetAllAlliances(); 109 }; 110