1
2-- -----------------------------------------------------------------
3-- Init
4-- -----------------------------------------------------------------
5local function prog_init()
6    initModels()
7    sound_playMusic("music/rybky14.ogg")
8    local pokus = getRestartCount()
9
10
11    -- -------------------------------------------------------------
12    local function prog_init_room()
13        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
14
15        room.zvednout = 0
16        room.uvod = random(42) + 14
17        room.ahojkrabe = 0
18        room.pobliz = 0
19        room.nesahat = 0
20        room.bud = 0
21        room.rozhovor = 0
22        room.veselit = 0
23
24        return function()
25            if no_dialog() and isReady(small) and isReady(big) then
26                if room.zvednout == 0 and dist(big, valec) <= 1 and big.dir == dir_no and random(6) == 1 and valec.Y > 14 then
27                    room.zvednout = 1
28                    addv(4, "re-v-ocel")
29                elseif room.uvod <= 0 then
30                    local bit_spi = {}
31                    if krab.spi == 0 then
32                        switch(random(10)){
33                            [1] = function()
34                                bit_spi[0] = true
35                                bit_spi[2] = true
36                            end,
37                            [2] = function()
38                                bit_spi[0] = true
39                                bit_spi[2] = true
40                            end,
41                            [3] = function()
42                                bit_spi[1] = true
43                                bit_spi[3] = true
44                            end,
45                            [4] = function()
46                                bit_spi[1] = true
47                                bit_spi[3] = true
48                            end,
49                            [5] = function()
50                                bit_spi[4] = true
51                                bit_spi[5] = true
52                            end,
53                            [6] = function()
54                                bit_spi[0] = true
55                                bit_spi[2] = true
56                            end,
57                            [7] = function()
58                                bit_spi[1] = true
59                                bit_spi[3] = true
60                            end,
61                            [8] = function()
62                                bit_spi[0] = true
63                                bit_spi[4] = true
64                            end,
65                            [9] = function()
66                                bit_spi[1] = true
67                                bit_spi[2] = true
68                            end,
69                            [0] = function()
70                                bit_spi[4] = true
71                            end,
72                        }
73                    end
74                    if bit_spi[0] then
75                        addv(3 + random(9), "re-v-koraly0")
76                    end
77                    if bit_spi[1] then
78                        addv(3 + random(9), "re-v-koraly1")
79                    end
80                    if bit_spi[2] then
81                        addm(3 + random(9), "re-m-libi0")
82                    end
83                    if bit_spi[3] then
84                        addm(3 + random(9), "re-m-libi1")
85                    end
86                    if bit_spi[4] then
87                        addm(3 + random(9), "re-m-libi2")
88                    end
89                    if bit_spi[5] then
90                        addv(3 + random(9), "re-v-pokoj")
91                    end
92                    room.uvod = 800 + random(300) + random(400)
93                elseif room.ahojkrabe == 0 and dist(small, krab) <= 1 and random(20) == 1 then
94                    room.ahojkrabe = 1
95                    addm(1, "re-m-ahoj")
96                elseif krab.spi == 0 and room.pobliz > 20 then
97                    krab.spi = 1
98                elseif room.bud == 0 and room.pobliz > random(800) then
99                    room.bud = 1
100                    krab:planDialog(2, "re-k-budi")
101                    if room.ahojkrabe == 0 and random(2) == 1 then
102                        room.ahojkrabe = 1
103                        addm(5, "re-m-ahoj")
104                    end
105                elseif krab.dopad >= 1 and krab.dopad <= 10 then
106                    krab.dopad = 1000
107                    krab:planDialog(0, "re-k-au")
108                elseif room.nesahat == 0 and (krab.dir == dir_left or krab.dir == dir_right) then
109                    room.nesahat = 1
110                    if odd(game_getCycles()) then
111                        room.bud = 1
112                    end
113                    krab:planDialog(0, "re-k-nesahej")
114                elseif room.pobliz == random(500) + 30 then
115                    if odd(room.pobliz) then
116                        krab:planDialog(5, "re-k-spim")
117                    else
118                        krab:planDialog(5, "re-k-otravujete")
119                    end
120                elseif room.rozhovor == 0 and room.pobliz > 1 and random(333) == 1 then
121                    room.rozhovor = 1
122                    addm(7, "re-m-uzitecny"..random(2))
123                    if odd(game_getCycles()) then
124                        addv(7, "re-v-obejit")
125                    else
126                        addv(6, "re-v-nech")
127                        addv(3, "re-v-nervozni")
128                    end
129                elseif room.veselit == 0 and krab.spi > 0 and random(2000 + 100 * pokus) <= room.bud * 2 + room.nesahat * 2 + room.ahojkrabe + room.rozhovor then
130                    room.veselit = 1
131                    addm(10, "re-m-rozveselit")
132                    addv(7, "re-v-nevsimej")
133                end
134            end
135            room.uvod = room.uvod - 1
136            if dist(big, krab) <= 1 or dist(small, krab) <= 1 then
137                room.pobliz = room.pobliz + 1
138            else
139                room.pobliz = 0
140            end
141            if math.mod(game_getCycles(), 3000) == 0 then
142                room.rozhovor = 0
143            end
144        end
145    end
146
147    -- -------------------------------------------------------------
148    local function prog_init_valec()
149        return function()
150            if valec.dir == dir_up then
151                room.zvednout = 1
152            end
153        end
154    end
155
156    -- -------------------------------------------------------------
157    local function prog_init_krab()
158        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
159
160        krab.spi = 0
161        krab.dopad = 10000
162
163        return function()
164            if krab:isTalking() then
165                krab.spi = 1
166            end
167            if krab.spi == 0 then
168                if krab.dir == dir_no then
169                    krab.afaze = 0
170                else
171                    krab.spi = 1
172                end
173            elseif krab:isTalking() then
174                krab.afaze = math.mod(game_getCycles(), 4) + 2
175            elseif krab.dir == dir_down then
176                krab.afaze = random(9) + 1
177            else
178                anim_table = {
179                    [99] = function()
180                        krab.spi = 0
181                        room.pobliz = -14 - random(50)
182                        if random(2) == 1 then
183                            room.ahojkrabe = 0
184                        end
185                        if random(2) == 1 then
186                            room.nesahat = 0
187                        end
188                        if random(2) == 1 then
189                            room.bud = 0
190                        end
191                    end,
192                    [20] = function()
193                        krab.afaze = 0
194                    end,
195                    [26] = function()
196                        krab.afaze = random(4) + 2
197                    end,
198                    default = function()
199                        krab.afaze = 1
200                    end,
201                }
202                anim_table[21] = anim_table[20]
203                anim_table[22] = anim_table[20]
204                anim_table[23] = anim_table[20]
205                anim_table[24] = anim_table[20]
206                anim_table[25] = anim_table[20]
207                anim_table[27] = anim_table[26]
208                anim_table[28] = anim_table[26]
209
210                switch(math.mod(random(krab.spi), 100))(anim_table)
211            end
212            if krab.spi > 0 then
213                krab.spi = krab.spi + 1
214            end
215            if krab.dir == dir_down then
216                krab.dopad = 0
217            else
218                krab.dopad = krab.dopad + 1
219            end
220
221            krab:updateAnim()
222        end
223    end
224
225    -- --------------------
226    local update_table = {}
227    local subinit
228    subinit = prog_init_room()
229    if subinit then
230        table.insert(update_table, subinit)
231    end
232    subinit = prog_init_valec()
233    if subinit then
234        table.insert(update_table, subinit)
235    end
236    subinit = prog_init_krab()
237    if subinit then
238        table.insert(update_table, subinit)
239    end
240    return update_table
241end
242local update_table = prog_init()
243
244
245-- -----------------------------------------------------------------
246-- Update
247-- -----------------------------------------------------------------
248function prog_update()
249    for key, subupdate in pairs(update_table) do
250        subupdate()
251    end
252end
253
254