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 (426 lines) | stat: -rw-r--r-- 15,848 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
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

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


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

        room.uvod = 0
        room.sas = 0
        room.kuk = 0
        room.okoralech = 0
        room.obarvach = 0
        room.neprojedes = 0
        room.mohlabys = 0

        return function()
            if isReady(small) and isReady(big) and no_dialog() then
                if room.uvod == 0 then
                    room.uvod = 1
                    switch(random(1)){
                        [0] = function()
                            addm(20 + random(30), "ncp-m-tesno0")
                        end,
                        [1] = function()
                            addm(20 + random(30), "ncp-m-tesno1")
                        end,
                    }
                    if random(100) < 30 then
                        addv(random(8), "ncp-v-dostala")
                    end
                elseif look_at(small, sasanka) and dist(small, sasanka) < 3 and room.sas == 0 and random(100) < 20 then
                    addv(random(5), "ncp-v-sasanka")
                    room.sas = 1
                elseif look_at(small, konik) and konik.afaze == 3 and dist(small, konik) < 4 and room.kuk == 0 then
                    addm(random(5), "ncp-m-nekoukej")
                    room.kuk = 1
                elseif (koral1.dir ~= dir_no or koral2.dir ~= dir_no or koral3.dir ~= dir_no or koral0.dir ~= dir_no) and room.okoralech == 0 and random(100) < 2 then
                    room.okoralech = 1
                    if big.dir ~= dir_no then
                        addv(0, "ncp-v-mekky")
                    else
                        switch(random(5)){
                            [4] = function()
                                addm(0, "ncp-m-komari")
                                addv(random(3), "ncp-v-ceho")
                                addm(random(3), "ncp-m-koraly")
                            end,
                            default = function()
                                addm(0, "ncp-m-tvrdy")
                            end,
                        }
                    end
                elseif big.X == 4 and big.Y == 29 and room.neprojedes == 0 and random(100) < 10 then
                    addv(random(3), "ncp-v-neprojedu")
                    room.neprojedes = 1
                elseif room.obarvach == 0 and random(10000) < 5 then
                    room.obarvach = 1
                    addm(random(10), "ncp-m-barvy")
                elseif valec.X == 3 and valec.Y == 34 and room.mohlabys == 0 then
                    room.mohlabys = 1
                    addv(random(3), "ncp-v-tak")
                    if random(100) < 80 then
                        addm(random(10), "ncp-m-muzes")
                    end
                end
            end
        end
    end

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

        sasanka.cinnost = 0
        sasanka.noha = 0
        sasanka.kvet = 1
        sasanka.akcnost = 1

        return function()
            if sasanka.cinnost ~= 5 and (dist(small, sasanka) < 3 or dist(big, sasanka) < 3) then
                sasanka.cinnost = 5
                sasanka.counts = random(10) + 15
                sasanka.akcnost = 1
            end
            if sasanka.cinnost == 0 then
                sasanka.cinnost = random(4) + 1
                sasanka.fazec = 0
                sasanka.akcnost = 2 + random(2)
            end
            if math.mod(game_getCycles(), sasanka.akcnost) == 0 then
                cinnost_table = {
                    [1] = function()
                        sasanka.noha = math.floor(sasanka.fazec / 4)
                        if sasanka.cinnost == 1 then
                            sasanka.kvet = math.mod(sasanka.fazec, 2) + 1
                            sasanka.akcnost = 2
                            if sasanka.kvet == 2 then
                                sasanka:talk("ncp-x-tup", VOLUME_FULL)
                            end
                        else
                            sasanka.kvet = math.mod(sasanka.fazec, 2) * 2 + 1
                            sasanka.akcnost = 3
                        end
                        sasanka.fazec = sasanka.fazec + 1
                        if sasanka.fazec == 8 then
                            if random(100) < 30 then
                                sasanka.cinnost = 0
                            else
                                sasanka.fazec = 0
                            end
                        end
                    end,
                    [3] = function()
                        switch(sasanka.fazec){
                            [0] = function()
                                sasanka.counts = random(10) + 7
                                sasanka.fazec = sasanka.fazec + 1
                                sasanka.kvet = 1
                            end,
                            [1] = function()
                                sasanka.noha = 1 - sasanka.noha
                                sasanka.counts = sasanka.counts - 1
                                if sasanka.counts == 0 then
                                    sasanka.fazec = sasanka.fazec + 1
                                end
                            end,
                            [2] = function()
                                if sasanka.cinnost == 3 then
                                    sasanka.kvet = 0
                                    sasanka.counts = random(8) + 5
                                else
                                    sasanka.kvet = 3
                                    sasanka.counts = random(6) + 3
                                end
                                sasanka.fazec = sasanka.fazec + 1
                            end,
                            [3] = function()
                                sasanka.counts = sasanka.counts - 1
                                if sasanka.counts == 0 then
                                    if random(100) < 30 then
                                        sasanka.cinnost = 0
                                    else
                                        sasanka.fazec = 0
                                    end
                                end
                            end,
                        }
                    end,
                    [5] = function()
                        sasanka.akcnost = 2
                        sasanka.counts = sasanka.counts - 1
                        switch(sasanka.counts){
                            [0] = function()
                                sasanka.cinnost = 0
                            end,
                            [1] = function()
                                sasanka.kvet = 1
                                sasanka.noha = 1 - sasanka.noha
                            end,
                            default = function()
                                sasanka.kvet = 0
                            end,
                        }
                    end,
                }

                cinnost_table[2] = cinnost_table[1]
                cinnost_table[4] = cinnost_table[3]
                switch(sasanka.cinnost)(cinnost_table)
            end
            sasanka.afaze = sasanka.noha * 4 + sasanka.kvet
            sasanka:updateAnim()
        end
    end

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

        snek.stav = 0

        return function()
            switch(snek.stav){
                [0] = function()
                    if snek.dir ~= dir_no then
                        snek.stav = 1
                    end
                end,
                [1] = function()
                    snek.afaze = 3
                    snek.stav = snek.stav + 1
                end,
                [2] = function()
                    snek.afaze = 1
                    snek.stav = snek.stav + 1
                end,
                [3] = function()
                    snek.afaze = 2
                    if snek.dir == dir_no then
                        snek.stav = 4
                        snek.count = 20
                    end
                end,
                [4] = function()
                    snek.count = snek.count - 1
                    if snek.count == 0 then
                        snek.stav = 5
                        snek.count = 5
                    end
                    if snek.dir ~= dir_no then
                        snek.stav = 2
                    end
                end,
                [5] = function()
                    snek.afaze = 1
                    snek.count = snek.count - 1
                    if snek.count == 0 then
                        snek.afaze = 0
                        snek.stav = 0
                    end
                    if snek.dir ~= dir_no then
                        snek.stav = 1
                    end
                end,
            }
            snek:updateAnim()
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_small()
        local small_boring = 0
        local small_smile = 4
        local xicht = 0

        return function()
            if small:getAction() == "rest" then
                small_boring = small_boring + 1
            else
                small_boring = 0
            end
            if small_boring >= 15 and small_boring < 40 and look_at(small, konik) and ydist(small, konik) == 0 and xdist(small, konik) < 3 then
                if xicht ~= small_smile then
                    xicht = small_smile
                    konik.stav = 7
                end
            else
                xicht = 0
            end
            if xicht ~= 0 then
                small:useSpecialAnim("head_all", xicht)
            end
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_big()
        local big_boring = 0
        local xicht = 0
        return function()
            if big:getAction() == "rest" then
                big_boring = big_boring + 1
            else
                big_boring = 0
            end
            if big_boring >= 15 and big_boring < 40 and look_at(big, konik) and ydist(big, konik) == 0 and xdist(big, konik) < 3 then
                if xicht ~= 6 then
                    xicht = 6
                    konik.stav = 7
                end
            else
                xicht = 0
            end
            if xicht ~= 0 then
                big:useSpecialAnim("head_all", xicht)
            end
        end
    end

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

        konik.stav = 0
        konik.mrkani = 0

        return function()
            if konik.stav ~= 2 and konik.dir == dir_down then
                konik:talk("ncp-x-ihaha", VOLUME_FULL)
            end
            if konik.dir == dir_down or elko.dir == dir_down then
                konik.stav = 2
            elseif konik.stav == 2 then
                konik.stav = 0
            end
            switch(konik.stav){
                [0] = function()
                    pom1 = 15
                    if look_at(small, konik) and math.abs(xdist(small, konik)) <= 3 and math.abs(ydist(small, konik)) <= 1 then
                        pom1 = 0
                    end
                    if look_at(big, konik) and math.abs(xdist(big, konik)) <= 3 and math.abs(ydist(big, konik)) <= 1 then
                        pom1 = 0
                    end
                    if random(100) < pom1 then
                        konik.stav = 1
                        konik.mrkani = 0
                    end
                    konik.afaze = 0
                end,
                [2] = function()
                    konik.afaze = 3
                end,
                [6] = function()
                    konik.stav = 10
                    konik.mrkani = 10
                end,
                [7] = function()
                    konik.mrkani = 10
                    konik.stav = 8
                end,
                [8] = function()
                    konik.mrkani = konik.mrkani - 1
                    if konik.mrkani == 0 then
                        konik.stav = 3
                    end
                end,
                [10] = function()
                    if konik.mrkani > 0 then
                        konik.mrkani = konik.mrkani - 1
                    else
                        konik.stav = 11
                    end
                end,
                [11] = function()
                    konik.afaze = 3
                    konik.mrkani = random(10) + 10
                    konik.stav = konik.stav + 1
                end,
                [12] = function()
                    if konik.mrkani > 0 then
                        konik.mrkani = konik.mrkani - 1
                    else
                        konik.afaze = 0
                        konik.stav = 0
                    end
                end,
                default = function()
                    if isIn(konik.stav, {1, 3, 4, 5}) then
                        switch(konik.mrkani){
                            [0] = function()
                                konik.afaze = 2
                            end,
                            [1] = function()
                                konik.afaze = 1
                                konik:talk("ncp-x-tik", VOLUME_FULL)
                            end,
                            [2] = function()
                                konik.afaze = 2
                            end,
                            [3] = function()
                                konik.afaze = 0
                                konik.mrkani = -1
                                if konik.stav == 1 then
                                    konik.stav = 0
                                else
                                    konik.stav = konik.stav + 1
                                end
                            end,
                        }
                        konik.mrkani = konik.mrkani + 1
                    end
                end,
            }
            konik:updateAnim()
        end
    end

    -- --------------------
    local update_table = {}
    local subinit
    subinit = prog_init_room()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_sasanka()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_snek()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_small()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_big()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_konik()
    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