diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 30b49555..37a4237f 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1338,7 +1338,7 @@ void MenuStateCustomGame::render() { int mouse2dAnim = mainMenu->getMouse2dAnim(); renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim); - bool renderAll = (listBoxFogOfWar.getSelectedItemIndex() == 1); + bool renderAll = (listBoxFogOfWar.getSelectedItemIndex() == 2); if(mapPreviewTexture == NULL) { //printf("=================> Rendering map preview into a texture BEFORE (%p)\n", mapPreviewTexture); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index b10b9f69..e2c22509 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -53,7 +53,6 @@ UnitUpdater::UnitUpdater() { this->scriptManager= NULL; this->routePlanner = NULL; this->pathFinder = NULL; - lastWarnFrameCount=0; //UnitRangeCellsLookupItemCacheTimerCount = 0; } @@ -68,7 +67,7 @@ void UnitUpdater::init(Game *game){ this->scriptManager= game->getScriptManager(); this->routePlanner = NULL; this->pathFinder = NULL; - lastWarnFrameCount=0; + attackWarnRange=Config::getInstance().getFloat("AttackWarnRange","50.0"); //UnitRangeCellsLookupItemCacheTimerCount = 0; switch(this->game->getGameSettings()->getPathFinderType()) { @@ -89,6 +88,12 @@ UnitUpdater::~UnitUpdater() { delete pathFinder; pathFinder = NULL; + + while(attackWarnings.empty() == false) { + AttackWarningData* awd=attackWarnings.back(); + attackWarnings.pop_back(); + delete awd; + } } // ==================== progress skills ==================== @@ -1782,12 +1787,63 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, if(result && !(unit->isAlly(enemySeen))) { - if(world->getFrameCount()-lastWarnFrameCount>100) //after 100 frames attack break we warn again - { - world->addAttackEffects(enemySeen); - SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound()); - } - lastWarnFrameCount=world->getFrameCount(); + // find nearest Attack and cleanup old dates + AttackWarningData *nearest=NULL; + float currentDistance; + float nearestDistance; + for(int i = attackWarnings.size()-1; i>-1; --i) { + if(world->getFrameCount()-attackWarnings[i]->lastFrameCount>100) { //after 100 frames attack break we warn again + AttackWarningData *toDelete=attackWarnings[i]; + attackWarnings.erase(attackWarnings.begin()+i); + delete toDelete; // old one + } + else { + currentDistance=floor(floatCenter.dist(attackWarnings[i]->attackPosition)); // no need for streflops here! + if( nearest==NULL ){ + nearest=attackWarnings[i]; + nearestDistance=currentDistance; + } + else { + + if( currentDistance< nearestDistance ){ + nearest=attackWarnings[i]; + nearestDistance=currentDistance; + } + } + } + } + + if(nearest!=NULL) + { // does it fit? + if(nearestDistancelastFrameCount=world->getFrameCount(); + nearest->attackPosition.x=enemySeen->getFloatCenteredPos().x; + nearest->attackPosition.y=enemySeen->getFloatCenteredPos().y; + } + else + {//Must be a different Attack! + nearest=NULL; //set to null to force a new entry in next step + } + } + // add new attack + if(nearest==NULL) // no else! + { + AttackWarningData* awd= new AttackWarningData(); + awd->lastFrameCount=world->getFrameCount(); + awd->attackPosition.x=enemySeen->getFloatCenteredPos().x; + awd->attackPosition.y=enemySeen->getFloatCenteredPos().y; + attackWarnings.push_back(awd); + SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound()); + world->addAttackEffects(enemySeen); + } + +// if(world->getFrameCount()-lastWarnFrameCount>100) //after 100 frames attack break we warn again +// { +// world->addAttackEffects(enemySeen); +// SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound()); +// } +// lastWarnFrameCount=world->getFrameCount(); } diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index 5818c9c0..88ded15a 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -49,9 +49,16 @@ public: static time_t lastDebug; }; +class AttackWarningData { +public: + Vec2f attackPosition; + int lastFrameCount; +}; + class UnitUpdater { private: friend class ParticleDamager; + typedef vector AttackWarnings; private: static const int maxResSearchRadius= 10; @@ -70,7 +77,8 @@ private: RoutePlanner *routePlanner; Game *game; RandomGen random; - int lastWarnFrameCount; + float attackWarnRange; + AttackWarnings attackWarnings; std::map > > UnitRangeCellsLookupItemCache; //std::map ExploredCellsLookupItemCacheTimer;