DecloakNeedsLos.diff (4,374 bytes)
2008-10-14 12:20
Index: rts/Game/GameHelper.cpp
===================================================================
--- rts/Game/GameHelper.cpp (revision 6713)
+++ rts/Game/GameHelper.cpp (working copy)
@@ -24,6 +24,7 @@
#include "Sim/Misc/LosHandler.h"
#include "Sim/Misc/QuadField.h"
#include "Sim/Misc/RadarHandler.h"
+#include "Sim/ModInfo.h"
#include "Sim/Projectiles/ExplosionGenerator.h"
#include "Sim/Projectiles/Projectile.h"
#include "Sim/Units/CommandAI/CommandAI.h"
@@ -531,12 +532,14 @@
}
CUnit* CGameHelper::GetClosestEnemyUnitNoLosTest(const float3 &pos, float radius,
- int searchAllyteam, bool sphere)
+ int searchAllyteam, bool sphere, bool canBeBlind)
{
const int tempNum = gs->tempNum++;
CUnit* closeUnit = NULL;
+ float losFactor = (SQUARE_SIZE * (1 << modInfo.losMipLevel));
+
if (sphere) { // includes target radius
float closeDist = radius;
std::vector<int> quads = qf->GetQuads(pos, radius + uh->maxUnitRadius);
@@ -550,7 +553,8 @@
!gs->Ally(searchAllyteam, unit->allyteam)) {
unit->tempNum = tempNum;
const float dist = (pos - unit->midPos).Length() - unit->radius;
- if (dist <= closeDist){
+ if (dist <= closeDist &&
+ (canBeBlind || unit->losRadius * losFactor > dist)){
closeDist = dist;
closeUnit = unit;
}
@@ -571,7 +575,8 @@
!gs->Ally(searchAllyteam, unit->allyteam)) {
unit->tempNum = tempNum;
const float sqDist = (pos - unit->midPos).SqLength2D();
- if (sqDist <= closeDistSq){
+ if (sqDist <= closeDistSq &&
+ (canBeBlind || unit->losRadius * losFactor > sqDist)){
closeDistSq = sqDist;
closeUnit = unit;
}
Index: rts/Game/GameHelper.h
===================================================================
--- rts/Game/GameHelper.h (revision 6713)
+++ rts/Game/GameHelper.h (working copy)
@@ -36,7 +36,7 @@
void GetEnemyUnits(const float3& pos,float radius,int searchAllyteam,std::vector<int>& found);
CUnit* GetClosestUnit(const float3& pos,float radius);
CUnit* GetClosestEnemyUnit(const float3& pos,float radius,int searchAllyteam);
- CUnit* GetClosestEnemyUnitNoLosTest(const float3& pos,float radius,int searchAllyteam,bool sphere);
+ CUnit* GetClosestEnemyUnitNoLosTest(const float3& pos,float radius,int searchAllyteam,bool sphere,bool canBeBlind);
CUnit* GetClosestFriendlyUnit(const float3& pos,float radius,int searchAllyteam);
CUnit* GetClosestEnemyAircraft(const float3& pos,float radius,int searchAllyteam);
void GenerateTargets(const CWeapon *attacker, CUnit* lastTarget,std::map<float,CUnit*> &targets);
Index: rts/Lua/LuaSyncedRead.cpp
===================================================================
--- rts/Lua/LuaSyncedRead.cpp (revision 6713)
+++ rts/Lua/LuaSyncedRead.cpp (working copy)
@@ -2137,7 +2137,7 @@
target = helper->GetClosestEnemyUnit(unit->pos, range, unit->allyteam);
} else {
target = helper->GetClosestEnemyUnitNoLosTest(unit->pos, range,
- unit->allyteam, false);
+ unit->allyteam, false, true);
}
if (target) {
lua_pushnumber(L, target->id);
Index: rts/Sim/Units/Unit.cpp
===================================================================
--- rts/Sim/Units/Unit.cpp (revision 6713)
+++ rts/Sim/Units/Unit.cpp (working copy)
@@ -811,7 +811,7 @@
else if (wantCloak || (scriptCloak >= 1)) {
if ((decloakDistance > 0.0f) &&
helper->GetClosestEnemyUnitNoLosTest(midPos, decloakDistance,
- allyteam, unitDef->decloakSpherical)) {
+ allyteam, unitDef->decloakSpherical, false)) {
curCloakTimeout = gs->frameNum + cloakTimeout;
isCloaked = false;
}
@@ -862,7 +862,7 @@
if (unitDef->canKamikaze) {
if (fireState >= 2) {
- CUnit* u = helper->GetClosestEnemyUnitNoLosTest(pos, unitDef->kamikazeDist, allyteam, false);
+ CUnit* u = helper->GetClosestEnemyUnitNoLosTest(pos, unitDef->kamikazeDist, allyteam, false, true);
if (u && u->physicalState != CSolidObject::Flying && u->speed.dot(pos - u->pos) <= 0) {
// self destruct when unit start moving away from mine, should maximize damage
KillUnit(true, false, NULL);