Skip to content

Commit

Permalink
fix target avoidance for cloaked units
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Nov 27, 2018
1 parent 82a205f commit 984bc30
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rts/Sim/Weapons/Weapon.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions rts/Sim/Weapons/WeaponDef.cpp
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions rts/Sim/Weapons/WeaponDef.h
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions rts/Sim/Weapons/WeaponLoader.cpp
Expand Up @@ -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);

Expand Down

0 comments on commit 984bc30

Please sign in to comment.