Advanced Strategic Command
gameevents.cpp
Go to the documentation of this file.
1 
5 /*
6  This file is part of Advanced Strategic Command; http://www.asc-hq.de
7  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING. If not, write to the
21  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  Boston, MA 02111-1307 USA
23 */
24 
25 
26 
27 
28 #include <stdio.h>
29 
30 #include <cstring>
31 
32 #include "global.h"
33 #include "buildingtype.h"
34 #include "vehicletype.h"
35 #include "typen.h"
36 
37 #include "gameevent_dialogs.h"
38 #include "spfst.h"
39 #include "loaders.h"
40 #include "gameevents.h"
41 #include "dlg_box.h"
42 #include "dialog.h"
43 #include "errors.h"
44 #include "itemrepository.h"
45 #include "messagedlg.h"
46 #include "mapdisplayinterface.h"
47 
49 
50 #ifdef sgmain
51 # include "viewcalculation.h"
52 # include "resourcenet.h"
53 # include "sg.h"
54 # include "turncontrol.h"
55 #endif
56 
57 
58 
60 // Trigger
61 
62 
63 int versionTest( tnstream& stream, int min, int max )
64 {
65  int version = stream.readInt();
66  if ( version < min || version > max )
67  throw tinvalidversion( stream.getLocation(), max, version );
68  return version;
69 }
70 
72 {
73  versionTest(stream,1,1);
74 }
75 
77 {
78  stream.writeInt(1);
79 }
80 
81 
82 
84 {
85  if ( gamemap->time.turn() > turn || (gamemap->time.turn() == turn && gamemap->time.move() >= move ))
86  return finally_fulfilled;
87  else
88  return unfulfilled;
89 }
90 
91 
93 {
94  GameTime t;
95  t.set ( turn, move );
96  gamemap->eventTimes.push_back ( t );
97  sort( gamemap->eventTimes.begin(), gamemap->eventTimes.end(), GameTime::comp );
98 }
99 
101 {
102  versionTest(stream,1,1);
103  turn = stream.readInt();
104  move = stream.readInt();
105 }
106 
108 {
109  stream.writeInt(1);
110  stream.writeInt( turn );
111  stream.writeInt( move );
112 }
113 
115 {
116  turn = editInt( "turn", turn );
117  move = editInt( "move", move );
118 }
119 
120 
122 {
123  return "turn passed";
124 }
125 
127 {
128  if ( turn >= 0 ) {
129  ASCString s;
130  s.format( "turn %d , move %d passed ", turn, move );
131  return s;
132  } else
133  return getTypeName();
134 }
135 
136 
137 
139 {
140  ASCString s = "Building ";
142  s += gamemap->getField(pos)->building->getName();
143  else
144  if ( pos.valid() )
145  s += " <not found> ";
146 
147  return s;
148 }
149 
151 {
152  getxy_building( &pos.x, &pos.y );
153 }
154 
155 
156 
158 {
159  MapField* fld = gamemap->getField ( pos );
160  if( !fld ) {
161  displaymessage ("invalid event - map field not found!", 1);
162  return finally_failed;
163  }
164 
165  if ( !fld->building )
166  return finally_failed;
167 
168  if ( fld->building->getOwner() == player )
169  return fulfilled;
170  else
171  return unfulfilled;
172 }
173 
175 {
176  if( !gamemap->getField ( pos ) ) {
177  displaymessage ("invalid event - map field not found!", 1);
178  return;
179  }
180 
181  Building* bld = gamemap->getField ( pos )->building;
182  if ( bld )
183  bld->conquered.connect( sigc::mem_fun( *this, &BuildingConquered::triggered ));
184 }
185 
187 {
188  if ( isFulfilled() )
189  eventReady( gamemap );
190 }
191 
192 
194 {
195  State s = BuildingConquered::getState ( player );
196  if ( s == fulfilled)
197  return unfulfilled;
198  if ( s == unfulfilled )
199  return fulfilled;
200  return s;
201 }
202 
203 
205 {
206  if( !gamemap->getField ( pos ) ) {
207  displaymessage ("invalid event - map field not found!", 1);
208  return;
209  }
210 
211  Building* bld = gamemap->getField ( pos )->building;
212  if ( bld ) {
213  bld->conquered.connect( sigc::mem_fun( *this, &BuildingConquered::triggered ));
214  bld->destroyed.connect( sigc::mem_fun( *this, &BuildingConquered::triggered ));
215  }
216 }
217 
218 
219 
221 {
222  versionTest(stream,1,1);
223  pos.read( stream );
224 }
225 
226 
228 {
229  stream.writeInt(1);
230  pos.write( stream );
231 }
232 
234 {
235  if( !gamemap->getField ( pos ) ) {
236  displaymessage ("invalid event - map field not found!", 1);
237  return finally_fulfilled;
238  }
239 
240  MapField* fld = gamemap->getField ( pos );
241  if ( !fld->building )
242  return finally_fulfilled;
243  else
244  return unfulfilled;
245 }
246 
247 
249 {
250  if( !gamemap->getField ( pos ) ) {
251  displaymessage ("invalid event - map field not found!", 1);
252  return finally_fulfilled;
253  }
254 
255  Building* bld = gamemap->getField ( pos )->building;
256  if ( !bld )
257  return finally_failed;
258 
259  int cnt = 0;
260  for ( int x = 0; x < 4; x++ )
261  for ( int y = 0; y < 6; y++ ) {
262  if ( bld->typ->fieldExists ( BuildingType::LocalCoordinate(x, y) ) ) {
263  MapField* fld = bld->getField ( BuildingType::LocalCoordinate( x, y) );
264  if ( fld ) {
265  int vis = (fld-> visible >> (player*2) ) & 3;
266  if ( bld->typ->height >= chschwimmend && bld->typ->height <= chhochfliegend ) {
267  if ( vis >= visible_now )
268  cnt++;
269  } else {
270  if ( vis == visible_all )
271  cnt++;
272  }
273  }
274  }
275  }
276 
277  if ( cnt )
278  return finally_fulfilled;
279  else
280  return unfulfilled;
281 }
282 
284 {
285  if( !gamemap->getField ( pos ) ) {
286  displaymessage ("invalid event - map field not found!", 1);
287  return;
288  }
289 
290  Building* bld = gamemap->getField ( pos )->building;
291  if ( bld ) {
293  #ifdef sgmain
294  buildingSeen.connect( sigc::mem_fun( *this, &BuildingSeen::triggered ));
295  #endif
296  }
297 }
298 
300 {
301  if ( isFulfilled() )
302  eventReady( gamemap );
303 }
304 
305 
307 {
308  if ( gamemap->player[player].buildingList.empty() )
309  return fulfilled;
310  else
311  return unfulfilled;
312 }
313 
315 {
316  return "All Buildings Lost";
317 }
318 
320 {
321  return getTypeName();
322 }
323 
324 
326 {
327  if ( gamemap->player[player].vehicleList.empty() )
328  return fulfilled;
329  else
330  return unfulfilled;
331 }
332 
334 {
335  return "All Units Lost";
336 }
337 
339 {
340  return getTypeName();
341 }
342 
344 {
345  versionTest(stream,1,1);
346  unitID = stream.readInt();
347 }
348 
349 
351 {
352  stream.writeInt(1);
353  stream.writeInt( unitID );
354 }
355 
357 {
358  ASCString s = "unit ";
359  if ( gamemap ) {
360  if ( gamemap->getUnit( unitID ))
361  s += gamemap->getUnit( unitID )->getName();
362  else
363  s += "<not found>";
364  }
365  return s;
366 }
367 
369 {
370  unitID = selectunit ( unitID );
371 }
372 
374 {
375  state( -1 );
376  eventReady( gamemap );
377 }
378 
379 
381 {
382  Vehicle* veh = gamemap->getUnit( unitID );
383  if ( veh ) {
384  veh->destroyed.connect( sigc::mem_fun( *this, &UnitLost::triggered ));
385  veh->conquered.connect( sigc::mem_fun( *this, &UnitLost::triggered ));
386  }
387 }
388 
389 
391 {
392  Vehicle* veh = gamemap->getUnit( unitID );
393  if ( !veh )
394  return finally_fulfilled;
395  if ( veh->getOwner() != player )
396  return fulfilled;
397  return unfulfilled;
398 }
399 
400 
402 {
403  return "unit lost";
404 }
405 
406 
408 {
409  return UnitTrigger::getName() + " lost";
410 }
411 
412 
413 
414 
415 
417 {
418  Vehicle* veh = gamemap->getUnit( unitID );
419  if ( !veh )
420  return finally_failed;
421  if ( veh->getOwner() == player )
422  return fulfilled;
423  return unfulfilled;
424 
425 }
426 
428 {
429  return "unit conquered";
430 }
431 
432 
434 {
435  return UnitTrigger::getName() + " conquered";
436 }
437 
439 {
440  Vehicle* veh = gamemap->getUnit( unitID );
441  if ( veh )
442  veh->conquered.connect( sigc::mem_fun( *this, &UnitConquered::triggered ));
443 }
444 
445 
446 
447 
449 {
450  Vehicle* veh = gamemap->getUnit( unitID );
451  if ( !veh )
452  return finally_fulfilled;
453  return unfulfilled;
454 }
455 
456 
458 {
459  return "unit destroyed";
460 }
461 
463 {
464  return UnitTrigger::getName() + " destroyed";
465 }
466 
468 {
469  Vehicle* veh = gamemap->getUnit( unitID );
470  if ( veh )
471  veh->destroyed.connect( sigc::mem_fun( *this, &UnitDestroyed::triggered ));
472 }
473 
474 
475 
476 
478 {
479  for ( GameMap::Events::iterator i = gamemap->events.begin(); i != gamemap->events.end(); ++i )
480  if ( (*i)->id == eventID && (*i)->status == Event::Executed )
481  return finally_fulfilled;
482  return unfulfilled;
483 }
484 
486 {
487  versionTest(stream,1,1);
488  eventID = stream.readInt();
489 }
490 
492 {
493  stream.writeInt(1);
494  stream.writeInt( eventID );
495 }
496 
497 
498 Event* EventTriggered::getTargetEventName() const
499 {
500  if ( gamemap )
501  for ( GameMap::Events::iterator i = gamemap->events.begin(); i != gamemap->events.end(); ++i )
502  if ( (*i)->id == eventID )
503  return *i;
504  return NULL;
505 }
506 
507 
509 {
510  return "Event triggered";
511 }
512 
514 {
515  Event* e = getTargetEventName();
516  if ( e ) {
517  ASCString s = "Event ";
518  if ( !e->description.empty() )
519  s += e->description;
520  else
521  s += e->action->getName();
522  s += " triggered";
523  return s;
524  } else
525  return getTypeName();
526 }
527 
529 {
530  vector<int> eventIDs;
531  vector<ASCString> eventnames;
532  int fnd = -1;
533  int counter = 0;
534  for ( GameMap::Events::iterator i = gamemap->events.begin(); i != gamemap->events.end(); ++i ) {
535  eventnames.push_back( (*i)->action->getName() + " : " + (*i)->description );
536  eventIDs.push_back ( (*i)->id );
537  if ( (*i)->id == eventID )
538  fnd = counter;
539  ++counter;
540  }
541 
542  int res = chooseString ( "select event", eventnames, fnd );
543  if ( res >= 0)
544  eventID = eventIDs[res];
545 }
546 
548 {
549  Event* e = getTargetEventName();
550  if ( e )
551  e->executed.connect( sigc::mem_fun( *this, &EventTriggered::triggered));
552 }
553 
555 {
556  state( -1 );
557  eventReady( gamemap );
558 }
559 
560 
562 {
563  for ( int i = 0; i < 8; i++ )
564  if ( gamemap->player[player].diplomacy.isHostile(i))
565  if ( !gamemap->player[i].vehicleList.empty() )
566  return unfulfilled;
567 
568  return fulfilled;
569 }
570 
571 
573 {
574  return getTypeName();
575 }
576 
578 {
579  return "All enemy units destroyed";
580 }
581 
583 {
584  ContainerBase::anyContainerDestroyed.connect( sigc::hide( sigc::mem_fun( *this, &AllEnemyUnitsDestroyed::triggered)));
585  ContainerBase::anyContainerConquered.connect( sigc::hide( sigc::mem_fun( *this, &AllEnemyUnitsDestroyed::triggered)));
586 }
587 
588 void AllEnemyUnitsDestroyed::triggered()
589 {
590  if ( isFulfilled() )
591  eventReady( gamemap );
592 }
593 
594 
596 {
597  for ( int i = 0; i < 8; i++ )
598  if ( gamemap->getPlayer(player).diplomacy.isHostile(i))
599  if ( !gamemap->player[i].buildingList.empty() )
600  return unfulfilled;
601 
602  return fulfilled;
603 }
604 
606 {
607  return "All enemy buildings destroyed";
608 }
609 
611 {
612  return getTypeName();
613 }
614 
615 
616 
618 {
619  ContainerBase::anyContainerDestroyed.connect( sigc::hide( sigc::mem_fun( *this, &AllEnemyBuildingsDestroyed::triggered)));
620  ContainerBase::anyContainerConquered.connect( sigc::hide( sigc::mem_fun( *this, &AllEnemyBuildingsDestroyed::triggered)));
621 }
622 
623 void AllEnemyBuildingsDestroyed::triggered()
624 {
625  if ( isFulfilled() )
626  eventReady( gamemap );
627 }
628 
629 
631 {
632  found = false;
633  operate();
634  if ( found )
635  return fulfilled;
636  else
637  return unfulfilled;
638 }
639 
641 {
642  MapField* fld = gamemap->getField ( mc );
643  if ( !arming ) {
644  if ( fld && fld->getVehicle() )
645  if ( fld->getVehicle()->networkid == unitID || unitID == -1 )
646  found = true;
647 
648  Vehicle* veh = gamemap->getUnit( unitID );
649  if ( veh )
650  if ( mc.x == veh->getPosition().x && mc.y == veh->getPosition().y )
651  found = true;
652  } else
654 }
655 
657 {
658  versionTest(stream,1,1);
659  readMapModificationData( stream );
660  unitID = stream.readInt();
661 }
662 
664 {
665  stream.writeInt(1);
666  writeMapModificationData( stream );
667  stream.writeInt( unitID );
668 }
669 
671 {
672  return "specific unit entered polygon";
673 }
674 
675 
677 {
678  ASCString s;
679  if ( unitID > 0 && gamemap->getUnit( unitID )) {
680  s = "unit ";
681  s += gamemap->getUnit( unitID )->getName();
682  } else
683  s = "specific unit";
684  s += " enters polygon";
685  return s;
686 }
687 
689 {
691  unitID = selectunit ( unitID );
692 }
693 
695 {
696  #ifdef sgmain
697  arming = true;
698  operate();
699  arming = false;
700  fieldCrossed.connect( sigc::mem_fun( *this, &SpecificUnitEntersPolygon::triggered));
701  Vehicle* veh = gamemap->getUnit( unitID );
702  if ( veh )
704  #endif
705 }
706 
708 {
709  if ( isFulfilled() )
710  eventReady( gamemap );
711 }
712 
714 {
715  found = false;
716  operate();
717  if ( found )
718  return finally_fulfilled;
719  else
720  return unfulfilled;
721 }
722 
724 {
725  MapField* fld = gamemap->getField ( mc );
726  if ( !arming ) {
727  if ( fld && fld->getVehicle() )
728  if ( (1 << fld->getVehicle()->getOwner()) & player )
729  found = true;
730 
731  if ( fld && fld->building )
732  for ( ContainerBase::Cargo::const_iterator i = fld->building->getCargo().begin(); i != fld->building->getCargo().end(); ++i )
733  if ( *i )
734  if ( (1 << (*i)->getOwner()) & player )
735  found = true;
736 
737  } else {
739  }
740 }
741 
743 {
744  versionTest(stream,1,1);
745  readMapModificationData( stream );
746  player = stream.readInt();
747 }
748 
750 {
751  stream.writeInt(1);
752  writeMapModificationData( stream );
753  stream.writeInt( player );
754 }
755 
757 {
758  return "Any unit entered polygon";
759 }
760 
762 {
763  ASCString s = "any unit ";
764  if ( player ) {
765  s += "from ";
766  for ( int i = 0; i < 8; ++i )
767  if ( player & ( 1 << i)) {
768  s += gamemap->player[i].getName();
769  s += " ";
770  }
771  }
772  s += " enters polygon";
773  return s;
774 }
775 
777 {
779  playerselall( &player );
780 }
781 
783 {
784  #ifdef sgmain
785  arming = true;
786  operate();
787  arming = false;
788  fieldCrossed.connect( sigc::mem_fun( *this, &AnyUnitEntersPolygon::triggered));
789  #endif
790 }
791 
793 {
794  if ( isFulfilled() )
795  eventReady( gamemap );
796 }
797 
798 
800 {
801  if ( payingPlayer < 0 || gamemap->tribute.avail[payingPlayer][player] + gamemap->tribute.paid[player][payingPlayer] < demand )
802  return unfulfilled;
803  else
804  return finally_fulfilled;
805 }
806 
808 {
809  versionTest(stream,1,1);
810  payingPlayer = stream.readInt();
811  demand.read ( stream );
812 }
813 
814 
816 {
817  stream.writeInt( 1 );
818  stream.writeInt( payingPlayer );
819  demand.write ( stream );
820 }
821 
822 
824 {
825  return "Resource tribute";
826 }
827 
829 {
830  if ( payingPlayer >= 0 ) {
831  ASCString s;
832  s.format ( "Resource tribute: %d E ; %d M ; %d F", demand.energy, demand.material, demand.fuel );
833  return s;
834  } else
835  return getTypeName();
836 }
837 
839 {
840  payingPlayer = editInt( "Paying Player", payingPlayer );
841  demand.energy = editInt( "energy", demand.energy );
842  demand.material = editInt( "material", demand.material );
843  demand.fuel = editInt( "fuel", demand.fuel );
844 }
845 
847 {
848  #ifdef sgmain
849  tributeTransferred.connect( sigc::mem_fun( *this, &ResourceTribute::triggered));
850  #endif
851 }
852 
854 {
855  if ( isFulfilled() )
856  eventReady( gamemap );
857 }
858 
860 // Actions
861 
862 
864 {
865  stream.readInt();
866 }
867 
869 {
870  stream.writeInt(1);
871 }
872 
873 
875 {
876  if ( speed != -1 )
877  gamemap->weather.windSpeed = speed;
878 
879  if ( direction != -1 )
880  gamemap->weather.windDirection = direction;
881 
882  if ( md )
883  md->updateDashboard();
884 }
885 
887 {
888  versionTest(stream,1,1);
889  speed = stream.readInt();
890  direction = stream.readInt();
891 }
892 
894 {
895  stream.writeInt(1);
896  stream.writeInt( speed );
897  stream.writeInt( direction );
898 }
899 
901 {
902  speed = editInt("Wind Speed", speed, 0, 255);
903  direction = editInt("Wind Direction", direction, 0, 5);
904 }
905 
906 
907 
909 {
910  if ( parameterNum >= 0 )
911  if ( gameParameterSettings[parameterNum ].changeableByEvent )
912  gamemap->setgameparameter( GameParameter(parameterNum) , parameterValue );
913 }
914 
916 {
917  versionTest(stream,1,1);
918  parameterNum = stream.readInt();
919  parameterValue = stream.readInt();
920 }
921 
923 {
924  stream.writeInt(1);
925  stream.writeInt( parameterNum );
926  stream.writeInt( parameterValue );
927 }
928 
929 int ChangeGameParameter::selectgameparameter( int para )
930 {
931  vector<ASCString> list;
932  for ( int i = 0; i < gameparameternum; ++i )
933  list.push_back ( gameParameterSettings[i].name );
934  return chooseString("Select GameParameter", list, para );
935 }
936 
938 {
939  int nr = selectgameparameter( parameterNum );
940  if ( (nr >= 0) && ( nr < gameparameternum) ) {
941  if ( gameParameterSettings[nr].changeableByEvent ) {
942  int org = parameterValue;
943  if ( org < gameParameterSettings[nr].minValue && org > gameParameterSettings[nr].maxValue )
945  parameterValue = getid("Parameter Val", org, gameParameterSettings[nr].minValue, gameParameterSettings[nr].maxValue);
946  parameterNum = nr;
947  } else
948  displaymessage("This parameter cannot be changed by events",1);
949  }
950 
951 }
952 
953 
954 void DisplayMessage :: viewtextmessage ( GameMap* actmap, int id, int player )
955 {
956  ASCString txt = readtextmessage( id );
957  if ( !txt.empty() ) {
958 
959  int to;
960  if ( player < 8 )
961  to = (1 << player);
962  else
963  to = 0xff;
964 
965  new Message ( txt, actmap, to );
966 #ifdef sgmain
967  if ( player == actmap->actplayer )
968  viewunreadmessages ( actmap->player[ actmap->actplayer ] );
969 #endif
970  } else
971  displaymessage( "Message %d not found", 1, id );
972 }
973 
974 
976 {
977  if ( gamemap->state == GameMap::Replay )
978  return;
979 
980  viewtextmessage ( gamemap, messageNum , gamemap->actplayer );
981 }
982 
984 {
985  versionTest(stream,1,1);
986  messageNum = stream.readInt();
987 }
988 
990 {
991  stream.writeInt(1);
992  stream.writeInt( messageNum );
993 }
994 
996 {
997  messageNum = editInt ( "Message ID", messageNum );
998 }
999 
1000 
1001 
1002 
1003 void FieldAddressing::setpointabs ( int x, int y )
1004 {
1005  fieldOperator ( MapCoordinate(x,y) );
1006 }
1007 
1009 {
1010  if ( addressingMode == singleField ) {
1011  for ( Fields::iterator i = fields.begin(); i != fields.end(); ++i )
1012  fieldOperator ( *i );
1013  }
1014  if ( addressingMode == poly ) {
1015  for ( Polygons::iterator i = polygons.begin(); i != polygons.end(); ++i )
1016  paintPolygon ( *i );
1017  }
1018  if ( addressingMode == global ) {
1019  for ( int y = 0; y < gameMap->ysize; ++y )
1020  for ( int x = 0; x < gameMap->xsize; ++x )
1021  fieldOperator ( MapCoordinate ( x, y ));
1022  }
1023 }
1024 
1026 {
1028  fields.clear();
1029  fields.push_back ( pos );
1030 }
1031 
1032 void FieldAddressing::setPolygon ( const Poly_gon& poly_gon )
1033 {
1034  addressingMode = poly;
1035  polygons.clear();
1036  polygons.push_back ( poly_gon );
1037 }
1038 
1040 {
1042 }
1043 
1044 
1045 
1047 {
1048  versionTest(stream,1000,1000);
1049  addressingMode = AddressingMode ( stream.readInt() );
1050  if ( addressingMode == singleField )
1051  readClassContainer( fields, stream );
1052 
1053  if ( addressingMode == poly )
1054  readClassContainer( polygons, stream );
1055 }
1056 
1057 
1059 {
1060  vector<ASCString> entries;
1061  entries.push_back ( "none" );
1062  entries.push_back ( "Single Fields");
1063  entries.push_back ( "Polygons" );
1064  entries.push_back ( "global");
1065 
1066  int c = chooseString ( "choose operation target", entries, addressingMode );
1067  if ( c < 0 )
1068  return;
1069 
1071 
1072  if ( addressingMode == singleField )
1073  selectFields( fields );
1074  else
1075  if ( addressingMode == poly ) {
1076  if ( !polygons.size() )
1077  polygons.push_back ( Poly_gon() );
1078  editpolygon ( polygons[0] );
1079  }
1080 }
1081 
1082 
1084 {
1085  stream.writeInt( 1000 );
1086  stream.writeInt ( addressingMode );
1087 
1088  if ( addressingMode == singleField )
1089  writeClassContainer ( fields, stream );
1090 
1091  if ( addressingMode == poly )
1092  writeClassContainer ( polygons, stream );
1093 }
1094 
1096 {
1097  operate();
1098 #ifdef sgmain
1099  computeview( gamemap );
1100 #endif
1101  if ( md ) {
1102  md->displayMap();
1103  md->updateDashboard();
1104  }
1105 }
1106 
1107 
1109 {
1110  versionTest(stream,1,1);
1111  weather = stream.readInt();
1112  readMapModificationData ( stream );
1113 }
1114 
1115 
1117 {
1118  stream.writeInt( 1 );
1119  stream.writeInt( weather );
1120  writeMapModificationData ( stream );
1121 }
1122 
1124 {
1125  MapField* field = gamemap->getField ( mc );
1126  if ( field )
1127  field->setWeather( weather );
1128 }
1129 
1131 {
1133  chooseWeather( weather );
1134 }
1135 
1136 
1138 {
1139  versionTest(stream,1,1);
1140  terrainID = stream.readInt();
1141  readMapModificationData ( stream );
1142 }
1143 
1144 
1146 {
1147  stream.writeInt( 1 );
1148  stream.writeInt( terrainID );
1149  writeMapModificationData ( stream );
1150 }
1151 
1153 {
1154  TerrainType* typ = terrainTypeRepository.getObject_byID ( terrainID );
1155  if ( !typ )
1156  return;
1157 
1158  MapField* field = gamemap->getField ( mc );
1159  if ( field ) {
1160  int w = field->getWeather();
1161  if (typ->weather[w] == NULL)
1162  w = 0;
1163 
1164  field->typ = typ->weather[ w ];
1165  field->setparams();
1166  }
1167 }
1168 
1170 {
1172  chooseTerrain( terrainID );
1173 }
1174 
1175 
1176 
1178 {
1179  versionTest(stream,1,1);
1180  objectID = stream.readInt();
1181  readMapModificationData ( stream );
1182 }
1183 
1184 
1186 {
1187  stream.writeInt( 1 );
1188  stream.writeInt( objectID );
1189  writeMapModificationData ( stream );
1190 }
1191 
1192 
1194 {
1195  ObjectType* obj = objectTypeRepository.getObject_byID ( objectID );
1196  if ( !obj )
1197  return;
1198 
1199  MapField* field = gamemap->getField ( mc );
1200  if ( field ) {
1201  field->addobject ( obj, -1, true );
1202  field->setparams();
1203  }
1204 }
1205 
1207 {
1209  chooseObject( objectID );
1210 }
1211 
1212 
1213 
1214 
1216 {
1217  versionTest(stream,1,1);
1218  readMapModificationData ( stream );
1219 }
1220 
1221 
1223 {
1224  stream.writeInt( 1 );
1225  writeMapModificationData ( stream );
1226 }
1227 
1228 
1230 {
1231  MapField* field = gamemap->getField ( mc );
1232  if ( field ) {
1233  field->objects.clear();
1234  field->setparams();
1235  }
1236 }
1237 
1239 {
1241 }
1242 
1243 
1244 
1246 {
1249 
1250  if ( md ) {
1251  mapChanged( gamemap );
1252 
1253 #ifdef sgmain
1254  if ( gamemap->getCurrentPlayer().isHuman() )
1256 #endif
1257 
1258  }
1259 
1260 }
1261 
1262 
1264 {
1265  versionTest(stream,1,1);
1266  damage = stream.readInt();
1267  position.read ( stream );
1268 }
1269 
1271 {
1272  stream.writeInt( 1);
1273  stream.writeInt( damage );
1274  position.write ( stream );
1275 }
1276 
1278 {
1279  MapField* fld = gamemap->getField ( position );
1280  if ( fld && fld->building ) {
1281  if ( damage >= 100 ) {
1282  delete fld->building;
1283  fld->building = NULL;
1284 
1285  if ( md )
1286  mapChanged( gamemap );
1287 
1288  } else {
1289  fld->building->damage = damage;
1290  if ( md )
1291  md->updateDashboard();
1292  }
1293  }
1294 }
1295 
1297 {
1298  getxy_building ( &position.x, &position.y );
1299  damage = editInt("new building damage", damage, 0, 100);
1300 }
1301 
1302 
1303 void NextMap::readData ( tnstream& stream )
1304 {
1305  versionTest(stream,1,1);
1306  mapID = stream.readInt();
1307 }
1308 
1310 {
1311  stream.writeInt( 1);
1312  stream.writeInt( mapID );
1313 }
1314 
1316 {
1317  if ( gamemap->state == GameMap::Replay )
1318  return;
1319 
1321  if ( name.find('.') != ASCString::npos )
1322  name.erase( name.find('.') );
1323 
1324 
1325  savegame( "map-" + name + "-completed" + (savegameextension + 1), gamemap );
1327  throw LoadNextMap(mapID);
1328 }
1329 
1331 {
1332  mapID = editInt("ID of next map", mapID, 0, maxint);
1333 }
1334 
1335 
1336 
1338 {
1339  if ( gamemap->state == GameMap::Replay )
1340  return;
1341 
1343  return;
1344 
1345  if ( !gamemap->continueplaying ) {
1346  displaymessage ( "You have been defeated !", 3 );
1348 
1349 #ifdef sgmain
1350  int humanCount = 0;
1351  for ( int p = 0; p < gamemap->getPlayerCount(); ++p )
1352  if ( gamemap->getPlayer(p).isHuman() && gamemap->getPlayer(p).exist() )
1353  humanCount++;
1354 
1355  if ( humanCount > 1 ) {
1357  } else {
1358  delete gamemap;
1359  throw NoMapLoaded();
1360  }
1361 #endif
1362  }
1363 }
1364 
1365 
1367 {
1368  versionTest(stream,1,1);
1369  x1 = stream.readInt();
1370  x2 = stream.readInt();
1371  y1 = stream.readInt();
1372  y2 = stream.readInt();
1373  alignRight = stream.readInt();
1374  alignBottom = stream.readInt();
1375 }
1376 
1378 {
1379  stream.writeInt( 1 );
1380  stream.writeInt( x1 );
1381  stream.writeInt( x2 );
1382  stream.writeInt( y1 );
1383  stream.writeInt( y2 );
1384  stream.writeInt( alignRight );
1385  stream.writeInt( alignBottom );
1386 }
1387 
1389 {
1390  warningMessage("Ellipses are not supported any more!");
1391  /*
1392  if ( !gamemap->ellipse )
1393  gamemap->ellipse = new EllipseOnScreen;
1394 
1395  if ( alignRight ) { // x orientation
1396  gamemap->ellipse->x1 = agmp->resolutionx - ( 640 - x1 );
1397  gamemap->ellipse->x2 = agmp->resolutionx - ( 640 - x2 );
1398  } else {
1399  gamemap->ellipse->x1 = x1;
1400  gamemap->ellipse->x2 = x2;
1401  }
1402 
1403  if ( alignBottom ) { // y orientation
1404  gamemap->ellipse->y1 = agmp->resolutiony - ( 480 - y1 );
1405  gamemap->ellipse->y2 = agmp->resolutiony - ( 480 - y2 );
1406  } else {
1407  gamemap->ellipse->y1 = y1;
1408  gamemap->ellipse->y2 = y2;
1409  }
1410 
1411  gamemap->ellipse->color = white;
1412  gamemap->ellipse->precision = 0.15;
1413  gamemap->ellipse->active = 1;
1414 
1415  if ( md )
1416  md->updateDashboard();
1417 
1418  */
1419 }
1420 
1422 {
1423  x1 = getid("x1",x1,0,639);
1424  y1 = getid("y1",y1,0,479);
1425  x2 = getid("x2",x2,0,639);
1426  y2 = getid("y2",y2,0,479);
1427  alignRight = choice_dlg("x orientation","~l~eft","~r~ight") - 1;
1428  alignBottom = choice_dlg("y orientation","~t~op","~b~ottom") - 1;
1429 }
1430 
1431 
1433 {
1434  /*
1435  if ( gamemap->ellipse ) {
1436  gamemap->ellipse->active = 0;
1437  if ( md )
1438  md->repaintDisplay();
1439  }
1440  */
1441 }
1442 
1443 
1444 
1445 
1447 {
1448  versionTest(stream,1,1);
1449  pos.read( stream );
1450  newOwner = stream.readInt();
1451 }
1452 
1453 
1455 {
1456  stream.writeInt( 1 );
1457  pos.write( stream );
1458  stream.writeInt ( newOwner );
1459 }
1460 
1461 
1463 {
1464  getxy_building( &pos.x, &pos.y );
1465  newOwner = getid("new owner",newOwner,0,8);
1466 }
1467 
1469 {
1470  MapField* fld = gamemap->getField ( pos );
1471  if ( fld && fld->building ) {
1472  fld->building->convert ( newOwner );
1473  #ifdef sgmain
1475  #endif
1476  if ( md )
1477  mapChanged( gamemap );
1478  }
1479 }
1480 
1481 
1483 {
1484  if ( gamemap->state == GameMap::Replay )
1485  return;
1486 
1487  if ( !message.empty() ) {
1488  if ( recipients == 0 )
1489  new Message ( message, gamemap, 1 << gamemap->actplayer, 0 );
1490  else
1491  new Message ( message, gamemap, recipients, 0 );
1492 
1493  #ifdef sgmain
1495  #endif
1496  }
1497 }
1498 
1500 {
1501  int version = versionTest(stream,1,2);
1502  message = stream.readString(true);
1503  if ( version >= 2 )
1504  recipients = stream.readInt();
1505  else
1506  recipients = 0;
1507 }
1508 
1510 {
1511  stream.writeInt(2);
1512  stream.writeString( message );
1513  stream.writeInt( recipients );
1514 }
1515 
1517 {
1518 
1519  vector<ASCString> player;
1520  for ( int p = 0; p < gamemap->getPlayerCount(); ++p )
1521  player.push_back( gamemap->getPlayer(p).getName() );
1522 
1523  BitMapEditor bme (recipients, "Select recieving players", player );
1524  bme.Show();
1525  bme.RunModal();
1526 
1527 
1528  while ( message.find ( "#CRT#" ) != ASCString::npos )
1529  message.replace ( message.find ( "#CRT#" ), 5, "\n" );
1530  while ( message.find ( "#crt#" ) != ASCString::npos )
1531  message.replace ( message.find ( "#crt#" ), 5, "\n" );
1532  MultiLineEditor( "Message", message );
1533 }
1534 
1535 
1537 {
1538  return message;
1539 }
1540 
1542 {
1543  message = s;
1544 }
1545 
1546 
1547 
1548 
1550 {
1551  versionTest(stream,1,1);
1552  pos.read( stream );
1553  vehicleTypeID = stream.readInt();
1554 }
1555 
1556 
1558 {
1559  stream.writeInt( 1 );
1560  pos.write( stream );
1561  stream.writeInt ( vehicleTypeID );
1562 }
1563 
1564 
1566 {
1567  getxy_building( &pos.x, &pos.y );
1568  chooseVehicleType( vehicleTypeID );
1569 }
1570 
1572 {
1573  MapField* fld = gamemap->getField ( pos );
1574  if ( fld && fld->building && vehicleTypeID >= 0 )
1575  fld->building->addProductionLine( gamemap->getvehicletype_byid(vehicleTypeID) );
1576 
1577 }
1578 
1579 
1580 
1582 {
1583  versionTest(stream,1,1);
1584  proposingPlayer = stream.readInt();
1585  targetPlayer = stream.readInt();
1586  proposal = Proposal(stream.readInt());
1587 }
1588 
1589 
1591 {
1592  stream.writeInt( 1 );
1593  stream.writeInt ( proposingPlayer );
1594  stream.writeInt ( targetPlayer );
1595  stream.writeInt ( proposal );
1596 }
1597 
1598 
1600 {
1601  proposingPlayer = editInt("Announcing Player",proposingPlayer,0,7);
1602  targetPlayer = editInt("Receiving Player",targetPlayer,0,7);
1603 
1604  vector<ASCString> list;
1605  list.push_back ( "Propose Peace");
1606  list.push_back ( "Declare War");
1607  list.push_back ( "Sneak Attack");
1608 
1609  proposal = Proposal ( chooseString ( "Action", list, proposal ));
1610 }
1611 
1613 {
1614 #ifdef sgmain
1615  auto_ptr<DiplomacyCommand> dc ( new DiplomacyCommand( gamemap->getPlayer(proposingPlayer) ));
1616  if ( proposal == Peace ) {
1617  dc->newstate( PEACE, gamemap->getPlayer(targetPlayer) );
1618  } else
1619  if ( proposal == War ) {
1620  dc->newstate( WAR, gamemap->getPlayer(targetPlayer) );
1621  } else {
1622  dc->sneakAttack( gamemap->getPlayer(targetPlayer) );
1623  }
1624 
1625  ActionResult res = dc->execute( createContext(gamemap) );
1626  if ( res.successful() )
1627  dc.release();
1628 #endif
1629 }
1630 
1631 
1632 
1633 
1634 
1635 
1637  int player;
1638  Player::PlayerStatus state;
1639  public:
1641 
1642  void readData ( tnstream& stream )
1643  {
1644  versionTest(stream,1,1);
1645  player = stream.readInt();
1646  state = (Player::PlayerStatus) stream.readInt();
1647  }
1648 
1649 
1650  void writeData ( tnstream& stream )
1651  {
1652  stream.writeInt( 1 );
1653  stream.writeInt ( player );
1654  stream.writeInt ( state );
1655  }
1656 
1658  {
1659  gamemap->getPlayer(player).stat = state;
1660  }
1661 
1662  void setup()
1663  {
1664  player = editInt("Player",player,0,7);
1665 
1666  vector<ASCString> list;
1667  list.push_back ( "human");
1668  list.push_back ( "computer");
1669  list.push_back ( "off");
1670  list.push_back ( "supervisor");
1671  list.push_back ( "suspended");
1672 
1673 #if 1
1674  state = Player::PlayerStatus( chooseString ( "State", list, state ));
1675 #else
1676  /* this is intended as security measure to prevent a player in a duell
1677  from switching himself to supervisor and seeing the whole map */
1678  do {
1679  state = Player::PlayerStatus( chooseString ( "State", list, state ));
1680  if ( state == Player::supervisor )
1681  warning("setting a player to supervisor is not allowed");
1682  } while ( state == Player::supervisor );
1683 #endif
1684  }
1685 
1686  ASCString getName() const { return "Change player state"; };
1687 };
1688 
1689 
1690 
1691 
1692 
1694 {
1695  versionTest(stream,1,1);
1696  viewingPlayer = stream.readInt();
1697  providingPlayer = stream.readInt();
1698  enable = stream.readInt();
1699 }
1700 
1701 
1703 {
1704  stream.writeInt( 1 );
1705  stream.writeInt ( viewingPlayer );
1706  stream.writeInt ( providingPlayer );
1707  stream.writeInt ( enable );
1708 }
1709 
1710 
1712 {
1713  viewingPlayer = editInt("Viewing Player",viewingPlayer,0,7);
1714  providingPlayer = editInt("Providing Player",providingPlayer,0,7);
1715 
1716  vector<ASCString> list;
1717  list.push_back ( "Disable View Sharing");
1718  list.push_back ( "Enable View Sharing");
1719 
1720  enable = chooseString ( "Action", list, enable );
1721 }
1722 
1724 {
1725  if ( enable )
1726  gamemap->player[providingPlayer].diplomacy.setState( viewingPlayer, PEACE_SV );
1727  else
1728  if ( gamemap->player[providingPlayer].diplomacy.getState( viewingPlayer ) >= PEACE_SV )
1729  gamemap->player[providingPlayer].diplomacy.setState( viewingPlayer, PEACE );
1730 
1731  #ifdef sgmain
1732  computeview( gamemap );
1733  #endif
1734  if ( md ) {
1735  md->displayMap();
1736  md->updateDashboard();
1737  }
1738 }
1739 
1740 
1741 
1742 
1744 {
1745  versionTest(stream,1,1);
1746  res.read( stream );
1747  pos.read( stream );
1748 }
1749 
1750 
1752 {
1753  stream.writeInt( 1 );
1754  res.write( stream );
1755  pos.write( stream );
1756 }
1757 
1758 
1760 {
1761  getxy_building( &pos.x, &pos.y );
1762 
1763  res.energy = editInt("Energy",res.energy,minint);
1764  res.material = editInt("Material",res.material,minint);
1765  res.fuel = editInt("Fuel",res.fuel ,minint);
1766 }
1767 
1769 {
1770  MapField* fld = gamemap->getField ( pos );
1771  if ( fld && fld->building )
1772  fld->building->putResource( res, 0 );
1773 }
1774 
1775 
1777 {
1778  versionTest(stream,1,1);
1779  objectNum = stream.readInt();
1780  buf.readfromstream ( &stream );
1781 }
1782 
1783 
1785 {
1786  stream.writeInt( 1 );
1787  stream.writeInt( objectNum );
1788  buf.writetostream ( &stream );
1789 }
1790 
1791 
1793 {
1794  vector<ASCString> list;
1795  list.push_back ( "Append units / buildings");
1796  list.push_back ( "Reposition and reselect units / buildings");
1797  list.push_back ( "Clear buffer and select other units / buildings");
1798 
1799  int i = chooseString ( "Choose Action", list, 0 );
1800  if ( i == 2 ){
1801  buf.clear();
1802  objectNum = 0;
1803  }
1804  if ( i == 1 ){
1805  execute( NULL );
1806  buf.clear();
1807  objectNum = 0;
1808  }
1809 
1811  ReinforcementSelector rs( fieldlist, gamemap, buf, objectNum );
1812  rs.Show();
1813  rs.RunModal();
1814 
1815 
1816 }
1817 
1819  Vehicle* vehicle;
1820  bool placed;
1821  public:
1823  : SearchFields ( gamemap ), vehicle(veh), placed(false)
1824  {
1825  initsearch(MapCoordinate(veh->xpos, veh->ypos),0,10);
1826  startsearch();
1827  };
1828 
1829  void testfield ( const MapCoordinate& pos )
1830  {
1831  MapField* fld = gamemap->getField( pos );
1832  if ( fld && !fld->vehicle ) {
1833  if ( fieldAccessible( fld, vehicle, -2, NULL, true ) == 2 ) {
1834  fld->vehicle = vehicle;
1835  fld->vehicle->setnewposition ( pos );
1836  fld->vehicle->addview();
1837  cancelSearch = true;
1838  placed = true;
1839  }
1840  }
1841  };
1842 
1843  bool success() {
1844  return placed;
1845  }
1846 };
1847 
1848 
1850 {
1851  int cnt = 0;
1852  MemoryStream stream ( &buf, tnstream::reading );
1853  while ( cnt < objectNum ) {
1854  Type type = Type(stream.readInt());
1855  if ( type == ReinfVehicle ) {
1856  try {
1858  FindUnitPlacementPos fupp( gamemap, veh );
1859  if ( !fupp.success() )
1860  delete veh;
1861  }
1862  catch ( InvalidID err ) {
1863  displaymessage( "Error executing event 'Reinforcements'\n" + err.getMessage(), 1);
1864  throw ShutDownMap();
1865  }
1866  }
1867  if ( type == ReinfBuilding ) {
1868  Building* bld = Building::newFromStream ( gamemap, stream );
1869  #if 0
1870  MapCoordinate pos = bld->getPosition();
1871 
1872  for ( int x = 0; x < 4; x++ )
1873  for ( int y = 0; y < 6; y++ )
1874  if ( bld->typ->getpicture ( BuildingType::LocalCoordinate( x , y ) )) {
1876  if ( !field ) {
1877  delete bld;
1878  // displaymessage("building does not fit here", 1 );
1879  return;
1880  }
1881 
1882  /*
1883  if ( !bld->typ->terrainaccess.accessible ( field->bdt ) ) {
1884  delete bld;
1885  displaymessage("building does can not be build here", 1 );
1886  return;
1887  }
1888  */
1889 
1890 
1891  if ( field->vehicle ) {
1892  delete field->vehicle;
1893  field->vehicle = NULL;
1894  }
1895  if ( field->building ) {
1896  delete field->building;
1897  field->building = NULL;
1898  }
1899  }
1900  bld->chainbuildingtofield( pos );
1901  #endif
1903  bld->addview();
1904  }
1905  ++cnt;
1906  }
1907  #ifdef sgmain
1909  // computeview ( gamemap );
1910 
1911  #endif
1912 
1913  if ( md )
1914  mapChanged( gamemap );
1915 }
1916 
1917 template<class T>
1919  // dynamic allocation is to prevent a compiler bug in gcc 4.2.1
1920  T* t = new T();
1921  ASCString name = t->getTypeName();
1922  delete t;
1923  return name;
1924 };
1925 
1926 template<class T>
1928  T* t = new T();
1929  ASCString name = t->getName();
1930  delete t;
1931  return name;
1932 };
1933 
1934 
1935 
1936 template <typename TriggerType >
1938 {
1939  return eventTriggerFactory::Instance().registerClass( id, ObjectCreator<EventTrigger, TriggerType>, TriggerNameProvider<TriggerType>() );
1940 }
1941 
1942 template <typename ActionType >
1944 {
1945  return eventActionFactory::Instance().registerClass( id, ObjectCreator<EventAction, ActionType>, ActionNameProvider<ActionType>() );
1946 }
1947 
1948 
1949 
1950 
1951 namespace {
1952  const bool r1 = registerTrigger<TurnPassed> ( Trigger_TurnPassed );
1953  const bool r2 = registerTrigger<UnitLost> ( Trigger_UnitLost );
1954  const bool r3 = registerTrigger<UnitConquered> ( Trigger_UnitConquered );
1955  const bool r4 = registerTrigger<UnitDestroyed> ( Trigger_UnitDestroyed );
1956  const bool r5 = registerTrigger<AllBuildingsLost> ( Trigger_AllBuildingsLost );
1957  const bool r6 = registerTrigger<AllUnitsLost> ( Trigger_AllUnitsLost );
1958  const bool r7 = registerTrigger<TriggerNothingFalse> ( Trigger_NothingFalse );
1959  const bool r8 = registerTrigger<TriggerNothingTrue> ( Trigger_NothingTrue );
1960  const bool r9 = registerTrigger<BuildingConquered> ( Trigger_BuildingConquered );
1961  const bool r10 = registerTrigger<BuildingLost> ( Trigger_BuildingLost );
1962  const bool r11 = registerTrigger<BuildingDestroyed> ( Trigger_BuildingDestroyed );
1963  const bool r12 = registerTrigger<BuildingSeen> ( Trigger_BuildingSeen );
1964  const bool r13 = registerTrigger<EventTriggered> ( Trigger_EventTriggered );
1965  const bool r14 = registerTrigger<AllEnemyBuildingsDestroyed>( Trigger_AllEnemyBuildingsDestroyed );
1966  const bool r15 = registerTrigger<AllEnemyUnitsDestroyed> ( Trigger_AllEnemyUnitsDestroyed );
1967  const bool r16 = registerTrigger<SpecificUnitEntersPolygon> ( Trigger_SpecificUnitEntersPolygon );
1968  const bool r17 = registerTrigger<AnyUnitEntersPolygon> ( Trigger_AnyUnitEntersPolygon );
1969  const bool r18 = registerTrigger<ResourceTribute> ( Trigger_ResourceTribute );
1970 
1971  const bool s0 = registerAction<Action_Nothing>( EventAction_Nothing );
1972  const bool s1 = registerAction<DisplayMessage>( EventAction_DisplayMessage );
1973  const bool s2 = registerAction<WindChange>( EventAction_WindChange );
1974  const bool s3 = registerAction<ChangeGameParameter>( EventAction_ChangeGameParameter );
1975  const bool s4 = registerAction<WeatherChange>( EventAction_WeatherChange );
1976  const bool s5 = registerAction<MapChange>( EventAction_MapChange );
1977  const bool s6 = registerAction<AddObject>( EventAction_AddObject );
1978  const bool s7 = registerAction<MapChangeCompleted>( EventAction_MapChangeCompleted );
1979  const bool s8 = registerAction<ChangeBuildingDamage>( EventAction_ChangeBuildingDamage );
1980  const bool s9 = registerAction<NextMap>( EventAction_NextMap );
1981  const bool s10 = registerAction<LoseMap>( EventAction_LoseMap );
1982  const bool s11 = registerAction<DisplayEllipse>( EventAction_DisplayEllipse );
1983  const bool s12 = registerAction<RemoveEllipse>( EventAction_RemoveEllipse );
1984  const bool s13 = registerAction<ChangeBuildingOwner>( EventAction_ChangeBuildingOwner );
1985  const bool s14 = registerAction<RemoveAllObjects>( EventAction_RemoveAllObjects );
1986  const bool s15 = registerAction<DisplayImmediateMessage>( EventAction_DisplayImmediateMessage );
1987  const bool s16 = registerAction<AddProductionCapability>( EventAction_AddProductionCapabiligy );
1988  const bool s17 = registerAction<ChangeDiplomaticStatus>( EventAction_ChangeDiplomaticStatus );
1989  const bool s18 = registerAction<AddResources>( EventAction_AddResources );
1990  const bool s19 = registerAction<Reinforcements>( EventAction_Reinforcements );
1991  const bool s20 = registerAction<SetViewSharing>( EventAction_SetViewSharing );
1992  const bool s21 = registerAction<ChangePlayerState>( EventAction_ChangePlayerState );
1993 };
1994 
void execute(MapDisplayInterface *md)
DiplomaticStates getState(PlayerID towardsPlayer) const
Definition: player.cpp:92
ASCString getTypeName() const
Definition: gameevents.cpp:457
the time in ASC, measured in turns and moves
Definition: typen.h:178
TerrainType::Weather * typ
the terraintype of the field
Definition: mapfield.h:38
ASCString getDetailledName() const
Definition: gameevents.cpp:433
int fuel
Definition: typen.h:101
Player & getCurrentPlayer()
Definition: gamemap.h:268
void fieldOperator(const MapCoordinate &mc)
void triggered(const Context &context)
Definition: gameevents.cpp:707
virtual State getState(int player)
Definition: gameevents.cpp:595
The type of a field.
Definition: terraintype.h:75
virtual void readData(tnstream &stream)
Definition: gameevents.cpp:742
The (base-) classes which are thrown as exceptions.
sigc::signal< void, GameMap * > mapChanged
Definition: spfst.cpp:52
ItemRepositoryLoader< ObjectType > objectTypeRepository("objecttype")
int fieldAccessible(const MapField *field, const Vehicle *vehicle, int uheight, const bool *attacked, bool ignoreVisibility)
Definition: spfst.cpp:124
void triggered(const Context &context)
Definition: gameevents.cpp:792
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
ASCString getDetailledName() const
Definition: gameevents.cpp:828
virtual void writeData(tnstream &stream)
Definition: gameevents.cpp:663
int xsize
the size of the map
Definition: gamemap.h:201
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
MapCoordinate getFieldCoordinate(const MapCoordinate &entryOnMap, const LocalCoordinate &localCoordinate) const
returns the Mapcoordinate of a buildings field
ASCString getName() const
virtual void writeData(tnstream &stream)
Definition: gameevents.cpp:491
int computeview(GameMap *gamemap, int player_fieldcount_mask, bool disableShareView, const Context *context)
completely computes the view
void execute(MapDisplayInterface *md)
map accessing and usage routines used by ASC and the mapeditor
const BuildingType * typ
Definition: buildings.h:48
void readData(tnstream &stream)
#define chschwimmend
Definition: typen.h:412
virtual State getState(int player)
Definition: gameevents.cpp:390
bool chooseTerrain(int &terrainID)
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
void execute(MapDisplayInterface *md)
const char * name
Definition: gamemap.h:118
void readData(tnstream &stream)
ASCString getDetailledName() const
Definition: gameevents.cpp:126
virtual State getState(int player)
Definition: gameevents.cpp:799
Vehicle * vehicle
Definition: mapfield.h:89
EventAction_ID
Definition: gameevents.h:60
void eventReady(GameMap *gamemap)
void execute(MapDisplayInterface *md)
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
bool isHostile(PlayerID towardsPlayer) const
Definition: player.h:80
Definition: player.h:53
int connection
are any events connected to this field
Definition: mapfield.h:164
int energy
Definition: typen.h:99
bool valid() const
Definition: typen.h:221
virtual State getState(int player)
Definition: gameevents.cpp:233
void setnewposition(int x, int y)
checks whether the unit can construct a building of the given type.
Definition: vehicle.cpp:808
virtual ASCString getLocation()
returns the location of the stream.
Definition: basestrm.cpp:274
void execute(MapDisplayInterface *md)
ASCString getName() const
returns a name for the building. If the building itself has a name, it will be returned. If it doesn't, the name of the building type will be returned.
Definition: buildings.cpp:711
void getxy_building(int *x, int *y)
void execute(MapDisplayInterface *md)
Definition: gameevents.cpp:908
ASCString getDetailledName() const
Definition: gameevents.cpp:407
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
void execute(MapDisplayInterface *md)
void readData(tnstream &stream)
ASCString readtextmessage(int id)
returns the message with the given ID from the message system.
Definition: dlg_box.cpp:3048
void execute(MapDisplayInterface *md)
int chainbuildingtofield(const MapCoordinate &entryPos, bool setupImages=true)
registers the building at the given position on the map
Definition: buildings.cpp:268
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
GameMap * gamemap
ASCString getTypeName() const
Definition: gameevents.cpp:508
Context createContext(GameMap *gamemap)
Weather * weather[cwettertypennum]
Definition: terraintype.h:140
sigc::signal< void, Player & > sigMapWon
Definition: gamemap.h:498
DiplomaticStateVector diplomacy
Definition: player.h:209
int turn() const
Definition: typen.h:181
bool registerTrigger(EventTrigger_ID id)
int getOwner() const
returns the number of the player this vehicle/building belongs to
virtual State getState(int player)
Definition: gameevents.cpp:157
Vehicle * getVehicle() const
Definition: mapfield.h:94
ASCString getTypeName() const
Definition: gameevents.cpp:605
A local coordinate referencing a single field that a building covers.
Definition: buildingtype.h:57
void readData(tnstream &stream)
Definition: gameevents.cpp:915
virtual void updateDashboard()=0
static sigc::signal< void, ContainerBase * > anyContainerConquered
void writeData(tnstream &stream)
Definition: gameevents.cpp:989
bool isHuman() const
Definition: player.h:152
ASCString description
void setLocalizationString(const ASCString &s)
ASCString getDetailledName() const
Definition: gameevents.cpp:761
void setup()
Definition: gameevents.cpp:900
void readMapModificationData(tnstream &stream)
bool MultiLineEditor(const ASCString &title, ASCString &textToEdit)
Definition: paradialog.cpp:736
virtual State getState(int player)
Definition: gameevents.cpp:448
ASCString getTypeName() const
Definition: gameevents.cpp:756
void arm()
Definition: gameevents.cpp:380
void execute(MapDisplayInterface *md)
void execute(MapDisplayInterface *md)
void warningMessage(const ASCString &str)
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
MapCoordinate3D getPosition() const
returns the units position
Definition: vehicle.cpp:1552
Events events
Definition: gamemap.h:291
void fieldOperator(const MapCoordinate &mc)
Definition: gameevents.cpp:723
virtual ASCString getName() const =0
EventAction * action
#define chhochfliegend
Definition: typen.h:416
ASCString getDetailledName() const
Definition: gameevents.cpp:462
virtual State getState(int player)
Definition: gameevents.cpp:193
ASCString getDetailledName() const
Definition: gameevents.cpp:572
void readData(tnstream &stream)
ASCString getDetailledName() const
Definition: gameevents.cpp:319
void testfield(const MapCoordinate &pos)
void read(tnstream &stream)
Definition: typen.cpp:195
Global platform dependant definitions. This file just branches to the platform specific files in thei...
Interface for some basic classes from which all of ASC's dialogs are derived.
The interface for all kinds of IO stream.
a single field of the map
Definition: mapfield.h:26
ASCString getTypeName() const
Definition: gameevents.cpp:670
ASCString & format(const charT *pFormat,...)
Definition: ascstring.cpp:78
void writeData(tnstream &stream)
void readData(tnstream &stream)
void writeData(tnstream &stream)
Resources paid[8][8]
Definition: gamemap.h:340
struct GameMap::Weather weather
EventTrigger_ID
Definition: gameevents.h:40
void setgameparameter(GameParameter num, int value)
Definition: gamemap.cpp:1058
void viewunreadmessages(Player &player)
Definition: messagedlg.cpp:621
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void writetostream(tnstream *stream)
persist the contents in another stream
Definition: basestrm.cpp:2303
ASCString getName() const
Definition: gameevents.cpp:356
void triggered()
Definition: gameevents.cpp:299
sigc::signal< void, const Context & > fieldCrossed
Definition: spfst.cpp:54
void readData(tnstream &stream)
void editpolygon(Poly_gon &poly)
Definition: edmisc.cpp:807
void fieldOperator(const MapCoordinate &mc)
void fieldOperator(const MapCoordinate &mc)
bool chooseVehicleType(int &vehicleTypeID)
Handling the connection of buildings by pipelines, powerlines etc.
virtual void readData(tnstream &stream)
Definition: gameevents.cpp:807
void readData(tnstream &stream)
Definition: gameevents.cpp:863
void writeData(tnstream &stream)
virtual State getState(int player)
Definition: gameevents.cpp:477
ASCString getLocalizationString() const
void writeData(tnstream &stream)
virtual State getState(int player)
Definition: gameevents.cpp:713
void execute(MapDisplayInterface *md)
Definition: gameevents.cpp:874
int getWeather()
the weather that is on this field
Definition: mapfield.cpp:370
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
virtual void readData(tnstream &stream)
Definition: gameevents.cpp:71
void setup()
Definition: gameevents.cpp:368
int move() const
Definition: typen.h:180
ASCString ActionNameProvider()
Interface for various global functions and variables.
struct GameMap::PreferredFilenames preferredFileNames
void writeData(tnstream &stream)
bool fieldExists(const LocalCoordinate &localCoordinate) const
returns whether this building covers the given field
Definition: buildingtype.h:108
void writeData(tnstream &stream)
ASCString getDetailledName() const
Definition: gameevents.cpp:513
void next_turn(GameMap *gamemap, const NextTurnStrategy &nextTurnStrategy, MapDisplayInterface *display, int playerView)
void triggered()
Definition: gameevents.cpp:373
ASCString getDetailledName() const
Definition: gameevents.cpp:610
AddressingMode addressingMode
Definition: gameevents.h:101
void setState(PlayerID towardsPlayer, DiplomaticStates s)
Definition: player.cpp:115
void writeData(tnstream &stream)
Definition: gameevents.cpp:868
VehicleList vehicleList
a list of all units
Definition: player.h:135
ASCString getTypeName() const
Definition: gameevents.cpp:314
void Show(bool fade=false)
vector< GameTime > eventTimes
Definition: gamemap.h:293
virtual State getState(int player)
Definition: gameevents.cpp:325
ASCString getTypeName() const
Definition: gameevents.cpp:427
int putResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only intern...
Definition: controls.cpp:226
void execute(MapDisplayInterface *md)
void write(tnstream &stream) const
Definition: typen.cpp:201
Interface to the event handling of ASC.
ItemRepositoryLoader< TerrainType > terrainTypeRepository("terraintype")
void write(tnstream &stream) const
Definition: typen.h:212
Interface to game event dialogs.
enum Player::PlayerStatus stat
ASCString getTypeName() const
Definition: gameevents.cpp:823
sigc::signal< void > tributeTransferred
Definition: resourcenet.cpp:32
void initsearch(const MapCoordinate &startPosition, int _firstDistance, int _lastDistance)
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
FindUnitPlacementPos(GameMap *gamemap, Vehicle *veh)
void writeData(tnstream &stream)
Definition: gameevents.cpp:922
ASCString getName() const
returns the units name or, if it does not exist, the unit type's name or description ...
Definition: vehicle.cpp:1569
MapField * getField(const BuildingType::LocalCoordinate &localCoordinates) const
returns the pointer to the field which the given part of the building is standing on ...
Definition: buildings.cpp:399
Reads data from or writes data to a MemoryStreamStorage This allows a completely volatile storage of ...
Definition: basestrm.h:204
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
virtual void displayMap(void)=0
void displaymessage(const char *formatstring, int num,...)
displays a dialog box with a message
Definition: dlg_box.cpp:1849
void execute(MapDisplayInterface *md)
searches fields in hexagonal "circles" around a field and calls testfield for each field ...
Definition: mapalgorithms.h:28
bool paintPolygon(const Poly_gon &poly)
Definition: mappolygons.cpp:42
sigc::signal< void > destroyed
void readData(tnstream &stream)
virtual State getState(int player)
Definition: gameevents.cpp:248
MapCoordinate pos
Definition: gameevents.h:241
The interface for the buildingtype class.
int evaluateviewcalculation(GameMap *gamemap, int player_fieldcount_mask, bool disableShareView, const Context *context)
evaluates the view on the whole map.
void setup()
bool chooseWeather(int &weather)
virtual void writeData(tnstream &stream)
Definition: gameevents.cpp:76
void playerselall(int *playerbitmap)
void writeData(tnstream &stream)
Definition: gameevents.cpp:893
virtual void startsearch(void)
void setup()
void setup()
Definition: gameevents.cpp:114
virtual void readData(tnstream &stream)
Definition: gameevents.cpp:485
bool addobject(const ObjectType *obj, int dir=-1, bool force=false, ObjectRemovalStrategy *objectRemovalStrategy=NULL)
add an object to the field
Definition: mapfield.cpp:212
void readData(tnstream &stream)
Definition: gameevents.cpp:983
int material
Definition: typen.h:100
const ASCString & getMessage(void) const
Definition: errors.h:42
void addProductionLine(const VehicleType *type)
sigc::signal< void > buildingSeen
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
VehicleType * getvehicletype_byid(int id)
Definition: gamemap.cpp:1794
bool successful() const
void readClassContainer(C &c, tnstream &stream)
Definition: basestrm.h:752
void readData(tnstream &stream)
void setPolygon(const Poly_gon &poly_gon)
Vehicle * getUnit(int x, int y, int nwid)
Definition: gamemap.cpp:1215
Player player[9]
Definition: gamemap.h:253
ASCString getTypeName() const
Definition: gameevents.cpp:333
void writeData(tnstream &stream)
void arm()
Definition: gameevents.cpp:92
void readData(tnstream &stream)
void execute(MapDisplayInterface *md)
virtual State getState(int player)
Definition: gameevents.cpp:83
void fieldOperator(const MapCoordinate &mc)
Definition: gameevents.cpp:640
virtual State getState(int player)
Definition: gameevents.cpp:630
void writeData(tnstream &stream)
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
virtual State getState(int player)
Definition: gameevents.cpp:306
int ysize
Definition: gamemap.h:201
GameParameter
Definition: gamemap.h:77
ASCString getName() const
Definition: gameevents.cpp:138
bool registerAction(EventAction_ID id)
virtual void writeData(tnstream &stream)
Definition: gameevents.cpp:107
int connection
bitmapped: are there events that are triggered by actions affecting this building ...
Definition: buildings.h:60
void writeData(tnstream &stream)
void readData(tnstream &stream)
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
int height
the levels of height which this unit can enter
BuildingList buildingList
a list of all units
Definition: player.h:139
void writeData(tnstream &stream)
int selectunit(int unitnetworkid)
virtual void readData(tnstream &stream)
Definition: gameevents.cpp:343
class GameMap::IDManager idManager
void selectFields(FieldAddressing::Fields &fields)
int connection
if events are triggered by this unit (if it is lost for example), this will set connection != 0 ...
Definition: vehicle.h:133
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 convert(int player, bool recursive=true)
changes the building's owner.
Definition: buildings.cpp:105
virtual void writeData(tnstream &stream)
Definition: gameevents.cpp:749
int xpos
the position on the map
Definition: vehicle.h:124
Definition: player.h:53
void readData(tnstream &stream)
void setWeather(int weather)
Definition: mapfield.cpp:380
vector< MapCoordinate > CoordinateList
Definition: fieldmarker.h:45
void writeData(tnstream &stream)
ASCString getDetailledName() const
Definition: gameevents.cpp:676
void calculateAllObjects(void)
Definition: gamemap.cpp:1002
virtual void readData(tnstream &stream)
Definition: gameevents.cpp:220
procedure for loading and writing savegames, maps etc.
PlayerStatus
the status of the player
Definition: player.h:150
ASCString getTypeName() const
Definition: gameevents.cpp:577
int editInt(const ASCString &title, int defaultValue, int minValue, int maxValue)
Definition: dialog.cpp:2163
void readData(tnstream &stream)
void readfromstream(tnstream *stream)
read persisted contents from another stream
Definition: basestrm.cpp:2316
Building * building
Definition: mapfield.h:102
void readData(tnstream &stream)
void setup()
void execute(MapDisplayInterface *md)
void checkobjectsforremoval(GameMap *gamemap)
removes all objects that cannot exist where they currently are (terrainaccess)
Definition: spfst.cpp:247
#define maxint
Definition: typen.h:462
sigc::signal< void > conquered
GameMap * actmap
Definition: spfst.cpp:64
ASCString getTypeName() const
Definition: gameevents.cpp:121
void execute(MapDisplayInterface *md)
Definition: gameevents.cpp:975
void writeClassContainer(const C &c, tnstream &stream)
Definition: basestrm.h:742
enum GameMap::State state
void warning(const ASCString &str)
#define minint
Definition: typen.h:463
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
bool chooseObject(int &objectID)
int versionTest(tnstream &stream, int min, int max)
Definition: gameevents.cpp:63
virtual State getState(int player)
Definition: gameevents.cpp:416
GameMap * gamemap
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
virtual State getState(int player)
Definition: gameevents.cpp:561
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
Polygons polygons
Definition: gameevents.h:103
void writeData(tnstream &stream)
void writeData(tnstream &stream)
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
void writeData(tnstream &stream)
ASCString getDetailledName() const
Definition: gameevents.cpp:338
virtual void writeData(tnstream &stream)
Definition: gameevents.cpp:350
void setField(const MapCoordinate &pos)
static Building * newFromStream(GameMap *gamemap, tnstream &stream, bool chainToField=true)
Definition: buildings.cpp:523
void writeMapModificationData(tnstream &stream)
virtual void writeData(tnstream &stream)
Definition: gameevents.cpp:227
static bool comp(const GameTime &a, const GameTime &b)
Definition: typen.h:182
void readData(tnstream &stream)
Definition: gameevents.cpp:886
virtual void readData(tnstream &stream)
Definition: gameevents.cpp:100
int choice_dlg(const ASCString &title, const ASCString &leftButton, const ASCString &rightButton)
Definition: dialog.cpp:616
void setpointabs(int x, int y)
const Cargo & getCargo() const
sigc::signal< void > executed
virtual void fieldOperator(const MapCoordinate &mc)=0
virtual void writeData(tnstream &stream)
Definition: gameevents.cpp:815
int ypos
Definition: vehicle.h:124
static sigc::signal< void, ContainerBase * > anyContainerDestroyed
int getPlayerCount() const
Definition: gamemap.h:255
ASCString getTypeName() const
Definition: gameevents.cpp:401
void readData(tnstream &stream)
int chooseString(const ASCString &title, const vector< ASCString > &entries, int defaultEntry)
displays a dialogbox which lets you choose one of a number of strings.
Definition: dlg_box.cpp:3788
GameMap * gamemap
Definition: mapalgorithms.h:30
ASCString TriggerNameProvider()
void execute(MapDisplayInterface *md)
int networkid
a unique identification of the unit that is used everywhere in ASC (and not only the network protocol...
Definition: vehicle.h:140
MapCoordinate3D getPosition() const
returns the position of the buildings entry
Definition: buildings.h:152
bool exist() const
does the player exist at all
Definition: player.cpp:313
State state(int player)
takes the inversion into account, which getState(int) does not
void fieldOperator(const MapCoordinate &mc)
const char * savegameextension
Definition: loaders.cpp:78
void readData(tnstream &stream)
void addview()
adds the units view to the map.
Definition: vehicle.cpp:990
void execute(MapDisplayInterface *md)
GameTime time
the time in the game, mesured in a turns and moves
Definition: gamemap.h:235
void writeData(tnstream &stream)
void addview()
Adds the view and jamming of the building to the player's global radar field.
Definition: buildings.cpp:353
ObjectContainer objects
Definition: mapfield.h:124
int getid(const char *title, int lval, int min, int max)
Definition: dlg_box.cpp:3701
virtual void readData(tnstream &stream)
Definition: gameevents.cpp:656
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
bool continueplaying
if a player has won a singleplayer map, but wants to continue playing without any enemies...
Definition: gamemap.h:512
void set(int turn, int move)
Definition: typen.h:183
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