replaymapdisplay.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  ***************************************************************************/
00009 
00010 
00011 #include "replaymapdisplay.h"
00012 #include "spfst.h"
00013 #include "viewcalculation.h"
00014 #include "events.h"
00015 #include "gameoptions.h"
00016 #include "spfst-legacy.h"
00017 
00018 int ReplayMapDisplay :: checkMapPosition ( int x, int y )
00019 {
00020    mapDisplay->displayPosition(x,y);
00021    /*
00022 
00023    if ( x >= actmap->xsize )
00024       x = actmap->xsize - 1;
00025    if ( y >= actmap->ysize )
00026       y = actmap->ysize - 1;
00027 
00028    int a = actmap->xpos;
00029    int b = actmap->ypos;
00030    int xss = idisplaymap.getscreenxsize();
00031    int yss = idisplaymap.getscreenysize();
00032 
00033    if ((x < a) || (x >= a + xss )) {
00034       if (x >= xss / 2)
00035          actmap->xpos = (x - xss / 2);
00036       else
00037          actmap->xpos = 0;
00038 
00039    }
00040 
00041    if (y < b   ||   y >= b + yss  ) {
00042       if (y >= yss / 2)
00043          actmap->ypos = (y - yss / 2);
00044       else
00045          actmap->ypos = 0;
00046       if ( actmap->ypos & 1 )
00047          actmap->ypos--;
00048 
00049    }
00050 
00051    if (actmap->xpos + xss > actmap->xsize)
00052       actmap->xpos = actmap->xsize - xss ;
00053    if (actmap->ypos + yss  > actmap->ysize)
00054       actmap->ypos = actmap->ysize - yss ;
00055 
00056    if ((actmap->xpos != a) || (actmap->ypos != b))
00057       return 1;
00058    else
00059       return 0;
00060       */
00061       return 0;
00062 }
00063 
00064 
00065 int ReplayMapDisplay :: displayMovingUnit ( const MapCoordinate3D& start, const MapCoordinate3D& dest, Vehicle* vehicle, int fieldnum, int totalmove, SoundStartCallback startSound, int duration )
00066 {
00067    if ( actmap->getPlayerView() < 0 )
00068       return 0;
00069 
00070    
00071    bool view1 = fieldvisiblenow ( getfield ( start.x, start.y ), actmap->getPlayerView() );
00072    
00073    int view2;
00074    MapField* fld2 = actmap->getField ( dest );
00075    
00076    if ( actmap->player[actmap->getPlayerView()].diplomacy.sharesView( vehicle->getOwner() )) 
00077       view2 = fieldVisibility ( fld2, actmap->getPlayerView() );
00078    else {
00079       // This is a workaround to estimate if the target field will be visible or not once the units is there 
00080       view2 = calcvisibilityfield ( actmap, fld2, actmap->getPlayerView(), -1, actmap->getgameparameter ( cgp_initialMapVisibility ), vehicle->typ->jamming );
00081    }
00082 
00083    /*
00084    if ( vehicle->height >= chschwimmend && vehicle->height <= chhochfliegend ) {
00085       visibility = fieldvisiblenow ( getfield ( start.x, start.y ), actmap->playerView) || fieldvisiblenow ( getfield ( dest.x, dest.y ), actmap->playerView);
00086    } else {
00087       // visibility = (fieldVisibility ( getfield ( start.x, start.y ), actmap->playerView) >= visible_all) && (fieldVisibility ( getfield ( dest.x, dest.y ), actmap->playerView) >= visible_now);
00088       visibility = fieldvisiblenow ( getfield ( start.x, start.y ), actmap->playerView) || fieldvisiblenow ( getfield ( dest.x, dest.y ), actmap->playerView);
00089    }
00090    */
00091    
00092    if ( view1 || (view2 >= visible_now ) ) {
00093       if ( checkMapPosition  ( start.x, start.y ))
00094          displayMap();
00095 
00096       int fc = mapDisplay->displayMovingUnit ( start, dest, vehicle, fieldnum, totalmove, startSound, duration );
00097       if ( fc == 1 ) {
00098          mapDisplay->resetMovement();
00099          mapDisplay->displayMap();
00100       }
00101 
00102       return fc;
00103    } else
00104       return 0;
00105 }
00106 
00107 void ReplayMapDisplay :: displayPosition ( int x, int y )
00108 {
00109    if ( fieldvisiblenow ( getfield ( x, y ), actmap->getPlayerView() )) {
00110       checkMapPosition  ( x, y );
00111       mapDisplay->displayPosition ( x, y );
00112    }
00113 }
00114 
00115 void ReplayMapDisplay :: removeActionCursor ( void )
00116 {
00117    mapDisplay->removeActionCursor();
00118  
00119 }
00120 
00121 void ReplayMapDisplay :: displayActionCursor ( int x1, int y1, int x2, int y2, int secondWait )
00122 {
00123    if ( x1 >= 0 && y1 >= 0 ) {
00124       int i = fieldvisiblenow ( getfield ( x1, y1 ), actmap->getPlayerView() );
00125       if( i ) {
00126          cursor_goto( MapCoordinate( x1, y1 ));
00127          
00128          if ( x2 >= 0 && y2 >= 0 )
00129             wait( 30 );
00130          else
00131             wait();
00132       }
00133    }
00134 
00135    if ( x2 >= 0 && y2 >= 0 ) {
00136       int i = fieldvisiblenow ( getfield ( x2, y2 ), actmap->getPlayerView() );
00137       if( i ) {
00138          cursor_goto( MapCoordinate( x2, y2 ));
00139          if ( secondWait )
00140             wait();
00141       }
00142    }
00143 }
00144 
00145 void ReplayMapDisplay :: wait ( int minTime )
00146 {
00147    int t = ticker;
00148    while ( ticker < t + max ( cursorDelay, minTime ) )
00149       releasetimeslice();
00150 }
00151 
00152 void ReplayMapDisplay :: playPositionalSound( const MapCoordinate& pos, Sound* snd )
00153 {
00154    if ( fieldvisiblenow ( actmap->getField ( pos ), actmap->getPlayerView() )) {
00155       mapDisplay->playPositionalSound( pos, snd );
00156    }
00157 }
00158 
00159 
00160 int ReplayMapDisplay :: getUnitMovementDuration() const 
00161 { 
00162    int speed = CGameOptions::Instance()->movespeed;
00163    int factor = max( 10, CGameOptions::Instance()->replayMoveSpeedFactor );
00164    return speed * 100 / factor;
00165 }
00166 

Generated on Mon May 21 01:26:36 2012 for Advanced Strategic Command by  doxygen 1.5.1