2011-01-20 16:56:30 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 08:40:48 +01:00
|
|
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
2011-01-20 16:56:30 +01:00
|
|
|
//
|
2010-03-25 13:15:10 +01:00
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
2011-01-20 16:56:30 +01:00
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_COMMAND_H_
|
|
|
|
#define _GLEST_GAME_COMMAND_H_
|
|
|
|
|
2012-04-20 03:04:05 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
2011-01-20 16:56:30 +01:00
|
|
|
|
2012-04-20 03:04:05 +02:00
|
|
|
#include <cstdlib>
|
2011-01-20 16:56:30 +01:00
|
|
|
#include "unit.h"
|
|
|
|
#include "vec.h"
|
|
|
|
#include "game_constants.h"
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
using Shared::Graphics::Vec2i;
|
|
|
|
|
|
|
|
class CommandType;
|
|
|
|
|
|
|
|
enum CommandStateType {
|
|
|
|
cst_None,
|
2013-02-12 22:51:25 +01:00
|
|
|
cst_linkedUnit,
|
|
|
|
cst_EmergencyReturnResource
|
2011-01-20 16:56:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Command
|
|
|
|
//
|
|
|
|
/// A unit command
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
class Command {
|
|
|
|
private:
|
|
|
|
const CommandType *commandType;
|
2011-03-25 21:51:14 +01:00
|
|
|
Vec2i originalPos;
|
2011-01-20 16:56:30 +01:00
|
|
|
Vec2i pos;
|
|
|
|
UnitReference unitRef; //target unit, used to move and attack optionally
|
|
|
|
CardinalDir facing; // facing, for build command
|
|
|
|
const UnitType *unitType; //used for build
|
|
|
|
|
|
|
|
CommandStateType stateType;
|
|
|
|
int stateValue;
|
|
|
|
|
2011-07-05 06:37:35 +02:00
|
|
|
int unitCommandGroupId;
|
|
|
|
|
2012-03-13 16:21:25 +01:00
|
|
|
Command();
|
2011-01-20 16:56:30 +01:00
|
|
|
public:
|
|
|
|
//constructor
|
|
|
|
Command(const CommandType *ct, const Vec2i &pos=Vec2i(0));
|
|
|
|
Command(const CommandType *ct, Unit *unit);
|
|
|
|
Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing);
|
|
|
|
|
2012-09-22 22:13:57 +02:00
|
|
|
virtual ~Command() {}
|
2011-01-20 16:56:30 +01:00
|
|
|
//get
|
2012-04-21 05:42:25 +02:00
|
|
|
inline const CommandType *getCommandType() const {return commandType;}
|
|
|
|
inline Vec2i getPos() const {return pos;}
|
|
|
|
inline Vec2i getOriginalPos() const {return originalPos;}
|
|
|
|
inline Unit* getUnit() const {return unitRef.getUnit();}
|
|
|
|
inline const UnitType* getUnitType() const {return unitType;}
|
|
|
|
inline CardinalDir getFacing() const {return facing;}
|
2011-01-20 16:56:30 +01:00
|
|
|
|
|
|
|
//Priority: commands of higher priority will cancel commands of lower priority
|
|
|
|
virtual int getPriority();
|
|
|
|
|
|
|
|
//set
|
|
|
|
void setCommandType(const CommandType *commandType);
|
|
|
|
void setPos(const Vec2i &pos);
|
2011-03-25 21:51:14 +01:00
|
|
|
void setOriginalPos(const Vec2i &pos);
|
|
|
|
void setPosToOriginalPos();
|
|
|
|
|
2011-01-20 16:56:30 +01:00
|
|
|
void setUnit(Unit *unit);
|
|
|
|
|
2012-04-21 05:42:25 +02:00
|
|
|
inline void setStateType(CommandStateType value) { stateType = value; }
|
|
|
|
inline CommandStateType getStateType() const { return stateType; }
|
2011-01-20 16:56:30 +01:00
|
|
|
|
2012-04-21 05:42:25 +02:00
|
|
|
inline void setStateValue(int value) { stateValue = value; }
|
|
|
|
inline int getStateValue() const { return stateValue; }
|
2011-01-20 16:56:30 +01:00
|
|
|
|
2012-04-21 05:42:25 +02:00
|
|
|
inline void setUnitCommandGroupId(int value) { unitCommandGroupId = value; }
|
|
|
|
inline int getUnitCommandGroupId() const { return unitCommandGroupId; }
|
2011-07-05 06:37:35 +02:00
|
|
|
|
2013-09-21 22:50:58 +02:00
|
|
|
std::string toString(bool translatedValue) const;
|
2012-03-10 04:27:25 +01:00
|
|
|
|
2012-03-13 16:21:25 +01:00
|
|
|
void saveGame(XmlNode *rootNode, Faction *faction);
|
|
|
|
static Command * loadGame(const XmlNode *rootNode,const UnitType *ut,World *world);
|
2013-09-23 19:16:34 +02:00
|
|
|
|
|
|
|
Checksum getCRC();
|
2011-01-20 16:56:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|