Advanced Strategic Command
map2pcx.cpp
Go to the documentation of this file.
1 
9 /*
10  This file is part of Advanced Strategic Command; http://www.asc-hq.de
11  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
12 
13  This program is free software; you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 2 of the License, or
16  (at your option) any later version.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program; see the file COPYING. If not, write to the
25  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
26  Boston, MA 02111-1307 USA
27 */
28 
29 #include <memory>
30 
31 #include "typen.h"
32 #include "loaders.h"
33 #include "loadpcx.h"
34 #include "loadbi3.h"
35 #include "errors.h"
36 #include "gameoptions.h"
37 #include "mapdisplay.h"
38 #include "dialog.h"
39 #include "strtmesg.h"
40 #include "itemrepository.h"
41 #include "memorycheck.cpp"
42 #include "graphicset.h"
43 
44 
45 void loadcursor(void)
46 {
47  int w,i;
48 
49  {
50  tnfilestream stream ("hexfeld.raw", tnstream::reading);
51  stream.readrlepict ( &icons.fieldshape, false, &w );
52  }
53 
54  {
55  tnfilestream stream ("mapbkgrb.raw", tnstream::reading);
56  stream.readrlepict ( &icons.mapbackground, false, &w );
57  }
58 
59  {
60  tnfilestream stream ("hexfld_a.raw",tnstream::reading);
61  stream.readrlepict( &icons.stellplatz, false, &w);
62  }
63 
64  {
65  tnfilestream stream ("x.raw", tnstream::reading);
66  stream.readrlepict( &icons.X, false, &w);
67  }
68 
69  {
70  tnfilestream stream ("pfeil-a0.raw", tnstream::reading);
71  for (i=0;i<8 ;i++ ) stream.readrlepict( &icons.pfeil2[i], false, &w);
72  }
73 
74  loadpalette();
75  for (w=0;w<256 ;w++ ) {
76  palette16[w][0] = pal[w][0];
77  palette16[w][1] = pal[w][1];
78  palette16[w][2] = pal[w][2];
79  xlattables.nochange[w] = w;
80  } /* endfor */
81 
82  loadicons();
83  loadmessages();
84 
85 }
86 
87 
88 
89 
90 
91 void loaddata( void )
92 {
93  loadcursor();
94 
96 
97  loadallobjecttypes();
98 
99  loadallvehicletypes();
100 
101  loadallbuildingtypes();
102 
103  loadalltechnologies();
104 
105  loadstreets();
106 
107  loadallterraintypes();
108 
109  readBI3translationTable();
110 
111  loadUnitSets();
112 }
113 
114 
115 typedef vector<string> FilesToLoad;
117 
118 
119 pfont load_font(char* name)
120 {
121  tnfilestream stream ( name, tnstream::reading );
122  return loadfont ( &stream );
123 }
124 
125 string outputDir;
126 
127 
128 void process_BI_map ( const ASCString& filename )
129 {
130  string fn;
131  if ( filename.find ( "mis/" ) == filename.npos )
132  fn = "mis/"+filename;
133  else
134  fn = filename;
135 
136  tfindfile ff ( fn );
137  string s = ff.getnextname();
138  while ( !s.empty () ) {
139  string errormsg;
140  importbattleislemap ( outputDir.c_str(), s.c_str(), terrainTypeRepository.getObject_byPos(0)->weather[0], &errormsg, true );
141  if ( !errormsg.empty() && 0 )
142  fprintf(stderr, "map %s : %s \n", s.c_str(), errormsg.c_str() );
143  string fn = outputDir+"images/pcx/"+s;
144  fn.replace ( fn.find (".dat"), 4, ".pcx");
145 
146  int width, height;
147 
148  string t = outputDir+"mis/"+s;
149  int maptime = get_filetime ( t.c_str());
150  int pcxtime = get_filetime ( fn.c_str() );
151  if ( maptime > pcxtime || pcxtime < 0 )
152  writemaptopcx ( false, fn, &width, &height );
153  else {
154  tdisplaywholemap wm ( fn );
155  wm.init ( actmap->xsize, actmap->ysize );
156  width = wm.getWidth();
157  height = wm.getHeight();
158  }
159 
160  int playernum = 0;
161  int ainum = 0;
162  for ( int i = 0; i < 8; i++ )
163  if ( actmap->player[i].exist() ) {
164  if ( actmap->player[i].stat == 0 )
165  playernum++;
166  if ( actmap->player[i].stat == 1 )
167  ainum++;
168  }
169 
170 
171  printf("%sÁ%sÁ%dÁ%dÁ%dÁ%dÁ%dÁ%d\n", s.c_str(), actmap->maptitle.c_str(), actmap->xsize*2, actmap->ysize/2, width, height, playernum, ainum );
172 
173  s = ff.getnextname();
174 
175  delete actmap;
176  actmap = NULL;
177  }
178 }
179 
180 
181 void process_ASC_map ( const ASCString& filename )
182 {
183  string fn;
184  if ( filename.find ( "mis/" ) == filename.npos )
185  fn = "mis/"+filename;
186  else
187  fn = filename;
188 
189  tfindfile ff ( fn );
190  string s = ff.getnextname();
191  while ( !s.empty () ) {
192  try {
193  tmaploaders gl;
194  gl.loadmap ( s.c_str() );
195  }
196  catch ( ASCexception ) {
197  fprintf(stderr, "skipping map %s \n", s.c_str() );
198  s = ff.getnextname();
199  continue;
200  }
201 
202  activateGraphicSet ( actmap->graphicset );
203  string fn = outputDir+"images/pcx/"+s;
204  fn.replace ( fn.find (".map"), 4, ".pcx");
205 
206  int width, height;
207 
208  string t = outputDir+"mis/"+s;
209  int maptime = get_filetime ( t.c_str());
210  int pcxtime = get_filetime ( fn.c_str() );
211  if ( maptime > pcxtime || pcxtime < 0 )
212  writemaptopcx ( false, fn, &width, &height );
213  else {
214  tdisplaywholemap wm ( fn );
215  wm.init ( actmap->xsize, actmap->ysize );
216  width = wm.getWidth();
217  height = wm.getHeight();
218  }
219 
220  int playernum = 0;
221  int ainum = 0;
222  for ( int i = 0; i < 8; i++ )
223  if ( actmap->player[i].exist() ) {
224  if ( actmap->player[i].stat == 0 )
225  playernum++;
226  if ( actmap->player[i].stat == 1 )
227  ainum++;
228  }
229 
230  char datebuf[1000];
231  tm* tmbuf = gmtime ( &actmap->archivalInformation.modifytime );
232  strftime ( datebuf, 1000, "%Y-%m-%d", tmbuf );
233 
234  printf("%sÁ%sÁ%dÁ%dÁ%dÁ%dÁ%dÁ%dÁ%sÁ%sÁ%sÁ%sÁ%dÁ%s\n", s.c_str(), actmap->maptitle.c_str(), actmap->xsize, actmap->ysize, width, height, playernum, ainum, actmap->archivalInformation.author.c_str(), actmap->archivalInformation.description.c_str(),actmap->archivalInformation.requirements.c_str(),actmap->archivalInformation.tags.c_str(),actmap->_resourcemode,datebuf);
235 
236  s = ff.getnextname();
237 
238  delete actmap;
239  actmap = NULL;
240  }
241 }
242 
243 
244 
245 int mapeditorMainThread ( void* _mapname )
246 {
247  tvirtualdisplay buf ( 800, 600 );
248  initMapDisplay( );
249 
250  cursor.init();
251 
252  try {
253  loaddata();
254 
255  for ( FilesToLoad::iterator i = filesToLoad.begin(); i != filesToLoad.end(); i++ )
256  if ( patimat ( "*.dat", i->c_str() ))
257  process_BI_map( *i );
258  else
259  process_ASC_map ( *i );
260 
261  } /* end try */
262  catch ( tfileerror err ) {
263  displaymessage ( " error loading file %s ",2,err.getFileName().c_str() );
264  } /* end catch */
265 
266  return 0;
267 }
268 
269 
270 // including the command line parser, which is generated by genparse
271 #include "clparser/map2pcx.cpp"
272 
273 int main(int argc, char *argv[] )
274 {
275  Cmdline* cl = NULL;
276  auto_ptr<Cmdline> apcl ( cl );
277  try {
278  cl = new Cmdline ( argc, argv );
279  }
280  catch ( string s ) {
281  cerr << s.c_str();
282  exit(1);
283  }
284 
285  verbosity = cl->r();
286 
287  if ( cl->v() ) {
288  cout << argv[0] << " " << getVersionString() << endl;
289  exit(0);
290  }
291 
292  outputDir = cl->d();
293 
294  for ( int i = cl->next_param(); i < argc; i++ )
295  filesToLoad.push_back ( argv[i] );
296 
297 
298  if ( filesToLoad.empty() ) {
299  cerr << "no maps to load!\n";
300  return 1;
301  }
302 
303  addSearchPath ( "./") ;
304  initFileIO( cl->c().c_str() );
305 
306  check_bi3_dir ();
307 
308  setDefaultBI3ImportTranslationTable ("bi-bi.asctxt");
309 
310  schriften.smallarial = load_font("smalaril.FNT");
311  schriften.large = load_font("USABLACK.FNT");
312  schriften.arial8 = load_font("ARIAL8.FNT");
313  schriften.smallsystem = load_font("msystem.fnt");
314  schriften.monogui = load_font("monogui.fnt");
315 
317 
319 
320  return 0;
321 }
322 
void writemaptopcx(GameMap *gamemap, bool addview)
The (base-) classes which are thrown as exceptions.
Interface for loading and writing of PCX images.
int xsize
the size of the map
Definition: gamemap.h:201
vector< string > FilesToLoad
Definition: map2pcx.cpp:115
const ASCString & getFileName() const
Definition: simplestream.h:80
pfont monogui
Definition: spfst-legacy.h:34
FilesToLoad filesToLoad
Definition: map2pcx.cpp:116
void loadmessages(void)
loads all messages from the files message?.txt
int mapeditorMainThread(void *_mapname)
Definition: map2pcx.cpp:245
txlattables xlattables
Definition: palette.cpp:37
ASCString getnextname(int *loc=NULL, bool *inContainer=NULL, ASCString *location=NULL)
Returns the next entry of the internal file list.
Definition: basestrm.cpp:2211
Loading Battle Isle 3 maps. The central BI3 map loading class is a straight conversion of Joerg Richt...
void addSearchPath(const ASCString &path)
Definition: basestrm.cpp:2517
tvirtualscreenbuf virtualscreenbuf
Definition: dlg_box.cpp:101
Includefile (!) for heap tracking.
virtual void readrlepict(void **pnter, bool allocated, int *size)
Writes an RLE compressed or uncompressed image from the stream.
Definition: basestrm.cpp:202
int main(int argc, char *argv[])
Definition: map2pcx.cpp:273
class GameMap::ArchivalInformation archivalInformation
pfont arial8
Definition: spfst-legacy.h:31
pfont smallarial
Definition: spfst-legacy.h:28
A system that provides a set of images for vehicles, buildings, etc.
static GameMap * loadmap(const ASCString &name)
Definition: loaders.cpp:1039
A virtual screen is allocated and the agmp pointer set to it.
Definition: basegfx.h:312
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
string outputDir
Definition: map2pcx.cpp:125
Schriften schriften
Definition: spfst.cpp:66
tpixelxlattable nochange
Definition: palette.h:81
int graphicset
the ID of the graphic set
Definition: gamemap.h:424
ItemRepositoryLoader< TerrainType > terrainTypeRepository("terraintype")
enum Player::PlayerStatus stat
pfont smallsystem
Definition: spfst-legacy.h:29
void displaymessage(const char *formatstring, int num,...)
displays a dialog box with a message
Definition: dlg_box.cpp:1849
void process_BI_map(const ASCString &filename)
Definition: map2pcx.cpp:128
Searching for files.
Definition: basestrm.h:484
void init(void)
Definition: dlg_box.cpp:110
pfont loadfont(tnstream *stream)
Definition: newfont.cpp:107
int _resourcemode
how are Resources handled on this map 0= "ASC mode": complex system with mineral resources etc 1= "BI...
Definition: gamemap.h:250
void loadcursor(void)
Definition: map2pcx.cpp:45
pfont load_font(char *name)
Definition: map2pcx.cpp:119
int initializeEventHandling(int(*fn)(void *), void *data)
Definition: events.cpp:560
Player player[9]
Definition: gamemap.h:253
void loaddata(void)
Definition: map2pcx.cpp:91
int ysize
Definition: gamemap.h:201
dacpalette256 pal
Definition: palette.cpp:33
void loadpalette(void)
Definition: sgstream.cpp:67
Interface for all the dialog boxes used by the game and the mapeditor.
ASCString maptitle
the title of the map
Definition: gamemap.h:213
pfont large
Definition: spfst-legacy.h:30
time_t get_filetime(const char *fileName)
Definition: basestrm.cpp:2468
void loadUnitSets(void)
Definition: unitset.cpp:190
procedure for loading and writing savegames, maps etc.
GameMap * actmap
Definition: spfst.cpp:64
void process_ASC_map(const ASCString &filename)
Definition: map2pcx.cpp:181
void initFileIO(const ASCString &configFileName, int skipChecks)
Definition: sgstream.cpp:475
bool patimat(const char *pat, const char *str, bool forceCaseInsensitivity)
Definition: basestrm.cpp:1997
void loadalltextfiles()
const char * getVersionString()
Definition: strtmesg.cpp:32
void setDefaultBI3ImportTranslationTable(const ASCString &filename)
to prevent the appearnce of the dialog "choose import translation table" when running in batch mode...
Definition: loadbi3.cpp:1659
bool exist() const
does the player exist at all
Definition: player.cpp:313
void importbattleislemap(const ASCString &path, const ASCString &mapfilename, TerrainType::Weather *trrn, const ASCString &importTable, ASCString *errorOutput, bool fakemap)
Imports a Battle Isle map.
Definition: loadbi3.cpp:1666
Definition: newfont.h:150