21#include "nlua_pilot.h"
54 xmlNodePtr node, parent;
59 parent = doc->xmlChildrenNode;
61 ERR( _(
"Malformed '%s' file: does not contain elements"), file );
74 xmlr_attr_strd(parent,
"name",efx->
name);
75 if (efx->
name == NULL)
76 WARN(_(
"Effect '%s' has invalid or no name"), file);
78 node = parent->xmlChildrenNode;
83 xmlr_strd(node,
"description", efx->
desc);
84 xmlr_strd(node,
"overwrite", efx->
overwrite);
85 xmlr_int(node,
"priority", efx->
priority);
86 xmlr_float(node,
"duration", efx->
duration);
87 if (xml_isNode(node,
"buff")) {
88 efx->
flags |= EFFECT_BUFF;
91 if (xml_isNode(node,
"debuff")) {
92 efx->
flags |= EFFECT_DEBUFF;
95 if (xml_isNode(node,
"icon")) {
99 if (xml_isNode(node,
"shader")) {
101 xmlr_attr_strd(node,
"vertex",vertex);
103 vertex = strdup(
"effect.vert");
104 efx->program = gl_program_vert_frag( vertex, xml_get(node), NULL );
106 efx->vertex = glGetAttribLocation( efx->program,
"vertex" );
107 efx->projection= glGetUniformLocation( efx->program,
"projection" );
108 efx->tex_mat = glGetUniformLocation( efx->program,
"tex_mat" );
109 efx->dimensions= glGetUniformLocation( efx->program,
"dimensions" );
110 efx->u_r = glGetUniformLocation( efx->program,
"u_r" );
111 efx->u_tex = glGetUniformLocation( efx->program,
"u_tex" );
112 efx->u_timer = glGetUniformLocation( efx->program,
"u_timer" );
113 efx->u_elapsed = glGetUniformLocation( efx->program,
"u_elapsed" );
114 efx->u_dir = glGetUniformLocation( efx->program,
"u_dir" );
117 if (xml_isNode(node,
"lua")) {
120 const char *filename = xml_get(node);
123 WARN(_(
"Effect '%s' failed to read Lua '%s'!"), efx->
name, filename );
129 if (nlua_dobufenv( env, dat, sz, filename ) != 0) {
130 WARN(_(
"Effect '%s' Lua error:\n%s"), efx->
name, lua_tostring(naevL,-1));
144 if (xml_isNode(node,
"stats")) {
145 xmlNodePtr cur = node->children;
156 WARN(_(
"Effect '%s' has unknown node '%s'"), efx->
name, cur->name);
157 }
while (xml_nextNode(cur));
160 WARN(_(
"Effect '%s' has unknown node '%s'"),efx->
name, node->name);
161 }
while (xml_nextNode(node));
163#define MELEMENT(o,s) \
164if (o) WARN( _("Effect '%s' missing/invalid '%s' element"), efx->name, s)
165 MELEMENT(efx->
name==NULL,
"name");
166 MELEMENT(efx->
desc==NULL,
"description");
167 MELEMENT(efx->
duration<0.,
"duration");
168 MELEMENT(efx->
icon==NULL,
"icon");
185 Uint32 time = SDL_GetTicks();
190 for (
int i=0; i<
array_size(effect_files); i++) {
197 free( effect_files[i] );
207 if (strcmp( effect_list[i-1].name, effect_list[i].name )==0)
208 WARN(_(
"Duplicated effect name '%s' detected!"), effect_list[i].name);
211 time = SDL_GetTicks() - time;
212 DEBUG( n_(
"Loaded %d Effect in %.3f s",
"Loaded %d Effects in %.3f s", ne ), ne, time/1000. );
215 DEBUG( n_(
"Loaded %d Effect",
"Loaded %d Effects", ne ), ne );
226 for (
int i=0; i<
array_size(effect_list); i++) {
249 WARN(_(
"Trying to get unknown effect data '%s'!"), name);
263 for (
int i=
array_size(*efxlist)-1; i>=0; i--) {
264 Effect *e = &(*efxlist)[i];
275 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
303 duration = (duration > 0.) ? duration : efx->
duration;
305 if (*efxlist == NULL)
311 Effect *el = &(*efxlist)[i];
316 if (e->
data == efx) {
321 if ((fabs(el->
strength-strength)<1e-5) && (el->
timer > duration))
333 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
361 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"extend", lua_tostring(naevL,-1));
367 if (efx->
lua_add != LUA_NOREF) {
368 lua_rawgeti(naevL, LUA_REGISTRYINDEX, e->
data->
lua_add);
371 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"add", lua_tostring(naevL,-1));
394 if ((idx < 0) || (idx >
array_size(efxlist))) {
395 WARN(_(
"Trying to remove invalid effect ID!"));
398 e = &(*efxlist)[idx];
405 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
424 for (
int i=
array_size(*efxlist)-1; i>=0; i++) {
425 const Effect *e = &(*efxlist)[i];
433 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
455 for (
int i=
array_size(*efxlist)-1; i>=0; i++) {
456 const Effect *e = &(*efxlist)[i];
463 else if (e->
data->
flags & EFFECT_DEBUFF) {
477 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
495 const Effect *e = &(*efxlist)[i];
501 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
518 const Effect *e = &efxlist[i];
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_end(array)
Returns a pointer to the end of the reserved memory space.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_begin(array)
Returns a pointer to the beginning of the reserved memory space.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
int effect_rmType(Effect **efxlist, const EffectData *efx, int all)
Removes an effect type from an effect list.
int effect_rm(Effect **efxlist, int idx)
Removes an effect from an effect list by index.
static int effect_cmp(const void *p1, const void *p2)
Compares effects based on name.
int effect_add(Effect **efxlist, const EffectData *efx, double duration, double strength, unsigned int parent)
Adds an effect to an effect list.
static int effect_parse(EffectData *efx, const char *file)
Parsess an effect.
void effect_clearSpecific(Effect **efxlist, int debuffs, int buffs, int others)
Clears specific types of effects.
const EffectData * effect_get(const char *name)
Gets an effect by name.
void effect_cleanup(Effect *efxlist)
Cleans up an effect list freeing it.
void effect_clear(Effect **efxlist)
Clears an effect list, removing all active effects.
static int effect_cmpTimer(const void *p1, const void *p2)
Compares effects based on priority, then timer.
void effect_compute(ShipStats *s, const Effect *efxlist)
Updates shipstats from effect list.
int effect_load(void)
Loads all the effects.
void effect_exit(void)
Gets rid of all the effects.
int effect_update(Effect **efxlist, double dt)
Updates an effect list.
Header file with generic functions and naev-specifics.
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
int ndata_matchExt(const char *path, const char *ext)
Sees if a file matches an extension.
char ** ndata_listRecursive(const char *path)
Lists all the visible files in a directory, at any depth.
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
int nlua_refenvtype(nlua_env env, const char *name, int type)
Gets the reference of a global in a lua environment if it matches a type.
LuaPilot * lua_pushpilot(lua_State *L, LuaPilot pilot)
Pushes a pilot on the stack.
glTexture * xml_parseTexture(xmlNodePtr node, const char *path, int defsx, int defsy, const unsigned int flags)
Parses a texture handling the sx and sy elements.
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
void gl_freeTexture(glTexture *texture)
Frees a texture.
void ss_free(ShipStatList *ll)
Frees a list of ship stats.
int ss_statsMergeFromListScale(ShipStats *stats, const ShipStatList *list, double scale)
Updates a stat structure from a stat list.
ShipStatList * ss_listFromXML(xmlNodePtr node)
Creates a shipstat list element from an xml node.
Represents relative ship statistics as a linked list.
struct ShipStatList_ * next
Represents ship statistics, properties ship can use.