Advanced Strategic Command
edmain.cpp
Go to the documentation of this file.
1 
5 /*
6  This file is part of Advanced Strategic Command; http://www.asc-hq.de
7  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING. If not, write to the
21  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  Boston, MA 02111-1307 USA
23 */
24 
25 #include <algorithm>
26 #include <memory>
27 #include <SDL_image.h>
28 #include <signal.h>
29 
30 #include "edmisc.h"
31 #include "loadbi3.h"
32 #include "edselfnt.h"
33 #include "edglobal.h"
34 #include "errors.h"
35 #include "gameoptions.h"
36 #include "mapdisplay.h"
37 #include "itemrepository.h"
38 #include "loadimage.h"
39 #include "graphicset.h"
40 #include "paradialog.h"
41 #include "soundList.h"
42 #include "maped-mainscreen.h"
43 #include "cannedmessages.h"
44 #include "stdio-errorhandler.h"
45 #include "unitset.h"
47 #include "spfst-legacy.h"
48 #include "dataversioncheck.h"
50 
51 #ifdef WIN32
52 # include "win32/win32-errormsg.h"
53 # include "win32/msvc/mdump.h"
54  MiniDumper miniDumper( "mapeditor" );
55 #endif
56 
57 
58 
59 // #define MEMCHK
60 #include "memorycheck.cpp"
61 
62 pfont load_font(const char* name)
63 {
64  tnfilestream stream ( name, tnstream::reading );
65  return loadfont ( &stream );
66 }
67 
68 
69 void loadEditordata( void )
70 {
71  loadmessages();
72 
74 
75  GraphicSetManager::Instance().loadData();
76 
79 
80  loadAllData();
81 
83 
84  loadUnitSets();
85 
86  schriften.smallarial = load_font("smalaril.fnt");
87  schriften.large = load_font("usablack.fnt");
88  schriften.arial8 = load_font("arial8.fnt");
89  schriften.smallsystem = load_font("msystem.fnt");
90  schriften.monogui = load_font("monogui.fnt");
91 
93 }
94 
95 void buildemptymap ( void )
96 {
97  TerrainType::Weather* w = terrainTypeRepository.getObject_byID(30)->weather[0];
98  if ( !w )
99  w = terrainTypeRepository.getObject_byPos(0)->weather[0];
100 
101  actmap = new GameMap;
102  actmap->allocateFields( 10, 20, w );
103 }
104 
105 
106 int mapeditorMainThread ( void* _mapname )
107 {
108  const char* mapname = (const char*) _mapname;
109  loadpalette();
110 
111  try {
112  StartupScreen sus( "title_mapeditor.jpg", dataLoaderTicker );
113 
114  GraphicSetManager::Instance().loadData();
115  loadEditordata();
116 
117  if ( mapname && mapname[0] ) {
118  /*
119  if( patimat ( savegameextension, mapname )) {
120  if( validatesavfile( mapname ) == 0 )
121  fatalError ( "The savegame %s is invalid. Aborting.", mapname );
122 
123  try {
124  loadgame( mapname );
125  } catch ( tfileerror ) {
126  fatalError ( "%s is not a legal savegame. ", mapname );
127  }
128  } else*/
129  if( patimat ( mapextension, mapname ))
131  else
132  fatalError ( "%s is not an accepted file format", mapname );
133  } else
134  buildemptymap();
135 
137  if ( exist ( "palette.map" ))
139 
140  if (!actmap )
141  buildemptymap();
142 
144 
146 
147  } /* end try */
148  catch ( ParsingError& err ) {
149  fatalError ( "Error parsing text file " + err.getMessage() );
150  }
151  catch ( tfileerror& err ) {
152  fatalError ( "Error loading file " + err.getFileName() );
153  } /* end catch */
154  catch ( ASCmsgException& err ) {
155  fatalError( "Error loading file " + err.getMessage() );
156  }
157 
163 
164 
166 
168  mainScreenWidget->Show();
169 
170  mousevisible(true);
171 
172  getPGApplication().Run();
173 
174  if (mapsaved == false )
175  if (choice_dlg("You have unsaved changes! Save?","~y~es","~n~o") == 1)
176  k_savemap(false);
177 
178  if ( actmap ) {
179  delete actmap;
180  actmap = NULL;
181  }
182  return 0;
183 }
184 
185 // including the command line parser, which is generated by genparse
186 #include "clparser/mapedit.cpp"
187 
189 {
190  mapsaved = false;
191 }
192 
193 int main(int argc, char *argv[] )
194 {
195 
196  StdIoErrorHandler stdIoErrorHandler(false);
197 
198  putenv(const_cast<char*>("SDL_VIDEO_CENTERED=1")) ;
199 
200  Cmdline* cl = NULL;
201  try {
202  cl = new Cmdline ( argc, argv );
203  }
204  catch ( string& s ) {
205  cerr << s;
206  exit(1);
207  }
208  auto_ptr<Cmdline> apcl ( cl );
209 
210  if ( cl->next_param() < argc ) {
211  cerr << "invalid command line parameter\n";
212  exit(1);
213  }
214 
215  if ( cl->v() ) {
217  printf( "%s", msg.c_str() );
218  exit(0);
219  }
220 
221  MessagingHub::Instance().setVerbosity( cl->r() );
222  MessagingHub::Instance().exitHandler.connect( sigc::bind( &exit_asc, -1 ));
223 
224  #ifdef logging
225  logtofile ( kgetstartupmessage() );
226  logtofile ( "\n new log started \n ");
227  #endif
228 
229 #ifdef WIN32
230  Win32IoErrorHandler* win32ErrorDialogGenerator = new Win32IoErrorHandler;
231 #endif
232 
233  ConfigurationFileLocator::Instance().setExecutableLocation( argv[0] );
234  initFileIO( cl->c() );
235 
236  signal ( SIGINT, SIG_IGN );
237 
238  bool fullscreen = !CGameOptions::Instance()->mapeditWindowedMode;
239  if ( cl->f() )
240  fullscreen = true;
241  if ( cl->w() )
242  fullscreen = false;
243 
245 
246  // determining the graphics resolution
248  if ( cl->x() != 800 )
249  xr = cl->x();
250 
252  if ( cl->y() != 600 )
253  yr = cl->y();
254 
255  PG_FileArchive archive( argv[0] );
256 
257  ASC_PG_App app ( "asc2_dlg" );
258 
259  int flags = SDL_SWSURFACE;
260  if ( fullscreen )
261  flags |= SDL_FULLSCREEN;
262 
263  #ifdef pbpeditor
264  app.setIcon( "pbpeditor-icon.png" );
265  #else
266  app.setIcon( "mapeditor-icon.png" );
267  #endif
268 
269  if ( !app.InitScreen( xr, yr, 32, flags))
270  fatalError( "Could not initialize video mode");
271 #ifdef WIN32
272  delete win32ErrorDialogGenerator;
273 #endif
274 
275  #ifdef pbpeditor
276  setWindowCaption ( "PBP Editor - Advanced Strategic Command");
277  #else
278  setWindowCaption ( "Map Editor - Advanced Strategic Command");
279  #endif
280 
282 
283  mapChanged.connect( sigc::hide( repaintMap.make_slot() ) );
284  mapChanged.connect( sigc::hide( updateFieldInfo.make_slot() ) );
285  mapChanged.connect( sigc::hide( sigc::ptr_fun( &setSaveNotification) ));
286 
288 
289 
290  char* buf = new char[cl->l().length()+10];
291  strcpy ( buf, cl->l().c_str() );
293  delete[] buf;
294 
295  writegameoptions ();
296 
298 
299  return 0;
300 }
301 
tfontsettings activefontsettings
Definition: newfont.cpp:51
int main(int argc, char *argv[])
Definition: edmain.cpp:193
Uint8 background
Definition: newfont.h:171
The (base-) classes which are thrown as exceptions.
sigc::signal< void, GameMap * > mapChanged
Definition: spfst.cpp:52
void setWindowCaption(const char *s)
sets the caption of the main window
Definition: graphics.cpp:34
const ASCString & getFileName() const
Definition: simplestream.h:80
pfont monogui
Definition: spfst-legacy.h:34
void loadmessages(void)
loads all messages from the files message?.txt
void setIcon(const ASCString &filename)
Definition: paradialog.cpp:211
int mapeditorMainThread(void *_mapname)
Definition: edmain.cpp:106
sigc::signal< void > dataLoaderTicker
Loading Battle Isle 3 maps. The central BI3 map loading class is a straight conversion of Joerg Richt...
int mapeditor_xresolution
the horizontal resolution the mapeditor uses
Definition: gameoptions.h:114
tvirtualscreenbuf virtualscreenbuf
Definition: dlg_box.cpp:101
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
void checkDataVersion()
pfont arial8
Definition: spfst-legacy.h:31
pfont smallarial
Definition: spfst-legacy.h:28
void loadAllData(bool useCache)
sigc::signal< void > repaintMap
}@
Definition: spfst.cpp:45
A system that provides a set of images for vehicles, buildings, etc.
Uint8 justify
Definition: newfont.h:176
bool InitScreen(int w, int h, int depth=0, Uint32 flags=SDL_SWSURFACE|SDL_HWPALETTE)
Definition: paradialog.cpp:403
void k_savemap(bool saveas)
Definition: edmisc.cpp:607
#define lefttext
Definition: newfont.h:184
static GameMap * loadmap(const ASCString &name)
Definition: loaders.cpp:1039
Uint8 color
Definition: newfont.h:170
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool mapeditWindowedMode
force the mapeditor to run in fullscreen mode (and not windowed, which is default) ...
Definition: gameoptions.h:105
struct GameMap::PreferredFilenames preferredFileNames
pfont load_font(const char *name)
Definition: edmain.cpp:62
pfont font
Definition: newfont.h:169
ASC_PG_App & getPGApplication()
Definition: paradialog.cpp:294
Schriften schriften
Definition: spfst.cpp:66
bool mapsaved
Definition: edmisc.cpp:66
void loadEditordata(void)
Definition: edmain.cpp:69
void setSaveNotification()
Definition: edmain.cpp:188
void uselessCallToTextRenderAddons()
GameMap * mapLoadingExceptionChecker(const ASCString &filename, MapLoadingFunction loader)
Definition: loaders.cpp:1539
ItemRepositoryLoader< TerrainType > terrainTypeRepository("terraintype")
bool writegameoptions(ASCString configFileName)
Definition: sgstream.cpp:418
const char * mapextension
Definition: loaders.cpp:79
pfont smallsystem
Definition: spfst-legacy.h:29
The collection of all sounds used by ASC.
void allocateFields(int x, int y, TerrainType::Weather *terrain=NULL)
Definition: gamemap.cpp:982
Dialog classes based on the Paragui library.
ASCString kgetstartupmessage()
Definition: strtmesg.cpp:83
void init(void)
Definition: dlg_box.cpp:110
pfont loadfont(tnstream *stream)
Definition: newfont.cpp:107
void deleteMaps()
Definition: edmisc.cpp:2003
Uint16 length
Definition: newfont.h:174
const int lightblue
Definition: basegfx.h:96
const ASCString & getMessage(void) const
Definition: errors.h:42
sigc::signal< void > updateFieldInfo
Definition: spfst.cpp:47
int mapeditor_yresolution
the vertical resolution the mapeditor uses
Definition: gameoptions.h:117
int initializeEventHandling(int(*fn)(void *), void *data)
Definition: events.cpp:560
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
void toggle()
Definition: edmisc.cpp:2012
void loadpalette(void)
Definition: sgstream.cpp:67
pfont large
Definition: spfst-legacy.h:30
void loadUnitSets(void)
Definition: unitset.cpp:190
void registerDataLoader(TextFileDataLoader *dataLoader)
registers a dataLoader . The object is delete after use, so use: registerDataLoader( new MyDataLoader...
ASC_MainScreenWidget * mainScreenWidget
GameMap * actmap
Definition: spfst.cpp:64
bool exist(const ASCString &s)
does a file s exist (wildcards allowed)
Definition: basestrm.cpp:2444
void initFileIO(const ASCString &configFileName, int skipChecks)
Definition: sgstream.cpp:475
int choice_dlg(const ASCString &title, const ASCString &leftButton, const ASCString &rightButton)
Definition: dialog.cpp:616
bool patimat(const char *pat, const char *str, bool forceCaseInsensitivity)
Definition: basestrm.cpp:1997
void buildemptymap(void)
Definition: edmain.cpp:95
void mousevisible(int an)
Definition: events.cpp:75
void fatalError(const ASCString &string)
MapSwitcher mapSwitcher
Definition: edmisc.cpp:2071
void setstartvariables(void)
Definition: edmisc.cpp:681
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
Definition: newfont.h:150