00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <cmath>
00027 #include <limits>
00028
00029 #include "pgeventsupplier.h"
00030
00031 #include "global.h"
00032 #include "typen.h"
00033 #include "mapdisplay.h"
00034 #include "vehicletype.h"
00035 #include "buildingtype.h"
00036 #include "spfst.h"
00037 #include "dialog.h"
00038 #include "mainscreenwidget.h"
00039 #include "sdl/sound.h"
00040 #include "dialogs/attackpanel.h"
00041 #include "spfst-legacy.h"
00042 #include "gameoptions.h"
00043
00044 extern bool tempsvisible;
00045 extern MapDisplayPG* theGlobalMapDisplay;
00046
00047
00048 #ifdef debugmapdisplay
00049 #include <iostream>
00050 #endif
00051
00052
00053 class PG_MapDisplay : public MapDisplayInterface {
00054 MapDisplayPG* mapDisplayWidget;
00055 public:
00056 PG_MapDisplay( MapDisplayPG* mapDisplayWidget_ ) : mapDisplayWidget( mapDisplayWidget_ ) {};
00057
00058 int displayMovingUnit ( const MapCoordinate3D& start, const MapCoordinate3D& dest, Vehicle* vehicle, int fieldnum, int totalmove, SoundStartCallback soundStart, int duration );
00059 void deleteVehicle ( Vehicle* vehicle ) {};
00060 void displayMap ( void );
00061 void displayMap ( Vehicle* vehicle );
00062 void displayPosition ( int x, int y );
00063 void resetMovement ( void ) {};
00064 void startAction ( void );
00065 void stopAction ( void );
00066 void cursor_goto ( const MapCoordinate& pos );
00067 void displayActionCursor ( int x1, int y1, int x2, int y2 ) {};
00068 void removeActionCursor ( void ) {
00069 mapDisplayWidget->cursor.invisible = 1;
00070 };
00071 void updateDashboard ();
00072 void repaintDisplay ();
00073 void setTempView( bool view ) { tempsvisible = view; };
00074 void showBattle( tfight& battle );
00075 void playPositionalSound( const MapCoordinate& pos, Sound* snd );
00076 int getUnitMovementDuration() const { return CGameOptions::Instance()->movespeed; };
00077 };
00078
00079
00080
00081 int PG_MapDisplay :: displayMovingUnit ( const MapCoordinate3D& start, const MapCoordinate3D& dest, Vehicle* vehicle, int fieldnum, int totalmove, SoundStartCallback soundStart, int duration )
00082 {
00083 if ( actmap->getPlayerView() == -2 )
00084 return 0;
00085
00086 MapCoordinate3D newstart = start;
00087 MapCoordinate3D newdest = dest;
00088
00089 if ( newdest.getNumericalHeight() == -1 )
00090 newdest.setNumericalHeight( newstart.getNumericalHeight() );
00091 else
00092 if ( newstart.getNumericalHeight() == -1 )
00093 newstart.setNumericalHeight( newdest.getNumericalHeight() );
00094
00095 if ( newstart.getNumericalHeight() < newdest.getNumericalHeight() ) {
00096 if ( fieldnum+1 < totalmove )
00097 newdest.setNumericalHeight( newstart.getNumericalHeight() );
00098 }
00099
00100 if ( newstart.getNumericalHeight() > newdest.getNumericalHeight() ) {
00101 if ( fieldnum > 0 )
00102 newstart.setNumericalHeight( newdest.getNumericalHeight() );
00103 }
00104
00105 MapField* fld1 = actmap->getField ( start );
00106 int view1 = fieldVisibility ( fld1, actmap->getPlayerView() );
00107
00108 MapField* fld2 = actmap->getField ( dest );
00109 int view2 = fieldVisibility ( fld2, actmap->getPlayerView() );
00110
00111 bool shareView;
00112 if ( actmap->getPlayerView() >= 0)
00113 shareView = actmap->player[actmap->getPlayerView()].diplomacy.sharesView( vehicle->getOwner() );
00114 else
00115 shareView = false;
00116
00117 if ( (view1 >= visible_now || view2 >= visible_now ) || ( vehicle->getOwner() == actmap->getPlayerView() ) || shareView || actmap->getPlayerView() == -1 )
00118 if ( ((vehicle->height >= chschwimmend) && (vehicle->height <= chhochfliegend)) || (( view1 == visible_all) || ( view2 == visible_all )) || ( actmap->actplayer == actmap->getPlayerView() ) || shareView || actmap->getPlayerView() == -1 ) {
00119 soundStart( 1 );
00120 mapDisplayWidget->displayUnitMovement( actmap, vehicle, newstart, newdest, duration );
00121 }
00122
00123
00124 int result = 0;
00125 if (view1 >= visible_now )
00126 result +=1;
00127
00128 if ( view2 >= visible_now )
00129 result +=2;
00130
00131 return result;
00132 }
00133
00134 void PG_MapDisplay :: showBattle( tfight& battle )
00135 {
00136 showAttackAnimation( battle, actmap );
00137 }
00138
00139
00140 void PG_MapDisplay :: displayMap ( void )
00141 {
00142 ::repaintMap();
00143 }
00144
00145 void PG_MapDisplay :: cursor_goto ( const MapCoordinate& pos )
00146 {
00147 mapDisplayWidget->cursor.goTo( pos );
00148 }
00149
00150
00151 void PG_MapDisplay :: displayMap ( Vehicle* vehicle )
00152 {
00153 mapDisplayWidget->registerAdditionalUnit( vehicle );
00154 ::repaintMap();
00155 mapDisplayWidget->registerAdditionalUnit( NULL );
00156 }
00157
00158
00159 void PG_MapDisplay :: displayPosition ( int x, int y )
00160 {
00161 if ( !mapDisplayWidget->fieldInView( MapCoordinate(x,y) ))
00162 mapDisplayWidget->centerOnField( MapCoordinate(x,y) );
00163 else
00164 mapDisplayWidget->Update();
00165 }
00166
00167
00168 void PG_MapDisplay :: startAction ( void )
00169 {
00170 }
00171
00172 void PG_MapDisplay :: stopAction ( void )
00173 {
00174 }
00175
00176 void PG_MapDisplay :: updateDashboard ( void )
00177 {
00178 updateFieldInfo();
00179 }
00180
00181 void PG_MapDisplay :: repaintDisplay ()
00182 {
00183 ::repaintDisplay();
00184 }
00185
00186 void PG_MapDisplay :: playPositionalSound( const MapCoordinate& pos, Sound* snd )
00187 {
00188 snd->play();
00189 }
00190
00191
00192 MapDisplayInterface& getDefaultMapDisplay()
00193 {
00194 static PG_MapDisplay* mapDisplay = NULL;
00195 if ( !mapDisplay ) {
00196 assert( theGlobalMapDisplay );
00197 mapDisplay = new PG_MapDisplay( theGlobalMapDisplay );
00198 }
00199 return *mapDisplay;
00200 }
00201