ref: 710b64171c4f486abbe52bcd03e225dc6761abc4
dir: /utils/genspr/
#!/bin/rc -e rfork n bind -a $home/p/pico /bin bind -a $home/p/sce/utils /bin ramfs -m /n/sce cp unit/^(\ terran/scv\ terran/control\ terran/tccShad\ zerg/drone\ zerg/mutalid\ zerg/hatchery\ zerg/zhashad\ thingy/tscglow\ neutral/min01\ neutral/min01Sha\ neutral/min02\ neutral/min02sha\ neutral/min03\ neutral/min03Sha\ )^.grp /n/sce/ pcx -9t tileset/badlands/ofire.pcx >/n/sce/ofire.bit cp tileset/badlands.^(wpe vr4 vx4) /n/sce/ cp SC_Unit_Palette.pal /n/sce/ cd /n/sce window -m awk ' function pipe(cmd){ if((cmd | getline x) < 0){ print cmd ": aborted" exit("aborted") } close(cmd) return x } function exec(cmd){ if(system(cmd) != 0){ print cmd ": aborted" exit("aborted") } close(cmd) } function unit17(u, i, r, n, fi, fo, fs, gf, frm, dim, rect, dx, dy){ n = split(units[u], a) gf = a[1] ".grp" split(pipe("grp -s " palfile " " gf), dim) for(i=6; i<=n; i++){ frm = a[i] * 17 for(r=0; r<17; r+=2){ fi = sprintf(gf ".%05d.bit", frm + r) fo = sprintf(u ".%02d.%02d.bit", i-5, r) fs = sprintf(u ".%02d.%02d.s.bit", i-5, r) split(pipe("read -c 60 " fi), rect) dx = rect[2] - (dim[1] / 2 - a[2]) dy = rect[3] - (dim[2] / 2 - a[3]) exec("scespr " fi " " fo " " dx " " dy) exec("scesha " fi " " fs " " dx+a[4] " " dy+a[5] " " a[4] " " a[5]) if(r != 16){ exec("rotate -l " fi " | iconv -u >" tmp) dx += dim[1] - rect[2] - rect[4] fo = sprintf(u ".%02d.%02d.bit", i-5, 31-r) fs = sprintf(u ".%02d.%02d.s.bit", i-5, 31-r) exec("scespr " tmp " " fo " " dx " " dy) exec("scesha " tmp " " fs " " dx+a[4] " " dy+a[5] " " a[4] " " a[5]) } } } exec("rm -f " tmp " " gf "*") } function glowspr17(u, i, r, n, fi, fo, gf, frm, dim, rect, dx, dy){ n = split(glows[u], a) gf = a[1] ".grp" split(pipe("grp -sx ofire.bit " gf), dim) for(i=4; i<=n; i++){ frm = a[i] * 17 for(r=0; r<17; r+=2){ fi = sprintf(gf ".%05d.bit", frm + r) fo = sprintf(u ".%02d.%02d.g.bit", i-4, r) split(pipe("read -c 60 " fi), rect) dx = -(dim[1] / 2 - a[2]) dy = -(dim[2] / 2 - a[3]) exec("crop -t " dx " " dy " " fi " >" fo) if(r != 16){ fo = sprintf(u ".%02d.%02d.g.bit", i-4, 31-r) dx += dim[1] - rect[2] - rect[4] exec("rotate -l " fi " | crop -t " dx " " dy " >" fo) } } } exec("rm -f " tmp " " gf "*") } function build(u, i, r, n, fi, fo, gf, frm, dim, rect, dx, dy){ n = split(builds[u], a) gf = a[1] ".grp" split(pipe("grp -s " palfile " " gf), dim) for(i=4; i<=n; i++){ frm = a[i] fi = sprintf(gf ".%05d.bit", frm) fo = sprintf(u ".%02d.00.bit", i-3) split(pipe("read -c 60 " fi), rect) dx = rect[2] - ((dim[1] / 2 - a[2]) >= 32 ? 32 : 0) dy = rect[3] - ((dim[2] / 2 - a[3]) >= 32 ? 32 : 0) exec("scespr " fi " " fo " " dx " " dy) } exec("rm -f " tmp " " gf "*") } function shad(u, i, r, n, fi, fo, gf, frm, dim, rect, dx, dy){ n = split(shads[u], a) gf = a[1] ".grp" split(pipe("grp -s " palfile " " gf), dim) for(i=4; i<=n; i++){ frm = a[i] fi = sprintf(gf ".%05d.bit", frm) fo = sprintf(u ".%02d.00.s.bit", i-4) split(pipe("read -c 60 " fi), rect) dx = rect[2] - ((dim[1] / 2 - a[2]) >= 32 ? 32 : 0) dy = rect[3] - ((dim[2] / 2 - a[3]) >= 32 ? 32 : 0) exec("sceshb " fi " " fo " " dx " " dy) } exec("rm -f " tmp " " gf "*") } function neutral(u, i, r, n, fi, fo, gf, sf, frm, dim, rect, srect, dx, dy){ n = split(neutrals[u], a) gf = a[1] ".grp" sf = a[2] ".grp" split(pipe("grp -s " palfile " " gf), dim) exec("grp -s " palfile " " sf " >/dev/null") for(i=5; i<=n; i++){ frm = a[i] fi = sprintf(gf ".%05d.bit", frm) fo = sprintf(u ".%02d.00.bit", i-5) split(pipe("read -c 60 " fi), rect) dx = 0 dy = -31 exec("iconv -c r8g8b8 " fi " | crop -t " dx " " dy " >" fo) fi = sprintf(sf ".%05d.bit", frm) fo = sprintf(u ".%02d.00.s.bit", i-5) split(pipe("read -c 60 " fi), srect) dx = srect[2] - 32 dy = srect[3] - 31 exec("sceshb " fi " " fo " " dx " " dy) } exec("rm -f " tmp " " gf "* " sf "* ") } function tiles(t, ntile){ exec("sctile " t) print "!s", 32, ntile*32 >tmp print "r = z == 0 ? 0 : Z" >>tmp # first tile is empty for(i=1; i<=ntile; i++){ printf "!r %s.%05d.bit a\n", t, i >>tmp printf "r = y >= %d && y < %d ? a[x,y-%d] : r\n", 32*(i-1), 32*i, 32*(i-1) >>tmp } print "!w r dicks" >>tmp exec("pico <" tmp) exec("iconv -c r8g8b8 dicks >" t ".bit") exec("rm -f dicks " tmp " " t ".[0-9]*bit") } BEGIN{ palfile = "SC_Unit_Palette.pal" tmp = "derp" # width/2 height/2 shadx shady frm.. units["scv"] = "scv 11 11 0 7 0" units["drone"] = "drone 11 11 0 7 0 1 2 3 4" units["mutalisk"] = "mutalid 22 22 0 42 0 1 2 3 4" # grp width/2 height/2 shadx shady frm.. glows["scv"] = "tscglow 11 11 0 1 2 3" # width/2 height/2 frm.. builds["control"] = "control 58 41 0" builds["hatchery"] = "hatchery 49 32 0 1 2 3" # grp shadgrp width/2 height/2 frm.. neutrals["mineral0"] = "min01 min01Sha 32 16 0 1 2 3" neutrals["mineral1"] = "min02 min02sha 32 16 0 1 2 3" neutrals["mineral2"] = "min03 min03Sha 32 16 0 1 2 3" # grp width/2 height/2 frm.. shads["control"] = "tccShad 58 41 0" shads["hatchery"] = "zhashad 49 32 0" for(u in units) unit17(u) for(u in glows) glowspr17(u) for(u in builds) build(u) for(u in shads) shad(u) for(u in neutrals) neutral(u) tiles("badlands", 24) } ' rm -f ofire.bit *.wpe *.vr4 *.vx4 *.pal #cp * /sys/games/lib/sce/