Skip to content

Commit

Permalink
Fix lighting weapon firing when out of range or obstructed
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Apr 26, 2024
1 parent 9a10893 commit 1234939
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions Source/Units/SecondGun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2161,32 +2161,60 @@ terWeaponLighting::~terWeaponLighting() = default;
void terWeaponLighting::quant()
{
WeaponDirectionalBase::quant();

if (!target_ || !isSwitchedOn()) {
//No target active currently
if (lighting_) {
releaseLighting();
}
return;
}

if (isSwitchedOn() && target_ && owner()->alive()) {
xassert(owner());

xassert(owner());
Vect3f target_pos = target_->position();
if (!owner()->alive() || !fireDistanceCheck(target_pos)) {
//Not on / weapon owner is not alive / target too far
if (lighting_) {
Vect3f v0,v1;
aimController()->getTargetingPosition(v0,v1);
v1 = target_->position();

std::vector<Vect3f> vect;
vect.push_back(v1);
//On default ET AttrLib Eflair has 2.0, Impaler 4.0
lighting_->Init(v0, vect, setup().laserWidth / 2.0f);
releaseLighting();
}
target_ = nullptr;
return;
}

if (lighting_) {
Vect3f v0,v1;
aimController()->getTargetingPosition(v0,v1);

std::vector<Vect3f> vect;
vect.push_back(target_pos);
//On default ET AttrLib Eflair has 2.0, Impaler 4.0
lighting_->Init(v0, vect, setup().laserWidth / 2.0f);
}

if (fireEnabled()) {
startFireDelay();

if (fireEnabled()) {
startFireDelay();

int fire_status = 0;
bool fire = fireTest(target_pos,target_,fire_status);
if (!fire || (fire_status & (
LEGION_FIRE_STATUS_GROUND_OBSTACLE |
LEGION_FIRE_STATUS_FRIENDLY_FIRE |
LEGION_FIRE_STATUS_BORDER_ANGLE |
LEGION_FIRE_STATUS_DISTANCE |
LEGION_FIRE_STATUS_FIELD_OBSTACLE |
LEGION_FIRE_STATUS_BAD_TARGET
))) {
//Target is no longer valid
target_ = nullptr;
} else {
//If lighting is not created we don't damage, so we give enough time for it to show
//the fire is delayed thanks to startFireDelay() so it wont kill before arc is displayed
if (!lighting_) {
lighting_ = new cLighting;
terScene->AttachObj(lighting_);
} else {
target_->SetHotCount(5);

//We consider setup's damage data to be per sec, divide by fireDelay to get damage to apply
//as this weapon is constant firing and not oneshot like most weapons
float factor = max(0.01f, static_cast<float>(setup().fireDelay) / 1000.0f);
Expand All @@ -2197,13 +2225,13 @@ void terWeaponLighting::quant()

owner()->DestroyLink();
destroyLink();
if (!target_) {
return;
}
}
}
} else if (lighting_) {
releaseLighting();

//If no target then destroy lighting
if (lighting_ && !target_) {
releaseLighting();
}
}
}

Expand Down

0 comments on commit 1234939

Please sign in to comment.