Skip to content

Commit

Permalink
seek_n_destroy: better clean up of missions
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Apr 18, 2024
1 parent fc06ce6 commit 74a38fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
36 changes: 19 additions & 17 deletions dat/missions/neutral/seek_n_destroy.lua
Expand Up @@ -417,40 +417,42 @@ function hail( target )
m._seekndestroy_rnd2 = rnd.rnd()
-- Custom option
local lbl = "seekndestroy_check"
local mmem = mem -- have to use auxiliary variable here
ccomm.customComm( target, function ()
if mem.stage ~= 0 or system.cur() ~= mem.mysys[mem.cursys] or inlist( hailed, target )then
if mmem.stage ~= 0 or system.cur() ~= mmem.mysys[mmem.cursys] or inlist( hailed, target )then
return nil -- Past first stage
end
return fmt.f(_("Ask about {plt} (#bSeek And Destroy#0)"),
{plt=mem.name,})
{plt=mmem.name,})
end, function ( lvn, vnp )
lvn.func( function ()
table.insert( hailed, target )
if mem.cursys+1 >= mem.nbsys then -- No more claimed system : need to finish the mission
if mmem.cursys+1 >= mem.nbsys then -- No more claimed system : need to finish the mission
return lvn.jump( "seekndestroy_cold")
end
return lvn.jump("seekndestroy_std")
end )
-- Message has gone cold
lvn.label("seekndestroy_cold")
vnp(fmt.f( quotes.cold[m._seekndestroy_cold], {plt=mem.name}))
vnp(fmt.f( quotes.cold[m._seekndestroy_cold], {plt=mmem.name}))
lvn.func( function ()
m.comm_custom = nil -- TODO Not good to overwrite others, but oh well
ccomm.customCommRemove( lbl )
misn.finish(false)
end )
lvn.jump("menu")
lvn.label("seekndestroy_std")
lvn.func( function ()
-- If hailed pilot is enemy to the target, there is less chance he knows
if mem.target_faction:areEnemies( target:faction() ) then
if mmem.target_faction:areEnemies( target:faction() ) then
m._seekndestroy_know = (m._seekndestroy_rnd1 > 0.9)
else
m._seekndestroy_know = (m._seekndestroy_rnd1 > 0.3)
end
-- If hailed pilot is enemy to the player, there is less chance he mem.tells
-- If hailed pilot is enemy to the player, there is less chance they mmem.tells
if target:hostile() then
m._seekndestroy_tells = (m._seekndestroy_rnd2 > 0.95)
else
Expand All @@ -468,7 +470,7 @@ function hail( target )
lvn.label("seekndestroy_notknow")
vnp(fmt.f( quotes.dono[m._seekndestroy_dono],
{plt=mem.name}))
{plt=mmem.name}))
lvn.jump("menu")
lvn.label("seekndestroy_tells")
Expand All @@ -477,7 +479,7 @@ function hail( target )
target:setHostile( false )
end )
vnp(fmt.f( quotes.clue[m._seekndestroy_clue],
{plt=mem.name, sys=mem.mysys[mem.cursys+1]}))
{plt=mmem.name, sys=mmem.mysys[mmem.cursys+1]}))
lvn.jump("menu")
lvn.label("seekndestroy_clue")
Expand Down Expand Up @@ -511,7 +513,7 @@ function hail( target )
player.pay(-m._seekndestroy_price)
end )
vnp(_([["I know the pilot you're looking for."]]))
vnp(fmt.f( quotes.clue[rnd.rnd(1,#quotes.clue)], {plt=mem.name, sys=mem.mysys[mem.cursys+1]}))
vnp(fmt.f( quotes.clue[rnd.rnd(1,#quotes.clue)], {plt=mmem.name, sys=mmem.mysys[mmem.cursys+1]}))
lvn.func( function ()
var.push("seekndestroy_nextsys",true)
target:setHostile( false )
Expand Down Expand Up @@ -542,7 +544,7 @@ function hail( target )
end )

lvn.label("seekndestroy_scared")
vnp(fmt.f( quotes.scared[rnd.rnd(1,#quotes.scared)], {plt=mem.name, sys=mem.mysys[mem.cursys+1]}))
vnp(fmt.f( quotes.scared[rnd.rnd(1,#quotes.scared)], {plt=mmem.name, sys=mmem.mysys[mmem.cursys+1]}))
lvn.func( function ()
var.push("seekndestroy_nextsys",true)
target:control()
Expand All @@ -552,14 +554,14 @@ function hail( target )
lvn.done()

lvn.label("seekndestroy_notimpressed")
vnp(fmt.f( quotes.not_scared[rnd.rnd(1,#quotes.not_scared)], {plt=mem.name, sys=mem.mysys[mem.cursys+1]}))
vnp(fmt.f( quotes.not_scared[rnd.rnd(1,#quotes.not_scared)], {plt=mmem.name, sys=mmem.mysys[mmem.cursys+1]}))
lvn.func( function ()
target:comm(comms.not_scared[rnd.rnd(1,#comms.not_scared)])
-- Clean the previous hook if it exists
if mem.attack then
hook.rm(mem.attack)
if mmem.attack then
hook.rm(mmem.attack)
end
mem.attack = hook.pilot( target, "attacked", "clue_attacked" )
mmem.attack = hook.pilot( target, "attacked", "clue_attacked" )
player.commClose()
end )
lvn.done()
Expand All @@ -573,14 +575,14 @@ function hail( target )
}

lvn.label( "seekndestroy_intimidating" )
vnp( fmt.f( quotes.scared[rnd.rnd(1,#quotes.scared)], {plt=mem.name, sys=mem.mysys[mem.cursys+1]} ) )
vnp( fmt.f( quotes.scared[rnd.rnd(1,#quotes.scared)], {plt=mmem.name, sys=mmem.mysys[mmem.cursys+1]} ) )
lvn.func( function ()
var.push("seekndestroy_nextsys",true)
target:control()
target:runaway(player.pilot())
end )
vn.jump("menu")
end )
end, lbl )

hook.timer(-1, "board_done")
end
Expand Down
25 changes: 24 additions & 1 deletion dat/scripts/common/comm.lua
@@ -1,5 +1,6 @@
local vn
local lg = require 'love.graphics'
local fmt = require "format"

local comm = {}

Expand Down Expand Up @@ -139,14 +140,36 @@ end
@tparam Pilot plt Pilot to set up for.
@tparam string|function menu Menu message or function returning message or nil.
@tparam function setup Function to call to set up the vn nodes when the selected menu option is pressed. Will be passed a local version of the vn library as the first parameter, and the pilot vn character as the second parameter.
@tparam string label Label to use with comm.customCommRemove
--]]
function comm.customComm( plt, menu, setup )
function comm.customComm( plt, menu, setup, label )
local m = plt:memory()
m.comm_custom = m.comm_custom or {}
table.insert( m.comm_custom, {
menu = menu,
setup = setup,
label = label,
} )
end
--[[--
Removes a custom messag eand handler from a pilot.
@tparam Pilot plt Pilot te remove from.
@tparam string label Label matching label assigned to comm.customComm
--]]
function comm.customCommRemove( plt, label )
local m = plt:memory()
if m.comm_custom then
for k,v in ipairs(m.comm_custom) do
if v.label==label then
table.remove( m.comm_custom, k )
return
end
end
end
warn(fmt.f(_([[Trying to remove custom comm from pilot {plt} with non-existent label '{label}'!]]),
{plt=plt, label=label}))
end
return comm

0 comments on commit 74a38fc

Please sign in to comment.