mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-16 01:11:44 +00:00
a.m32: add state 'for_sprites_near_picnum'.
The state quries the user for four values: ref. picnum, target picnum, max. ldist and a lotag. Then, for all sprites i (of ref. picnum), for all sprites j (of target picnum), if ldist(i,j)<=maxldist, sprite j's lotag is changed to the provided one. Also add lunatic/test/maputil.lua, containing a similar function but allowing to customize the selection predicates of the ref. and target sprites, as well as the action to carry out. git-svn-id: https://svn.eduke32.com/eduke32@4414 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
66947aed95
commit
6458c0ba34
2 changed files with 92 additions and 0 deletions
|
@ -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
|
||||
|
|
63
polymer/eduke32/source/lunatic/test/maputil.lua
Normal file
63
polymer/eduke32/source/lunatic/test/maputil.lua
Normal file
|
@ -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
|
||||
-- <spri> is a reference to sprite i
|
||||
-- use_sprite_j_func: function(sprj, spri, ud), where
|
||||
-- <spri> is a reference to sprite i
|
||||
-- <sprj> is a reference to sprite j
|
||||
--
|
||||
-- csfunc: function(userdata, process_sprite_j_func), where
|
||||
-- <userdata> is passed as <ud> to the functions described above
|
||||
-- <process_sprite_j_func>: 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 <picnumi>,
|
||||
-- for all sprites j of tile <picnumj> that are closer to sprite i than <dist> [*],
|
||||
-- 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
|
Loading…
Reference in a new issue