diff --git a/source/glest_game/types/command_type.h b/source/glest_game/types/command_type.h index b521212f..7697bd69 100644 --- a/source/glest_game/types/command_type.h +++ b/source/glest_game/types/command_type.h @@ -67,12 +67,12 @@ enum Queueability { class CommandType: public RequirableType { protected: - CommandClass commandTypeClass; Clicks clicks; int id; public: static const int invalidId= -1; + CommandClass commandTypeClass; public: CommandType() { diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 5f0e16e9..c059698f 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -53,6 +53,7 @@ UnitUpdater::UnitUpdater() { this->scriptManager= NULL; this->routePlanner = NULL; this->pathFinder = NULL; + lastWarnFrameCount=0; //UnitRangeCellsLookupItemCacheTimerCount = 0; } @@ -67,6 +68,7 @@ void UnitUpdater::init(Game *game){ this->scriptManager= game->getScriptManager(); this->routePlanner = NULL; this->pathFinder = NULL; + lastWarnFrameCount=0; //UnitRangeCellsLookupItemCacheTimerCount = 0; switch(this->game->getGameSettings()->getPathFinderType()) { @@ -180,6 +182,12 @@ void UnitUpdater::updateUnitCommand(Unit *unit) { //if unit has command process it if(unit->anyCommand()) { + CommandClass cc=unit->getCurrCommand()->getCommandType()->commandTypeClass; + if(unit->isOperative() && (!(cc==ccStop || cc==ccAttack)) ) + {//stop and attack already check for themselves + Unit *sighted; + attackerOnSight(unit, &sighted); + } unit->getCurrCommand()->getCommandType()->update(this, unit); } @@ -194,6 +202,12 @@ void UnitUpdater::updateUnitCommand(Unit *unit) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop))); } + else + { + // buidings have no stop skill but hav to check for attackers too. + Unit *sighted; + attackerOnSight(unit, &sighted); + } } if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); @@ -1692,7 +1706,7 @@ void UnitUpdater::findEnemiesForCell(const AttackSkillType *ast, Cell *cell, con bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, const AttackSkillType *ast){ vector enemies; - + bool result=false; //we check command target const Unit *commandTarget = NULL; if(unit->anyCommand()) { @@ -1743,18 +1757,30 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, if(enemies[i]->getType()->hasSkillClass(scAttack)) { *rangedPtr= enemies[i]; - return true; + result=true; + break; } } //any enemy - if(enemies.size() > 0) { + if(!result && (enemies.size() > 0)) { *rangedPtr= enemies.front(); return true; } - return false; + if(result) + { + + if(world->getFrameCount()-lastWarnFrameCount>80) //after 100 frames attack break we warn again + { + SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound()); + } + lastWarnFrameCount=world->getFrameCount(); + } + + + return result; } // ===================================================== diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index 923fac9a..5818c9c0 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -69,7 +69,8 @@ private: PathFinder *pathFinder; RoutePlanner *routePlanner; Game *game; - RandomGen random; + RandomGen random; + int lastWarnFrameCount; std::map > > UnitRangeCellsLookupItemCache; //std::map ExploredCellsLookupItemCacheTimer;