Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #4810
  • Loading branch information
ashdnazg committed Jun 17, 2015
1 parent df69e88 commit bf08f39
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions rts/Sim/Weapons/BombDropper.cpp
Expand Up @@ -74,10 +74,10 @@ float CBombDropper::GetPredictedImpactTime(float3 impactPos) const
bool CBombDropper::TestTarget(const float3 pos, const SWeaponTarget& trg) const
{
// assume we can still drop bombs on *partially* submerged targets
if (!dropTorpedoes && TargetUnderWater(trg))
if (!dropTorpedoes && TargetUnderWater(pos, trg))
return false;
// assume we can drop torpedoes on any partially or fully submerged target
if (dropTorpedoes && !TargetInWater(trg))
if (dropTorpedoes && !TargetInWater(pos, trg))
return false;

return CWeapon::TestTarget(pos, trg);
Expand Down
2 changes: 1 addition & 1 deletion rts/Sim/Weapons/Cannon.cpp
Expand Up @@ -73,7 +73,7 @@ void CCannon::UpdateWantedDir()
bool CCannon::HaveFreeLineOfFire(const float3 pos, const SWeaponTarget& trg) const
{
// assume we can still fire at partially submerged targets
if (!weaponDef->waterweapon && TargetUnderWater(trg))
if (!weaponDef->waterweapon && TargetUnderWater(pos, trg))
return false;

if (projectileSpeed == 0) {
Expand Down
4 changes: 2 additions & 2 deletions rts/Sim/Weapons/TorpedoLauncher.cpp
Expand Up @@ -37,10 +37,10 @@ bool CTorpedoLauncher::TestTarget(const float3 pos, const SWeaponTarget& trg) co
// able to, see #3951
//
// land- or air-based launchers cannot target anything not in water
if (weaponMuzzlePos.y > 0.0f && !TargetInWater(trg))
if (weaponMuzzlePos.y > 0.0f && !TargetInWater(pos, trg))
return false;
// water-based launchers cannot target anything not in water unless submissile
if (weaponMuzzlePos.y <= 0.0f && !weaponDef->submissile && !TargetInWater(trg))
if (weaponMuzzlePos.y <= 0.0f && !weaponDef->submissile && !TargetInWater(pos, trg))
return false;

return (CWeapon::TestTarget(pos, trg));
Expand Down
15 changes: 6 additions & 9 deletions rts/Sim/Weapons/Weapon.cpp
Expand Up @@ -750,24 +750,24 @@ void CWeapon::DependentDied(CObject* o)
}


bool CWeapon::TargetUnderWater(const SWeaponTarget& target)
bool CWeapon::TargetUnderWater(const float3 tgtPos, const SWeaponTarget& target)
{
switch (target.type) {
case Target_None: return false;
case Target_Unit: return target.unit->IsUnderWater();
case Target_Pos: return (target.groundPos.y < 0.0f); // consistent with CSolidObject::IsUnderWater (LT)
case Target_Pos: return (tgtPos.y < 0.0f); // consistent with CSolidObject::IsUnderWater (LT)
case Target_Intercept: return (target.intercept->pos.y < 0.0f);
default: return false;
}
}


bool CWeapon::TargetInWater(const SWeaponTarget& target)
bool CWeapon::TargetInWater(const float3 tgtPos, const SWeaponTarget& target)
{
switch (target.type) {
case Target_None: return false;
case Target_Unit: return target.unit->IsInWater();
case Target_Pos: return (target.groundPos.y <= 0.0f); // consistent with CSolidObject::IsInWater (LE)
case Target_Pos: return (tgtPos.y <= 0.0f); // consistent with CSolidObject::IsInWater (LE)
case Target_Intercept: return (target.intercept->pos.y <= 0.0f);
default: return false;
}
Expand Down Expand Up @@ -852,13 +852,10 @@ float3 CWeapon::GetTargetBorderPos(
bool CWeapon::TryTarget(const float3 tgtPos, const SWeaponTarget& trg) const
{
assert(GetLeadTargetPos(trg).SqDistance(tgtPos) < Square(250.f));

if (!TestTarget(tgtPos, trg))
return false;

if (!TestRange(tgtPos, trg))
return false;

//FIXME add a forcedUserTarget (a forced fire mode enabled with ctrl key or something) and skip the tests below then
return HaveFreeLineOfFire(tgtPos, trg);
}
Expand Down Expand Up @@ -921,10 +918,10 @@ bool CWeapon::TestTarget(const float3 tgtPos, const SWeaponTarget& trg) const
// water weapon checks
if (!weaponDef->waterweapon) {
// we cannot pick targets underwater, check where target is in relation to us
if (!owner->IsUnderWater() && TargetUnderWater(trg))
if (!owner->IsUnderWater() && TargetUnderWater(tgtPos, trg))
return false;
// if we are underwater but target is *not* in water, fireSubmersed gets checked
if (owner->IsUnderWater() && TargetInWater(trg))
if (owner->IsUnderWater() && TargetInWater(tgtPos, trg))
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions rts/Sim/Weapons/Weapon.h
Expand Up @@ -40,17 +40,17 @@ class CWeapon : public CObject

public:
/// test if the weapon is able to attack an enemy/mapspot just by its properties (no range check, no FreeLineOfFire check, ...)
virtual bool TestTarget(const float3 pos, const SWeaponTarget& trg) const;
virtual bool TestTarget(const float3 tgtPos, const SWeaponTarget& trg) const;
/// test if the enemy/mapspot is in range/angle
virtual bool TestRange(const float3 pos, const SWeaponTarget& trg) const;
virtual bool TestRange(const float3 tgtPos, const SWeaponTarget& trg) const;
/// test if something is blocking our LineOfFire
virtual bool HaveFreeLineOfFire(const float3 pos, const SWeaponTarget& trg) const;
virtual bool HaveFreeLineOfFire(const float3 tgtPos, const SWeaponTarget& trg) const;

virtual bool CanFire(bool ignoreAngleGood, bool ignoreTargetType, bool ignoreRequestedDir) const;

bool TryTarget(const SWeaponTarget& trg) const;
bool TryTargetRotate(const CUnit* unit, bool userTarget);
bool TryTargetRotate(float3 pos, bool userTarget);
bool TryTargetRotate(float3 tgtPos, bool userTarget);
bool TryTargetHeading(short heading, const SWeaponTarget& trg);

public:
Expand Down Expand Up @@ -85,8 +85,8 @@ class CWeapon : public CObject
virtual float GetPredictedImpactTime(float3 p) const; //< how long time we predict it take for a projectile to reach target

ProjectileParams GetProjectileParams();
static bool TargetUnderWater(const SWeaponTarget&);
static bool TargetInWater(const SWeaponTarget&);
static bool TargetUnderWater(const float3 tgtPos, const SWeaponTarget&);
static bool TargetInWater(const float3 tgtPos, const SWeaponTarget&);

void UpdateWeaponPieces(const bool updateAimFrom = true);
void UpdateWeaponVectors();
Expand All @@ -105,7 +105,7 @@ class CWeapon : public CObject
void HoldIfTargetInvalid();

void SetAttackTarget(const SWeaponTarget& newTarget); //< does not any checks etc. !
bool TryTarget(const float3 pos, const SWeaponTarget& trg) const;
bool TryTarget(const float3 tgtPos, const SWeaponTarget& trg) const;

public:
CUnit* owner;
Expand Down

0 comments on commit bf08f39

Please sign in to comment.