From ca39f8c6b10099a7d0ed049bdfc5292447ca063d Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Mon, 4 Jun 2012 21:53:20 +0000 Subject: [PATCH] new try with changed fighting behaviour of ultra and mega; fix for "*" in chat --- source/glest_game/game/chat_manager.cpp | 11 +++--- source/glest_game/type_instances/unit.h | 1 + source/glest_game/world/unit_updater.cpp | 48 ++++++++++++------------ source/glest_game/world/unit_updater.h | 8 ++-- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index 74067959..138b11e8 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -435,11 +435,12 @@ void ChatManager::updateNetwork() { playerName = this->manualPlayerNameOverride; } - if(StartsWith(msg.chatText,"*") && msg.chatText.find(playerName) != string::npos){ - CoreData &coreData= CoreData::getInstance(); - SoundRenderer &soundRenderer= SoundRenderer::getInstance(); - - soundRenderer.playFx(coreData.getHighlightSound()); + if(StartsWith(msg.chatText,"*")){ + if(msg.chatText.find(playerName) != string::npos){ + CoreData &coreData= CoreData::getInstance(); + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + soundRenderer.playFx(coreData.getHighlightSound()); + } console->addLine(msg.chatText.substr(1,msg.chatText.size()), true, msg.chatPlayerIndex,Vec3f(1.f, 1.f, 1.f),teamMode); } else { diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index ec37986a..d2e3274f 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -602,6 +602,7 @@ public: int update2(); bool update(); void tick(); + RandomGen* getRandom() { return &random; } bool applyAttackBoost(const AttackBoost *boost, const Unit *source); void deapplyAttackBoost(const AttackBoost *boost, const Unit *source); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 3444c095..96d500cd 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -2191,17 +2191,17 @@ bool UnitUpdater::searchForResource(Unit *unit, const HarvestCommandType *hct) { return false; } -bool UnitUpdater::attackerOnSight(const Unit *unit, Unit **rangedPtr){ +bool UnitUpdater::attackerOnSight(Unit *unit, Unit **rangedPtr){ int range= unit->getType()->getSight(); return unitOnRange(unit, range, rangedPtr, NULL); } -bool UnitUpdater::attackableOnSight(const Unit *unit, Unit **rangedPtr, const AttackSkillType *ast){ +bool UnitUpdater::attackableOnSight(Unit *unit, Unit **rangedPtr, const AttackSkillType *ast){ int range= unit->getType()->getSight(); return unitOnRange(unit, range, rangedPtr, ast); } -bool UnitUpdater::attackableOnRange(const Unit *unit, Unit **rangedPtr, const AttackSkillType *ast){ +bool UnitUpdater::attackableOnRange(Unit *unit, Unit **rangedPtr, const AttackSkillType *ast){ int range= ast->getTotalAttackRange(unit->getTotalUpgrade()); return unitOnRange(unit, range, rangedPtr, ast); } @@ -2295,7 +2295,7 @@ void UnitUpdater::findEnemiesForCell(const Vec2i pos, int size, int sightRange, } //if the unit has any enemy on range -bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, +bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, const AttackSkillType *ast) { vector enemies; bool result=false; @@ -2348,11 +2348,11 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, float distToUnit= -1; Unit* enemySeen= NULL; -//TT float distToStandingUnit= -1; -// Unit* attackingEnemySeen= NULL; -// ControlType controlType= unit->getFaction()->getControlType(); -// bool isUltra= controlType == ctCpuUltra || controlType == ctNetworkCpuUltra; -// bool isMega= controlType == ctCpuMega || controlType == ctNetworkCpuMega; + float distToStandingUnit= -1; + Unit* attackingEnemySeen= NULL; + ControlType controlType= unit->getFaction()->getControlType(); + bool isUltra= controlType == ctCpuUltra || controlType == ctNetworkCpuUltra; + bool isMega= controlType == ctCpuMega || controlType == ctNetworkCpuMega; //printf("unit %d has control:%d\n",unit->getId(),controlType); for(int i = 0; i< enemies.size(); ++i) { @@ -2376,25 +2376,25 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, result = true; } -//TT if(isUltra || isMega) { -// if(distToStandingUnit < 0 || currentDist< distToStandingUnit) { -// if(enemies[i]->getCurrSkill()!=NULL && enemies[i]->getCurrSkill()->getClass()==scAttack) { -// distToStandingUnit = currentDist; -// attackingEnemySeen=enemies[i]; -// } -// } -// } + if(isUltra || isMega) { + if(distToStandingUnit < 0 || currentDist< distToStandingUnit) { + if(enemies[i]->getCurrSkill()!=NULL && enemies[i]->getCurrSkill()->getClass()==scAttack) { + distToStandingUnit = currentDist; + attackingEnemySeen=enemies[i]; + } + } + } } } } -//TT if(isUltra || isMega) { -// if( attackingEnemySeen!=NULL && random.randRange(0,2)!=2 ) { -// *rangedPtr = attackingEnemySeen; -// enemySeen = attackingEnemySeen; -// //printf("Da hat er wen gefunden:%s\n",enemySeen->getType()->getName(false).c_str()); -// } -// } + if(isUltra || isMega) { + if( attackingEnemySeen!=NULL && unit->getRandom()->randRange(0,2)!=2 ) { + *rangedPtr = attackingEnemySeen; + enemySeen = attackingEnemySeen; + //printf("Da hat er wen gefunden:%s\n",enemySeen->getType()->getName(false).c_str()); + } + } if(result == true) { //const Unit* teamUnit = NULL; diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index c57ad6a1..b44e3482 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -145,10 +145,10 @@ private: //misc bool searchForResource(Unit *unit, const HarvestCommandType *hct); - bool attackerOnSight(const Unit *unit, Unit **enemyPtr); - bool attackableOnSight(const Unit *unit, Unit **enemyPtr, const AttackSkillType *ast); - bool attackableOnRange(const Unit *unit, Unit **enemyPtr, const AttackSkillType *ast); - bool unitOnRange(const Unit *unit, int range, Unit **enemyPtr, const AttackSkillType *ast); + bool attackerOnSight(Unit *unit, Unit **enemyPtr); + bool attackableOnSight(Unit *unit, Unit **enemyPtr, const AttackSkillType *ast); + bool attackableOnRange(Unit *unit, Unit **enemyPtr, const AttackSkillType *ast); + bool unitOnRange(Unit *unit, int range, Unit **enemyPtr, const AttackSkillType *ast); void enemiesAtDistance(const Unit *unit, const Unit *priorityUnit, int distance, vector &enemies); Unit * findPeerUnitBuilder(Unit *unit);