Advanced Strategic Command
cargodialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  cargodialog.cpp - description
3  -------------------
4  begin : Tue Oct 24 2000
5  copyright : (C) 2000 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include <sigc++/sigc++.h>
19 #include <pgimage.h>
20 #include <pgtooltiphelp.h>
21 #include "cargodialog.h"
22 #include "cargowidget.h"
23 #include "vehicletypeselector.h"
24 
25 #include "../containerbase.h"
26 #include "../paradialog.h"
27 #include "../util/messaginghub.h"
28 #include "../iconrepository.h"
29 #include "../vehicle.h"
30 #include "../gamemap.h"
31 #include "../containercontrols.h"
32 
33 #include "../asc-mainscreen.h"
34 #include "../guiiconhandler.h"
35 #include "../guifunctions.h"
36 #include "../guifunctions-interface.h"
37 #include "../cannedmessages.h"
38 #include "../dashboard.h"
39 #include "../dialog.h"
40 #include "../containerbase-functions.h"
41 #include "../resourcenet.h"
42 
43 #include "../containerbase-functions.h"
44 #include "../gameoptions.h"
45 
46 #include "../actions/moveunitcommand.h"
47 #include "../actions/cargomovecommand.h"
48 #include "../actions/servicecommand.h"
49 #include "../actions/recycleunitcommand.h"
50 #include "../actions/repairunitcommand.h"
51 #include "../actions/trainunitcommand.h"
52 #include "../actions/repairbuildingcommand.h"
53 #include "../actions/transfercontrolcommand.h"
54 #include "../actions/setresourceprocessingratecommand.h"
55 
56 #include "selectionwindow.h"
57 #include "ammotransferdialog.h"
58 #include "unitinfodialog.h"
60 #include "../sg.h"
61 #include "../spfst.h"
62 
63 const VehicleType* selectVehicletype( ContainerBase* plant, const vector<VehicleType*>& items );
64 
65 
66 class CargoDialog;
67 
68 class SubWindow: public sigc::trackable
69 {
70  protected:
72  PG_Widget* widget;
73 
74  SubWindow() : cargoDialog(NULL), widget(NULL) {};
76  public:
77  virtual bool available( CargoDialog* cd ) = 0;
78  virtual ASCString getASCTXTname() = 0;
79  virtual ASCString getFullName() = 0;
80  virtual void registerSubwindow( CargoDialog* cd );
81  virtual void registerChilds( CargoDialog* cd );
82  virtual void update() = 0;
83  virtual ~SubWindow() {} ;
84 };
85 
86 
87 class SubWinButton : public PG_Button
88 {
89 
90  static int calcWidth() {
91  if ( buttonwidth == -1 ) {
92  buttonwidth = IconRepository::getIcon("cargo-buttonpressed.png").w();
93  }
94  return buttonwidth;
95  }
96 
97  static int calcHeight() {
98  if ( buttonheight == -1 ) {
99  buttonheight = IconRepository::getIcon("cargo-buttonpressed.png").h();
100  }
101  return buttonheight;
102  }
103 
104  public:
105  static int buttonwidth;
106  static int buttonheight;
107 
108 
109  SubWinButton( PG_Widget *parent, const SPoint& pos, SubWindow* subWindow ) : PG_Button( parent, PG_Rect( pos.x, pos.y, calcWidth(), calcHeight() ), "", -1, "SubWinButton") {
110  SetBackground( PRESSED, IconRepository::getIcon("cargo-buttonpressed.png").getBaseSurface() );
111  SetBackground( HIGHLITED, IconRepository::getIcon("cargo-buttonhighlighted.png").getBaseSurface() );
112  SetBackground( UNPRESSED, IconRepository::getIcon("cargo-buttonunpressed.png").getBaseSurface() );
113  SetBorderSize(0,0,0);
114  ASCString filename = ASCString("cargo-") + subWindow->getASCTXTname();
115  SetIcon( IconRepository::getIcon( filename + ".png" ).getBaseSurface(),
116  IconRepository::getIcon( filename + "-pressed.png" ).getBaseSurface(),
117  IconRepository::getIcon( filename + ".png" ).getBaseSurface() );
118  SetToggle( true );
119  new PG_ToolTipHelp ( this, subWindow->getFullName() );
120  };
121 };
122 
125 
126 
127 
128 namespace CargoGuiFunctions
129 {
130 
132 {
133  PG_Widget& parent;
134  public:
135  MovementDestination( PG_Widget& masterParent ) : parent( masterParent) {};
136 
137  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
138  GuiFunctions::Movement::execute( pos, subject, num );
140  parent.QuitModal();
141  }
142 };
143 
145 {
146  PG_Widget& parent;
147  public:
148  CancelMovement ( PG_Widget& masterParent ) : parent( masterParent) {};
149 
150  bool available( const MapCoordinate& pos, ContainerBase* subject, int num )
151  {
153  parent.QuitModal();
154 
155  return true;
156  }
157 
158  void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) {
159  GuiFunctions::Cancel::execute( pos, subject, num );
160  parent.QuitModal();
161  }
162 };
163 
164 
165 class CloseDialog : public GuiFunction
166 {
167  CargoDialog& parent;
168  public:
169  CloseDialog( CargoDialog& masterParent ) : parent( masterParent) {};
170  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
171  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
172  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
173  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
174  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
175 };
176 
177 
178 class Movement : public GuiFunction
179 {
180  CargoDialog& parent;
181  public:
182  Movement( CargoDialog& masterParent ) : parent( masterParent) {};
183  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
184  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
185  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
186  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
187  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
188 };
189 
190 
191 class UnitProduction : public GuiFunction, public sigc::trackable
192 {
193  CargoDialog& parent;
195  ConstructUnitCommand* constructUnitCommand;
196  void productionLinesChanged();
197  public:
198  UnitProduction( CargoDialog& masterParent ) : parent( masterParent), constructUnitCommand(NULL) {};
199  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
200  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
201  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
202  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
203  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
204 };
205 
206 class UnitTraining : public GuiFunction
207 {
208  CargoDialog& parent;
209  public:
210  UnitTraining( CargoDialog& masterParent ) : parent( masterParent) {};
211  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
212  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
213  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
214  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
215  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
216 };
217 
219 {
220  CargoDialog& parent;
221  public:
222  RefuelUnitCommand( CargoDialog& masterParent ) : parent( masterParent) {};
223  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
224  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
225  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
226  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
227  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
228 };
230 {
231  CargoDialog& parent;
232  public:
233  RefuelUnitDialogCommand( CargoDialog& masterParent ) : parent( masterParent) {};
234  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
235  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
236  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
237  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
238  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
239 };
240 
241 class RepairUnit : public GuiFunction
242 {
243  CargoDialog& parent;
244  public:
245  RepairUnit( CargoDialog& masterParent ) : parent( masterParent) {};
246  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
247  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
248  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
249  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
250  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
251 };
252 
253 class MoveUnitUp : public GuiFunction
254 {
255  CargoDialog& parent;
256  public:
257  MoveUnitUp ( CargoDialog& masterParent ) : parent( masterParent) {};
258  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
259  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
260  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
261  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
262  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
263 };
264 
266 {
267  CargoDialog& parent;
268  public:
269  MoveUnitIntoInnerContainer ( CargoDialog& masterParent ) : parent( masterParent) {};
270  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
271  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
272  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
273  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
274  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
275 };
276 
277 
279 {
280  CargoDialog& parent;
281  public:
282  OpenContainer( CargoDialog& masterParent ) : parent( masterParent) {};
283  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
284  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
285  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
286  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
287  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
288 };
289 
291 {
292  ASCString getCommandName( const ContainerBase* carrier );
293  CargoDialog& parent;
294  public:
295  RecycleUnitCommandButton( CargoDialog& masterParent ) : parent( masterParent) {};
296  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
297  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
298  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
299  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
300  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
301 };
302 
303 
304 class UnitInfo : public GuiFunction
305 {
306  CargoDialog& parent;
307  public:
308  UnitInfo( CargoDialog& masterParent ) : parent( masterParent) {};
309  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
310  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
311  bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num );
312  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
313  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
314 };
315 
317 {
318  CargoDialog& parent;
319  public:
320  TransferUnitControl( CargoDialog& masterParent ) : parent( masterParent) {};
321  bool available( const MapCoordinate& pos, ContainerBase* subject, int num );
322  void execute( const MapCoordinate& pos, ContainerBase* subject, int num );
323  Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num );
324  ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num );
325 };
326 
327 
328 
329 }; // namespace CargoGuiFunctions
330 
331 
333 class CargoInfoWindow;
334 
335 class CargoDialog : public Panel
336 {
337 
338  GuiIconHandler guiIconHandler;
339 
340  ContainerBase* container;
341  bool setupOK;
342  Surface infoImage;
343 
344  typedef vector<SubWindow*> Activesubwindows;
345  Activesubwindows activesubwindows;
346 
348  Subwindows subwindows;
349 
350  vector<SubWinButton*> subWinButtons;
351 
352  CargoWidget* cargoWidget;
353  SubWindow* researchWindow;
354  SubWindow* matterWindow;
355  BuildingControlWindow* buildingControlWindow;
356 
357  bool shutdownImmediately;
358 
359  void containerDestroyed() {
360  shutdownImmediately = true;
361  }
362 
363  CargoInfoWindow* ciw;
364 
365  bool eventKeyDown(const SDL_KeyboardEvent* key) {
366  int mod = SDL_GetModState() & ~(KMOD_NUM | KMOD_CAPS | KMOD_MODE);
367 
368  if ( !mod ) {
369  if ( key->keysym.sym == SDLK_ESCAPE ) {
370  QuitModal();
371  return true;
372  }
373  }
374 
375  if ( (mod & KMOD_SHIFT) && (mod & KMOD_CTRL)) {
376  switch ( key->keysym.unicode ) {
377  case 26: // Z
379  cargoChanged();
380  return true;
381  }
382  }
383 
384  if ( (mod & KMOD_CTRL) && !(mod & KMOD_SHIFT)) {
385  switch ( key->keysym.unicode ) {
386  case 26: // Z
388  if ( shutdownImmediately ) {
389  QuitModal();
390  return true;
391  }
392 
393  cargoChanged();
394  for ( Activesubwindows::iterator i = activesubwindows.begin(); i != activesubwindows.end(); ++i )
395  (*i)->update();
396  return true;
397  }
398  }
399 
400  return false;
401  };
402 
403 
404 
405  void registerSpecialDisplay( const ASCString& name ) {
406  SpecialDisplayWidget* sdw = dynamic_cast<SpecialDisplayWidget*>( FindChild( name, true ) );
407  if ( sdw )
408  sdw->display.connect( sigc::mem_fun( *this, &CargoDialog::painter ));
409  };
410 
411  void registerSpecialInput( const ASCString& name ) {
412  SpecialInputWidget* siw = dynamic_cast<SpecialInputWidget*>( FindChild( name, true ) );
413  if ( siw )
414  siw->sigMouseButtonDown.connect( sigc::mem_fun( *this, &CargoDialog::onClick ));
415  };
416 
417  bool onClick ( PG_MessageObject* obj, const SDL_MouseButtonEvent* event ) {
418  PG_Widget* w = dynamic_cast<PG_Widget*>(obj);
419  if ( w ) {
420  // click( w->GetName() );
421  return true;
422  }
423  return false;
424  };
425 
426  void onUnitClick ( Vehicle* veh,SPoint pos, bool first ) {
427  // if ( veh )
429  SPoint iconPos = pos;
430  if ( veh ) {
431  iconPos.x -= smallGuiIconSizeX/2;
432  iconPos.y -= smallGuiIconSizeY/2;
433  } else {
434  iconPos.x += 2;
435  iconPos.y += 2;
436  }
437 
438  mainScreenWidget->getGuiHost()->showSmallIcons( this, iconPos, false );
439  }
440 
441  };
442 
443  void clearSmallIcons( ) {
446  }
447 
448 
449 
450  void painter ( const PG_Rect &src, const ASCString& name, const PG_Rect &dst) {
451  Surface screen = Surface::Wrap( PG_Application::GetScreen() );
452 
453  if ( name == "unitpad_unitsymbol" ) {
454  Vehicle* v = dynamic_cast<Vehicle*>(container);
455  if ( v )
456  v->paint( screen, SPoint( dst.x, dst.y ), 0);
457  }
458 
459  if ( name == "SelectedImage" ) {
460  if ( getMarkedUnit() )
461  getMarkedUnit()->typ->paint( screen, SPoint( dst.x, dst.y ), getMarkedUnit()->getOwningPlayer().getPlayerColor() );
462  }
463 
464  };
465 
466  bool activate_i( PG_Button* b, int pane ) {
467  if ( pane >= 0 && pane < activesubwindows.size() ) {
468  activate( activesubwindows[pane]->getASCTXTname() );
469  activesubwindows[pane]->update();
470  }
471  return true;
472  }
473 
474  void activate( const ASCString& pane ) {
475  BulkGraphicUpdates bgu( this );
476  for ( int i = 0; i < activesubwindows.size(); ++i )
477  if ( activesubwindows[i]->getASCTXTname() != pane )
478  hide( activesubwindows[i]->getASCTXTname() );
479 
480  for ( int i = 0; i < activesubwindows.size(); ++i )
481  if ( activesubwindows[i]->getASCTXTname() == pane )
482  show( activesubwindows[i]->getASCTXTname() );
483 
484  for ( int i = 0; i< subWinButtons.size(); ++i )
485  subWinButtons[i]->SetPressed( activesubwindows[i]->getASCTXTname() == pane );
486  };
487 
488 
489  void registerGuiFunctions( GuiIconHandler& handler ) {
490  handler.registerUserFunction( new CargoGuiFunctions::Movement( *this ) );
493  handler.registerUserFunction( new CargoGuiFunctions::RepairUnit( *this ) );
500  handler.registerUserFunction( new CargoGuiFunctions::UnitInfo( *this ));
503  }
504 
505  void checkStoringPosition( Vehicle* unit ) {
507  mainScreenWidget->getGuiHost()->eval( container->getPosition(), unit );
508  }
509 
511  mainScreenWidget->getUnitInfoPanel()->showUnitData( unit, NULL, NULL, true );
512  }
513 
514  void updateLoadMeter() {
515  if ( container->baseType->maxLoadableWeight > 0 )
516  setBargraphValue ( "LoadingMeter", float( container->cargoWeight()) / container->baseType->maxLoadableWeight );
517  }
518 
519  void dragUnitToInnerContainer( Vehicle* draggedUnit, Vehicle* targetUnit ) {
520  if ( !draggedUnit )
521  return;
522 
523  if ( draggedUnit != targetUnit ) {
524  if ( targetUnit && CargoMoveCommand::moveInAvail(draggedUnit, targetUnit) ) {
525  auto_ptr<CargoMoveCommand> cargomove ( new CargoMoveCommand( draggedUnit ));
526  cargomove->setMode( CargoMoveCommand::moveInwards );
527  cargomove->setTargetCarrier( targetUnit );
528  ActionResult res = cargomove->execute ( createContext( getContainer()->getMap() ));
529  if ( res.successful() )
530  cargomove.release();
531  } else {
532  if ( container->getCarrier() && !targetUnit ) {
533  auto_ptr<CargoMoveCommand> cargomove ( new CargoMoveCommand( draggedUnit ));
534  cargomove->setMode( CargoMoveCommand::moveOutwards );
535  ActionResult res = cargomove->execute ( createContext( getContainer()->getMap() ));
536  if ( res.successful() )
537  cargomove.release();
538  } else {
539 
540  }
541  }
542  }
543  cargoChanged();
544  }
545 
546  bool dragUnitToInnerContainerAvail( Vehicle* draggedUnit, Vehicle* targetUnit ) {
547  return CargoMoveCommand::moveInAvail( draggedUnit, targetUnit );
548  }
549 
550  void dragInProcess() {
553  }
554 
555  void dragAborted() {
556  // to redraw everything
557  cargoChanged();
558  }
559 
560  public:
561  int getResourceValue ( int resourcetype, int y, int scope ) {
562  int player = container->getMap()->actplayer;
563  if ( container->getMap()->getCurrentPlayer().stat == Player::supervisor )
564  player = container->getOwner();
565 
566  switch ( y ) {
567  case 0: { // avail
568  GetResource gr ( container->getMap() );
569  return gr.getresource ( container->getPosition().x, container->getPosition().y, resourcetype, maxint, 1, player, scope );
570  }
571  case 1: { // tank
572  GetResourceCapacity grc ( container->getMap() );
573  return grc.getresource ( container->getPosition().x, container->getPosition().y, resourcetype, maxint, 1, player, scope );
574  }
575  case 2: { // plus
576  GetResourcePlus grp ( container->getMap() );
577  return grp.getresource ( container->getPosition().x, container->getPosition().y, resourcetype, player, scope );
578  }
579  case 3: { // usage
580  GetResourceUsage gru( container->getMap() );
581  return gru.getresource ( container->getPosition().x, container->getPosition().y, resourcetype, player, scope );
582  }
583  } /* endswitch */
584  return -1;
585  }
586 
587 
588  public:
589 
590  CargoDialog (PG_Widget *parent, ContainerBase* cb );
591 
593  activesubwindows.push_back( w );
594  };
595 
597  setLabelText( "energyavail", container->getResource(maxint, 0, true ) );
598  setLabelText( "materialavail", container->getResource(maxint, 1, true ) );
599  setLabelText( "fuelavail", container->getResource(maxint, 2, true ) );
600  setLabelText( "numericaldamage", container->damage );
601  }
602 
603 
605  if ( cargoWidget )
606  return cargoWidget->getMarkedUnit();
607  else
608  return NULL;
609  }
610 
611  void cargoChanged() {
612  //unitHighLight.setNew( unitHighLight.getMark() );
613  if ( cargoWidget ) {
614  cargoWidget->redrawAll();
616  mainScreenWidget->getUnitInfoPanel()->showUnitData( cargoWidget->getMarkedUnit(), NULL, NULL, true );
617 
618  checkStoringPosition( cargoWidget->getMarkedUnit() );
619  }
620  sigCargoChanged();
622  showAmmo();
623  updateLoadMeter();
624  }
625 
626  int RunModal() {
627  if ( setupOK )
628  return Panel::RunModal();
629  return 0;
630  }
631 
632  bool ProcessEvent ( const SDL_Event * event,bool bModal = false ) {
633  // the unit info panel must get the events first. If a unit is renamed and a character entered, this
634  // key event shall go to the renaming - and not to the unit actions.
636  if ( mainScreenWidget->getUnitInfoPanel()->ProcessEvent( event, bModal ))
637  return true;
638 
640  if ( mainScreenWidget->getGuiHost()->ProcessEvent( event, bModal ))
641  return true;
642 
643  if ( Panel::ProcessEvent( event, bModal ))
644  return true;
645 
646  return false;
647  }
648 
649  void showAmmo() {
650  setLabelText( "cmmun", container->getAmmo( cwcruisemissilen, maxint, true ));
651  setLabelText( "minemun", container->getAmmo( cwminen, maxint, true ));
652  setLabelText( "bombmun", container->getAmmo( cwbombn, maxint, true ));
653  setLabelText( "lmmun", container->getAmmo( cwlargemissilen, maxint, true ));
654  setLabelText( "smmun", container->getAmmo( cwsmallmissilen, maxint, true ));
655  setLabelText( "mgmun", container->getAmmo( cwmachinegunn, maxint, true ));
656  setLabelText( "canmun", container->getAmmo( cwcannonn, maxint, true ));
657  setLabelText( "torpmun", container->getAmmo( cwtorpedon, maxint, true ));
658  }
659 
660  void userHandler( const ASCString& label, PropertyReadingContainer& pc, PG_Widget* parent, WidgetParameters widgetParams );
661 
663  return container;
664  };
665 
667  if ( container ) return container->getMap();
668  else return NULL;
669  };
670 
671  sigc::signal<void> sigCargoChanged;
672 
673  void setUnitInfoWidgets( const ContainerBase* container, const ASCString& prefix ) {
674  if ( container ) {
675  ASCString s;
676  s.format( "%d / %d", container->cargoWeight(), container->baseType->maxLoadableWeight );
677  setLabelText( prefix + "CargoUsage", s );
678 
679  int slots = 0;
680  for ( ContainerBase::Cargo::const_iterator i = container->getCargo().begin(); i != container->getCargo().end(); ++i )
681  if( *i )
682  ++slots;
683 
684  if ( container->baseType->maxLoadableUnits )
685  setBargraphValue ( prefix + "LoadingMeter3", float( slots ) / float(container->baseType->maxLoadableUnits) );
686  else
687  setBargraphValue ( prefix + "LoadingMeter3", 0 );
688 
689  s.format( "%d / %d", slots, container->baseType->maxLoadableUnits );
690  setLabelText( prefix + "SlotSummary", s );
691 
692  setLabelText( prefix + "UsedCargoSlots", slots );
693  setLabelText( prefix + "CargoSlotCount", container->baseType->maxLoadableUnits );
694  if ( container->baseType->maxLoadableUnits )
695  setLabelText( prefix + "MaxLoadableWeight", container->baseType->maxLoadableWeight );
696  else
697  setLabelText( prefix + "MaxLoadableWeight", "-" );
698 
699  setLabelText( prefix + "UserName", container->name );
700  setLabelText( prefix + "UnitTypeName", container->baseType->name );
701  setLabelText( prefix + "UnitTypeDescription", container->baseType->description );
702 
703  } else {
704  setLabelText( prefix + "CargoUsage", "" );
705  setBargraphValue ( prefix + "LoadingMeter3", 0 );
706  setLabelText( prefix + "UsedCargoSlots", "" );
707  setLabelText( prefix + "CargoSlotCount", "" );
708  setLabelText( prefix + "MaxLoadableWeight", "" );
709 
710  setLabelText( prefix + "UserName", "" );
711  setLabelText( prefix + "UnitTypeName", "" );
712  setLabelText( prefix + "UnitTypeDescription", "" );
713 
714  }
715  }
716 
717  void updateVariables( ) {
718  PG_Widget* widget = this;
719  // from solarpower
720  {
721  setLabelText( "MaxSolarPower", container->maxplus.energy );
722 
723  static const char* weathernames[] = {"terrain_weather_dry.png",
724  "terrain_weather_lightrain.png",
725  "terrain_weather_heavyrain.png",
726  "terrain_weather_lightsnow.png",
727  "terrain_weather_heavysnow.png",
728  "terrain_weather_ice.png"
729  };
730 
731 
732  SolarPowerplant solarPowerPlant ( container );
733  Resources plus = solarPowerPlant.getPlus();
734  setLabelText( "CurrentSolarPower", plus.energy );
735  setImage( "Weather", weathernames[ container->getMap()->getField( container->getPosition() )->getWeather() ], widget );
736  }
737 
738  // from windpower
739  {
740  WindPowerplant windPowerPlant ( container );
741  Resources plus = windPowerPlant.getPlus();
742  setLabelText( "CurrentWindPower", plus.energy, widget );
743 
744 #ifdef WEATHERGENERATOR
745  if ( container->getMap()->weatherSystem )
746  setLabelText( "WindSpeed", container->getMap()->weatherSystem->getCurrentWindSpeed(), widget );
747 #else
748  setLabelText( "WindSpeed", container->getMap()->weather.windSpeed, widget );
749 #endif
750  }
751 
752  // from cargo
753  {
754 
755  class MoveMalusType
756  {
757  public:
758  enum { deflt,
759  light_tracked_vehicle,
760  medium_tracked_vehicle,
761  heavy_tracked_vehicle,
762  light_wheeled_vehicle,
763  medium_wheeled_vehicle,
764  heavy_wheeled_vehicle,
765  trooper,
766  rail_vehicle,
767  medium_aircraft,
768  medium_ship,
769  structure,
770  light_aircraft,
771  heavy_aircraft,
772  light_ship,
773  heavy_ship,
774  helicopter,
775  hoovercraft
776  };
777  };
778 
779  setUnitInfoWidgets( container, "" );
780 
781 
782  setUnitInfoWidgets( getMarkedUnit(), "Selected" );
783 
784  PG_Widget* typeImage = FindChild( "TypeImage", true );
785  PG_ToolTipHelp* typeImageTooltip= NULL;
786  if ( typeImage )
787  typeImageTooltip = PG_ToolTipHelp::GetToolTip( typeImage );
788 
789  if ( getMarkedUnit() ) {
790  setLabelText( "CurrentCargo", getMarkedUnit()->weight(), widget );
791  setImage( "TypeImage", moveMaliTypeIcons[getMarkedUnit()->typ->movemalustyp], widget );
792  show( "TypeImage" );
793  if ( typeImageTooltip )
794  typeImageTooltip->SetText( cmovemalitypes[getMarkedUnit()->typ->movemalustyp ] );
795 
796  if ( getMarkedUnit()->baseType->infoImageSmallFilename.length() > 0 ) {
797  setImage( "Selected3DImageSmall", getMarkedUnit()->baseType->infoImageSmallFilename, widget );
798  show( "Selected3DImageSmall" );
799  } else
800  hide( "Selected3DImageSmall" );
801 
802  } else {
803  setLabelText( "CurrentCargo", "-" , widget );
804  hide( "TypeImage" );
805  hide( "Selected3DImageSmall" );
806  }
807 
808  PG_Widget* w = FindChild( "SelectedImage", true );
809  if ( w )
810  w->Update();
811 
812  if ( container->baseType->maxLoadableWeight > 0 )
813  setBargraphValue ( "LoadingMeter2", float( container->cargoWeight()) / container->baseType->maxLoadableWeight, widget );
814 
815  setLabelText("CargoWeight", container->cargoWeight() );
816 
817  if ( container->baseType->maxLoadableWeight >= 1000000 ) {
818  setLabelText ( "FreeWeight", "unlimited", widget );
819  setLabelText ( "MaxWeight", "unlimited", widget );
820  } else {
821  setLabelText ( "FreeWeight", container->baseType->maxLoadableWeight - container->cargoWeight(), widget );
822  setLabelText ( "MaxWeight", container->baseType->maxLoadableWeight, widget );
823  }
824 
825  setLabelText ( "FreeSlots", container->baseType->maxLoadableUnits - container->vehiclesLoaded(), widget );
826  setLabelText ( "MaxSlots", container->baseType->maxLoadableUnits , widget );
827  setLabelText ( "MaxUnitSize", container->baseType->maxLoadableUnitSize, widget );
828  }
829 
830  // from buildingcontrol
831  {
832  Building* bld = dynamic_cast<Building*>( container );
833  if ( bld ) {
834  if ( RepairBuildingCommand::avail( bld )) {
835  RepairBuildingCommand rbc( bld );
836  RepairBuildingCommand::RepairData repairData = rbc.getCost();
837  setLabelText( "RepairCostLabel", "Cost for repairing " + ASCString::toString( repairData.damageDelta ) + "%", widget );
838 
839  setLabelText( "EnergyCost", repairData.cost.energy, widget );
840  setLabelText( "MaterialCost", repairData.cost.material, widget );
841  setLabelText( "FuelCost", repairData.cost.fuel, widget );
842 
843  } else {
844  setLabelText( "RepairCostLabel", "No repair possible", widget );
845 
846  setLabelText( "EnergyCost", "-", widget );
847  setLabelText( "MaterialCost", "-", widget );
848  setLabelText( "FuelCost", "-", widget );
849  }
850  }
851  setLabelText( "Jamming", container->baseType->jamming , widget );
852  setLabelText( "View", container->baseType->view, widget );
853  setLabelText( "Armor", container->getArmor(), widget );
854  }
855 
856  }
857 
858 
860  if ( setupOK )
862 
863  }
864 
865 };
866 
867 
868 
869 
870 
872 {
873  CargoDialog cd ( NULL, cb );
874  cd.Show();
875  cd.RunModal();
876 }
877 
878 
879 
880 
881 /*
882 const Vehicletype* selectVehicletype( ContainerBase* plant, const vector<Vehicletype*>& items )
883 {
884  VehicleTypeSelectionWindow fsw( NULL, PG_Rect( 10, 10, 400, 500 ), plant, items );
885  fsw.Show();
886  fsw.RunModal();
887  const Vehicletype* v = fsw.getVehicletype();
888  return v;
889 }
890 
891 */
892 
893 
895 {
896  cargoDialog = cd;
897  cd->addAvailableSubwin( this );
898 }
899 
901 {
902  widget = cd->FindChild( getASCTXTname(), true);
903  if ( !widget )
904  warningMessage( "Could not find widget with name " + getASCTXTname() );
905 }
906 
907 
909 {
910  return cargoDialog->getContainer();
911 }
912 
913 /*
914 const int subWindowNum = 11;
915 static const char* subWindowName[subWindowNum] =
916 { "ammotransfer", "ammoproduction", "info", "cargoinfo", "conventionalpower", "mining", "netcontrol", "research", "resourceinfo", "solarpower", "windpower"
917 };
918 */
919 
920 
921 
923 {
924 
925  public:
926  bool available( CargoDialog* cd ) {
927  if ( !cd->getMap()->getCurrentPlayer().diplomacy.isAllied( cd->getContainer() ))
928  return false;
929 
931  };
932 
934  return "solarpower";
935  };
936 
938  return "Solar Power Generation";
939  };
940 
941  void update() {
943  }
944 };
945 
947 {
948  public:
949  bool available( CargoDialog* cd ) {
950  if ( !cd->getMap()->getCurrentPlayer().diplomacy.isAllied( cd->getContainer() ))
951  return false;
952 
954  };
955 
957  return "windpower";
958  };
959 
961  return "Wind Power Generation";
962  };
963 
964 
965  void update() {
967  }
968 };
969 
971 {
972 
973  private:
974 
975  bool click( PG_Button* b, int x, int y ) {
976  return true;
977  }
978 
979  PG_Button* findButton( int x, int y ) {
980  char c = 'a' + x;
981  ASCString buttonName = "Button" + ASCString::toString(y) + c;
982  return dynamic_cast<PG_Button*>( widget->FindChild( buttonName, true ) );
983  }
984 
985  public:
986  bool available( CargoDialog* cd ) {
987  if ( !cd->getMap()->getCurrentPlayer().diplomacy.isAllied( cd->getContainer() ))
988  return false;
989 
990  return dynamic_cast<Building*>(cd->getContainer()) != NULL;
991  };
992 
994  return "netcontrol";
995  };
996 
998  return "Resource Network Control";
999  };
1000 
1001 
1004 
1005  if ( widget ) {
1006  for ( int x = 0; x < 3; ++x ) {
1007  for ( int y = 0; y < 4; ++y ) {
1008  PG_Button* b = findButton( x, y );
1009  if ( b ) {
1010  b->sigClick.connect( sigc::bind( sigc::bind( sigc::mem_fun( *this, &NetControlWindow::click ), x), y));
1011  if ( y >= 2)
1012  b->SetToggle( true );
1013  }
1014 
1015  }
1016  }
1017 
1018  }
1019  }
1020 
1021  void update() {
1023  }
1024 };
1025 
1026 
1028 {
1029  public:
1030  bool available( CargoDialog* cd ) {
1031  return true;
1032  };
1033 
1035  return "cargoinfo";
1036  };
1037 
1039  return "Cargo Info";
1040  };
1041 
1044  cargoDialog->sigCargoChanged.connect( sigc::mem_fun( *this, &CargoInfoWindow::update ));
1045  };
1046 
1047 
1050 
1051  }
1052 
1053  void update() {
1055  }
1056 };
1057 
1058 
1060 {
1061  public:
1062  sigc::signal<void> damageChanged;
1063 
1064 
1067 
1068  if ( widget ) {
1069  PG_Button* b = dynamic_cast<PG_Button*>( widget->FindChild( "RepairButton", true ) );
1070  if ( b )
1071  b->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &BuildingControlWindow::repair )));
1072  }
1073  }
1074 
1075  bool repair() {
1076  Building* bld = dynamic_cast<Building*>(container() );
1077  if ( !RepairBuildingCommand::avail( bld ))
1078  return false;
1079 
1080  auto_ptr<RepairBuildingCommand> rbc ( new RepairBuildingCommand( bld ));
1081  ActionResult res = rbc->execute( createContext( container()->getMap() ));
1082  if ( res.successful() )
1083  rbc.release();
1084  else
1085  displayActionError( res );
1086 
1088 
1089  damageChanged();
1090  update();
1091 
1092  if ( widget )
1093  widget->Update();
1094 
1095  return true;
1096  }
1097 
1098 
1099  bool available( CargoDialog* cd ) {
1100  if ( !cd->getMap()->getCurrentPlayer().diplomacy.isAllied( cd->getContainer() ))
1101  return false;
1102 
1103  Building* bld = dynamic_cast<Building*>(cd->getContainer());
1104  if ( !bld )
1105  return false;
1106 
1107  return true;
1108 
1109  // return RepairBuildingCommand::avail( ));
1110  };
1111 
1113  return "damagecontrol";
1114  };
1115 
1117  return "Building Control";
1118  };
1119 
1120 
1121  void update() {
1123 
1124  damageChanged(); // it didn't really change, but we are triggering a redraw
1125  }
1126 };
1127 
1128 
1130 {
1131 
1132 
1133  public:
1134  bool available( CargoDialog* cd ) {
1136  return false;
1137 
1138  return dynamic_cast<Building*>( cd->getContainer() ) != NULL;
1139  };
1140 
1142  return "resourceinfo";
1143  };
1144 
1146  return "Resource Network Information";
1147  };
1148 
1149 
1150  void update() {
1151 
1152  ContainerBase* activeContainer= container();
1153 
1154  int value[3][3][4];
1155  int mx = 0;
1156 
1157  for ( int c = 0; c < 3; c++ )
1158  for ( int x = 0; x < 3; x++ )
1159  for ( int y = 0; y < 4; y++ ) {
1160  value[c][x][y] = cargoDialog->getResourceValue ( x, y, c );
1161  if ( y != 1 )
1162  if ( value[c][x][y] > mx )
1163  mx = value[c][x][y];
1164  }
1165 
1166 
1167 
1168  for ( int c = 0; c < 3; c++ )
1169  for ( int x = 0; x < 3; x++ )
1170  for ( int y = 0; y < 4; y++ ) {
1171  char xx = 'A' + (c * 3 + x);
1172  char yy = '1' + y;
1173  ASCString label = "Res";
1174  label += xx;
1175  label += yy;
1176  if ( (y != 1 || value[c][x][y] < mx*10 || value[c][x][y] < 1000000000 ) && ( !activeContainer->getMap()->isResourceGlobal(x) || y!=0 ||c ==2)) // don't show extremely high numbers
1177  cargoDialog->setLabelText( label, value[c][x][y] );
1178  else
1179  cargoDialog->setLabelText( label, "-" );
1180  }
1181 
1182  }
1183 
1184 };
1185 
1186 
1187 class GraphWidget : public PG_Widget
1188 {
1189  map<int,int> verticalLines;
1190  vector<int> curves;
1191  typedef vector< pair<int,int> > Bars;
1192  Bars bars;
1193  protected:
1194  int xrange;
1195  int yrange;
1196  virtual int getPoint( int curve, int x ) {
1197  return 0;
1198  };
1199  virtual int getBarHeight( int bar ) {
1200  return 0;
1201  };
1202  virtual void click( int x, int button ) {};
1203 
1204  bool eventMouseMotion (const SDL_MouseMotionEvent *motion) {
1205  PG_Point p = ScreenToClient ( motion->x, motion->y );
1206  if ( motion->type == SDL_MOUSEMOTION && (motion->state == SDL_BUTTON(1)))
1207  click ( p.x, 1 );
1208 
1209  if ( motion->type == SDL_MOUSEMOTION && (motion->state == SDL_BUTTON(3)))
1210  click( p.x, 3 );
1211 
1212  return true;
1213  }
1214 
1215  bool eventMouseButtonDown (const SDL_MouseButtonEvent *button) {
1216  PG_Point p = ScreenToClient ( button->x, button->y );
1217  if ( button->type == SDL_MOUSEBUTTONDOWN && (button->button == SDL_BUTTON_LEFT))
1218  click ( p.x, 1 );
1219 
1220  if ( button->type == SDL_MOUSEBUTTONDOWN && (button->button == SDL_BUTTON_RIGHT))
1221  click ( p.x, 3 );
1222 
1223  return true;
1224  }
1225 
1226  int mapColor( int col ) {
1227  PG_Color color = col;
1228  return color.MapRGBA( PG_Application::GetScreen()->format, 255-GetTransparency());
1229  }
1230 
1231  public:
1232  GraphWidget( PG_Widget *parent, const PG_Rect& rect ) : PG_Widget( parent, rect ), xrange(1), yrange(1) {};
1233  void setRange( int x, int y ) {
1234  xrange = max( x, 1);
1235  yrange = max( y, 1);
1236  }
1237 
1238  int addCurve( int color ) {
1239  curves.push_back( color );
1240  return curves.size();
1241  }
1242 
1243  int addBar( int pos, int color ) {
1244  bars.push_back ( make_pair( pos, color ));
1245  return bars.size();
1246  }
1247 
1248 
1249  void addVerticalLine ( int x, int color ) {
1250  verticalLines[x] = color;
1251  }
1252 
1254  verticalLines.clear();
1255  }
1256 
1257  void eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst) {
1258  Surface s = Surface::Wrap( PG_Application::GetScreen() );
1259 
1260  for ( int c = 0; c < curves.size(); ++c ) {
1261  int realcol = mapColor( curves[c] );
1262 
1263  for ( int x = 0; x < Width(); ++x ) {
1264  int y = getPoint( c, x * xrange / Width() ) * Height() / yrange;
1265  if ( y < 0 )
1266  y = 0;
1267  if ( y >= Height() )
1268  y = Height() -1 ;
1269  PG_Point pos = ClientToScreen( x, Height() - y );
1270  s.SetPixel( pos.x, pos.y, realcol );
1271  }
1272  }
1273 
1274  for ( map<int,int>::iterator v = verticalLines.begin(); v != verticalLines.end(); ++v ) {
1275  int realcol = mapColor( v->second );
1276 
1277  int x = v->first * Width() / xrange;
1278  for ( int y = 0; y < Height(); ++y ) {
1279  PG_Point pos = ClientToScreen( x, y );
1280  s.SetPixel( pos.x, pos.y, realcol );
1281  }
1282  }
1283  int barNum = 0;
1284  for ( Bars::iterator b = bars.begin(); b != bars.end(); ++b ) {
1285  int x = b->first * Width() / (xrange+1);
1286  int x2 = (b->first + 1) * Width() / xrange - 1;
1287  if ( x2 <= x )
1288  x2 = x + 1;
1289 
1290  int y = getBarHeight( barNum ) * Height() / yrange;
1291  if ( y < 0 )
1292  y = 0;
1293  if ( y >= Height() )
1294  y = Height() -1 ;
1295 
1296  PG_Point pos = ClientToScreen( x, Height() - y );
1297  paintFilledRectangle<4>( s, SPoint( pos.x, pos.y), x2-x, y, ColorMerger_ColoredOverwrite<4>( mapColor( b->second ) ) );
1298 
1299  ++barNum;
1300  }
1301  };
1302 };
1303 
1305 {
1306  ContainerBase* cont;
1307  protected:
1308  int getPoint( int curve, int x ) {
1309  Resources cost = returnResourcenUseForResearch( cont, x );
1310  return cost.energy;
1311  }
1312 
1313 
1317  addVerticalLine( rel, 0xd9d9d9 );
1318  }
1319  }
1320 
1321  void recalc() {
1323 
1324  Player& player = cont->getMap()->player[ cont->getOwner() ];
1325  for ( Player::BuildingList::iterator i = player.buildingList.begin(); i != player.buildingList.end(); ++i )
1326  addSecondaryLab( *i );
1327 
1328  for ( Player::VehicleList::iterator i = player.vehicleList.begin(); i != player.vehicleList.end(); ++i )
1329  addSecondaryLab( *i );
1330 
1331  addVerticalLine( cont->researchpoints, 0xd5d200 );
1332  }
1333 
1334  bool setResearch ( ContainerBase* lab, int x ) {
1335  if ( cont->baseType->nominalresearchpoints ) {
1336  int res;
1337 
1338  if ( returnResourcenUseForResearch ( lab, lab->maxresearchpoints ) == Resources(0,0,0))
1339  res = lab->maxresearchpoints;
1340  else
1341  res = x * xrange / Width() * lab->baseType->nominalresearchpoints / cont->baseType->nominalresearchpoints;
1342 
1343  if ( res > lab->maxresearchpoints )
1344  res = lab->maxresearchpoints;
1345  int old = lab->researchpoints;
1346  lab->researchpoints = res;
1347  return res != old;
1348  } else
1349  return false;
1350  }
1351 
1352 
1353  void click( int x, int button ) {
1354  setResearch( x, button == 3 );
1355  }
1356 
1357  void setResearch( int x, bool global = false ) {
1358  if ( global ) {
1359  Player& player = cont->getMap()->player[ cont->getOwner() ];
1360  for ( Player::BuildingList::iterator i = player.buildingList.begin(); i != player.buildingList.end(); ++i )
1361  setResearch( *i, x );
1362 
1363  for ( Player::VehicleList::iterator i = player.vehicleList.begin(); i != player.vehicleList.end(); ++i )
1364  setResearch( *i, x );
1365  }
1366 
1367  if ( setResearch( cont, x ) || global ) {
1368  sigChange();
1369  recalc();
1370  Update();
1371  }
1372  }
1373 
1374  public:
1375  ResearchGraph( PG_Widget *parent, const PG_Rect& rect, ContainerBase* container ) : GraphWidget( parent, rect ), cont( container ) {
1377  addCurve( 0x00ff00 );
1378  recalc();
1379  }
1380 
1381  sigc::signal<void> sigChange;
1382 
1383 };
1384 
1385 
1387 {
1388  public:
1389  bool available( CargoDialog* cd ) {
1390  if ( !cd->getMap()->getCurrentPlayer().diplomacy.isAllied( cd->getContainer() ))
1391  return false;
1392 
1394  };
1395 
1397  return "research";
1398  };
1399 
1401  return "Research Lab";
1402  };
1403 
1404 
1405  void update() {
1406  ContainerBase* activeContainer= container();
1407 
1408  // from researchwindow
1409  Player& player = activeContainer->getMap()->player[ activeContainer->getOwner() ];
1410 
1411  cargoDialog->setLabelText( "ResPerTurnLocal", activeContainer->researchpoints * player.research.getMultiplier(), widget );
1412  cargoDialog->setLabelText( "ResPerTurnGlobal", player.research.getResearchPerTurn(), widget );
1413 
1414  Resources cost = returnResourcenUseForResearch( activeContainer );
1415  for ( int r = 0; r < 3; ++r)
1416  cargoDialog->setLabelText( "CostLocal" + ASCString::toString(r), cost.resource(r), widget );
1417 
1418  Resources globalCost;
1419  for ( Player::BuildingList::iterator i = player.buildingList.begin(); i != player.buildingList.end(); ++i )
1420  globalCost += returnResourcenUseForResearch( *i );
1421 
1422  for ( Player::VehicleList::iterator i = player.vehicleList.begin(); i != player.vehicleList.end(); ++i )
1423  globalCost += returnResourcenUseForResearch( *i );
1424 
1425  for ( int r = 0; r < 3; ++r)
1426  cargoDialog->setLabelText( "CostGlobal" + ASCString::toString(r), globalCost.resource(r), widget );
1427 
1428  int availIn = player.research.currentTechAvailableIn();
1429  if ( availIn >= 0 )
1430  cargoDialog->setLabelText( "AvailGlobal", availIn, widget );
1431  else
1432  cargoDialog->setLabelText( "AvailGlobal", "-", widget );
1433 
1434  if ( player.research.activetechnology )
1435  cargoDialog->setLabelText( "CurrentTech", player.research.activetechnology->name, widget );
1436  else
1437  cargoDialog->setLabelText( "CurrentTech", "-", widget );
1438  }
1439 };
1440 
1441 
1442 
1444 {
1445  PG_Slider* slider;
1446  bool first;
1447 
1448  protected:
1449  virtual bool invertSlider() {
1450  return false;
1451  };
1452  private:
1453 
1454  bool scrollPos( long pos ) {
1455  if ( invertSlider() )
1456  pos = 100 - pos;
1457 
1458  setnewpower( pos );
1459  update();
1460  return true;
1461  };
1462 
1463 
1464  bool scrollTrack( long pos ) {
1465 
1466  if ( invertSlider() )
1467  pos = 100 - pos;
1468 
1469  showResourceTable( getOutput( pos ));
1470 
1471  return true;
1472  };
1473 
1474  void setnewpower ( ContainerBase* c, int power ) {
1475  if ( hasFunction( c ) ) {
1476  auto_ptr<SetResourceProcessingRateCommand> srprc ( new SetResourceProcessingRateCommand( c, power ));
1477 
1478  ActionResult res = srprc->execute( createContext( c->getMap() ));
1479  if ( res.successful() )
1480  srprc.release();
1481  else
1482  displayActionError( res );
1483  }
1484  }
1485 
1486  void setnewpower ( int pwr ) {
1487  if ( pwr < 0 )
1488  pwr = 0;
1489 
1490  if ( pwr > 100 )
1491  pwr = 100;
1492 
1493  bool allbuildings = false;
1494 
1495  Player& player = container()->getMap()->player[ container()->getOwner() ];
1496 
1497  if ( allbuildings ) {
1498  for ( Player::BuildingList::iterator bi = player.buildingList.begin(); bi != player.buildingList.end(); bi++ )
1499  setnewpower( *bi, pwr );
1500  for ( Player::VehicleList::iterator bi = player.vehicleList.begin(); bi != player.vehicleList.end(); bi++ )
1501  setnewpower( *bi, pwr );
1502  } else {
1503  setnewpower( container(), pwr );
1504  }
1505  }
1506 
1507  virtual bool hasFunction( const ContainerBase* container ) = 0;
1508 
1509  bool available( CargoDialog* cd ) {
1510  if ( !cd->getMap()->getCurrentPlayer().diplomacy.isAllied( cd->getContainer() ))
1511  return false;
1512 
1513  return hasFunction( cd->getContainer() );
1514  };
1515 
1516  virtual Resources getOutput() = 0;
1517  virtual Resources getOutput( int rate ) = 0;
1518 
1519  private:
1520  void showResourceTable( const Resources& res ) {
1521  for ( int r = 0; r < 3; ++r ) {
1522  ASCString s = Resources::name(r);
1523  int amount = res.resource(r);
1524  if ( container()->maxplus.resource(r) < 0 ) {
1525  s += "In";
1526  amount = -amount;
1527  } else {
1528  s += "Out";
1529  }
1530  if ( container()->maxplus.resource(r) != 0 )
1531  cargoDialog->setLabelText( s, amount, widget );
1532  }
1533  }
1534 
1535  public:
1536  MatterAndMiningBaseWindow () : slider(NULL), first(true) {};
1537 
1538 
1539  void update() {
1541 
1542  if ( widget )
1543  slider = dynamic_cast<PG_Slider*>( widget->FindChild( "PowerSlider", true ));
1544 
1545  if ( first && slider ) {
1546  first = false;
1547  slider->SetRange( 0, 100 );
1548  slider->sigScrollPos.connect( sigc::mem_fun( *this, &MatterAndMiningBaseWindow::scrollPos ));
1549  slider->sigScrollTrack.connect( sigc::mem_fun( *this, &MatterAndMiningBaseWindow::scrollTrack ));
1550  }
1551 
1552  for ( int r = 0; r < 3; ++r )
1553  if ( container()->maxplus.resource(r) ) {
1554  slider->SetPosition( 100 * container()->plus.resource(r) / container()->maxplus.resource(r) );
1555  break;
1556  }
1557 
1558  showResourceTable( getOutput() );
1559  }
1560 };
1561 
1563 {
1564  protected:
1567  };
1568 
1570  return container()->plus;
1571  }
1572 
1573  Resources getOutput( int rate ) {
1574  Resources r;
1575  for ( int i = 0; i < Resources::count; ++i )
1576  r.resource(i) = rate * container()->maxplus.resource(i) / 100;
1577  return r;
1578  }
1579 
1580 
1581  public:
1582 
1584  return "conventionalpower";
1585  };
1586 
1588  return "Power Generation";
1589  };
1590 
1591 };
1592 
1593 
1594 
1595 class MiningGraph : public GraphWidget
1596 {
1597  ContainerBase* cont;
1598  GetMiningInfo::MiningInfo mininginfo;
1599  protected:
1600 
1601  int getBarHeight( int bar ) {
1602  int r = (bar % 4) - 1;
1603  switch ( bar % 4 ) {
1604  case 0:
1605  case 1:
1606  return 100;
1607  case 2:
1608  case 3:
1609  return 100 * mininginfo.avail[bar/4].resource(r) / mininginfo.max[bar/4].resource(r);
1610  };
1611  return 0;
1612  };
1613 
1614 
1615  public:
1616  MiningGraph( PG_Widget *parent, const PG_Rect& rect, ContainerBase* container ) : GraphWidget( parent, rect ), cont( container ) {
1617  setRange( (maxminingrange+1)*3+1, 110 );
1618 
1619  GetMiningInfo gmi ( container );
1620  mininginfo = gmi.getMiningInfo();
1621 
1622  int neutralColor = 0x666666;
1623 
1624  for ( int i = 0; i <= min( mininginfo.nextMiningDistance + 1, maxminingrange); ++i ) {
1625  addBar( i * 3, neutralColor );
1626  addBar( i * 3+1, neutralColor );
1627  addBar( i * 3, Resources::materialColor );
1628  addBar( i * 3+1, Resources::fuelColor );
1629  }
1630 
1631  }
1632 };
1633 
1634 
1636 {
1637  protected:
1640  };
1641 
1642  bool invertSlider() {
1643  return false;
1644  };
1645 
1647  Resources r;
1648  MiningStation miningStation ( container(), true );
1649 
1650  for ( int i = 0; i <3; ++i ) {
1651  Resources plus = miningStation.getPlus();
1652  if ( plus.resource(i) > 0 )
1653  r.resource(i) = plus.resource(i);
1654 
1655  Resources usage = miningStation.getUsage();
1656  if ( usage.resource(i) > 0 )
1657  r.resource(i) = -usage.resource(i);
1658  }
1659  return r;
1660  }
1661 
1662  Resources getOutput( int rate ) {
1663  ContainerBase* c = container();
1664  Resources temp = c->plus;
1665 
1666  for ( int r = 0; r < Resources::count; r++ )
1667  c->plus.resource(r) = c->maxplus.resource(r) * rate/100;
1668 
1669 
1670  Resources r;
1671  MiningStation miningStation ( container(), true );
1672 
1673  for ( int i = 0; i <3; ++i ) {
1674  Resources plus = miningStation.getPlus();
1675  if ( plus.resource(i) > 0 )
1676  r.resource(i) = plus.resource(i);
1677 
1678  Resources usage = miningStation.getUsage();
1679  if ( usage.resource(i) > 0 )
1680  r.resource(i) = -usage.resource(i);
1681  }
1682 
1683  c->plus = temp;
1684 
1685  return r;
1686  }
1687 
1688  public:
1689 
1691  return "mining";
1692  };
1693 
1695  return "Mining Facility";
1696  };
1697 
1698 
1699  void update() {
1701  }
1702 };
1703 
1704 
1705 
1706 class DamageBarWidget : public PG_ThemeWidget
1707 {
1708  private:
1709  ContainerBase* container;
1710  public:
1711  DamageBarWidget (PG_Widget *parent, const PG_Rect &rect, ContainerBase* container ) : PG_ThemeWidget( parent, rect, false ) {
1712  this->container = container;
1713  };
1714 
1715 
1716  void repaint() {
1717  Update();
1718  }
1719 
1720  void eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst) {
1721  DI_Color color( container->damage * 255 / 100, (100-container->damage) * 255/100, 0 );
1722 
1723  PG_Rect r = dst;
1724  r.w = (100 - container->damage ) * dst.w / 100;
1725 
1726  Resources cost;
1727  int w2 = (100 - container->damage + container->repairableDamage() ) * dst.w / 100;
1728 
1729  Uint32 c = color.MapRGBA( PG_Application::GetScreen()->format, 255-GetTransparency());
1730  if ( w > 0 ) {
1731  SDL_FillRect(PG_Application::GetScreen(), &r, c );
1732  }
1733 
1734  if ( w2 > 0 ) {
1735  int h = dst.h / 4;
1736  Surface s = Surface::Wrap( PG_Application::GetScreen() );
1737  ColorMerger_Set<4> cm ( c );
1738  drawLine<4> ( s, cm, SPoint(dst.x, dst.y + h), SPoint( dst.x + w2, dst.y + h));
1739  drawLine<4> ( s, cm, SPoint(dst.x, dst.y + h+1), SPoint( dst.x + w2, dst.y + h+1));
1740  drawLine<4> ( s, cm, SPoint(dst.x, dst.y + dst.h - h-1), SPoint( dst.x + w2, dst.y + dst.h - h-1));
1741  drawLine<4> ( s, cm, SPoint(dst.x, dst.y + dst.h - h), SPoint( dst.x + w2, dst.y + dst.h - h));
1742  drawLine<4> ( s, cm, SPoint( dst.x + w2, dst.y), SPoint( dst.x + w2, dst.y + dst.h));
1743  drawLine<4> ( s, cm, SPoint( dst.x-1 + w2, dst.y), SPoint( dst.x-1 + w2, dst.y + dst.h));
1744  }
1745 
1746  /* Uint32 c = color.MapRGBA( PG_Application::GetScreen()->format, 255-GetTransparency());
1747  for ( Colors::iterator i = colors.begin(); i != colors.end(); ++i)
1748  if ( fraction < i->first ) {
1749  PG_Color col = i->second;
1750  c = col.MapRGBA( PG_Application::GetScreen()->format, 255-GetTransparency());
1751  }
1752  */
1753 
1754 
1755  }
1756 
1757 };
1758 
1759 
1760 
1761 
1762 //*****************************************************************************************************
1763 //*****************************************************************************************************
1764 //
1765 // Cargo Dialog
1766 //
1767 //*****************************************************************************************************
1768 //*****************************************************************************************************
1769 
1770 
1771 
1772 CargoDialog ::CargoDialog (PG_Widget *parent, ContainerBase* cb )
1773  : Panel( parent, PG_Rect::null, "cargodialog", false ), container(cb), setupOK(false), cargoWidget(NULL), researchWindow( NULL ), matterWindow(NULL)
1774 {
1775  shutdownImmediately = false;
1776 
1777  sigClose.connect( sigc::mem_fun( *this, &CargoDialog::QuitModal ));
1778 
1779  registerGuiFunctions( guiIconHandler );
1780 
1781  cb->destroyed.connect( sigc::mem_fun( *this, &CargoDialog::containerDestroyed ));
1782 
1783  ciw = new CargoInfoWindow;
1784  subwindows.push_back( ciw );
1785  subwindows.push_back( new SolarPowerWindow );
1786  subwindows.push_back( new WindPowerWindow );
1787  subwindows.push_back( new MiningWindow );
1788  subwindows.push_back( new ResourceInfoWindow );
1789  // subwindows.push_back( new NetControlWindow );
1790 
1791  buildingControlWindow = new BuildingControlWindow;
1792  subwindows.push_back( buildingControlWindow );
1793 
1794  researchWindow = new ResearchWindow;
1795  subwindows.push_back( researchWindow );
1796 
1797  matterWindow = new MatterConversionWindow;
1798  subwindows.push_back ( matterWindow );
1799 
1800  for ( Subwindows::iterator i = subwindows.begin(); i != subwindows.end(); ++i )
1801  if ( (*i)->available( this ))
1802  (*i)->registerSubwindow( this );
1803 
1804 
1805 
1806  // cb->resourceChanged.connect( sigc::mem_fun( *this, &CargoDialog::updateResourceDisplay ));
1807  // cb->ammoChanged.connect( sigc::mem_fun( *this, &CargoDialog::showAmmo ));
1808 
1809 
1810  try {
1811  if ( !setup() )
1812  return;
1813 
1814  // to not block the weapon info on 800*600 screens
1815 
1816  if ( my_xpos + Width() > PG_Application::GetScreenWidth() - 100 )
1817  MoveWidget( 0, 0, false);
1818 
1819 
1820  } catch ( ParsingError err ) {
1821  errorMessage( err.getMessage() );
1822  return;
1823  } catch ( ... ) {
1824  errorMessage( "unknown exception" );
1825  return;
1826  }
1827 
1828  registerSpecialDisplay( "unitpad_unitsymbol" );
1829  registerSpecialDisplay( "SelectedImage" );
1830 
1831 
1832  for ( Subwindows::iterator i = subwindows.begin(); i != subwindows.end(); ++i ) {
1833  if ( (*i)->available( this ))
1834  (*i)->registerChilds( this );
1835  hide( (*i)->getASCTXTname() );
1836  }
1837 
1838 
1839 
1840  if ( !cb->baseType->infoImageFilename.empty() && exist( cb->baseType->infoImageFilename )) {
1841  PG_Image* img = dynamic_cast<PG_Image*>(FindChild( "ContainerImage", true ));
1842  if ( img ) {
1844  infoImage.readImageFile( stream );
1845  img->SetDrawMode( PG_Draw::STRETCH );
1846  img->SetImage( infoImage.getBaseSurface(), false );
1847  img->SizeWidget( img->GetParent()->w, img->GetParent()->h );
1848  }
1849  } else {
1850  PG_Image* img = dynamic_cast<PG_Image*>(FindChild( "ContainerImage", true ));
1851  Vehicle* v = dynamic_cast<Vehicle*>(cb);
1852  if ( img && v )
1853  img->SetImage( infoImage.getBaseSurface(), false );
1854 
1855  }
1856 
1857  if ( container->baseType->infoImageSmallFilename.length() > 0 )
1858  setImage( "Container3DImageSmall", container->baseType->infoImageSmallFilename );
1859 
1860 
1861 
1862  setLabelText( "UnitName", cb->getName() );
1863  if ( cb->getName() != cb->baseType->name )
1864  setLabelText( "UnitClass", cb->baseType->name );
1865 
1866  NewGuiHost::pushIconHandler( &guiIconHandler );
1867 
1868  activate_i(NULL, 0);
1869  cargoChanged();
1870  Show();
1871  setupOK = true;
1872 
1873 };
1874 
1875 
1876 void CargoDialog::userHandler( const ASCString& label, PropertyReadingContainer& pc, PG_Widget* parent, WidgetParameters widgetParams )
1877 {
1878  if ( label == "ButtonPanel" ) {
1879  int x = 0;
1880  int y = 0;
1881  for ( int i = 0; i < activesubwindows.size(); ++i ) {
1882  SubWinButton* button = new SubWinButton( parent, SPoint( x, y ), activesubwindows[i] );
1883  button->sigClick.connect( sigc::bind( sigc::mem_fun( *this, &CargoDialog::activate_i ), i));
1884  if ( x + 2*SubWinButton::buttonwidth < parent->Width() )
1886  else {
1887  x = 0;
1889  }
1890  subWinButtons.push_back( button );
1891  }
1892  }
1893 
1894  if ( label == "ResourceTable" ) {
1895  int gap = 2;
1896  int cellwidth = (parent->Width() - 8 * gap) / 9;
1897  int cellHeight = (parent->Height() - 3 * gap ) / 4;
1898  for ( int x = 0; x < 9; ++x )
1899  for ( int y = 0; y < 4; ++y ) {
1900  PG_Rect r ( x * parent->Width() / 9, y * parent->Height() / 4, cellwidth, cellHeight );
1901  PG_Label* l = new PG_Label ( parent, r, PG_NULLSTR );
1902  widgetParams.assign( l );
1903  ASCString label = "Res";
1904  char xx = 'A' + x;
1905  char yy = '1' + y;
1906  label += xx;
1907  label += yy;
1908  l->SetName( label );
1909  }
1910  }
1911 
1912  if ( label == "ResearchGraph" ) {
1913  ResearchGraph* graph = new ResearchGraph( parent, PG_Rect( 0, 0, parent->Width(), parent->Height() ), container );
1914  graph->sigChange.connect( sigc::mem_fun( *researchWindow, &SubWindow::update ));
1915  }
1916 
1917  if ( label == "MiningGraph" ) {
1918  MiningGraph* mg = new MiningGraph( parent, PG_Rect( 0, 0, parent->Width(), parent->Height() ), container );
1919  new PG_ToolTipHelp( mg, "Horizontal: distance from building ; vertical: amount of resources(M/F)");
1920 
1921  }
1922 
1923  if ( label == "DamageBar" ) {
1924  DamageBarWidget* dbw = new DamageBarWidget( parent, PG_Rect( 0, 0, parent->Width(), parent->Height() ), container );
1925  buildingControlWindow->damageChanged.connect( sigc::mem_fun( *dbw, &DamageBarWidget::repaint ));
1926  }
1927 
1928  if ( label == "ScrollArea" ) {
1929  PG_Widget* unitScrollArea = parent;
1930  if ( unitScrollArea ) {
1931  cargoWidget = new CargoWidget( unitScrollArea, PG_Rect( 1, 1, unitScrollArea->Width() -2 , unitScrollArea->Height() -2 ), container, false );
1932  cargoWidget->enableDragNDrop( true );
1933  cargoWidget->sigDragDone.connect( sigc::mem_fun( *this, &CargoDialog::dragUnitToInnerContainer ));
1934  cargoWidget->sigDragAvail.connect( sigc::mem_fun( *this, &CargoDialog::dragUnitToInnerContainerAvail ));
1935  cargoWidget->sigDragInProcess.connect( sigc::mem_fun( *this, &CargoDialog::dragInProcess ));
1936  cargoWidget->sigDragAborted.connect( sigc::mem_fun( *this, &CargoDialog::dragAborted ));
1937 
1938  vector<StoringPosition*> storingPositionVector;
1939 
1940  int x = 0;
1941  int y = 0;
1942 
1943  int posNum = container->baseType->maxLoadableUnits;
1944  if ( container->getCargo().size() > posNum )
1945  posNum = container->getCargo().size();
1946 
1947  int unitColumnCount = 0;
1948  for ( int i = 0; i < posNum; ++i ) {
1949  pc.openBracket( "UnitSlot" );
1950 
1951  int unitposx, unitposy;
1952  pc.addInteger( "unitposx", unitposx );
1953  pc.addInteger( "unitposy", unitposy );
1954 
1955  StoringPosition* sp = new StoringPosition( cargoWidget, PG_Point( x, y), PG_Point(unitposx, unitposy), cargoWidget->getHighLightingManager(), container->getCargo(), i, container->baseType->maxLoadableUnits >= container->getCargo().size(), cargoWidget );
1956  storingPositionVector.push_back( sp );
1957  x += sp->Width();
1958  if ( x + sp->Width() >= parent->Width() - 20 ) {
1959  if ( !unitColumnCount )
1960  unitColumnCount = i + 1;
1961  x = 0;
1962  y += sp->Height();
1963  }
1964 
1965 
1966  widgetParams.runTextIO( pc );
1967  parsePanelASCTXT( pc, sp, widgetParams );
1968  pc.closeBracket();
1969 
1970  }
1971 
1972  cargoWidget->registerStoringPositions( storingPositionVector, unitColumnCount );
1973  cargoWidget->sigScrollTrack.connect( sigc::mem_fun( *this, &CargoDialog::clearSmallIcons ));
1974 
1975  cargoWidget->unitMarked.connect( sigc::mem_fun( *this, &CargoDialog::checkStoringPosition ));
1976 
1977  if ( ciw )
1978  cargoWidget->unitMarked.connect( sigc::hide( sigc::mem_fun( *ciw, &CargoInfoWindow::update )));
1979 
1981  cargoWidget->unitMarked.connect( sigc::hide( sigc::mem_fun( *this, &CargoDialog::clearSmallIcons )));
1982 
1983  cargoWidget->unitClicked.connect ( sigc::mem_fun( *this, &CargoDialog::onUnitClick ));
1984 
1985  container->cargoChanged.connect( sigc::mem_fun( *cargoWidget, &CargoWidget::redrawAll ));
1986  }
1987  }
1988  if ( label == "UnitTypeList" || label == "UnitTypeListHorizontal" ) {
1989  int y = 0;
1990  int x = 0;
1991  parent->SetTransparency(255);
1992  for ( int i = 0; i < cmovemalitypenum; ++i ) {
1993  if ( container->baseType->vehicleCategoriesStorable & (1<<i)) {
1994  PG_Image* img = new PG_Image( parent, PG_Point(x, y),IconRepository::getIcon(moveMaliTypeIcons[i] ).getBaseSurface(), false);
1995  new PG_ToolTipHelp( img, cmovemalitypes[i] );
1996  if ( label == "UnitTypeList" )
1997  y += img->Height();
1998 
1999  if ( label == "UnitTypeListHorizontal" )
2000  x += img->Width();
2001  }
2002  }
2003 
2004  }
2005 
2006 };
2007 
2008 
2009 //*****************************************************************************************************
2010 //*****************************************************************************************************
2011 //
2012 // GUI FUNCTIONS
2013 //
2014 //*****************************************************************************************************
2015 //*****************************************************************************************************
2016 
2017 
2018 
2019 
2020 
2021 
2022 namespace CargoGuiFunctions
2023 {
2024 
2025 
2026 bool Movement::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2027 {
2028  return ( key->keysym.sym == SDLK_SPACE );
2029 };
2030 
2031 Surface& Movement::getImage( const MapCoordinate& pos, ContainerBase* subject, int num )
2032 {
2033  return IconRepository::getIcon("movement.png");
2034 };
2035 ASCString Movement::getName( const MapCoordinate& pos, ContainerBase* subject, int num )
2036 {
2037  return "move unit";
2038 };
2039 
2040 bool Movement::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2041 {
2042  Vehicle* unit = dynamic_cast<Vehicle*>(subject);
2043  if ( unit && unit->getOwner() == unit->getMap()->actplayer )
2044  return unit->canMove();
2045  return false;
2046 }
2047 
2048 void Movement::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2049 {
2050  if ( !mainScreenWidget )
2051  return;
2052 
2053  Vehicle* unit = dynamic_cast<Vehicle*>(subject);
2054  if ( !unit )
2055  return;
2056 
2057  int mode = 0;
2058  if ( isKeyPressed( SDLK_LSHIFT ) || isKeyPressed( SDLK_RSHIFT ))
2060 
2061 
2062  MoveUnitCommand* move = new MoveUnitCommand( unit );
2063 
2064  ActionResult res = move->searchFields (-1, mode);
2065  if ( !res.successful() ) {
2066  dispmessage2 ( res.getCode(), NULL );
2067  delete move;
2068  return;
2069  }
2070 
2071  for ( set<MapCoordinate3D>::const_iterator i = move->getReachableFields().begin(); i != move->getReachableFields().end(); ++i )
2072  unit->getMap()->getField( *i)->setaTemp(1);
2073 
2074  for ( set<MapCoordinate3D>::const_iterator i = move->getReachableFieldsIndirect().begin(); i != move->getReachableFieldsIndirect().end(); ++i )
2075  unit->getMap()->getField( *i)->setaTemp2(2);
2076 
2077  repaintMap();
2079 
2080  GuiIconHandler guiIconHandler;
2081  guiIconHandler.registerUserFunction( new MovementDestination( *mainScreenWidget ) );
2082  guiIconHandler.registerUserFunction( new CancelMovement( *mainScreenWidget ) );
2083 
2084  NewGuiHost::pushIconHandler( &guiIconHandler );
2085 
2086  parent.Hide();
2087 
2088  mainScreenWidget->Update();
2089  mainScreenWidget->RunModal();
2090  parent.getMap()->cleartemps(7);
2091 
2093  parent.cargoChanged();
2094  parent.Show();
2095 
2096 }
2097 
2098 
2100 
2101 
2102 bool UnitProduction::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2103 {
2104  if ( parent.getContainer()->getOwner() == parent.getContainer()->getMap()->actplayer )
2106 
2107  return false;
2108 }
2109 
2110 
2111 bool UnitProduction::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2112 {
2113  return ( key->keysym.sym == 'p' );
2114 };
2115 
2117 {
2118  return IconRepository::getIcon("unitproduction.png");
2119 };
2121 {
2122  return "produce unit";
2123 };
2124 
2125 void UnitProduction::productionLinesChanged()
2126 {
2127  if (constructUnitCommand ) {
2128  producables.clear();
2129  ConstructUnitCommand::Producables temp = constructUnitCommand->getProduceableVehicles();
2130  producables.insert( producables.end(), temp.begin(), temp.end () );
2131  }
2132 }
2133 
2134 void UnitProduction::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2135 {
2136  bool refillAmmo;
2137  bool refillResources;
2138 
2139  auto_ptr<ConstructUnitCommand> production ( new ConstructUnitCommand( parent.getContainer() ));
2140  constructUnitCommand = production.get();
2141 
2142  const VehicleType* v;
2143  {
2144  production->setMode( ConstructUnitCommand::internal );
2145  producables = production->getProduceableVehicles();
2146  VehicleProduction_SelectionWindow fsw( NULL, PG_Rect( 10, 10, 450, 550 ), parent.getContainer(), producables, true );
2147  fsw.reloadProducebles.connect( sigc::mem_fun( *this, &UnitProduction::productionLinesChanged ));
2148  fsw.SetTransparency(0);
2149  fsw.Show();
2150  fsw.RunModal();
2151  v = fsw.getVehicletype();
2152  refillAmmo = fsw.fillWithAmmo();
2153  refillResources = fsw.fillWithResources();
2154  }
2155  if ( v ) {
2156 
2157  for ( ConstructUnitCommand::Producables::const_iterator i = producables.begin(); i != producables.end(); ++i )
2158  if ( i->type == v ) {
2160  warningMessage("Not enough resources to build unit");
2161  return;
2162  }
2163 
2164  if ( i->prerequisites.getValue() & ( ConstructUnitCommand::Lack::Movement )) {
2165  warningMessage("Not enough movement to build unit");
2166  return;
2167  }
2168 
2169  if ( i->prerequisites.getValue() & ( ConstructUnitCommand::Lack::Research )) {
2170  warningMessage("This unit has not been researched yet");
2171  return;
2172  }
2173  }
2174 
2175  production->setVehicleType( v );
2176  ActionResult res = production->execute ( createContext( parent.getContainer()->getMap() ) );
2177 
2178  if ( !res.successful() )
2179  throw res;
2180 
2181  production.release();
2182 
2183  Vehicle* newUnit = constructUnitCommand->getProducedUnit();
2184  if ( !newUnit )
2185  throw ActionResult( 21804 );
2186 
2187 
2188  if ( refillAmmo || refillResources ) {
2189  auto_ptr<ServiceCommand> ser ( new ServiceCommand( parent.getContainer() ));
2190  ser->setDestination( newUnit );
2191  TransferHandler& trans = ser->getTransferHandler();
2192  if ( refillAmmo )
2193  trans.fillDestAmmo();
2194 
2195  if ( refillResources )
2196  trans.fillDestResource();
2197 
2198  ser->saveTransfers();
2199  ActionResult res = ser->execute( createContext( newUnit->getMap() ));
2200  if ( res.successful() )
2201  ser.release();
2202  else
2203  displayActionError(res);
2204 
2205  }
2206  if ( CGameOptions::Instance()->unitProduction.fillAmmo != refillAmmo ) {
2209  }
2210  if ( CGameOptions::Instance()->unitProduction.fillResources != refillResources ) {
2213  }
2214 
2215  }
2216  parent.cargoChanged(); // we need to update the resources because new production lines may have been build
2217  constructUnitCommand = NULL;
2218 }
2219 
2220 
2222 
2223 
2224 bool UnitTraining::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2225 {
2226  if ( !subject )
2227  return false;
2228 
2229  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2230  if ( !veh )
2231  return false;
2232 
2233  GameMap* map = parent.getContainer()->getMap();
2234  if ( map->actplayer == veh->getOwner() || map->actplayer == parent.getContainer()->getOwner() )
2235  if ( map->player[map->actplayer].diplomacy.isAllied( veh->getOwner() ))
2236  return TrainUnitCommand::avail( parent.getContainer(), veh);
2237 
2238  return false;
2239 }
2240 
2241 
2242 bool UnitTraining::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2243 {
2244  return ( key->keysym.sym == 't' );
2245 };
2246 
2248 {
2249  return IconRepository::getIcon("training.png");
2250 };
2251 
2253 {
2254  return "train unit";
2255 };
2256 
2257 
2258 void UnitTraining::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2259 {
2260  if ( !subject )
2261  return;
2262 
2263  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2264  if ( !veh )
2265  return;
2266 
2267  auto_ptr<TrainUnitCommand> tuc ( new TrainUnitCommand( parent.getContainer() ));
2268  tuc->setUnit( veh );
2269  ActionResult res = tuc->execute( createContext( veh->getMap()));
2270  if ( res.successful() ) {
2271  tuc.release();
2272  parent.cargoChanged();
2273  } else
2274  displayActionError( res );
2275 }
2276 
2277 
2280 
2281 
2282 bool RefuelUnitCommand::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2283 {
2284  if ( !subject )
2285  return false;
2286 
2287  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2288  if ( !veh )
2289  return false;
2290 
2291  ServiceCommand sc( parent.getContainer() );
2293 
2294  return find( dest.begin(), dest.end(), subject ) != dest.end();
2295 }
2296 
2297 
2298 bool RefuelUnitCommand::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2299 {
2300  return ( key->keysym.sym == 'f' );
2301 };
2302 
2304 {
2305  return IconRepository::getIcon("refuel.png");
2306 };
2307 
2309 {
2310  return "refuel unit";
2311 };
2312 
2313 
2314 void RefuelUnitCommand::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2315 {
2316  if ( !subject )
2317  return;
2318 
2319  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2320  if ( !veh )
2321  return;
2322 
2323  auto_ptr<ServiceCommand> ser ( new ServiceCommand( parent.getContainer() ));
2324  ser->setDestination( subject );
2325  ser->getTransferHandler().fillDest();
2326  ser->saveTransfers();
2327  ActionResult res = ser->execute( createContext( subject->getMap() ));
2328  if ( res.successful() )
2329  ser.release();
2330  else
2331  displayActionError(res);
2332  parent.cargoChanged();
2333 }
2335 
2336 bool RepairUnit::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2337 {
2338  if ( !subject )
2339  return false;
2340 
2342  return false;
2343 
2344  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2345  if ( !veh )
2346  return false;
2347 
2348 
2349  return veh->damage > 0;
2350 }
2351 
2352 
2353 bool RepairUnit::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2354 {
2355  return ( key->keysym.sym == 'r' );
2356 };
2357 
2358 Surface& RepairUnit::getImage( const MapCoordinate& pos, ContainerBase* subject, int num )
2359 {
2360  return IconRepository::getIcon("repair.png");
2361 };
2362 
2364 {
2365  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2366  if ( veh && parent.getContainer() ) {
2367  Resources r;
2368  parent.getContainer()->getMaxRepair ( veh, 0, r);
2369  return "~r~epair unit (cost: " + r.toString() + ")";
2370  }
2371 
2372  return "repair unit";
2373 };
2374 
2375 
2376 void RepairUnit::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2377 {
2378  if ( !subject )
2379  return;
2380 
2381  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2382  if ( !veh )
2383  return;
2384 
2385  auto_ptr<RepairUnitCommand> rp ( new RepairUnitCommand( parent.getContainer() ));
2386 
2387  if ( !rp->validTarget( veh ) )
2388  return;
2389 
2390  rp->setTarget( veh );
2391  ActionResult res = rp->execute( createContext ( veh->getMap() ));
2392  if ( res.successful() )
2393  rp.release();
2394 
2395  parent.cargoChanged();
2396 }
2397 
2399 
2400 bool MoveUnitUp::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2401 {
2402  if ( !subject )
2403  return false;
2404 
2405  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2406  if ( !veh )
2407  return false;
2408 
2409  return CargoMoveCommand::moveOutAvail( veh );
2410 }
2411 
2412 
2413 bool MoveUnitUp::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2414 {
2415  return ( key->keysym.sym == 'o' );
2416 };
2417 
2418 Surface& MoveUnitUp::getImage( const MapCoordinate& pos, ContainerBase* subject, int num )
2419 {
2420  return IconRepository::getIcon("moveunitup.png");
2421 };
2422 
2424 {
2425  return "move unit to ~o~uter transport";
2426 };
2427 
2428 
2429 void MoveUnitUp::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2430 {
2431  if ( !subject )
2432  return;
2433 
2434 
2435  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2436  if ( !veh )
2437  return;
2438 
2439  auto_ptr<CargoMoveCommand> cargomove ( new CargoMoveCommand( veh ));
2440  cargomove->setMode( CargoMoveCommand::moveOutwards );
2441  ActionResult res = cargomove->execute ( createContext( veh->getMap() ));
2442  if ( res.successful() )
2443  cargomove.release();
2444 
2445  parent.cargoChanged();
2446 }
2447 
2449 
2450 
2451 bool CloseDialog::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2452 {
2453  return true;
2454 }
2455 
2456 
2457 bool CloseDialog::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2458 {
2459  return ( key->keysym.sym == 'x' );
2460 };
2461 
2463 {
2464  return IconRepository::getIcon("closecargodialog.png");
2465 };
2466 
2468 {
2469  return "close dialog";
2470 };
2471 
2472 
2473 void CloseDialog::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2474 {
2475  parent.QuitModal();
2476 }
2477 
2479 
2480 
2481 bool UnitInfo::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2482 {
2483  if ( !subject )
2484  return false;
2485 
2486  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2487  return veh;
2488 }
2489 
2490 
2491 bool UnitInfo::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2492 {
2493  return ( key->keysym.sym == 'i' );
2494 };
2495 
2496 Surface& UnitInfo::getImage( const MapCoordinate& pos, ContainerBase* subject, int num )
2497 {
2498  return IconRepository::getIcon("unitinfo.png");
2499 };
2500 
2501 ASCString UnitInfo::getName( const MapCoordinate& pos, ContainerBase* subject, int num )
2502 {
2503  return "show unit ~i~nformation";
2504 };
2505 
2506 
2507 void UnitInfo::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2508 {
2509  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2510  if ( veh )
2511  unitInfoDialog( veh->typ );
2512 }
2513 
2515 
2516 
2517 bool TransferUnitControl::available( const MapCoordinate& pos, ContainerBase* subject, int num )
2518 {
2519  if ( !subject )
2520  return false;
2521 
2522  if ( subject->getOwner() != subject->getMap()->actplayer )
2523  return false;
2524 
2525  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2526  if ( !veh )
2527  return false;
2528 
2529  return TransferControlCommand::avail( subject );
2530 
2531 }
2532 
2533 
2535 {
2536  return IconRepository::getIcon("transferunitcontrol.png");
2537 };
2538 
2540 {
2541  return "transfer unit control";
2542 };
2543 
2544 
2545 void TransferUnitControl::execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2546 {
2547  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2548  if ( veh ) {
2549 
2550  auto_ptr<TransferControlCommand> tcc ( new TransferControlCommand( subject ));
2551  TransferControlCommand::Receivers rec = tcc->getReceivers();
2552 
2553  vector<ASCString> entries;
2554  for ( TransferControlCommand::Receivers::iterator i = rec.begin(); i != rec.end(); ++i )
2555  entries.push_back ( (*i)->getName() );
2556 
2557  if ( !entries.size() ) {
2558  infoMessage("you don't have any allies!");
2559  return;
2560  }
2561 
2562  int result = chooseString ( "Choose player", entries );
2563  if ( result >= 0 ) {
2564  tcc->setReceiver( rec[result] );
2565  ActionResult res = tcc->execute( createContext( subject->getMap() ));
2566  if ( res.successful() ) {
2567  tcc.release();
2568  parent.cargoChanged();
2569  } else
2570  displayActionError( res );
2571  }
2572 
2573 
2574  }
2575 }
2576 
2578 
2579 
2580 
2582 {
2583  if ( !subject )
2584  return false;
2585 
2586  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2587  if ( !veh )
2588  return false;
2589 
2590  CargoMoveCommand cmc( veh );
2591  return cmc.getTargetCarriers().size() > 0 ;
2592 }
2593 
2594 
2595 bool MoveUnitIntoInnerContainer::checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2596 {
2597  return ( key->keysym.sym == 'u' );
2598 };
2599 
2601 {
2602  return IconRepository::getIcon("container-in.png");
2603 };
2604 
2606 {
2607  return "move ~u~nit into neighboring transport";
2608 };
2609 
2610 
2611 
2613 {
2614  private:
2615  Vehicle* veh;
2616  public:
2617  VehicleWidget( PG_Widget* parent, const PG_Point& pos, int width, Vehicle* unit )
2618  : VehicleBaseWidget( parent, pos, width, unit, unit->getMap()->getPlayer(unit) ) {
2619  veh = unit;
2620  };
2621 
2622  Vehicle* getUnit() const {
2623  return veh;
2624  };
2625 };
2626 
2627 class VehicleSelectionFactory: public SelectionItemFactory, public sigc::trackable
2628 {
2629  public:
2630  typedef vector<Vehicle*> Container;
2631  protected:
2632  Container::iterator it;
2634 
2635  public:
2636  VehicleSelectionFactory( Container& units ) : items ( units ), selected(NULL) {};
2637  void restart() {
2638  it = items.begin();
2639  };
2640 
2641  SelectionWidget* spawnNextItem( PG_Widget* parent, const PG_Point& pos ) {
2642  if ( it != items.end() ) {
2643  Vehicle* v = *(it++);
2644  return new VehicleWidget( parent, pos, parent->Width() - 15, v );
2645  } else
2646  return NULL;
2647  };
2648 
2649  void itemSelected( const SelectionWidget* widget, bool mouse ) {
2650  if ( !widget )
2651  return;
2652 
2653  const VehicleWidget* vw = dynamic_cast<const VehicleWidget*>(widget);
2654  assert( vw );
2655  selected = vw->getUnit();
2656  }
2657 
2659 };
2660 
2661 
2662 Vehicle* selectVehicle( vector<Vehicle*> targets )
2663 {
2664  Vehicle* target = NULL;
2665  VehicleSelectionFactory* vsf = new VehicleSelectionFactory( targets );
2666  ItemSelectorWindow isw ( NULL, PG_Rect( 50, 50, 300, 400), "Please choose target unit", vsf );
2667  isw.Show();
2668  isw.RunModal();
2669  target = vsf->selected;
2670  return target;
2671 }
2672 
2673 
2674 
2675 
2677 {
2678  if ( !subject )
2679  return;
2680 
2681 
2682  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2683  if ( !veh )
2684  return;
2685 
2686  auto_ptr<CargoMoveCommand> cargomove ( new CargoMoveCommand( veh ));
2687  cargomove->setMode( CargoMoveCommand::moveInwards );
2688 
2689  vector<Vehicle*> targets = cargomove->getTargetCarriers();
2690 
2691  choiceDialog("You can also use Drag'n'Drop to move units in the Cargo Dialog\nMouse button: " + CGameOptions::Mouse::getButtonName( CGameOptions::Instance()->mouse.dragndropbutton ), "OK", "", "dragndropinfo");
2692 
2693  Vehicle* target = selectVehicle( targets );
2694  if ( target ) {
2695  cargomove->setTargetCarrier( target );
2696  ActionResult res = cargomove->execute ( createContext( veh->getMap() ));
2697  if ( res.successful() )
2698  cargomove.release();
2699  }
2700  parent.cargoChanged();
2701 }
2702 
2703 
2704 
2706 
2708 {
2709  if ( !subject )
2710  return false;
2711 
2712  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2713  if ( !veh )
2714  return false;
2715 
2716  ServiceCommand sc( parent.getContainer() );
2718 
2719  return find( dest.begin(), dest.end(), subject ) != dest.end();
2720 };
2721 
2723 {
2724  if ( !subject )
2725  return;
2726 
2727  auto_ptr<ServiceCommand> ser ( new ServiceCommand( parent.getContainer() ));
2728  ser->setDestination( subject );
2729  ammoTransferWindow( parent.getContainer(), subject, ser.get() );
2730  parent.cargoChanged();
2731  if ( ser->getState() == Command::Finished )
2732  ser.release();
2733 }
2734 
2736 {
2737  return IconRepository::getIcon("refuel-dialog.png");
2738 };
2739 
2740 bool RefuelUnitDialogCommand :: checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2741 {
2742  return ( key->keysym.unicode == 'd' );
2743 };
2744 
2746 {
2747  return "Refuel Dialog";
2748 };
2749 
2751 
2752 bool OpenContainer :: available( const MapCoordinate& pos, ContainerBase* subject, int num )
2753 {
2754  if ( !subject )
2755  return false;
2756 
2757  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2758  if ( !veh )
2759  return false;
2760 
2761  Player& player = veh->getMap()->player[veh->getOwner()];
2762  if ( veh->typ->maxLoadableUnits && player.diplomacy.isAllied( veh->getMap()->actplayer) )
2763  return true;
2764 
2765  return false;
2766 };
2767 
2768 void OpenContainer :: execute( const MapCoordinate& pos, ContainerBase* subject, int num )
2769 {
2770  if ( !subject )
2771  return;
2772 
2773  cargoDialog( subject );
2774  parent.cargoChanged();
2775 }
2776 
2778 {
2779  return IconRepository::getIcon("container.png");
2780 };
2781 
2782 bool OpenContainer :: checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2783 {
2784  return ( key->keysym.unicode == 'l' );
2785 };
2786 
2788 {
2789  return "open transport ";
2790 };
2791 
2792 
2793 
2794 
2796 
2797 
2799 {
2800  if ( !subject )
2801  return false;
2802 
2803  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2804  if ( !veh )
2805  return false;
2806 
2807  if ( !RecycleUnitCommand::avail( parent.getContainer(), veh))
2808  return false;
2809 
2810  Player& player = veh->getMap()->player[veh->getOwner()];
2811  if ( player.diplomacy.isAllied( veh->getMap()->actplayer) )
2812  return true;
2813  else
2814  return false;
2815 };
2816 
2817 ASCString RecycleUnitCommandButton :: getCommandName( const ContainerBase* carrier )
2818 {
2820  return "recycle";
2821  else
2822  return "salvage";
2823 }
2824 
2825 
2827 {
2828  if ( !subject )
2829  return;
2830 
2831  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2832  if ( !veh )
2833  return;
2834 
2835  ASCString msg = "do you really want to " + getCommandName( parent.getContainer() ) + " this unit ?";
2836 
2837  if (choice_dlg( msg ,"~y~es","~n~o") == 1) {
2838  auto_ptr<RecycleUnitCommand> command ( new RecycleUnitCommand( parent.getContainer() ));
2839  command->setUnit( veh );
2840  ActionResult res = command->execute( createContext( parent.getContainer()->getMap() ));
2841  if ( res.successful() )
2842  command.release();
2843  else
2844  displayActionError( res );
2845  parent.cargoChanged();
2846  }
2847 }
2848 
2849 
2851 {
2852  return IconRepository::getIcon("recycle.png");
2853 };
2854 
2855 bool RecycleUnitCommandButton :: checkForKey( const SDL_KeyboardEvent* key, int modifier, int num )
2856 {
2857  return false;
2858 };
2859 
2861 {
2862  if ( !subject )
2863  return "";
2864 
2865  Vehicle* veh = dynamic_cast<Vehicle*>(subject);
2866  if ( !veh )
2867  return "";
2868 
2869  ASCString s = getCommandName( parent.getContainer() ) + " unit - ";
2870 
2871  Resources res = RecycleUnitCommand::getOutput( parent.getContainer(), veh );
2872 
2873  bool cost = false;
2874  for ( int r = 0; r < 3; ++r ) {
2875  if ( res.resource(r) < 0 ) {
2876  if ( !cost ) {
2877  s += "Cost: ";
2878  cost = true;
2879  }
2880  s += ASCString::toString( -res.resource( r ));
2881  s += " ";
2882  s += Resources::name( r );
2883  }
2884  }
2885 
2886  bool gain = false;
2887  for ( int r = 0; r < 3; ++r ) {
2888  if ( res.resource(r) > 0 ) {
2889  if ( !gain ) {
2890  s += "Gain: ";
2891  cost = true;
2892  }
2893  s += ASCString::toString( res.resource( r ));
2894  s += " ";
2895  s += Resources::name( r );
2896  }
2897  }
2898 
2899  return s;
2900 
2901 };
2902 
2903 }
2904 
const VehicleType * selectVehicletype(ContainerBase *plant, const vector< VehicleType * > &items)
void showUnitData(Vehicle *veh, Building *bld, MapField *fld, bool redraw=false)
Definition: dashboard.cpp:378
int fuel
Definition: typen.h:101
ASCString infoImageSmallFilename
calculates some mining statistics for a mining station
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
Player & getCurrentPlayer()
Definition: gamemap.h:268
void fillDestAmmo()
Definition: servicing.cpp:852
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
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)
static bool avail(const Building *building)
virtual bool available(CargoDialog *cd)=0
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void updateVariables()
void cleartemps(int b=-1, int value=0)
Definition: gamemap.cpp:964
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool invertSlider()
ASCString getFullName()
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
int maxLoadableUnits
the maximum number of units that can be loaded
RefuelUnitCommand(CargoDialog &masterParent)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
DisplayHook display
Definition: paradialog.h:182
DamageBarWidget(PG_Widget *parent, const PG_Rect &rect, ContainerBase *container)
#define cwmachinegunn
Definition: vehicletype.h:77
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
int getresource(int x, int y, int resource, int _player, int _scope)
void enableDragNDrop(bool enable)
Definition: cargowidget.h:132
int getMaxRepair(const ContainerBase *item) const
returns the maximum amount of damage that the given item can be repaired
#define cwsmallmissilen
Definition: vehicletype.h:73
the command is totally done
Definition: command.h:120
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
A Device Independent color. Shamelessly pinched from Paragui to reduce coupling.
Definition: surface.h:30
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
sigc::signal< void > sigDragInProcess
Definition: cargowidget.h:127
void click(int x, int button)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
GraphWidget(PG_Widget *parent, const PG_Rect &rect)
int energy
Definition: typen.h:99
ASCString name
a name given by the user or the map creator
const int smallGuiIconSizeY
Resources getOutput()
MoveUnitUp(CargoDialog &masterParent)
void registerSubwindow(CargoDialog *cd)
bool available(CargoDialog *cd)
sigc::signal< bool, Vehicle *, Vehicle * > sigDragAvail
First param: dragged unit, Second Param: target unit.
Definition: cargowidget.h:125
void registerUserFunction(GuiFunction *function)
registers a user function.
void ammoTransferWindow(ContainerBase *source, ContainerBase *destination, ServiceCommand *command)
void move(Vehicle *veh, const MapCoordinate &dest)
int currentTechAvailableIn() const
Definition: research.cpp:908
int getresource(int x, int y, int resource, int _need, int _queryonly, int _player, int _scope)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
virtual ASCString getName() const =0
static bool avail(const ContainerBase *carrier, const Vehicle *unit)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
#define cwcruisemissilen
Definition: vehicletype.h:65
sigc::signal< void, Vehicle * > unitMarked
Definition: cargowidget.h:111
#define cwbombn
Definition: vehicletype.h:69
Movement(CargoDialog &masterParent)
ASCString toString() const
Definition: typen.cpp:268
static const int materialColor
Definition: typen.h:140
Context createContext(GameMap *gamemap)
int choiceDialog(const ASCString &text, const ASCString &button1, const ASCString &button2, const ASCString &shortLabel)
Definition: paradialog.cpp:806
DiplomaticStateVector diplomacy
Definition: player.h:209
bool hasFunction(ContainerFunctions function) const
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(CargoDialog *cd)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
int getOwner() const
returns the number of the player this vehicle/building belongs to
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool fillResources
Definition: gameoptions.h:186
static bool moveOutAvail(const Vehicle *movingUnit)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool setResearch(ContainerBase *lab, int x)
const char * cmovemalitypes[cmovemalitypenum]
the names of the different MoveMalusTypes
Definition: typen.cpp:43
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
virtual Resources getPlus()
bool available(CargoDialog *cd)
ASCString getFullName()
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void setImage(const ASCString &widgetName, Surface &image, PG_Widget *parent=NULL)
Definition: windowing.cpp:739
UnitProduction(CargoDialog &masterParent)
void bar(int x1, int y1, int x2, int y2, Uint8 color)
paints a colored bar
Definition: basegfx.cpp:1239
static bool moveInAvail(const Vehicle *movingUnit, Vehicle *newCarrier)
SubWinButton(PG_Widget *parent, const SPoint &pos, SubWindow *subWindow)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
sigc::signal< void > cargoChanged
int getPoint(int curve, int x)
void warningMessage(const ASCString &str)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
Vehicle * getMarkedUnit()
static Command * pendingCommand
ASCString getASCTXTname()
CloseDialog(CargoDialog &masterParent)
sigc::signal< void > repaintMap
}@
Definition: spfst.cpp:45
void cargoChanged()
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
int addBar(int pos, int color)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString & format(const charT *pFormat,...)
Definition: ascstring.cpp:78
const set< MapCoordinate3D > & getReachableFieldsIndirect()
ASCString getASCTXTname()
sigc::signal< void, Vehicle *, Vehicle * > sigDragDone
First param: dragged unit, Second Param: target unit.
Definition: cargowidget.h:122
static Resources getOutput(const ContainerBase *carrier, const Vehicle *unit)
bool eventMouseMotion(const SDL_MouseMotionEvent *motion)
SDL_Surface * getBaseSurface()
Definition: surface.h:116
sigc::signal< void > sigScrollTrack
Definition: cargowidget.h:130
static const char * name(int r)
Definition: typen.cpp:190
DashboardPanel * getUnitInfoPanel()
struct GameMap::Weather weather
void eventBlit(SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
Resources getOutput(int rate)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
Uint32 MapRGBA(SDL_PixelFormat *format, Uint8 a) const
Definition: surface.h:47
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
Resources max[maxminingrange+2]
ASCString description
short description of the units role, for example "strategic bomber"
void dispmessage2(const ActionResult &result)
Definition: dialog.cpp:466
int vehicleCategoriesStorable
bitmapped: vehicle categories that can be stored the container
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
RecycleUnitCommandButton(CargoDialog &masterParent)
int view
the visibility range
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void showAmmo()
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
OpenContainer(CargoDialog &masterParent)
bool clearSmallIcons()
virtual Resources getPlus()
static void popIconHandler()
GameMap * getMap()
int maxLoadableUnitSize
the maximum size of a unit that may enter the building
Producables getProduceableVehicles()
int mapColor(int col)
struct CGameOptions::@9 unitProduction
UnitInfo(CargoDialog &masterParent)
void redrawAll()
void parsePanelASCTXT(PropertyReadingContainer &pc, PG_Widget *parent, WidgetParameters widgetParams)
Definition: windowing.cpp:370
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void itemSelected(const SelectionWidget *widget, bool mouse)
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
ActionResult undo(const Context &context)
does a single undo step
VehicleList vehicleList
a list of all units
Definition: player.h:135
#define cwcannonn
Definition: vehicletype.h:79
virtual int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)=0
vector< const Player * > Receivers
static bool internalConstructionAvail(const ContainerBase *eht)
int getBarHeight(int bar)
void setChanged(bool flag=true)
Definition: gameoptions.h:272
const int maxminingrange
The maximum number of fields a mining station can extract mineral resources from; Counted from its en...
Definition: typen.h:542
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(CargoDialog *cd)
void addAvailableSubwin(SubWindow *w)
enum Player::PlayerStatus stat
Vehicle * selectVehicle(vector< Vehicle * > targets)
virtual Resources getPlus()
const Technology * activetechnology
the technology that is currently being researched
Definition: research.h:191
Coordinate on the twodimensional map.
Definition: typen.h:202
MiningGraph(PG_Widget *parent, const PG_Rect &rect, ContainerBase *container)
static bool avail(const ContainerBase *item)
Vehicle * getMarkedUnit()
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
ASCString getASCTXTname()
void eval(const MapCoordinate &pos, ContainerBase *subject)
const int cmovemalitypenum
The number of vehicle categories; Each category has its own move malus.
Definition: typen.h:384
void clearVerticalLines()
const MiningInfo & getMiningInfo()
int jamming
the radar jamming power
ASCString getFullName()
bool isResourceGlobal(int resource)
Definition: gamemap.cpp:1024
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
void assign(PG_Widget *widget)
Definition: windowing.cpp:284
void paint(Surface &s, SPoint pos, int shadowDist=-1) const
displays the unit at position spos on s
Definition: vehicle.cpp:1681
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
static int buttonheight
sigc::signal< void > destroyed
bool ProcessEvent(const SDL_Event *event, bool bModal=false)
void registerStoringPositions(vector< StoringPosition * > sp, const int &colcount)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString infoImageFilename
the filename of an image that is shown in info dialogs
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void setBargraphValue(const ASCString &widgetName, float fraction, PG_Widget *parent=NULL)
Definition: windowing.cpp:790
PG_Widget * widget
Definition: cargodialog.cpp:72
void addVerticalLine(int x, int color)
static int buttonwidth
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
SelectionWidget * spawnNextItem(PG_Widget *parent, const PG_Point &pos)
sigc::signal< void > sigCargoChanged
Resources maxplus
the maximum amount of Resources that the building can produce each turn in the ASC resource mode ; se...
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
void registerChilds(CargoDialog *cd)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
void cargoDialog(ContainerBase *cb)
ActionResult redo(const Context &context)
does a single redo step
int material
Definition: typen.h:100
ASCString getFullName()
virtual int getBarHeight(int bar)
const ASCString & getMessage(void) const
Definition: errors.h:42
void setRange(int x, int y)
void setUnitInfoWidgets(const ContainerBase *container, const ASCString &prefix)
virtual int getPoint(int curve, int x)
void fillDestResource()
Definition: servicing.cpp:860
const char * moveMaliTypeIcons[cmovemalitypenum]
filenames of icons representing the varios movemalus types
Definition: typen.cpp:51
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
int getResourceValue(int resourcetype, int y, int scope)
Resources returnResourcenUseForResearch(const ContainerBase *bld, int research)
Calculates the resources that are needed to research the given number of research.
Definition: research.cpp:937
void updateResourceDisplay()
CargoDialog * cargoDialog
Definition: cargodialog.cpp:71
bool successful() const
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
void show(const ASCString &widgetName, PG_Widget *parent=NULL)
Definition: windowing.cpp:778
#define cwminen
Definition: vehicletype.h:67
SDLmm::SPoint SPoint
Definition: surface.h:27
Player player[9]
Definition: gamemap.h:253
Resources plus
the Resources that are produced each turn
bool singleClickAction
marks a field and opens the small gui buttons with a single click (default: first click mark...
Definition: gameoptions.h:161
void errorMessage(const ASCString &string)
virtual Resources getUsage()
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
ASCString getFullName()
void registerChilds(CargoDialog *cd)
MovementDestination(PG_Widget &masterParent)
struct CGameOptions::Mouse mouse
Cargo Move is moving a unit between different carriers that are nested.
ASCString getASCTXTname()
int getResearchPerTurn() const
Definition: research.cpp:896
bool available(CargoDialog *cd)
Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)
void eventBlit(SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
int vehiclesLoaded(void) const
returns the number of loaded units
bool available(CargoDialog *cd)
BuildingList buildingList
a list of all units
Definition: player.h:139
bool canMove(void) const
can the unit move from its current position (does not check neighbouring fields)
Definition: vehicle.cpp:599
sigc::signal< void > sigChange
void addInteger(const ASCString &name, int &property)
void setResearch(int x, bool global=false)
vector< Vehicle * > getTargetCarriers()
void addSecondaryLab(ContainerBase *lab)
bool isKeyPressed(SDLKey key)
Definition: events.cpp:187
bool eventMouseButtonDown(const SDL_MouseButtonEvent *button)
Research research
the status of the scientific research
Definition: player.h:142
int nominalresearchpoints
the number of reseach points for which the plus settings apllies
RefuelUnitDialogCommand(CargoDialog &masterParent)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
int & resource(int type)
Definition: typen.h:105
virtual void closeBracket()
ContainerBase * getCarrier() const
if this is a unit and it is inside a building or transport, returns the transport. NULL otherwise.
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
ActionResult searchFields(int height=-1, int capabilities=0)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
const VehicleType * typ
Definition: vehicle.h:83
bool isAllied(PlayerID towardsPlayer) const
Definition: player.h:82
static Surface & getIcon(const ASCString &name)
ActionContainer actions
Records all action that have been done for undo/redo purposes.
Definition: gamemap.h:390
void runTextIO(PropertyReadingContainer &pc)
Definition: windowing.cpp:166
virtual int getAmmo(int type, int num, bool queryOnly)=0
static const int fuelColor
Definition: typen.h:141
static ASCString getButtonName(int button)
bool showSmallIcons(PG_Widget *parent, const SPoint &pos, bool cursorChanged)
virtual int repairableDamage() const =0
returns the amount of damage that can still be repaired this turn
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
ASCString name
Definition: research.h:137
static bool avail(const ContainerBase *carrier, const Vehicle *unit)
vector< ContainerBase * > Targets
Definition: servicing.h:129
UnitTraining(CargoDialog &masterParent)
int cargoWeight() const
weight of all loaded units
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
ASC_MainScreenWidget * mainScreenWidget
static const int count
Definition: typen.h:103
void paint(Surface &s, SPoint pos, const PlayerColor &player, int direction=0) const
const ContainerBaseType * baseType
the type descriping all non-instance specific properties of the container
Definition: containerbase.h:80
ASCString getName(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
GameMap * getMap() const
sigc::signal< void, Vehicle *, SPoint, bool > unitClicked
the bool param is set to true if this is the first click on a unit
Definition: cargowidget.h:114
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
NewGuiHost * getGuiHost()
static Surface Wrap(SDL_Surface *surface)
Definition: surface.h:76
ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
bool ProcessEvent(const SDL_Event *event, bool bModal)
virtual void openBracket(const ASCString &name)
const int smallGuiIconSizeX
bool exist(const ASCString &s)
does a file s exist (wildcards allowed)
Definition: basestrm.cpp:2444
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
static bool availInternally(const ContainerBase *servicer)
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
void hide(const ASCString &widgetName, PG_Widget *parent=NULL)
Definition: windowing.cpp:768
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
void setaTemp2(Uint8 atemp2)
Definition: mapfield.cpp:56
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
virtual ASCString getFullName()=0
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
void userHandler(const ASCString &label, PropertyReadingContainer &pc, PG_Widget *parent, WidgetParameters widgetParams)
void readImageFile(tnstream &stream)
Definition: surface.cpp:380
Resources are basically the currency of ASC.
Definition: typen.h:97
void displayActionError(const ActionResult &result, const ASCString &additionalInfo)
Definition: dialog.cpp:2168
TransferUnitControl(CargoDialog &masterParent)
int researchpoints
the current amount of research that the building conducts every turn
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool hasFunction(const ContainerBase *container)
ASCString getASCTXTname()
int choice_dlg(const ASCString &title, const ASCString &leftButton, const ASCString &rightButton)
Definition: dialog.cpp:616
virtual int getArmor() const =0
ASCString getASCTXTname()
const Cargo & getCargo() const
Resources avail[maxminingrange+2]
ContainerBase * getContainer()
MoveUnitIntoInnerContainer(CargoDialog &masterParent)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
#define cwtorpedon
Definition: vehicletype.h:75
ASCString getFullName()
const set< MapCoordinate3D > & getReachableFields()
this will return a 2D representation of the reachable fields.
int getCode() const
Definition: actionresult.h:43
virtual void registerChilds(CargoDialog *cd)
HighLightingManager & getHighLightingManager()
Definition: cargowidget.h:135
ASCString getFullName()
ResearchGraph(PG_Widget *parent, const PG_Rect &rect, ContainerBase *container)
int maxLoadableWeight
the maximum total weight of all loaded units
VehicleWidget(PG_Widget *parent, const PG_Point &pos, int width, Vehicle *unit)
SDL_Surface * screen
Definition: graphics.cpp:31
void unitInfoDialog(const VehicleType *vt)
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
CancelMovement(PG_Widget &masterParent)
virtual void click(int x, int button)
void setLabelText(const ASCString &widgetName, const ASCString &text, PG_Widget *parent=NULL)
Definition: windowing.cpp:685
sigc::signal< void > damageChanged
void registerChilds(CargoDialog *cd)
virtual void registerSubwindow(CargoDialog *cd)
sigc::signal< void > sigDragAborted
Definition: cargowidget.h:128
static void pushIconHandler(GuiIconHandler *iconHandler)
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
void execute(const MapCoordinate &pos, ContainerBase *subject, int num)
Resources getOutput(int rate)
ASCString getASCTXTname()
virtual void update()=0
#define cwlargemissilen
Definition: vehicletype.h:71
ASCString name
a short name, for example B-52
const ServiceTargetSearcher::Targets & getDestinations()
bool available(CargoDialog *cd)
bool hasFunction(const ContainerBase *container)
ContainerBase * container()
virtual ASCString getASCTXTname()=0
vector< ConstructUnitCommand::ProductionEntry > Producables
int getMultiplier()
Definition: research.h:232
bool available(const MapCoordinate &pos, ContainerBase *subject, int num)
CargoDialog(PG_Widget *parent, ContainerBase *cb)
RepairUnit(CargoDialog &masterParent)
void infoMessage(const ASCString &string)
void execute(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
int addCurve(int color)
virtual ~SubWindow()
Definition: cargodialog.cpp:83
MapField * getField(int x, int y)
Definition: gamemap.h:465
virtual MapCoordinate3D getPosition() const =0
The MoveMalusType categorizes the different units (Vehicle) Originally, these types were only used to...
Definition: typen.h:361