naev 0.11.5
unidiff.c File Reference

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

#include "unidiff.h"
#include "conf.h"
#include "array.h"
#include "economy.h"
#include "log.h"
#include "map_overlay.h"
#include "ndata.h"
#include "nstring.h"
#include "nxml.h"
#include "safelanes.h"
#include "space.h"
#include "player.h"

Go to the source code of this file.

Data Structures

struct  UniDiffData_t
 Universe diff filepath list. More...
 
struct  UniHunkTarget_t
 Represents the hunk's target. More...
 
struct  UniHunk_t
 Represents a single hunk in the diff. More...
 
struct  UniDiff_t
 Represents each Universe Diff. More...
 

Enumerations

enum  UniHunkTargetType_t {
  HUNK_TARGET_NONE , HUNK_TARGET_SYSTEM , HUNK_TARGET_SPOB , HUNK_TARGET_TECH ,
  HUNK_TARGET_FACTION
}
 Represents the possible hunk targets. More...
 
enum  UniHunkType_t {
  HUNK_TYPE_NONE , HUNK_TYPE_SPOB_ADD , HUNK_TYPE_SPOB_REMOVE , HUNK_TYPE_VSPOB_ADD ,
  HUNK_TYPE_VSPOB_REMOVE , HUNK_TYPE_JUMP_ADD , HUNK_TYPE_JUMP_REMOVE , HUNK_TYPE_SSYS_BACKGROUND ,
  HUNK_TYPE_SSYS_BACKGROUND_REVERT , HUNK_TYPE_SSYS_FEATURES , HUNK_TYPE_SSYS_FEATURES_REVERT , HUNK_TYPE_TECH_ADD ,
  HUNK_TYPE_TECH_REMOVE , HUNK_TYPE_SPOB_FACTION , HUNK_TYPE_SPOB_FACTION_REMOVE , HUNK_TYPE_SPOB_POPULATION ,
  HUNK_TYPE_SPOB_POPULATION_REMOVE , HUNK_TYPE_SPOB_DISPLAYNAME , HUNK_TYPE_SPOB_DISPLAYNAME_REVERT , HUNK_TYPE_SPOB_DESCRIPTION ,
  HUNK_TYPE_SPOB_DESCRIPTION_REVERT , HUNK_TYPE_SPOB_BAR , HUNK_TYPE_SPOB_BAR_REVERT , HUNK_TYPE_SPOB_SERVICE_ADD ,
  HUNK_TYPE_SPOB_SERVICE_REMOVE , HUNK_TYPE_SPOB_NOMISNSPAWN_ADD , HUNK_TYPE_SPOB_NOMISNSPAWN_REMOVE , HUNK_TYPE_SPOB_TECH_ADD ,
  HUNK_TYPE_SPOB_TECH_REMOVE , HUNK_TYPE_SPOB_TAG_ADD , HUNK_TYPE_SPOB_TAG_REMOVE , HUNK_TYPE_SPOB_SPACE ,
  HUNK_TYPE_SPOB_SPACE_REVERT , HUNK_TYPE_SPOB_EXTERIOR , HUNK_TYPE_SPOB_EXTERIOR_REVERT , HUNK_TYPE_SPOB_LUA ,
  HUNK_TYPE_SPOB_LUA_REVERT , HUNK_TYPE_FACTION_VISIBLE , HUNK_TYPE_FACTION_INVISIBLE , HUNK_TYPE_FACTION_ALLY ,
  HUNK_TYPE_FACTION_ENEMY , HUNK_TYPE_FACTION_NEUTRAL , HUNK_TYPE_FACTION_REALIGN
}
 Represents the different type of hunk actions. More...
 

Functions

static int diff_applyInternal (const char *name, int oneshot)
 Applies a diff to the universe.
 
 NONNULL (1)
 
int diff_loadAvailable (void)
 Loads available universe diffs.
 
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.
 
static int diff_patchSystem (UniDiff_t *diff, xmlNodePtr node)
 Patches a system.
 
static int diff_patchTech (UniDiff_t *diff, xmlNodePtr node)
 Patches a tech.
 
static int diff_patchSpob (UniDiff_t *diff, xmlNodePtr node)
 Patches a spob.
 
static int diff_patchFaction (UniDiff_t *diff, xmlNodePtr node)
 Patches a faction.
 
static int diff_patch (xmlNodePtr parent)
 Actually applies a diff in XML node form.
 
static int diff_patchHunk (UniHunk_t *hunk)
 Applies a hunk and adds it to the diff.
 
static void diff_hunkFailed (UniDiff_t *diff, UniHunk_t *hunk)
 Adds a hunk to the failed list.
 
static void diff_hunkSuccess (UniDiff_t *diff, 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().)
 
void diff_free (void)
 Clean up after diff_loadAvailable().
 
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.
 
static 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 = 0
 
static int diff_universe_defer = 0
 

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.

Enumeration Type Documentation

◆ UniHunkTargetType_t

Represents the possible hunk targets.

Definition at line 47 of file unidiff.c.

◆ UniHunkType_t

Represents the different type of hunk actions.

Definition at line 72 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 284 of file unidiff.c.

◆ diff_applyInternal()

static 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 296 of file unidiff.c.

◆ diff_checkUpdateUniverse()

static int diff_checkUpdateUniverse ( void )
static

Checks and updates the universe if necessary.

Definition at line 1834 of file unidiff.c.

◆ diff_cleanup()

static void diff_cleanup ( UniDiff_t * diff)
static

Cleans up a diff.

Parameters
diffDiff to clean up.

Definition at line 1703 of file unidiff.c.

◆ diff_cleanupHunk()

static void diff_cleanupHunk ( UniHunk_t * hunk)
static

Cleans up a hunk.

Parameters
hunkHunk to clean up.

Definition at line 1720 of file unidiff.c.

◆ diff_clear()

void diff_clear ( void )

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

Definition at line 1522 of file unidiff.c.

◆ diff_free()

void diff_free ( void )

Clean up after diff_loadAvailable().

Definition at line 1535 of file unidiff.c.

◆ diff_get()

static 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 270 of file unidiff.c.

◆ diff_hunkFailed()

static void diff_hunkFailed ( UniDiff_t * diff,
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 1478 of file unidiff.c.

◆ diff_hunkSuccess()

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

Adds a hunk to the applied list.

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

Definition at line 1493 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 257 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 1797 of file unidiff.c.

◆ diff_loadAvailable()

int diff_loadAvailable ( void )

Loads available universe diffs.

Returns
0 on success.

Definition at line 199 of file unidiff.c.

◆ diff_newDiff()

static UniDiff_t * diff_newDiff ( void )
static

Creates a new UniDiff_t for usage.

Returns
A newly created UniDiff_t.

Definition at line 1552 of file unidiff.c.

◆ diff_patch()

static int diff_patch ( xmlNodePtr parent)
static

Actually applies a diff in XML node form.

Parameters
parentNode containing the diff information.
Returns
0 on success.

Definition at line 910 of file unidiff.c.

◆ diff_patchFaction()

static int diff_patchFaction ( UniDiff_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 811 of file unidiff.c.

◆ diff_patchHunk()

static int diff_patchHunk ( UniHunk_t * hunk)
static

Applies a hunk and adds it to the diff.

Parameters
hunkHunk to apply.
Returns
0 on success.

Definition at line 1114 of file unidiff.c.

◆ diff_patchSpob()

static int diff_patchSpob ( UniDiff_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 561 of file unidiff.c.

◆ diff_patchSystem()

static int diff_patchSystem ( UniDiff_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 344 of file unidiff.c.

◆ diff_patchTech()

static int diff_patchTech ( UniDiff_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 492 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 1507 of file unidiff.c.

◆ diff_removeDiff()

static int diff_removeDiff ( UniDiff_t * diff)
static

Removes a diff.

Parameters
diffDiff to remove.
Returns
0 on success.

Definition at line 1566 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 1776 of file unidiff.c.

◆ NONNULL()

NONNULL ( 1 )

Definition at line 166 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 1890 of file unidiff.c.

Variable Documentation

◆ diff_available

UniDiffData_t* diff_available = NULL
static

Available diffs.

Definition at line 40 of file unidiff.c.

◆ diff_stack

UniDiff_t* diff_stack = NULL
static

Currently applied universe diffs.

Definition at line 156 of file unidiff.c.

◆ diff_universe_changed

int diff_universe_changed = 0
static

Whether or not the universe changed.

Definition at line 159 of file unidiff.c.

◆ diff_universe_defer

int diff_universe_defer = 0
static

Defers changes to later.

Definition at line 160 of file unidiff.c.