![]() |
naev 0.12.5
|
Handles the ship statistics. More...
#include "shipstats.h"#include "log.h"#include "nstring.h"#include "physics.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, u, d, i) |
| #define | D__ELEM(t, n, dsp) |
| #define | DI_ELEM(t, n, dsp) |
| #define | A__ELEM(t, n, dsp, u) |
| #define | AI_ELEM(t, n, dsp, u) |
| #define | P__ELEM(t, n, dsp) |
| #define | PI_ELEM(t, n, dsp) |
| #define | I__ELEM(t, n, dsp, u) |
| #define | II_ELEM(t, n, dsp) |
| #define | B__ELEM(t, n, dsp) |
| #define | BI_ELEM(t, n, dsp) |
| #define | N__ELEM(t) |
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. | |
| static const char * | ss_printI_colour (int i, const ShipStatsLookup *sl) |
| Some colour coding for ship stats integers. | |
| static int | ss_printD (char *buf, int len, int newline, double d, const ShipStatsLookup *sl) |
| Helper to print doubles. | |
| static int | ss_printA (char *buf, int len, int newline, double d, const ShipStatsLookup *sl) |
| Helper to print absolute doubles. | |
| static int | ss_printI (char *buf, int len, int newline, int i, const ShipStatsLookup *sl) |
| Helper to print integers. | |
| static int | ss_printB (char *buf, int len, int newline, int b, const ShipStatsLookup *sl) |
| Helper to print booleans. | |
| static double | ss_statsGetInternal (const ShipStats *s, ShipStatsType type, int raw) |
| static int | ss_statsGetLuaInternal (lua_State *L, const ShipStats *s, ShipStatsType type, int internal) |
| static void | ss_adjustDoubleStat (double *statptr, double adjustment, int inverted) |
| Makes adjustments so the stats are positively additive. | |
| ShipStatList * | ss_statsSetList (ShipStatList *head, ShipStatsType type, double value, int overwrite, int raw) |
| ShipStatList * | ss_listFromXML (xmlNodePtr node) |
| Creates a shipstat list element from an xml node. | |
| int | ss_listToXML (xmlTextWriterPtr writer, const ShipStatList *ll) |
| Creatse a shipstat list element from an xml node. | |
| static int | shipstat_sort (const void *a, const void *b) |
| int | ss_sort (ShipStatList **ll) |
| Sorts the ship stats, useful if doing saving stuff. | |
| int | ss_check (void) |
| Checks for validity. | |
| int | ss_statsInit (ShipStats *stats) |
| Initializes a stat structure. | |
| int | ss_statsMerge (ShipStats *dest, const ShipStats *src) |
| Merges two different ship stats. | |
| int | ss_statsMergeSingle (ShipStats *stats, const ShipStatList *list) |
| Modifies a stat structure using a single element. | |
| int | ss_statsMergeSingleScale (ShipStats *stats, const ShipStatList *list, double scale) |
| Modifies a stat structure using a single element. | |
| int | ss_statsMergeFromList (ShipStats *stats, const ShipStatList *list) |
| Updates a stat structure from a stat list. | |
| int | ss_statsMergeFromListScale (ShipStats *stats, const ShipStatList *list, double scale) |
| Updates a stat structure from a stat list. | |
| const char * | ss_nameFromType (ShipStatsType type) |
| Gets the name from type. | |
| size_t | ss_offsetFromType (ShipStatsType type) |
| Gets the offset from type. | |
| ShipStatsType | ss_typeFromName (const char *name) |
| Gets the type from the name. | |
| int | ss_statsListDesc (const ShipStatList *ll, char *buf, int len, int newline) |
| Writes the ship statistics description. | |
| int | ss_statsDesc (const ShipStats *s, char *buf, int len, int newline) |
| Writes the ship statistics description. | |
| void | ss_free (ShipStatList *ll) |
| Frees a list of ship stats. | |
| int | ss_statsSet (ShipStats *s, const char *name, double value, int overwrite) |
| Sets a ship stat by name. | |
| double | ss_statsGet (const ShipStats *s, const char *name) |
| Gets a ship stat value by name. | |
| double | ss_statsGetRaw (const ShipStats *s, ShipStatsType type) |
| Gets a ship stat value by name. | |
| 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. | |
| 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. | |
| int | ss_statsGetLuaTableList (lua_State *L, const ShipStatList *list, int internal) |
| Converts ship stats to a Lua table, which is pushed on the Lua stack. | |
Variables | |
| static const ShipStatsLookup | ss_lookup [] |
Handles the ship statistics.
Definition in file shipstats.c.
| #define A__ELEM | ( | t, | |
| n, | |||
| dsp, | |||
| u ) |
Definition at line 67 of file shipstats.c.
| #define AI_ELEM | ( | t, | |
| n, | |||
| dsp, | |||
| u ) |
Definition at line 69 of file shipstats.c.
| #define B__ELEM | ( | t, | |
| n, | |||
| dsp ) |
Definition at line 80 of file shipstats.c.
| #define BI_ELEM | ( | t, | |
| n, | |||
| dsp ) |
Definition at line 81 of file shipstats.c.
| #define D__ELEM | ( | t, | |
| n, | |||
| dsp ) |
Definition at line 62 of file shipstats.c.
| #define DI_ELEM | ( | t, | |
| n, | |||
| dsp ) |
Definition at line 64 of file shipstats.c.
| #define ELEM | ( | t, | |
| n, | |||
| dsp, | |||
| u, | |||
| d, | |||
| i ) |
Definition at line 53 of file shipstats.c.
| #define I__ELEM | ( | t, | |
| n, | |||
| dsp, | |||
| u ) |
Definition at line 77 of file shipstats.c.
| #define II_ELEM | ( | t, | |
| n, | |||
| dsp ) |
Definition at line 78 of file shipstats.c.
| #define N__ELEM | ( | t | ) |
Nil element.
Definition at line 84 of file shipstats.c.
| #define P__ELEM | ( | t, | |
| n, | |||
| dsp ) |
Definition at line 72 of file shipstats.c.
| #define PI_ELEM | ( | t, | |
| n, | |||
| dsp ) |
Definition at line 74 of file shipstats.c.
| enum StatDataType |
The data type.
Definition at line 22 of file shipstats.c.
|
static |
Definition at line 427 of file shipstats.c.
|
static |
Makes adjustments so the stats are positively additive.
Definition at line 597 of file shipstats.c.
| int ss_check | ( | void | ) |
Checks for validity.
Definition at line 474 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 353 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 404 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 703 of file shipstats.c.
| size_t ss_offsetFromType | ( | ShipStatsType | type | ) |
Gets the offset from type.
| type | Type to get offset of. |
Definition at line 714 of file shipstats.c.
|
static |
Helper to print absolute doubles.
Definition at line 773 of file shipstats.c.
|
static |
Helper to print booleans.
Definition at line 801 of file shipstats.c.
|
static |
Helper to print doubles.
Definition at line 759 of file shipstats.c.
|
static |
Some colour coding for ship stats doubles.
Definition at line 739 of file shipstats.c.
|
static |
Helper to print integers.
Definition at line 788 of file shipstats.c.
|
static |
Some colour coding for ship stats integers.
Definition at line 749 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 442 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 864 of file shipstats.c.
| double ss_statsGet | ( | const ShipStats * | s, |
| const char * | name ) |
Gets a ship stat value by name.
Definition at line 1094 of file shipstats.c.
|
static |
Definition at line 1008 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 1116 of file shipstats.c.
|
static |
Definition at line 1045 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 1136 of file shipstats.c.
| int ss_statsGetLuaTableList | ( | lua_State * | L, |
| const ShipStatList * | list, | ||
| int | internal ) |
Converts ship stats to a Lua table, which is pushed on the Lua stack.
Definition at line 1157 of file shipstats.c.
| double ss_statsGetRaw | ( | const ShipStats * | s, |
| ShipStatsType | type ) |
Gets a ship stat value by name.
Definition at line 1108 of file shipstats.c.
| int ss_statsInit | ( | ShipStats * | stats | ) |
Initializes a stat structure.
Definition at line 490 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 820 of file shipstats.c.
Merges two different ship stats.
| dest | Destination ship stats. |
| src | Source to be merged with destination. |
Definition at line 533 of file shipstats.c.
| int ss_statsMergeFromList | ( | 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 666 of file shipstats.c.
| int ss_statsMergeFromListScale | ( | 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 684 of file shipstats.c.
| int ss_statsMergeSingle | ( | 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 589 of file shipstats.c.
| int ss_statsMergeSingleScale | ( | 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 620 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 946 of file shipstats.c.
| ShipStatList * ss_statsSetList | ( | ShipStatList * | head, |
| ShipStatsType | type, | ||
| double | value, | ||
| int | overwrite, | ||
| int | raw ) |
Definition at line 271 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 725 of file shipstats.c.
|
static |
The ultimate look up table for ship stats, everything goes through this.
Definition at line 95 of file shipstats.c.