Advanced Strategic Command
loaders.cpp
Go to the documentation of this file.
1 
8 /*
9  This file is part of Advanced Strategic Command; http://www.asc-hq.de
10  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
11 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; see the file COPYING. If not, write to the
24  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
25  Boston, MA 02111-1307 USA
26 */
27 
28 #include <algorithm>
29 #include <cstring>
30 #include <stdlib.h>
31 #include <stdio.h>
32 
33 #include "typen.h"
34 #include "misc.h"
35 #include "buildingtype.h"
36 #include "vehicletype.h"
37 #include "spfst.h"
38 #include "loaders.h"
39 #include "dlg_box.h"
40 #include "dlg_box.h"
41 #include "dialog.h"
42 #include "sgstream.h"
43 #include "attack.h"
44 #include "errors.h"
45 #include "strtmesg.h"
46 #include "textfileparser.h"
47 #include "itemrepository.h"
48 #include "prehistoricevents.h"
49 #include "gamemap.h"
50 #include "gameeventsystem.h"
51 #include "graphicset.h"
52 #include "gameoptions.h"
53 #include "lua/luarunner.h"
54 #include "lua/luastate.h"
55 #include "packagemanager.h"
56 #include "i18n.h"
57 #include "mapimageexport.h"
58 
59 #ifdef sgmain
60 # include "ai/ai.h"
61 #endif
62 
63 
64 
65 const int actsavegameversion = 0xff63;
66 const int minsavegameversion = 0xff31;
67 const int actmapversion = 0xfe51;
68 const int minmapversion = 0xfe24;
69 const int actnetworkversion = 0x0032;
70 const int minnetworkversion = 0x0004;
71 const int actreplayversion = 0x0003;
72 const int minreplayversion = 0x0001;
73 
74 
75 const int fileterminator = 0xa01a;
76 
77 
78 const char* savegameextension = "*.sav";
79 const char* mapextension = "*.map";
80 const char* tournamentextension = ".ascpbm";
81 
83 
85 {
87  for ( GameMap::Events::iterator i = actmap->events.begin(); i != actmap->events.end(); ++i )
88  (*i)->arm();
89 
90  for ( int i = 0; i < 8; i++ )
91  actmap->player[i].queuedEvents = 1;
92 }
93 
94 
95 
96 #define csm_typid32 1 /* b1 */
97 #define csm_direction 2 /* b1 */
98 #define csm_vehicle 4 /* b1 */
99 #define csm_building 8 /* b1 */
100 #define csm_height 32 /* b1 */
101 #define csm_cnt2 64 /* b1 */
102 #define csm_b3 128 /* b1 */
103 
104 #define csm_material 1 /* b3 */
105 #define csm_fuel 2 /* b3 */
106 #define csm_visible 4 /* b3 */
107 #define csm_weather 16 /* b3 */
108 #define csm_object 64 /* b3 */
109 #define csm_b4 128 /* b3 */
110 
111 #define csm_resources 1 /* b4 */
112 #define csm_connection 2 // b4
113 #define csm_newobject 4 // b4
114 
115 
116 
117 
118 
119 
120 
121 /**************************************************************/
122 /* sezierungen schreiben / lesen */
123 /**************************************************************/
124 
125 
127 {
128  for (int i = 0; i < 8; i ++ ) {
129  if ( spfld->player[ i ].__dissectionsToLoad ) {
130  int k;
131  do {
133  stream->readInt(); // dummy;
134  stream->readInt(); // dummy;
135 
136  du.orgpoints = stream->readInt();
137  du.points = stream->readInt();
138  du.num = stream->readInt();
139 
140  k = stream->readInt();
141 
142  int j = stream->readInt();
143  du.fzt = vehicleTypeRepository.getObject_byID ( j );
144  if ( !du.fzt )
145  throw InvalidID ( "vehicle", j );
146 
147  j = stream->readInt();
148  du.tech = technologyRepository.getObject_byID ( j );
149  if ( !du.tech )
150  throw InvalidID ( "technology", j );
151 
152  spfld->player[ i ].dissections.push_back ( du );
153  } while ( k );
154  }
155  } /* endfor */
156 }
157 
159 {
160  for (int i = 0; i < 8; i ++ ) {
161  Player::DissectionContainer::iterator di = spfld->player[i].dissections.begin();
162  while ( di != spfld->player[i].dissections.end() ) {
163  stream->writeInt ( 1 ); // dummy
164  stream->writeInt ( 1 ); // dummy
165  stream->writeInt ( di->orgpoints );
166  stream->writeInt ( di->points );
167  stream->writeInt ( di->num );
168 
169  di++;
170  if ( di != spfld->player[i].dissections.end() )
171  stream->writeInt ( 1 );
172  else
173  stream->writeInt ( 0 );
174 
175  stream->writeInt ( di->fzt->id );
176  stream->writeInt ( di->tech->id );
177  }
178  }
179 }
180 
181 
182 
183 /**************************************************************/
184 /* Messages schreiben / lesen */
185 /**************************************************************/
186 
187 const int messageVersion = 0xabcdf1;
188 const int messageMinVersion = 0xabcdef;
189 
191 {
193 
194  int id = 0;
195  for ( MessageContainer::iterator mi = spfld->messages.begin(); mi != spfld->messages.end(); ) {
196  id++;
197  (*mi)->id = id;
198 
199  stream->writeInt ( (*mi)->from );
200  stream->writeInt ( (*mi)->to );
201  stream->writeInt ( (*mi)->cc );
202  stream->writeInt ( (unsigned int) (*mi)->time );
203  stream->writeInt ( 1 );
204  stream->writeInt ( (*mi)->id );
205  stream->writeInt ( (*mi)->gametime.turn() );
206  stream->writeInt ( (*mi)->gametime.move() );
207  stream->writeInt( (*mi)->reminder );
208 
209 
210  ASCString& t = (*mi)->text;
211 
212  mi++;
213  stream->writeInt ( mi != spfld->messages.end() ? 1 : 0 );
214 
215  stream->writeString ( t );
216  }
217 
218  for ( int i = 0; i < 8; i++ )
220 
221  for ( int i = 0; i < 8; i++ )
223 
224  for ( int i = 0; i < 8; i++ )
226 
228 
230 
233 }
234 
235 
237 {
238  for ( MessagePntrContainer::iterator i = lst.begin(); i != lst.end(); i++ )
239  stream->writeInt ( (*i)->id );
240  stream->writeInt ( 0 );
241 }
242 
243 
244 /*
245 class MessageIDequals : public unary_function<Message*,bool>{
246  int id;
247  public:
248  MessageIDequals ( int _id ) { id == _id; };
249  bool operator() ( const Message* m ) { return m->id == id; };
250 };
251 */
252 
254 {
255  int i = stream->readInt();
256 
257  while ( i ) {
258  // MessageContainer::iterator mi = find ( spfld->messages.begin(), spfld->messages.end(), MessageIDequals ( i ));
259  MessageContainer::iterator mi = spfld->messages.end();
260  for ( MessageContainer::iterator mi2 = spfld->messages.begin(); mi2 != spfld->messages.end(); mi2++ )
261  if ( (*mi2)->id == i )
262  mi = mi2;
263 
264  if ( mi == spfld->messages.end())
265  warningMessage( "message list corrupted !\nplease report this bug!\nthe game will continue, but some messages will probably be missing\nand other instabilities may occur.");
266  lst.push_back ( *mi );
267  i = stream->readInt();
268  }
269 }
270 
271 
273 {
274  int magic = stream->readInt();
275  assertOrThrow( magic >= messageMinVersion && magic <= messageVersion );
276 
277  while ( spfld->__loadmessages ) {
278  Message* msg = new Message ( spfld );
279 
280  msg->from = stream->readInt();
281  msg->to = stream->readInt();
282  if ( magic >= 0xabcdf0 )
283  msg->cc = stream->readInt();
284  else
285  msg->cc = 0;
286 
287  msg->time = stream->readInt();
288  bool msgtext = stream->readInt();
289  msg->id = stream->readInt();
290  int t = stream->readInt();
291  int m = stream->readInt();
292  msg->gametime.set ( t, m );
293 
294  if ( magic >= 0xabcdf1 )
295  msg->reminder = stream->readInt();
296  else
297  msg->reminder = false;
298 
300 
301  if ( msgtext )
302  msg->text = stream->readString( true );
303 
304  }
305 
306  for ( int i = 0; i < 8; i++ )
307  if ( spfld->player[ i ].__loadoldmessage )
309 
310  for ( int i = 0; i < 8; i++ )
311  if ( spfld->player[ i ].__loadunreadmessage )
313 
314  for ( int i = 0; i < 8; i++ )
315  if ( spfld->player[ i ].__loadsentmessage )
317 
318  if ( spfld->__loadunsentmessage )
320 
321  stream->readInt(); // magic
322 
323  if ( spfld->___loadJournal )
325 
326  if ( spfld->___loadNewJournal )
328 }
329 
330 
331 
332 
333 
334 
336 {
337  if ( spfld->loadOldEvents ) {
338  int num = stream->readInt();
339  while ( num ) {
340  for ( int i = 0; i < num; i++ )
341  stream->readInt();
342  for ( int i = 0; i < num; i++ )
343  stream->readInt();
344 
345  num = stream->readInt();
346  }
347  }
348 }
349 
351 {
352  map<int,int> units;
353  for ( int p = 0; p < gamemap->getPlayerCount(); ++p )
354  for ( Player::VehicleList::iterator i = gamemap->getPlayer(p).vehicleList.begin(); i != gamemap->getPlayer(p).vehicleList.end(); ++i )
355  if ( units[(*i)->networkid]++ > 0 ) {
356  warningMessage("unit with duplicate network ids: " + ASCString::toString( (*i)->networkid ) + "\nThis will lead to replay errors during the next turn." );
357  (*i)->networkid = gamemap->idManager.getNewNetworkID();;
358  }
359 }
360 
361 /**************************************************************/
362 /* map schreiben / lesen / initialisieren */
363 /**************************************************************/
364 
366 {
368  if ( !spfld )
369  displaymessage ( "tspfldloaders::writemap ; no map to write ! ",2);
370 
371  spfld->write ( *stream );
372 }
373 
374 
375 void tmaploaders::initmap ( void )
376 {
377  spfld->game_parameter = NULL;
378 }
379 
380 
382 {
383  spfld->game_parameter = NULL;
384 }
385 
386 
388 {
389  spfld = new GameMap;
390 
391  spfld->read ( *stream );
392 }
393 
394 
395 
397 {
398 #ifdef sgmain
399  int a = 0;
400  for ( int i = 0; i< 8; i++ )
401  if ( spfld->player[i].ai )
402  a += 1 << i;
403 
404  stream->writeInt ( a );
405 
406  for ( int i = 0; i < 8; i++ )
407  if ( spfld->player[i].ai )
408  spfld->player[i].ai->write( *stream );
409 #else
410  stream->writeInt(0);
411 #endif
412 }
413 
415 {
416 #ifdef sgmain
417  int a = stream->readInt();
418  for ( int i = 0; i< 8; i++ )
419  if ( a & ( 1 << i ) ) {
420  AI* ai = new AI ( spfld, i );
421  ai->read ( *stream );
422  spfld->player[i].ai = ai;
423  } else {
424  spfld->player[i].ai = NULL;
425  }
426 #else
427  for ( int i = 0; i< 9; i++ )
428  spfld->player[i].ai = NULL;
429 #endif
430 }
431 
432 
433 /**************************************************************/
434 /* Network schreiben / lesen */
435 /**************************************************************/
436 
437 extern void readLegacyNetworkData ( tnstream& stream );
438 
439 
441 {
444 }
445 
446 
447 
448 
449 /**************************************************************/
450 /* fielder schreiben / lesen */
451 /**************************************************************/
452 
453 const int objectstreamversion = 4;
454 
456 {
457  int l = 0;
458  int cnt1 = spfld->xsize * spfld->ysize;
459  int cnt2;
460 
461  do {
462  cnt2 = 0;
463  MapField* fld = &spfld->field[l];
464  /*
465 
466  RLE encoding not supported any more, since tfield is becomming too complex
467 
468  if (l + 2 < cnt1) {
469  l2 = l + 1;
470  fld2 = &spfld->field[l2];
471  asfasfdasfd
472  while ((l2 + 2 < cnt1) && ( memcmp(fld2, fld, sizeof(*fld2)) == 0) ) {
473  cnt2++;
474  l2++;
475  fld2 = &spfld->field[l2];
476  }
477  }
478  */
479 
480 
481  Uint8 b1 = 0;
482  Uint8 b3 = 0;
483  Uint8 b4 = 0;
484 
485  if (fld->typ->terraintype->id > 255)
486  b1 |= csm_typid32;
487  if (fld->vehicle != NULL)
488  b1 |= csm_vehicle;
489  if ( (fld->bdt & getTerrainBitType( cbbuildingentry )).any() )
490  b1 |= csm_building;
491 
492 
493  if (cnt2 > 0)
494  b1 |= csm_cnt2;
495 
496  if (fld->material > 0)
497  b3 |= csm_material;
498  if (fld->fuel > 0)
499  b3 |= csm_fuel;
500 
501  if (fld->typ != fld->typ->terraintype->weather[0])
502  b3 |= csm_weather;
503  if (fld->visible)
504  b3 |= csm_visible;
505  if ( !fld->objects.empty() || !fld->mines.empty() )
506  b4 |= csm_newobject;
507 
508  if ( fld->resourceview )
509  b4 |= csm_resources;
510 
511  if ( fld->connection )
512  b4 |= csm_connection;
513 
514  if ( b4 )
515  b3 |= csm_b4;
516 
517  if ( b3 )
518  b1 |= csm_b3;
519 
520  stream->writeUint8( b1 );
521 
522  if (b1 & csm_b3 )
523  stream->writeUint8 ( b3 );
524 
525  if (b3 & csm_b4 )
526  stream->writeUint8 ( b4 );
527 
528  if (b1 & csm_cnt2 )
529  stream->writeInt ( cnt2 );
530 
531  if (b3 & csm_weather ) {
532  int k = 1;
533  while ( fld->typ != fld->typ->terraintype->weather[k] && k < cwettertypennum ) {
534  k++;
535  } /* endwhile */
536 
537  if ( k == cwettertypennum ) {
538  k = 0;
539  displaymessage ( "invalid terrain ( weather not found ) at position %d \n",1,l );
540  }
541  stream->writeInt ( k );
542  }
543 
544  if (b1 & csm_typid32 )
545  stream->writeInt ( fld->typ->terraintype->id );
546  else
547  stream->writeUint8 ( fld->typ->terraintype->id );
548 
549  if (b1 & csm_vehicle )
550  fld->vehicle->write ( *stream );
551 
552 
553  if (b1 & csm_building )
554  fld->building->write ( *stream );
555 
556  if (b3 & csm_material )
557  stream->writeUint8 ( fld->material );
558 
559  if (b3 & csm_fuel )
560  stream->writeUint8 ( fld->fuel );
561 
562  if (b3 & csm_visible )
563  stream->writeWord ( fld->visible );
564 
565  if ( b4 & csm_newobject ) {
567 
568  stream->writeInt ( fld->mines.size() );
569  for ( MapField::MineContainer::iterator m = fld->mines.begin(); m != fld->mines.end(); m++ ) {
570  stream->writeInt ( m->type );
571  stream->writeInt ( m->strength );
572  stream->writeInt ( m->lifetimer );
573  stream->writeInt ( m->player );
574  stream->writeInt ( m->identifier );
575  }
576 
577  stream->writeInt ( fld->objects.size() );
578 
579  for ( MapField::ObjectContainer::iterator o = fld->objects.begin(); o != fld->objects.end(); o++ ) {
580  stream->writeInt ( 1 ); // was: pointer to type
581  stream->writeInt ( o->damage );
582  stream->writeInt ( o->dir );
583  stream->writeInt ( o->lifetimer );
584  for ( int i = 0; i < 4; i++ )
585  stream->writeInt ( 0 ); // dummy
586  stream->writeInt ( o->typ->id );
587  stream->writeInt( o->remainingGrowthTime );
588  }
589  }
590 
591  if (b4 & csm_resources ) {
593  for ( int i = 0; i < 8; i++ )
595  for ( int i = 0; i < 8; i++ )
597  }
598 
599  if ( b4 & csm_connection )
600  stream->writeInt ( fld->connection );
601 
602  l += 1 + cnt2;
603  } while (l < cnt1);
604 }
605 
606 
607 
608 
609 
611 {
612  int cnt2 = 0;
613  int cnt1 = spfld->xsize * spfld->ysize;
614 
615  assertOrThrow( cnt1 > 0 );
616  assertOrThrow( spfld->xsize > 0 );
617  assertOrThrow( spfld->ysize > 0 );
618 
620 
621  if (spfld->field == NULL)
622  displaymessage ( "Could not allocate memory for map ",2);
623 
624  int l = 0;
625  MapField* lfld = NULL;
626 
627  do {
628  MapField* fld2;
629 
630  if (cnt2 == 0) {
631 
632  fld2 = & spfld->field[l];
633 
634  fld2->bdt.setInt ( 0 , 0 );
635 
636  Uint8 b1, b3, b4;
637  b1 = stream->readUint8();
638 
639  if (b1 & csm_b3 )
640  b3 = stream->readUint8();
641  else
642  b3 = 0;
643 
644  if (b3 & csm_b4 )
645  b4 = stream->readUint8();
646  else
647  b4 = 0;
648 
649  if (b1 & csm_cnt2 )
650  cnt2 = stream->readInt();
651  else
652  cnt2 = 0;
653 
654  int weather;
655  if (b3 & csm_weather )
656  weather = stream->readInt();
657  else
658  weather = 0;
659 
660  assertOrThrow( weather >= 0 && weather < cwettertypennum );
661 
662  int k;
663 
664  if (b1 & csm_typid32 )
665  k = stream->readInt();
666  else
667  k = stream->readUint8();
668 
669  pterraintype trn = terrainTypeRepository.getObject_byID ( k );
670  if ( !trn )
671  throw InvalidID ( "terrain", k );
672 
673  fld2->typ = trn->weather[weather];
674  if ( !fld2->typ ) {
675  fld2->typ = trn->weather[0];
676  if ( !fld2->typ )
677  throw InvalidID ( "terrain", k );
678  }
679 
680  if (b1 & csm_direction )
681  stream->readUint8(); // fld2->direction = 0;
682 
683 
684  if (b1 & csm_vehicle ) {
686  fld2->vehicle->setnewposition ( l%spfld->xsize, l/spfld->xsize );
687  if ( fld2->vehicle->getOwner() == 8 ) // neutral units are not allowed, it was a bug that they could be placed on some maps
688  delete fld2->vehicle;
689  }
690 
691  if (b1 & csm_building ) {
694  }
695 
696  if (b3 & csm_material)
697  fld2->material = stream->readUint8();
698  else
699  fld2->material = 0;
700 
701  if (b3 & csm_fuel)
702  fld2->fuel = stream->readUint8();
703  else
704  fld2->fuel = 0;
705 
706  if (b3 & csm_visible)
707  fld2->visible = stream->readWord();
708  else
709  fld2->visible = 0;
710 
711  int tempobjectNum = 0;
712 
713  if (b3 & csm_object ) {
714 
715  Uint8 minetype = stream->readUint8();
716  Uint8 minestrength = stream->readUint8();
717  if ( minetype >> 4 ) {
718  Mine m( MineTypes((minetype >> 1) & 7), minestrength, minetype >> 4, spfld );
719  fld2->mines.push_back ( m );
720  }
721 
722  tempobjectNum = stream->readInt();
723 
724  for ( int i = 0; i < 16; i++ )
725  stream->readInt();
726  }
727 
728  int objectversion = 1;
729  if ( b4 & csm_newobject ) {
730  objectversion = stream->readInt();
731 
732  if ( objectversion < 1 || objectversion > objectstreamversion )
733  throw tinvalidversion ( "object", objectstreamversion, objectversion );
734 
735  int minenum = stream->readInt();
736 
737  for ( int i = 0; i < minenum; i++ ) {
738  MineTypes type = MineTypes(stream->readInt());
739  int strength = stream->readInt();
740  int minetime = stream->readInt();
741  int player = stream->readInt();
742  if ( player < 0 || player > 7 )
743  player = 0;
744 
745  assertOrThrow( strength >= 0 );
746  assertOrThrow( type > 0 && type <= 4 );
747 
748  int id;
749  if ( objectversion >= 4 )
750  id = stream->readInt();
751  else
753 
754  Mine m ( type, strength, player, spfld, id );
755  if ( objectversion == 1 ) {
756  int endtime = minetime;
758  if ( lifetime > 0 && endtime > 0 )
760  else if ( lifetime > 0 )
761  m.lifetimer = lifetime;
762  else
763  m.lifetimer = -1;
764  } else
765  m.lifetimer = minetime;
766  fld2->mines.push_back ( m );
767  }
768 
769  tempobjectNum = stream->readInt();
770  }
771 
772  if ( (b3 & csm_object) || (b4 & csm_newobject )) {
773  for ( int n = 0; n < tempobjectNum; n++ ) {
774  Object o;
775  stream->readInt(); // was: type
776  o.damage = stream->readInt();
777  assertOrThrow( o.damage >= 0 );
778  o.dir = stream->readInt();
779  if ( objectversion >= 2 )
780  o.lifetimer = stream->readInt();
781  else
782  stream->readInt();
783 
784  for ( int i = 0; i < 4; i++ )
785  stream->readInt(); // dummy
786 
787  int id = stream->readInt();
788  o.typ = objectTypeRepository.getObject_byID ( id );
789 
790  if ( !o.typ )
791  throw InvalidID ( "object", id );
792 
793  if ( objectversion >= 3 )
795 
796  if ( objectversion == 1 )
797  o.lifetimer = o.typ->lifetime;
798 
799 
800  fld2->objects.push_back ( o );
801  }
802  fld2->sortobjects();
803  }
804 
805  if (b4 & csm_resources ) {
807  fld2->resourceview->visible = stream->readUint8();
808  for ( int i = 0; i < 8; i++ )
809  fld2->resourceview->fuelvisible[i] = stream->readUint8();
810  for ( int i = 0; i < 8; i++ )
812  }
813 
814  if ( b4 & csm_connection )
815  fld2->connection = stream->readInt();
816 
817  if (b1 & csm_cnt2 )
818  lfld = fld2;
819 
820  } else {
821  spfld->field[l].typ = lfld->typ;
822  spfld->field[l].fuel = lfld->material;
823  spfld->field[l].visible = lfld->visible;
824  spfld->field[l].setTempw(0);
825  spfld->field[l].connection = lfld->connection;
826  for ( int i = 0; i < 8; i++ )
827  spfld->field[l].view[i] = lfld->view[i];
828  cnt2--;
829  }
830  l++ ;
831  } while (l < cnt1);
832 
834 
835 }
836 
837 
838 
839 /**************************************************************/
840 /* Chain Items */
841 /**************************************************************/
842 
844 {
845  int i = 0;
846  for (int y = 0; y < actmap->ysize; y++)
847  for (int x = 0; x < actmap->xsize; x++) {
848  MapField* fld = &actmap->field[i];
849  fld->setparams();
850  i++;
851  }
852 }
853 
854 
855 
856 /**************************************************************/
857 /* Set Player Existencies */
858 /**************************************************************/
859 
860 sigc::signal<void,GameMap*> tspfldloaders::mapLoaded;
861 
862 
864 {
865  spfld = NULL;
866 }
867 
868 
870 {
871  delete spfld;
872  spfld = NULL;
873 }
874 
875 
876 
877 
878 
879 
880 
881 
882 
883 
884 
885 
886 
887 
888 
889 
890 
891 
892 int tmaploaders::savemap( const ASCString& name, GameMap* gamemap )
893 {
894 #ifdef logging
895  logtofile ( "loaders / tmaploaders::savemap / started " );
896 #endif
897 
898  tnfilestream filestream ( name, tnstream::writing );
899 
900  stream = &filestream;
901 
902  spfld = gamemap;
903 
904 
905  /********************************************************************************/
906  /* Stream initialisieren, Dateiinfo schreiben , map schreiben */
907  /********************************************************************************/
908  {
909  stream->writepchar ( getFullVersionString() ); // description is not used any more
912 
913  writemap ( );
914  }
915 
916  writefields ();
917 #ifdef WEATHERGENERATOR
918  spfld->weatherSystem->write(filestream);
919 #endif
921 
922  spfld = NULL;
923 
924  return 0;
925 }
926 
927 
928 
930 {
931  throw ASCmsgException( "This file can not be loaded, since it contains data of the discontinued weather generator");
932 }
933 
934 
935 GameMap* tmaploaders::_loadmap( const ASCString& name )
936 {
937  displayLogMessage ( 4, "loading map %s ... ", name.c_str() );
938 
939  tnfilestream filestream ( name, tnstream::reading);
940 
941  stream = &filestream;
942 
943  char* description = NULL;
944 
945  stream->readpchar ( &description );
946  delete[] description;
947 
948  int w = stream->readWord();
949 
950  if ( w != fileterminator )
951  throw tinvalidversion ( name, fileterminator, w );
952 
953 
954  int version = stream->readInt();
955 
956  if ( version > actmapversion || version < minmapversion )
957  throw tinvalidversion ( name, actmapversion, version );
958 
959 
960  displayLogMessage ( 8, "map, ");
961  readmap ();
962 
963  if ( version <= 0xfe27 ) {
964  displayLogMessage ( 8, "eventsToCome, ");
965  readOldEventLists ( stream, false, spfld );
966  }
967 
968  displayLogMessage ( 8, "fields, ");
969  readfields ();
970 
971 
972  if(version == 0xfe50)
974 
975  version = stream->readInt();
976  if (version > actmapversion || version < minmapversion )
977  throw tinvalidversion ( name, actmapversion, version );
978 
979 
980  displayLogMessage ( 8, "chainItems, ");
981  chainitems ( spfld );
982 
983  for ( int sp = spfld->getPlayerCount()-1; sp >= 0; sp--)
984  if ( spfld->player[sp].exist() )
985  spfld->actplayer = sp;
986 
987  displayLogMessage ( 8, "setEventTriggers, ");
989 
990  displayLogMessage ( 8, "calculateallobjects ");
992 
993 
994  displayLogMessage ( 8, "init for playing, ");
995 
996  spfld->time.set ( 1, 0 );
997  spfld->levelfinished = false;
998  spfld->preferredFileNames.mapname[0] = name ;
1000  spfld->startGame();
1001 
1002  displayLogMessage ( 4, "done\n");
1003 
1004  GameMap* m = spfld;
1005  spfld = NULL;
1006 
1007  mapLoaded( m );
1008 
1009  return m;
1010 }
1011 
1012 
1014 
1015 
1016 
1017 void loadLocalizedMessageFile( GameMap* map, const ASCString& filename )
1018 {
1019  eventLocalizationMap = map;
1020 
1021  LuaState state;
1022  LuaRunner runner( state );
1023  runner.runFile( filename );
1024  if ( !runner.getErrors().empty() )
1025  errorMessage( runner.getErrors() );
1026 
1027  eventLocalizationMap = NULL;
1028 }
1029 
1030 void loadLocalizedMessages( GameMap* map, const ASCString& name )
1031 {
1032  Locale locale;
1033  ASCString filename = locale.getLocalizedFile( name );
1034  if( !filename.empty() && exist( filename ) )
1035  loadLocalizedMessageFile( map, filename );
1036 
1037 }
1038 
1040 {
1041  tmaploaders gl;
1042  GameMap* map = gl._loadmap ( name );
1043 #ifdef sgmain
1044  loadLocalizedMessages( map, name );
1045 #endif
1046  return map;
1047 }
1048 
1049 
1050 
1051 
1052 
1053 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1054  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1055  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1056 
1057 
1058 
1059 
1060 void tsavegameloaders::savegame( tnstream* strm, GameMap* gamemap, bool writeReplays )
1061 {
1062  PackageManager::storeData( gamemap );
1063 
1064  stream = strm;
1065  spfld = gamemap;
1066 
1069 
1071 
1072  //An Image of the Map will now be saved to the file.
1073  writemaptostream( spfld , 100, 100, *stream);
1074 
1075  stream->writeString( gamemap->maptitle );
1076  stream->writeString( gamemap->getCurrentPlayer().getName() );
1077  stream->writeInt( gamemap->time.turn() );
1078 
1079  writemap ();
1080 
1081  writemessages();
1082 
1083  writefields ( );
1084 
1085  writedissections();
1086 
1087  if ( writeReplays && spfld->replayinfo ) {
1088  stream->writeInt( 1 );
1090  } else
1091  stream->writeInt( 0 );
1092 
1093  writeAI();
1094 
1095 
1096 
1098 
1099  spfld = NULL;
1100 }
1101 
1102 
1103 void tsavegameloaders::savegame( GameMap* gamemap, const ASCString& name)
1104 {
1105  tnfilestream filestream ( name, tnstream::writing );
1106  savegame ( &filestream, gamemap, true );
1107 }
1108 
1110 {
1111  GameFileInformation gfi;
1112  try {
1113  tnfilestream stream( filename, tnstream::reading );
1114 
1115  stream.readString(); // was: description
1116 
1117  int w = stream.readWord();
1118 
1119  if ( w != fileterminator )
1120  throw tinvalidversion ( stream.getDeviceName(), fileterminator, w );
1121 
1122  int version = stream.readInt();
1123 
1124  if ( version >= 0xff63 ) {
1125  gfi.image = loadmapfromstream( stream );
1126  gfi.maptitle = stream.readString();
1127  gfi.playername = stream.readString();
1128  gfi.turn = stream.readInt();
1129  }
1130  } catch(...) {
1131  }
1132  return gfi;
1133 }
1134 
1136 {
1137  tnfilestream filestream( filename, tnstream::reading );
1138  tsavegameloaders gl;
1139  return gl.loadgame( &filestream );
1140 }
1141 
1143 {
1144  stream = strm;
1145 
1146  stream->readString(); // was: description
1147 
1148  int w = stream->readWord();
1149 
1150  if ( w != fileterminator )
1151  throw tinvalidversion ( strm->getDeviceName(), fileterminator, w );
1152 
1153  int version = stream->readInt();
1154 
1155  if (version > actsavegameversion || version < minsavegameversion )
1156  throw tinvalidversion ( strm->getDeviceName(), actsavegameversion, version );
1157 
1158  if ( version >= 0xff62 ) {
1159  // ignoring the map image
1161  }
1162 
1163  if ( version >= 0xff63 ) {
1164  // ignoring the map information
1165  stream->readString();
1166  stream->readString();
1167  stream->readInt();
1168  }
1169 
1170  readmap ();
1171 
1172  readLegacyNetwork ();
1173 
1174  if ( version <= 0xff39 )
1175  for ( int i = 0; i < 8; i++ )
1177 
1178  readmessages();
1179 
1180  if ( version <= 0xff37 ) {
1181  readOldEventLists ( stream, true, spfld );
1182  readoldevents ();
1183  }
1184 
1185  readfields ( );
1186 
1187  if(version == 0xff60)
1189 
1190  readdissections();
1191 
1192  bool loadReplay = true;
1193  if ( version >= 0xff35 )
1194  if ( !stream->readInt() )
1195  loadReplay = false;
1196 
1197  if ( loadReplay ) {
1199  spfld->replayinfo->read ( *stream );
1200  } else
1201  spfld->replayinfo = NULL;
1202 
1203 
1204  if ( version >= 0xff34 )
1205  readAI ();
1206 
1207  version = stream->readInt();
1208  if (version > actsavegameversion || version < minsavegameversion )
1209  throw tinvalidversion ( strm->getDeviceName(), actsavegameversion, version );
1210 
1211  chainitems ( spfld );
1212 
1214 
1217 
1218  mapLoaded( spfld );
1219 
1220 
1221  GameMap* s = spfld;
1222  spfld = NULL; // to avoid that is is deleted by the destructor of tsavegameloaders
1223  return s;
1224 }
1225 
1226 
1227 
1228 /*****************************************************************************************************/
1229 /* Netzwerk */
1230 /*****************************************************************************************************/
1231 
1232 
1233 
1234 
1235 int tnetworkloaders::savenwgame( tnstream* strm, const GameMap* gamemap )
1236 {
1237 
1238  PackageManager::storeData( gamemap );
1239 
1240  spfld = const_cast<GameMap*>(gamemap); // yes, this is bad, but spfld can't be made constant because it is also used for loading
1241 
1242  stream = strm;
1243 
1244  stream->writepchar ( getFullVersionString() ); // description is not used any more
1246 
1248 
1249  writemap ();
1250 
1251  writemessages();
1252 
1254 
1255  writefields ( );
1256 
1257  writedissections();
1258 
1259  if ( spfld->replayinfo )
1260  spfld->replayinfo->write ( *stream );
1261 
1262  // the AI must be the last data of the file
1263  writeAI();
1264 
1266 
1267  spfld = NULL;
1268 
1269  return 0;
1270 }
1271 
1272 
1273 
1274 
1275 
1277 {
1278  const char* name = "network game";
1279 
1280  stream = strm;
1281 
1282 
1283  char* description = NULL;
1284  stream->readpchar ( &description );
1285  delete[] description;
1286 
1287  int w = stream->readWord();
1288 
1289  if ( w != fileterminator )
1290  throw tinvalidversion ( name, fileterminator, (int) w );
1291 
1292 
1293  int version = stream->readInt();
1294 
1295  if (version > actnetworkversion || version < minnetworkversion )
1296  throw tinvalidversion ( name, actnetworkversion, version );
1297 
1298  readmap ();
1299 
1300  if ( version <= 0x11 )
1301  for ( int i = 0; i < 8; i++ )
1303 
1304 
1305  //NEW SaveData Weather
1306  if(version == 0x0030)
1308 
1309  /*if(version > 0xfe28){ //Vielleicht minus 1
1310  actmap->weatherSystem->read(*stream);
1311  }*/
1312  readmessages();
1313  readLegacyNetwork ();
1314 
1315  version = stream->readInt();
1316 
1317  if (version > actnetworkversion || version < minnetworkversion )
1318  throw tinvalidversion ( name, actnetworkversion, version );
1319 
1320 
1321 
1322  if ( version < 10 ) {
1323  readOldEventLists ( stream, true, spfld );
1324  readoldevents ();
1325  }
1326 
1327  readfields ( );
1328 
1329  readdissections();
1330 
1331  if ( spfld->__loadreplayinfo ) {
1333  spfld->replayinfo->read ( *stream );
1334  }
1335 
1336  if ( version > 8 )
1337  readAI();
1338 
1339 #ifdef sgmain
1340  version = stream->readInt();
1341  if (version > actnetworkversion || version < minnetworkversion )
1342  throw tinvalidversion ( name, actnetworkversion, version );
1343 #endif
1344 
1345  chainitems ( spfld );
1346 
1348 
1350 
1352 
1353  spfld->levelfinished = false;
1354 
1355  // there was a bug that made the ammo amount underflow
1356  for ( int i = 0; i < 8; ++i)
1357  for ( Player::BuildingList::iterator b = spfld->player[i].buildingList.begin(); b != spfld->player[i].buildingList.end(); ++b )
1358  for ( int a = 0; a < waffenanzahl; ++a )
1359  if ( (*b)->ammo[a] > 32000 ) {
1360  ASCString s;
1361  s.format( "Player %s had %d ammo of type %s in the building at %d/%d", spfld->player[i].getName().c_str(), (*b)->ammo[a], cwaffentypen[a], (*b)->getEntry().x, (*b)->getEntry().y );
1362  new Message( s, spfld, 1 );
1363  (*b)->ammo[a] = 0;
1364  }
1365 
1366 
1367 
1368  GameMap* spfldcopy = spfld;
1369  spfld = NULL;
1370 
1371  mapLoaded( spfldcopy );
1372 
1373 
1374  return spfldcopy;
1375 
1376 }
1377 
1378 
1379 
1380 
1381 
1382 
1383 ASCString getLuaQuote( bool open, int n )
1384 {
1385  ASCString s = open? "[[" : "]]";
1386  for ( int i =0; i < n; ++i )
1387  s.insert(1, "=" );
1388  return s;
1389 }
1390 
1392 {
1393  int count = 0;
1394  while( text.find_first_of( getLuaQuote( true, count )) != ASCString::npos ||
1395  text.find_first_of( getLuaQuote( false, count )) != ASCString::npos )
1396  ++count;
1397 
1398  return getLuaQuote( true, count) + text + getLuaQuote( false, count );
1399 }
1400 
1401 void writeMessageFile( GameMap* gamemap, tnstream& stream )
1402 {
1403  stream.writeString( "map = asc.getLoadingMap() \n", false);
1404  for ( GameMap::Events::const_iterator i = gamemap->events.begin(); i != gamemap->events.end(); ++i ) {
1405  ASCString s = (*i)->action->getLocalizationString();
1406  if ( !s.empty() ) {
1407  stream.writeString ( "--- ===== Event " + ASCString::toString((*i)->id) + " ======= \n", false );
1408  stream.writeString ( "message = " + luaQuote( s ) + "\n", false );
1409  stream.writeString ( "asc.setLocalizedEventMessage( map, " + ASCString::toString((*i)->id) + ", message )\n\n", false);
1410  }
1411  }
1412 
1413  for ( int p = 0; p <= gamemap->getPlayerCount(); ++p ) {
1414  Player& player = gamemap->getPlayer(p);
1415  for ( Player::BuildingList::const_iterator b = player.buildingList.begin(); b != player.buildingList.end(); ++b ) {
1416  if ( !(*b)->name.empty() ) {
1417  stream.writeString ( "--- ===== Building " + ASCString::toString((*b)->getIdentification()) + " ======= \n", false );
1418  ASCString f;
1419  f.format( "asc.setLocalizedContainerName( map, asc.MapCoordinate( %d, %d ), %s ) \n", (*b)->getPosition().x, (*b)->getPosition().y, + luaQuote( (*b)->name ).c_str() );
1420  stream.writeString ( f, false );
1421  }
1422  }
1423  }
1424 }
1425 
1426 
1427 
1428 void savemap( const ASCString& name, GameMap* gamemap )
1429 {
1430 
1431 #ifdef logging
1432  logtofile ( "loaders / savemap / started " );
1433 #endif
1434 
1435  try {
1436  tmaploaders gl;
1437  gl.savemap ( name, gamemap );
1438 
1439 
1440  if ( CGameOptions::Instance()->saveEventMessagesExternal && gamemap->nativeMessageLanguage.length() ) {
1441  tn_file_buf_stream messages ( name + "." + gamemap->nativeMessageLanguage, tnstream::writing );
1442  writeMessageFile( gamemap, messages );
1443  }
1444 
1445  } /* endtry */
1446 
1447  catch ( const tfileerror& err ) {
1448  displaymessage( "file error writing map to filename %s ", 1, err.getFileName().c_str() );
1449  } /* endcatch */
1450  catch ( const ASCexception& ) {
1451  displaymessage( "error writing map ", 1 );
1452  } /* endcatch */
1453 
1454 }
1455 
1456 void savegame( const ASCString& name, GameMap* gamemap)
1457 {
1458  try {
1459  tsavegameloaders gl;
1460  gl.savegame ( gamemap, name);
1461  } catch ( const tfileerror& err) {
1462  displaymessage( "error writing map to filename %s ", 1, err.getFileName().c_str() );
1463  } /* endcatch */
1464  catch ( const ASCexception& ) {
1465  displaymessage( "error writing map ", 1 );
1466  } /* endcatch */
1467 }
1468 
1469 
1470 void savereplay( GameMap* gamemap, int num )
1471 {
1472  try {
1473  if ( !gamemap->replayinfo )
1474  fatalError ( "treplayloaders :: savereplay ; No replay activated !");
1475 
1476  if ( gamemap->replayinfo->map[num] ) {
1477  delete gamemap->replayinfo->map[num];
1478  gamemap->replayinfo->map[num] = NULL;
1479  }
1480 
1481  gamemap->replayinfo->map[num] = new MemoryStreamStorage;
1482  MemoryStream memstream ( gamemap->replayinfo->map[num], tnstream::writing );
1483 
1484  memstream.writeInt( actreplayversion );
1485 
1486  tsavegameloaders sgl;
1487  sgl.savegame ( &memstream, gamemap, false );
1488 
1489  memstream.writeInt ( actreplayversion );
1490  } catch ( const ASCexception & ) {
1491  displaymessage( "error saving replay information", 1 );
1492  } /* endcatch */
1493 }
1494 
1496 {
1497  GameMap* replaymap = NULL;
1498 
1499  try {
1500  const char* name = "memorystream actmap->replayinfo";
1501  MemoryStream memstream ( streambuf, tnstream::reading );
1502 
1503  int version = memstream.readInt();
1504  if (version > actreplayversion || version < minreplayversion )
1505  throw tinvalidversion ( name, actreplayversion, version );
1506 
1507  tsavegameloaders sgl;
1508  replaymap = sgl.loadgame ( &memstream );
1509 
1510  version = memstream.readInt();
1511  if (version > actreplayversion || version < minreplayversion ) {
1512  delete replaymap;
1513  throw tinvalidversion ( name, actreplayversion, version );
1514  }
1515 
1516  } catch ( const InvalidID & err ) {
1517  displaymessage( err.getMessage().c_str(), 1 );
1518  replaymap = NULL;
1519  } /* endcatch */
1520  catch ( const tinvalidversion & err ) {
1521  displaymessage( err.getMessage().c_str(), 1 );
1522  replaymap = NULL;
1523  } /* endcatch */
1524  catch ( const tfileerror & err) {
1525  displaymessage( "error reading map filename %s ", 1, err.getFileName().c_str() );
1526  replaymap = NULL;
1527  } /* endcatch */
1528  catch ( const ASCexception & ) {
1529  displaymessage( "error loading replay", 1 );
1530  replaymap = NULL;
1531  } /* endcatch */
1532 
1533  return replaymap;
1534 }
1535 
1536 
1537 
1538 
1540 {
1541  GameMap* m = NULL;
1542  try {
1543  m = loader( filename );
1544  } catch ( const InvalidID & err ) {
1545  displaymessage( err.getMessage().c_str(), 1 );
1546  return NULL;
1547  } /* endcatch */
1548  catch ( const tinvalidversion & err ) {
1549  displaymessage( err.getMessage().c_str(), 1 );
1550  return NULL;
1551  } /* endcatch */
1552  catch ( const StreamCompressionError & err ) {
1553  displaymessage( "The file %s is corrupted.\nPlease obtain a new copy of that file", 1, filename.c_str() );
1554  return NULL;
1555  } catch ( const tfileerror & err) {
1556  displaymessage( "error reading map filename %s ", 1, err.getFileName().c_str() );
1557  return NULL;
1558  } /* endcatch */
1559  catch ( const ASCmsgException & msg ) {
1560  displaymessage( "error loading file\n" + msg.getMessage() , 1 );
1561  return NULL;
1562  } /* endcatch */
1563  catch ( const ASCexception & ) {
1564  displaymessage( "error loading file", 1 );
1565  return NULL;
1566  } /* endcatch */
1567 
1568  return m;
1569 }
1570 
1571 
1572 
1573 
1574 
1575 
1576 
1577 
1578 
1579 bool validatemapfile ( const ASCString& filename )
1580 {
1581 
1582  char* description = NULL;
1583 
1584  try {
1585 
1586  tnfilestream stream ( filename, tnstream::reading );
1587  stream.readpchar ( &description, 200 );
1588  if ( description ) {
1589  delete[] description ;
1590  description = NULL;
1591  }
1592 
1593  int w = stream.readWord();
1594  if ( w != fileterminator )
1595  throw tinvalidversion ( filename, fileterminator, (int) w );
1596 
1597  int version = stream.readInt();
1598 
1599  if (version > actmapversion || version < minmapversion )
1600  throw tinvalidversion ( filename, actmapversion, version );
1601 
1602  } /* endtry */
1603 
1604  catch ( ... ) {
1605  return false;
1606  } /* endcatch */
1607 
1608  return true;
1609 }
1610 
1611 
1612 
1613 
1614 
1615 bool validateemlfile ( const ASCString& filename )
1616 {
1617  char* description = NULL;
1618 
1619  try {
1620 
1621  tnfilestream stream ( filename, tnstream::reading );
1622  stream.readpchar ( &description, 200 );
1623  if ( description ) {
1624  delete[] description ;
1625  description = NULL;
1626  }
1627 
1628  int w = stream.readWord();
1629  if ( w != fileterminator )
1630  throw tinvalidversion ( filename, fileterminator, (int) w );
1631 
1632  int version = stream.readInt();
1633 
1634  if (version > actnetworkversion || version < minnetworkversion )
1635  throw tinvalidversion ( filename, actnetworkversion, version );
1636 
1637  } /* endtry */
1638 
1639  catch ( const ASCexception & ) {
1640  return false;
1641  } /* endcatch */
1642 
1643 
1644  return true;
1645 }
1646 
1647 
1648 bool validatesavfile ( const ASCString& filename )
1649 {
1650 
1651  char* description = NULL;
1652 
1653  try {
1654 
1655  tnfilestream stream ( filename, tnstream::reading );
1656  stream.readpchar ( &description, 200 );
1657  if ( description ) {
1658  delete[] description ;
1659  description = NULL;
1660  }
1661 
1662  int w = stream.readWord();
1663  if ( w != fileterminator )
1664  throw tinvalidversion ( filename, fileterminator, w );
1665 
1666  int version = stream.readInt();
1667  if (version > actsavegameversion || version < minsavegameversion )
1668  throw tinvalidversion ( filename, actsavegameversion, version );
1669 
1670  } /* endtry */
1671 
1672  catch ( const ASCexception & ) {
1673  return false;
1674  } /* endcatch */
1675 
1676  return true;
1677 }
1678 
1679 
1680 
1681 
1683 {
1684  MapConinuationInfo mi;
1685 
1686  tfindfile ff ( mapextension );
1687 
1688  ASCString filename = ff.getnextname();
1689  while( !filename.empty() ) {
1690 
1691  try {
1692  tnfilestream filestream ( filename, tnstream::reading );
1693  tmaploaders spfldloader;
1694  spfldloader.stream = &filestream;
1695 
1696  CharBuf description;
1697 
1698  spfldloader.stream->readpchar ( &description.buf );
1699 
1700  int w = spfldloader.stream->readWord();
1701 
1702  if ( w != fileterminator )
1703  throw tinvalidversion ( filename.c_str(), w, fileterminator );
1704 
1705  int version = spfldloader.stream->readInt();
1706 
1707  if (version > actmapversion || version < minmapversion )
1708  throw tinvalidversion ( filename.c_str(), version, actmapversion );
1709 
1710  spfldloader.readmap ();
1711 
1712  if ( spfldloader.spfld->campaign.avail && spfldloader.spfld->campaign.id == id ) {
1713  mi.title = spfldloader.spfld->maptitle;
1714  mi.codeword = spfldloader.spfld->codeWord;
1715  mi.filename = filename;
1716  return mi;
1717  }
1718  } catch ( ... ) {
1719  } /* endcatch */
1720 
1721  filename = ff.getnextname();
1722  }
1723 
1724  return mi;
1725 }
1726 
1727 
void write(tnstream &stream, bool includeLoadedUnits=true) const
Definition: vehicle.cpp:1121
void startGame()
prepares a new game for being played
Definition: gamemap.cpp:1911
TerrainType::Weather * typ
the terraintype of the field
Definition: mapfield.h:38
MessagePntrContainer sentmessage
the list of messages that have been sent yet
Definition: player.h:189
Uint8 materialvisible[8]
Definition: mapfield.h:110
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
virtual void write(tnstream &stream) const =0
void writemessages(void)
Definition: loaders.cpp:190
const char * getFullVersionString()
Definition: strtmesg.cpp:58
int id
an identification for identifying a map in the chain of maps that make up a campaign ...
Definition: gamemap.h:224
The (base-) classes which are thrown as exceptions.
An in-memory storage of streamed data.
Definition: basestrm.h:172
ASCString codeWord
the codeword for accessing a map in a campaign
Definition: gamemap.h:210
ItemRepositoryLoader< ObjectType > objectTypeRepository("objecttype")
void chainitems(GameMap *actmap)
Definition: loaders.cpp:843
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
int xsize
the size of the map
Definition: gamemap.h:201
bool loadOldEvents
just a helper variable for loading the map; no function outside;
Definition: gamemap.h:566
void read(tnstream &stream)
Definition: gamemap.cpp:297
void read_techs(tnstream &stream, bool merge=false)
Definition: research.cpp:717
virtual void writeInt(int i)
Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is p...
Definition: basestrm.cpp:363
map accessing and usage routines used by ASC and the mapeditor
miscellaneous functions which are used by ASC and all its tools
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
void initmap(void)
Definition: loaders.cpp:381
Vehicle * vehicle
Definition: mapfield.h:89
const int waffenanzahl
The number of different weapon types.
Definition: typen.h:58
int getNewNetworkID()
returns a new and unique ID
Definition: gamemap.cpp:1139
int connection
are any events connected to this field
Definition: mapfield.h:164
bool __loadunsentmessage
Definition: gamemap.h:351
bool suppressMapTriggerExecution
Definition: loaders.cpp:82
void setnewposition(int x, int y)
checks whether the unit can construct a building of the given type.
Definition: vehicle.cpp:808
bool __loadunreadmessage
Definition: player.h:182
Uint8 levelfinished
Definition: gamemap.h:321
void writemessagelist(MessagePntrContainer &lst)
Definition: loaders.cpp:236
ASCString text
the body of the message
Definition: messages.h:51
BaseAI * ai
if the player is run by an AI, this is the pointer to it
Definition: player.h:144
void loadLocalizedMessages(GameMap *map, const ASCString &name)
Definition: loaders.cpp:1030
virtual int readInt(void)
Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is pe...
Definition: basestrm.cpp:284
virtual ASCString getDeviceName()
returns the name of the stream.
Definition: basestrm.cpp:269
ASCString getnextname(int *loc=NULL, bool *inContainer=NULL, ASCString *location=NULL)
Returns the next entry of the internal file list.
Definition: basestrm.cpp:2211
#define assertOrThrow(expr)
Definition: errors.h:69
time_t time
the real world time the message was written
Definition: messages.h:48
class TerrainType * pterraintype
Definition: terraintype.h:72
static void storeData(const GameMap *game)
int lifetime
the object is removed when it is lifetime turns old. -1 disables removal
Definition: objecttype.h:187
bool __loadoldmessage
Definition: player.h:186
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
Uint8 material
Definition: mapfield.h:54
bool ___loadLegacyNetwork
Definition: gamemap.h:361
static GameMap * loadGameFromFile(const ASCString &name)
Definition: loaders.cpp:1135
void runFile(const ASCString &filename)
Definition: luarunner.cpp:25
TerrainType * terraintype
pointer to the outer structure
Definition: terraintype.h:128
#define csm_typid32
Definition: loaders.cpp:96
Weather * weather[cwettertypennum]
Definition: terraintype.h:140
int damage
Definition: objects.h:49
const int minsavegameversion
Definition: loaders.cpp:66
void readfields(void)
Definition: loaders.cpp:610
int turn() const
Definition: typen.h:181
int from
bitmapped variable showing the sender of the message. Bit 0 - 7 are the players, Bit 9 is the system...
Definition: messages.h:34
void weatherSystemRequired()
Definition: loaders.cpp:929
GameMap * loadnwgame(tnstream *strm)
Definition: loaders.cpp:1276
int getOwner() const
returns the number of the player this vehicle/building belongs to
void writemaptostream(GameMap *gamemap, int width, int height, tnstream &stream)
struct MapField::View view[8]
#define csm_object
Definition: loaders.cpp:108
void savemap(const ASCString &name, GameMap *gamemap)
saves the map located in actmap to the map file name
Definition: loaders.cpp:1428
const char * cwaffentypen[weaponTypeNum]
Definition: vehicletype.cpp:71
void checkForUniqueUnitIDs(GameMap *gamemap)
Definition: loaders.cpp:350
#define csm_fuel
Definition: loaders.cpp:105
#define csm_vehicle
Definition: loaders.cpp:98
Loki::Functor< GameMap *, LOKI_TYPELIST_1(const ASCString &) > MapLoadingFunction
Definition: loaders.h:57
const int objectstreamversion
Definition: loaders.cpp:453
#define csm_connection
Definition: loaders.cpp:112
virtual int readWord(void)
Reads a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is ...
Definition: basestrm.cpp:291
const int messageMinVersion
Definition: loaders.cpp:188
ASCString getLuaQuote(bool open, int n)
Definition: loaders.cpp:1383
const int minmapversion
Definition: loaders.cpp:68
MessagePntrContainer oldmessage
the list of messages that already have been read by the player yet
Definition: player.h:185
void warningMessage(const ASCString &str)
Events events
Definition: gamemap.h:291
A system that provides a set of images for vehicles, buildings, etc.
bool __loadreplayinfo
a helper variable to store some information during the loading process. No usage outside.
Definition: gamemap.h:399
tspfldloaders(void)
Definition: loaders.cpp:863
const int actnetworkversion
Definition: loaders.cpp:69
#define csm_resources
Definition: loaders.cpp:111
Interface for some basic classes from which all of ASC's dialogs are derived.
The interface for all kinds of IO stream.
a single field of the map
Definition: mapfield.h:26
Definition: ai.h:44
ASCString & format(const charT *pFormat,...)
Definition: ascstring.cpp:78
void readoldevents(void)
Definition: loaders.cpp:335
#define csm_newobject
Definition: loaders.cpp:113
const int actsavegameversion
Definition: loaders.cpp:65
ItemRepositoryLoader< Technology > technologyRepository("technology")
static GameMap * loadmap(const ASCString &name)
Definition: loaders.cpp:1039
bool ___loadJournal
temporary variables for loading the map
Definition: gamemap.h:361
Surface loadmapfromstream(tnstream &stream)
bool validatesavfile(const ASCString &filename)
checks, whether filename is a valid savegame
Definition: loaders.cpp:1648
virtual ~tspfldloaders()
Definition: loaders.cpp:869
virtual Uint8 readUint8(void)
Reads a 8 bit unsigned Integer.
Definition: basestrm.cpp:305
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ASCString getLocalizedFile(const ASCString &filename, const ASCString &nativeMessageLanguage="")
Tries to find a file containing native message These files are the filename appended by "...
Definition: i18n.cpp:52
tnstream * stream
Definition: loaders.h:70
int to
bitmapped variable showing the recipients of the message.
Definition: messages.h:38
#define csm_material
Definition: loaders.cpp:104
ASCString gameJournal
Definition: gamemap.h:365
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
#define csm_direction
Definition: loaders.cpp:97
const int magic
Definition: stack.cpp:36
#define csm_weather
Definition: loaders.cpp:107
struct GameMap::PreferredFilenames preferredFileNames
void read(tnstream &stream)
Definition: gamemap.cpp:2182
MineTypes
Definition: objects.h:70
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
ASCString luaQuote(const ASCString &text)
Definition: loaders.cpp:1391
VehicleList vehicleList
a list of all units
Definition: player.h:135
#define csm_building
Definition: loaders.cpp:99
ItemRepositoryLoader< VehicleType > vehicleTypeRepository("vehicletype")
int cc
bitmapped variable showing the recipients of the message.
Definition: messages.h:44
MessageContainer messages
these are the messages themselfs. A MessagePntrContainer only stores pointers to message body which a...
Definition: gamemap.h:354
TerrainBits getTerrainBitType(TerrainBitTypes tbt)
GameMap * mapLoadingExceptionChecker(const ASCString &filename, MapLoadingFunction loader)
Definition: loaders.cpp:1539
char * buf
Definition: basestrm.h:68
#define csm_cnt2
Definition: loaders.cpp:101
void sortobjects(void)
sorts the objects. Since objects can be on different levels of height, the lower one must be displaye...
Definition: mapfield.cpp:436
ItemRepositoryLoader< TerrainType > terrainTypeRepository("terraintype")
GameMap * spfld
Definition: loaders.h:71
const ObjectType * typ
Definition: objects.h:48
Uint8 fuel
mineral resources on this field.
Definition: mapfield.h:54
void displayLogMessage(int msgVerbosity, const char *message,...)
const char * mapextension
Definition: loaders.cpp:79
int lifetimer
Definition: objects.h:37
The old event system that is still required to load old maps.
bool ___loadNewJournal
Definition: gamemap.h:361
MineTypes type
void readOldEventLists(tnstream *stream, bool passedEvents, GameMap *spfld)
Definition of THE central asc class: GameMap.
Reads data from or writes data to a MemoryStreamStorage This allows a completely volatile storage of ...
Definition: basestrm.h:204
void setparams(ObjectRemovalStrategy *objectRemovalStrategy)
recalculates the terrain properties, movemalus etc from the terraintype and the objects,
Definition: mapfield.cpp:605
int savemap(const ASCString &name, GameMap *gamemap)
Definition: loaders.cpp:892
void displaymessage(const char *formatstring, int num,...)
displays a dialog box with a message
Definition: dlg_box.cpp:1849
void allocateFields(int x, int y, TerrainType::Weather *terrain=NULL)
Definition: gamemap.cpp:982
virtual void writeUint8(Uint8 c)
Writes a 8 bit unsigned Integer.
Definition: basestrm.cpp:380
Interface for all the fighting routines of ASC.
Uint16 visible
can this field be seen be the player. Variable is bitmapped; two bits for each player. These two bits can have the states defined in VisibilityStates
Definition: mapfield.h:63
VehicleType * fzt
Definition: player.h:167
Searching for files.
Definition: basestrm.h:484
void readdissections(void)
Definition: loaders.cpp:126
void savegame(tnstream *strm, GameMap *gamemap, bool writeReplays=true)
Definition: loaders.cpp:1060
The interface for the buildingtype class.
const int minnetworkversion
Definition: loaders.cpp:70
const int minreplayversion
Definition: loaders.cpp:72
bool avail
is this a campaign map?
Definition: gamemap.h:221
int dir
Definition: objects.h:51
void writeMessageFile(GameMap *gamemap, tnstream &stream)
Definition: loaders.cpp:1401
GameMap * loadgame(tnstream *strm)
Definition: loaders.cpp:1142
void write(tnstream &stream)
Definition: gamemap.cpp:2212
void calculateallobjects(GameMap *actmap)
recalculates the connection (like road interconnections) of all objects on the map ...
Definition: spfst.cpp:562
bool __dissectionsToLoad
Definition: player.h:178
int id
an id that identifies the message. It is assigned automatically
Definition: messages.h:54
const ASCString & getMessage(void) const
Definition: errors.h:42
GameTime gametime
the game time the messages was written
Definition: messages.h:57
#define csm_b3
Definition: loaders.cpp:102
ASCString playername
Definition: loaders.h:134
GameMap * loadreplay(MemoryStreamStorage *streambuf)
Definition: loaders.cpp:1495
ASCString maptitle
Definition: loaders.h:132
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
MemoryStreamStorage * map[8]
Definition: gamemap.h:375
The IO for many basic classes and structurs of ACS.
GameFileInformation loadMapimageFromFile(const ASCString &filename)
Definition: loaders.cpp:1109
ASCString codeword
Definition: loaders.h:161
#define csm_visible
Definition: loaders.cpp:106
Player player[9]
Definition: gamemap.h:253
void errorMessage(const ASCString &string)
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
list< Message * > MessagePntrContainer
Definition: messages.h:74
int savenwgame(tnstream *strm, const GameMap *gamemap)
Definition: loaders.cpp:1235
GameMap * eventLocalizationMap
used by setLocalizedEventMessage to get the map being loaded It's not nice having a global variable f...
Definition: loaders.cpp:1013
void writeAI()
Definition: loaders.cpp:396
const int fileterminator
Definition: loaders.cpp:75
static Vehicle * newFromStream(GameMap *gamemap, tnstream &stream, int forceNetworkID=-1)
generates a new unit, loads its parameters from the stream (where they have been previously written w...
Definition: vehicle.cpp:1728
void write(tnstream &stream)
Definition: gamemap.cpp:711
MapConinuationInfo findNextCampaignMap(int id)
Definition: loaders.cpp:1682
int ysize
Definition: gamemap.h:201
GameParameter
Definition: gamemap.h:77
TerrainBits bdt
the terraintype properties. They determine which units can move over the field. This variable is reca...
Definition: mapfield.h:161
MineContainer mines
Definition: mapfield.h:117
OverviewMapHolder overviewMapHolder
Definition: gamemap.h:532
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
int remainingGrowthTime
Definition: objects.h:52
int getgameparameter(GameParameter num) const
Definition: gamemap.cpp:1047
BuildingList buildingList
a list of all units
Definition: player.h:139
void readmap(void)
Definition: loaders.cpp:387
void readAI()
Definition: loaders.cpp:414
class GameMap::IDManager idManager
A Message to a player. It may either be send by another player or by the system.
Definition: messages.h:30
Interface for all the dialog boxes used by the game and the mapeditor.
void setInt(int terrain1=0, int terrain2=0)
Research research
the status of the scientific research
Definition: player.h:142
MapField * field
the array of fields
Definition: gamemap.h:204
const int messageVersion
Definition: loaders.cpp:187
ASCString maptitle
the title of the map
Definition: gamemap.h:213
The interface for the artificial intelligence of ASC.
procedure for loading and writing savegames, maps etc.
bool __loadmessages
Definition: gamemap.h:355
ASCString filename
Definition: loaders.h:162
void seteventtriggers(GameMap *actmap)
Definition: loaders.cpp:84
Building * building
Definition: mapfield.h:102
virtual void writeWord(int w)
Writes a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is...
Definition: basestrm.cpp:369
void setTempw(Uint16 tempw)
Definition: mapfield.cpp:63
virtual void readpchar(char **pc, int maxlength=0)
Reads a string.
Definition: basestrm.cpp:390
void writedissections(void)
Definition: loaders.cpp:158
const ASCString & getErrors()
Definition: luarunner.cpp:61
void read(tnstream &stream)
Definition: base.cpp:477
GameMap * actmap
Definition: spfst.cpp:64
ASCString getMessage() const
Definition: basestrm.cpp:176
virtual void writepchar(const char *pc)
write the C-String pc to the stream
Definition: basestrm.cpp:554
int * game_parameter
Definition: gamemap.h:426
Interface to the event handling of ASC.
void readmessages(void)
Definition: loaders.cpp:272
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
void writemap(void)
Definition: loaders.cpp:365
bool exist(const ASCString &s)
does a file s exist (wildcards allowed)
Definition: basestrm.cpp:2444
static sigc::signal< void, GameMap * > mapLoaded
Definition: loaders.h:73
an instance of an object type (ObjectType) on the map
Definition: objects.h:46
bool reminder
reminders are special messages that the players sends to himself, to be read the next turn ...
Definition: messages.h:60
const int actmapversion
Definition: loaders.cpp:67
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
void writefields(void)
Definition: loaders.cpp:455
void savereplay(GameMap *gamemap, int num)
writes all replay relevant map information of player num to the replay variable of actmap ...
Definition: loaders.cpp:1470
void loadLocalizedMessageFile(GameMap *map, const ASCString &filename)
Definition: loaders.cpp:1017
bool validateemlfile(const ASCString &filename)
checks, whether filename is a valid email game
Definition: loaders.cpp:1615
DissectionContainer dissections
Definition: player.h:176
static Building * newFromStream(GameMap *gamemap, tnstream &stream, bool chainToField=true)
Definition: buildings.cpp:523
const int actreplayversion
Definition: loaders.cpp:71
ASCString nativeMessageLanguage
the language string that describes the messages which are saved in the game events For example: en_US...
Definition: gamemap.h:432
bool __loadsentmessage
Definition: player.h:190
void readLegacyNetworkData(tnstream &stream)
void fatalError(const ASCString &string)
int getPlayerCount() const
Definition: gamemap.h:255
void readLegacyNetwork(void)
Definition: loaders.cpp:440
const int cwettertypennum
The number of different weather.
Definition: typen.h:61
bool exist() const
does the player exist at all
Definition: player.cpp:313
const char * savegameextension
Definition: loaders.cpp:78
Resourceview * resourceview
the mineral resources that were seen by a player on this field; since the actual amount may have decr...
Definition: mapfield.h:114
ReplayInfo * replayinfo
Definition: gamemap.h:396
GameTime time
the time in the game, mesured in a turns and moves
Definition: gamemap.h:235
ASCString title
Definition: loaders.h:160
void readmessagelist(MessagePntrContainer &lst)
Definition: loaders.cpp:253
Functions to parse the *.asctxt files.
const char * tournamentextension
Definition: loaders.cpp:80
ObjectContainer objects
Definition: mapfield.h:124
Definition: i18n.h:28
#define csm_b4
Definition: loaders.cpp:109
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
MessagePntrContainer unreadmessage
the list of messages that haven't been read by the player yet
Definition: player.h:181
const Technology * tech
Definition: player.h:168
ASCString newJournal
Definition: gamemap.h:366
void set(int turn, int move)
Definition: typen.h:183
struct GameMap::Campaign campaign
void savegame(const ASCString &name, GameMap *gamemap)
saves the game located in actmap to the savegame file name
Definition: loaders.cpp:1456
void write(tnstream &stream, bool includeLoadedUnits=true) const
Definition: buildings.cpp:451