naev 0.11.5
nlua_misn.c File Reference

Handles the mission Lua bindings. More...

#include "nlua_misn.h"
#include "array.h"
#include "gui_osd.h"
#include "land.h"
#include "log.h"
#include "mission.h"
#include "music.h"
#include "ndata.h"
#include "nlua.h"
#include "nlua_audio.h"
#include "nlua_bkg.h"
#include "nlua_camera.h"
#include "nlua_commodity.h"
#include "nlua_faction.h"
#include "nlua_hook.h"
#include "nlua_music.h"
#include "nlua_spob.h"
#include "nlua_player.h"
#include "nlua_system.h"
#include "nlua_tex.h"
#include "nlua_tk.h"
#include "nluadef.h"
#include "npc.h"
#include "nstring.h"
#include "nxml.h"
#include "player.h"
#include "rng.h"
#include "shiplog.h"
#include "toolkit.h"

Go to the source code of this file.

Functions

static int misn_setTitle (lua_State *L)
 Mission Lua bindings.
 
static int misn_setDesc (lua_State *L)
 Sets the current mission description.
 
static int misn_setReward (lua_State *L)
 Sets the current mission reward description.
 
static int misn_setNPC (lua_State *L)
 Sets the current mission NPC.
 
static int misn_factions (lua_State *L)
 Gets the factions the mission is available for.
 
static int misn_accept (lua_State *L)
 Attempts to accept the mission.
 
static int misn_finish (lua_State *L)
 Finishes the mission.
 
static int misn_markerAdd (lua_State *L)
 Adds a new marker.
 
static int misn_markerMove (lua_State *L)
 Moves a marker to a new system.
 
static int misn_markerRm (lua_State *L)
 Removes a mission system marker.
 
static int misn_cargoAdd (lua_State *L)
 Adds some mission cargo to the player. They cannot sell it nor get rid of it unless they abandons the mission in which case it'll get eliminated.
 
static int misn_cargoRm (lua_State *L)
 Removes the mission cargo.
 
static int misn_cargoJet (lua_State *L)
 Jettisons the mission cargo.
 
static int misn_osdCreate (lua_State *L)
 Creates a mission OSD.
 
static int misn_osdDestroy (lua_State *L)
 Destroys the mission OSD.
 
static int misn_osdActive (lua_State *L)
 Sets active in mission OSD.
 
static int misn_osdGet (lua_State *L)
 Gets the current mission OSD information.
 
static int misn_osdGetActiveItem (lua_State *L)
 Gets the active OSD element.
 
static int misn_npcAdd (lua_State *L)
 Adds an NPC.
 
static int misn_npcRm (lua_State *L)
 Removes an NPC.
 
static int misn_claim (lua_State *L)
 Tries to claim systems or strings.
 
int misn_loadLibs (nlua_env env)
 Registers all the mission libraries.
 
int nlua_loadMisn (nlua_env env)
 Loads the mission Lua library.
 
int misn_tryRun (Mission *misn, const char *func)
 Tries to run a mission, but doesn't err if it fails.
 
int misn_run (Mission *misn, const char *func)
 Runs a mission function.
 
Missionmisn_getFromLua (lua_State *L)
 Gets the mission that's being currently run in Lua.
 
void misn_runStart (Mission *misn, const char *func)
 Sets up the mission to run misn_runFunc.
 
int misn_runFunc (const Mission *misn, const char *func, int nargs)
 Runs a mission set up with misn_runStart.
 
void misn_pushMissionData (lua_State *L, const MissionData *md)
 

Variables

static const luaL_Reg misn_methods []
 

Detailed Description

Handles the mission Lua bindings.

Definition in file nlua_misn.c.

Function Documentation

◆ misn_accept()

static int misn_accept ( lua_State * L)
static

Attempts to accept the mission.

Note: there is no limit on the maximum number of missions a player can have simultaneously.

Lua usage parameter: if not misn.accept() then return end Lua return parameter: boolean true if mission was properly accepted.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: accept

Definition at line 562 of file nlua_misn.c.

◆ misn_cargoAdd()

static int misn_cargoAdd ( lua_State * L)
static

Adds some mission cargo to the player. They cannot sell it nor get rid of it unless they abandons the mission in which case it'll get eliminated.

Lua function parameter: Commodity|string cargo Type of cargo to add, either as a Commodity object or as the raw (untranslated) name of a commodity. Lua function parameter: number quantity Quantity of cargo to add. Lua return parameter: number The id of the cargo which can be used in cargoRm.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: cargoAdd

Definition at line 645 of file nlua_misn.c.

◆ misn_cargoJet()

static int misn_cargoJet ( lua_State * L)
static

Jettisons the mission cargo.

Lua function parameter: number cargoid ID of the cargo to jettison. Lua return parameter: boolean true on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: cargoJet

Definition at line 700 of file nlua_misn.c.

◆ misn_cargoRm()

static int misn_cargoRm ( lua_State * L)
static

Removes the mission cargo.

Lua function parameter: number cargoid Identifier of the mission cargo. Lua return parameter: boolean true on success.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: cargoRm

Definition at line 671 of file nlua_misn.c.

◆ misn_claim()

static int misn_claim ( lua_State * L)
static

Tries to claim systems or strings.

Claiming systems and strings is a way to avoid mission collisions preemptively.

Note it does not actually perform the claim if it fails to claim. It also does not work more than once.

Lua usage parameter: if not misn.claim( { system.get("Gamma Polaris") } ) then misn.finish( false ) end Lua usage parameter: if not misn.claim( system.get("Gamma Polaris") ) then misn.finish( false ) end Lua usage parameter: if not misn.claim( 'some_string' ) then misn.finish( false ) end Lua usage parameter: if not misn.claim( { system.get("Gamma Polaris"), 'some_string' } ) then misn.finish( false ) end

Lua function parameter: System|String|{System,String...} params Table of systems/strings to claim or a single system/string. Lua function parameter:[opt=false] boolean inclusive Whether or not to allow the claim to include other inclusive claims. Multiple missions/events can inclusively claim the same system, but only one system can exclusively claim it. Lua return parameter: boolean true if was able to claim, false otherwise.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: claim

Definition at line 968 of file nlua_misn.c.

◆ misn_factions()

static int misn_factions ( lua_State * L)
static

Gets the factions the mission is available for.

Lua usage parameter: f = misn.factions() Lua return parameter: {Faction,...} A table containing the factions for whom the mission is available.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: factions

Definition at line 539 of file nlua_misn.c.

◆ misn_finish()

static int misn_finish ( lua_State * L)
static

Finishes the mission.

Lua function parameter:[opt] boolean properly If true and the mission is unique it marks the mission as completed. If false it deletes the mission but doesn't mark it as completed. If the parameter isn't passed it just ends the mission (without removing it from the player's list of active missions).

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: finish

Definition at line 617 of file nlua_misn.c.

◆ misn_getFromLua()

Mission * misn_getFromLua ( lua_State * L)

Gets the mission that's being currently run in Lua.

This should ONLY be called below an nlua_pcall, so __NLUA_CURENV is set

Definition at line 180 of file nlua_misn.c.

◆ misn_loadLibs()

int misn_loadLibs ( nlua_env env)

Registers all the mission libraries.

Parameters
envLua environment.
Returns
0 on success.

Definition at line 115 of file nlua_misn.c.

◆ misn_markerAdd()

static int misn_markerAdd ( lua_State * L)
static

Adds a new marker.

Lua usage parameter: my_marker = misn.markerAdd( system.get("Gamma Polaris"), "low" )

Valid marker types are:

  • "plot": Important plot marker.
  • "high": High importance mission marker (lower than plot).
  • "low": Low importance mission marker (lower than high).
  • "computer": Mission computer marker.

    Lua function parameter: System|Spob target System or spob to mark. Lua function parameter:[opt="high"] string type Colouring scheme to use. Lua return parameter: number A marker ID to be used with markerMove and markerRm.

    Parameters
    LLua State
    Returns
    Number of variables on the Lua State stack.

    Lua function: markerAdd

Definition at line 340 of file nlua_misn.c.

◆ misn_markerMove()

static int misn_markerMove ( lua_State * L)
static

Moves a marker to a new system.

Lua usage parameter: misn.markerMove( my_marker, system.get("Delta Pavonis") )

Lua function parameter: number id ID of the mission marker to move. Lua function parameter: System sys System to move the marker to.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: markerMove

Definition at line 396 of file nlua_misn.c.

◆ misn_markerRm()

static int misn_markerRm ( lua_State * L)
static

Removes a mission system marker.

Lua usage parameter: misn.markerRm( my_marker )

Lua function parameter:[opt] number id ID of the marker to remove. If no parameter is passed, all markers associated with the mission are removed.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: markerRm

Definition at line 446 of file nlua_misn.c.

◆ misn_npcAdd()

static int misn_npcAdd ( lua_State * L)
static

Adds an NPC.

Lua usage parameter: npc_id = misn.npcAdd( "my_func", "Mr. Test", "none.webp", "A test." ) – Creates an NPC.

Lua function parameter: string func Name of the function to run when approaching, gets passed the npc_id when called. Lua function parameter: string name Name of the NPC Lua function parameter: string portrait Portrait file name to use for the NPC (from GFX_PATH/portraits/). Lua function parameter: string desc Description associated to the NPC. Lua function parameter:[opt=5] number priority Optional priority argument (highest is 0, lowest is 10). Lua function parameter:[opt=nil] string background Background file name to use (from GFX_PATH/portraits/). Lua return parameter: number The ID of the NPC to pass to npcRm.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: npcAdd

Definition at line 891 of file nlua_misn.c.

◆ misn_npcRm()

static int misn_npcRm ( lua_State * L)
static

Removes an NPC.

Lua usage parameter: misn.npcRm( npc_id )

Lua function parameter: number id ID of the NPC to remove.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: npcRm

Definition at line 936 of file nlua_misn.c.

◆ misn_osdActive()

static int misn_osdActive ( lua_State * L)
static

Sets active in mission OSD.

Note
Uses Lua indexes, so 1 is first member, 2 is second and so on.

Lua function parameter: number n Element of the OSD to make active.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: osdActive

Definition at line 813 of file nlua_misn.c.

◆ misn_osdCreate()

static int misn_osdCreate ( lua_State * L)
static

Creates a mission OSD.

Note
You can index elements by using '\t' as first character of an element.
Destroys an osd if it already exists.

Lua usage parameter: misn.osdCreate( "My OSD", {"Element 1", "Element 2"})

Lua function parameter: string title Title to give the OSD. Lua function parameter: {string,...} list List of elements to put in the OSD.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: osdCreate

Definition at line 735 of file nlua_misn.c.

◆ misn_osdDestroy()

static int misn_osdDestroy ( lua_State * L)
static

Destroys the mission OSD.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: osdDestroy

Definition at line 793 of file nlua_misn.c.

◆ misn_osdGet()

static int misn_osdGet ( lua_State * L)
static

Gets the current mission OSD information.

Lua function parameter: string Title of the OSD. Lua function parameter: table List of items in the OSD. Lua function parameter: number ID of the current active OSD element.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: osdGet

Definition at line 858 of file nlua_misn.c.

◆ misn_osdGetActiveItem()

static int misn_osdGetActiveItem ( lua_State * L)
static

Gets the active OSD element.

Lua return parameter: string Th ename of the active element or nil if none.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: osdGetActive

Definition at line 835 of file nlua_misn.c.

◆ misn_pushMissionData()

void misn_pushMissionData ( lua_State * L,
const MissionData * md )

Definition at line 1018 of file nlua_misn.c.

◆ misn_run()

int misn_run ( Mission * misn,
const char * func )

Runs a mission function.

Parameters
misnMission that owns the function.
funcName of the function to call.
Returns
-1 on error, 1 on misn.finish() call, 2 if mission got deleted, 3 if the mission got accepted, and 0 normally.

Definition at line 169 of file nlua_misn.c.

◆ misn_runFunc()

int misn_runFunc ( const Mission * misn,
const char * func,
int nargs )

Runs a mission set up with misn_runStart.

Parameters
misnMission that owns the function.
funcName of the function to call.
nargsNumber of arguments to pass.
Returns
-1 on error, 1 on misn.finish() call, 2 if mission got deleted, 3 if the mission got accepted, and 0 normally.

Definition at line 215 of file nlua_misn.c.

◆ misn_runStart()

void misn_runStart ( Mission * misn,
const char * func )

Sets up the mission to run misn_runFunc.

Definition at line 195 of file nlua_misn.c.

◆ misn_setDesc()

static int misn_setDesc ( lua_State * L)
static

Sets the current mission description.

Also sets the mission OSD unless you explicitly force an OSD, however you can't specify bullet points or other fancy things like with the real OSD.

Lua function parameter: string desc Description to use for mission.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setDesc

Definition at line 292 of file nlua_misn.c.

◆ misn_setNPC()

static int misn_setNPC ( lua_State * L)
static

Sets the current mission NPC.

This is used in bar missions where you talk to a person. The portraits are the ones found in GFX_PATH/portraits. (For GFX_PATH/portraits/none.webp you would use "none.webp".)

Note that this NPC will disappear when either misn.accept() or misn.finish() is called.

Lua usage parameter: misn.setNPC( "Invisible Man", "none.webp", _("You see a levitating mug drain itself.") )

Lua function parameter: string name Name of the NPC. Lua function parameter: string portrait File name of the portrait to use for the NPC. Lua function parameter: string desc Description of the NPC to use.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setNPC

Definition at line 500 of file nlua_misn.c.

◆ misn_setReward()

static int misn_setReward ( lua_State * L)
static

Sets the current mission reward description.

Lua function parameter: string|number reward Description of the reward to use. Can pass a number to signify a monetary reward, and allow for sorting.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setReward

Definition at line 306 of file nlua_misn.c.

◆ misn_setTitle()

static int misn_setTitle ( lua_State * L)
static

Mission Lua bindings.

Sets the current mission title.

An example would be:

misn.setNPC( "Keer", "empire/unique/keer.webp", _("You see here Commodore Keer.") )

Lua module: misn

Lua function parameter: string title Title to use for mission.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setTitle

Definition at line 275 of file nlua_misn.c.

◆ misn_tryRun()

int misn_tryRun ( Mission * misn,
const char * func )

Tries to run a mission, but doesn't err if it fails.

Parameters
misnMission that owns the function.
funcName of the function to call.
Returns
-1 on error, 1 on misn.finish() call, 2 if mission got deleted, 3 if the mission got accepted, and 0 normally.

Definition at line 148 of file nlua_misn.c.

◆ nlua_loadMisn()

int nlua_loadMisn ( nlua_env env)

Loads the mission Lua library.

Parameters
envLua environment.

Definition at line 134 of file nlua_misn.c.

Variable Documentation

◆ misn_methods

const luaL_Reg misn_methods[]
static
Initial value:
= {
{ "setTitle", misn_setTitle },
{ "setDesc", misn_setDesc },
{ "setReward", misn_setReward },
{ "setNPC", misn_setNPC },
{ "factions", misn_factions },
{ "accept", misn_accept },
{ "finish", misn_finish },
{ "markerAdd", misn_markerAdd },
{ "markerMove", misn_markerMove },
{ "markerRm", misn_markerRm },
{ "cargoAdd", misn_cargoAdd },
{ "cargoRm", misn_cargoRm },
{ "cargoJet", misn_cargoJet },
{ "osdCreate", misn_osdCreate },
{ "osdDestroy", misn_osdDestroy },
{ "osdActive", misn_osdActive },
{ "osdGet", misn_osdGet },
{ "osdGetActive", misn_osdGetActiveItem },
{ "npcAdd", misn_npcAdd },
{ "npcRm", misn_npcRm },
{ "claim", misn_claim },
{0,0}
}
static int misn_factions(lua_State *L)
Gets the factions the mission is available for.
Definition nlua_misn.c:539
static int misn_npcRm(lua_State *L)
Removes an NPC.
Definition nlua_misn.c:936
static int misn_osdGet(lua_State *L)
Gets the current mission OSD information.
Definition nlua_misn.c:858
static int misn_osdActive(lua_State *L)
Sets active in mission OSD.
Definition nlua_misn.c:813
static int misn_osdDestroy(lua_State *L)
Destroys the mission OSD.
Definition nlua_misn.c:793
static int misn_finish(lua_State *L)
Finishes the mission.
Definition nlua_misn.c:617
static int misn_markerMove(lua_State *L)
Moves a marker to a new system.
Definition nlua_misn.c:396
static int misn_osdCreate(lua_State *L)
Creates a mission OSD.
Definition nlua_misn.c:735
static int misn_cargoRm(lua_State *L)
Removes the mission cargo.
Definition nlua_misn.c:671
static int misn_setTitle(lua_State *L)
Mission Lua bindings.
Definition nlua_misn.c:275
static int misn_claim(lua_State *L)
Tries to claim systems or strings.
Definition nlua_misn.c:968
static int misn_markerAdd(lua_State *L)
Adds a new marker.
Definition nlua_misn.c:340
static int misn_osdGetActiveItem(lua_State *L)
Gets the active OSD element.
Definition nlua_misn.c:835
static int misn_setReward(lua_State *L)
Sets the current mission reward description.
Definition nlua_misn.c:306
static int misn_accept(lua_State *L)
Attempts to accept the mission.
Definition nlua_misn.c:562
static int misn_setDesc(lua_State *L)
Sets the current mission description.
Definition nlua_misn.c:292
static int misn_cargoJet(lua_State *L)
Jettisons the mission cargo.
Definition nlua_misn.c:700
static int misn_markerRm(lua_State *L)
Removes a mission system marker.
Definition nlua_misn.c:446
static int misn_npcAdd(lua_State *L)
Adds an NPC.
Definition nlua_misn.c:891
static int misn_cargoAdd(lua_State *L)
Adds some mission cargo to the player. They cannot sell it nor get rid of it unless they abandons the...
Definition nlua_misn.c:645
static int misn_setNPC(lua_State *L)
Sets the current mission NPC.
Definition nlua_misn.c:500

Mission Lua methods.

Definition at line 84 of file nlua_misn.c.