* remove specialization of getDroidLevel: cmdDroidGetLevel

* modify getDroidLevel to provide the functionality of cmdDroidLevel for command and sensor droids

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1827 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2007-06-05 23:22:44 +00:00
parent 6d2e839bf4
commit a9a5b965ab
4 changed files with 28 additions and 81 deletions

View File

@ -169,58 +169,10 @@ void cmdDroidMultiExpBoost(BOOL bDoit)
bMultiExpBoost = bDoit;
}
// get the experience level of a command droid
unsigned int cmdDroidGetLevel(DROID *psCommander)
{
SDWORD numKills = psCommander->numKills;
// commanders do not need as much experience in multiplayer
if (bMultiExpBoost)
{
numKills *= 2;
}
if (numKills > 2047)
{
return 8;
}
else if (numKills > 1023)
{
return 7;
}
else if (numKills > 511)
{
return 6;
}
else if (numKills > 255)
{
return 5;
}
else if (numKills > 127)
{
return 4;
}
else if (numKills > 63)
{
return 3;
}
else if (numKills > 31)
{
return 2;
}
else if (numKills > 15)
{
return 1;
}
return 0;
}
// get the maximum group size for a command droid
unsigned int cmdDroidMaxGroup(DROID *psCommander)
{
return cmdDroidGetLevel(psCommander) * 2 + 6;
return getDroidLevel(psCommander) * 2 + 6;
}
// update the kills of a command droid if psKiller is in a command group
@ -259,7 +211,7 @@ unsigned int cmdGetCommanderLevel(DROID *psDroid)
psCommander = psDroid->psGroup->psCommander;
// Return the experience level of this commander
return cmdDroidGetLevel(psCommander);
return getDroidLevel(psCommander);
}
// Selects all droids for a given commander

View File

@ -56,9 +56,6 @@ extern void cmdDroidClearDesignator(UDWORD player);
// get the index of the command droid
extern SDWORD cmdDroidGetIndex(DROID *psCommander);
// get the experience level of a command droid
extern unsigned int cmdDroidGetLevel(DROID *psCommander);
// get the maximum group size for a command droid
extern unsigned int cmdDroidMaxGroup(DROID *psCommander);

View File

@ -4227,57 +4227,55 @@ BOOL selectDroidByID(UDWORD id, UDWORD player)
return FALSE;
}
typedef struct
struct rankMap
{
UDWORD kills; // required minimum amount of kills to reach this rank
const char* name; // name of this rank
} RANK_MAP;
unsigned int kills; // required minimum amount of kills to reach this rank
unsigned int commanderKills; // required minimum amount of kills for a commander (or sensor) to reach this rank
const char* name; // name of this rank
};
static const RANK_MAP arrRank[] =
static const struct rankMap arrRank[] =
{
{0, N_("Rookie")},
{4, NP_("rank", "Green")},
{8, N_("Trained")},
{16, N_("Regular")},
{32, N_("Professional")},
{64, N_("Veteran")},
{128, N_("Elite")},
{256, N_("Special")},
{512, N_("Hero")}
{0, 0, N_("Rookie")},
{4, 16, NP_("rank", "Green")},
{8, 32, N_("Trained")},
{16, 64, N_("Regular")},
{32, 128, N_("Professional")},
{64, 256, N_("Veteran")},
{128, 512, N_("Elite")},
{256, 1024, N_("Special")},
{512, 2048, N_("Hero")}
};
UDWORD getDroidLevel(DROID *psDroid)
{
UDWORD i;
static const UDWORD end = sizeof(arrRank) / sizeof(RANK_MAP);
if (psDroid->droidType == DROID_COMMAND ||
psDroid->droidType == DROID_SENSOR)
{
return cmdDroidGetLevel(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 i;
// 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 != end; ++i)
for (i = 1; i != lastRank; ++i)
{
if (psDroid->numKills < arrRank[i].kills)
unsigned int requiredKills = isCommander ? arrRank[i].commanderKills : arrRank[i].kills;
if (psDroid->numKills < requiredKills)
{
return i - 1;
}
}
// If the criteria of the last rank are met, then select the last one
return end - 1;
return lastRank - 1;
}
const char *getDroidNameForRank(UDWORD rank)
{
ASSERT( rank < (sizeof(arrRank) / sizeof(RANK_MAP)),
"getDroidNameForRank: given rank number (%d) out of bounds, we only have %d ranks\n", rank, (sizeof(arrRank) / sizeof(RANK_MAP)) );
ASSERT( rank < (sizeof(arrRank) / sizeof(struct rankMap)),
"getDroidNameForRank: given rank number (%d) out of bounds, we only have %d ranks\n", rank, (sizeof(arrRank) / sizeof(struct rankMap)) );
return PE_("rank", arrRank[rank].name);
}

View File

@ -629,7 +629,7 @@ void intUpdateCommandExp(WIDGET *psWidget, W_CONTEXT *psContext)
ASSERT( psDroid->droidType == DROID_COMMAND,
"intUpdateCommandSize: droid is not a command droid" );
numStars = cmdDroidGetLevel(psDroid);
numStars = getDroidLevel(psDroid);
numStars = (numStars >= 1) ? (numStars - 1) : 0;
for(i=0; i<numStars; i++)
{