raze/polymer/eduke32/source/lunatic/test/damagehplane.lua
helixhorned 0c69779b98 Scripting: Add EVENT_DAMAGEHPLANE and document it in Lunatic doc Appendix B.
Also add test/damagehplane.lua with these demonstrations:
 - custom breakable ceilings
 - breakable TROR glass

git-svn-id: https://svn.eduke32.com/eduke32@4206 1a8010ca-5511-0410-912e-c29ae57300e0
2013-12-20 18:31:33 +00:00

105 lines
2.9 KiB
Lua

local bit = require("bit")
local band = bit.band
local tostring = tostring
local gv = gv
local actor = actor
local sector, wall, sprite = sector, wall, sprite
local printf = printf
local sectorsofbunch = sectorsofbunch
local con = require("con")
local D = require("CON.DEFS")
----------
local TROR_GLASSBREAKER = 2959 -- red 'T'
-- Actor controlling the timing of a TROR hplane breaking.
gameactor
{
TROR_GLASSBREAKER,
function(aci, pli, dist)
local spr = sprite[aci]
if (not (spr.lotag == 712 and spr.hitag == 119)) then -- check BREAKER_MAGIC
sprite.changestat(aci, actor.STAT.DEFAULT)
return
end
local cnt = actor[aci]:get_count()
local finish = (cnt >= 6)
if (cnt == 0) then
-- NOTE: INTERNAL interface, DON'T USE!
con._sound(aci, D.GLASS_BREAKING)
end
local bunchnum = spr.extra
for sectnum, what in sectorsofbunch(bunchnum, gv.BOTH_CF) do
local cf = sector[sectnum][what]
-- TODO: provide cf:set_picnum()
if (what=="ceiling") then
sector[sectnum]:set_ceilingpicnum(D.GLASS2 + cnt)
else
sector[sectnum]:set_floorpicnum(D.GLASS2 + cnt)
end
cf.statbits:clear(sector.STAT.BLOCK + sector.STAT.HITSCAN)
if (finish) then
cf.statbits:clear(sector.STAT.TRANS_BITMASK)
end
end
if (finish) then
con.killit()
end
end
}
local DHP = sector.DAMAGEHPLANE
gameevent
{
gv.EVENT_DAMAGEHPLANE,
function(aci, pli, dist)
local what, sectnum = sector.damagehplane_whatsect(gv.RETURN)
local sec = sector[sectnum]
-- Part I: make various screens breakable when it's a ceiling picnum.
if (what == "ceiling") then
-- hit ceiling
if (sec.ceilingpicnum >= 263 and sec.ceilingpicnum <= 275) then
sec:set_ceilingpicnum(D.W_SCREENBREAK + gv.krand()%3)
gv.RETURN = DHP.GLASSBREAK
return
end
end
-- Part II: breakable TROR hplanes
local cf = sec[what]
-- printf("damage %s of sector %d (pic %d, bunch %d, hittable: %s)", what, sectnum,
-- cf.picnum, cf.bunch, tostring(cf.statbits:test(sector.STAT.HITSCAN)))
if (cf.bunch >= 0 and (cf.picnum==198 or cf.picnum==D.GLASS2) and
cf.statbits:test(sector.STAT.HITSCAN)) then
local bi = con.insertsprite(TROR_GLASSBREAKER, wall[sec.wallptr], sectnum, aci, actor.STAT.ACTOR)
local breaker = sprite[bi]
breaker.cstat = sprite.CSTAT.INVISIBLE
breaker.lotag, breaker.hitag = 712, 119 -- BREAKER_MAGIC
breaker.extra = cf.bunch
gv.RETURN = DHP.SUPPRESS
return
end
gv.RETURN = DHP.DEFAULT
end
}