16#include "difficulty.h"
23#define DIFFICULTY_XML_ID "difficulty"
26static const Difficulty *difficulty_default = NULL;
27static const Difficulty *difficulty_global = NULL;
28static const Difficulty *difficulty_local = NULL;
29static const Difficulty *difficulty_current = NULL;
34int difficulty_load (
void)
38 for (
int i=0; i<
array_size(difficulty_files); i++) {
49 node = doc->xmlChildrenNode;
50 if (!xml_isNode(node,DIFFICULTY_XML_ID)) {
51 ERR( _(
"Malformed '%s' file: missing root element '%s'"), difficulty_files[i], DIFFICULTY_XML_ID);
60 xmlr_attr_strd( node,
"name",
d.name );
61 xmlr_attr_int_opt( node,
"default",
d.def );
64 cur = node->xmlChildrenNode;
69 xmlr_strd( cur,
"description",
d.description );
78 WARN(_(
"Difficulty '%s' has unknown node '%s'"),
d.name, cur->name);
79 }
while (xml_nextNode(cur));
87 for (
int i=0; i<
array_size(difficulty_stack); i++) {
90 if (difficulty_default)
91 WARN(_(
"More than one difficulty with default flag set!"));
92 difficulty_default = dd;
95 if (difficulty_default==NULL) {
96 WARN(_(
"No default difficulty set!"));
97 difficulty_default = difficulty_stack;
99 difficulty_current = difficulty_default;
103 difficulty_setGlobal( difficulty_get( conf.
difficulty ) );
105 for (
int i=0; i<
array_size(difficulty_files); i++)
106 free( difficulty_files[i] );
114void difficulty_free (
void)
116 for (
int i=0; i<
array_size(difficulty_stack); i++) {
119 free(
d->description );
130 return difficulty_current;
138 return difficulty_stack;
141static const Difficulty *difficulty_getDefault (
void)
143 if (difficulty_global != NULL)
144 return difficulty_global;
146 return difficulty_default;
152const Difficulty *difficulty_get(
const char *name )
155 return difficulty_getDefault();
156 for (
int i=0; i<
array_size(difficulty_stack); i++) {
158 if (strcmp(name,
d->name)==0)
161 WARN(_(
"Uknown difficulty setting '%s'"), name);
162 return difficulty_default;
165static void difficulty_update (
void)
167 if (difficulty_local != NULL)
168 difficulty_current = difficulty_local;
169 else if (difficulty_global != NULL)
170 difficulty_current = difficulty_global;
172 difficulty_current = difficulty_default;
180 difficulty_global =
d;
189 difficulty_local =
d;
201 char *display = malloc( STRMAX );
202 l =
scnprintf( display, STRMAX, _(
"Difficulty %s"), _(
d->name) );
203 l +=
scnprintf( &display[l], STRMAX-l,
"\n" );
204 if (
d->description != NULL)
205 l +=
scnprintf( &display[l], STRMAX-l,
"%s\n", _(
d->description) );
206 l +=
scnprintf( &display[l], STRMAX-l, _(
"This difficulty applies the following effect to the player ships:") );
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_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’.
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.
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
int ss_statsListDesc(const ShipStatList *ll, char *buf, int len, int newline)
Writes the ship statistics description.
void ss_free(ShipStatList *ll)
Frees a list of ship stats.
int ss_statsMergeFromList(ShipStats *stats, const ShipStatList *list)
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.