Skip to content

Commit

Permalink
Show max craft range when launching from base
Browse files Browse the repository at this point in the history
  • Loading branch information
SupSuper committed Nov 19, 2018
1 parent c90d2f8 commit 8437311
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
34 changes: 30 additions & 4 deletions src/Geoscape/Globe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ struct CreateShadow
* @param x X position in pixels.
* @param y Y position in pixels.
*/
Globe::Globe(Game* game, int cenX, int cenY, int width, int height, int x, int y) : InteractiveSurface(width, height, x, y), _rotLon(0.0), _rotLat(0.0), _hoverLon(0.0), _hoverLat(0.0), _cenX(cenX), _cenY(cenY), _game(game), _hover(false), _blink(-1),
Globe::Globe(Game* game, int cenX, int cenY, int width, int height, int x, int y) : InteractiveSurface(width, height, x, y), _cenX(cenX), _cenY(cenY), _rotLon(0.0), _rotLat(0.0), _hoverLon(0.0), _hoverLat(0.0), _craftLon(0.0), _craftLat(0.0), _craftRange(0.0), _game(game), _hover(false), _craft(false), _blink(-1),
_isMouseScrolling(false), _isMouseScrolled(false), _xBeforeMouseScrolling(0), _yBeforeMouseScrolling(0), _lonBeforeMouseScrolling(0.0), _latBeforeMouseScrolling(0.0), _mouseScrollingStartTime(0), _totalMouseMoveX(0), _totalMouseMoveY(0), _mouseMovedOverThreshold(false)
{
_rules = game->getMod()->getGlobe();
Expand Down Expand Up @@ -1071,6 +1071,22 @@ void Globe::XuLine(Surface* surface, Surface* src, double x1, double y1, double
void Globe::drawRadars()
{
_radars->clear();

// Draw craft circle instead of radar circles to avoid confusion
if (_craft)
{
_radars->lock();

if (_craftRange < M_PI)
{
drawGlobeCircle(_craftLat, _craftLon, _craftRange, 64);
drawGlobeCircle(_craftLat, _craftLon, _craftRange - 0.025, 64, 2);
}

_radars->unlock();
return;
}

if (!Options::globeRadarLines)
return;

Expand Down Expand Up @@ -1124,7 +1140,7 @@ void Globe::drawRadars()

for (std::vector<Craft*>::iterator j = (*i)->getCrafts()->begin(); j != (*i)->getCrafts()->end(); ++j)
{
if ((*j)->getStatus()!= "STR_OUT")
if ((*j)->getStatus() != "STR_OUT")
continue;
lat=(*j)->getLatitude();
lon=(*j)->getLongitude();
Expand All @@ -1140,11 +1156,12 @@ void Globe::drawRadars()
/**
* Draw globe range circle
*/
void Globe::drawGlobeCircle(double lat, double lon, double radius, int segments)
void Globe::drawGlobeCircle(double lat, double lon, double radius, int segments, int frac)
{
double x, y, x2 = 0, y2 = 0;
double lat1, lon1;
double seg = M_PI / (static_cast<double>(segments) / 2);
int i = 0;
for (double az = 0; az <= M_PI*2+0.01; az+=seg) //48 circle segments
{
//calculating sphere-projected circle
Expand All @@ -1157,9 +1174,10 @@ void Globe::drawGlobeCircle(double lat, double lon, double radius, int segments)
y2=y;
continue;
}
if (!pointBack(lon1,lat1))
if (!pointBack(lon1,lat1) && i % frac == 0)
XuLine(_radars, this, x, y, x2, y2, 6);
x2=x; y2=y;
i++;
}
}

Expand Down Expand Up @@ -1884,4 +1902,12 @@ void Globe::stopScrolling(Action *action)
action->setMouseAction(_xBeforeMouseScrolling, _yBeforeMouseScrolling, getX(), getY());
}

void Globe::setCraftRange(double lon, double lat, double range)
{
_craft = (range > 0.0);
_craftLon = lon;
_craftLat = lat;
_craftRange = range;
}

}
11 changes: 7 additions & 4 deletions src/Geoscape/Globe.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ class Globe : public InteractiveSurface

RuleGlobe *_rules;
double _cenLon, _cenLat, _rotLon, _rotLat, _hoverLon, _hoverLat;
double _craftLon, _craftLat, _craftRange;
Sint16 _cenX, _cenY;
size_t _zoom, _zoomOld, _zoomTexture;
SurfaceSet *_texture, *_markerSet;
Game *_game;
Surface *_markers, *_countries, *_radars;
bool _hover;
bool _hover, _craft;
int _blink;
Timer *_blinkTimer, *_rotTimer;
std::list<Polygon*> _cacheLand;
Expand Down Expand Up @@ -93,7 +94,7 @@ class Globe : public InteractiveSurface
/// Get position of sun relative to given position in polar cords and date.
Cord getSunDirection(double lon, double lat) const;
/// Draw globe range circle.
void drawGlobeCircle(double lat, double lon, double radius, int segments);
void drawGlobeCircle(double lat, double lon, double radius, int segments, int frac = 1);
/// Special "transparent" line.
void XuLine(Surface* surface, Surface* src, double x1, double y1, double x2, double y2, int shade);
/// Draw line on globe surface.
Expand All @@ -102,6 +103,8 @@ class Globe : public InteractiveSurface
void drawPath(Surface *surface, double lon1, double lat1, double lon2, double lat2);
/// Draw target marker.
void drawTarget(Target *target, Surface *surface);
/// Set up the radius of earth and stuff.
void setupRadii(int width, int height);
public:

static Uint8 COUNTRY_LABEL_COLOR;
Expand Down Expand Up @@ -201,12 +204,12 @@ class Globe : public InteractiveSurface
void setNewBaseHoverPos(double lon, double lat);
/// Turns on new base hover mode.
void setNewBaseHover(bool hover);
/// Sets craft range mode.
void setCraftRange(double lon, double lat, double range);
/// set the _radarLines variable
void toggleRadarLines();
/// Update the resolution settings, we just resized the window.
void resize();
/// Set up the radius of earth and stuff.
void setupRadii(int width, int height);
/// Move the mouse back to where it started after we finish drag scrolling.
void stopScrolling(Action *action);
};
Expand Down
8 changes: 7 additions & 1 deletion src/Geoscape/SelectDestinationState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,20 @@ SelectDestinationState::SelectDestinationState(Craft *craft, Globe *globe) : _cr
_btnCydonia->setText(tr("STR_CYDONIA"));
_btnCydonia->onMouseClick((ActionHandler)&SelectDestinationState::btnCydoniaClick);
}

if (_craft->getStatus() != "STR_OUT")
{
_globe->setCraftRange(_craft->getLongitude(), _craft->getLatitude(), _craft->getBaseRange());
_globe->invalidate();
}
}

/**
*
*/
SelectDestinationState::~SelectDestinationState()
{

_globe->setCraftRange(0.0, 0.0, 0.0);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Savegame/Craft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,16 @@ int Craft::getFuelLimit(Base *base) const
return (int)floor(getFuelConsumption(_rules->getMaxSpeed()) * getDistance(base) / _speedMaxRadian);
}

/**
* Returns the maximum range the craft can travel
* from its origin base on its current fuel.
* @return Range in radians.
*/
double Craft::getBaseRange() const
{
return _fuel / 2.0 / getFuelConsumption(_rules->getMaxSpeed()) * _speedMaxRadian;
}

/**
* Sends the craft back to its origin base.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Savegame/Craft.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class Craft : public MovingTarget
int getFuelLimit() const;
/// Gets the craft's minimum fuel limit to go to a base.
int getFuelLimit(Base *base) const;

double getBaseRange() const;
/// Returns the craft to its base.
void returnToBase();
/// Checks if a target is detected by the craft's radar.
Expand Down

0 comments on commit 8437311

Please sign in to comment.