File: code.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 (438 lines) | stat: -rw-r--r-- 16,745 bytes parent folder | download | duplicates (2)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438

--NOTE: rows must be together in models.lua
local advices1 = {}
local advices1_end = rada1end.index - rada1beg.index
for i = 0, advices1_end do
    advices1[i] = getModelsTable()[rada1beg.index + i]
end

local advices2 = {}
local advices2_end = rada2end.index - rada2beg.index
for i = 0, advices2_end do
    advices2[i] = getModelsTable()[rada2beg.index + i]
end

-- -----------------------------------------------------------------
-- Init
-- -----------------------------------------------------------------
local function prog_init()
    initModels()
    sound_playMusic("music/rybky05.ogg")
    local pokus = getRestartCount()


    -- -------------------------------------------------------------
    local function prog_init_room()
        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false

        switch(pokus){
            [1] = function()
                room.uvod = 12
            end,
            default = function()
                room.uvod = random(4) + random(2) * 10
            end,
        }
        room.kochani = random(2)
        room.pady = 0
        room.osose = random(1500) + 500

        return function()
            if isReady(small) and isReady(big) and no_dialog() then
                if room.osose > 0 then
                    room.osose = room.osose - 1
                end
                if room.uvod > 0 then
                    if room.uvod >= 10 and random(100) < 40 then
                        addm(10 + random(40), "sl-m-velkolepe")
                        room.uvod = room.uvod - 10
                    end
                    if math.mod(room.uvod, 10) >= 1 then
                        addv(20, "sl-v-stopa")
                    end
                    if room.uvod > 10 then
                        addm(5 + random(30), "sl-m-velkolepe")
                        room.uvod = room.uvod - 10
                    end
                    if room.uvod >= 2 then
                        addv(5, "sl-v-vkapse")
                    end
                    if room.uvod >= 3 then
                        addm(random(20) + 5, "sl-m-trvat")
                    end
                    room.uvod = 0
                elseif room.osose == 0 and chlapik.cinnost == 0 then
                    addm(20, "sl-m-sedi")
                    addv(5, "sl-v-feidios")
                    addm(20 + random(50), "sl-m-tehdy")
                    room.osose = -1
                elseif room.kochani == 0 and room.pady <= 1 and big.dir ~= dir_no and random(100) < 2 then
                    room.kochani = 1
                    big:setBusy(true)
                    addv(0, "sl-v-nechme")
                    adddel(random(90) + 30)
                    planBusy(big, false)
                elseif room.pady <= 0 and small.X == 33 and small.Y == 27 and ocel.Y < 26 then
                    addv(0, "sl-v-opatrne")
                    room.pady = 1
                elseif room.pady <= 1 and sochoradi.cinnost >= 8 then
                    addv(0, "sl-v-skoda")
                    room.pady = 2
                elseif room.pady <= 2 and sochoradi.Y == 16 and samotna.X >= 14 and chlapik.cinnost == 0 then
                    room.pady = 3
                    addv(0, "sl-v-pust")
                end
            end
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_samotna()
        return function()
            if random(100) < 2 then
                samotna.afaze = random(2) * 2
            end
            if samotna.dir ~= dir_no then
                samotna.afaze = 1
            end
            samotna:updateAnim()
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_rada1beg()
        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false

        rada1beg.cinnost = 0

        return function()
            switch(rada1beg.cinnost){
                [0] = function()
                    if random(1000) < 15 then
                        rada1beg.cinnost = random(5) + 2
                        switch(rada1beg.cinnost){
                            [4] = function()
                                repeat
                                    rada1beg.xicht1 = random(3)
                                until rada1beg.xicht1 ~= rada1beg.afaze
                                repeat
                                    rada1beg.xicht2 = random(3)
                                until rada1beg.xicht2 ~= rada1beg.afaze
                            end,
                            default = function()
                                if isIn(rada1beg.cinnost, {2, 3}) then
                                    repeat
                                        rada1beg.xicht1 = random(3)
                                    until rada1beg.xicht1 ~= rada1beg.afaze
                                end
                            end,
                        }
                        rada1beg.faze = 0
                    end
                end,
                [1] = function()
                    rada1beg.cinnost = random(3) + 2
                    rada1beg.xicht1 = random(3)
                    rada1beg.xicht2 = random(3)
                    rada1beg.faze = 0
                end,
                [2] = function()
                    if odd(game_getCycles()) then
                        advices1[rada1beg.faze].afaze = rada1beg.xicht1
                        rada1beg.faze = rada1beg.faze + 1
                        if rada1beg.faze > advices1_end then
                            rada1beg.cinnost = 0
                        end
                    end
                end,
                [3] = function()
                    if odd(game_getCycles()) then
                        advices1[advices1_end - rada1beg.faze].afaze = rada1beg.xicht1
                        rada1beg.faze = rada1beg.faze + 1
                        if advices1_end - rada1beg.faze < 0 then
                            rada1beg.cinnost = 0
                        end
                    end
                end,
                [4] = function()
                    if odd(game_getCycles()) then
                        advices1[rada1beg.faze].afaze = rada1beg.xicht1
                        advices1[advices1_end - rada1beg.faze].afaze = rada1beg.xicht2

                        rada1beg.faze = rada1beg.faze + 1
                        if rada1beg.faze > advices1_end then
                            rada1beg.cinnost = 0
                        end
                    end
                end,
                [5] = function()
                    if random(1000) < 15 then
                        rada1beg.cinnost = 1
                    elseif random(100) < 20 then
                        pom1 = random(advices1_end + 1)
                        advices1[pom1].afaze = random(3)
                    end
                end,
                [6] = function()
                    if random(1000) < 15 then
                        rada1beg.cinnost = 1
                    elseif random(100) < 50 then
                        pom1 = random(advices1_end + 1)
                        if random(100) < 20 then
                            advices1[pom1].afaze = random(3)
                        else
                            switch(random(2)){
                                [0] = function()
                                    if pom1 > 0 then
                                        advices1[pom1].afaze = advices1[pom1 - 1].afaze
                                    end
                                end,
                                [1] = function()
                                    if pom1 < advices1_end then
                                        advices1[pom1].afaze = advices1[pom1 + 1].afaze
                                    end
                                end,
                            }
                        end
                    end
                end,
                [7] = function()
                    rada1beg.cinnost = 4
                    rada1beg.xicht1 = 1
                    rada1beg.xicht2 = 1
                    rada1beg.faze = 0
                end,
            }
            for index, advice in advices1 do
                advice:updateAnim()
            end
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_rada2beg()
        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false

        rada2beg.cinnost = 0

        return function()
            switch(rada2beg.cinnost){
                [0] = function()
                    if random(1000) < 15 then
                        rada2beg.cinnost = random(5) + 2
                        switch(rada2beg.cinnost){
                            [4] = function()
                                repeat
                                    rada2beg.xicht1 = random(3)
                                until rada2beg.xicht1 ~= rada2beg.afaze
                                repeat
                                    rada2beg.xicht2 = random(3)
                                until rada2beg.xicht2 ~= rada2beg.afaze
                            end,
                            default = function()
                                if isIn(rada2beg.cinnost, {2, 3}) then
                                    repeat
                                        rada2beg.xicht1 = random(3)
                                    until rada2beg.xicht1 ~= rada2beg.afaze
                                end
                            end,
                        }
                        rada2beg.faze = 0
                    end
                end,
                [1] = function()
                    rada2beg.cinnost = random(3) + 2
                    rada2beg.xicht1 = random(3)
                    rada2beg.xicht2 = random(3)
                    rada2beg.faze = 0
                end,
                [2] = function()
                    if odd(game_getCycles()) then
                        advices2[rada2beg.faze].afaze = rada2beg.xicht1
                        rada2beg.faze = rada2beg.faze + 1
                        if rada2beg.faze > advices2_end then
                            rada2beg.cinnost = 0
                        end
                    end
                end,
                [3] = function()
                    if odd(game_getCycles()) then
                        advices2[advices2_end - rada2beg.faze].afaze = rada2beg.xicht1
                        rada2beg.faze = rada2beg.faze + 1
                        if advices2_end - rada2beg.faze < 0 then
                            rada2beg.cinnost = 0
                        end
                    end
                end,
                [4] = function()
                    if odd(game_getCycles()) then
                        advices2[rada2beg.faze].afaze = rada2beg.xicht1
                        advices2[advices2_end - rada2beg.faze].afaze = rada2beg.xicht2
                        rada2beg.faze = rada2beg.faze + 1
                        if rada2beg.faze > advices2_end then
                            rada2beg.cinnost = 0
                        end
                    end
                end,
                [5] = function()
                    if random(1000) < 15 then
                        rada2beg.cinnost = 1
                    elseif random(100) < 20 then
                        pom1 = random(advices2_end + 1)
                        advices2[pom1].afaze = random(3)
                    end
                end,
                [6] = function()
                    if random(1000) < 15 then
                        rada2beg.cinnost = 1
                    elseif random(100) < 50 then
                        pom1 = random(advices2_end + 1)
                        if random(100) < 20 then
                            advices2[pom1].afaze = random(3)
                        else
                            switch(random(2)){
                                [0] = function()
                                    if pom1 > 0 then
                                        advices2[pom1].afaze = advices2[pom1 - 1].afaze
                                    end
                                end,
                                [1] = function()
                                    if pom1 < advices2_end then
                                        advices2[pom1].afaze = advices2[pom1 + 1].afaze
                                    end
                                end,
                            }
                        end
                    end
                end,
                [7] = function()
                    rada2beg.cinnost = 4
                    rada2beg.xicht1 = 1
                    rada2beg.xicht2 = 1
                    rada2beg.faze = 0
                end,
            }
            for index, advice in advices2 do
                advice:updateAnim()
            end
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_sochoradi()
        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false

        sochoradi.cinnost = 0

        return function()
            if isIn(sochoradi.cinnost, {4, 5, 7}) then
                sound_playSound("impact_light")
            end
            switch(sochoradi.cinnost){
                [0] = function()
                    if sochoradi.dir == dir_up then
                        sochoradi.cinnost = sochoradi.cinnost + 1
                    end
                end,
                [8] = function()
                    rada1beg.cinnost = 7
                    sochoradi.cinnost = sochoradi.cinnost + 1
                end,
                default = function()
                    if 1 <= sochoradi.cinnost and sochoradi.cinnost <= 7 then
                        sochoradi.afaze = sochoradi.cinnost
                        sochoradi.cinnost = sochoradi.cinnost + 1
                    end
                end,
            }
            sochoradi:updateAnim()
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_chlapik()
        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false

        chlapik.cinnost = 0

        return function()
            if isIn(chlapik.cinnost, {5, 9}) then
                sound_playSound("impact_light")
            end
            switch(chlapik.cinnost){
                [0] = function()
                    if chlapik.dir == dir_down then
                        chlapik.cinnost = chlapik.cinnost + 1
                    end
                end,
                [1] = function()
                    if chlapik.dir == dir_no then
                        chlapik.afaze = 1
                        chlapik.cinnost = chlapik.cinnost + 1
                        small:killSound()
                        game_killPlan()
                        if isReady(small) then
                            addm(2, "sl-m-jekot")
                            if isReady(big) then
                                addv(0, "sl-v-barbarka")
                            end
                            addm(20 + random(20), "sl-m-nelibila")
                        end
                    end
                end,
                [10] = function()
                    rada1beg.cinnost = 7
                    chlapik.cinnost = chlapik.cinnost + 1
                end,
                default = function()
                    if 2 <= chlapik.cinnost and chlapik.cinnost <= 9 then
                        chlapik.afaze = chlapik.cinnost
                        chlapik.cinnost = chlapik.cinnost + 1
                    end
                end,
            }
            chlapik:updateAnim()
        end
    end

    -- --------------------
    local update_table = {}
    local subinit
    subinit = prog_init_room()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_samotna()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_rada1beg()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_rada2beg()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_sochoradi()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_chlapik()
    if subinit then
        table.insert(update_table, subinit)
    end
    return update_table
end
local update_table = prog_init()


-- -----------------------------------------------------------------
-- Update
-- -----------------------------------------------------------------
function prog_update()
    for key, subupdate in pairs(update_table) do
        subupdate()
    end
end