[Add] Aborting missions should also have the mission cargo jettisoned.

kthx.
This commit is contained in:
Allanis 2014-03-15 03:05:40 +00:00
parent e02f379050
commit 83fb0634cc
6 changed files with 56 additions and 8 deletions

View File

@ -202,3 +202,9 @@ function failed()
misn.finish(false)
end
function abort()
if misn_type ~= "People" then
player.jetCargo(carg_id)
end
end

View File

@ -141,3 +141,9 @@ function failed()
misn_finish(false)
end
function abort()
if misn_type ~= "People" then
player.jetCargo(carg_id)
end
end

View File

@ -569,16 +569,28 @@ static void mission_menu_abort(unsigned int wid, char* str) {
char* selected_misn;
int pos;
Mission* misn;
int ret;
selected_misn = toolkit_getList(wid, "lstMission");
if(dialogue_YesNo("Abort Mission",
"Are you sure you want to abort this mission?")) {
/* Get the mission. */
pos = toolkit_getListPos(wid, "lstMission");
misn = &player_missions[pos];
/* We run the "abort" function if it's found. */
ret = misn_tryRun(misn, "abort");
/* Now clean up mission. */
if(ret != 2) {
mission_cleanup(misn);
memmove(misn, &player_missions[pos+1],
sizeof(Mission) * (MISSION_MAX-pos-1));
}
/* Regenerate list. */
mission_menu_genList(wid, 0);
}
}

View File

@ -55,6 +55,7 @@ static int misn_delete = 0; /* If 1 delete current mission. */
static int var_add(misn_var* var);
static void var_free(misn_var* var);
static unsigned int hook_generic(lua_State* L, char* stack);
static int misn_runTopStack(Mission* misn, char* func);
/* Extern. */
int misn_run(Mission* misn, char* func);
int var_save(xmlTextWriterPtr writer);
@ -245,18 +246,41 @@ int lua_loadDiff(lua_State* L, int readonly) {
return 0;
}
/**
* @brief Tries to run a mission, but doesn't err if it fails.
* @param misn Mission that owns the function.
* @param func Name of the function to call.
* @return -1 on error, 1 on misn.finish() call, 2 if mission got deleted
* and 0 normally.
*/
int misn_tryRun(Mission* misn, char* func) {
/* Get the function to run. */
lua_getglobal(misn->L, func);
if(lua_isnil(misn->L, -1))
return 0;
return misn_runTopStack(misn, func);
}
/*
* Run a mission function.
* -1 on error, 1 on misn.finish() call and 0 normally.
* -1 on error, 1 on misn.finish() call, 2 if mission got deleted and 0 normally.
*/
int misn_run(Mission* misn, char* func) {
/* Run the function. */
lua_getglobal(misn->L, func);
return misn_runTopStack(misn, func);
}
/**
*
*/
static int misn_runTopStack(Mission* misn, char* func) {
int i, ret;
char* err;
cur_mission = misn;
misn_delete = 0;
lua_getglobal(misn->L, func);
if((ret = lua_pcall(misn->L, 0, 0, 0))) {
/* Did an oops. */
err = (lua_isstring(misn->L, -1)) ? (char*) lua_tostring(misn->L, -1) : NULL;

View File

@ -36,9 +36,6 @@ static int mission_nstack = 0;
extern StarSystem* systems_stack;
extern int systems_nstack;
/* Extern. */
extern int misn_run(Mission* misn, char* func);
/* Static. */
static unsigned int mission_genID(void);
static int mission_init(Mission* mission, MissionData* misn, int load);

View File

@ -94,3 +94,6 @@ void mission_cleanup(Mission* misn);
void missions_free(void);
void missions_cleanup(void);
int misn_tryRun(Mission* misn, char* func);
int misn_run(Mission* misn, char* func);