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

ProdOrder.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(ProdOrder_h)
00031 #define ProdOrder_h
00032 
00033 #include "FSTypes.h"
00034 #include "Rules.h"
00035 #include "Cost.h"
00036 
00037 class Player;
00038 class Planet;
00039 class TiXmlNode;
00040 //#include "Component.h"
00041 
00042 const long POP_FACTS            = 1001;
00043 const long POP_MINES            = 1002;
00044 const long POP_DEFS                     = 1003;
00045 const long POP_ALCHEMY          = 1004;
00046 const long POP_SCANNER          = 1005;
00047 const long POP_MINTERRA         = 1006;
00048 const long POP_MAXTERRA         = 1007;
00049 const long POP_TERRAFORM        = 1008;
00050 const long POP_MIXEDPACKET      = 2000; // Leave space after packets blank for mineral type
00051 
00052 class ProdOrder {
00053 public:
00054         virtual ~ProdOrder();
00055         static deque<ProdOrder *> ParseNode(const TiXmlNode * node, Planet * planet, Player * player = NULL, bool TrustPartials = false);
00056         static TiXmlNode * WriteNode(TiXmlNode * node, const deque<ProdOrder *> & ords);
00057         virtual TiXmlNode * WriteNode(TiXmlNode * node) const = 0;
00058 
00059         virtual bool Produce(Planet * planet, long * resources, bool * AutoAlchemy) = 0;
00060         virtual void Built(Planet * planet, long number) = 0;
00061         ProdOrder * ProdOrder::Copy() const;
00062         Cost& GetPartial() {return Partial;}
00063         virtual string TypeToString() const = 0;
00064         long GetType() const    { return Type; }
00065 
00066 protected:
00067         ProdOrder();
00068         ProdOrder(long type, long amount);
00069         ProdOrder(const ProdOrder & orig);
00070         Cost Partial;
00071         long Type;
00072         long Amount;
00073         bool DoProduce(const Cost & cost, Planet * planet, long * resources, bool * AutoAlchemy, long maxbuild = -1);
00074 
00075 private:
00076         void CheckPartials(Planet * planet, const TiXmlNode * node, bool TrustPartials);
00077         void BuildPartial(const Cost & cost, Planet * planet, long * resources, double Build);
00078         void init();
00079 };
00080 
00081 class POBase : public ProdOrder {
00082 public:
00083         POBase(long ship) : ProdOrder(ship, 1) {}
00084         POBase(const POBase & orig) : ProdOrder(orig.Type, orig.Amount) {}
00085         ~POBase();
00086         virtual TiXmlNode * WriteNode(TiXmlNode * node) const;
00087 
00088         virtual bool Produce(Planet * planet, long * resources, bool * AutoAlchemy);
00089         virtual void Built(Planet * planet, long number);
00090         virtual string TypeToString() const;
00091 };
00092 
00093 class POPlanetary : public ProdOrder {
00094 public:
00095         POPlanetary(const POPlanetary & orig) : ProdOrder(orig.Type, orig.Amount) {}
00096         POPlanetary(long type, long num) : ProdOrder(type, num) {}
00097         ~POPlanetary();
00098         virtual TiXmlNode * WriteNode(TiXmlNode * node) const;
00099 
00100         virtual bool Produce(Planet * planet, long * resources, bool * AutoAlchemy);
00101         virtual void Built(Planet * planet, long number);
00102         virtual string TypeToString() const;
00103 };
00104 
00105 class POAuto : public POPlanetary {
00106 public:
00107         POAuto(long type, long num) : POPlanetary(type, num) {}
00108         POAuto(const POAuto & orig) : POPlanetary(orig.Type, orig.Amount) {}
00109         ~POAuto();
00110         virtual TiXmlNode * WriteNode(TiXmlNode * node) const;
00111 
00112         virtual bool Produce(Planet * planet, long * resources, bool * AutoAlchemy);
00113         virtual string TypeToString() const;
00114 };
00115 
00116 class POPacket : public POPlanetary {
00117 public:
00118         POPacket(long type, long num) : POPlanetary(type + POP_MIXEDPACKET + 1, num) {}
00119         POPacket(const POPacket & orig) : POPlanetary(orig.Type, orig.Amount) {}
00120         ~POPacket();
00121         virtual TiXmlNode * WriteNode(TiXmlNode * node) const;
00122         static bool CheckPacket(Planet * planet);
00123 
00124         virtual bool Produce(Planet * planet, long * resources, bool * AutoAlchemy);
00125         virtual string TypeToString() const;
00126 };
00127 
00128 class POShip : public ProdOrder {
00129 public:
00130         POShip(long ship, long num) : ProdOrder(ship, num) {}
00131         POShip(const POShip & orig) : ProdOrder(orig.Type, orig.Amount) {}
00132         ~POShip();
00133         virtual TiXmlNode * WriteNode(TiXmlNode * node) const;
00134 
00135         virtual bool Produce(Planet * planet, long * resources, bool * AutoAlchemy);
00136         virtual void Built(Planet * planet, long number);
00137         virtual string TypeToString() const;
00138 };
00139 
00140 class POTerraform : public ProdOrder {
00141 public:
00142         POTerraform(long type, long num) : ProdOrder(type, num), mResCost(0) { assert(type == POP_MINTERRA || type == POP_MAXTERRA || type == POP_TERRAFORM); }
00143         POTerraform(const POTerraform & orig) : ProdOrder(orig.Type, orig.Amount), mResCost(orig.mResCost) {}
00144         virtual ~POTerraform();
00145         virtual TiXmlNode * WriteNode(TiXmlNode * node) const;
00146 
00147         virtual bool Produce(Planet * planet, long * resources, bool * AutoAlchemy);
00148         virtual void Built(Planet * planet, long number);
00149         virtual string TypeToString() const;
00150 
00151 private:
00152         long mResCost;
00153 };
00154 
00155 #endif // !defined(ProdOrder_h)

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