Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang tidy #1286

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Battlescape/AIModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
#include <climits>
#include <algorithm>
#include <cmath>
#include "AIModule.h"
#include "../Savegame/BattleItem.h"
#include "../Savegame/Node.h"
Expand Down Expand Up @@ -1505,7 +1506,7 @@ bool AIModule::findFirePoint()
* @param grenade Is the explosion coming from a grenade?
* @return True if it is worthwhile creating an explosion in the target position.
*/
bool AIModule::explosiveEfficacy(Position targetPos, BattleUnit *attackingUnit, int radius, int diff, bool grenade) const
bool AIModule::explosiveEfficacy(const Position& targetPos, BattleUnit *attackingUnit, int radius, int diff, bool grenade) const
{
// i hate the player and i want him dead, but i don't want to piss him off.
Mod *mod = _save->getBattleState()->getGame()->getMod();
Expand Down Expand Up @@ -1878,7 +1879,7 @@ bool AIModule::psiAction()
int cost = psiWeaponRules->getTUUse();
if (!psiWeaponRules->getFlatRate())
{
cost = (int)floor(_unit->getBaseStats()->tu * cost / 100.0f);
cost = (int)std::floor(_unit->getBaseStats()->tu * cost / 100.0f);
}
bool LOSRequired = psiWeaponRules->isLOSRequired();

Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/AIModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AIModule
/// Selects a suitable position from which to attack.
bool findFirePoint();
/// Decides if we should throw a grenade/launch a missile to this position.
bool explosiveEfficacy(Position targetPos, BattleUnit *attackingUnit, int radius, int diff, bool grenade = false) const;
bool explosiveEfficacy(const Position& targetPos, BattleUnit *attackingUnit, int radius, int diff, bool grenade = false) const;
bool getNodeOfBestEfficacy(BattleAction *action);
/// Attempts to take a melee attack/charge an enemy we can see.
void meleeAction();
Expand Down
9 changes: 5 additions & 4 deletions src/Battlescape/BattlescapeGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cmath>
#include <sstream>
#include "BattlescapeGame.h"
#include "BattlescapeState.h"
Expand Down Expand Up @@ -1426,7 +1427,7 @@ bool BattlescapeGame::isBusy() const
* Activates primary action (left click).
* @param pos Position on the map.
*/
void BattlescapeGame::primaryAction(Position pos)
void BattlescapeGame::primaryAction(const Position& pos)
{
bool bPreviewed = Options::battleNewPreviewPath != PATH_NONE;

Expand Down Expand Up @@ -1571,7 +1572,7 @@ void BattlescapeGame::primaryAction(Position pos)
* Activates secondary action (right click).
* @param pos Position on the map.
*/
void BattlescapeGame::secondaryAction(Position pos)
void BattlescapeGame::secondaryAction(const Position& pos)
{
// -= turn to or open door =-
_currentAction.target = pos;
Expand Down Expand Up @@ -1608,7 +1609,7 @@ void BattlescapeGame::psiButtonAction()
_currentAction.TU = _currentAction.weapon->getRules()->getTUUse();
if (!_currentAction.weapon->getRules()->getFlatRate())
{
_currentAction.TU = (int)floor(_save->getSelectedUnit()->getBaseStats()->tu * _currentAction.TU / 100.0f);
_currentAction.TU = (int)std::floor(_save->getSelectedUnit()->getBaseStats()->tu * _currentAction.TU / 100.0f);
}
setupCursor();
}
Expand Down Expand Up @@ -1670,7 +1671,7 @@ void BattlescapeGame::setTUReserved(BattleActionType tur)
* @param newItem Bool whether this is a new item.
* @param removeItem Bool whether to remove the item from the owner.
*/
void BattlescapeGame::dropItem(Position position, BattleItem *item, bool newItem, bool removeItem)
void BattlescapeGame::dropItem(const Position& position, BattleItem *item, bool newItem, bool removeItem)
{
const Position& p = position;

Expand Down
6 changes: 3 additions & 3 deletions src/Battlescape/BattlescapeGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class BattlescapeGame
/// Handles unit AI.
void handleAI(BattleUnit *unit);
/// Drops an item and affects it with gravity.
void dropItem(Position position, BattleItem *item, bool newItem = false, bool removeItem = false);
void dropItem(const Position& position, BattleItem *item, bool newItem = false, bool removeItem = false);
/// Converts a unit into a unit of another type.
BattleUnit *convertUnit(BattleUnit *unit);
/// Handles kneeling action.
Expand All @@ -137,9 +137,9 @@ class BattlescapeGame
/// Determines whether there is an action currently going on.
bool isBusy() const;
/// Activates primary action (left click).
void primaryAction(Position pos);
void primaryAction(const Position& pos);
/// Activates secondary action (right click).
void secondaryAction(Position pos);
void secondaryAction(const Position& pos);
/// Handler for the blaster launcher button.
void launchAction();
/// Handler for the psi button.
Expand Down
8 changes: 4 additions & 4 deletions src/Battlescape/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void Camera::setViewLevel(int viewlevel)
* @param mapPos Position to center on.
* @param redraw Redraw map or not.
*/
void Camera::centerOnPosition(Position mapPos, bool redraw)
void Camera::centerOnPosition(const Position& mapPos, bool redraw)
{
Position screenPos;
_center = mapPos;
Expand Down Expand Up @@ -458,7 +458,7 @@ void Camera::convertScreenToMap(int screenX, int screenY, int *mapX, int *mapY)
* @param mapPos X,Y,Z coordinates on the map.
* @param screenPos Screen position.
*/
void Camera::convertMapToScreen(Position mapPos, Position *screenPos) const
void Camera::convertMapToScreen(const Position& mapPos, Position *screenPos) const
{
screenPos->z = 0; // not used
screenPos->x = mapPos.x * (_spriteWidth / 2) - mapPos.y * (_spriteWidth / 2);
Expand All @@ -470,7 +470,7 @@ void Camera::convertMapToScreen(Position mapPos, Position *screenPos) const
* @param voxelPos X,Y,Z coordinates of the voxel.
* @param screenPos Screen position.
*/
void Camera::convertVoxelToScreen(Position voxelPos, Position *screenPos) const
void Camera::convertVoxelToScreen(const Position& voxelPos, Position *screenPos) const
{
Position mapPosition = Position(voxelPos.x / 16, voxelPos.y / 16, voxelPos.z / 24);
convertMapToScreen(mapPosition, screenPos);
Expand Down Expand Up @@ -555,7 +555,7 @@ bool Camera::getShowAllLayers() const
* @param boundary True if it's for caching calculation
* @return True if the map coordinates are on screen.
*/
bool Camera::isOnScreen(Position mapPos, const bool unitWalking, const int unitSize, const bool boundary) const
bool Camera::isOnScreen(const Position& mapPos, const bool unitWalking, const int unitSize, const bool boundary) const
{
Position screenPos;
convertMapToScreen(mapPos, &screenPos);
Expand Down
8 changes: 4 additions & 4 deletions src/Battlescape/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class Camera
/// Sets the view level.
void setViewLevel(int viewlevel);
/// Converts map coordinates to screen coordinates.
void convertMapToScreen(Position mapPos, Position *screenPos) const;
void convertMapToScreen(const Position& mapPos, Position *screenPos) const;
/// Converts voxel coordinates to screen coordinates.
void convertVoxelToScreen(Position voxelPos, Position *screenPos) const;
void convertVoxelToScreen(const Position& voxelPos, Position *screenPos) const;
/// Converts screen coordinates to map coordinates.
void convertScreenToMap(int screenX, int screenY, int *mapX, int *mapY) const;
/// Center map on a position.
void centerOnPosition(Position pos, bool redraw = true);
void centerOnPosition(const Position& pos, bool redraw = true);
/// Gets map's center position.
Position getCenterPosition();
/// Gets the map displayed level.
Expand All @@ -101,7 +101,7 @@ class Camera
/// Checks if the camera is showing all map layers.
bool getShowAllLayers() const;
/// Checks if map coordinates X,Y,Z are on screen.
bool isOnScreen(Position mapPos, const bool unitWalking, const int unitSize, const bool boundary) const;
bool isOnScreen(const Position& mapPos, const bool unitWalking, const int unitSize, const bool boundary) const;
/// Resize the viewable area.
void resize();
/// stop mouse scrolling.
Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/Explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const int Explosion::BULLET_FRAMES = 10;
* @param big Flag to indicate it is a bullet hit (false), or a real explosion (true).
* @param hit True for melee and psi attacks.
*/
Explosion::Explosion(Position position, int startFrame, int frameDelay, bool big, bool hit) : _position(position), _currentFrame(startFrame), _startFrame(startFrame), _frameDelay(frameDelay), _big(big), _hit(hit)
Explosion::Explosion(const Position& position, int startFrame, int frameDelay, bool big, bool hit) : _position(position), _currentFrame(startFrame), _startFrame(startFrame), _frameDelay(frameDelay), _big(big), _hit(hit)
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/Explosion.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Explosion
static const int EXPLODE_FRAMES;
static const int BULLET_FRAMES;
/// Creates a new Explosion.
Explosion(Position _position, int startFrame, int frameDelay = 0, bool big = false, bool hit = false);
Explosion(const Position& _position, int startFrame, int frameDelay = 0, bool big = false, bool hit = false);
/// Cleans up the Explosion.
~Explosion();
/// Moves the Explosion on one frame.
Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/ExplosionBState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace OpenXcom
* @param tile Tile the explosion is on.
* @param lowerWeapon Whether the unit causing this explosion should now lower their weapon.
*/
ExplosionBState::ExplosionBState(BattlescapeGame *parent, Position center, BattleItem *item, BattleUnit *unit, Tile *tile, bool lowerWeapon, bool cosmetic) : BattleState(parent), _unit(unit), _center(center), _item(item), _tile(tile), _power(0), _areaOfEffect(false), _lowerWeapon(lowerWeapon), _cosmetic(cosmetic)
ExplosionBState::ExplosionBState(BattlescapeGame *parent, const Position& center, BattleItem *item, BattleUnit *unit, Tile *tile, bool lowerWeapon, bool cosmetic) : BattleState(parent), _unit(unit), _center(center), _item(item), _tile(tile), _power(0), _areaOfEffect(false), _lowerWeapon(lowerWeapon), _cosmetic(cosmetic)
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/ExplosionBState.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ExplosionBState : public BattleState
void explode();
public:
/// Creates a new ExplosionBState class.
ExplosionBState(BattlescapeGame *parent, Position center, BattleItem *item, BattleUnit *unit, Tile *tile = 0, bool lowerWeapon = false, bool cosmetic = false);
ExplosionBState(BattlescapeGame *parent, const Position& center, BattleItem *item, BattleUnit *unit, Tile *tile = 0, bool lowerWeapon = false, bool cosmetic = false);
/// Cleans up the ExplosionBState.
~ExplosionBState();
/// Initializes the state.
Expand Down
4 changes: 2 additions & 2 deletions src/Battlescape/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void Map::setPalette(SDL_Color *colors, int firstcolor, int ncolors)
/**
* Check two positions if have same XY cords
*/
static bool positionHaveSameXY(Position a, Position b)
static bool positionHaveSameXY(const Position& a, const Position& b)
{
return a.x == b.x && a.y == b.y;
}
Expand All @@ -265,7 +265,7 @@ static bool positionHaveSameXY(Position a, Position b)
* @param obstacleShade unitShade override for no LOF obstacle indicator
* @param topLayer
*/
void Map::drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, Position currTileScreenPosition, int shade, int obstacleShade, bool topLayer)
void Map::drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, const Position& currTileScreenPosition, int shade, int obstacleShade, bool topLayer)
{
const int tileFoorWidth = 32;
const int tileFoorHeight = 16;
Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Map : public InteractiveSurface
Text *_txtAccuracy;
SurfaceSet *_projectileSet;

void drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, Position tileScreenPosition, int shade, int obstacleShade, bool topLayer);
void drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, const Position& tileScreenPosition, int shade, int obstacleShade, bool topLayer);
void drawTerrain(Surface *surface);
int getTerrainLevel(const Position& pos, int size) const;
int _iconHeight, _iconWidth, _messageColor;
Expand Down
12 changes: 6 additions & 6 deletions src/Battlescape/Pathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Pathfinding::~Pathfinding()
* @param pos Position.
* @return Pointer to node.
*/
PathfindingNode *Pathfinding::getNode(Position pos)
PathfindingNode *Pathfinding::getNode(const Position& pos)
{
return &_nodes[_save->getTileIndex(pos)];
}
Expand Down Expand Up @@ -189,7 +189,7 @@ void Pathfinding::calculate(BattleUnit *unit, Position endPosition, BattleUnit *
* @param maxTUCost Maximum time units the path can cost.
* @return True if a path exists, false otherwise.
*/
bool Pathfinding::aStarPath(Position startPosition, Position endPosition, BattleUnit *target, bool sneak, int maxTUCost)
bool Pathfinding::aStarPath(const Position& startPosition, const Position& endPosition, BattleUnit *target, bool sneak, int maxTUCost)
{
// reset every node, so we have to check them all
for (std::vector<PathfindingNode>::iterator it = _nodes.begin(); it != _nodes.end(); ++it)
Expand Down Expand Up @@ -255,7 +255,7 @@ bool Pathfinding::aStarPath(Position startPosition, Position endPosition, Battle
* @param missile Is this a guided missile?
* @return TU cost or 255 if movement is impossible.
*/
int Pathfinding::getTUCost(Position startPosition, int direction, Position *endPosition, BattleUnit *unit, BattleUnit *target, bool missile)
int Pathfinding::getTUCost(const Position& startPosition, int direction, Position *endPosition, BattleUnit *unit, BattleUnit *target, bool missile)
{
_unit = unit;
directionToVector(direction, endPosition);
Expand Down Expand Up @@ -527,7 +527,7 @@ void Pathfinding::directionToVector(int direction, Position *vector)
* @param vector Pointer to a position (which acts as a vector).
* @param dir Resulting direction.
*/
void Pathfinding::vectorToDirection(Position vector, int &dir)
void Pathfinding::vectorToDirection(const Position& vector, int &dir)
{
dir = -1;
int x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
Expand Down Expand Up @@ -798,7 +798,7 @@ bool Pathfinding::canFallDown(Tile *here, int size) const
* @param endPosition The position we wanna reach.
* @return True if the unit is going up a stairs.
*/
bool Pathfinding::isOnStairs(Position startPosition, Position endPosition) const
bool Pathfinding::isOnStairs(const Position& startPosition, const Position& endPosition) const
{
//condition 1 : endposition has to the south a terrainlevel -16 object (upper part of the stairs)
if (_save->getTile(endPosition + Position(0, 1, 0)) && _save->getTile(endPosition + Position(0, 1, 0))->getTerrainLevel() == -16)
Expand Down Expand Up @@ -1024,7 +1024,7 @@ bool Pathfinding::removePreview()
* @param maxTUCost Maximum time units the path can cost.
* @return True if a path exists, false otherwise.
*/
bool Pathfinding::bresenhamPath(Position origin, Position target, BattleUnit *targetUnit, bool sneak, int maxTUCost)
bool Pathfinding::bresenhamPath(const Position& origin, const Position& target, BattleUnit *targetUnit, bool sneak, int maxTUCost)
{
int xd[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int yd[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
Expand Down
12 changes: 6 additions & 6 deletions src/Battlescape/Pathfinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ class Pathfinding
bool _modifierUsed;
MovementType _movementType;
/// Gets the node at certain position.
PathfindingNode *getNode(Position pos);
PathfindingNode *getNode(const Position& pos);
/// Determines whether a tile blocks a certain movementType.
bool isBlocked(Tile *tile, const int part, BattleUnit *missileTarget, int bigWallExclusion = -1) const;
/// Tries to find a straight line path between two positions.
bool bresenhamPath(Position origin, Position target, BattleUnit *missileTarget, bool sneak = false, int maxTUCost = 1000);
bool bresenhamPath(const Position& origin, const Position& target, BattleUnit *missileTarget, bool sneak = false, int maxTUCost = 1000);
/// Tries to find a path between two positions.
bool aStarPath(Position origin, Position target, BattleUnit *missileTarget, bool sneak = false, int maxTUCost = 1000);
bool aStarPath(const Position& origin, const Position& target, BattleUnit *missileTarget, bool sneak = false, int maxTUCost = 1000);
/// Determines whether a unit can fall down from this tile.
bool canFallDown(Tile *destinationTile) const;
/// Determines whether a unit can fall down from this tile.
bool canFallDown(Tile *destinationTile, int size) const;
std::vector<int> _path;
public:
/// Determines whether the unit is going up a stairs.
bool isOnStairs(Position startPosition, Position endPosition) const;
bool isOnStairs(const Position& startPosition, const Position& endPosition) const;
/// Determines whether or not movement between starttile and endtile is possible in the direction.
bool isBlocked(Tile *startTile, Tile *endTile, const int direction, BattleUnit *missileTarget);
static const int DIR_UP = 8;
Expand All @@ -78,13 +78,13 @@ class Pathfinding
/// Converts direction to a vector.
static void directionToVector(int direction, Position *vector);
/// Converts a vector to a direction.
static void vectorToDirection(Position vector, int &dir);
static void vectorToDirection(const Position& vector, int &dir);
/// Checks whether a path is ready and gives the first direction.
int getStartDirection() const;
/// Dequeues a direction.
int dequeuePath();
/// Gets the TU cost to move from 1 tile to the other.
int getTUCost(Position startPosition, int direction, Position *endPosition, BattleUnit *unit, BattleUnit *target, bool missile);
int getTUCost(const Position& startPosition, int direction, Position *endPosition, BattleUnit *unit, BattleUnit *target, bool missile);
/// Aborts the current path.
void abortPath();
/// Gets the strafe move setting.
Expand Down
4 changes: 2 additions & 2 deletions src/Battlescape/PathfindingNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OpenXcom
* Sets up a PathfindingNode.
* @param pos Position.
*/
PathfindingNode::PathfindingNode(Position pos) : _pos(pos), _checked(0), _tuCost(0), _prevNode(0), _prevDir(0), _tuGuess(0), _openentry(0)
PathfindingNode::PathfindingNode(const Position& pos) : _pos(pos), _checked(0), _tuCost(0), _prevNode(0), _prevDir(0), _tuGuess(0), _openentry(0)
{

}
Expand Down Expand Up @@ -105,7 +105,7 @@ int PathfindingNode::getPrevDir() const
* @param prevDir The direction FROM the previous node.
* @param target The target position (used to update our guess cost).
*/
void PathfindingNode::connect(int tuCost, PathfindingNode* prevNode, int prevDir, Position target)
void PathfindingNode::connect(int tuCost, PathfindingNode* prevNode, int prevDir, const Position& target)
{
_tuCost = tuCost;
_prevNode = prevNode;
Expand Down
4 changes: 2 additions & 2 deletions src/Battlescape/PathfindingNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PathfindingNode
friend class PathfindingOpenSet;
public:
/// Creates a new PathfindingNode class.
PathfindingNode(Position pos);
PathfindingNode(const Position& pos);
/// Cleans up the PathfindingNode.
~PathfindingNode();
/// Gets the node position.
Expand All @@ -70,7 +70,7 @@ class PathfindingNode
#endif

/// Connects to previous node along the path.
void connect(int tuCost, PathfindingNode* prevNode, int prevDir, Position target);
void connect(int tuCost, PathfindingNode* prevNode, int prevDir, const Position& target);
/// Connects to previous node along a visit.
void connect(int tuCost, PathfindingNode* prevNode, int prevDir);
};
Expand Down
4 changes: 2 additions & 2 deletions src/Battlescape/Projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace OpenXcom
* @param targetVoxel Position the projectile is targeting.
* @param ammo the ammo that produced this projectile, where applicable.
*/
Projectile::Projectile(Mod *mod, SavedBattleGame *save, BattleAction action, Position origin, Position targetVoxel, BattleItem *ammo) : _mod(mod), _save(save), _action(action), _origin(origin), _targetVoxel(targetVoxel), _position(0), _bulletSprite(-1), _reversed(false), _vaporColor(-1), _vaporDensity(-1), _vaporProbability(5)
Projectile::Projectile(Mod *mod, SavedBattleGame *save, BattleAction action, const Position& origin, const Position& targetVoxel, BattleItem *ammo) : _mod(mod), _save(save), _action(action), _origin(origin), _targetVoxel(targetVoxel), _position(0), _bulletSprite(-1), _reversed(false), _vaporColor(-1), _vaporDensity(-1), _vaporProbability(5)
{
// this is the number of pixels the sprite will move between frames
_speed = Options::battleFireSpeed;
Expand Down Expand Up @@ -331,7 +331,7 @@ int Projectile::calculateThrow(double accuracy)
* @param keepRange Whether range affects accuracy.
* @param extendLine should this line get extended to maximum distance?
*/
void Projectile::applyAccuracy(Position origin, Position *target, double accuracy, bool keepRange, bool extendLine)
void Projectile::applyAccuracy(const Position& origin, Position *target, double accuracy, bool keepRange, bool extendLine)
{
int xdiff = origin.x - target->x;
int ydiff = origin.y - target->y;
Expand Down