naev 0.11.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_faction.h"
#include "nlua_misn.h"
#include "nlua_ship.h"
#include "nlua_shiplog.h"
#include "nluadef.h"
#include "npc.h"
#include "nstring.h"
#include "nxml.h"
#include "nxml_lua.h"
#include "player.h"
#include "player_fleet.h"
#include "rng.h"
#include "space.h"

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_compare (const void *arg1, const void *arg2)
 Compares to missions to see which has more priority.
 
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)
 
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.
 
Missionmissions_genList (int *n, 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 = NULL
 
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 41 of file mission.c.

Function Documentation

◆ 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 206 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 549 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 225 of file mission.c.

◆ mission_availabilityStr()

const char * mission_availabilityStr ( MissionAvailability loc)

Definition at line 398 of file mission.c.

◆ mission_cleanup()

void mission_cleanup ( Mission * misn)

Cleans up a mission.

Parameters
misnMission to clean up.

Definition at line 739 of file mission.c.

◆ mission_compare()

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

Compares to missions to see which has more priority.

Definition at line 877 of file mission.c.

◆ mission_freeData()

static void mission_freeData ( MissionData * mission)
static

Frees MissionData.

Parameters
missionMissionData to free.

Definition at line 814 of file mission.c.

◆ mission_genID()

static unsigned int mission_genID ( void )
static

Generates a new id for the mission.

Returns
New id for the mission.

Definition at line 84 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 116 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 100 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 656 of file mission.c.

◆ mission_init()

static 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 701 of file mission.c.

◆ mission_list()

const MissionData * mission_list ( void )

Returns all the missions.

Definition at line 214 of file mission.c.

◆ mission_loadFailed()

const char ** mission_loadFailed ( void )

Definition at line 501 of file mission.c.

◆ mission_location()

static 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 978 of file mission.c.

◆ mission_markerLoad()

static int mission_markerLoad ( Mission * misn,
xmlNodePtr node )
static

Loads a mission marker from xml.

Definition at line 509 of file mission.c.

◆ mission_markerTarget()

static const char * mission_markerTarget ( const MissionMarker * m)
static

Gets the name of the mission marker target.

Definition at line 420 of file mission.c.

◆ mission_markerTypeSpobToSystem()

MissionMarkerType mission_markerTypeSpobToSystem ( MissionMarkerType t)

Definition at line 439 of file mission.c.

◆ mission_markerTypeSystemToSpob()

MissionMarkerType mission_markerTypeSystemToSpob ( MissionMarkerType t)

Definition at line 461 of file mission.c.

◆ mission_matchFaction()

static 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 850 of file mission.c.

◆ mission_meetConditionals()

static int mission_meetConditionals ( const MissionData * misn)
static

Definition at line 234 of file mission.c.

◆ mission_meetReq()

static 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 288 of file mission.c.

◆ mission_parseFile()

static 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 1167 of file mission.c.

◆ mission_parseXML()

static 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 1002 of file mission.c.

◆ mission_reload()

int mission_reload ( const char * name)

Definition at line 1642 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 791 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 358 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 603 of file mission.c.

◆ mission_sysMark()

void mission_sysMark ( void )

Marks all active systems that need marking.

Definition at line 578 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 386 of file mission.c.

◆ mission_toLuaTable()

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

Definition at line 483 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 716 of file mission.c.

◆ missions_activateClaims()

void missions_activateClaims ( void )

Activates mission claims.

Definition at line 867 of file mission.c.

◆ missions_cleanup()

void missions_cleanup ( void )

Cleans up all the player's active missions.

Definition at line 1268 of file mission.c.

◆ missions_cmp()

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

Ordering function for missions.

Definition at line 1103 of file mission.c.

◆ missions_free()

void missions_free ( void )

Frees all the mission data.

Definition at line 1245 of file mission.c.

◆ missions_genList()

Mission * missions_genList ( int * n,
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
[out]nMissions created.
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 914 of file mission.c.

◆ missions_load()

int missions_load ( void )

Loads all the mission data.

Returns
0 on success.

Definition at line 1120 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 1477 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 1400 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 1430 of file mission.c.

◆ missions_parseActive()

static int missions_parseActive ( xmlNodePtr parent)
static

Parses the actual individual mission nodes.

Parameters
parentParent node to parse.
Returns
0 on success.

Definition at line 1504 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 321 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 1287 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 1385 of file mission.c.

Variable Documentation

◆ mission_id

unsigned int mission_id = 0
static

Mission ID generator.

Definition at line 46 of file mission.c.

◆ mission_stack

MissionData* mission_stack = NULL
static

Unmutable after creation

Definition at line 53 of file mission.c.

◆ player_missions

Mission** player_missions = NULL

Player's active missions.

Definition at line 47 of file mission.c.

◆ player_missions_failed

char** player_missions_failed = NULL
static

Name of missions that failed to load.

Definition at line 48 of file mission.c.