From 646d11f14384cd4be220daeb0a400e6908f89a1e Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 12 Feb 2013 21:51:25 +0000 Subject: [PATCH] - if unit harvests a resource, stops and harvest the same type again they do not need to return to the store house --- source/glest_game/type_instances/command.h | 3 ++- source/glest_game/world/unit_updater.cpp | 28 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/source/glest_game/type_instances/command.h b/source/glest_game/type_instances/command.h index 135ec9fb..08b8ebdd 100644 --- a/source/glest_game/type_instances/command.h +++ b/source/glest_game/type_instances/command.h @@ -31,7 +31,8 @@ class CommandType; enum CommandStateType { cst_None, - cst_linkedUnit + cst_linkedUnit, + cst_EmergencyReturnResource }; // ===================================================== diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 9a2a3379..3459dd43 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -953,6 +953,8 @@ void UnitUpdater::updateHarvestEmergencyReturn(Unit *unit, int frameIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Command* new_command= this->game->getCommander()->buildCommand(&networkCommand); + new_command->setStateType(cst_EmergencyReturnResource); + new_command->setStateValue(1); std::pair cr= unit->checkCommand(new_command); if(cr.first == crSuccess) { //printf("\n\n#1b return harvested resources\n\n"); @@ -994,9 +996,21 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) { //printf("In UpdateHarvest [%d - %s] unit->getCurrSkill()->getClass() = %d\n",unit->getId(),unit->getType()->getName().c_str(),unit->getCurrSkill()->getClass()); + Resource *harvestResource = NULL; + SurfaceCell *sc = map->getSurfaceCell(Map::toSurfCoords(command->getPos())); + if(sc != NULL) { + harvestResource = sc->getResource(); + } + if(unit->getCurrSkill() != NULL && unit->getCurrSkill()->getClass() != scHarvest) { + bool forceReturnToStore = (command != NULL && + command->getStateType() == cst_EmergencyReturnResource && command->getStateValue() == 1); + //if not working - if(unit->getLoadCount() == 0) { + if(unit->getLoadCount() == 0 || + (forceReturnToStore == false && unit->getLoadType() != NULL && + harvestResource != NULL && + harvestResource->getType() != NULL && unit->getLoadType() == harvestResource->getType())) { //if not loaded go for resources SurfaceCell *sc = map->getSurfaceCell(Map::toSurfCoords(command->getPos())); if(sc != NULL) { @@ -1054,7 +1068,11 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) { unit->setCurrSkill(hct->getHarvestSkillType()); unit->setTargetPos(targetPos); command->setPos(targetPos); - unit->setLoadCount(0); + + if(unit->getLoadType() == NULL || harvestResource == NULL || + harvestResource->getType() == NULL || unit->getLoadType() != harvestResource->getType()) { + unit->setLoadCount(0); + } unit->getFaction()->addResourceTargetToCache(targetPos); switch(this->game->getGameSettings()->getPathFinderType()) { @@ -1128,7 +1146,11 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) { unit->setCurrSkill(hct->getHarvestSkillType()); unit->setTargetPos(targetPos); command->setPos(targetPos); - unit->setLoadCount(0); + + if(unit->getLoadType() == NULL || harvestResource == NULL || + harvestResource->getType() == NULL || unit->getLoadType() != harvestResource->getType()) { + unit->setLoadCount(0); + } unit->getFaction()->addResourceTargetToCache(targetPos); switch(this->game->getGameSettings()->getPathFinderType()) {