16#include "damagetype.h"
27#define DTYPE_XML_ID "dtype"
34typedef struct DTYPE_ {
52static int dtype_cmp(
const void *p1,
const void *p2 );
57static int dtype_cmp(
const void *p1,
const void *p2 )
73 xmlNodePtr node, parent;
83 parent = doc->xmlChildrenNode;
85 WARN(_(
"Malformed '%s' file: missing root element '%s'"), file,
DTYPE_XML_ID);
90 memset( temp, 0,
sizeof(
DTYPE) );
92 xmlr_attr_strd( parent,
"name", temp->
name );
93 xmlr_attr_strd( parent,
"display", temp->
display );
96 node = parent->xmlChildrenNode;
100 if (xml_isNode(node,
"shield")) {
101 temp->
sdam = xml_getFloat(node);
103 xmlr_attr_strd( node,
"stat", stat );
111 else if (xml_isNode(node,
"armour")) {
112 temp->
adam = xml_getFloat(node);
114 xmlr_attr_strd( node,
"stat", stat );
122 xmlr_float(node,
"knockback", temp->
knock);
124 WARN(_(
"Unknown node of type '%s' in damage node '%s'."), node->name, temp->
name);
125 }
while (xml_nextNode(node));
127#define MELEMENT(o,s) \
128 if (o) WARN(_("DTYPE '%s' invalid '"s"' element"), temp->name)
129 MELEMENT(temp->
sdam<0.,
"shield");
130 MELEMENT(temp->
adam<0.,
"armour");
131 MELEMENT(temp->
knock<0.,
"knockback");
148 damtype->
name = NULL;
161 const DTYPE d= { .name = (
char*)name };
164 WARN(_(
"Damage type '%s' not found in stack."), name);
176 WARN(_(
"Damage type '%d' is invalid."), type);
201 .name = strdup(N_(
"raw")),
215 for (
int i=0; i<
array_size(dtype_files); i++) {
220 free( dtype_files[i] );
252int dtype_raw(
int type,
double *shield,
double *armour,
double *knockback )
258 *shield = dtype->
sdam;
260 *armour = dtype->
adam;
261 if (knockback != NULL)
262 *knockback = dtype->
knock;
288 if (dshield != NULL) {
289 if ((dtype->
soffset <= 0) || (s == NULL))
290 *dshield = dtype->
sdam * dmg->
damage * absorb;
300 memcpy(&multiplier, &ptr[ dtype->
soffset ],
sizeof(
double));
301 multiplier =
MAX( 0., 1. - multiplier );
302 *dshield = dtype->
sdam * dmg->
damage * absorb * multiplier;
305 if (darmour != NULL) {
306 if ((dtype->
aoffset) <= 0 || (s == NULL))
307 *darmour = dtype->
adam * dmg->
damage * absorb;
310 memcpy(&multiplier, &ptr[ dtype->
aoffset ],
sizeof(
double));
311 multiplier =
MAX( 0., 1. - multiplier );
312 *darmour = dtype->
adam * dmg->
damage * absorb * multiplier;
316 if (knockback != NULL)
317 *knockback = dtype->
knock;
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_shrink(ptr_array)
Shrinks memory to fit only ‘size’ elements.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
int dtype_load(void)
Loads the dtype stack.
static void DTYPE_free(DTYPE *damtype)
Frees a DTYPE.
int dtype_raw(int type, double *shield, double *armour, double *knockback)
Gets the raw modulation stats of a damage type.
void dtype_calcDamage(double *dshield, double *darmour, double absorb, double *knockback, const Damage *dmg, const ShipStats *s)
Gives the real shield damage, armour damage and knockback modifier.
static DTYPE * dtype_types
int dtype_get(const char *name)
Gets the id of a dtype based on name.
void dtype_free(void)
Frees the dtype stack.
static int DTYPE_parse(DTYPE *temp, const char *file)
Parses an XML file containing a DTYPE.
static DTYPE * dtype_validType(int type)
Gets the damage type.
const char * dtype_damageTypeToStr(int type)
Gets the human readable string from damage type.
static int dtype_cmp(const void *p1, const void *p2)
For sorting and bsearching.
Header file with generic functions and naev-specifics.
char ** ndata_listRecursive(const char *path)
Lists all the visible files in a directory, at any depth.
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
size_t ss_offsetFromType(ShipStatsType type)
Gets the offset from type.
ShipStatsType ss_typeFromName(const char *name)
Gets the type from the name.
Core damage that an outfit does.
Represents ship statistics, properties ship can use.