Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pg_mapdisplay.cpp

Go to the documentation of this file.
00001 
00006 /***************************************************************************
00007                           mapdisplay.cpp  -  description
00008                              -------------------
00009     begin                : Wed Jan 24 2001
00010     copyright            : (C) 2001 by Martin Bickel
00011     email                : bickel@asc-hq.org
00012  ***************************************************************************/
00013 
00014 /***************************************************************************
00015  *                                                                         *
00016  *   This program is free software; you can redistribute it and/or modify  *
00017  *   it under the terms of the GNU General Public License as published by  *
00018  *   the Free Software Foundation; either version 2 of the License, or     *
00019  *   (at your option) any later version.                                   *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 // #define debugmapdisplay
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 
00042 extern bool tempsvisible;
00043 extern MapDisplayPG* theGlobalMapDisplay;
00044 
00045 
00046 #ifdef debugmapdisplay
00047 #include <iostream>
00048 #endif
00049 
00050 
00051 class PG_MapDisplay : public MapDisplayInterface {
00052            MapDisplayPG* mapDisplayWidget;
00053          public:
00054            PG_MapDisplay( MapDisplayPG* mapDisplayWidget_ ) : mapDisplayWidget( mapDisplayWidget_ ) {};
00055 
00056            int displayMovingUnit ( const MapCoordinate3D& start, const MapCoordinate3D& dest, Vehicle* vehicle, int fieldnum, int totalmove, SoundStartCallback soundStart );
00057            void deleteVehicle ( Vehicle* vehicle ) {};
00058            void displayMap ( void );
00059            void displayMap ( Vehicle* vehicle );
00060            void displayPosition ( int x, int y );
00061            void resetMovement ( void ) {};
00062            void startAction ( void );
00063            void stopAction ( void );
00064            void cursor_goto ( const MapCoordinate& pos );
00065            void displayActionCursor ( int x1, int y1, int x2, int y2 ) {};
00066            void removeActionCursor ( void ) {
00067               mapDisplayWidget->cursor.invisible = 1;
00068            };
00069            void updateDashboard ();
00070            void repaintDisplay ();
00071            void setTempView( bool view ) { tempsvisible = view; };
00072            void showBattle( tfight& battle );
00073            void playPositionalSound( const MapCoordinate& pos, Sound* snd );
00074 };
00075 
00076 
00077 
00078 int  PG_MapDisplay :: displayMovingUnit ( const MapCoordinate3D& start, const MapCoordinate3D& dest, Vehicle* vehicle, int fieldnum, int totalmove, SoundStartCallback soundStart )
00079 {
00080    if ( actmap->getPlayerView() == -2 )
00081       return 0;
00082 
00083    MapCoordinate3D newstart = start;
00084    MapCoordinate3D newdest = dest;
00085    
00086    if ( newdest.getNumericalHeight() == -1 )
00087       newdest.setNumericalHeight( newstart.getNumericalHeight() );
00088    else
00089       if ( newstart.getNumericalHeight() == -1 )
00090          newstart.setNumericalHeight( newdest.getNumericalHeight() );
00091 
00092    if ( newstart.getNumericalHeight() < newdest.getNumericalHeight() ) {
00093       if ( fieldnum+1 < totalmove )
00094          newdest.setNumericalHeight( newstart.getNumericalHeight() );
00095    }
00096    
00097    if ( newstart.getNumericalHeight() > newdest.getNumericalHeight() ) {
00098       if ( fieldnum > 0  )
00099          newstart.setNumericalHeight( newdest.getNumericalHeight() );
00100    }
00101    
00102    tfield* fld1 = actmap->getField ( start );
00103    int view1 = fieldVisibility ( fld1, actmap->getPlayerView(), actmap );
00104 
00105    tfield* fld2 = actmap->getField ( dest );
00106    int view2 = fieldVisibility ( fld2, actmap->getPlayerView(), actmap );
00107 
00108    bool shareView;
00109    if ( actmap->getPlayerView() >= 0)
00110       shareView = actmap->player[actmap->getPlayerView()].diplomacy.sharesView( vehicle->getOwner() );
00111    else
00112       shareView = false;
00113 
00114    if (  (view1 >= visible_now  ||  view2 >= visible_now ) || ( vehicle->getOwner() == actmap->getPlayerView() ) || shareView || actmap->getPlayerView() == -1 )
00115       if ( ((vehicle->height >= chschwimmend) && (vehicle->height <= chhochfliegend)) || (( view1 == visible_all) || ( view2 == visible_all )) || ( actmap->actplayer == actmap->getPlayerView() ) || shareView || actmap->getPlayerView() == -1 ) {
00116          soundStart( 1 );
00117          mapDisplayWidget->displayUnitMovement( actmap, vehicle, newstart, newdest );
00118       }
00119 
00120 
00121    int result = 0;
00122    if (view1 >= visible_now )
00123       result +=1;
00124 
00125    if ( view2 >= visible_now )
00126       result +=2;
00127 
00128    return result;
00129 }
00130 
00131 void PG_MapDisplay :: showBattle( tfight& battle )
00132 {
00133    showAttackAnimation( battle, actmap );
00134 }
00135 
00136 
00137 void PG_MapDisplay :: displayMap ( void )
00138 {
00139    ::repaintMap();
00140 }
00141 
00142 void PG_MapDisplay :: cursor_goto ( const MapCoordinate& pos )
00143 {
00144    mapDisplayWidget->cursor.goTo( pos );
00145 }
00146 
00147 
00148 void PG_MapDisplay :: displayMap ( Vehicle* vehicle )
00149 {
00150    mapDisplayWidget->registerAdditionalUnit( vehicle ); 
00151    ::repaintMap();
00152    mapDisplayWidget->registerAdditionalUnit( NULL ); 
00153 }
00154 
00155 
00156 void PG_MapDisplay :: displayPosition ( int x, int y )
00157 {
00158    if ( !mapDisplayWidget->fieldInView( MapCoordinate(x,y) ))
00159       mapDisplayWidget->centerOnField( MapCoordinate(x,y) );
00160    else
00161       mapDisplayWidget->Update();
00162 }
00163 
00164 
00165 void PG_MapDisplay :: startAction ( void )
00166 {
00167 }
00168 
00169 void PG_MapDisplay :: stopAction ( void )
00170 {
00171 }
00172 
00173 void PG_MapDisplay :: updateDashboard ( void )
00174 {
00175    updateFieldInfo();
00176 }
00177 
00178 void PG_MapDisplay :: repaintDisplay ()
00179 {
00180    ::repaintDisplay();
00181 }
00182 
00183 void PG_MapDisplay :: playPositionalSound( const MapCoordinate& pos, Sound* snd )
00184 {
00185    snd->play();
00186 }
00187     
00188 
00189 MapDisplayInterface& getDefaultMapDisplay()
00190 {
00191    static PG_MapDisplay* mapDisplay = NULL;
00192    if ( !mapDisplay ) {
00193       assert( theGlobalMapDisplay );
00194       mapDisplay = new PG_MapDisplay( theGlobalMapDisplay );
00195    }   
00196    return *mapDisplay;
00197 }
00198 

Generated on Tue Jun 24 01:27:47 2008 for Advanced Strategic Command by  doxygen 1.4.2