diff --git a/src/advvis.cpp b/src/advvis.cpp index 57568427ec0..fb3d28b8e2e 100644 --- a/src/advvis.cpp +++ b/src/advvis.cpp @@ -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; diff --git a/src/advvis.h b/src/advvis.h index dfe76dae995..97eda602226 100644 --- a/src/advvis.h +++ b/src/advvis.h @@ -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(); diff --git a/src/ai.cpp b/src/ai.cpp index a2e42341792..ff281ccb879 100644 --- a/src/ai.cpp +++ b/src/ai.cpp @@ -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) { @@ -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) { @@ -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; } @@ -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)) @@ -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; diff --git a/src/ai.h b/src/ai.h index aa51977fa92..c15f997856b 100644 --- a/src/ai.h +++ b/src/ai.h @@ -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); @@ -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) { diff --git a/src/animation.cpp b/src/animation.cpp index 4945b3f1c9d..1dedf23609b 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -41,7 +41,7 @@ ValueTracker* ValueTracker::stopTracking() this->_reachedTarget = false; return this; } -bool ValueTracker::isTracking() +bool ValueTracker::isTracking() const { return this->startTime != 0; } @@ -95,7 +95,7 @@ ValueTracker* ValueTracker::update() this->current = adjustedChange + this->current; return this; } -int ValueTracker::getCurrent() +int ValueTracker::getCurrent() const { if(this->_reachedTarget) { @@ -103,7 +103,7 @@ int ValueTracker::getCurrent() } return static_cast(this->current); } -int ValueTracker::getCurrentDelta() +int ValueTracker::getCurrentDelta() const { if(this->_reachedTarget) { @@ -111,19 +111,19 @@ int ValueTracker::getCurrentDelta() } return static_cast(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; } diff --git a/src/animation.h b/src/animation.h index 479fdf60290..cf83d926717 100644 --- a/src/animation.h +++ b/src/animation.h @@ -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 @@ -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 diff --git a/src/baseobject.h b/src/baseobject.h index 79435f0e72b..c821b480af0 100644 --- a/src/baseobject.h +++ b/src/baseobject.h @@ -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; } diff --git a/src/cmddroid.cpp b/src/cmddroid.cpp index 5df095fabb8..102b2a753f6 100644 --- a/src/cmddroid.cpp +++ b/src/cmddroid.cpp @@ -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; diff --git a/src/cmddroid.h b/src/cmddroid.h index dfda74a5393..9a38d2ebf98 100644 --- a/src/cmddroid.h +++ b/src/cmddroid.h @@ -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); diff --git a/src/display3d.cpp b/src/display3d.cpp index e82ee6c7e6c..d4d77637023 100644 --- a/src/display3d.cpp +++ b/src/display3d.cpp @@ -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)); diff --git a/src/display3d.h b/src/display3d.h index 50dce1d7e80..7c7a464caf8 100644 --- a/src/display3d.h +++ b/src/display3d.h @@ -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); diff --git a/src/droid.cpp b/src/droid.cpp index d672c9830d0..3b13bbeead3 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -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) @@ -1583,7 +1583,7 @@ UDWORD calcDroidSpeed(UDWORD baseSpeed, UDWORD terrainType, UDWORD propIndex, UD } template -static uint32_t calcBuild(T *obj) +static uint32_t calcBuild(const T *obj) { return calcSum(obj, [](COMPONENT_STATS const &stat) { return stat.buildPoints; @@ -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); } @@ -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]) { @@ -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]) { @@ -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); @@ -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; @@ -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]; diff --git a/src/droid.h b/src/droid.h index ca59abada6c..c73fc5cce23 100644 --- a/src/droid.h +++ b/src/droid.h @@ -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); @@ -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); @@ -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); @@ -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 @@ -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); @@ -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 diff --git a/src/group.cpp b/src/group.cpp index 36bc3e6cd16..9c0b740d35c 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -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(); diff --git a/src/group.h b/src/group.h index 6f838b231ec..ae41a0bdb33 100644 --- a/src/group.h +++ b/src/group.h @@ -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) diff --git a/src/objmem.cpp b/src/objmem.cpp index 7e49e96c854..15337b16189 100644 --- a/src/objmem.cpp +++ b/src/objmem.cpp @@ -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) { @@ -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; diff --git a/src/objmem.h b/src/objmem.h index 614c8a3a646..75043137548 100644 --- a/src/objmem.h +++ b/src/objmem.h @@ -147,7 +147,7 @@ BASE_OBJECT* getBaseObjFromId(const std::list& list, unsigned id) BASE_OBJECT *getBaseObjFromData(unsigned id, unsigned player, OBJECT_TYPE type); BASE_OBJECT *getBaseObjFromId(UDWORD id); -UDWORD getRepairIdFromFlag(FLAG_POSITION *psFlag); +UDWORD getRepairIdFromFlag(const FLAG_POSITION *psFlag); void objCount(int *droids, int *structures, int *features); diff --git a/src/order.cpp b/src/order.cpp index 812ee950e6b..9f40b165fe8 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -1948,7 +1948,7 @@ void orderDroid(DROID *psDroid, DROID_ORDER order, QUEUE_MODE mode) /** This function compares the current droid's order to the order. * Returns true if they are the same, false else. */ -bool orderState(DROID *psDroid, DROID_ORDER order) +bool orderState(const DROID *psDroid, DROID_ORDER order) { if (order == DORDER_RTR) { @@ -1991,7 +1991,7 @@ void orderDroidLoc(DROID *psDroid, DROID_ORDER order, UDWORD x, UDWORD y, QUEUE_ /** This function attributes the order's location to (pX,pY) if the order is the same as the droid. * Returns true if it was attributed and false if not. */ -bool orderStateLoc(DROID *psDroid, DROID_ORDER order, UDWORD *pX, UDWORD *pY) +bool orderStateLoc(const DROID *psDroid, DROID_ORDER order, UDWORD *pX, UDWORD *pY) { if (order != psDroid->order.type) { @@ -2207,7 +2207,7 @@ void orderDroidStatsTwoLocDirAdd(DROID *psDroid, DROID_ORDER order, STRUCTURE_ST /** This function returns false if droid's order and order don't match or the order is not a location order. Else ppsStats = psDroid->psTarStats, (pX,pY) = psDroid.(orderX,orderY) and it returns true. * @todo seems closely related to orderStateLoc() */ -bool orderStateStatsLoc(DROID *psDroid, DROID_ORDER order, STRUCTURE_STATS **ppsStats) +bool orderStateStatsLoc(const DROID *psDroid, DROID_ORDER order, STRUCTURE_STATS **ppsStats) { bool match = false; @@ -3044,7 +3044,7 @@ static STRUCTURE *FindARepairFacility(unsigned player) /** This function returns true if the droid supports the secondary order, and false if not.*/ -bool secondarySupported(DROID *psDroid, SECONDARY_ORDER sec) +bool secondarySupported(const DROID *psDroid, SECONDARY_ORDER sec) { bool supported; @@ -3155,7 +3155,7 @@ bool secondarySupported(DROID *psDroid, SECONDARY_ORDER sec) /** This function returns the droid order's secondary state of the secondary order.*/ -SECONDARY_STATE secondaryGetState(DROID *psDroid, SECONDARY_ORDER sec, QUEUE_MODE mode) +SECONDARY_STATE secondaryGetState(const DROID *psDroid, SECONDARY_ORDER sec, QUEUE_MODE mode) { uint32_t state = psDroid->secondaryOrder; @@ -4095,7 +4095,7 @@ bool setFactoryState(STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE S * return true except on an ASSERT (which is not a good design.) * or, an invalid factory. */ -bool getFactoryState(STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE *pState) +bool getFactoryState(const STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE *pState) { ASSERT_OR_RETURN(false, StructIsFactory(psStruct), "Structure is not a factory"); if ((FACTORY *)psStruct->pFunctionality) diff --git a/src/order.h b/src/order.h index f7f6742990a..b348efccb73 100644 --- a/src/order.h +++ b/src/order.h @@ -50,7 +50,7 @@ void orderUpdateDroid(DROID *psDroid); void orderDroid(DROID *psDroid, DROID_ORDER order, QUEUE_MODE mode); /** \brief Compares droid's order with order. */ -bool orderState(DROID *psDroid, DROID_ORDER order); +bool orderState(const DROID *psDroid, DROID_ORDER order); /** \brief Checks if an order is valid for a location. */ bool validOrderForLoc(DROID_ORDER order); @@ -62,7 +62,7 @@ bool validOrderForObj(DROID_ORDER order); void orderDroidLoc(DROID *psDroid, DROID_ORDER order, UDWORD x, UDWORD y, QUEUE_MODE mode); /** \brief Gets the state of a droid order with a location. */ -bool orderStateLoc(DROID *psDroid, DROID_ORDER order, UDWORD *pX, UDWORD *pY); +bool orderStateLoc(const DROID *psDroid, DROID_ORDER order, UDWORD *pX, UDWORD *pY); /** \brief Sends an order with an object target to a droid. */ void orderDroidObj(DROID *psDroid, DROID_ORDER order, BASE_OBJECT *psObj, QUEUE_MODE mode); @@ -74,7 +74,7 @@ BASE_OBJECT *orderStateObj(const DROID *psDroid, DROID_ORDER order); void orderDroidStatsLocDir(DROID *psDroid, DROID_ORDER order, STRUCTURE_STATS *psStats, UDWORD x, UDWORD y, uint16_t direction, QUEUE_MODE mode); /** \brief Gets the state of a droid order with a location and a stat. */ -bool orderStateStatsLoc(DROID *psDroid, DROID_ORDER order, STRUCTURE_STATS **ppsStats); +bool orderStateStatsLoc(const DROID *psDroid, DROID_ORDER order, STRUCTURE_STATS **ppsStats); /** \brief Sends an order with a location and a stat to a droid. */ void orderDroidStatsTwoLocDir(DROID *psDroid, DROID_ORDER order, STRUCTURE_STATS *psStats, UDWORD x1, UDWORD y1, UDWORD x2, UDWORD y2, uint16_t direction, QUEUE_MODE mode); @@ -108,10 +108,10 @@ void orderDroidStatsLocDirAdd(DROID *psDroid, DROID_ORDER order, STRUCTURE_STATS void orderSelectedStatsTwoLocDir(UDWORD player, DROID_ORDER order, STRUCTURE_STATS *psStats, UDWORD x1, UDWORD y1, UDWORD x2, UDWORD y2, uint16_t direction, bool add); /** \brief Sees if a droid supports a given secondary order. */ -bool secondarySupported(DROID *psDroid, SECONDARY_ORDER sec); +bool secondarySupported(const DROID *psDroid, SECONDARY_ORDER sec); /** \brief Gets the state of a secondary order, return false if unsupported. */ -SECONDARY_STATE secondaryGetState(DROID *psDroid, SECONDARY_ORDER sec, QUEUE_MODE mode = ModeImmediate); +SECONDARY_STATE secondaryGetState(const DROID *psDroid, SECONDARY_ORDER sec, QUEUE_MODE mode = ModeImmediate); /** \brief Sets the state of a secondary order, return false if failed. */ bool secondarySetState(DROID *psDroid, SECONDARY_ORDER sec, SECONDARY_STATE State, QUEUE_MODE mode = ModeQueue); @@ -133,7 +133,7 @@ DROID *FindATransporter(DROID const *embarkee); bool setFactoryState(STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE State); /** \brief Gets the state of a secondary order for a Factory. */ -bool getFactoryState(STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE *pState); +bool getFactoryState(const STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE *pState); /** \brief lasSat structure can select a target. */ void orderStructureObj(UDWORD player, BASE_OBJECT *psObj); diff --git a/src/projectile.cpp b/src/projectile.cpp index a34e1dffb75..06d376b1f79 100644 --- a/src/projectile.cpp +++ b/src/projectile.cpp @@ -135,7 +135,7 @@ static inline void setProjectileDestination(PROJECTILE *psProj, BASE_OBJECT *psO /***************************************************************************/ -bool gfxVisible(PROJECTILE *psObj) +bool gfxVisible(const PROJECTILE *psObj) { // Already know it is visible if (psObj->bVisible) @@ -1511,7 +1511,7 @@ int proj_GetShortRange(const WEAPON_STATS *psStats, int player) } /***************************************************************************/ -ObjectShape establishTargetShape(BASE_OBJECT *psTarget) +ObjectShape establishTargetShape(const BASE_OBJECT *psTarget) { CHECK_OBJECT(psTarget); @@ -1557,7 +1557,7 @@ ObjectShape establishTargetShape(BASE_OBJECT *psTarget) /*the damage depends on the weapon effect and the target propulsion type or structure strength*/ -UDWORD calcDamage(UDWORD baseDamage, WEAPON_EFFECT weaponEffect, BASE_OBJECT *psTarget) +UDWORD calcDamage(UDWORD baseDamage, WEAPON_EFFECT weaponEffect, const BASE_OBJECT *psTarget) { if (baseDamage == 0) { diff --git a/src/projectile.h b/src/projectile.h index 9df66a134f7..5b1a37f2bb6 100644 --- a/src/projectile.h +++ b/src/projectile.h @@ -81,8 +81,8 @@ int proj_GetMinRange(const WEAPON_STATS *psStats, int player); /** Return the short range for a weapon. */ int proj_GetShortRange(const WEAPON_STATS *psStats, int player); -UDWORD calcDamage(UDWORD baseDamage, WEAPON_EFFECT weaponEffect, BASE_OBJECT *psTarget); -bool gfxVisible(PROJECTILE *psObj); +UDWORD calcDamage(UDWORD baseDamage, WEAPON_EFFECT weaponEffect, const BASE_OBJECT *psTarget); +bool gfxVisible(const PROJECTILE *psObj); /***************************************************************************/ @@ -137,6 +137,6 @@ struct ObjectShape Vector2i size; ///< x == y if circular. }; -ObjectShape establishTargetShape(BASE_OBJECT *psTarget); +ObjectShape establishTargetShape(const BASE_OBJECT *psTarget); #endif // __INCLUDED_SRC_PROJECTILE_H__ diff --git a/src/structure.cpp b/src/structure.cpp index ebd2fe4ec18..8d79921a714 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -6714,7 +6714,7 @@ void ensureRearmPadClear(STRUCTURE *psStruct, DROID *psDroid) // return whether a rearm pad has a vtol on it -bool vtolOnRearmPad(const STRUCTURE *psStruct, DROID *psDroid) +bool vtolOnRearmPad(const STRUCTURE *psStruct, const DROID *psDroid) { SDWORD tx, ty; @@ -6736,7 +6736,7 @@ bool vtolOnRearmPad(const STRUCTURE *psStruct, DROID *psDroid) /* Just returns true if the structure's present body points aren't as high as the original*/ -bool structIsDamaged(STRUCTURE *psStruct) +bool structIsDamaged(const STRUCTURE *psStruct) { return psStruct->body < structureBody(psStruct); } diff --git a/src/structure.h b/src/structure.h index 671c3c3eca3..66ffc4108e8 100644 --- a/src/structure.h +++ b/src/structure.h @@ -311,10 +311,10 @@ bool clearRearmPad(const STRUCTURE *psStruct); void ensureRearmPadClear(STRUCTURE *psStruct, DROID *psDroid); // return whether a rearm pad has a vtol on it -bool vtolOnRearmPad(const STRUCTURE *psStruct, DROID *psDroid); +bool vtolOnRearmPad(const STRUCTURE *psStruct, const DROID *psDroid); /* Just returns true if the structure's present body points aren't as high as the original*/ -bool structIsDamaged(STRUCTURE *psStruct); +bool structIsDamaged(const STRUCTURE *psStruct); // give a structure from one player to another - used in Electronic Warfare STRUCTURE *giftSingleStructure(STRUCTURE *psStructure, UBYTE attackPlayer, bool electronic_warfare = true); @@ -356,7 +356,7 @@ static inline int structJammerPower(const STRUCTURE *psObj) return objJammerPower((const BASE_OBJECT *)psObj); } -static inline Rotation structureGetInterpolatedWeaponRotation(STRUCTURE *psStructure, int weaponSlot, uint32_t time) +static inline Rotation structureGetInterpolatedWeaponRotation(const STRUCTURE *psStructure, int weaponSlot, uint32_t time) { return interpolateRot(psStructure->asWeaps[weaponSlot].prevRot, psStructure->asWeaps[weaponSlot].rot, psStructure->prevTime, psStructure->time, time); } @@ -468,24 +468,24 @@ static inline int getBuildingResearchPoints(const STRUCTURE *psStruct) return upgrade.research + upgrade.moduleResearch * psStruct->capacity; } -static inline int getBuildingProductionPoints(STRUCTURE *psStruct) +static inline int getBuildingProductionPoints(const STRUCTURE *psStruct) { - auto &upgrade = psStruct->pStructureType->upgrade[psStruct->player]; + const auto &upgrade = psStruct->pStructureType->upgrade[psStruct->player]; return upgrade.production + upgrade.moduleProduction * psStruct->capacity; } -static inline int getBuildingPowerPoints(STRUCTURE *psStruct) +static inline int getBuildingPowerPoints(const STRUCTURE *psStruct) { - auto &upgrade = psStruct->pStructureType->upgrade[psStruct->player]; + const auto &upgrade = psStruct->pStructureType->upgrade[psStruct->player]; return upgrade.power + upgrade.modulePower * psStruct->capacity; } -static inline int getBuildingRepairPoints(STRUCTURE *psStruct) +static inline int getBuildingRepairPoints(const STRUCTURE *psStruct) { return psStruct->pStructureType->upgrade[psStruct->player].repair; } -static inline int getBuildingRearmPoints(STRUCTURE *psStruct) +static inline int getBuildingRearmPoints(const STRUCTURE *psStruct) { return psStruct->pStructureType->upgrade[psStruct->player].rearm; } diff --git a/src/template.cpp b/src/template.cpp index 3e547581bfa..321e6c503c0 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -227,7 +227,7 @@ bool loadTemplateCommon(WzConfig &ini, DROID_TEMPLATE &outputTemplate) } // A way to check if a design is something someone could legitimately have in multiplayer -bool designableTemplate(DROID_TEMPLATE *psTempl, int player) +bool designableTemplate(const DROID_TEMPLATE *psTempl, int player) { if (!bMultiPlayer || !isHumanPlayer(player)) { @@ -735,7 +735,7 @@ void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, unsigned player, Q } // return whether a template is for an IDF droid -bool templateIsIDF(DROID_TEMPLATE *psTemplate) +bool templateIsIDF(const DROID_TEMPLATE *psTemplate) { //add Cyborgs if (!(psTemplate->droidType == DROID_WEAPON || psTemplate->droidType == DROID_CYBORG || psTemplate->droidType == DROID_CYBORG_SUPER)) diff --git a/src/template.h b/src/template.h index ef6ee402738..5e05e1563c0 100644 --- a/src/template.h +++ b/src/template.h @@ -29,7 +29,7 @@ extern bool allowDesign; extern bool includeRedundantDesigns; extern bool playerBuiltHQ; -bool designableTemplate(DROID_TEMPLATE *psTempl, int player); +bool designableTemplate(const DROID_TEMPLATE *psTempl, int player); bool initTemplates(); /// Take ownership of template given by pointer. @@ -50,7 +50,7 @@ bool storeTemplates(); bool loadDroidTemplates(const char *filename); /// return whether a template is for an IDF droid -bool templateIsIDF(DROID_TEMPLATE *psTemplate); +bool templateIsIDF(const DROID_TEMPLATE *psTemplate); /// Fills the list with Templates that can be manufactured in the Factory - based on size std::vector fillTemplateList(STRUCTURE *psFactory); diff --git a/src/transporter.cpp b/src/transporter.cpp index cb18fc9c212..a9718850db0 100644 --- a/src/transporter.cpp +++ b/src/transporter.cpp @@ -1369,7 +1369,7 @@ void resetTransporter() } /*checks the order of the droid to see if its currently flying*/ -bool transporterFlying(DROID *psTransporter) +bool transporterFlying(const DROID *psTransporter) { ASSERT_OR_RETURN(false, psTransporter != nullptr, "Invalid droid pointer"); ASSERT_OR_RETURN(false, isTransporter(psTransporter), "Droid is not a Transporter"); diff --git a/src/transporter.h b/src/transporter.h index 7ea103c16b3..fc8700b097f 100644 --- a/src/transporter.h +++ b/src/transporter.h @@ -99,7 +99,7 @@ void transporterSetLaunchTime(UDWORD time); void flashMissionButton(UDWORD buttonID); void stopMissionButtonFlash(UDWORD buttonID); /*checks the order of the droid to see if its currently flying*/ -bool transporterFlying(DROID *psTransporter); +bool transporterFlying(const DROID *psTransporter); //initialise the flag to indicate the first transporter has arrived - set in startMission() void initFirstTransporterFlag(); diff --git a/src/version.h b/src/version.h index e9b099361ea..bd51147673c 100644 --- a/src/version.h +++ b/src/version.h @@ -57,35 +57,35 @@ struct TagVer qualifier[TAGVER_MAX_QUALIF_LEN - 1] = 0; } - uint16_t get_major() + uint16_t get_major() const { return version[0]; }; - uint16_t get_minor() + uint16_t get_minor() const { return version[1]; }; - uint16_t revision() + uint16_t revision() const { return version[2]; }; - bool operator < (const TagVer &other) + bool operator < (const TagVer &other) const { return std::lexicographical_compare(version, version + 3, other.version, other.version + 3); } - bool operator == (const TagVer &other) + bool operator == (const TagVer &other) const { return memcmp(version, other.version, sizeof(uint16_t) * 3) == 0; } - bool operator <= (const TagVer &other) + bool operator <= (const TagVer &other) const { return *this < other || *this == other; } - std::string major_minor() + std::string major_minor() const { char tmp[8] = {0}; // shall be enough 999.999 ASSERT(get_major() <= 999, "incorrect major version: %i", get_major()); @@ -94,7 +94,7 @@ struct TagVer return std::string(tmp); } - bool hasQualifier() + bool hasQualifier() const { return qualifier[0] != 0; } diff --git a/src/visibility.h b/src/visibility.h index 5bac2b3b70e..b4387dfab2f 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -67,7 +67,7 @@ void visRemoveVisibilityOffWorld(BASE_OBJECT *psObj); void visRemoveVisibility(BASE_OBJECT *psObj); // fast test for whether obj2 is in range of obj1 -static inline bool visObjInRange(BASE_OBJECT *psObj1, BASE_OBJECT *psObj2, SDWORD range) +static inline bool visObjInRange(const BASE_OBJECT *psObj1, const BASE_OBJECT *psObj2, SDWORD range) { int32_t xdiff = psObj1->pos.x - psObj2->pos.x, ydiff = psObj1->pos.y - psObj2->pos.y; diff --git a/src/wzapi.h b/src/wzapi.h index 3f7e1dc7b3e..9dd45167eb4 100644 --- a/src/wzapi.h +++ b/src/wzapi.h @@ -795,9 +795,9 @@ namespace wzapi , x1(x1), y1(y1), x2(x2), y2(y2) { } public: - inline bool isValid() { return type != Type::Invalid_Request; } - inline bool isLabel() { return type == Type::Label_Request; } - inline bool isPositionValues() { return type == Type::Position_Values_Request; } + inline bool isValid() const { return type != Type::Invalid_Request; } + inline bool isLabel() const { return type == Type::Label_Request; } + inline bool isPositionValues() const { return type == Type::Position_Values_Request; } public: enum Type { diff --git a/src/wzpropertyproviders.h b/src/wzpropertyproviders.h index 19c3c583703..6d8f30601cf 100644 --- a/src/wzpropertyproviders.h +++ b/src/wzpropertyproviders.h @@ -60,6 +60,7 @@ class CombinedPropertyProvider : public PropertyMatcher::PropertyProvider { public: CombinedPropertyProvider(const std::vector>& providers) { + propertyProviders.reserve(providers.size()); for (auto& provider : providers) { if (!provider) continue;