File: prog_compatible.lua

package info (click to toggle)
fillets-ng-data 0.6.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 73,664 kB
  • ctags: 2,328
  • sloc: makefile: 46
file content (118 lines) | stat: -rw-r--r-- 3,466 bytes parent folder | download | duplicates (8)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
-- -----------------------------------------------------------------
-- There are functions used in levels to raise dialogs and animation
-- -----------------------------------------------------------------

file_include("script/share/prog_goanim.lua")
file_include("script/share/prog_finder.lua")

-- -----------------------------------------------------------------
-- Compatibility functions
-- -----------------------------------------------------------------
function no_dialog()
    return not dialog_isDialog() and not game_isPlanning()
end

function isReady(model)
    -- fish is ready for dialog
    return model:isAlive() and not model:isOut()
end

function odd(number)
    return math.mod(number, 2) == 1
end

function getRestartCount()
    return level_getRestartCounter()
end

-- -----------------------------------------------------------------
-- Planning
-- -----------------------------------------------------------------
function addm(time, text)
    small:planDialog(time, text)
end
function addv(time, text)
    big:planDialog(time, text)
end
function adddel(time)
    -- plan delay
    planTimeAction(time, function() end)
end

function planSet(model, variable_name, value)
    -- plan value set, variable_name must be string
    planTimeAction(0, function() model[variable_name] = value end)
end
function planDialogSet(time, text, value, model, variable_name)
    -- plan value set, and unset after dialog end
    model:planDialog(time, text, function() model[variable_name] = value end)
    planTimeAction(0, function() model[variable_name] = 0 end)
end

function planBusy(model, value, delay)
    if delay == nil then
        delay = 0
    end
    planTimeAction(delay, function()
            model:setBusy(value)
        end)
end

-- -----------------------------------------------------------------
-- Distance measuring
-- -----------------------------------------------------------------
function xdist(one, second)
    local result = 0
    local one_min = one.X
    local one_max = one.X + one:getW() - 1
    local second_min = second.X
    local second_max = second.X + second:getW() - 1
    if one_max < second_min then
        result = one_max - second_min
    elseif second_max < one_min then
        result = one_min - second_max
    else
        result = 0
    end
    return result
end
function ydist(one, second)
    local result = 0
    local one_min = one.Y
    local one_max = one.Y + one:getH() - 1
    local second_min = second.Y
    local second_max = second.Y + second:getH() - 1
    if one_max < second_min then
        result = one_max - second_min
    elseif second_max < one_min then
        result = one_min - second_max
    else
        result = 0
    end
    return result
end
function dist(one, second)
    local dx = math.abs(xdist(one, second))
    local dy = math.abs(ydist(one, second))
    return math.max(dx, dy)
end

function look_at(fish, object)
    local dx = xdist(fish, object)
    return (fish:isLeft() and dx > 0) or (not fish:isLeft() and dx < 0)
end

-- -----------------------------------------------------------------
-- Alternative for FArray
-- -----------------------------------------------------------------
function modelEquals(model, x, y)
    -- Compares this model and model on [x,y] position
    -- index -1 is for empty space (water)
    return model_equals(model.index, x, y)
end

function isWater(x, y)
    -- Compares model on [x,y] position
    return model_equals(-1, x, y)
end