Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List

Player.h

Go to the documentation of this file.
00001 /*
00002 Copyright 2003 - 2005 Elliott Kleinrock, Dan Neely, Kurt W. Over, Damon Domjan
00003 
00004 This file is part of FreeStars, a free clone of the Stars! game.
00005 
00006 FreeStars is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 FreeStars is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with FreeStars; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 The full GPL Copyright notice should be in the file COPYING.txt
00021 
00022 Contact:
00023 Email Elliott at 9jm0tjj02@sneakemail.com
00024 */
00025 
00030 #if !defined(Player_h)
00031 #define Player_h
00032 
00033 #include <string>
00034 using namespace std;
00035 
00036 class Message;
00037 class Battle;
00038 class Bombing;
00039 class Order;
00040 class BattlePlanOrder;
00041 class RelationsOrder;
00042 class ProductionOrder;
00043 class MultipleOrder;
00044 #include "BattlePlan.h"
00045 #include "Ship.h"
00046 #include "ProdOrder.h"
00047 #include "Fleet.h"
00048 #include "Race.h"
00049 #include "MineField.h"
00050 
00054 class Player : public Race {
00055 public:
00056         Player(int id);
00057         virtual ~Player();
00058 
00059         void Remove()   { delete this; }
00060 //      static Player * Create(int id)  { return new Player(id); }
00061 
00062         bool ParseNode(const TiXmlNode * node, bool other);
00063         bool ParseCommon(const TiXmlNode * node);
00064         long CreateFromFile(const char * file);
00065         void SetupRelations();
00066         bool WriteNode(TiXmlNode * node, const Player * viewer) const;
00067         void ParseFleet(const TiXmlNode * node, bool other);
00068         void ParseOrders(const TiXmlNode * node);
00069         CargoHolder * ParseTransport(const TiXmlNode * node, const CargoHolder * owned);
00070         void TransferCargo(CargoHolder * from, CargoHolder * to, long pop, long fuel, deque<long> & cargo, bool write = true);
00071         void ParseMessages(const TiXmlNode * node);
00072 //      void UpdateSeen(const CargoHolder * from);
00073 //      void UpdateSeen();
00074         void ResetSeen();
00075         void SetSeenDesign(long p, long design, bool base);
00076         void SetSeenHull(long p, long design, bool base);
00077         void SetSeenHab(const Player * viewer)  { mSeenHab[viewer->GetID() - 1] = true; }
00078 
00079         Message * AddMessage(string type, const Location * loc);
00080         Message * AddMessage(string type);
00081         void WriteMessages(TiXmlNode * node, const char * type);
00082         void StoreMessageLocation(const Location * loc);
00083 
00084         // tech functions
00085         bool HasGotTech() const                                 { return mGotTech; }
00086         void SetGotTech(bool val)                               { mGotTech = val; }
00087         long GainTech(long TechGain, TechType tech);
00088         long GainTech(long TechGain)                    { return GainTech(TechGain, mResearchField); }
00089         bool GainTechLevel(TechType tech);
00090         void GainSpyTech(long TechGain, TechType tech);
00091         void CheckTechGain();
00092         long TechCost(TechType tech) const;
00093         long GetTechLevel(TechType tech) const  { return mTechLevel[tech]; }
00094         void AddProductionTech();
00095 
00096         void SetResearchTax(double tax);
00097         void SetResearchField(long current);
00098         void SetResearchNext(long next);
00099         double GetResearchTax() const                   { return mResearchTax; }
00100         long GetResearchField() const                   { return mResearchField; }
00101         long GetResearchNext() const                    { return mResearchNext; }
00102 
00103         long GetScanSpace() const                               { return mScanSpace; }
00104         long GetScanPen() const                                 { return mScanPen; }
00105         const deque<ProdOrder *> & GetDefaultQ() const  { return mDefaultQ; }
00106         bool GetDefaultPayTax() const                   { return mDefaultPayTax; }
00107         void SetDefaultPayTax(bool pt)                  { mDefaultPayTax = pt; }
00108         const Fleet * GetFleet(long n) const    { return const_cast<Player *>(this)->NCGetFleet(n); }
00109         Fleet * NCGetFleet(unsigned long n);
00110         Fleet * GetFleetCreate(unsigned long n, const CargoHolder &loc);
00111         const Ship * GetShipDesign(unsigned long n) const;
00112         const Ship * GetBaseDesign(unsigned long n) const;
00113         unsigned long GetBaseDesign(const Ship * design) const
00114                 { return find(mBaseDesigns.begin(), mBaseDesigns.end(), design) - mBaseDesigns.begin(); }
00115         long GetShipNumber(const Ship * design) const
00116                 { return find(mShipDesigns.begin(), mShipDesigns.end(), design) - mShipDesigns.begin(); }
00117         const Ship * GetExistingDesign(const Ship * check) const;
00118         const Ship * GetExistingBaseDesign(const Ship * check) const;
00119 
00120         void DeleteFleet(Fleet * gone);
00121         unsigned long GetID() const                                             { return mID; }
00122         void SetRelations(const deque<long> rel);
00123         long GetRelations(const Player * p2) const              { return p2 == this ? PR_SELF : mRelations[p2->GetID()-1]; }
00124         const BattlePlan * GetBattlePlan(unsigned long num) const;
00125         void ChangeBattlePlan(BattlePlan * bp, int num);
00126         double GetDefenseValue() const                  { return mDefenseValue * DefenseFactor(); }
00127         double Miniturize(const Component * comp) const;
00128         long TerraLimit(HabType ht) const               { return mTerraLimit[ht]; }
00129         void BuildShips(Planet * planet, long Type, long number);
00130         long ForEachFleet(Fleet::FuncType func, bool arg);
00131 
00132         void ResetTerraLimits();
00133         void SetTerraLimit(HabType ht, long limit);
00134 
00135         void DoBattles();
00136         void AddBattleFleets(Battle * bat);
00137         bool AddBombingFleets(Bombing * bom, const Player* owner,const long t) const; // returns true if it added any fleets
00138         void ClearBattleEnemies();
00139         void SetBattleEnemy(long p)                     { mBattleEnemy[p] = true; mInBattle = true; }
00140         bool GetBattleEnemy(long p) const       { return mBattleEnemy[p]; }
00141         bool InThisBattle() const                       { return mInBattle; }
00142         
00143         const deque<Message *>& GetMessages() const {return mMessages;}
00144         long GetMineFieldID() const;
00145 
00146         void AddStartShips(Planet * planet, bool HomeWorld);
00147         void AddStartShips(const RacialTrait * rt, int i, Planet * planet, bool HomeWorld);
00148 
00149         bool HasHW()            { return mHasHW; }
00150         void PlaceHW(Planet * planet);
00151         void PlaceSW(Planet * second, Planet * homeworld);
00152 
00153         void IncrementBaseBuilt(long base)      { mBaseDesigns[base]->IncrementBuilt(1); }
00154         void LoadFleets();
00155         void LoadMinefields();
00156 
00157         bool UnsavedChanges() const     { return mUnsavedChanges != 0; }
00158         bool OpenOrdersFile();
00159         bool OpenOrdersFile(const char * file);
00160         bool SaveXFile();
00161         bool WriteXFile() const         { return mWriteXFile; }
00162         void SetWriteXFile()            { mWriteXFile = true; }
00163         void AddOrder(Order * o);
00164         void TestUndoRedo();
00165         const Order * GetOrder(int i)           { return mOrders[i]; }
00166         bool UndoOrder(int pos = -1);
00167         bool RedoOrder();
00168         void StartMultipleOrder();
00169         void EndMultipleOrder();
00170 
00171         void ParseResearchTax(const TiXmlNode * node);
00172         long ParseResearchField(const TiXmlNode * node);
00173 
00174         void UndoBattlePlan(BattlePlanOrder * bpo);
00175         TiXmlNode * WriteBattlePlan(TiXmlNode * node, int num) const;
00176 
00177         void SetProduction(const deque<ProdOrder *> & ords);
00178         void SetPayTax(bool paytax);
00179         void ParseWaypoints(const TiXmlNode * node);
00180 
00181 private:
00182         double mResearchTax;
00183         long mResearchField;
00184         long mResearchNext;
00185         bool mGotTech;
00186         deque<long> mTechLevel;
00187         deque<long> mTempTechLevel;
00188         deque<long> mTechProgress;
00189         long mScanSpace;
00190         long mScanPen;
00191         double mDefenseValue;
00192         deque<ProdOrder *> mDefaultQ;
00193         bool mDefaultPayTax;
00194         deque<Fleet *> mFleets;
00195         deque<Ship *> mShipDesigns;
00196         deque<Ship *> mBaseDesigns;
00197         deque<long> mRelations;
00198         deque<BattlePlan *> mBattlePlans;
00199         unsigned long mID;
00200         deque<long> mTerraLimit;
00201         deque<MineField *> mMineFields;
00202         deque<Message *> mMessages;
00203         deque<bool> mSeenHab;
00204 
00205         bool mWriteXFile;
00206         long mUnsavedChanges;
00207         deque<Order *> mOrders;
00208         MultipleOrder * mMO;
00209 
00210         // Temporary stuff for battles
00211         deque<bool> mBattleEnemy;       // Will we fight this race in the current battle.
00212         bool mInBattle;                         // Are we in this battle at all?
00213 
00214         bool mHasHW;    // for setup only
00215 };
00216 
00217 #endif // !defined(Player_h)

Generated on Mon Aug 8 21:33:44 2005 for Freestars by  doxygen 1.4.2-20050421