Skip to content

Commit

Permalink
Fix dogfight logic so TFTD depth checks actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
SupSuper committed Nov 27, 2016
1 parent 84de73f commit d5d3127
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 82 deletions.
10 changes: 5 additions & 5 deletions bin/standard/xcom2/crafts.rul
Expand Up @@ -12,7 +12,7 @@ crafts: #done
refuelRate: 50
transferTime: 72
score: 200
maxDepth: 3
maxAltitude: 4
battlescapeTerrainData:
name: TRITON
mapDataSets:
Expand Down Expand Up @@ -49,7 +49,7 @@ crafts: #done
refuelRate: 50
transferTime: 96
score: 250
maxDepth: 2
maxAltitude: 3
- type: STR_MANTA
sprite: 4
fuelMax: 30
Expand All @@ -60,7 +60,7 @@ crafts: #done
refuelItem: STR_ZRBITE
refuelRate: 5
score: 250
maxDepth: 3
maxAltitude: 4
- type: STR_HAMMERHEAD
sprite: 1
fuelMax: 60
Expand All @@ -72,7 +72,7 @@ crafts: #done
refuelItem: STR_ZRBITE
refuelRate: 5
score: 300
maxDepth: 3
maxAltitude: 4
battlescapeTerrainData:
name: HAMMER
mapDataSets:
Expand Down Expand Up @@ -108,7 +108,7 @@ crafts: #done
spacecraft: true
refuelRate: 5
score: 400
maxDepth: 3
maxAltitude: 4
battlescapeTerrainData:
name: LEVIATH
mapDataSets:
Expand Down
46 changes: 31 additions & 15 deletions src/Geoscape/DogfightState.cpp
Expand Up @@ -234,8 +234,8 @@ const int DogfightState::_projectileBlobs[4][6][3] =
*/
DogfightState::DogfightState(GeoscapeState *state, Craft *craft, Ufo *ufo) : _state(state), _craft(craft), _ufo(ufo), _timeout(50), _currentDist(640), _targetDist(560),
_w1FireCountdown(0), _w2FireCountdown(0), _end(false), _destroyUfo(false), _destroyCraft(false), _ufoBreakingOff(false), _weapon1Enabled(true), _weapon2Enabled(true),
_minimized(false), _endDogfight(false), _animatingHit(false), _waitForPoly(false), _ufoSize(0), _craftHeight(0), _currentCraftDamageColor(0), _interceptionNumber(0),
_interceptionsCount(0), _x(0), _y(0), _minimizedIconX(0), _minimizedIconY(0)
_minimized(false), _endDogfight(false), _animatingHit(false), _waitForPoly(false), _waitForAltitude(false), _ufoSize(0), _craftHeight(0), _currentCraftDamageColor(0),
_interceptionNumber(0), _interceptionsCount(0), _x(0), _y(0), _minimizedIconX(0), _minimizedIconY(0)
{
_screen = false;

Expand Down Expand Up @@ -1658,22 +1658,19 @@ void DogfightState::setMinimized(const bool minimized)
*/
void DogfightState::btnMinimizedIconClick(Action *)
{
if (_craft->getDestination()->getSiteDepth() > _craft->getRules()->getMaxDepth())
if (_ufo->getAltitudeInt() > _craft->getRules()->getMaxAltitude())
{
_state->popup(new DogfightErrorState(_craft, tr("STR_UNABLE_TO_ENGAGE_DEPTH")));
setWaitForAltitude(true);
}
else if (_craft->getRules()->isWaterOnly() && !_state->getGlobe()->insideLand(_craft->getLongitude(), _craft->getLatitude()))
{
_state->popup(new DogfightErrorState(_craft, tr("STR_UNABLE_TO_ENGAGE_AIRBORNE")));
setWaitForPoly(true);
}
else
{
bool underwater = _craft->getRules()->getMaxDepth() > 0;
if (underwater && !_state->getGlobe()->insideLand(_craft->getLongitude(), _craft->getLatitude()))
{
_state->popup(new DogfightErrorState(_craft, tr("STR_UNABLE_TO_ENGAGE_AIRBORNE")));
setWaitForPoly(true);
}
else
{
setMinimized(false);
}
setMinimized(false);
}
}

Expand Down Expand Up @@ -1809,11 +1806,20 @@ bool DogfightState::dogfightEnded() const
* Returns the UFO associated to this dogfight.
* @return Returns pointer to UFO object associated to this dogfight.
*/
Ufo* DogfightState::getUfo() const
Ufo *DogfightState::getUfo() const
{
return _ufo;
}

/**
* Returns the craft associated to this dogfight.
* @return Returns pointer to craft object associated to this dogfight.
*/
Craft *DogfightState::getCraft() const
{
return _craft;
}

/**
* Ends the dogfight.
*/
Expand All @@ -1838,9 +1844,19 @@ void DogfightState::setWaitForPoly(bool wait)
_waitForPoly = wait;
}

bool DogfightState::getWaitForPoly()
bool DogfightState::getWaitForPoly() const
{
return _waitForPoly;
}

void DogfightState::setWaitForAltitude(bool wait)
{
_waitForAltitude = wait;
}

bool DogfightState::getWaitForAltitude() const
{
return _waitForAltitude;
}

}
15 changes: 12 additions & 3 deletions src/Geoscape/DogfightState.h
Expand Up @@ -55,7 +55,8 @@ class DogfightState : public State
Craft *_craft;
Ufo *_ufo;
int _timeout, _currentDist, _targetDist, _w1FireInterval, _w2FireInterval, _w1FireCountdown, _w2FireCountdown;
bool _end, _destroyUfo, _destroyCraft, _ufoBreakingOff, _weapon1Enabled, _weapon2Enabled, _minimized, _endDogfight, _animatingHit, _waitForPoly;
bool _end, _destroyUfo, _destroyCraft, _ufoBreakingOff, _weapon1Enabled, _weapon2Enabled;
bool _minimized, _endDogfight, _animatingHit, _waitForPoly, _waitForAltitude;
std::vector<CraftWeaponProjectile*> _projectiles;
static const int _ufoBlobs[8][13][13];
static const int _projectileBlobs[4][6][3];
Expand Down Expand Up @@ -138,9 +139,17 @@ class DogfightState : public State
/// Checks if the dogfight should be ended.
bool dogfightEnded() const;
/// Gets pointer to the UFO in this dogfight.
Ufo* getUfo() const;
Ufo *getUfo() const;
/// Gets pointer to the craft in this dogfight.
Craft *getCraft() const;
/// Waits until the UFO reaches a polygon.
void setWaitForPoly(bool wait);
bool getWaitForPoly();
/// Waits until the UFO reaches a polygon.
bool getWaitForPoly() const;
/// Waits until the UFO reaches the right altitude.
void setWaitForAltitude(bool wait);
/// Waits until the UFO reaches the right altutude.
bool getWaitForAltitude() const;
};

}
3 changes: 1 addition & 2 deletions src/Geoscape/GeoscapeCraftState.cpp
Expand Up @@ -181,8 +181,7 @@ GeoscapeCraftState::GeoscapeCraftState(Craft *craft, Globe *globe, Waypoint *way
_txtMaxSpeed->setText(tr("STR_MAXIMUM_SPEED_UC").arg(Text::formatNumber(_craft->getRules()->getMaxSpeed())));

std::string altitude = _craft->getAltitude() == "STR_GROUND" ? "STR_GROUNDED" : _craft->getAltitude();
bool underwater = _craft->getRules()->getMaxDepth() > 0;
if (underwater && !_globe->insideLand(_craft->getLongitude(), _craft->getLatitude()))
if (_craft->getRules()->isWaterOnly() && !_globe->insideLand(_craft->getLongitude(), _craft->getLatitude()))
{
altitude = "STR_AIRBORNE";
}
Expand Down
24 changes: 12 additions & 12 deletions src/Geoscape/GeoscapeState.cpp
Expand Up @@ -868,7 +868,6 @@ void GeoscapeState::time5Seconds()
Waypoint *w = dynamic_cast<Waypoint*>((*j)->getDestination());
MissionSite* m = dynamic_cast<MissionSite*>((*j)->getDestination());
AlienBase* b = dynamic_cast<AlienBase*>((*j)->getDestination());
bool underwater = false;
if (u != 0)
{
switch (u->getStatus())
Expand All @@ -881,20 +880,16 @@ void GeoscapeState::time5Seconds()
continue;
}
// Can we actually fight it
if ((*j)->getDestination()->getSiteDepth() > (*j)->getRules()->getMaxDepth())
{
popup(new DogfightErrorState((*j), tr("STR_UNABLE_TO_ENGAGE_DEPTH")));
++j;
continue;
}
else
{
underwater = (*j)->getRules()->getMaxDepth() > 0;
}
if (!(*j)->isInDogfight() && !(*j)->getDistance(u))
{
_dogfightsToBeStarted.push_back(new DogfightState(this, (*j), u));
if (underwater && !_globe->insideLand((*j)->getLongitude(), (*j)->getLatitude()))
if (u->getAltitudeInt() > (*j)->getRules()->getMaxAltitude())
{
popup(new DogfightErrorState((*j), tr("STR_UNABLE_TO_ENGAGE_DEPTH")));
_dogfightsToBeStarted.back()->setMinimized(true);
_dogfightsToBeStarted.back()->setWaitForAltitude(true);
}
else if ((*j)->getRules()->isWaterOnly() && !_globe->insideLand((*j)->getLongitude(), (*j)->getLatitude()))
{
popup(new DogfightErrorState((*j), tr("STR_UNABLE_TO_ENGAGE_AIRBORNE")));
_dogfightsToBeStarted.back()->setMinimized(true);
Expand Down Expand Up @@ -2052,6 +2047,11 @@ void GeoscapeState::handleDogfights()
(*d)->setMinimized(false);
(*d)->setWaitForPoly(false);
}
else if ((*d)->getWaitForAltitude() && (*d)->getUfo()->getAltitudeInt() <= (*d)->getCraft()->getRules()->getMaxAltitude())
{
(*d)->setMinimized(false);
(*d)->setWaitForAltitude(false);
}
else
{
_minimizedDogfights++;
Expand Down
2 changes: 1 addition & 1 deletion src/Geoscape/UfoDetectedState.cpp
Expand Up @@ -151,7 +151,7 @@ UfoDetectedState::UfoDetectedState(Ufo *ufo, GeoscapeState *state, bool detected
const std::vector<std::string> &crafts = _game->getMod()->getCraftsList();
for (std::vector<std::string>::const_iterator i = crafts.begin(); i != crafts.end() && !underwater; ++i)
{
underwater = _game->getMod()->getCraft(*i)->getMaxDepth() > 0;
underwater = _game->getMod()->getCraft(*i)->isWaterOnly();
}
if (underwater && !_state->getGlobe()->insideLand(_ufo->getLongitude(), _ufo->getLatitude()))
{
Expand Down
21 changes: 15 additions & 6 deletions src/Mod/RuleCraft.cpp
Expand Up @@ -28,7 +28,7 @@ namespace OpenXcom
* type of craft.
* @param type String defining the type.
*/
RuleCraft::RuleCraft(const std::string &type) : _type(type), _sprite(-1), _marker(-1), _fuelMax(0), _damageMax(0), _speedMax(0), _accel(0), _weapons(0), _soldiers(0), _vehicles(0), _costBuy(0), _costRent(0), _costSell(0), _repairRate(1), _refuelRate(1), _radarRange(672), _radarChance(100), _sightRange(1696), _transferTime(0), _score(0), _battlescapeTerrainData(0), _spacecraft(false), _listOrder(0), _maxItems(0), _maxDepth(0)
RuleCraft::RuleCraft(const std::string &type) : _type(type), _sprite(-1), _marker(-1), _fuelMax(0), _damageMax(0), _speedMax(0), _accel(0), _weapons(0), _soldiers(0), _vehicles(0), _costBuy(0), _costRent(0), _costSell(0), _repairRate(1), _refuelRate(1), _radarRange(672), _radarChance(100), _sightRange(1696), _transferTime(0), _score(0), _battlescapeTerrainData(0), _spacecraft(false), _listOrder(0), _maxItems(0), _maxAltitude(-1)
{

}
Expand Down Expand Up @@ -91,7 +91,7 @@ void RuleCraft::load(const YAML::Node &node, Mod *mod, int listOrder)
{
_listOrder = listOrder;
}
_maxDepth = node["maxDepth"].as<int>(_maxDepth);
_maxAltitude = node["maxAltitude"].as<int>(_maxAltitude);
_maxItems = node["maxItems"].as<int>(_maxItems);
}

Expand Down Expand Up @@ -348,14 +348,23 @@ int RuleCraft::getMaxItems() const
}

/**
* Gets the maximum depth this craft can dive to.
* @return max depth.
* Gets the maximum altitude this craft can dogfight to.
* @return max altitude (0-4).
*/
int RuleCraft::getMaxDepth() const
int RuleCraft::getMaxAltitude() const
{
return _maxDepth;
return _maxAltitude;
}

/**
* If the craft is underwater, it can only dogfight over polygons.
* TODO: Replace this with its own flag.
* @return underwater or not
*/
bool RuleCraft::isWaterOnly() const
{
return _maxAltitude > -1;
}

}

8 changes: 5 additions & 3 deletions src/Mod/RuleCraft.h
Expand Up @@ -44,7 +44,7 @@ class RuleCraft
int _repairRate, _refuelRate, _radarRange, _radarChance, _sightRange, _transferTime, _score;
RuleTerrain *_battlescapeTerrainData;
bool _spacecraft;
int _listOrder, _maxItems, _maxDepth;
int _listOrder, _maxItems, _maxAltitude;
std::vector<std::vector <int> > _deployment;
public:
/// Creates a blank craft ruleset.
Expand Down Expand Up @@ -107,8 +107,10 @@ class RuleCraft
std::vector<std::vector<int> > &getDeployment();
/// Gets the item limit for this craft.
int getMaxItems() const;
/// checks how deep this craft can go.
int getMaxDepth() const;
/// Gets how high this craft can go.
int getMaxAltitude() const;
/// Gets if this craft only fights on water.
bool isWaterOnly() const;
};

}
13 changes: 2 additions & 11 deletions src/Mod/UfoTrajectory.cpp
Expand Up @@ -17,16 +17,7 @@
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UfoTrajectory.h"

namespace {
const char *altitudeString[] = {
"STR_GROUND",
"STR_VERY_LOW",
"STR_LOW_UC",
"STR_HIGH_UC",
"STR_VERY_HIGH"
};
}
#include "../Savegame/Ufo.h"

namespace YAML
{
Expand Down Expand Up @@ -83,7 +74,7 @@ void UfoTrajectory::load(const YAML::Node &node)
*/
std::string UfoTrajectory::getAltitude(size_t wp) const
{
return altitudeString[_waypoints[wp].altitude];
return Ufo::ALTITUDE_STRING[_waypoints[wp].altitude];
}

}
1 change: 0 additions & 1 deletion src/Savegame/AlienMission.cpp
Expand Up @@ -761,7 +761,6 @@ MissionSite *AlienMission::spawnMissionSite(SavedGame &game, AlienDeployment *de
missionSite->setAlienRace(_race);
missionSite->setTexture(area.texture);
missionSite->setCity(area.name);
missionSite->setSiteDepth(RNG::generate(deployment->getMinSiteDepth(), deployment->getMaxSiteDepth()));
game.getMissionSites()->push_back(missionSite);
return missionSite;
}
Expand Down
18 changes: 0 additions & 18 deletions src/Savegame/Target.cpp
Expand Up @@ -187,22 +187,4 @@ double Target::getDistance(const Target *target) const
return acos(cos(_lat) * cos(target->getLatitude()) * cos(target->getLongitude() - _lon) + sin(_lat) * sin(target->getLatitude()));
}

/**
* Gets the mission site's depth.
* @return the depth of the site.
*/
int Target::getSiteDepth() const
{
return _depth;
}

/**
* Sets the mission site's depth.
* @param depth the depth we want.
*/
void Target::setSiteDepth(int depth)
{
_depth = depth;
}

}
4 changes: 0 additions & 4 deletions src/Savegame/Target.h
Expand Up @@ -68,10 +68,6 @@ class Target
std::vector<Target*> *getFollowers();
/// Gets the distance to another target.
double getDistance(const Target *target) const;
/// Gets the depth of the target.
int getSiteDepth() const;
/// Sets the depth of the target.
void setSiteDepth(int depth);
};

}

0 comments on commit d5d3127

Please sign in to comment.