Advanced Strategic Command
player.h
Go to the documentation of this file.
1 /***************************************************************************
2  gamemap.h - description
3  -------------------
4  begin : Tue Feb 17 2001
5  copyright : (C) 2001 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 #ifndef playerH
20  #define playerH
21 
22  #include <vector>
23  #include <list>
24 
25  #include "typen.h"
26  #include "vehicle.h"
27  #include "buildings.h"
28  #include "basestrm.h"
29  #include "research.h"
30  #include "password.h"
31  #include "messages.h"
32  #include "networkinterface.h"
33  #include "playercolor.h"
34 
35 
36 class Player;
37 
38 
40 class PlayerID {
41  int num;
42  public:
43  PlayerID( int num ) { this->num = num; };
44  PlayerID( const ContainerBase* c ) : num( c->getOwner() ) {};
45  PlayerID( const ContainerBase& c ) : num( c.getOwner() ) {};
46  PlayerID( const Player& p );
47  PlayerID( const PlayerID& p ) : num( p.getID() ) {};
48  int getID() const { return num; };
49 };
50 
51 
52 const int diplomaticStateNum = 5;
54 extern const char* diplomaticStateNames[diplomaticStateNum+1];
55 
56 
57 class DiplomaticStateVector : public sigc::trackable {
58 
59  friend class AllianceSetupWidget;
60  friend class ChangeDiplomaticState;
61  friend class DiplomacyCommand;
62 
63  Player& player;
64 
65  typedef vector<DiplomaticStates> States;
66  States states;
67 
68 
69  typedef map<int,DiplomaticStates> QueuedStateChanges;
70  QueuedStateChanges queuedStateChanges;
71 
72  void resize( int size );
73 
74  public:
75  DiplomaticStateVector( Player& _player );
76 
77  DiplomaticStates getState( PlayerID towardsPlayer ) const;
78  void setState( PlayerID towardsPlayer, DiplomaticStates s );
79 
80  bool isHostile( PlayerID towardsPlayer ) const { return getState( towardsPlayer.getID() ) == WAR; };
81  bool sharesView( PlayerID receivingPlayer ) const { return getState( receivingPlayer.getID() ) >= PEACE_SV; };
82  bool isAllied( PlayerID towardsPlayer ) const { return getState( towardsPlayer.getID() ) >= ALLIANCE; };
83 
84  void turnBegins();
85 
86  void swap( int secondPlayer );
87 
89  bool getProposal( int fromPlayer, DiplomaticStates* state );
90 
91  void read ( tnstream& stream );
92  void write ( tnstream& stream ) const;
93 };
94 
95 class GameMap;
96 
97 
99 class Player : public sigc::trackable {
100  int player;
101  GameMap* parentMap;
102 
103  void turnBegins( Player& p );
104  void userInteractionBegins( Player& p );
105  void turnEnds( Player& p );
106 
107  int serverPlayerID;
108 
109  public:
110  Player();
111 
112  int getPosition() const { return player; };
113 
114  const GameMap* getParentMap() const { return parentMap; };
115  GameMap* getParentMap() { return parentMap; };
116 
117  void setParentMap( GameMap* map, int pos );
118 
119 
121  void swap ( Player& secondPlayer );
122 
124  void merge( Player& secondPlayer );
125 
126 
128  bool exist() const;
129 
132 
133  typedef list<Vehicle*> VehicleList;
136 
137  typedef list<Building*> BuildingList;
140 
143 
144  Research& getResearch() { return research; };
145 
147  BaseAI* ai;
148 
151 
152  bool isHuman() const { return stat == human || stat == supervisor || stat == suspended; };
153 
154  static int getHumanPlayerNum( const GameMap* gamemap );
155 
156  static const char* playerStatusNames[];
157 
159  ASCString getName( ) const;
160  void setName( const ASCString& name ) { this->name = name; };
161 
164 
165  class Dissection {
166  public:
168  const Technology* tech;
170  int points;
171  int num;
172  };
173 
175  typedef list<Dissection> DissectionContainer;
177 
179 
183 
187 
191 
194 
197 
198  struct PlayTime {
199  int turn;
200  time_t date;
201  };
202  typedef list<PlayTime> PlayTimeContainer;
203 
206 
208 
210 
212 
213  DI_Color getColor() const;
214  PlayerColor getPlayerColor() const;
215  void setColor( const DI_Color& color );
216 
217  void read ( tnstream& stream );
218  void write ( tnstream& stream ) const;
219 
220  void resetView();
221  void resetResearch();
222  void resetTribute();
223  void resetPassword();
224 
225  bool operator==( const Player& otherPlayer) const;
226 
227  void setPlayerID( int id ) { serverPlayerID = id; };
228  int getPlayerID() const { return serverPlayerID; };
229 
230  private:
231  ASCString name;
232  DI_Color color;
233  void sendQueuedMessages();
234 };
235 
236 
237 
238 #endif
239 
DiplomaticStates getState(PlayerID towardsPlayer) const
Definition: player.cpp:92
Research & getResearch()
Definition: player.h:144
MessagePntrContainer sentmessage
the list of messages that have been sent yet
Definition: player.h:189
int queuedEvents
if ASC should check all events for fullfilled triggers, this variable will be set to true...
Definition: player.h:193
int getPlayerID() const
Definition: player.h:228
DiplomaticStates
Definition: player.h:53
void setColor(const DI_Color &color)
A Device Independent color. Shamelessly pinched from Paragui to reduce coupling.
Definition: surface.h:30
bool isHostile(PlayerID towardsPlayer) const
Definition: player.h:80
Definition: player.h:53
void setParentMap(GameMap *map, int pos)
Definition: player.cpp:203
bool __loadunreadmessage
Definition: player.h:182
Classes and Functions managing the in-game mails and the journal.
static const char * playerStatusNames[]
Definition: player.h:156
void read(tnstream &stream)
Definition: player.cpp:321
BaseAI * ai
if the player is run by an AI, this is the pointer to it
Definition: player.h:144
int getPosition() const
Definition: player.h:112
const GameMap * getParentMap() const
Definition: player.h:114
bool __loadoldmessage
Definition: player.h:186
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
A class for holding, encoding and comparing passwords.
DiplomaticStateVector diplomacy
Definition: player.h:209
Player()
Definition: player.cpp:192
void read(tnstream &stream)
Definition: player.cpp:145
PlayerColor getPlayerColor() const
Definition: player.cpp:268
bool isHuman() const
Definition: player.h:152
void resetResearch()
Definition: player.cpp:499
MessagePntrContainer oldmessage
the list of messages that already have been read by the player yet
Definition: player.h:185
void swap(int secondPlayer)
Definition: player.cpp:462
bool sharesView(PlayerID receivingPlayer) const
Definition: player.h:81
Definition: player.h:53
The buildings which a placed on the map.
The interface for all kinds of IO stream.
GameMap * getParentMap()
Definition: player.h:115
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void setName(const ASCString &name)
Definition: player.h:160
bool operator==(const Player &otherPlayer) const
Definition: player.cpp:521
void resetPassword()
Definition: player.cpp:516
const int diplomaticStateNum
Definition: player.h:52
const char * diplomaticStateNames[diplomaticStateNum+1]
Definition: player.cpp:36
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
void setState(PlayerID towardsPlayer, DiplomaticStates s)
Definition: player.cpp:115
void resetView()
Definition: player.cpp:488
VehicleList vehicleList
a list of all units
Definition: player.h:135
PlayerID(const ContainerBase &c)
Definition: player.h:45
enum Player::PlayerStatus stat
Coordinate on the twodimensional map.
Definition: typen.h:202
MapCoordinate cursorPos
Definition: player.h:207
VehicleType * fzt
Definition: player.h:167
The interface for the various streams that ASC offers, like file and memory streams.
bool __dissectionsToLoad
Definition: player.h:178
void write(tnstream &stream) const
Definition: player.cpp:163
list< Vehicle * > VehicleList
Definition: player.h:133
ASCString email
Definition: player.h:211
DI_Color getColor() const
Definition: player.cpp:249
void merge(Player &secondPlayer)
merges all units, buildings etc from secondplayer to this one
Definition: player.cpp:482
list< Message * > MessagePntrContainer
Definition: messages.h:74
static int getHumanPlayerNum(const GameMap *gamemap)
Definition: player.cpp:285
list< Dissection > DissectionContainer
the list of dissected units
Definition: player.h:175
void swap(Player &secondPlayer)
swaps all information, units, buildings etc with the given player
Definition: player.cpp:350
cancels the research on the current technology, losing all research points
void resetTribute()
Definition: player.cpp:504
void write(tnstream &stream) const
Definition: player.cpp:331
BuildingList buildingList
a list of all units
Definition: player.h:139
PlayerID(const PlayerID &p)
Definition: player.h:47
Research research
the status of the scientific research
Definition: player.h:142
time_t date
Definition: player.h:200
Definition: player.h:53
bool isAllied(PlayerID towardsPlayer) const
Definition: player.h:82
PlayerStatus
the status of the player
Definition: player.h:150
PlayerID(int num)
Definition: player.h:43
bool existanceAtBeginOfTurn
did the player exist when the turn started? Required for checking if a player has been terminated ...
Definition: player.h:131
list< Building * > BuildingList
Definition: player.h:137
void setPlayerID(int id)
Definition: player.h:227
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
int getID() const
Definition: player.h:48
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
Password passwordcrc
the Password required for playing this player
Definition: player.h:160
PlayTimeContainer playTime
The time this player ended his turns. This is very informative in email games with > 2 players to fin...
Definition: player.h:205
DissectionContainer dissections
Definition: player.h:176
bool __loadsentmessage
Definition: player.h:190
bool getProposal(int fromPlayer, DiplomaticStates *state)
Definition: player.cpp:127
convenience-class which automatically determines the Player of units, buildings and other game object...
Definition: player.h:40
PlayerID(const ContainerBase *c)
Definition: player.h:44
Everything related to research.
list< PlayTime > PlayTimeContainer
Definition: player.h:202
DiplomaticStateVector(Player &_player)
Definition: player.cpp:48
int ASCversion
the version of ASC that this player has used to make his last turn
Definition: player.h:196
bool exist() const
does the player exist at all
Definition: player.cpp:313
cancels the research on the current technology, losing all research points
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
MessagePntrContainer unreadmessage
the list of messages that haven't been read by the player yet
Definition: player.h:181
const Technology * tech
Definition: player.h:168