00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ConstructUnitCommandH
00023 #define ConstructUnitCommandH
00024
00025 #include "containercommand.h"
00026
00027 #include "../typen.h"
00028 #include "../objects.h"
00029 #include "../mapfield.h"
00030
00031
00032 class ConstructUnitCommand : public ContainerCommand {
00033
00034 public:
00035 static bool externalConstructionAvail( const ContainerBase* eht );
00036 static bool internalConstructionAvail( const ContainerBase* eht );
00037 static bool avail ( const ContainerBase* eht );
00038 enum Mode { undefined, internal, external } ;
00039 private:
00040 Mode mode;
00041 MapCoordinate target;
00042 int vehicleTypeID;
00043 int newUnitID;
00044
00045 void fieldChecker( const MapCoordinate& pos );
00046
00047 map<MapCoordinate,vector<int> > unitsConstructable;
00048
00049 ConstructUnitCommand( GameMap* map ) : ContainerCommand( map ), mode( undefined ) {};
00050 template<class Child> friend GameAction* GameActionCreator( GameMap* map);
00051
00052 protected:
00053 void readData ( tnstream& stream );
00054 void writeData ( tnstream& stream ) const;
00055
00056 GameActionID getID() const;
00057 ASCString getDescription() const;
00058
00059 public:
00060 ConstructUnitCommand ( ContainerBase* unit );
00061
00062 void setMode( Mode mode );
00063 ActionResult go ( const Context& context );
00064 ASCString getCommandString() const;
00065
00066
00067 class Lack {
00068 int value;
00069 public:
00070 Lack() : value(0) {};
00071 Lack( int value ) { this->value = value; };
00072 enum Prerequisites { Energy = 1, Material = 2, Fuel = 4, Research = 8 , Unloadability = 0x10, Movement = 0x20 };
00073 bool ok() const { return value == 0 ; };
00074 int getValue() const { return value; };
00075 };
00076
00077 class ProductionEntry {
00078 public:
00079 const VehicleType* type;
00080 Resources cost;
00081 ConstructUnitCommand::Lack prerequisites;
00082 ProductionEntry() : type(NULL) {};
00083 ProductionEntry(const VehicleType* type, const Resources& cost, ConstructUnitCommand::Lack prerequisites ) {
00084 this->type = type;
00085 this->cost = cost;
00086 this->prerequisites = prerequisites;
00087 }
00088 };
00089
00090 typedef vector<ConstructUnitCommand::ProductionEntry> Producables;
00091
00092 Lack unitProductionPrerequisites( const VehicleType* type ) const;
00093
00094 void setVehicleType( const VehicleType* type );
00095
00100 Producables getProduceableVehicles();
00101
00102 vector<MapCoordinate> getFields();
00103 bool isFieldUsable( const MapCoordinate& pos );
00104
00105 Vehicle* getProducedUnit();
00106
00107 void setTargetPosition( const MapCoordinate& pos );
00108 };
00109
00110 #endif
00111