naev 0.12.6
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 "ndata.h"
#include "nlua.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_system.h"
#include "nlua_tex.h"
#include "nlua_tk.h"
#include "nluadef.h"
#include "npc.h"
#include "player.h"
#include "player_fleet.h"
Include dependency graph for nlua_misn.c:

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_setDistance (lua_State *L)
 Sets the distance to the mission's goal. Used for sorting missions in the mission computer. Unused otherwise.
static int misn_setIllegal (lua_State *L)
 Marks whether or not a mission should be considered illegal in the current system. Used for filtering missions at the mission computer, unused otherwise.
static int misn_setFaction (lua_State *L)
 Sets the faction giver of the mission. Used mainly as metadata for sorting and organizing missions in the mission computer.
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.
static int misn_computerRefresh (lua_State *L)
 Refreshes the mission computer offerings.
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()

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 616 of file nlua_misn.c.

◆ misn_cargoAdd()

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 699 of file nlua_misn.c.

◆ misn_cargoJet()

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 755 of file nlua_misn.c.

◆ misn_cargoRm()

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 725 of file nlua_misn.c.

◆ misn_claim()

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 1036 of file nlua_misn.c.

◆ misn_computerRefresh()

int misn_computerRefresh ( lua_State * L)
static

Refreshes the mission computer offerings.

Do not use from a mission 'create' function.

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

Lua function: computerRefresh

Definition at line 1151 of file nlua_misn.c.

◆ misn_factions()

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 592 of file nlua_misn.c.

◆ misn_finish()

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 671 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()

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 390 of file nlua_misn.c.

◆ misn_markerMove()

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 445 of file nlua_misn.c.

◆ misn_markerRm()

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 496 of file nlua_misn.c.

◆ misn_npcAdd()

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 951 of file nlua_misn.c.

◆ misn_npcRm()

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 997 of file nlua_misn.c.

◆ misn_osdActive()

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 869 of file nlua_misn.c.

◆ misn_osdCreate()

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 790 of file nlua_misn.c.

◆ misn_osdDestroy()

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 849 of file nlua_misn.c.

◆ misn_osdGet()

int misn_osdGet ( lua_State * L)
static

Gets the current mission OSD information.

Lua return parameter: string Title of the OSD. Lua return parameter: table List of items in the OSD. Lua return 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 913 of file nlua_misn.c.

◆ misn_osdGetActiveItem()

int misn_osdGetActiveItem ( lua_State * L)
static

Gets the active OSD element.

Lua return parameter: number|nil The active element or nil if not active.

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

Lua function: osdGetActive

Definition at line 891 of file nlua_misn.c.

◆ misn_pushMissionData()

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

Definition at line 1085 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()

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_setDistance()

int misn_setDistance ( lua_State * L)
static

Sets the distance to the mission's goal. Used for sorting missions in the mission computer. Unused otherwise.

Lua function parameter: number Distance from the current player position.

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

Lua function: setDistance

Definition at line 334 of file nlua_misn.c.

◆ misn_setFaction()

int misn_setFaction ( lua_State * L)
static

Sets the faction giver of the mission. Used mainly as metadata for sorting and organizing missions in the mission computer.

Lua function parameter: faction Faction to set the mission to or nil to disable.

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

Lua function: setFaction

Definition at line 364 of file nlua_misn.c.

◆ misn_setIllegal()

int misn_setIllegal ( lua_State * L)
static

Marks whether or not a mission should be considered illegal in the current system. Used for filtering missions at the mission computer, unused otherwise.

Lua function parameter: boolean Whether or not the mission should be considered illegal.

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

Lua function: setIllegal

Definition at line 350 of file nlua_misn.c.

◆ misn_setNPC()

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 552 of file nlua_misn.c.

◆ misn_setReward()

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 307 of file nlua_misn.c.

◆ misn_setTitle()

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 },
{ "setDistance", misn_setDistance },
{ "setIllegal", misn_setIllegal },
{ "setFaction", misn_setFaction },
{ "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 },
{ "computerRefresh", misn_computerRefresh },
{ 0, 0 } }
static void misn_accept(unsigned int wid, const char *str)
Accepts the selected mission.
Definition land.c:661
static int misn_factions(lua_State *L)
Gets the factions the mission is available for.
Definition nlua_misn.c:592
static int misn_computerRefresh(lua_State *L)
Refreshes the mission computer offerings.
Definition nlua_misn.c:1151
static int misn_npcRm(lua_State *L)
Removes an NPC.
Definition nlua_misn.c:997
static int misn_osdGet(lua_State *L)
Gets the current mission OSD information.
Definition nlua_misn.c:913
static int misn_setDistance(lua_State *L)
Sets the distance to the mission's goal. Used for sorting missions in the mission computer....
Definition nlua_misn.c:334
static int misn_osdActive(lua_State *L)
Sets active in mission OSD.
Definition nlua_misn.c:869
static int misn_osdDestroy(lua_State *L)
Destroys the mission OSD.
Definition nlua_misn.c:849
static int misn_finish(lua_State *L)
Finishes the mission.
Definition nlua_misn.c:671
static int misn_markerMove(lua_State *L)
Moves a marker to a new system.
Definition nlua_misn.c:445
static int misn_osdCreate(lua_State *L)
Creates a mission OSD.
Definition nlua_misn.c:790
static int misn_cargoRm(lua_State *L)
Removes the mission cargo.
Definition nlua_misn.c:725
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:1036
static int misn_markerAdd(lua_State *L)
Adds a new marker.
Definition nlua_misn.c:390
static int misn_osdGetActiveItem(lua_State *L)
Gets the active OSD element.
Definition nlua_misn.c:891
static int misn_setFaction(lua_State *L)
Sets the faction giver of the mission. Used mainly as metadata for sorting and organizing missions in...
Definition nlua_misn.c:364
static int misn_setReward(lua_State *L)
Sets the current mission reward description.
Definition nlua_misn.c:307
static int misn_setIllegal(lua_State *L)
Marks whether or not a mission should be considered illegal in the current system....
Definition nlua_misn.c:350
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:755
static int misn_markerRm(lua_State *L)
Removes a mission system marker.
Definition nlua_misn.c:496
static int misn_npcAdd(lua_State *L)
Adds an NPC.
Definition nlua_misn.c:951
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:699
static int misn_setNPC(lua_State *L)
Sets the current mission NPC.
Definition nlua_misn.c:552

Mission Lua methods.

Definition at line 81 of file nlua_misn.c.