![]() |
naev 0.10.4
|
Handles the ship statistics. More...
#include "shipstats.h"#include "log.h"#include "nstring.h"Go to the source code of this file.
Data Structures | |
| struct | ShipStatsLookup |
| Internal look up table for ship stats. More... | |
Macros | |
| #define | ELEM(t, n, dsp, d, i) { .type=t, .name=#n, .display=dsp, .data=d, .inverted=i, .offset=offsetof( ShipStats, n ) } |
| #define | D__ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE, 0 ) |
| #define | A__ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE_ABSOLUTE, 0 ) |
| #define | P__ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE_ABSOLUTE_PERCENT, 0 ) |
| #define | I__ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_INTEGER, 0 ) |
| #define | B__ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_BOOLEAN, 0 ) |
| #define | DI_ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE, 1 ) |
| #define | AI_ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE_ABSOLUTE, 1 ) |
| #define | PI_ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE_ABSOLUTE_PERCENT, 1 ) |
| #define | II_ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_INTEGER, 1 ) |
| #define | BI_ELEM(t, n, dsp) ELEM( t, n, dsp, SS_DATA_TYPE_BOOLEAN, 1 ) |
| #define | N__ELEM(t) { .type=t, .name=NULL, .display=NULL, .inverted=0, .offset=0 } |
Enumerations | |
| enum | StatDataType { SS_DATA_TYPE_DOUBLE , SS_DATA_TYPE_DOUBLE_ABSOLUTE , SS_DATA_TYPE_DOUBLE_ABSOLUTE_PERCENT , SS_DATA_TYPE_INTEGER , SS_DATA_TYPE_BOOLEAN } |
| The data type. More... | |
Functions | |
| static const char * | ss_printD_colour (double d, const ShipStatsLookup *sl) |
| Some colour coding for ship stats doubles. More... | |
| static const char * | ss_printI_colour (int i, const ShipStatsLookup *sl) |
| Some colour coding for ship stats integers. More... | |
| static int | ss_printD (char *buf, int len, int newline, double d, const ShipStatsLookup *sl) |
| Helper to print doubles. More... | |
| static int | ss_printA (char *buf, int len, int newline, double d, const ShipStatsLookup *sl) |
| Helper to print absolute doubles. More... | |
| static int | ss_printI (char *buf, int len, int newline, int i, const ShipStatsLookup *sl) |
| Helper to print integers. More... | |
| static int | ss_printB (char *buf, int len, int newline, int b, const ShipStatsLookup *sl) |
| Helper to print booleans. More... | |
| static double | ss_statsGetInternal (const ShipStats *s, ShipStatsType type) |
| static int | ss_statsGetLuaInternal (lua_State *L, const ShipStats *s, ShipStatsType type, int internal) |
| ShipStatList * | ss_listFromXML (xmlNodePtr node) |
| Creates a shipstat list element from an xml node. More... | |
| int | ss_listToXML (xmlTextWriterPtr writer, const ShipStatList *ll) |
| Creatse a shipstat list element from an xml node. More... | |
| static int | shipstat_sort (const void *a, const void *b) |
| int | ss_sort (ShipStatList **ll) |
| Sorts the ship stats, useful if doing saving stuff. More... | |
| int | ss_check (void) |
| Checks for validity. More... | |
| int | ss_statsInit (ShipStats *stats) |
| Initializes a stat structure. More... | |
| int | ss_statsMerge (ShipStats *dest, const ShipStats *src) |
| Merges two different ship stats. More... | |
| int | ss_statsModSingle (ShipStats *stats, const ShipStatList *list) |
| Modifies a stat structure using a single element. More... | |
| int | ss_statsModSingleScale (ShipStats *stats, const ShipStatList *list, double scale) |
| Modifies a stat structure using a single element. More... | |
| int | ss_statsModFromList (ShipStats *stats, const ShipStatList *list) |
| Updates a stat structure from a stat list. More... | |
| int | ss_statsModFromListScale (ShipStats *stats, const ShipStatList *list, double scale) |
| Updates a stat structure from a stat list. More... | |
| const char * | ss_nameFromType (ShipStatsType type) |
| Gets the name from type. More... | |
| size_t | ss_offsetFromType (ShipStatsType type) |
| Gets the offset from type. More... | |
| ShipStatsType | ss_typeFromName (const char *name) |
| Gets the type from the name. More... | |
| int | ss_statsListDesc (const ShipStatList *ll, char *buf, int len, int newline) |
| Writes the ship statistics description. More... | |
| int | ss_statsDesc (const ShipStats *s, char *buf, int len, int newline) |
| Writes the ship statistics description. More... | |
| void | ss_free (ShipStatList *ll) |
| Frees a list of ship stats. More... | |
| int | ss_statsSet (ShipStats *s, const char *name, double value, int overwrite) |
| Sets a ship stat by name. More... | |
| double | ss_statsGet (const ShipStats *s, const char *name) |
| Gets a ship stat value by name. More... | |
| int | ss_statsGetLua (lua_State *L, const ShipStats *s, const char *name, int internal) |
| Gets a ship stat value by name and pushes it to Lua. More... | |
| int | ss_statsGetLuaTable (lua_State *L, const ShipStats *s, int internal) |
| Converts ship stats to a Lua table, which is pushed on the Lua stack. More... | |
Variables | |
| static const ShipStatsLookup | ss_lookup [] |
Handles the ship statistics.
Definition in file shipstats.c.
| #define A__ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE_ABSOLUTE, 0 ) |
Definition at line 54 of file shipstats.c.
| #define AI_ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE_ABSOLUTE, 1 ) |
Definition at line 65 of file shipstats.c.
| #define B__ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_BOOLEAN, 0 ) |
Definition at line 60 of file shipstats.c.
| #define BI_ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_BOOLEAN, 1 ) |
Definition at line 71 of file shipstats.c.
| #define D__ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE, 0 ) |
Definition at line 52 of file shipstats.c.
| #define DI_ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE, 1 ) |
Definition at line 63 of file shipstats.c.
| #define ELEM | ( | t, | |
| n, | |||
| dsp, | |||
| d, | |||
| i | |||
| ) | { .type=t, .name=#n, .display=dsp, .data=d, .inverted=i, .offset=offsetof( ShipStats, n ) } |
Definition at line 49 of file shipstats.c.
| #define I__ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_INTEGER, 0 ) |
Definition at line 58 of file shipstats.c.
| #define II_ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_INTEGER, 1 ) |
Definition at line 69 of file shipstats.c.
| #define N__ELEM | ( | t | ) | { .type=t, .name=NULL, .display=NULL, .inverted=0, .offset=0 } |
Nil element.
Definition at line 74 of file shipstats.c.
| #define P__ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE_ABSOLUTE_PERCENT, 0 ) |
Definition at line 56 of file shipstats.c.
| #define PI_ELEM | ( | t, | |
| n, | |||
| dsp | |||
| ) | ELEM( t, n, dsp, SS_DATA_TYPE_DOUBLE_ABSOLUTE_PERCENT, 1 ) |
Definition at line 67 of file shipstats.c.
| enum StatDataType |
The data type.
Definition at line 21 of file shipstats.c.
|
static |
Definition at line 283 of file shipstats.c.
| int ss_check | ( | void | ) |
Checks for validity.
Definition at line 331 of file shipstats.c.
| void ss_free | ( | ShipStatList * | ll | ) |
| ShipStatList * ss_listFromXML | ( | xmlNodePtr | node | ) |
Creates a shipstat list element from an xml node.
| node | Node to create element from. |
Definition at line 209 of file shipstats.c.
| int ss_listToXML | ( | xmlTextWriterPtr | writer, |
| const ShipStatList * | ll | ||
| ) |
Creatse a shipstat list element from an xml node.
| writer | Writer to use to write the XML data. |
| ll | ShipStats to save. |
Definition at line 260 of file shipstats.c.
| const char * ss_nameFromType | ( | ShipStatsType | type | ) |
Gets the name from type.
O(1) look up.
| type | Type to get name of. |
Definition at line 574 of file shipstats.c.
| size_t ss_offsetFromType | ( | ShipStatsType | type | ) |
Gets the offset from type.
| type | Type to get offset of. |
Definition at line 585 of file shipstats.c.
|
static |
Helper to print absolute doubles.
Definition at line 654 of file shipstats.c.
|
static |
Helper to print booleans.
Definition at line 680 of file shipstats.c.
|
static |
Helper to print doubles.
Definition at line 641 of file shipstats.c.
|
static |
Some colour coding for ship stats doubles.
Definition at line 609 of file shipstats.c.
|
static |
Helper to print integers.
Definition at line 667 of file shipstats.c.
|
static |
Some colour coding for ship stats integers.
Definition at line 625 of file shipstats.c.
| int ss_sort | ( | ShipStatList ** | ll | ) |
Sorts the ship stats, useful if doing saving stuff.
| ll | Ship stat list to sort. |
Definition at line 298 of file shipstats.c.
| int ss_statsDesc | ( | const ShipStats * | s, |
| char * | buf, | ||
| int | len, | ||
| int | newline | ||
| ) |
Writes the ship statistics description.
| s | Ship stats to use. |
| buf | Buffer to write to. |
| len | Space left in the buffer. |
| newline | Add a newline at start. |
Definition at line 744 of file shipstats.c.
| double ss_statsGet | ( | const ShipStats * | s, |
| const char * | name | ||
| ) |
Gets a ship stat value by name.
Definition at line 953 of file shipstats.c.
|
static |
Definition at line 875 of file shipstats.c.
| int ss_statsGetLua | ( | lua_State * | L, |
| const ShipStats * | s, | ||
| const char * | name, | ||
| int | internal | ||
| ) |
Gets a ship stat value by name and pushes it to Lua.
Definition at line 967 of file shipstats.c.
|
static |
Definition at line 905 of file shipstats.c.
| int ss_statsGetLuaTable | ( | lua_State * | L, |
| const ShipStats * | s, | ||
| int | internal | ||
| ) |
Converts ship stats to a Lua table, which is pushed on the Lua stack.
Definition at line 986 of file shipstats.c.
| int ss_statsInit | ( | ShipStats * | stats | ) |
Initializes a stat structure.
Definition at line 347 of file shipstats.c.
| int ss_statsListDesc | ( | const ShipStatList * | ll, |
| char * | buf, | ||
| int | len, | ||
| int | newline | ||
| ) |
Writes the ship statistics description.
| ll | Ship stats to use. |
| buf | Buffer to write to. |
| len | Space left in the buffer. |
| newline | Add a newline at start. |
Definition at line 699 of file shipstats.c.
Merges two different ship stats.
| dest | Destination ship stats. |
| src | Source to be merged with destination. |
Definition at line 391 of file shipstats.c.
| int ss_statsModFromList | ( | ShipStats * | stats, |
| const ShipStatList * | list | ||
| ) |
Updates a stat structure from a stat list.
| stats | Stats to update. |
| list | List to update from. |
Definition at line 543 of file shipstats.c.
| int ss_statsModFromListScale | ( | ShipStats * | stats, |
| const ShipStatList * | list, | ||
| double | scale | ||
| ) |
Updates a stat structure from a stat list.
| stats | Stats to update. |
| list | List to update from. |
| scale | Scaling factor. |
Definition at line 558 of file shipstats.c.
| int ss_statsModSingle | ( | ShipStats * | stats, |
| const ShipStatList * | list | ||
| ) |
Modifies a stat structure using a single element.
| stats | Stat structure to modify. |
| list | Single element to apply. |
Definition at line 447 of file shipstats.c.
| int ss_statsModSingleScale | ( | ShipStats * | stats, |
| const ShipStatList * | list, | ||
| double | scale | ||
| ) |
Modifies a stat structure using a single element.
| stats | Stat structure to modify. |
| list | Single element to apply. |
| scale | Scaling factor. |
Definition at line 496 of file shipstats.c.
| int ss_statsSet | ( | ShipStats * | s, |
| const char * | name, | ||
| double | value, | ||
| int | overwrite | ||
| ) |
Sets a ship stat by name.
Definition at line 819 of file shipstats.c.
| ShipStatsType ss_typeFromName | ( | const char * | name | ) |
Gets the type from the name.
| name | Name to get type of. |
Definition at line 596 of file shipstats.c.
|
static |
The ultimate look up table for ship stats, everything goes through this.
Definition at line 80 of file shipstats.c.