Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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 
00060       Player& player; 
00061       
00062       typedef vector<DiplomaticStates> States;
00063       States states;
00064       
00065       typedef map<int,DiplomaticStates> QueuedStateChanges;
00066       QueuedStateChanges queuedStateChanges;
00067 
00068       void changeToState( int towardsPlayer, DiplomaticStates s, bool mail = true );
00069       
00070       void resize( int size );
00071 
00072    public:
00073       DiplomaticStateVector( Player& _player );
00074       
00075       DiplomaticStates getState( int towardsPlayer ) const;
00076       void setState( int towardsPlayer, DiplomaticStates s, bool fireSignal = true );
00077       void propose ( int towardsPlayer, DiplomaticStates s );
00078       void sneakAttack( int towardsPlayer );
00079       
00080       bool isHostile( PlayerID towardsPlayer ) { return getState( towardsPlayer.getID() ) == WAR; };
00081       bool sharesView( PlayerID receivingPlayer ) { return getState( receivingPlayer.getID() ) >= PEACE_SV; };
00082       bool isAllied( PlayerID towardsPlayer ) { return getState( towardsPlayer.getID() ) >= ALLIANCE; };
00083 
00084       void turnBegins();
00085       
00086       void swap( int secondPlayer );
00087             
00088       static SigC::Signal4<void,GameMap*,int,int,DiplomaticStates> anyStateChanged;
00089       static SigC::Signal3<void,GameMap*,int,int> shareViewChanged;
00090 
00092       bool getProposal( int fromPlayer, DiplomaticStates* state );
00093       
00094       void read ( tnstream& stream );
00095       void write ( tnstream& stream ) const;
00096 };
00097 
00098 class GameMap;
00099 
00100 
00102 class Player : public SigC::Object {
00103       int player;
00104       GameMap* parentMap;
00105       
00106       void turnBegins( Player& p );
00107       void userInteractionBegins( Player& p );
00108       void turnEnds( Player& p );
00109       
00110       
00111    public:
00112       Player();
00113 
00114       int getPosition() const { return player; };
00115       
00116       const GameMap* getParentMap() const { return parentMap; };
00117       GameMap* getParentMap() { return parentMap; };
00118       
00119       void setParentMap( GameMap* map, int pos );
00120       
00121 
00123       void swap ( Player& secondPlayer );
00124 
00126       void merge( Player& secondPlayer );
00127 
00128 
00130       bool         exist() const;
00131 
00133       bool existanceAtBeginOfTurn;
00134 
00135       typedef list<Vehicle*> VehicleList;
00137       VehicleList  vehicleList;
00138 
00139       typedef list<Building*> BuildingList;
00141       BuildingList  buildingList;
00142 
00144       Research    research;
00145 
00147       BaseAI*      ai;
00148 
00150       enum PlayerStatus { human, computer, off, supervisor, suspended } stat;
00151       
00152       bool isHuman() const { return stat == human || stat == supervisor || stat == suspended; };
00153 
00154       static int getHumanPlayerNum( const GameMap* gamemap );
00155 
00156       static const char* playerStatusNames[];
00157 
00159       ASCString getName( ) const;
00160       
00161       void setName( const ASCString& name ) { this->name = name; };
00162 
00164       Password passwordcrc;
00165 
00166       class Dissection {
00167          public:
00168             Vehicletype*  fzt;
00169             const Technology*   tech;
00170             int           orgpoints;
00171             int           points;
00172             int           num;
00173       };
00174 
00176       typedef list<Dissection> DissectionContainer;
00177       DissectionContainer dissections;
00178 
00179       bool __dissectionsToLoad;
00180 
00182       MessagePntrContainer  unreadmessage;
00183       bool __loadunreadmessage;
00184 
00186       MessagePntrContainer  oldmessage;
00187       bool __loadoldmessage;
00188 
00190       MessagePntrContainer  sentmessage;
00191       bool __loadsentmessage;
00192 
00194       int queuedEvents;
00195 
00197       int ASCversion;
00198 
00199       struct PlayTime {
00200          int turn;
00201          time_t date;
00202       };
00203       typedef list<PlayTime> PlayTimeContainer;
00204 
00206       PlayTimeContainer playTime;
00207 
00208       MapCoordinate cursorPos;
00209 
00210       DiplomaticStateVector diplomacy;
00211       
00212       ASCString email;
00213                   
00214       DI_Color getColor() const;
00215       PlayerColor getPlayerColor() const;
00216       void setColor( const DI_Color& color ); 
00217 
00218       void read ( tnstream& stream );
00219       void write ( tnstream& stream ) const;
00220 
00221       void resetView();
00222       void resetResearch();
00223       void resetTribute();
00224       void resetPassword();
00225 
00226    private:   
00227       ASCString       name;
00228       DI_Color        color;
00229       void sendQueuedMessages();
00230                  
00231 };
00232 
00233 
00234 
00235 #endif
00236 

Generated on Tue Jun 24 01:27:50 2008 for Advanced Strategic Command by  doxygen 1.4.2