~ubuntu-branches/ubuntu/maverick/asc/maverick

« back to all changes in this revision

Viewing changes to source/actions/jumpdrive.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Eddy Petrișor, Gonéri Le Bouder, Cyril Brulebois, Barry deFreese
  • Date: 2008-01-08 19:54:18 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080108195418-n19fc4eobhhqxcy5
Tags: 2.0.1.0-1
[ Eddy Petrișor ]
* fixed Homepage semifield

[ Gonéri Le Bouder ]
* add a watchfile
* move homepage from the description to the new Homepage field

[ Cyril Brulebois ]
* Added Vcs-Svn and Vcs-Browser fields in the control file.

[ Barry deFreese ]
* Fix make-clean lintian warning
* New upstream release
* Bump debhelper build-dep to match compat
* Add desktop file
* Update watch file for new upstream naming
* Remove nostrip check from rules
* Bump Standards Version to 3.7.3
* Add myself to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
     This file is part of Advanced Strategic Command; http://www.asc-hq.de
 
3
     Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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
 
19
*/
 
20
 
 
21
 
 
22
#include "jumpdrive.h"
 
23
#include "../gamemap.h"
 
24
#include "../vehicle.h"
 
25
#include "../spfst.h"
 
26
#include "../viewcalculation.h"
 
27
#include "../replay.h"
 
28
#include "../soundList.h"
 
29
#include "../reactionfire.h"
 
30
 
 
31
bool JumpDrive::available( const Vehicle* subject )
 
32
{
 
33
   if ( 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 ) 
 
37
               return true;
 
38
 
 
39
   return false;
 
40
};
 
41
 
 
42
bool JumpDrive::fieldReachable( const Vehicle* subject, const MapCoordinate& dest )
 
43
{
 
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 ) 
 
50
               return true;
 
51
   
 
52
   return false;
 
53
}
 
54
 
 
55
 
 
56
bool JumpDrive::getFields( const Vehicle* subject )
 
57
{
 
58
   if ( !available(subject ))
 
59
      return false;
 
60
     
 
61
   GameMap* gamemap = subject->getMap();
 
62
    
 
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;
 
69
         }
 
70
      }
 
71
      
 
72
      
 
73
   return destinations.size() > 0;
 
74
}
 
75
 
 
76
bool JumpDrive::jump( Vehicle* subject, const MapCoordinate& destination, MapDisplayInterface* mapDisplay )
 
77
{
 
78
   if ( !available(subject ))
 
79
      return false;
 
80
      
 
81
   if ( !fieldReachable( subject, destination ))
 
82
      return false;
 
83
   
 
84
   tfield* fld = subject->getMap()->getField(subject->getPosition() ); 
 
85
   if ( fld->vehicle != subject )
 
86
      return false;
 
87
   
 
88
   fld->vehicle = NULL;
 
89
   subject->getResource( subject->typ->jumpDrive.consumption, false );
 
90
   subject->removeview();
 
91
 
 
92
   int networkID = subject->networkid;
 
93
   GameMap* map  = subject->getMap();
 
94
 
 
95
 
 
96
   MapCoordinate3D dest3D (destination, subject->height );
 
97
 
 
98
   tsearchreactionfireingunits srfu;
 
99
   srfu.init( subject , dest3D );
 
100
 
 
101
   SoundList::getInstance().playSound ( SoundList::jumpdrive, 0 );
 
102
 
 
103
 
 
104
   srfu.checkfield( dest3D, subject, mapDisplay );
 
105
   srfu.finalCheck( mapDisplay, subject->getOwner() );
 
106
 
 
107
 
 
108
   subject = map->getUnit ( networkID );
 
109
 
 
110
   if ( subject ) {
 
111
      subject->setnewposition ( destination.x, destination.y );
 
112
      subject->setMovement(0, 1);
 
113
      subject->addview();
 
114
      subject->getMap()->getField(destination)->vehicle = subject;
 
115
   }
 
116
   evaluateviewcalculation( map );
 
117
   
 
118
   logtoreplayinfo( rpl_jump , networkID, destination.x, destination.y );
 
119
   
 
120
   return true;
 
121
}
 
122