From d38a1f88774967ad030926d179abac9b9b513428 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 6 Apr 2010 03:28:20 +0000 Subject: [PATCH] Bugfix for cheating when the harvest command type has changed to a different command. Got this from Silnarm. --- source/glest_game/world/unit_updater.cpp | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index f0995141..aa211eb9 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -443,6 +443,8 @@ void UnitUpdater::updateHarvest(Unit *unit){ //if working SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(unit->getTargetPos())); Resource *r= sc->getResource(); + + /* if(r!=NULL){ //if there is a resource, continue working, until loaded unit->update2(); @@ -467,6 +469,42 @@ void UnitUpdater::updateHarvest(Unit *unit){ //if there is no resource, just stop unit->setCurrSkill(hct->getStopLoadedSkillType()); } + */ + + if (r != NULL) { + // Fix from Silnarm to disable cheating - START + if (!hct->canHarvest(r->getType()) || r->getType() != unit->getLoadType()) { + // hct has changed to a different harvest command. + unit->setCurrSkill(hct->getStopLoadedSkillType()); // this is actually the wrong animation + unit->getPath()->clear(); + return; + } + // Fix from Silnarm to disable cheating - END + + // if there is a resource, continue working, until loaded + unit->update2(); + if (unit->getProgress2() >= hct->getHitsPerUnit()) { + if (unit->getLoadCount() < hct->getMaxLoad()) { + unit->setProgress2(0); + unit->setLoadCount(unit->getLoadCount() + 1); + + //if resource exausted, then delete it and stop + if (r->decAmount(1)) { + sc->deleteResource(); + unit->setCurrSkill(hct->getStopLoadedSkillType()); + } + } + if (unit->getLoadCount() >= hct->getMaxLoad()) { + unit->setCurrSkill(hct->getStopLoadedSkillType()); + unit->getPath()->clear(); + } + } + } + else{ + //if there is no resource, just stop + unit->setCurrSkill(hct->getStopLoadedSkillType()); + } + } }