Advanced Strategic Command
constructunitcommand.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 ConstructUnitCommandH
23 #define ConstructUnitCommandH
24 
25 #include "containercommand.h"
26 
27 #include "../typen.h"
28 #include "../objects.h"
29 #include "../mapfield.h"
30 
31 
33 
34  public:
35  static bool externalConstructionAvail( const ContainerBase* eht );
36  static bool internalConstructionAvail( const ContainerBase* eht );
37  static bool avail ( const ContainerBase* eht );
38  enum Mode { undefined, internal, external } ;
39  private:
40  Mode mode;
41  MapCoordinate target;
42  int vehicleTypeID;
43  int newUnitID;
44 
45  void fieldChecker( const MapCoordinate& pos );
46 
47  map<MapCoordinate,vector<int> > unitsConstructable;
48 
49  ConstructUnitCommand( GameMap* map ) : ContainerCommand( map ), mode( undefined ) {};
50  template<class Child> friend GameAction* GameActionCreator( GameMap* map);
51 
52  protected:
53  void readData ( tnstream& stream );
54  void writeData ( tnstream& stream ) const;
55 
56  GameActionID getID() const;
57  ASCString getDescription() const;
58 
59  public:
61 
62  void setMode( Mode mode );
63  ActionResult go ( const Context& context );
65 
66 
67  class Lack {
68  int value;
69  public:
70  Lack() : value(0) {};
71  Lack( int value ) { this->value = value; };
72  enum Prerequisites { Energy = 1, Material = 2, Fuel = 4, Research = 8 , Unloadability = 0x10, Movement = 0x20 };
73  bool ok() const { return value == 0 ; };
74  int getValue() const { return value; };
75  };
76 
78  public:
79  const VehicleType* type;
82  ProductionEntry() : type(NULL) {};
84  this->type = type;
85  this->cost = cost;
86  this->prerequisites = prerequisites;
87  }
88  };
89 
90  typedef vector<ConstructUnitCommand::ProductionEntry> Producables;
91 
92  Lack unitProductionPrerequisites( const VehicleType* type ) const;
93 
94  void setVehicleType( const VehicleType* type );
95 
101 
102  vector<MapCoordinate> getFields();
103  bool isFieldUsable( const MapCoordinate& pos );
104 
106 
107  void setTargetPosition( const MapCoordinate& pos );
108 };
109 
110 #endif
111 
Lack unitProductionPrerequisites(const VehicleType *type) const
void writeData(tnstream &stream) const
int GameActionID
Definition: action.h:35
void setVehicleType(const VehicleType *type)
ASCString getDescription() const
bool isFieldUsable(const MapCoordinate &pos)
GameActionID getID() const
The interface for all kinds of IO stream.
void readData(tnstream &stream)
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ConstructUnitCommand::Lack prerequisites
Producables getProduceableVehicles()
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
const VehicleType * type
static bool internalConstructionAvail(const ContainerBase *eht)
ProductionEntry()
void setTargetPosition(const MapCoordinate &pos)
Coordinate on the twodimensional map.
Definition: typen.h:202
vector< MapCoordinate > getFields()
Resources cost
ASCString getCommandString() const
static bool externalConstructionAvail(const ContainerBase *eht)
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
A GameAction is an modification of something on a map.
Definition: action.h:45
Resources are basically the currency of ASC.
Definition: typen.h:97
friend GameAction * GameActionCreator(GameMap *map)
Definition: action.h:114
static bool avail(const ContainerBase *eht)
ActionResult go(const Context &context)
ProductionEntry(const VehicleType *type, const Resources &cost, ConstructUnitCommand::Lack prerequisites)
vector< ConstructUnitCommand::ProductionEntry > Producables
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182