00001
00002
00003
00004
00005
00006 #include "ai/ai.h"
00007 #include "loaders.h"
00008 #include "dlg_box.h"
00009 #include "dlg_box.h"
00010 #include "strtmesg.h"
00011 #include "sg.h"
00012 #include "viewcalculation.h"
00013 #include "replay.h"
00014 #include "messagedlg.h"
00015
00016 #include "researchexecution.h"
00017 #include "resourcenet.h"
00018 #include "mapimageexport.h"
00019 #include "soundList.h"
00020 #include "turncontrol.h"
00021
00022 #include "stdio-errorhandler.h"
00023
00024 #include "autotraining.h"
00025
00026 #include "actiontest.h"
00027 #include "movementtest.h"
00028 #include "attacktest.h"
00029 #include "ai-move1.h"
00030 #include "viewtest.h"
00031 #include "ai-service1.h"
00032 #include "transfercontroltest.h"
00033 #include "recyclingtest.h"
00034 #include "researchtest.h"
00035 #include "applicationstarter.h"
00036 #include "diplomacytest.h"
00037 #include "objectconstructiontest.h"
00038 #include "eventtest.h"
00039 #include "gameeventsystem.h"
00040 #include "jumptest.h"
00041 #include "testversionidentifier.h"
00042 #include "streamencoding.h"
00043 #include "tasks/taskcontainer.h"
00044 #include "maptest.h"
00045
00046
00047 void viewcomp( Player& player )
00048 {
00049 computeview( player.getParentMap() );
00050 }
00051
00052 void hookGuiToMap( GameMap* map )
00053 {
00054 if ( !map->getGuiHooked() ) {
00055
00056 map->sigPlayerUserInteractionBegins.connect( SigC::slot( &viewcomp ) );
00057 map->sigPlayerUserInteractionBegins.connect( SigC::hide<Player&>( repaintMap.slot() ));
00058
00059 map->sigPlayerUserInteractionBegins.connect( SigC::hide<Player&>( SigC::slot( &checkforreplay )));
00060 map->sigPlayerUserInteractionBegins.connect( SigC::slot( &viewunreadmessages ));
00061 map->sigPlayerUserInteractionBegins.connect( SigC::slot( &checkJournal ));
00062 map->sigPlayerUserInteractionBegins.connect( SigC::slot( &checkUsedASCVersions ));
00063 map->sigPlayerUserInteractionBegins.connect( SigC::hide<Player&>( updateFieldInfo.slot() ));
00064
00065 map->sigPlayerTurnHasEnded.connect( SigC::slot( viewOwnReplay));
00066 map->guiHooked();
00067 }
00068 }
00069
00070 bool loadGameFromFile( const ASCString& filename )
00071 {
00072 return false;
00073 }
00074
00075
00076 void runUnitTests()
00077 {
00078 testView();
00079
00080 testAttack();
00081 testObjectConstruction();
00082 testMovement();
00083 testStreamEncoding();
00084 testVersionIdentifier();
00085 testJumpdrive();
00086 testEvents();
00087 testActions();
00088 testResearch();
00089 testDiplomacy();
00090 testRecycling();
00091 testTransferControl();
00092 testAiService();
00093 testAiMovement();
00094 }
00095
00096
00097 void checkGameEvents( GameMap* map,const Command& command )
00098 {
00099 checktimedevents( map, NULL );
00100 checkevents( map, NULL );
00101 }
00102
00103
00104 int runTester ( )
00105 {
00106 loadpalette();
00107
00108 virtualscreenbuf.init();
00109
00110 try {
00111 loaddata();
00112 }
00113 catch ( ParsingError err ) {
00114 errorMessage ( "Error parsing text file " + err.getMessage() );
00115 return -1;
00116 }
00117 catch ( tfileerror err ) {
00118 errorMessage ( "Error loading file " + err.getFileName() );
00119 return -1;
00120 }
00121 catch ( ASCexception ) {
00122 errorMessage ( "loading of game failed" );
00123 return -1;
00124 }
00125 catch ( ThreadExitException ) {
00126 displayLogMessage(0, "caught thread exiting exception, shutting down");
00127 return -1;
00128 }
00129
00130 #ifndef _WIN32_
00131
00132 catch ( ... ) {
00133 fatalError ( "caught undefined exception" );
00134 return -1;
00135 }
00136 #endif
00137
00138 GameMap::sigPlayerTurnEndsStatic.connect( SigC::slot( automaticTrainig ));
00139
00140
00141 suppressMapTriggerExecution = false;
00142
00143 runUnitTests();
00144
00145 return 0;
00146 }
00147
00148
00149
00150 static void __runResearch( Player& player ){
00151 runResearch( player, NULL, NULL );
00152 }
00153
00154 void deployMapPlayingHooks ( GameMap* map )
00155 {
00156 map->sigPlayerTurnBegins.connect( SigC::slot( initReplayLogging ));
00157 map->sigPlayerTurnBegins.connect( SigC::slot( transfer_all_outstanding_tribute ));
00158 map->sigPlayerTurnBegins.connect( SigC::slot( __runResearch ));
00159 }
00160
00161
00162
00163
00164
00165 #include "clparser/asc.cpp"
00166
00167
00168 void executeUserAction ( tuseractions action ) {};
00169 void execUserAction_ev ( tuseractions action ) {};
00170
00171
00172 int main(int argc, char *argv[] )
00173 {
00174 assert ( sizeof(PointerSizedInt) == sizeof(int*));
00175
00176
00177 Cmdline* cl = NULL;
00178 try {
00179 cl = new Cmdline ( argc, argv );
00180 } catch ( string s ) {
00181 cerr << s;
00182 exit(1);
00183 }
00184 auto_ptr<Cmdline> apcl ( cl );
00185
00186 if ( cl->v() ) {
00187 ASCString msg = getstartupmessage();
00188 printf( "%s", msg.c_str() );
00189 exit(0);
00190 }
00191
00192 MessagingHub::Instance().setVerbosity( cl->r() );
00193 StdIoErrorHandler stdIoErrorHandler(false);
00194 MessagingHub::Instance().exitHandler.connect( SigC::bind( SigC::slot( exit_asc ), -1 ));
00195
00196 #ifdef WIN32
00197 Win32IoErrorHandler* win32ErrorDialogGenerator = new Win32IoErrorHandler;
00198 #endif
00199
00200 ConfigurationFileLocator::Instance().setExecutableLocation( argv[0] );
00201 initFileIO( cl->c() );
00202
00203 SoundSystem soundSystem ( true, true, true );
00204
00205 tspfldloaders::mapLoaded.connect( SigC::slot( deployMapPlayingHooks ));
00206 TaskContainer::registerHooks();
00207
00208 PG_FileArchive archive( argv[0] );
00209
00210 try {
00211 runTester();
00212 }
00213 catch ( bad_alloc ) {
00214 fatalError ("Out of memory");
00215 return 1;
00216 }
00217 catch ( ASCmsgException e ) {
00218 cerr << e.getMessage() << "\n";
00219 return 2;
00220 }
00221 catch ( ActionResult ar ) {
00222 cerr << "ActionResult failed:" << ar.getCode() << " : " << ar.getMessage() << "\n";
00223 return 2;
00224 }
00225 catch ( ... ) {
00226 cerr << "caught exception\n";
00227 return 2;
00228 }
00229
00230 cout << "unittests completed successfully \n";
00231 return 0;
00232 }