naev 0.12.5
space.c File Reference

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

#include "space.h"
#include "array.h"
#include "background.h"
#include "camera.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 "nlua.h"
#include "nlua_camera.h"
#include "nlua_gfx.h"
#include "nlua_pilot.h"
#include "nlua_spob.h"
#include "nlua_tex.h"
#include "nmath.h"
#include "nstring.h"
#include "ntime.h"
#include "ntracing.h"
#include "nxml.h"
#include "pilot.h"
#include "player.h"
#include "queue.h"
#include "rng.h"
#include "safelanes.h"
#include "sound.h"
#include "spfx.h"
#include "start.h"
#include "weapon.h"
Include dependency graph for space.c:

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 void spob_initDefaults (Spob *spob)
 Initializes a new spob to safe defaults.
static int spob_parse (Spob *spob, const char *filename, Commodity **stdList)
 Parses a spob from an xml node.
static int space_parseSaveNodes (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_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 void system_scheduler (double dt, int init)
 Controls fleet spawning.
static SystemPresencesystem_getFactionPresenceGrow (StarSystem *sys, int faction)
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)
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).
StarSystem * spob_getSystem (const Spob *spob)
 Gets the system a spob is in.
const char * spob_getSystemName (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_distress (Spob *spb, const Pilot *p, const Pilot *attacker)
 Spob is receiving distress from a pilot about an attacker.
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_addJump (StarSystem *sys, StarSystem *target)
 Adds a jump point between two star systems.
int system_rmJump (StarSystem *sys, StarSystem *target)
 Removes a jump point from a star system.
StarSystem * system_new (void)
 Creates a new star system.
const char * system_name (const StarSystem *sys)
const char * system_nameKnown (const StarSystem *sys)
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.
int space_playerSave (xmlTextWriterPtr writer)
 Saves what is needed to be saved for space.
int space_playerLoad (xmlNodePtr parent, const char *version)
 Loads player's space properties from an XML node.
void system_presenceAddSpob (StarSystem *sys, const SpobPresence *ap)
 Adds (or removes) some presence to a system.
SystemPresencesystem_getFactionPresence (StarSystem *sys, int faction)
const SystemPresencesystem_getFactionPresenceConst (const StarSystem *sys, int faction)
double system_getReputation (const StarSystem *sys, int faction)
 Gets the local reputation of the player in a system or returns 0.
double system_getReputationOrGlobal (const StarSystem *sys, int faction)
 Gets the local reputation of the player in a system or returns the global standing.
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 const double spob_aa_scale = 2.
static spob_lua_filespob_lua_stack = NULL
static char ** spobname_stack
static char ** systemname_stack
StarSystem * systems_stack = NULL
static Spobspob_stack = NULL
static VirtualSpobvspob_stack = NULL
static int systemstack_changed
static int spobstack_changed
static MapShader ** mapshaders = NULL
static int systems_loading = 1
StarSystem * cur_system = NULL
glTexturejumppoint_gfx = NULL
static glTexturejumpbuoy_gfx = NULL
static int space_fchg
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 71 of file space.c.

◆ FLAG_FACTIONSET

#define FLAG_FACTIONSET   ( 1 << 3 )

Set the faction value.

Definition at line 69 of file space.c.

◆ FLAG_INTERFERENCESET

#define FLAG_INTERFERENCESET   ( 1 << 1 )

Set the interference value.

Definition at line 67 of file space.c.

◆ FLAG_POSSET

#define FLAG_POSSET   ( 1 << 0 )

Set the position.

Definition at line 66 of file space.c.

◆ FLAG_SERVICESSET

#define FLAG_SERVICESSET   ( 1 << 2 )

Set the service value.

Definition at line 68 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 63 of file space.c.

◆ SPOB_GFX_EXTERIOR_PATH_W

#define SPOB_GFX_EXTERIOR_PATH_W   400

Spob exterior graphic width.

Definition at line 62 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 )
lua_State * naevL
Definition nlua.c:54

◆ XML_SPOB_TAG

#define XML_SPOB_TAG   "spob"

Individual spob xml tag.

Definition at line 59 of file space.c.

◆ XML_SYSTEM_TAG

#define XML_SYSTEM_TAG   "ssys"

Individual systems xml tag.

Definition at line 60 of file space.c.

Function Documentation

◆ 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 1279 of file space.c.

◆ jump_getSymbol()

const char * jump_getSymbol ( const JumpPoint * jp)

Gets the jump point symbol.

Definition at line 1317 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 1303 of file space.c.

◆ mapshader_get()

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 4807 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 4055 of file space.c.

◆ space_addMarkerSpob()

int space_addMarkerSpob ( int pntid,
MissionMarkerType type )
static

Definition at line 4026 of file space.c.

◆ space_addMarkerSystem()

int space_addMarkerSystem ( int sysid,
MissionMarkerType type )
static

Definition at line 3990 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 556 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 494 of file space.c.

◆ space_checkLand()

void space_checkLand ( void )

Handles landing if necessary.

Definition at line 1468 of file space.c.

◆ space_clearComputerMarkers()

void space_clearComputerMarkers ( void )

Clears all the system computer markers.

Definition at line 3984 of file space.c.

◆ space_clearKnown()

void space_clearKnown ( void )

Clears all system knowledge.

Definition at line 3945 of file space.c.

◆ space_clearMarkers()

void space_clearMarkers ( void )

Clears all system markers.

Definition at line 3964 of file space.c.

◆ space_exit()

void space_exit ( void )

Cleans up the system.

Definition at line 3824 of file space.c.

◆ space_factionChange()

void space_factionChange ( void )

Mark when a faction changes.

Definition at line 1460 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 623 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 666 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 2266 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 2281 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 529 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 1620 of file space.c.

◆ space_isSimulation()

int space_isSimulation ( void )

returns whether we're just simulating.

Definition at line 1601 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 479 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 3532 of file space.c.

◆ space_loadLua()

int space_loadLua ( void )

initializes the Lua for all the spobs.

Definition at line 3569 of file space.c.

◆ space_needsEffects()

int space_needsEffects ( void )

returns whether or not we're simulating with effects.

Definition at line 1609 of file space.c.

◆ space_parseSaveNodes()

int space_parseSaveNodes ( 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 4298 of file space.c.

◆ space_playerLoad()

int space_playerLoad ( xmlNodePtr parent,
const char * version )

Loads player's space properties from an XML node.

Parameters
parentParent node for space.
versionVersion of save game being loaded.
Returns
0 on success.

Definition at line 4221 of file space.c.

◆ space_playerSave()

int space_playerSave ( xmlTextWriterPtr writer)

Saves what is needed to be saved for space.

Parameters
writerXML writer to use.
Returns
0 on success.

Definition at line 4166 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 4743 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 4731 of file space.c.

◆ space_reconstructPresences()

void space_reconstructPresences ( void )

Reset the presence of all systems.

Definition at line 4620 of file space.c.

◆ space_render()

void space_render ( const double dt)

Renders the system.

Parameters
dtCurrent delta tick.

Definition at line 3666 of file space.c.

◆ space_renderJumpPoint()

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

Renders a jump point.

Definition at line 3737 of file space.c.

◆ space_renderOverlay()

void space_renderOverlay ( const double dt)

Renders the system overlay.

Parameters
dtCurrent delta tick.

Definition at line 3686 of file space.c.

◆ space_renderSpob()

void space_renderSpob ( const Spob * p)
static

Renders a spob.

Definition at line 3767 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 4141 of file space.c.

◆ space_rmMarkerSpob()

int space_rmMarkerSpob ( int pntid,
MissionMarkerType type )
static

Definition at line 4114 of file space.c.

◆ space_rmMarkerSystem()

int space_rmMarkerSystem ( int sysid,
MissionMarkerType type )
static

Definition at line 4075 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 869 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 911 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 889 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 1482 of file space.c.

◆ space_updateSpob()

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

Renders a spob.

Definition at line 3805 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 385 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 399 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 321 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 336 of file space.c.

◆ spob_cmp()

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

Comparison function for qsort'ing Spob by name.

Definition at line 1094 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 293 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 307 of file space.c.

◆ spob_distress()

void spob_distress ( Spob * spb,
const Pilot * p,
const Pilot * attacker )

Spob is receiving distress from a pilot about an attacker.

Definition at line 2081 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 1185 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 1199 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 1107 of file space.c.

◆ spob_getAll()

Spob * spob_getAll ( void )

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

Definition at line 1166 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 226 of file space.c.

◆ spob_getColour()

const glColour * spob_getColour ( const Spob * p)

Gets the spob colour.

Definition at line 2009 of file space.c.

◆ spob_getColourChar()

char spob_getColourChar ( const Spob * p)

Gets the spob colour char.

Definition at line 1966 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 1140 of file space.c.

◆ spob_getService()

int spob_getService ( const char * name)

Converts name to spob service flag.

Definition at line 197 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 169 of file space.c.

◆ spob_getSymbol()

const char * spob_getSymbol ( const Spob * p)

Gets the spob symbol.

Definition at line 1986 of file space.c.

◆ spob_getSystem()

StarSystem * spob_getSystem ( const Spob * spob)

Gets the system a spob is in.

Definition at line 1071 of file space.c.

◆ spob_getSystemName()

const char * spob_getSystemName ( 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 1082 of file space.c.

◆ spob_gfxLoad()

void spob_gfxLoad ( Spob * spob)

Loads a spob's graphics (and radius).

Definition at line 2206 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 1060 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 1158 of file space.c.

◆ spob_initDefaults()

void spob_initDefaults ( Spob * spob)
static

Initializes a new spob to safe defaults.

Definition at line 2334 of file space.c.

◆ spob_lua_cmp()

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

Definition at line 4835 of file space.c.

◆ spob_lua_free()

void spob_lua_free ( spob_lua_file * lf)
static

Definition at line 4901 of file space.c.

◆ spob_lua_get()

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

Definition at line 4842 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 2120 of file space.c.

◆ spob_luaInitMem()

void spob_luaInitMem ( const Spob * spob)

Initializes the memory fo a spob.

Definition at line 2109 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 1834 of file space.c.

◆ spob_new()

Spob * spob_new ( void )

Creates a new spob.

Definition at line 1804 of file space.c.

◆ spob_parse()

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 2365 of file space.c.

◆ spob_parsePresence()

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 2313 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 455 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 442 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 1211 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 372 of file space.c.

◆ spob_setKnown()

void spob_setKnown ( Spob * p)

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

Definition at line 1174 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 2031 of file space.c.

◆ spobs_load()

int spobs_load ( void )
static

Loads all the spobs in the game.

Returns
0 on success.

Definition at line 1846 of file space.c.

◆ spobs_render()

void spobs_render ( void )

Renders the current systems' spobs.

Definition at line 3709 of file space.c.

◆ sys_cmpSysFaction()

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

Compares two system presences.

Definition at line 3350 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 4597 of file space.c.

◆ system_addJump()

int system_addJump ( StarSystem * sys,
StarSystem * target )

Adds a jump point between two star systems.

Note that economy_execQueued should always be run after this.

Parameters
sysStar System to add jump point to.
targetTarget system to add a jump to.
Returns
0 on success.

Definition at line 2829 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 2668 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 2765 of file space.c.

◆ system_cmp()

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

Comparison function for qsort'ing StarSystem by name.

Definition at line 993 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 936 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 1007 of file space.c.

◆ system_getAll()

StarSystem * system_getAll ( void )

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

Definition at line 925 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 723 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 808 of file space.c.

◆ system_getFactionPresence()

SystemPresence * system_getFactionPresence ( StarSystem * sys,
int faction )

Definition at line 4479 of file space.c.

◆ system_getFactionPresenceConst()

const SystemPresence * system_getFactionPresenceConst ( const StarSystem * sys,
int faction )

Definition at line 4488 of file space.c.

◆ system_getFactionPresenceGrow()

SystemPresence * system_getFactionPresenceGrow ( StarSystem * sys,
int faction )
static

Definition at line 4463 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 1038 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 4537 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 4566 of file space.c.

◆ system_getReputation()

double system_getReputation ( const StarSystem * sys,
int faction )

Gets the local reputation of the player in a system or returns 0.

Definition at line 4502 of file space.c.

◆ system_getReputationOrGlobal()

double system_getReputationOrGlobal ( const StarSystem * sys,
int faction )

Gets the local reputation of the player in a system or returns the global standing.

Definition at line 4518 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 4660 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 1049 of file space.c.

◆ system_init()

void system_init ( StarSystem * sys)
static

Initializes a new star system with null memory.

Definition at line 2892 of file space.c.

◆ system_name()

const char * system_name ( const StarSystem * sys)

Definition at line 2941 of file space.c.

◆ system_nameKnown()

const char * system_nameKnown ( const StarSystem * sys)

Definition at line 2948 of file space.c.

◆ system_new()

StarSystem * system_new ( void )

Creates a new star system.

Definition at line 2908 of file space.c.

◆ system_parse()

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 3163 of file space.c.

◆ system_parseAsteroidExclusion()

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 3104 of file space.c.

◆ system_parseAsteroidField()

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 3029 of file space.c.

◆ system_parseJumpPoint()

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 3406 of file space.c.

◆ system_parseJumps()

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 3495 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 4339 of file space.c.

◆ system_reconstructJumps()

void system_reconstructJumps ( StarSystem * sys)

Reconstructs the jumps for a single system.

Definition at line 2958 of file space.c.

◆ system_rmCurrentPresence()

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

Removes active presence.

Definition at line 4678 of file space.c.

◆ system_rmJump()

int system_rmJump ( StarSystem * sys,
StarSystem * target )

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.
targetName of the jump target to remove.
Returns
0 on success.

Definition at line 2868 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 2709 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 2789 of file space.c.

◆ system_scheduler()

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 1330 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 948 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 3377 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 347 of file space.c.

◆ systems_load()

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 3587 of file space.c.

◆ systems_reconstructJumps()

void systems_reconstructJumps ( void )

Reconstructs the jumps.

Definition at line 2990 of file space.c.

◆ systems_reconstructSpobs()

void systems_reconstructSpobs ( void )

Updates the system spob pointers.

Definition at line 3009 of file space.c.

◆ virtualspob_cmp()

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

Comparison function for qsort'ing VirtuaSpob by name.

Definition at line 1251 of file space.c.

◆ virtualspob_get()

VirtualSpob * virtualspob_get ( const char * name)

Gets a virtual spob by matching name.

Definition at line 1261 of file space.c.

◆ virtualspob_getAll()

VirtualSpob * virtualspob_getAll ( void )

Gets all the virtual spobs.

Definition at line 1243 of file space.c.

◆ virtualspobs_load()

int virtualspobs_load ( void )
static

Loads all the virtual spobs.

Returns
0 on success.

Definition at line 1892 of file space.c.

Variable Documentation

◆ cur_system

StarSystem* cur_system = NULL

Current star system.

Definition at line 110 of file space.c.

◆ jumpbuoy_gfx

glTexture* jumpbuoy_gfx = NULL
static

Jump buoy graphics.

Definition at line 112 of file space.c.

◆ jumppoint_gfx

glTexture* jumppoint_gfx = NULL

Jump point graphics.

Definition at line 111 of file space.c.

◆ mapshaders

MapShader** mapshaders = NULL
static

Map shaders.

Definition at line 104 of file space.c.

◆ space_fchg

int space_fchg
static
Initial value:
=
0

Faction change counter, to avoid unnecessary calls.

Definition at line 113 of file space.c.

◆ space_landQueueSpob

Spob* space_landQueueSpob = NULL
static

Definition at line 117 of file space.c.

◆ space_simulating

int space_simulating = 0
static

Are we simulating space?

Definition at line 115 of file space.c.

◆ space_simulating_effects

int space_simulating_effects = 0
static

Are we doing special effects?

Definition at line 116 of file space.c.

◆ space_spawn

int space_spawn = 1

Spawn enabled by default.

Definition at line 122 of file space.c.

◆ spob_aa_scale

const double spob_aa_scale = 2.
static

Definition at line 73 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 95 of file space.c.

◆ spobname_stack

char** spobname_stack
static
Initial value:
=
NULL

Spob name stack corresponding to system.

Definition at line 86 of file space.c.

◆ spobstack_changed

int spobstack_changed
static
Initial value:
=
0

Whether or not the spob_stack was changed after loading.

Definition at line 102 of file space.c.

◆ systemname_stack

char** systemname_stack
static
Initial value:
=
NULL

System name stack corresponding to spob.

Definition at line 88 of file space.c.

◆ systems_loading

int systems_loading = 1
static

Systems are loading.

Definition at line 109 of file space.c.

◆ systems_stack

StarSystem* systems_stack = NULL

Star system stack.

Definition at line 94 of file space.c.

◆ systemstack_changed

int systemstack_changed
static
Initial value:
=
0

Whether or not the systems_stack was changed after loading.

Definition at line 100 of file space.c.

◆ vspob_stack

VirtualSpob* vspob_stack = NULL
static

Virtual spob stack.

Definition at line 96 of file space.c.