1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
-- -----------------------------------------------------------------
-- NOTE: uses 'small' and 'big' names for fishes
local function canReport()
--TODO: don't talk when room is solved
return no_dialog() and small:isAlive() and big:isAlive()
end
-- -----------------------------------------------------------------
local wereAtBorder = {}
local function markAtBorder(unit, value)
wereAtBorder[unit] = value
end
local function wasAtBorder(unit)
return wereAtBorder[unit]
end
-- -----------------------------------------------------------------
-- NOTE: uses 'small' and 'big' names for fishes
local function selectMessage(unit, n)
if unit == small then
addm(0, 'cil-m-hlaska'..n)
elseif unit == big then
addv(0, 'cil-v-hlaska'..n)
end
end
-- -----------------------------------------------------------------
local reportLimit = 1
local reportRate = 0
local lastMessage = random(4)
local function reportBorder(unit)
local result = false
reportRate = reportRate + 1
if reportRate == reportLimit then
reportLimit = reportLimit + 1
reportRate = random(reportLimit)
local message = random(3)
if message == lastMessage then
message = 3
end
lastMessage = message
selectMessage(unit, message)
result = true
end
return result
end
-- -----------------------------------------------------------------
local loaded = false
function stdBorderReportLoad()
if not loaded then
loaded = true
file_include("script/share/borderdialogs.lua")
end
end
-- -----------------------------------------------------------------
function stdBorderReport()
stdBorderReportLoad()
local reported = false
local oneTry = true
if canReport() then
for index, unit in pairs(getUnitTable()) do
if unit:isAtBorder() then
if oneTry and not wasAtBorder(unit) then
oneTry = false
reported = reportBorder(unit)
end
markAtBorder(unit, true)
else
markAtBorder(unit, false)
end
end
end
return reported
end
|