27#include "nlua_audio.h"
29#include "nlua_camera.h"
30#include "nlua_commodity.h"
31#include "nlua_faction.h"
33#include "nlua_music.h"
35#include "nlua_player.h"
36#include "nlua_system.h"
153 if (lua_isnil( naevL, -1 )) {
184 nlua_getenv( L, __NLUA_CURENV,
"__misn" );
185 misnptr = lua_touserdata( L, -1 );
186 misn = misnptr ? *misnptr : NULL;
198 misnptr = lua_newuserdata( naevL,
sizeof(
Mission*) );
200 nlua_setenv( naevL, misn->
env,
"__misn" );
203 nlua_getenv( naevL, misn->
env, func );
228 ret = nlua_pcall(env, nargs, 0);
231 nlua_getenv(naevL, env,
"__misn");
232 cur_mission = *(
Mission**) lua_touserdata(naevL, -1);
236 const char* err = (lua_isstring(naevL,-1)) ? lua_tostring(naevL,-1) : NULL;
237 if ((err==NULL) || (strcmp(err,NLUA_DONE)!=0)) {
238 WARN(_(
"Mission '%s' -> '%s': %s"),
239 cur_mission->
data->
name, func, (err) ? err : _(
"unknown error"));
248 nlua_getenv(naevL, env,
"__misn_delete");
249 misn_delete = lua_toboolean(naevL,-1);
265 else if (!isaccepted && cur_mission->
accepted)
279 const char *str = luaL_checkstring(L,1);
281 free(cur_mission->
title);
282 cur_mission->
title = strdup(str);
296 const char *str = luaL_checkstring(L,1);
298 free(cur_mission->
desc);
299 cur_mission->
desc = strdup(str);
312 free(cur_mission->
reward);
314 if (lua_isnumber(L,1)) {
315 char buf[ECON_CRED_STRLEN];
316 cur_mission->
reward_value =
CLAMP( CREDITS_MIN, CREDITS_MAX, (credits_t)round(luaL_checknumber(L,1)) );
318 cur_mission->
reward = strdup(buf);
321 str = luaL_checkstring(L,1);
322 cur_mission->
reward = strdup(str);
345 int id, issys, objid;
347 MissionMarkerType type;
359 stype = luaL_optstring( L, 2,
"high" );
362 if (strcmp(stype,
"computer")==0)
363 type = SPOBMARKER_COMPUTER;
364 else if (strcmp(stype,
"low")==0)
365 type = SPOBMARKER_LOW;
366 else if (strcmp(stype,
"high")==0)
367 type = SPOBMARKER_HIGH;
368 else if (strcmp(stype,
"plot")==0)
369 type = SPOBMARKER_PLOT;
371 NLUA_ERROR(L, _(
"Unknown marker type: %s"), stype);
377 type = mission_markerTypeSpobToSystem( type );
388 lua_pushnumber( L,
id );
403 int id, objid, issys;
408 id = luaL_checkinteger( L, 1 );
424 marker = &cur_mission->
markers[i];
428 if (marker == NULL) {
429 NLUA_ERROR( L, _(
"Mission does not have a marker with id '%d'"),
id );
435 marker->
type = mission_markerTypeSpobToSystem( marker->
type );
437 marker->
type = mission_markerTypeSystemToSpob( marker->
type );
438 marker->
objid = objid;
460 if (lua_isnoneornil(L,1)) {
467 id = luaL_checkinteger( L, 1 );
473 marker = &cur_mission->
markers[i];
477 if (marker == NULL) {
509 const char *name, *desc;
517 free(cur_mission->
npc);
518 cur_mission->
npc = NULL;
524 if (lua_gettop(L) == 0)
528 name = luaL_checkstring(L,1);
530 desc = luaL_checkstring(L,3);
533 cur_mission->
npc = strdup(name);
534 cur_mission->
npc_desc = strdup(desc);
556 lua_rawseti(L,-2,i+1);
571 Mission *new_misn, *cur_mission, **misnptr;
588 new_misn = calloc( 1,
sizeof(
Mission) );
595 NLUA_ERROR(L, _(
"Mission already accepted!"));
597 *new_misn = *cur_mission;
598 memset( cur_mission, 0,
sizeof(
Mission) );
599 cur_mission->
env = LUA_NOREF;
601 cur_mission = new_misn;
605 misnptr = lua_newuserdata( L,
sizeof(
Mission*) );
606 *misnptr = cur_mission;
607 nlua_setenv( L, cur_mission->
env,
"__misn" );
610 lua_pushboolean(L,!ret);
625 int b = lua_toboolean(L,1);
628 lua_pushboolean( L, 1 );
629 nlua_setenv( L, cur_mission->
env,
"__misn_delete" );
634 lua_pushstring(L, NLUA_DONE);
659 quantity = luaL_checkint(L,2);
667 lua_pushnumber(L, ret);
683 id = luaL_checklong(L,1);
687 lua_pushboolean(L,0);
696 lua_pushboolean(L,!ret);
712 id = luaL_checklong(L,1);
716 lua_pushboolean(L,0);
725 lua_pushboolean(L,!ret);
750 WARN(_(
"Can't create an OSD on an unaccepted mission!"));
755 title = luaL_checkstring(L,1);
756 luaL_checktype(L,2,LUA_TTABLE);
757 nitems = lua_objlen(L,2);
760 if (cur_mission->
osd != 0) {
761 osd_destroy( cur_mission->
osd );
762 cur_mission->
osd = 0;
766 items = calloc( nitems,
sizeof(
char *) );
769 for (
int i=0; i<nitems; i++) {
770 lua_pushnumber(L,i+1);
772 if (!lua_isstring(L,-1)) {
774 luaL_typerror(L, -1,
"string");
777 items[i] = strdup( lua_tostring(L, -1) );
782 cur_mission->
osd = osd_create( title, nitems, (
const char**) items,
787 for (
int i=0; i<nitems; i++)
803 if (cur_mission->
osd != 0) {
804 osd_destroy( cur_mission->
osd );
805 cur_mission->
osd = 0;
824 n = luaL_checkint(L,1);
829 if (cur_mission->
osd != 0)
830 osd_active( cur_mission->
osd, n );
844 char **items = osd_getItems(cur_mission->
osd);
845 int active = osd_getActive(cur_mission->
osd);
847 if (!items || active < 0) {
852 lua_pushstring(L, items[active]);
869 if (cur_mission->
osd == 0)
872 lua_pushstring( L, osd_getTitle(cur_mission->
osd) );
874 items = osd_getItems(cur_mission->
osd);
876 lua_pushstring( L, items[i] );
877 lua_rawseti( L, -2, i+1 );
879 lua_pushinteger( L, osd_getActive(cur_mission->
osd) );
901 const char *func, *name, *desc;
906 func = luaL_checkstring(L, 1);
907 name = luaL_checkstring(L, 2);
909 desc = luaL_checkstring(L, 4);
912 priority = luaL_optinteger(L,5,5);
913 if (!lua_isnoneornil(L,6))
921 id =
npc_add_mission( cur_mission->
id, func, name, priority, portrait, desc, bg );
928 lua_pushnumber( L,
id );
944 unsigned int id = luaL_checklong(L, 1);
952 NLUA_ERROR(L, _(
"Invalid NPC ID!"));
979 int onlytest, inclusive;
984 onlytest = lua_toboolean(L,2);
985 inclusive = lua_toboolean(L,3);
989 NLUA_ERROR(L, _(
"Mission trying to claim but already has."));
996 if (lua_istable(L,1)) {
999 while (lua_next(L, 1) != 0) {
1002 else if (lua_isstring(L,-1))
1009 else if (lua_isstring(L, 1))
1012 NLUA_INVALID_PARAMETER(L);
1024 lua_pushboolean(L,0);
1029 cur_mission->
claims = claim;
1031 lua_pushboolean(L,1);
Provides macros to work with dynamic arrays.
#define array_end(array)
Returns a pointer to the end of the reserved memory space.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_begin(array)
Returns a pointer to the beginning of the reserved memory space.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
int claim_test(const Claim_t *claim)
Tests to see if a system claim would have collisions.
void claim_destroy(Claim_t *claim)
Destroys a system claim.
int claim_addStr(Claim_t *claim, const char *str)
Adds a string claim to a claim.
int claim_addSys(Claim_t *claim, int ss_id)
Adds a claim to a system claim.
void claim_activate(Claim_t *claim)
Activates a claim on a system.
int claim_isNull(const Claim_t *claim)
See if a claim actually contains data.
Claim_t * claim_create(int exclusive)
Creates a system claim.
void bar_regen(void)
Regenerates the bar list.
Mission ** player_missions
void mission_cleanup(Mission *misn)
Cleans up a mission.
int mission_addMarker(Mission *misn, int id, int objid, MissionMarkerType type)
Adds a system marker to a mission.
int mission_linkCargo(Mission *misn, unsigned int cargo_id)
Links cargo to the mission for posterior cleanup.
void mission_sysMark(void)
Marks all active systems that need marking.
void mission_shift(int pos)
Puts the specified mission at the end of the player_missions array.
int mission_getID(const char *name)
Gets id from mission name.
int mission_unlinkCargo(Mission *misn, unsigned int cargo_id)
Unlinks cargo from the mission, removes it from the player.
Header file with generic functions and naev-specifics.
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
int nlua_loadBackground(nlua_env env)
Loads the graphics library.
int nlua_loadCamera(nlua_env env)
Loads the camera library.
Commodity * luaL_validcommodity(lua_State *L, int ind)
Makes sure the commodity is valid or raises a Lua error.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
int nlua_loadHook(nlua_env env)
Loads the hook Lua library.
static int misn_factions(lua_State *L)
Gets the factions the mission is available for.
Mission * misn_getFromLua(lua_State *L)
Gets the mission that's being currently run in Lua.
static const luaL_Reg misn_methods[]
static int misn_npcRm(lua_State *L)
Removes an NPC.
static int misn_osdGet(lua_State *L)
Gets the current mission OSD information.
static int misn_osdActive(lua_State *L)
Sets active in mission OSD.
int misn_tryRun(Mission *misn, const char *func)
Tries to run a mission, but doesn't err if it fails.
static int misn_osdDestroy(lua_State *L)
Destroys the mission OSD.
void misn_runStart(Mission *misn, const char *func)
Sets up the mission to run misn_runFunc.
static int misn_finish(lua_State *L)
Finishes the mission.
static int misn_markerMove(lua_State *L)
Moves a marker to a new system.
static int misn_osdCreate(lua_State *L)
Creates a mission OSD.
static int misn_cargoRm(lua_State *L)
Removes the mission cargo.
static int misn_setTitle(lua_State *L)
Mission Lua bindings.
static int misn_claim(lua_State *L)
Tries to claim systems or strings.
static int misn_markerAdd(lua_State *L)
Adds a new marker.
static int misn_osdGetActiveItem(lua_State *L)
Gets the active OSD element.
static int misn_setReward(lua_State *L)
Sets the current mission reward description.
static int misn_accept(lua_State *L)
Attempts to accept the mission.
static int misn_setDesc(lua_State *L)
Sets the current mission description.
int misn_runFunc(Mission *misn, const char *func, int nargs)
Runs a mission set up with misn_runStart.
static int misn_cargoJet(lua_State *L)
Jettisons the mission cargo.
static int misn_markerRm(lua_State *L)
Removes a mission system marker.
static int misn_npcAdd(lua_State *L)
Adds an NPC.
int nlua_loadMisn(nlua_env env)
Loads the mission Lua library.
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...
int misn_loadLibs(nlua_env env)
Registers all the mission libraries.
static int misn_setNPC(lua_State *L)
Sets the current mission NPC.
int misn_run(Mission *misn, const char *func)
Runs a mission function.
int nlua_loadMusic(nlua_env env)
Music Lua module.
LuaSpob luaL_checkspob(lua_State *L, int ind)
Gets spob at index raising an error if isn't a spob.
int lua_isspob(lua_State *L, int ind)
Checks to see if ind is a spob.
LuaSystem luaL_checksystem(lua_State *L, int ind)
Gets system at index raising an error if type doesn't match.
StarSystem * luaL_validsystem(lua_State *L, int ind)
Gets system (or system name) at index raising an error if type doesn't match.
LuaSystem lua_tosystem(lua_State *L, int ind)
Lua system module.
int lua_issystem(lua_State *L, int ind)
Checks to see if ind is a system.
glTexture * luaL_validtex(lua_State *L, int ind, const char *searchpath)
Gets texture directly or from a filename (string) at index or raises error if there is no texture at ...
int nlua_loadTex(nlua_env env)
Loads the texture library.
int nlua_loadTk(nlua_env env)
Loads the Toolkit Lua library.
unsigned int npc_add_mission(unsigned int mid, const char *func, const char *name, int priority, glTexture *portrait, const char *desc, glTexture *background)
Adds a mission NPC to the mission computer.
int npc_rm_mission(unsigned int id, unsigned int mid)
removes a mission NPC.
void gl_freeTexture(glTexture *texture)
Frees a texture.
unsigned int pilot_addMissionCargo(Pilot *pilot, const Commodity *cargo, int quantity)
Adds special mission cargo, can't sell it and such.
int pilot_rmMissionCargo(Pilot *pilot, unsigned int cargo_id, int jettison)
Removes special mission cargo based on id.
void player_missionFinished(int id)
Marks a mission as completed.
int system_index(const StarSystem *sys)
Gets the index of a star system.
Represents an active mission.
Abstraction for rendering sprite sheets.