Skip to content

Commit

Permalink
Rewrite stats loading for STRUCTURE_STATS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyp committed Jan 4, 2011
1 parent 7481694 commit 9cdf0c4
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 522 deletions.
3 changes: 1 addition & 2 deletions src/feature.cpp
Expand Up @@ -72,7 +72,7 @@ FEATURE_STATS* oilResFeature = NULL;
//specifies how far round (in tiles) a constructor droid sound look for more wreckage
#define WRECK_SEARCH 3

static const StringToEnum<FEATURE_TYPE> mapUnsorted_FEATURE_TYPE[] =
static const StringToEnum<FEATURE_TYPE> map_FEATURE_TYPE[] =
{
{ "PROPULSION_TYPE_HOVER WRECK", FEAT_HOVER },
{ "TANK WRECK", FEAT_TANK },
Expand All @@ -87,7 +87,6 @@ static const StringToEnum<FEATURE_TYPE> mapUnsorted_FEATURE_TYPE[] =
{ "TREE", FEAT_TREE },
{ "SKYSCRAPER", FEAT_SKYSCRAPER }
};
static const StringToEnumMap<FEATURE_TYPE> map_FEATURE_TYPE(mapUnsorted_FEATURE_TYPE, ARRAY_SIZE(mapUnsorted_FEATURE_TYPE));


void featureInitVars(void)
Expand Down
30 changes: 24 additions & 6 deletions src/stats.cpp
Expand Up @@ -124,6 +124,8 @@ static void updateMaxECMStats(UWORD maxValue);
static void updateMaxBodyStats(UWORD maxBody, UWORD maxPower, UWORD maxArmour);
static void updateMaxConstStats(UWORD maxValue);

static bool getWeaponEffect(const char* weaponEffect, WEAPON_EFFECT* effect); // Kill this function, when rewriting stats.cpp.


BASE_STATS::BASE_STATS(unsigned ref, std::string const &str)
: ref(ref)
Expand Down Expand Up @@ -191,13 +193,13 @@ void LineView::setError(unsigned index, char const *error)
char const *cellEnd = table.buffer + (cells[index + 1] - 1);

char cellDesc[150];
ssprintf(cellDesc, "Line %u, column %u \"%*s\": ", lineNumber, index, std::min<unsigned>(100, cellEnd - cellBegin), cellBegin);
ssprintf(cellDesc, "Line %u, column %d \"%.*s\": ", lineNumber, index, std::min<unsigned>(100, cellEnd - cellBegin), cellBegin);
table.parseError = QString::fromUtf8((std::string(cellDesc) + error).c_str());
}
else
{
char cellDesc[50];
ssprintf(cellDesc, "Line %u, column %u: ", lineNumber, index);
ssprintf(cellDesc, "Line %u, column %d: ", lineNumber, index);
table.parseError = QString::fromUtf8((std::string(cellDesc) + error).c_str());
}
}
Expand All @@ -213,9 +215,9 @@ bool LineView::checkRange(unsigned index)
return false;
}

int64_t LineView::i(unsigned index, int min, int max)
int64_t LineView::i(unsigned index, int64_t min, int64_t max)
{
int errorReturn = std::min(std::max(0, min), max); // On error, return 0 if possible.
int errorReturn = std::min(std::max<int64_t>(0, min), max); // On error, return 0 if possible.

if (!checkRange(index))
{
Expand Down Expand Up @@ -304,9 +306,13 @@ std::string const &LineView::s(unsigned index)
return table.returnString;
}

iIMDShape *LineView::imdShape(unsigned int index)
iIMDShape *LineView::imdShape(unsigned int index, bool accept0AsNULL)
{
std::string const &str = s(index);
if (accept0AsNULL && str == "0")
{
return NULL;
}
iIMDShape *result = (iIMDShape *)resGetData("IMD", str.c_str());
if (result == NULL)
{
Expand Down Expand Up @@ -2962,7 +2968,19 @@ bool getMovementModel(const char* movementModel, MOVEMENT_MODEL* model)
return true;
}

bool getWeaponEffect(const char* weaponEffect, WEAPON_EFFECT* effect)
const StringToEnum<WEAPON_EFFECT> mapUnsorted_WEAPON_EFFECT[] =
{
{"ANTI PERSONNEL", WE_ANTI_PERSONNEL },
{"ANTI TANK", WE_ANTI_TANK },
{"BUNKER BUSTER", WE_BUNKER_BUSTER },
{"ARTILLERY ROUND", WE_ARTILLERY_ROUND },
{"FLAMER", WE_FLAMER },
{"ANTI AIRCRAFT", WE_ANTI_AIRCRAFT },
{"ALL ROUNDER", WE_ANTI_AIRCRAFT }, // Alternative name for WE_ANTI_AIRCRAFT.
};
const StringToEnumMap<WEAPON_EFFECT> map_WEAPON_EFFECT = mapUnsorted_WEAPON_EFFECT;

static bool getWeaponEffect(const char* weaponEffect, WEAPON_EFFECT* effect)
{
if (strcmp(weaponEffect, "ANTI PERSONNEL") == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/stats.h
Expand Up @@ -311,7 +311,7 @@ extern bool getPropulsionType(const char* typeName, PROPULSION_TYPE* type);
* contain a valid weapon effect enumerator, otherwise its value will
* be left unchanged.
*/
extern bool getWeaponEffect(const char* weaponEffect, WEAPON_EFFECT* effect);
extern const StringToEnumMap<WEAPON_EFFECT> map_WEAPON_EFFECT;

extern UWORD weaponROF(WEAPON_STATS *psStat, SBYTE player);
/*Access functions for the upgradeable stats of a weapon*/
Expand Down

0 comments on commit 9cdf0c4

Please sign in to comment.