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

Main.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 "Battle.h"
00029 
00030 #include <stdlib.h>
00031 
00032 #ifdef _DEBUG
00033 #define new DEBUG_NEW
00034 class CheckMemLeaks {
00035 public:
00036         CheckMemLeaks() {}
00037         ~CheckMemLeaks() { _CrtDumpMemoryLeaks(); }
00038 };
00039 
00040 CheckMemLeaks cml;
00041 #endif
00042 
00043 int main (int argc, char * argv[])
00044 {
00045         if (argc != 2)
00046         {
00047                 cerr << "usage : fs_server [file]" << endl;
00048                 return -1;
00049         }
00050 
00051         bool error = false;
00052 
00053         {
00054         string HostFile = argv[1];
00055         string FileType = HostFile.substr(HostFile.find_last_of('.'));
00056 
00057         TheGame = new Game();
00058         TheGalaxy = new Galaxy();
00059 
00060         if (stricmp(FileType.c_str(), ".def") == 0) {
00061                 cout << "Loading Defination File" << endl;
00062                 if (!TheGame->LoadDefFile(argv[1]))
00063                         error = true;
00064 
00065                 TheGame->InitialSeen();
00066 
00067                 cout << "Writing XY File" << endl;
00068                 if (!error)
00069                         TheGame->WriteXYFile();
00070         } else if (stricmp(FileType.c_str(), ".hst") == 0) {
00071                 cout << "Loading Host File" << endl;
00072                 if (!TheGame->LoadHostFile(argv[1]))
00073                         error = true;
00074 
00075                 cout << "Loading Turns" << endl;
00076                 if (!error && !TheGame->LoadTurns())
00077                         error = true;
00078                 
00079                 cout << "Processing Turns" << endl;
00080                 if (!error && !TheGame->ProcessTurn())
00081                         error = true;
00082         } else if (FileType[1] == 'm') {
00083                 cout << "Loading player file and orders (.x file)" << endl;
00084                 if (!TheGame->LoadPlayerFile(argv[1]))
00085                         error = true;
00086 
00087                 cout << "Writing player orders (.x file)" << endl;
00088                 if (!error && !TheGame->GetCurrentPlayer()->SaveXFile())
00089                         error = true;
00090 
00091                 if (!error)
00092                         TheGame->GetCurrentPlayer()->TestUndoRedo();
00093 
00094                 error = true;   // always set to true to prevent host file being written when .m file is read
00095         } else {
00096                 cout << "Unknown file type " << FileType << endl;
00097                 error = true;
00098         }
00099 
00100         cout << "Writing Host File" << endl;
00101         if (!error && !TheGame->WriteHostFile())
00102                 error = true;
00103 
00104         cout << "Writing Players Files" << endl;
00105         if (!error && !TheGame->WritePlayerFiles())
00106                 error = true;
00107         
00108         // For debugging
00109         for (unsigned int i = 0; i < TheGame->GetMessages().size(); ++i)
00110         {
00111                 string message = TheGame->GetMessages()[i]->ToString();
00112                 /*if(message.find("Error") != -1 || message.find("Warn") != -1)*/
00113                         cout << message << endl;
00114         }
00115 
00116         for (unsigned int j = 1; j <= TheGame->NumberPlayers(); ++j)
00117         {
00118                 const Player* p = TheGame->GetPlayer(j);
00119                 if (p != NULL) {
00120                         for (unsigned int i = 0; i < p->GetMessages().size(); ++i)
00121                         {
00122                                 string message = p->GetMessages()[i]->ToString();
00123                                 /*if(message.find("Error") != -1 || message.find("Warn") != -1)*/
00124                                 {
00125                                         cout << "Player(" << Long2String(j) << ")" << endl;
00126                                         cout << message << endl;
00127                                 }
00128                         }
00129                 }
00130         }
00131 
00132         Rules::Cleanup();
00133         Component::Cleanup();
00134         Battle::Cleanup();
00135         Ship::Cleanup();
00136         delete TheGalaxy;
00137         delete TheGame;
00138         }
00139 
00140         if(error)
00141                 return -1;
00142 
00143         return 0;
00144 }

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