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

jumpdrive.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
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 

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