Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Air units should no longer damage self or friendly units #592

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading