Advanced Strategic Command
sg.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  sg.cpp - description
3  -------------------
4  begin : a long time ago...
5  copyright : (C) 1994-2010 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
14 /***************************************************************************
15  * *
16  * This program is free software; you can redistribute it and/or modify *
17  * it under the terms of the GNU General Public License as published by *
18  * the Free Software Foundation; either version 2 of the License, or *
19  * (at your option) any later version. *
20  * *
21  ***************************************************************************/
22 
23 
75 #include "global.h"
76 
77 #include <stdio.h>
78 #include <stdlib.h>
79 #include <new>
80 #include <cstdlib>
81 #include <ctype.h>
82 #include <algorithm>
83 #include <memory>
84 #include <fstream>
85 
86 #include <boost/regex.hpp>
87 #include <boost/algorithm/string/split.hpp>
88 #include <boost/algorithm/string/classification.hpp>
89 
90 #include "paradialog.h"
91 
92 #include "vehicletype.h"
93 #include "buildingtype.h"
94 #include "ai/ai.h"
95 #include "misc.h"
96 #include "events.h"
97 #include "typen.h"
98 #include "spfst.h"
99 #include "loaders.h"
100 #include "dlg_box.h"
101 #include "controls.h"
102 #include "dlg_box.h"
103 #include "dialog.h"
104 #include "strtmesg.h"
105 #include "gamedlg.h"
106 #include "sg.h"
107 #include "gameoptions.h"
108 #include "loadimage.h"
109 #include "astar2.h"
110 #include "errors.h"
111 #include "dialogs/pwd_dlg.h"
112 #include "viewcalculation.h"
113 #include "replay.h"
114 #include "graphicset.h"
115 #include "loadbi3.h"
116 #include "itemrepository.h"
117 #include "music.h"
118 #include "messagedlg.h"
119 #include "statisticdialog.h"
120 #include "clipboard.h"
121 #include "guifunctions.h"
122 #include "iconrepository.h"
123 #include "dashboard.h"
124 #include "gamedialog.h"
125 #include "unitset.h"
126 #include "applicationstarter.h"
127 #include "replaymapdisplay.h"
128 
129 #ifdef WEATHERGENERATOR
130 # include "weathercast.h"
131 #endif
132 
133 #include "asc-mainscreen.h"
134 #include "dialogs/unitinfodialog.h"
135 #include "util/messaginghub.h"
136 #include "cannedmessages.h"
137 #include "memorycheck.cpp"
138 #include "networkinterface.h"
139 #include "resourcenet.h"
140 #include "mapimageexport.h"
141 #include "loadpcx.h"
142 #include "gameeventsystem.h"
143 #include "sdl/sound.h"
144 #include "soundList.h"
145 #include "turncontrol.h"
146 #include "networksupervisor.h"
147 
148 #include "dialogs/newgame.h"
149 #include "dialogs/soundsettings.h"
150 #include "dialogs/alliancesetup.h"
151 #include "dialogs/unitcounting.h"
152 #include "dialogs/editgameoptions.h"
153 #include "dialogs/nextcampaignmap.h"
154 #include "dialogs/terraininfo.h"
155 #include "dialogs/editplayerdata.h"
156 #include "dialogs/locatefile.h"
157 #include "dialogs/infodialogs.h"
158 #include "stdio-errorhandler.h"
159 #include "widgets/textrenderer.h"
161 #include "dialogs/fileselector.h"
162 #include "containerbase-functions.h"
163 #include "memory-measurement.h"
165 #include "dialogs/unitguidedialog.h"
168 #include "gameevent_dialogs.h"
169 #include "actions/commandwriter.h"
170 #include "dialogs/actionmanager.h"
171 #include "dialogs/gotoposition.h"
172 #include "loggingoutput.h"
173 #include "contextutils.h"
174 #include "actions/taskinterface.h"
175 #include "tasks/taskcontainer.h"
176 #include "dialogs/taskmanager.h"
177 #include "autotraining.h"
178 #include "spfst-legacy.h"
179 #include "dialogs/eventinfo.h"
180 
181 #include "lua/luarunner.h"
182 #include "lua/luastate.h"
183 #include "luacommandwriter.h"
184 #include "campaignactionrecorder.h"
185 #include "textfiletags.h"
186 #include "dataversioncheck.h"
187 #include "packagemanager.h"
188 #include "i18n.h"
189 
190 #ifdef WIN32
191 # include "win32/win32-errormsg.h"
192 # include "win32/msvc/mdump.h"
193  MiniDumper miniDumper( "main" );
194 # include <direct.h>
195 # include <stdlib.h>
196 # include <stdio.h>
197 #endif
198 
200 {
201  return actmap->getField( actmap->getCursor() );
202 }
203 
204 
205 #define mmaintainence
206 
207 bool maintainencecheck( void )
208 {
209  int res = 0;
210  if ( res )
211  return true;
212 
213 #ifdef maintainence
214  int num = 0;
215 
216  for ( int i = 0; i < 8; i++ )
217  if ( actmap->player[i].stat == Player::human && actmap->player[i].exist())
218  num++;
219 
220  if ( actmap->campaign )
221  num++;
222 
223  if ( actmap->network )
224  num++;
225 
226  if ( num <= 1 )
227  return 1;
228  else
229  return 0;
230 
231 #else
232  return false;
233 #endif
234 }
235 
236 
237 void positionCursor( Player& player )
238 {
240 }
241 
242 void viewcomp( Player& player )
243 {
244  computeview( player.getParentMap() );
245 }
246 
247 
249 {
250  GameMap* map = actmap;
251 
252  if ( map->tasks ) {
253  TaskContainer* tc = dynamic_cast<TaskContainer*>( map->tasks );
254  if ( tc ) {
255  while ( tc->pendingCommands.begin() != tc->pendingCommands.end() ) {
256  Command* c = tc->pendingCommands.front();
257  TaskInterface* ti = dynamic_cast<TaskInterface*>( c );
258 
259  if ( ti->operatable() ) {
260  ReplayContext context( map );
261  ActionResult res = c->execute( context.getContext() );
262  if ( !res.successful() )
263  dispmessage2(res);
264  }
265 
266  tc->pendingCommands.erase( tc->pendingCommands.begin() );
267  }
268  }
269  }
270 }
271 
272 
273 void runPendingTasks( Player& player )
274 {
275  GameMap* map = player.getParentMap();
276  if ( map->tasks ) {
277  TaskContainer* tc = dynamic_cast<TaskContainer*>( map->tasks );
278  if ( tc )
279  if( tc->pendingCommands.begin() != tc->pendingCommands.end() )
280  if (choice_dlg("run pending tasks ?","~y~es","~n~o") == 1)
281  runOpenTasks();
282  }
283 }
284 
285 
286 
287 void hookGuiToMap( GameMap* map )
288 {
289  if ( !map->getGuiHooked() ) {
290 
291  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &viewcomp ) );
292  map->sigPlayerUserInteractionBegins.connect( sigc::hide( repaintMap.make_slot() ));
293 
294  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &positionCursor ));
295  map->sigPlayerUserInteractionBegins.connect( sigc::hide( sigc::ptr_fun( &checkforreplay )));
296  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &checkForNewResearch ));
297  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &viewunreadmessages ));
298  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &checkJournal ));
299  map->sigPlayerUserInteractionBegins.connect( sigc::ptr_fun( &checkUsedASCVersions ));
300  map->sigPlayerUserInteractionBegins.connect( sigc::hide( updateFieldInfo.make_slot() ));
301 
302  map->sigPlayerUserInteractionEnds.connect( sigc::ptr_fun( &runPendingTasks ));
303 
304  map->sigPlayerTurnHasEnded.connect( sigc::ptr_fun( &viewOwnReplay));
305  map->guiHooked();
306  }
307 }
308 
309 bool loadGameFromFile( const ASCString& filename )
310 {
312  if ( !m )
313  return false;
314 
315  delete actmap;
316  actmap = m;
317  actmap->levelfinished = false;
318 
319  if ( actmap->replayinfo ) {
321  displaymessage2( "actmemstream already open at begin of turn ",2 );
322 
325  else {
328  }
329  }
330 
331  computeview( actmap );
332  hookGuiToMap ( actmap );
333  return true;
334 }
335 
336 
337 
338 
339 bool loadGame( bool mostRecent )
340 {
341  ASCString s1;
342  if ( mostRecent ) {
343  int datefound = 0;
344 
347  while ( ff.getnextname( fi ))
348  if ( fi.date > datefound ) {
349  datefound = fi.date;
350  s1 = fi.name;
351  }
352  } else {
353  // s1 = selectFile( savegameextension, true );
354  s1 = selectSavegame( savegameextension, true );
355  }
356 
357  if ( !s1.empty() ) {
358  StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "loading " + s1 );
359 
360  loadGameFromFile( s1 );
361 
362  updateFieldInfo();
365  displaymap();
366 
367  return true;
368  } else
369  return false;
370 }
371 
372 
373 void saveGame( bool as )
374 {
375  if ( !actmap )
376  return;
377 
378  ASCString s1;
379 
380  int nameavail = 0;
382  nameavail = 1;
383 
384  if ( as || !nameavail ) {
385  s1 = selectSavegame( savegameextension, false);
386  } else
388 
389  if ( !s1.empty() ) {
391 
392  StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "saving " + s1 );
393  savegame( s1, actmap );
394  }
395 }
396 
397 
398 
399 
400 void loadmap( const ASCString& name, bool campaign )
401 {
403  delete actmap;
404  actmap = m;
405  computeview( actmap );
406  hookGuiToMap( actmap );
407  if ( !campaign )
408  actmap->campaign.avail = false;
409 }
410 
411 
413 
414 MapTypeLoaded loadStartupMap ( const char *gameToLoad=NULL )
415 {
416  if ( gameToLoad && gameToLoad[0] ) {
417  try {
418  if ( patimat ( ASCString("*")+tournamentextension, gameToLoad )) {
419 
420  if( validateemlfile( gameToLoad ) == 0 )
421  fatalError( "Email gamefile %s is invalid. Aborting.", gameToLoad );
422 
423  try {
424  GameMap* map = continueNetworkGame( ASCString(gameToLoad) );
425  if ( map ) {
426  delete actmap;
427  actmap = map;
429  }
430 
431  return Mailfile;
432  } catch ( tfileerror ) {
433  fatalError ( "%s is not a legal email game.", gameToLoad );
434  }
435  } else if( patimat ( savegameextension, gameToLoad )) {
436  if( validatesavfile( gameToLoad ) == 0 )
437  fatalError ( "The savegame %s is invalid. Aborting.", gameToLoad );
438 
439  try {
440  loadGameFromFile( gameToLoad );
441  computeview( actmap );
442  return Savegame;
443  } catch ( tfileerror ) {
444  fatalError ( "%s is not a legal savegame. ", gameToLoad );
445  }
446 
447  } else if( patimat ( mapextension, gameToLoad )) {
448  if( validatemapfile( gameToLoad ) == 0 )
449  fatalError ( "Mapfile %s is invalid. Aborting.", gameToLoad );
450 
451  try {
452  loadmap( gameToLoad, false );
453  } catch ( tfileerror ) {
454  fatalError ( "%s is not a legal map. ", gameToLoad );
455  }
456  } else
457  fatalError ( "Don't know how to handle the file %s ", gameToLoad );
458 
459  }
460  catch ( const InvalidID & err ) {
461  displaymessage( err.getMessage(), 2 );
462  } /* endcatch */
463  catch ( const tinvalidversion & err ) {
464  if ( err.expected < err.found )
465  displaymessage( "File/module %s has invalid version.\nExpected version %d\nFound version %d\nPlease install the latest version from www.asc-hq.org", 2, err.getFileName().c_str(), err.expected, err.found );
466  else
467  displaymessage( "File/module %s has invalid version.\nExpected version %d\nFound version %d\nThis is a bug, please report it!", 2, err.getFileName().c_str(), err.expected, err.found );
468  }
469  } else { // resort to loading defaults
470 
472 
473  if ( s.empty() )
474  s = "asc001.map";
475 
476 
477  int maploadable;
478  {
479  tfindfile ff ( s );
480  string filename = ff.getnextname();
481  maploadable = validatemapfile ( filename );
482  }
483 
484  if ( !maploadable ) {
485 
486  tfindfile ff ( mapextension );
487  string filename = ff.getnextname();
488 
489  if ( filename.empty() )
490  displaymessage( "unable to load startup-map",2);
491 
492  while ( !validatemapfile ( filename ) ) {
493  filename = ff.getnextname();
494  if ( filename.empty() )
495  displaymessage( "unable to load startup-map",2);
496 
497  }
498  s = filename;
499  }
500 
501  loadmap( s, true );
502  return Map;
503  displayLogMessage ( 6, "done\n" );
504  }
505 
506  return None;
507 }
508 
509 
510 void startnextcampaignmap( int id)
511 {
512  GameMap* map = nextCampaignMap( id );
513  delete actmap;
514  actmap = map;
515 
516  if ( actmap ) {
517  computeview( actmap );
518  hookGuiToMap( actmap );
519  repaintMap();
520 
521  if ( CGameOptions::Instance()->recordCampaignMaps )
523 
524  }
525 }
526 
527 
528 void benchgame ( bool withViewCalc )
529 {
530  int t2;
531  int t = ticker;
532  int n = 0;
533  do {
534  if ( withViewCalc )
535  computeview( actmap );
536 
537  repaintMap();
538 
539  n++;
540  t2 = ticker;
541  } while ( t + 1000 > t2 ); /* enddo */
542  double d = 100 * n;
543  d /= (t2-t);
544  char buf[100];
545  sprintf ( buf, "%3.1f fps", d );
546  infoMessage ( buf );
547 }
548 
549 
550 
551 
552 
553 void changePassword( GameMap* gamemap )
554 {
555  if ( Player::getHumanPlayerNum( gamemap) < 2 ) {
556  infoMessage ("Passwords are only used for multiplayer games");
557  return;
558  }
559 
560  bool success;
561  do {
562  Password oldpwd = gamemap->player[gamemap->actplayer].passwordcrc;
563  gamemap->player[gamemap->actplayer].passwordcrc.reset();
564  success = enterpassword ( gamemap->player[gamemap->actplayer].passwordcrc, true, true );
565  if ( !success )
566  gamemap->player[gamemap->actplayer].passwordcrc = oldpwd;
567  } while ( gamemap->player[gamemap->actplayer].passwordcrc.empty() && success && viewtextquery ( 910, "warning", "~e~nter password", "~c~ontinue without password" ) == 0 ); /* enddo */
568 }
569 
570 
571 void helpAbout()
572 {
573  ASCString s = "#fontsize=22#Advanced Strategic Command#fontsize=14#\n";
575 
576  s += "\n#fontsize=18#Credits#fontsize=14#\n";
577 
578  s += readtextmessage( 30 );
579 
580  ViewFormattedText vft( "About", s, PG_Rect(-1,-1,450,550));
581  vft.Show();
582  vft.RunModal();
583 }
584 
585 
586 
587 void undo()
588 {
589  if ( actmap ) {
592  displaymap();
594  updateFieldInfo();
595  }
596 }
597 
598 void redo()
599 {
600  if ( actmap ) {
603  displaymap();
605  updateFieldInfo();
606  }
607 }
608 
609 
610 bool continueAndStartMultiplayerGame( bool mostRecent = false )
611 {
612  GameMap* map = continueNetworkGame( mostRecent );
613  if ( map ) {
614  delete actmap;
615  actmap = map;
618  displaymap();
619  return true;
620  } else
621  return false;
622 }
623 
624 
625 
626 
628 {
629  ASCString filename = selectFile("*.lua", false );
630  if ( !filename.empty() ) {
631  LuaCommandFileWriter writer ( filename );
632  actmap->actions.getCommands( writer );
633  }
634 }
635 
637 {
638  ASCString file = selectFile( "*.lua", true );
639  if ( file.size() ) {
640  LuaState state;
641  LuaRunner runner( state );
642  runner.runFile( file );
643  if ( !runner.getErrors().empty() )
644  errorMessage( runner.getErrors() );
645  updateFieldInfo();
646  }
647 }
648 
649 
651 {
652  MapField* fld = getSelectedField();
653  if ( fld->vehicle && fieldvisiblenow(fld ) ) {
654  Vehicle* v = fld->vehicle;
655  ASCString s;
656  s += "Unit nwid = " + ASCString::toString( v->networkid ) + "\n";
657 
658  AiParameter* a = NULL;
659 
660  for ( int i = 0; i < 8; ++i )
661  if ( v->aiparam[i] ) {
662  a = v->aiparam[i];
663  break;
664  }
665 
666  if ( a ) {
667  s += "Task = " + ASCString(AItasks[(int)a->getTask() ]) + "\n";
668  s += "Job = " + ASCString(AIjobs[(int)a->getJob() ]) + "\n";
669 
670 
671  s += "Destination: ";
672  if ( a->dest.valid() )
673  s += a->dest.toString();
674  s += "\n";
675  }
676 
677  ViewFormattedText vat ( "AI properties", s, PG_Rect( 20, -1 , 450, 480 ));
678  vat.Show();
679  vat.RunModal();
680  }
681 }
682 
683 
685 {
687  if ( actmap->packageData ) {
688  ASCString s;
689  for ( PackageData::Packages::const_iterator i = actmap->packageData->packages.begin(); i != actmap->packageData->packages.end(); ++i ) {
690  s += "#fontsize=14#" + i->second->name + "#fontsize=11#\n";
691  s += i->second->description;
692  s += "\n\n";
693  }
694 
695  ViewFormattedText vat ( "Used Packages", s, PG_Rect( 20, -1 , 450, 480 ));
696  vat.Show();
697  vat.RunModal();
698  }
699 }
700 
701 
703  virtual void sneakAttack ( GameMap* map, int actingPlayer, int towardsPlayer )
704  {
705  auto_ptr<DiplomacyCommand> dc ( new DiplomacyCommand( map->player[actingPlayer]));
706  dc->sneakAttack( map->getPlayer( towardsPlayer ));
707  ActionResult res = dc->execute( createContext(actmap) );
708  if ( res.successful() )
709  dc.release();
710  else
711  displayActionError( res );
712  }
713 
714  virtual void setState ( GameMap* map, int actingPlayer, int towardsPlayer, DiplomaticStates newState )
715  {
716  auto_ptr<DiplomacyCommand> dc ( new DiplomacyCommand( map->player[actingPlayer]));
717  dc->newstate( newState, map->getPlayer( towardsPlayer ));
718  ActionResult res = dc->execute( createContext(actmap) );
719  if ( res.successful() )
720  dc.release();
721  else
722  displayActionError( res );
723  }
724 };
725 
726 
728 {
731  if ( computeview( actmap ))
732  displaymap();
733  }
734 }
735 
736 
742 {
743  if ( player.research.activetechnology ) {
744  infoMessage("You are already researching " + player.research.activetechnology->name);
745  } else {
746  if ( !player.research.progress )
747  infoMessage("You don't have any research points to spend");
748  else {
749  checkForNewResearch( player );
750  }
751  }
752 }
753 
754 
755 
756 
757 
758 // user actions using the old event system
760 {
761  switch ( action ) {
762  case ua_repainthard :
763  case ua_repaint :
764  repaintDisplay();
765  break;
766 
767  case ua_help :
768  help(20);
769  break;
770 
771  case ua_howtostartpbem :
772  help(21);
773  break;
774 
775  case ua_howtocontinuepbem :
776  help(22);
777  break;
778 
779 /*
780  case ua_mntnc_morefog:
781  if (actmap->weather.fog < 255 && maintainencecheck() ) {
782  actmap->weather.fog++;
783  computeview( actmap );
784  displaymessage2("fog intensity set to %d ", actmap->weather.fog);
785  displaymap();
786  }
787  break;
788 
789  case ua_mntnc_lessfog:
790  if (actmap->weather.fog && maintainencecheck()) {
791  actmap->weather.fog--;
792  computeview( actmap );
793  displaymessage2("fog intensity set to %d ", actmap->weather.fog);
794  displaymap();
795  }
796  break;
797 
798  case ua_mntnc_morewind:
799  if ((actmap->weather.windSpeed < 254) && maintainencecheck()) {
800  actmap->weather.windSpeed+=2;
801  displaywindspeed ( );
802  updateFieldInfo();
803  }
804  break;
805 
806  case ua_mntnc_lesswind:
807  if ((actmap->weather.windSpeed > 1) && maintainencecheck() ) {
808  actmap->weather.windSpeed-=2;
809  displaywindspeed ( );
810  updateFieldInfo();
811  }
812  break;
813 
814  case ua_mntnc_rotatewind:
815  if ( maintainencecheck() ) {
816  if (actmap->weather.windDirection < sidenum-1 )
817  actmap->weather.windDirection++;
818  else
819  actmap->weather.windDirection = 0;
820  displaymessage2("wind dir set to %d ", actmap->weather.windDirection);
821  updateFieldInfo();
822  displaymap();
823  }
824  break;
825 */
827  if ( mainScreenWidget )
828  mainScreenWidget->toggleMapLayer( "resources");
829  displaymap();
830  break;
831 
832  case ua_visibilityInfo:
833  if ( mainScreenWidget )
834  mainScreenWidget->toggleMapLayer( "visibilityvalue");
835  displaymap();
836  break;
837 
838  case ua_showCargoLayer:
839  if ( mainScreenWidget )
840  mainScreenWidget->toggleMapLayer( "container");
841  displaymap();
842  break;
843 
844  case ua_benchgamewov:
845  benchgame( false );
846  break;
847 
848  case ua_benchgamewv :
849  benchgame( true );
850  break;
851 
852  case ua_writescreentopcx:
853  {
854  ASCString name = getnextfilenumname ( "screen", "pcx", 0 );
855  Surface s ( PG_Application::GetScreen() );
856  writepcx ( name, s);
857  displaymessage2( "screen saved to %s", name.c_str() );
858  }
859  break;
860 
861  case ua_bi3preferences:
862  bi3preferences();
863  break;
864 
865  case ua_settribute :
867  break;
868 
869  case ua_giveunitaway:
872  else
873  infoMessage("Sorry, this function has been disabled when starting the map!");
874  break;
875 
876  case ua_newmessage:
877  newmessage();
878  break;
879 
881  viewmessages( "queued messages", actmap->unsentmessage, 1 );
882  break;
883 
884  case ua_viewsentmessages:
885  viewmessages( "sent messages", actmap->player[ actmap->actplayer ].sentmessage, 0);
886  break;
887 
889  viewmessages( "received messages", actmap->player[ actmap->actplayer ].oldmessage, 0 );
890  break;
891 
892  case ua_viewjournal:
893  viewjournal( true );
894  break;
895 
896  case ua_editjournal:
897  editjournal();
898  break;
899 
900  case ua_viewaboutmessage:
901  helpAbout();
902  break;
903 
904  case ua_viewlayerhelp:
905  help(49);
906  break;
907 
908  case ua_SDLinfo:
909  showSDLInfo();
910  break;
911 
912  case ua_toggleunitshading:
913  {
916  displaymap();
917  while ( mouseparams.taste )
919 
920  ASCString condition;
921  if ( CGameOptions::Instance()->units_gray_after_move )
922  condition = "- thay can't move";
923  else
924  condition = "- thay can't move AND\n- thay can't shoot";
925 
926  infoMessage ("units that now displayed shaded when:\n" + condition);
927  }
928 
929  break;
930 
931  case ua_computerturn:
932  if ( maintainencecheck() ) {
933  displaymessage("This function is under development and for programmers only\n"
934  "unpredictable things may happen ...",3 ) ;
935 
936  if (choice_dlg("do you really want to start the AI?","~y~es","~n~o") == 1) {
937 
938  if ( !actmap->player[ actmap->actplayer ].ai )
940 
941  savegame ( "aistart.sav", actmap);
943  }
944  }
945  break;
946  case ua_setupnetwork:
947  /*
948  if ( actmap->network )
949  setupnetwork ( actmap->network );
950  else
951  displaymessage("This map is not played across a network",3 );
952  */
953  displaymessage("Not implemented yet",3 );
954  break;
955  case ua_UnitSetInfo:
956  viewUnitSetinfo();
957  break;
960  break;
963  break;
964 
967  break;
968 
969  case ua_aibench:
970  if ( maintainencecheck() && 0 ) {
971  if ( !actmap->player[ actmap->actplayer ].ai )
973 
974  if ( AI* ai = dynamic_cast<AI*>( actmap->player[ actmap->actplayer ].ai )) {
975  savegame ( "ai-bench-start.sav", actmap);
976  ai->run( true, &getDefaultMapDisplay() );
977  }
978  }
979  break;
980 
981  case ua_selectPlayList:
982  selectPlayList();
983  break;
984  case ua_statisticdialog:
985  statisticDialog();
986  break;
987 
988  case ua_togglesound:
989  if ( !SoundSystem::getInstance()->isOff() ) {
992  if ( on )
994  else
996  }
997  break;
998  case ua_showPlayerSpeed:
999  showPlayerTime();
1000  break;
1001  case ua_cancelResearch:
1003  ASCString s = "do you really want to cancel the current research project ?\n";
1004  // s += strrr ( actmap->player[actmap->actplayer].research.progress );
1005  // s += " research points will be lost.";
1006  if (choice_dlg(s.c_str(),"~y~es","~n~o") == 1) {
1007  auto_ptr<CancelResearchCommand> crc ( new CancelResearchCommand( actmap ));
1008  crc->setPlayer( actmap->player[actmap->actplayer] );
1009  ActionResult res = crc->execute( createContext( actmap ));
1010  if ( res.successful() )
1011  crc.release();
1012  else
1013  displayActionError( res );
1014  }
1015 
1016  } else
1017  displaymessage("you are not researching anything", 3);
1018  break;
1019  case ua_showResearchStatus: {
1020  ASCString s;
1021  s += "Current technology:\n";
1024  else
1025  s += " - none - ";
1026  s += "\n\n";
1027 
1028  s += "Research Points: \n";
1032  s += "\n\n";
1033 
1034  s+= "Research Points Plus \n";
1035 
1037 
1038  s += "\n\n";
1039 
1040  s+= "Developed Technologies: \n";
1041  for ( vector<int>::iterator i = actmap->player[actmap->actplayer].research.developedTechnologies.begin(); i != actmap->player[actmap->actplayer].research.developedTechnologies.end(); ++i ) {
1042  Technology* t = technologyRepository.getObject_byID( *i );
1043  if ( t )
1044  s += t->name + "\n";
1045  }
1046 
1047  tviewanytext vat ;
1048  vat.init ( "Research Status", s.c_str(), 20, -1 , 450, 480 );
1049  vat.run();
1050  vat.done();
1051  }
1052  break;
1053  case ua_exportUnitToFile:
1054  warningMessage("this function is not supported any longer");
1055  break;
1056  case ua_undo:
1057  undo();
1058  break;
1059  case ua_redo:
1060  redo();
1061  break;
1062 
1063 
1064  case ua_unitweightinfo:
1065  if ( fieldvisiblenow ( getSelectedField() )) {
1066  Vehicle* eht = getSelectedField()->vehicle;
1067  if ( eht && actmap->player[actmap->actplayer].diplomacy.getState( eht->getOwner()) >= PEACE_SV )
1068  infoMessage(" weight of unit: \n basic: " + ASCString::toString(eht->typ->weight) + "\n+cargo: " + ASCString::toString(eht->cargoWeight()) + "\n= " + ASCString::toString( eht->weight() ));
1069  }
1070  break;
1071  case ua_GameStatus:
1072  infoMessage ( "Current game time is:\n turn " + ASCString::toString( actmap->time.turn() ) + " , move " + ASCString::toString( actmap->time.move() ));
1073  break;
1074  case ua_soundDialog:
1075  soundSettings( NULL );
1076  break;
1077  case ua_reloadDlgTheme:
1079  MessagingHub::Instance().message( MessagingHubBase::InfoMessage, "Theme reloaded" );
1080  // soundSettings( NULL );
1081  break;
1083  break;
1085  break;
1087  break;
1089  break;
1091  break;
1093  break;
1094 // case ua_viewActionPanel: mainScreenWidget->spawnPanel( ASC_MainScreenWidget::ActionInfo );
1095 // break;
1097  break;
1098 #ifdef WEATHERGENERATOR
1099  case ua_weathercast: weathercast();
1100  break;
1101 #endif
1102  case ua_newGame:
1104  break;
1105 
1108  break;
1109 
1112  break;
1113  case ua_loadgame: loadGame( false);
1114  break;
1115  case ua_loadrecentgame: loadGame ( true );
1116  break;
1117  case ua_savegame: saveGame( true );
1118  break;
1119  case ua_setupalliances:
1120  editAlliances();
1121  updateFieldInfo();
1122  break;
1123  case ua_mainmenu:
1124  /*
1125  if (choice_dlg("do you really want to close the current game ?","~y~es","~n~o") == 1) {
1126  delete actmap;
1127  actmap = NULL;
1128  throw NoMapLoaded();
1129  }
1130  */
1132  break;
1133  case ua_viewterraininfo:
1136  break;
1137  case ua_testMessages:
1138  MessagingHub::Instance().message( MessagingHubBase::InfoMessage, "This is an informational message" );
1139  MessagingHub::Instance().message( MessagingHubBase::Warning, "This is an warning message" );
1140  MessagingHub::Instance().message( MessagingHubBase::Error, "This is an error message" );
1141  MessagingHub::Instance().message( MessagingHubBase::FatalError, "This is an fatal error message. Game will be exited." );
1142  break;
1143  case ua_writemaptopcx :
1144  writemaptopcx ( actmap, choice_dlg("Include View ?","~y~es","~n~o")==1 );
1145  break;
1146  case ua_exitgame:
1147  if (choiceDialog("do you really want to quit ?","~y~es","~n~o", "quitasc") == 1)
1148  getPGApplication().Quit();
1149  break;
1150  case ua_cargosummary:
1152  break;
1154  break;
1155  case ua_gamepreferences:
1156  editGameOptions();
1157  break;
1158  case ua_increase_zoom:
1161  viewChanged();
1162  repaintMap();
1163  }
1164  break;
1165  case ua_decrease_zoom:
1168  viewChanged();
1169  repaintMap();
1170  }
1171  break;
1172  case ua_selectgraphicset:
1173  selectgraphicset();
1174  break;
1175  case ua_networksupervisor:
1177  displaymap();
1178  break;
1179  case ua_researchinfo:
1180  researchinfo ();
1181  break;
1182  case ua_viewPipeNet:
1184  repaintMap();
1185  break;
1187  mainScreenWidget->getMapDisplay()->toggleMapLayer("reactionfire");
1188  repaintMap();
1189  break;
1192  repaintMap();
1193  break;
1195  mainScreenWidget->getMapDisplay()->toggleMapLayer("unittraining");
1196  repaintMap();
1197  break;
1199  break;
1200  case ua_changepassword:
1202  break;
1203  case ua_editPlayerData:
1205  break;
1206  case ua_locatefile:
1207  locateFile();
1208  break;
1209  case ua_viewfont:
1210  viewFont();
1211  break;
1212  case ua_resourceAnalysis:
1213  resourceAnalysis();
1214  break;
1217  break;
1218  case ua_gotoPosition: {
1219  GotoPosition gp( actmap );
1220  gp.Show();
1221  gp.RunModal();
1222  };
1223  break;
1224  case ua_showTechAdapter: {
1225  ViewFormattedText vft("TechAdapter", actmap->getCurrentPlayer().research.listTriggeredTechAdapter(), PG_Rect( -1,-1,300,500));
1226  vft.Show();
1227  vft.RunModal();
1228  };
1229  break;
1231  break;
1232 
1234  break;
1235 
1237  break;
1238 
1240  break;
1241 
1242  case ua_createReminder: newreminder();
1243  break;
1244 
1245  case ua_recompteview:
1247  displaymap();
1248  break;
1249 
1250  case ua_unitGuideDialog:
1251  unitGuideWindow( 2);
1252  break;
1253 
1255  break;
1256 
1258  break;
1259 
1261  break;
1262 
1264  break;
1265 
1267  break;
1268 
1270  break;
1271 
1272  case ua_runOpenTasks: runOpenTasks();
1273  break;
1274 
1276  break;
1277 
1279  break;
1280 
1282  break;
1283 
1284  default:
1285  break;
1286  };
1287 }
1288 
1289 
1290 
1291 
1292 bool mainloopidle( PG_MessageObject* msgObj )
1293 {
1294  if ( msgObj != PG_Application::GetApp())
1295  return false;
1296 
1297  if ( actmap ) {
1298  while ( actmap->player[ actmap->actplayer ].queuedEvents )
1300  return false;
1301 
1303 
1304  checkforvictory( actmap, true );
1305  }
1306  return false;
1307 }
1308 
1309 
1310 void resetActions( GameMap& map )
1311 {
1315  }
1316 }
1317 
1318 void resetActmap( GameMap& map )
1319 {
1320  if ( &map == actmap )
1321  actmap = NULL;
1322 }
1323 
1324 
1325 pfont load_font ( const char* name )
1326 {
1327  tnfilestream stream ( name , tnstream::reading );
1328  return loadfont ( &stream );
1329 }
1330 
1332 {
1333  schriften.smallarial = load_font("smalaril.fnt");
1334  schriften.large = load_font("usablack.fnt");
1335  schriften.arial8 = load_font("arial8.fnt");
1336  schriften.smallsystem = load_font("msystem.fnt");
1337  schriften.guifont = load_font("gui.fnt");
1338  schriften.guicolfont = load_font("guicol.fnt");
1339  schriften.monogui = load_font("monogui.fnt");
1340 
1342  shrinkfont ( schriften.guifont, -1 );
1344  shrinkfont ( schriften.monogui, -1 );
1345 
1346 }
1347 
1348 
1349 
1350 
1351 
1352 class GameThreadParams: public sigc::trackable
1353 {
1354  private:
1355  bool exit() { exitMainloop = true; return true; };
1356  public:
1361  {
1362  app.sigQuit.connect( sigc::hide( sigc::mem_fun( *this, &GameThreadParams::exit )));
1363  };
1364 };
1365 
1366 
1367 void checkGameEvents( GameMap* map,const Command& command )
1368 {
1370  checkevents( map, &getDefaultMapDisplay() );
1371 }
1372 
1373 int gamethread ( void* data )
1374 {
1375  GameMap::sigMapDeletion.connect( sigc::ptr_fun( &resetActions ));
1376  GameMap::sigMapDeletion.connect( sigc::ptr_fun( &resetActmap ));
1377  GameMap::sigPlayerTurnEndsStatic.connect( sigc::ptr_fun( &automaticTrainig ));
1378 
1380 
1381  GameThreadParams* gtp = (GameThreadParams*) data;
1382 
1383  std::auto_ptr<StartupScreen> startupScreen;
1384 
1385  MapTypeLoaded mtl = None;
1386 
1387  try {
1388  loadpalette();
1390 
1391  startupScreen.reset( new StartupScreen( "title.jpg", dataLoaderTicker ));
1392  loadLegacyFonts();
1393  loaddata();
1394 
1396 
1397  mtl = loadStartupMap( gtp->filename.c_str() );
1398  }
1399  catch ( const ParsingError & err ) {
1400  errorMessage ( "Error parsing text file " + err.getMessage() );
1401  return -1;
1402  }
1403  catch ( const tfileerror & err ) {
1404  errorMessage ( "Error loading file " + err.getFileName() );
1405  return -1;
1406  }
1407  catch ( const ASCmsgException & msg ) {
1408  errorMessage ( msg.getMessage() );
1409  return -1;
1410  }
1411  catch ( const ASCexception & ) {
1412  errorMessage ( "loading of game failed" );
1413  return -1;
1414  }
1415  catch ( const ThreadExitException & ) {
1416  displayLogMessage(0, "caught thread exiting exception, shutting down");
1417  return -1;
1418  }
1419 
1420 #ifndef _WIN32_
1421  // Windows/MSVC will catch access violations with this, which we don't want to, because it makes our dump files useless.
1422  catch ( ... ) {
1423  fatalError ( "caught undefined exception" );
1424  }
1425 #endif
1426 
1427 
1428 
1429 // ActionContainer::postActionExecution.connect( SigC::slot( &checkGameEvents ));
1430 
1431  static ShowNewTechnology showNewTechs;
1432  setResearchPresenter( &showNewTechs );
1433 
1434  displayLogMessage ( 5, "loaddata completed successfully.\n" );
1435  dataLoaderTicker();
1436 
1437  displayLogMessage ( 5, "starting music..." );
1438  startMusic();
1439  displayLogMessage ( 5, " done\n" );
1440  dataLoaderTicker();
1441 
1442  repaintDisplay.connect( repaintMap );
1443 
1445  dataLoaderTicker();
1446 
1447  /*
1449  if ( actmap && actmap->actplayer == -1 ) {
1450  displayLogMessage ( 8, "Startup :: performing first next_turn..." );
1451  next_turn( actmap, NextTurnStrategy_AskUser(), &getDefaultMapDisplay() );
1452  displayLogMessage ( 8, "done.\n" );
1453  }
1454  */
1455 
1456  displayLogMessage ( 5, "entering outer main loop.\n" );
1457  do {
1458  try {
1459  if ( !actmap || actmap->xsize <= 0 || actmap->ysize <= 0 ) {
1460  displayLogMessage ( 8, "gamethread :: starting main menu.\n" );
1461  startupScreen.reset();
1463  mtl = None;
1464  } else {
1465  mainScreenWidget->Show();
1466  startupScreen.reset();
1467 
1468  if ( actmap->actplayer == -1 ) {
1469  displayLogMessage ( 8, "gamethread :: performing next_turn..." );
1471  displayLogMessage ( 8, "done.\n" );
1472  }
1473 
1474  updateFieldInfo();
1475 
1476  displayLogMessage ( 4, "Spawning MainScreenWidget\n ");
1477 
1478 
1479  displayLogMessage ( 7, "Entering main event loop\n");
1480 
1481  if ( mtl == Mailfile )
1483 
1484  mtl = None;
1485 
1486  getPGApplication().Run();
1487  displayLogMessage ( 7, "mainloop exited\n");
1488  }
1489  } /* endtry */
1490  catch ( const NoMapLoaded & ) {
1491  delete actmap;
1492  actmap = NULL;
1493  } /* endcatch */
1494  catch ( const ShutDownMap & ) {
1495  delete actmap;
1496  actmap = NULL;
1497  }
1498  catch ( const LoadNextMap & lnm ) {
1499  if ( actmap->campaign.avail ) {
1500  delete actmap;
1501  actmap = NULL;
1502  startnextcampaignmap( lnm.id );
1503  } else {
1504  viewtext2(904);
1505  if (choice_dlg("Do you want to continue playing ?","~y~es","~n~o") == 2) {
1506  delete actmap;
1507  actmap = NULL;
1508  } else {
1509  actmap->continueplaying = 1;
1510  if ( actmap->replayinfo ) {
1511  delete actmap->replayinfo;
1512  actmap->replayinfo = NULL;
1513  }
1514  }
1515  }
1516  }
1517  } while ( !gtp->exitMainloop );
1518 
1519  delete actmap;
1520  actmap = NULL;
1521 
1522  return 0;
1523 }
1524 
1525 
1526 static void __runResearch( Player& player ){
1527  runResearch( player, NULL, NULL );
1528 }
1529 
1531 {
1532  map->sigPlayerTurnBegins.connect( sigc::ptr_fun( &initReplayLogging ));
1533  map->sigPlayerTurnBegins.connect( sigc::ptr_fun( &transfer_all_outstanding_tribute ));
1534  map->sigPlayerTurnBegins.connect( sigc::ptr_fun( &__runResearch ));
1535 }
1536 
1537 
1538 
1539 
1540 
1541 
1542 
1543 // including the command line parser, which is generated by genparse
1544 #include "clparser/asc.cpp"
1545 
1546 
1547 class ResourceLogger: public sigc::trackable {
1548  ofstream s;
1549  public:
1551  s.open("resource-log", ios_base::out | ios_base::trunc );
1552  MessagingHub::Instance().logCategorizedMessage.connect( sigc::mem_fun( *this, &ResourceLogger::message ));
1553  MessagingHub::Instance().setLoggingCategory("ResourceWork", true);
1554  };
1555 
1556  void message( const ASCString& category, const ASCString& msg )
1557  {
1558  if ( category == "ResourceWork" )
1559  s << msg << "\n";
1560  }
1561 
1563  s.close();
1564  }
1565 
1566 };
1567 
1568 
1570  Cmdline& cli;
1571  int x,y;
1572  bool fullscreen;
1573  public:
1574  ScreenResolutionSetup( Cmdline& commandLine );
1575 
1576  int getWidth() { return x; };
1577  int getHeight() { return y; };
1578  bool isFullscreen() { return fullscreen; };
1579 
1580 };
1581 
1582 ScreenResolutionSetup::ScreenResolutionSetup( Cmdline& commandLine ) : cli( commandLine )
1583 {
1584  if ( SDL_Init( SDL_INIT_VIDEO ) )
1585  fatalError( ASCString("Unable to init SDL: ") + SDL_GetError());
1586 
1587  putenv(const_cast<char*>("SDL_VIDEO_CENTERED=1")) ;
1588 
1589  fullscreen = true;
1590 
1591  if ( cli.w() )
1592  fullscreen = false;
1593 
1594  if ( cli.f() )
1595  fullscreen = true;
1596 
1597  if ( CGameOptions::Instance()->forceWindowedMode && !cli.f() ) // cl->f == force fullscreen command line param
1598  fullscreen = false;
1599 
1600  int xr = -1;
1601  int yr = -1;
1602  // determining the graphics resolution
1603 
1604  if ( CGameOptions::Instance()->xresolution != -1 )
1606  if ( cli.x() != -1 )
1607  xr = cli.x();
1608 
1609  if ( CGameOptions::Instance()->yresolution != -1 )
1611  if ( cli.y() != -1 )
1612  yr = cli.y();
1613 
1614 
1615  GetVideoModes gvm;
1616 
1617  GetVideoModes::ModeRes best = gvm.getBest();
1618  if ( xr == -1 ) {
1619  if ( fullscreen )
1620  xr = best.first;
1621  else
1622  xr = best.first - 100;
1623  }
1624 
1625  if ( yr == -1 ) {
1626  if ( fullscreen )
1627  yr = best.second;
1628  else
1629  yr = best.second - 100;
1630  }
1631 
1632 
1633  if ( CGameOptions::Instance()->graphicsDriver.compare_ci("default") != 0 ) {
1634  static char buf[100];
1635  strcpy(buf, "SDL_VIDEODRIVER=" );
1636  strncat( buf, CGameOptions::Instance()->graphicsDriver.c_str(), 100 - strlen(buf));
1637  buf[99] = 0;
1638  putenv( buf );
1639  }
1640 
1641  if ( xr == -1 )
1642  xr = 1024;
1643 
1644  if ( yr == -1 )
1645  yr = 768;
1646 
1647  x = xr;
1648  y = yr;
1649 }
1650 
1651 
1652 int main(int argc, char *argv[] )
1653 {
1654  assert ( sizeof(PointerSizedInt) == sizeof(int*));
1655 
1656  // we should think about replacing clparser with libpopt
1657  Cmdline* cl = NULL;
1658  try {
1659  cl = new Cmdline ( argc, argv );
1660  } catch ( const string & s ) {
1661  cerr << s;
1662  exit(1);
1663  }
1664  auto_ptr<Cmdline> apcl ( cl );
1665 
1666  if ( cl->v() ) {
1667  ASCString msg = getstartupmessage();
1668  printf( "%s", msg.c_str() );
1669  exit(0);
1670  }
1671 
1672  MessagingHub::Instance().setVerbosity( cl->r() );
1673  StdIoErrorHandler stdIoErrorHandler(false);
1674  MessagingHub::Instance().exitHandler.connect( sigc::bind( &exit_asc, -1 ));
1675 
1676  // ResourceLogger rl;
1677 
1678 #ifdef WIN32
1679  Win32IoErrorHandler* win32ErrorDialogGenerator = new Win32IoErrorHandler;
1680 #endif
1681 
1682 
1684 
1685  ConfigurationFileLocator::Instance().setExecutableLocation( argv[0] );
1686 
1687  try {
1688  initFileIO( cl->c() ); // passing the filename from the command line options
1689  checkDataVersion();
1690  } catch ( const tfileerror & err ) {
1691  displaymessage ( "unable to access file %s \n", 2, err.getFileName().c_str() );
1692  }
1693  catch ( ... ) {
1694  displaymessage ( "loading of game failed during pre graphic initializing", 2 );
1695  }
1696 
1697  LoggingOutputHandler logger( getSearchPath( 0 ));
1698 
1699 
1700 
1701  SoundSystem soundSystem ( CGameOptions::Instance()->sound.muteEffects, CGameOptions::Instance()->sound.muteMusic, cl->q() || CGameOptions::Instance()->sound.off );
1702  soundSystem.setMusicVolume ( CGameOptions::Instance()->sound.musicVolume );
1703  soundSystem.setEffectVolume ( CGameOptions::Instance()->sound.soundVolume );
1704 
1705 
1706  tspfldloaders::mapLoaded.connect( sigc::ptr_fun( &deployMapPlayingHooks ));
1707 
1708  PG_FileArchive archive( argv[0] );
1709 
1710  ASC_PG_App app ( "asc2_dlg" );
1711 
1712  app.sigAppIdle.connect ( sigc::ptr_fun( &mainloopidle ));
1713 
1714  cursorMoved.connect( updateFieldInfo.make_slot() );
1715 
1716 
1717  ScreenResolutionSetup screenResolutionSetup ( *cl );
1718  int flags = 0;
1719 
1720  if ( CGameOptions::Instance()->hardwareSurface )
1721  flags |= SDL_HWSURFACE;
1722  else
1723  flags |= SDL_SWSURFACE;
1724 
1725  if ( screenResolutionSetup.isFullscreen() )
1726  flags |= SDL_FULLSCREEN;
1727 
1728  app.setIcon( "program-icon.png" );
1729  bool initialized = false;
1730  if ( !app.InitScreen( screenResolutionSetup.getWidth(), screenResolutionSetup.getHeight(), 32, flags)) {
1731  if ( flags & SDL_FULLSCREEN ) {
1732  GetVideoModes gvm;
1733  if ( gvm.getList().size() > 0 ) {
1734  if ( app.InitScreen( gvm.getx(0), gvm.gety(0), 32, flags))
1735  initialized = true;
1736  }
1737  }
1738  } else
1739  initialized = true;
1740 
1741  if ( !initialized )
1742  fatalError( "Could not initialize video mode");
1743 
1744 
1745 #ifdef WIN32
1746  delete win32ErrorDialogGenerator;
1747 #endif
1748 
1749  setWindowCaption ( "Advanced Strategic Command" );
1750 
1751  GameThreadParams gtp ( app );
1752  gtp.filename = cl->l();
1753 
1754  if ( cl->next_param() < argc )
1755  for ( int i = cl->next_param(); i < argc; i++ )
1756  gtp.filename = argv[i];
1757 
1758 
1759  int returncode = 0;
1760  try {
1761  // this starts the gamethread procedure, whichs will run the entire game
1762  returncode = initializeEventHandling ( gamethread, &gtp );
1763  }
1764  catch ( const bad_alloc & ) {
1765  fatalError ("Out of memory");
1766  }
1767 
1768  writegameoptions ( );
1769 
1770  return( returncode );
1771 }
void viewOwnReplay(Player &player)
runs the replay of the current player. This is used primarily for debugging the replay system ...
Definition: replay.cpp:630
DiplomaticStates getState(PlayerID towardsPlayer) const
Definition: player.cpp:92
void writemaptopcx(GameMap *gamemap, bool addview)
void init(const char *title, const char *text, int xx1=50, int yy1=50, int xxsize=360, int yysize=360)
Definition: dialog.cpp:920
MessagePntrContainer sentmessage
the list of messages that have been sent yet
Definition: player.h:189
int queuedEvents
if ASC should check all events for fullfilled triggers, this variable will be set to true...
Definition: player.h:193
Player & getCurrentPlayer()
Definition: gamemap.h:268
void startMusic()
start playing the first playlist
Definition: music.cpp:143
Context & getContext()
void displaymap()
Definition: spfst.cpp:58
void viewmessages(const char *title, const MessagePntrContainer &msg, bool editable)
Definition: messagedlg.cpp:561
tfontsettings activefontsettings
Definition: newfont.cpp:51
static sigc::signal< void, GameMap *, Player & > sigPlayerTurnEndsStatic
Definition: gamemap.h:502
void benchgame(bool withViewCalc)
Definition: sg.cpp:528
The (base-) classes which are thrown as exceptions.
An in-memory storage of streamed data.
Definition: basestrm.h:172
sigc::signal< void, GameMap * > mapChanged
Definition: spfst.cpp:52
bool forceWindowedMode
force ASC to run in windowed mode (and not fullscreen, which is default)
Definition: gameoptions.h:93
void deployMapPlayingHooks(GameMap *map)
Definition: sg.cpp:1530
Interface for loading and writing of PCX images.
GameMap * nextCampaignMap(int id)
void checkForNewResearch(Player &player)
Let's the user select new technology for research if the current research projects are finished...
void setEffectsMute(bool mute)
Turns the sound on and off.
Definition: sound.cpp:128
void showPlayerTime()
Definition: gamedlg.cpp:665
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
MapCoordinate & getCursor()
Definition: gamemap.cpp:933
MapDisplayInterface & getDefaultMapDisplay()
void setWindowCaption(const char *s)
sets the caption of the main window
Definition: graphics.cpp:34
int xsize
the size of the map
Definition: gamemap.h:201
void showMemoryFootprint()
const char * AItasks[AiParameter::taskNum]
int computeview(GameMap *gamemap, int player_fieldcount_mask, bool disableShareView, const Context *context)
completely computes the view
map accessing and usage routines used by ASC and the mapeditor
bool units_gray_after_move
are units that cannot move but shoot displayed in gray ?
Definition: gameoptions.h:72
miscellaneous functions which are used by ASC and all its tools
DiplomaticStates
Definition: player.h:53
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
bool validatemapfile(const ASCString &filename)
checks, whether filename is a valid map file
Definition: loaders.cpp:1579
const ASCString & getFileName() const
Definition: simplestream.h:80
pfont monogui
Definition: spfst-legacy.h:34
void automaticTrainig(GameMap *gamemap, Player &player)
trains all units that are in training centers, which increases their experience at the cost of time (...
pair< int, int > ModeRes
ASCString getSearchPath(int i)
Definition: basestrm.cpp:2539
ASCString getnextfilenumname(const ASCString &first, const ASCString &suffix, int num)
Definition: basestrm.cpp:2418
Vehicle * vehicle
Definition: mapfield.h:89
void pauseMusic()
Pauses the music that is currently being played.
Definition: sound.cpp:227
const char * AIjobs[AiParameter::jobNum]
sigc::signal< void > repaintDisplay
Definition: spfst.cpp:46
void toggleMapLayer(const ASCString &name)
bool valid() const
Definition: typen.h:221
bool suppressMapTriggerExecution
Definition: loaders.cpp:82
The clipboard for ASC.
Everything that happens on the main screen of ASC.
virtual void displayPosition(int x, int y)=0
void initReplayLogging(Player &player)
Initialized the replay logging at the beginning of a players or the ai's turn.
Definition: replay.cpp:687
void resetActions(GameMap &map)
Definition: sg.cpp:1310
void setIcon(const ASCString &filename)
Definition: paradialog.cpp:211
Uint8 levelfinished
Definition: gamemap.h:321
AiParameter * aiparam[8]
Definition: vehicle.h:182
pfont guifont
Definition: spfst-legacy.h:32
ASCString toString(bool coordinates=false) const
Definition: typen.cpp:314
Definition: sg.h:32
void bi3preferences(void)
the dialog box for setting up how to load bi3 graphics and maps. Since ASC now uses its own graphics...
Definition: dialog.cpp:1124
BaseAI * ai
if the player is run by an AI, this is the pointer to it
Definition: player.h:144
void showMovementRange(GameMap *gamemap, const MapCoordinate &pos)
ASCString getVersionAndCompilation()
Version: 1.2.3 ; compiled : ...
Definition: strtmesg.cpp:63
ASCString getnextname(int *loc=NULL, bool *inContainer=NULL, ASCString *location=NULL)
Returns the next entry of the internal file list.
Definition: basestrm.cpp:2211
bool mainloopidle(PG_MessageObject *msgObj)
Definition: sg.cpp:1292
ResourceLogger()
Definition: sg.cpp:1550
const GameMap * getParentMap() const
Definition: player.h:114
ASCString readtextmessage(int id)
returns the message with the given ID from the message system.
Definition: dlg_box.cpp:3048
static void storeData(const GameMap *game)
sigc::signal< void > dataLoaderTicker
Loading Battle Isle 3 maps. The central BI3 map loading class is a straight conversion of Joerg Richt...
static GameMap * loadGameFromFile(const ASCString &name)
Definition: loaders.cpp:1135
Definition: sg.h:41
void runFile(const ASCString &filename)
Definition: luarunner.cpp:25
Context createContext(GameMap *gamemap)
void editAlliances()
Definition: sg.cpp:727
int choiceDialog(const ASCString &text, const ASCString &button1, const ASCString &button2, const ASCString &shortLabel)
Definition: paradialog.cpp:806
Definition: sg.cpp:412
DiplomaticStateVector diplomacy
Definition: player.h:209
int turn() const
Definition: typen.h:181
int getOwner() const
returns the number of the player this vehicle/building belongs to
int weight(void) const
weight of unit including cargo
Definition: vehicle.cpp:395
MemoryStreamStorage * guidata[8]
Definition: gamemap.h:374
vector< int > developedTechnologies
Definition: research.h:183
void saveGame(bool as)
Definition: sg.cpp:373
void toggleMapLayer(const ASCString &name)
tvirtualscreenbuf virtualscreenbuf
Definition: dlg_box.cpp:101
VList & getList()
Includefile (!) for heap tracking.
Loki::Functor< GameMap *, LOKI_TYPELIST_1(const ASCString &) > MapLoadingFunction
Definition: loaders.h:57
void exit_asc(int returnresult)
Definition: events.cpp:612
Definition: sg.h:36
bool muteMusic
muted soud can be reactivated during the game
Definition: gameoptions.h:174
void shrinkfont(pfont font, int diff)
Definition: newfont.cpp:206
void soundSettings(PG_MessageObject *caller)
void checkDataVersion()
unsigned long PointerSizedInt
pfont arial8
Definition: spfst-legacy.h:31
void checkGameEvents(GameMap *map, const Command &command)
Definition: sg.cpp:1367
bool areEffectsMuted()
can sounds be played right now ?
Definition: sound.h:101
MessagePntrContainer oldmessage
the list of messages that already have been read by the player yet
Definition: player.h:185
void chooseTechnologyIfAvail(Player &player)
this performs some check if a technology may be choosen right now and than either calls chooseTechnol...
Definition: sg.cpp:741
void warningMessage(const ASCString &str)
pfont smallarial
Definition: spfst-legacy.h:28
int yresolution
the vertical resolution ASC uses
Definition: gameoptions.h:111
static Command * pendingCommand
sigc::signal< void > repaintMap
}@
Definition: spfst.cpp:45
A system that provides a set of images for vehicles, buildings, etc.
Definition: sg.h:36
bool InitScreen(int w, int h, int depth=0, Uint32 flags=SDL_SWSURFACE|SDL_HWPALETTE)
Definition: paradialog.cpp:403
Global platform dependant definitions. This file just branches to the platform specific files in thei...
Interface for some basic classes from which all of ASC's dialogs are derived.
GameMap * continueNetworkGame(bool mostRecent)
continues a PBeM game; the current map is deleted
void statisticDialog()
void changePassword(GameMap *gamemap)
Definition: sg.cpp:553
a single field of the map
Definition: mapfield.h:26
bool enterpassword(Password &pwd, bool firstTime, bool cancelAllowed, bool defaultAllowed, const ASCString &username)
Definition: pwd_dlg.cpp:158
Definition: ai.h:44
sigc::signal< void, Player & > sigPlayerUserInteractionEnds
Definition: gamemap.h:495
void selectAndRunLuaScript()
Definition: sg.cpp:636
void showCargoSummary(MapField *fld)
Definition: sg.h:45
A Command is an action that the player initiates.
Definition: command.h:114
void setMusicVolume(int Volume)
Sets the music volume. Range is 0 .. 100.
Definition: sound.cpp:264
void viewMiningPower()
ItemRepositoryLoader< Technology > technologyRepository("technology")
static GameMap * loadmap(const ASCString &name)
Definition: loaders.cpp:1039
static void __runResearch(Player &player)
Definition: sg.cpp:1526
void viewunreadmessages(Player &player)
Definition: messagedlg.cpp:621
bool validatesavfile(const ASCString &filename)
checks, whether filename is a valid savegame
Definition: loaders.cpp:1648
A class that hols a MessageWindow. This class ensures that the window is removed if the last copy of ...
Definition: messaginghub.h:34
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
virtual bool operatable()=0
checks if the task can still be operated.
MapTypeLoaded
Definition: sg.cpp:412
void dispmessage2(const ActionResult &result)
Definition: dialog.cpp:466
void editPlayerData(GameMap *gamemap)
void checktimedevents(GameMap *gamemap, MapDisplayInterface *md)
void actionManager(GameMap *map)
Uint8 taste
Definition: events.h:95
bool checkevents(GameMap *gamemap, MapDisplayInterface *md)
Handling the connection of buildings by pipelines, powerlines etc.
static bool gameDialog()
Definition: gamedialog.cpp:224
bool loadGameFromFile(const ASCString &filename)
Definition: sg.cpp:309
void giveunitaway(MapField *fld, const Context &context)
Definition: gamedlg.cpp:639
void resumeMusic()
resumes the music
Definition: sound.cpp:238
virtual void run(void)
Definition: dialog.cpp:1009
void viewcomp(Player &player)
Definition: sg.cpp:242
ASCString filename
Definition: sg.cpp:1355
int move() const
Definition: typen.h:180
ASC_PG_App & application
Definition: sg.cpp:1358
Interface for various global functions and variables.
struct GameMap::PreferredFilenames preferredFileNames
void writepcx(const ASCString &name, int x1, int y1, int x2, int y2, dacpalette256 pal)
Definition: loadpcxc.cpp:277
bool fieldvisiblenow(const MapField *pe, Vehicle *veh, int player)
{@
Definition: spfst.cpp:399
void next_turn(GameMap *gamemap, const NextTurnStrategy &nextTurnStrategy, MapDisplayInterface *display, int playerView)
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
static SoundSystem * getInstance()
Definition: sound.h:127
ActionResult undo(const Context &context)
does a single undo step
bool loadGame(bool mostRecent)
Definition: sg.cpp:339
ASC_PG_App & getPGApplication()
Definition: paradialog.cpp:294
Schriften schriften
Definition: spfst.cpp:66
void done(void)
Definition: dlg_box.cpp:1235
void setChanged(bool flag=true)
Definition: gameoptions.h:272
ActionResult execute(const Context &context)
Definition: action.cpp:41
bool empty() const
Definition: password.cpp:89
void showUnitAiProperties()
Definition: sg.cpp:650
ActionRecorder * actionRecorder
Definition: gamemap.h:391
char * strrr(int a)
converts a to a string.
Definition: misc.cpp:66
bool startMultiplayerGame()
Definition: newgame.cpp:921
void positionCursor(Player &player)
Definition: sg.cpp:237
GameMap * mapLoadingExceptionChecker(const ASCString &filename, MapLoadingFunction loader)
Definition: loaders.cpp:1539
Interface for recording and playing replays.
sigc::signal< void, Player & > sigPlayerTurnHasEnded
Definition: gamemap.h:497
Definition: sg.h:46
void showSDLInfo()
Definition: infodialogs.cpp:82
Interface to game event dialogs.
enum Player::PlayerStatus stat
bool writegameoptions(ASCString configFileName)
Definition: sgstream.cpp:418
void Quit()
Definition: paradialog.cpp:223
void displayLogMessage(int msgVerbosity, const char *message,...)
const char * mapextension
Definition: loaders.cpp:79
const Technology * activetechnology
the technology that is currently being researched
Definition: research.h:191
void editGameOptions(bool mainApp)
void resetActmap(GameMap &map)
Definition: sg.cpp:1318
creates a context that will move the map so that any action can be seen by the user ...
Definition: contextutils.h:28
Packages packages
struct CGameOptions::SoundSettings sound
pfont smallsystem
Definition: spfst-legacy.h:29
Definition: sg.h:44
Reads data from or writes data to a MemoryStreamStorage This allows a completely volatile storage of ...
Definition: basestrm.h:204
The collection of all sounds used by ASC.
void displaymessage(const char *formatstring, int num,...)
displays a dialog box with a message
Definition: dlg_box.cpp:1849
static sigc::signal< void, GameMap & > sigMapDeletion
Definition: gamemap.h:501
virtual void run(MapDisplayInterface *mapDisplay)=0
void showGameParameters(void)
Definition: gamedlg.cpp:495
int getx(int index)
Dialog classes based on the Paragui library.
Searching for files.
Definition: basestrm.h:484
void viewEventInfo(GameMap *gamemap)
Definition: eventinfo.cpp:37
void init(void)
Definition: dlg_box.cpp:110
ASCString name
Definition: basestrm.h:489
void viewUnitSetinfo(void)
Definition: dialog.cpp:1367
The interface for the buildingtype class.
sigc::signal< void, Player & > sigPlayerTurnBegins
Definition: gamemap.h:493
pfont loadfont(tnstream *stream)
Definition: newfont.cpp:107
void locateFile(const ASCString &filename, FileLocation *loc)
Definition: basestrm.cpp:1008
bool avail
is this a campaign map?
Definition: gamemap.h:221
AbstractTaskContainer * tasks
Definition: gamemap.h:394
MapTypeLoaded loadStartupMap(const char *gameToLoad=NULL)
Definition: sg.cpp:414
ScreenResolutionSetup(Cmdline &commandLine)
Definition: sg.cpp:1582
void showUnitSummary(GameMap *actmap)
ActionResult redo(const Context &context)
does a single redo step
const ASCString & getMessage(void) const
Definition: errors.h:42
sigc::signal< void > updateFieldInfo
Definition: spfst.cpp:47
int viewtextquery(int id, const char *title, const char *s1, const char *s2)
Definition: dlg_box.cpp:3394
void selectPlayList()
opens a dialog to select a playlist
Definition: music.cpp:215
void checkforreplay()
checks if there is replay information and -if there is any- runs the replay
Definition: replay.cpp:641
tuseractions
Definition: edglobal.h:34
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
int releasetimeslice(void)
Definition: events.cpp:209
void message(const ASCString &category, const ASCString &msg)
Definition: sg.cpp:1556
bool successful() const
void newreminder()
Definition: messagedlg.cpp:349
bool maintainencecheck(void)
Definition: sg.cpp:207
ASCString selectSavegame(const ASCString &ext, bool load, bool overwriteMessage)
Definition: sg.h:36
void undo()
Definition: sg.cpp:587
void loadLegacyFonts()
Definition: sg.cpp:1331
int initializeEventHandling(int(*fn)(void *), void *data)
Definition: events.cpp:560
Player player[9]
Definition: gamemap.h:253
MapDisplayPG * getMapDisplay()
VisibilityStates fieldVisibility(const MapField *pe)
}@
Definition: spfst.cpp:440
void errorMessage(const ASCString &string)
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
void showUnitEndurance()
static int getHumanPlayerNum(const GameMap *gamemap)
Definition: player.cpp:285
int weight
the weight of the unit, without fuel or other cargo
Definition: vehicletype.h:218
void viewjournal(bool showEmptyDlg)
Definition: messagedlg.cpp:597
GameThreadParams(ASC_PG_App &app)
Definition: sg.cpp:1360
All parameters the AI stores persistently about a unit.
int ysize
Definition: gamemap.h:201
The widget that controls the main screen of ASC.
int getResearchPerTurn() const
Definition: research.cpp:896
sigc::signal< void > viewChanged
the view of the player onto the map changed, for example because he scrolled the map ...
Definition: spfst.cpp:51
bool isFullscreen()
Definition: sg.cpp:1578
void weathercast()
ASCString getstartupmessage()
Definition: strtmesg.cpp:70
void editEmailOptions()
ASCString selectFile(const ASCString &ext, bool load, bool overwriteMessage)
void loaddata()
void help(int id)
displays a dialogbog with the given help topic
Definition: dlg_box.cpp:3286
void runPendingTasks(Player &player)
Definition: sg.cpp:273
void runResearch(Player &player, vector< const Technology * > *newTechs, vector< ASCString > *newTechAdapter)
progresses in the current research, automatically chosing technologies towards the research goal...
void settributepayments(void)
Definition: gamedlg.cpp:255
pfont guicolfont
Definition: spfst-legacy.h:33
int getgameparameter(GameParameter num) const
Definition: gamemap.cpp:1047
void setResearchPresenter(TechnologyPresenter *presenter)
registers the class that will present newly researched technologies to the user
void loadpalette(void)
Definition: sgstream.cpp:67
void viewterraininfo(GameMap *gamemap, const MapCoordinate &pos, bool fullVisibility)
Definition: terraininfo.cpp:34
void displaymessage2(const char *formatstring,...)
displays a message in the status line of ASC
Interface for all the dialog boxes used by the game and the mapeditor.
void checkforvictory(GameMap *gamemap, bool hasTurnControl)
checks if the current player has terminated another player or even won
PackageData * packageData
Definition: gamemap.h:582
Research research
the status of the scientific research
Definition: player.h:142
CommandContainer pendingCommands
Definition: taskcontainer.h:44
pfont large
Definition: spfst-legacy.h:30
Definition: sg.cpp:412
The interface for the artificial intelligence of ASC.
void startnextcampaignmap(int id)
Definition: sg.cpp:510
procedure for loading and writing savegames, maps etc.
const VehicleType * typ
Definition: vehicle.h:83
ActionContainer actions
Records all action that have been done for undo/redo purposes.
Definition: gamemap.h:390
void reset()
Definition: password.cpp:120
ASCString name
Definition: research.h:137
int cargoWeight() const
weight of all loaded units
Definition: sg.h:46
void changeZoom(int delta)
Definition: mapdisplay.h:190
ASC_MainScreenWidget * mainScreenWidget
void editjournal(void)
Definition: messagedlg.cpp:610
void selectgraphicset(void)
Definition: dialog.cpp:2151
void newmessage()
Definition: messagedlg.cpp:335
sigc::signal< void > cursorMoved
Definition: spfst.cpp:48
pfont load_font(const char *name)
Definition: sg.cpp:1325
const ASCString & getErrors()
Definition: luarunner.cpp:61
GameMap * actmap
Definition: spfst.cpp:64
void showUsedPackages()
Definition: sg.cpp:684
Interface to the event handling of ASC.
void getCommands(AbstractCommandWriter &writer)
GameTransferMechanism * network
Definition: gamemap.h:576
void viewtext2(int id)
displays a dialogbog with the given message
Definition: dlg_box.cpp:3296
void createUnitCostList()
MessagePntrContainer unsentmessage
the list of messages that were written this turn and are waiting to be processed at the end of the tu...
Definition: gamemap.h:350
int researchpoints
Definition: research.h:135
void hookGuiToMap(GameMap *map)
Definition: sg.cpp:287
static sigc::signal< void, GameMap * > mapLoaded
Definition: loaders.h:73
pfont markfont
Definition: newfont.h:180
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 loadmap(const ASCString &name, bool campaign)
Definition: sg.cpp:400
void guiHooked()
Definition: gamemap.cpp:289
void researchinfo(void)
Definition: gamedlg.cpp:357
Password passwordcrc
the Password required for playing this player
Definition: player.h:160
Definition: sg.cpp:412
void displayActionError(const ActionResult &result, const ASCString &additionalInfo)
Definition: dialog.cpp:2168
bool validateemlfile(const ASCString &filename)
checks, whether filename is a valid email game
Definition: loaders.cpp:1615
sigc::signal< void, Player & > sigPlayerUserInteractionBegins
Definition: gamemap.h:494
void transfer_all_outstanding_tribute(Player &player)
MapCoordinate3D dest
bool exitMainloop
Definition: sg.cpp:1359
void showWeaponRange(GameMap *gamemap, const MapCoordinate &pos)
void showSearchPath()
Definition: infodialogs.cpp:30
bool off
if the sound is off, it can only be reactivated by restarting asc, but doesn't lock the sound device ...
Definition: gameoptions.h:177
void writeLuaCommands()
Definition: sg.cpp:627
int choice_dlg(const ASCString &title, const ASCString &leftButton, const ASCString &rightButton)
Definition: dialog.cpp:616
void spawnPanel(Panels panel)
bool patimat(const char *pat, const char *str, bool forceCaseInsensitivity)
Definition: basestrm.cpp:1997
static void clear()
void runOpenTasks()
Definition: sg.cpp:248
MapField * getSelectedField(void)
Definition: sg.cpp:199
bool getGuiHooked()
Definition: gamemap.h:572
Definition: sg.h:45
void checkJournal(Player &player)
Definition: messagedlg.cpp:587
volatile tmousesettings mouseparams
Definition: events.cpp:35
void fatalError(const ASCString &string)
void reloadTheme()
Definition: paradialog.cpp:423
~ResourceLogger()
Definition: sg.cpp:1562
The box displaying unit information.
int gamethread(void *data)
Definition: sg.cpp:1373
static void registerHooks()
void unitInfoDialog(const VehicleType *vt)
int progress
Definition: research.h:189
void helpAbout()
Definition: sg.cpp:571
int main(int argc, char *argv[])
Definition: sg.cpp:1652
int networkid
a unique identification of the unit that is used everywhere in ASC (and not only the network protocol...
Definition: vehicle.h:140
Interface for the A* pathfinding algorithm.
Definition: sg.h:32
bool continueAndStartMultiplayerGame(bool mostRecent=false)
Definition: sg.cpp:610
bool exist() const
does the player exist at all
Definition: player.cpp:313
void unitGuideWindow(int tabs)
void redo()
Definition: sg.cpp:598
const char * savegameextension
Definition: loaders.cpp:78
void executeUserAction(tuseractions action)
Definition: sg.cpp:759
const int found
Definition: basestrm.h:107
Definition: sg.cpp:412
bool setupalliances(GameMap *actmap, AllianceSetupWidget::ApplyStrategy *strategy, bool supervisor)
runs the Alliance-Setup dialog.
ASCString startupMap
Definition: gameoptions.h:235
void networksupervisor(void)
ReplayInfo * replayinfo
Definition: gamemap.h:396
GameTime time
the time in the game, mesured in a turns and moves
Definition: gamemap.h:235
void viewFont()
int xresolution
the horizontal resolution ASC uses
Definition: gameoptions.h:108
ASCString listTriggeredTechAdapter() const
Definition: research.cpp:790
const int expected
Definition: basestrm.h:106
MemoryStream * actmemstream
Definition: gamemap.h:376
const char * tournamentextension
Definition: loaders.cpp:80
void taskManager(GameMap *map)
int gety(int index)
void infoMessage(const ASCString &string)
void unitProductionAnalysis(GameMap *gamemap, bool checkResearch)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
volatile int ticker
Definition: events.cpp:234
Definition: sg.h:32
void resetActiveGuiAction(GameMap *map)
bool continueplaying
if a player has won a singleplayer map, but wants to continue playing without any enemies...
Definition: gamemap.h:512
Definition: newfont.h:150
struct GameMap::Campaign campaign
void resourceAnalysis()
void savegame(const ASCString &name, GameMap *gamemap)
saves the game located in actmap to the savegame file name
Definition: loaders.cpp:1456
MapField * getField(int x, int y)
Definition: gamemap.h:465