From f64fdf33844e4eb75fec02b965d15d5d96ff385a Mon Sep 17 00:00:00 2001 From: helixhorned Date: Tue, 10 Sep 2013 19:17:06 +0000 Subject: [PATCH] Add foreachmap.lua module 'colenemy', allow passing module name to findmaps.sh. The 'colenemy' module searches for colored enemies in maps, excluding pal-21 liztroops. DONT_BUILD. git-svn-id: https://svn.eduke32.com/eduke32@4056 1a8010ca-5511-0410-912e-c29ae57300e0 --- .../eduke32/source/lunatic/util/colenemy.lua | 102 ++++++++++++++++++ .../eduke32/source/lunatic/util/findmaps.sh | 16 ++- 2 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 polymer/eduke32/source/lunatic/util/colenemy.lua diff --git a/polymer/eduke32/source/lunatic/util/colenemy.lua b/polymer/eduke32/source/lunatic/util/colenemy.lua new file mode 100644 index 000000000..ab7a1202d --- /dev/null +++ b/polymer/eduke32/source/lunatic/util/colenemy.lua @@ -0,0 +1,102 @@ + +-- Search for enemies with nonzero pal. +-- foreachmap module. + +local build = require("build") +local D = build.readdefs("../../names.h") or error("Need ../../names.h") + +local assert = assert +local print = print +local string = require("string") + +local io = require("io") + +local function printf(fmt, ...) + print(string.format(fmt, ...)) +end + + +module(...) + + +local ENEMY_NAME = { + [D.BOSS1] = "BOSS1", + [D.BOSS1STAYPUT] = "BOSS1STAYPUT", + [D.BOSS2] = "BOSS2", + [D.BOSS3] = "BOSS3", + [D.BOSS4] = "BOSS4", + [D.BOSS4STAYPUT] = "BOSS4STAYPUT", + [D.COMMANDER] = "COMMANDER", + [D.COMMANDERSTAYPUT] = "COMMANDERSTAYPUT", + [D.DRONE] = "DRONE", + [D.GREENSLIME] = "GREENSLIME", + [D.LIZMAN] = "LIZMAN", + [D.LIZMANFEEDING] = "LIZMANFEEDING", + [D.LIZMANJUMP] = "LIZMANJUMP", + [D.LIZMANSPITTING] = "LIZMANSPITTING", + [D.LIZMANSTAYPUT] = "LIZMANSTAYPUT", + [D.LIZTROOP] = "LIZTROOP", + [D.LIZTROOPDUCKING] = "LIZTROOPDUCKING", + [D.LIZTROOPJETPACK] = "LIZTROOPJETPACK", + [D.LIZTROOPJUSTSIT] = "LIZTROOPJUSTSIT", + [D.LIZTROOPONTOILET] = "LIZTROOPONTOILET", + [D.LIZTROOPRUNNING] = "LIZTROOPRUNNING", + [D.LIZTROOPSHOOT] = "LIZTROOPSHOOT", + [D.LIZTROOPSTAYPUT] = "LIZTROOPSTAYPUT", + [D.OCTABRAIN] = "OCTABRAIN", + [D.OCTABRAINSTAYPUT] = "OCTABRAINSTAYPUT", + [D.ORGANTIC] = "ORGANTIC", + [D.PIGCOP] = "PIGCOP", + [D.PIGCOPDIVE] = "PIGCOPDIVE", + [D.PIGCOPSTAYPUT] = "PIGCOPSTAYPUT", + [D.RAT] = "RAT", + [D.ROTATEGUN] = "ROTATEGUN", + [D.SHARK] = "SHARK", +} + +local uniq = false + +function init(args) + if (#args == 1) then + local wr = function(s) io.stderr:write(s) end + wr("Usage: "..args[0].." "..args[1].." [-u] *.map ...\n") + wr(" -u: print only one pal-x-tilenum combination\n") + end + + if (args[2]:sub(1,1)=="-") then + assert(args[2]=="-u", "Unknown option "..args[2]) + uniq = true + return 3 + end +end + +function success(map, fn) + -- Have one at all? + local haveone = false + + -- Have pal-x-tile combination? + -- [tile*256 + pal] = true + local havept = {} + + for i=0,map.numsprites-1 do + local spr = map.sprite[i] + local picnum, pal = spr.picnum, spr.pal + local name = ENEMY_NAME[picnum] + + if (name and pal~=0) then + if (not (name:match("^LIZTROOP") and pal==21)) then -- those are handled by CON + if (not uniq or not havept[picnum*256 + pal]) then + if (not haveone) then + printf("%s:", fn) + haveone = true + end + printf("%5d %3d %s", i, pal, name) + havept[picnum*256 + pal] = true + end + end + end + end + if (haveone) then + print("") + end +end diff --git a/polymer/eduke32/source/lunatic/util/findmaps.sh b/polymer/eduke32/source/lunatic/util/findmaps.sh index 74a4752bc..93a5e7d7a 100755 --- a/polymer/eduke32/source/lunatic/util/findmaps.sh +++ b/polymer/eduke32/source/lunatic/util/findmaps.sh @@ -9,7 +9,7 @@ if [ -z "$2" ]; then fi if [ -z "$ok" ]; then - echo "Usage: $0 " + echo "Usage: $0 " exit 1 fi @@ -19,4 +19,16 @@ if [ "$idx" != 0 ]; then LOPT= fi -find $LOPT "$1" -iname '*.map' -print0 | xargs -0 ./foreachmap.lua "-e$2" +FN="$1" +ARG="$2" + +idx=$(expr match "$ARG" '.*lua$') +if [ "$idx" == 0 ]; then + ARG="-e$ARG" + find $LOPT "$FN" -iname '*.map' -print0 | xargs -0 ./foreachmap.lua "$ARG" +else + shift + # So that you can e.g. do + # ./findmaps.sh ~/.eduke32 ./colenemy.lua -u + find $LOPT "$FN" -iname '*.map' -print0 | xargs -0 ./foreachmap.lua "$@" +fi