Module lmisn
Mission helper utilities.
Functions
sfxVictory () | Plays a happy victory sound. |
sfxMoney () | Plays a money indicating money made. |
sfxBingo () | Plays a jingle indicating success. |
sfxEerie () | Plays a weird eerie sfx. |
getLandableSpobs ([sys[, fct[, fctmatch=false]]]) | Returns a complete or filtered table of landable spobs (that is, landable, inhabitable, and not restricted) |
getNextSystem (nowsys, finalsys[, hidden=false]) | Choose the next system to jump to on the route from system nowsys to system finalsys. |
getRoute (nowsys, finalsys, hidden) | Gets the route between nowsys and finalsys. |
lmisn.sysFilters.default () | Provides the default system filter. |
lmisn.sysFilters.faction (fct, threshold) | Provides the faction system filter. |
lmisn.sysFilters.factionLandable (fct[, samefact=false]) | Provides the landable system filter. |
getSysAtDistance (sys, min, max, filter, data, hidden) | Fetches an array of systems from min to max jumps away from the given system sys. |
getSpobAtDistance ([sys=system.cur()], min, max[, fct=faction.get("Player")[, samefct=false[, filter=nil[, data=nil[, hidden=false]]]]]) | Works the same as lmisn.getSysAtDistance, but for spobs. |
getRandomSpobAtDistance ([sys=system.cur()], min, max[, fct=nil[, samefct=false[, filter=nil[, data=nil[, hidden=false]]]]]) | Gets a random spob at a distance. |
calculateDistance (origin_sys, origin_pos, dest_sys, dest_pos, params) | Calculates the distance (in pixels) from a position in a system to a position in another system. |
anyMissionActive (names) | Wrapper for player.misnActive that works on a table of missions. |
fail (reason) | Wrapper for player.msg + misn.finish for when the player fails a mission. |
Functions
- sfxVictory ()
- Plays a happy victory sound. Should be used for unique mission completion.
- sfxMoney ()
- Plays a money indicating money made. Should be used when the player receives payment for generic repeatable missions.
- sfxBingo ()
- Plays a jingle indicating success. Meant more for small good things advancing missions rather than completion.
- sfxEerie ()
- Plays a weird eerie sfx.
- getLandableSpobs ([sys[, fct[, fctmatch=false]]])
-
Returns a complete or filtered table of landable spobs (that is, landable, inhabitable, and not restricted)
Parameters:
- sys System The system to search, defaulting to the current one. (optional)
- fct Faction If nil, return all landable spobs in the system meeting the landable criteria, otherwise... (optional)
- fctmatch boolean If true, restrict results to the given faction; if false, restricts it to factions not hostile with fct. (default false)
Returns:
-
table
All matching spobs in a list.
- getNextSystem (nowsys, finalsys[, hidden=false])
-
Choose the next system to jump to on the route from system nowsys to system finalsys.
Parameters:
- nowsys System Start point.
- finalsys System End point.
- hidden boolean Whether the path may include hidden systems. (default false)
Returns:
-
System
The next system to jump to, defaulting to nowsys if there's no path or nothing to do.
- getRoute (nowsys, finalsys, hidden)
-
Gets the route between nowsys and finalsys.
Parameters:
- nowsys
- finalsys
- hidden
Returns:
-
table
A table of systems including the nowsys and finalsys.
- lmisn.sysFilters.default ()
-
Provides the default system filter. Always true regardless of input.
Returns:
-
function
The filter function.
- lmisn.sysFilters.faction (fct, threshold)
-
Provides the faction system filter. Makes sure each system hasa minimum amount of presence of a certain faction.
Parameters:
- fct Faction Faction to ensure minimum presence.
- threshold number Minimum amount of presence necessary to return true.
Returns:
-
function
The filter function.
Usage:
sys = lmisn.getSysAtDistance( system.cur(), 1, 3, lmisn.sysFilters.faction( "Dvaered", 50 ) ) -- Gets all systems within 1 to 3 jumps that have >= 50 Dvaered presence
- lmisn.sysFilters.factionLandable (fct[, samefact=false])
-
Provides the landable system filter. Makes sure each system has at least on landable, inhabited, non-restricted spob and is landable by a certain faction.
Parameters:
- fct Faction Faction to make sure can land.
- samefact boolean Whether or not being non-hostile is sufficient, or we enforce exact match (true). (default false)
Returns:
-
function
The filter function.
- getSysAtDistance (sys, min, max, filter, data, hidden)
-
Fetches an array of systems from min to max jumps away from the given
system sys.
The following example gets a random Sirius M class spob between 1 to 6 jumps away.
Parameters:
- sys System to calculate distance from or nil to use current system
- min Min distance to check for.
- max Maximum distance to check for.
- filter Optional filter function to use for more details.
- data Data to pass to filter
- hidden Whether or not to consider hidden jumps (off by default)
Returns:
-
The table of systems n jumps away from sys
Usage:
local spobs = {} lmisn.getSysAtDistance( system.cur(), 1, 6, function(s) for i, v in ipairs(s:spobs()) do if v:faction() == faction.get("Sirius") and v:class() == "M" then return true end end return false end ) if #spobs == 0 then misn.finish(false) end -- In case no suitable spobs are in range. local index = rnd.rnd(1, #spobs) destspob = spobs[index][1] destsys = spobs[index][2]
- getSpobAtDistance ([sys=system.cur()], min, max[, fct=faction.get("Player")[, samefct=false[, filter=nil[, data=nil[, hidden=false]]]]])
-
Works the same as lmisn.getSysAtDistance, but for spobs.
Filter is applied on a spob level.
Parameters:
- sys System System to base distance calculations off of. (default system.cur())
- min number Minimum jump distance to get spob at.
- max number Maximum jump distance to get spob at.
- fct Faction What faction to do landing checks with. (default faction.get("Player"))
- samefct boolean Whether or not to only allow spobs to belong exactly to fct. (default false)
- filter function Filtering function that returns a boolean and takes a spob being tested as a parameter. (default nil)
- data Custom data that will be passed to filter. (default nil)
- hidden boolean Whether or not to consider hidden jumps when computing system distance. (default false)
Returns:
-
table
A table containing all the spobs matching the criteria. Can be empty if no matches found.
Usage:
-- Get random spob within 3 to 5 jumps of current system that is landable by independent pilots. local candidates = lmisn.getSpobAtDistance( system.cur(), 3, 5, "Independent", false ) -- Make sure there are candidates if #candidates==0 then error("There are no spobs meeting the criteria!") end -- Sort candidates by some criteria table.sort( candidates, my_spob_sort_function ) -- Get best by sorting criteria local destpnt = candidates[1]
- getRandomSpobAtDistance ([sys=system.cur()], min, max[, fct=nil[, samefct=false[, filter=nil[, data=nil[, hidden=false]]]]])
-
Gets a random spob at a distance. Only checks for inhabited, landable, and non-restricted spobs.
Parameters:
- sys System System to base distance calculations off of. (default system.cur())
- min number Minimum jump distance to get spob at.
- max number Maximum jump distance to get spob at.
- fct Faction What faction to do landing checks with. (default nil)
- samefct boolean Whether or not to only allow spobs to belong exactly to fct. (default false)
- filter function Filtering function that returns a boolean and takes a spob being tested as a parameter. (default nil)
- data Custom data that will be passed to filter. (default nil)
- hidden boolean Whether or not to consider hidden jumps when computing system distance. (default false)
Returns:
-
Spob
A single spob matching all the criteria.
Usage:
destpnt = lmisn.getRandomSpobAtDistance( system.cur(), 3, 5, "Independent", false ) -- Get random spob within 3 to 5 jumps of current system that is landable by independent pilots.
- calculateDistance (origin_sys, origin_pos, dest_sys, dest_pos, params)
-
Calculates the distance (in pixels) from a position in a system to a position in another system.
Parameters:
- origin_sys System System to calculate distance from.
- origin_pos Vec2 Position to calculate distance from.
- dest_sys System Target system to calculate distance to.
- dest_pos Vec2 Target position to calculate distance to.
- params table Table of parameters. Currently supported are "use_hidden".
Returns:
- The distance travelled
- The jumpPath leading to the target system
- anyMissionActive (names)
-
Wrapper for player.misnActive that works on a table of missions.
Parameters:
- names table Table of names (strings) of missions to check
Returns:
-
true if any of the listed missions are active
Usage:
if anyMissionActive( { "Cargo", "Cargo Rush" } ) then -- at least one Cargo or Cargo Rush is active
- fail (reason)
-
Wrapper for player.msg + misn.finish for when the player fails a mission.
Parameters:
- reason string Reason the mission failed.