Advanced Strategic Command
moveunitcommand.h
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 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 #ifndef MoveUnitCommandH
23 #define MoveUnitCommandH
24 
25 #include <set>
26 #include <sigc++/sigc++.h>
27 
28 #include "unitcommand.h"
29 #include "taskinterface.h"
30 
31 #include "../typen.h"
32 #include "../attack.h"
33 #include "../astar2.h"
34 
35 
36 class MoveUnitCommand : public UnitCommand, public TaskInterface, public sigc::trackable {
37 
38  public:
39  static bool avail ( Vehicle* eht );
40  static bool ascendAvail ( Vehicle* eht );
41  static bool descendAvail ( Vehicle* eht );
42  typedef map<MapCoordinate,AttackWeap > FieldList;
43 
44  private:
45  MapCoordinate3D destination;
46 
47  void fieldChecker( const MapCoordinate& pos );
48 
49  set<MapCoordinate3D> reachableFields;
50  set<MapCoordinate3D> reachableFieldsIndirect;
51 
52  AStar3D::Path path;
53 
54  int flags;
55  int verticalDirection;
56  bool multiTurnMovement;
58 
59  MoveUnitCommand( GameMap* map );
60  template<class Child> friend GameAction* GameActionCreator( GameMap* map);
61 
62  void changeCoordinates( const MapCoodinateVector& delta );
63 
64  protected:
65  void readData ( tnstream& stream );
66  void writeData ( tnstream& stream ) const;
67 
68  GameActionID getID() const;
69  ASCString getDescription() const;
70 
71  ActionResult go ( const Context& context );
72 
73  public:
74  MoveUnitCommand ( Vehicle* unit );
75 
80  };
81 
82  void setFlags( int flags ) { this->flags = flags; };
83 
84  ActionResult searchFields(int height = -1, int capabilities = 0);
85 
87  void setVerticalDirection( int dir );
88 
89  int getVerticalDirection() const { return verticalDirection; };
90 
91  void calcPath();
92  void calcPath( AStar3D* const astar );
93  const AStar3D::Path& getPath();
94 
95  void setDestination( const MapCoordinate& destination );
96  void setDestination( const MapCoordinate3D& destination );
98 
109  bool isFieldReachable( const MapCoordinate& pos, bool direct );
110 
111 
117  const set<MapCoordinate3D>& getReachableFields() { return reachableFields; };
118  const set<MapCoordinate3D>& getReachableFieldsIndirect() { return reachableFieldsIndirect; };
119 
120  const Vehicle* getUnit() const { return UnitCommand::getUnit(); };
122 
123  bool longDistAvailable( const MapCoordinate& pos );
124 
125  virtual vector<MapCoordinate> getCoordinates() const;
126 
127  int getCompletion();
128  bool operatable();
129  void rearm();
130 
132 };
133 
134 #endif
135 
Definition: ndir.h:39
const AStar3D::Path & getPath()
int GameActionID
Definition: action.h:35
void readData(tnstream &stream)
Vehicle * getUnit()
the unit will not interrupt the movement if it runs onto a mine of into reaction fire ...
virtual vector< MapCoordinate > getCoordinates() const
this is for informational purposes, so the player can see where a Command has taken place when review...
void setFlags(int flags)
we want only results on a certain level of height
The interface for all kinds of IO stream.
const set< MapCoordinate3D > & getReachableFieldsIndirect()
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ASCString getDescription() const
bool longDistAvailable(const MapCoordinate &pos)
static bool descendAvail(Vehicle *eht)
Coordinate on the twodimensional map.
Definition: typen.h:202
represents a change of a MapCoordinate
Definition: typen.h:189
ASCString getCommandString() const
static bool avail(Vehicle *eht)
void writeData(tnstream &stream) const
const Vehicle * getUnit() const
GameActionID getID() const
static bool ascendAvail(Vehicle *eht)
void setVerticalDirection(int dir)
defines whether we want to end up either at the same level of height (0), lower(<0), or heigher(>0)
void setDestination(const MapCoordinate &destination)
ActionResult searchFields(int height=-1, int capabilities=0)
deque< PathPoint > Path
Definition: astar2.h:48
map< MapCoordinate, AttackWeap > FieldList
Coordinate on the map including height.
Definition: typen.h:238
A 3D path finding algorithm, based on the 2D algorithm by Amit J. Patel.
Definition: astar2.h:19
the unit will not change its height even if that would provide a shortcut
friend GameAction * GameActionCreator(GameMap *map)
Definition: action.h:114
int getVerticalDirection() const
A GameAction is an modification of something on a map.
Definition: action.h:45
const set< MapCoordinate3D > & getReachableFields()
this will return a 2D representation of the reachable fields.
bool isFieldReachable(const MapCoordinate &pos, bool direct)
checks if the field can be reached by the unit this turn Precondition: searchFields(int,int) was called
const Vehicle * getUnit() const
Definition: unitcommand.cpp:26
ActionResult go(const Context &context)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
bool operatable()
checks if the task can still be operated.