Skip to content

Commit 95546be

Browse files
committed
fix potential bug in dogfights
previous commit could have played weird when long range weapons are disabled and engagement distance is set to cautious. moved check for weapon disabled state to compensate, and set projectileInFlight flag more appropriately. this will be applied whether the weapon fired is a beam or missile, as beam weapons have a burn duration, and only do the hit calculation on the last frame.
1 parent 51ef55c commit 95546be

1 file changed

Lines changed: 38 additions & 40 deletions

File tree

‎src/Geoscape/DogfightState.cpp‎

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -875,16 +875,13 @@ void DogfightState::update()
875875
}
876876
}
877877
// Check if projectile passed it's maximum range.
878-
if (p->getGlobalType() == CWPGT_MISSILE)
878+
if (p->getGlobalType() == CWPGT_MISSILE && p->getPosition() / 8 >= p->getRange())
879879
{
880-
if (p->getPosition() / 8 >= p->getRange())
881-
{
882-
p->remove();
883-
}
884-
else if (!_ufo->isCrashed())
885-
{
886-
projectileInFlight = true;
887-
}
880+
p->remove();
881+
}
882+
else if (!_ufo->isCrashed())
883+
{
884+
projectileInFlight = true;
888885
}
889886
}
890887
// Projectiles fired by UFO.
@@ -951,13 +948,20 @@ void DogfightState::update()
951948
{
952949
if (i == 0)
953950
{
954-
fireWeapon1();
951+
if (_weapon1Enabled)
952+
{
953+
fireWeapon1();
954+
projectileInFlight = true;
955+
}
955956
}
956957
else
957958
{
958-
fireWeapon2();
959+
if (_weapon2Enabled)
960+
{
961+
fireWeapon2();
962+
projectileInFlight = true;
963+
}
959964
}
960-
projectileInFlight = true;
961965
}
962966
else if (wTimer > 0)
963967
{
@@ -1187,24 +1191,21 @@ void DogfightState::update()
11871191
*/
11881192
void DogfightState::fireWeapon1()
11891193
{
1190-
if (_weapon1Enabled)
1194+
CraftWeapon *w1 = _craft->getWeapons()->at(0);
1195+
if (w1->setAmmo(w1->getAmmo() - 1))
11911196
{
1192-
CraftWeapon *w1 = _craft->getWeapons()->at(0);
1193-
if (w1->setAmmo(w1->getAmmo() - 1))
1194-
{
1195-
_w1FireCountdown = _w1FireInterval;
1197+
_w1FireCountdown = _w1FireInterval;
11961198

1197-
std::wostringstream ss;
1198-
ss << w1->getAmmo();
1199-
_txtAmmo1->setText(ss.str());
1199+
std::wostringstream ss;
1200+
ss << w1->getAmmo();
1201+
_txtAmmo1->setText(ss.str());
12001202

1201-
CraftWeaponProjectile *p = w1->fire();
1202-
p->setDirection(D_UP);
1203-
p->setHorizontalPosition(HP_LEFT);
1204-
_projectiles.push_back(p);
1203+
CraftWeaponProjectile *p = w1->fire();
1204+
p->setDirection(D_UP);
1205+
p->setHorizontalPosition(HP_LEFT);
1206+
_projectiles.push_back(p);
12051207

1206-
_game->getMod()->getSound("GEO.CAT", w1->getRules()->getSound())->play();
1207-
}
1208+
_game->getMod()->getSound("GEO.CAT", w1->getRules()->getSound())->play();
12081209
}
12091210
}
12101211

@@ -1214,24 +1215,21 @@ void DogfightState::fireWeapon1()
12141215
*/
12151216
void DogfightState::fireWeapon2()
12161217
{
1217-
if (_weapon2Enabled)
1218+
CraftWeapon *w2 = _craft->getWeapons()->at(1);
1219+
if (w2->setAmmo(w2->getAmmo() - 1))
12181220
{
1219-
CraftWeapon *w2 = _craft->getWeapons()->at(1);
1220-
if (w2->setAmmo(w2->getAmmo() - 1))
1221-
{
1222-
_w2FireCountdown = _w2FireInterval;
1221+
_w2FireCountdown = _w2FireInterval;
12231222

1224-
std::wostringstream ss;
1225-
ss << w2->getAmmo();
1226-
_txtAmmo2->setText(ss.str());
1223+
std::wostringstream ss;
1224+
ss << w2->getAmmo();
1225+
_txtAmmo2->setText(ss.str());
12271226

1228-
CraftWeaponProjectile *p = w2->fire();
1229-
p->setDirection(D_UP);
1230-
p->setHorizontalPosition(HP_RIGHT);
1231-
_projectiles.push_back(p);
1227+
CraftWeaponProjectile *p = w2->fire();
1228+
p->setDirection(D_UP);
1229+
p->setHorizontalPosition(HP_RIGHT);
1230+
_projectiles.push_back(p);
12321231

1233-
_game->getMod()->getSound("GEO.CAT", w2->getRules()->getSound())->play();
1234-
}
1232+
_game->getMod()->getSound("GEO.CAT", w2->getRules()->getSound())->play();
12351233
}
12361234
}
12371235

0 commit comments

Comments
 (0)