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

Stack.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(Stack_h)
00031 #define Stack_h
00032 
00033 #include <deque>
00034 using namespace std;
00035 
00036 class Ship;
00037 
00042 class Stack {
00043 public:
00044         Stack() : mShip(NULL), mShips(0), mDamage(0), mDamaged(0), mFleetIn(NULL), bIsBase(false), bRandInit(0) {}
00045         ~Stack();
00046         bool ParseNode(const TiXmlNode * node, Player * owner);
00047         void WriteNode(TiXmlNode * node, const Player * owner, const Player * viewer) const;
00048         void WriteNode(TiXmlNode * node) const;         // for battle reports
00049 
00050         const Ship * GetDesign() const          { return mShip; }
00051         long GetCount() const                   { return mShips; }
00052         long GetDamaged() const                 { return mDamaged; }
00053         int GetDamage() const                   { return mDamage; }
00054 
00055         void SetDesign(const Ship * s)          { mShip = s; }
00056         void SetCount(long count)               { mShips = count; }
00057         void SetDamaged(long d)                 { mDamaged = d; }
00058         void SetDamage(int d)                   { mDamage = d; }
00059 
00060         long DamageAllShips(long damage);
00061         bool KillShips(long count, bool salvage);
00062 //      long ApplyDamage(long damage, int type);        // returns number of ships destroyed
00063         void AddFromFleet(long fleet, long ships, long damaged);
00064         const Fleet * GetFleetIn() const        { return mFleetIn; }
00065         Fleet * GetFleetIn()                            { return mFleetIn; }
00066         void SetFleetIn(Fleet * fin)            { mFleetIn = fin; }
00067         bool operator ==(const Stack& s) const {return mShip == s.GetDesign() && mFleetIn == s.GetFleetIn();}
00068 
00069 private:
00070         const Ship * mShip;     // Design
00071         long mShips;    // number of ships in the stack
00072         long mDamage;   // Amount of damage per ship
00073         long mDamaged;  // Number of damaged ships
00074         Fleet * mFleetIn;       // Fleet this stack is in
00075 
00076         class Origin {
00077         public:
00078                 long fleet;             // fleet of origin
00079                 long ships;             // number of ships transfered to this fleet
00080                 long damaged;   // number of those that are damaged
00081         };
00082 
00083         deque<Origin> mOrigins;
00084 
00085         friend class Fleet;
00086         friend class Battle;
00087         friend class Bombing;
00088 
00089         // While in the battle board
00090         long bArmor;            // total armor remaining of the stack
00091         long bShield;   // total shield of the stack
00092         int bSpeed;             // Speed (taking into account ship design and other factors -- WM, ED, etc)
00093         long bx, by;
00094         long bMass;             // Mass (adjusted by +-15% for battles)
00095         long bShips;    // Current ship count in battle
00096         bool bIsBase;   // bases in combat use become a stack too
00097         long bRandInit; // used to resolve init ties
00098         long bPlan;             // battle plan, may change
00099         long bFlee;             // moves spent toward fleeing
00100         const Stack * bMAT;     // Most Attractive Target
00101 
00102         bool IsBase() const     { return bIsBase; }
00103         void SetupShips(const Player * owner, long cargo);
00104         void SetupBase(const Planet * planet);
00105         long DP() const         { return bArmor + bShield; }
00106 
00107         friend inline bool StackLighter(Stack * s1, Stack * s2)
00108         {
00109                 if (s1->bMass < s2->bMass)
00110                         return true;
00111                 else if (s1->bMass == s2->bMass)
00112                         return Random(2) == 0 ? true : false;
00113                 else
00114                         return false;
00115         }
00116 };
00117 
00118 #endif // !defined(Stack_h)

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