diff --git a/polymer/eduke32/source/lunatic/bcheck.lua b/polymer/eduke32/source/lunatic/bcheck.lua index 0eec78df3..091f93c12 100644 --- a/polymer/eduke32/source/lunatic/bcheck.lua +++ b/polymer/eduke32/source/lunatic/bcheck.lua @@ -94,6 +94,12 @@ function bcheck.level_idx(level) end end +function bcheck.linear_map_idx(idx) + if (not (idx >= 0 and idx <= con_lang.MAXLEVELS * con_lang.MAXVOLUMES)) then + error("invalid linear map index "..idx, 3) + end +end + function bcheck.quote_idx(qnum, onlyidx) if (not (qnum >= 0 and qnum < con_lang.MAXQUOTES)) then error("invalid quote number "..qnum, 3) diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index a39ba03cc..5102e52af 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -1946,6 +1946,11 @@ function _loadmapstate() ffiC.G_RestoreMapState() end +function _clearmapstate(idx) + bcheck.linear_map_idx(idx) + ffiC.G_FreeMapState(idx) +end + -- Gamevar persistence in the configuration file function _savegamevar(name, val) diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 69b8b009c..de38520e1 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -728,6 +728,7 @@ const char* G_PrintBestTime(void); void G_UpdateScreenArea(void); void G_SaveMapState(void); void G_RestoreMapState(void); +void G_FreeMapState(int32_t mapnum); ]] decl[[ diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index 1a05ee2ba..1c736dc40 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -249,4 +249,5 @@ G_PrintBestTime; G_UpdateScreenArea; G_SaveMapState; G_RestoreMapState; +G_FreeMapState; }; diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 7544fa84f..391723118 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -2727,7 +2727,7 @@ local Cinner = { / ACS":reset_acount()", resetcount = cmd() / ACS":set_count(0)", - resetplayer = cmd() -- NLCF + resetplayer = cmd() * #sp1 -- NLCF / "if (_con._VM_ResetPlayer2(_pli,0)) then _con.longjmp() end", resetplayerflags = cmd(R) -- NLCF / "if (_con._VM_ResetPlayer2(_pli,%1)) then _con.longjmp() end", @@ -2818,7 +2818,7 @@ local Cinner = { -- Persistence clearmapstate = cmd(R) - / handle.NYI, + / "_con._clearmapstate(%1)", loadmapstate = cmd() / "_con._loadmapstate()", savemapstate = cmd() diff --git a/polymer/eduke32/source/lunatic/test/mapstate.con b/polymer/eduke32/source/lunatic/test/mapstate.con index 06e904bea..137e5708e 100644 --- a/polymer/eduke32/source/lunatic/test/mapstate.con +++ b/polymer/eduke32/source/lunatic/test/mapstate.con @@ -3,9 +3,10 @@ // To warp to a particular map, press the steroids key. // Volume: player angle / 512, displayed on screen. // Level: current weapon. +// Clear mapstate: press [QuickKick] -define Q 400 -definequote Q ====== TEMP ======= +define Q_tmp 400 +definequote Q_tmp ====== TEMP ======= definequote 401 WILL WARP TO VOLUME %d @@ -24,6 +25,9 @@ definequote 412 definequote 413 definequote 414 +define Q_cms 500 +definequote Q_cms Cleared mapstate for volume %d level %d + // Test gamevar flags GAMEVAR_NODEFAULT and GAMEVAR_NORESET. // Global. define GV_NODEFAULT 1024 @@ -73,8 +77,8 @@ ends onevent EVENT_DISPLAYREST state calcvolume - qsprintf Q /*<-*/ 401 /**/ gs - gametext STARTALPHANUM 20 20 Q 0 0 0 0 0 xdim ydim + qsprintf Q_tmp /*<-*/ 401 /**/ gs + gametext STARTALPHANUM 20 20 Q_tmp 0 0 0 0 0 xdim ydim setvar y 40 setvar dq 403 @@ -148,6 +152,19 @@ onevent EVENT_USESTEROIDS startlevel gs currentweapon endevent +onevent EVENT_QUICKKICK + state calcvolume + + qsprintf Q_tmp Q_cms gs currentweapon + userquote Q_tmp + + // Calc linear map index. + mulvar gs 64 // MAXLEVELS (XXX: should be exposed via CON) + addvarvar gs currentweapon + + clearmapstate gs +endevent + onevent EVENT_ENTERLEVEL loadmapstate endevent