1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
/***************************************************************************
gamemap.h - description
-------------------
begin : Tue Feb 17 2001
copyright : (C) 2001 by Martin Bickel
email : bickel@asc-hq.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef playerH
#define playerH
#include <vector>
#include "typen.h"
#include "vehicle.h"
#include "buildings.h"
#include "basestrm.h"
#include "research.h"
#include "password.h"
#include "messages.h"
#include "networkinterface.h"
#include "playercolor.h"
class Player;
//! convenience-class which automatically determines the Player of units, buildings and other game objects
class PlayerID {
int num;
public:
PlayerID( int num ) { this->num = num; };
PlayerID( const ContainerBase* c ) : num( c->getOwner() ) {};
PlayerID( const ContainerBase& c ) : num( c.getOwner() ) {};
PlayerID( const Player& p );
PlayerID( const PlayerID& p ) : num( p.getID() ) {};
int getID() const { return num; };
};
const int diplomaticStateNum = 5;
enum DiplomaticStates { WAR, TRUCE, PEACE, PEACE_SV, ALLIANCE };
extern const char* diplomaticStateNames[diplomaticStateNum+1];
class DiplomaticStateVector : public SigC::Object {
friend class AllianceSetupWidget;
friend class ChangeDiplomaticState;
friend class DiplomacyCommand;
Player& player;
typedef vector<DiplomaticStates> States;
States states;
typedef map<int,DiplomaticStates> QueuedStateChanges;
QueuedStateChanges queuedStateChanges;
void resize( int size );
public:
DiplomaticStateVector( Player& _player );
DiplomaticStates getState( PlayerID towardsPlayer ) const;
void setState( PlayerID towardsPlayer, DiplomaticStates s );
bool isHostile( PlayerID towardsPlayer ) const { return getState( towardsPlayer.getID() ) == WAR; };
bool sharesView( PlayerID receivingPlayer ) const { return getState( receivingPlayer.getID() ) >= PEACE_SV; };
bool isAllied( PlayerID towardsPlayer ) const { return getState( towardsPlayer.getID() ) >= ALLIANCE; };
void turnBegins();
void swap( int secondPlayer );
//! \returns true if there are any proposals
bool getProposal( int fromPlayer, DiplomaticStates* state );
void read ( tnstream& stream );
void write ( tnstream& stream ) const;
};
class GameMap;
//! the different players in ASC. There may be 8 players (0..7) and neutral units (8)
class Player : public SigC::Object {
int player;
GameMap* parentMap;
void turnBegins( Player& p );
void userInteractionBegins( Player& p );
void turnEnds( Player& p );
public:
Player();
int getPosition() const { return player; };
const GameMap* getParentMap() const { return parentMap; };
GameMap* getParentMap() { return parentMap; };
void setParentMap( GameMap* map, int pos );
//! swaps all information, units, buildings etc with the given player
void swap ( Player& secondPlayer );
//! merges all units, buildings etc from secondplayer to this one
void merge( Player& secondPlayer );
//! does the player exist at all
bool exist() const;
//! did the player exist when the turn started? Required for checking if a player has been terminated
bool existanceAtBeginOfTurn;
typedef list<Vehicle*> VehicleList;
//! a list of all units
VehicleList vehicleList;
typedef list<Building*> BuildingList;
//! a list of all units
BuildingList buildingList;
//! the status of the scientific research
Research research;
Research& getResearch() { return research; };
//! if the player is run by an AI, this is the pointer to it
BaseAI* ai;
//! the status of the player
enum PlayerStatus { human, computer, off, supervisor, suspended } stat;
bool isHuman() const { return stat == human || stat == supervisor || stat == suspended; };
static int getHumanPlayerNum( const GameMap* gamemap );
static const char* playerStatusNames[];
//! returns the name of the player
ASCString getName( ) const;
void setName( const ASCString& name ) { this->name = name; };
void setName( const char* name ) { setName( ASCString(name)); };
//! the Password required for playing this player
Password passwordcrc;
class Dissection {
public:
Vehicletype* fzt;
const Technology* tech;
int orgpoints;
int points;
int num;
};
//! the list of dissected units
typedef list<Dissection> DissectionContainer;
DissectionContainer dissections;
bool __dissectionsToLoad;
//! the list of messages that haven't been read by the player yet
MessagePntrContainer unreadmessage;
bool __loadunreadmessage;
//! the list of messages that already have been read by the player yet
MessagePntrContainer oldmessage;
bool __loadoldmessage;
//! the list of messages that have been sent yet
MessagePntrContainer sentmessage;
bool __loadsentmessage;
//! if ASC should check all events for fullfilled triggers, this variable will be set to true. This does not mean that there really ARE events that are ready to be executed
int queuedEvents;
//! the version of ASC that this player has used to make his last turn
int ASCversion;
struct PlayTime {
int turn;
time_t date;
};
typedef list<PlayTime> PlayTimeContainer;
//! The time this player ended his turns. This is very informative in email games with > 2 players to find out who is delaying the game.
PlayTimeContainer playTime;
MapCoordinate cursorPos;
DiplomaticStateVector diplomacy;
ASCString email;
DI_Color getColor() const;
PlayerColor getPlayerColor() const;
void setColor( const DI_Color& color );
void read ( tnstream& stream );
void write ( tnstream& stream ) const;
void resetView();
void resetResearch();
void resetTribute();
void resetPassword();
private:
ASCString name;
DI_Color color;
void sendQueuedMessages();
};
#endif
|