Advanced Strategic Command
putobjectcommand.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 PutObjectCommandH
23 #define PutObjectCommandH
24 
25 #include "unitcommand.h"
26 
27 #include "../typen.h"
28 #include "../objects.h"
29 #include "../mapfield.h"
30 
31 
32 class PutObjectCommand : public UnitCommand {
33 
34  public:
35  static bool avail ( Vehicle* eht );
36  private:
37  enum Mode { Build, Remove };
38 
39  MapCoordinate target;
40  int object;
41  Mode mode;
42 
43  void fieldChecker( const MapCoordinate& pos );
44 
45  map<MapCoordinate,set<int> > objectsCreatable;
46  map<MapCoordinate,set<int> > objectsRemovable;
47 
48  bool checkObject( MapField* fld, ObjectType* objtype, Mode mode );
49 
50 
51  PutObjectCommand( GameMap* map ) : UnitCommand( map ) {};
52  template<class Child> friend GameAction* GameActionCreator( GameMap* map);
53 
54  protected:
55  void readData ( tnstream& stream );
56  void writeData ( tnstream& stream ) const;
57 
58  GameActionID getID() const;
59  ASCString getDescription() const;
60 
61  public:
62  PutObjectCommand ( Vehicle* unit );
64 
65  Vehicle* getAttacker() { return getUnit(); };
66 
67  void setTarget( const MapCoordinate& target, int objectID );
68  ActionResult go ( const Context& context );
70 
71  const set<int>& getCreatableObjects( const MapCoordinate& pos );
72  const set<int>& getRemovableObjects( const MapCoordinate& pos );
73 
74  vector<MapCoordinate> getFields();
75 };
76 
77 #endif
78 
const set< int > & getRemovableObjects(const MapCoordinate &pos)
int GameActionID
Definition: action.h:35
GameActionID getID() const
The interface for all kinds of IO stream.
a single field of the map
Definition: mapfield.h:26
UnitCommand(GameMap *map)
Definition: unitcommand.cpp:44
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void setTarget(const MapCoordinate &target, int objectID)
void writeData(tnstream &stream) const
const set< int > & getCreatableObjects(const MapCoordinate &pos)
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
Coordinate on the twodimensional map.
Definition: typen.h:202
friend GameAction * GameActionCreator(GameMap *map)
Definition: action.h:114
vector< MapCoordinate > getFields()
static bool avail(Vehicle *eht)
ASCString getDescription() const
ASCString getCommandString() const
ActionResult go(const Context &context)
A GameAction is an modification of something on a map.
Definition: action.h:45
Vehicle * getAttacker()
void readData(tnstream &stream)
ActionResult searchFields()
const Vehicle * getUnit() const
Definition: unitcommand.cpp:26
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182