diff --git a/polymer/eduke32/source/lunatic/bcheck.lua b/polymer/eduke32/source/lunatic/bcheck.lua index ac9d841e4..29ea4c9c8 100644 --- a/polymer/eduke32/source/lunatic/bcheck.lua +++ b/polymer/eduke32/source/lunatic/bcheck.lua @@ -89,5 +89,11 @@ function bcheck.quote_idx(qnum, onlyidx) return cstr end +function bcheck.top_level(funcname) + if (ffiC.g_elCallDepth > 0) then + error("Invalid use of "..funcname..": must be called from top level", 3) + end +end + return bcheck diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 3675f391f..e0f10ed59 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -12,6 +12,7 @@ local bit = require("bit") local io = require("io") local math = require("math") local geom = require("geom") +local bcheck = require("bcheck") local con_lang = require("con_lang") local byte = require("string").byte @@ -93,17 +94,19 @@ end ---=== ACTION / MOVE / AI ===--- function action(name, ...) + bcheck.top_level("action") action_or_move("action", 5, def.action, name, ...) end function move(name, ...) + bcheck.top_level("move") action_or_move("move", 2, def.move, name, ...) end - +-- Get action or move for an 'ai' definition. local function get_action_or_move(what, val, argi) if (val == nil) then - return {} -- will init the struct to all zeros + return {} -- ffi.new will init the struct to all zeros elseif (type(val)=="string") then local am = def[what][val] if (am==nil) then @@ -112,13 +115,20 @@ local function get_action_or_move(what, val, argi) return am elseif (ffi.istype("con_"..what.."_t", val)) then return val + elseif (type(val)=="number") then + if (val==0 or val==1) then + -- Create an action or move with an ID of 0 or 1 but all other + -- fields cleared. + return ffi.new("con_"..what.."_t", val) + end end - -- TODO: literal number actions/moves? - error("bad argument #"..argi.." to ai: must be string or "..what, 3) + error("bad argument #"..argi.." to ai: must be string or (literal) "..what, 3) end function ai(name, action, move, flags) + bcheck.top_level("ai") + if (lastid.ai <= -(2^31)) then error("Too many AIs defined", 2); end @@ -143,7 +153,6 @@ end ---=== RUNTIME CON FUNCTIONS ===--- -local bcheck = require("bcheck") local check_sector_idx = bcheck.sector_idx local check_tile_idx = bcheck.tile_idx local check_sprite_idx = bcheck.sprite_idx @@ -1584,7 +1593,7 @@ function _setaspect(viewingrange, yxaspect) end function _setgamepalette(pli, basepal) - ffiC.P_SetGamePalette(player[pli], basepal) + ffiC.P_SetGamePalette(player[pli], basepal, 2+16) end -- Gamevar persistence in the configuration file diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 0890f025f..abf4b1cb0 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -1360,9 +1360,7 @@ G_._G = G_ local gameactor_internal = gameactor_internal -- included in lunatic.c -- gameactor(tilenum [, strength [, act [, mov [, movflags]]]], actor_func) local function our_gameactor(tilenum, ...) - if (ffiC.g_elCallDepth > 0) then - error("Invalid use of gameactor: must be called from top level", 2) - end + bcheck.top_level("gameactor") local args = {...} if (type(tilenum) ~= "number") then diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 91df19fc6..929280390 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -308,7 +308,8 @@ function on.actor_end(usertype, tsamm, codetab) local str = "" for i=2,math.min(#tsamm,4) do if ((i==3 or i==4) and tsamm[i]=="0") then - -- HACK, gameactor() currently doesn't support literals + -- HACK, gameactor() currently doesn't support literals for actions + -- and moves. tsamm[i] = "'NO'" end str = str .. tostring(tsamm[i]).."," @@ -603,11 +604,12 @@ local function do_define_composite(labeltype, identifier, ...) return end - -- Fill up omitted arguments with zeros. + -- Fill up omitted arguments denoting composites with zeros. local isai = (labeltype == LABEL.AI) local args = {...} for i=#args+1,labeltype do - -- passing nil to con.ai will make the action/move the null one + -- Passing nil/nothing as remaining args to con.ai will make the + -- action/move the null one. args[i] = (isai and i<=2) and "nil" or 0 end