2024-04-24 20:13 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0001132Spring engineGeneralpublic2008-10-14 20:47
Reporterlurker 
Assigned Toimbaczek 
PrioritynormalSeverityfeatureReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0001132: [PATCH] Make Decloaking Require Los
DescriptionAny unit that is tested in the decloak radius has to have a large enough LOS radius to reach the cloaker before a decloak is triggered. Notably, this fixes 0 los units-as-missiles decloaking targets.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • diff file icon 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);
    
    diff file icon DecloakNeedsLos.diff (4,374 bytes) 2008-10-14 12:20 +

-Relationships
+Relationships

-Notes

~0002874

lurker (reporter)

Last edited: 2008-10-14 12:27

s/targets/units they happen to get close to/
I don't have the required permissions to edit my own submission.

~0002891

imbaczek (reporter)

applied in r6729, thanks.
+Notes

-Issue History
Date Modified Username Field Change
2008-10-14 12:20 lurker New Issue
2008-10-14 12:20 lurker File Added: DecloakNeedsLos.diff
2008-10-14 12:26 lurker Note Added: 0002874
2008-10-14 12:27 lurker Note Edited: 0002874
2008-10-14 20:47 imbaczek Status new => resolved
2008-10-14 20:47 imbaczek Resolution open => fixed
2008-10-14 20:47 imbaczek Assigned To => imbaczek
2008-10-14 20:47 imbaczek Note Added: 0002891
+Issue History