/** * @brief Checks to see if the player has a mission active. * * @usage if player.misnActive( "The Space Family" ) then -- Player is doing space family mission * * @luaparam name Name of the mission to check. * @luareturn true if the mission is active, false if it isn't. * @luafunc misnActive( name ) */ static int playerL_misnActive( lua_State *L ) { MissionData *misn; const char *str; str = luaL_checkstring(L,1); misn = mission_getFromName( str ); if (misn == NULL) { NLUA_ERROR(L, "Mission '%s' not found in stack", str); return 0; } lua_pushboolean( L, mission_alreadyRunning( misn ) ); return 1; }
/** * @brief Checks to see if a mission meets the requirements. * * @param mission ID of the mission to check. * @param faction Faction of the current planet. * @param planet Name of the current planet. * @param sysname Name of the current system. * @return 1 if requirements are met, 0 if they aren't. */ static int mission_meetReq( int mission, int faction, const char* planet, const char* sysname ) { MissionData* misn; int c; misn = mission_get( mission ); if (misn == NULL) /* In case it doesn't exist */ return 0; /* If planet, must match planet. */ if ((misn->avail.planet != NULL) && (strcmp(misn->avail.planet,planet)!=0)) return 0; /* If system, must match system. */ if ((misn->avail.system != NULL) && (strcmp(misn->avail.system,sysname)!=0)) return 0; /* Match faction. */ if ((faction >= 0) && !mission_matchFaction(misn,faction)) return 0; /* Must not be already done or running if unique. */ if (mis_isFlag(misn,MISSION_UNIQUE) && (player_missionAlreadyDone(mission) || mission_alreadyRunning(misn))) return 0; /* Must meet Lua condition. */ if (misn->avail.cond != NULL) { c = cond_check(misn->avail.cond); if (c < 0) { WARN("Conditional for mission '%s' failed to run", misn->name); return 0; } else if (!c) return 0; } /* Must meet previous mission requirements. */ if ((misn->avail.done != NULL) && (player_missionAlreadyDone( mission_getID(misn->avail.done) ) == 0)) return 0; return 1; }