2010-03-25 13:15:10 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2010-05-01 11:27:08 +02:00
|
|
|
// Copyright (C) 2001-2008 Martio Figueroa
|
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
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#include "command.h"
|
|
|
|
|
|
|
|
#include "command_type.h"
|
2010-05-01 11:27:08 +02:00
|
|
|
#include "util.h"
|
2010-05-18 05:53:57 +02:00
|
|
|
#include "conversion.h"
|
2010-05-29 12:34:56 +02:00
|
|
|
#include "unit_type.h"
|
2010-05-18 05:53:57 +02:00
|
|
|
#include "leak_dumper.h"
|
2010-05-01 11:27:08 +02:00
|
|
|
|
|
|
|
using namespace Shared::Util;
|
2010-03-25 13:15:10 +01:00
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Command
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
Command::Command(const CommandType *ct, const Vec2i &pos){
|
2010-05-01 11:27:08 +02:00
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ct = [%p]\n",__FILE__,__FUNCTION__,__LINE__,ct);
|
|
|
|
|
2010-03-25 13:15:10 +01:00
|
|
|
this->commandType= ct;
|
|
|
|
this->pos= pos;
|
|
|
|
unitType= NULL;
|
2010-08-30 22:45:12 +02:00
|
|
|
stateType = cst_None;
|
|
|
|
stateValue = -1;
|
2010-03-25 13:15:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Command::Command(const CommandType *ct, Unit* unit){
|
|
|
|
this->commandType= ct;
|
|
|
|
this->pos= Vec2i(0);
|
|
|
|
this->unitRef= unit;
|
|
|
|
unitType= NULL;
|
2010-08-30 22:45:12 +02:00
|
|
|
if(unit!=NULL) {
|
2010-03-25 13:15:10 +01:00
|
|
|
unit->resetHighlight();
|
|
|
|
pos= unit->getCellPos();
|
|
|
|
}
|
2010-08-30 22:45:12 +02:00
|
|
|
stateType = cst_None;
|
|
|
|
stateValue = -1;
|
2010-03-25 13:15:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing){
|
|
|
|
this->commandType= ct;
|
|
|
|
this->pos= pos;
|
|
|
|
this->unitType= unitType;
|
|
|
|
this->facing = facing;
|
2010-08-30 22:45:12 +02:00
|
|
|
stateType = cst_None;
|
|
|
|
stateValue = -1;
|
2010-05-29 12:34:56 +02:00
|
|
|
|
|
|
|
if(this->unitType != NULL) {
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitType = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->unitType->toString().c_str());
|
|
|
|
}
|
2010-03-25 13:15:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// =============== set ===============
|
|
|
|
|
|
|
|
void Command::setCommandType(const CommandType *commandType){
|
|
|
|
this->commandType= commandType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Command::setPos(const Vec2i &pos){
|
|
|
|
this->pos= pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Command::setUnit(Unit *unit){
|
|
|
|
this->unitRef= unit;
|
|
|
|
}
|
|
|
|
|
2010-05-18 05:53:57 +02:00
|
|
|
std::string Command::toString() const {
|
2010-06-02 10:03:56 +02:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);
|
|
|
|
|
2010-05-29 18:55:55 +02:00
|
|
|
std::string result = "";
|
2010-06-10 16:58:06 +02:00
|
|
|
if(commandType != NULL) {
|
|
|
|
result = "commandType id = " + intToStr(commandType->getId()) + ", desc = " + commandType->toString() + ", pos = " + pos.getString() + ", facing = " + intToStr(facing.asInt());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = "commandType = NULL";
|
|
|
|
}
|
2010-06-02 10:03:56 +02:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);
|
|
|
|
|
|
|
|
//if(unitRef.getUnit() != NULL) {
|
|
|
|
if(unitRef.getUnitId() >= 0) {
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);
|
|
|
|
|
2010-06-02 22:06:49 +02:00
|
|
|
result += ", unitRef.getUnit() id = " + intToStr(unitRef.getUnitId());
|
2010-12-01 01:05:33 +01:00
|
|
|
|
|
|
|
// The code below causes a STACK OVERFLOW!
|
|
|
|
//if(unitRef.getUnit() != NULL) {
|
|
|
|
// result += ", unitRef.getUnit() = " + unitRef.getUnit()->toString();
|
|
|
|
//}
|
2010-05-31 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
2010-06-02 10:03:56 +02:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);
|
|
|
|
|
2010-05-29 18:55:55 +02:00
|
|
|
if(unitType != NULL) {
|
2010-08-07 05:26:38 +02:00
|
|
|
result += ", unitTypeId = " + intToStr(unitType->getId());
|
|
|
|
result += ", unitTypeDesc = " + unitType->getReqDesc();
|
2010-05-29 18:55:55 +02:00
|
|
|
}
|
2010-06-02 10:03:56 +02:00
|
|
|
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);
|
|
|
|
|
2010-10-28 20:31:12 +02:00
|
|
|
result += ", stateType = " + intToStr(stateType) + ", stateValue = " + intToStr(stateValue);
|
2010-08-30 22:45:12 +02:00
|
|
|
|
2010-05-18 05:53:57 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-03-25 13:15:10 +01:00
|
|
|
}}//end namespace
|