diff --git a/src/basedef.h b/src/basedef.h index 7f56c6ae9..b700ebdd5 100644 --- a/src/basedef.h +++ b/src/basedef.h @@ -75,7 +75,7 @@ typedef enum _object_type SDWORD sensorPower; /**< Active sensor power */ \ SDWORD sensorRange; /**< Range of sensor */ \ SDWORD ECMMod; /**< Ability to conceal oneself from sensors */ \ - UDWORD armour[NUM_HIT_SIDES][NUM_WEAPON_CLASS] + UDWORD armour[NUM_HIT_SIDES][WC_NUM_WEAPON_CLASSES] #define NEXTOBJ(pointerType) \ pointerType *psNext /**< Pointer to the next object in the list */ diff --git a/src/droid.c b/src/droid.c index dcfe5fb5c..e586b13a7 100644 --- a/src/droid.c +++ b/src/droid.c @@ -2995,7 +2995,7 @@ DROID* buildDroid(DROID_TEMPLATE *pTemplate, UDWORD x, UDWORD y, UDWORD player, if (cyborgDroid(psDroid)) { - for (inc = 0; inc < NUM_WEAPON_CLASS; inc++) + for (inc = 0; inc < WC_NUM_WEAPON_CLASSES; inc++) { for (impact_side = 0;impact_side < NUM_HIT_SIDES;impact_side=impact_side+1) { @@ -3006,7 +3006,7 @@ DROID* buildDroid(DROID_TEMPLATE *pTemplate, UDWORD x, UDWORD y, UDWORD player, } else { - for (inc = 0; inc < NUM_WEAPON_CLASS; inc++) + for (inc = 0; inc < WC_NUM_WEAPON_CLASSES; inc++) { for (impact_side = 0;impact_side < NUM_HIT_SIDES;impact_side=impact_side+1) { diff --git a/src/feature.c b/src/feature.c index d81ba5d02..475e5a122 100644 --- a/src/feature.c +++ b/src/feature.c @@ -334,7 +334,7 @@ FEATURE * buildFeature(FEATURE_STATS *psStats, UDWORD x, UDWORD y,BOOL FromSave) { int j; - for (j = 0; j < NUM_WEAPON_CLASS; j++) + for (j = 0; j < WC_NUM_WEAPON_CLASSES; j++) { psFeature->armour[i][j] = psFeature->psStats->armourValue; } diff --git a/src/function.c b/src/function.c index 5858f6174..63ff022a0 100644 --- a/src/function.c +++ b/src/function.c @@ -612,8 +612,7 @@ static BOOL loadWeaponUpgradeFunction(const char *pData) //allocate storage for the name storeName((FUNCTION *)psFunction, functionName); - psFunction->subClass = getWeaponSubClass(weaponSubClass); - if (psFunction->subClass == INVALID_SUBCLASS) + if (!getWeaponSubClass(weaponSubClass, &psFunction->subClass)) { return false; } @@ -1059,7 +1058,7 @@ void structureArmourUpgrade(FUNCTION *pFunction, STRUCTURE *psBuilding) // TODO: support advanced armour system for (i = 0; i < NUM_HIT_SIDES; i++) { - for (j = 0; j < NUM_WEAPON_CLASS; j++) + for (j = 0; j < WC_NUM_WEAPON_CLASSES; j++) { psBuilding->armour[i][j] = (UWORD)((psBuilding->armour[i][j] * newBaseArmour) / prevBaseArmour); } @@ -1425,7 +1424,7 @@ void bodyUpgrade(FUNCTION *pFunction, UBYTE player) asBodyUpgrade[player][DROID_BODY_UPGRADE].body = pUpgrade->body; } - for (inc=0; inc < NUM_WEAPON_CLASS; inc++) + for (inc=0; inc < WC_NUM_WEAPON_CLASSES; inc++) { if (asBodyUpgrade[player][DROID_BODY_UPGRADE].armourValue[inc] < pUpgrade->armourValue[inc]) @@ -1449,7 +1448,7 @@ void bodyUpgrade(FUNCTION *pFunction, UBYTE player) asBodyUpgrade[player][CYBORG_BODY_UPGRADE].body = pUpgrade->body; } - for (inc=0; inc < NUM_WEAPON_CLASS; inc++) + for (inc=0; inc < WC_NUM_WEAPON_CLASSES; inc++) { if (asBodyUpgrade[player][CYBORG_BODY_UPGRADE].armourValue[inc] < pUpgrade->armourValue[inc]) diff --git a/src/functiondef.h b/src/functiondef.h index f43ba847e..5cfdc56f1 100644 --- a/src/functiondef.h +++ b/src/functiondef.h @@ -240,7 +240,7 @@ typedef struct _droidBody_upgrade_function { UPGRADE_FUNCTION_STATS; UWORD body; //The % to increase the whole vehicle body points by*/ - UWORD armourValue[NUM_WEAPON_CLASS]; + UWORD armourValue[WC_NUM_WEAPON_CLASSES]; UBYTE cyborg; //flag to specify the upgrade is valid for cyborgs UBYTE droid; /*flag to specify the upgrade is valid for droids (non cyborgs!)*/ diff --git a/src/game.c b/src/game.c index 70319adbd..d03c4812f 100644 --- a/src/game.c +++ b/src/game.c @@ -2379,7 +2379,7 @@ BOOL loadGame(const char *pGameToLoad, BOOL keepObjects, BOOL freeMem, BOOL User memset(asReArmUpgrade, 0, MAX_PLAYERS * sizeof(REARM_UPGRADE)); //initialise the upgrade structures - memset(asWeaponUpgrade, 0, MAX_PLAYERS * NUM_WEAPON_SUBCLASS * sizeof(WEAPON_UPGRADE)); + memset(asWeaponUpgrade, 0, MAX_PLAYERS * WSC_NUM_WEAPON_SUBCLASSES * sizeof(WEAPON_UPGRADE)); memset(asSensorUpgrade, 0, MAX_PLAYERS * sizeof(SENSOR_UPGRADE)); memset(asECMUpgrade, 0, MAX_PLAYERS * sizeof(ECM_UPGRADE)); memset(asRepairUpgrade, 0, MAX_PLAYERS * sizeof(REPAIR_UPGRADE)); diff --git a/src/map.c b/src/map.c index 7a5c811f8..a017461c9 100644 --- a/src/map.c +++ b/src/map.c @@ -351,7 +351,7 @@ static void objectStatTagged(BASE_OBJECT *psObj, int body, int resistance) tagWriteEnter(0x03, 1); tagWrite(0x01, body); - tagWrite(0x02, NUM_WEAPON_CLASS); + tagWrite(0x02, WC_NUM_WEAPON_CLASSES); tagWriteEnter(0x03, NUM_HIT_SIDES); for (i = 0; i < NUM_HIT_SIDES; i++) { diff --git a/src/projectile.c b/src/projectile.c index 82fbbaf75..8f0a49b83 100644 --- a/src/projectile.c +++ b/src/projectile.c @@ -694,7 +694,7 @@ static void proj_InFlightDirectFunc(PROJECTILE *psProj) distanceExtensionFactor = 1.5f; break; default: - // NUM_WEAPON_SUBCLASS and INVALID_SUBCLASS + // WSC_NUM_WEAPON_SUBCLASSES break; } diff --git a/src/stats-db.c b/src/stats-db.c index 4155744f9..d77a922f9 100644 --- a/src/stats-db.c +++ b/src/stats-db.c @@ -551,8 +551,7 @@ static bool _loadWeaponStats(WEAPON_STATS* stats, SQL_WEAPON_STATS* cols, sqlite } // weaponSubClass TEXT NOT NULL, -- the subclass to which the weapon belongs - stats->weaponSubClass = getWeaponSubClass((const char*)sqlite3_column_text(stmt, cols->weaponSubClass)); - if (stats->weaponSubClass == INVALID_SUBCLASS) + if (!getWeaponSubClass((const char*)sqlite3_column_text(stmt, cols->weaponSubClass), &stats->weaponSubClass)) { return false; } diff --git a/src/stats-db2.h b/src/stats-db2.h index 1f401400a..bedd532aa 100644 --- a/src/stats-db2.h +++ b/src/stats-db2.h @@ -63,6 +63,88 @@ typedef enum BODY_SIZE SIZE_SUPER_HEAVY, } BODY_SIZE; +/** + * only using KINETIC and HEAT for now + */ +typedef enum WEAPON_CLASS +{ + /** + * Bullets, etc. + */ + WC_KINETIC, + + /** + * Rockets, etc. - classed as KINETIC now to save space in DROID + *EXPLOSIVE + * Laser, etc. + */ + WC_HEAT, + + /** + * The number of enumerators in this enum. + */ + WC_NUM_WEAPON_CLASSES, +} WEAPON_CLASS; + +/** + * weapon subclasses used to define which weapons are affected by weapon upgrade + * functions + * + * Watermelon:added a new subclass to do some tests + */ +typedef enum WEAPON_SUBCLASS +{ + WSC_MGUN, + + WSC_CANNON, + + /** + *ARTILLARY + */ + WSC_MORTARS, + + WSC_MISSILE, + + WSC_ROCKET, + + WSC_ENERGY, + + WSC_GAUSS, + + WSC_FLAME, + + /** + *CLOSECOMBAT + */ + WSC_HOWITZERS, + + WSC_ELECTRONIC, + + WSC_AAGUN, + + WSC_SLOWMISSILE, + + WSC_SLOWROCKET, + + WSC_LAS_SAT, + + WSC_BOMB, + + WSC_COMMAND, + + WSC_EMP, + + /** + * Counter missile + */ + WSC_COUNTER, + + /** + * The number of enumerators in this enum. + */ + WSC_NUM_WEAPON_SUBCLASSES, +} WEAPON_SUBCLASS; + typedef enum PROPULSION_TYPE { PROPULSION_TYPE_WHEELED, diff --git a/src/stats-db2.tpl b/src/stats-db2.tpl index 18722c572..6c67946ee 100644 --- a/src/stats-db2.tpl +++ b/src/stats-db2.tpl @@ -31,6 +31,56 @@ enum BODY_SIZE SUPER_HEAVY end; +# only using KINETIC and HEAT for now +enum WEAPON_CLASS + %max "NUM_WEAPON_CLASSES"; + %valprefix "WC_"; + + # Bullets, etc. + KINETIC + + # Rockets, etc. - classed as KINETIC now to save space in DROID + #EXPLOSIVE + + # Laser, etc. + HEAT + + # others we haven't thought of! - classed as HEAT now to save space in DROID + #WC_MISC, ///< +end; + +# weapon subclasses used to define which weapons are affected by weapon upgrade +# functions +# +# Watermelon:added a new subclass to do some tests +enum WEAPON_SUBCLASS + %max "NUM_WEAPON_SUBCLASSES"; + %valprefix "WSC_"; + + MGUN + CANNON + #ARTILLARY + MORTARS + MISSILE + ROCKET + ENERGY + GAUSS + FLAME + #CLOSECOMBAT + HOWITZERS + ELECTRONIC + AAGUN + SLOWMISSILE + SLOWROCKET + LAS_SAT + BOMB + COMMAND + EMP + + # Counter missile + COUNTER +end; + enum PROPULSION_TYPE %max "NUM"; WHEELED diff --git a/src/stats.c b/src/stats.c index b670d13ca..4a546b2ec 100644 --- a/src/stats.c +++ b/src/stats.c @@ -56,7 +56,7 @@ static SPECIAL_ABILITY *asSpecialAbility; WEAPON_MODIFIER asWeaponModifier[WE_NUMEFFECTS][PROPULSION_TYPE_NUM]; //used to hold the current upgrade level per player per weapon subclass -WEAPON_UPGRADE asWeaponUpgrade[MAX_PLAYERS][NUM_WEAPON_SUBCLASS]; +WEAPON_UPGRADE asWeaponUpgrade[MAX_PLAYERS][WSC_NUM_WEAPON_SUBCLASSES]; SENSOR_UPGRADE asSensorUpgrade[MAX_PLAYERS]; ECM_UPGRADE asECMUpgrade[MAX_PLAYERS]; REPAIR_UPGRADE asRepairUpgrade[MAX_PLAYERS]; @@ -187,7 +187,7 @@ void statsInitVars(void) } //initialise the upgrade structures - memset(asWeaponUpgrade, 0, MAX_PLAYERS * NUM_WEAPON_SUBCLASS * sizeof(WEAPON_UPGRADE)); + memset(asWeaponUpgrade, 0, MAX_PLAYERS * WSC_NUM_WEAPON_SUBCLASSES * sizeof(WEAPON_UPGRADE)); memset(asSensorUpgrade, 0, MAX_PLAYERS * sizeof(SENSOR_UPGRADE)); memset(asECMUpgrade, 0, MAX_PLAYERS * sizeof(ECM_UPGRADE)); memset(asRepairUpgrade, 0, MAX_PLAYERS * sizeof(REPAIR_UPGRADE)); @@ -577,8 +577,7 @@ BOOL loadWeaponStats(const char *pWeaponData, UDWORD bufferSize) } //set the subClass - psStats->weaponSubClass = getWeaponSubClass(weaponSubClass); - if (psStats->weaponSubClass == INVALID_SUBCLASS) + if (!getWeaponSubClass(weaponSubClass, &psStats->weaponSubClass)) { return false; } @@ -2666,80 +2665,83 @@ BOOL getBodySize(const char *pSize, UBYTE *pStore) } /*returns the weapon sub class based on the string name passed in */ -WEAPON_SUBCLASS getWeaponSubClass(const char *pSubClass) +bool getWeaponSubClass(const char* subClass, WEAPON_SUBCLASS* wclass) { - if (!strcmp(pSubClass, "CANNON")) + if (strcmp(subClass, "CANNON") == 0) { - return WSC_CANNON; + *wclass = WSC_CANNON; } - if (!strcmp(pSubClass, "MORTARS")) + else if (strcmp(subClass, "MORTARS") == 0) { - return WSC_MORTARS; + *wclass = WSC_MORTARS; } - if (!strcmp(pSubClass, "MISSILE")) + else if (strcmp(subClass, "MISSILE") == 0) { - return WSC_MISSILE; + *wclass = WSC_MISSILE; } - if (!strcmp(pSubClass, "ROCKET")) + else if (strcmp(subClass, "ROCKET") == 0) { - return WSC_ROCKET; + *wclass = WSC_ROCKET; } - if (!strcmp(pSubClass, "ENERGY")) + else if (strcmp(subClass, "ENERGY") == 0) { - return WSC_ENERGY; + *wclass = WSC_ENERGY; } - if (!strcmp(pSubClass, "GAUSS")) + else if (strcmp(subClass, "GAUSS") == 0) { - return WSC_GAUSS; + *wclass = WSC_GAUSS; } - if (!strcmp(pSubClass, "FLAME")) + else if (strcmp(subClass, "FLAME") == 0) { - return WSC_FLAME; + *wclass = WSC_FLAME; } - if (!strcmp(pSubClass, "HOWITZERS")) + else if (strcmp(subClass, "HOWITZERS") == 0) { - return WSC_HOWITZERS; + *wclass = WSC_HOWITZERS; } - if (!strcmp(pSubClass, "MACHINE GUN")) + else if (strcmp(subClass, "MACHINE GUN") == 0) { - return WSC_MGUN; + *wclass = WSC_MGUN; } - if (!strcmp(pSubClass, "ELECTRONIC")) + else if (strcmp(subClass, "ELECTRONIC") == 0) { - return WSC_ELECTRONIC; + *wclass = WSC_ELECTRONIC; } - if (!strcmp(pSubClass, "A-A GUN")) + else if (strcmp(subClass, "A-A GUN") == 0) { - return WSC_AAGUN; + *wclass = WSC_AAGUN; } - if (!strcmp(pSubClass, "SLOW MISSILE")) + else if (strcmp(subClass, "SLOW MISSILE") == 0) { - return WSC_SLOWMISSILE; + *wclass = WSC_SLOWMISSILE; } - if (!strcmp(pSubClass, "SLOW ROCKET")) + else if (strcmp(subClass, "SLOW ROCKET") == 0) { - return WSC_SLOWROCKET; + *wclass = WSC_SLOWROCKET; } - if (!strcmp(pSubClass, "LAS_SAT")) + else if (strcmp(subClass, "LAS_SAT") == 0) { - return WSC_LAS_SAT; + *wclass = WSC_LAS_SAT; } - if (!strcmp(pSubClass, "BOMB")) + else if (strcmp(subClass, "BOMB") == 0) { - return WSC_BOMB; + *wclass = WSC_BOMB; } - if (!strcmp(pSubClass, "COMMAND")) + else if (strcmp(subClass, "COMMAND") == 0) { - return WSC_COMMAND; + *wclass = WSC_COMMAND; } - if (!strcmp(pSubClass, "EMP")) + else if (strcmp(subClass, "EMP") == 0) { - return WSC_EMP; + *wclass = WSC_EMP; } + else + { + ASSERT(!"Invalid weapon sub class", "Invalid weapon sub class: %s", subClass); + return false; + } - //problem if we've got to here - ASSERT( false, "Invalid weapon sub class - %s", pSubClass ); - return INVALID_SUBCLASS; + return true; } /*returns the movement model based on the string name passed in */ diff --git a/src/stats.h b/src/stats.h index 9050ff4ec..3543bfe8e 100644 --- a/src/stats.h +++ b/src/stats.h @@ -45,7 +45,7 @@ extern PROPULSION_TYPES *asPropulsionTypes; extern WEAPON_MODIFIER asWeaponModifier[WE_NUMEFFECTS][PROPULSION_TYPE_NUM]; //used to hold the current upgrade level per player per weapon subclass -extern WEAPON_UPGRADE asWeaponUpgrade[MAX_PLAYERS][NUM_WEAPON_SUBCLASS]; +extern WEAPON_UPGRADE asWeaponUpgrade[MAX_PLAYERS][WSC_NUM_WEAPON_SUBCLASSES]; extern SENSOR_UPGRADE asSensorUpgrade[MAX_PLAYERS]; extern ECM_UPGRADE asECMUpgrade[MAX_PLAYERS]; extern REPAIR_UPGRADE asRepairUpgrade[MAX_PLAYERS]; @@ -265,7 +265,7 @@ extern SDWORD getCompFromName(UDWORD compType, const char *pName); //get the component Inc for a stat based on the Resource name held in Names.txt extern SDWORD getCompFromResName(UDWORD compType, const char *pName); /*returns the weapon sub class based on the string name passed in */ -extern WEAPON_SUBCLASS getWeaponSubClass(const char *pSubClass); +extern bool getWeaponSubClass(const char* subClass, WEAPON_SUBCLASS* wclass); /*either gets the name associated with the resource (if one) or allocates space and copies pName*/ extern BOOL allocateName(char **ppStore, const char *pName); //converts the name read in from Access into the name which is used in the Stat lists (or ignores it) diff --git a/src/statsdef.h b/src/statsdef.h index 031bebd0f..12574aace 100644 --- a/src/statsdef.h +++ b/src/statsdef.h @@ -62,47 +62,6 @@ typedef struct _comp_base_stats COMPONENT_STATS; } COMP_BASE_STATS; -//only using KINETIC and HEAT for now -typedef enum _weapon_class -{ - WC_KINETIC, ///< bullets etc - //WC_EXPLOSIVE, ///< rockets etc - classed as WC_KINETIC now to save space in DROID - WC_HEAT, ///< laser etc - //WC_MISC, ///< others we haven't thought of! - classed as WC_HEAT now to save space in DROID - - NUM_WEAPON_CLASS -} WEAPON_CLASS; - -// weapon subclasses used to define which weapons are affected by weapon upgrade functions -// Watermelon:added a new subclass to do some tests -typedef enum _weapon_subclass -{ - WSC_MGUN, - WSC_CANNON, - //WSC_ARTILLARY, - WSC_MORTARS, - WSC_MISSILE, - WSC_ROCKET, - WSC_ENERGY, - WSC_GAUSS, - WSC_FLAME, - //WSC_CLOSECOMBAT, - WSC_HOWITZERS, - WSC_ELECTRONIC, - WSC_AAGUN, - WSC_SLOWMISSILE, - WSC_SLOWROCKET, - WSC_LAS_SAT, - WSC_BOMB, - WSC_COMMAND, - WSC_EMP, - WSC_COUNTER, // Counter missile - - NUM_WEAPON_SUBCLASS, - - INVALID_SUBCLASS -} WEAPON_SUBCLASS; - // used to define which projectile model to use for the weapon typedef enum _movement_model { @@ -162,7 +121,7 @@ typedef struct _body_stats UBYTE size; ///< How big the body is - affects how hit UDWORD weaponSlots; ///< The number of weapon slots on the body - UDWORD armourValue[NUM_HIT_SIDES][NUM_WEAPON_CLASS]; ///< A measure of how much protection the armour provides. Cross referenced with the weapon types. + UDWORD armourValue[NUM_HIT_SIDES][WC_NUM_WEAPON_CLASSES]; ///< A measure of how much protection the armour provides. Cross referenced with the weapon types. // A measure of how much energy the power plant outputs UDWORD powerOutput; ///< this is the engine output of the body @@ -382,7 +341,7 @@ typedef struct _body_upgrade { UWORD powerOutput; UWORD body; - UWORD armourValue[NUM_WEAPON_CLASS]; + UWORD armourValue[WC_NUM_WEAPON_CLASSES]; } BODY_UPGRADE; #endif // __INCLUDED_STATSDEF_H__ diff --git a/src/structure.c b/src/structure.c index 5935264c8..1c23516c3 100644 --- a/src/structure.c +++ b/src/structure.c @@ -1773,7 +1773,7 @@ STRUCTURE* buildStructure(STRUCTURE_STATS* pStructureType, UDWORD x, UDWORD y, U { int j; - for (j = 0; j < NUM_WEAPON_CLASS; j++) + for (j = 0; j < WC_NUM_WEAPON_CLASSES; j++) { psBuilding->armour[i][j] = (UWORD)structureArmour(pStructureType, (UBYTE)player); }