From 2e444ff54b47d6500ca66e390f085a15b11cb470 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 21 Sep 2013 21:30:51 +0100 Subject: [PATCH] [Change] Split beam/bolt loading logic. --- src/outfit.c | 64 +++++++++++++++++++++++++++++++++++++++------------- src/outfit.h | 9 ++++---- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/outfit.c b/src/outfit.c index e745df2..33be31d 100644 --- a/src/outfit.c +++ b/src/outfit.c @@ -28,7 +28,8 @@ static OutfitType outfit_strToOutfitType(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_parseSBolt(Outfit* tmp, const xmlNodePtr parent); +static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent); static void outfit_parseSLauncher(Outfit* tmp, const xmlNodePtr parent); static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent); static void outfit_parseSMod(Outfit* tmp, const xmlNodePtr parent); @@ -436,7 +437,7 @@ static int outfit_parseDamage(DamageType* dtype, double* dmg, xmlNodePtr node) { } /* Parses the specific area for a weapon and loads it into outfit. */ -static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) { +static void outfit_parseSBolt(Outfit* tmp, const xmlNodePtr parent) { xmlNodePtr node; char str[PATH_MAX] = "\0"; @@ -468,7 +469,7 @@ static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) { #define MELEMENT(o,s) \ if (o) WARN("Outfit '%s' missing/invalid '"s"' element", tmp->name) MELEMENT(tmp->u.blt.gfx_space==NULL, "gfx"); - MELEMENT((sound_disabled!=NULL) && (tmp->u.blt.sound==0), "sound"); + MELEMENT((sound_disabled!=0) && (tmp->u.blt.sound<0), "sound"); MELEMENT(tmp->u.blt.delay==0, "delay"); MELEMENT(tmp->u.blt.speed==0, "speed"); MELEMENT(tmp->u.blt.range==0, "range"); @@ -477,6 +478,37 @@ static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) { #undef MELEMENT } +/** + * @fn static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) + * + * @brief Parse the beam weapon specifics of an outfit. + * @param tmp Outfit to finish loading. + * @param parent Outfit's parent node. + */ +static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) { + xmlNodePtr node; + + node = parent->xmlChildrenNode; + do { /* Load all the data. */ + xmlr_float(node, "range", tmp->u.bem.range); + xmlr_float(node, "turn", tmp->u.bem.turn); + xmlr_float(node, "energy", tmp->u.bem.energy); + + if(xml_isNode(node, "damage")) + outfit_parseDamage(&tmp->u.bem.dtype, &tmp->u.bem.damage, node); + } while(xml_nextNode(node)); + + tmp->u.bem.colour = &cWhite; /** @todo Make it loadable. */ + +#define MELEMENT(o,s) if(0) WARN("Outfit '%s' missing/invalid '"s"' element", tmp->name) + MELEMENT(tmp->u.bem.range==0, "range"); + MELEMENT(tmp->u.bem.turn==0, "turn"); + MELEMENT(tmp->u.bem.energy==0, "energy"); + MELEMENT(tmp->u.bem.damage==0, "damage"); +#undef MELEMENT + +} + /* Parse the specific area for a launcher and loads it into Outfit. */ static void outfit_parseSLauncher(Outfit* tmp, const xmlNodePtr parent) { xmlNodePtr node; @@ -530,7 +562,7 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) { #define MELEMENT(o,s) if(o) WARN("Outfit '%s' missing '"s"' element", tmp->name) MELEMENT(tmp->u.amm.gfx_space == NULL, "gfx"); - MELEMENT((sound_disabled != NULL) && (tmp->u.amm.sound == 0), "sound"); + MELEMENT((sound_disabled != 0) && (tmp->u.amm.sound < 0), "sound"); MELEMENT(tmp->u.amm.thrust==0, "thrust"); /* Dumb missiles don't need everything. */ if(tmp->type != OUTFIT_TYPE_MISSILE_DUMB_AMMO) { @@ -673,14 +705,14 @@ static Outfit* outfit_parse(const xmlNodePtr parent) { } if(tmp->type == OUTFIT_TYPE_NULL) WARN("Outfit '%s' is of type NONE", tmp->name); - else if(outfit_isWeapon(tmp)) - outfit_parseSWeapon(tmp, node); + else if(outfit_isBolt(tmp)) + outfit_parseSBolt(tmp, node); + else if(outfit_isBeam(tmp)) + outfit_parseSBeam(tmp, node); else if(outfit_isLauncher(tmp)) outfit_parseSLauncher(tmp, node); else if(outfit_isAmmo(tmp)) outfit_parseSAmmo(tmp, node); - else if(outfit_isTurret(tmp)) - outfit_parseSWeapon(tmp, node); else if(outfit_isMod(tmp)) outfit_parseSMod(tmp, node); else if(outfit_isAfterburner(tmp)) @@ -690,15 +722,15 @@ static Outfit* outfit_parse(const xmlNodePtr parent) { else if(outfit_isJammer(tmp)) outfit_parseSJammer(tmp, node); } - } while((node = node->next)); + } while(xml_nextNode(node)); #define MELEMENT(o,s) if(o) WARN("Outfit '%s' missing '"s"' element", tmp->name) - MELEMENT(tmp->name==NULL, "name"); - MELEMENT(tmp->max==0, "max"); - MELEMENT(tmp->tech==0, "tech"); - MELEMENT(tmp->gfx_store==NULL, "gfx_store"); - /*MELEMENT(tmp->mass==0, "mass"); */ - MELEMENT(tmp->type==0, "type"); - MELEMENT(tmp->price==0, "price"); + MELEMENT(tmp->name==NULL, "name"); + MELEMENT(tmp->max==0, "max"); + MELEMENT(tmp->tech==0, "tech"); + MELEMENT(tmp->gfx_store==NULL, "gfx_store"); + /*MELEMENT(tmp->mass==0, "mass"); */ + MELEMENT(tmp->type==0, "type"); + MELEMENT(tmp->price==0, "price"); MELEMENT(tmp->description==NULL, "description"); #undef MELEMENT diff --git a/src/outfit.h b/src/outfit.h index 2e5064f..f130693 100644 --- a/src/outfit.h +++ b/src/outfit.h @@ -64,10 +64,11 @@ typedef struct OutfitBoltData_ { */ typedef struct OutfitBeamData_ { double range; /**< How far it goes. */ - glColour colour; /**< Beam colour. */ - double energy; /**< Energy it drains. */ - double dtype; /**< Damage type. */ - double damage; /**< Damage. */ + double turn; /**< How fast it can turn. Only for turrets. */ + glColour* colour; /**< Beam colour. */ + double energy; /**< Amount of energy it drains (per second). */ + DamageType dtype; /**< Damage type. */ + double damage; /**< Damage amount. */ } OutfitBeamData; /**