fix for boosting sight

This commit is contained in:
titiger 2014-12-22 21:11:58 +01:00
parent dc143f8819
commit 8925a8997c
2 changed files with 19 additions and 10 deletions

View File

@ -578,6 +578,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos,
this->lastHarvestResourceTarget.first = Vec2i(0);
this->morphFieldsBlocked=false;
//this->lastBadHarvestListPurge = 0;
this->oldTotalSight = 0;
level= NULL;
loadType= NULL;
@ -1394,10 +1395,10 @@ void Unit::setPos(const Vec2i &pos, bool clearPathFinder) {
logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
}
void Unit::refreshPos() {
void Unit::refreshPos(bool forceRefresh) {
// Attempt to improve performance
this->exploreCells();
calculateFogOfWarRadius();
this->exploreCells(forceRefresh);
calculateFogOfWarRadius(forceRefresh);
}
FowAlphaCellsLookupItem Unit::getFogOfWarRadius(bool useCache) const {
@ -1438,9 +1439,9 @@ FowAlphaCellsLookupItem Unit::getFogOfWarRadius(bool useCache) const {
return result;
}
void Unit::calculateFogOfWarRadius() {
void Unit::calculateFogOfWarRadius(bool forceRefresh) {
if(game->getWorld()->getFogOfWar() == true) {
if(this->pos != this->cachedFowPos) {
if(forceRefresh || this->pos != this->cachedFowPos) {
cachedFow = getFogOfWarRadius(false);
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
@ -2623,6 +2624,12 @@ bool Unit::update() {
//speed
int speed= currSkill->getTotalSpeed(&totalUpgrade);
if( oldTotalSight != getType()->getTotalSight(this->getTotalUpgrade())){
oldTotalSight= getType()->getTotalSight(this->getTotalUpgrade());
// refresh FogOfWar and so on, because sight ha changed since last update
refreshPos(true);
}
if(changedActiveCommand) {
if(changedActiveCommandFrame - lastChangedActiveCommandFrame >= MIN_FRAMECOUNT_CHANGE_COMMAND_SPEED) {
//printf("Line: %d speed = %d changedActiveCommandFrame [%u] lastChangedActiveCommandFrame [%u] skill [%s] command [%s]\n",__LINE__,speed,changedActiveCommandFrame,lastChangedActiveCommandFrame,currSkill->toString(false).c_str(),getCurrCommand()->toString(false).c_str());
@ -4362,7 +4369,7 @@ uint32 Unit::getFrameCount() const {
return frameCount;
}
void Unit::exploreCells() {
void Unit::exploreCells(bool forceRefresh) {
if(this->isOperative() == true) {
const Vec2i &newPos = this->getCenteredPos();
int sightRange = this->getType()->getTotalSight(this->getTotalUpgrade());
@ -4376,7 +4383,8 @@ void Unit::exploreCells() {
}
// Try the local unit exploration cache
if(cacheExploredCellsKey.first == newPos &&
if( !forceRefresh &&
cacheExploredCellsKey.first == newPos &&
cacheExploredCellsKey.second == sightRange) {
game->getWorld()->exploreCells(teamIndex, cacheExploredCells);
}

View File

@ -370,6 +370,7 @@ private:
int32 kills;
int32 enemyKills;
bool morphFieldsBlocked;
int oldTotalSight;
UnitReference targetRef;
@ -519,7 +520,7 @@ public:
const FowAlphaCellsLookupItem & getCachedFow() const { return cachedFow; }
FowAlphaCellsLookupItem getFogOfWarRadius(bool useCache) const;
void calculateFogOfWarRadius();
void calculateFogOfWarRadius(bool forceRefresh=false);
//queries
Command *getCurrrentCommandThreadSafe();
@ -626,7 +627,7 @@ public:
inline void setLoadType(const ResourceType *loadType) {this->loadType= loadType;}
inline void setProgress2(int progress2) {this->progress2= progress2;}
void setPos(const Vec2i &pos,bool clearPathFinder=false);
void refreshPos();
void refreshPos(bool forceRefresh=false);
void setTargetPos(const Vec2i &targetPos);
void setTarget(const Unit *unit);
//void setTargetVec(const Vec3f &targetVec);
@ -711,7 +712,7 @@ public:
inline string getCurrentUnitTitle() const {return currentUnitTitle;}
void setCurrentUnitTitle(string value) { currentUnitTitle = value;}
void exploreCells();
void exploreCells(bool forceRefresh=false);
inline bool getInBailOutAttempt() const { return inBailOutAttempt; }
inline void setInBailOutAttempt(bool value) { inBailOutAttempt = value; }