Skip to content

Commit

Permalink
Merge pull request #592 from stefanhendriks/bugfix/361/ornithopters-s…
Browse files Browse the repository at this point in the history
…hould-not-friendly-fire

Air units should no longer damage self or friendly units
  • Loading branch information
stefanhendriks authored Nov 10, 2024
2 parents c307d16 + a743a54 commit 598669c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ target_compile_options(${PROJECT_NAME}
"-Werror"
"-Wall"
"-Wextra"
"-Wno-dangling-reference"
"-Wno-deprecated"
"-Wpedantic"
"-Wnon-virtual-dtor"
"-Wuseless-cast"
Expand Down
26 changes: 20 additions & 6 deletions gameobjects/projectiles/bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,31 @@ bool cBullet::isSonicWave() const {
return iType == BULLET_SHIMMER;
}

/**
* Returns true if air unit exists and can be damaged. Takes same team into account.
*
* @param unitIdOnAirLayer
* @return
*/
bool cBullet::doesAirUnitTakeDamage(int unitIdOnAirLayer) const {
if (unitIdOnAirLayer < 0) return false; // invalid id, so no
if (unitIdOnAirLayer < 0) return false;
if (iOwnerUnit > 0 && unitIdOnAirLayer == iOwnerUnit) return false; // do not damage self

cUnit &airUnit = unit[unitIdOnAirLayer];
if (iOwnerUnit > 0) {
cUnit &ownerUnit = unit[iOwnerUnit];
if (ownerUnit.isValid() && ownerUnit.getPlayer()->isSameTeamAs(airUnit.getPlayer())) {
return false;
}
if (iOwnerUnit <= 0) {
return false; // no air unit to damage
}

cUnit &ownerUnit = unit[iOwnerUnit];
if (!ownerUnit.isValid()) {
return false; // unit is not 'valid'
}

if (ownerUnit.getPlayer()->isSameTeamAs(airUnit.getPlayer())) {
return false; // Do not damage same team
}

// yes, an air unit is present, is not of my team and can should be damaged.
return true;
}

Expand Down

0 comments on commit 598669c

Please sign in to comment.