Permalink
Browse files

Merge pull request #1208 from MeridianOXC/obstacle-indicator

Obstacle indicator
  • Loading branch information...
SupSuper committed Nov 19, 2018
2 parents 8437311 + 0d8f592 commit 9bba3c34078807715ff73c0a3127251326035025
@@ -602,7 +602,7 @@ void AIModule::setupAmbush()
// make sure we can't be seen here.
Position target;
if (!_save->getTileEngine()->canTargetUnit(&origin, tile, &target, _aggroTarget, _unit) && !getSpottingUnits(pos))
if (!_save->getTileEngine()->canTargetUnit(&origin, tile, &target, _aggroTarget, false, _unit) && !getSpottingUnits(pos))
{
_save->getPathfinding()->calculate(_unit, pos);
int ambushTUs = _save->getPathfinding()->getTotalTUCost();
@@ -658,7 +658,7 @@ void AIModule::setupAmbush()
Tile *tile = _save->getTile(currentPos);
Position target;
// do a virtual fire calculation
if (_save->getTileEngine()->canTargetUnit(&origin, tile, &target, _unit, _aggroTarget))
if (_save->getTileEngine()->canTargetUnit(&origin, tile, &target, _unit, false, _aggroTarget))
{
// if we can virtually fire at the hypothetical target, we know which way to face.
_ambushAction->finalFacing = _save->getTileEngine()->getDirectionTo(_ambushAction->target, currentPos);
@@ -1003,14 +1003,14 @@ int AIModule::getSpottingUnits(const Position& pos) const
Position targetVoxel;
if (checking)
{
if (_save->getTileEngine()->canTargetUnit(&originVoxel, _save->getTile(pos), &targetVoxel, *i, _unit))
if (_save->getTileEngine()->canTargetUnit(&originVoxel, _save->getTile(pos), &targetVoxel, *i, false, _unit))
{
tally++;
}
}
else
{
if (_save->getTileEngine()->canTargetUnit(&originVoxel, _save->getTile(pos), &targetVoxel, *i))
if (_save->getTileEngine()->canTargetUnit(&originVoxel, _save->getTile(pos), &targetVoxel, *i, false))
{
tally++;
}
@@ -1048,7 +1048,7 @@ int AIModule::selectNearestTarget()
action.weapon = _attackAction->weapon;
action.target = (*i)->getPosition();
Position origin = _save->getTileEngine()->getOriginVoxel(action, 0);
valid = _save->getTileEngine()->canTargetUnit(&origin, (*i)->getTile(), &target, _unit);
valid = _save->getTileEngine()->canTargetUnit(&origin, (*i)->getTile(), &target, _unit, false);
}
else
{
@@ -1443,7 +1443,7 @@ bool AIModule::findFirePoint()
// 4 because -2 is eyes and 2 below that is the rifle (or at least that's my understanding)
Position(8,8, _unit->getHeight() + _unit->getFloatHeight() - tile->getTerrainLevel() - 4);
if (_save->getTileEngine()->canTargetUnit(&origin, _aggroTarget->getTile(), &target, _unit))
if (_save->getTileEngine()->canTargetUnit(&origin, _aggroTarget->getTile(), &target, _unit, false))
{
_save->getPathfinding()->calculate(_unit, pos);
// can move here
@@ -2098,7 +2098,7 @@ bool AIModule::getNodeOfBestEfficacy(BattleAction *action)
}
int dist = _save->getTileEngine()->distance((*i)->getPosition(), _unit->getPosition());
if (dist <= 20 && dist > action->weapon->getRules()->getExplosionRadius() &&
_save->getTileEngine()->canTargetTile(&originVoxel, _save->getTile((*i)->getPosition()), O_FLOOR, &targetVoxel, _unit))
_save->getTileEngine()->canTargetTile(&originVoxel, _save->getTile((*i)->getPosition()), O_FLOOR, &targetVoxel, _unit, false))
{
int nodePoints = 0;
for (std::vector<BattleUnit*>::const_iterator j = _save->getUnits()->begin(); j != _save->getUnits()->end(); ++j)
@@ -2107,7 +2107,7 @@ bool AIModule::getNodeOfBestEfficacy(BattleAction *action)
if (!(*j)->isOut() && dist < action->weapon->getRules()->getExplosionRadius())
{
Position targetOriginVoxel = _save->getTileEngine()->getSightOriginVoxel(*j);
if (_save->getTileEngine()->canTargetTile(&targetOriginVoxel, _save->getTile((*i)->getPosition()), O_FLOOR, &targetVoxel, *j))
if (_save->getTileEngine()->canTargetTile(&targetOriginVoxel, _save->getTile((*i)->getPosition()), O_FLOOR, &targetVoxel, *j, false))
{
if ((_unit->getFaction() == FACTION_HOSTILE && (*j)->getFaction() != FACTION_HOSTILE) ||
(_unit->getFaction() == FACTION_NEUTRAL && (*j)->getFaction() == FACTION_HOSTILE))
@@ -1402,6 +1402,8 @@ void BattlescapeGame::primaryAction(Position pos)
{
bool bPreviewed = Options::battleNewPreviewPath != PATH_NONE;
getMap()->resetObstacles();
if (_currentAction.targeting && _save->getSelectedUnit())
{
if (_currentAction.type == BA_LAUNCH)
@@ -74,7 +74,7 @@ namespace OpenXcom
* @param y Y position in pixels.
* @param visibleMapHeight Current visible map height.
*/
Map::Map(Game *game, int width, int height, int x, int y, int visibleMapHeight) : InteractiveSurface(width, height, x, y), _game(game), _arrow(0), _selectorX(0), _selectorY(0), _mouseX(0), _mouseY(0), _cursorType(CT_NORMAL), _cursorSize(1), _animFrame(0), _projectile(0), _projectileInFOV(false), _explosionInFOV(false), _launch(false), _visibleMapHeight(visibleMapHeight), _unitDying(false), _smoothingEngaged(false), _flashScreen(false)
Map::Map(Game *game, int width, int height, int x, int y, int visibleMapHeight) : InteractiveSurface(width, height, x, y), _game(game), _arrow(0), _selectorX(0), _selectorY(0), _mouseX(0), _mouseY(0), _cursorType(CT_NORMAL), _cursorSize(1), _animFrame(0), _projectile(0), _projectileInFOV(false), _explosionInFOV(false), _launch(false), _visibleMapHeight(visibleMapHeight), _unitDying(false), _smoothingEngaged(false), _flashScreen(false), _showObstacles(false)
{
_iconHeight = _game->getMod()->getInterface("battlescape")->getElement("icons")->h;
_iconWidth = _game->getMod()->getInterface("battlescape")->getElement("icons")->w;
@@ -105,6 +105,9 @@ Map::Map(Game *game, int width, int height, int x, int y, int visibleMapHeight)
_scrollKeyTimer = new Timer(SCROLL_INTERVAL);
_scrollKeyTimer->onTimer((SurfaceHandler)&Map::scrollKey);
_camera->setScrollTimer(_scrollMouseTimer, _scrollKeyTimer);
_obstacleTimer = new Timer(2500);
_obstacleTimer->stop();
_obstacleTimer->onTimer((SurfaceHandler)&Map::disableObstacles);
_txtAccuracy = new Text(24, 9, 0, 0);
_txtAccuracy->setSmall();
@@ -120,6 +123,7 @@ Map::~Map()
{
delete _scrollMouseTimer;
delete _scrollKeyTimer;
delete _obstacleTimer;
delete _arrow;
delete _message;
delete _camera;
@@ -170,6 +174,7 @@ void Map::think()
{
_scrollMouseTimer->think(0, this);
_scrollKeyTimer->think(0, this);
_obstacleTimer->think(0, this);
}
/**
@@ -257,9 +262,10 @@ static bool positionHaveSameXY(Position a, Position b)
* @param currTile
* @param currTileScreenPosition
* @param shade
* @param obstacleShade unitShade override for no LOF obstacle indicator
* @param topLayer
*/
void Map::drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, Position currTileScreenPosition, int shade, bool topLayer)
void Map::drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, Position currTileScreenPosition, int shade, int obstacleShade, bool topLayer)
{
const int tileFoorWidth = 32;
const int tileFoorHeight = 16;
@@ -450,6 +456,10 @@ void Map::drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, Position cu
calculateWalkingOffset(bu, &offset, &shadeOffset);
int tileShade = currTile->isDiscovered(2) ? currTile->getShade() : 16;
int unitShade = (tileShade * (16 - shadeOffset) + shade * shadeOffset) / 16;
if (!moving && unitTile->getObstacle(4))
{
unitShade = obstacleShade;
}
tmpSurface->blitNShade(surface, tileScreenPosition.x + offset.x - _spriteWidth / 2, tileScreenPosition.y + offset.y, unitShade, mask);
// draw fire
if (bu->getFire() > 0)
@@ -487,7 +497,7 @@ void Map::drawTerrain(Surface *surface)
int bulletLowX=16000, bulletLowY=16000, bulletLowZ=16000, bulletHighX=0, bulletHighY=0, bulletHighZ=0;
int dummy;
BattleUnit *unit = 0;
int tileShade, wallShade, tileColor;
int tileShade, wallShade, tileColor, obstacleShade;
static const int arrowBob[8] = {0,1,2,1,0,1,2,1};
NumberText *_numWaypid = 0;
@@ -636,10 +646,21 @@ void Map::drawTerrain(Surface *surface)
if (tile->isDiscovered(2))
{
tileShade = tile->getShade();
obstacleShade = tileShade;
if (_showObstacles)
{
if (tile->isObstacle())
{
if (tileShade > 7) obstacleShade = 7;
if (tileShade < 2) obstacleShade = 2;
obstacleShade += (arrowBob[_animFrame] * 2 - 2);
}
}
}
else
{
tileShade = 16;
obstacleShade = 16;
unit = 0;
}
@@ -648,7 +669,12 @@ void Map::drawTerrain(Surface *surface)
// Draw floor
tmpSurface = tile->getSprite(O_FLOOR);
if (tmpSurface)
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_FLOOR)->getYOffset(), tileShade, false);
{
if (tile->getObstacle(O_FLOOR))
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_FLOOR)->getYOffset(), obstacleShade, false);
else
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_FLOOR)->getYOffset(), tileShade, false);
}
unit = tile->getUnit();
// Draw cursor back
@@ -692,7 +718,7 @@ void Map::drawTerrain(Surface *surface)
for (int b = 0; b < backPosSize; ++b)
{
drawUnit(surface, _save->getTile(mapPosition + backPos[b]), tile, screenPosition, tileShade, topLayer);
drawUnit(surface, _save->getTile(mapPosition + backPos[b]), tile, screenPosition, tileShade, obstacleShade, topLayer);
}
// Draw walls
@@ -707,7 +733,10 @@ void Map::drawTerrain(Surface *surface)
wallShade = tile->getShade();
else
wallShade = tileShade;
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_WESTWALL)->getYOffset(), wallShade, false);
if (tile->getObstacle(O_WESTWALL))
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_WESTWALL)->getYOffset(), obstacleShade, false);
else
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_WESTWALL)->getYOffset(), wallShade, false);
}
// Draw north wall
tmpSurface = tile->getSprite(O_NORTHWALL);
@@ -718,21 +747,22 @@ void Map::drawTerrain(Surface *surface)
wallShade = tile->getShade();
else
wallShade = tileShade;
if (tile->getMapData(O_WESTWALL))
{
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_NORTHWALL)->getYOffset(), wallShade, true);
}
if (tile->getObstacle(O_NORTHWALL))
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_NORTHWALL)->getYOffset(), obstacleShade, tile->getMapData(O_WESTWALL) != 0);
else
{
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_NORTHWALL)->getYOffset(), wallShade, false);
}
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_NORTHWALL)->getYOffset(), wallShade, tile->getMapData(O_WESTWALL) != 0);
}
// Draw object
if (tile->getMapData(O_OBJECT) && (tile->getMapData(O_OBJECT)->getBigWall() < 6 || tile->getMapData(O_OBJECT)->getBigWall() == 9))
{
tmpSurface = tile->getSprite(O_OBJECT);
if (tmpSurface)
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_OBJECT)->getYOffset(), tileShade, false);
{
if (tile->getObstacle(O_OBJECT))
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_OBJECT)->getYOffset(), obstacleShade, false);
else
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_OBJECT)->getYOffset(), tileShade, false);
}
}
// draw an item on top of the floor (if any)
int sprite = tile->getTopItemSprite();
@@ -833,7 +863,7 @@ void Map::drawTerrain(Surface *surface)
}
unit = tile->getUnit();
// Draw soldier from this tile or below
drawUnit(surface, tile, tile, screenPosition, tileShade, topLayer);
drawUnit(surface, tile, tile, screenPosition, tileShade, obstacleShade, topLayer);
// special handling for a moving unit in forground of tile.
const int frontPosSize = 5;
@@ -848,7 +878,7 @@ void Map::drawTerrain(Surface *surface)
for (int f = 0; f < frontPosSize; ++f)
{
drawUnit(surface, _save->getTile(mapPosition + frontPos[f]), tile, screenPosition, tileShade, topLayer);
drawUnit(surface, _save->getTile(mapPosition + frontPos[f]), tile, screenPosition, tileShade, obstacleShade, topLayer);
}
// Draw smoke/fire
@@ -928,7 +958,12 @@ void Map::drawTerrain(Surface *surface)
{
tmpSurface = tile->getSprite(O_OBJECT);
if (tmpSurface)
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_OBJECT)->getYOffset(), tileShade, false);
{
if (tile->getObstacle(O_OBJECT))
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_OBJECT)->getYOffset(), obstacleShade, false);
else
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_OBJECT)->getYOffset(), tileShade, false);
}
}
}
// Draw cursor front
@@ -1727,4 +1762,44 @@ bool Map::getBlastFlash() const
return _flashScreen;
}
/**
* Resets obstacle markers.
*/
void Map::resetObstacles(void)
{
for (int z = 0; z < _save->getMapSizeZ(); z++)
for (int y = 0; y < _save->getMapSizeY(); y++)
for (int x = 0; x < _save->getMapSizeX(); x++)
{
Tile *tile = _save->getTile(Position(x, y, z));
if (tile) tile->resetObstacle();
}
_showObstacles = false;
}
/**
* Enables obstacle markers.
*/
void Map::enableObstacles(void)
{
_showObstacles = true;
if (_obstacleTimer)
{
_obstacleTimer->stop();
_obstacleTimer->start();
}
}
/**
* Disables obstacle markers.
*/
void Map::disableObstacles(void)
{
_showObstacles = false;
if (_obstacleTimer)
{
_obstacleTimer->stop();
}
}
}
@@ -46,7 +46,7 @@ class Map : public InteractiveSurface
private:
static const int SCROLL_INTERVAL = 15;
static const int BULLET_SPRITES = 35;
Timer *_scrollMouseTimer, *_scrollKeyTimer;
Timer *_scrollMouseTimer, *_scrollKeyTimer, *_obstacleTimer;
Game *_game;
SavedBattleGame *_save;
Surface *_arrow;
@@ -69,11 +69,12 @@ class Map : public InteractiveSurface
Text *_txtAccuracy;
SurfaceSet *_projectileSet;
void drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, Position tileScreenPosition, int shade, bool topLayer);
void drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, Position tileScreenPosition, int shade, int obstacleShade, bool topLayer);
void drawTerrain(Surface *surface);
int getTerrainLevel(const Position& pos, int size) const;
int _iconHeight, _iconWidth, _messageColor;
const std::vector<Uint8> *_transparencies;
bool _showObstacles;
public:
/// Creates a new map at the specified position and size.
Map(Game* game, int width, int height, int x, int y, int visibleMapHeight);
@@ -151,6 +152,12 @@ class Map : public InteractiveSurface
void setBlastFlash(bool flash);
/// Check if the screen is flashing this.
bool getBlastFlash() const;
/// Resets obstacle markers.
void resetObstacles();
/// Enables obstacle markers.
void enableObstacles();
/// Disables obstacle markers.
void disableObstacles();
};
}
Oops, something went wrong.

0 comments on commit 9bba3c3

Please sign in to comment.