[Fix] Annoying ass bug with mission disappearing when no cargo space left.

This commit is contained in:
Allanis 2013-05-09 18:15:56 +01:00
parent 95ee7852de
commit bc935960f8
7 changed files with 28 additions and 13 deletions

View File

@ -108,6 +108,7 @@ end
function accept() function accept()
if player.freeCargo() < carg_mass then if player.freeCargo() < carg_mass then
tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo())) 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. elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
carg_id = player.addCargo(carg_type, carg_mass) carg_id = player.addCargo(carg_type, carg_mass)
@ -120,6 +121,7 @@ function accept()
end end
else else
tk.msg(toomany_title, toomany_msg) tk.msg(toomany_title, toomany_msg)
misn.finish()
end end
end end

View File

@ -72,6 +72,7 @@ end
function accept() function accept()
if player.freeCargo() < carg_mass then if player.freeCargo() < carg_mass then
tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo())) 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. elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
carg_id = player.addCargo(carg_type, carg_mass) carg_id = player.addCargo(carg_type, carg_mass)
tk.msg(accept_title, string.format( accept_msg, carg_mass, carg_type)) tk.msg(accept_title, string.format( accept_msg, carg_mass, carg_type))
@ -79,6 +80,7 @@ function accept()
hook.time("timeup") hook.time("timeup")
else else
tk.msg(toomany_title, toomany_msg) tk.msg(toomany_title, toomany_msg)
misn.finish()
end end
end end

View File

@ -43,7 +43,7 @@ static int hook_run(Hook* hook) {
} }
misn = &player_missions[i]; misn = &player_missions[i];
if(misn_run(misn, hook->func)) if(misn_run(misn, hook->func) < 0)
// Error has accured. // Error has accured.
WARN("Hook [%s] '%d' -> '%s' failed", hook->stack, WARN("Hook [%s] '%d' -> '%s' failed", hook->stack,
hook->id, hook->func); hook->id, hook->func);

View File

@ -855,12 +855,14 @@ static void misn_accept(char* str) {
"Are you sure you want to accept this mission?")) { "Are you sure you want to accept this mission?")) {
pos = toolkit_getListPos(secondary_wid, "lstMission"); pos = toolkit_getListPos(secondary_wid, "lstMission");
misn = &mission_computer[pos]; misn = &mission_computer[pos];
mission_accept(misn); if(mission_accept(misn)) {
// Success is accepting the mission.
memmove(misn, &mission_computer[pos+1], memmove(misn, &mission_computer[pos+1],
sizeof(Mission) * (mission_ncomputer-pos-1)); sizeof(Mission) * (mission_ncomputer-pos-1));
mission_ncomputer--; mission_ncomputer--;
misn_genList(0); misn_genList(0);
} }
}
} }
static void misn_genList(int first) { static void misn_genList(int first) {

View File

@ -188,6 +188,8 @@ int misn_loadLibs(lua_State* L) {
} }
// Run a mission function. // Run a mission function.
//
// -1 on error, 1 on misn.finish() call and 0 normally.
int misn_run(Mission* misn, char* func) { int misn_run(Mission* misn, char* func) {
int i, ret; int i, ret;
char* err; char* err;
@ -199,10 +201,10 @@ int misn_run(Mission* misn, char* func) {
if((ret = lua_pcall(misn->L, 0, 0, 0))) { if((ret = lua_pcall(misn->L, 0, 0, 0))) {
// Did an oops. // Did an oops.
err = (lua_isstring(misn->L, -1)) ? (char*) lua_tostring(misn->L, -1) : NULL; 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", WARN("Mission '%s' -> '%s' : %s",
cur_mission->data->name, func, (err) ? err : "Unknown Error"); cur_mission->data->name, func, (err) ? err : "Unknown Error");
else ret = 0; else ret = 1;
} }
// Mission is finished. // Mission is finished.
@ -302,14 +304,18 @@ static int misn_finish(lua_State* L) {
int b; int b;
if(lua_isboolean(L, -1)) b = lua_toboolean(L, -1); 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; misn_delete = 1;
if(b && mis_isFlag(cur_mission->data, MISSION_UNIQUE)) if(b && mis_isFlag(cur_mission->data, MISSION_UNIQUE))
player_missionFinished(mission_getID(cur_mission->data)); player_missionFinished(mission_getID(cur_mission->data));
lua_pushstring(L, "Mission Finished"); lua_pushstring(L, "Mission Done");
lua_error(L); // Should not return.. lua_error(L); // Should not return..
return 0; return 0;

View File

@ -100,8 +100,11 @@ static int mission_init(Mission* mission, MissionData* misn) {
} }
// Small wrapper for misn_run. // Small wrapper for misn_run.
void mission_accept(Mission* mission) { int mission_accept(Mission* mission) {
misn_run(mission, "accept"); int ret;
ret = misn_run(mission, "accept");
if(ret == 0) return 1;
return 0;
} }
// Check to see if mission is already running. // Check to see if mission is already running.

View File

@ -64,7 +64,7 @@ extern Mission player_missions[MISSION_MAX];
// For mission computer. // For mission computer.
Mission* missions_computer(int* n, int faction, char* planet, char* system); Mission* missions_computer(int* n, int faction, char* planet, char* system);
// Player accepted mission - mission computer. // Player accepted mission - mission computer.
void mission_accept(Mission* mission); int mission_accept(Mission* mission);
void missions_bar(int faction, char* planet, char* system); void missions_bar(int faction, char* planet, char* system);
// Misc. // Misc.