From 5d340655129a9135324ab5626122d5b8cf725096 Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 15 Apr 2014 23:14:38 +0100 Subject: [PATCH] [Add] Support for different armour/shield hit animations. --- src/outfit.c | 67 +++++++++++++++++++++++++++++++++++++++------------- src/outfit.h | 9 ++++--- src/weapon.c | 26 +++++++++++++++----- 3 files changed, 76 insertions(+), 26 deletions(-) diff --git a/src/outfit.c b/src/outfit.c index 64781f7..e8e03dd 100644 --- a/src/outfit.c +++ b/src/outfit.c @@ -331,10 +331,21 @@ glTexture* outfit_gfx(const Outfit* o) { * @brief Get the outfits sound effect. * @param o Outfit to get information from. */ -int outfit_spfx(const Outfit* o) { - if(outfit_isBolt(o)) return o->u.blt.spfx; - else if(outfit_isBeam(o)) return o->u.bem.spfx; - else if(outfit_isAmmo(o)) return o->u.amm.spfx; +int outfit_spfxArmour(const Outfit* o) { + if(outfit_isBolt(o)) return o->u.blt.spfx_armour; + else if(outfit_isBeam(o)) return o->u.bem.spfx_armour; + else if(outfit_isAmmo(o)) return o->u.amm.spfx_armour; + return -1; +} + +/** + * @brief Get the outfits sound effect. + * @param o Outfit to get information from. + */ +int outfit_spfxShield(const Outfit* o) { + if(outfit_isBolt(o)) return o->u.blt.spfx_shield; + else if(outfit_isBeam(o)) return o->u.bem.spfx_shield; + else if(outfit_isAmmo(o)) return o->u.amm.spfx_shield; return -1; } @@ -554,8 +565,9 @@ static void outfit_parseSBolt(Outfit* tmp, const xmlNodePtr parent) { char str[PATH_MAX] = "\0"; /* Defaults. */ - tmp->u.blt.spfx = -1; - tmp->u.blt.sound = -1; + tmp->u.blt.spfx_armour = -1; + tmp->u.blt.spfx_shield = -1; + tmp->u.blt.sound = -1; node = parent->xmlChildrenNode; do { @@ -571,8 +583,12 @@ static void outfit_parseSBolt(Outfit* tmp, const xmlNodePtr parent) { tmp->u.blt.gfx_space = gl_newSprite(str, 6, 6); continue; } - if(xml_isNode(node, "spfx")) { - tmp->u.blt.spfx = spfx_get(xml_get(node)); + if(xml_isNode(node, "spfx_shield")) { + tmp->u.blt.spfx_shield = spfx_get(xml_get(node)); + continue; + } + if(xml_isNode(node, "spfx_armour")) { + tmp->u.blt.spfx_armour = spfx_get(xml_get(node)); continue; } if(xml_isNode(node, "sound")) { @@ -583,12 +599,13 @@ static void outfit_parseSBolt(Outfit* tmp, const xmlNodePtr parent) { outfit_parseDamage(&tmp->u.blt.dtype, &tmp->u.blt.damage, node); continue; } - } while((node = node->next)); + } while(xml_nextNode(node)); #define MELEMENT(o,s) \ if (o) WARN("Outfit '%s' missing/invalid '"s"' element", tmp->name) MELEMENT(tmp->u.blt.gfx_space==NULL, "gfx"); - MELEMENT(tmp->u.blt.spfx==-1, "spfx"); + MELEMENT(tmp->u.blt.spfx_shield==-1, "spfx_shield"); + MELEMENT(tmp->u.blt.spfx_armour==-1, "spfx_armour"); MELEMENT((sound_disabled!=0) && (tmp->u.blt.sound<0), "sound"); MELEMENT(tmp->u.blt.delay==0, "delay"); MELEMENT(tmp->u.blt.speed==0, "speed"); @@ -610,7 +627,8 @@ static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) { char str[PATH_MAX] = "\0"; /* Defaults. */ - tmp->u.bem.spfx = -1; + tmp->u.bem.spfx_armour = -1; + tmp->u.bem.spfx_shield = -1; tmp->u.bem.sound_warmup = -1; tmp->u.bem.sound = -1; tmp->u.bem.sound_off = -1; @@ -636,8 +654,13 @@ static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) { continue; } - if(xml_isNode(node, "spfx")) { - tmp->u.bem.spfx = spfx_get(xml_get(node)); + if(xml_isNode(node, "spfx_armour")) { + tmp->u.bem.spfx_armour = spfx_get(xml_get(node)); + continue; + } + + if(xml_isNode(node, "spfx_shield")) { + tmp->u.bem.spfx_shield = spfx_get(xml_get(node)); continue; } @@ -661,7 +684,8 @@ static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) { #define MELEMENT(o,s) if(0) WARN("Outfit '%s' missing/invalid '"s"' element", tmp->name) MELEMENT(tmp->u.bem.gfx==NULL, "gfx"); - MELEMENT(tmp->u.bem.spfx==-1, "spfx"); + MELEMENT(tmp->u.bem.spfx_shield==-1, "spfx_shield"); + MELEMENT(tmp->u.bem.spfx_armour==-1, "spfx_armour"); MELEMENT((sound_disabled!=0) && (tmp->u.bem.warmup > 0.) && (tmp->u.bem.sound<0),"sound_warmup"); MELEMENT((sound_disabled!=0) && (tmp->u.bem.sound < 0), "sound"); MELEMENT((sound_disabled!=0) && (tmp->u.bem.sound_off < 0), "sound_off"); @@ -699,6 +723,11 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) { char str[PATH_MAX] = "\0"; + /* Defaults. */ + tmp->u.amm.spfx_armour = -1; + tmp->u.amm.spfx_shield = -1; + tmp->u.amm.sound = -1; + do { /* Basic. */ xmlr_float(node, "duration", tmp->u.amm.duration); @@ -714,19 +743,23 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) { tmp->u.amm.gfx_space = gl_newSprite(str, 6, 6); continue; } - else if(xml_isNode(node, "spfx")) - tmp->u.amm.spfx = spfx_get(xml_get(node)); + else if(xml_isNode(node, "spfx_armour")) + tmp->u.amm.spfx_armour = spfx_get(xml_get(node)); + else if(xml_isNode(node, "spfx_shield")) + tmp->u.amm.spfx_shield = 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")) outfit_parseDamage(&tmp->u.amm.dtype, &tmp->u.amm.damage, node); - } while((node = node->next)); + } while(xml_nextNode(node)); /* Post-processing. */ tmp->u.amm.resist /= 100.; /* Set it in per one. */ #define MELEMENT(o,s) if(o) WARN("Outfit '%s' missing '"s"' element", tmp->name) MELEMENT(tmp->u.amm.gfx_space == NULL, "gfx"); + MELEMENT(tmp->u.amm.spfx_shield==-1, "spfx_shield"); + MELEMENT(tmp->u.amm.spfx_armour==-1, "spfx_armour"); MELEMENT((sound_disabled != 0) && (tmp->u.amm.sound < 0), "sound"); MELEMENT(tmp->u.amm.thrust==0, "thrust"); /* Dumb missiles don't need everything. */ diff --git a/src/outfit.h b/src/outfit.h index daa958f..cdeb1e1 100644 --- a/src/outfit.h +++ b/src/outfit.h @@ -71,7 +71,8 @@ typedef struct OutfitBoltData_ { /* Sound and graphics. */ glTexture* gfx_space; /**< Graphic. */ int sound; /**< Sound to play. */ - int spfx; /**< Special effect on hit. */ + int spfx_armour; /**< Special effect on hit. */ + int spfx_shield; /**< Special effect on hit. */ } OutfitBoltData; /** @@ -95,7 +96,8 @@ typedef struct OutfitBeamData_ { /* Graphics and sound */ glTexture* gfx; /**< Base texture. */ - int spfx; /**< Special effect on hit. */ + int spfx_armour; /**< Special effect on hit. */ + int spfx_shield; /**< Special effect on hit. */ int sound_warmup; /**< Sound to play when warming up. @todo use. */ int sound; /**< Sound to play. */ int sound_off; /**< Sound to play when turning off. */ @@ -133,7 +135,8 @@ typedef struct OutfitAmmoData_ { glTexture* gfx_space; /**< Graphic. */ int sound; /**< Sound to play. */ - int spfx; /**< Special effect on hit. */ + int spfx_armour; /**< Special effect on hit. */ + int spfx_shield; /**< Special effect on hit. */ } OutfitAmmoData; /** diff --git a/src/weapon.c b/src/weapon.c index 1bda436..40df881 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -609,6 +609,13 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) { */ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) { Pilot* parent; + int spfx; + + /* Choose spfx. */ + if(p->shield > 0.) + spfx = outfit_spfxShield(w->outfit); + else + spfx = outfit_spfxArmour(w->outfit); /* Someone should let the ai know it's been attacked. */ if(!pilot_isPlayer(p)) { @@ -623,10 +630,10 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) { pilot_rmFlag(p, PILOT_BRIBED); ai_attacked(p, w->parent); } - spfx_add(outfit_spfx(w->outfit), pos->x, pos->y, + spfx_add(spfx, pos->x, pos->y, VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_BACK); } else - spfx_add(outfit_spfx(w->outfit), pos->x, pos->y, + spfx_add(spfx, pos->x, pos->y, VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_FRONT); /* Let the ship know that is should take some kind of damage. */ @@ -652,6 +659,13 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer, (void)layer; Pilot* parent; + int spfx; + + /* Choose spfx. */ + if(p->shield > 0.) + spfx = outfit_spfxShield(w->outfit); + else + spfx = outfit_spfxArmour(w->outfit); /* Inform the ai it has been attacked, useless if player. */ if(!pilot_isPlayer(p)) { @@ -667,17 +681,17 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer, ai_attacked(p, w->parent); } if(w->lockon == -1.) { /* Code to signal create explosions. */ - spfx_add(outfit_spfx(w->outfit), pos[0].x, pos[0].y, + spfx_add(spfx, pos[0].x, pos[0].y, VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_BACK); - spfx_add(outfit_spfx(w->outfit), pos[1].x, pos[1].y, + spfx_add(spfx, pos[1].x, pos[1].y, VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_BACK); w->lockon = -2; } } else if(w->lockon == -1.) { - spfx_add(outfit_spfx(w->outfit), pos[0].x, pos[0].y, + spfx_add(spfx, pos[0].x, pos[0].y, VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_FRONT); - spfx_add(outfit_spfx(w->outfit), pos[1].x, pos[1].y, + spfx_add(spfx, pos[1].x, pos[1].y, VX(p->solid->vel), VY(p->solid->vel), SPFX_LAYER_FRONT); w->lockon = -2; }