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

Order.cpp

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 
00026 #include "FSServer.h"
00027 
00028 #include "TempFleet.h"
00029 #include "Order.h"
00030 
00031 
00032 Order::~Order()
00033 {
00034 }
00035 
00036 bool Order::Undo()
00037 {
00038         if (mUndone)
00039                 return false;
00040 
00041         mUndone = true;
00042         return DoUndo();
00043 }
00044 
00045 bool Order::Redo()
00046 {
00047         if (!mUndone)
00048                 return false;
00049 
00050         mUndone = false;
00051         return DoUndo();
00052 }
00053 
00054 TiXmlNode * WaypointOrder::WriteNode(TiXmlNode * node) const
00055 {
00056         TiXmlNode * wo = TypedListOrder<WayOrder>::WriteNode(node);
00057         if (wo != NULL)
00058                 AddLong(wo, "Fleet", mFleet);
00059 
00060         return wo;
00061 }
00062 
00063 BattlePlanOrder::~BattlePlanOrder()
00064 {
00065         delete mBP;
00066 }
00067 
00068 bool BattlePlanOrder::DoUndo()
00069 {
00070         mPlayer->UndoBattlePlan(this);
00071         return true;
00072 }
00073 
00074 TiXmlNode * BattlePlanOrder::WriteNode(TiXmlNode * node) const
00075 {
00076         if (!mUndone)
00077                 return mPlayer->WriteBattlePlan(node, mNum);
00078         else
00079                 return NULL;
00080 }
00081 
00082 TiXmlNode * RelationsOrder::WriteNode(TiXmlNode * node) const
00083 {
00084         if (!mUndone)
00085                 return node->LinkEndChild(Rules::WriteArray("Relations", "Race", "IDNumber", *m_pValue));
00086         else
00087                 return NULL;
00088 }
00089 
00090 TiXmlNode * ProductionOrder::WriteNode(TiXmlNode * node) const
00091 {
00092         TiXmlNode * wo = TypedListOrder<ProdOrder>::WriteNode(node);
00093         if (wo != NULL)
00094                 AddString(wo, "Planet", mQName);
00095 
00096         return wo;
00097 }
00098 
00099 MultipleOrder::~MultipleOrder()
00100 {
00101         for (int i = 0; i < mOrds.size(); ++i)
00102                 delete mOrds[i];
00103 }
00104 
00105 TiXmlNode * MultipleOrder::WriteNode(TiXmlNode * node) const
00106 {
00107         node->LinkEndChild(new TiXmlElement("StartMultipleOrder"));
00108 //      AddString(node, "StartMultipleOrder", "");
00109         for (int i = 0; i < mOrds.size(); ++i)
00110                 mOrds[i]->WriteNode(node);
00111 
00112         node->LinkEndChild(new TiXmlElement("EndMultipleOrder"));
00113 //      AddString(node, "EndMultipleOrder", "");
00114         return node;
00115 }
00116 
00117 bool MultipleOrder::DoUndo()
00118 {
00119         bool Result = true;
00120         for (int i = 0; Result && i < mOrds.size(); ++i)
00121                 Result = mOrds[i]->DoUndo();
00122 
00123         return Result;
00124 }
00125 
00126 void MultipleOrder::AddOrder(Order * o)
00127 {
00128         mOrds.push_back(o);
00129 }
00130 
00131 bool TransportOrder::DoUndo()
00132 {
00133         mPop = -mPop;
00134         mFuel = -mFuel;
00135         for (int i = 0; i < Rules::MaxMinType; ++i)
00136                 mCargo[i] = -mCargo[i];
00137 
00138         mPlayer->TransferCargo(mOwned, mOther, mPop, mFuel, mCargo, false);
00139 
00140         return true;
00141 }
00142 
00143 TiXmlNode * TransportOrder::WriteNode(TiXmlNode * node) const
00144 {
00145         TiXmlElement * trans = new TiXmlElement("Transfer");
00146         TiXmlElement * owned = new TiXmlElement("Owned");
00147         mOwned->WriteTransport(owned);
00148         trans->LinkEndChild(owned);
00149 
00150         CargoHolder * ch;
00151         TempFleet * tf = dynamic_cast<TempFleet *>(mOther);
00152         if (tf == NULL)
00153                 ch = mOther;
00154         else
00155                 ch = tf->GetRealCH();
00156 
00157         TiXmlElement * other = new TiXmlElement("Other");
00158         if (ch == NULL)
00159                 other->LinkEndChild(new TiXmlElement("Space"));
00160         else
00161                 ch->WriteTransport(other);
00162         trans->LinkEndChild(other);
00163 
00164         TiXmlElement * cargo = Rules::WriteCargo(trans, "Cargo", mCargo, mPop);
00165         if (mFuel != 0)
00166                 AddLong(cargo, "Fuel", mFuel);
00167 
00168         node->LinkEndChild(trans);
00169 
00170         return trans;
00171 }

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