From cfb0f11d5c552da87ff61c79ecb8e1afff19728d Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Tue, 14 Oct 2008 20:17:55 +0000 Subject: [PATCH] Cleanup: * Const correctness * Return as soon as we've got our result (rather than assigning to a temporary and returning only at the end of the function) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6156 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/structure.c | 42 ++++++++++++++++++------------------------ src/structure.h | 4 ++-- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/structure.c b/src/structure.c index 0397f9246..0f3c7438d 100644 --- a/src/structure.c +++ b/src/structure.c @@ -5742,32 +5742,26 @@ void buildingComplete(STRUCTURE *psBuilding) /*for a given structure, return a pointer to its module stat */ -STRUCTURE_STATS* getModuleStat(STRUCTURE *psStruct) +STRUCTURE_STATS* getModuleStat(const STRUCTURE* psStruct) { - STRUCTURE_STATS *psStat; + ASSERT(psStruct != NULL, "Invalid structure pointer"); - ASSERT( psStruct != NULL, - "getModuleStat: Invalid structure pointer" ); - - psStat = NULL; switch (psStruct->pStructureType->type) { - case REF_POWER_GEN: - psStat = &asStructureStats[powerModuleStat]; - break; - case REF_FACTORY: - case REF_VTOL_FACTORY: - psStat = &asStructureStats[factoryModuleStat]; - break; - case REF_RESEARCH: - psStat = &asStructureStats[researchModuleStat]; - break; - default: - //no other structures can have modules attached - break; - } + case REF_POWER_GEN: + return &asStructureStats[powerModuleStat]; - return psStat; + case REF_FACTORY: + case REF_VTOL_FACTORY: + return &asStructureStats[factoryModuleStat]; + + case REF_RESEARCH: + return &asStructureStats[researchModuleStat]; + + default: + //no other structures can have modules attached + return NULL; + } } /* count the artillery droids assigned to a structure (only makes sence by sensor towers and headquarters) */ @@ -7709,7 +7703,7 @@ BOOL checkStructureStats(void) /*returns the power cost to build this structure*/ -UDWORD structPowerToBuild(STRUCTURE *psStruct) +UDWORD structPowerToBuild(const STRUCTURE* psStruct) { STRUCTURE_STATS *psStat; UBYTE capacity; @@ -7723,10 +7717,10 @@ UDWORD structPowerToBuild(STRUCTURE *psStruct) switch(psStruct->pStructureType->type) { case REF_POWER_GEN: - capacity = (UBYTE)psStruct->pFunctionality->powerGenerator.capacity; + capacity = psStruct->pFunctionality->powerGenerator.capacity; break; case REF_RESEARCH: - capacity = (UBYTE)psStruct->pFunctionality->researchFacility.capacity; + capacity = psStruct->pFunctionality->researchFacility.capacity; break; case REF_FACTORY: case REF_VTOL_FACTORY: diff --git a/src/structure.h b/src/structure.h index c7cd0924e..71624f42f 100644 --- a/src/structure.h +++ b/src/structure.h @@ -239,7 +239,7 @@ extern void assignFactoryCommandDroid(STRUCTURE *psStruct, struct DROID *psComma void clearCommandDroidFactory(DROID *psDroid); /*for a given structure, return a pointer to its module stat */ -extern STRUCTURE_STATS* getModuleStat(STRUCTURE *psStruct); +extern STRUCTURE_STATS* getModuleStat(const STRUCTURE* psStruct); /*called when a Res extractor is destroyed or runs out of power or is disconnected adjusts the owning Power Gen so that it can link to a different Res Extractor if one @@ -389,7 +389,7 @@ all StructureStats parts have been loaded*/ extern BOOL checkStructureStats(void); /*returns the power cost to build this structure*/ -extern UDWORD structPowerToBuild(STRUCTURE *psStruct); +extern UDWORD structPowerToBuild(const STRUCTURE* psStruct); extern UDWORD getMaxDroids(UDWORD PlayerNumber);