diff --git a/polymer/eduke32/package/sdk/samples/a.m32 b/polymer/eduke32/package/sdk/samples/a.m32 index 98524326d..82892b457 100644 --- a/polymer/eduke32/package/sdk/samples/a.m32 +++ b/polymer/eduke32/package/sdk/samples/a.m32 @@ -1610,6 +1610,35 @@ defstate uniformfloor set sector[i].floorz avgz ends +defstate for_sprites_near_picnum + "Ch. lotag for near spr." + + var ii dst + var picnumi picnumj maxldist lotag + + getnumberfromuser picnumi "picnum i: " MAXTILES 10 + ifvarl picnumi 0 break + getnumberfromuser picnumj "picnum j: " MAXTILES 10 + ifvarl picnumj 0 break + + getnumberfromuser maxldist "max ldist: " 65536 8 + ifvarl maxldist 0 break + + getnumberfromuser lotag "lotag (unsigned) to change to: " 65536 8 + ifvarl lotag 0 break + + for i allsprites ife sprite[i].picnum picnumi + for j allsprites ife sprite[j].picnum picnumj + { + ldist dst i j + ifle dst maxldist + set sprite[j].lotag lotag + } + + qsprintf TQUOTE "changed lotag of sprites w/ tile %d near those w/ tile %d to %d" picnumj picnumi lotag + quote TQUOTE +ends + // This must be *compiled* with script_expertmode /* defstate setstartpos diff --git a/polymer/eduke32/source/lunatic/test/maputil.lua b/polymer/eduke32/source/lunatic/test/maputil.lua new file mode 100644 index 000000000..8d6af385f --- /dev/null +++ b/polymer/eduke32/source/lunatic/test/maputil.lua @@ -0,0 +1,63 @@ + +local xmath = require("xmath") + +local sprite = sprite + +-- + +local maputil = {} + +-- csfunc = maputil.CreateCrossSpriteFunc(use_sprite_i_func, use_sprite_j_func) +-- +-- use_sprite_i_func: function(spri, ud), where +-- is a reference to sprite i +-- use_sprite_j_func: function(sprj, spri, ud), where +-- is a reference to sprite i +-- is a reference to sprite j +-- +-- csfunc: function(userdata, process_sprite_j_func), where +-- is passed as to the functions described above +-- : function(sprj, spri, ud), the user-provided +-- function that processes sprite j in some way +function maputil.CreateCrossSpriteFunc(use_sprite_i_func, use_sprite_j_func) + return function(userdata, process_sprite_j_func) + for i in sprite.all() do + if (use_sprite_i_func(sprite[i], userdata)) then + for j in sprite.all() do + if (use_sprite_j_func(sprite[j], sprite[i], userdata)) then + process_sprite_j_func(sprite[j], sprite[i], userdata) + end + end + end + end + end +end + + +-- Functions for "for all sprites Y of tile X that are closer than D, ..." +-- Passed userdefs: { picnumi, picnumj, maxldist } +local function snearpic_usei(spr, ud) + return spr.picnum == ud[1] +end + +local function snearpic_usej(sprj, spri, ud) + return sprj.picnum == ud[2] and xmath.ldist(spri, sprj) <= ud[3] +end + +local snearpic_func = maputil.CreateCrossSpriteFunc(snearpic_usei, snearpic_usej) + +-- maputil.for_sprites_near_picnum(picnumi, picnumj, dist, process_sprite_func) +-- +-- Runs the following loop: +-- +-- for all sprites i with tile , +-- for all sprites j of tile that are closer to sprite i than [*], +-- call process_sprite_func(sprite[j], sprite[i]) +-- +-- [*] using xmath.ldist() +function maputil.for_sprites_near_picnum(picnumi, picnumj, dist, process_sprite_func) + snearpic_func({picnumi, picnumj, dist}, process_sprite_func) +end + + +return maputil