Advanced Strategic Command
guifunctions.cpp
Go to the documentation of this file.
1 
5 /*
6  This file is part of Advanced Strategic Command; http://www.asc-hq.de
7  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING. If not, write to the
21  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  Boston, MA 02111-1307 USA
23 */
24 
25 #include <stdio.h>
26 #include <cstring>
27 #include <stdlib.h>
28 
29 #include "guifunctions.h"
30 #include "guifunctions-interface.h"
31 #include "controls.h"
32 #include "dialog.h"
33 #include "gameoptions.h"
34 #include "iconrepository.h"
35 #include "attack.h"
36 #include "graphics/blitter.h"
37 #include "viewcalculation.h"
38 #include "spfst.h"
39 #include "dialogs/cargodialog.h"
41 #include "mapdisplay.h"
42 #include "sg.h"
43 #include "loaders.h"
44 #include "itemrepository.h"
45 #include "turncontrol.h"
46 #include "spfst-legacy.h"
52 #include "actions/attackcommand.h"
55 #include "actions/putminecommand.h"
57 #include "actions/servicecommand.h"
64 
66 {
68 }
69 
70 namespace GuiFunctions
71 {
72 
73 
74 
75 class AttackGui : public GuiIconHandler, public GuiFunction, public sigc::trackable
76 {
77  pair<const AttackWeap*, int> getEntry( const MapCoordinate& pos, int num );
78 
79  void mapDeleted( GameMap& map ) {
80  if ( NewGuiHost::getIconHandler() == this )
82  }
83 
84 protected:
85  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
86  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
87  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
88  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
89  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
90 
91 public:
93  GameMap::sigMapDeletion.connect( sigc::mem_fun( *this, &AttackGui::mapDeleted ));
94  };
98  };
99  void eval( const MapCoordinate& mc, ContainerBase* subject );
100 
101 };
102 
103 bool AttackGui :: checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
104 {
105  if ( key->keysym.sym == SDLK_ESCAPE || key->keysym.unicode == 'c' ) {
106  // execute( actmap->getCursor(), actmap->getField( actmap->getCursor())->getContainer() , -1 );
107  return true;
108  }
109  return false;
110 }
111 
112 
113 pair<const AttackWeap*, int> AttackGui::getEntry( const MapCoordinate& pos, int num )
114 {
115  int counter = 0;
116 
117  AttackCommand* attackEngine = dynamic_cast<AttackCommand*>(NewGuiHost::pendingCommand );
118  if ( attackEngine ) {
119  const AttackCommand::FieldList* afl = NULL;
120  for ( int i = 0; i < 3; ++i ) {
121  switch ( i ) {
122  case 0:
123  afl = &attackEngine->getAttackableUnits();
124  break;
125  case 1:
126  afl = &attackEngine->getAttackableBuildings();
127  break;
128  case 2:
129  afl = &attackEngine->getAttackableObjects();
130  break;
131  }
132 
133  AttackCommand::FieldList::const_iterator it = afl->find( pos );
134  if ( it != afl->end() ) {
135  const AttackWeap* aw = &(it->second);
136  for ( int a = 0; a < aw->count; ++a ) {
137  if ( counter == num )
138  return make_pair( aw, a );
139 
140  ++counter;
141  }
142  }
143  }
144  }
145  return make_pair( (AttackWeap*)(NULL), 0 );
146 }
147 
148 
149 bool AttackGui::available( const MapCoordinate& pos, ContainerBase* subject, int num )
150 {
151  if ( num == -1 )
152  return true;
153 
154  if ( getEntry(pos,num).first )
155  return true;
156  else
157  return false;
158 }
159 
160 void AttackGui::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
161 {
162  if ( num != -1 ) {
163 
164  pair<const AttackWeap*, int> p = getEntry(pos,num);
165  if ( p.first ) {
167  if ( attack ) {
168  attack->setTarget ( pos, p.first->num[p.second] );
169  ActionResult res = attack->execute( createContext( actmap ));
170  if ( !res.successful() ) {
171  dispmessage2 ( res );
173  }
174  }
175 
176  }
177  }
179 
180  actmap->cleartemps();
182  repaintMap();
183  updateFieldInfo();
184 }
185 
186 Surface& AttackGui::getImage( const MapCoordinate& pos, ContainerBase* subject, int num )
187 {
188  if ( num == -1 )
189  return IconRepository::getIcon("cancel.png");
190 
191  pair<const AttackWeap*, int> p = getEntry(pos,num);
192  switch ( p.first->typ[p.second] ) {
193  case cwcruisemissileb:
194  return IconRepository::getIcon("weap-cruisemissile.png");
195  case cwbombb:
196  return IconRepository::getIcon("weap-bomb.png");
197  case cwlargemissileb:
198  return IconRepository::getIcon("weap-bigmissile.png");
199  case cwsmallmissileb:
200  return IconRepository::getIcon("weap-smallmissile.png");
201  case cwtorpedob:
202  return IconRepository::getIcon("weap-torpedo.png");
203  case cwmachinegunb:
204  return IconRepository::getIcon("weap-machinegun.png");
205  case cwcannonb:
206  return IconRepository::getIcon("weap-cannon.png");
207  default:
208  return IconRepository::getIcon("weap-laser.png");
209  };
210 }
211 
212 ASCString AttackGui::getName( const MapCoordinate& pos, ContainerBase* subject, int num )
213 {
214 
215  AttackCommand* attackEngine = dynamic_cast<AttackCommand*>(NewGuiHost::pendingCommand);
216 
217  if ( num == -1 || attackEngine == NULL )
218  return "cancel";
219 
220  Vehicle* attacker = attackEngine->getAttacker();
221 
222  tfight* battle = NULL;
223 
224  pair<const AttackWeap*, int> p = getEntry(pos,num);
225 
226 
227  if ( p.first->target == AttackWeap::vehicle )
228  battle = new tunitattacksunit ( attacker, actmap->getField(pos)->vehicle, true, p.first->num[p.second] );
229  else if ( p.first->target == AttackWeap::building )
230  battle = new tunitattacksbuilding ( attacker, pos.x, pos.y, p.first->num[p.second] );
231  else if ( p.first->target == AttackWeap::object )
232  battle = new tunitattacksobject ( attacker, pos.x, pos.y, p.first->num[p.second] );
233 
234 
235  int dd = battle->dv.damage;
236  int ad = battle->av.damage;
237  battle->calc ( );
238 
239  ASCString result;
240  result.format( "%s; eff strength: %d; damage inflicted to enemy: %d, making a total of ~%d~; own damage will be +%d = %d", cwaffentypen[getFirstBit(p.first->typ[p.second])], battle->av.strength, battle->dv.damage-dd, battle->dv.damage, battle->av.damage-ad, battle->av.damage );
241  return result;
242 }
243 
244 
245 void AttackGui::eval( const MapCoordinate& mc, ContainerBase* subject )
246 {
247 
248  int num = 0;
249  while ( getEntry( mc, num).first ) {
250  GuiButton* b = host->getButton(num);
251  b->registerFunc( this, mc, subject, num );
252  b->Show();
253  ++num;
254  }
255 
256  GuiButton* b = host->getButton(num);
257  b->registerFunc( this, mc, subject, -1 );
258  b->Show();
259  ++num;
260 
261  host->disableButtons(num);
262 }
263 
264 
265 
267 
268 
269 
270 bool Cancel::available( const MapCoordinate& pos, ContainerBase* subject, int num )
271 {
272  return commandPending();
273 };
274 
275 void Cancel::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
276 {
280  }
281 
282  actmap->cleartemps(7);
283  updateFieldInfo();
284  displaymap();
285 };
286 
287 bool Cancel::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
288 {
289  return ( key->keysym.sym == SDLK_ESCAPE || key->keysym.unicode == 'c' );
290 };
291 
292 
293 Surface& Cancel::getImage( const MapCoordinate& po, ContainerBase* subject, int nums )
294 {
295  return IconRepository::getIcon("cancel.png");
296 };
297 
298 ASCString Cancel::getName( const MapCoordinate& pos, ContainerBase* subject, int num )
299 {
300  return "~c~ancel";
301 };
302 
303 
304 
305 bool Movement::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
306 {
307  return ( key->keysym.sym == SDLK_SPACE );
308 };
309 
310 Surface& Movement::getImage( const MapCoordinate& pos, ContainerBase* subject, int num )
311 {
312  return IconRepository::getIcon("movement.png");
313 };
314 
315 ASCString Movement::getName( const MapCoordinate& pos, ContainerBase* subject, int num )
316 {
317  return "move unit (~space~)";
318 };
319 
320 
321 bool MovementBase::available( const MapCoordinate& pos, ContainerBase* subject, int num )
322 {
323  if ( !commandPending() ) {
324  Vehicle* eht = actmap->getField(pos)->vehicle;
325  if ( eht )
326  if ( eht->getOwner() == actmap->actplayer)
327  return MoveUnitCommand::avail ( eht );
328  } else {
330  return false;
331 
332  MoveUnitCommand* moveCommand = dynamic_cast<MoveUnitCommand*>(NewGuiHost::pendingCommand);
333  if ( moveCommand && moveCommand->getVerticalDirection() == getVerticalDirection() ) {
334  const AStar3D::Path& path = moveCommand->getPath();
335  if ( path.size() == 0 )
336  return moveCommand->isFieldReachable(pos, true );
337  else
338  return path.rbegin()->x == pos.x && path.rbegin()->y == pos.y;
339  }
340  }
341  return false;
342 }
343 
345 {
346 }
347 
348 bool Movement::available( const MapCoordinate& pos, ContainerBase* subject, int num )
349 {
350  if ( !commandPending() ) {
351  return MovementBase::available( pos, subject, num );
352  } else {
353  MoveUnitCommand* moveCommand = dynamic_cast<MoveUnitCommand*>(NewGuiHost::pendingCommand);
354  if ( moveCommand && moveCommand->getVerticalDirection() == getVerticalDirection() ) {
355  bool avail = MovementBase::available( pos, subject, num );
356  if ( avail )
357  return true;
358  else {
359  return moveCommand->longDistAvailable( pos );
360  }
361  }
362  }
363  return false;
364 }
365 
366 
367 
368 
369 void MovementBase::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
370 {
371  if ( !commandPending() ) {
372  // This situation should have already been covered by MovementBase::available(), but there were crash reports with vehicle being NULL
373  if ( !actmap->getField(pos)->vehicle )
374  return;
375 
376 
378 
380 
381  int mode = 0;
382  if ( isKeyPressed( SDLK_LSHIFT ) || isKeyPressed( SDLK_RSHIFT )) {
383  if ( getVerticalDirection() == 0 )
385  else
387  }
388 
389  ActionResult res = move->searchFields ( -1, mode );
390  if ( !res.successful() ) {
391  dispmessage2 ( res.getCode(), NULL );
392  delete move;
393  return;
394  }
395 
396  for ( set<MapCoordinate3D>::const_iterator i = move->getReachableFields().begin(); i != move->getReachableFields().end(); ++i )
397  actmap->getField( *i)->setaTemp(1);
398 
399  // if ( !CGameOptions::Instance()->dontMarkFieldsNotAccessible_movement )
400  for ( set<MapCoordinate3D>::const_iterator i = move->getReachableFieldsIndirect().begin(); i != move->getReachableFieldsIndirect().end(); ++i )
401  actmap->getField( *i)->setaTemp2(2);
402  displaymap();
404  updateFieldInfo();
405 
406 
407  } else {
409  if ( !move || move->getVerticalDirection() != getVerticalDirection() )
410  return;
411 
412  move->setDestination( pos );
413 
414  if ( CGameOptions::Instance()->fastmove || move->getPath().size() ) {
415  move->calcPath();
416  actmap->cleartemps(7);
417  displaymap();
419  ActionResult res = move->execute( createContext(actmap));
421  if ( !res.successful() ) {
422  delete move;
423  dispmessage2(res);
424  updateFieldInfo();
425  return;
426  }
427  } else {
428  move->calcPath();
429  actmap->cleartemps(7);
430  for ( AStar3D::Path::const_iterator i = move->getPath().begin(); i != move->getPath().end(); ++i )
431  actmap->getField( *i ) ->setaTemp(1);
432  displaymap();
433  }
434  updateFieldInfo();
435  }
436 }
437 
438 
439 
440 
441 
442 class Ascend : public MovementBase
443 {
444 protected:
445  virtual void parametrizePathFinder( AStar3D& pathFinder ) {};
446 public:
447  // void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
448  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
449  return ( key->keysym.unicode == 's' );
450  };
451  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
452  return IconRepository::getIcon("ascend-airplane.png");
453  };
454  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
455  return "a~s~cend";
456  };
458  return 1;
459  };
460 
461  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
462  if ( !commandPending() ) {
463  Vehicle* eht = actmap->getField(pos)->vehicle;
464  if ( eht )
465  if ( eht->getOwner() == actmap->actplayer)
466  return MoveUnitCommand::ascendAvail ( eht );
467  return false;
468  } else
469  return MovementBase::available( pos, subject, num );
470  }
471 
472 };
473 
474 
475 
476 
477 
478 
479 class Descend : public MovementBase
480 {
481 protected:
483  return -1;
484  };
485 public:
486  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
487  return ( key->keysym.unicode == 'd' );
488  };
489  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
490  return IconRepository::getIcon("descent-airplane.png");
491  };
492  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
493  return "~d~escend";
494  };
495 
496  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
497  if ( !commandPending() ) {
498  Vehicle* eht = actmap->getField(pos)->vehicle;
499  if ( eht )
500  if ( eht->getOwner() == actmap->actplayer)
501  return MoveUnitCommand::descendAvail ( eht );
502  return false;
503  } else
504  return MovementBase::available( pos, subject, num );
505  }
506 
507 };
508 
509 
510 
511 
512 
513 class EndTurn : public GuiFunction
514 {
515 public:
516  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) ;
517  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
518  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
519  return ( key->keysym.unicode == 'e' );
520  };
521  Surface& getImage( const MapCoordinate& po, ContainerBase* subject, int nums ) {
522  return IconRepository::getIcon("endturn.png");
523  };
524  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
525  return "~e~nd turn";
526  };
527 };
528 
529 bool EndTurn::available( const MapCoordinate& pos, ContainerBase* subject, int num )
530 {
531  if (!commandPending() )
532  if (actmap->levelfinished == false)
533  return true;
534  return false;
535 }
536 
537 
538 void EndTurn::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
539 {
540  if ( !CGameOptions::Instance()->endturnquestion || (choice_dlg("do you really want to end your turn ?","~y~es","~n~o") == 1)) {
541 
542  Player& player = actmap->player[actmap->actplayer];
543  ASCString message = "The following units are about to crash\n\n";
544  bool crashWarning = checkUnitsForCrash( player, message );
545  if ( crashWarning ) {
546  if ( choiceDialog( message, "continue", "cancel", "AircraftCrashWarning" ) == 2 )
547  return;
548 
549  }
550 
551 
552  static int autosave = 0;
553  ASCString name = ASCString("autosave") + strrr( autosave ) + &savegameextension[1];
554 
555  savegame ( name, actmap );
556 
557 
558 
559  autosave = !autosave;
560 
562 
564 
565  displaymap();
566  }
567 }
568 
569 
570 class Attack : public GuiFunction
571 {
572 public:
573  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) ;
574  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
575  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
576  return ( key->keysym.unicode == 'a' );
577  };
578  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
579  return IconRepository::getIcon("attack.png");
580  };
581  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
582  return "~a~ttack";
583  };
584 };
585 
586 
587 bool Attack::available( const MapCoordinate& pos, ContainerBase* subject, int num )
588 {
589  if ( !commandPending() ) {
590  Vehicle* eht = actmap->getField(pos)->vehicle;
591  if ( eht )
592  if ( eht->color == actmap->actplayer * 8)
593  return AttackCommand::avail ( eht );
594  }
595  return false;
596 }
597 
598 void Attack::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
599 {
601 
602  ActionResult result = attack->searchTargets();
603  if ( !result.successful() ) {
604  dispmessage2 ( result );
605  return;
606  }
607 
608  AttackCommand::FieldList::const_iterator i;
609  for ( i = attack->getAttackableUnits().begin(); i != attack->getAttackableUnits().end(); i++ )
610  actmap->getField( i->first )->setaTemp(1);
611  for ( i = attack->getAttackableBuildings().begin(); i != attack->getAttackableBuildings().end(); i++ )
612  actmap->getField( i->first )->setaTemp(1);
613  for ( i = attack->getAttackableObjects().begin(); i != attack->getAttackableObjects().end(); i++ )
614  actmap->getField( i->first )->setaTemp(1);
615 
616  displaymap();
617  attackGui.setupWeapons( attack );
619 }
620 
621 
622 
623 
624 class PowerSwitch : public GuiFunction
625 {
626 private:
627  bool newState;
628 public:
629 
630  PowerSwitch( bool state ) : newState( state ) {};
631 
632  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
633  if (!commandPending() ) {
634  MapField* fld = actmap->getField ( pos );
635  if ( fld->vehicle )
636  return PowerGenerationSwitchCommand::avail( fld->vehicle, newState );
637 
638  }
639  return false;
640  };
641 
642  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
643  return ( key->keysym.unicode == 'p' );
644  };
645  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
646  auto_ptr<PowerGenerationSwitchCommand> pgsc ( new PowerGenerationSwitchCommand( actmap->getField(pos)->vehicle));
647  pgsc->setNewState( newState );
648  ActionResult res = pgsc->execute( createContext( actmap ));
649  if ( !res.successful() )
650  displayActionError( res );
651  else
652  pgsc.release();
653 
654  updateFieldInfo();
655  }
656 };
657 
658 
659 
660 class PowerOn : public PowerSwitch
661 {
662 public:
663  PowerOn() : PowerSwitch( true ) {};
664 
665  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
666  return IconRepository::getIcon("poweron.png");
667  };
668 
669  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
670  return "enable ~p~ower generation";
671  };
672 };
673 
674 
675 class PowerOff : public PowerSwitch
676 {
677 public:
678  PowerOff() : PowerSwitch( false ) {};
679 
680  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
681  return ( key->keysym.unicode == 'p' );
682  };
683 
684  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
685  return IconRepository::getIcon("poweroff.png");
686  };
687 
688  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
689  return "disable ~p~ower generation";
690  };
691 };
692 
693 
694 
695 class UnitInfo : public GuiFunction
696 {
697 public:
698  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) ;
699  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
701  };
702  Surface& getImage( const MapCoordinate& po, ContainerBase* subject, int nums ) {
703  return IconRepository::getIcon("unitinfo.png");
704  };
705  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
706  return "unit ~i~nfo";
707  };
708  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
709  return ( key->keysym.unicode == 'i' );
710  };
711 };
712 
713 bool UnitInfo::available( const MapCoordinate& pos, ContainerBase* subject, int num )
714 {
715  MapField* fld = actmap->getField(pos);
716  if ( fld && fld->vehicle )
717  if ( !commandPending() )
718  if ( fld->vehicle != NULL)
719  if (fieldvisiblenow( fld ))
720  return true;
721  return false;
722 }
723 
724 
725 
726 
727 
728 
730 {
731 public:
732  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) ;
733  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
734  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
735  return IconRepository::getIcon("destructbuilding.png");
736  };
737  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
738  return "destruct building";
739  };
740 };
741 
742 
743 bool DestructBuilding::available( const MapCoordinate& pos, ContainerBase* subject, int num )
744 {
745  MapField* fld = actmap->getField(pos);
746  if (!commandPending()) {
747  if ( fld->vehicle )
749  } else {
751  if ( dbc ) {
752  return dbc->isFieldUsable(pos);
753  }
754  }
755  return false;
756 }
757 
758 void DestructBuilding::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
759 {
761  if ( !dbc ) {
762  Vehicle* unit = actmap->getField(pos)->vehicle;
763  if ( !unit )
764  return;
765 
766  auto_ptr<DestructBuildingCommand> db ( new DestructBuildingCommand( unit ));
767 
768  vector<MapCoordinate> fields = db->getFields();
769 
770  if ( fields.empty() ) {
771  dispmessage2( 306, NULL );
772  return;
773  }
774  for ( vector<MapCoordinate>::iterator i = fields.begin(); i != fields.end(); ++i )
775  actmap->getField(*i)->setaTemp(1);
776 
777  repaintMap();
778 
779  NewGuiHost::pendingCommand = db.release();
780 
781  updateFieldInfo();
782 
783  } else {
784  dbc->setTargetPosition( pos );
785  actmap->cleartemps();
786 
787  ActionResult res = dbc->execute( createContext( actmap ));
788  if ( !res.successful() ) {
789  displayActionError(res);
791  }
793 
794  repaintMap();
795  updateFieldInfo();
796  }
797 }
798 
799 
801 {
802  static int containeractive;
803 public:
804  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
805  MapField* fld = actmap->getField(pos);
806  if ( fieldvisiblenow ( fld ) && fld->getContainer() ) {
807  if ( !containeractive && !commandPending() ) {
808  Player& player = fld->getContainer()->getMap()->player[fld->getContainer()->getOwner()];
810  if ( fld->building->getCompletion() == fld->building->typ->construction_steps-1 )
811  return true;
812  } else {
814  return true;
815  }
816  }
817  }
818  return false;
819  };
820 
821  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
822  MapField* fld = actmap->getField(pos);
823 
824  cargoDialog( fld->getContainer() );
825 
826  updateFieldInfo();
827  repaintMap();
828  }
829 
830  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
831  return IconRepository::getIcon("container.png");
832  };
833 
834  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
835  return ( key->keysym.unicode == 'l' );
836  };
837 
838  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
839  return "view ~l~oaded units";
840  };
841 };
842 
843 int OpenContainer::containeractive = 0;
844 
845 
846 
847 
849 {
850 public:
851  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
852  Vehicle* eht = actmap->getField(pos)->vehicle;
853  if ( !commandPending() )
854  if ( eht )
855  if ( eht->getOwner() == actmap->actplayer )
856  return ReactionFireSwitchCommand::avail( eht, true );
857 
858  return false;
859  };
860  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
861  return ( key->keysym.unicode == 'x' );
862  };
863 
864  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
865  Vehicle* eht = actmap->getField(pos)->vehicle;
866  auto_ptr<ReactionFireSwitchCommand> rf ( new ReactionFireSwitchCommand( eht ));
867  rf->setNewState( true );
868  ActionResult res = rf->execute( createContext( actmap ));
869  if ( res.successful() )
870  rf.release();
871  else
872  displayActionError( res );
873 
874  updateFieldInfo();
875  }
876 
877  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
878  return IconRepository::getIcon("enable-reactionfire.png");
879  };
880 
881  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
882  return "enable reaction fire (~x~)";
883  };
884 };
885 
887 {
888 public:
889  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
890  Vehicle* eht = actmap->getField(pos)->vehicle;
891  if ( !commandPending() )
892  if ( eht )
893  if ( eht->getOwner() == actmap->actplayer )
894  return ReactionFireSwitchCommand::avail( eht, false );
895 
896  return false;
897  };
898 
899  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
900  return ( key->keysym.unicode == 'x' );
901  };
902  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
903  Vehicle* eht = actmap->getField(pos)->vehicle;
904  auto_ptr<ReactionFireSwitchCommand> rf ( new ReactionFireSwitchCommand( eht ));
905  rf->setNewState( false );
906  ActionResult res = rf->execute( createContext( actmap ));
907  if ( res.successful() )
908  rf.release();
909  else
910  displayActionError( res );
911 
912  repaintMap();
913  updateFieldInfo();
914  }
915 
916  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
917  return IconRepository::getIcon("disable-reactionfire.png");
918  };
919 
920  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
921  return "disable reaction fire (~x~)";
922  };
923 };
924 
925 
926 class JumpDriveIcon : public GuiFunction, public sigc::trackable
927 {
928 public:
929  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
930  if ( !commandPending() ) {
931 
932  Vehicle* eht = actmap->getField(pos)->vehicle;
933  if ( eht )
934  if ( eht->getOwner() == actmap->actplayer )
936  } else {
938  if ( jdc ) {
939  if ( jdc->fieldReachable( pos ))
940  return true;
941  }
942  }
943 
944  return false;
945  };
946 
947  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
948  return ( key->keysym.unicode == 'j' );
949  };
950 
951  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
952  if ( !commandPending() ) {
953  Vehicle* eht = actmap->getField(pos)->vehicle;
954  if ( !eht )
955  return;
956 
958  if ( !aa.ready() ) {
959  warningMessage( aa.getMessage() );
960  return;
961  }
962 
963  auto_ptr<JumpDriveCommand> jdc ( new JumpDriveCommand( eht ));
964 
965  vector<MapCoordinate> fields = jdc->getDestinations();
966  for ( vector<MapCoordinate>::const_iterator i = fields.begin(); i != fields.end(); ++i )
967  actmap->getField(*i)->setaTemp(1);
968 
969  if ( fields.size() ) {
970  repaintMap();
971  NewGuiHost::pendingCommand = jdc.release();
972  updateFieldInfo();
973  } else
974  dispmessage2( 22602 );
975  } else {
977  if ( jdc ) {
979  jdc->setDestination( pos );
980  actmap->cleartemps(7);
981  ActionResult res = jdc->execute( createContext( actmap ));;
982  mapChanged( actmap );
983 
984  if ( !res.successful() ) {
986  displayActionError( res );
987  }
988  updateFieldInfo();
989  }
990  }
991  }
992 
993  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
994  return IconRepository::getIcon("jumpdrive.png");
995  };
996 
997  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
998  return "activate jump drive (~j~)";
999  };
1000 };
1001 
1002 
1003 
1004 class RepairUnit : public GuiFunction
1005 {
1006 public:
1007  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1008  MapField* fld = actmap->getField(pos);
1009  if (!commandPending()) {
1010  if ( fld && fld->vehicle )
1011  if (fld->vehicle->getOwner() == actmap->actplayer )
1013  return true;
1014  } else {
1017  if ( service && fld->vehicle )
1018  return service->validTarget( fld->vehicle );
1019  }
1020  }
1021  return false;
1022  };
1023 
1024  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
1025  return ( key->keysym.unicode == 'r' );
1026  };
1027  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1028  if ( !commandPending() ) {
1029  auto_ptr<RepairUnitCommand> rp ( new RepairUnitCommand( actmap->getField(pos)->vehicle ));
1030 
1031  vector<Vehicle*> targets = rp->getExternalTargets();
1032 
1033  int fieldCount = 0;
1034  for ( vector<Vehicle*>::iterator i = targets.begin(); i != targets.end(); ++i ) {
1035  actmap->getField ( (*i)->getPosition() )->setaTemp(1);
1036  fieldCount++;
1037  }
1038  if ( !fieldCount ) {
1039  dispmessage2 ( 211 );
1040  } else {
1041  NewGuiHost::pendingCommand = rp.release();
1042  repaintMap();
1043  updateFieldInfo();
1044  }
1045  } else {
1048  if ( service ) {
1049  MapField* fld = actmap->getField(pos);
1050  if ( fld->vehicle ) {
1051  service->setTarget( fld->vehicle );
1052  ActionResult res = service->execute( createContext ( actmap ));
1053  if ( !res.successful() ) {
1054  displayActionError(res);
1056  }
1058 
1059  actmap->cleartemps(7);
1060  repaintMap();
1061  updateFieldInfo();
1062  }
1063  }
1064  }
1065  }
1066  }
1067 
1068  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1069  return IconRepository::getIcon("repair.png");
1070  };
1071 
1072  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1073  MapField* fld = actmap->getField(pos);
1074  if ( fld && fld->vehicle && NewGuiHost::pendingCommand ) {
1076  if ( service ) {
1077  Resources r;
1078  service->getRepairingUnit( )->getMaxRepair ( fld->vehicle, 0, r);
1079  return "~r~epair unit (cost: " + r.toString() + ")";
1080  }
1081  }
1082  return "~r~epair a unit";
1083  };
1084 };
1085 
1086 
1087 
1088 
1090 {
1091 public:
1092  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1093  MapField* fld = actmap->getField(pos);
1094  if (!commandPending()) {
1095  if ( fld && fld->getContainer() )
1096  if (fld->getContainer()->getOwner() == actmap->actplayer )
1098  return true;
1099  } else {
1101  ServiceCommand* service = dynamic_cast<ServiceCommand*>(NewGuiHost::pendingCommand);
1102  if ( service && fld->getContainer() ) {
1103  const ServiceTargetSearcher::Targets& destinations = service->getDestinations();
1104  return find( destinations.begin(), destinations.end(), fld->getContainer() ) != destinations.end();
1105  }
1106  }
1107  }
1108  return false;
1109 
1110  };
1111  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
1112  return ( key->keysym.unicode == 'f' );
1113  };
1114 
1115  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1116  if ( !NewGuiHost::pendingCommand ) {
1117  auto_ptr<ServiceCommand> service ( new ServiceCommand( subject ));
1118 
1119  MapCoordinate srcPos = subject->getPosition();
1120  int fieldCount = 0;
1121 
1122  const ServiceTargetSearcher::Targets& destinations = service->getDestinations();
1123  for ( ServiceTargetSearcher::Targets::const_iterator i = destinations.begin(); i != destinations.end(); ++i ) {
1124  MapCoordinate targetPos = (*i)->getPosition();
1125  if ( targetPos != srcPos ) {
1126  MapField* fld = subject->getMap()->getField ( targetPos );
1127  fieldCount++;
1128  fld->setaTemp(1);
1129  }
1130  }
1131  if ( !fieldCount ) {
1132  dispmessage2 ( 211 );
1133  return;
1134  }
1135 
1136  NewGuiHost::pendingCommand = service.release();
1137  displaymap();
1138  updateFieldInfo();
1139 
1140  } else {
1141  ServiceCommand* service = dynamic_cast<ServiceCommand*>(NewGuiHost::pendingCommand);
1142 
1143  service->setDestination( subject );
1144  service->getTransferHandler().fillDest();
1145  service->saveTransfers();
1146  ActionResult res = service->execute( createContext( actmap ));
1147  if ( !res.successful() ) {
1148  dispmessage2( res );
1150  }
1151 
1153  actmap->cleartemps ( 7 );
1154  displaymap();
1155  updateFieldInfo();
1156  }
1157  }
1158 
1159  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1160  return IconRepository::getIcon("refuel.png");
1161  };
1162 
1163  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1164  return "re~f~uel a unit";
1165  };
1166 };
1167 
1168 
1170 {
1171 public:
1172  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1174  ServiceCommand* service = dynamic_cast<ServiceCommand*>(NewGuiHost::pendingCommand);
1175  MapField* fld = actmap->getField(pos);
1176  if ( service && fld->getContainer() ) {
1177  const ServiceTargetSearcher::Targets& destinations = service->getDestinations();
1178  return find( destinations.begin(), destinations.end(), fld->getContainer() ) != destinations.end();
1179  }
1180  }
1181  return false;
1182  };
1183  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
1184  return ( key->keysym.unicode == 'f' && (modifier & KMOD_SHIFT) );
1185  };
1186 
1187  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1188  ServiceCommand* service = dynamic_cast<ServiceCommand*>(NewGuiHost::pendingCommand);
1189  MapField* fld = actmap->getField(pos);
1190  service->setDestination( fld->getContainer() );
1191  ammoTransferWindow( service->getRefueller(), actmap->getField(pos)->getContainer(), service );
1192 
1193  if ( service->getState() != Command::Finished )
1195 
1197  actmap->cleartemps ( 7 );
1198  displaymap();
1199  updateFieldInfo();
1200  }
1201 
1202  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1203  return IconRepository::getIcon("refuel-dialog.png");
1204  };
1205 
1206  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1207  return "re~F~uel dialog ";
1208  };
1209 };
1210 
1211 
1212 
1213 class PutMine : public GuiFunction
1214 {
1215 public:
1216  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1217  MapField* fld = actmap->getField(pos);
1218  if ( !commandPending())
1219  if ( fld->vehicle )
1220  return PutMineCommand::avail(fld->vehicle);
1221  return false;
1222  };
1223 
1224  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
1225  return ( key->keysym.unicode == 'm' );
1226  };
1227 
1228  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1229  MapField* fld = actmap->getField(pos);
1230  if ( fld->vehicle ) {
1231  auto_ptr<PutMineCommand> poc ( new PutMineCommand( actmap->getField(pos)->vehicle ));
1232  ActionResult res = poc->searchFields();
1233  if ( res.successful() ) {
1234  vector<MapCoordinate> fields = poc->getFields();
1235  for ( vector<MapCoordinate>::iterator i = fields.begin(); i != fields.end(); ++i )
1236  actmap->getField(*i)->setaTemp(1);
1237 
1238  NewGuiHost::pendingCommand = poc.get();
1239  poc.release();
1240 
1241  repaintMap();
1242  updateFieldInfo();
1243  } else
1244  MessagingHub::Instance().statusInformation("can't build or remove any objects here");
1245  }
1246  }
1247 
1248  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1249  return IconRepository::getIcon("putmine.png");
1250  };
1251 
1252  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1253  return "put / remove ~m~ines";
1254  };
1255 };
1256 
1257 
1259 {
1260 private:
1261  MineTypes type;
1262 protected:
1264  this->type = type;
1265  };
1266 
1267 public:
1268  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1270  return false;
1271 
1272  PutMineCommand* pmc = dynamic_cast<PutMineCommand*>( NewGuiHost::pendingCommand );
1273  if ( pmc ) {
1274  const vector<MineTypes>& mines = pmc->getCreatableMines( pos );
1275  for ( vector<MineTypes>::const_iterator i = mines.begin(); i != mines.end(); ++i )
1276  if ( *i == type )
1277  return true;
1278  }
1279  return false;
1280  };
1281 
1282  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1283  PutMineCommand* pmc = dynamic_cast<PutMineCommand*>( NewGuiHost::pendingCommand );
1284  if ( pmc ) {
1285  actmap->cleartemps();
1286  pmc->setCreationTarget( pos, type );
1287  ActionResult res = pmc->execute( createContext( actmap ));
1288  if ( !res.successful() ) {
1289  displayActionError(res);
1291  }
1293  updateFieldInfo();
1294  }
1295  }
1296 };
1297 
1299 {
1300 public:
1301 
1303 
1304  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1305  return IconRepository::getIcon("putantitankmine.png");
1306  };
1307 
1308  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1309  return "put anti-tank mine";
1310  };
1311 };
1312 
1314 {
1315 public:
1316 
1318 
1319  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1320  return IconRepository::getIcon("putantipersonalmine.png");
1321  };
1322 
1323  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1324  return "put anti-personnel mine";
1325  };
1326 };
1327 
1328 
1329 
1330 
1332 {
1333 public:
1335 
1336  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1337  return IconRepository::getIcon("putantishipmine.png");
1338  };
1339 
1340  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1341  return "put anti-ship mine";
1342  };
1343 };
1344 
1346 {
1347 public:
1349 
1350  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1351  return IconRepository::getIcon("putantisubmine.png");
1352  };
1353 
1354  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1355  return "put anti-submarine mine";
1356  };
1357 };
1358 
1359 
1360 class RemoveMine : public GuiFunction
1361 {
1362 public:
1363  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1365  return false;
1366 
1367  PutMineCommand* pmc = dynamic_cast<PutMineCommand*>( NewGuiHost::pendingCommand );
1368  if ( pmc )
1369  return pmc->getRemovableMines(pos);
1370 
1371  return false;
1372  };
1373 
1374  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1375  PutMineCommand* pmc = dynamic_cast<PutMineCommand*>( NewGuiHost::pendingCommand );
1376  if ( pmc ) {
1377  pmc->setRemovalTarget( pos );
1378  actmap->cleartemps();
1379  ActionResult res = pmc->execute( createContext( actmap ));
1380  if ( !res.successful() ) {
1381  displayActionError(res);
1383  }
1385  updateFieldInfo();
1386  }
1387  }
1388 
1389  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1390  return IconRepository::getIcon("removemine.png");
1391  };
1392 
1393  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1394  return "remove mine";
1395  };
1396 };
1397 
1398 
1399 
1400 
1401 
1402 
1403 class ObjectBuildingGui : public GuiIconHandler, public GuiFunction, public sigc::trackable
1404 {
1405  Vehicle* veh;
1406 
1407  void mapDeleted( GameMap& map ) {
1408  if ( NewGuiHost::getIconHandler() == this )
1410  }
1411 
1412 protected:
1413  enum Mode { Build, Remove };
1414 
1415  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
1416  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
1417  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
1418  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
1419 
1420  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
1421 
1422  void addButton( int &num, const MapCoordinate& mc, ContainerBase* subject, int id );
1423 
1424 public:
1425  ObjectBuildingGui() : veh( NULL ) {
1426  GameMap::sigMapDeletion.connect( sigc::mem_fun( *this, &ObjectBuildingGui::mapDeleted ));
1427  };
1428 
1429  bool init( Vehicle* vehicle );
1430  void eval( const MapCoordinate& mc, ContainerBase* subject );
1431 
1432 };
1433 
1434 
1436 {
1437  veh = vehicle;
1438  return true;
1439 }
1440 
1441 
1442 bool ObjectBuildingGui::available( const MapCoordinate& pos, ContainerBase* subject, int num )
1443 {
1444  return true;
1445  /*
1446  if ( num == 0 )
1447  return true;
1448 
1449  checkObject
1450 
1451  if ( getEntry(pos,num).first )
1452  return true;
1453  else
1454  return false;
1455  */
1456 }
1457 
1458 void ObjectBuildingGui::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
1459 {
1461  actmap->cleartemps();
1462  if ( num && poc ) {
1463  poc->setTarget( pos, abs(num) );
1464  ActionResult res = poc->execute( createContext( actmap ));
1465  if ( !res.successful()) {
1466  displayActionError(res);
1468  }
1469  } else {
1471  }
1472  repaintMap();
1473 
1475 
1477  updateFieldInfo();
1478 }
1479 
1480 
1481 Surface buildGuiIcon( const Surface& image, bool remove = false )
1482 {
1483  const Surface& cancelIcon = IconRepository::getIcon("empty-pressed.png" ); // "cancel.png"
1484  Surface s = Surface::createSurface( cancelIcon.w(), cancelIcon.h(), 32, 0 );
1485 
1486  const Surface& o = image;
1487  if ( o.GetPixelFormat().BitsPerPixel() == 32 ) {
1489  blitter.setSize( o.w(), o.h(), s.w(), s.h() );
1490  blitter.blit( o, s, SPoint(int((s.w() - blitter.getZoomX() * o.w())/2), int((s.h() - blitter.getZoomY() * o.h())/2)));
1491  } else {
1493  blitter.setSize( o.w(), o.h(), s.w(), s.h() );
1494  blitter.blit( o, s, SPoint(int((s.w() - blitter.getZoomX() * o.w())/2), int((s.h() - blitter.getZoomY() * o.h())/2)));
1495  }
1496 
1497  if ( remove ) {
1499  Surface& removegui = IconRepository::getIcon( "cancel-addon.png" );
1500  blitter.blit( removegui, s, SPoint((s.w() - removegui.w())/2, (s.h() - removegui.h())/2));
1501  }
1502  return s;
1503 }
1504 
1505 
1506 bool ObjectBuildingGui::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
1507 {
1508  if ( num > 0 )
1509  return false;
1510  else
1511  return ( key->keysym.sym == SDLK_ESCAPE || key->keysym.unicode == 'c' );
1512 }
1513 
1515 {
1516  if ( num == 0 )
1517  return IconRepository::getIcon("cancel.png");
1518 
1519  ObjectType* objtype = objectTypeRepository.getObject_byID( abs(num) );
1520 
1521  if ( !objtype )
1522  return IconRepository::getIcon("cancel.png");
1523 
1524  static map<int,Surface> removeIconRepository;
1525 
1526  if ( removeIconRepository.find( num ) != removeIconRepository.end() )
1527  return removeIconRepository[num];
1528 
1529  removeIconRepository[num] = buildGuiIcon( objtype->getPicture(), num < 0 );
1530  return removeIconRepository[num];
1531 }
1532 
1533 
1535 {
1536  if ( num == 0 )
1537  return "~c~ancel";
1538 
1539  ObjectType* objtype = objectTypeRepository.getObject_byID( abs(num) );
1540  if ( !objtype )
1541  return "";
1542 
1543  ASCString result;
1544  if ( num >= 0 ) {
1545  result.format( "Build %s (%d Material, %d Fuel, %d Movepoints)", objtype->name.c_str(), objtype->buildcost.material, objtype->buildcost.fuel, objtype->build_movecost );
1546  // num = -num;
1547  } else
1548  result.format( "Remove %s (%d Material, %d Fuel, %d Movepoints)", objtype->name.c_str(), objtype->removecost.material, objtype->removecost.fuel, objtype->remove_movecost );
1549 
1550  return result;
1551 }
1552 
1553 
1554 
1555 void ObjectBuildingGui::addButton( int &num, const MapCoordinate& mc, ContainerBase* subject, int id )
1556 {
1557  GuiButton* b = host->getButton(num);
1558  b->registerFunc( this, mc, subject, id );
1559  b->Show();
1560  ++num;
1561 }
1562 
1563 
1564 
1566 {
1568 
1569  if ( poc ) {
1570  int num = 0;
1571  const set<int>& creatable = poc->getCreatableObjects( mc );
1572  for ( set<int>::const_iterator i = creatable.begin(); i != creatable.end(); ++i ) {
1573  addButton(num, mc, veh, *i);
1574  }
1575 
1576 
1577  const set<int>& removable = poc->getRemovableObjects( mc );
1578  for ( set<int>::const_iterator i = removable.begin(); i != removable.end(); ++i ) {
1579  addButton(num, mc, veh, -(*i));
1580  }
1581 
1582  GuiButton* b = host->getButton(num);
1583  b->registerFunc( this, mc, subject, 0 );
1584  b->Show();
1585  ++num;
1586 
1587  host->disableButtons(num);
1588  }
1589 
1590 }
1591 
1592 
1593 
1595 
1596 
1597 class BuildObject : public GuiFunction
1598 {
1599 public:
1600  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) ;
1601  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
1602  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1603  return IconRepository::getIcon("buildobjects.png");
1604  };
1605  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1606  return "~c~onstruct / remove objects";
1607  };
1608  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
1609  return ( key->keysym.unicode == 'c' );
1610  };
1611 };
1612 
1613 
1614 bool BuildObject::available( const MapCoordinate& pos, ContainerBase* subject, int num )
1615 {
1616  MapField* fld = actmap->getField(pos);
1617  if (!commandPending())
1618  if ( fld && fld->vehicle )
1619  return PutObjectCommand::avail(fld->vehicle );
1620  return false;
1621 }
1622 
1623 void BuildObject::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
1624 {
1625  MapField* fld = actmap->getField(pos);
1626  if ( fld->vehicle ) {
1627  auto_ptr<PutObjectCommand> poc ( new PutObjectCommand( actmap->getField(pos)->vehicle ));
1628  ActionResult res =poc->searchFields();
1629  if ( res.successful() ) {
1630  vector<MapCoordinate> fields = poc->getFields();
1631  for ( vector<MapCoordinate>::iterator i = fields.begin(); i != fields.end(); ++i )
1632  actmap->getField(*i)->setaTemp(1);
1633 
1634  NewGuiHost::pendingCommand = poc.get();
1635  poc.release();
1637 
1638  repaintMap();
1639  updateFieldInfo();
1640  } else
1641  MessagingHub::Instance().statusInformation("can't build or remove any objects here");
1642  }
1643 }
1644 
1645 
1646 
1647 
1648 
1650 {
1651 public:
1652  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) ;
1653  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
1654  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1655  return IconRepository::getIcon("constructunit.png");
1656  };
1657  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1658  return "Unit construction Command";
1659  };
1660 };
1661 
1662 
1663 bool BuildVehicleCommand::available( const MapCoordinate& pos, ContainerBase* subject, int num )
1664 {
1665  MapField* fld = actmap->getField(pos);
1666  if (!commandPending())
1667  if ( fld && fld->vehicle )
1668  if (fld->vehicle->getOwner() == actmap->actplayer )
1670 
1673  if ( construct )
1674  return construct->isFieldUsable(pos);
1675 
1676  }
1677  return false;
1678 }
1679 
1680 void BuildVehicleCommand::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
1681 {
1682 
1684  if ( !construct ) {
1685  delete construct;
1686  auto_ptr<ConstructUnitCommand> constructCommand ( new ConstructUnitCommand( subject ));
1687  constructCommand->setMode( ConstructUnitCommand::external);
1688  ConstructUnitCommand::Producables buildables = constructCommand->getProduceableVehicles();
1689 
1690  VehicleProduction_SelectionWindow fsw( NULL, PG_Rect( 10, 10, 450, 550 ), subject, buildables, false );
1691  fsw.Show();
1692  fsw.RunModal();
1693  const VehicleType* v = fsw.getVehicletype();
1694  if ( v ) {
1695 
1696  for ( ConstructUnitCommand::Producables::const_iterator i = buildables.begin(); i != buildables.end(); ++i )
1697  if ( i->type == v ) {
1699  warningMessage("Not enough resources to build unit");
1700  return;
1701  }
1702 
1703  if ( i->prerequisites.getValue() & ( ConstructUnitCommand::Lack::Movement )) {
1704  ASCString message = "Not enough movement to build unit";
1705  Vehicle* constructor = dynamic_cast<Vehicle*>(subject);
1706  if ( constructor )
1707  message += "\nRequired: " + ASCString::toString(constructor->typ->unitConstructionMoveCostPercentage * constructor->maxMovement() / 100 ) + " points";
1708  warningMessage(message);
1709  return;
1710  }
1711 
1712  if ( i->prerequisites.getValue() & ( ConstructUnitCommand::Lack::Research )) {
1713  warningMessage("This unit has not been researched yet");
1714  return;
1715  }
1716  }
1717 
1718 
1719  constructCommand->setVehicleType( v );
1720  vector<MapCoordinate> fields = constructCommand->getFields();
1721 
1722  if ( fields.size() ) {
1723  for ( vector<MapCoordinate>::const_iterator i = fields.begin(); i != fields.end(); ++i )
1724  subject->getMap()->getField( *i )->setaTemp(1);
1725 
1726  repaintMap();
1727 
1728  NewGuiHost::pendingCommand = constructCommand.release();
1729 
1730  updateFieldInfo();
1731 
1732  } else {
1733  warningMessage("no fields to construct unit.\n" + v->terrainaccess.toString());
1734  }
1735  }
1736  } else {
1737  actmap->cleartemps();
1738  construct->setTargetPosition( pos );
1739  ActionResult res = construct->execute ( createContext( actmap ) );
1740  if ( !res.successful() ) {
1742  repaintMap();
1743  dispmessage2( res );
1744  }
1746  updateFieldInfo();
1747  }
1748 
1749 }
1750 
1751 
1752 
1754 {
1755  Surface s = Surface::createSurface(500,500,32, 0);
1756 
1757  int minx = 1000;
1758  int miny = 1000;
1759  int maxx = 0;
1760  int maxy = 0;
1761 
1762  for (int y = 0; y <= 5; y++)
1763  for (int x = 0; x <= 3; x++)
1764  if (bld->fieldExists( BuildingType::LocalCoordinate(x,y) ) ) {
1765  int xp = fielddistx * x + fielddisthalfx * ( y & 1);
1766  int yp = fielddisty * y ;
1767  if ( xp < minx )
1768  minx = xp;
1769  if ( yp < miny )
1770  miny = yp;
1771  if ( xp > maxx )
1772  maxx = xp;
1773  if ( yp > maxy )
1774  maxy = yp;
1775 
1776  // bld->paintSingleField( s, SPoint(xp,yp), BuildingType::LocalCoordinate(x,y) );
1777  bld->paintSingleField( s, SPoint(xp,yp),BuildingType::LocalCoordinate(x,y) );
1778  }
1779  maxx += fieldxsize;
1780  maxy += fieldysize;
1781 
1782  /*
1783  Surface sc = Surface::Wrap( PG_Application::GetScreen() );
1784  sc.Blit( s, SPoint(0,0 ));
1785  PG_Application::UpdateRect( PG_Application::GetScreen(), 0,0,0,0);
1786  */
1787 
1788  Surface s2 = Surface::createSurface(maxx-minx+1,maxy-miny+1,32,0);
1789  // s2.Blit( s, SDLmm::SRect(SPoint(minx,miny), SPoint(maxx,maxy) ), SPoint(0,0));
1790 
1792  blitter.setSrcRectangle( SPoint( minx, miny ), maxx-minx, maxy-miny );
1793  blitter.blit ( s, s2, SPoint(0,0) );
1794 
1795  /*
1796 
1797  MegaBlitter<4,4,ColorTransform_None,ColorMerger_AlphaOverwrite,SourcePixelSelector_Zoom> blitter;
1798 
1799  blitter.setSize( s2.w(), s2.h(), s3.w(), s3.h() );
1800  blitter.initSource ( s2 );
1801  blitter.blit ( s2, s3, SPoint((s3.w() - blitter.getWidth())/2, (s3.h() - blitter.getHeight())/2) );
1802  */
1803 
1804  return s2;
1805 }
1806 
1807 
1809 {
1810 public:
1811  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) ;
1812  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
1813  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1814  return IconRepository::getIcon("constructbuilding.png");
1815  };
1816  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1818  if ( !build )
1819  return "Building construction";
1820  else {
1821  return "Select building entrance position";
1822  }
1823  };
1824 };
1825 
1826 
1827 bool ConstructBuilding::available( const MapCoordinate& pos, ContainerBase* subject, int num )
1828 {
1829  MapField* fld = actmap->getField(pos);
1830  if (!commandPending()) {
1831  if ( fld->vehicle )
1833  if (fld->vehicle->getOwner() == actmap->actplayer )
1834  return true;
1835  }
1836 
1838  if ( build )
1839  return build->isFieldUsable( pos );
1840 
1841  return false;
1842 }
1843 
1844 
1846 {
1847 private:
1848  const BuildingType* selectedType;
1849 protected:
1850  void BuildingTypeSelected( const BuildingType* type ) {
1851  selectedType = type;
1852  };
1853 public:
1854  BuildingConstructionSelection ( Resources plantResources, const Container& types, const Player& player ) : BuildingTypeSelectionItemFactory(plantResources, types, player ), selectedType(NULL) {};
1856  return selectedType;
1857  };
1858 };
1859 
1860 void ConstructBuilding::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
1861 {
1862 
1864 
1865  if ( !build ) {
1866  MapField* fld = actmap->getField(pos);
1867 
1868 
1869  auto_ptr<ConstructBuildingCommand> cbc ( new ConstructBuildingCommand( fld->vehicle ));
1870 
1871  ConstructBuildingCommand::Producables producables = cbc->getProduceableBuildings();
1872 
1874  for ( ConstructBuildingCommand::Producables::const_iterator i = producables.begin(); i != producables.end(); ++i )
1875  if ( !( i->prerequisites.getValue() & (ConstructBuildingCommand::Lack::Research | ConstructBuildingCommand::Lack::Level )))
1876  buildings.push_back( i->type );
1877 
1878  if ( buildings.empty() ) {
1879  dispmessage2( 303, NULL );
1880  return;
1881  }
1882 
1883 
1885  ItemSelectorWindow isw ( NULL, PG_Rect( -1, -1, 550, 650), "Select Building", bcs);
1886  isw.Show();
1887  isw.RunModal();
1888  isw.Hide();
1889 
1890  if ( bcs->getSelectedType() && cbc->buildingProductionPrerequisites( bcs->getSelectedType()).ok() ) {
1891 
1892  cbc->setBuildingType( bcs->getSelectedType() );
1893 
1894  vector<MapCoordinate> fields = cbc->getFields();
1895  if ( fields.size() == 0 ) {
1896  dispmessage2(301, NULL );
1897  return;
1898  }
1899 
1900  for ( vector<MapCoordinate>::iterator i = fields.begin(); i != fields.end(); ++i )
1901  actmap->getField(*i)->setaTemp(1);
1902 
1903  repaintMap();
1904 
1905  NewGuiHost::pendingCommand = cbc.release();
1906 
1907  updateFieldInfo();
1908  }
1909  } else {
1910  actmap->cleartemps();
1911  build->setTargetPosition( pos );
1912  ActionResult res = build->execute( createContext( actmap ));
1913 
1914  if ( !res.successful() ) {
1915  displayActionError(res);
1917  }
1918 
1920 
1921 
1922  updateFieldInfo();
1923  }
1924 }
1925 
1926 
1927 
1928 
1929 
1930 
1932 {
1933 public:
1934  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1935 
1936  // deactivated, because there shouldn't be any units left which need this function
1937  return false;
1938 
1939  if ( subject && subject->getMap()->getPlayer(subject).diplomacy.isAllied( subject->getMap()->actplayer ))
1940  if (!commandPending()) {
1941  Vehicle* v = dynamic_cast<Vehicle*>(subject);
1942  if ( v )
1944  }
1945 
1946  return false;
1947  };
1948 
1949  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
1950  return ( key->keysym.unicode == 't' && (modifier & KMOD_SHIFT) );
1951  };
1952 
1953  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1954  internalAmmoTransferWindow( (Vehicle*) subject );
1955  displaymap();
1956  updateFieldInfo();
1957  }
1958 
1959  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1960  return IconRepository::getIcon("internalAmmoTransfer-dialog.png");
1961  };
1962 
1963  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1964  return "internal Ammo ~T~ransfer dialog ";
1965  };
1966 };
1967 
1969 {
1970  static int containeractive;
1971 public:
1972  bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1973  MapField* fld = actmap->getField(pos);
1974  ContainerBase* c = fld->getContainer();
1976  return DestructUnitCommand::avail( c );
1977  else
1978  return false;
1979  };
1980 
1981  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1982  MapField* fld = actmap->getField(pos);
1983  if (choice_dlg("do you really want to destruct this unit?","~y~es","~n~o") == 1) {
1984  auto_ptr<DestructUnitCommand> destructor ( new DestructUnitCommand( fld->getContainer() ));
1985  ActionResult res = destructor->execute( createContext( actmap ) );
1986  if ( res.successful() )
1987  destructor.release();
1988  else
1989  displayActionError( res );
1990  updateFieldInfo();
1991  repaintMap();
1992  }
1993  }
1994 
1995  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) {
1996  return IconRepository::getIcon("self-destruct.png");
1997  };
1998 
1999  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) {
2000  return false;
2001  };
2002 
2003  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) {
2004  return "self destruct";
2005  };
2006 };
2007 
2008 
2009 
2011 
2012 
2013 
2014 
2015 
2016 
2017 } // namespace GuiFunctions
2018 
2019 
2020 
2022 {
2025  handler.registerUserFunction( new GuiFunctions::Attack() );
2033 // handler.registerUserFunction( new GuiFunctions::SearchForMineralResources() );
2042  // handler.registerUserFunction( new GuiFunctions::ViewMap );
2050 
2053  handler.registerUserFunction( new GuiFunctions::Cancel() );
2054 
2055 }
2056 
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
int fuel
Definition: typen.h:101
Player & getCurrentPlayer()
Definition: gamemap.h:268
#define cwcruisemissileb
Definition: vehicletype.h:66
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
void displaymap()
Definition: spfst.cpp:58
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
void disableButtons(int i)
disables all button from i onward
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
void setCreationTarget(const MapCoordinate &target, MineTypes mineType)
sigc::signal< void, GameMap * > mapChanged
Definition: spfst.cpp:52
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void paintSingleField(Surface &s, SPoint pos, const LocalCoordinate &localCoordinate, const PlayerColor &player, int weather=0, int constructionStep=0) const
const set< int > & getRemovableObjects(const MapCoordinate &pos)
void setaTemp(Uint8 atemp)
Various algorithms need to store some information in the fields they process.
Definition: mapfield.cpp:49
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
GuiButton * getButton(int i)
ItemRepositoryLoader< ObjectType > objectTypeRepository("objecttype")
void setTargetPosition(const MapCoordinate &pos)
void cleartemps(int b=-1, int value=0)
Definition: gamemap.cpp:964
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
MapDisplayInterface & getDefaultMapDisplay()
int maxLoadableUnits
the maximum number of units that can be loaded
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
const AStar3D::Path & getPath()
map accessing and usage routines used by ASC and the mapeditor
const BuildingType * typ
Definition: buildings.h:48
struct tfight::tavalues dv
int maxMovement() const
the maximum distance that the unit can drive in a single turn on the current level of height ...
Definition: vehicle.cpp:1069
const vector< MineTypes > & getCreatableMines(const MapCoordinate &pos)
AttackGui attackGui
map< MapCoordinate, AttackWeap > FieldList
Definition: attackcommand.h:34
int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
Definition: vehicle.cpp:328
int getMaxRepair(const ContainerBase *item) const
returns the maximum amount of damage that the given item can be repaired
static bool avail(const Vehicle *unit, bool newState)
the command is totally done
Definition: command.h:120
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
Vehicle * vehicle
Definition: mapfield.h:89
bool isFieldUsable(const MapCoordinate &pos)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
Structure to store the weapons which a unit can use to perform an attack.
Definition: attack.h:291
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void registerUserFunction(GuiFunction *function)
registers a user function.
bool commandPending()
struct tfight::tavalues av
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void ammoTransferWindow(ContainerBase *source, ContainerBase *destination, ServiceCommand *command)
void move(Vehicle *veh, const MapCoordinate &dest)
void blit(const Surface &src, Surface &dst, SPoint dstPos)
Definition: blitter.h:349
Uint8 levelfinished
Definition: gamemap.h:321
void setRemovalTarget(const MapCoordinate &target)
#define cwtorpedob
Definition: vehicletype.h:76
void setDestination(ContainerBase *destination)
static bool avail(const Vehicle *eht)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
GuiIconHandler primaryGuiIcons
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
int getFirstBit(int zahl)
Count the number of zero bits on the LSB side of "zahl".
Definition: misc.cpp:45
ASCString toString() const
Definition: typen.cpp:268
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
Context createContext(GameMap *gamemap)
#define cwcannonb
Definition: vehicletype.h:80
int choiceDialog(const ASCString &text, const ASCString &button1, const ASCString &button2, const ASCString &shortLabel)
Definition: paradialog.cpp:806
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
DiplomaticStateVector diplomacy
Definition: player.h:209
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
we want only results on a certain level of height
ObjectBuildingGui objectBuildingGui
int getOwner() const
returns the number of the player this vehicle/building belongs to
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
#define fieldysize
Definition: typen.h:432
int build_movecost
The movement points that are needed to build this object.
Definition: objecttype.h:113
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
A local coordinate referencing a single field that a building covers.
Definition: buildingtype.h:57
void internalAmmoTransferWindow(Vehicle *vehicle)
const char * cwaffentypen[weaponTypeNum]
Definition: vehicletype.cpp:71
static bool avail(const ContainerBase *unit)
void setTarget(Vehicle *target)
State getState() const
Definition: command.h:125
static bool avail(Vehicle *eht)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
void warningMessage(const ASCString &str)
static Surface createSurface(int width, int height, SDLmm::Color color=255)
Definition: surface.cpp:387
static Command * pendingCommand
the action would be available, if not some prerequisites are missing which the user could provide ...
sigc::signal< void > repaintMap
}@
Definition: spfst.cpp:45
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
ContainerBase * getContainer()
returns a pointer to the ContainerBase of the field or NULL if there is none
Definition: mapfield.cpp:331
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
a single field of the map
Definition: mapfield.h:26
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
void eval(const MapCoordinate &mc, ContainerBase *subject)
checks evaluates the field on which the cursor resides
ASCString & format(const charT *pFormat,...)
Definition: ascstring.cpp:78
sigc::signal< void, Player & > sigPlayerUserInteractionEnds
Definition: gamemap.h:495
const set< MapCoordinate3D > & getReachableFieldsIndirect()
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
int getCompletion() const
returns the completion of the building.
Definition: buildings.h:164
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
bool isFieldUsable(const MapCoordinate &pos)
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
const FieldList & getAttackableObjects()
Definition: attackcommand.h:74
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
void dispmessage2(const ActionResult &result)
Definition: dialog.cpp:466
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
void setupWeapons(AttackCommand *va)
void calc(void)
Performs the calculation of the attack. The result is only stored in the av and dv structures and is ...
Definition: attack.cpp:178
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
int getNeutralPlayerNum() const
Definition: gamemap.h:278
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void setTarget(const MapCoordinate &target, int objectID)
static void popIconHandler()
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
const Surface & getPicture(int i=0, int weather=0) const
returns the pointer to the image i
Definition: objecttype.cpp:132
Interface for various global functions and variables.
int remove_movecost
The movement points that are needed to remove this object.
Definition: objecttype.h:116
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
bool fieldvisiblenow(const MapField *pe, Vehicle *veh, int player)
{@
Definition: spfst.cpp:399
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
#define fielddisthalfx
Definition: typen.h:435
MineTypes
Definition: objects.h:70
bool fieldExists(const LocalCoordinate &localCoordinate) const
returns whether this building covers the given field
Definition: buildingtype.h:108
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
Resources buildcost
The resources required to construct the object with a unit; Note that units usually don't have any en...
Definition: objecttype.h:107
void next_turn(GameMap *gamemap, const NextTurnStrategy &nextTurnStrategy, MapDisplayInterface *display, int playerView)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
const ContainerBase * getRepairingUnit() const
void BuildingTypeSelected(const BuildingType *type)
Player & getOwningPlayer() const
returns the player this vehicle/building belongs to
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool longDistAvailable(const MapCoordinate &pos)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
The class describing properties that are common to all buildings of a certain kind.
Definition: buildingtype.h:35
ActionResult execute(const Context &context)
Definition: action.cpp:41
vector< ConstructBuildingCommand::ProductionEntry > Producables
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
char * strrr(int a)
converts a to a string.
Definition: misc.cpp:66
Surface generate_gui_build_icon(BuildingType *bld)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
static GuiIconHandler * getIconHandler()
ASCString toString(bool brief=true) const
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
static bool descendAvail(Vehicle *eht)
void setTargetPosition(const MapCoordinate &pos)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
enum Player::PlayerStatus stat
const set< int > & getCreatableObjects(const MapCoordinate &pos)
#define fieldxsize
Definition: typen.h:431
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
BuildingConstructionSelection(Resources plantResources, const Container &types, const Player &player)
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
static ActionAvailability available(const Vehicle *unit)
Coordinate on the twodimensional map.
Definition: typen.h:202
const FieldList & getAttackableBuildings()
Definition: attackcommand.h:73
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
static bool avail(const Vehicle *unit)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
static sigc::signal< void, GameMap & > sigMapDeletion
Definition: gamemap.h:501
Interface for all the fighting routines of ASC.
Surface & getImage(const MapCoordinate &po, ContainerBase *subject, int nums)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
int unitConstructionMoveCostPercentage
if this unit constructs another unit externally (for example a turret), it costs this much of its mov...
Definition: vehicletype.h:254
ContainerBase * getRefueller()
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
static bool avail(Vehicle *eht)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &po, ContainerBase *subject, int nums)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void cargoDialog(ContainerBase *cb)
void setDestination(const MapCoordinate &position)
int material
Definition: typen.h:100
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
sigc::signal< void > updateFieldInfo
Definition: spfst.cpp:47
static bool avail(Vehicle *eht)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
bool isFieldUsable(const MapCoordinate &pos)
static bool ascendAvail(Vehicle *eht)
bool successful() const
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
SDLmm::SPoint SPoint
Definition: surface.h:27
static bool availExternally(const Vehicle *servicer)
Player player[9]
Definition: gamemap.h:253
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
vector< const BuildingType * > Container
static bool avail(const Vehicle *eht)
void setVerticalDirection(int dir)
defines whether we want to end up either at the same level of height (0), lower(<0), or heigher(>0)
void setDestination(const MapCoordinate &destination)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void attack(Vehicle *veh, const MapCoordinate &target)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
const FieldList & getAttackableUnits()
Definition: attackcommand.h:72
TransferHandler & getTransferHandler()
each call to getTransferHandler will deallocate the previous handler and create a new one Make sure t...
Surface & getImage(const MapCoordinate &po, ContainerBase *subject, int nums)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
#define fielddistx
Definition: typen.h:433
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
#define cwmachinegunb
Definition: vehicletype.h:78
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
Vehicle * getAttacker()
Definition: attackcommand.h:66
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
#define cwlargemissileb
Definition: vehicletype.h:72
bool isKeyPressed(SDLKey key)
Definition: events.cpp:187
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
Interface for all the dialog boxes used by the game and the mapeditor.
#define cwbombb
Definition: vehicletype.h:70
static bool externalConstructionAvail(const ContainerBase *eht)
int color
The owner of the container.
static bool avail(Vehicle *eht)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
Definition: attack.h:83
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool fieldReachable(const MapCoordinate &dest)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
int count
Definition: attack.h:294
void registerGuiFunctions(GuiIconHandler &handler)
ActionResult searchFields(int height=-1, int capabilities=0)
void registerFunc(GuiFunction *f, const MapCoordinate &position, ContainerBase *subject, int id)
deque< PathPoint > Path
Definition: astar2.h:48
int construction_steps
the number of stages that are required to construct a building using a construction unit...
Definition: buildingtype.h:89
procedure for loading and writing savegames, maps etc.
const VehicleType * typ
Definition: vehicle.h:83
bool isAllied(PlayerID towardsPlayer) const
Definition: player.h:82
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
static Surface & getIcon(const ASCString &name)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
virtual int getVerticalDirection()=0
Building * building
Definition: mapfield.h:102
vector< ContainerBase * > Targets
Definition: servicing.h:129
A 3D path finding algorithm, based on the 2D algorithm by Amit J. Patel.
Definition: astar2.h:19
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
#define maxint
Definition: typen.h:462
the unit will not change its height even if that would provide a shortcut
void addButton(int &num, const MapCoordinate &mc, ContainerBase *subject, int id)
GameMap * actmap
Definition: spfst.cpp:64
GameMap * getMap() const
void eval(const MapCoordinate &mc, ContainerBase *subject)
checks evaluates the field on which the cursor resides
#define cwsmallmissileb
Definition: vehicletype.h:74
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
static bool avail(const Vehicle *unit, bool newState)
void setaTemp2(Uint8 atemp2)
Definition: mapfield.cpp:56
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
int getVerticalDirection() const
Resources are basically the currency of ASC.
Definition: typen.h:97
ActionResult searchTargets()
bool validTarget(const Vehicle *target)
void displayActionError(const ActionResult &result, const ASCString &additionalInfo)
Definition: dialog.cpp:2168
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getMessage() const
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
void setTargetPosition(const MapCoordinate &pos)
NewGuiHost * host
void setTarget(const MapCoordinate &target, int weapon=-1)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
int choice_dlg(const ASCString &title, const ASCString &leftButton, const ASCString &rightButton)
Definition: dialog.cpp:616
bool init(Vehicle *vehicle)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
const set< MapCoordinate3D > & getReachableFields()
this will return a 2D representation of the reachable fields.
bool checkUnitsForCrash(Player &player, ASCString &text)
Definition: controls.cpp:49
virtual void parametrizePathFinder(AStar3D &pathFinder)
int getCode() const
Definition: actionresult.h:43
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
Resources removecost
The resources required to remove the object with a unit; Note that units usually don't have any energ...
Definition: objecttype.h:110
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
Availability getAvailability() const
TerrainAccess terrainaccess
the terrain this unit can move to
Definition: vehicletype.h:221
bool isFieldReachable(const MapCoordinate &pos, bool direct)
checks if the field can be reached by the unit this turn Precondition: searchFields(int,int) was called
virtual void parametrizePathFinder(AStar3D &pathFinder)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
static void pushIconHandler(GuiIconHandler *iconHandler)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
static bool availExternally(ContainerBase *source)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
const ServiceTargetSearcher::Targets & getDestinations()
bool getRemovableMines(const MapCoordinate &pos)
Surface buildGuiIcon(const Surface &image, bool remove=false)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
const char * savegameextension
Definition: loaders.cpp:78
void executeUserAction(tuseractions action)
Definition: sg.cpp:759
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
vector< ConstructUnitCommand::ProductionEntry > Producables
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
#define fielddisty
Definition: typen.h:434
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
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
ASCString name
The name of the object.
Definition: objecttype.h:122
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
virtual MapCoordinate3D getPosition() const =0