naev 0.10.4
Macros | Functions | Variables
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)    if (o) WARN( _("Mission '%s' missing/invalid '%s' element"), temp->name, s)
 

Functions

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

Variables

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

Detailed Description

Handles missions.

Definition in file mission.c.

Macro Definition Documentation

◆ 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 199 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 487 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 210 of file mission.c.

◆ mission_cleanup()

void mission_cleanup ( Mission misn)

Cleans up a mission.

Parameters
misnMission to clean up.

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

◆ mission_freeData()

static void mission_freeData ( MissionData mission)
static

Frees MissionData.

Parameters
missionMissionData to free.

Definition at line 752 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 82 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 114 of file mission.c.

◆ mission_getFromName()

const MissionData * mission_getFromName ( const char *  name)

Gets mission data from a name.

Definition at line 123 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 98 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 594 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 142 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 639 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 909 of file mission.c.

◆ mission_markerLoad()

static int mission_markerLoad ( Mission misn,
xmlNodePtr  node 
)
static

Loads a mission marker from xml.

Definition at line 447 of file mission.c.

◆ mission_markerTarget()

static const char * mission_markerTarget ( MissionMarker m)
static

Gets the name of the mission marker target.

Definition at line 363 of file mission.c.

◆ mission_markerTypeSpobToSystem()

MissionMarkerType mission_markerTypeSpobToSystem ( MissionMarkerType  t)

Definition at line 382 of file mission.c.

◆ mission_markerTypeSystemToSpob()

MissionMarkerType mission_markerTypeSystemToSpob ( MissionMarkerType  t)

Definition at line 404 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 782 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 228 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 1084 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 933 of file mission.c.

◆ mission_reload()

int mission_reload ( const char *  name)

Definition at line 1514 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 729 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 338 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 541 of file mission.c.

◆ mission_sysMark()

void mission_sysMark ( void  )

Marks all active systems that need marking.

Definition at line 516 of file mission.c.

◆ mission_toLuaTable()

void mission_toLuaTable ( lua_State *  L,
const MissionData m 
)

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

◆ missions_activateClaims()

void missions_activateClaims ( void  )

Activates mission claims.

Definition at line 799 of file mission.c.

◆ missions_cleanup()

void missions_cleanup ( void  )

Cleans up all the player's active missions.

Definition at line 1179 of file mission.c.

◆ missions_cmp()

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

Ordering function for missions.

Definition at line 1024 of file mission.c.

◆ missions_free()

void missions_free ( void  )

Frees all the mission data.

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

◆ missions_load()

int missions_load ( void  )

Loads all the mission data.

Returns
0 on success.

Definition at line 1041 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 1376 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 1299 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 1329 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 1403 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 301 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 1194 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 1284 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 52 of file mission.c.

◆ player_missions

Mission** player_missions = NULL

Player's active missions.

Definition at line 47 of file mission.c.