naev 0.12.5
mission.c File Reference

Handles missions. More...

#include "mission.h"
#include "array.h"
#include "cond.h"
#include "faction.h"
#include "gui_osd.h"
#include "hook.h"
#include "land.h"
#include "log.h"
#include "ndata.h"
#include "nlua.h"
#include "nlua_misn.h"
#include "npc.h"
#include "nstring.h"
#include "ntracing.h"
#include "nxml.h"
#include "nxml_lua.h"
#include "player.h"
#include "player_fleet.h"
#include "rng.h"
#include "space.h"
Include dependency graph for mission.c:

Go to the source code of this file.

Macros

#define XML_MISSION_TAG   "mission"
#define MELEMENT(o, s)

Functions

static unsigned int mission_genID (void)
 Generates a new id for the mission.
static int mission_init (Mission *mission, const MissionData *misn, int genid, int create, unsigned int *id)
 Initializes a mission.
static void mission_freeData (MissionData *mission)
 Frees MissionData.
static int mission_meetConditionals (const MissionData *misn)
static int mission_meetReq (const MissionData *misn, int faction, const Spob *pnt, const StarSystem *sys)
 Checks to see if a mission meets the requirements.
static int mission_matchFaction (const MissionData *misn, int faction)
 Checks to see if a mission matches the faction requirements.
static int mission_location (const char *loc)
 Gets location based on a human readable string.
static int missions_cmp (const void *a, const void *b)
 Ordering function for missions.
static int mission_parseFile (const char *file, MissionData *temp)
 Parses a single mission.
static int mission_parseXML (MissionData *temp, const xmlNodePtr parent)
 Parses a node of a mission.
static int missions_parseActive (xmlNodePtr parent)
 Parses the actual individual mission nodes.
static const char * mission_markerTarget (const MissionMarker *m)
 Gets the name of the mission marker target.
static int mission_markerLoad (Mission *misn, xmlNodePtr node)
 Loads a mission marker from xml.
int mission_getID (const char *name)
 Gets id from mission name.
const MissionDatamission_get (int id)
 Gets a MissionData based on ID.
const MissionDatamission_getFromName (const char *name)
 Gets mission data from a name.
int mission_accept (Mission *mission)
 Small wrapper for misn_run.
const MissionDatamission_list (void)
 Returns all the missions.
int mission_alreadyRunning (const MissionData *misn)
 Checks to see if mission is already running.
void missions_run (MissionAvailability loc, int faction, const Spob *pnt, const StarSystem *sys)
 Runs missions matching location, all Lua side and one-shot.
int mission_start (const char *name, unsigned int *id)
 Starts a mission.
int mission_test (const char *name)
 Tests the conditionals of a mission.
const char * mission_availabilityStr (MissionAvailability loc)
MissionMarkerType mission_markerTypeSpobToSystem (MissionMarkerType t)
MissionMarkerType mission_markerTypeSystemToSpob (MissionMarkerType t)
void mission_toLuaTable (lua_State *L, const MissionData *m)
const char ** mission_loadFailed (void)
void misn_osdSetHide (Mission *misn, int hide)
 Sets the hide state of the mission OSD.
int misn_osdGetHide (const Mission *misn)
void misn_osdSetPriority (Mission *misn, int priority)
int misn_osdGetPriority (const Mission *misn)
int mission_addMarker (Mission *misn, int id, int objid, MissionMarkerType type)
 Adds a system marker to a mission.
void mission_sysMark (void)
 Marks all active systems that need marking.
const StarSystem * mission_sysComputerMark (const Mission *misn)
 Marks the system of the computer mission to reflect where it will head to.
const StarSystem * mission_getSystemMarker (const Mission *misn)
 Gets the first system that has been marked by a mission.
int mission_linkCargo (Mission *misn, unsigned int cargo_id)
 Links cargo to the mission for posterior cleanup.
int mission_unlinkCargo (Mission *misn, unsigned int cargo_id)
 Unlinks cargo from the mission, removes it from the player.
void mission_cleanup (Mission *misn)
 Cleans up a mission.
void mission_shift (int pos)
 Puts the specified mission at the end of the player_missions array.
void missions_activateClaims (void)
 Activates mission claims.
int mission_compare (const void *arg1, const void *arg2)
 Compares to missions to see which has more priority.
Missionmissions_genList (int faction, const Spob *pnt, const StarSystem *sys, MissionAvailability loc)
 Generates a mission list. This runs create() so won't work with all missions.
int missions_load (void)
 Loads all the mission data.
void missions_free (void)
 Frees all the mission data.
void missions_cleanup (void)
 Cleans up all the player's active missions.
int missions_saveActive (xmlTextWriterPtr writer)
 Saves the player's active missions.
int missions_saveTempCommodity (xmlTextWriterPtr writer, const Commodity *c)
 Saves a temporary commodity's defintion into the current node.
int missions_loadCommodity (xmlNodePtr parent)
 Loads the player's special mission commodities.
Commoditymissions_loadTempCommodity (xmlNodePtr cur)
 Loads a temporary commodity.
int missions_loadActive (xmlNodePtr parent)
 Loads the player's active missions from a save.
int mission_reload (const char *name)

Variables

static unsigned int mission_id = 0
Mission ** player_missions = NULL
static char ** player_missions_failed
static MissionDatamission_stack = NULL

Detailed Description

Handles missions.

Definition in file mission.c.

Macro Definition Documentation

◆ MELEMENT

#define MELEMENT ( o,
s )
Value:
if ( o ) \
WARN( _( "Mission '%s' missing/invalid '%s' element" ), temp->name, s )

◆ XML_MISSION_TAG

#define XML_MISSION_TAG   "mission"

XML mission tag.

Definition at line 39 of file mission.c.

Function Documentation

◆ misn_osdGetHide()

int misn_osdGetHide ( const Mission * misn)

Definition at line 527 of file mission.c.

◆ misn_osdGetPriority()

int misn_osdGetPriority ( const Mission * misn)

Definition at line 536 of file mission.c.

◆ misn_osdSetHide()

void misn_osdSetHide ( Mission * misn,
int hide )

Sets the hide state of the mission OSD.

Definition at line 521 of file mission.c.

◆ misn_osdSetPriority()

void misn_osdSetPriority ( Mission * misn,
int priority )

Definition at line 531 of file mission.c.

◆ mission_accept()

int mission_accept ( Mission * mission)

Small wrapper for misn_run.

Parameters
missionMission to accept.
Returns
-1 on error, 1 on misn.finish() call, 2 if mission got deleted, 3 if the mission got accepted, and 0 normally.
See also
misn_run

Definition at line 210 of file mission.c.

◆ mission_addMarker()

int mission_addMarker ( Mission * misn,
int id,
int objid,
MissionMarkerType type )

Adds a system marker to a mission.

Definition at line 586 of file mission.c.

◆ mission_alreadyRunning()

int mission_alreadyRunning ( const MissionData * misn)

Checks to see if mission is already running.

Parameters
misnMission to check if is already running.
Returns
Number of instances if already running, 0 if isn't.

Definition at line 229 of file mission.c.

◆ mission_availabilityStr()

const char * mission_availabilityStr ( MissionAvailability loc)

Definition at line 410 of file mission.c.

◆ mission_cleanup()

void mission_cleanup ( Mission * misn)

Cleans up a mission.

Parameters
misnMission to clean up.

Definition at line 779 of file mission.c.

◆ mission_compare()

int mission_compare ( const void * arg1,
const void * arg2 )

Compares to missions to see which has more priority.

Definition at line 921 of file mission.c.

◆ mission_freeData()

void mission_freeData ( MissionData * mission)
static

Frees MissionData.

Parameters
missionMissionData to free.

Definition at line 858 of file mission.c.

◆ mission_genID()

unsigned int mission_genID ( void )
static

Generates a new id for the mission.

Returns
New id for the mission.

Definition at line 83 of file mission.c.

◆ mission_get()

const MissionData * mission_get ( int id)

Gets a MissionData based on ID.

Parameters
idID to match.
Returns
MissonData matching ID.

Definition at line 115 of file mission.c.

◆ mission_getFromName()

const MissionData * mission_getFromName ( const char * name)

Gets mission data from a name.

Definition at line 125 of file mission.c.

◆ mission_getID()

int mission_getID ( const char * name)

Gets id from mission name.

Parameters
nameName to match.
Returns
id of the matching mission.

Definition at line 99 of file mission.c.

◆ mission_getSystemMarker()

const StarSystem * mission_getSystemMarker ( const Mission * misn)

Gets the first system that has been marked by a mission.

Parameters
misnMission to get marked system of.
Returns
First marked system.

Definition at line 695 of file mission.c.

◆ mission_init()

int mission_init ( Mission * mission,
const MissionData * misn,
int genid,
int create,
unsigned int * id )
static

Initializes a mission.

Parameters
missionMission to initialize.
misnData to use.
genid1 if should generate id, 0 otherwise.
create1 if should run create function, 0 otherwise.
[out]idID of the newly created mission.
Returns
0 on success.

Definition at line 144 of file mission.c.

◆ mission_linkCargo()

int mission_linkCargo ( Mission * misn,
unsigned int cargo_id )

Links cargo to the mission for posterior cleanup.

Parameters
misnMission to link cargo to.
cargo_idID of cargo to link.
Returns
0 on success.

Definition at line 741 of file mission.c.

◆ mission_list()

const MissionData * mission_list ( void )

Returns all the missions.

Definition at line 218 of file mission.c.

◆ mission_loadFailed()

const char ** mission_loadFailed ( void )

Definition at line 513 of file mission.c.

◆ mission_location()

int mission_location ( const char * loc)
static

Gets location based on a human readable string.

Parameters
locString to get the location of.
Returns
Location matching loc.

Definition at line 1008 of file mission.c.

◆ mission_markerLoad()

int mission_markerLoad ( Mission * misn,
xmlNodePtr node )
static

Loads a mission marker from xml.

Definition at line 544 of file mission.c.

◆ mission_markerTarget()

const char * mission_markerTarget ( const MissionMarker * m)
static

Gets the name of the mission marker target.

Definition at line 432 of file mission.c.

◆ mission_markerTypeSpobToSystem()

MissionMarkerType mission_markerTypeSpobToSystem ( MissionMarkerType t)

Definition at line 451 of file mission.c.

◆ mission_markerTypeSystemToSpob()

MissionMarkerType mission_markerTypeSystemToSpob ( MissionMarkerType t)

Definition at line 473 of file mission.c.

◆ mission_matchFaction()

int mission_matchFaction ( const MissionData * misn,
int faction )
static

Checks to see if a mission matches the faction requirements.

Parameters
misnMission to check.
factionFaction to check against.
Returns
1 if it meets the faction requirement, 0 if it doesn't.

Definition at line 894 of file mission.c.

◆ mission_meetConditionals()

int mission_meetConditionals ( const MissionData * misn)
static

Definition at line 238 of file mission.c.

◆ mission_meetReq()

int mission_meetReq ( const MissionData * misn,
int faction,
const Spob * pnt,
const StarSystem * sys )
static

Checks to see if a mission meets the requirements.

Parameters
misnMission to check.
factionFaction of the current spob.
pntSpob to run on.
sysSystem to run on.
Returns
1 if requirements are met, 0 if they aren't.

Definition at line 293 of file mission.c.

◆ mission_parseFile()

int mission_parseFile ( const char * file,
MissionData * temp )
static

Parses a single mission.

Parameters
fileSource file path.
tempData to load into, or NULL for initial load.

Definition at line 1221 of file mission.c.

◆ mission_parseXML()

int mission_parseXML ( MissionData * temp,
const xmlNodePtr parent )
static

Parses a node of a mission.

Parameters
tempData to load into.
parentNode containing the mission.
Returns
0 on success.

Definition at line 1032 of file mission.c.

◆ mission_reload()

int mission_reload ( const char * name)

Definition at line 1706 of file mission.c.

◆ mission_shift()

void mission_shift ( int pos)

Puts the specified mission at the end of the player_missions array.

Parameters
posMission's position within player_missions

Definition at line 835 of file mission.c.

◆ mission_start()

int mission_start ( const char * name,
unsigned int * id )

Starts a mission.

Mission must still call misn.accept() to actually get added to the player's active missions.

Parameters
nameName of the mission to start.
[out]idID of the newly created mission.
Returns
0 on success, >0 on forced exit (misn.finish), <0 on error.

Definition at line 365 of file mission.c.

◆ mission_sysComputerMark()

const StarSystem * mission_sysComputerMark ( const Mission * misn)

Marks the system of the computer mission to reflect where it will head to.

Does not modify other markers.

Parameters
misnMission to mark.

Definition at line 642 of file mission.c.

◆ mission_sysMark()

void mission_sysMark ( void )

Marks all active systems that need marking.

Definition at line 616 of file mission.c.

◆ mission_test()

int mission_test ( const char * name)

Tests the conditionals of a mission.

Parameters
nameName of the mission to test.
Returns
-1 on error, 0 on mission conditionals passing, >0 otherwise.

Definition at line 398 of file mission.c.

◆ mission_toLuaTable()

void mission_toLuaTable ( lua_State * L,
const MissionData * m )

Definition at line 495 of file mission.c.

◆ mission_unlinkCargo()

int mission_unlinkCargo ( Mission * misn,
unsigned int cargo_id )

Unlinks cargo from the mission, removes it from the player.

Parameters
misnMission to unlink cargo from.
cargo_idID of cargo to unlink.
Returns
returns 0 on success.

Definition at line 756 of file mission.c.

◆ missions_activateClaims()

void missions_activateClaims ( void )

Activates mission claims.

Definition at line 911 of file mission.c.

◆ missions_cleanup()

void missions_cleanup ( void )

Cleans up all the player's active missions.

Definition at line 1327 of file mission.c.

◆ missions_cmp()

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

Ordering function for missions.

Definition at line 1151 of file mission.c.

◆ missions_free()

void missions_free ( void )

Frees all the mission data.

Definition at line 1304 of file mission.c.

◆ missions_genList()

Mission * missions_genList ( int faction,
const Spob * pnt,
const StarSystem * sys,
MissionAvailability loc )

Generates a mission list. This runs create() so won't work with all missions.

Parameters
factionFaction of the spob.
pntSpob to run on.
sysSystem to run on.
locLocation
Returns
The stack of Missions created with n members.

Definition at line 954 of file mission.c.

◆ missions_load()

int missions_load ( void )

Loads all the mission data.

Returns
0 on success.

Definition at line 1168 of file mission.c.

◆ missions_loadActive()

int missions_loadActive ( xmlNodePtr parent)

Loads the player's active missions from a save.

Parameters
parentNode containing the player's active missions.
Returns
0 on success.

Definition at line 1535 of file mission.c.

◆ missions_loadCommodity()

int missions_loadCommodity ( xmlNodePtr parent)

Loads the player's special mission commodities.

Parameters
parentNode containing the player's special mission cargo.
Returns
0 on success.

Definition at line 1459 of file mission.c.

◆ missions_loadTempCommodity()

Commodity * missions_loadTempCommodity ( xmlNodePtr cur)

Loads a temporary commodity.

Parameters
curNode defining the commodity.
Returns
The temporary commodity, or NULL on failure.

Definition at line 1488 of file mission.c.

◆ missions_parseActive()

int missions_parseActive ( xmlNodePtr parent)
static

Parses the actual individual mission nodes.

Parameters
parentParent node to parse.
Returns
0 on success.

Definition at line 1562 of file mission.c.

◆ missions_run()

void missions_run ( MissionAvailability loc,
int faction,
const Spob * pnt,
const StarSystem * sys )

Runs missions matching location, all Lua side and one-shot.

Parameters
locLocation to match.
factionFaction of the spob.
pntSpob to run on.
sysSystem to run on.

Definition at line 326 of file mission.c.

◆ missions_saveActive()

int missions_saveActive ( xmlTextWriterPtr writer)

Saves the player's active missions.

Parameters
writerXML Write to use to save missions.
Returns
0 on success.

Definition at line 1348 of file mission.c.

◆ missions_saveTempCommodity()

int missions_saveTempCommodity ( xmlTextWriterPtr writer,
const Commodity * c )

Saves a temporary commodity's defintion into the current node.

Parameters
writerXML Write to use to save missions.
cCommodity to save.
Returns
0 on success.

Definition at line 1444 of file mission.c.

Variable Documentation

◆ mission_id

unsigned int mission_id = 0
static

Mission ID generator.

Definition at line 44 of file mission.c.

◆ mission_stack

MissionData* mission_stack = NULL
static

Unmutable after creation

Definition at line 52 of file mission.c.

◆ player_missions

Mission** player_missions = NULL

Player's active missions.

Definition at line 45 of file mission.c.

◆ player_missions_failed

char** player_missions_failed
static
Initial value:
=
NULL

Name of missions that failed to load.

Definition at line 46 of file mission.c.