[Fix] Annoying ass bug with mission disappearing when no cargo space left.
This commit is contained in:
parent
95ee7852de
commit
bc935960f8
@ -108,6 +108,7 @@ end
|
||||
function accept()
|
||||
if player.freeCargo() < carg_mass then
|
||||
tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo()))
|
||||
misn.finish()
|
||||
|
||||
elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
|
||||
carg_id = player.addCargo(carg_type, carg_mass)
|
||||
@ -120,6 +121,7 @@ function accept()
|
||||
end
|
||||
else
|
||||
tk.msg(toomany_title, toomany_msg)
|
||||
misn.finish()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -72,6 +72,7 @@ end
|
||||
function accept()
|
||||
if player.freeCargo() < carg_mass then
|
||||
tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo()))
|
||||
misn.finish()
|
||||
elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
|
||||
carg_id = player.addCargo(carg_type, carg_mass)
|
||||
tk.msg(accept_title, string.format( accept_msg, carg_mass, carg_type))
|
||||
@ -79,6 +80,7 @@ function accept()
|
||||
hook.time("timeup")
|
||||
else
|
||||
tk.msg(toomany_title, toomany_msg)
|
||||
misn.finish()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,7 @@ static int hook_run(Hook* hook) {
|
||||
}
|
||||
misn = &player_missions[i];
|
||||
|
||||
if(misn_run(misn, hook->func))
|
||||
if(misn_run(misn, hook->func) < 0)
|
||||
// Error has accured.
|
||||
WARN("Hook [%s] '%d' -> '%s' failed", hook->stack,
|
||||
hook->id, hook->func);
|
||||
|
@ -855,13 +855,15 @@ static void misn_accept(char* str) {
|
||||
"Are you sure you want to accept this mission?")) {
|
||||
pos = toolkit_getListPos(secondary_wid, "lstMission");
|
||||
misn = &mission_computer[pos];
|
||||
mission_accept(misn);
|
||||
if(mission_accept(misn)) {
|
||||
// Success is accepting the mission.
|
||||
memmove(misn, &mission_computer[pos+1],
|
||||
sizeof(Mission) * (mission_ncomputer-pos-1));
|
||||
mission_ncomputer--;
|
||||
misn_genList(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void misn_genList(int first) {
|
||||
int i, j;
|
||||
|
@ -188,6 +188,8 @@ int misn_loadLibs(lua_State* L) {
|
||||
}
|
||||
|
||||
// Run a mission function.
|
||||
//
|
||||
// -1 on error, 1 on misn.finish() call and 0 normally.
|
||||
int misn_run(Mission* misn, char* func) {
|
||||
int i, ret;
|
||||
char* err;
|
||||
@ -199,10 +201,10 @@ int misn_run(Mission* misn, char* 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;
|
||||
if(strcmp(err, "Mission Finished"))
|
||||
if(strcmp(err, "Mission Done"))
|
||||
WARN("Mission '%s' -> '%s' : %s",
|
||||
cur_mission->data->name, func, (err) ? err : "Unknown Error");
|
||||
else ret = 0;
|
||||
else ret = 1;
|
||||
}
|
||||
|
||||
// Mission is finished.
|
||||
@ -302,14 +304,18 @@ static int misn_finish(lua_State* L) {
|
||||
int b;
|
||||
|
||||
if(lua_isboolean(L, -1)) b = lua_toboolean(L, -1);
|
||||
else return 0; // With no argument it won't delete the mission.
|
||||
else {
|
||||
lua_pushstring(L, "Mission Done");
|
||||
lua_error(L); // THERE IS NO RETURN!
|
||||
return 0;
|
||||
}
|
||||
|
||||
misn_delete = 1;
|
||||
|
||||
if(b && mis_isFlag(cur_mission->data, MISSION_UNIQUE))
|
||||
player_missionFinished(mission_getID(cur_mission->data));
|
||||
|
||||
lua_pushstring(L, "Mission Finished");
|
||||
lua_pushstring(L, "Mission Done");
|
||||
lua_error(L); // Should not return..
|
||||
|
||||
return 0;
|
||||
|
@ -100,8 +100,11 @@ static int mission_init(Mission* mission, MissionData* misn) {
|
||||
}
|
||||
|
||||
// Small wrapper for misn_run.
|
||||
void mission_accept(Mission* mission) {
|
||||
misn_run(mission, "accept");
|
||||
int mission_accept(Mission* mission) {
|
||||
int ret;
|
||||
ret = misn_run(mission, "accept");
|
||||
if(ret == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Check to see if mission is already running.
|
||||
|
@ -64,7 +64,7 @@ extern Mission player_missions[MISSION_MAX];
|
||||
// For mission computer.
|
||||
Mission* missions_computer(int* n, int faction, char* planet, char* system);
|
||||
// Player accepted mission - mission computer.
|
||||
void mission_accept(Mission* mission);
|
||||
int mission_accept(Mission* mission);
|
||||
void missions_bar(int faction, char* planet, char* system);
|
||||
|
||||
// Misc.
|
||||
|
Loading…
Reference in New Issue
Block a user