Permalink
Browse files

fix target avoidance for cloaked units

  • Loading branch information...
rt
rt committed Nov 27, 2018
1 parent 82a205f commit 984bc302e5f33e8ae069e68cfd02ebe526576ece
@@ -418,7 +418,8 @@ void CWeapon::UpdateFire()
return;
// pre-check if we got enough resources (so CobBlockShot gets only called when really possible to shoot)
auto shotRes = SResourcePack(weaponDef->metalcost, weaponDef->energycost);
const SResourcePack shotRes = {weaponDef->metalcost, weaponDef->energycost};
if (!weaponDef->stockpile && !owner->HaveResources(shotRes))
return;
@@ -468,9 +469,8 @@ bool CWeapon::UpdateStockpile()
if (numStockpileQued > 0) {
const float p = 1.0f / weaponDef->stockpileTime;
auto res = SResourcePack(weaponDef->metalcost * p, weaponDef->energycost * p);
if (owner->UseResources(res))
if (owner->UseResources({weaponDef->metalcost * p, weaponDef->energycost * p}))
buildPercent += p;
if (buildPercent >= 1) {
@@ -32,6 +32,7 @@ WEAPONTAG(bool, avoidFriendly).defaultValue(true);
WEAPONTAG(bool, avoidFeature).defaultValue(true);
WEAPONTAG(bool, avoidNeutral).defaultValue(false);
WEAPONTAG(bool, avoidGround).defaultValue(true);
WEAPONTAG(bool, avoidCloaked).defaultValue(false);
WEAPONDUMMYTAG(bool, collideEnemy).defaultValue(true);
WEAPONDUMMYTAG(bool, collideFriendly).defaultValue(true);
WEAPONDUMMYTAG(bool, collideFeature).defaultValue(true);
@@ -187,6 +187,8 @@ struct WeaponDef
bool avoidFeature; // if true, try to avoid features while aiming
bool avoidNeutral; // if true, try to avoid neutral units while aiming
bool avoidGround; // if true, try to avoid ground while aiming
bool avoidCloaked; // if true, try to avoid cloaked units while aiming
/**
* If nonzero, targetting units will TryTarget at the edge of collision sphere
* (radius*tag value, [-1;1]) instead of its centre.
@@ -174,6 +174,7 @@ void CWeaponLoader::InitWeapon(CUnit* owner, CWeapon* weapon, const UnitDefWeapo
weapon->avoidFlags |= (Collision::NOFRIENDLIES * (!weaponDef->avoidFriendly));
weapon->avoidFlags |= (Collision::NOFEATURES * (!weaponDef->avoidFeature));
weapon->avoidFlags |= (Collision::NOGROUND * (!weaponDef->avoidGround));
weapon->avoidFlags |= (Collision::NOCLOAKED * (!weaponDef->avoidCloaked));
weapon->damages = DynDamageArray::IncRef(&weaponDef->damages);

0 comments on commit 984bc30

Please sign in to comment.