00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00109 for (int i = 0; i < mOrds.size(); ++i)
00110 mOrds[i]->WriteNode(node);
00111
00112 node->LinkEndChild(new TiXmlElement("EndMultipleOrder"));
00113
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 }