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

WayOrderList.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 "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         <Waypoints>
00046                 <Fleet>123</Fleet>
00047                 <Repeat>true</Repeat>
00048                 <Waypoint>
00049                         <Fleet>123</Fleet>
00050                         <Mine>123</Mine>
00051                         <Packet>123</Packet>
00052                         <Player>5</Player>
00053                         <Scrap>123</Scrap>
00054                         <Space>123 123</Space>
00055             <Trader>1</Trader>
00056                         <Planet>Cosine</Planet>
00057                         <Speed>0</Speed><!-- -1 for gating -->
00058                         <Order>
00059                                 Colonize
00060                                 Remote Mine
00061                                 Scrap
00062                                 Route
00063                                 <Transport>
00064                                         <Cargo>
00065                                                 <Type>1</Type> <!-- 0-4 for Fuel, Ironium, Boranium, Germanium, Population in that order (if we're going by Stars! UI) -->
00066                                                 <Action>Load All</Action> <!-- Load All, Unload All, Load Exactly, Unload Exactly, Fill To Percent, Wait For Percent, Load Optimal/Load Dunnage, Set Amount To, Set Waypoint To, Set To Percent, Drop And Load -->
00067                                                 <Value>1000</Value>
00068                                         </Cargo>
00069                                 </Transport>
00070                                 <Merge>123</Merge>
00071                                 <LayMine>5</LayMine> <!-- Lay mines for this many years.  -1 for indefinately. -->
00072                                 <Patrol>
00073                                         <Range>50</Range>
00074                                         <Speed>0</Speed>
00075                                 </Patrol>
00076                                 <Transfer>5</Transfer> <!-- Transfers to this player -->
00077                         </Order>
00078                 </Waypoint>
00079         </Waypoints>
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         // don't verify the fleet, it might not yet exist
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                                 // add after mines are added
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                                 // add after packets are added
00165                         } else if (stricmp(child2->Value(), "Trader") == 0) {
00166                                 if (loc != NULL)
00167                                         continue;
00168 
00169                                 // add after Mystery Traders are added
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                         <Order>
00296                                 Colonize
00297                                 Remote Mine
00298                                 Scrap
00299                                 Route
00300                                 <Merge>123</Merge>
00301                                 <LayMine>5</LayMine> <!-- Lay mines for this many years.  -1 for indefinately. -->
00302                                 <Transfer>5</Transfer> <!-- Transfers to this player -->
00303                                 <Patrol>
00304                                         <Range>50</Range>
00305                                         <Speed>0</Speed>
00306                                 </Patrol>
00307                                 <Transport>
00308                                         <Cargo>
00309                                                 <Type>1</Type> <!-- 0-4 for Fuel, Ironium, Boranium, Germanium, Population in that order (if we're going by Stars! UI) -->
00310                                                 <Action>Load All</Action> <!-- Load All, Unload All, Load Exactly, Unload Exactly, Fill To Percent, Wait For Percent, Load Optimal/Load Dunnage, Set Amount To, Set Waypoint To, Set To Percent, Drop And Load -->
00311                                                 <Value>1000</Value>
00312                                         </Cargo>
00313                                 </Transport>
00314                         </Order>
00315 */

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