13#include "damagetype.h"
21#define DTYPE_XML_ID "dtype"
28typedef struct DTYPE_ {
46static int dtype_cmp(
const void *p1,
const void *p2 );
51static int dtype_cmp(
const void *p1,
const void *p2 )
67 xmlNodePtr node, parent;
77 parent = doc->xmlChildrenNode;
79 WARN( _(
"Malformed '%s' file: missing root element '%s'" ), file,
85 memset( temp, 0,
sizeof(
DTYPE ) );
87 xmlr_attr_strd( parent,
"name", temp->
name );
88 xmlr_attr_strd( parent,
"display", temp->
display );
91 node = parent->xmlChildrenNode;
93 xml_onlyNodes( node );
95 if ( xml_isNode( node,
"shield" ) ) {
96 temp->
sdam = xml_getFloat( node );
98 xmlr_attr_strd( node,
"stat", stat );
105 }
else if ( xml_isNode( node,
"armour" ) ) {
106 temp->
adam = xml_getFloat( node );
108 xmlr_attr_strd( node,
"stat", stat );
109 if ( stat != NULL ) {
116 xmlr_float( node,
"knockback", temp->
knock );
118 WARN( _(
"Unknown node of type '%s' in damage node '%s'." ), node->name,
120 }
while ( xml_nextNode( node ) );
122#define MELEMENT( o, s ) \
124 WARN( _( "DTYPE '%s' invalid '"s \
127 MELEMENT( temp->
sdam < 0.,
"shield" );
128 MELEMENT( temp->
adam < 0.,
"armour" );
129 MELEMENT( temp->
knock < 0.,
"knockback" );
145 free( damtype->
name );
146 damtype->
name = NULL;
159 const DTYPE d = { .name = (
char *)name };
162 if ( dout == NULL ) {
163 WARN( _(
"Damage type '%s' not found in stack." ), name );
175 WARN( _(
"Damage type '%d' is invalid." ), type );
199 const DTYPE dtype_raw_type = {
200 .name = strdup( N_(
"raw" ) ),
214 for (
int i = 0; i <
array_size( dtype_files ); i++ ) {
219 free( dtype_files[i] );
251int dtype_raw(
int type,
double *shield,
double *armour,
double *knockback )
256 if ( shield != NULL )
257 *shield = dtype->
sdam;
258 if ( armour != NULL )
259 *armour = dtype->
adam;
260 if ( knockback != NULL )
261 *knockback = dtype->
knock;
276 double *knockback,
const Damage *dmg,
289 if ( dshield != NULL ) {
290 if ( ( dtype->
soffset == 0 ) || ( s == NULL ) )
291 *dshield = dtype->
sdam * dmg->
damage * absorb;
301 memcpy( &multiplier, &ptr[dtype->
soffset],
sizeof(
double ) );
302 multiplier =
MAX( 0., 1. - multiplier );
303 *dshield = dtype->
sdam * dmg->
damage * absorb * multiplier;
306 if ( darmour != NULL ) {
307 if ( ( dtype->
aoffset ) == 0 || ( s == NULL ) )
308 *darmour = dtype->
adam * dmg->
damage * absorb;
311 memcpy( &multiplier, &ptr[dtype->
aoffset],
sizeof(
double ) );
312 multiplier =
MAX( 0., 1. - multiplier );
313 *darmour = dtype->
adam * dmg->
damage * absorb * multiplier;
317 if ( knockback != NULL )
318 *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.