Advanced Strategic Command
main.cpp
Go to the documentation of this file.
1 // The main program for running the unit tests
2 
3 
4 
5 
6 #include "ai/ai.h"
7 #include "loaders.h"
8 #include "dlg_box.h"
9 #include "dlg_box.h"
10 #include "strtmesg.h"
11 #include "sg.h"
12 #include "viewcalculation.h"
13 #include "replay.h"
14 #include "messagedlg.h"
15 
16 #include "researchexecution.h"
17 #include "resourcenet.h"
18 #include "mapimageexport.h"
19 #include "soundList.h"
20 #include "turncontrol.h"
21 
22 #include "stdio-errorhandler.h"
23 
24 #include "autotraining.h"
25 
26 #include "actiontest.h"
27 #include "movementtest.h"
28 #include "attacktest.h"
29 #include "ai-move1.h"
30 #include "viewtest.h"
31 #include "ai-service1.h"
32 #include "transfercontroltest.h"
33 #include "recyclingtest.h"
34 #include "researchtest.h"
35 #include "applicationstarter.h"
36 #include "diplomacytest.h"
37 #include "objectconstructiontest.h"
38 #include "eventtest.h"
39 #include "gameeventsystem.h"
40 #include "jumptest.h"
41 #include "testversionidentifier.h"
42 #include "streamencoding.h"
43 #include "tasks/taskcontainer.h"
44 #include "maptest.h"
45 #include "repairtest.h"
46 
47 
48 void viewcomp( Player& player )
49 {
50  computeview( player.getParentMap() );
51 }
52 
53 void hookGuiToMap( GameMap* map )
54 {
55  if ( !map->getGuiHooked() ) {
56 
57  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &viewcomp ) );
58  map->sigPlayerUserInteractionBegins.connect( sigc::hide( repaintMap.make_slot() ));
59 
60  map->sigPlayerUserInteractionBegins.connect( sigc::hide( sigc::ptr_fun( &checkforreplay )));
61  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &viewunreadmessages ));
62  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &checkJournal ));
63  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &checkUsedASCVersions ));
64  map->sigPlayerUserInteractionBegins.connect( sigc::hide( updateFieldInfo.make_slot() ));
65 
66  map->sigPlayerTurnHasEnded.connect( sigc::ptr_fun( &viewOwnReplay));
67  map->guiHooked();
68  }
69 }
70 
71 bool loadGameFromFile( const ASCString& filename )
72 {
73  return false;
74 }
75 
76 
78 {
79  testView();
80  // testMaps();
81  testAttack();
83  testMovement();
86  testJumpdrive();
87  testEvents();
88  testActions();
89  testResearch();
90  testDiplomacy();
91  testRecycling();
93  testAiService();
96 }
97 
98 
99 void checkGameEvents( GameMap* map,const Command& command )
100 {
101  checktimedevents( map, NULL );
102  checkevents( map, NULL );
103 }
104 
105 
106 int runTester ( )
107 {
108  loadpalette();
109 
111 
112  try {
113  loaddata();
114  }
115  catch ( ParsingError& err ) {
116  errorMessage ( "Error parsing text file " + err.getMessage() );
117  return -1;
118  }
119  catch ( tfileerror& err ) {
120  errorMessage ( "Error loading file " + err.getFileName() );
121  return -1;
122  }
123  catch ( ASCexception& ) {
124  errorMessage ( "loading of game failed" );
125  return -1;
126  }
127  catch ( ThreadExitException& ) {
128  displayLogMessage(0, "caught thread exiting exception, shutting down");
129  return -1;
130  }
131 
132 #ifndef _WIN32_
133  // Windows/MSVC will catch access violations with this, which we don't want to, because it makes our dump files useless.
134  catch ( ... ) {
135  fatalError ( "caught undefined exception" );
136  return -1;
137  }
138 #endif
139 
140  GameMap::sigPlayerTurnEndsStatic.connect( sigc::ptr_fun( &automaticTrainig ));
141  //ActionContainer::postActionExecution.connect( SigC::slot( &checkGameEvents ));
142 
144 
145  runUnitTests();
146 
147  return 0;
148 }
149 
150 
151 
152 static void __runResearch( Player& player ){
153  runResearch( player, NULL, NULL );
154 }
155 
157 {
158  map->sigPlayerTurnBegins.connect( sigc::ptr_fun( &initReplayLogging ));
159  map->sigPlayerTurnBegins.connect( sigc::ptr_fun( &transfer_all_outstanding_tribute ));
160  map->sigPlayerTurnBegins.connect( sigc::ptr_fun( &__runResearch ));
161 }
162 
163 
164 
165 
166 // including the command line parser, which is generated by genparse
167 #include "clparser/asc.cpp"
168 
169 
170 void executeUserAction ( tuseractions action ) {};
171 void execUserAction_ev ( tuseractions action ) {};
172 
173 
174 int main(int argc, char *argv[] )
175 {
176  assert ( sizeof(PointerSizedInt) == sizeof(int*));
177 
178  // we should think about replacing clparser with libpopt
179  Cmdline* cl = NULL;
180  try {
181  cl = new Cmdline ( argc, argv );
182  } catch ( const string& s ) {
183  cerr << s;
184  exit(1);
185  }
186  auto_ptr<Cmdline> apcl ( cl );
187 
188  if ( cl->v() ) {
190  printf( "%s", msg.c_str() );
191  exit(0);
192  }
193 
194  MessagingHub::Instance().setVerbosity( cl->r() );
195  StdIoErrorHandler stdIoErrorHandler(false);
196  MessagingHub::Instance().exitHandler.connect( sigc::bind( &exit_asc, -1 ));
197 
198 #ifdef WIN32
199  Win32IoErrorHandler* win32ErrorDialogGenerator = new Win32IoErrorHandler;
200 #endif
201 
202  ConfigurationFileLocator::Instance().setExecutableLocation( argv[0] );
203  initFileIO( cl->c() ); // passing the filename from the command line options
204 
205  SoundSystem soundSystem ( true, true, true );
206 
207  tspfldloaders::mapLoaded.connect( sigc::ptr_fun( &deployMapPlayingHooks ));
209 
210  PG_FileArchive archive( argv[0] );
211 
212  try {
213  int result = runTester();
214  if ( result != 0 )
215  return result;
216  }
217  catch ( bad_alloc& ) {
218  fatalError ("Out of memory");
219  return 1;
220  }
221  catch ( ASCmsgException& e ) {
222  cerr << e.getMessage() << "\n";
223  return 2;
224  }
225  catch ( ActionResult& ar ) {
226  cerr << "ActionResult failed:" << ar.getCode() << " : " << ar.getMessage() << "\n";
227  return 2;
228  }
229  catch ( ... ) {
230  cerr << "caught exception\n";
231  return 2;
232  }
233 
234  cout << "unittests completed successfully \n";
235  return 0;
236 }
void viewOwnReplay(Player &player)
runs the replay of the current player. This is used primarily for debugging the replay system ...
Definition: replay.cpp:630
void viewcomp(Player &player)
Definition: main.cpp:48
static void __runResearch(Player &player)
Definition: main.cpp:152
static sigc::signal< void, GameMap *, Player & > sigPlayerTurnEndsStatic
Definition: gamemap.h:502
void testJumpdrive()
Definition: jumptest.cpp:19
int computeview(GameMap *gamemap, int player_fieldcount_mask, bool disableShareView, const Context *context)
completely computes the view
void checkUsedASCVersions(Player &currentPlayer)
this checks if one player has been using a new ASC version than the current player. If this is the case, the current player is notified and asked to upgrade
const ASCString & getFileName() const
Definition: simplestream.h:80
void automaticTrainig(GameMap *gamemap, Player &player)
trains all units that are in training centers, which increases their experience at the cost of time (...
bool suppressMapTriggerExecution
Definition: loaders.cpp:82
void initReplayLogging(Player &player)
Initialized the replay logging at the beginning of a players or the ai's turn.
Definition: replay.cpp:687
void testAttack()
Definition: attacktest.cpp:155
const GameMap * getParentMap() const
Definition: player.h:114
void testView()
Definition: viewtest.cpp:109
void testEvents()
Definition: eventtest.cpp:32
bool loadGameFromFile(const ASCString &filename)
Definition: main.cpp:71
void testAiService()
Definition: ai-service1.cpp:59
tvirtualscreenbuf virtualscreenbuf
Definition: dlg_box.cpp:101
void exit_asc(int returnresult)
Definition: events.cpp:612
unsigned long PointerSizedInt
sigc::signal< void > repaintMap
}@
Definition: spfst.cpp:45
void execUserAction_ev(tuseractions action)
Definition: main.cpp:171
Interface for some basic classes from which all of ASC's dialogs are derived.
void deployMapPlayingHooks(GameMap *map)
Definition: main.cpp:156
void testRecycling()
A Command is an action that the player initiates.
Definition: command.h:114
void testUnitRepair()
Definition: repairtest.cpp:123
void viewunreadmessages(Player &player)
Definition: messagedlg.cpp:621
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ASCString getMessage() const
void checktimedevents(GameMap *gamemap, MapDisplayInterface *md)
bool checkevents(GameMap *gamemap, MapDisplayInterface *md)
Handling the connection of buildings by pipelines, powerlines etc.
void testResearch()
void testDiplomacy()
Interface for various global functions and variables.
void executeUserAction(tuseractions action)
Definition: main.cpp:170
void checkGameEvents(GameMap *map, const Command &command)
Definition: main.cpp:99
void testAiMovement()
Definition: ai-move1.cpp:175
Interface for recording and playing replays.
sigc::signal< void, Player & > sigPlayerTurnHasEnded
Definition: gamemap.h:497
void runUnitTests()
Definition: main.cpp:77
void displayLogMessage(int msgVerbosity, const char *message,...)
The collection of all sounds used by ASC.
void testStreamEncoding()
void init(void)
Definition: dlg_box.cpp:110
sigc::signal< void, Player & > sigPlayerTurnBegins
Definition: gamemap.h:493
const ASCString & getMessage(void) const
Definition: errors.h:42
sigc::signal< void > updateFieldInfo
Definition: spfst.cpp:47
void checkforreplay()
checks if there is replay information and -if there is any- runs the replay
Definition: replay.cpp:641
void testTransferControl()
tuseractions
Definition: edglobal.h:34
void errorMessage(const ASCString &string)
ASCString getstartupmessage()
Definition: strtmesg.cpp:70
void loaddata()
void runResearch(Player &player, vector< const Technology * > *newTechs, vector< ASCString > *newTechAdapter)
progresses in the current research, automatically chosing technologies towards the research goal...
void loadpalette(void)
Definition: sgstream.cpp:67
The interface for the artificial intelligence of ASC.
int runTester()
Definition: main.cpp:106
procedure for loading and writing savegames, maps etc.
Interface to the event handling of ASC.
void testActions()
Definition: actiontest.cpp:17
static sigc::signal< void, GameMap * > mapLoaded
Definition: loaders.h:73
void initFileIO(const ASCString &configFileName, int skipChecks)
Definition: sgstream.cpp:475
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
void guiHooked()
Definition: gamemap.cpp:289
sigc::signal< void, Player & > sigPlayerUserInteractionBegins
Definition: gamemap.h:494
void transfer_all_outstanding_tribute(Player &player)
int getCode() const
Definition: actionresult.h:43
bool getGuiHooked()
Definition: gamemap.h:572
void checkJournal(Player &player)
Definition: messagedlg.cpp:587
int main(int argc, char *argv[])
Definition: main.cpp:174
void fatalError(const ASCString &string)
void testObjectConstruction()
static void registerHooks()
void testVersionIdentifier()
void testMovement()
pround ar
Definition: history.cpp:94
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
void hookGuiToMap(GameMap *map)
Definition: main.cpp:53