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 "WayOrderList.h"
00029 #include "TempFleet.h"
00030
00031 #ifdef _DEBUG
00032 #define new DEBUG_NEW
00033 #endif
00034
00035 WayOrderList::~WayOrderList()
00036 {
00037 if (!mNoDelete) {
00038 int i;
00039 for (i = 0; i < orders.size(); ++i)
00040 delete orders[i];
00041 }
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 bool WayOrderList::ParseNode(const TiXmlNode * node, Player * player)
00083 {
00084 const TiXmlNode * child1;
00085 const TiXmlNode * child2;
00086
00087 WayOrder * wo;
00088 Location * loc;
00089 bool fmo;
00090 Player * player2;
00091 long speed;
00092
00093 nPlayer = player->GetID();
00094
00095 if (nFleet <= 0 || nFleet > Rules::MaxFleets) {
00096 Message * mess = player->AddMessage("Error: invalid fleet number");
00097 mess->AddLong("Waypoint order", nFleet);
00098 nFleet = 0;
00099 return true;
00100 }
00101
00102 for (child1 = node->FirstChild("Waypoint"); child1; child1 = child1->NextSibling("Waypoint")) {
00103 wo = NULL;
00104 loc = NULL;
00105 fmo = false;
00106 speed = 0;
00107 unsigned long pnum = GetLong(child1->FirstChild("Player"));
00108 if (pnum < 0 || pnum > TheGame->NumberPlayers()) {
00109 Message * mess = player->AddMessage("Error: invalid player number");
00110 mess->AddLong("", pnum);
00111 mess->AddItem("Where", "Fleet destination");
00112 continue;
00113 }
00114 player2 = TheGame->NCGetPlayer(pnum);
00115
00116 for (child2 = child1->FirstChild(); child2; child2 = child2->NextSibling()) {
00117 if (child2->Type() == TiXmlNode::COMMENT)
00118 continue;
00119
00120 if (stricmp(child2->Value(), "Location") == 0) {
00121 if (loc != NULL)
00122 continue;
00123
00124 Location * nl = new Location();
00125 if (!nl->ParseNode(child2)) {
00126 delete nl;
00127 continue;
00128 }
00129 loc = nl;
00130 fmo = true;
00131 } else if (stricmp(child2->Value(), "Planet") == 0) {
00132 if (loc != NULL)
00133 continue;
00134
00135 Planet * planet = TheGalaxy->GetPlanet(GetString(child2));
00136 if (!planet) {
00137 Message * mess = player->AddMessage("Error: invalid planet");
00138 mess->AddItem("", GetString(child2));
00139 mess->AddItem("Where", "Waypoint order");
00140 continue;
00141 }
00142 loc = planet;
00143 } else if (stricmp(child2->Value(), "Minefield") == 0) {
00144 if (loc != NULL)
00145 continue;
00146
00147
00148 } else if (stricmp(child2->Value(), "Scrap") == 0) {
00149 if (loc != NULL)
00150 continue;
00151
00152 long l = GetLong(child2);
00153 Salvage * salvage = TheGalaxy->GetSalvage(l);
00154 if (!salvage || !salvage->SeenBy(player)) {
00155 Message * mess = player->AddMessage("Error: invalid salvage pile");
00156 mess->AddLong("Waypoint order", l);
00157 continue;
00158 }
00159 loc = salvage;
00160 } else if (stricmp(child2->Value(), "Packet") == 0) {
00161 if (loc != NULL)
00162 continue;
00163
00164
00165 } else if (stricmp(child2->Value(), "Trader") == 0) {
00166 if (loc != NULL)
00167 continue;
00168
00169
00170 } else if (stricmp(child2->Value(), "Fleet") == 0) {
00171 if (loc != NULL)
00172 continue;
00173
00174 if (player2 == player) {
00175 loc = new TempFleet(GetLong(child2), player);
00176 fmo = true;
00177 } else {
00178 Fleet * f2 = player2->NCGetFleet(GetLong(child2));
00179 if (!f2 || !f2->SeenBy(player)) {
00180 Message * mess = player->AddMessage("Error: invalid fleet number");
00181 mess->AddLong("Waypoint order", GetLong(child2));
00182 continue;
00183 }
00184
00185 loc = f2;
00186 f2->AddChaser(nPlayer, nFleet);
00187 chasing.insert(chasing.end(), f2);
00188 }
00189 } else if (stricmp(child2->Value(), "Speed") == 0) {
00190 speed = GetLong(child2);
00191 if (speed < -1 || speed > Rules::GetConstant("MaxSpeed")) {
00192 Message * mess = player->AddMessage("Error: invalid speed");
00193 mess->AddLong("Waypoint order", speed);
00194 continue;
00195 }
00196 } else if (stricmp(child2->Value(), "Order") == 0) {
00197 if (loc == NULL)
00198 continue;
00199
00200 const TiXmlNode * child3;
00201 child3 = child2->FirstChild();
00202 while (child3->Type() == TiXmlNode::COMMENT)
00203 child3 = child3->NextSibling();
00204
00205 if (strnicmp(child3->Value(), "No Task", 7) == 0) {
00206 wo = new WayOrder(loc, fmo);
00207 wo->mOrder = OT_NONE;
00208 } else if (strnicmp(child3->Value(), "Colonize", 8) == 0) {
00209 wo = new WayOrder(loc, fmo);
00210 wo->mOrder = OT_COLONIZE;
00211 } else if (strnicmp(child3->Value(), "Remote Mine", 11) == 0) {
00212 wo = new WayOrder(loc, fmo);
00213 wo->mOrder = OT_REMOTEMINE;
00214 } else if (strnicmp(child3->Value(), "Scrap", 5) == 0) {
00215 wo = new WayOrder(loc, fmo);
00216 wo->mOrder = OT_SCRAP;
00217 } else if (strnicmp(child3->Value(), "Route", 5) == 0) {
00218 wo = new WayOrder(loc, fmo);
00219 wo->mOrder = OT_ROUTE;
00220 } else if (strnicmp(child3->Value(), "Merge", 5) == 0) {
00221 unsigned long num = (unsigned long)GetLong(child3);
00222 if (num > Rules::MaxFleets) {
00223 Message * mess = player->AddMessage("Error: invalid fleet number");
00224 mess->AddLong("Waypoint order", num);
00225 continue;
00226 }
00227
00228 wo = new WayOrderNumber(num, loc, fmo);
00229 wo->mOrder = OT_MERGE;
00230 } else if (strnicmp(child3->Value(), "LayMine", 7) == 0) {
00231 long num = GetLong(child3);
00232 if (num < -1 || num == 0) {
00233 Message * mess = player->AddMessage("Error: invalid number of years");
00234 mess->AddLong("Waypoint order", num);
00235 continue;
00236 }
00237
00238 wo = new WayOrderNumber(num, loc, fmo);
00239 wo->mOrder = OT_LAYMINE;
00240 } else if (strnicmp(child3->Value(), "Transfer", 8) == 0) {
00241 unsigned long num = GetLong(child3);
00242 if (num < 0 || num > TheGame->NumberPlayers()) {
00243 Message * mess = player->AddMessage("Error: invalid player number");
00244 mess->AddLong("", num);
00245 mess->AddItem("Where", "Waypoint order");
00246 continue;
00247 }
00248
00249 wo = new WayOrderNumber(num, loc, fmo);
00250 wo->mOrder = OT_TRANSFER;
00251 } else if (strnicmp(child3->Value(), "Patrol", 6) == 0) {
00252 long s = GetLong(child3->FirstChild("Speed"));
00253 if (s < 0 || s > Rules::GetConstant("MaxSpeed")) {
00254 Message * mess = player->AddMessage("Error: invalid speed");
00255 mess->AddLong("Waypoint order", s);
00256 continue;
00257 }
00258
00259 long r = GetLong(child3->FirstChild("Range"));
00260 if (r <= 0) {
00261 Message * mess = player->AddMessage("Error: invalid range");
00262 mess->AddLong("Waypoint order", r);
00263 continue;
00264 }
00265
00266 wo = new WayOrderPatrol(s, r, loc, fmo);
00267 wo->mOrder = OT_PATROL;
00268 } else if (strnicmp(child3->Value(), "Transport", 9) == 0) {
00269 WayOrderTransport * wot;
00270 wot = new WayOrderTransport(loc, fmo);
00271 if (!wot->ParseNode(child3, player))
00272 continue;
00273
00274 wo = wot;
00275 wo->mOrder = OT_TRANSPORT;
00276 }
00277 } else {
00278 Message * mess = player->AddMessage("Warning: Unknown type");
00279 mess->AddItem("Waypoint order", child2->Value());
00280 continue;
00281 }
00282 }
00283
00284 if (wo != NULL) {
00285 wo->mSpeed = speed;
00286 orders.push_back(wo);
00287 } else if (fmo && loc) {
00288 delete loc;
00289 }
00290 }
00291
00292 return true;
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315