22#include "nlua_pilot.h"
57 xmlNodePtr node, parent;
62 parent = doc->xmlChildrenNode;
63 if ( parent == NULL ) {
64 WARN( _(
"Malformed '%s' file: does not contain elements" ), file );
77 xmlr_attr_strd( parent,
"name", efx->
name );
78 if ( efx->
name == NULL )
79 WARN( _(
"Effect '%s' has invalid or no name" ), file );
81 node = parent->xmlChildrenNode;
84 xml_onlyNodes( node );
86 xmlr_strd( node,
"description", efx->
desc );
87 xmlr_strd( node,
"overwrite", efx->
overwrite );
88 xmlr_int( node,
"priority", efx->
priority );
89 xmlr_float( node,
"duration", efx->
duration );
90 if ( xml_isNode( node,
"buff" ) ) {
91 efx->
flags |= EFFECT_BUFF;
94 if ( xml_isNode( node,
"debuff" ) ) {
95 efx->
flags |= EFFECT_DEBUFF;
98 if ( xml_isNode( node,
"icon" ) ) {
102 if ( xml_isNode( node,
"shader" ) ) {
104 xmlr_attr_strd( node,
"vertex", vertex );
105 if ( vertex == NULL )
106 vertex = strdup(
"effect.vert" );
108 efx->
flags |= EFFECT_VERTEX;
109 xmlr_attr_strd( node,
"img", img );
112 gl_newImage( img, OPENGL_TEX_MIPMAPS | OPENGL_TEX_CLAMP_ALPHA );
115 efx->program = gl_program_vert_frag( vertex, xml_get( node ) );
117 efx->vertex = glGetAttribLocation( efx->program,
"vertex" );
118 efx->projection = glGetUniformLocation( efx->program,
"projection" );
119 efx->tex_mat = glGetUniformLocation( efx->program,
"tex_mat" );
120 efx->dimensions = glGetUniformLocation( efx->program,
"dimensions" );
121 efx->u_r = glGetUniformLocation( efx->program,
"u_r" );
122 efx->u_tex = glGetUniformLocation( efx->program,
"u_tex" );
123 efx->u_timer = glGetUniformLocation( efx->program,
"u_timer" );
124 efx->u_elapsed = glGetUniformLocation( efx->program,
"u_elapsed" );
125 efx->u_dir = glGetUniformLocation( efx->program,
"u_dir" );
126 efx->u_img = glGetUniformLocation( efx->program,
"u_img" );
129 if ( xml_isNode( node,
"lua" ) ) {
132 const char *filename = xml_get( node );
135 WARN( _(
"Effect '%s' failed to read Lua '%s'!" ), efx->
name,
140 env = nlua_newEnv( filename );
142 if ( nlua_dobufenv( env, dat, sz, filename ) != 0 ) {
143 WARN( _(
"Effect '%s' Lua error:\n%s" ), efx->
name,
144 lua_tostring(
naevL, -1 ) );
158 if ( xml_isNode( node,
"stats" ) ) {
159 xmlNodePtr cur = node->children;
162 xml_onlyNodes( cur );
170 WARN( _(
"Effect '%s' has unknown node '%s'" ), efx->
name,
172 }
while ( xml_nextNode( cur ) );
176 WARN( _(
"Effect '%s' has unknown node '%s'" ), efx->
name, node->name );
177 }
while ( xml_nextNode( node ) );
179#define MELEMENT( o, s ) \
181 WARN( _( "Effect '%s' missing/invalid '%s' element" ), efx->name, \
183 MELEMENT( efx->
name == NULL,
"name" );
184 MELEMENT( efx->
desc == NULL,
"description" );
185 MELEMENT( efx->
duration < 0.,
"duration" );
186 MELEMENT( efx->
icon == NULL,
"icon" );
203 Uint32 time = SDL_GetTicks();
208 for (
int i = 0; i <
array_size( effect_files ); i++ ) {
215 free( effect_files[i] );
224 for (
int i = 1; i <
array_size( effect_list ); i++ )
225 if ( strcmp( effect_list[i - 1].name, effect_list[i].name ) == 0 )
226 WARN( _(
"Duplicated effect name '%s' detected!" ),
227 effect_list[i].name );
229 if ( conf.devmode ) {
230 time = SDL_GetTicks() - time;
232 n_(
"Loaded %d Effect in %.3f s",
"Loaded %d Effects in %.3f s", ne ),
235 DEBUG( n_(
"Loaded %d Effect",
"Loaded %d Effects", ne ), ne );
246 for (
int i = 0; i <
array_size( effect_list ); i++ ) {
267 const EffectData k = { .name = (
char *)name };
271 WARN( _(
"Trying to get unknown effect data '%s'!" ), name );
285 for (
int i =
array_size( *efxlist ) - 1; i >= 0; i-- ) {
286 Effect *e = &( *efxlist )[i];
297 WARN( _(
"Effect '%s' failed to run '%s':\n%s" ), e->
data->
name,
298 "remove", lua_tostring(
naevL, -1 ) );
323 double strength,
unsigned int parent )
327 duration = ( duration > 0. ) ? duration : efx->
duration;
329 if ( *efxlist == NULL )
334 for (
int i = 0; i <
array_size( *efxlist ); i++ ) {
335 Effect *el = &( *efxlist )[i];
340 if ( e->
data == efx ) {
347 if ( ( fabs( el->
strength - strength ) < DOUBLE_TOL ) &&
348 ( el->
timer > duration ) )
357 lua_rawgeti(
naevL, LUA_REGISTRYINDEX,
361 WARN( _(
"Effect '%s' failed to run '%s':\n%s" ),
390 WARN( _(
"Effect '%s' failed to run '%s':\n%s" ), e->
data->
name,
391 "extend", lua_tostring(
naevL, -1 ) );
396 if ( efx->
lua_add != LUA_NOREF ) {
400 WARN( _(
"Effect '%s' failed to run '%s':\n%s" ), e->
data->
name,
401 "add", lua_tostring(
naevL, -1 ) );
424 if ( ( idx < 0 ) || ( idx >
array_size( efxlist ) ) ) {
425 WARN( _(
"Trying to remove invalid effect ID!" ) );
428 e = &( *efxlist )[idx];
435 WARN( _(
"Effect '%s' failed to run '%s':\n%s" ), e->
data->
name,
436 "remove", lua_tostring(
naevL, -1 ) );
455 for (
int i =
array_size( *efxlist ) - 1; i >= 0; i-- ) {
456 const Effect *e = &( *efxlist )[i];
457 if ( e->
data != efx )
464 WARN( _(
"Effect '%s' failed to run '%s':\n%s" ), e->
data->
name,
465 "remove", lua_tostring(
naevL, -1 ) );
488 for (
int i =
array_size( *efxlist ) - 1; i >= 0; i-- ) {
489 const Effect *e = &( *efxlist )[i];
495 }
else if ( e->
data->
flags & EFFECT_DEBUFF ) {
508 WARN( _(
"Effect '%s' failed to run '%s':\n%s" ), e->
data->
name,
509 "remove", lua_tostring(
naevL, -1 ) );
526 for (
int i = 0; i <
array_size( *efxlist ); i++ ) {
527 const Effect *e = &( *efxlist )[i];
533 WARN( _(
"Effect '%s' failed to run '%s':\n%s" ), e->
data->
name,
534 "remove", lua_tostring(
naevL, -1 ) );
550 for (
int i = 0; i <
array_size( efxlist ); i++ ) {
551 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.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
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.