* Fix several "comparison between signed and unsigned" warnings
 * Use ARRAY_SIZE(array) instead of sizeof(array) / sizeof(typeof(*array))
 * Const correctness
 * Use "(unsigned )?int" instead of "[SU](D?WORD|BYTE)" where the size guarantee is not required
 * Use "%u" as format specifier for unsigned integers instead of "%d"
 * Remove redundant function prototypes
 * Use ssprintf instead of snprintf where appropriate


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6159 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-10-14 20:53:51 +00:00
parent 1df1706440
commit 8312b90c8a
8 changed files with 25 additions and 30 deletions

View File

@ -42,8 +42,6 @@ DROID *apsCmdDesignator[MAX_PLAYERS];
// whether experience should be boosted due to a multi game
static BOOL bMultiExpBoost = false;
bool hasCommander(DROID *psDroid);
// Initialise the command droids
BOOL cmdDroidInit(void)
{
@ -169,7 +167,7 @@ BOOL cmdGetDroidMultiExpBoost()
}
// get the maximum group size for a command droid
unsigned int cmdDroidMaxGroup(DROID *psCommander)
unsigned int cmdDroidMaxGroup(const DROID* psCommander)
{
return getDroidLevel(psCommander) * 2 + MIN_CMD_GROUP_DROIDS;
}
@ -190,10 +188,9 @@ void cmdDroidUpdateKills(DROID *psKiller, float experienceInc)
}
// returns true if a droid in question is assigned to a commander
bool hasCommander(DROID *psDroid)
bool hasCommander(const DROID* psDroid)
{
ASSERT( psDroid != NULL,
"hasCommander: invalid droid pointer" );
ASSERT(psDroid != NULL, "invalid droid pointer");
if (psDroid->droidType != DROID_COMMAND &&
psDroid->psGroup != NULL &&
@ -206,12 +203,11 @@ bool hasCommander(DROID *psDroid)
}
// get the level of a droids commander, if any
unsigned int cmdGetCommanderLevel(DROID *psDroid)
unsigned int cmdGetCommanderLevel(const DROID* psDroid)
{
DROID *psCommander;
const DROID* psCommander;
ASSERT( psDroid != NULL,
"cmdGetCommanderLevel: invalid droid pointer" );
ASSERT(psDroid != NULL, "invalid droid pointer");
// If this droid is not the member of a Commander's group
// Return an experience level of 0

View File

@ -55,16 +55,16 @@ extern void cmdDroidClearDesignator(UDWORD player);
extern SDWORD cmdDroidGetIndex(DROID *psCommander);
// get the maximum group size for a command droid
extern unsigned int cmdDroidMaxGroup(DROID *psCommander);
extern unsigned int cmdDroidMaxGroup(const DROID* psCommander);
// update the kills of a command droid if psKiller is in a command group
extern void cmdDroidUpdateKills(DROID *psKiller, float experienceInc);
// get the level of a droids commander, if any
extern unsigned int cmdGetCommanderLevel(DROID *psDroid);
extern unsigned int cmdGetCommanderLevel(const DROID* psDroid);
// returns true if a unit in question has is assigned to a commander
extern bool hasCommander(DROID *psDroid);
extern bool hasCommander(const DROID* psDroid);
// Select all droids assigned to the passed in command droids
extern void cmdSelectSubDroids(DROID *psDroid);

View File

@ -3654,9 +3654,8 @@ static const struct rankMap arrRank[] =
{512, 2048, N_("Hero")}
};
UDWORD getDroidLevel(DROID *psDroid)
unsigned int getDroidLevel(const DROID* psDroid)
{
static const unsigned int lastRank = sizeof(arrRank) / sizeof(struct rankMap);
bool isCommander = (psDroid->droidType == DROID_COMMAND ||
psDroid->droidType == DROID_SENSOR) ? true : false;
unsigned int numKills = psDroid->experience;
@ -3671,9 +3670,10 @@ UDWORD getDroidLevel(DROID *psDroid)
// Search through the array of ranks until one is found
// which requires more kills than the droid has.
// Then fall back to the previous rank.
for (i = 1; i != lastRank; ++i)
for (i = 1; i < ARRAY_SIZE(arrRank); ++i)
{
unsigned int requiredKills = isCommander ? arrRank[i].commanderKills : arrRank[i].kills;
const unsigned int requiredKills = isCommander ? arrRank[i].commanderKills : arrRank[i].kills;
if (numKills < requiredKills)
{
return i - 1;
@ -3681,7 +3681,7 @@ UDWORD getDroidLevel(DROID *psDroid)
}
// If the criteria of the last rank are met, then select the last one
return lastRank - 1;
return ARRAY_SIZE(arrRank) - 1;
}
UDWORD getDroidEffectiveLevel(DROID *psDroid)

View File

@ -249,7 +249,7 @@ extern DROID_TEMPLATE* getTemplateFromMultiPlayerID(UDWORD multiPlayerID);
extern BOOL selectDroidByID(UDWORD id, UDWORD player);
/* Droid experience stuff */
extern UDWORD getDroidLevel(DROID *psDroid);
extern unsigned int getDroidLevel(const DROID* psDroid);
extern UDWORD getDroidEffectiveLevel(DROID *psDroid);
extern const char *getDroidLevelName(DROID *psDroid);

View File

@ -286,17 +286,16 @@ void grpLeave(DROID_GROUP *psGroup, DROID *psDroid)
}
// count the members of a group
SDWORD grpNumMembers(DROID_GROUP *psGroup)
unsigned int grpNumMembers(const DROID_GROUP* psGroup)
{
DROID *psCurr;
SDWORD num;
const DROID* psCurr;
unsigned int num;
ASSERT(grpInitialized, "Group code not initialized yet");
ASSERT( psGroup != NULL,
"grpNumMembers: invalid droid group" );
ASSERT(psGroup != NULL, "invalid droid group");
num = 0;
for(psCurr = psGroup->psList; psCurr; psCurr = psCurr->psGrpNext)
for (psCurr = psGroup->psList; psCurr; psCurr = psCurr->psGrpNext)
{
num += 1;
}

View File

@ -63,7 +63,7 @@ void grpJoinEnd(DROID_GROUP *psGroup, DROID *psDroid);
void grpLeave(DROID_GROUP *psGroup, DROID *psDroid);
// count the members of a group
SDWORD grpNumMembers(DROID_GROUP *psGroup);
unsigned int grpNumMembers(const DROID_GROUP* psGroup);
// remove all droids from a group
void grpReset(DROID_GROUP *psGroup);

View File

@ -514,7 +514,7 @@ void intUpdateCommandSize(WIDGET *psWidget, W_CONTEXT *psContext)
ASSERT( psDroid->droidType == DROID_COMMAND,
"intUpdateCommandSize: droid is not a command droid" );
snprintf(Label->aText, sizeof(Label->aText), "%d/%d", psDroid->psGroup ? grpNumMembers(psDroid->psGroup) : 0, cmdDroidMaxGroup(psDroid));
ssprintf(Label->aText, "%u/%u", psDroid->psGroup ? grpNumMembers(psDroid->psGroup) : 0, cmdDroidMaxGroup(psDroid));
Label->style &= ~WIDG_HIDDEN;
}
else

View File

@ -399,7 +399,7 @@ BOOL scrOrderGroup(void)
return false;
}
debug( LOG_NEVER, "scrOrderGroup: group %p (%d) order %d\n", psGroup, grpNumMembers(psGroup), order);
debug(LOG_NEVER, "group %p (%u) order %d", psGroup, grpNumMembers(psGroup), order);
orderGroup(psGroup, order);
return true;
@ -438,7 +438,7 @@ BOOL scrOrderGroupLoc(void)
return false;
}
debug( LOG_NEVER, "scrOrderGroupLoc: group %p (%d) order %d (%d,%d)\n",
debug(LOG_NEVER, "group %p (%u) order %d (%d,%d)",
psGroup, grpNumMembers(psGroup), order, x,y);
orderGroupLoc(psGroup, order, (UDWORD)x,(UDWORD)y);
@ -477,7 +477,7 @@ BOOL scrOrderGroupObj(void)
return false;
}
debug( LOG_NEVER, "scrOrderGroupObj: group %p (%d) order %d, obj type %d player %d id %d\n",
debug(LOG_NEVER, "group %p (%u) order %d, obj type %d player %d id %d",
psGroup, grpNumMembers(psGroup), order, psObj->type, psObj->player, psObj->id);
orderGroupObj(psGroup, order, psObj);