From 68f1ec06b58dc67820a261e8e81e67f5e62905f7 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 25 Mar 2011 20:51:14 +0000 Subject: [PATCH] - fix for harvesting workers to reset to original harvest location each time they deliver resources --- source/glest_game/type_instances/command.cpp | 17 +++++++++++++++-- source/glest_game/type_instances/command.h | 5 +++++ source/glest_game/world/unit_updater.cpp | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/source/glest_game/type_instances/command.cpp b/source/glest_game/type_instances/command.cpp index c9bd03af..7f38e12e 100644 --- a/source/glest_game/type_instances/command.cpp +++ b/source/glest_game/type_instances/command.cpp @@ -30,6 +30,7 @@ Command::Command(const CommandType *ct, const Vec2i &pos){ this->commandType= ct; this->pos= pos; + this->originalPos = this->pos; this->unitRef= NULL; unitType= NULL; stateType = cst_None; @@ -39,6 +40,7 @@ Command::Command(const CommandType *ct, const Vec2i &pos){ Command::Command(const CommandType *ct, Unit* unit) { this->commandType= ct; this->pos= Vec2i(0); + this->originalPos = this->pos; this->unitRef= unit; unitType= 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) { this->commandType= ct; this->pos= pos; + this->originalPos = this->pos; this->unitRef= NULL; this->unitType= unitType; this->facing = facing; @@ -71,7 +74,7 @@ int Command::getPriority(){ } // =============== set =============== -void Command::setCommandType(const CommandType *commandType){ +void Command::setCommandType(const CommandType *commandType) { this->commandType= commandType; } @@ -79,6 +82,14 @@ void Command::setPos(const Vec2i &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){ this->unitRef= unit; } @@ -88,13 +99,15 @@ std::string Command::toString() const { std::string result = ""; 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 { result = "commandType = NULL"; } //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.getUnitId() >= 0) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__); diff --git a/source/glest_game/type_instances/command.h b/source/glest_game/type_instances/command.h index e55a6828..3fd18597 100644 --- a/source/glest_game/type_instances/command.h +++ b/source/glest_game/type_instances/command.h @@ -39,6 +39,7 @@ enum CommandStateType { class Command { private: const CommandType *commandType; + Vec2i originalPos; Vec2i pos; UnitReference unitRef; //target unit, used to move and attack optionally CardinalDir facing; // facing, for build command @@ -56,6 +57,7 @@ public: //get const CommandType *getCommandType() const {return commandType;} Vec2i getPos() const {return pos;} + Vec2i getOriginalPos() const {return originalPos;} Unit* getUnit() const {return unitRef.getUnit();} const UnitType* getUnitType() const {return unitType;} CardinalDir getFacing() const {return facing;} @@ -66,6 +68,9 @@ public: //set void setCommandType(const CommandType *commandType); void setPos(const Vec2i &pos); + void setOriginalPos(const Vec2i &pos); + void setPosToOriginalPos(); + void setUnit(Unit *unit); void setStateType(CommandStateType value) { stateType = value; } diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 07a94e04..0b993d68 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -1042,6 +1042,8 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) { unit->getPath()->clear(); unit->setCurrSkill(scStop); 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());