constructunitcommand.h

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
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 

Generated on Mon May 21 01:26:30 2012 for Advanced Strategic Command by  doxygen 1.5.1