1 // ============================================================== 2 // This file is part of Glest (www.glest.org) 3 // 4 // Copyright (C) 2001-2008 Martiño Figueroa 5 // 6 // You can redistribute this code and/or modify it under 7 // the terms of the GNU General Public License as published 8 // by the Free Software Foundation; either version 2 of the 9 // License, or (at your option) any later version 10 // ============================================================== 11 12 #ifndef _GLEST_GAME_COMMAND_H_ 13 #define _GLEST_GAME_COMMAND_H_ 14 15 #ifdef WIN32 16 #include <winsock2.h> 17 #include <winsock.h> 18 #endif 19 20 #include <cstdlib> 21 #include "unit.h" 22 #include "vec.h" 23 #include "game_constants.h" 24 #include "leak_dumper.h" 25 26 namespace Glest{ namespace Game{ 27 28 using Shared::Graphics::Vec2i; 29 30 class CommandType; 31 32 enum CommandStateType { 33 cst_None, 34 cst_linkedUnit, 35 cst_EmergencyReturnResource 36 }; 37 38 // ===================================================== 39 // class Command 40 // 41 /// A unit command 42 // ===================================================== 43 44 class Command { 45 private: 46 const CommandType *commandType; 47 Vec2i originalPos; 48 Vec2i pos; 49 UnitReference unitRef; //target unit, used to move and attack optionally 50 CardinalDir facing; // facing, for build command 51 const UnitType *unitType; //used for build 52 53 CommandStateType stateType; 54 int stateValue; 55 56 int unitCommandGroupId; 57 58 Command(); 59 public: 60 //constructor 61 Command(const CommandType *ct, const Vec2i &pos=Vec2i(0)); 62 Command(const CommandType *ct, Unit *unit); 63 Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing); 64 ~Command()65 virtual ~Command() {} 66 //get getCommandType()67 inline const CommandType *getCommandType() const {return commandType;} getPos()68 inline Vec2i getPos() const {return pos;} getOriginalPos()69 inline Vec2i getOriginalPos() const {return originalPos;} getUnit()70 inline Unit* getUnit() const {return unitRef.getUnit();} getUnitType()71 inline const UnitType* getUnitType() const {return unitType;} getFacing()72 inline CardinalDir getFacing() const {return facing;} 73 74 //Priority: commands of higher priority will cancel commands of lower priority 75 virtual int getPriority(); 76 77 //set 78 void setCommandType(const CommandType *commandType); 79 void setPos(const Vec2i &pos); 80 void setOriginalPos(const Vec2i &pos); 81 void setPosToOriginalPos(); 82 83 void setUnit(Unit *unit); 84 setStateType(CommandStateType value)85 inline void setStateType(CommandStateType value) { stateType = value; } getStateType()86 inline CommandStateType getStateType() const { return stateType; } 87 setStateValue(int value)88 inline void setStateValue(int value) { stateValue = value; } getStateValue()89 inline int getStateValue() const { return stateValue; } 90 setUnitCommandGroupId(int value)91 inline void setUnitCommandGroupId(int value) { unitCommandGroupId = value; } getUnitCommandGroupId()92 inline int getUnitCommandGroupId() const { return unitCommandGroupId; } 93 94 std::string toString(bool translatedValue) const; 95 96 void saveGame(XmlNode *rootNode, Faction *faction); 97 static Command * loadGame(const XmlNode *rootNode,const UnitType *ut,World *world); 98 99 Checksum getCRC(); 100 }; 101 102 }}//end namespace 103 104 #endif 105