naev 0.12.6
unidiff.c File Reference

Handles the application and removal of 'diffs' to the universe. More...

#include "unidiff.h"
#include "array.h"
#include "conf.h"
#include "economy.h"
#include "log.h"
#include "map_overlay.h"
#include "ndata.h"
#include "nxml.h"
#include "player.h"
#include "safelanes.h"
#include "space.h"
Include dependency graph for unidiff.c:

Go to the source code of this file.

Data Structures

struct  UniDiff_t
 Represents each Universe Diff. More...
struct  HunkProperties

Macros

#define HUNK_CUST(TYPE, DTYPE, FUNC)
#define HUNK_NONE(TYPE)
#define HUNK_STRD(TYPE)
#define HUNK_INT(TYPE)
#define HUNK_FLOAT(TYPE)

Functions

static int diff_applyInternal (const char *name, int oneshot)
 Applies a diff to the universe.
 NONNULL (1)
int diff_init (void)
 Loads available universe diffs.
void diff_freeData (UniDiffData_t *diff)
void diff_exit (void)
 Clean up after diffs.
int diff_parse (UniDiffData_t *diff, char *filename)
int diff_parsePhysFS (UniDiffData_t *diff, char *filename)
static int diff_parseDoc (UniDiffData_t *diff, xmlDocPtr doc)
int diff_isApplied (const char *name)
 Checks if a diff is currently applied.
static UniDiff_tdiff_get (const char *name)
 Gets a diff by name.
int diff_apply (const char *name)
 Applies a diff to the universe.
void diff_start (void)
 Starts applying a set of diffs.
void diff_end (void)
 Cleans up after applying a set of diffs.
static void diff_parseAttr (UniHunk_t *hunk, xmlNodePtr node)
 Parsess the attributes.
static const char * diff_getAttr (UniHunk_t *hunk, const char *name)
static AsteroidAnchordiff_getAsteroidsLabel (StarSystem *ssys, const char *label)
static AsteroidAnchordiff_getAsteroids (StarSystem *ssys, UniHunk_t *hunk)
static int diff_parseSystem (UniDiffData_t *diff, xmlNodePtr node)
 Patches a system.
static int diff_parseTech (UniDiffData_t *diff, xmlNodePtr node)
 Patches a tech.
static int diff_parseSpob (UniDiffData_t *diff, xmlNodePtr node)
 Patches a spob.
static int diff_parseFaction (UniDiffData_t *diff, xmlNodePtr node)
 Patches a faction.
int diff_revertHunk (const UniHunk_t *hunk)
 Reverts a hunk.
int diff_patchHunk (UniHunk_t *hunk)
 Applies a hunk.
static void diff_hunkFailed (UniDiff_t *diff, const UniHunk_t *hunk)
 Adds a hunk to the failed list.
static void diff_hunkSuccess (UniDiff_t *diff, const UniHunk_t *hunk)
 Adds a hunk to the applied list.
void diff_remove (const char *name)
 Removes a diff from the universe.
void diff_clear (void)
 Removes all active diffs. (Call before economy_destroy().)
static UniDiff_tdiff_newDiff (void)
 Creates a new UniDiff_t for usage.
static int diff_removeDiff (UniDiff_t *diff)
 Removes a diff.
static void diff_cleanup (UniDiff_t *diff)
 Cleans up a diff.
const char * diff_hunkName (UniHunkType_t t)
 Gets the human readable name of a hunk.
const char * diff_hunkTag (UniHunkType_t t)
 Gets the XML tag of a hunk.
void diff_cleanupHunk (UniHunk_t *hunk)
 Cleans up a hunk.
int diff_save (xmlTextWriterPtr writer)
 Saves the active diffs.
int diff_load (xmlNodePtr parent)
 Loads the diffs.
static int diff_checkUpdateUniverse (void)
 Checks and updates the universe if necessary.
void unidiff_universeDefer (int enable)
 Sets whether or not to defer universe change stuff.

Variables

static UniDiffData_tdiff_available = NULL
static UniDiff_tdiff_stack = NULL
static int diff_universe_changed
static int diff_universe_defer = 0
static const char * diff_nav_spob
static const char * diff_nav_hyperspace
const char *const hunk_attr_label [] = { "label", NULL }
static const HunkProperties hunk_prop [HUNK_TYPE_SENTINAL+1]

Detailed Description

Handles the application and removal of 'diffs' to the universe.

Diffs allow changing spobs, factions, etc... in the universe. These are meant to be applied after the player triggers them, mostly through missions.

Definition in file unidiff.c.

Macro Definition Documentation

◆ HUNK_CUST

#define HUNK_CUST ( TYPE,
DTYPE,
FUNC )
Value:
/* should be possible to do the static_assert with C23's constexpr. */ \
/* static_assert( hunk_prop[TYPE].tag != NULL, "" ); */ \
if ( xml_isNode( cur, hunk_prop[TYPE].tag ) ) { \
memset( &hunk, 0, sizeof( hunk ) ); \
hunk.target.type = base.target.type; \
hunk.target.u.name = strdup( base.target.u.name ); \
hunk.type = TYPE; \
hunk.dtype = DTYPE; \
diff_parseAttr( &hunk, cur ); \
FUNC array_push_back( &diff->hunks, hunk ); \
continue; \
}
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
Definition array.h:134
A damage type.
Definition damagetype.c:28

Definition at line 419 of file unidiff.c.

◆ HUNK_FLOAT

#define HUNK_FLOAT ( TYPE)
Value:
HUNK_CUST( TYPE, HUNK_DATA_FLOAT, hunk.u.fdata = xml_getFloat( cur ); );

Definition at line 438 of file unidiff.c.

◆ HUNK_INT

#define HUNK_INT ( TYPE)
Value:
HUNK_CUST( TYPE, HUNK_DATA_INT, hunk.u.data = xml_getUInt( cur ); );

Definition at line 436 of file unidiff.c.

◆ HUNK_NONE

#define HUNK_NONE ( TYPE)
Value:
HUNK_CUST( TYPE, HUNK_DATA_NONE, hunk.u.name = NULL; );

Definition at line 432 of file unidiff.c.

◆ HUNK_STRD

#define HUNK_STRD ( TYPE)
Value:
HUNK_CUST( TYPE, HUNK_DATA_STRING, hunk.u.name = xml_getStrd( cur ); );

Definition at line 434 of file unidiff.c.

Function Documentation

◆ diff_apply()

int diff_apply ( const char * name)

Applies a diff to the universe.

Parameters
nameDiff to apply.
Returns
0 on success.

Definition at line 658 of file unidiff.c.

◆ diff_applyInternal()

int diff_applyInternal ( const char * name,
int oneshot )
static

Applies a diff to the universe.

Parameters
nameDiff to apply.
oneshotWhether or not this diff should be applied as a single one-shot diff.
Returns
0 on success.

Definition at line 680 of file unidiff.c.

◆ diff_checkUpdateUniverse()

int diff_checkUpdateUniverse ( void )
static

Checks and updates the universe if necessary.

Definition at line 2020 of file unidiff.c.

◆ diff_cleanup()

void diff_cleanup ( UniDiff_t * diff)
static

Cleans up a diff.

Parameters
diffDiff to clean up.

Definition at line 1908 of file unidiff.c.

◆ diff_cleanupHunk()

void diff_cleanupHunk ( UniHunk_t * hunk)

Cleans up a hunk.

Parameters
hunkHunk to clean up.

Definition at line 1940 of file unidiff.c.

◆ diff_clear()

void diff_clear ( void )

Removes all active diffs. (Call before economy_destroy().)

Definition at line 1858 of file unidiff.c.

◆ diff_end()

void diff_end ( void )

Cleans up after applying a set of diffs.

Definition at line 796 of file unidiff.c.

◆ diff_exit()

void diff_exit ( void )

Clean up after diffs.

Definition at line 560 of file unidiff.c.

◆ diff_freeData()

void diff_freeData ( UniDiffData_t * diff)

Definition at line 548 of file unidiff.c.

◆ diff_get()

UniDiff_t * diff_get ( const char * name)
static

Gets a diff by name.

Parameters
nameName of the diff to get.
Returns
The diff if found or NULL if not found.

Definition at line 644 of file unidiff.c.

◆ diff_getAsteroids()

AsteroidAnchor * diff_getAsteroids ( StarSystem * ssys,
UniHunk_t * hunk )
static

Definition at line 857 of file unidiff.c.

◆ diff_getAsteroidsLabel()

AsteroidAnchor * diff_getAsteroidsLabel ( StarSystem * ssys,
const char * label )
static

Definition at line 846 of file unidiff.c.

◆ diff_getAttr()

const char * diff_getAttr ( UniHunk_t * hunk,
const char * name )
static

Definition at line 838 of file unidiff.c.

◆ diff_hunkFailed()

void diff_hunkFailed ( UniDiff_t * diff,
const UniHunk_t * hunk )
static

Adds a hunk to the failed list.

Parameters
diffDiff to add hunk to.
hunkHunk that failed to apply.

Definition at line 1814 of file unidiff.c.

◆ diff_hunkName()

const char * diff_hunkName ( UniHunkType_t t)

Gets the human readable name of a hunk.

Definition at line 1922 of file unidiff.c.

◆ diff_hunkSuccess()

void diff_hunkSuccess ( UniDiff_t * diff,
const UniHunk_t * hunk )
static

Adds a hunk to the applied list.

Parameters
diffDiff to add hunk to.
hunkHunk that applied correctly.

Definition at line 1829 of file unidiff.c.

◆ diff_hunkTag()

const char * diff_hunkTag ( UniHunkType_t t)

Gets the XML tag of a hunk.

Definition at line 1930 of file unidiff.c.

◆ diff_init()

int diff_init ( void )

Loads available universe diffs.

Returns
0 on success.

Definition at line 480 of file unidiff.c.

◆ diff_isApplied()

int diff_isApplied ( const char * name)

Checks if a diff is currently applied.

Parameters
nameDiff to check.
Returns
0 if it's not applied, 1 if it is.

Definition at line 631 of file unidiff.c.

◆ diff_load()

int diff_load ( xmlNodePtr parent)

Loads the diffs.

Parameters
parentParent node containing diffs.
Returns
0 on success.

Definition at line 1979 of file unidiff.c.

◆ diff_newDiff()

UniDiff_t * diff_newDiff ( void )
static

Creates a new UniDiff_t for usage.

Returns
A newly created UniDiff_t.

Definition at line 1874 of file unidiff.c.

◆ diff_parse()

int diff_parse ( UniDiffData_t * diff,
char * filename )

Definition at line 571 of file unidiff.c.

◆ diff_parseAttr()

void diff_parseAttr ( UniHunk_t * hunk,
xmlNodePtr node )
static

Parsess the attributes.

Definition at line 804 of file unidiff.c.

◆ diff_parseDoc()

int diff_parseDoc ( UniDiffData_t * diff,
xmlDocPtr doc )
static

Definition at line 591 of file unidiff.c.

◆ diff_parseFaction()

int diff_parseFaction ( UniDiffData_t * diff,
xmlNodePtr node )
static

Patches a faction.

Parameters
diffDiff that is doing the patching.
nodeNode containing the spob.
Returns
0 on success.

Definition at line 1059 of file unidiff.c.

◆ diff_parsePhysFS()

int diff_parsePhysFS ( UniDiffData_t * diff,
char * filename )

Definition at line 581 of file unidiff.c.

◆ diff_parseSpob()

int diff_parseSpob ( UniDiffData_t * diff,
xmlNodePtr node )
static

Patches a spob.

Parameters
diffDiff that is doing the patching.
nodeNode containing the spob.
Returns
0 on success.

Definition at line 991 of file unidiff.c.

◆ diff_parseSystem()

int diff_parseSystem ( UniDiffData_t * diff,
xmlNodePtr node )
static

Patches a system.

Parameters
diffDiff that is doing the patching.
nodeNode containing the system.
Returns
0 on success.

Definition at line 881 of file unidiff.c.

◆ diff_parseTech()

int diff_parseTech ( UniDiffData_t * diff,
xmlNodePtr node )
static

Patches a tech.

Parameters
diffDiff that is doing the patching.
nodeNode containing the tech.
Returns
0 on success.

Definition at line 951 of file unidiff.c.

◆ diff_patchHunk()

int diff_patchHunk ( UniHunk_t * hunk)

Applies a hunk.

Parameters
hunkHunk to apply.
Returns
0 on success.

Definition at line 1114 of file unidiff.c.

◆ diff_remove()

void diff_remove ( const char * name)

Removes a diff from the universe.

Parameters
nameDiff to remove.

Definition at line 1843 of file unidiff.c.

◆ diff_removeDiff()

int diff_removeDiff ( UniDiff_t * diff)
static

Removes a diff.

Parameters
diffDiff to remove.
Returns
0 on success.

Definition at line 1888 of file unidiff.c.

◆ diff_revertHunk()

int diff_revertHunk ( const UniHunk_t * hunk)

Reverts a hunk.

Parameters
hunkHunk to revert.
Returns
0 on success.

Definition at line 1101 of file unidiff.c.

◆ diff_save()

int diff_save ( xmlTextWriterPtr writer)

Saves the active diffs.

Parameters
writerXML Writer to use.
Returns
0 on success.

Definition at line 1960 of file unidiff.c.

◆ diff_start()

void diff_start ( void )

Starts applying a set of diffs.

Definition at line 788 of file unidiff.c.

◆ NONNULL()

NONNULL ( 1 )

Definition at line 445 of file unidiff.c.

◆ unidiff_universeDefer()

void unidiff_universeDefer ( int enable)

Sets whether or not to defer universe change stuff.

Parameters
enableWhether or not to enable deferring.

Definition at line 2107 of file unidiff.c.

Variable Documentation

◆ diff_available

UniDiffData_t* diff_available = NULL
static

Available diffs.

Definition at line 30 of file unidiff.c.

◆ diff_nav_hyperspace

const char* diff_nav_hyperspace
static
Initial value:
=
NULL

Stores the player's hyperspace target if necessary.

Definition at line 54 of file unidiff.c.

◆ diff_nav_spob

const char* diff_nav_spob
static
Initial value:
=
NULL

Stores the player's spob target if necessary.

Definition at line 52 of file unidiff.c.

◆ diff_stack

UniDiff_t* diff_stack = NULL
static

Currently applied universe diffs.

Definition at line 46 of file unidiff.c.

◆ diff_universe_changed

int diff_universe_changed
static
Initial value:
=
0

Whether or not the universe changed.

Definition at line 49 of file unidiff.c.

◆ diff_universe_defer

int diff_universe_defer = 0
static

Defers changes to later.

Definition at line 51 of file unidiff.c.

◆ hunk_attr_label

const char* const hunk_attr_label[] = { "label", NULL }

Definition at line 64 of file unidiff.c.

◆ hunk_prop

const HunkProperties hunk_prop[HUNK_TYPE_SENTINAL+1]
static

Definition at line 65 of file unidiff.c.