Advanced Strategic Command
gamemap.cpp
Go to the documentation of this file.
1 
5 /***************************************************************************
6  gamemap.cpp - description
7  -------------------
8  begin : Tue Oct 24 2000
9  copyright : (C) 2000 by Martin Bickel
10  email : bickel@asc-hq.org
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #include <algorithm>
23 #include <ctime>
24 #include <cmath>
25 
26 #include "global.h"
27 #include "misc.h"
28 #include "typen.h"
29 #include "vehicletype.h"
30 #include "buildingtype.h"
31 #include "gamemap.h"
32 #include "dialog.h"
33 #include "itemrepository.h"
34 #include "strtmesg.h"
35 // #include "graphics/blitter.h"
36 #include "overviewmapimage.h"
37 #include "gameeventsystem.h"
38 #include "spfst.h"
39 #include "campaignactionrecorder.h"
40 
41 #include "packagemanager.h"
43 
45 
46 }
47 
49 
50 
51 }
52 
54  return getRandomValue(100);
55 }
56 
57 unsigned int RandomGenerator::getRandomValue(int limit) {
58  return getRandomValue(0, limit);
59 }
60 
61 unsigned int RandomGenerator::getRandomValue (int lowerLimit, int upperLimit){
62  if(upperLimit == 0) {
63  return 1;
64  }
65  int random_integer = rand();
66  random_integer = random_integer % upperLimit;
67  return (lowerLimit + random_integer);
68 }
69 
70 
71 
72 
73 OverviewMapHolder :: OverviewMapHolder( GameMap& gamemap ) : map(gamemap), initialized(false), secondMapReady(false), completed(false), connected(false), x(0),y(0)
74 {
75 }
76 
78 {
79  if ( !connected ) {
80  idleEvent.connect ( sigc::mem_fun( *this, &OverviewMapHolder::idleHandler ));
81  connected = true;
82  }
83 }
84 
85 
86 sigc::signal<void> OverviewMapHolder::generationComplete;
87 
89 {
90  int t = ticker;
91  while ( !completed && (t + 5 > ticker ))
92  drawNextField( true );
93  return true;
94 }
95 
96 
98 {
99  SPoint imgpos = OverviewMapImage::map2surface( pos );
100 
101  MapField* fld = map.getField( pos );
102  VisibilityStates visi = fieldVisibility( fld, map.getPlayerView() );
103  if ( visi == visible_not ) {
104  OverviewMapImage::fill ( overviewMapImage, imgpos, 0xff545454 );
105  } else {
106  if ( fld->building && fieldvisiblenow( fld, map.getPlayerView()) )
107  OverviewMapImage::fill ( overviewMapImage, imgpos, map.player[fld->building->getOwner()].getColor() );
108  else {
109 
110  int w = fld->getWeather();
111  fld->typ->getQuickView()->blit( overviewMapImage, imgpos );
112  for ( MapField::ObjectContainer::iterator i = fld->objects.begin(); i != fld->objects.end(); ++i )
113  if ( visi > visible_ago || i->typ->visibleago )
114  i->getOverviewMapImage( w )->blit( overviewMapImage, imgpos );
115 
116  if ( fld->vehicle && fieldvisiblenow( fld, map.getPlayerView()) )
117  OverviewMapImage::fillCenter ( overviewMapImage, imgpos, map.player[fld->vehicle->getOwner()].getColor() );
118 
119  if ( visi == visible_ago )
120  OverviewMapImage::lighten( overviewMapImage, imgpos, 0.7 );
121 
122  }
123 
124  }
125  return true;
126 }
127 
128 void OverviewMapHolder::drawNextField( bool signalOnCompletion )
129 {
130  if ( !init() )
131  return;
132 
133  if ( x == map.xsize ) {
134  x = 0;
135  ++y;
136  }
137  if ( y < map.ysize ) {
138  if ( !updateField( MapCoordinate(x,y)))
139  return;
140 
141  ++x;
142  }
143  if ( y == map.ysize ) {
144  completed = true;
145  if ( signalOnCompletion )
147 
148  completedMapImage = overviewMapImage.Duplicate();
149  secondMapReady = true;
150  }
151 }
152 
153 Surface OverviewMapHolder::createNewSurface()
154 {
155  Surface s;
156  if ( map.xsize > 0 && map.ysize > 0 ) {
157  s = Surface::createSurface( (map.xsize+1) * 6, 4 + map.ysize * 2 , 32, 0 );
158  }
159  return s;
160 }
161 
163 {
164  if ( map.ysize <= 0 || map.xsize <= 0 )
165  return false;
166 
167  if ( !initialized ) {
168  overviewMapImage = createNewSurface();
169  initialized = true;
170  }
171  return initialized;
172 }
173 
175 {
176  initialized = false;
177 }
178 
179 
181 {
182  bool initialized = init();
183  assert( initialized );
184  if ( complete )
185  while ( !completed )
186  drawNextField( false );
187 
188  if( secondMapReady )
189  return completedMapImage;
190  else
191  return overviewMapImage;
192 }
193 
195 {
196  completed = false;
197  x = 0;
198  y = 0;
199 }
200 
201 void OverviewMapHolder::clear(bool allImages )
202 {
203  if ( !initialized )
204  return;
205 
206  overviewMapImage.Fill( Surface::transparent );
207  if ( allImages ) {
208  if ( completedMapImage.valid() )
209  completedMapImage.Fill( Surface::transparent );
210  secondMapReady = false;
211  }
212 
213  startUpdate();
214 }
215 
217 {
218  if ( actmap )
219  actmap->overviewMapHolder.clear();
220 }
221 
222 
224  : actions(this), actionRecorder(NULL), overviewMapHolder( *this ), network(NULL), packageData(NULL)
225 {
226  serverMapID = 0;
227  randomSeed = rand();
228  dialogsHooked = false;
229 
230  eventID = 0;
231 
232  state = Normal;
233 
234  xsize = 0;
235  ysize = 0;
236  field = NULL;
237  temp = NULL;
238  temp2 = NULL;
239  temp3 = NULL;
240  temp4 = NULL;
241 
242  actplayer = -1;
243  time.abstime = 0;
244 
245  _resourcemode = 0;
246 
247  for ( int i = 0; i < 9; ++i ) {
248  player[i].setParentMap ( this, i );
249  if ( i == 0 )
251  else
253 
254  player[i].research.chainToMap ( this, i );
255  }
256 
257  levelfinished = 0;
258 
259  messageid = 0;
260 
261  continueplaying = false;
262  replayinfo = NULL;
263  playerView = 0;
265  graphicset = 0;
266  gameparameter_num = 0;
267  game_parameter = NULL;
269 
270 
271 #ifdef WEATHERGENERATOR
272  weatherSystem = new WeatherSystem(this, 1, 0.03);
273 #endif
275 
276 
277  nativeMessageLanguage = "en_US";
278 
279  sigMapCreation( *this );
280 }
281 
283 {
284  avail = false;
285  id = 0;
286  directaccess = true;
287 }
288 
290 {
292  dialogsHooked = true;
293 }
294 
295 const int tmapversion = 34;
296 
297 void GameMap :: read ( tnstream& stream )
298 {
299  int version;
300 
301  xsize = stream.readWord();
302  ysize = stream.readWord();
303 
304  if ( xsize == 0xfffe && ysize == 0xfffc ) {
305  version = stream.readInt();
306  if ( version > tmapversion )
307  throw tinvalidversion ( "GameMap", tmapversion, version );
308 
309  xsize = stream.readInt();
310  ysize = stream.readInt();
311  } else
312  version = 1;
313 
314  stream.readWord(); // xpos
315  stream.readWord(); // ypos
316  stream.readInt(); // dummy
317  field = NULL;
318 
319  if ( version <= 13 ) {
320  char buf[11];
321  stream.readdata ( buf, 11 );
322  buf[10] = 0;
323  codeWord = buf;
324  } else {
325  codeWord = stream.readString();
326  }
327 
328  if ( version < 2 )
329  ___loadtitle = stream.readInt();
330  else
331  ___loadtitle = true;
332 
333 
334  bool loadCampaign = stream.readInt();
335  actplayer = stream.readUint8();
336  time.abstime = stream.readInt();
337  if(version < 9 || version >= 17){
338  stream.readUint8();
339  weather.windSpeed = stream.readUint8();
340  weather.windDirection = stream.readUint8();
341  }
342 
343  if ( version >= 11 )
344  if ( stream.readInt() != 0x12345678 )
345  throw ASCmsgException("marker not matched when loading GameMap");
346 
347  if ( version >= 32 ) {
348  int p = stream.readInt();
349  if ( p ) {
350  packageData = new PackageData();
351  packageData->read( stream );
352 
354 
355  } else
356  packageData = NULL;
357  } else
358  packageData = NULL;
359 
360 
361  for ( int j = 0; j < 4; j++ )
362  stream.readUint8(); // was: different wind in different altitudes
363  for ( int i = 0; i< 12; i++ )
364  stream.readUint8(); // dummy
365 
366  _resourcemode = stream.readInt();
367 
368  int alliances[8][8];
369  if ( version <= 10 )
370  for ( int i = 0; i < 8; i++ )
371  for ( int j = 0; j < 8; j++ )
372  alliances[j][i] = stream.readUint8();
373 
374  int dummy_playername[9];
375  for ( int i = 0; i< 9; i++ ) {
377  stream.readInt(); // dummy
378  stream.readInt(); // dummy
379  if ( version <= 5 )
380  player[i].research.read_struct ( stream );
381  else
382  player[i].research.read ( stream );
383 
384  // player[i].ai = (BaseAI*)
385  stream.readInt() ;
386  player[i].ai = NULL;
387  player[i].stat = Player::PlayerStatus ( stream.readUint8() );
388  stream.readUint8(); // dummy
389  dummy_playername[i] = stream.readInt();
390  player[i].passwordcrc.read ( stream );
391  player[i].__dissectionsToLoad = stream.readInt();
392  player[i].__loadunreadmessage = stream.readInt();
393  player[i].__loadoldmessage = stream.readInt();
394  player[i].__loadsentmessage = stream.readInt();
395  if ( version >= 3 )
396  player[i].ASCversion = stream.readInt();
397  else
398  player[i].ASCversion = 0;
399 
400  if ( version >= 9 )
401  player[i].cursorPos.read( stream );
402 
403  if ( version >= 11 )
404  player[i].diplomacy.read( stream );
405  else {
406  if ( i < 8 ) // no alliances for neutral 'player'
407  for ( int j = 0; j< 8; ++j ) {
408  if ( alliances[i][j] == 0 )
409  player[i].diplomacy.setState( j, PEACE );
410  else
411  player[i].diplomacy.setState( j, WAR );
412  }
413  }
414 
415  if ( version >= 12 )
416  player[i].email = stream.readString();
417 
418  if ( version >= 22 )
419  player[i].read( stream );
420  }
421 
422  if ( version >= 11 )
423  if ( stream.readInt() != 0x12345678 )
424  throw ASCmsgException("marker not matched when loading GameMap");
425 
426 
427 
428 
429  if ( version <= 4 ) {
431  loadOldEvents = stream.readInt();
432  stream.readInt(); // int loadeventstocome
433  stream.readInt(); // int loadeventpassed
434  }
435 
436 
437  idManager.readData(stream );
438 
439  levelfinished = stream.readUint8();
440 
441  bool alliance_names_not_used_any_more[8];
442  if ( version <= 9 ) {
443  ___loadLegacyNetwork = stream.readInt();
444  for ( int i = 0; i < 8; i++ )
445  alliance_names_not_used_any_more[i] = stream.readInt(); // dummy
446  } else {
447  ___loadLegacyNetwork = false;
448  for ( int i = 0; i < 8; i++ )
449  alliance_names_not_used_any_more[i] = 0;
450  }
451 
452  if ( version <= 12 ) {
453  for ( int i = 0; i< 8; i++ ) {
454  stream.readWord(); // cursorpos.position[i].cx =
455  stream.readWord(); // cursorpos.position[i].sx =
456  stream.readWord(); // cursorpos.position[i].cy =
457  stream.readWord(); // cursorpos.position[i].sy =
458  }
459  }
460 
461  if ( version <= 9 )
462  stream.readInt(); // loadtribute
463 
464  __loadunsentmessage = stream.readInt();
465  __loadmessages = stream.readInt();
466 
467  messageid = stream.readInt();
468 
469  if( version < 2 ) {
470  ___loadJournal = stream.readInt();
471  ___loadNewJournal = stream.readInt();
472  } else {
473  ___loadJournal = true;
474  ___loadNewJournal = true;
475  }
476 
477  int exist_humanplayername[9];
478  for ( int i = 0; i < 8; i++ )
479  exist_humanplayername[i] = stream.readInt();
480  exist_humanplayername[8] = 0;
481 
482 
483  int exist_computerplayername[9];
484  for ( int i = 0; i < 8; i++ )
485  exist_computerplayername[i] = stream.readInt();
486  exist_computerplayername[8] = 0;
487 
488  supervisorpasswordcrc.read ( stream );
489 
490  if ( version <= 10 )
491  for ( int i = 0; i < 8; i++ )
492  stream.readUint8(); // alliances_at_beginofturn[i] =
493 
494  stream.readInt(); // was objectcrc = (Object*containercrcs)
495  bool load_shareview = false;
496  if ( version <= 10 )
497  load_shareview = stream.readInt();
498 
499  continueplaying = stream.readInt();
500  __loadreplayinfo = stream.readInt();
501  playerView = stream.readInt();
502  lastjournalchange.abstime = stream.readInt();
503 
504  for ( int i = 0; i< 8; i++ )
505  bi_resource[i].read ( stream );
506 
507  int preferredfilenames = stream.readInt();
508 
509  bool __loadEllipse = stream.readInt();
510  graphicset = stream.readInt();
511  gameparameter_num = stream.readInt();
512 
513  stream.readInt(); // dummy
515  for ( int i = 0; i< 9; i++ )
516  player[i].queuedEvents = stream.readInt();
517 
518  for ( int i = 0; i < 19; i++ )
519  stream.readInt();
520 
521  int _oldgameparameter[8];
522  for ( int i = 0; i < 8; i++ )
523  _oldgameparameter[i] = stream.readInt();
524 
525  if ( version >= 11 )
526  if ( stream.readInt() != 0x12345678 )
527  throw ASCmsgException("marker not matched when loading GameMap");
528 
530 // Here initmap was called
532 
533 
534 
535  if ( ___loadtitle )
536  maptitle = stream.readString();
537 
538  if ( loadCampaign ) {
539  if ( version <= 14 ) {
540  campaign.id = stream.readWord();
541  stream.readWord(); // campaign->prevmap
542  stream.readUint8(); // campaign->player
543  campaign.directaccess = stream.readUint8();
544  campaign.avail = true;
545  for ( int d = 0; d < 21; d++ )
546  stream.readUint8(); // dummy
547  } else {
548  campaign.id = stream.readInt();
549  campaign.directaccess = stream.readUint8();
550  if ( version > 15 )
551  campaign.avail = stream.readInt();
552  }
553  }
554 
555  for ( int w=0; w<9 ; w++ ) {
556  if (dummy_playername[w] )
557  stream.readString();
558 
559  player[w].ai = NULL;
560 
561 
562  if ( exist_humanplayername[w] )
563  player[w].setName( stream.readString() );
564 
565  if ( exist_computerplayername[w] )
566  stream.readString();
567 
568  } /* endfor */
569 
570  if ( stream.readInt() )
571  tribute.read ( stream );
572 
573  for ( int aa = 0; aa < 8; aa++ )
574  if ( alliance_names_not_used_any_more[aa] ) {
575  char* tempname = NULL;
576  stream.readpchar ( &tempname );
577  delete[] tempname;
578  }
579 
580  stream.readInt();
581 
582  if ( load_shareview && version <= 10 ) {
583 
584  for ( int i = 0; i < 8; i++ )
585  for ( int j =0; j < 8; j++ ) {
586  int sv = stream.readUint8();
587  if ( sv )
589  }
590 
591  stream.readInt();
592  }
593 
594  if ( preferredfilenames ) {
595  int p;
596  int mapname[8];
597  int mapdescription_not_used_any_more[8];
598  int savegame[8];
599  int savegamedescription_not_used_any_more[8];
600  for ( p = 0; p < 8; p++ )
601  mapname[p] = stream.readInt();
602  for ( p = 0; p < 8; p++ )
603  mapdescription_not_used_any_more[p] = stream.readInt();
604  for ( p = 0; p < 8; p++ )
605  savegame[p] = stream.readInt();
606  for ( p = 0; p < 8; p++ )
607  savegamedescription_not_used_any_more[p] = stream.readInt();
608 
609  for ( int i = 0; i < 8; i++ ) {
610  if ( mapname[i] )
611  preferredFileNames.mapname[i] = stream.readString ();
612 
613  if ( mapdescription_not_used_any_more[i] )
614  stream.readString(); // dummy
615 
616  if ( savegame[i] )
617  preferredFileNames.savegame[i] = stream.readString ();
618 
619  if ( savegamedescription_not_used_any_more[i] )
620  stream.readString();
621  }
622  }
623 
624  if ( __loadEllipse ) {
625  for ( int i = 0; i < 5; ++i )
626  stream.readInt();
627  stream.readFloat();
628  stream.readInt();
629  }
630 
631  int orggpnum = gameparameter_num;
632  gameparameter_num = 0;
633  for ( int gp = 0; gp < 8; gp ++ )
634  setgameparameter ( GameParameter(gp), _oldgameparameter[gp] );
635 
636  for ( int ii = 0 ; ii < orggpnum; ii++ ) {
637  int gpar = stream.readInt();
638  setgameparameter ( GameParameter(ii), gpar );
639  }
640 
641  if ( version >= 2 ) {
647  }
648 
649  if ( version >= 4 ) {
650  int num = stream.readInt();
651  for ( int ii = 0; ii < num; ++ii )
652  unitProduction.idsAllowed.push_back ( stream.readInt() );
653 
654  for ( int ii = 0; ii < 9; ii++ ) {
655  int num = stream.readInt( );
656  for ( int i = 0; i < num; i++ ) {
657  Player::PlayTime pt;
658  pt.turn = stream.readInt();
659  pt.date = stream.readInt();
660  player[ii].playTime.push_back ( pt );
661  }
662  }
663 
664  }
665 
666  if ( version >= 5 ) {
667  eventID = stream.readInt();
668 
669  int num = stream.readInt();
670  for ( int i = 0; i< num; ++i ) {
671  Event* ev = new Event ( *this );
672  ev->read ( stream );
673  events.push_back ( ev );
674  }
675  }
676 
677  if ( version >= 8 )
678  randomSeed = stream.readInt();
679 
680  if ( version >= 12 ) {
681  bool nw = stream.readInt();
682  if ( nw )
684  }
685 
686  if ( version >= 25 )
687  actions.read( stream );
688 
689  if ( version >= 30 ) {
691  int recorder = stream.readInt();
692  if ( recorder == 1 ) {
693  actionRecorder = new CampaignActionLogger( this );
694  actionRecorder->readData( stream );
695  } else
696  actionRecorder = NULL;
697  }
698 
699  if( version >= 31 )
700  properties.read( stream );
701 
702  if ( version >= 33 )
703  tasks->read( stream );
704 
705  if ( version >= 34 )
706  serverMapID = stream.readInt();
707 
708 }
709 
710 
711 void GameMap :: write ( tnstream& stream )
712 {
713  int i;
714 
715  stream.writeWord( 0xfffe );
716  stream.writeWord( 0xfffc );
717 
718  stream.writeInt ( tmapversion );
719  stream.writeInt( xsize );
720  stream.writeInt( ysize );
721 
722  stream.writeWord( 0 );
723  stream.writeWord( 0 );
724  stream.writeInt (1); // dummy
725  stream.writeString ( codeWord );
726 
727 
728  stream.writeInt( campaign.avail );
729  stream.writeUint8( actplayer );
730  stream.writeInt( time.abstime );
731 
732  stream.writeUint8(0);
733  stream.writeUint8( weather.windSpeed );
734  stream.writeUint8( weather.windDirection );
735 
736  stream.writeInt( 0x12345678 );
737 
738  stream.writeInt( packageData != NULL );
739  if ( packageData )
740  packageData->write( stream );
741 
742 
743  for ( i= 0; i < 4; i++ )
744  stream.writeUint8( 0 );
745 
746  for ( i = 0; i< 12; i++ )
747  stream.writeUint8( 0 ); // dummy
748 
749  stream.writeInt( _resourcemode );
750 
751  for ( i = 0; i< 9; i++ ) {
752  stream.writeUint8( player[i].existanceAtBeginOfTurn );
753  stream.writeInt( 1 ); // dummy
754  stream.writeInt( 1 ); // dummy
755  player[i].research.write ( stream );
756  stream.writeInt( player[i].ai != NULL );
757  stream.writeUint8( player[i].stat );
758  stream.writeUint8( 0 ); // dummy
759  stream.writeInt( 0 );
760  player[i].passwordcrc.write ( stream );
761  stream.writeInt( !player[i].dissections.empty() );
762  stream.writeInt( 1 );
763  stream.writeInt( 1 );
764  stream.writeInt( 1 );
765  stream.writeInt ( player[i].ASCversion );
766  player[i].cursorPos.write( stream );
767  player[i].diplomacy.write( stream );
768  stream.writeString ( player[i].email );
769  player[i].write(stream);
770  }
771 
772  stream.writeInt( 0x12345678 );
773 
774  idManager.writeData(stream);
775 
776  stream.writeUint8( levelfinished );
777 
778  stream.writeInt( 1 );
779  stream.writeInt( !messages.empty() );
780 
781  stream.writeInt( messageid );
782 
783  for ( i = 0; i < 8; i++ )
784  stream.writeInt( 1 );
785 
786  for ( i = 0; i < 8; i++ )
787  stream.writeInt( 0 );
788 
789  supervisorpasswordcrc.write ( stream );
790 
791  stream.writeInt( 0 );
792 
793  stream.writeInt( continueplaying );
794  stream.writeInt( replayinfo != NULL );
795  stream.writeInt( playerView );
797 
798  for ( i = 0; i< 8; i++ )
799  bi_resource[i].write ( stream );
800 
801  stream.writeInt( 1 );
802  stream.writeInt( 0 ); // was: ellipse
803  stream.writeInt( graphicset );
804  stream.writeInt( gameparameter_num );
805 
806  stream.writeInt( game_parameter != NULL );
808  for ( i = 0; i< 9; i++ )
809  stream.writeInt( player[i].queuedEvents );
810 
811  for ( i = 0; i < 19; i++ )
812  stream.writeInt( 0 );
813 
814  for ( i = 0; i < 8; i++ )
816 
817 
818  stream.writeInt( 0x12345678 );
819 
820 
822 // second part
824 
825 
826 
827  stream.writeString( maptitle );
828 
829  if ( campaign.avail ) {
830  stream.writeInt( campaign.id );
831  stream.writeUint8( campaign.directaccess );
832  stream.writeInt( campaign.avail );
833  }
834 
835  for (int w=0; w<8 ; w++ )
836  stream.writeString ( player[w].getName() );
837 
838  if ( !tribute.empty() ) {
839  stream.writeInt ( -1 );
840  tribute.write ( stream );
841  } else
842  stream.writeInt ( 0 );
843 
844  stream.writeInt ( 0 );
845 
846  int p;
847  for ( p = 0; p < 8; p++ )
848  stream.writeInt( 1 );
849 
850  for ( p = 0; p < 8; p++ )
851  stream.writeInt( 0 );
852 
853  for ( p = 0; p < 8; p++ )
854  stream.writeInt( 1 );
855 
856  for ( p = 0; p < 8; p++ )
857  stream.writeInt( 0 );
858 
859  for ( int k = 0; k < 8; k++ ) {
860  stream.writeString ( preferredFileNames.mapname[k] );
862  }
863 
864 
865  for ( int ii = 0 ; ii < gameparameter_num; ii++ )
866  stream.writeInt ( game_parameter[ii] );
867 
868 
873  stream.writeInt ( (unsigned int) (::time ( &archivalInformation.modifytime )));
874 
875 
876  stream.writeInt( unitProduction.idsAllowed.size() );
877  for ( int ii = 0; ii < unitProduction.idsAllowed.size(); ++ii )
878  stream.writeInt ( unitProduction.idsAllowed[ii] );
879 
880 
881  for ( int ii = 0; ii < 9; ii++ ) {
882  stream.writeInt( player[ii].playTime.size() );
883  for ( Player::PlayTimeContainer::iterator i = player[ii].playTime.begin(); i != player[ii].playTime.end(); ++i ) {
884  stream.writeInt( i->turn );
885  stream.writeInt( (unsigned int) i->date );
886  }
887  }
888 
889  stream.writeInt( eventID );
890 
891  stream.writeInt ( events.size());
892  for ( Events::iterator i = events.begin(); i != events.end(); ++i )
893  (*i)->write( stream );
894 
895  stream.writeInt( randomSeed );
896 
897  if ( network ) {
898  stream.writeInt( 1 );
899  network->write( stream );
900  } else
901  stream.writeInt( 0 );
902 
903  actions.write( stream );
904 
906 
907  if ( actionRecorder != NULL ) {
908  stream.writeInt( 1 );
909  actionRecorder->writeData( stream );
910  } else
911  stream.writeInt( 0 );
912 
913  properties.write( stream );
914 
915  tasks->write( stream );
916 
917  stream.writeInt( serverMapID );
918 }
919 
920 
921 MapCoordinate GameMap::findFirstContainer() const
922 {
923  for ( int y = 0; y < ysize; ++y )
924  for ( int x = 0; x < xsize; ++x )
925  if ( getField(x,y)->getContainer() )
926  if ( getField(x,y)->getContainer()->getOwner() == actplayer )
927  return MapCoordinate(x,y);
928 
929  return MapCoordinate(0,0);
930 }
931 
932 
934 {
935  #ifdef sgmain
936  if ( actplayer >= 0 ) {
937  if ( !player[actplayer].cursorPos.valid() || player[actplayer].cursorPos.x >= xsize || player[actplayer].cursorPos.y >= ysize)
938  player[actplayer].cursorPos = findFirstContainer();
939 
940  return player[actplayer].cursorPos;
941  } else
942  return player[0].cursorPos;
943 #else
944  return player[8].cursorPos;
945  #endif
946 }
947 
949 {
950 #ifdef sgmain
951  if ( actplayer >= 0 ) {
952  if ( !player[actplayer].cursorPos.valid() || player[actplayer].cursorPos.x >= xsize || player[actplayer].cursorPos.y >= ysize)
953  return findFirstContainer();
954  else
955  return player[actplayer].cursorPos;
956  } else
957  return player[0].cursorPos;
958 #else
959  return player[8].cursorPos;
960 #endif
961 }
962 
963 
964 void GameMap :: cleartemps( int b, int value )
965 {
966  if ( xsize <= 0 || ysize <= 0)
967  return;
968 
969  size_t lmax = xsize * ysize;
970  if (b & 1)
971  memset(temp, value, lmax);
972  if (b & 2)
973  memset(temp2, value, lmax);
974  if (b & 4)
975  for (int l = 0; l < lmax; ++l)
976  temp3[l] = value;
977  if (b & 8)
978  for (int l = 0; l < lmax; ++l)
979  temp4[l] = value;
980 }
981 
982 void GameMap :: allocateFields ( int x, int y, TerrainType::Weather* terrain )
983 {
984  field = new MapField[x*y];
985  for ( int i = 0; i < x*y; i++ ) {
986  if ( terrain ) {
987  field[i].typ = terrain;
988  field[i].setparams();
989  }
990  field[i].setMap ( this, i );
991  }
992  xsize = x;
993  ysize = y;
994  temp = new char[x*y]();
995  temp2 = new char[x*y]();
996  temp3 = new int[x*y]();
997  temp4 = new int[x*y]();
999 }
1000 
1001 
1003 {
1004  calculateallobjects( this );
1005 }
1006 
1008 {
1009 #ifdef karteneditor
1010  return -1;
1011 #else
1012  return playerView;
1013 #endif
1014 }
1015 
1016 
1018 {
1019  playerView = player;
1020 }
1021 
1022 
1023 
1024 bool GameMap :: isResourceGlobal ( int resource )
1025 {
1026  if ( _resourcemode == 1 ) { // BI-Mode
1027  if ( resource == 1 ) // material
1028  return false;
1029  else
1030  if ( resource == 2 )
1032  else
1033  return true;
1034  } else {
1035  /*
1036  if ( resource == 0 )
1037  return getgameparameter(cgp_globalenergy);
1038  if ( resource == 1 )
1039  return false;
1040  if ( resource == 2 )
1041  return getgameparameter(cgp_globalfuel);
1042  */
1043  return false;
1044  }
1045 }
1046 
1048 {
1049  if ( game_parameter && num < gameparameter_num ) {
1050  return game_parameter[num];
1051  } else
1052  if ( num < gameparameternum )
1053  return gameParameterSettings[num].defaultValue;
1054  else
1055  return 0;
1056 }
1057 
1059 {
1060  if ( game_parameter ) {
1061  if ( num < gameparameter_num )
1062  game_parameter[num] = value;
1063  else {
1064  int* oldparam = game_parameter;
1065  game_parameter = new int[num+1];
1066  for ( int i = 0; i < gameparameter_num; i++ )
1067  game_parameter[i] = oldparam[i];
1068  for ( int j = gameparameter_num; j < num; j++ )
1069  if ( j < gameparameternum )
1071  else
1072  game_parameter[j] = 0;
1073  game_parameter[num] = value;
1074  gameparameter_num = num + 1;
1075  delete[] oldparam;
1076  }
1077  } else {
1078  game_parameter = new int[num+1];
1079  for ( int j = 0; j < num; j++ )
1080  if ( j < gameparameternum )
1082  else
1083  game_parameter[j] = 0;
1084  game_parameter[num] = value;
1085  gameparameter_num = num + 1;
1086  }
1087 }
1088 
1089 void GameMap :: setupResources ( void )
1090 {
1091  for ( int n = 0; n< 8; n++ ) {
1092  bi_resource[n].energy = 0;
1093  bi_resource[n].material = 0;
1094  bi_resource[n].fuel = 0;
1095 
1096  #ifdef sgmain
1097 
1098  for ( Player::BuildingList::iterator i = player[n].buildingList.begin(); i != player[n].buildingList.end(); i++ )
1099  for ( int r = 0; r < 3; r++ )
1100  if ( isResourceGlobal( r )) {
1101  bi_resource[n].resource(r) += (*i)->actstorage.resource(r);
1102  (*i)->actstorage.resource(r) = 0;
1103  }
1104  #endif
1105  }
1106 }
1107 
1108 
1109 
1110 
1111 int GameMap :: eventpassed( int saveas, int action, int mapid )
1112 {
1113  return eventpassed ( (action << 16) | saveas, mapid );
1114 }
1115 
1116 
1117 
1118 int GameMap :: eventpassed( int id, int mapid )
1119 {
1120  return 0;
1121 }
1122 
1123 
1125 {
1126  vehicleLookupCache[veh->networkid] = veh;
1127  if ( unitnetworkid < veh->networkid )
1128  unitnetworkid = veh->networkid;
1129 }
1130 
1132 {
1133  VehicleLookupCache::iterator j = vehicleLookupCache.find(veh->networkid);
1134  if ( j != vehicleLookupCache.end() )
1135  vehicleLookupCache.erase(j);
1136 }
1137 
1138 
1140 {
1141  ++unitnetworkid;
1142  return unitnetworkid;
1143 }
1144 
1146 {
1147  unitnetworkid = stream.readInt();
1148 }
1149 
1151 {
1152  stream.writeInt( unitnetworkid );
1153 }
1154 
1155 Vehicle* GameMap :: getUnit ( Vehicle* eht, int nwid )
1156 {
1157  if ( !eht )
1158  return NULL;
1159  else {
1160  if ( eht->networkid == nwid )
1161  return eht;
1162  else
1163  for ( ContainerBase::Cargo::const_iterator i = eht->getCargo().begin(); i != eht->getCargo().end(); ++i )
1164  if ( *i ) {
1165  if ( (*i)->networkid == nwid )
1166  return *i;
1167  else {
1168  Vehicle* ld = getUnit ( *i, nwid );
1169  if ( ld )
1170  return ld;
1171  }
1172  }
1173  return NULL;
1174  }
1175 }
1176 
1177 
1178 
1179 Vehicle* GameMap :: getUnit ( int nwid, bool consistencyCheck )
1180 {
1181  IDManager::VehicleLookupCache::iterator i = idManager.vehicleLookupCache.find( nwid );
1182  if ( i != idManager.vehicleLookupCache.end() )
1183  return i->second;
1184 
1185 
1186  if ( consistencyCheck )
1187  for ( int p = 0; p < 9; p++ )
1188  for ( Player::VehicleList::iterator i = player[p].vehicleList.begin(); i != player[p].vehicleList.end(); i++ )
1189  if ( (*i)->networkid == nwid ) {
1190  displaymessage("warning: id not registered in VehicleLookupCache!",1);
1191  return *i;
1192  }
1193 
1194  return NULL;
1195 }
1196 
1197 const Vehicle* GameMap :: getUnit ( int nwid, bool consistencyCheck ) const
1198 {
1199  IDManager::VehicleLookupCache::const_iterator i = idManager.vehicleLookupCache.find( nwid );
1200  if ( i != idManager.vehicleLookupCache.end() )
1201  return i->second;
1202 
1203 
1204  if ( consistencyCheck )
1205  for ( int p = 0; p < 9; p++ )
1206  for ( Player::VehicleList::const_iterator i = player[p].vehicleList.begin(); i != player[p].vehicleList.end(); i++ )
1207  if ( (*i)->networkid == nwid ) {
1208  displaymessage("warning: id not registered in VehicleLookupCache!",1);
1209  return *i;
1210  }
1211 
1212  return NULL;
1213 }
1214 
1215 Vehicle* GameMap :: getUnit ( int x, int y, int nwid )
1216 {
1217  MapField* fld = getField ( x, y );
1218  if ( !fld )
1219  return NULL;
1220 
1221  if ( fld->vehicle && fld->vehicle->networkid == nwid )
1222  return fld->vehicle;
1223 
1224  if ( fld->getContainer() )
1225  return fld->getContainer()->findUnit( nwid );
1226 
1227  return NULL;
1228 
1229 }
1230 
1232 {
1233  if ( nwid > 0 )
1234  return getUnit(nwid);
1235  else {
1236  int x = (-nwid) & 0xffff;
1237  int y = (-nwid) >> 16;
1238  MapField* fld = getField(x,y);
1239  if ( !fld )
1240  return NULL;
1241 
1242  return fld->building;
1243  }
1244 }
1245 
1246 const ContainerBase* GameMap::getContainer ( int nwid ) const
1247 {
1248  if ( nwid > 0 )
1249  return getUnit(nwid);
1250  else {
1251  int x = (-nwid) & 0xffff;
1252  int y = (-nwid) >> 16;
1253  const MapField* fld = getField(x,y);
1254  if ( !fld )
1255  return NULL;
1256 
1257  return fld->building;
1258  }
1259 }
1260 
1261 
1262 
1264 {
1265  if ( !player[actplayer].exist() )
1266  if ( replayinfo )
1267  if ( replayinfo->guidata[actplayer] ) {
1268  delete replayinfo->guidata[actplayer];
1269  replayinfo->guidata[actplayer] = NULL;
1270  }
1271 
1272  for ( Player::VehicleList::const_iterator i = player[actplayer].vehicleList.begin(); i != player[actplayer].vehicleList.end(); i++ )
1273  (*i)->beginTurn();
1274 
1275  if ( player[actplayer].exist() && player[actplayer].stat != Player::off )
1277 
1278 }
1279 
1280 
1282 {
1283 
1285  Player::PlayTime pt;
1286  pt.turn = time.turn();
1287  ::time ( &pt.date );
1288  player[actplayer].playTime.push_back ( pt );
1289 
1291  sigPlayerTurnEndsStatic( this, player[actplayer] );
1292 
1293  actions.breakUndo(); // commits all actions to the replay log
1294 
1295  for ( int i = 0; i < 9; ++i )
1296  for ( Player::BuildingList::iterator v = player[i].buildingList.begin(); v != player[i].buildingList.end(); ++v ) {
1297  if ( i == actplayer )
1298  (*v)->endOwnTurn();
1299  (*v)->endAnyTurn();
1300  }
1301 
1302 
1303  Player::VehicleList toRemove;
1304  for ( Player::VehicleList::iterator v = player[actplayer].vehicleList.begin(); v != player[actplayer].vehicleList.end(); ++v ) {
1305  Vehicle* actvehicle = *v;
1306 
1307  // Bei Aenderungen hier auch die Windanzeige dashboard.PAINTWIND aktualisieren !!!
1308 
1309  if (( actvehicle->height >= chtieffliegend ) && ( actvehicle->height <= chhochfliegend ) && ( getField(actvehicle->xpos,actvehicle->ypos)->vehicle == actvehicle)) {
1310  if ( getmaxwindspeedforunit ( actvehicle ) < weather.windSpeed*maxwindspeed ){
1311  new Message ( getUnitReference( *v ) + " crashed because of the strong wind", this, 1<<(*v)->getOwner());
1312  toRemove.push_back ( *v );
1313  } else {
1314 
1315  int j = actvehicle->getTank().fuel - UnitHooveringLogic::calcFuelUsage( actvehicle );
1316  if (j < 0) {
1317  new Message ( getUnitReference( *v ) + " crashed due to lack of fuel", this, 1<<(*v)->getOwner());
1318  toRemove.push_back ( *v );
1319  } else {
1320  actvehicle->getResource( actvehicle->getTank().fuel - j, Resources::Fuel, false);
1321  }
1322  }
1323  }
1324 
1325  if ( actvehicle->typ->autorepairrate < 0 ) {
1326  if ( actvehicle->damage - actvehicle->typ->autorepairrate > 100 )
1327  toRemove.push_back( *v );
1328  else
1329  actvehicle->damage -= actvehicle->typ->autorepairrate;
1330  }
1331 
1332  if ( actvehicle )
1333  actvehicle->endOwnTurn();
1334 
1335  }
1336 
1337  for ( Player::VehicleList::iterator v = toRemove.begin(); v != toRemove.end(); v++ )
1338  delete *v;
1339 
1340  checkunitsforremoval( this );
1341 
1342  for ( int i = 0; i < 9; ++i )
1343  for ( Player::VehicleList::iterator v = player[i].vehicleList.begin(); v != player[i].vehicleList.end(); ++v )
1344  (*v)->endAnyTurn();
1345 
1346 
1347  if ( replayinfo )
1349 
1350  processJournal();
1351 
1352  sigPlayerTurnHasEnded( player[actplayer] );
1353 
1354 }
1355 
1356 
1358 {
1359  actplayer = 0;
1360  time.set ( time.turn()+1, 0 );
1361 
1362  for ( int y = 0; y < ysize; ++y )
1363  for ( int x = 0; x < xsize; ++x )
1364  getField(x,y)->endRound( time.turn() );
1365 
1366  for (int i = 0; i <= 7; i++) {
1367  if (player[i].exist() && player[i].stat != Player::off ) {
1368 
1369  for ( Player::VehicleList::iterator j = player[i].vehicleList.begin(); j != player[i].vehicleList.end(); j++ )
1370  (*j)->endRound();
1371 
1372  for ( Player::BuildingList::iterator j = player[i].buildingList.begin(); j != player[i].buildingList.end(); j++ )
1373  (*j)->endRound();
1374 
1375  typedef PointerList<ContainerBase::Work*> BuildingWork;
1376  BuildingWork buildingWork;
1377 
1378  for ( Player::BuildingList::iterator j = player[i].buildingList.begin(); j != player[i].buildingList.end(); j++ ) {
1379  if ( (*j)->getEntry().x == 19 && (*j)->getEntry().y == 72 )
1380  logMessage("dummy", "dummy");
1381  ContainerBase::Work* w = (*j)->spawnWorkClasses( false );
1382  if ( w ) {
1383  buildingWork.push_back ( w );
1384  logMessage("ResourceWork", "Building " + (*j)->getEntry().toString() + " has work to do");
1385  } else
1386  logMessage("ResourceWork", "Building " + (*j)->getEntry().toString() + " has no work to do");
1387  }
1388 
1389  for ( Player::VehicleList::iterator j = player[i].vehicleList.begin(); j != player[i].vehicleList.end(); j++ ) {
1390  ContainerBase::Work* w = (*j)->spawnWorkClasses( false );
1391  if ( w ) {
1392  buildingWork.push_back ( w );
1393  // logMessage("ResourceWork", "Vehicle " + ASCString::toString((*j)->networkid ) + " has work to do");
1394  }
1395  // logMessage("ResourceWork", "Vehicle " + ASCString::toString((*j)->networkid ) + " has no work to do");
1396  }
1397 
1398 
1399  bool didSomething;
1400  do {
1401  didSomething = false;
1402  for ( BuildingWork::iterator j = buildingWork.begin(); j != buildingWork.end(); j++ ) {
1403  if ( ! (*j)->finished() )
1404  if ( (*j)->run() )
1405  didSomething = true;
1406  }
1407  } while ( didSomething );
1408  doresearch( this, i );
1409  }
1410  }
1411 
1412  int playerMask = 0;
1413  for ( int i = 0; i < getPlayerCount(); ++i )
1414  if ( !getPlayer(i).exist() )
1415  playerMask |= 1 << i;
1416  MapField::resetView(this,playerMask);
1417 
1419  objectGrowth();
1420 }
1421 
1422 #include "libs/rand/rand_r.h"
1423 #include "libs/rand/rand_r.c"
1424 
1426 {
1427  return asc_rand_r( &randomSeed ) % max;
1428 }
1429 
1430 void GameMap::objectGrowth()
1431 {
1432  typedef vector< pair<MapField*,int> > NewObjects;
1433  map<MapField*,int> remainingGrowthTime;
1434 
1435  NewObjects newObjects;
1436  for ( int y = 0; y < ysize; ++y )
1437  for ( int x = 0; x < xsize; ++x ) {
1438  MapField* fld = getField( x, y );
1439  for ( MapField::ObjectContainer::iterator i = fld->objects.begin(); i != fld->objects.end(); ++i)
1440  if ( i->typ->growthRate > 0 )
1441  for ( int d = 0; d < 6; ++d ) {
1443  if ( fld2 )
1444  if ( i->typ->growOnUnits || ((!fld2->vehicle || fld2->vehicle->height >= chtieffliegend) && !fld2->building ))
1445  if ( fld2->objects.empty() || getgameparameter( cgp_objectGrowOnOtherObjects ) > 0 )
1446  if ( i->remainingGrowthTime > 0 || i->typ->growthDuration <= 0 ) {
1447  double d = i->typ->growthRate * getgameparameter( cgp_objectGrowthMultiplier) / 100;
1448  if ( d > 0 ) {
1449  if ( d > 0.9 )
1450  d = 0.9;
1451 
1452  int p = static_cast<int>(std::ceil ( double(1) / d));
1453  if ( p > 1 )
1454  if ( random ( p ) == 1 )
1455  if ( i->typ->fieldModification[fld2->getWeather()].terrainaccess.accessible( fld2->bdt) > 0 ) {
1456  newObjects.push_back( make_pair( fld2, i->typ->id ));
1457  i->remainingGrowthTime -= 1;
1458  remainingGrowthTime[fld2] = i->remainingGrowthTime;
1459  }
1460  }
1461  }
1462  }
1463  }
1464 
1465  for ( NewObjects::iterator i = newObjects.begin(); i != newObjects.end(); ++i )
1466  if ( !i->first->checkForObject( getobjecttype_byid( i->second ))) {
1467  if ( i->first->addobject ( getobjecttype_byid( i->second ))) {
1468  Object* o = i->first->checkForObject( getobjecttype_byid( i->second ));
1469  assert(o);
1470  o->remainingGrowthTime = remainingGrowthTime[i->first];
1471  }
1472  }
1473 
1474  checkunitsforremoval( this );
1475 }
1476 
1477 sigc::signal<void,GameMap&> GameMap::sigMapDeletion;
1478 sigc::signal<void,GameMap&> GameMap::sigMapCreation;
1479 sigc::signal<void,GameMap*,Player&> GameMap::sigPlayerTurnEndsStatic;
1480 
1482 {
1483  sigMapDeletion( *this );
1484  state = Destruction;
1485 
1486  if ( field )
1487 
1488  for ( int l=0 ;l < xsize * ysize ; l++ ) {
1489  if ( (field[l].bdt & getTerrainBitType(cbbuildingentry)).any() )
1490  delete field[l].building;
1491 
1492 
1493  Vehicle* aktvehicle = field[l].vehicle;
1494  if ( aktvehicle )
1495  delete aktvehicle;
1496 
1497  } /* endfor */
1498 
1499  int i;
1500  for ( i = 0; i <= 8; i++) {
1501  if ( player[i].ai ) {
1502  delete player[i].ai;
1503  player[i].ai = NULL;
1504  }
1505  }
1506 
1507  if ( replayinfo ) {
1508  delete replayinfo;
1509  replayinfo = NULL;
1510  }
1511 
1512  if ( game_parameter ) {
1513  delete[] game_parameter;
1514  game_parameter = NULL;
1515  }
1516 
1517  if ( network ) {
1518  delete network;
1519  network = NULL;
1520  }
1521 
1522  if ( actionRecorder ) {
1523  delete actionRecorder;
1524  actionRecorder = NULL;
1525  }
1526 
1527 #ifdef WEATHERGENERATOR
1528  delete weatherSystem;
1529 #endif
1530 
1531  if ( field ) {
1532  delete[] field;
1533  field = NULL;
1534  }
1535 
1536  delete tasks;
1537  tasks = NULL;
1538 
1539  if (temp) {
1540  delete[] temp;
1541  temp = NULL;
1542  }
1543  if (temp2) {
1544  delete[] temp2;
1545  temp2 = NULL;
1546  }
1547  if (temp3) {
1548  delete[] temp3;
1549  temp3 = NULL;
1550  }
1551  if (temp4) {
1552  delete[] temp4;
1553  temp4 = NULL;
1554  }
1555 }
1556 
1557 /*
1558 gamemap :: ResourceTribute :: tresourcetribute ( )
1559 {
1560  for ( int a = 0; a < 3; a++ )
1561  for ( int b = 0; b < 8; b++ )
1562  for ( int c = 0; c < 8; c++ ) {
1563  avail.resource[a][b][c] = 0;
1564  paid.resource[a][b][c] = 0;
1565  }
1566 }
1567 */
1568 
1570 {
1571  for (int i = 0; i < 8; i++)
1572  for (int j = 0; j < 8; j++)
1573  for (int k = 0; k < 3; k++) {
1574  if ( avail[i][j].resource(k) )
1575  return false;
1576  if ( paid[i][j].resource(k) )
1577  return false;
1578  }
1579 
1580  return true;
1581 }
1582 
1583 const int tributeVersion = 1; // we are counting backwards, -2 is newer than -1
1584 
1586 {
1587  int version = stream.readInt();
1588  bool noVersion;
1589 
1590  if ( -version >= tributeVersion ) {
1591  for ( int a = 0; a < 8; ++a )
1592  for ( int b = 0; b < 8; ++b )
1593  payStatusLastTurn[a][b].read( stream );
1594  noVersion = false;
1595  } else
1596  noVersion = true;
1597 
1598 
1599  for ( int a = 0; a < 3; a++ )
1600  for ( int b = 0; b < 8; b++ )
1601  for ( int c = 0; c < 8; c++ ) {
1602  if ( noVersion ) {
1603  avail[b][c].resource(a) = version;
1604  noVersion = false;
1605  } else
1606  avail[b][c].resource(a) = stream.readInt();
1607  }
1608 
1609  for ( int a = 0; a < 3; a++ )
1610  for ( int b = 0; b < 8; b++ )
1611  for ( int c = 0; c < 8; c++ )
1612  paid[b][c].resource(a) = stream.readInt();
1613 }
1614 
1616 {
1617  stream.writeInt ( -tributeVersion );
1618  for ( int a = 0; a < 8; a++ )
1619  for ( int b = 0; b < 8; b++ )
1620  payStatusLastTurn[a][b].write( stream );
1621 
1622  for ( int a = 0; a < 3; a++ )
1623  for ( int b = 0; b < 8; b++ )
1624  for ( int c = 0; c < 8; c++ )
1625  stream.writeInt ( avail[b][c].resource(a) );
1626 
1627 
1628  for ( int a = 0; a < 3; a++ )
1629  for ( int b = 0; b < 8; b++ )
1630  for ( int c = 0; c < 8; c++ )
1631  stream.writeInt ( paid[b][c].resource(a) );
1632 }
1633 
1634 
1635 
1636 int GameMap::resize( int top, int bottom, int left, int right ) // positive: larger
1637 {
1638  if ( !top && !bottom && !left && !right )
1639  return 0;
1640 
1641  if ( -(top + bottom) > ysize )
1642  return 1;
1643 
1644  if ( -(left + right) > xsize )
1645  return 2;
1646 
1647  if ( (bottom & 1) || (top & 1) )
1648  return 3;
1649 
1650 
1651  int ox1, oy1, ox2, oy2;
1652 
1653  if ( top < 0 ) {
1654  for ( int x = 0; x < xsize; x++ )
1655  for ( int y = 0; y < -top; y++ )
1656  getField(x,y)->deleteeverything();
1657 
1658  oy1 = -top;
1659  } else
1660  oy1 = 0;
1661 
1662  if ( bottom < 0 ) {
1663  for ( int x = 0; x < xsize; x++ )
1664  for ( int y = ysize+bottom; y < ysize; y++ )
1665  getField(x,y)->deleteeverything();
1666 
1667  oy2 = ysize + bottom;
1668  } else
1669  oy2 = ysize;
1670 
1671  if ( left < 0 ) {
1672  for ( int x = 0; x < -left; x++ )
1673  for ( int y = 0; y < ysize; y++ )
1674  getField(x,y)->deleteeverything();
1675  ox1 = -left;
1676  } else
1677  ox1 = 0;
1678 
1679  if ( right < 0 ) {
1680  for ( int x = xsize+right; x < xsize; x++ )
1681  for ( int y = 0; y < ysize; y++ )
1682  getField(x,y)->deleteeverything();
1683  ox2 = xsize + right;
1684  } else
1685  ox2 = xsize;
1686 
1687  for (int s = 0; s < 9; s++)
1688  for ( Player::BuildingList::iterator i = player[s].buildingList.begin(); i != player[s].buildingList.end(); i++ )
1689  (*i)->unchainbuildingfromfield();
1690 
1691 
1692  int newx = xsize + left + right;
1693  int newy = ysize + top + bottom;
1694 
1695  MapField* newfield = new MapField [ newx * newy ];
1696  for ( int i = 0; i < newx * newy; i++ )
1697  newfield[i].setMap ( this, i );
1698 
1699  int x;
1700  for ( x = ox1; x < ox2; x++ )
1701  for ( int y = oy1; y < oy2; y++ ) {
1702  MapField* org = getField ( x, y );
1703  MapField* dst = &newfield[ (x + left) + ( y + top ) * newx];
1704  *dst = *org;
1705  }
1706 
1707  //MapField defaultfield;
1708  //defaultfield.setMap ( this );
1709  //defaultfield.typ = getterraintype_byid ( 30 )->weather[0];
1710 
1711  for ( x = 0; x < left; x++ )
1712  for ( int y = 0; y < newy; y++ )
1713  newfield[ x + y * newx ].typ = getterraintype_byid ( 30 )->weather[0];
1714 
1715  for ( x = xsize + left; x < xsize + left + right; x++ )
1716  for ( int y = 0; y < newy; y++ )
1717  newfield[ x + y * newx ].typ = getterraintype_byid ( 30 )->weather[0];
1718 
1719 
1720  int y;
1721  for ( y = 0; y < top; y++ )
1722  for ( int x = 0; x < newx; x++ )
1723  newfield[ x + y * newx ].typ = getterraintype_byid ( 30 )->weather[0];
1724 
1725  for ( y = ysize + top; y < ysize + top + bottom; y++ )
1726  for ( int x = 0; x < newx; x++ )
1727  newfield[ x + y * newx ].typ = getterraintype_byid ( 30 )->weather[0];
1728 
1729  calculateallobjects( this );
1730 
1731  for ( int p = 0; p < newx*newy; p++ )
1732  newfield[p].setparams();
1733 
1734  delete[] field;
1735  field = newfield;
1736  xsize = newx;
1737  ysize = newy;
1738 
1739  delete[] temp;
1740  delete[] temp2;
1741  delete[] temp3;
1742  delete[] temp4;
1743  temp = new char[newx*newy]();
1744  temp2 = new char[newx*newy]();
1745  temp3 = new int[newx*newy]();
1746  temp4 = new int[newx*newy]();
1747 
1748  for (int s = 0; s < 9; s++)
1749  for ( Player::BuildingList::iterator i = player[s].buildingList.begin(); i != player[s].buildingList.end(); i++ ) {
1750  MapCoordinate mc = (*i)->getEntry();
1751  mc.x += left;
1752  mc.y += top;
1753  (*i)->chainbuildingtofield ( mc );
1754  }
1755 
1756  for (int s = 0; s < 9; s++)
1757  for ( Player::VehicleList::iterator i = player[s].vehicleList.begin(); i != player[s].vehicleList.end(); i++ ) {
1758  (*i)->xpos += left;
1759  (*i)->ypos += top;
1760  }
1761 
1762 
1763  /*
1764  if (xpos + idisplaymap.getscreenxsize() > xsize)
1765  xpos = xsize - idisplaymap.getscreenxsize() ;
1766  if (ypos + idisplaymap.getscreenysize() > ysize)
1767  ypos = ysize - idisplaymap.getscreenysize() ;
1768  */
1769 
1771 
1772  if ( left || top )
1774 
1775  return 0;
1776 }
1777 
1779 {
1780  return terrainTypeRepository.getObject_byID ( id );
1781 }
1782 
1784 {
1785  return objectTypeRepository.getObject_byID ( id );
1786 }
1787 
1789 {
1790  return objectTypeRepository.getObject_byID ( id );
1791 }
1792 
1793 
1795 {
1796  return vehicleTypeRepository.getObject_byID ( id );
1797 }
1798 
1800 {
1801  return vehicleTypeRepository.getObject_byID ( id );
1802 }
1803 
1804 
1806 {
1807  return buildingTypeRepository.getObject_byID ( id );
1808 }
1809 
1811 {
1812  return buildingTypeRepository.getObject_byID ( id );
1813 }
1814 
1816 {
1817  return technologyRepository.getObject_byID ( id );
1818 }
1819 
1820 
1822 {
1823  return terrainTypeRepository.getObject_byPos ( pos );
1824 }
1825 
1827 {
1828  return objectTypeRepository.getObject_byPos ( pos );
1829 }
1830 
1832 {
1833  return vehicleTypeRepository.getObject_byPos ( pos );
1834 }
1835 
1837 {
1838  return buildingTypeRepository.getObject_byPos ( pos );
1839 }
1840 
1842 {
1843  return technologyRepository.getObject_byPos ( pos );
1844 }
1845 
1847 {
1848  return terrainTypeRepository.getNum();
1849 }
1850 
1852 {
1853  return objectTypeRepository.getNum();
1854 }
1855 
1857 {
1858  return vehicleTypeRepository.getNum();
1859 }
1860 
1862 {
1863  return buildingTypeRepository.getNum();
1864 }
1865 
1867 {
1868  return technologyRepository.getNum();
1869 }
1870 
1871 void GameMap::processJournal()
1872 {
1873  if ( !newJournal.empty() ) {
1874  ASCString add = gameJournal;
1875 
1876  char tempstring[100];
1877  char tempstring2[100];
1878  sprintf( tempstring, "#color0# %s ; turn %d #color0##crt##crt#", player[actplayer].getName().c_str(), time.turn() );
1879  sprintf( tempstring2, "#color%d#", getplayercolor ( actplayer ));
1880 
1881  int fnd;
1882  do {
1883  fnd = 0;
1884  if ( !add.empty() ) {
1885  if ( add.find ( '\n', add.length()-1 ) != add.npos ) {
1886  add.erase ( add.length()-1 );
1887  fnd++;
1888  } else
1889  if ( add.length() > 4 )
1890  if ( add.find ( "#crt#", add.length()-5 ) != add.npos ) {
1891  add.erase ( add.length()-5 );
1892  fnd++;
1893  }
1894  }
1895 
1896  } while ( fnd ); /* enddo */
1897 
1898  add += tempstring2;
1899  add += newJournal;
1900  add += tempstring;
1901 
1902  gameJournal = add;
1903  newJournal.erase();
1904 
1906  }
1907 
1908 }
1909 
1910 
1912 {
1913  time.set ( 1, 0 );
1914 
1915  for ( int j = 0; j < 8; j++ )
1916  player[j].queuedEvents = 1;
1917 
1918  levelfinished = false;
1919 
1920  for ( int n = 0; n< 8; n++ ) {
1921  bi_resource[n].energy = 0;
1922  bi_resource[n].material = 0;
1923  bi_resource[n].fuel = 0;
1925  }
1926 
1927 
1928 
1929  #ifndef karteneditor
1930  actplayer = -1;
1931  #else
1932  actplayer = 0;
1933  #endif
1934 
1935  setupResources();
1936 
1937  // calling signal
1938  newRound();
1939 }
1940 
1942 {
1943  for ( GameMap::UnitProduction::IDsAllowed::iterator i = idsAllowed.begin(); i != idsAllowed.end(); i ++ )
1944  if( *i == id )
1945  return true;
1946 
1947  return false;
1948 }
1949 
1951 {
1953 
1954  if ( this->player[player].ai ) {
1955  if ( this->playerAiRunning[player] ) {
1956  if ( c < this->playerAiVision[player] )
1957  c = this->playerAiVision[player];
1958  } else
1959  if ( c < visible_ago )
1960  c = visible_ago;
1961  }
1962  return c;
1963 }
1964 
1965 void GameMap::setPlayerMode( Player& p, State s )
1966 {
1967  p.getParentMap()->state = s;
1968 }
1969 
1971 {
1972  int size = sizeof(*this);
1973  if( replayinfo )
1974  for ( int i = 0; i < 8; ++i ) {
1975  if ( replayinfo->guidata[i] )
1976  size += replayinfo->guidata[i]->getMemoryFootprint();
1977  if ( replayinfo->map[i] )
1978  size += replayinfo->map[i]->getMemoryFootprint();
1979  }
1980  return size;
1981 }
1982 
1983 
1984 
1985 void GameMap::operator= ( const GameMap& map )
1986 {
1987  throw ASCmsgException ( "GameMap::operator= undefined");
1988 }
1989 
1990 
1991 void AiThreat :: write ( tnstream& stream )
1992 {
1993  const int version = 1000;
1994  stream.writeInt ( version );
1995  stream.writeInt ( threatTypes );
1996  for ( int i = 0; i < threatTypes; i++ )
1997  stream.writeInt ( threat[i] );
1998 }
1999 
2000 void AiThreat:: read ( tnstream& stream )
2001 {
2002 
2003  int version = stream.readInt();
2004  if ( version == 1000 ) {
2005  threatTypes = stream.readInt();
2006  for ( int i = 0; i < threatTypes; i++ )
2007  threat[i] = stream.readInt();
2008  }
2009 }
2010 
2011 
2012 void AiValue :: write ( tnstream& stream )
2013 {
2014  const int version = 2000;
2015  stream.writeInt ( version );
2016  stream.writeInt ( value );
2017  stream.writeInt ( addedValue );
2018  threat.write ( stream );
2019  stream.writeInt ( valueType );
2020 }
2021 
2022 void AiValue:: read ( tnstream& stream )
2023 {
2024  int version = stream.readInt();
2025  if ( version == 2000 ) {
2026  value = stream.readInt ( );
2027  addedValue= stream.readInt ( );
2028  threat.read ( stream );
2029  valueType = stream.readInt ( );
2030  }
2031 }
2032 
2033 const int aiParamVersion = 3002;
2034 
2036 {
2037  stream.writeInt ( aiParamVersion );
2038  stream.writeInt ( lastDamage );
2039  stream.writeInt ( damageTime.abstime );
2040  stream.writeInt ( dest.x );
2041  stream.writeInt ( dest.y );
2042  stream.writeInt ( dest.getNumericalHeight() );
2043  stream.writeInt ( dest_nwid );
2044  stream.writeInt ( data );
2045  AiValue::write( stream );
2046  stream.writeInt ( task );
2047  stream.writeInt ( jobPos );
2048  stream.writeInt ( jobs.size() );
2049  for ( int i = 0; i < jobs.size(); i++ )
2050  stream.writeInt( jobs[i] );
2051  stream.writeInt ( resetAfterJobCompletion );
2052 }
2053 
2054 void AiParameter::read ( tnstream& stream )
2055 {
2056  int version = stream.readInt();
2057  if ( version >= 3000 && version <= aiParamVersion ) {
2058  lastDamage = stream.readInt();
2059  damageTime.abstime = stream.readInt();
2060  int x = stream.readInt();
2061  int y = stream.readInt();
2062  int z = stream.readInt();
2063  dest.setnum ( x, y, z );
2064  dest_nwid = stream.readInt();
2065  data = stream.readInt();
2066  AiValue::read( stream );
2067  task = (Task) stream.readInt();
2068  if ( version == 3000 ) {
2069  jobs.clear();
2070  jobs.push_back ( Job( stream.readInt() ));
2071  } else {
2072  jobPos = stream.readInt();
2073  int num = stream.readInt();
2074  jobs.clear();
2075  for ( int i = 0; i < num; i++ )
2076  jobs.push_back ( Job( stream.readInt() ));
2077  }
2078  if ( version >= 3002 )
2079  resetAfterJobCompletion = stream.readInt();
2080  else
2081  resetAfterJobCompletion = false;
2082  }
2083 }
2084 
2085 void AiThreat :: reset ( void )
2086 {
2087  for ( int i = 0; i < aiValueTypeNum; i++ )
2088  threat[i] = 0;
2089 }
2090 
2092 {
2093  reset( _unit );
2094 }
2095 
2096 
2098 {
2099  dest.setnum ( -1, -1, -1 );
2100  dest_nwid = -1;
2101  task = tsk_nothing;
2102 }
2103 
2104 void AiParameter::addJob ( Job j, bool front )
2105 {
2106  if ( front )
2107  jobs.insert ( jobs.begin(), j );
2108  else
2109  jobs.push_back ( j );
2110 }
2111 
2112 void AiParameter::setJob ( const JobList& jobs )
2113 {
2114  this->jobs = jobs;
2115 }
2116 
2118 {
2119  int pos = 0;
2120  for ( JobList::iterator i = jobs.begin(); i != jobs.end(); ++i, ++pos )
2121  if ( *i == j ) {
2122  jobPos = pos;
2123  return;
2124  }
2125 
2126  addJob ( j, true );
2127 }
2128 
2129 
2131 {
2132  return find ( jobs.begin(), jobs.end(), j ) != jobs.end();
2133 }
2134 
2136 {
2137  AiValue::reset ( getFirstBit( unit->height ) );
2138 }
2139 
2140 
2142 {
2143  unit = _unit;
2144  lastDamage = unit->damage;
2145  AiValue::reset ( getFirstBit( _unit->height ) );
2146  data = 0;
2147 
2148  clearJobs();
2149  resetTask();
2150  resetAfterJobCompletion = false;
2151 }
2152 
2154 {
2155  jobPos++;
2156 }
2157 
2159 {
2160  jobPos = 0;
2161 }
2162 
2164 {
2165  jobs.clear();
2166  jobPos = 0;
2167 }
2168 
2169 
2170 
2171 
2173 {
2174  for (int i = 0; i < 8; i++) {
2175  guidata[i] = NULL;
2176  map[i] = NULL;
2177  }
2178  actmemstream = NULL;
2180 }
2181 
2183 {
2184  bool loadgui[8];
2185  bool loadmap[8];
2186 
2187  for ( int i = 0; i < 8; i++ )
2188  loadgui[i] = stream.readInt();
2189 
2190  for ( int i = 0; i < 8; i++ )
2191  loadmap[i] = stream.readInt();
2192 
2193  stream.readInt(); // was: actmemstream
2194 
2195  for ( int i = 0; i < 8; i++ ) {
2196  if ( loadgui[i] ) {
2197  guidata[i] = new MemoryStreamStorage;
2198  guidata[i]->readfromstream ( &stream );
2199  } else
2200  guidata[i] = NULL;
2201 
2202  if ( loadmap[i] ) {
2203  map[i] = new MemoryStreamStorage;
2204  map[i]->readfromstream ( &stream );
2205  } else
2206  map[i] = NULL;
2207  }
2208 
2209  actmemstream = NULL;
2210 }
2211 
2213 {
2214  for ( int i = 0; i < 8; i++ )
2215  stream.writeInt ( guidata[i] != NULL );
2216 
2217  for ( int i = 0; i < 8; i++ )
2218  stream.writeInt ( map[i] != NULL );
2219 
2220  stream.writeInt ( actmemstream != NULL );
2221 
2222  for ( int i = 0; i < 8; i++ ) {
2223  // printf("GameMap :: ReplayInfo :: write i=%d\n", i );
2224  if ( guidata[i] )
2225  guidata[i]->writetostream ( &stream );
2226 
2227  if ( map[i] )
2228  map[i]->writetostream ( &stream );
2229  }
2230 }
2231 
2233 {
2234  if ( actmemstream ) {
2235  delete actmemstream;
2236  actmemstream = NULL;
2237  }
2238 }
2239 
2241 {
2242  for (int i = 0; i < 8; i++) {
2243  if ( guidata[i] ) {
2244  delete guidata[i];
2245  guidata[i] = NULL;
2246  }
2247  if ( map[i] ) {
2248  delete map[i];
2249  map[i] = NULL;
2250  }
2251  }
2252  if ( actmemstream ) {
2253  delete actmemstream ;
2254  actmemstream = NULL;
2255  }
2256 }
2257 
2259  // name default min max EventChangable legace description
2260  { "LifetimeTrack", 1, 1, maxint, true, false, "lifetime of tracks"},// cgp_fahrspur
2261  { "LifetimeBrokenIce", 2, 1, maxint, true, false, "freezing time of icebreaker fairway"}, // cgp_eis,
2262  { "MoveFromInaccessibleFields", 1, 0, 1, true, false, "move vehicles from unaccessible fields"}, // cgp_movefrominvalidfields,
2263  { "BuildingConstructionFactorMaterial", 100, 0, maxint, true, false, "building construction material factor (percent)"}, // cgp_building_material_factor,
2264  { "BuildingConstructionFactorEnergy", 100, 0, maxint, true, false, "building construction fuel factor (percent)"}, // cgp_building_fuel_factor,
2265  { "ForbidBuildingConstruction", 0, 0, 1, true, false, "forbid construction of buildings"}, // cgp_forbid_building_construction,
2266  { "LimitUnitProductionByUnit", 0, 0, 2, true, false, "limit construction of units by other units"}, // cgp_forbid_unitunit_construction,
2267  { "Bi3Training", 0, 0, maxunitexperience, true, false, "use BI3 style training factor "}, // cgp_bi3_training,
2268  { "MaxMinesOnField", 1, 0, maxint, true, false, "maximum number of mines on a single field"}, // cgp_maxminesonfield,
2269  { "LifetimeAntipersonnelMine", 0, 0, maxint, true, false, "lifetime of antipersonnel mine"}, // cgp_antipersonnelmine_lifetime,
2270  { "LifetimeAntiTankMine", 0, 0, maxint, true, false, "lifetime of antitank mine"}, // cgp_antitankmine_lifetime,
2271  { "LifetimeAntiSubMine", 0, 0, maxint, true, false, "lifetime of antisub mine"}, // cgp_mooredmine_lifetime,
2272  { "LifetimeAntiShipMine", 0, 0, maxint, true, false, "lifetime of antiship mine"}, // cgp_floatingmine_lifetime,
2273  { "BuildingArmorFactor", 100, 1, maxint, true, false, "building armor factor (percent)"}, // cgp_buildingarmor,
2274  { "MaxBuildingRepair", 100, 0, 100, true, false, "max building damage repair / turn"}, // cgp_maxbuildingrepair,
2275  { "BuildingRepairCostIncrease", 100, 1, maxint, true, false, "building repair cost increase (percent)"}, // cgp_buildingrepairfactor,
2276  { "GlobalFuel", 1, 0, 1, true, false, "fuel globally available (BI Resource Mode)"}, // cgp_globalfuel,
2277  { "MaxTrainingExperience", maxunitexperience, 0, maxunitexperience, true, false, "maximum experience that can be gained by training"}, // cgp_maxtrainingexperience,
2278  { "InitialMapVisibility", 0, 0, 2, true, false, "initial map visibility"}, // cgp_initialMapVisibility,
2279  { "AttackPower", 40, 1, 100, true, false, "attack power (EXPERIMENTAL!)"}, // cgp_attackPower,
2280  { "JammingAmplifier", 100, 0, 1000, true, false, "jamming amplifier (EXPERIMENTAL!)"}, // cgp_jammingAmplifier,
2281  { "JammingSlope", 10, 0, 100, true, false, "jamming slope (EXPERIMENTAL!)"}, // cgp_jammingSlope,
2282  { "SupervisorMapSave", 0, 0, 1, false, false, "The Supervisor may save a game as new map (spying!!!)"}, // cgp_superVisorCanSaveMap,
2283  { "ObjectsDestroyedByTerrain", 1, 0, 1, true, false, "objects can be destroyed by terrain"}, // cgp_objectsDestroyedByTerrain,
2284  { "TrainingIncrement", 2, 1, maxunitexperience, true, false, "training centers: training increment"}, // cgp_trainingIncrement,
2285  { "ExperienceEffectDivisorAttack", 1, 1, 10, false, false, "experience effect divisor for attack"}, // gp_experienceDivisorAttack
2286  { "DisableDirectView", 1, 0, 1, false, false, "disable direct View"}, // cgp_disableDirectView
2287  { "DisableUnitTrade", 0, 0, 1, false, false, "disable transferring units/buildings to other players"}, // cgp_disableUnitTransfer
2288  { "ExperienceEffectDivisorDefense", 1, 1, 10, false, false, "experience effect divisor for defense"}, // cgp_experienceDivisorDefense
2289  { "DebugGameEvents", 0, 0, 2, true, false, "debug game events"}, // cgp_debugEvents
2290  { "ObjectGrowthRate", 0, 0, maxint, true, false, "Object growth rate (percentage)" }, // cgp_objectGrowthMultiplier
2291  { "ObjectsGrowOnOtherObjects", 1, 0, 1, false, false, "Objects can grow on fields with other objects" }, // cgp_objectGrowOnOtherObjects
2292  { "ResearchOutputMultiplier", 1, 1, maxint, false, false, "Multiplies the research output of all labs" }, // cgp_researchOutputMultiplier
2293  { "ProduceOnlyResearchedStuffInternally", 0, 0, 1, true, false, "Produce only researched stuff internally" },
2294  { "ProduceOnlyResearchedStuffExternally", 1, 0, 1, true, false, "Produce only researched stuff externally" },
2295  { "ExperienceAt90PercentBonus", 25, 3, 1000, false, false, "Experience level to achieve 90% bonus" }, // cgp_experienceAt90percentbonus
2296  { "maxAttackExperienceBonus", 100, 0, 1000, false, false, "Max attack bonus for experience (percent)" }, // maxAttackExperienceBonus
2297  { "maxDefenseExperienceBonus", 100, 0, 1000, false, false, "Max defense bonus for experience (percent)" } // maxDefenseExperienceBonus
2298 };
2299 
Vehicle * findUnit(int nwid, bool recursive=true) const
searches for a the unit in carrier and optionally all inner carriers
void startGame()
prepares a new game for being played
Definition: gamemap.cpp:1911
ASCString getUnitReference(Vehicle *veh)
Definition: vehicle.cpp:1770
TerrainType::Weather * typ
the terraintype of the field
Definition: mapfield.h:38
int fuel
Definition: typen.h:101
int queuedEvents
if ASC should check all events for fullfilled triggers, this variable will be set to true...
Definition: player.h:193
static sigc::signal< void, GameMap *, Player & > sigPlayerTurnEndsStatic
Definition: gamemap.h:502
int id
an identification for identifying a map in the chain of maps that make up a campaign ...
Definition: gamemap.h:224
An in-memory storage of streamed data.
Definition: basestrm.h:172
void closeLogging()
Close the replay logging at the end of a players or the ai's turn.
Definition: gamemap.cpp:2232
ASCString codeWord
the codeword for accessing a map in a campaign
Definition: gamemap.h:210
int getVehicleTypeNum()
Definition: gamemap.cpp:1856
ItemRepositoryLoader< ObjectType > objectTypeRepository("objecttype")
void cleartemps(int b=-1, int value=0)
Definition: gamemap.cpp:964
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
MapCoordinate & getCursor()
Definition: gamemap.cpp:933
void deleteeverything(void)
deletes everything placed on the field
Definition: mapfield.cpp:295
void writeData(tnstream &stream) const
Definition: gamemap.cpp:1150
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
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
void read(tnstream &stream)
Definition: typen.cpp:384
int getNumericVersion()
Definition: strtmesg.cpp:37
void clear(bool allImages=false)
Definition: gamemap.cpp:201
static sigc::signal< void > generationComplete
Definition: gamemap.h:168
map accessing and usage routines used by ASC and the mapeditor
void write(tnstream &stream) const
Definition: password.cpp:106
miscellaneous functions which are used by ASC and all its tools
const Technology * gettechnology_bypos(int pos)
Definition: gamemap.cpp:1841
void drawNextField(bool signalOnCompletion=true)
Definition: gamemap.cpp:128
const int aiParamVersion
Definition: gamemap.cpp:2033
int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
Definition: vehicle.cpp:328
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
void logMessage(const ASCString &category, const ASCString &message)
static int calcFuelUsage(const Vehicle *veh)
Definition: vehicle.cpp:1781
Vehicle * vehicle
Definition: mapfield.h:89
int random(int max)
generated a pseudo-random number with the map-internal seed
Definition: gamemap.cpp:1425
const int gameparameternum
The number of game paramters that can be specified for each map.
Definition: gamemap.h:75
int getNewNetworkID()
returns a new and unique ID
Definition: gamemap.cpp:1139
Definition: player.h:53
int energy
Definition: typen.h:99
bool __loadunsentmessage
Definition: gamemap.h:351
void setParentMap(GameMap *map, int pos)
Definition: player.cpp:203
Properties properties
general key/value storage, primarily for Lua scripts
Definition: gamemap.h:572
class GameMap::UnitProduction unitProduction
bool __loadunreadmessage
Definition: player.h:182
Uint8 levelfinished
Definition: gamemap.h:321
void read(tnstream &stream)
Definition: player.cpp:321
void read(tnstream &stream)
Definition: password.cpp:100
BaseAI * ai
if the player is run by an AI, this is the pointer to it
Definition: player.h:144
int abstime
Definition: typen.h:183
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
static void lighten(Surface &s, const SPoint &pos, float value)
void write(tnstream &stream) const
Definition: typen.cpp:374
const GameMap * getParentMap() const
Definition: player.h:114
class TerrainType * pterraintype
Definition: terraintype.h:72
void write(tnstream &stream) const
bool ___loadtitle
Definition: gamemap.h:361
bool __loadoldmessage
Definition: player.h:186
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
int getFirstBit(int zahl)
Count the number of zero bits on the LSB side of "zahl".
Definition: misc.cpp:45
bool ___loadLegacyNetwork
Definition: gamemap.h:361
virtual void write(tnstream &stream) const =0
static const Uint32 transparent
Definition: surface.h:65
void blit(Surface &s, const SPoint &pos, int layer=0) const
void write(tnstream &stream)
Definition: gamemap.cpp:2012
void readData(tnstream &stream)
Definition: gamemap.cpp:1145
DiplomaticStateVector diplomacy
Definition: player.h:209
void read(tnstream &stream)
Definition: player.cpp:145
int turn() const
Definition: typen.h:181
int getOwner() const
returns the number of the player this vehicle/building belongs to
MemoryStreamStorage * guidata[8]
Definition: gamemap.h:374
ContainerBase * getContainer(int nwid)
Definition: gamemap.cpp:1231
VisibilityStates
the different states that a player's view on a field can have
Definition: typen.h:403
static SPoint map2surface(const MapCoordinate &pos)
const int tributeVersion
Definition: gamemap.cpp:1583
int getBuildingTypeNum()
Definition: gamemap.cpp:1861
void write(tnstream &stream)
Definition: research.cpp:698
int getMemoryFootprint() const
Definition: basestrm.h:192
void beginTurn()
called when a player starts his turn
Definition: gamemap.cpp:1263
bool hasJob(Job j)
Definition: gamemap.cpp:2130
vector< AiParameter::Job > JobList
class GameMap::ArchivalInformation archivalInformation
OverviewMapHolder(GameMap &gamemap)
Definition: gamemap.cpp:73
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
RandomGenerator(int seedValue)
Definition: gamemap.cpp:44
const Surface & getOverviewMap(bool complete=true)
returns the overview surface for the map.
Definition: gamemap.cpp:180
void read(tnstream &stream)
Definition: typen.h:213
void checkunitsforremoval(GameMap *gamemap)
removes all units that cannot exist any more, either due to invalid terrin (like tanks on melting ice...
Definition: spfst.cpp:261
Events events
Definition: gamemap.h:291
static Surface createSurface(int width, int height, SDLmm::Color color=255)
Definition: surface.cpp:387
bool __loadreplayinfo
a helper variable to store some information during the loading process. No usage outside.
Definition: gamemap.h:399
#define chhochfliegend
Definition: typen.h:416
ItemRepositoryLoader< BuildingType > buildingTypeRepository("buildingtype")
ContainerBase * getContainer()
returns a pointer to the ContainerBase of the field or NULL if there is none
Definition: mapfield.cpp:331
Global platform dependant definitions. This file just branches to the platform specific files in thei...
The interface for all kinds of IO stream.
Resources getTank() const
returns the resources that the unit is carrying
Definition: vehicle.cpp:378
a single field of the map
Definition: mapfield.h:26
if(!yyg->yy_init)
Definition: scanner.cpp:695
static void fill(Surface &s, const SPoint &pos, SDLmm::Color color)
A list that stores pointers, but deletes the objects (and not only the pointers) on destruction...
Definition: basictypes.h:39
GameTime lastjournalchange
Definition: gamemap.h:413
void setNewHeight()
Definition: gamemap.cpp:2135
int getTerrainTypeNum()
Definition: gamemap.cpp:1846
struct GameMap::Weather weather
ItemRepositoryLoader< Technology > technologyRepository("technology")
bool ___loadJournal
temporary variables for loading the map
Definition: gamemap.h:361
void setgameparameter(GameParameter num, int value)
Definition: gamemap.cpp:1058
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
void setJob(const JobList &jobs)
Definition: gamemap.cpp:2112
char * temp2
Definition: gamemap.h:188
pterraintype getterraintype_bypos(int pos)
Definition: gamemap.cpp:1821
void setName(const ASCString &name)
Definition: player.h:160
void setNextJob()
Definition: gamemap.cpp:2153
int height
the current level of height ( BITMAPPED ! )
Definition: vehicle.h:118
static void resetView(GameMap *gamemap, int playersToReset)
Definition: mapfield.cpp:413
void write(tnstream &stream)
Definition: gamemap.cpp:1615
ASCString gameJournal
Definition: gamemap.h:365
const int aiValueTypeNum
how many different target types are there?
const OverviewMapImage * getQuickView()
void read(tnstream &stream)
int getWeather()
the weather that is on this field
Definition: mapfield.cpp:370
char * temp
Definition: gamemap.h:187
int getPlayerView() const
the player which is currently viewing the map.
Definition: gamemap.cpp:1007
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
bool playerAiRunning[9]
Definition: gamemap.h:192
virtual float readFloat(void)
Reads a flaot variable.
Definition: basestrm.cpp:328
void read(tnstream &stream)
virtual void read(tnstream &stream)=0
int eventpassed(int saveas, int action, int mapid)
Definition: gamemap.cpp:1111
static void checkGame(GameMap *game)
int getObjectTypeNum()
Definition: gamemap.cpp:1851
int resize(int top, int bottom, int left, int right)
resizes the map. Positive numbers enlarge the map in that direction
Definition: gamemap.cpp:1636
GameMap(void)
Definition: gamemap.cpp:223
struct GameMap::PreferredFilenames preferredFileNames
void read(tnstream &stream)
Definition: gamemap.cpp:2182
bool fieldvisiblenow(const MapField *pe, Vehicle *veh, int player)
{@
Definition: spfst.cpp:399
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
const int tmapversion
Definition: gamemap.cpp:295
sigc::signal< void, Player & > sigPlayerTurnEnds
Definition: gamemap.h:496
int getMemoryFootprint() const
Definition: gamemap.cpp:1970
int messageid
each message has an identification number (which is incremented with each message) for referencing it...
Definition: gamemap.h:358
void clearJobs()
Definition: gamemap.cpp:2163
void setState(PlayerID towardsPlayer, DiplomaticStates s)
Definition: player.cpp:115
void read(tnstream &stream)
Definition: gamemap.cpp:2054
The value of a unit for the AI.
VehicleList vehicleList
a list of all units
Definition: player.h:135
int gameparameter_num
Definition: gamemap.h:425
The class describing properties that are common to all buildings of a certain kind.
Definition: buildingtype.h:35
bool updateField(const MapCoordinate &pos)
Definition: gamemap.cpp:97
void read(tnstream &stream)
Definition: gamemap.cpp:1585
ItemRepositoryLoader< VehicleType > vehicleTypeRepository("vehicletype")
int graphicset
the ID of the graphic set
Definition: gamemap.h:424
Resources bi_resource[8]
in BI resource mode ( see _resourcemode , isResourceGlobal ) , this is where the globally available r...
Definition: gamemap.h:416
void read(tnstream &stream)
Definition: gamemap.cpp:2022
ActionRecorder * actionRecorder
Definition: gamemap.h:391
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)
void endRound()
called between endTurn() of player 7 and the next turn of player 0
Definition: gamemap.cpp:1357
void read(tnstream &stream)
Definition: research.cpp:621
int stopRecordingActions
if stopRecordingActions > 0 then no actions will be recorded.
Definition: gamemap.h:379
void reset(void)
Definition: gamemap.cpp:2085
sigc::signal< void, Player & > sigPlayerTurnHasEnded
Definition: gamemap.h:497
bool idleHandler()
Definition: gamemap.cpp:88
ItemRepositoryLoader< TerrainType > terrainTypeRepository("terraintype")
void write(tnstream &stream) const
Definition: typen.h:212
enum Player::PlayerStatus stat
#define chtieffliegend
Definition: typen.h:414
pterraintype getterraintype_byid(int id)
Definition: gamemap.cpp:1778
class GameMap::ResourceTribute tribute
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
Coordinate on the twodimensional map.
Definition: typen.h:202
void setMultiplier(int m)
Definition: research.h:231
bool ___loadNewJournal
Definition: gamemap.h:361
Definition of THE central asc class: GameMap.
BuildingType * getbuildingtype_bypos(int pos)
Definition: gamemap.cpp:1836
GameParameterSettings gameParameterSettings[gameparameternum]
Definition: gamemap.cpp:2258
void setparams(ObjectRemovalStrategy *objectRemovalStrategy)
recalculates the terrain properties, movemalus etc from the terraintype and the objects,
Definition: mapfield.cpp:605
bool isResourceGlobal(int resource)
Definition: gamemap.cpp:1024
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
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
MapCoordinate cursorPos
Definition: player.h:207
void endOwnTurn(void)
hook that is called when a player ends his turn
Definition: vehicle.cpp:478
The interface for the buildingtype class.
void setnum(int _x, int _y, int numericalz)
Definition: typen.h:250
sigc::signal< void, Player & > sigPlayerTurnBegins
Definition: gamemap.h:493
virtual int readdata(void *buf, int size, bool excpt=true)=0
Reads data from the stream.
void unregisterUnitNetworkID(Vehicle *veh)
Definition: gamemap.cpp:1131
represents a change of a MapCoordinate
Definition: typen.h:189
bool avail
is this a campaign map?
Definition: gamemap.h:221
AbstractTaskContainer * tasks
Definition: gamemap.h:394
void breakUndo()
to be called when some modification to the map is taking place that is not recorded by undo ...
int getmaxwindspeedforunit(const Vehicle *eht)
returns the maximum wind speed that the unit can endure
Definition: spfst.cpp:332
int _resourcemode
how are Resources handled on this map 0= "ASC mode": complex system with mineral resources etc 1= "BI...
Definition: gamemap.h:250
int getplayercolor(int i)
Definition: dlg_box.cpp:303
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
void write(tnstream &stream) const
Definition: player.cpp:163
void restartJobs()
Definition: gamemap.cpp:2158
int material
Definition: typen.h:100
void resetTask()
Definition: gamemap.cpp:2097
VehicleType * getvehicletype_bypos(int pos)
Definition: gamemap.cpp:1831
int getTechnologyNum()
Definition: gamemap.cpp:1866
list< Vehicle * > VehicleList
Definition: player.h:133
ASCString email
Definition: player.h:211
int height() const
Definition: gamemap.h:204
DI_Color getColor() const
Definition: player.cpp:249
void read(tnstream &stream)
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
VehicleType * getvehicletype_byid(int id)
Definition: gamemap.cpp:1794
BuildingType * getbuildingtype_byid(int id)
Definition: gamemap.cpp:1805
int autorepairrate
the damage this unit can repair itself automatically each turn.
Definition: vehicletype.h:251
int * temp4
Definition: gamemap.h:190
SDLmm::SPoint SPoint
Definition: surface.h:27
Vehicle * getUnit(int x, int y, int nwid)
Definition: gamemap.cpp:1215
Player player[9]
Definition: gamemap.h:253
VisibilityStates fieldVisibility(const MapField *pe)
}@
Definition: spfst.cpp:440
void chainToMap(GameMap *_map, int _player)
Definition: research.h:211
bool directaccess
can the map be loaded just by knowing its filenmae? If 0, the codeword is required ...
Definition: gamemap.h:227
IDsAllowed idsAllowed
Definition: gamemap.h:451
void read(tnstream &stream)
Definition: gamemap.cpp:2000
void write(tnstream &stream)
Definition: gamemap.cpp:711
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
void doresearch(GameMap *actmap, int player)
Definition: buildings.cpp:799
OverviewMapHolder overviewMapHolder
Definition: gamemap.h:532
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
sigc::signal< bool > idleEvent
Definition: spfst.cpp:53
int remainingGrowthTime
Definition: objects.h:52
int getgameparameter(GameParameter num) const
Definition: gamemap.cpp:1047
void write(tnstream &stream) const
Definition: player.cpp:331
BuildingList buildingList
a list of all units
Definition: player.h:139
const int maxunitexperience
The maximum experience value of a Vehicle.
Definition: typen.h:73
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
void registerUnitNetworkID(Vehicle *veh)
Definition: gamemap.cpp:1124
Interface for all the dialog boxes used by the game and the mapeditor.
PackageData * packageData
Definition: gamemap.h:582
Research research
the status of the scientific research
Definition: player.h:142
MapField * field
the array of fields
Definition: gamemap.h:204
int & resource(int type)
Definition: typen.h:105
int xpos
the position on the map
Definition: vehicle.h:124
ASCString maptitle
the title of the map
Definition: gamemap.h:213
time_t date
Definition: player.h:200
int eventID
Definition: gamemap.h:288
Definition: player.h:53
void calculateAllObjects(void)
Definition: gamemap.cpp:1002
bool __loadmessages
Definition: gamemap.h:355
const VehicleType * typ
Definition: vehicle.h:83
PlayerStatus
the status of the player
Definition: player.h:150
ActionContainer actions
Records all action that have been done for undo/redo purposes.
Definition: gamemap.h:390
AiParameter(Vehicle *_unit)
Definition: gamemap.cpp:2091
void startUpdate()
Definition: gamemap.cpp:194
void readfromstream(tnstream *stream)
read persisted contents from another stream
Definition: basestrm.cpp:2316
Building * building
Definition: mapfield.h:102
~GameMap()
Definition: gamemap.cpp:1481
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 read_struct(tnstream &stream, bool merge=false)
Definition: research.cpp:634
virtual void readpchar(char **pc, int maxlength=0)
Reads a string.
Definition: basestrm.cpp:390
bool existanceAtBeginOfTurn
did the player exist when the turn started? Required for checking if a player has been terminated ...
Definition: player.h:131
Password supervisorpasswordcrc
Definition: gamemap.h:368
#define maxint
Definition: typen.h:462
GameMap * actmap
Definition: spfst.cpp:64
int * game_parameter
Definition: gamemap.h:426
Interface to the event handling of ASC.
GameTransferMechanism * network
Definition: gamemap.h:576
enum GameMap::State state
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
bool exist(const ASCString &s)
does a file s exist (wildcards allowed)
Definition: basestrm.cpp:2444
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
sigc::signal< void, const MapCoodinateVector & > sigCoordinateShift
called when the map is resized and all coordinates have to be adjusted
Definition: gamemap.h:505
an instance of an object type (ObjectType) on the map
Definition: objects.h:46
unsigned int getPercentage()
Definition: gamemap.cpp:53
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
virtual void writeData(tnstream &stream)=0
void setPlayerView(int player)
Definition: gamemap.cpp:1017
int mineralResourcesDisplayed
Definition: gamemap.h:434
Password passwordcrc
the Password required for playing this player
Definition: player.h:160
virtual void readData(tnstream &stream)=0
PlayTimeContainer playTime
The time this player ended his turns. This is very informative in email games with > 2 players to fin...
Definition: player.h:205
MapCoordinate3D dest
void addJob(Job j, bool front=false)
Definition: gamemap.cpp:2104
ObjectType * getobjecttype_bypos(int pos)
Definition: gamemap.cpp:1826
ObjectType * getobjecttype_byid(int id)
Definition: gamemap.cpp:1783
sigc::signal< void > newRound
called when a new round starts (after switching from player 7 to player 0 )
Definition: gamemap.h:508
ASCString nativeMessageLanguage
the language string that describes the messages which are saved in the game events For example: en_US...
Definition: gamemap.h:432
void write(tnstream &stream)
Definition: gamemap.cpp:1991
bool __loadsentmessage
Definition: player.h:190
static void fillCenter(Surface &s, const SPoint &pos, SDLmm::Color color)
void write(tnstream &stream)
VisibilityStates playerAiVision[9]
Definition: gamemap.h:193
const Cargo & getCargo() const
void reset(Vehicle *_unit)
Definition: gamemap.cpp:2141
static GameTransferMechanism * read(tnstream &stream)
int ypos
Definition: vehicle.h:124
void endRound(int turn)
Definition: mapfield.cpp:129
int getPlayerCount() const
Definition: gamemap.h:255
unsigned int getRandomValue(int upperLimit)
Definition: gamemap.cpp:57
int ASCversion
the version of ASC that this player has used to make his last turn
Definition: player.h:196
int networkid
a unique identification of the unit that is used everywhere in ASC (and not only the network protocol...
Definition: vehicle.h:140
void setMap(GameMap *gamemap_, int index_)
Definition: mapfield.h:37
void endTurn()
called after a player ends his turn
Definition: gamemap.cpp:1281
void write(tnstream &stream)
Definition: gamemap.cpp:2035
VisibilityStates getInitialMapVisibility(int player)
Definition: gamemap.cpp:1950
bool exist() const
does the player exist at all
Definition: player.cpp:313
Surface Duplicate() const
Definition: surface.cpp:85
void reset(int _valueType)
void write(tnstream &stream) const
ReplayInfo * replayinfo
Definition: gamemap.h:396
GameTime time
the time in the game, mesured in a turns and moves
Definition: gamemap.h:235
MemoryStream * actmemstream
Definition: gamemap.h:376
const int maxwindspeed
Wind with its maximum strength of 255 is moving this distance per turn.
Definition: typen.h:501
MapCoordinate3D getNeighbouringFieldCoordinate(const MapCoordinate3D &pos, int direc)
returns the coordinate of the field that is adjecent to the given field in the direction of direc ...
bool resetAfterJobCompletion
static sigc::signal< void, GameMap & > sigMapCreation
Definition: gamemap.h:500
ObjectContainer objects
Definition: mapfield.h:124
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
const Technology * gettechnology_byid(int id)
Definition: gamemap.cpp:1815
static void clearmap(GameMap *actmap)
Definition: gamemap.cpp:216
bool continueplaying
if a player has won a singleplayer map, but wants to continue playing without any enemies...
Definition: gamemap.h:512
int * temp3
Definition: gamemap.h:189
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
MapField * getField(int x, int y)
Definition: gamemap.h:465