diff --git a/polymer/eduke32/source/lunatic/doc/lunatic.txt b/polymer/eduke32/source/lunatic/doc/lunatic.txt index dced6aa22..c0cbb37b6 100644 --- a/polymer/eduke32/source/lunatic/doc/lunatic.txt +++ b/polymer/eduke32/source/lunatic/doc/lunatic.txt @@ -2242,19 +2242,27 @@ cheat give a different ``full'' amount. A negative value is ignored. ~~~~~~~~~~~~~~~~~~~~ Triggered when a ceiling or a floor (collectively called ``hplane'') is -determined as being damaged. The event receives `RETURN` as a value that can be -decoded into two parts by passing it to `sector.damagehplane_whatsect`: +determined as being damaged. The event receives `RETURN` in the variable +`gv.RETURN` as well as the third, `dist` argument to the event +<>.footnote:[Passing `RETURN` in the `dist` +argument serves the possibility to create chained callbacks for +`EVENT_DAMAGEHPLANE`. Otherwise, once `gv.RETURN` were assigned to, there would +be no way to obtain its original value in subsequent chained callbacks.] This +value can be decoded into two parts by passing it to +`sector.damagehplane_whatsect`: [source] ---------- -local what, sectnum = sector.damagehplane_whatsect(gv.RETURN) +function(aci, pli, RETURN) + local what, sectnum = sector.damagehplane_whatsect(RETURN) + -- (...) ---------- Then, * `what` is one of the strings `'ceiling'` or `'floor'` and * `sectnum` is the sector whose hplane is considered to be damaged. -When `EVENT_DAMAGEHPLANE` is left, `RETURN` is examined to determine the +When `EVENT_DAMAGEHPLANE` is left, `gv.RETURN` is examined to determine the further action. It may be one of three values given by `sector.DAMAGEHPLANE` (abbreviated `DHP` in the following): diff --git a/polymer/eduke32/source/lunatic/test/damagehplane.lua b/polymer/eduke32/source/lunatic/test/damagehplane.lua index 486d40324..3bae93bdf 100644 --- a/polymer/eduke32/source/lunatic/test/damagehplane.lua +++ b/polymer/eduke32/source/lunatic/test/damagehplane.lua @@ -59,10 +59,10 @@ local DHP = sector.DAMAGEHPLANE gameevent { - gv.EVENT_DAMAGEHPLANE, + "DAMAGEHPLANE", - function(aci, pli, dist) - local what, sectnum = sector.damagehplane_whatsect(gv.RETURN) + function(aci, pli, RETURN) + local what, sectnum = sector.damagehplane_whatsect(RETURN) local sec = sector[sectnum] -- Part I: make various screens breakable when it's a ceiling picnum. @@ -71,10 +71,22 @@ gameevent if (sec.ceilingpicnum >= 263 and sec.ceilingpicnum <= 275) then sec:set_ceilingpicnum(D.W_SCREENBREAK + gv.krand()%3) gv.RETURN = DHP.GLASSBREAK - return + return con.longjmp() end end + gv.RETURN = DHP.DEFAULT + end +} + +gameevent +{ + "DAMAGEHPLANE", + + function(aci, pli, RETURN) + local what, sectnum = sector.damagehplane_whatsect(RETURN) + local sec = sector[sectnum] + -- Part II: breakable TROR hplanes local cf = sec[what] -- printf("damage %s of sector %d (pic %d, bunch %d, hittable: %s)", what, sectnum, @@ -90,7 +102,7 @@ gameevent breaker.extra = cf.bunch gv.RETURN = DHP.SUPPRESS - return + return con.longjmp() end gv.RETURN = DHP.DEFAULT diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 6b0bf4082..6970f5c70 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -1880,7 +1880,9 @@ int32_t Sect_DamageCeilingOrFloor(int32_t floorp, int32_t sn) int32_t i, j; const int32_t RETURN_in = floorp ? 131072+sn : 65536+sn; - int32_t ret = VM_OnEvent(EVENT_DAMAGEHPLANE, g_player[screenpeek].ps->i, screenpeek, -1, RETURN_in); + // NOTE: pass RETURN in the dist argument, too. + int32_t ret = VM_OnEvent(EVENT_DAMAGEHPLANE, g_player[screenpeek].ps->i, screenpeek, + RETURN_in, RETURN_in); if (ret < 0) return 0;