1
2-- Search for enemies with nonzero pal.
3-- foreachmap module.
4
5local build = require("build")
6local D = build.readdefs("../../names.h") or error("Need ../../names.h")
7
8local assert = assert
9local print = print
10local string = require("string")
11
12local io = require("io")
13
14local function printf(fmt, ...)
15    print(string.format(fmt, ...))
16end
17
18
19module(...)
20
21
22local ENEMY_NAME = {
23--[[
24    [D.BOSS1] = "BOSS1",
25    [D.BOSS1STAYPUT] = "BOSS1STAYPUT",
26--]]
27    [D.BOSS2] = "BOSS2",
28    [D.BOSS3] = "BOSS3",
29    [D.BOSS4] = "BOSS4",
30    [D.BOSS4STAYPUT] = "BOSS4STAYPUT",
31    [D.COMMANDER] = "COMMANDER",
32    [D.COMMANDERSTAYPUT] = "COMMANDERSTAYPUT",
33    [D.DRONE] = "DRONE",
34    [D.GREENSLIME] = "GREENSLIME",
35    [D.LIZMAN] = "LIZMAN",
36    [D.LIZMANFEEDING] = "LIZMANFEEDING",
37    [D.LIZMANJUMP] = "LIZMANJUMP",
38    [D.LIZMANSPITTING] = "LIZMANSPITTING",
39    [D.LIZMANSTAYPUT] = "LIZMANSTAYPUT",
40    [D.LIZTROOP] = "LIZTROOP",
41    [D.LIZTROOPDUCKING] = "LIZTROOPDUCKING",
42    [D.LIZTROOPJETPACK] = "LIZTROOPJETPACK",
43    [D.LIZTROOPJUSTSIT] = "LIZTROOPJUSTSIT",
44    [D.LIZTROOPONTOILET] = "LIZTROOPONTOILET",
45    [D.LIZTROOPRUNNING] = "LIZTROOPRUNNING",
46    [D.LIZTROOPSHOOT] = "LIZTROOPSHOOT",
47    [D.LIZTROOPSTAYPUT] = "LIZTROOPSTAYPUT",
48    [D.OCTABRAIN] = "OCTABRAIN",
49    [D.OCTABRAINSTAYPUT] = "OCTABRAINSTAYPUT",
50    [D.ORGANTIC] = "ORGANTIC",
51    [D.PIGCOP] = "PIGCOP",
52    [D.PIGCOPDIVE] = "PIGCOPDIVE",
53    [D.PIGCOPSTAYPUT] = "PIGCOPSTAYPUT",
54    [D.RAT] = "RAT",
55    [D.ROTATEGUN] = "ROTATEGUN",
56    [D.SHARK] = "SHARK",
57}
58
59local uniq = false
60
61function init(args)
62    if (#args == 1) then
63        local wr = function(s) io.stderr:write(s) end
64        wr("Usage: "..args[0].." "..args[1].." [-u] *.map ...\n")
65        wr("  -u: print only one pal-x-tilenum combination\n")
66    end
67
68    if (args[2]:sub(1,1)=="-") then
69        assert(args[2]=="-u", "Unknown option "..args[2])
70        uniq = true
71        return 3
72    end
73end
74
75function success(map, fn)
76    -- Have one at all?
77    local haveone = false
78
79    -- Have pal-x-tile combination?
80    -- [tile*256 + pal] = true
81    local havept = {}
82
83    for i=0,map.numsprites-1 do
84        local spr = map.sprite[i]
85        local picnum, pal = spr.picnum, spr.pal
86        local name = ENEMY_NAME[picnum]
87
88        if (name and pal~=0) then
89            if (not (name:match("^LIZTROOP") and pal==21)) then  -- those are handled by CON
90                if (not uniq or not havept[picnum*256 + pal]) then
91                    if (not haveone) then
92                        printf("%s:", fn)
93                        haveone = true
94                    end
95                    printf("%5d %3d %s", i, pal, name)
96                    havept[picnum*256 + pal] = true
97                end
98            end
99        end
100    end
101    if (haveone) then
102        print("")
103    end
104end
105