Skip to content

Commit

Permalink
Add missing const across the code base
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Solodovnikov <[email protected]>
  • Loading branch information
ManManson committed Jan 10, 2024
1 parent e40b8ee commit c4e3ef8
Show file tree
Hide file tree
Showing 31 changed files with 100 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/advvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void avUpdateTiles()
}

// ------------------------------------------------------------------------------------
UDWORD avGetObjLightLevel(BASE_OBJECT *psObj, UDWORD origLevel)
UDWORD avGetObjLightLevel(BASE_OBJECT const *psObj, UDWORD origLevel)
{
float div = (float)psObj->visibleForLocalDisplay() / 255.f;
unsigned int lowest = origLevel / START_DIVIDE;
Expand Down
2 changes: 1 addition & 1 deletion src/advvis.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "basedef.h"

void avUpdateTiles();
UDWORD avGetObjLightLevel(BASE_OBJECT *psObj, UDWORD origLevel);
UDWORD avGetObjLightLevel(BASE_OBJECT const *psObj, UDWORD origLevel);
void setRevealStatus(bool val);
bool getRevealStatus();
void preProcessVisibility();
Expand Down
16 changes: 8 additions & 8 deletions src/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ int aiBestNearestTarget(DROID *psDroid, BASE_OBJECT **ppsObj, int weapon_slot, i
}

// Are there a lot of bullets heading towards the droid?
static bool aiDroidIsProbablyDoomed(DROID *psDroid, bool isDirect)
static bool aiDroidIsProbablyDoomed(DROID const *psDroid, bool isDirect)
{
if (isDirect)
{
Expand All @@ -760,14 +760,14 @@ static bool aiDroidIsProbablyDoomed(DROID *psDroid, bool isDirect)
}

// Are there a lot of bullets heading towards the structure?
static bool aiStructureIsProbablyDoomed(STRUCTURE *psStructure)
static bool aiStructureIsProbablyDoomed(STRUCTURE const *psStructure)
{
return psStructure->expectedDamage > psStructure->body
&& psStructure->expectedDamage - psStructure->body > psStructure->body / 15; // Doomed if projectiles will damage 106.6666666667% of remaining body points.
}

// Are there a lot of bullets heading towards the object?
bool aiObjectIsProbablyDoomed(BASE_OBJECT *psObject, bool isDirect)
bool aiObjectIsProbablyDoomed(BASE_OBJECT const *psObject, bool isDirect)
{
if (psObject->died)
{
Expand All @@ -777,9 +777,9 @@ bool aiObjectIsProbablyDoomed(BASE_OBJECT *psObject, bool isDirect)
switch (psObject->type)
{
case OBJ_DROID:
return aiDroidIsProbablyDoomed((DROID *)psObject, isDirect);
return aiDroidIsProbablyDoomed((DROID const *)psObject, isDirect);
case OBJ_STRUCTURE:
return aiStructureIsProbablyDoomed((STRUCTURE *)psObject);
return aiStructureIsProbablyDoomed((STRUCTURE const *)psObject);
default:
return false;
}
Expand Down Expand Up @@ -1239,9 +1239,9 @@ void aiUpdateDroid(DROID *psDroid)
}

/* Check if any of our weapons can hit the target... */
bool checkAnyWeaponsTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget)
bool checkAnyWeaponsTarget(BASE_OBJECT const *psObject, BASE_OBJECT const *psTarget)
{
DROID *psDroid = (DROID *) psObject;
DROID const *psDroid = (DROID const *) psObject;
for (int i = 0; i < psDroid->numWeaps; i++)
{
if (validTarget(psObject, psTarget, i))
Expand All @@ -1253,7 +1253,7 @@ bool checkAnyWeaponsTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget)
}

/* Set of rules which determine whether the weapon associated with the object can fire on the propulsion type of the target. */
bool validTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget, int weapon_slot)
bool validTarget(BASE_OBJECT const *psObject, BASE_OBJECT const *psTarget, int weapon_slot)
{
bool bTargetInAir = false, bValidTarget = false;
UBYTE surfaceToAir = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void aiUpdateDroid(DROID *psDroid);
int aiBestNearestTarget(DROID *psDroid, BASE_OBJECT **ppsObj, int weapon_slot, int extraRange = 0);

// Are there a lot of bullets heading towards the structure?
bool aiObjectIsProbablyDoomed(BASE_OBJECT *psObject, bool isDirect);
bool aiObjectIsProbablyDoomed(BASE_OBJECT const *psObject, bool isDirect);

// Update the expected damage of the object.
void aiObjectAddExpectedDamage(BASE_OBJECT *psObject, SDWORD damage, bool isDirect);
Expand All @@ -82,9 +82,9 @@ bool aiChooseSensorTarget(BASE_OBJECT *psObj, BASE_OBJECT **ppsTarget);

/*set of rules which determine whether the weapon associated with the object
can fire on the propulsion type of the target*/
bool validTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget, int weapon_slot);
bool validTarget(BASE_OBJECT const *psObject, BASE_OBJECT const *psTarget, int weapon_slot);
// Check if any of the weapons can target the target
bool checkAnyWeaponsTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget);
bool checkAnyWeaponsTarget(BASE_OBJECT const *psObject, BASE_OBJECT const *psTarget);
// Check properties of the AllianceType enum.
static inline bool alliancesFixed(int t)
{
Expand Down
14 changes: 7 additions & 7 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ValueTracker* ValueTracker::stopTracking()
this->_reachedTarget = false;
return this;
}
bool ValueTracker::isTracking()
bool ValueTracker::isTracking() const
{
return this->startTime != 0;
}
Expand Down Expand Up @@ -95,35 +95,35 @@ ValueTracker* ValueTracker::update()
this->current = adjustedChange + this->current;
return this;
}
int ValueTracker::getCurrent()
int ValueTracker::getCurrent() const
{
if(this->_reachedTarget)
{
return this->target;
}
return static_cast<int>(this->current);
}
int ValueTracker::getCurrentDelta()
int ValueTracker::getCurrentDelta() const
{
if(this->_reachedTarget)
{
return this->targetDelta;
}
return static_cast<int>(this->current - this->initial);
}
int ValueTracker::getInitial()
int ValueTracker::getInitial() const
{
return this->initial;
}
int ValueTracker::getTarget()
int ValueTracker::getTarget() const
{
return this->target;
}
int ValueTracker::getTargetDelta()
int ValueTracker::getTargetDelta() const
{
return this->targetDelta;
}
bool ValueTracker::reachedTarget()
bool ValueTracker::reachedTarget() const
{
return this->_reachedTarget;
}
Expand Down
14 changes: 7 additions & 7 deletions src/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ValueTracker {
/// Stops tracking
ValueTracker* stopTracking();
/// Returns true if currently tracking a value.
bool isTracking();
bool isTracking() const;
/// Sets speed/smoothness of the interpolation. 1 is syrup, 100 is instant. Default 10.
ValueTracker* setSpeed(int value);
/// Sets the target delta value
Expand All @@ -52,17 +52,17 @@ class ValueTracker {
/// Update current value
ValueTracker* update();
/// Get initial value
int getInitial();
int getInitial() const;
/// Get current value
int getCurrent();
int getCurrent() const;
/// Get current delta value
int getCurrentDelta();
int getCurrentDelta() const;
/// Get absolute target value
int getTarget();
int getTarget() const;
/// Get target delta value
int getTargetDelta();
int getTargetDelta() const;
/// Returns if the tracker reached its target
bool reachedTarget();
bool reachedTarget() const;
};

enum EasingType
Expand Down
2 changes: 1 addition & 1 deletion src/baseobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct StructureBounds
, size(0,0)
{}
StructureBounds(Vector2i const &map, Vector2i const &size) : map(map), size(size) {}
bool valid()
bool valid() const
{
return size.x >= 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmddroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void cmdDroidClearDesignator(UDWORD player)
* It does this by searching throughout all the player's droids.
* @todo try to find something more efficient, has this function is of O(TotalNumberOfDroidsOfPlayer).
*/
SDWORD cmdDroidGetIndex(DROID *psCommander)
SDWORD cmdDroidGetIndex(const DROID *psCommander)
{
SDWORD index = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/cmddroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void cmdDroidSetDesignator(DROID *psDroid);
void cmdDroidClearDesignator(UDWORD player);

/** \brief Gets the index of the command droid.*/
SDWORD cmdDroidGetIndex(DROID *psCommander);
SDWORD cmdDroidGetIndex(const DROID *psCommander);

/** \brief Gets the maximum group size for a command droid.*/
unsigned int cmdDroidMaxGroup(const DROID *psCommander);
Expand Down
2 changes: 1 addition & 1 deletion src/display3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4283,7 +4283,7 @@ UDWORD getDroidRankGraphicFromLevel(unsigned int level)
return gfxId;
}
/// Get the graphic ID for a droid rank
UDWORD getDroidRankGraphic(DROID *psDroid)
UDWORD getDroidRankGraphic(const DROID *psDroid)
{
/* Establish the numerical value of the droid's rank */
return getDroidRankGraphicFromLevel(getDroidLevel(psDroid));
Expand Down
2 changes: 1 addition & 1 deletion src/display3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ extern bool showPath;
extern const Vector2i visibleTiles;

/*returns the graphic ID for a droid rank*/
UDWORD getDroidRankGraphic(DROID *psDroid);
UDWORD getDroidRankGraphic(const DROID *psDroid);
UDWORD getDroidRankGraphicFromLevel(unsigned int level);

void setSkyBox(const char *page, float mywind, float myscale);
Expand Down
16 changes: 8 additions & 8 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ static void droidUpdateDroidSelfRepair(DROID *psRepairDroid)
}

// return whether a droid is IDF
bool idfDroid(DROID *psDroid)
bool idfDroid(const DROID *psDroid)
{
//add Cyborgs
//if (psDroid->droidType != DROID_WEAPON)
Expand Down Expand Up @@ -1583,7 +1583,7 @@ UDWORD calcDroidSpeed(UDWORD baseSpeed, UDWORD terrainType, UDWORD propIndex, UD
}

template <typename T>
static uint32_t calcBuild(T *obj)
static uint32_t calcBuild(const T *obj)
{
return calcSum(obj, [](COMPONENT_STATS const &stat) {
return stat.buildPoints;
Expand All @@ -1599,7 +1599,7 @@ UDWORD calcTemplateBuild(const DROID_TEMPLATE *psTemplate)
return calcBuild(psTemplate);
}

UDWORD calcDroidPoints(DROID *psDroid)
UDWORD calcDroidPoints(const DROID *psDroid)
{
return calcBuild(psDroid);
}
Expand Down Expand Up @@ -2558,7 +2558,7 @@ PICKTILE pickHalfATile(UDWORD *x, UDWORD *y, UBYTE numIterations)

/* Looks through the players list of droids to see if any of them are
building the specified structure - returns true if finds one*/
bool checkDroidsBuilding(STRUCTURE *psStructure)
bool checkDroidsBuilding(const STRUCTURE *psStructure)
{
for (const DROID* psDroid : apsDroidLists[psStructure->player])
{
Expand All @@ -2574,7 +2574,7 @@ bool checkDroidsBuilding(STRUCTURE *psStructure)

/* Looks through the players list of droids to see if any of them are
demolishing the specified structure - returns true if finds one*/
bool checkDroidsDemolishing(STRUCTURE *psStructure)
bool checkDroidsDemolishing(const STRUCTURE *psStructure)
{
for (const DROID* psDroid : apsDroidLists[psStructure->player])
{
Expand Down Expand Up @@ -2854,7 +2854,7 @@ bool vtolFull(const DROID *psDroid)
}

// true if a vtol is waiting to be rearmed by a particular rearm pad
bool vtolReadyToRearm(DROID *psDroid, STRUCTURE *psStruct)
bool vtolReadyToRearm(const DROID *psDroid, const STRUCTURE *psStruct)
{
CHECK_DROID(psDroid);

Expand Down Expand Up @@ -3385,7 +3385,7 @@ true if valid weapon*/
/* this will be buggy if the droid being checked has both AA weapon and non-AA weapon
Cannot think of a solution without adding additional return value atm.
*/
bool checkValidWeaponForProp(DROID_TEMPLATE *psTemplate)
bool checkValidWeaponForProp(const DROID_TEMPLATE *psTemplate)
{
PROPULSION_STATS *psPropStats;

Expand Down Expand Up @@ -3557,7 +3557,7 @@ void checkDroid(const DROID *droid, const char *const location, const char *func
}
}

int droidSqDist(DROID *psDroid, BASE_OBJECT *psObj)
int droidSqDist(const DROID *psDroid, const BASE_OBJECT *psObj)
{
PROPULSION_STATS *psPropStats = asPropulsionStats + psDroid->asBits[COMP_PROPULSION];

Expand Down
14 changes: 7 additions & 7 deletions src/droid.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ UDWORD calcDroidWeight(const DROID_TEMPLATE *psTemplate);
UDWORD calcDroidPower(const DROID *psDroid);

// Calculate the number of points required to build a droid
UDWORD calcDroidPoints(DROID *psDroid);
UDWORD calcDroidPoints(const DROID *psDroid);

/* Calculate the body points of a droid from it's template */
UDWORD calcTemplateBody(const DROID_TEMPLATE *psTemplate, UBYTE player);
Expand All @@ -113,7 +113,7 @@ UDWORD calcTemplateBuild(const DROID_TEMPLATE *psTemplate);
UDWORD calcTemplatePower(const DROID_TEMPLATE *psTemplate);

// return whether a droid is IDF
bool idfDroid(DROID *psDroid);
bool idfDroid(const DROID *psDroid);

/* Do damage to a droid */
int32_t droidDamage(DROID *psDroid, unsigned damage, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, unsigned impactTime, bool isDamagePerSecond, int minDamage, bool empRadiusHit);
Expand Down Expand Up @@ -210,10 +210,10 @@ bool pickATileGenThreat(UDWORD *x, UDWORD *y, UBYTE numIterations, SDWORD threat
void initDroidMovement(DROID *psDroid);

/// Looks through the players list of droids to see if any of them are building the specified structure - returns true if finds one
bool checkDroidsBuilding(STRUCTURE *psStructure);
bool checkDroidsBuilding(const STRUCTURE *psStructure);

/// Looks through the players list of droids to see if any of them are demolishing the specified structure - returns true if finds one
bool checkDroidsDemolishing(STRUCTURE *psStructure);
bool checkDroidsDemolishing(const STRUCTURE *psStructure);

/// Returns the next module which can be built after lastOrderedModule, or returns 0 if not possible.
int nextModuleToBuild(STRUCTURE const *psStruct, int lastOrderedModule);
Expand Down Expand Up @@ -259,7 +259,7 @@ UWORD getNumAttackRuns(const DROID *psDroid, int weapon_slot);
//assign rearmPad to the VTOL
void assignVTOLPad(DROID *psNewDroid, STRUCTURE *psReArmPad);
// true if a vtol is waiting to be rearmed by a particular rearm pad
bool vtolReadyToRearm(DROID *psDroid, STRUCTURE *psStruct);
bool vtolReadyToRearm(const DROID *psDroid, const STRUCTURE *psStruct);
// true if a vtol droid currently returning to be rearmed
bool vtolRearming(const DROID *psDroid);
// true if a droid is currently attacking
Expand All @@ -284,7 +284,7 @@ bool standardSensorDroid(const DROID *psDroid);
SWORD droidResistance(const DROID *psDroid);

/// This is called to check the weapon is allowed
bool checkValidWeaponForProp(DROID_TEMPLATE *psTemplate);
bool checkValidWeaponForProp(const DROID_TEMPLATE *psTemplate);

const char *getDroidNameForRank(UDWORD rank);

Expand Down Expand Up @@ -453,7 +453,7 @@ void checkDroid(const DROID *droid, const char *const location_description, cons
#define CHECK_DROID(droid) checkDroid(droid, AT_MACRO, __FUNCTION__, max_check_object_recursion)

/** If droid can get to given object using its current propulsion, return the square distance. Otherwise return -1. */
int droidSqDist(DROID *psDroid, BASE_OBJECT *psObj);
int droidSqDist(const DROID *psDroid, const BASE_OBJECT *psObj);

// Minimum damage a weapon will deal to its target
#define MIN_WEAPON_DAMAGE 1
Expand Down
2 changes: 1 addition & 1 deletion src/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void DROID_GROUP::remove(DROID *psDroid)
}

// count the members of a group
unsigned int DROID_GROUP::getNumMembers()
unsigned int DROID_GROUP::getNumMembers() const
{
ASSERT(grpInitialized, "Group code not initialized yet");
return psList.size();
Expand Down
2 changes: 1 addition & 1 deletion src/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DROID_GROUP

void add(DROID *psDroid); // Add a droid to group. Remove it from its group in case it already has group
void remove(DROID *psDroid); // Remove droid from group. Free group in case RefCount<=0
unsigned int getNumMembers(); // Count the number of members of a group
unsigned int getNumMembers() const; // Count the number of members of a group

void orderGroup(DROID_ORDER order); // give an order all the droids of the group
void orderGroup(DROID_ORDER order, UDWORD x, UDWORD y); // give an order all the droids of the group (using location)
Expand Down
4 changes: 2 additions & 2 deletions src/objmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ BASE_OBJECT *getBaseObjFromId(UDWORD id)
return nullptr;
}

static UDWORD getRepairIdFromFlagSingleList(FLAG_POSITION* psFlag, uint32_t player, const StructureList& list)
static UDWORD getRepairIdFromFlagSingleList(const FLAG_POSITION* psFlag, uint32_t player, const StructureList& list)
{
for (STRUCTURE* psObj : list)
{
Expand All @@ -826,7 +826,7 @@ static UDWORD getRepairIdFromFlagSingleList(FLAG_POSITION* psFlag, uint32_t play
return UDWORD_MAX;
}

UDWORD getRepairIdFromFlag(FLAG_POSITION *psFlag)
UDWORD getRepairIdFromFlag(const FLAG_POSITION *psFlag)
{
unsigned int i;
UDWORD player;
Expand Down
Loading

0 comments on commit c4e3ef8

Please sign in to comment.