2
This file is part of Advanced Strategic Command; http://www.asc-hq.de
3
Copyright (C) 1994-1999 Martin Bickel and Marc Schellenberger
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; see the file COPYING. If not, write to the
17
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
Boston, MA 02111-1307 USA
22
#include "jumpdrive.h"
23
#include "../gamemap.h"
24
#include "../vehicle.h"
26
#include "../viewcalculation.h"
27
#include "../replay.h"
28
#include "../soundList.h"
29
#include "../reactionfire.h"
31
bool JumpDrive::available( const Vehicle* subject )
34
if ( !subject->hasMoved() )
35
if ( subject->height & subject->typ->jumpDrive.height )
36
if ( subject->getResource( subject->typ->jumpDrive.consumption ) == subject->typ->jumpDrive.consumption )
42
bool JumpDrive::fieldReachable( const Vehicle* subject, const MapCoordinate& dest )
44
GameMap* gamemap = subject->getMap();
45
tfield* fld = gamemap->getField( dest );
46
if ( beeline( dest, subject->getPosition()) <= subject->typ->jumpDrive.maxDistance )
47
if ( !fld->vehicle && !fld->building )
48
if ( fieldvisiblenow( fld, subject->getOwner(), gamemap ))
49
if ( subject->typ->jumpDrive.targetterrain.accessible( fld->bdt ) > 0 )
56
bool JumpDrive::getFields( const Vehicle* subject )
58
if ( !available(subject ))
61
GameMap* gamemap = subject->getMap();
63
for ( int y = 0; y < gamemap->ysize; ++y )
64
for (int x = 0; x < gamemap->xsize; ++x ) {
65
MapCoordinate dest (x,y);
66
if ( fieldReachable( subject, dest)) {
67
fieldAvailable(gamemap,dest);
68
destinations[dest] = true;
73
return destinations.size() > 0;
76
bool JumpDrive::jump( Vehicle* subject, const MapCoordinate& destination, MapDisplayInterface* mapDisplay )
78
if ( !available(subject ))
81
if ( !fieldReachable( subject, destination ))
84
tfield* fld = subject->getMap()->getField(subject->getPosition() );
85
if ( fld->vehicle != subject )
89
subject->getResource( subject->typ->jumpDrive.consumption, false );
90
subject->removeview();
92
int networkID = subject->networkid;
93
GameMap* map = subject->getMap();
96
MapCoordinate3D dest3D (destination, subject->height );
98
tsearchreactionfireingunits srfu;
99
srfu.init( subject , dest3D );
101
SoundList::getInstance().playSound ( SoundList::jumpdrive, 0 );
104
srfu.checkfield( dest3D, subject, mapDisplay );
105
srfu.finalCheck( mapDisplay, subject->getOwner() );
108
subject = map->getUnit ( networkID );
111
subject->setnewposition ( destination.x, destination.y );
112
subject->setMovement(0, 1);
114
subject->getMap()->getField(destination)->vehicle = subject;
116
evaluateviewcalculation( map );
118
logtoreplayinfo( rpl_jump , networkID, destination.x, destination.y );