naev 0.11.5
space.c File Reference

Handles all the space stuff, namely systems and space objects (spobs). More...

#include "space.h"
#include "background.h"
#include "conf.h"
#include "damagetype.h"
#include "dev_uniedit.h"
#include "economy.h"
#include "gatherable.h"
#include "gui.h"
#include "hook.h"
#include "land.h"
#include "log.h"
#include "map.h"
#include "map_overlay.h"
#include "menu.h"
#include "mission.h"
#include "music.h"
#include "ndata.h"
#include "nebula.h"
#include "nfile.h"
#include "nlua.h"
#include "nlua_pilot.h"
#include "nlua_spob.h"
#include "nlua_gfx.h"
#include "nlua_camera.h"
#include "nlua_tex.h"
#include "nluadef.h"
#include "nmath.h"
#include "nstring.h"
#include "ntime.h"
#include "nxml.h"
#include "opengl.h"
#include "pause.h"
#include "pilot.h"
#include "player.h"
#include "queue.h"
#include "rng.h"
#include "sound.h"
#include "spfx.h"
#include "start.h"
#include "toolkit.h"
#include "weapon.h"

Go to the source code of this file.

Data Structures

struct  spob_lua_file
 

Macros

#define XML_SPOB_TAG   "spob"
 
#define XML_SYSTEM_TAG   "ssys"
 
#define SPOB_GFX_EXTERIOR_PATH_W   400
 
#define SPOB_GFX_EXTERIOR_PATH_H   400
 
#define FLAG_POSSET   (1<<0)
 
#define FLAG_INTERFERENCESET   (1<<1)
 
#define FLAG_SERVICESSET   (1<<2)
 
#define FLAG_FACTIONSET   (1<<3)
 
#define DEBRIS_BUFFER   1000
 
#define UNREF(x)
 
#define MELEMENT(o, s)
 
#define MELEMENT(o, s)
 
#define MELEMENT(o, s)
 
#define MELEMENT(o, s)
 

Functions

static int spob_parse (Spob *spob, const char *filename, Commodity **stdList)
 Parses a spob from an xml node.
 
static int space_parseSpobs (xmlNodePtr parent, StarSystem *sys)
 Parses spobs in a system.
 
static int spob_parsePresence (xmlNodePtr node, SpobPresence *ap)
 Parsess an spob presence from xml.
 
static void system_init (StarSystem *sys)
 Initializes a new star system with null memory.
 
static int systems_load (void)
 Loads the entire systems, needs to be called after spobs_load.
 
static int system_parse (StarSystem *sys, const char *filename)
 Creates a system from an XML node.
 
static int system_parseJumpPoint (const xmlNodePtr node, StarSystem *sys)
 Parses a single jump point for a system.
 
static int system_parseJumpPointDiff (const xmlNodePtr node, StarSystem *sys)
 Parses a single jump point for a system, from unidiff.
 
static int system_parseJumps (StarSystem *sys)
 Loads the jumps into a system.
 
static int system_parseAsteroidField (const xmlNodePtr node, StarSystem *sys)
 Parses a single asteroid field for a system.
 
static int system_parseAsteroidExclusion (const xmlNodePtr node, StarSystem *sys)
 Parses a single asteroid exclusion zone for a system.
 
static int spob_cmp (const void *p1, const void *p2)
 Comparison function for qsort'ing Spob by name.
 
static int getPresenceIndex (StarSystem *sys, int faction)
 Gets the index of the presence element for a faction. Creates one if it doesn't exist.
 
static void system_scheduler (double dt, int init)
 Controls fleet spawning.
 
static int space_addMarkerSystem (int sysid, MissionMarkerType type)
 
static int space_addMarkerSpob (int pntid, MissionMarkerType type)
 
static int space_rmMarkerSystem (int sysid, MissionMarkerType type)
 
static int space_rmMarkerSpob (int pntid, MissionMarkerType type)
 
static void space_renderJumpPoint (const JumpPoint *jp, int i)
 Renders a jump point.
 
static void space_renderSpob (const Spob *p)
 Renders a spob.
 
static void space_updateSpob (const Spob *p, double dt, double real_dt)
 Renders a spob.
 
static const MapShadermapshader_get (const char *name)
 Gets the map shader by name.
 
static int spob_lua_cmp (const void *a, const void *b)
 
static nlua_env spob_lua_get (int *mem, const char *filename)
 
static void spob_lua_free (spob_lua_file *lf)
 
int space_sysSave (xmlTextWriterPtr writer)
 Saves what is needed to be saved for space.
 
int space_sysLoad (xmlNodePtr parent)
 Loads player's space properties from an XML node.
 
const char * spob_getServiceName (int service)
 Gets the (English) name for a service code.
 
int spob_getService (const char *name)
 Converts name to spob service flag.
 
const char * spob_getClassName (const char *class)
 Gets the long class name for a spob.
 
credits_t spob_commodityPrice (const Spob *p, const Commodity *c)
 Gets the price of a commodity at a spob.
 
credits_t spob_commodityPriceAtTime (const Spob *p, const Commodity *c, ntime_t t)
 Gets the price of a commodity at a spob at given time.
 
void spob_averageSeenPricesAtTime (const Spob *p, const ntime_t tupdate)
 Adds cost of commodities on spob p to known statistics at time t.
 
int spob_averageSpobPrice (const Spob *p, const Commodity *c, credits_t *mean, double *std)
 Gets the average price of a commodity at a spob that has been seen so far.
 
void system_updateAsteroids (StarSystem *sys)
 Updates some internal calculations about asteroids in a system.
 
int spob_setFaction (Spob *p, int faction)
 Changes the spobs faction.
 
int spob_addCommodity (Spob *p, Commodity *c)
 Adds a commodity to a spob.
 
int spob_addService (Spob *p, int service)
 Removes a service from a spob.
 
int spob_rmService (Spob *p, int service)
 Removes a service from a spob.
 
int spob_rename (Spob *p, char *newname)
 Renames a spob.
 
int space_jumpDistance (const Pilot *p, const JumpPoint *jp)
 Distance at which a pilot can jump.
 
int space_canHyperspace (const Pilot *p)
 Checks to make sure if pilot is far enough away to hyperspace.
 
int space_hyperspace (Pilot *p)
 Tries to get the pilot into hyperspace.
 
int space_calcJumpInPos (const StarSystem *in, const StarSystem *out, vec2 *pos, vec2 *vel, double *dir, const Pilot *p)
 Calculates the jump in pos for a pilot.
 
char ** space_getFactionSpob (const int *factions, int landable)
 Gets the name of all the spobs that belong to factions.
 
const char * space_getRndSpob (int landable, unsigned int services, int(*filter)(Spob *p))
 Gets the name of a random spob.
 
double system_getClosest (const StarSystem *sys, int *pnt, int *jp, int *ast, int *fie, double x, double y)
 Gets the closest feature to a position in the system.
 
double system_getClosestAng (const StarSystem *sys, int *pnt, int *jp, int *ast, int *fie, double x, double y, double ang)
 Gets the feature nearest to directly ahead of a position in the system.
 
int space_sysReachable (const StarSystem *sys)
 Sees if a system is reachable.
 
int space_sysReallyReachable (const char *sysname)
 Sees if a system can be reached via jumping.
 
int space_sysReachableFromSys (const StarSystem *target, const StarSystem *sys)
 Sees if a system is reachable from another system.
 
StarSystem * system_getAll (void)
 Gets an array (array.h) of all star systems.
 
const char * system_existsCase (const char *sysname)
 Checks to see if a system exists case insensitively.
 
char ** system_searchFuzzyCase (const char *sysname, int *n)
 Does a fuzzy case matching. Searches translated names but returns internal names.
 
static int system_cmp (const void *p1, const void *p2)
 Comparison function for qsort'ing StarSystem by name.
 
StarSystem * system_get (const char *sysname)
 Get the system from its name.
 
StarSystem * system_getIndex (int id)
 Get the system by its index.
 
int system_index (const StarSystem *sys)
 Gets the index of a star system.
 
int spob_hasSystem (const Spob *spb)
 Get whether or not a spob has a system (i.e. is on the map).
 
const char * spob_getSystem (const char *spobname)
 Get the name of a system from a spobname.
 
Spobspob_get (const char *spobname)
 Gets a spob based on its name.
 
Spobspob_getIndex (int ind)
 Gets spob by index.
 
int spob_index (const Spob *p)
 Gets the ID of a spob.
 
Spobspob_getAll (void)
 Gets an array (array.h) of all spobs.
 
void spob_setKnown (Spob *p)
 Sets a spob's known status, if it's real.
 
int spob_exists (const char *spobname)
 Check to see if a spob exists.
 
const char * spob_existsCase (const char *spobname)
 Check to see if a spob exists (case insensitive).
 
char ** spob_searchFuzzyCase (const char *spobname, int *n)
 Does a fuzzy case matching. Searches spob_name() but returns internal names.
 
VirtualSpobvirtualspob_getAll (void)
 Gets all the virtual spobs.
 
static int virtualspob_cmp (const void *p1, const void *p2)
 Comparison function for qsort'ing VirtuaSpob by name.
 
VirtualSpobvirtualspob_get (const char *name)
 Gets a virtual spob by matching name.
 
JumpPoint * jump_get (const char *jumpname, const StarSystem *sys)
 Gets a jump point based on its target and system.
 
JumpPoint * jump_getTarget (const StarSystem *target, const StarSystem *sys)
 Less safe version of jump_get that works with pointers.
 
const char * jump_getSymbol (const JumpPoint *jp)
 Gets the jump point symbol.
 
void space_factionChange (void)
 Mark when a faction changes.
 
void space_checkLand (void)
 Handles landing if necessary.
 
void space_update (double dt, double real_dt)
 Controls fleet spawning.
 
int space_isSimulation (void)
 returns whether we're just simulating.
 
int space_needsEffects (void)
 returns whether or not we're simulating with effects.
 
void space_init (const char *sysname, int do_simulate)
 Initializes the system.
 
Spobspob_new (void)
 Creates a new spob.
 
const char * spob_name (const Spob *p)
 Gets the translated name of a spob.
 
static int spobs_load (void)
 Loads all the spobs in the game.
 
static int virtualspobs_load (void)
 Loads all the virtual spobs.
 
char spob_getColourChar (const Spob *p)
 Gets the spob colour char.
 
const char * spob_getSymbol (const Spob *p)
 Gets the spob symbol.
 
const glColour * spob_getColour (const Spob *p)
 Gets the spob colour.
 
void spob_updateLand (Spob *p)
 Updates the land possibilities of a spob.
 
void spob_luaInitMem (const Spob *spob)
 Initializes the memory fo a spob.
 
int spob_luaInit (Spob *spob)
 Updatse the spob's internal Lua stuff.
 
void spob_gfxLoad (Spob *spob)
 Loads a spob's graphics (and radius).
 
void space_gfxLoad (StarSystem *sys)
 Loads all the graphics for a star system.
 
void space_gfxUnload (StarSystem *sys)
 Unloads all the graphics for a star system.
 
int system_addSpob (StarSystem *sys, const char *spobname)
 Adds a spob to a star system.
 
int system_rmSpob (StarSystem *sys, const char *spobname)
 Removes a spob from a star system.
 
int system_addVirtualSpob (StarSystem *sys, const char *spobname)
 Adds a virtual spob to a system.
 
int system_rmVirtualSpob (StarSystem *sys, const char *spobname)
 Removes a virtual spob from a system.
 
int system_addJumpDiff (StarSystem *sys, xmlNodePtr node)
 Adds a jump point to a star system from a diff.
 
int system_rmJump (StarSystem *sys, const char *jumpname)
 Removes a jump point from a star system.
 
StarSystem * system_new (void)
 Creates a new star system.
 
void system_reconstructJumps (StarSystem *sys)
 Reconstructs the jumps for a single system.
 
void systems_reconstructJumps (void)
 Reconstructs the jumps.
 
void systems_reconstructSpobs (void)
 Updates the system spob pointers.
 
static int sys_cmpSysFaction (const void *a, const void *b)
 Compares two system presences.
 
void system_setFaction (StarSystem *sys)
 Sets the system faction based on the spobs it has.
 
int space_load (void)
 Loads the entire universe into ram - pretty big feat eh?
 
int space_loadLua (void)
 initializes the Lua for all the spobs.
 
void space_render (const double dt)
 Renders the system.
 
void space_renderOverlay (const double dt)
 Renders the system overlay.
 
void spobs_render (void)
 Renders the current systems' spobs.
 
void space_exit (void)
 Cleans up the system.
 
void space_clearKnown (void)
 Clears all system knowledge.
 
void space_clearMarkers (void)
 Clears all system markers.
 
void space_clearComputerMarkers (void)
 Clears all the system computer markers.
 
int space_addMarker (int objid, MissionMarkerType type)
 Adds a marker to a system.
 
int space_rmMarker (int objid, MissionMarkerType type)
 Removes a marker from a system.
 
void system_presenceAddSpob (StarSystem *sys, const SpobPresence *ap)
 Adds (or removes) some presence to a system.
 
double system_getPresence (const StarSystem *sys, int faction)
 Get the presence of a faction in a system.
 
double system_getPresenceFull (const StarSystem *sys, int faction, double *base, double *bonus)
 Get the presence of a faction in a system.
 
void system_addAllSpobsPresence (StarSystem *sys)
 Go through all the spobs and call system_addPresence().
 
void space_reconstructPresences (void)
 Reset the presence of all systems.
 
int system_hasSpob (const StarSystem *sys)
 See if the system has a spob.
 
void system_rmCurrentPresence (StarSystem *sys, int faction, double amount)
 Removes active presence.
 
void space_queueLand (Spob *pnt)
 Cues a spob to be landed on. This is not done immediately, but when the engine thinks it is ok to do.
 
const char * space_populationStr (const Spob *spb)
 Gets the population in an approximated string. Note this function changes the string value each call, so be careful!
 

Variables

static spob_lua_filespob_lua_stack = NULL
 
static char ** spobname_stack = NULL
 
static char ** systemname_stack = NULL
 
StarSystem * systems_stack = NULL
 
static Spobspob_stack = NULL
 
static VirtualSpobvspob_stack = NULL
 
static int systemstack_changed = 0
 
static int spobstack_changed = 0
 
static MapShader ** mapshaders = NULL
 
static int systems_loading = 1
 
StarSystem * cur_system = NULL
 
glTexturejumppoint_gfx = NULL
 
static glTexturejumpbuoy_gfx = NULL
 
static int space_fchg = 0
 
static int space_simulating = 0
 
static int space_simulating_effects = 0
 
static Spobspace_landQueueSpob = NULL
 
int space_spawn = 1
 

Detailed Description

Handles all the space stuff, namely systems and space objects (spobs).

Definition in file space.c.

Macro Definition Documentation

◆ DEBRIS_BUFFER

#define DEBRIS_BUFFER   1000

Buffer to smooth appearance of debris

Definition at line 73 of file space.c.

◆ FLAG_FACTIONSET

#define FLAG_FACTIONSET   (1<<3)

Set the faction value.

Definition at line 71 of file space.c.

◆ FLAG_INTERFERENCESET

#define FLAG_INTERFERENCESET   (1<<1)

Set the interference value.

Definition at line 69 of file space.c.

◆ FLAG_POSSET

#define FLAG_POSSET   (1<<0)

Set the position.

Definition at line 68 of file space.c.

◆ FLAG_SERVICESSET

#define FLAG_SERVICESSET   (1<<2)

Set the service value.

Definition at line 70 of file space.c.

◆ MELEMENT [1/4]

#define MELEMENT ( o,
s )
Value:
if (o) WARN(_("Spob '%s' missing '%s' element"), spob->name, s)

◆ MELEMENT [2/4]

#define MELEMENT ( o,
s )
Value:
if (o) WARN(_("Asteroid Field in Star System '%s' has missing/invalid '%s' element"), sys->name, s)

◆ MELEMENT [3/4]

#define MELEMENT ( o,
s )
Value:
if (o) WARN(_("Asteroid Exclusion Zone in Star System '%s' has missing/invalid '%s' element"), sys->name, s)

◆ MELEMENT [4/4]

#define MELEMENT ( o,
s )
Value:
if (o) WARN(_("Star System '%s' missing '%s' element"), sys->name, s)

◆ SPOB_GFX_EXTERIOR_PATH_H

#define SPOB_GFX_EXTERIOR_PATH_H   400

Spob exterior graphic height.

Definition at line 65 of file space.c.

◆ SPOB_GFX_EXTERIOR_PATH_W

#define SPOB_GFX_EXTERIOR_PATH_W   400

Spob exterior graphic width.

Definition at line 64 of file space.c.

◆ UNREF

#define UNREF ( x)
Value:
do { if ((x) != LUA_NOREF) { \
luaL_unref( naevL, LUA_REGISTRYINDEX, (x) ); \
(x) = LUA_NOREF; \
} } while (0)

◆ XML_SPOB_TAG

#define XML_SPOB_TAG   "spob"

Individual spob xml tag.

Definition at line 61 of file space.c.

◆ XML_SYSTEM_TAG

#define XML_SYSTEM_TAG   "ssys"

Individual systems xml tag.

Definition at line 62 of file space.c.

Function Documentation

◆ getPresenceIndex()

static int getPresenceIndex ( StarSystem * sys,
int faction )
static

Gets the index of the presence element for a faction. Creates one if it doesn't exist.

Parameters
sysPointer to the system to check.
factionThe index of the faction to search for.
Returns
The index of the presence array for faction.

Definition at line 4025 of file space.c.

◆ jump_get()

JumpPoint * jump_get ( const char * jumpname,
const StarSystem * sys )

Gets a jump point based on its target and system.

Parameters
jumpnameName to match.
sysSystem jump is in.
Returns
Jump point matich jumpname in sys or NULL if not found.

Definition at line 1222 of file space.c.

◆ jump_getSymbol()

const char * jump_getSymbol ( const JumpPoint * jp)

Gets the jump point symbol.

Definition at line 1260 of file space.c.

◆ jump_getTarget()

JumpPoint * jump_getTarget ( const StarSystem * target,
const StarSystem * sys )

Less safe version of jump_get that works with pointers.

Parameters
targetTarget system jump leads to.
sysSystem to look in.
Returns
Jump point in sys to target or NULL if not found.

Definition at line 1246 of file space.c.

◆ mapshader_get()

static const MapShader * mapshader_get ( const char * name)
static

Gets the map shader by name.

Parameters
nameNAme of the map shader.
Returns
The map shader.

Definition at line 4432 of file space.c.

◆ space_addMarker()

int space_addMarker ( int objid,
MissionMarkerType type )

Adds a marker to a system.

Parameters
objidID of the object to add marker to.
typeType of the marker to add.
Returns
0 on success.

Definition at line 3787 of file space.c.

◆ space_addMarkerSpob()

static int space_addMarkerSpob ( int pntid,
MissionMarkerType type )
static

Definition at line 3758 of file space.c.

◆ space_addMarkerSystem()

static int space_addMarkerSystem ( int sysid,
MissionMarkerType type )
static

Definition at line 3722 of file space.c.

◆ space_calcJumpInPos()

int space_calcJumpInPos ( const StarSystem * in,
const StarSystem * out,
vec2 * pos,
vec2 * vel,
double * dir,
const Pilot * p )

Calculates the jump in pos for a pilot.

Parameters
inStar system entering.
outStar system exiting.
[out]posPosition calculated.
[out]velVelocity calculated.
[out]dirAngle calculated.
pPilot that is entering to use stats of (or NULL if not important).

Definition at line 527 of file space.c.

◆ space_canHyperspace()

int space_canHyperspace ( const Pilot * p)

Checks to make sure if pilot is far enough away to hyperspace.

Parameters
pPilot to check if he can hyperspace.
Returns
1 if he can hyperspace, 0 else.

Definition at line 469 of file space.c.

◆ space_checkLand()

void space_checkLand ( void )

Handles landing if necessary.

Definition at line 1400 of file space.c.

◆ space_clearComputerMarkers()

void space_clearComputerMarkers ( void )

Clears all the system computer markers.

Definition at line 3716 of file space.c.

◆ space_clearKnown()

void space_clearKnown ( void )

Clears all system knowledge.

Definition at line 3677 of file space.c.

◆ space_clearMarkers()

void space_clearMarkers ( void )

Clears all system markers.

Definition at line 3696 of file space.c.

◆ space_exit()

void space_exit ( void )

Cleans up the system.

Definition at line 3564 of file space.c.

◆ space_factionChange()

void space_factionChange ( void )

Mark when a faction changes.

Definition at line 1392 of file space.c.

◆ space_getFactionSpob()

char ** space_getFactionSpob ( const int * factions,
int landable )

Gets the name of all the spobs that belong to factions.

Parameters
factionsArray (array.h): Factions to check against.
landableWhether the search is limited to landable spobs.
Returns
An array (array.h) of faction names. Individual names are not allocated.

Definition at line 590 of file space.c.

◆ space_getRndSpob()

const char * space_getRndSpob ( int landable,
unsigned int services,
int(* filter )(Spob *p) )

Gets the name of a random spob.

Parameters
landableWhether the spob must let the player land normally.
servicesServices the spob must have.
filterFilter function for including spobs.
Returns
The name (internal/English) of a random spob.

Definition at line 633 of file space.c.

◆ space_gfxLoad()

void space_gfxLoad ( StarSystem * sys)

Loads all the graphics for a star system.

Parameters
sysSystem to load graphics for.

Definition at line 2116 of file space.c.

◆ space_gfxUnload()

void space_gfxUnload ( StarSystem * sys)

Unloads all the graphics for a star system.

Parameters
sysSystem to unload graphics for.

Definition at line 2127 of file space.c.

◆ space_hyperspace()

int space_hyperspace ( Pilot * p)

Tries to get the pilot into hyperspace.

Parameters
pPilot to try to start hyperspacing.
Returns
0 on success.

Definition at line 503 of file space.c.

◆ space_init()

void space_init ( const char * sysname,
int do_simulate )

Initializes the system.

Parameters
sysnameName of the system to initialize.
do_simulateWhether or not perform the initial simulation.

Definition at line 1549 of file space.c.

◆ space_isSimulation()

int space_isSimulation ( void )

returns whether we're just simulating.

Definition at line 1530 of file space.c.

◆ space_jumpDistance()

int space_jumpDistance ( const Pilot * p,
const JumpPoint * jp )

Distance at which a pilot can jump.

Definition at line 455 of file space.c.

◆ space_load()

int space_load ( void )

Loads the entire universe into ram - pretty big feat eh?

Returns
0 on success.

Definition at line 3313 of file space.c.

◆ space_loadLua()

int space_loadLua ( void )

initializes the Lua for all the spobs.

Definition at line 3349 of file space.c.

◆ space_needsEffects()

int space_needsEffects ( void )

returns whether or not we're simulating with effects.

Definition at line 1538 of file space.c.

◆ space_parseSpobs()

static int space_parseSpobs ( xmlNodePtr parent,
StarSystem * sys )
static

Parses spobs in a system.

Parameters
parentNode of the system.
sysSystem to populate.
Returns
0 on success.

Definition at line 3998 of file space.c.

◆ space_populationStr()

const char * space_populationStr ( const Spob * spb)

Gets the population in an approximated string. Note this function changes the string value each call, so be careful!

Parameters
spbSpob to get population string of.
Returns
String corresponding to the population.

Definition at line 4375 of file space.c.

◆ space_queueLand()

void space_queueLand ( Spob * pnt)

Cues a spob to be landed on. This is not done immediately, but when the engine thinks it is ok to do.

Parameters
pntSpob to land on.

Definition at line 4364 of file space.c.

◆ space_reconstructPresences()

void space_reconstructPresences ( void )

Reset the presence of all systems.

Definition at line 4263 of file space.c.

◆ space_render()

void space_render ( const double dt)

Renders the system.

Parameters
dtCurrent delta tick.

Definition at line 3441 of file space.c.

◆ space_renderJumpPoint()

static void space_renderJumpPoint ( const JumpPoint * jp,
int i )
static

Renders a jump point.

Definition at line 3501 of file space.c.

◆ space_renderOverlay()

void space_renderOverlay ( const double dt)

Renders the system overlay.

Parameters
dtCurrent delta tick.

Definition at line 3457 of file space.c.

◆ space_renderSpob()

static void space_renderSpob ( const Spob * p)
static

Renders a spob.

Definition at line 3528 of file space.c.

◆ space_rmMarker()

int space_rmMarker ( int objid,
MissionMarkerType type )

Removes a marker from a system.

Parameters
objidID of the object to remove marker from.
typeType of the marker to remove.
Returns
0 on success.

Definition at line 3873 of file space.c.

◆ space_rmMarkerSpob()

static int space_rmMarkerSpob ( int pntid,
MissionMarkerType type )
static

Definition at line 3846 of file space.c.

◆ space_rmMarkerSystem()

static int space_rmMarkerSystem ( int sysid,
MissionMarkerType type )
static

Definition at line 3807 of file space.c.

◆ space_sysLoad()

int space_sysLoad ( xmlNodePtr parent)

Loads player's space properties from an XML node.

Parameters
parentParent node for space.
Returns
0 on success.

Definition at line 3938 of file space.c.

◆ space_sysReachable()

int space_sysReachable ( const StarSystem * sys)

Sees if a system is reachable.

Returns
1 if target system is reachable, 0 if it isn't.

Definition at line 826 of file space.c.

◆ space_sysReachableFromSys()

int space_sysReachableFromSys ( const StarSystem * target,
const StarSystem * sys )

Sees if a system is reachable from another system.

Returns
1 if target system is reachable, 0 if it isn't.

Definition at line 865 of file space.c.

◆ space_sysReallyReachable()

int space_sysReallyReachable ( const char * sysname)

Sees if a system can be reached via jumping.

Returns
1 if target system is reachable, 0 if it isn't.

Definition at line 846 of file space.c.

◆ space_sysSave()

int space_sysSave ( xmlTextWriterPtr writer)

Saves what is needed to be saved for space.

Parameters
writerXML writer to use.
Returns
0 on success.

Definition at line 3898 of file space.c.

◆ space_update()

void space_update ( double dt,
double real_dt )

Controls fleet spawning.

Parameters
dtCurrent delta tick.
real_dtReal time incrcement (in real world seconds).

Definition at line 1414 of file space.c.

◆ space_updateSpob()

static void space_updateSpob ( const Spob * p,
double dt,
double real_dt )
static

Renders a spob.

Definition at line 3546 of file space.c.

◆ spob_addCommodity()

int spob_addCommodity ( Spob * p,
Commodity * c )

Adds a commodity to a spob.

Parameters
pSpob to add commodity to.
cCommodity to add.
Returns
0 on success.

Definition at line 362 of file space.c.

◆ spob_addService()

int spob_addService ( Spob * p,
int service )

Removes a service from a spob.

Parameters
pSpob to remove service from.
serviceService flag to remove.
Returns
0 on success.

Definition at line 376 of file space.c.

◆ spob_averageSeenPricesAtTime()

void spob_averageSeenPricesAtTime ( const Spob * p,
const ntime_t tupdate )

Adds cost of commodities on spob p to known statistics at time t.

Parameters
pSpob to get price at
tupdateTime to get prices at

Definition at line 303 of file space.c.

◆ spob_averageSpobPrice()

int spob_averageSpobPrice ( const Spob * p,
const Commodity * c,
credits_t * mean,
double * std )

Gets the average price of a commodity at a spob that has been seen so far.

Parameters
pSpob to get average price at.
cCommodity to get average price of.
[out]meanSample mean, rounded to nearest credit.
[out]stdSample standard deviation (via uncorrected population formula).

Definition at line 316 of file space.c.

◆ spob_cmp()

static int spob_cmp ( const void * p1,
const void * p2 )
static

Comparison function for qsort'ing Spob by name.

Definition at line 1037 of file space.c.

◆ spob_commodityPrice()

credits_t spob_commodityPrice ( const Spob * p,
const Commodity * c )

Gets the price of a commodity at a spob.

Parameters
pSpob to get price at.
cCommodity to get price of.

Definition at line 276 of file space.c.

◆ spob_commodityPriceAtTime()

credits_t spob_commodityPriceAtTime ( const Spob * p,
const Commodity * c,
ntime_t t )

Gets the price of a commodity at a spob at given time.

Parameters
pSpob to get price at.
cCommodity to get price of.
tTime to get price at.

Definition at line 290 of file space.c.

◆ spob_exists()

int spob_exists ( const char * spobname)

Check to see if a spob exists.

Parameters
spobnameName of the spob to see if it exists.
Returns
1 if spob exists.

Definition at line 1126 of file space.c.

◆ spob_existsCase()

const char * spob_existsCase ( const char * spobname)

Check to see if a spob exists (case insensitive).

Parameters
spobnameName of the spob to see if it exists.
Returns
The actual name of the spob or NULL if not found.

Definition at line 1140 of file space.c.

◆ spob_get()

Spob * spob_get ( const char * spobname)

Gets a spob based on its name.

Parameters
spobnameName to match.
Returns
Spob matching spobname.

Definition at line 1051 of file space.c.

◆ spob_getAll()

Spob * spob_getAll ( void )

Gets an array (array.h) of all spobs.

Definition at line 1107 of file space.c.

◆ spob_getClassName()

const char * spob_getClassName ( const char * class)

Gets the long class name for a spob.

Parameters
className of the class to process.
Returns
Long name of the class.

Definition at line 215 of file space.c.

◆ spob_getColour()

const glColour * spob_getColour ( const Spob * p)

Gets the spob colour.

Definition at line 1922 of file space.c.

◆ spob_getColourChar()

char spob_getColourChar ( const Spob * p)

Gets the spob colour char.

Definition at line 1881 of file space.c.

◆ spob_getIndex()

Spob * spob_getIndex ( int ind)

Gets spob by index.

Parameters
indIndex of the spob to get.
Returns
The spob gotten.

Definition at line 1082 of file space.c.

◆ spob_getService()

int spob_getService ( const char * name)

Converts name to spob service flag.

Definition at line 186 of file space.c.

◆ spob_getServiceName()

const char * spob_getServiceName ( int service)

Gets the (English) name for a service code.

Parameters
serviceOne of the SPOB_SERVICE_* enum values.
Returns
English name, reversible via spob_getService() and presentable via _().

Definition at line 167 of file space.c.

◆ spob_getSymbol()

const char * spob_getSymbol ( const Spob * p)

Gets the spob symbol.

Definition at line 1900 of file space.c.

◆ spob_getSystem()

const char * spob_getSystem ( const char * spobname)

Get the name of a system from a spobname.

Parameters
spobnameSpob name to match.
Returns
Name of the system spob belongs to.

Definition at line 1025 of file space.c.

◆ spob_gfxLoad()

void spob_gfxLoad ( Spob * spob)

Loads a spob's graphics (and radius).

Definition at line 2078 of file space.c.

◆ spob_hasSystem()

int spob_hasSystem ( const Spob * spb)

Get whether or not a spob has a system (i.e. is on the map).

Parameters
spbSpob to search for.
Returns
1 if the spob has a system, 0 otherwise.

Definition at line 1011 of file space.c.

◆ spob_index()

int spob_index ( const Spob * p)

Gets the ID of a spob.

Parameters
pSpob to get ID of.
Returns
The ID of the spob.

Definition at line 1099 of file space.c.

◆ spob_lua_cmp()

static int spob_lua_cmp ( const void * a,
const void * b )
static

Definition at line 4460 of file space.c.

◆ spob_lua_free()

static void spob_lua_free ( spob_lua_file * lf)
static

Definition at line 4522 of file space.c.

◆ spob_lua_get()

static nlua_env spob_lua_get ( int * mem,
const char * filename )
static

Definition at line 4467 of file space.c.

◆ spob_luaInit()

int spob_luaInit ( Spob * spob)

Updatse the spob's internal Lua stuff.

Parameters
spobSpob to update.

Definition at line 1997 of file space.c.

◆ spob_luaInitMem()

void spob_luaInitMem ( const Spob * spob)

Initializes the memory fo a spob.

Definition at line 1986 of file space.c.

◆ spob_name()

const char * spob_name ( const Spob * p)

Gets the translated name of a spob.

Parameters
pSpob to get translated name of.
Returns
Translated name of the spob.

Definition at line 1752 of file space.c.

◆ spob_new()

Spob * spob_new ( void )

Creates a new spob.

Definition at line 1709 of file space.c.

◆ spob_parse()

static int spob_parse ( Spob * spob,
const char * filename,
Commodity ** stdList )
static

Parses a spob from an xml node.

Parameters
spobSpob to fill up.
filenameName of the file to parse.
[in]stdListThe array of standard commodities.
Returns
0 on success.

Definition at line 2178 of file space.c.

◆ spob_parsePresence()

static int spob_parsePresence ( xmlNodePtr node,
SpobPresence * ap )
static

Parsess an spob presence from xml.

Parameters
nodeNode to process.
[out]apSpob presence to save to.

Definition at line 2152 of file space.c.

◆ spob_rename()

int spob_rename ( Spob * p,
char * newname )

Renames a spob.

Parameters
pSpob to rename.
newnameNew name to give the spob.
Returns
0 on success.

Definition at line 431 of file space.c.

◆ spob_rmService()

int spob_rmService ( Spob * p,
int service )

Removes a service from a spob.

Parameters
pSpob to remove service from.
serviceService flag to remove.
Returns
0 on success.

Definition at line 418 of file space.c.

◆ spob_searchFuzzyCase()

char ** spob_searchFuzzyCase ( const char * spobname,
int * n )

Does a fuzzy case matching. Searches spob_name() but returns internal names.

Definition at line 1151 of file space.c.

◆ spob_setFaction()

int spob_setFaction ( Spob * p,
int faction )

Changes the spobs faction.

Parameters
pSpob to change faction of.
factionFaction to change to.
Returns
0 on success.

Definition at line 349 of file space.c.

◆ spob_setKnown()

void spob_setKnown ( Spob * p)

Sets a spob's known status, if it's real.

Definition at line 1115 of file space.c.

◆ spob_updateLand()

void spob_updateLand ( Spob * p)

Updates the land possibilities of a spob.

Parameters
pSpob to update land possibilities of.

Definition at line 1943 of file space.c.

◆ spobs_load()

static int spobs_load ( void )
static

Loads all the spobs in the game.

Returns
0 on success.

Definition at line 1764 of file space.c.

◆ spobs_render()

void spobs_render ( void )

Renders the current systems' spobs.

Definition at line 3476 of file space.c.

◆ sys_cmpSysFaction()

static int sys_cmpSysFaction ( const void * a,
const void * b )
static

Compares two system presences.

Definition at line 3064 of file space.c.

◆ system_addAllSpobsPresence()

void system_addAllSpobsPresence ( StarSystem * sys)

Go through all the spobs and call system_addPresence().

Parameters
sysPointer to the system to process.

Definition at line 4240 of file space.c.

◆ system_addJumpDiff()

int system_addJumpDiff ( StarSystem * sys,
xmlNodePtr node )

Adds a jump point to a star system from a diff.

Note that economy_execQueued should always be run after this.

Parameters
sysStar System to add jump point to.
nodeParent node containing jump point information.
Returns
0 on success.

Definition at line 2606 of file space.c.

◆ system_addSpob()

int system_addSpob ( StarSystem * sys,
const char * spobname )

Adds a spob to a star system.

Parameters
sysStar System to add spob to. (Assumed to belong to systems_stack.)
spobnameName of the spob to add.
Returns
0 on success.

Definition at line 2452 of file space.c.

◆ system_addVirtualSpob()

int system_addVirtualSpob ( StarSystem * sys,
const char * spobname )

Adds a virtual spob to a system.

Parameters
sysSystem to add virtual spob to.
spobnameName of the virtual spob being added.

Definition at line 2545 of file space.c.

◆ system_cmp()

static int system_cmp ( const void * p1,
const void * p2 )
static

Comparison function for qsort'ing StarSystem by name.

Definition at line 946 of file space.c.

◆ system_existsCase()

const char * system_existsCase ( const char * sysname)

Checks to see if a system exists case insensitively.

Parameters
sysnameName of the system to match (case insensitive).
Returns
The actual name of the system of NULL if not found.

Definition at line 890 of file space.c.

◆ system_get()

StarSystem * system_get ( const char * sysname)

Get the system from its name.

Parameters
sysnameName to match.
Returns
System matching sysname.

Definition at line 960 of file space.c.

◆ system_getAll()

StarSystem * system_getAll ( void )

Gets an array (array.h) of all star systems.

Definition at line 879 of file space.c.

◆ system_getClosest()

double system_getClosest ( const StarSystem * sys,
int * pnt,
int * jp,
int * ast,
int * fie,
double x,
double y )

Gets the closest feature to a position in the system.

Parameters
sysSystem to get closest feature from a position.
[out]pntID of closest spob or -1 if a jump point is closer (or none is close).
[out]jpID of closest jump point or -1 if a spob is closer (or none is close).
[out]astID of closest asteroid or -1 if something else is closer (or none is close).
[out]fieID of the asteroid anchor the asteroid belongs to.
xX position to get closest from.
yY position to get closest from.

Definition at line 687 of file space.c.

◆ system_getClosestAng()

double system_getClosestAng ( const StarSystem * sys,
int * pnt,
int * jp,
int * ast,
int * fie,
double x,
double y,
double ang )

Gets the feature nearest to directly ahead of a position in the system.

Parameters
sysSystem to get closest feature from a position.
[out]pntID of closest spob or -1 if something else is closer (or none is close).
[out]jpID of closest jump point or -1 if something else is closer (or none is close).
[out]astID of closest asteroid or -1 if something else is closer (or none is close).
[out]fieID of the asteroid anchor the asteroid belongs to.
xX position to get closest from.
yY position to get closest from.
angReference angle.
Returns
The nearest angle to ang which is the direction from (x, y) to a feature.

Definition at line 766 of file space.c.

◆ system_getIndex()

StarSystem * system_getIndex ( int id)

Get the system by its index.

Parameters
idIndex to match.
Returns
System matching index.

Definition at line 989 of file space.c.

◆ system_getPresence()

double system_getPresence ( const StarSystem * sys,
int faction )

Get the presence of a faction in a system.

Parameters
sysPointer to the system to process.
factionThe faction to get the presence for.
Returns
The amount of presence the faction has in the system.

Definition at line 4181 of file space.c.

◆ system_getPresenceFull()

double system_getPresenceFull ( const StarSystem * sys,
int faction,
double * base,
double * bonus )

Get the presence of a faction in a system.

Parameters
sysPointer to the system to process.
factionThe faction to get the presence for.
[out]baseBase value of the presence.
[out]bonusBonus value of the presence.
Returns
The amount of presence the faction has in the system.

Definition at line 4210 of file space.c.

◆ system_hasSpob()

int system_hasSpob ( const StarSystem * sys)

See if the system has a spob.

Parameters
sysPointer to the system to process.
Returns
0 If empty; otherwise 1.

Definition at line 4294 of file space.c.

◆ system_index()

int system_index ( const StarSystem * sys)

Gets the index of a star system.

Parameters
sysSystem to get index of.
Returns
The index of the system.

Definition at line 1000 of file space.c.

◆ system_init()

static void system_init ( StarSystem * sys)
static

Initializes a new star system with null memory.

Definition at line 2658 of file space.c.

◆ system_new()

StarSystem * system_new ( void )

Creates a new star system.

Definition at line 2673 of file space.c.

◆ system_parse()

static int system_parse ( StarSystem * sys,
const char * filename )
static

Creates a system from an XML node.

Parameters
sysSystem to set up.
filenameName of the file to parse.
Returns
0 on success.

Definition at line 2897 of file space.c.

◆ system_parseAsteroidExclusion()

static int system_parseAsteroidExclusion ( const xmlNodePtr node,
StarSystem * sys )
static

Parses a single asteroid exclusion zone for a system.

Parameters
nodeParent node containing asteroid exclusion information.
sysSystem.
Returns
0 on success.

Definition at line 2847 of file space.c.

◆ system_parseAsteroidField()

static int system_parseAsteroidField ( const xmlNodePtr node,
StarSystem * sys )
static

Parses a single asteroid field for a system.

Parameters
nodeParent node containing asteroid field information.
sysSystem.
Returns
0 on success.

Definition at line 2769 of file space.c.

◆ system_parseJumpPoint()

static int system_parseJumpPoint ( const xmlNodePtr node,
StarSystem * sys )
static

Parses a single jump point for a system.

Parameters
nodeParent node containing jump point information.
sysSystem to which the jump point belongs.
Returns
0 on success.

Definition at line 3190 of file space.c.

◆ system_parseJumpPointDiff()

static int system_parseJumpPointDiff ( const xmlNodePtr node,
StarSystem * sys )
static

Parses a single jump point for a system, from unidiff.

Parameters
nodeParent node containing jump point information.
sysSystem to which the jump point belongs.
Returns
0 on success.

Definition at line 3118 of file space.c.

◆ system_parseJumps()

static int system_parseJumps ( StarSystem * sys)
static

Loads the jumps into a system.

Parameters
sysStar system to load jumps of.
Returns
0 on success.

Definition at line 3276 of file space.c.

◆ system_presenceAddSpob()

void system_presenceAddSpob ( StarSystem * sys,
const SpobPresence * ap )

Adds (or removes) some presence to a system.

Parameters
sysPointer to the system to add to or remove from.
apSpob presence to add.

Definition at line 4054 of file space.c.

◆ system_reconstructJumps()

void system_reconstructJumps ( StarSystem * sys)

Reconstructs the jumps for a single system.

Definition at line 2707 of file space.c.

◆ system_rmCurrentPresence()

void system_rmCurrentPresence ( StarSystem * sys,
int faction,
double amount )

Removes active presence.

Definition at line 4312 of file space.c.

◆ system_rmJump()

int system_rmJump ( StarSystem * sys,
const char * jumpname )

Removes a jump point from a star system.

Note that economy_execQueued should always be run after this.

Parameters
sysStar System to remove jump point from.
jumpnameName of the jump point to remove.
Returns
0 on success.

Definition at line 2625 of file space.c.

◆ system_rmSpob()

int system_rmSpob ( StarSystem * sys,
const char * spobname )

Removes a spob from a star system.

Remember to call space_reconstructPresences() after using this function.

Parameters
sysStar System to remove spob from.
spobnameName of the spob to remove.
Returns
0 on success.

Definition at line 2493 of file space.c.

◆ system_rmVirtualSpob()

int system_rmVirtualSpob ( StarSystem * sys,
const char * spobname )

Removes a virtual spob from a system.

Parameters
sysSystem to remove virtual spob from.
spobnameName of the virtual spob being removed.

Definition at line 2569 of file space.c.

◆ system_scheduler()

static void system_scheduler ( double dt,
int init )
static

Controls fleet spawning.

Parameters
dtCurrent delta tick.
initShould be 1 to initialize the scheduler.

Definition at line 1273 of file space.c.

◆ system_searchFuzzyCase()

char ** system_searchFuzzyCase ( const char * sysname,
int * n )

Does a fuzzy case matching. Searches translated names but returns internal names.

Definition at line 901 of file space.c.

◆ system_setFaction()

void system_setFaction ( StarSystem * sys)

Sets the system faction based on the spobs it has.

Parameters
sysSystem to set the faction of.
Todo
Handle multiple different factions.

Definition at line 3091 of file space.c.

◆ system_updateAsteroids()

void system_updateAsteroids ( StarSystem * sys)

Updates some internal calculations about asteroids in a system.

Parameters
sysSystem to update.

Definition at line 326 of file space.c.

◆ systems_load()

static int systems_load ( void )
static

Loads the entire systems, needs to be called after spobs_load.

Does multiple passes to load:

  • First loads the star systems.
  • Next sets the jump routes.

    Returns
    0 on success.

Definition at line 3367 of file space.c.

◆ systems_reconstructJumps()

void systems_reconstructJumps ( void )

Reconstructs the jumps.

Definition at line 2738 of file space.c.

◆ systems_reconstructSpobs()

void systems_reconstructSpobs ( void )

Updates the system spob pointers.

Definition at line 2753 of file space.c.

◆ virtualspob_cmp()

static int virtualspob_cmp ( const void * p1,
const void * p2 )
static

Comparison function for qsort'ing VirtuaSpob by name.

Definition at line 1194 of file space.c.

◆ virtualspob_get()

VirtualSpob * virtualspob_get ( const char * name)

Gets a virtual spob by matching name.

Definition at line 1205 of file space.c.

◆ virtualspob_getAll()

VirtualSpob * virtualspob_getAll ( void )

Gets all the virtual spobs.

Definition at line 1186 of file space.c.

◆ virtualspobs_load()

static int virtualspobs_load ( void )
static

Loads all the virtual spobs.

Returns
0 on success.

Definition at line 1810 of file space.c.

Variable Documentation

◆ cur_system

StarSystem* cur_system = NULL

Current star system.

Definition at line 106 of file space.c.

◆ jumpbuoy_gfx

glTexture* jumpbuoy_gfx = NULL
static

Jump buoy graphics.

Definition at line 108 of file space.c.

◆ jumppoint_gfx

glTexture* jumppoint_gfx = NULL

Jump point graphics.

Definition at line 107 of file space.c.

◆ mapshaders

MapShader** mapshaders = NULL
static

Map shaders.

Definition at line 100 of file space.c.

◆ space_fchg

int space_fchg = 0
static

Faction change counter, to avoid unnecessary calls.

Definition at line 109 of file space.c.

◆ space_landQueueSpob

Spob* space_landQueueSpob = NULL
static

Definition at line 112 of file space.c.

◆ space_simulating

int space_simulating = 0
static

Are we simulating space?

Definition at line 110 of file space.c.

◆ space_simulating_effects

int space_simulating_effects = 0
static

Are we doing special effects?

Definition at line 111 of file space.c.

◆ space_spawn

int space_spawn = 1

Spawn enabled by default.

Definition at line 117 of file space.c.

◆ spob_lua_stack

spob_lua_file* spob_lua_stack = NULL
static

Handles spob Lua chunks.

Definition at line 81 of file space.c.

◆ spob_stack

Spob* spob_stack = NULL
static

Spob stack.

Definition at line 93 of file space.c.

◆ spobname_stack

char** spobname_stack = NULL
static

Spob name stack corresponding to system.

Definition at line 86 of file space.c.

◆ spobstack_changed

int spobstack_changed = 0
static

Whether or not the spob_stack was changed after loading.

Definition at line 99 of file space.c.

◆ systemname_stack

char** systemname_stack = NULL
static

System name stack corresponding to spob.

Definition at line 87 of file space.c.

◆ systems_loading

int systems_loading = 1
static

Systems are loading.

Definition at line 105 of file space.c.

◆ systems_stack

StarSystem* systems_stack = NULL

Star system stack.

Definition at line 92 of file space.c.

◆ systemstack_changed

int systemstack_changed = 0
static

Whether or not the systems_stack was changed after loading.

Definition at line 98 of file space.c.

◆ vspob_stack

VirtualSpob* vspob_stack = NULL
static

Virtual spob stack.

Definition at line 94 of file space.c.