- fix for harvesting workers to reset to original harvest location each time they deliver resources

This commit is contained in:
Mark Vejvoda 2011-03-25 20:51:14 +00:00
parent 0f6f5cfe21
commit 68f1ec06b5
3 changed files with 22 additions and 2 deletions

View File

@ -30,6 +30,7 @@ Command::Command(const CommandType *ct, const Vec2i &pos){
this->commandType= ct; this->commandType= ct;
this->pos= pos; this->pos= pos;
this->originalPos = this->pos;
this->unitRef= NULL; this->unitRef= NULL;
unitType= NULL; unitType= NULL;
stateType = cst_None; stateType = cst_None;
@ -39,6 +40,7 @@ Command::Command(const CommandType *ct, const Vec2i &pos){
Command::Command(const CommandType *ct, Unit* unit) { Command::Command(const CommandType *ct, Unit* unit) {
this->commandType= ct; this->commandType= ct;
this->pos= Vec2i(0); this->pos= Vec2i(0);
this->originalPos = this->pos;
this->unitRef= unit; this->unitRef= unit;
unitType= NULL; unitType= NULL;
if(unit!=NULL) { if(unit!=NULL) {
@ -52,6 +54,7 @@ Command::Command(const CommandType *ct, Unit* unit) {
Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing) { Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing) {
this->commandType= ct; this->commandType= ct;
this->pos= pos; this->pos= pos;
this->originalPos = this->pos;
this->unitRef= NULL; this->unitRef= NULL;
this->unitType= unitType; this->unitType= unitType;
this->facing = facing; this->facing = facing;
@ -71,7 +74,7 @@ int Command::getPriority(){
} }
// =============== set =============== // =============== set ===============
void Command::setCommandType(const CommandType *commandType){ void Command::setCommandType(const CommandType *commandType) {
this->commandType= commandType; this->commandType= commandType;
} }
@ -79,6 +82,14 @@ void Command::setPos(const Vec2i &pos){
this->pos= pos; this->pos= pos;
} }
void Command::setOriginalPos(const Vec2i &pos) {
this->originalPos= pos;
}
void Command::setPosToOriginalPos() {
this->pos= this->originalPos;
}
void Command::setUnit(Unit *unit){ void Command::setUnit(Unit *unit){
this->unitRef= unit; this->unitRef= unit;
} }
@ -88,13 +99,15 @@ std::string Command::toString() const {
std::string result = ""; std::string result = "";
if(commandType != NULL) { if(commandType != NULL) {
result = "commandType id = " + intToStr(commandType->getId()) + ", desc = " + commandType->toString() + ", pos = " + pos.getString() + ", facing = " + intToStr(facing.asInt()); result = "commandType id = " + intToStr(commandType->getId()) + ", desc = " + commandType->toString();
} }
else { else {
result = "commandType = NULL"; result = "commandType = NULL";
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);
result += ", pos = " + pos.getString() + ", originalPos = " + originalPos.getString() + ", facing = " + intToStr(facing.asInt());
//if(unitRef.getUnit() != NULL) { //if(unitRef.getUnit() != NULL) {
if(unitRef.getUnitId() >= 0) { if(unitRef.getUnitId() >= 0) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);

View File

@ -39,6 +39,7 @@ enum CommandStateType {
class Command { class Command {
private: private:
const CommandType *commandType; const CommandType *commandType;
Vec2i originalPos;
Vec2i pos; Vec2i pos;
UnitReference unitRef; //target unit, used to move and attack optionally UnitReference unitRef; //target unit, used to move and attack optionally
CardinalDir facing; // facing, for build command CardinalDir facing; // facing, for build command
@ -56,6 +57,7 @@ public:
//get //get
const CommandType *getCommandType() const {return commandType;} const CommandType *getCommandType() const {return commandType;}
Vec2i getPos() const {return pos;} Vec2i getPos() const {return pos;}
Vec2i getOriginalPos() const {return originalPos;}
Unit* getUnit() const {return unitRef.getUnit();} Unit* getUnit() const {return unitRef.getUnit();}
const UnitType* getUnitType() const {return unitType;} const UnitType* getUnitType() const {return unitType;}
CardinalDir getFacing() const {return facing;} CardinalDir getFacing() const {return facing;}
@ -66,6 +68,9 @@ public:
//set //set
void setCommandType(const CommandType *commandType); void setCommandType(const CommandType *commandType);
void setPos(const Vec2i &pos); void setPos(const Vec2i &pos);
void setOriginalPos(const Vec2i &pos);
void setPosToOriginalPos();
void setUnit(Unit *unit); void setUnit(Unit *unit);
void setStateType(CommandStateType value) { stateType = value; } void setStateType(CommandStateType value) { stateType = value; }

View File

@ -1042,6 +1042,8 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
unit->getPath()->clear(); unit->getPath()->clear();
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
unit->setLoadCount(0); unit->setLoadCount(0);
command->setPosToOriginalPos();
} }
} }
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());