/** * @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, const char *func ) { /* Get the function to run. */ misn_runStart( misn, func ); if (lua_isnil( misn->L, -1 )) { lua_pop(misn->L,1); return 0; } return misn_runFunc( misn, func, 0 ); }
/** * @brief Approaches the NPC. * * @param i Index of the NPC to approach. */ int npc_approach( int i ) { NPC_t *npc; lua_State *L; /* Make sure in bounds. */ if ((i<0) || (i>=array_size(npc_array))) return -1; /* Comfortability. */ npc = &npc_array[i]; /* Handle type. */ switch (npc->type) { case NPC_TYPE_GIVER: return npc_approach_giver( npc ); case NPC_TYPE_MISSION: L = misn_runStart( npc->u.m.misn, npc->u.m.func ); lua_pushnumber( L, npc->id ); misn_runFunc( npc->u.m.misn, npc->u.m.func, 1 ); break; case NPC_TYPE_EVENT: L = event_runStart( npc->u.e.id, npc->u.e.func ); lua_pushnumber( L, npc->id ); event_runFunc( npc->u.e.id, npc->u.e.func, 1 ); break; default: WARN("Unknown NPC type!"); return -1; } return 0; }
/** * @brief Runs a mission function. * * @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_run( Mission *misn, const char *func ) { /* Run the function. */ misn_runStart( misn, func ); return misn_runFunc( misn, func, 0 ); }