Skip to content

Commit

Permalink
fix #6057
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Oct 25, 2018
1 parent 0292973 commit 836743e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
12 changes: 3 additions & 9 deletions rts/Game/SelectedUnitsHandler.cpp
Expand Up @@ -745,27 +745,21 @@ static const CUnit* targetUnit = nullptr;
static const CFeature* targetFeature = nullptr;


static inline bool CanDamage(const UnitDef* ud)
{
return ((ud->canAttack && !ud->weapons.empty()) || ud->canKamikaze);
}


static inline bool IsBetterLeader(const UnitDef* newDef, const UnitDef* oldDef)
{
// There is a lot more that could be done here to make better
// selections, but the users may prefer simplicity over smarts.

if (targetUnit != nullptr) {
if (targetIsEnemy) {
const bool newCanDamage = CanDamage(newDef);
const bool oldCanDamage = CanDamage(oldDef);
const bool newCanDamage = newDef->CanDamage();
const bool oldCanDamage = oldDef->CanDamage();

if ( newCanDamage && !oldCanDamage)
return true;
if (!newCanDamage && oldCanDamage)
return false;
if (!CanDamage(targetUnit->unitDef)) {
if (!targetUnit->unitDef->CanDamage()) {
if ( newDef->canReclaim && !oldDef->canReclaim)
return true;
if (!newDef->canReclaim && oldDef->canReclaim)
Expand Down
11 changes: 4 additions & 7 deletions rts/Sim/Units/CommandAI/CommandAI.cpp
Expand Up @@ -476,10 +476,7 @@ void CCommandAI::AddCommandDependency(const Command& c) {

bool CCommandAI::IsAttackCapable() const
{
const UnitDef* ud = owner->unitDef;
const bool b = (!ud->weapons.empty() || ud->canKamikaze || (ud->IsFactoryUnit()));

return (ud->canAttack && b);
return (owner->unitDef->CanAttack());
}


Expand Down Expand Up @@ -1499,13 +1496,13 @@ void CCommandAI::SlowUpdate()

int CCommandAI::GetDefaultCmd(const CUnit* pointed, const CFeature* feature)
{
if (pointed) {
if (pointed != nullptr) {
if (!teamHandler.Ally(gu->myAllyTeam, pointed->allyteam)) {
if (IsAttackCapable()) {
if (IsAttackCapable())
return CMD_ATTACK;
}
}
}

return CMD_STOP;
}

Expand Down
5 changes: 4 additions & 1 deletion rts/Sim/Units/UnitDef.h
Expand Up @@ -70,12 +70,15 @@ struct UnitDef: public SolidObjectDef

bool DontLand() const { return (dlHoverFactor >= 0.0f); }
bool RequireMoveDef() const { return (canmove && speed > 0.0f && !canfly); }
bool CanChangeFireState() const { return (canFireControl && (HasWeapons() || canKamikaze || IsFactoryUnit())); }
bool CanChangeFireState() const { return (canFireControl && (canKamikaze || HasWeapons() || IsFactoryUnit())); }

bool HasWeapons() const { return (HasWeapon(0)); }
bool HasWeapon(unsigned int idx) const { return (weapons[idx].def != nullptr); }
bool HasBomberWeapon(unsigned int idx) const;

bool CanAttack() const { return (canAttack && (canKamikaze || HasWeapons() || IsFactoryUnit())); }
bool CanDamage() const { return (canKamikaze || (canAttack && HasWeapons())); }

unsigned int NumWeapons() const {
unsigned int n = 0;

Expand Down

0 comments on commit 836743e

Please sign in to comment.