From 65e25f6ce0e6ece93e8db1aa86d2737454d73370 Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 4 Jun 2013 12:06:39 +0100 Subject: [PATCH] [Change] Moved from damage_armour and co, to just damage and damagetype. --- dat/outfit.xml | 30 +++------------ src/outfit.c | 100 +++++++++++++++++++++++++++++++++---------------- src/outfit.h | 51 +++++++++++++++---------- src/pilot.c | 7 +++- src/pilot.h | 2 +- src/weapon.c | 3 +- 6 files changed, 114 insertions(+), 79 deletions(-) diff --git a/dat/outfit.xml b/dat/outfit.xml index 57514b1..4572c21 100644 --- a/dat/outfit.xml +++ b/dat/outfit.xml @@ -18,10 +18,7 @@ 300 1 8 - - 10 - 13 - + 10 @@ -42,10 +39,7 @@ 300 30 10 - - 13 - 10 - + 10 @@ -66,10 +60,7 @@ 500 10 30 - - 35 - 30 - + 30 @@ -104,10 +95,7 @@ 1600 200 800 - - 25 - 20 - + 20 @@ -142,10 +130,7 @@ 1300 200 650 - - 23 - 18 - + 20 @@ -166,10 +151,7 @@ 200 15 5 - - 7 - 7 - + 7 diff --git a/src/outfit.c b/src/outfit.c index 0965313..fb2a6e6 100644 --- a/src/outfit.c +++ b/src/outfit.c @@ -24,6 +24,10 @@ extern SDL_mutex* sound_lock; // Sound.c static Outfit* outfit_stack = NULL; static int outfits = 0; +// Misc. +static DamageType outfit_strToDamageType(char* buf); +// Parsing. +static int outfit_parseDamage(DamageType* dtype, double* dmg, xmlNodePtr node); static Outfit* outfit_parse(const xmlNodePtr parent); static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent); static void outfit_parseSLauncher(Outfit* tmp, const xmlNodePtr parent); @@ -62,6 +66,24 @@ char** outfit_getTech(int* n, const int* tech, const int techmax) { return outfitnames; } +void outfit_calcDamage(double* dshield, double* darmour, + DamageType dtype, double dmg) { + + switch(dtype) { + case DAMAGE_TYPE_ENERGY: + (*dshield) = dmg*1.1; + (*darmour) = dmg*0.7; + break; + case DAMAGE_TYPE_KINETIC: + (*dshield) = dmg*0.8; + (*darmour) = dmg*1.2; + break; +defualt: + (*dshield) = (*darmour) = 0.; + break; + } +} + // Return 1 if outfit is a weapon (beam/bolt). int outfit_isWeapon(const Outfit* o) { return ((o->type == OUTFIT_TYPE_BOLT) || (o->type == OUTFIT_TYPE_BEAM)); @@ -117,18 +139,18 @@ int outfit_spfx(const Outfit* o) { return -1; } -double outfit_dmgShield(const Outfit* o) { - if(outfit_isWeapon(o)) return o->u.blt.damage_armour; - else if(outfit_isAmmo(o)) return o->u.amm.damage_armour; - else if(outfit_isTurret(o)) return o->u.blt.damage_armour; +double outfit_damage(const Outfit* o) { + if(outfit_isWeapon(o)) return o->u.blt.damage; + else if(outfit_isAmmo(o)) return o->u.amm.damage; + else if(outfit_isTurret(o)) return o->u.blt.damage; return -1; } -double outfit_dmgArmour(const Outfit* o) { - if(outfit_isWeapon(o)) return o->u.blt.damage_shield; - else if(outfit_isAmmo(o)) return o->u.amm.damage_shield; - else if(outfit_isTurret(o)) return o->u.blt.damage_shield; - return -1; +DamageType outfit_damageType(const Outfit* o) { + if(outfit_isWeapon(o)) return o->u.blt.dtype; + else if(outfit_isAmmo(o)) return o->u.amm.dtype; + else if(outfit_isTurret(o)) return o->u.blt.dtype; + return DAMAGE_TYPE_NULL; } int outfit_delay(const Outfit* o) { @@ -192,13 +214,39 @@ const char* outfit_getTypeBroad(const Outfit* o) { return outfit_typenamebroad[i]; } +// Return the damage type from a str. +static DamageType outfit_strToDamageType(char* buf) { + if(strcmp(buf, "energy")==0) return DAMAGE_TYPE_ENERGY; + else if(strcmp(buf, "kinetic")==0) return DAMAGE_TYPE_KINETIC; + + WARN("Invalid damage type: '%s'", buf); + return DAMAGE_TYPE_NULL; +} + +static int outfit_parseDamage(DamageType* dtype, double* dmg, xmlNodePtr node) { + char* buf; + + if(xml_isNode(node, "damage")) { + xmlr_attr(node, "type", buf); + (*dtype) = outfit_strToDamageType(buf); + if(buf) free(buf); + (*dmg) = xml_getFloat(node); + + return 0; + } + + (*dtype) = DAMAGE_TYPE_NULL; + (*dmg) = 0; + WARN("Trying to parse non-damage node as damage node!"); + return 1; +} + // Parses the specific area for a weapon and loads it into outfit. static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) { - xmlNodePtr cur, node; - node = parent->xmlChildrenNode; - + xmlNodePtr node; char str[PATH_MAX] = "\0"; + node = parent->xmlChildrenNode; do { // Load all the things. xmlr_float(node, "speed", tmp->u.blt.speed); @@ -216,25 +264,19 @@ static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) { tmp->u.blt.spfx = spfx_get(xml_get(node)); else if(xml_isNode(node, "sound")) tmp->u.blt.sound = sound_get(xml_get(node)); - else if(xml_isNode(node, "damage")) { - cur = node->children; - do { - xmlr_float(cur, "armour", tmp->u.blt.damage_armour); - xmlr_float(cur, "shield", tmp->u.blt.damage_shield); - } while((cur = cur->next)); - } + else if(xml_isNode(node, "damage")) + outfit_parseDamage(&tmp->u.blt.dtype, &tmp->u.blt.damage, node); } while((node = node->next)); #define MELEMENT(o,s) if((o) == 0) \ WARN("Outfit '%s' missing '"s"' element", tmp->name) if(tmp->u.blt.gfx_space == NULL) WARN("Outfit '%s' missing 'gfx' element", tmp->name); - MELEMENT(tmp->u.blt.sound, "sound"); + MELEMENT(tmp->u.blt.sound, "sound"); MELEMENT(tmp->u.blt.delay, "delay"); MELEMENT(tmp->u.blt.speed, "speed"); MELEMENT(tmp->u.blt.range, "range"); MELEMENT(tmp->u.blt.accuracy, "accuracy"); - MELEMENT(tmp->u.blt.damage_armour, "armour' from element 'damage"); - MELEMENT(tmp->u.blt.damage_shield, "shield' from element 'damage"); + MELEMENT(tmp->u.blt.damage==0, "damage"); #undef MELEMENT } @@ -257,7 +299,7 @@ static void outfit_parseSLauncher(Outfit* tmp, const xmlNodePtr parent) { // Parse the specific area for a weapon and load it into Outfit. static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) { - xmlNodePtr cur, node; + xmlNodePtr node; node = parent->xmlChildrenNode; char str[PATH_MAX] = "\0"; @@ -280,13 +322,8 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) { tmp->u.amm.spfx = spfx_get(xml_get(node)); else if(xml_isNode(node, "sound")) tmp->u.amm.sound = sound_get(xml_get(node)); - else if(xml_isNode(node, "damage")) { - cur = node->children; - do { - xmlr_float(cur, "armour", tmp->u.amm.damage_armour); - xmlr_float(cur, "shield", tmp->u.amm.damage_shield); - } while((cur = cur->next)); - } + else if(xml_isNode(node, "damage")) + outfit_parseDamage(&tmp->u.amm.dtype, &tmp->u.amm.damage, node); } while((node = node->next)); #define MELEMENT(o,s) if(o) WARN("Outfit '%s' missing '"s"' element", tmp->name) MELEMENT(tmp->u.amm.gfx_space == NULL, "gfx"); @@ -296,8 +333,7 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) { MELEMENT(tmp->u.amm.speed==0, "speed"); MELEMENT(tmp->u.amm.duration==0, "duration"); MELEMENT(tmp->u.amm.lockon==0, "lockon"); - MELEMENT(tmp->u.amm.damage_armour==0, "armour' from element 'damage"); - MELEMENT(tmp->u.amm.damage_shield==0, "shield' from element 'damage"); + MELEMENT(tmp->u.amm.damage==0, "damage"); #undef MELEMENT } diff --git a/src/outfit.h b/src/outfit.h index d9d2c88..0502850 100644 --- a/src/outfit.h +++ b/src/outfit.h @@ -27,6 +27,13 @@ typedef enum OutfitType_ { OUTFIT_TYPE_AFTERBURNER = 16 } OutfitType; +typedef enum DamageType_ { + DAMAGE_TYPE_NULL = 0, + DAMAGE_TYPE_ENERGY = 1, + DAMAGE_TYPE_KINETIC = 2 + +} DamageType; + // An outfit depends a lot on the type. typedef struct Outfit_ { char* name; @@ -49,20 +56,21 @@ typedef struct Outfit_ { union { struct { // Bolt. unsigned int delay; // Delay between shots. - double speed; // Speed of shot. (not applicable to beam. + double speed; // Speed of shot. (not applicable to beam. double range; - double accuracy; // Desviation accuracy. - double energy; // Energy usage. - double damage_armour, damage_shield; // Damage. + double accuracy; // Desviation accuracy. + double energy; // Energy usage. + DamageType dtype; // Damage type. + double damage; // Damage. glTexture* gfx_space; ALuint sound; // Sound to play. - int spfx; // Special effect on hit. + int spfx; // Special effect on hit. } blt; struct { // Beam. - double range; // Distance it travels. - glColour colour; // Beam colour. - double energy; // Energy drained. + double range; // Distance it travels. + glColour colour; // Beam colour. + double energy; // Energy drained. double damage_armour, damage_shield; // Damage. } bem; struct { // Launcher. @@ -70,17 +78,18 @@ typedef struct Outfit_ { char* ammo; } lau; struct { // Ammo. - unsigned int duration; // Duration. - double speed; // Max speed. - double turn; // Turn vel. - double thrust; // Acceleration. - double energy; // Energy usage. - double damage_armour, damage_shield; // Damage. + unsigned int duration; // Duration. + double speed; // Max speed. + double turn; // Turn vel. + double thrust; // Acceleration. + double energy; // Energy usage. + DamageType dtype; // Damage type. + double damage; // Damage. glTexture* gfx_space; - ALuint sound; // Sound to play. - int spfx; // Special effect on hit. - unsigned int lockon; // Time taken to lock on the target. + ALuint sound; // Sound to play. + int spfx; // Special effect on hit. + unsigned int lockon; // Time taken to lock on the target. } amm; struct { // Modification. // Movement. @@ -104,6 +113,10 @@ typedef struct Outfit_ { } u; } Outfit; +// Misc. +void outfit_calcDamage(double* dshield, double* darmour, + DamageType dtype, double dmg); + // Get. Outfit* outfit_get(const char* name); char** outfit_getTech(int* n, const int* tech, const int techmax); @@ -120,8 +133,8 @@ const char* outfit_getTypeBroad(const Outfit* o); // Get data from outfit. glTexture* outfit_gfx(const Outfit* o); int outfit_spfx(const Outfit* o); -double outfit_dmgShield(const Outfit* o); -double outfit_dmgArmour(const Outfit* o); +double outfit_damage(const Outfit* o); +DamageType outfit_damageType(const Outfit* o); int outfit_delay(const Outfit* o); double outfit_energy(const Outfit* o); diff --git a/src/pilot.c b/src/pilot.c index 6ef7894..b4dc430 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -242,9 +242,12 @@ static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t) { // Damage the pilot. void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter, - const double damage_shield, const double damage_armour) { + const DamageType dtype, const double damage) { - double dam_mod; + double damage_shield, damage_armour, dam_mod; + + // Calculate the damage. + outfit_calcDamage(&damage_shield, &damage_armour, dtype, damage); if(p->shield - damage_shield > 0.) { p->shield -= damage_shield; diff --git a/src/pilot.h b/src/pilot.h index a1fa3e2..7a09f4f 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -145,7 +145,7 @@ int pilot_getJumps(const Pilot* p); // MISC. void pilot_shoot(Pilot* p, const unsigned int target, const int secondary); void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter, - const double damage_shield, const double damage_armour); + const DamageType dtype, const double damage); void pilot_setSecondary(Pilot* p, const char* secondary); void pilot_setAmmo(Pilot* p); double pilot_face(Pilot* p, const float dir); diff --git a/src/weapon.c b/src/weapon.c index 49455ff..b4980b5 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -338,7 +338,8 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer) { VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_FRONT); // Let the ship know that is should take some kind of damage. - pilot_hit(p, w->solid, w->parent, outfit_dmgShield(w->outfit), outfit_dmgShield(w->outfit)); + pilot_hit(p, w->solid, w->parent, + outfit_damageType(w->outfit), outfit_damage(w->outfit)); // We don't need the weapon particle any longer. weapon_destroy(w, layer); }