Skip to content

Commit

Permalink
fix #4830: weapon target flipping
Browse files Browse the repository at this point in the history
  • Loading branch information
jK committed Jun 21, 2015
1 parent ec90085 commit ed3804b
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions rts/Sim/Weapons/Weapon.cpp
Expand Up @@ -636,24 +636,21 @@ bool CWeapon::AutoTarget()
// search for other in range targets
lastTargetRetry = gs->frameNum;

std::multimap<float, CUnit*> targets;
std::multimap<float, CUnit*>::const_iterator targetsIt;

const CUnit* avoidUnit = ( avoidTarget && currentTarget.type == Target_Unit) ? currentTarget.unit : nullptr;
const CUnit* ignorUnit = (!avoidTarget && currentTarget.type == Target_Unit) ? currentTarget.unit : nullptr;
const CUnit* avoidUnit = (avoidTarget && currentTarget.type == Target_Unit) ? currentTarget.unit : nullptr;

// NOTE:
// sorts by INCREASING order of priority, so lower equals better
// <targets> can contain duplicates if a unit covers multiple quads
// <targets> is normally sorted such that all bad TC units are at the
// end, but Lua can mess with the ordering arbitrarily
std::multimap<float, CUnit*> targets;
CGameHelper::GenerateWeaponTargets(this, avoidUnit, targets);

CUnit* goodTargetUnit = nullptr;
CUnit* badTargetUnit = nullptr;

for (targetsIt = targets.begin(); targetsIt != targets.end(); ++targetsIt) {
CUnit* unit = targetsIt->second;
for (auto targetsPair: targets) {
CUnit* unit = targetsPair.second;

// save the "best" bad target in case we have no other
// good targets (of higher priority) left in <targets>
Expand All @@ -667,9 +664,6 @@ bool CWeapon::AutoTarget()
if (unit->IsNeutral() && (owner->fireState < FIRESTATE_FIREATNEUTRAL))
continue;

if (unit == ignorUnit)
continue;

if (isBadTarget) {
badTargetUnit = unit;
} else {
Expand Down

0 comments on commit ed3804b

Please sign in to comment.