00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "jumpdrive.h"
00023 #include "../gamemap.h"
00024 #include "../vehicle.h"
00025 #include "../spfst.h"
00026 #include "../viewcalculation.h"
00027 #include "../replay.h"
00028 #include "../soundList.h"
00029 #include "../reactionfire.h"
00030
00031 bool JumpDrive::available( const Vehicle* subject )
00032 {
00033 if ( subject )
00034 if ( !subject->hasMoved() )
00035 if ( subject->height & subject->typ->jumpDrive.height )
00036 if ( subject->getResource( subject->typ->jumpDrive.consumption ) == subject->typ->jumpDrive.consumption )
00037 return true;
00038
00039 return false;
00040 };
00041
00042 bool JumpDrive::fieldReachable( const Vehicle* subject, const MapCoordinate& dest )
00043 {
00044 GameMap* gamemap = subject->getMap();
00045 tfield* fld = gamemap->getField( dest );
00046 if ( beeline( dest, subject->getPosition()) <= subject->typ->jumpDrive.maxDistance )
00047 if ( !fld->vehicle && !fld->building )
00048 if ( fieldvisiblenow( fld, subject->getOwner(), gamemap ))
00049 if ( subject->typ->jumpDrive.targetterrain.accessible( fld->bdt ) > 0 )
00050 return true;
00051
00052 return false;
00053 }
00054
00055
00056 bool JumpDrive::getFields( const Vehicle* subject )
00057 {
00058 if ( !available(subject ))
00059 return false;
00060
00061 GameMap* gamemap = subject->getMap();
00062
00063 for ( int y = 0; y < gamemap->ysize; ++y )
00064 for (int x = 0; x < gamemap->xsize; ++x ) {
00065 MapCoordinate dest (x,y);
00066 if ( fieldReachable( subject, dest)) {
00067 fieldAvailable(gamemap,dest);
00068 destinations[dest] = true;
00069 }
00070 }
00071
00072
00073 return destinations.size() > 0;
00074 }
00075
00076 bool JumpDrive::jump( Vehicle* subject, const MapCoordinate& destination, MapDisplayInterface* mapDisplay )
00077 {
00078 if ( !available(subject ))
00079 return false;
00080
00081 if ( !fieldReachable( subject, destination ))
00082 return false;
00083
00084 tfield* fld = subject->getMap()->getField(subject->getPosition() );
00085 if ( fld->vehicle != subject )
00086 return false;
00087
00088 fld->vehicle = NULL;
00089 subject->getResource( subject->typ->jumpDrive.consumption, false );
00090 subject->removeview();
00091
00092 int networkID = subject->networkid;
00093 GameMap* map = subject->getMap();
00094
00095
00096 MapCoordinate3D dest3D (destination, subject->height );
00097
00098 tsearchreactionfireingunits srfu;
00099 srfu.init( subject , dest3D );
00100
00101 SoundList::getInstance().playSound ( SoundList::jumpdrive, 0 );
00102
00103
00104 srfu.checkfield( dest3D, subject, mapDisplay );
00105 srfu.finalCheck( mapDisplay, subject->getOwner() );
00106
00107
00108 subject = map->getUnit ( networkID );
00109
00110 if ( subject ) {
00111 subject->setnewposition ( destination.x, destination.y );
00112 subject->setMovement(0, 1);
00113 subject->addview();
00114 subject->getMap()->getField(destination)->vehicle = subject;
00115 }
00116 evaluateviewcalculation( map );
00117
00118 logtoreplayinfo( rpl_jump , networkID, destination.x, destination.y );
00119
00120 return true;
00121 }
00122