16#include "damagetype.h"
27#define DTYPE_XML_ID "dtype"
34typedef struct DTYPE_ {
61 xmlNodePtr node, parent;
71 parent = doc->xmlChildrenNode;
73 WARN(_(
"Malformed '%s' file: missing root element '%s'"), file,
DTYPE_XML_ID);
78 memset( temp, 0,
sizeof(
DTYPE) );
80 xmlr_attr_strd( parent,
"name", temp->
name );
83 node = parent->xmlChildrenNode;
87 if (xml_isNode(node,
"shield")) {
88 temp->
sdam = xml_getFloat(node);
90 xmlr_attr_strd( node,
"stat", stat );
98 else if (xml_isNode(node,
"armour")) {
99 temp->
adam = xml_getFloat(node);
101 xmlr_attr_strd( node,
"stat", stat );
109 xmlr_float(node,
"knockback", temp->
knock);
111 WARN(_(
"Unknown node of type '%s' in damage node '%s'."), node->name, temp->
name);
112 }
while (xml_nextNode(node));
114#define MELEMENT(o,s) \
115 if (o) WARN(_("DTYPE '%s' invalid '"s"' element"), temp->name)
116 MELEMENT(temp->
sdam<0.,
"shield");
117 MELEMENT(temp->
adam<0.,
"armour");
118 MELEMENT(temp->
knock<0.,
"knockback");
135 damtype->
name = NULL;
149 WARN(_(
"Damage type '%s' not found in stack."), name);
159 WARN(_(
"Damage type '%d' is invalid."), type);
183 const DTYPE normal = {
184 .
name = strdup(N_(
"normal")),
197 for (
int i=0; i<
array_size(dtype_files); i++) {
202 free( dtype_files[i] );
233int dtype_raw(
int type,
double *shield,
double *armour,
double *knockback )
239 *shield = dtype->
sdam;
241 *armour = dtype->
adam;
242 if (knockback != NULL)
243 *knockback = dtype->
knock;
269 if (dshield != NULL) {
270 if ((dtype->
soffset <= 0) || (s == NULL))
271 *dshield = dtype->
sdam * dmg->
damage * absorb;
281 memcpy(&multiplier, &ptr[ dtype->
soffset ],
sizeof(
double));
282 multiplier =
MAX( 0., 1. - multiplier );
283 *dshield = dtype->
sdam * dmg->
damage * absorb * multiplier;
286 if (darmour != NULL) {
287 if ((dtype->
aoffset) <= 0 || (s == NULL))
288 *darmour = dtype->
adam * dmg->
damage * absorb;
291 memcpy(&multiplier, &ptr[ dtype->
aoffset ],
sizeof(
double));
292 multiplier =
MAX( 0., 1. - multiplier );
293 *darmour = dtype->
adam * dmg->
damage * absorb * multiplier;
297 if (knockback != NULL)
298 *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.
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.