player.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           gamemap.h  -  description
00003                              -------------------
00004     begin                : Tue Feb 17 2001
00005     copyright            : (C) 2001 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #ifndef playerH
00020  #define playerH
00021 
00022  #include <vector>
00023 
00024  #include "typen.h"
00025  #include "vehicle.h"
00026  #include "buildings.h"
00027  #include "basestrm.h"
00028  #include "research.h"
00029  #include "password.h"
00030  #include "messages.h"
00031  #include "networkinterface.h"
00032  #include "playercolor.h"
00033  
00034 
00035 class Player;
00036 
00037 
00039 class PlayerID {
00040       int num;
00041    public:
00042       PlayerID( int num ) { this->num = num; };
00043       PlayerID( const ContainerBase* c ) : num( c->getOwner() ) {};
00044       PlayerID( const ContainerBase& c ) : num( c.getOwner() ) {};
00045       PlayerID( const Player& p );
00046       PlayerID( const PlayerID& p ) : num( p.getID() ) {};
00047       int getID() const { return num; };
00048 };
00049 
00050 
00051 const int diplomaticStateNum = 5;
00052 enum DiplomaticStates { WAR, TRUCE, PEACE, PEACE_SV, ALLIANCE };
00053 extern const char* diplomaticStateNames[diplomaticStateNum+1];
00054 
00055 
00056 class DiplomaticStateVector : public SigC::Object {
00057 
00058       friend class AllianceSetupWidget;
00059       friend class ChangeDiplomaticState;
00060       friend class DiplomacyCommand;
00061 
00062       Player& player; 
00063       
00064       typedef vector<DiplomaticStates> States;
00065       States states;
00066       
00067        
00068       typedef map<int,DiplomaticStates> QueuedStateChanges;
00069       QueuedStateChanges queuedStateChanges;
00070 
00071       void resize( int size );
00072       
00073    public:
00074       DiplomaticStateVector( Player& _player );
00075       
00076       DiplomaticStates getState( PlayerID towardsPlayer ) const;
00077       void setState( PlayerID towardsPlayer, DiplomaticStates s );
00078       
00079       bool isHostile( PlayerID towardsPlayer ) const { return getState( towardsPlayer.getID() ) == WAR; };
00080       bool sharesView( PlayerID receivingPlayer ) const { return getState( receivingPlayer.getID() ) >= PEACE_SV; };
00081       bool isAllied( PlayerID towardsPlayer ) const { return getState( towardsPlayer.getID() ) >= ALLIANCE; };
00082 
00083       void turnBegins();
00084       
00085       void swap( int secondPlayer );
00086             
00088       bool getProposal( int fromPlayer, DiplomaticStates* state );
00089       
00090       void read ( tnstream& stream );
00091       void write ( tnstream& stream ) const;
00092 };
00093 
00094 class GameMap;
00095 
00096 
00098 class Player : public SigC::Object {
00099       int player;
00100       GameMap* parentMap;
00101       
00102       void turnBegins( Player& p );
00103       void userInteractionBegins( Player& p );
00104       void turnEnds( Player& p );
00105       
00106       int serverPlayerID;
00107 
00108    public:
00109       Player();
00110 
00111       int getPosition() const { return player; };
00112       
00113       const GameMap* getParentMap() const { return parentMap; };
00114       GameMap* getParentMap() { return parentMap; };
00115       
00116       void setParentMap( GameMap* map, int pos );
00117       
00118 
00120       void swap ( Player& secondPlayer );
00121 
00123       void merge( Player& secondPlayer );
00124 
00125 
00127       bool         exist() const;
00128 
00130       bool existanceAtBeginOfTurn;
00131 
00132       typedef list<Vehicle*> VehicleList;
00134       VehicleList  vehicleList;
00135 
00136       typedef list<Building*> BuildingList;
00138       BuildingList  buildingList;
00139 
00141       Research    research;
00142       
00143       Research& getResearch() { return research; };
00144 
00146       BaseAI*      ai;
00147 
00149       enum PlayerStatus { human, computer, off, supervisor, suspended } stat;
00150       
00151       bool isHuman() const { return stat == human || stat == supervisor || stat == suspended; };
00152 
00153       static int getHumanPlayerNum( const GameMap* gamemap );
00154 
00155       static const char* playerStatusNames[];
00156 
00158       ASCString getName( ) const;
00159       void setName( const ASCString& name ) { this->name = name; };
00160 
00162       Password passwordcrc;
00163 
00164       class Dissection {
00165          public:
00166             VehicleType*  fzt;
00167             const Technology*   tech;
00168             int           orgpoints;
00169             int           points;
00170             int           num;
00171       };
00172 
00174       typedef list<Dissection> DissectionContainer;
00175       DissectionContainer dissections;
00176 
00177       bool __dissectionsToLoad;
00178 
00180       MessagePntrContainer  unreadmessage;
00181       bool __loadunreadmessage;
00182 
00184       MessagePntrContainer  oldmessage;
00185       bool __loadoldmessage;
00186 
00188       MessagePntrContainer  sentmessage;
00189       bool __loadsentmessage;
00190 
00192       int queuedEvents;
00193 
00195       int ASCversion;
00196 
00197       struct PlayTime {
00198          int turn;
00199          time_t date;
00200       };
00201       typedef list<PlayTime> PlayTimeContainer;
00202 
00204       PlayTimeContainer playTime;
00205 
00206       MapCoordinate cursorPos;
00207 
00208       DiplomaticStateVector diplomacy;
00209       
00210       ASCString email;
00211                   
00212       DI_Color getColor() const;
00213       PlayerColor getPlayerColor() const;
00214       void setColor( const DI_Color& color ); 
00215 
00216       void read ( tnstream& stream );
00217       void write ( tnstream& stream ) const;
00218 
00219       void resetView();
00220       void resetResearch();
00221       void resetTribute();
00222       void resetPassword();
00223 
00224       bool operator==( const Player& otherPlayer) const;
00225       
00226       void setPlayerID( int id ) { serverPlayerID = id; };
00227       int getPlayerID() const { return serverPlayerID; };
00228       
00229    private:   
00230       ASCString       name;
00231       DI_Color        color;
00232       void sendQueuedMessages();
00233 };
00234 
00235 
00236 
00237 #endif
00238 

Generated on Mon May 21 01:26:36 2012 for Advanced Strategic Command by  doxygen 1.5.1