2012-04-07 20:10:03 +00:00
|
|
|
-- LunaCON CON to Lunatic translator
|
|
|
|
-- requires LPeg, http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html
|
|
|
|
|
2012-12-09 13:24:28 +00:00
|
|
|
local require = require
|
2012-04-07 20:10:03 +00:00
|
|
|
local lpeg = require("lpeg")
|
|
|
|
|
2013-01-01 15:24:28 +00:00
|
|
|
local bit
|
2012-12-09 13:24:28 +00:00
|
|
|
local math = require("math")
|
|
|
|
local string = require("string")
|
|
|
|
local table = require("table")
|
|
|
|
|
2012-12-09 13:24:39 +00:00
|
|
|
|
2012-12-09 13:24:28 +00:00
|
|
|
local arg = arg
|
|
|
|
|
|
|
|
local assert = assert
|
2013-06-07 10:18:12 +00:00
|
|
|
local error = error
|
2013-01-13 16:40:07 +00:00
|
|
|
local ipairs = ipairs
|
2013-02-25 15:31:09 +00:00
|
|
|
local loadstring = loadstring
|
2012-12-09 13:24:28 +00:00
|
|
|
local pairs = pairs
|
|
|
|
local pcall = pcall
|
|
|
|
local print = print
|
2013-03-03 16:06:16 +00:00
|
|
|
local setmetatable = setmetatable
|
2012-12-09 13:24:28 +00:00
|
|
|
local tonumber = tonumber
|
2012-12-23 19:24:16 +00:00
|
|
|
local tostring = tostring
|
2012-12-09 13:24:28 +00:00
|
|
|
local type = type
|
2012-12-28 17:18:02 +00:00
|
|
|
local unpack = unpack
|
2012-12-09 13:24:28 +00:00
|
|
|
|
2012-12-29 15:21:24 +00:00
|
|
|
-- non-nil if running from EDuke32
|
|
|
|
-- (read_into_string~=nil iff string.dump==nil)
|
|
|
|
local read_into_string = read_into_string
|
2013-01-01 15:24:22 +00:00
|
|
|
local ffi, ffiC
|
2012-12-29 15:21:24 +00:00
|
|
|
|
2013-02-28 17:30:15 +00:00
|
|
|
if (string.dump) then -- running stand-alone
|
|
|
|
local ljp = pcall(function() require("ffi") end)
|
|
|
|
-- "lbit" is the same module as LuaJIT's "bit" (LuaBitOp:
|
|
|
|
-- http://bitop.luajit.org/), but under a different name for (IMO) less
|
|
|
|
-- confusion. Useful for running with Rio Lua for cross-checking.
|
|
|
|
bit = ljp and require("bit") or require("lbit")
|
2012-06-17 19:45:33 +00:00
|
|
|
require("strict")
|
2013-01-01 15:24:22 +00:00
|
|
|
else
|
2013-01-01 15:24:28 +00:00
|
|
|
bit = require("bit")
|
2013-01-01 15:24:22 +00:00
|
|
|
ffi = require("ffi")
|
|
|
|
ffiC = ffi.C
|
2012-06-17 19:45:33 +00:00
|
|
|
end
|
|
|
|
|
2012-04-29 20:54:06 +00:00
|
|
|
|
2013-05-24 13:54:27 +00:00
|
|
|
|
2012-12-23 19:24:16 +00:00
|
|
|
module("lunacon")
|
2012-12-09 13:24:28 +00:00
|
|
|
|
|
|
|
|
2012-06-17 19:45:33 +00:00
|
|
|
-- I think that the "too many pending calls/choices" is unavoidable in general.
|
|
|
|
-- This limit is of course still arbitrary, but writing long if/else cascades
|
2012-04-29 20:54:06 +00:00
|
|
|
-- in CON isn't pretty either (though sometimes necessary because nested switches
|
|
|
|
-- don't work?)
|
|
|
|
-- See also: http://lua-users.org/lists/lua-l/2010-03/msg00086.html
|
|
|
|
lpeg.setmaxstack(1024);
|
|
|
|
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
local Pat, Set, Range, Var = lpeg.P, lpeg.S, lpeg.R, lpeg.V
|
2013-03-03 16:06:12 +00:00
|
|
|
local POS, Cc, Ctab = lpeg.Cp, lpeg.Cc, lpeg.Ct
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-05 13:09:31 +00:00
|
|
|
-- CON language definitions (among other things, all keywords pattern).
|
2012-11-30 18:57:40 +00:00
|
|
|
local conl = require("con_lang")
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
local function match_until(matchsp, untilsp) -- (!untilsp matchsp)* in PEG
|
|
|
|
-- sp: string or pattern
|
|
|
|
return (matchsp - Pat(untilsp))^0
|
|
|
|
end
|
|
|
|
|
2013-06-13 17:11:06 +00:00
|
|
|
local format = string.format
|
2013-05-24 13:54:27 +00:00
|
|
|
--[[
|
2013-06-13 17:11:06 +00:00
|
|
|
format = function(fmt, ...)
|
2013-05-24 13:54:27 +00:00
|
|
|
local ok, res = pcall(string.format, fmt, ...)
|
|
|
|
if (not ok) then
|
|
|
|
error(string.format("FAILED format(%q, ...) | message: %s", fmt, res))
|
|
|
|
end
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
--]]
|
2012-11-30 18:57:40 +00:00
|
|
|
|
2012-06-10 18:56:18 +00:00
|
|
|
local function printf(fmt, ...)
|
2012-11-30 18:57:40 +00:00
|
|
|
print(format(fmt, ...))
|
2012-06-10 18:56:18 +00:00
|
|
|
end
|
|
|
|
|
2013-07-13 21:04:41 +00:00
|
|
|
--- some constants
|
|
|
|
|
|
|
|
local C = {
|
|
|
|
-- These two are not used except for predefined labels.
|
|
|
|
-- NOTE: in-game, MAXSPRITES may be 4096 for a V7 build!
|
|
|
|
MAXSTATUS = ffiC and ffiC.MAXSTATUS or 1024,
|
|
|
|
MAXSPRITES = ffiC and ffiC.MAXSPRITES or 16384,
|
|
|
|
|
|
|
|
MAXTILES = ffiC and ffiC.MAXTILES or 30720,
|
|
|
|
MAX_WEAPONS = ffiC and ffiC.MAX_WEAPONS or 12,
|
|
|
|
}
|
2012-06-10 18:56:18 +00:00
|
|
|
|
|
|
|
---=== semantic action functions ===---
|
|
|
|
|
2012-06-10 18:56:21 +00:00
|
|
|
local inf = 1/0
|
2012-06-17 19:45:33 +00:00
|
|
|
local NaN = 0/0
|
2012-06-10 18:56:21 +00:00
|
|
|
|
|
|
|
-- Last keyword position, for error diagnosis.
|
|
|
|
local g_lastkwpos = nil
|
|
|
|
local g_lastkw = nil
|
|
|
|
local g_badids = {} -- maps bad id strings to 'true'
|
|
|
|
|
|
|
|
local g_recurslevel = -1 -- 0: base CON file, >0 included
|
2012-06-13 23:13:26 +00:00
|
|
|
local g_filename = "???"
|
2012-06-10 18:56:21 +00:00
|
|
|
local g_directory = "" -- with trailing slash if not empty
|
2012-12-09 13:24:28 +00:00
|
|
|
local g_maxerrors = 20
|
2012-06-10 18:56:21 +00:00
|
|
|
local g_numerrors = 0
|
|
|
|
|
2013-01-26 17:08:02 +00:00
|
|
|
-- Default directory to search for GAME.CON etc.
|
|
|
|
-- Stand-alone LunaCON only.
|
|
|
|
local g_defaultDir = nil
|
|
|
|
|
2012-12-03 18:24:33 +00:00
|
|
|
-- Warning options. Key names are the same as cmdline options, e.g.
|
|
|
|
-- -Wno-bad-identifier for disabling the "bad identifier" warning.
|
2013-03-17 18:11:44 +00:00
|
|
|
local g_warn = { ["not-redefined"]=true, ["bad-identifier"]=false,
|
2013-03-17 18:11:47 +00:00
|
|
|
["number-conversion"]=true, ["system-gamevar"]=true,
|
2014-02-08 14:37:47 +00:00
|
|
|
["error-bad-getactorvar"]=false, ["chained-loadactor"]=true,
|
|
|
|
["never-used-gamevar"]=false, ["never-read-gamevar"]=false, }
|
2012-12-03 18:24:33 +00:00
|
|
|
|
2013-03-03 16:06:32 +00:00
|
|
|
-- Code generation and output options.
|
2013-03-15 16:56:07 +00:00
|
|
|
local g_cgopt = { ["no"]=false, ["debug-lineinfo"]=false, ["gendir"]=nil,
|
2013-06-01 20:09:41 +00:00
|
|
|
["cache-sap"]=false, ["error-nostate"]=true,
|
2014-01-24 21:39:04 +00:00
|
|
|
["playervar"]=true, ["trapv"]=false, ["wrapv"]=false,
|
2014-02-01 16:19:59 +00:00
|
|
|
["bad-getactorvar-use-pli"]=false,
|
2014-02-28 20:33:46 +00:00
|
|
|
["error-nonlocal-userdef"]=true,
|
|
|
|
["error-negative-tag-write"]=false, }
|
2013-06-01 20:09:41 +00:00
|
|
|
|
2013-03-15 16:56:07 +00:00
|
|
|
local function csapp() return g_cgopt["cache-sap"] end
|
2013-01-13 16:40:32 +00:00
|
|
|
|
2013-07-13 21:04:50 +00:00
|
|
|
local function handle_cmdline_arg(str)
|
|
|
|
if (str:sub(1,1)=="-") then
|
|
|
|
if (#str == 1) then
|
|
|
|
printf("Warning: input from stdin not supported")
|
|
|
|
else
|
|
|
|
local ok = false
|
|
|
|
local kind = str:sub(2,2)
|
|
|
|
|
|
|
|
-- -W(no-)*: warnings
|
|
|
|
if (kind=="W" and #str >= 3) then
|
|
|
|
local val = true
|
|
|
|
local warnstr = str:sub(3)
|
|
|
|
|
|
|
|
if (warnstr == "all") then
|
|
|
|
-- Enable all warnings.
|
|
|
|
for wopt in pairs(g_warn) do
|
|
|
|
g_warn[wopt] = true
|
|
|
|
end
|
|
|
|
ok = true
|
|
|
|
else
|
|
|
|
-- Enable or disable a particular warning.
|
|
|
|
if (warnstr:sub(1,3)=="no-") then
|
|
|
|
val = false
|
|
|
|
warnstr = warnstr:sub(4)
|
|
|
|
end
|
|
|
|
|
|
|
|
if (type(g_warn[warnstr])=="boolean") then
|
|
|
|
g_warn[warnstr] = val
|
|
|
|
ok = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- -fno* special handling
|
|
|
|
elseif (str:sub(2)=="fno") then
|
|
|
|
-- Disable printing code entirely.
|
|
|
|
g_cgopt["no"] = true
|
|
|
|
ok = true
|
|
|
|
elseif (str:sub(2)=="fno=onlycheck") then
|
|
|
|
-- Disable printing code, only do syntax check of gen'd code.
|
|
|
|
g_cgopt["no"] = "onlycheck"
|
|
|
|
ok = true
|
|
|
|
|
|
|
|
-- -fgendir=<directory>: specify directory for generated code
|
|
|
|
elseif (str:sub(2,9)=="fgendir=" and #str >= 10) then
|
|
|
|
g_cgopt["gendir"] = str:sub(10)
|
|
|
|
ok = true
|
|
|
|
|
|
|
|
-- -f(no-)*: code generation options
|
|
|
|
elseif (kind=="f" and #str >= 3) then
|
|
|
|
local val = true
|
|
|
|
local cgstr = str:sub(3)
|
|
|
|
|
|
|
|
if (cgstr:sub(1,3)=="no-") then
|
|
|
|
val = false
|
|
|
|
cgstr = cgstr:sub(4)
|
|
|
|
end
|
|
|
|
|
|
|
|
if (type(g_cgopt[cgstr])=="boolean") then
|
|
|
|
g_cgopt[cgstr] = val
|
|
|
|
ok = true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- -I<directory>: default search directory (only ONCE, not search path)
|
|
|
|
elseif (kind=="I" and #str >= 3) then
|
|
|
|
g_defaultDir = str:sub(3)
|
|
|
|
ok = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if (not ffi and not ok) then
|
|
|
|
printf("Warning: Unrecognized option %s", str)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Handle command line arguments. Has to happen before pattern construction,
|
|
|
|
-- because some of them depend on codegen options (specifically, -ftrapv,
|
|
|
|
-- -fwrapv).
|
|
|
|
if (string.dump) then
|
|
|
|
-- running stand-alone
|
|
|
|
local i = 1
|
|
|
|
while (arg[i]) do
|
|
|
|
if (handle_cmdline_arg(arg[i])) then
|
|
|
|
table.remove(arg, i) -- remove processed cmdline arg
|
|
|
|
else
|
|
|
|
i = i+1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- running from EDuke32
|
|
|
|
local i=0
|
|
|
|
while (ffiC.g_argv[i] ~= nil) do
|
|
|
|
handle_cmdline_arg(ffi.string(ffiC.g_argv[i]))
|
|
|
|
i = i+1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-28 20:33:46 +00:00
|
|
|
if (g_cgopt["error-negative-tag-write"]) then
|
|
|
|
conl.setup_negative_tag_check("_st")
|
|
|
|
end
|
|
|
|
|
2013-02-28 17:29:58 +00:00
|
|
|
-- Stack with *true* on top if the innermost block is a "whilevar*n".
|
|
|
|
local g_isWhile = {}
|
|
|
|
-- Sequence number of 'while' statements, used to implement CON "break" inside
|
|
|
|
-- whilevar*n, which really behaves like what sane languages call "continue"...
|
|
|
|
local g_whilenum = 0
|
2012-07-01 22:11:17 +00:00
|
|
|
|
|
|
|
---=== Code generation ===---
|
2013-01-13 16:40:32 +00:00
|
|
|
local GVFLAG = {
|
|
|
|
PERPLAYER=1, PERACTOR=2, PERX_MASK=3,
|
|
|
|
SYSTEM = 0x00000800,
|
|
|
|
READONLY = 0x00001000,
|
2013-01-24 20:03:02 +00:00
|
|
|
|
|
|
|
NODEFAULT = 0x00000400, -- don't reset on actor spawn
|
|
|
|
NORESET = 0x00020000, -- don't reset when restoring map state
|
2013-06-01 20:09:41 +00:00
|
|
|
|
|
|
|
CON_PERPLAYER = 0x40000000, -- LunaCON internal
|
2013-01-13 16:40:32 +00:00
|
|
|
}
|
2013-01-13 16:40:21 +00:00
|
|
|
|
2013-01-24 20:03:02 +00:00
|
|
|
-- NOTE: This differs from enum GamevarFlags_t's GAMEVAR_USER_MASK
|
|
|
|
GVFLAG.USER_MASK = GVFLAG.PERX_MASK + GVFLAG.NODEFAULT + GVFLAG.NORESET
|
|
|
|
|
2013-01-05 13:09:31 +00:00
|
|
|
-- CON --> mangled Lua function name, also existence check:
|
|
|
|
local g_funcname = {}
|
2013-02-21 18:54:02 +00:00
|
|
|
-- while parsing a block, it is a table of "gencode" tables:
|
|
|
|
local g_switchCode = nil
|
|
|
|
-- Global number of switch statements:
|
|
|
|
local g_switchCount = 0
|
2013-10-20 12:35:06 +00:00
|
|
|
-- Number of session gamevars:
|
|
|
|
local g_numSessionVars = 0
|
2013-01-13 16:40:32 +00:00
|
|
|
-- [identifier] = { name=<mangled name / code>, flags=<gamevar flags> }
|
2013-01-13 16:40:21 +00:00
|
|
|
local g_gamevar = {}
|
2013-02-18 16:07:48 +00:00
|
|
|
-- [identifier] = { name=<mangled name / code>, size=<initial size> }
|
|
|
|
local g_gamearray = {}
|
2013-01-05 13:09:31 +00:00
|
|
|
|
2013-03-17 18:11:38 +00:00
|
|
|
-- * nil if dynamic tile remapping disabled
|
2013-06-02 14:07:52 +00:00
|
|
|
-- * {} if enabled but no remappings made
|
|
|
|
-- * else, a nonempty table { [name]=<g_dynTileList index> }
|
2013-03-17 18:11:38 +00:00
|
|
|
local g_dyntilei = nil
|
2013-06-02 14:07:52 +00:00
|
|
|
-- Analogously for sounds.
|
|
|
|
local g_dynsoundi = nil
|
2013-03-17 18:11:38 +00:00
|
|
|
|
2012-12-28 17:18:06 +00:00
|
|
|
local g_have_file = {} -- [filename]=true
|
2012-07-01 22:11:17 +00:00
|
|
|
local g_curcode = nil -- a table of string pieces or other "gencode" tables
|
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
-- will be a table, see reset.codegen()
|
2013-02-21 18:54:13 +00:00
|
|
|
local g_code = nil
|
2012-06-13 23:13:26 +00:00
|
|
|
|
|
|
|
|
2013-03-15 16:56:07 +00:00
|
|
|
local function ACS(s) return (csapp() and "_a" or "actor[_aci]")..s end
|
|
|
|
local function SPS(s) return (csapp() and "_spr" or "sprite[_aci]")..s end
|
|
|
|
local function PLS(s) return (csapp() and "_ps" or "player[_pli]")..s end
|
|
|
|
local function PLSX(s) return "player[_pli]"..s end
|
2013-01-13 16:40:32 +00:00
|
|
|
|
|
|
|
|
2012-06-10 18:56:18 +00:00
|
|
|
local function getlinecol(pos) end -- fwd-decl
|
|
|
|
|
2012-12-28 17:18:06 +00:00
|
|
|
local function new_initial_codetab()
|
2013-03-18 22:05:26 +00:00
|
|
|
-- NOTE: Keep this one line per line to not confuse the Lua->CON line
|
|
|
|
-- mapping system.
|
2012-12-28 17:18:06 +00:00
|
|
|
return {
|
2013-04-05 17:53:21 +00:00
|
|
|
-- Requires.
|
2013-06-20 18:31:47 +00:00
|
|
|
"local require=require",
|
2013-04-05 17:53:21 +00:00
|
|
|
"local _con, _bit, _math = require'con', require'bit', require'math'",
|
2013-06-28 14:07:41 +00:00
|
|
|
"local _xmath = require'xmath'",
|
2013-04-05 17:53:21 +00:00
|
|
|
|
|
|
|
-- Cache globals into locals.
|
2013-07-07 20:59:10 +00:00
|
|
|
"local sector, sprite, wall, spriteext, _atsprite = sector, sprite, wall, spriteext, _atsprite",
|
2013-05-28 19:52:48 +00:00
|
|
|
"local actor, player, projectile, g_tile = actor, player, projectile, g_tile",
|
2013-04-05 17:53:21 +00:00
|
|
|
"local gameactor, gameevent, _gv = gameactor, gameevent, gv",
|
|
|
|
"local updatesector, updatesectorz, cansee = updatesector, updatesectorz, cansee",
|
|
|
|
"local print, printf = print, printf",
|
|
|
|
|
|
|
|
-- Cache a couple of often-used functions.
|
2013-07-13 21:04:50 +00:00
|
|
|
"local _div, _mod, _mulTR, _mulWR = _con._div, _con._mod, _con._mulTR, _con._mulWR",
|
2013-04-05 17:53:21 +00:00
|
|
|
"local _band, _bor, _bxor = _bit.band, _bit.bor, _bit.bxor",
|
|
|
|
"local _lsh, _rsh, _arsh = _bit.lshift, _bit.rshift, _bit.arshift",
|
2013-11-12 21:03:11 +00:00
|
|
|
"local _setsprite,_ssp = _con._setsprite,_con._ssp",
|
2014-02-01 16:19:59 +00:00
|
|
|
g_cgopt["error-nonlocal-userdef"]
|
|
|
|
and "local _gud=_con._get_userdef_check" or "local _gud=_con._get_userdef",
|
2014-02-28 20:33:46 +00:00
|
|
|
"local _st=_con._err_if_negative",
|
2013-04-05 17:53:21 +00:00
|
|
|
|
2013-06-20 18:31:47 +00:00
|
|
|
-- * CON "states" (subroutines) and
|
|
|
|
-- * Switch function table, indexed by global switch sequence number:
|
|
|
|
"local _F,_SW = {},{}",
|
|
|
|
|
|
|
|
-- CON gamevars and gamearrays (see mangle_name()), set up for
|
|
|
|
-- restoration from savegames.
|
|
|
|
"module(...)",
|
|
|
|
"_V,_A={},{}",
|
|
|
|
"-- NOTE to the reader: This require's result is Lunatic-private API! DO NOT USE!",
|
|
|
|
"local _dummy,_S=require'end_gamevars'",
|
2013-10-27 21:12:22 +00:00
|
|
|
-- XXX: Currently commented out because of gamevar restoration from loadmapstate.
|
|
|
|
-- "local _V,_A=_V,_A",
|
2013-06-30 20:38:39 +00:00
|
|
|
"local _C,_M,_I={},{},{}", -- actions, moves, ais
|
2013-03-13 10:48:23 +00:00
|
|
|
|
|
|
|
-- Static ivec3s so that no allocations need to be made.
|
2013-06-28 14:07:41 +00:00
|
|
|
"local _IVEC = { _xmath.ivec3(), _xmath.ivec3() }",
|
2013-03-18 22:05:26 +00:00
|
|
|
"local function _IV(num, x, y, z)",
|
|
|
|
" local v=_IVEC[num]; v.x=x; v.y=y; v.z=z; return v;",
|
|
|
|
"end",
|
2012-12-28 17:18:06 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-02-11 17:16:58 +00:00
|
|
|
-- CON global system gamevar
|
2013-02-16 18:53:15 +00:00
|
|
|
local function CSV(var) return "_gv._csv"..var end
|
2013-02-07 21:01:18 +00:00
|
|
|
|
2013-01-13 16:40:32 +00:00
|
|
|
-- Creates the table of predefined game variables.
|
|
|
|
-- KEEPINSYNC gamevars.c: Gv_AddSystemVars()
|
|
|
|
local function new_initial_gvartab()
|
|
|
|
local wmembers = conl.wdata_members
|
|
|
|
|
2013-01-20 21:17:23 +00:00
|
|
|
local function GamevarCreationFunc(addflags)
|
|
|
|
return function(varname)
|
2014-02-08 14:37:47 +00:00
|
|
|
-- 'used' is a bitmask: 1 is 'was read', 2 is 'was written to'
|
|
|
|
return { name=varname, flags=GVFLAG.SYSTEM+addflags, used=3 }
|
2013-01-20 21:17:23 +00:00
|
|
|
end
|
2013-01-19 18:28:40 +00:00
|
|
|
end
|
|
|
|
|
2013-01-20 21:17:23 +00:00
|
|
|
local RW = GamevarCreationFunc(0)
|
|
|
|
local RO = GamevarCreationFunc(GVFLAG.READONLY)
|
|
|
|
local PRW = GamevarCreationFunc(GVFLAG.PERPLAYER)
|
|
|
|
local PRO = GamevarCreationFunc(GVFLAG.READONLY+GVFLAG.PERPLAYER)
|
2013-01-19 18:28:40 +00:00
|
|
|
|
|
|
|
local gamevar = {
|
2013-02-24 16:05:22 +00:00
|
|
|
-- NOTE: THISACTOR can mean different things in some contexts.
|
2013-01-19 18:28:40 +00:00
|
|
|
THISACTOR = RO "_aci",
|
|
|
|
|
2013-08-23 17:01:10 +00:00
|
|
|
RETURN = RW "_gv.RETURN",
|
2013-02-11 17:16:58 +00:00
|
|
|
HITAG = RW(CSV".HITAG"),
|
|
|
|
LOTAG = RW(CSV".LOTAG"),
|
|
|
|
TEXTURE = RW(CSV".TEXTURE"),
|
2013-01-19 18:28:40 +00:00
|
|
|
|
2013-03-13 10:48:14 +00:00
|
|
|
-- This will warn when defining from CON, but it's the most
|
|
|
|
-- straightforward implementation.
|
|
|
|
LOGO_FLAGS = RW "_gv.g_logoFlags",
|
|
|
|
|
2013-01-19 18:28:40 +00:00
|
|
|
xdim = RO "_gv.xdim",
|
|
|
|
ydim = RO "_gv.ydim",
|
2013-01-19 18:28:55 +00:00
|
|
|
windowx1 = RO "_gv.windowx1",
|
|
|
|
windowy1 = RO "_gv.windowy1",
|
|
|
|
windowx2 = RO "_gv.windowx2",
|
|
|
|
windowy2 = RO "_gv.windowy2",
|
2013-01-19 18:28:40 +00:00
|
|
|
|
2013-02-10 16:24:32 +00:00
|
|
|
yxaspect = RO "_gv._get_yxaspect()",
|
2013-02-11 17:16:58 +00:00
|
|
|
viewingrange = RO "_gv._get_viewingrange()",
|
2013-07-19 12:49:02 +00:00
|
|
|
-- TODO: gravitationalconstant, gametype_flags
|
2013-02-10 16:24:32 +00:00
|
|
|
|
2013-01-19 18:28:40 +00:00
|
|
|
numsectors = RO "_gv.numsectors",
|
|
|
|
NUMSECTORS = RO "_gv.numsectors",
|
|
|
|
NUMWALLS = RO "_gv.numwalls",
|
2014-05-18 09:55:42 +00:00
|
|
|
Numsprites = RO "_gv.Numsprites",
|
2013-01-19 18:28:40 +00:00
|
|
|
|
2013-01-19 18:28:55 +00:00
|
|
|
randomseed = RW "_gv.randomseed",
|
|
|
|
totalclock = RO "_gv.totalclock",
|
2013-01-24 20:03:02 +00:00
|
|
|
framerate = RO "_gv._currentFramerate()",
|
|
|
|
current_menu = RO "_gv._currentMenu()",
|
2013-07-04 19:38:42 +00:00
|
|
|
rendmode = RO "_gv.rendmode",
|
2013-01-19 18:28:55 +00:00
|
|
|
|
|
|
|
screenpeek = RO "_gv.screenpeek",
|
|
|
|
|
2013-01-19 18:28:40 +00:00
|
|
|
camerax = RW "_gv.cam.pos.x",
|
|
|
|
cameray = RW "_gv.cam.pos.y",
|
|
|
|
cameraz = RW "_gv.cam.pos.z",
|
|
|
|
cameraang = RW "_gv.cam.ang",
|
|
|
|
camerahoriz = RW "_gv.cam.horiz",
|
|
|
|
camerasect = RW "_gv.cam.sect",
|
|
|
|
cameradist = RW "_gv.cam.dist",
|
|
|
|
cameraclock = RW "_gv.cam.clock",
|
2013-01-19 18:28:55 +00:00
|
|
|
|
|
|
|
-- HUD weapon gamevars
|
|
|
|
currentweapon = RW "_gv.hudweap.cur",
|
|
|
|
weaponcount = RW "_gv.hudweap.count",
|
|
|
|
weapon_xoffset = RW "_gv.hudweap.gunposx",
|
|
|
|
looking_angSR1 = RW "_gv.hudweap.lookhalfang",
|
|
|
|
gun_pos = RW "_gv.hudweap.gunposy",
|
|
|
|
looking_arc = RW "_gv.hudweap.lookhoriz",
|
|
|
|
gs = RW "_gv.hudweap.shade",
|
|
|
|
|
|
|
|
-- Some per-player gamevars
|
2013-03-15 16:56:07 +00:00
|
|
|
ZRANGE = PRW(PLSX".zrange"),
|
|
|
|
ANGRANGE = PRW(PLSX".angrange"),
|
|
|
|
AUTOAIMANGLE = PRW(PLSX".autoaimang"),
|
2013-01-19 18:28:55 +00:00
|
|
|
|
2013-03-15 16:56:07 +00:00
|
|
|
PIPEBOMB_CONTROL = PRW(PLSX".pipebombControl"),
|
|
|
|
GRENADE_LIFETIME = PRW(PLSX".pipebombLifetime"),
|
|
|
|
GRENADE_LIFETIME_VAR = PRW(PLSX".pipebombLifetimeVar"),
|
|
|
|
TRIPBOMB_CONTROL = PRW(PLSX".tripbombControl"),
|
|
|
|
STICKYBOMB_LIFETIME = PRW(PLSX".tripbombLifetime"),
|
|
|
|
STICKYBOMB_LIFETIME_VAR = PRW(PLSX".tripbombLifetimeVar"),
|
2013-01-19 18:28:55 +00:00
|
|
|
|
2013-05-26 18:42:53 +00:00
|
|
|
-- Some *writable* system gamevars relating to multiplayer.
|
|
|
|
-- TODO_MP.
|
|
|
|
RESPAWN_MONSTERS = RO "0",
|
|
|
|
RESPAWN_ITEMS = RO "0",
|
|
|
|
RESPAWN_INVENTORY = RO "0",
|
|
|
|
MONSTERS_OFF = RO "0",
|
|
|
|
MARKER = RO "0",
|
|
|
|
|
2013-01-20 21:17:06 +00:00
|
|
|
-- These are not 100% authentic (they're only updated in certain
|
|
|
|
-- circumstances, see player.c: P_SetWeaponGamevars()). But IMO it's
|
|
|
|
-- more useful like this.
|
2013-03-15 16:56:07 +00:00
|
|
|
WEAPON = PRO(PLSX".curr_weapon"),
|
|
|
|
WORKSLIKE = PRO(format(PLSX".weapon[%s].workslike", PLSX".curr_weapon")),
|
2013-01-20 21:17:06 +00:00
|
|
|
|
2014-01-15 20:29:10 +00:00
|
|
|
VOLUME = RO "_gv._ud.volume_number",
|
|
|
|
LEVEL = RO "_gv._ud.level_number",
|
2013-01-19 18:28:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 16:56:15 +00:00
|
|
|
-- Reserved bits
|
2014-08-02 17:24:39 +00:00
|
|
|
gamevar.LOGO_FLAGS.rbits = bit.bnot(0x001fffff)
|
2013-03-15 16:56:15 +00:00
|
|
|
|
2013-07-13 21:04:41 +00:00
|
|
|
for w=0,C.MAX_WEAPONS-1 do
|
2013-01-13 16:40:32 +00:00
|
|
|
for i=1,#wmembers do
|
2013-03-18 22:05:26 +00:00
|
|
|
local member = wmembers[i]:gsub(".*_t ","") -- strip e.g. "const int32_t "
|
|
|
|
:gsub("^_","") -- strip potentially leading underscore
|
2013-01-13 16:40:32 +00:00
|
|
|
local name = format("WEAPON%d_%s", w, member:upper())
|
2013-03-15 16:56:07 +00:00
|
|
|
gamevar[name] = PRW(format(PLSX".weapon[%d].%s", w, member))
|
2013-03-15 16:56:15 +00:00
|
|
|
|
|
|
|
if (member=="flags") then
|
|
|
|
gamevar[name].rbits = bit.bnot(0x1ffff)
|
|
|
|
end
|
2013-01-13 16:40:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return gamevar
|
|
|
|
end
|
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
local reset = {}
|
|
|
|
|
|
|
|
function reset.codegen()
|
2013-01-05 13:09:31 +00:00
|
|
|
g_funcname = {}
|
2013-02-21 18:54:02 +00:00
|
|
|
g_switchCode = nil
|
|
|
|
g_switchCount = 0
|
2013-10-20 12:35:06 +00:00
|
|
|
g_numSessionVars = 0
|
2013-01-13 16:40:32 +00:00
|
|
|
g_gamevar = new_initial_gvartab()
|
2013-03-15 16:56:11 +00:00
|
|
|
g_gamearray = {
|
2013-07-09 18:23:43 +00:00
|
|
|
-- SYSTEM_GAMEARRAY
|
2013-07-13 21:04:41 +00:00
|
|
|
tilesizx = { name="g_tile.sizx", size=C.MAXTILES, sysp=true },
|
|
|
|
tilesizy = { name="g_tile.sizy", size=C.MAXTILES, sysp=true },
|
2013-03-15 16:56:11 +00:00
|
|
|
}
|
2013-01-05 13:09:31 +00:00
|
|
|
|
2013-03-17 18:11:38 +00:00
|
|
|
g_dyntilei = nil
|
2013-06-02 14:07:52 +00:00
|
|
|
g_dynsoundi = nil
|
2013-03-17 18:11:38 +00:00
|
|
|
|
2012-12-28 17:18:06 +00:00
|
|
|
g_have_file = {}
|
|
|
|
g_curcode = new_initial_codetab()
|
2014-03-15 14:10:49 +00:00
|
|
|
-- actor, event, loadactor: [{actor, event, actor}num] = gencode_table
|
|
|
|
--
|
|
|
|
-- aflagsloc[actornum]: location of '(user)actor' token, 'spriteflags' or
|
|
|
|
-- 'sprite*' command; result of getLocation(<kind>, <pos>)
|
|
|
|
g_code = { actor={}, event={}, loadactor={}, aflagsloc={} }
|
2012-12-28 17:18:06 +00:00
|
|
|
|
|
|
|
g_recurslevel = -1
|
|
|
|
g_numerrors = 0
|
2012-07-01 22:11:17 +00:00
|
|
|
end
|
|
|
|
|
2013-07-09 18:23:43 +00:00
|
|
|
-- Is SYSTEM_GAMEARRAY?
|
|
|
|
local function issysgar(str)
|
|
|
|
return str:match("^g_tile.siz[xy]")
|
|
|
|
end
|
|
|
|
|
2012-07-01 22:11:17 +00:00
|
|
|
local function addcode(x)
|
2012-11-30 18:57:40 +00:00
|
|
|
assert(type(x)=="string" or type(x)=="table")
|
2012-07-01 22:11:17 +00:00
|
|
|
g_curcode[#g_curcode+1] = x
|
|
|
|
end
|
|
|
|
|
|
|
|
local function addcodef(fmt, ...)
|
2012-11-30 18:57:40 +00:00
|
|
|
addcode(format(fmt, ...))
|
2012-07-01 22:11:17 +00:00
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
local function paddcodef(pos, fmt, ...)
|
|
|
|
addcodef(fmt.."--"..getlinecol(pos), ...)
|
|
|
|
end
|
|
|
|
|
2013-01-05 13:09:19 +00:00
|
|
|
local function add_code_and_end(codetab, endstr)
|
|
|
|
assert(type(codetab)=="table")
|
|
|
|
addcode(codetab)
|
|
|
|
addcode(endstr)
|
|
|
|
end
|
|
|
|
|
2013-03-15 16:56:07 +00:00
|
|
|
local function get_cache_sap_code()
|
|
|
|
return csapp() and "local _spr,_a,_ps=_con._getsap(_aci,_pli)" or ""
|
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
-- fwd-decls
|
2013-11-12 21:03:18 +00:00
|
|
|
local warnprintf, errprintf, pwarnprintf, perrprintf, contprintf
|
2014-03-15 14:10:49 +00:00
|
|
|
local getLocation
|
2013-02-21 18:54:13 +00:00
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
local on = {}
|
|
|
|
|
2013-03-24 18:53:28 +00:00
|
|
|
-- Map from CON actor usertype to SFLAGs.
|
|
|
|
local MAP_ACTOR_FLAGS = {
|
|
|
|
[0] = 0,
|
|
|
|
[1] = conl.SFLAG.SFLAG_BADGUY,
|
|
|
|
[2] = conl.SFLAG.SFLAG_BADGUY + conl.SFLAG.SFLAG_BADGUYSTAYPUT,
|
|
|
|
[3] = conl.SFLAG.SFLAG_BADGUY + conl.SFLAG.SFLAG_BADGUYSTAYPUT,
|
|
|
|
}
|
|
|
|
for i=4,7 do
|
|
|
|
MAP_ACTOR_FLAGS[i] = MAP_ACTOR_FLAGS[i-4] + conl.SFLAG.SFLAG_ROTFIXED
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
function on.actor_end(pos, usertype, tsamm, codetab)
|
2012-07-01 22:11:17 +00:00
|
|
|
local tilenum = tsamm[1]
|
2013-03-24 18:53:28 +00:00
|
|
|
local flags = 0
|
|
|
|
|
|
|
|
if (usertype ~= nil) then -- useractor
|
|
|
|
if (not (bit.band(usertype, bit.bnot(7)) == 0)) then
|
2013-03-24 18:55:27 +00:00
|
|
|
perrprintf(pos, "invalid usertype: must be bitwise OR of 1, 2 and/or 4")
|
2013-03-24 18:53:28 +00:00
|
|
|
else
|
|
|
|
flags = MAP_ACTOR_FLAGS[usertype]
|
|
|
|
end
|
|
|
|
end
|
2012-07-01 22:11:17 +00:00
|
|
|
|
2014-03-15 14:10:50 +00:00
|
|
|
-- 0x08000000: actor.FLAGS.replace
|
|
|
|
flags = bit.bor(flags, 0x08000000)
|
2013-05-30 18:10:54 +00:00
|
|
|
|
2013-03-24 18:53:28 +00:00
|
|
|
local str = flags..","
|
2012-12-23 19:24:16 +00:00
|
|
|
for i=2,math.min(#tsamm,4) do
|
|
|
|
str = str .. tostring(tsamm[i])..","
|
|
|
|
end
|
2013-03-24 18:53:28 +00:00
|
|
|
if (#tsamm >= 5) then
|
|
|
|
local movflags = bit.bor(unpack(tsamm, 5))
|
|
|
|
str = str .. movflags..","
|
2012-12-23 19:24:16 +00:00
|
|
|
end
|
|
|
|
|
2013-06-22 11:31:09 +00:00
|
|
|
paddcodef(pos, "gameactor{%d,%sfunction(_aci,_pli,_dist)", tilenum, str)
|
2013-03-15 16:56:07 +00:00
|
|
|
addcode(get_cache_sap_code())
|
2013-06-12 17:49:53 +00:00
|
|
|
add_code_and_end(codetab, "end}")
|
2012-07-01 22:11:17 +00:00
|
|
|
|
2013-02-21 18:54:13 +00:00
|
|
|
if (g_code.actor[tilenum] ~= nil) then
|
2013-03-24 18:55:27 +00:00
|
|
|
pwarnprintf(pos, "redefined actor %d", tilenum)
|
2013-02-21 18:54:13 +00:00
|
|
|
end
|
2013-01-13 16:40:21 +00:00
|
|
|
g_code.actor[tilenum] = codetab
|
2014-03-15 14:10:49 +00:00
|
|
|
g_code.aflagsloc[tilenum] = getLocation("definition of actor", pos)
|
2012-07-01 22:11:17 +00:00
|
|
|
end
|
|
|
|
|
2013-07-07 20:58:57 +00:00
|
|
|
-- NOTE: in C-CON, the slash and backslash can also be part of an identifier,
|
|
|
|
-- but this is likely to support file names in other places.
|
|
|
|
local BAD_ID_CHARS0 = "_*?" -- allowed 1st identifier chars
|
2014-05-18 09:55:39 +00:00
|
|
|
local BAD_ID_CHARS1 = "_*-+?." -- allowed following identifier chars
|
2013-01-05 13:09:31 +00:00
|
|
|
|
2013-06-07 10:18:15 +00:00
|
|
|
local function truetab(tab)
|
|
|
|
local ttab = {}
|
|
|
|
for i=1,#tab do
|
|
|
|
ttab[tab[i]] = true
|
|
|
|
end
|
|
|
|
return ttab
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Lua 5.2 keywords. Not 5.1 because we use "goto" for codegen.
|
|
|
|
local LUA_KEYW = truetab {
|
|
|
|
"and", "break", "do", "else", "elseif", "end",
|
|
|
|
"false", "for", "function", "goto", "if", "in",
|
|
|
|
"local", "nil", "not", "or", "repeat", "return",
|
|
|
|
"then", "true", "until", "while"
|
|
|
|
}
|
|
|
|
|
2013-02-24 16:05:37 +00:00
|
|
|
-- Return the Lua code by which the CON object <name> is referenced in the
|
|
|
|
-- translated code.
|
2013-01-05 13:09:31 +00:00
|
|
|
local function mangle_name(name, prefix)
|
2013-06-07 10:18:15 +00:00
|
|
|
if (name:match("^[A-Za-z_][A-Za-z_0-9]*$") and not LUA_KEYW[name]) then
|
2013-04-05 17:53:21 +00:00
|
|
|
return format("_%s.%s", prefix, name)
|
|
|
|
else
|
|
|
|
return format("_%s[%q]", prefix, name)
|
|
|
|
end
|
2013-01-05 13:09:31 +00:00
|
|
|
end
|
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
function on.state_begin_Cmt(_subj, _pos, statename)
|
2013-01-19 18:28:55 +00:00
|
|
|
-- We must register the state name early (Cmt) because otherwise, it won't
|
|
|
|
-- be found in a recursive state. XXX: The real issue seems to be the use
|
|
|
|
-- of "Cmt"s in other places, which messes up the sequence of running the
|
|
|
|
-- semantic actions.
|
2013-01-05 13:09:31 +00:00
|
|
|
local ourname = mangle_name(statename, "F")
|
|
|
|
g_funcname[statename] = ourname
|
2013-01-19 18:28:55 +00:00
|
|
|
return true, ourname
|
2013-01-05 13:09:31 +00:00
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
function on.state_end(pos, funcname, codetab)
|
2013-06-22 11:31:09 +00:00
|
|
|
paddcodef(pos, "%s=function(_aci,_pli,_dist)", funcname)
|
2013-03-15 16:56:07 +00:00
|
|
|
addcode(get_cache_sap_code())
|
2013-01-05 13:09:19 +00:00
|
|
|
add_code_and_end(codetab, "end")
|
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
function on.event_end(pos, eventidx, codetab)
|
2013-02-25 15:31:19 +00:00
|
|
|
assert(type(codetab)=="table")
|
2013-04-05 17:52:50 +00:00
|
|
|
-- 0x20000000: actor.FLAGS.chain_beg
|
2013-06-22 11:31:09 +00:00
|
|
|
paddcodef(pos, "gameevent{%d,0x20000000,function (_aci,_pli,_dist)", eventidx)
|
2013-03-15 16:56:07 +00:00
|
|
|
addcode(get_cache_sap_code())
|
2013-02-25 15:31:19 +00:00
|
|
|
addcode(codetab)
|
2013-06-12 17:49:53 +00:00
|
|
|
addcode("end}")
|
2013-01-05 13:09:19 +00:00
|
|
|
|
2013-01-13 16:40:21 +00:00
|
|
|
g_code.event[eventidx] = codetab
|
2012-12-03 18:24:33 +00:00
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
function on.eventloadactor_end(pos, tilenum, codetab)
|
2013-02-21 18:54:13 +00:00
|
|
|
-- Translate eventloadactor into a chained EVENT_LOADACTOR block
|
2013-06-22 11:31:09 +00:00
|
|
|
paddcodef(pos, "gameevent{'LOADACTOR', function (_aci,_pli,_dist)")
|
2013-03-15 16:56:07 +00:00
|
|
|
addcode(get_cache_sap_code())
|
2013-02-21 18:54:13 +00:00
|
|
|
addcodef("if (%s==%d) then", SPS".picnum", tilenum)
|
|
|
|
addcode(codetab)
|
|
|
|
addcode("end")
|
2013-06-12 17:49:53 +00:00
|
|
|
addcode("end}")
|
2013-02-21 18:54:13 +00:00
|
|
|
|
2013-05-24 13:54:39 +00:00
|
|
|
if (g_code.loadactor[tilenum] ~= nil and g_warn["chained-loadactor"]) then
|
2013-03-24 18:55:27 +00:00
|
|
|
-- NOTE: C-CON redefines loadactor code if encountered multiple times.
|
|
|
|
pwarnprintf(pos, "chained additional loadactor %d code", tilenum)
|
2013-02-21 18:54:13 +00:00
|
|
|
end
|
|
|
|
g_code.loadactor[tilenum] = codetab
|
|
|
|
end
|
|
|
|
|
2012-07-01 22:11:17 +00:00
|
|
|
----------
|
|
|
|
|
2012-06-10 18:56:21 +00:00
|
|
|
local function linecolstr(pos)
|
|
|
|
local line, col = getlinecol(pos)
|
2012-11-30 18:57:40 +00:00
|
|
|
return format("%d:%d", line, col)
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
|
|
|
|
2012-12-09 13:24:28 +00:00
|
|
|
local function increment_numerrors()
|
|
|
|
g_numerrors = g_numerrors+1
|
|
|
|
if (g_numerrors == g_maxerrors) then
|
|
|
|
g_numerrors = inf
|
|
|
|
printf("Too many errors (%d), aborting...", g_maxerrors)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
function perrprintf(pos, fmt, ...)
|
2013-11-12 21:03:18 +00:00
|
|
|
printf("%s %s: error: "..fmt, g_filename,
|
|
|
|
pos and linecolstr(pos) or "???", ...)
|
2012-12-09 13:24:28 +00:00
|
|
|
increment_numerrors()
|
2012-07-01 22:11:17 +00:00
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
function errprintf(fmt, ...)
|
2013-11-12 21:03:18 +00:00
|
|
|
perrprintf(g_lastkwpos, fmt, ...)
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
function pwarnprintf(pos, fmt, ...)
|
2013-11-12 21:03:18 +00:00
|
|
|
printf("%s %s: warning: "..fmt, g_filename,
|
|
|
|
pos and linecolstr(pos) or "???", ...)
|
2012-07-01 22:11:17 +00:00
|
|
|
end
|
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
function warnprintf(fmt, ...)
|
2013-11-12 21:03:18 +00:00
|
|
|
pwarnprintf(g_lastkwpos, fmt, ...)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Print a continuation line to an error or warning.
|
|
|
|
function contprintf(iserr, fmt, ...)
|
|
|
|
printf("%s %s: %s "..fmt, g_filename,
|
|
|
|
g_lastkwpos and linecolstr(g_lastkwpos) or "???",
|
|
|
|
iserr and " " or " ", ...)
|
2012-06-13 23:13:26 +00:00
|
|
|
end
|
|
|
|
|
2012-07-01 22:11:17 +00:00
|
|
|
local function parse_number(pos, numstr)
|
2013-03-17 18:11:53 +00:00
|
|
|
-- <numstr> is a full number string, potentially prefixed with a minus sign.
|
2013-01-05 13:09:31 +00:00
|
|
|
local num = tonumber((numstr:gsub("h$", "")))
|
2013-03-17 18:11:53 +00:00
|
|
|
-- local onum = num
|
|
|
|
local hex = numstr:match("0[xX]([^h]*)h?") -- get hex digits, if any
|
2012-06-10 18:56:18 +00:00
|
|
|
|
2013-01-26 17:08:02 +00:00
|
|
|
-- num==nil for Rio Lua, which doesn't handle large hex literals.
|
|
|
|
if (num==nil or not (num >= -0x80000000 and num <= 0xffffffff)) then
|
2013-03-17 18:11:53 +00:00
|
|
|
-- number is <INT32_MIN or >UINT32_MAX or NaN
|
|
|
|
if (hex and #hex>8 and hex:sub(1,#hex-8):match("^[fF]$")) then
|
|
|
|
-- Too many hex digits, but they're all Fs.
|
|
|
|
pwarnprintf(pos, "number %s truncated to 32 bits", numstr)
|
2013-06-28 14:07:41 +00:00
|
|
|
num = bit.tobit(num)
|
2013-03-17 18:11:53 +00:00
|
|
|
else
|
|
|
|
perrprintf(pos, "number %s out of the range of a 32-bit integer", numstr)
|
|
|
|
-- Be careful not to write bound checks like
|
|
|
|
-- "if (i<LOWBOUND or i>HIGHBOUND) then error('...') end":
|
|
|
|
num = NaN
|
|
|
|
end
|
|
|
|
elseif (num >= 0x80000000) then
|
2014-01-24 21:39:04 +00:00
|
|
|
num = bit.tobit(num)
|
2013-03-17 18:11:53 +00:00
|
|
|
if (not hex and g_warn["number-conversion"]) then
|
2014-01-24 21:39:04 +00:00
|
|
|
pwarnprintf(pos, "number %s converted to %d", numstr, num)
|
2012-12-09 13:24:28 +00:00
|
|
|
end
|
2012-06-10 18:56:18 +00:00
|
|
|
end
|
|
|
|
|
2013-03-17 18:11:53 +00:00
|
|
|
-- printf("numstr:%s, num=%d (0x%s) '%s', resnum=%d (0x%s)",
|
|
|
|
-- numstr, onum, bit.tohex(onum), hex, num, bit.tohex(num))
|
2012-06-10 18:56:18 +00:00
|
|
|
return num
|
|
|
|
end
|
|
|
|
|
2013-06-09 16:37:16 +00:00
|
|
|
-- Bound checking functions that generate a compilation error on failure.
|
|
|
|
local check = {}
|
|
|
|
|
|
|
|
function check.tile_idx(tilenum)
|
2013-07-13 21:04:41 +00:00
|
|
|
if (not (tilenum >= 0 and tilenum < C.MAXTILES)) then
|
2013-02-24 16:05:22 +00:00
|
|
|
errprintf("invalid tile number %d", tilenum)
|
|
|
|
return false
|
|
|
|
end
|
2013-06-09 16:37:16 +00:00
|
|
|
return true
|
|
|
|
end
|
2013-02-24 16:05:22 +00:00
|
|
|
|
2013-06-09 16:37:16 +00:00
|
|
|
function check.sound_idx(sidx)
|
|
|
|
if (not (sidx >= 0 and sidx < conl.MAXSOUNDS)) then
|
|
|
|
errprintf("invalid sound number %d", sidx)
|
|
|
|
return false
|
|
|
|
end
|
2013-02-24 16:05:22 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
-- Mapping of various "define" types to the respective number of members and
|
|
|
|
-- vice versa
|
|
|
|
local LABEL = { MOVE=2, AI=3, ACTION=5, [2]="move", [3]="ai", [5]="action",
|
|
|
|
NUMBER=1, [1]="number" }
|
2012-06-17 19:45:43 +00:00
|
|
|
|
2013-06-30 20:38:39 +00:00
|
|
|
-- Function names in the 'con' module:
|
2012-11-25 13:18:46 +00:00
|
|
|
local LABEL_FUNCNAME = { [2]="move", [3]="ai", [5]="action" }
|
2013-06-30 20:38:39 +00:00
|
|
|
local LABEL_PREFIX = { [2]="M", [3]="I", [5]="C" } -- _C, _M, _I in the gen'd code
|
2012-06-17 19:45:43 +00:00
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
local g_labeldef = {} -- Lua numbers for numbers, strings for composites
|
|
|
|
local g_labeltype = {}
|
2013-06-12 17:49:47 +00:00
|
|
|
local g_labelspecial = {} -- [<label>] = true
|
2013-11-12 21:03:18 +00:00
|
|
|
local g_labelloc = {} -- [<label>] = { filename, linenum, colnum }
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2013-11-12 21:03:23 +00:00
|
|
|
-- Get location table for use in continued warning/error reporting.
|
2014-03-15 14:10:49 +00:00
|
|
|
--[[ local --]]
|
|
|
|
function getLocation(kind, pos)
|
|
|
|
local loc = { g_filename, getlinecol(pos or g_lastkwpos) }
|
|
|
|
loc[4] = kind
|
|
|
|
return loc
|
2013-11-12 21:03:23 +00:00
|
|
|
end
|
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
function reset.labels()
|
2012-12-28 17:18:06 +00:00
|
|
|
g_badids = {}
|
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
-- NO is also a valid `move', `ai' or `action', but they are handled
|
2013-01-24 20:03:10 +00:00
|
|
|
-- separately in lookup.composite().
|
2013-01-19 18:28:40 +00:00
|
|
|
g_labeldef = {
|
|
|
|
NO = 0,
|
|
|
|
-- NOTE: these are read-only gamevars in C-CON
|
|
|
|
CLIPMASK0 = 65536+1, -- blocking
|
|
|
|
CLIPMASK1 = (256*65536)+64, -- hittable
|
2013-03-03 16:06:22 +00:00
|
|
|
-- TODO_MP
|
2013-01-24 20:03:02 +00:00
|
|
|
COOP = 0,
|
2013-05-30 18:10:49 +00:00
|
|
|
MULTIMODE = 1,
|
2013-01-24 20:03:02 +00:00
|
|
|
numplayers = 1,
|
2013-01-24 20:03:06 +00:00
|
|
|
myconnectindex = 0,
|
2013-07-13 21:04:41 +00:00
|
|
|
-- Predefined constants
|
|
|
|
MAXSTATUS = C.MAXSTATUS,
|
|
|
|
MAXSPRITES = C.MAXSPRITES,
|
|
|
|
MAX_WEAPONS = C.MAX_WEAPONS,
|
2013-01-19 18:28:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
g_labeltype = {}
|
|
|
|
g_labelspecial = {}
|
|
|
|
g_labelloc = {}
|
|
|
|
|
2013-01-24 20:03:02 +00:00
|
|
|
for varname,_ in pairs(g_labeldef) do
|
|
|
|
g_labeltype[varname] = LABEL.NUMBER
|
2013-06-12 17:49:47 +00:00
|
|
|
g_labelspecial[varname] = true
|
2013-01-24 20:03:02 +00:00
|
|
|
end
|
2012-11-25 13:18:46 +00:00
|
|
|
|
|
|
|
-- Initialize default defines.
|
2012-11-30 18:57:40 +00:00
|
|
|
for i=1,#conl.labels do
|
|
|
|
for label, val in pairs(conl.labels[i]) do
|
2012-06-17 19:45:33 +00:00
|
|
|
g_labeldef[label] = val
|
2012-11-25 13:18:46 +00:00
|
|
|
g_labeltype[label] = LABEL.NUMBER
|
2012-06-17 19:45:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-24 20:03:10 +00:00
|
|
|
-- Table of functions doing various lookups (label, gamevar, ...)
|
|
|
|
local lookup = {}
|
|
|
|
|
|
|
|
function lookup.defined_label(pos, maybe_minus_str, identifier)
|
2012-06-10 18:56:21 +00:00
|
|
|
local num = g_labeldef[identifier]
|
|
|
|
|
|
|
|
if (num == nil) then
|
2012-07-01 22:11:17 +00:00
|
|
|
perrprintf(pos, "label \"%s\" is not defined", identifier)
|
2012-06-17 19:45:37 +00:00
|
|
|
return -inf -- return a number for type cleanness
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
if (g_labeltype[identifier] ~= LABEL.NUMBER) then
|
|
|
|
perrprintf(pos, "label \"%s\" is not a `define'd number", identifier)
|
2012-06-17 19:45:43 +00:00
|
|
|
return -inf
|
|
|
|
end
|
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
assert(type(num)=="number")
|
|
|
|
|
2012-06-17 19:45:43 +00:00
|
|
|
return (maybe_minus_str=="" and 1 or -1) * num
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
|
|
|
|
2013-06-02 14:07:52 +00:00
|
|
|
assert(not BAD_ID_CHARS1:find(":"))
|
|
|
|
function lookup.raw_defined_label(pos, maybe_minus_str, identifier)
|
|
|
|
return pos..":"..maybe_minus_str..":"..identifier
|
|
|
|
end
|
|
|
|
|
|
|
|
local dynmap = {}
|
|
|
|
-- When necessary, initialize dynamic {tile,sound} mapping list.
|
|
|
|
function dynmap.maybe_init(dyni, dynList)
|
|
|
|
if (dyni[1]==nil) then
|
|
|
|
dyni[1] = true
|
|
|
|
-- Init name -> g_dyn*List index mapping
|
|
|
|
for i=0,math.huge do
|
|
|
|
local str = dynList[i].str
|
|
|
|
if (str==nil) then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
dyni[ffi.string(str)] = i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Potentially process one dynamic {tile,sound} remapping.
|
|
|
|
function dynmap.maybe_process(dyni, dynList, identifier, num)
|
|
|
|
if (dyni[identifier]) then
|
|
|
|
local di = dynList[dyni[identifier]]
|
|
|
|
|
|
|
|
if (ffiC._DEBUG_LUNATIC~=0 and di.staticval~=num) then
|
|
|
|
printf("REMAP %s (%d) --> %d", ffi.string(di.str), di.staticval, num)
|
|
|
|
end
|
|
|
|
di.dynvalptr[0] = num
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
-- The 'check' table is also used to hold a couple of misc checkers.
|
|
|
|
|
|
|
|
function check.sysvar_def_attempt(identifier)
|
2013-02-18 16:07:48 +00:00
|
|
|
if (identifier=="actorvar") then
|
|
|
|
errprintf("cannot define reserved symbol `actorvar'")
|
|
|
|
return true
|
|
|
|
end
|
2013-11-08 18:08:37 +00:00
|
|
|
if (identifier=="_IS_NORESET_GAMEVAR") then
|
|
|
|
errprintf("cannot define reserved symbol `_IS_NORESET_GAMEVAR'")
|
|
|
|
return true
|
|
|
|
end
|
2013-02-18 16:07:48 +00:00
|
|
|
end
|
|
|
|
|
2013-11-12 21:03:23 +00:00
|
|
|
|
|
|
|
local inform = {}
|
|
|
|
|
|
|
|
function inform.common(loc, iserr)
|
2013-11-12 21:03:18 +00:00
|
|
|
if (loc) then
|
2014-03-15 14:10:49 +00:00
|
|
|
contprintf(iserr, "Old definition is at %s %d:%d", loc[1], loc[2], loc[3])
|
2013-11-12 21:03:18 +00:00
|
|
|
else
|
|
|
|
contprintf(iserr, "Old definition is built-in")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-12 21:03:23 +00:00
|
|
|
function inform.olddef_location(identifier, iserr)
|
|
|
|
inform.common(g_labelloc[identifier], iserr)
|
|
|
|
end
|
|
|
|
|
|
|
|
function inform.oldgv_location(identifier, iserr)
|
|
|
|
inform.common(g_gamevar[identifier].loc, iserr)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local Define = {}
|
|
|
|
|
2013-06-30 20:38:39 +00:00
|
|
|
function Define.label(identifier, num)
|
2013-11-12 21:03:20 +00:00
|
|
|
if (check.sysvar_def_attempt(identifier)) then
|
2013-02-18 16:07:48 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
local oldtype = g_labeltype[identifier]
|
2012-06-17 19:45:43 +00:00
|
|
|
local oldval = g_labeldef[identifier]
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2012-06-17 19:45:43 +00:00
|
|
|
if (oldval) then
|
2012-11-25 13:18:46 +00:00
|
|
|
if (oldtype ~= LABEL.NUMBER) then
|
2013-11-12 21:03:18 +00:00
|
|
|
errprintf("Refusing to overwrite `%s' label \"%s\" with a `define'd number.",
|
2012-11-25 13:18:46 +00:00
|
|
|
LABEL[oldtype], identifier)
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.olddef_location(identifier, true)
|
2012-11-25 13:18:46 +00:00
|
|
|
else
|
2012-11-30 18:57:40 +00:00
|
|
|
-- conl.labels[...]: don't warn for wrong PROJ_ redefinitions
|
2012-12-03 18:24:33 +00:00
|
|
|
if (g_warn["not-redefined"]) then
|
2013-01-05 13:09:19 +00:00
|
|
|
if (oldval ~= num and conl.PROJ[identifier]==nil) then
|
2013-11-12 21:03:18 +00:00
|
|
|
warnprintf("Label \"%s\" not redefined with new value %d (old: %d).",
|
2012-12-03 18:24:33 +00:00
|
|
|
identifier, num, oldval)
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.olddef_location(identifier, false)
|
2012-12-03 18:24:33 +00:00
|
|
|
end
|
2012-11-25 13:18:46 +00:00
|
|
|
end
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
2012-11-25 13:18:46 +00:00
|
|
|
else
|
2013-01-13 16:40:21 +00:00
|
|
|
if (g_gamevar[identifier]) then
|
|
|
|
warnprintf("symbol `%s' already used for game variable", identifier)
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.oldgv_location(identifier, false)
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
|
|
|
|
2013-07-13 21:04:41 +00:00
|
|
|
if (ffi and g_dyntilei and (num>=0 and num<C.MAXTILES)) then
|
2013-06-02 14:07:52 +00:00
|
|
|
dynmap.maybe_init(g_dyntilei, ffiC.g_dynTileList)
|
|
|
|
dynmap.maybe_process(g_dyntilei, ffiC.g_dynTileList, identifier, num)
|
2013-03-17 18:11:38 +00:00
|
|
|
end
|
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
-- New definition of a label
|
|
|
|
g_labeldef[identifier] = num
|
|
|
|
g_labeltype[identifier] = LABEL.NUMBER
|
2013-11-12 21:03:23 +00:00
|
|
|
g_labelloc[identifier] = getLocation()
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
function check.composite_literal(labeltype, pos, num)
|
2012-11-25 13:18:46 +00:00
|
|
|
if (num==0 or num==1) then
|
|
|
|
return (num==0) and "0" or "1"
|
|
|
|
else
|
|
|
|
perrprintf(pos, "literal `%s' number must be either 0 or 1", LABEL[labeltype])
|
|
|
|
return "_INVALIT"
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-24 20:03:10 +00:00
|
|
|
function lookup.composite(labeltype, pos, identifier)
|
2012-06-17 19:45:43 +00:00
|
|
|
if (identifier=="NO") then
|
2012-11-25 13:18:46 +00:00
|
|
|
-- NO is a special case and is valid for move, action and ai,
|
|
|
|
-- being the same as passing a literal 0.
|
|
|
|
return "0"
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local val = g_labeldef[identifier]
|
2013-08-19 19:26:58 +00:00
|
|
|
local typ = g_labeltype[identifier]
|
2012-06-17 19:45:43 +00:00
|
|
|
|
|
|
|
if (val == nil) then
|
2012-07-01 22:11:17 +00:00
|
|
|
perrprintf(pos, "label \"%s\" is not defined", identifier)
|
2012-11-25 13:18:46 +00:00
|
|
|
return "_NOTDEF"
|
2013-08-19 19:26:58 +00:00
|
|
|
elseif (typ ~= labeltype) then
|
|
|
|
if (identifier=="randomangle" and labeltype==LABEL.MOVE and typ==LABEL.NUMBER) then
|
|
|
|
-- Be forgiving with a 1.3/1.5 GAME.CON type error.
|
2012-12-28 17:18:06 +00:00
|
|
|
pwarnprintf(pos, "label \"randomangle\" is not a `move' value, assuming 0")
|
|
|
|
return "0"
|
2013-08-19 19:26:58 +00:00
|
|
|
elseif (identifier=="BLIMPRESPAWNTIME" and labeltype==LABEL.ACTION and typ==LABEL.NUMBER) then
|
|
|
|
-- Be forgiving with a 1.3 GAME.CON type error.
|
|
|
|
pwarnprintf(pos, "label \"BLIMPRESPAWNTIME\" is not an `action' value, assuming 0")
|
|
|
|
return "0"
|
2012-12-28 17:18:06 +00:00
|
|
|
else
|
|
|
|
perrprintf(pos, "label \"%s\" is not a%s `%s' value", identifier,
|
|
|
|
labeltype==LABEL.MOVE and "" or "n", LABEL[labeltype])
|
|
|
|
return "_WRONGTYPE"
|
|
|
|
end
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return val
|
|
|
|
end
|
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
function check.reserved_bits(flags, allowedbits, suffix)
|
2013-06-13 17:11:07 +00:00
|
|
|
local rbits = bit.bnot(allowedbits)
|
|
|
|
if (bit.band(flags, rbits) ~= 0) then
|
|
|
|
warnprintf("set one or more reserved bits (0x%s) "..suffix,
|
|
|
|
bit.tohex(bit.band(flags, rbits)))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-04 19:38:32 +00:00
|
|
|
Define.ALLOWED_VIEWTYPE = truetab { 0, 1, 3,4, 5, 7, 8, -5, -7 }
|
|
|
|
|
2013-06-30 20:38:39 +00:00
|
|
|
function Define.composite(labeltype, identifier, ...)
|
2012-11-25 13:18:46 +00:00
|
|
|
local oldtype = g_labeltype[identifier]
|
2012-06-17 19:45:43 +00:00
|
|
|
local oldval = g_labeldef[identifier]
|
|
|
|
|
|
|
|
if (oldval) then
|
2012-11-25 13:18:46 +00:00
|
|
|
if (oldtype ~= labeltype) then
|
2013-11-12 21:03:18 +00:00
|
|
|
errprintf("Refusing to overwrite `%s' label \"%s\" with a `%s' value.",
|
2012-11-25 13:18:46 +00:00
|
|
|
LABEL[oldtype], identifier, LABEL[labeltype])
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.olddef_location(identifier, true)
|
2012-11-25 13:18:46 +00:00
|
|
|
else
|
2013-11-12 21:03:18 +00:00
|
|
|
warnprintf("Duplicate `%s' definition of \"%s\" ignored.",
|
2012-11-25 13:18:46 +00:00
|
|
|
LABEL[labeltype], identifier)
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.olddef_location(identifier, false)
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:37 +00:00
|
|
|
-- Fill up omitted arguments denoting composites with zeros.
|
2012-11-25 13:18:46 +00:00
|
|
|
local isai = (labeltype == LABEL.AI)
|
|
|
|
local args = {...}
|
|
|
|
for i=#args+1,labeltype do
|
2013-03-03 16:06:37 +00:00
|
|
|
-- Passing nil/nothing as remaining args to con.ai will make the
|
|
|
|
-- action/move the null one.
|
2012-11-25 13:18:46 +00:00
|
|
|
args[i] = (isai and i<=2) and "nil" or 0
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
if (isai) then
|
|
|
|
assert(type(args[1])=="string")
|
|
|
|
assert(type(args[2])=="string")
|
|
|
|
|
2012-06-17 19:45:43 +00:00
|
|
|
-- OR together the flags
|
2012-11-25 13:18:46 +00:00
|
|
|
for i=#args,LABEL.AI+1, -1 do
|
|
|
|
args[LABEL.AI] = bit.bor(args[LABEL.AI], args[i])
|
|
|
|
args[i] = nil
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
2013-06-13 17:11:07 +00:00
|
|
|
|
|
|
|
-- Check whether movflags use reserved bits.
|
2013-11-12 21:03:20 +00:00
|
|
|
check.reserved_bits(args[LABEL.AI], 4096+2047, "for ai's movflags")
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
|
|
|
|
2013-07-04 19:38:32 +00:00
|
|
|
if (labeltype == LABEL.ACTION) then
|
|
|
|
-- Sanity-check action members.
|
2013-08-04 20:37:40 +00:00
|
|
|
-- KEEPINSYNC with ACTOR_CHECK in control.lua for consistency.
|
2013-07-04 19:38:32 +00:00
|
|
|
if (not (args[2] >= 0)) then
|
|
|
|
errprintf("action \"%s\" has negative number of frames", identifier)
|
|
|
|
end
|
|
|
|
if (Define.ALLOWED_VIEWTYPE[args[3]] == nil) then
|
|
|
|
errprintf("action \"%s\" has disallowed viewtype %d", identifier, args[3])
|
|
|
|
end
|
|
|
|
if (not (args[4] >= -1 and args[4] <= 1)) then
|
|
|
|
warnprintf("action \"%s\" has incval different from -1, 0 or 1", identifier)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-25 13:18:46 +00:00
|
|
|
-- Make a string out of that.
|
|
|
|
for i=1+(isai and 2 or 0),#args do
|
2012-11-30 18:57:40 +00:00
|
|
|
args[i] = format("%d", args[i])
|
2012-11-25 13:18:46 +00:00
|
|
|
end
|
|
|
|
|
2013-06-30 20:38:39 +00:00
|
|
|
local refcode = mangle_name(identifier, LABEL_PREFIX[labeltype])
|
|
|
|
addcodef(isai and "%s=_con.%s(%s)" or "%s=_con.%s{%s}", -- ai has parens
|
|
|
|
refcode, LABEL_FUNCNAME[labeltype], table.concat(args, ","))
|
2012-11-25 13:18:46 +00:00
|
|
|
|
2013-06-30 20:38:39 +00:00
|
|
|
g_labeldef[identifier] = refcode
|
2012-11-25 13:18:46 +00:00
|
|
|
g_labeltype[identifier] = labeltype
|
2013-11-12 21:03:23 +00:00
|
|
|
g_labelloc[identifier] = getLocation()
|
2012-06-17 19:45:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-10 18:56:21 +00:00
|
|
|
local function parse(contents) end -- fwd-decl
|
|
|
|
|
2013-05-24 13:54:33 +00:00
|
|
|
local function do_include_file(dirname, filename, isroot)
|
2012-12-29 15:21:24 +00:00
|
|
|
assert(type(filename)=="string")
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2012-12-29 15:21:24 +00:00
|
|
|
if (g_have_file[filename] ~= nil) then
|
2013-06-13 17:11:06 +00:00
|
|
|
printf("[%d] Fatal error: infinite loop including \"%s\"", g_recurslevel, filename)
|
2012-12-29 15:21:24 +00:00
|
|
|
g_numerrors = inf
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local contents
|
|
|
|
|
|
|
|
if (read_into_string) then
|
|
|
|
-- running from EDuke32
|
|
|
|
contents = read_into_string(filename)
|
|
|
|
else
|
|
|
|
-- running stand-alone
|
2012-06-10 18:56:21 +00:00
|
|
|
local io = require("io")
|
|
|
|
|
|
|
|
local fd, msg = io.open(dirname..filename)
|
2013-06-07 14:26:34 +00:00
|
|
|
while (fd == nil and not isroot and filename:find("/")) do
|
2012-06-10 18:56:21 +00:00
|
|
|
-- strip up to and including first slash:
|
2013-01-26 17:08:02 +00:00
|
|
|
filename = filename:gsub("^.-/", "")
|
2012-06-10 18:56:21 +00:00
|
|
|
fd, msg = io.open(dirname..filename)
|
2013-06-07 14:26:34 +00:00
|
|
|
end
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2013-06-07 14:26:34 +00:00
|
|
|
-- As a last resort, try the "default directory"
|
2013-07-07 20:58:57 +00:00
|
|
|
if (fd==nil and not isroot and g_defaultDir) then
|
2013-06-07 14:26:34 +00:00
|
|
|
-- strip up to and including last slash (if any):
|
|
|
|
filename = filename:gsub("^.*/", "")
|
|
|
|
dirname = g_defaultDir.."/"
|
|
|
|
fd, msg = io.open(dirname..filename)
|
2013-05-24 13:54:33 +00:00
|
|
|
end
|
2013-01-26 17:08:02 +00:00
|
|
|
|
2013-05-24 13:54:33 +00:00
|
|
|
if (fd == nil) then
|
|
|
|
printf("[%d] Fatal error: couldn't open %s", g_recurslevel, msg)
|
|
|
|
g_numerrors = inf
|
|
|
|
return
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
|
|
|
|
2012-12-29 15:21:24 +00:00
|
|
|
contents = fd:read("*all")
|
2012-06-10 18:56:21 +00:00
|
|
|
fd:close()
|
2012-12-29 15:21:24 +00:00
|
|
|
end
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2012-12-29 15:21:24 +00:00
|
|
|
if (contents == nil) then
|
|
|
|
-- maybe that file name turned out to be a directory or other
|
|
|
|
-- special file accidentally
|
|
|
|
printf("[%d] Fatal error: couldn't read from \"%s\"",
|
|
|
|
g_recurslevel, dirname..filename)
|
|
|
|
g_numerrors = inf
|
|
|
|
return
|
|
|
|
end
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2012-12-29 15:21:24 +00:00
|
|
|
printf("%s[%d] Translating file \"%s\"", (g_recurslevel==-1 and "\n---- ") or "",
|
|
|
|
g_recurslevel+1, dirname..filename);
|
2012-06-17 19:45:43 +00:00
|
|
|
|
2012-12-29 15:21:24 +00:00
|
|
|
local oldfilename = g_filename
|
|
|
|
g_filename = filename
|
|
|
|
parse(contents)
|
|
|
|
g_filename = oldfilename
|
|
|
|
end
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
-- Table of various outer command handling functions.
|
|
|
|
local Cmd = {}
|
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
function Cmd.NYI(msg)
|
|
|
|
return function()
|
|
|
|
errprintf(msg.." not yet implemented")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Cmd.nyi(msg)
|
|
|
|
return function()
|
|
|
|
warnprintf(msg.." not yet implemented")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
function Cmd.include(filename)
|
2013-05-24 13:54:33 +00:00
|
|
|
do_include_file(g_directory, filename, false)
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
|
|
|
|
2012-06-17 19:45:37 +00:00
|
|
|
--- Per-module game data
|
|
|
|
local g_data = {}
|
2012-11-30 18:57:40 +00:00
|
|
|
local EPMUL = conl.MAXLEVELS
|
2012-06-17 19:45:37 +00:00
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
function reset.gamedata()
|
2012-06-17 19:45:37 +00:00
|
|
|
g_data = {}
|
|
|
|
|
|
|
|
-- [EPMUL*ep + lev] = { ptime=<num>, dtime=<num>, fn=<str>, name=<str> }
|
2012-06-17 19:45:41 +00:00
|
|
|
g_data.level = {}
|
|
|
|
-- [ep] = <str>
|
|
|
|
g_data.volname = {}
|
|
|
|
-- [skillnum] = <str>
|
|
|
|
g_data.skillname = {}
|
|
|
|
-- [quotenum] = <str>
|
|
|
|
g_data.quote = {}
|
|
|
|
-- table of length 26 or 30 containg numbers
|
|
|
|
g_data.startup = {}
|
|
|
|
-- [soundnum] = { fn=<str>, params=<table of length 5> }
|
|
|
|
g_data.sound = {}
|
|
|
|
-- [volnum] = <table of length numlevels (<= MAXLEVELS) of <str>>
|
|
|
|
g_data.music = {}
|
2012-06-17 19:45:37 +00:00
|
|
|
end
|
|
|
|
|
2013-05-24 13:54:29 +00:00
|
|
|
-- TODO: PRE13 has no <dtstr> (3D Realms time).
|
2013-01-13 16:40:26 +00:00
|
|
|
function Cmd.definelevelname(vol, lev, fn, ptstr, dtstr, levname)
|
2013-01-20 21:17:23 +00:00
|
|
|
if (not (vol >= 0 and vol < conl.MAXVOLUMES)) then
|
2012-06-17 19:45:37 +00:00
|
|
|
errprintf("volume number exceeds maximum volume count.")
|
2012-06-17 19:45:41 +00:00
|
|
|
return
|
2012-06-17 19:45:37 +00:00
|
|
|
end
|
|
|
|
|
2013-01-20 21:17:23 +00:00
|
|
|
if (not (lev >= 0 and lev < conl.MAXLEVELS)) then
|
2012-06-17 19:45:37 +00:00
|
|
|
errprintf("level number exceeds maximum number of levels per episode.")
|
2012-06-17 19:45:41 +00:00
|
|
|
return
|
2012-06-17 19:45:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- TODO: Bcorrectfilename(fn)
|
|
|
|
|
|
|
|
local function secs(tstr)
|
|
|
|
local m, s = string.match(tstr, ".+:.+")
|
|
|
|
m, s = tonumber(m), tonumber(s)
|
|
|
|
return (m and s) and m*60+s or 0
|
|
|
|
end
|
|
|
|
|
2013-01-05 13:09:19 +00:00
|
|
|
local map = {
|
|
|
|
ptime=secs(ptstr), dtime=secs(dtstr), fn="/"..fn, name=levname
|
2012-06-17 19:45:37 +00:00
|
|
|
}
|
2013-01-05 13:09:19 +00:00
|
|
|
|
|
|
|
if (ffi) then
|
|
|
|
ffiC.C_DefineLevelName(vol, lev, map.fn, map.ptime, map.dtime, map.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
g_data.level[EPMUL*vol+lev] = map
|
2012-06-17 19:45:37 +00:00
|
|
|
end
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2013-01-05 13:09:31 +00:00
|
|
|
local function defineXname(what, ffiCfuncname, X, name)
|
|
|
|
name = name:upper()
|
|
|
|
if (ffi) then
|
|
|
|
ffiC[ffiCfuncname](X, name)
|
|
|
|
if (#name > 32) then
|
|
|
|
warnprintf("%s %d name truncated to 32 characters.", what, X)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return name
|
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
function Cmd.defineskillname(skillnum, name)
|
2013-01-20 21:17:23 +00:00
|
|
|
if (not (skillnum >= 0 and skillnum < conl.MAXSKILLS)) then
|
2013-01-05 13:09:31 +00:00
|
|
|
errprintf("skill number is negative or exceeds maximum skill count.")
|
2012-06-17 19:45:41 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-01-05 13:09:31 +00:00
|
|
|
name = defineXname("skill", "C_DefineSkillName", skillnum, name)
|
|
|
|
g_data.skillname[skillnum] = name
|
2012-06-17 19:45:41 +00:00
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
function Cmd.definevolumename(vol, name)
|
2013-01-20 21:17:23 +00:00
|
|
|
if (not (vol >= 0 and vol < conl.MAXVOLUMES)) then
|
2012-06-17 19:45:41 +00:00
|
|
|
errprintf("volume number is negative or exceeds maximum volume count.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-01-05 13:09:31 +00:00
|
|
|
name = defineXname("volume", "C_DefineVolumeName", vol, name)
|
2013-01-05 13:09:19 +00:00
|
|
|
g_data.volname[vol] = name
|
|
|
|
end
|
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
function Cmd.definegamefuncname(idx, name)
|
|
|
|
local NUMGAMEFUNCTIONS = (ffi and ffiC.NUMGAMEFUNCTIONS or 56)
|
|
|
|
if (not (idx >= 0 and idx < NUMGAMEFUNCTIONS)) then
|
|
|
|
errprintf("function number exceeds number of game functions.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
assert(type(name)=="string")
|
|
|
|
-- XXX: in place of C-CON's "invalid character in function name" report:
|
2013-04-09 17:34:53 +00:00
|
|
|
name = name:gsub("[^A-Za-z0-9]", "_")
|
2013-02-24 16:05:22 +00:00
|
|
|
|
|
|
|
if (ffi) then
|
|
|
|
ffiC.C_DefineGameFuncName(idx, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-30 18:10:49 +00:00
|
|
|
function Cmd.definegametype(idx, flags, name)
|
|
|
|
if (not (idx >= 0 and idx < conl.MAXGAMETYPES)) then
|
|
|
|
errprintf("gametype number exceeds maximum gametype count.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if (ffi) then
|
|
|
|
ffiC.C_DefineGameType(idx, flags, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-05 13:09:19 +00:00
|
|
|
-- strip whitespace from front and back
|
|
|
|
local function stripws(str)
|
|
|
|
return str:match("^%s*(.*)%s*$")
|
2012-06-17 19:45:41 +00:00
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
function Cmd.definequote(qnum, quotestr)
|
2013-01-01 15:24:28 +00:00
|
|
|
if (not (qnum >= 0 and qnum < conl.MAXQUOTES)) then
|
|
|
|
errprintf("quote number is negative or exceeds limit of %d.", conl.MAXQUOTES-1)
|
2013-04-09 17:34:53 +00:00
|
|
|
return ""
|
2013-01-01 15:24:28 +00:00
|
|
|
end
|
2012-06-17 19:45:41 +00:00
|
|
|
|
2013-01-05 13:09:19 +00:00
|
|
|
quotestr = stripws(quotestr)
|
2013-01-01 15:24:28 +00:00
|
|
|
|
2013-02-21 18:53:49 +00:00
|
|
|
if (#quotestr >= conl.MAXQUOTELEN) then
|
|
|
|
-- NOTE: Actually, C_DefineQuote takes care of this! That is,
|
|
|
|
-- standalone, the string isn't truncated.
|
|
|
|
warnprintf("quote %d truncated to %d characters.", qnum, conl.MAXQUOTELEN-1)
|
|
|
|
end
|
2013-01-01 15:24:28 +00:00
|
|
|
|
2013-02-21 18:53:49 +00:00
|
|
|
if (ffi) then
|
2013-01-01 15:24:28 +00:00
|
|
|
ffiC.C_DefineQuote(qnum, quotestr)
|
|
|
|
end
|
|
|
|
|
|
|
|
g_data.quote[qnum] = quotestr
|
2013-04-09 17:34:53 +00:00
|
|
|
return ""
|
2012-06-17 19:45:41 +00:00
|
|
|
end
|
|
|
|
|
2013-06-09 16:37:16 +00:00
|
|
|
local PROJ = {}
|
|
|
|
for key, val in pairs(conl.PROJ) do
|
|
|
|
-- Strip "PROJ_"
|
|
|
|
PROJ[key:sub(6)] = val
|
|
|
|
end
|
|
|
|
|
2013-02-07 21:01:03 +00:00
|
|
|
function Cmd.defineprojectile(tilenum, what, val)
|
2013-06-09 16:37:16 +00:00
|
|
|
local ok = check.tile_idx(tilenum)
|
|
|
|
|
|
|
|
if (what==PROJ.WORKSLIKE) then
|
2013-11-12 21:03:20 +00:00
|
|
|
check.reserved_bits(val, 2^21-1, "for PROJ_WORKSLIKE")
|
2013-06-09 16:37:16 +00:00
|
|
|
elseif (what==PROJ.SOUND or what==PROJ.ISOUND or what==PROJ.BSOUND) then
|
|
|
|
ok = ok and (val==-1 or check.sound_idx(val))
|
|
|
|
elseif (what==PROJ.SPAWNS or what==PROJ.DECAL or what==PROJ.TRAIL) then
|
|
|
|
ok = ok and (val==-1 or check.tile_idx(val))
|
|
|
|
end
|
2013-02-07 21:01:03 +00:00
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
if (ffi and ok) then
|
2013-02-07 21:01:03 +00:00
|
|
|
ffiC.C_DefineProjectile(tilenum, what, val)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-15 14:10:48 +00:00
|
|
|
-- <override>: override-set flags? The default is to bitwise OR with existing.
|
|
|
|
function Cmd.xspriteflags(tilenum, flags, override)
|
2013-06-09 16:37:16 +00:00
|
|
|
local ok = check.tile_idx(tilenum)
|
2014-03-15 14:10:48 +00:00
|
|
|
check.reserved_bits(flags, conl.user_sflags, "for sprite flags")
|
2013-02-24 16:05:22 +00:00
|
|
|
|
2014-03-15 14:10:49 +00:00
|
|
|
local loc = g_code.aflagsloc[tilenum]
|
|
|
|
|
|
|
|
if (override and loc ~= nil) then
|
|
|
|
warnprintf("'spriteflags' after %s %d", loc[4], tilenum)
|
|
|
|
contprintf(false, "at %s %d:%d", loc[1], loc[2], loc[3])
|
|
|
|
end
|
|
|
|
|
|
|
|
g_code.aflagsloc[tilenum] = getLocation(format("'%s' for actor", g_lastkw), pos)
|
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
if (ffi and ok) then
|
2014-03-15 14:10:48 +00:00
|
|
|
local tile = ffiC.g_tile[tilenum]
|
|
|
|
tile._flags = bit.bor(override and 0 or tile._flags, flags)
|
2013-02-24 16:05:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-02 10:50:40 +00:00
|
|
|
function Cmd.precache(tilenum0, tilenum1, flagnum)
|
|
|
|
local ok = check.tile_idx(tilenum0) and check.tile_idx(tilenum1)
|
|
|
|
|
|
|
|
if (ffi and ok) then
|
2014-03-15 14:10:48 +00:00
|
|
|
local tile = ffiC.g_tile[tilenum0]
|
|
|
|
tile._cacherange = tilenum1;
|
2014-02-02 10:50:40 +00:00
|
|
|
if (flagnum) then
|
2014-03-15 14:10:48 +00:00
|
|
|
tile._flags = bit.bor(tile._flags, conl.SFLAG.SFLAG_CACHE)
|
2014-02-02 10:50:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
function Cmd.cheatkeys(sc1, sc2)
|
|
|
|
if (ffi) then
|
|
|
|
ffiC.CheatKeys[0] = sc1
|
|
|
|
ffiC.CheatKeys[1] = sc2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Cmd.setdefname(filename)
|
|
|
|
assert(type(filename)=="string")
|
|
|
|
if (ffi) then
|
|
|
|
if (ffiC.C_SetDefName(filename) ~= 0) then
|
|
|
|
error("OUT OF MEMORY", 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-08 18:08:45 +00:00
|
|
|
function Cmd.setcfgname(filename)
|
|
|
|
assert(type(filename)=="string")
|
|
|
|
if (ffi) then
|
|
|
|
ffiC.C_SetCfgName(filename)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
function Cmd.gamestartup(...)
|
2012-12-29 15:21:24 +00:00
|
|
|
local args = {...}
|
2012-06-17 19:45:41 +00:00
|
|
|
|
2013-05-24 13:54:29 +00:00
|
|
|
-- TODO: PRE13: detection of other g_scriptVersion.
|
2012-12-29 15:21:24 +00:00
|
|
|
if (#args ~= 26 and #args ~= 30) then
|
2012-06-17 19:45:41 +00:00
|
|
|
errprintf("must pass either 26 (1.3D) or 30 (1.5) values")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-01-01 15:24:22 +00:00
|
|
|
if (ffi) then
|
2012-12-29 15:21:24 +00:00
|
|
|
-- running from EDuke32
|
2013-01-01 15:24:22 +00:00
|
|
|
if (#args == 30) then
|
2012-12-29 15:21:24 +00:00
|
|
|
ffiC.g_scriptVersion = 14
|
|
|
|
end
|
|
|
|
local params = ffi.new("int32_t [30]", args)
|
|
|
|
ffiC.G_DoGameStartup(params)
|
|
|
|
end
|
|
|
|
|
|
|
|
g_data.startup = args -- TODO: sanity-check them
|
2012-06-17 19:45:41 +00:00
|
|
|
end
|
|
|
|
|
2013-06-02 14:07:52 +00:00
|
|
|
function Cmd.definesound(sndlabel, fn, ...)
|
|
|
|
local sndnum
|
|
|
|
|
|
|
|
if (type(sndlabel)=="string") then
|
|
|
|
local pos, minus, label = sndlabel:match("(.-):(.-):(.+)")
|
|
|
|
sndnum = lookup.defined_label(tonumber(pos), minus, label)
|
|
|
|
|
|
|
|
if (ffi and g_dynsoundi and (sndnum>=0 and sndnum<conl.MAXSOUNDS)) then
|
|
|
|
dynmap.maybe_init(g_dynsoundi, ffiC.g_dynSoundList)
|
|
|
|
dynmap.maybe_process(g_dynsoundi, ffiC.g_dynSoundList, label, sndnum)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
assert(type(sndlabel)=="number")
|
|
|
|
sndnum = sndlabel
|
|
|
|
end
|
|
|
|
|
2013-01-01 15:24:28 +00:00
|
|
|
if (not (sndnum >= 0 and sndnum < conl.MAXSOUNDS)) then
|
2013-01-05 13:09:19 +00:00
|
|
|
errprintf("sound number is negative or exceeds sound limit of %d", conl.MAXSOUNDS-1)
|
2012-06-17 19:45:41 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 17:11:07 +00:00
|
|
|
local params = {...} -- TODO: sanity-check them some more
|
2013-11-12 21:03:20 +00:00
|
|
|
check.reserved_bits(params[4], 31+128, "for sound flags")
|
2013-06-13 17:11:07 +00:00
|
|
|
|
2013-01-01 15:24:22 +00:00
|
|
|
if (ffi) then
|
|
|
|
local cparams = ffi.new("int32_t [5]", params)
|
|
|
|
assert(type(fn)=="string")
|
|
|
|
ffiC.C_DefineSound(sndnum, fn, cparams)
|
|
|
|
end
|
2012-06-17 19:45:41 +00:00
|
|
|
|
|
|
|
g_data.sound[sndnum] = { fn=fn, params=params }
|
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
function Cmd.music(volnum, ...)
|
2013-03-17 18:11:27 +00:00
|
|
|
local envmusicp = (volnum==0)
|
2013-03-13 10:48:23 +00:00
|
|
|
|
2013-05-26 18:42:53 +00:00
|
|
|
if (not (volnum >= 0 and volnum <= conl.MAXVOLUMES+1)) then
|
|
|
|
-- NOTE: Also allow MAXVOLUMES+1.
|
2013-03-17 18:11:27 +00:00
|
|
|
errprintf("volume number must be between 0 and MAXVOLUMES=%d", conl.MAXVOLUMES)
|
2012-06-17 19:45:41 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local filenames = {...}
|
2013-03-17 18:11:27 +00:00
|
|
|
local MAXFNS = envmusicp and conl.MAXVOLUMES or conl.MAXLEVELS
|
2012-06-17 19:45:41 +00:00
|
|
|
|
2013-03-17 18:11:27 +00:00
|
|
|
if (#filenames > MAXFNS) then
|
|
|
|
warnprintf("ignoring extraneous %d music file names", #filenames-MAXFNS)
|
|
|
|
for i=MAXFNS+1,#filenames do
|
2012-06-17 19:45:41 +00:00
|
|
|
filenames[i] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-05 13:09:19 +00:00
|
|
|
if (ffi) then
|
|
|
|
for i=1,#filenames do
|
|
|
|
assert(type(filenames[i])=="string")
|
2013-03-13 10:48:23 +00:00
|
|
|
ffiC.C_DefineMusic(volnum-1, i-1, "/"..filenames[i])
|
2013-01-05 13:09:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-17 19:45:41 +00:00
|
|
|
g_data.music[volnum] = filenames
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-01-13 16:40:21 +00:00
|
|
|
--- GAMEVARS / GAMEARRAYS
|
|
|
|
|
2013-02-18 16:07:48 +00:00
|
|
|
function Cmd.gamearray(identifier, initsize)
|
2013-11-12 21:03:20 +00:00
|
|
|
if (check.sysvar_def_attempt(identifier)) then
|
2013-02-18 16:07:48 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-02-28 17:30:15 +00:00
|
|
|
if (not (initsize >= 0 and initsize < 0x7fffffff)) then
|
2013-02-18 16:07:48 +00:00
|
|
|
errprintf("invalid initial size %d for gamearray `%s'", initsize, identifier)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local oga = g_gamearray[identifier]
|
|
|
|
if (oga) then
|
2013-03-15 16:56:11 +00:00
|
|
|
if (oga.sysp) then
|
|
|
|
errprintf("attempt to define system gamearray `%s'", identifier)
|
|
|
|
return
|
|
|
|
elseif (initsize ~= oga.size) then
|
2013-02-18 16:07:48 +00:00
|
|
|
errprintf("duplicate gamearray definition `%s' has different size", identifier)
|
|
|
|
return
|
|
|
|
else
|
|
|
|
warnprintf("duplicate gamearray definition `%s' ignored", identifier)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (g_gamevar[identifier]) then
|
|
|
|
warnprintf("symbol `%s' already used for game variable", identifier)
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.oldgv_location(identifier, false)
|
2013-02-18 16:07:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local ga = { name=mangle_name(identifier, "A"), size=initsize }
|
|
|
|
g_gamearray[identifier] = ga
|
|
|
|
|
2013-06-20 18:31:47 +00:00
|
|
|
addcode("if _S then")
|
2013-02-24 16:05:37 +00:00
|
|
|
addcodef("%s=_con._gamearray(%d)", ga.name, initsize)
|
2013-06-20 18:31:47 +00:00
|
|
|
addcode("end")
|
2013-02-18 16:07:48 +00:00
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
function Cmd.gamevar(identifier, initval, flags)
|
2013-11-12 21:03:20 +00:00
|
|
|
if (check.sysvar_def_attempt(identifier)) then
|
2013-02-18 16:07:48 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-01-24 20:03:02 +00:00
|
|
|
if (bit.band(flags, bit.bnot(GVFLAG.USER_MASK)) ~= 0) then
|
2013-01-13 16:40:21 +00:00
|
|
|
-- TODO: a couple of the presumably safe ones
|
2013-01-24 20:03:02 +00:00
|
|
|
errprintf("gamevar flags other than 1, 2, 1024 or 131072: NYI or forbidden")
|
2013-01-23 19:36:48 +00:00
|
|
|
return
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
|
|
|
|
2013-10-20 12:35:06 +00:00
|
|
|
local perPlayer = (bit.band(flags, GVFLAG.PERPLAYER) ~= 0)
|
|
|
|
local perActor = (bit.band(flags, GVFLAG.PERACTOR) ~= 0)
|
|
|
|
|
|
|
|
if (perPlayer and perActor) then
|
2013-01-13 16:40:21 +00:00
|
|
|
errprintf("invalid gamevar flags: must be either PERPLAYER or PERACTOR, not both")
|
2013-01-23 19:36:48 +00:00
|
|
|
return
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local ogv = g_gamevar[identifier]
|
2014-08-08 20:02:55 +00:00
|
|
|
-- handle NORESET or NODEFAULT
|
2013-10-20 12:35:06 +00:00
|
|
|
local isSessionVar = (bit.band(flags, GVFLAG.NODEFAULT) ~= 0)
|
2013-11-08 18:08:37 +00:00
|
|
|
local storeWithSavegames = (bit.band(flags, GVFLAG.NORESET) == 0)
|
2013-10-20 12:35:06 +00:00
|
|
|
|
|
|
|
if (isSessionVar and (perPlayer or perActor)) then
|
|
|
|
if (ogv == nil) then -- warn only once per gamevar
|
2013-11-08 18:08:37 +00:00
|
|
|
warnprintf("per-%s session gamevar `%s': NYI, made %s",
|
2013-10-20 12:35:06 +00:00
|
|
|
perPlayer and "player" or "actor",
|
2013-11-08 18:08:37 +00:00
|
|
|
identifier,
|
|
|
|
perPlayer and "global" or "non-session")
|
2013-10-20 12:35:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if (perActor) then
|
|
|
|
flags = bit.band(flags, bit.bnot(GVFLAG.NODEFAULT))
|
|
|
|
isSessionVar = false
|
|
|
|
elseif (perPlayer) then
|
|
|
|
flags = bit.band(flags, bit.bnot(GVFLAG.PERPLAYER))
|
|
|
|
perPlayer = false
|
|
|
|
end
|
|
|
|
end
|
2013-01-13 16:40:21 +00:00
|
|
|
|
|
|
|
if (ogv ~= nil) then
|
2013-01-20 21:17:23 +00:00
|
|
|
local oflags = ogv.flags
|
|
|
|
if (oflags ~= flags) then
|
2013-10-20 12:35:06 +00:00
|
|
|
if (bit.band(oflags, GVFLAG.SYSTEM) ~= 0 and not isSessionVar) then
|
2013-01-20 21:17:23 +00:00
|
|
|
-- Attempt to override a system gamevar. See if it's read-only...
|
|
|
|
if (bit.band(oflags, GVFLAG.READONLY) ~= 0) then
|
|
|
|
errprintf("attempt to override read-only system gamevar `%s'", identifier)
|
2013-01-23 19:36:48 +00:00
|
|
|
return
|
2013-01-20 21:17:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local flagsnosys = bit.band(oflags, bit.bnot(GVFLAG.SYSTEM))
|
2013-01-26 17:08:02 +00:00
|
|
|
if (flagsnosys ~= flags and g_warn["system-gamevar"]) then
|
2013-01-20 21:17:23 +00:00
|
|
|
warnprintf("overrode initial value of `%s', but kept "..
|
|
|
|
"flags (%d)", identifier, flagsnosys)
|
|
|
|
end
|
|
|
|
|
2013-03-15 16:56:15 +00:00
|
|
|
if (ogv.rbits and bit.band(ogv.rbits, initval)~=0) then
|
|
|
|
warnprintf("set one or more reserved bits (0x%s) in overriding `%s'",
|
|
|
|
bit.tohex(bit.band(ogv.rbits, initval)), identifier)
|
|
|
|
end
|
|
|
|
|
2013-03-18 22:05:26 +00:00
|
|
|
local linestr = "--"..getlinecol(g_lastkwpos)
|
|
|
|
|
2013-01-20 21:17:23 +00:00
|
|
|
-- Emit code to set the variable at Lua parse time.
|
2013-06-20 18:31:47 +00:00
|
|
|
-- XXX: How does this interact with savegame restoration?
|
2013-01-20 21:17:23 +00:00
|
|
|
if (bit.band(oflags, GVFLAG.PERPLAYER) ~= 0) then
|
2013-06-02 14:07:56 +00:00
|
|
|
-- Replace player index by 0. PLAYER_0.
|
2013-03-15 16:56:15 +00:00
|
|
|
-- TODO_MP: init for all players.
|
2013-01-20 21:17:23 +00:00
|
|
|
local pvar, numrepls = ogv.name:gsub("_pli", "0")
|
|
|
|
assert(numrepls>=1)
|
2013-03-18 22:05:26 +00:00
|
|
|
addcodef("%s=%d%s", pvar, initval, linestr)
|
2013-01-20 21:17:23 +00:00
|
|
|
else
|
2013-03-18 22:05:26 +00:00
|
|
|
addcodef("%s=%d%s", ogv.name, initval, linestr)
|
2013-01-20 21:17:23 +00:00
|
|
|
end
|
2013-01-23 19:36:48 +00:00
|
|
|
return
|
2013-01-20 21:17:23 +00:00
|
|
|
end
|
|
|
|
|
2013-11-12 21:03:18 +00:00
|
|
|
errprintf("duplicate definition of gamevar `%s' has different flags", identifier)
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.oldgv_location(identifier, true)
|
2013-01-23 19:36:48 +00:00
|
|
|
return
|
2013-01-13 16:40:21 +00:00
|
|
|
else
|
2013-11-12 21:03:18 +00:00
|
|
|
warnprintf("duplicate definition of gamevar `%s' ignored", identifier)
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.oldgv_location(identifier, false)
|
2013-01-23 19:36:48 +00:00
|
|
|
return
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local ltype = g_labeltype[identifier]
|
|
|
|
if (ltype ~= nil) then
|
2013-11-12 21:03:18 +00:00
|
|
|
warnprintf("Symbol `%s' already used for a defined %s.", identifier, LABEL[ltype])
|
2013-11-12 21:03:23 +00:00
|
|
|
inform.olddef_location(identifier, false)
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
|
|
|
|
2013-10-20 12:35:06 +00:00
|
|
|
if (isSessionVar) then
|
|
|
|
if (g_numSessionVars == conl.MAXSESSIONVARS) then
|
|
|
|
errprintf("Declared too many session gamevars (flag 1024), can have at most %d.",
|
|
|
|
conl.MAXSESSIONVARS)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Declare new session gamevar.
|
2014-08-08 20:02:55 +00:00
|
|
|
local gv = { name=format("_gv._sessionVar[%d]", g_numSessionVars),
|
|
|
|
flags=flags, loc=getLocation(), used=0 }
|
2013-10-20 12:35:06 +00:00
|
|
|
g_numSessionVars = g_numSessionVars+1
|
2014-08-08 20:02:55 +00:00
|
|
|
|
|
|
|
g_gamevar[identifier] = gv;
|
|
|
|
-- Initialize it (i.e. set to the declared initial value) on first run,
|
|
|
|
-- but not from savegames.
|
|
|
|
addcodef("if _S then %s=%d end", gv.name, initval)
|
|
|
|
|
2013-10-20 12:35:06 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-02-08 14:37:47 +00:00
|
|
|
local gv = { name=mangle_name(identifier, "V"), flags=flags, loc=getLocation(), used=0 }
|
2013-01-13 16:40:21 +00:00
|
|
|
g_gamevar[identifier] = gv
|
|
|
|
|
2013-11-08 18:08:37 +00:00
|
|
|
if (storeWithSavegames) then
|
|
|
|
addcode("if _S then")
|
|
|
|
end
|
2013-06-20 18:31:47 +00:00
|
|
|
|
2013-10-20 12:35:06 +00:00
|
|
|
if (perActor) then
|
2013-05-20 19:58:54 +00:00
|
|
|
addcodef("%s=_con.actorvar(%d)", gv.name, initval)
|
2013-10-20 12:35:06 +00:00
|
|
|
elseif (perPlayer and g_cgopt["playervar"]) then
|
2013-06-01 20:09:41 +00:00
|
|
|
gv.flags = bit.bor(gv.flags, GVFLAG.CON_PERPLAYER)
|
|
|
|
addcodef("%s=_con.playervar(%d)", gv.name, initval)
|
2013-01-13 16:40:21 +00:00
|
|
|
else
|
2013-02-24 16:05:37 +00:00
|
|
|
addcodef("%s=%d", gv.name, initval)
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
2013-06-20 18:31:47 +00:00
|
|
|
|
2013-11-08 18:08:37 +00:00
|
|
|
if (storeWithSavegames) then
|
|
|
|
addcode("end")
|
|
|
|
end
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
|
|
|
|
2013-05-26 18:42:53 +00:00
|
|
|
function Cmd.dynamicremap()
|
|
|
|
if (g_dyntilei==nil) then
|
|
|
|
print("Using dynamic tile remapping");
|
2013-06-02 14:07:52 +00:00
|
|
|
g_dyntilei = {};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Cmd.dynamicsoundremap()
|
|
|
|
if (g_dynsoundi==nil) then
|
|
|
|
print("Using dynamic sound remapping");
|
|
|
|
g_dynsoundi = {};
|
2013-05-26 18:42:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-18 16:07:48 +00:00
|
|
|
function lookup.gamearray(identifier)
|
|
|
|
local ga = g_gamearray[identifier]
|
|
|
|
if (ga == nil) then
|
|
|
|
errprintf("symbol `%s' is not a game array", identifier)
|
|
|
|
return "_INVALIDGA"
|
|
|
|
end
|
|
|
|
return ga.name
|
|
|
|
end
|
|
|
|
|
2013-06-01 20:09:41 +00:00
|
|
|
local function thisactor_to_pli(var)
|
|
|
|
return (var=="_aci") and "_pli" or var
|
|
|
|
end
|
|
|
|
|
2013-10-20 12:35:03 +00:00
|
|
|
function lookup.error_not_gamevar(identifier)
|
|
|
|
errprintf("symbol `%s' is not a game variable", identifier)
|
|
|
|
return "_INVALIDGV"
|
|
|
|
end
|
|
|
|
|
2013-02-10 16:23:59 +00:00
|
|
|
-- <aorpvar>: code for actor or player index
|
|
|
|
function lookup.gamevar(identifier, aorpvar, writable)
|
2013-01-13 16:40:21 +00:00
|
|
|
local gv = g_gamevar[identifier]
|
|
|
|
|
|
|
|
if (gv == nil) then
|
2013-10-20 12:35:03 +00:00
|
|
|
return lookup.error_not_gamevar(identifier)
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:32 +00:00
|
|
|
if (writable and bit.band(gv.flags, GVFLAG.READONLY) ~= 0) then
|
2013-03-17 18:11:47 +00:00
|
|
|
errprintf("gamevar `%s' is read-only", identifier)
|
2013-01-13 16:40:32 +00:00
|
|
|
return "_READONLYGV"
|
|
|
|
end
|
|
|
|
|
2014-02-08 14:37:47 +00:00
|
|
|
gv.used = bit.bor(gv.used, writable and 2 or 1)
|
|
|
|
|
2013-02-10 16:23:59 +00:00
|
|
|
if (bit.band(gv.flags, GVFLAG.PERACTOR)~=0) then
|
|
|
|
return format("%s[%s]", gv.name, aorpvar)
|
2013-06-01 20:09:41 +00:00
|
|
|
elseif (bit.band(gv.flags, GVFLAG.CON_PERPLAYER)~=0 and g_cgopt["playervar"]) then
|
|
|
|
return format("%s[%s]", gv.name, thisactor_to_pli(aorpvar))
|
2013-01-13 16:40:21 +00:00
|
|
|
else
|
|
|
|
return gv.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function maybe_gamevar_Cmt(subj, pos, identifier)
|
|
|
|
if (g_gamevar[identifier]) then
|
2013-02-10 16:23:59 +00:00
|
|
|
return true, lookup.gamevar(identifier, "_aci", false)
|
2013-01-13 16:40:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
----==== patterns ====----
|
|
|
|
|
|
|
|
---- basic ones
|
2012-04-29 20:54:06 +00:00
|
|
|
-- Windows, *nix and Mac newlines all exist in the wild!
|
|
|
|
local newline = "\r"*Pat("\n")^-1 + "\n"
|
|
|
|
local EOF = Pat(-1)
|
2012-04-07 20:10:03 +00:00
|
|
|
local anychar = Pat(1)
|
|
|
|
-- comments
|
|
|
|
local comment = "/*" * match_until(anychar, "*/") * "*/"
|
|
|
|
local linecomment = "//" * match_until(anychar, newline)
|
|
|
|
local whitespace = Var("whitespace")
|
|
|
|
local sp0 = whitespace^0
|
2012-04-29 20:54:06 +00:00
|
|
|
-- This "WS+" pattern matches EOF too, so that a forgotten newline at EOF is
|
|
|
|
-- properly handled
|
|
|
|
local sp1 = whitespace^1 + EOF
|
2012-04-07 20:10:03 +00:00
|
|
|
local alpha = Range("AZ", "az") -- locale?
|
|
|
|
local alphanum = alpha + Range("09")
|
2012-04-29 20:54:06 +00:00
|
|
|
--local alnumtok = alphanum + Set("{}/\\*-_.") -- see isaltok() in gamedef.c
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-13 16:40:21 +00:00
|
|
|
--- Basic lexical elements ("tokens"). See the final grammar ("Grammar") for
|
|
|
|
--- their definitions.
|
2013-01-13 16:40:26 +00:00
|
|
|
local tok =
|
|
|
|
{
|
|
|
|
maybe_minus = (Pat("-") * sp0)^-1,
|
|
|
|
number = Var("t_number"),
|
|
|
|
|
2013-01-24 20:03:06 +00:00
|
|
|
-- Valid identifier names are disjunct from keywords!
|
|
|
|
-- XXX: CON is more permissive with identifier name characters:
|
2013-01-13 16:40:26 +00:00
|
|
|
identifier = Var("t_identifier"),
|
2013-01-24 20:03:06 +00:00
|
|
|
-- This one matches keywords, too:
|
2013-01-13 16:40:26 +00:00
|
|
|
identifier_all = Var("t_identifier_all"),
|
|
|
|
define = Var("t_define"),
|
2013-06-02 14:07:52 +00:00
|
|
|
rawdefine = Var("t_rawdefine"),
|
2013-01-13 16:40:26 +00:00
|
|
|
move = Var("t_move"),
|
|
|
|
ai = Var("t_ai"),
|
|
|
|
action = Var("t_action"),
|
|
|
|
|
2013-01-24 20:03:06 +00:00
|
|
|
-- NOTE: no chance to whitespace and double quotes in filenames:
|
2013-01-13 16:40:26 +00:00
|
|
|
filename = lpeg.C((anychar-Set(" \t\r\n\""))^1),
|
|
|
|
newline_term_str = match_until(anychar, newline),
|
|
|
|
|
|
|
|
rvar = Var("t_rvar"),
|
|
|
|
wvar = Var("t_wvar"),
|
2013-02-18 16:07:48 +00:00
|
|
|
gamearray = Var("t_gamearray"),
|
2013-01-13 16:40:26 +00:00
|
|
|
|
2013-01-24 20:03:06 +00:00
|
|
|
-- for definelevelname
|
2013-01-13 16:40:26 +00:00
|
|
|
time = lpeg.C(alphanum*alphanum^-1*":"*alphanum*alphanum^-1),
|
2013-01-19 18:28:55 +00:00
|
|
|
|
|
|
|
state_ends = Pat("ends")
|
|
|
|
+ POS() * "else" * sp1 * "ends"
|
|
|
|
/ function(pos) pwarnprintf(pos, "stray `else' at end of state") end,
|
2013-01-13 16:40:26 +00:00
|
|
|
}
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
---- helper patterns / pattern constructing functions
|
2013-01-13 16:40:26 +00:00
|
|
|
local maybe_quoted_filename = ('"' * tok.filename * '"' + tok.filename)
|
2012-04-29 20:54:06 +00:00
|
|
|
-- empty string is handled too; we must not eat the newline then!
|
2012-06-10 18:56:21 +00:00
|
|
|
local newline_term_string = (#newline + EOF)*lpeg.Cc("")
|
2013-01-13 16:40:26 +00:00
|
|
|
+ (whitespace-newline)^1 * lpeg.C(tok.newline_term_str)
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
-- (sp1 * tok.define) repeated exactly n times
|
2012-04-07 20:10:03 +00:00
|
|
|
local function n_defines(n) -- works well only for small n
|
|
|
|
local pat = Pat(true)
|
|
|
|
for i=1,n do
|
2013-01-13 16:40:26 +00:00
|
|
|
pat = sp1 * tok.define * pat
|
2012-04-07 20:10:03 +00:00
|
|
|
end
|
|
|
|
return pat
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-02-18 16:07:48 +00:00
|
|
|
local D, R, W, I, GARI, AC, MV, AI = -1, -2, -3, -4, -5, -6, -7, -8
|
|
|
|
local TOKEN_PATTERN = { [D]=tok.define, [R]=tok.rvar, [W]=tok.wvar,
|
|
|
|
[I]=tok.identifier, [GARI]=tok.gamearray,
|
2013-01-13 16:40:26 +00:00
|
|
|
[AC]=tok.action, [MV]=tok.move, [AI]=tok.ai }
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
-- Generic command pattern, types given by varargs.
|
|
|
|
-- The command name to be matched is attached later.
|
|
|
|
-- Example:
|
|
|
|
-- "command" writtenvar readvar def def: gencmd(W,R,D,D)
|
2013-01-13 16:40:26 +00:00
|
|
|
-- --> sp1 * tok.wvar * sp1 * tok.rvar * sp1 * tok.define * sp1 * tok.define
|
2012-04-07 20:10:03 +00:00
|
|
|
-- "command_with_no_args": gencmd()
|
|
|
|
-- --> Pat(true)
|
|
|
|
local function cmd(...)
|
|
|
|
local pat = Pat(true)
|
|
|
|
local vartypes = {...}
|
|
|
|
|
|
|
|
for i=1,#vartypes do
|
2012-06-17 19:45:43 +00:00
|
|
|
pat = pat * sp1 * assert(TOKEN_PATTERN[vartypes[i]])
|
2012-04-07 20:10:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return pat
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- The command names will be attached to the front of the patterns later!
|
|
|
|
|
|
|
|
--== Top level CON commands ==--
|
2012-04-29 20:54:06 +00:00
|
|
|
-- XXX: many of these are also allowed inside actors/states/events in CON.
|
2013-01-13 16:40:26 +00:00
|
|
|
local Couter = {
|
2012-04-07 20:10:03 +00:00
|
|
|
--- 1. Preprocessor
|
2013-02-24 16:05:22 +00:00
|
|
|
include = sp1 * maybe_quoted_filename
|
|
|
|
/ Cmd.include,
|
|
|
|
includedefault = cmd()
|
|
|
|
/ Cmd.NYI("`includedefault'"),
|
|
|
|
define = cmd(I,D)
|
2013-06-30 20:38:39 +00:00
|
|
|
/ Define.label,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
--- 2. Defines and Meta-Settings
|
2013-02-24 16:05:22 +00:00
|
|
|
dynamicremap = cmd()
|
2013-05-26 18:42:53 +00:00
|
|
|
/ Cmd.dynamicremap,
|
2013-06-01 20:09:45 +00:00
|
|
|
dynamicsoundremap = cmd()
|
2013-06-02 14:07:52 +00:00
|
|
|
/ Cmd.dynamicsoundremap,
|
2013-02-24 16:05:22 +00:00
|
|
|
setcfgname = sp1 * tok.filename
|
2013-11-08 18:08:45 +00:00
|
|
|
/ Cmd.setcfgname,
|
2013-02-24 16:05:22 +00:00
|
|
|
setdefname = sp1 * tok.filename
|
|
|
|
/ Cmd.setdefname,
|
|
|
|
setgamename = newline_term_string
|
|
|
|
/ Cmd.nyi("`setgamename'"),
|
|
|
|
|
|
|
|
precache = cmd(D,D,D)
|
2014-02-02 10:50:40 +00:00
|
|
|
/ Cmd.precache,
|
2012-12-09 13:24:39 +00:00
|
|
|
scriptsize = cmd(D)
|
|
|
|
/ "", -- no-op
|
2013-02-24 16:05:22 +00:00
|
|
|
cheatkeys = cmd(D,D)
|
|
|
|
/ Cmd.cheatkeys,
|
|
|
|
|
|
|
|
definecheat = newline_term_string -- XXX: actually tricker syntax (TS)
|
|
|
|
, -- / Cmd.nyi("`definecheat'"),
|
|
|
|
definegamefuncname = sp1 * tok.define * newline_term_string -- XXX: TS?
|
|
|
|
/ Cmd.definegamefuncname,
|
|
|
|
definegametype = n_defines(2) * newline_term_string
|
2013-05-30 18:10:49 +00:00
|
|
|
/ Cmd.definegametype,
|
2013-01-13 16:40:26 +00:00
|
|
|
definelevelname = n_defines(2) * sp1 * tok.filename * sp1 * tok.time * sp1 * tok.time *
|
2013-02-24 16:05:22 +00:00
|
|
|
newline_term_string
|
|
|
|
/ Cmd.definelevelname,
|
|
|
|
defineskillname = sp1 * tok.define * newline_term_string
|
|
|
|
/ Cmd.defineskillname,
|
|
|
|
definevolumename = sp1 * tok.define * newline_term_string
|
|
|
|
/ Cmd.definevolumename,
|
|
|
|
|
|
|
|
definequote = sp1 * tok.define * newline_term_string
|
|
|
|
/ Cmd.definequote,
|
|
|
|
defineprojectile = cmd(D,D,D)
|
|
|
|
/ Cmd.defineprojectile,
|
2013-06-02 14:07:52 +00:00
|
|
|
definesound = sp1 * tok.rawdefine * sp1 * maybe_quoted_filename * n_defines(5)
|
2013-02-24 16:05:22 +00:00
|
|
|
/ Cmd.definesound,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-06-17 19:45:37 +00:00
|
|
|
-- NOTE: gamevar.ogg and the like is OK, too
|
2013-02-24 16:05:22 +00:00
|
|
|
music = sp1 * tok.define * match_until(sp1 * tok.filename, sp1 * conl.keyword * sp1)
|
|
|
|
/ Cmd.music,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
--- 3. Game Settings
|
2012-12-03 18:24:30 +00:00
|
|
|
-- gamestartup has 26/30 fixed defines, depending on 1.3D/1.5 version:
|
2013-02-24 16:05:22 +00:00
|
|
|
gamestartup = (sp1 * tok.define)^26
|
|
|
|
/ Cmd.gamestartup,
|
|
|
|
spritenopal = cmd(D)
|
2014-03-15 14:10:48 +00:00
|
|
|
/ function(tilenum, flags) Cmd.xspriteflags(tilenum, conl.SFLAG.SFLAG_NOPAL) end,
|
2013-02-24 16:05:22 +00:00
|
|
|
spritenoshade = cmd(D)
|
2014-03-15 14:10:48 +00:00
|
|
|
/ function(tilenum, flags) Cmd.xspriteflags(tilenum, conl.SFLAG.SFLAG_NOSHADE) end,
|
2013-02-24 16:05:22 +00:00
|
|
|
spritenvg = cmd(D)
|
2014-03-15 14:10:48 +00:00
|
|
|
/ function(tilenum, flags) Cmd.xspriteflags(tilenum, conl.SFLAG.SFLAG_NVG) end,
|
2013-02-24 16:05:22 +00:00
|
|
|
spriteshadow = cmd(D)
|
2014-03-15 14:10:48 +00:00
|
|
|
/ function(tilenum, flags) Cmd.xspriteflags(tilenum, conl.SFLAG.SFLAG_SHADOW) end,
|
2013-02-24 16:05:22 +00:00
|
|
|
|
|
|
|
spriteflags = cmd(D,D) -- also see inner
|
2014-03-15 14:10:48 +00:00
|
|
|
/ function(tilenum, flags) Cmd.xspriteflags(tilenum, flags, true) end,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
--- 4. Game Variables / Arrays
|
2013-02-24 16:05:22 +00:00
|
|
|
gamevar = cmd(I,D,D)
|
|
|
|
/ Cmd.gamevar,
|
|
|
|
gamearray = cmd(I,D)
|
|
|
|
/ Cmd.gamearray,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
--- 5. Top level commands that are also run-time commands
|
2013-02-24 16:05:22 +00:00
|
|
|
move = sp1 * tok.identifier * (sp1 * tok.define)^-2 -- hvel, vvel
|
2013-06-30 20:38:39 +00:00
|
|
|
/ function(...) Define.composite(LABEL.MOVE, ...) end,
|
2012-11-25 13:18:46 +00:00
|
|
|
|
2012-06-17 19:45:43 +00:00
|
|
|
-- startframe, numframes, viewtype, incval, delay:
|
2013-02-24 16:05:22 +00:00
|
|
|
action = sp1 * tok.identifier * (sp1 * tok.define)^-5
|
2013-06-30 20:38:39 +00:00
|
|
|
/ function(...) Define.composite(LABEL.ACTION, ...) end,
|
2012-06-17 19:45:43 +00:00
|
|
|
|
|
|
|
-- action, move, flags...:
|
2013-01-13 16:40:26 +00:00
|
|
|
ai = sp1 * tok.identifier * (sp1 * tok.action *
|
2013-02-24 16:05:22 +00:00
|
|
|
(sp1 * tok.move * (sp1 * tok.define)^0)^-1
|
|
|
|
)^-1
|
2013-06-30 20:38:39 +00:00
|
|
|
/ function(...) Define.composite(LABEL.AI, ...) end,
|
2012-06-17 19:45:43 +00:00
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
--- 6. Deprecated TLCs
|
|
|
|
betaname = newline_term_string,
|
|
|
|
enhanced = cmd(D),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
--== Run time CON commands ==--
|
|
|
|
--- 1. Gamevar Operators
|
2013-06-07 10:18:12 +00:00
|
|
|
local Op = {}
|
|
|
|
Op.var = cmd(W,D)
|
|
|
|
Op.varvar = cmd(W,R)
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-07-13 21:04:50 +00:00
|
|
|
function Op.var_common(thecmd, defaultop, trapop, wrapop)
|
|
|
|
local theop =
|
|
|
|
g_cgopt["trapv"] and trapop or
|
|
|
|
g_cgopt["wrapv"] and wrapop or
|
|
|
|
assert(defaultop)
|
|
|
|
|
|
|
|
if (#theop <= 2) then
|
|
|
|
return thecmd / ("%1=%1"..theop.."%2")
|
2013-01-13 16:40:32 +00:00
|
|
|
else
|
2013-07-13 21:04:50 +00:00
|
|
|
return thecmd / ("%1="..theop.."(%1,%2)")
|
2013-01-13 16:40:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-13 21:04:50 +00:00
|
|
|
function Op.varf(...)
|
|
|
|
return Op.var_common(Op.var, ...)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Op.varvarf(...)
|
|
|
|
return Op.var_common(Op.varvar, ...)
|
2013-01-13 16:40:32 +00:00
|
|
|
end
|
|
|
|
|
2012-04-29 20:54:06 +00:00
|
|
|
-- Allow nesting... stuff like
|
|
|
|
-- ifvarl actorvar[sprite[THISACTOR].owner].burning 0
|
|
|
|
-- is kinda breaking the classic "no array nesting" rules
|
2012-12-28 17:18:02 +00:00
|
|
|
-- (if there ever were any) but making our life harder else.
|
2013-01-13 16:40:26 +00:00
|
|
|
local arraypat = sp0 * "[" * sp0 * tok.rvar * sp0 * "]"
|
2014-02-01 16:19:55 +00:00
|
|
|
-- For {get,set}userdef:
|
|
|
|
local arraypat_maybe_empty = sp0 * "[" * sp0 * (tok.rvar * sp0)^-1 * "]"
|
2012-04-29 20:54:06 +00:00
|
|
|
|
2013-06-07 10:18:12 +00:00
|
|
|
-- Table of various patterns that are (parts of) more complex inner commands.
|
|
|
|
local patt = {}
|
|
|
|
|
2013-01-24 20:03:06 +00:00
|
|
|
-- Have to bite the bullet here and list actor/player members with second
|
|
|
|
-- parameters, even though it's ugly to make it part of the syntax. Also,
|
|
|
|
-- stuff like
|
2012-04-29 20:54:06 +00:00
|
|
|
-- actor[xxx].loogiex parm2 x
|
2013-01-24 20:03:06 +00:00
|
|
|
-- will be wrongly accepted at the parsing stage (loogiex is player's member)
|
|
|
|
-- because we don't discriminate between actor and player here.
|
2013-06-07 10:18:12 +00:00
|
|
|
patt.parm2member = lpeg.C(Pat("htg_t") + "loogiex" + "loogiey" + "ammo_amount" +
|
|
|
|
"weaprecs" + "gotweapon" + "pals" + "max_ammo_amount") * sp1 * tok.rvar
|
|
|
|
|
|
|
|
-- The member name must match keywords, too (_all), because e.g. cstat is a
|
|
|
|
-- member of sprite[].
|
|
|
|
patt.bothmember = sp0 * "." * sp0 * lpeg.Ct(patt.parm2member + tok.identifier_all)
|
|
|
|
patt.singlemember = sp0 * "." * sp0 * tok.identifier_all
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-06-07 10:18:12 +00:00
|
|
|
patt.cmdgetstruct = -- get<structname>[<idx>].<member> (<parm2>)? <<var>>
|
|
|
|
arraypat * patt.bothmember * sp1 * tok.wvar
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-06-07 10:18:12 +00:00
|
|
|
patt.cmdsetstruct = -- set<structname>[<idx>].<<member>> (<parm2>)? <var>
|
|
|
|
arraypat * patt.bothmember * sp1 * tok.rvar
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-06-07 10:18:12 +00:00
|
|
|
patt.cmdgetperxvar = -- get<actor/player>var[<idx>].<varname> <<var>>
|
|
|
|
arraypat * patt.singlemember * sp1 * tok.wvar
|
2013-01-24 20:03:06 +00:00
|
|
|
|
2013-06-07 10:18:12 +00:00
|
|
|
patt.cmdsetperxvar = -- set<actor/player>var[<idx>].<<varname>> <var>
|
|
|
|
arraypat * patt.singlemember * sp1 * tok.rvar
|
2013-01-24 20:03:06 +00:00
|
|
|
|
2013-01-24 20:03:10 +00:00
|
|
|
-- Function generating code for a struct read/write access.
|
|
|
|
local function StructAccess(Structname, writep, index, membertab)
|
|
|
|
assert(type(membertab)=="table")
|
2013-02-10 16:24:20 +00:00
|
|
|
-- Lowercase the member name for CON compatibility
|
|
|
|
local member, parm2 = membertab[1]:lower(), membertab[2]
|
2013-01-24 20:03:10 +00:00
|
|
|
|
2013-02-03 12:48:06 +00:00
|
|
|
local MemberCode = conl.StructAccessCode[Structname] or conl.StructAccessCode2[Structname]
|
2013-01-24 20:03:10 +00:00
|
|
|
-- Look up array+member name first, e.g. "spriteext[%s].angoff".
|
2013-02-03 12:48:06 +00:00
|
|
|
local armembcode = MemberCode[member]
|
2013-01-24 20:03:10 +00:00
|
|
|
if (armembcode == nil) then
|
2013-02-10 16:24:20 +00:00
|
|
|
errprintf("%s: invalid %s member `.%s'", g_lastkw, Structname, member)
|
2013-01-24 20:03:10 +00:00
|
|
|
return "_MEMBINVALID"
|
|
|
|
end
|
|
|
|
|
2013-12-11 21:23:42 +00:00
|
|
|
-- Function checking a literal number for being OK for assignment to this
|
|
|
|
-- member. Can also be a table {min, max}. See con_lang.lua, LITERAL_CHECKING.
|
|
|
|
local lit_ok_func_or_table
|
|
|
|
|
2013-01-24 20:03:10 +00:00
|
|
|
if (type(armembcode)=="table") then
|
|
|
|
-- Read and write accesses differ.
|
2013-12-11 21:23:42 +00:00
|
|
|
if (writep) then
|
|
|
|
lit_ok_func_or_table = armembcode[3]
|
|
|
|
end
|
2013-01-24 20:03:10 +00:00
|
|
|
armembcode = armembcode[writep and 2 or 1]
|
|
|
|
if (armembcode==nil) then
|
|
|
|
errprintf("%s access to %s[].%s is not available",
|
|
|
|
writep and "write" or "read", Structname, member)
|
|
|
|
return "_MEMBNOACCESS"
|
2013-01-24 20:03:06 +00:00
|
|
|
end
|
2013-01-24 20:03:10 +00:00
|
|
|
end
|
2013-01-24 20:03:06 +00:00
|
|
|
|
2013-02-10 16:24:20 +00:00
|
|
|
if (Structname~="userdef") then
|
|
|
|
-- Count number of parameters ("%s"), don't count "%%s".
|
|
|
|
local _, numparms = armembcode:gsub("[^%%]%%s", "", 2)
|
|
|
|
if (#membertab ~= numparms) then
|
|
|
|
local nums = { "one", "two" }
|
|
|
|
errprintf("%s[].%s has %s parameter%s, but %s given", Structname,
|
|
|
|
member, nums[numparms], numparms==1 and "" or "s",
|
|
|
|
nums[#membertab])
|
|
|
|
return "_MEMBINVPARM"
|
|
|
|
end
|
2013-01-24 20:03:10 +00:00
|
|
|
end
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
-- THISACTOR special meanings
|
|
|
|
if (Structname=="player" or Structname=="input") then
|
|
|
|
index = thisactor_to_pli(index)
|
|
|
|
elseif (Structname=="sector") then
|
|
|
|
if (index=="_aci") then
|
|
|
|
index = SPS".sectnum"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-01 13:04:52 +00:00
|
|
|
-- METHOD_MEMBER
|
|
|
|
local ismethod = (armembcode:find("%%s",1,true)~=nil)
|
|
|
|
-- If ismethod is true, then the formatted string will now have an "%s"
|
2013-03-15 16:56:07 +00:00
|
|
|
local code
|
2013-02-10 16:24:20 +00:00
|
|
|
|
|
|
|
if (Structname=="userdef") then
|
|
|
|
-- assert(index==nil)
|
|
|
|
assert(parm2==nil)
|
2013-03-15 16:56:07 +00:00
|
|
|
code = format(armembcode, parm2)
|
2013-02-10 16:24:20 +00:00
|
|
|
else
|
2013-03-15 16:56:07 +00:00
|
|
|
code = format(armembcode, index, parm2)
|
2013-02-10 16:24:20 +00:00
|
|
|
end
|
2013-03-15 16:56:07 +00:00
|
|
|
|
|
|
|
if (csapp()) then
|
|
|
|
if (Structname=="player") then
|
|
|
|
code = code:gsub("^player%[_pli%]", "_ps")
|
|
|
|
elseif (Structname=="sprite") then
|
|
|
|
code = code:gsub("^actor%[_aci%]", "_a")
|
|
|
|
code = code:gsub("^sprite%[_aci%]", "_spr")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-11 21:23:42 +00:00
|
|
|
return code, ismethod, lit_ok_func_or_table
|
2013-01-24 20:03:10 +00:00
|
|
|
end
|
2013-01-24 20:03:06 +00:00
|
|
|
|
2013-01-24 20:03:10 +00:00
|
|
|
function lookup.array_expr(writep, structname, index, membertab)
|
|
|
|
if (conl.StructAccessCode[structname] == nil) then
|
2013-02-18 16:07:48 +00:00
|
|
|
-- Try a gamearray
|
2013-02-24 16:05:22 +00:00
|
|
|
local ganame = g_gamearray[structname] and lookup.gamearray(structname)
|
|
|
|
if (ganame == nil) then
|
2013-02-18 16:07:48 +00:00
|
|
|
if (structname=="actorvar") then
|
|
|
|
-- actorvar[] inline array expr
|
|
|
|
-- XXX: kind of CODEDUP with GetOrSetPerxvarCmd() factory
|
|
|
|
local gv = g_gamevar[structname]
|
|
|
|
if (gv and bit.band(gv.flags, GVFLAG.PERX_MASK)~=GVFLAG.PERACTOR) then
|
2013-03-17 18:11:47 +00:00
|
|
|
errprintf("gamevar `%s' is not per-actor", structname, "actor")
|
2013-02-18 16:07:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if (membertab == nil) then
|
|
|
|
errprintf("actorvar[] requires a pseudo member (gamevar) name")
|
|
|
|
return "_INVALIDAV"
|
|
|
|
end
|
|
|
|
|
|
|
|
if (#membertab > 1) then
|
|
|
|
errprintf("actorvar[] cannot be used with a second parameter")
|
|
|
|
return "_INVALIDAV"
|
|
|
|
end
|
|
|
|
|
2014-02-08 14:37:47 +00:00
|
|
|
if (gv) then
|
|
|
|
gv.used = bit.bor(gv.used, writep and 2 or 1)
|
|
|
|
end
|
|
|
|
|
2013-02-18 16:07:48 +00:00
|
|
|
assert(#membertab == 1)
|
|
|
|
return lookup.gamevar(membertab[1], index, writep)
|
|
|
|
end
|
|
|
|
|
|
|
|
errprintf("symbol `%s' is neither a struct nor a gamearray", structname)
|
|
|
|
return "_INVALIDAR"
|
|
|
|
end
|
|
|
|
|
|
|
|
if (membertab ~= nil) then
|
|
|
|
errprintf("gamearrays cannot be indexed with member names")
|
|
|
|
return "_INVALIDAR"
|
|
|
|
end
|
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
assert(type(ganame)=="string")
|
|
|
|
return format("%s[%s]", ganame, index)
|
2013-01-24 20:03:10 +00:00
|
|
|
end
|
|
|
|
|
2013-02-01 13:04:52 +00:00
|
|
|
local membercode, ismethod = StructAccess(structname, writep, index, membertab)
|
|
|
|
-- Written METHOD_MEMBER syntax not supported as "qwe:method(asd) = val"
|
|
|
|
-- isn't valid Lua syntax.
|
|
|
|
assert(not (writep and ismethod))
|
|
|
|
return membercode
|
2013-01-24 20:03:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local Access =
|
|
|
|
{
|
|
|
|
sector = function(...) return StructAccess("sector", ...) end,
|
|
|
|
wall = function(...) return StructAccess("wall", ...) end,
|
|
|
|
xsprite = function(...) return StructAccess("sprite", ...) end,
|
|
|
|
player = function(...) return StructAccess("player", ...) end,
|
2013-02-03 12:48:06 +00:00
|
|
|
|
|
|
|
tspr = function(...) return StructAccess("tspr", ...) end,
|
2013-02-07 21:01:03 +00:00
|
|
|
projectile = function(...) return StructAccess("projectile", ...) end,
|
2013-02-07 21:01:18 +00:00
|
|
|
thisprojectile = function(...) return StructAccess("thisprojectile", ...) end,
|
2013-02-10 16:24:20 +00:00
|
|
|
userdef = function(...) return StructAccess("userdef", ...) end,
|
2013-02-10 16:24:44 +00:00
|
|
|
input = function(...) return StructAccess("input", ...) end,
|
2013-01-24 20:03:06 +00:00
|
|
|
}
|
|
|
|
|
2013-02-10 16:24:20 +00:00
|
|
|
local function GetStructCmd(accessfunc, pattern)
|
2013-06-07 10:18:12 +00:00
|
|
|
return (pattern or patt.cmdgetstruct) /
|
2013-02-10 16:23:59 +00:00
|
|
|
function(idx, memb, var)
|
2013-01-24 20:03:06 +00:00
|
|
|
return format("%s=%s", var, accessfunc(false, idx, memb))
|
2013-02-10 16:23:59 +00:00
|
|
|
end
|
2013-01-24 20:03:06 +00:00
|
|
|
end
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-10 16:24:20 +00:00
|
|
|
local function SetStructCmd(accessfunc, pattern)
|
2013-02-10 16:23:59 +00:00
|
|
|
local function capfunc(idx, memb, var)
|
2013-12-11 21:23:42 +00:00
|
|
|
-- litok: function or table
|
|
|
|
local membercode, ismethod, litok = accessfunc(true, idx, memb)
|
|
|
|
|
|
|
|
-- Light static checking for literal values being OK for member
|
|
|
|
-- assignment. LITERAL_CHECKING.
|
|
|
|
if (type(var)=="number" and litok) then
|
|
|
|
if (type(litok)=="table" and not (var>=litok[1] and var<=litok[2]) or
|
|
|
|
type(litok)=="function" and not litok(var)) then
|
|
|
|
local member = memb[1]:lower()
|
|
|
|
warnprintf("setting member '.%s' to %d will fail at game time",
|
|
|
|
member, var)
|
|
|
|
end
|
2013-03-29 15:59:23 +00:00
|
|
|
end
|
2013-12-11 21:23:42 +00:00
|
|
|
|
2013-02-01 13:04:52 +00:00
|
|
|
if (ismethod) then
|
|
|
|
-- METHOD_MEMBER syntax
|
|
|
|
|
|
|
|
-- BE EXTRA CAREFUL! We must be sure that percent characters have
|
|
|
|
-- not been smuggled into the member code string via variable names
|
|
|
|
-- etc.
|
|
|
|
local _, numpercents = membercode:gsub("%%", "", 2)
|
|
|
|
assert(numpercents==1)
|
|
|
|
|
|
|
|
return format(membercode, var)
|
|
|
|
else
|
|
|
|
return format("%s=%s", membercode, var)
|
|
|
|
end
|
2013-01-26 17:08:02 +00:00
|
|
|
end
|
2013-02-10 16:23:59 +00:00
|
|
|
|
2013-06-07 10:18:12 +00:00
|
|
|
return (pattern or patt.cmdsetstruct) / capfunc
|
2013-02-10 16:23:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- <Setp>: whether the perxvar is set
|
|
|
|
local function GetOrSetPerxvarCmd(Setp, Actorp)
|
|
|
|
local EXPECTED_PERX_BIT = Actorp and GVFLAG.PERACTOR or GVFLAG.PERPLAYER
|
2013-06-07 10:18:12 +00:00
|
|
|
local pattern = (Setp and patt.cmdsetperxvar or patt.cmdgetperxvar)
|
2013-02-10 16:23:59 +00:00
|
|
|
|
|
|
|
local function capfunc(idx, perxvarname, var)
|
|
|
|
local gv = g_gamevar[perxvarname]
|
|
|
|
if (gv and bit.band(gv.flags, GVFLAG.PERX_MASK)~=EXPECTED_PERX_BIT) then
|
2013-03-17 18:11:47 +00:00
|
|
|
-- [gs]set*var for wrong gamevar type. See if it's a getactorvar,
|
2013-06-28 14:07:41 +00:00
|
|
|
-- in which case we may only warn and access that instead. Note
|
|
|
|
-- that accesses of player gamevars with actor indices are usually
|
|
|
|
-- meaningless.
|
2013-03-17 18:11:47 +00:00
|
|
|
local warnp = not Setp and Actorp and not g_warn["error-bad-getactorvar"]
|
|
|
|
local xprintf = warnp and warnprintf or errprintf
|
|
|
|
|
|
|
|
xprintf("gamevar `%s' is not per-%s", perxvarname, Actorp and "actor" or "player")
|
2014-01-24 21:39:04 +00:00
|
|
|
|
|
|
|
if (warnp and bit.band(gv.flags, GVFLAG.PERX_MASK)==GVFLAG.PERPLAYER
|
|
|
|
and g_cgopt["bad-getactorvar-use-pli"]) then
|
|
|
|
-- For getactorvar[] accesses to per-player gamevars, if
|
|
|
|
-- -fbad-getactorvar-use-pli is provided, use current player
|
|
|
|
-- index, for compatibility with CON.
|
|
|
|
idx = "_pli"
|
|
|
|
end
|
2013-02-10 16:23:59 +00:00
|
|
|
end
|
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
if (not Actorp) then
|
|
|
|
-- THISACTOR -> player index for {g,s}etplayervar
|
|
|
|
idx = thisactor_to_pli(idx)
|
|
|
|
end
|
|
|
|
|
2014-02-08 14:37:47 +00:00
|
|
|
if (gv) then
|
|
|
|
gv.used = bit.bor(gv.used, Setp and 2 or 1)
|
|
|
|
end
|
|
|
|
|
2013-02-10 16:23:59 +00:00
|
|
|
if (Setp) then
|
|
|
|
return format("%s=%s", lookup.gamevar(perxvarname, idx, true), var)
|
|
|
|
else
|
|
|
|
return format("%s=%s", var, lookup.gamevar(perxvarname, idx, false))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return pattern / capfunc
|
2013-01-26 17:08:02 +00:00
|
|
|
end
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-18 16:07:59 +00:00
|
|
|
local function n_s_fmt(n)
|
|
|
|
return string.rep("%s,", n-1).."%s"
|
|
|
|
end
|
|
|
|
|
2013-01-24 20:03:02 +00:00
|
|
|
-- Various inner command handling functions / string capture strings.
|
2013-01-13 16:40:26 +00:00
|
|
|
local handle =
|
|
|
|
{
|
2013-01-24 20:03:02 +00:00
|
|
|
NYI = function()
|
|
|
|
errprintf("command `%s' not yet implemented", g_lastkw)
|
2013-02-25 15:31:09 +00:00
|
|
|
return ""
|
2013-01-24 20:03:02 +00:00
|
|
|
end,
|
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
dynNYI = function()
|
2013-06-13 17:11:07 +00:00
|
|
|
return format([[print(%q..":%d: `%s' not yet implemented")]],
|
2013-02-24 16:05:22 +00:00
|
|
|
g_filename, getlinecol(g_lastkwpos), g_lastkw)
|
|
|
|
end,
|
|
|
|
|
2013-01-24 20:03:02 +00:00
|
|
|
addlog = function()
|
2013-06-13 17:11:07 +00:00
|
|
|
return format("print(%q..':%d: addlog')", g_filename, getlinecol(g_lastkwpos))
|
2013-01-24 20:03:02 +00:00
|
|
|
end,
|
|
|
|
|
|
|
|
addlogvar = function(val)
|
2013-06-13 17:11:07 +00:00
|
|
|
return format("printf(%q..':%d: addlogvar %%s', %s)", g_filename, getlinecol(g_lastkwpos), val)
|
2013-01-24 20:03:02 +00:00
|
|
|
end,
|
|
|
|
|
|
|
|
debug = function(val)
|
2013-06-13 17:11:07 +00:00
|
|
|
return format("print(%q..':%d: debug %d')", g_filename, getlinecol(g_lastkwpos), val)
|
2013-01-24 20:03:02 +00:00
|
|
|
end,
|
|
|
|
|
2013-02-25 15:31:13 +00:00
|
|
|
getzrange = function(...)
|
|
|
|
local v = {...}
|
|
|
|
assert(#v == 10) -- 4R 4W 2R
|
|
|
|
return format("%s,%s,%s,%s=_con._getzrange(%s,%s,%s,%s,%s,%s)",
|
|
|
|
v[5], v[6], v[7], v[8], -- outargs
|
|
|
|
v[1], v[2], v[3], v[4], v[9], v[10]) -- inargs
|
|
|
|
end,
|
|
|
|
|
2013-02-16 18:53:24 +00:00
|
|
|
hitscan = function(...)
|
|
|
|
local v = {...}
|
|
|
|
assert(#v == 14) -- 7R 6W 1R
|
|
|
|
local vals = {
|
|
|
|
v[8], v[9], v[10], v[11], v[12], v[13], -- outargs
|
|
|
|
v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[14] -- inargs
|
|
|
|
}
|
|
|
|
return format("%s,%s,%s,%s,%s,%s=_con._hitscan(%s,%s,%s,%s,%s,%s,%s,%s)",
|
|
|
|
unpack(vals))
|
|
|
|
end,
|
|
|
|
|
|
|
|
neartag = function(...)
|
|
|
|
local v = {...}
|
|
|
|
assert(#v == 11) -- 5R 4W 2R
|
|
|
|
local vals = {
|
|
|
|
v[6], v[7], v[8], v[9], -- outargs
|
|
|
|
v[1], v[2], v[3], v[4], v[5], v[10], v[11] -- inargs
|
|
|
|
}
|
|
|
|
return format("%s,%s,%s,%s=_con._neartag(%s,%s,%s,%s,%s,%s,%s)",
|
|
|
|
unpack(vals))
|
|
|
|
end,
|
|
|
|
|
2013-05-24 13:54:37 +00:00
|
|
|
clipmove = function(noslidep, ...)
|
|
|
|
local v = {...}
|
|
|
|
assert(#v == 11) -- 3W 1R 1W 6R
|
|
|
|
local vals = {
|
|
|
|
v[1], v[2], v[3], v[5], -- outargs
|
|
|
|
v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], -- inargs
|
|
|
|
noslidep
|
|
|
|
}
|
|
|
|
return format("%s,%s,%s,%s=_con._clipmovex("..n_s_fmt(11)..")",
|
|
|
|
unpack(vals))
|
|
|
|
end,
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
palfrom = function(...)
|
|
|
|
local v = {...}
|
|
|
|
return format(PLS":_palfrom(%d,%d,%d,%d)",
|
|
|
|
v[1] or 0, v[2] or 0, v[3] or 0, v[4] or 0)
|
|
|
|
end,
|
|
|
|
|
2013-02-18 16:07:59 +00:00
|
|
|
qsprintf = function(qdst, qsrc, ...)
|
|
|
|
local codes = {...}
|
2013-05-24 13:54:27 +00:00
|
|
|
return format("_con._qsprintf(%s,%s%s%s)", qdst, qsrc,
|
2013-02-25 15:31:09 +00:00
|
|
|
#codes>0 and "," or "", table.concat(codes, ','))
|
2013-02-18 16:07:59 +00:00
|
|
|
end,
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
move = function(mv, ...)
|
|
|
|
local flags = {...}
|
|
|
|
return format(ACS":set_move(%s,%d)", mv, (flags[1] and bit.bor(...)) or 0)
|
|
|
|
end,
|
|
|
|
|
2013-02-11 17:16:58 +00:00
|
|
|
rotatesprite = function(...)
|
2013-05-15 18:32:50 +00:00
|
|
|
return format("_con._rotspr(%s,%s,%s,%s,%s,%s,%s,%s,0,%s,%s,%s,%s)", ...)
|
2013-02-11 17:16:58 +00:00
|
|
|
end,
|
|
|
|
|
2013-03-25 19:19:05 +00:00
|
|
|
rotatesprite16 = function(...) -- (orientation|ROTATESPRITE_FULL16)
|
2013-05-15 18:32:50 +00:00
|
|
|
return format("_con._rotspr(%s,%s,%s,%s,%s,%s,%s,_bor(%s,2048),0,%s,%s,%s,%s)", ...)
|
2013-03-25 04:33:03 +00:00
|
|
|
end,
|
|
|
|
|
|
|
|
rotatespritea = function(...)
|
2013-05-15 18:32:50 +00:00
|
|
|
return format("_con._rotspr(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", ...)
|
2013-02-28 17:30:15 +00:00
|
|
|
end,
|
|
|
|
|
2013-07-09 18:23:43 +00:00
|
|
|
-- <fmt>: format string, number of %s's must match number of varargs
|
|
|
|
arraycmd = function(fmt, dstargi, ...)
|
|
|
|
local args = {...}
|
|
|
|
if (issysgar(args[dstargi])) then
|
|
|
|
errprintf("%s: system gamearray not supported", g_lastkw)
|
|
|
|
end
|
|
|
|
return format(fmt, ...)
|
|
|
|
end,
|
|
|
|
|
2013-02-28 17:30:15 +00:00
|
|
|
-- readgamevar or savegamevar
|
|
|
|
RSgamevar = function(identifier, dosave)
|
|
|
|
-- check identifier for sanity
|
2013-03-03 16:06:12 +00:00
|
|
|
if (not identifier:match("^[A-Za-z][A-Za-z0-9_%-]*$")) then
|
|
|
|
errprintf("%s: bad identifier `%s' for config file persistence",
|
|
|
|
g_lastkw, identifier)
|
2013-02-28 17:30:15 +00:00
|
|
|
return "_BADRSGV()"
|
|
|
|
end
|
|
|
|
|
|
|
|
local gv = g_gamevar[identifier]
|
2013-10-20 12:35:03 +00:00
|
|
|
if (gv == nil) then
|
|
|
|
return lookup.error_not_gamevar(identifier)
|
|
|
|
end
|
2013-03-17 18:11:47 +00:00
|
|
|
|
|
|
|
-- For per-actor or per-player gamevars, the value at the current actor or
|
|
|
|
-- player index gets saved / loaded.
|
|
|
|
local gvkind = bit.band(gv.flags, GVFLAG.PERX_MASK)
|
|
|
|
local index = (gvkind==GVFLAG.PERACTOR) and "_aci" or
|
|
|
|
(gvkind==GVFLAG.PERPLAYER) and "_pli" or nil
|
2013-02-28 17:30:15 +00:00
|
|
|
|
|
|
|
-- NOTE: more strict than C-CON: we require the gamevar being writable
|
|
|
|
-- even if we're saving it.
|
2013-03-17 18:11:47 +00:00
|
|
|
local code = lookup.gamevar(identifier, index, true)
|
2013-02-28 17:30:15 +00:00
|
|
|
|
2014-02-08 14:37:47 +00:00
|
|
|
gv.used = bit.bor(gv.used, not dosave and 2 or 1)
|
|
|
|
|
2013-02-28 17:30:15 +00:00
|
|
|
if (dosave) then
|
|
|
|
return format("_con._savegamevar(%q,%s)", identifier, code)
|
|
|
|
else
|
2014-01-12 14:54:34 +00:00
|
|
|
return format("%s=_con._readgamevar(%q,%s)", code, identifier, code)
|
2013-02-28 17:30:15 +00:00
|
|
|
end
|
2013-02-11 17:16:58 +00:00
|
|
|
end,
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
state = function(statename)
|
|
|
|
if (g_funcname[statename]==nil) then
|
2013-04-09 17:34:53 +00:00
|
|
|
local warn = not g_cgopt["error-nostate"]
|
2013-03-31 18:58:04 +00:00
|
|
|
local xprintf = warn and warnprintf or errprintf
|
|
|
|
|
|
|
|
xprintf("state `%s' not found.", statename)
|
|
|
|
return warn and "" or "_NULLSTATE()"
|
2013-01-13 16:40:26 +00:00
|
|
|
end
|
|
|
|
return format("%s(_aci,_pli,_dist)", g_funcname[statename])
|
|
|
|
end,
|
2013-01-24 20:02:57 +00:00
|
|
|
|
|
|
|
addweapon = format("if (%s) then _con.longjmp() end", PLS":addweapon(%1,%2)"),
|
2013-01-24 20:03:02 +00:00
|
|
|
|
|
|
|
-- Sound commands
|
|
|
|
sound = "_con._sound(_aci,%1)",
|
|
|
|
globalsound = "_con._globalsound(_pli,%1)",
|
|
|
|
stopsound = "_con._stopsound(_aci,%1)",
|
|
|
|
soundonce = "_con._soundonce(_aci,%1)",
|
2013-01-13 16:40:26 +00:00
|
|
|
}
|
2013-01-05 13:09:31 +00:00
|
|
|
|
2014-02-01 16:19:55 +00:00
|
|
|
local userdef_common_pat = (arraypat_maybe_empty + sp1)/{}
|
|
|
|
* lpeg.Cc(0) * lpeg.Ct(patt.singlemember) * sp1
|
2013-02-10 16:24:20 +00:00
|
|
|
|
2012-06-17 19:45:37 +00:00
|
|
|
-- NOTE about prefixes: most is handled by all_alt_pattern(), however commands
|
|
|
|
-- that have no arguments and that are prefixes of other commands MUST be
|
|
|
|
-- suffixed with a "* #sp1" pattern.
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
local Cinner = {
|
2012-04-07 20:10:03 +00:00
|
|
|
-- these can appear anywhere in the script
|
2012-11-30 18:57:40 +00:00
|
|
|
["break"] = cmd()
|
2013-02-28 17:29:58 +00:00
|
|
|
/ function()
|
|
|
|
return g_isWhile[#g_isWhile]
|
2013-02-28 17:30:15 +00:00
|
|
|
and format("goto l%d", #g_isWhile)
|
2013-02-28 17:29:58 +00:00
|
|
|
or "do return end"
|
|
|
|
end,
|
2012-12-03 18:24:25 +00:00
|
|
|
["return"] = cmd() -- NLCF
|
2013-01-05 13:09:31 +00:00
|
|
|
/ "_con.longjmp()",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-11-30 18:57:40 +00:00
|
|
|
state = cmd(I)
|
2013-01-13 16:40:26 +00:00
|
|
|
/ handle.state,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
--- 1. get*, set*
|
2013-01-26 17:08:02 +00:00
|
|
|
getsector = GetStructCmd(Access.sector),
|
|
|
|
getwall = GetStructCmd(Access.wall),
|
2013-01-24 20:03:10 +00:00
|
|
|
getactor = GetStructCmd(Access.xsprite),
|
|
|
|
getplayer = GetStructCmd(Access.player),
|
2013-01-26 17:08:02 +00:00
|
|
|
|
2013-02-10 16:24:44 +00:00
|
|
|
getinput = GetStructCmd(Access.input),
|
2013-02-07 21:01:03 +00:00
|
|
|
getprojectile = GetStructCmd(Access.projectile),
|
2013-02-07 21:01:18 +00:00
|
|
|
getthisprojectile = GetStructCmd(Access.thisprojectile),
|
2013-02-03 12:48:06 +00:00
|
|
|
gettspr = GetStructCmd(Access.tspr),
|
2012-04-29 20:54:06 +00:00
|
|
|
-- NOTE: {get,set}userdef is the only struct that can be accessed without
|
2012-06-03 16:11:22 +00:00
|
|
|
-- an "array part", e.g. H266MOD has "setuserdef .weaponswitch 0" (space
|
2013-01-24 20:03:06 +00:00
|
|
|
-- between keyword and "." is mandatory).
|
|
|
|
-- NOTE2: userdef has at least three members with a second parameter:
|
|
|
|
-- user_name, ridecule, savegame. Then there's wchoice. Given that they're
|
|
|
|
-- arrays, I highly doubt that they worked (much less were safe) in CON.
|
2013-02-16 18:53:04 +00:00
|
|
|
-- We disallow them, recent EDuke32 versions didn't expose them either.
|
2013-02-10 16:24:20 +00:00
|
|
|
getuserdef = GetStructCmd(Access.userdef, userdef_common_pat * tok.wvar),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
getplayervar = GetOrSetPerxvarCmd(false, false), -- THISACTOR
|
2013-02-10 16:23:59 +00:00
|
|
|
getactorvar = GetOrSetPerxvarCmd(false, true),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-26 17:08:02 +00:00
|
|
|
setsector = SetStructCmd(Access.sector),
|
|
|
|
setwall = SetStructCmd(Access.wall),
|
|
|
|
setactor = SetStructCmd(Access.xsprite),
|
|
|
|
setplayer = SetStructCmd(Access.player),
|
|
|
|
|
2013-02-10 16:24:44 +00:00
|
|
|
setinput = SetStructCmd(Access.input),
|
2013-02-07 21:01:03 +00:00
|
|
|
setprojectile = SetStructCmd(Access.projectile),
|
2013-02-07 21:01:18 +00:00
|
|
|
setthisprojectile = SetStructCmd(Access.thisprojectile),
|
2013-02-03 12:48:06 +00:00
|
|
|
settspr = SetStructCmd(Access.tspr),
|
2013-02-10 16:24:20 +00:00
|
|
|
setuserdef = SetStructCmd(Access.userdef, userdef_common_pat * tok.rvar),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-24 16:05:22 +00:00
|
|
|
setplayervar = GetOrSetPerxvarCmd(true, false), -- THISACTOR
|
2013-02-10 16:23:59 +00:00
|
|
|
setactorvar = GetOrSetPerxvarCmd(true, true),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-06-07 10:18:12 +00:00
|
|
|
setvarvar = Op.varvar / "%1=%2",
|
|
|
|
addvarvar = Op.varvarf "+",
|
2013-02-25 15:31:09 +00:00
|
|
|
-- NOTE the space after the minus sign so that e.g. "subvar x -1" won't get
|
|
|
|
-- translated to "x=x--1" (-- being the Lua line comment start).
|
2013-06-07 10:18:12 +00:00
|
|
|
subvarvar = Op.varvarf "- ",
|
2013-07-13 21:04:50 +00:00
|
|
|
mulvarvar = Op.varvarf("*", "_mulTR", "_mulWR"),
|
|
|
|
divvarvar = Op.varvarf "_div",
|
|
|
|
modvarvar = Op.varvarf "_mod",
|
2013-06-07 10:18:12 +00:00
|
|
|
andvarvar = Op.varvarf "_band",
|
|
|
|
orvarvar = Op.varvarf "_bor",
|
|
|
|
xorvarvar = Op.varvarf "_bxor",
|
|
|
|
randvarvar = Op.varvar / "%1=_con._rand(%2)",
|
|
|
|
|
|
|
|
setvar = Op.var / "%1=%2",
|
|
|
|
addvar = Op.varf "+",
|
|
|
|
subvar = Op.varf "- ",
|
2013-07-13 21:04:50 +00:00
|
|
|
mulvar = Op.varf("*", "_mulTR", "_mulWR"),
|
|
|
|
divvar = Op.varf "_div",
|
|
|
|
modvar = Op.varf "_mod",
|
2013-06-07 10:18:12 +00:00
|
|
|
andvar = Op.varf "_band",
|
|
|
|
orvar = Op.varf "_bor",
|
|
|
|
xorvar = Op.varf "_bxor",
|
|
|
|
randvar = Op.var / "%1=_con._rand(%2)",
|
|
|
|
shiftvarl = Op.varf "_lsh",
|
|
|
|
shiftvarr = Op.varf "_arsh",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
--- 2. Math operations
|
2013-02-11 17:16:58 +00:00
|
|
|
sqrt = cmd(R,W)
|
2013-02-16 18:53:15 +00:00
|
|
|
/ "%2=_gv.ksqrt(%1)",
|
2013-02-11 17:16:58 +00:00
|
|
|
calchypotenuse = cmd(W,R,R)
|
|
|
|
/ "%1=_con._hypot(%2,%3)",
|
2013-02-16 18:53:15 +00:00
|
|
|
sin = cmd(W,R)
|
|
|
|
/ "%1=_xmath.ksin(%2)",
|
|
|
|
cos = cmd(W,R)
|
|
|
|
/ "%1=_xmath.kcos(%2)",
|
|
|
|
mulscale = cmd(W,R,R,R)
|
2013-03-24 18:52:41 +00:00
|
|
|
/ "%1=_gv.Mulscale(%2,%3,%4)",
|
2013-02-11 17:16:58 +00:00
|
|
|
getangle = cmd(W,R,R)
|
2013-02-16 18:53:15 +00:00
|
|
|
/ "%1=_gv.getangle(%2,%3)",
|
2013-02-11 17:16:58 +00:00
|
|
|
getincangle = cmd(W,R,R)
|
|
|
|
/ "%1=_con._angdiff(%2,%3)",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
--- 3. Actors
|
2012-11-30 18:57:46 +00:00
|
|
|
action = cmd(AC)
|
|
|
|
/ ACS":set_action(%1)",
|
|
|
|
ai = cmd(AI)
|
|
|
|
/ ACS":set_ai(%1)",
|
2013-01-13 16:40:26 +00:00
|
|
|
move = sp1 * tok.move * (sp1 * tok.define)^0
|
|
|
|
/ handle.move,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-11-30 18:57:46 +00:00
|
|
|
cactor = cmd(D)
|
2012-11-30 18:57:50 +00:00
|
|
|
/ SPS":set_picnum(%1)",
|
2012-11-30 18:57:46 +00:00
|
|
|
count = cmd(D)
|
|
|
|
/ ACS":set_count(%1)",
|
2012-12-03 18:24:25 +00:00
|
|
|
cstator = cmd(D)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ (SPS".cstat=_bor(%1,"..SPS".cstat)"),
|
2012-12-03 18:24:25 +00:00
|
|
|
cstat = cmd(D)
|
|
|
|
/ SPS".cstat=%1",
|
2012-12-03 18:24:30 +00:00
|
|
|
clipdist = cmd(D)
|
|
|
|
/ SPS".clipdist=%1",
|
2013-05-24 13:54:29 +00:00
|
|
|
shadeto = cmd(D) / -- PRE13
|
|
|
|
"",
|
2012-12-03 18:24:25 +00:00
|
|
|
sizeto = cmd(D,D)
|
2012-12-29 15:21:32 +00:00
|
|
|
/ "_con._sizeto(_aci,%1,%2)", -- TODO: see control.lua:_sizeto
|
2012-11-30 18:57:46 +00:00
|
|
|
sizeat = cmd(D,D)
|
|
|
|
/ (SPS".xrepeat,"..SPS".yrepeat=%1,%2"),
|
|
|
|
strength = cmd(D)
|
|
|
|
/ SPS".extra=%1",
|
|
|
|
addstrength = cmd(D)
|
|
|
|
/ (SPS".extra="..SPS".extra+%1"),
|
2013-01-05 13:09:31 +00:00
|
|
|
spritepal = cmd(D)
|
|
|
|
/ SPS".pal=%1",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-12-03 18:24:30 +00:00
|
|
|
hitradius = cmd(D,D,D,D,D)
|
2013-01-01 15:24:22 +00:00
|
|
|
/ "_con._A_RadiusDamage(_aci,%1,%2,%3,%4,%5)",
|
2013-01-24 20:02:57 +00:00
|
|
|
hitradiusvar = cmd(R,R,R,R,R)
|
|
|
|
/ "_con._A_RadiusDamage(_aci,%1,%2,%3,%4,%5)",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
-- some commands taking read vars
|
2013-02-16 18:53:04 +00:00
|
|
|
operaterespawns = cmd(R)
|
|
|
|
/ "_con._G_OperateRespawns(%1)",
|
|
|
|
operatemasterswitches = cmd(R)
|
|
|
|
/ "_con._G_OperateMasterSwitches(%1)",
|
|
|
|
checkactivatormotion = cmd(R)
|
2013-08-23 17:01:10 +00:00
|
|
|
/ "_gv.RETURN=_con._checkactivatormotion(%1)",
|
2013-01-24 20:03:02 +00:00
|
|
|
time = cmd(R) -- no-op
|
|
|
|
/ "",
|
2013-02-16 18:53:04 +00:00
|
|
|
inittimer = cmd(R)
|
|
|
|
/ "_con._inittimer(%1)",
|
|
|
|
lockplayer = cmd(R)
|
|
|
|
/ PLS".transporter_hold=%1",
|
2013-02-11 17:16:58 +00:00
|
|
|
quake = cmd(R)
|
2013-06-22 11:31:09 +00:00
|
|
|
/ "_gv.doQuake(%1,81)", -- TODO: dynsound (EARTHQUAKE)
|
2013-02-11 17:16:58 +00:00
|
|
|
jump = cmd(R)
|
|
|
|
/ handle.NYI, -- will never be
|
|
|
|
cmenu = cmd(R)
|
2013-04-09 17:34:53 +00:00
|
|
|
/ "_gv._changeMenu(%1)",
|
2013-02-18 16:07:32 +00:00
|
|
|
checkavailweapon = cmd(R) -- THISACTOR
|
2013-02-24 16:05:22 +00:00
|
|
|
/ function(pli)
|
|
|
|
return format("_con._checkavailweapon(%s)", thisactor_to_pli(pli))
|
|
|
|
end,
|
2013-02-18 16:07:32 +00:00
|
|
|
checkavailinven = cmd(R) -- THISACTOR
|
2013-02-24 16:05:22 +00:00
|
|
|
/ function(pli)
|
|
|
|
return format("_con._selectnextinv(player[%s])", thisactor_to_pli(pli))
|
|
|
|
end,
|
2013-02-18 16:07:32 +00:00
|
|
|
guniqhudid = cmd(R)
|
|
|
|
/ "_gv._set_guniqhudid(%1)",
|
2013-01-24 20:03:02 +00:00
|
|
|
echo = cmd(R)
|
|
|
|
/ "_con._echo(%1)",
|
2013-02-16 18:53:04 +00:00
|
|
|
activatecheat = cmd(R)
|
|
|
|
/ handle.NYI,
|
2013-02-25 15:31:09 +00:00
|
|
|
setgamepalette = cmd(R)
|
|
|
|
/ "_con._setgamepalette(_pli,%1)",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-24 20:03:02 +00:00
|
|
|
-- Sound commands
|
|
|
|
sound = cmd(D)
|
|
|
|
/ handle.sound,
|
|
|
|
soundvar = cmd(R)
|
|
|
|
/ handle.sound,
|
|
|
|
globalsound = cmd(D)
|
|
|
|
/ handle.globalsound,
|
|
|
|
globalsoundvar = cmd(R)
|
|
|
|
/ handle.globalsound,
|
|
|
|
stopsound = cmd(D)
|
|
|
|
/ handle.stopsound,
|
|
|
|
stopsoundvar = cmd(R)
|
|
|
|
/ handle.stopsound,
|
|
|
|
soundonce = cmd(D)
|
|
|
|
/ handle.soundonce,
|
|
|
|
soundoncevar = cmd(R)
|
|
|
|
/ handle.soundonce,
|
|
|
|
stopactorsound = cmd(R,R)
|
2013-02-25 15:31:19 +00:00
|
|
|
/ "_con._stopactorsound(%1,%2)",
|
2013-01-24 20:03:02 +00:00
|
|
|
stopallsounds = cmd()
|
2013-02-25 15:31:19 +00:00
|
|
|
/ "_con._stopallsounds()",
|
2013-06-28 14:07:46 +00:00
|
|
|
screensound = cmd(R)
|
|
|
|
/ "_con._screensound(%1)",
|
2013-01-24 20:03:02 +00:00
|
|
|
mikesnd = cmd()
|
|
|
|
/ format("_con._soundonce(_aci,%s)", SPS".yvel"),
|
|
|
|
setactorsoundpitch = cmd(R,R,R)
|
|
|
|
/ "_con._setactorsoundpitch(%1,%2,%3)",
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
-- some commands taking defines
|
2012-12-03 18:24:25 +00:00
|
|
|
addammo = cmd(D,D) -- NLCF
|
|
|
|
/ format("if (%s) then _con.longjmp() end", PLS":addammo(%1,%2)"),
|
|
|
|
addweapon = cmd(D,D) -- NLCF
|
2013-01-24 20:02:57 +00:00
|
|
|
/ handle.addweapon,
|
2012-12-03 18:24:25 +00:00
|
|
|
debris = cmd(D,D)
|
2012-12-28 17:18:02 +00:00
|
|
|
/ "_con._debris(_aci, %1, %2)",
|
2012-12-03 18:24:25 +00:00
|
|
|
addinventory = cmd(D,D)
|
2013-01-24 20:02:57 +00:00
|
|
|
/ format("_con._addinventory(%s,%%1,%%2,_aci)", PLS""),
|
2012-12-03 18:24:30 +00:00
|
|
|
guts = cmd(D,D)
|
2012-12-28 17:18:02 +00:00
|
|
|
/ "_con._A_DoGuts(_aci,%1,%2)",
|
2013-02-11 17:16:58 +00:00
|
|
|
|
2013-01-24 20:03:02 +00:00
|
|
|
spawn = cmd(D)
|
2013-07-09 18:23:41 +00:00
|
|
|
/ "_con.spawn(%1,_aci)",
|
2013-02-11 17:16:58 +00:00
|
|
|
espawn = cmd(D)
|
2013-08-23 17:01:10 +00:00
|
|
|
/ "_gv.RETURN=_con.spawn(%1,_aci)",
|
2013-02-11 17:16:58 +00:00
|
|
|
espawnvar = cmd(R)
|
2013-08-23 17:01:10 +00:00
|
|
|
/ "_gv.RETURN=_con.spawn(%1,_aci)",
|
2013-02-11 17:16:58 +00:00
|
|
|
qspawn = cmd(D)
|
2013-07-09 18:23:41 +00:00
|
|
|
/ "_con.spawn(%1,_aci,true)",
|
2013-02-11 17:16:58 +00:00
|
|
|
qspawnvar = cmd(R)
|
2013-07-09 18:23:41 +00:00
|
|
|
/ "_con.spawn(%1,_aci,true)",
|
2013-02-11 17:16:58 +00:00
|
|
|
eqspawn = cmd(D)
|
2013-08-23 17:01:10 +00:00
|
|
|
/ "_gv.RETURN=_con.spawn(%1,_aci,true)",
|
2013-02-11 17:16:58 +00:00
|
|
|
eqspawnvar = cmd(R)
|
2013-08-23 17:01:10 +00:00
|
|
|
/ "_gv.RETURN=_con.spawn(%1,_aci,true)",
|
2013-02-11 17:16:58 +00:00
|
|
|
|
|
|
|
angoff = cmd(D)
|
|
|
|
/ "spriteext[_aci].angoff=%1",
|
|
|
|
angoffvar = cmd(R)
|
|
|
|
/ "spriteext[_aci].angoff=%1",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
-- cont'd
|
2012-11-30 18:57:46 +00:00
|
|
|
addkills = cmd(D)
|
2013-06-12 17:49:55 +00:00
|
|
|
/ (PLS".actors_killed="..PLS".actors_killed+%1;"..ACS".stayputsect=-1"),
|
2012-12-03 18:24:25 +00:00
|
|
|
addphealth = cmd(D)
|
2013-01-06 18:56:45 +00:00
|
|
|
/ format("_con._addphealth(%s,_aci,%%1)", PLS""),
|
2012-11-30 18:57:46 +00:00
|
|
|
debug = cmd(D)
|
2013-01-13 16:40:26 +00:00
|
|
|
/ handle.debug,
|
2012-12-03 18:24:30 +00:00
|
|
|
endofgame = cmd(D)
|
|
|
|
/ "_con._endofgame(_pli,%1)",
|
2013-05-24 13:54:29 +00:00
|
|
|
endoflevel = cmd(D) -- PRE13
|
|
|
|
/ "_con._endofgame(_pli,%1)",
|
2012-12-28 17:18:02 +00:00
|
|
|
lotsofglass = cmd(D)
|
|
|
|
/ "_con._A_SpawnGlass(_aci,%1)",
|
2012-12-03 18:24:30 +00:00
|
|
|
mail = cmd(D)
|
2013-06-13 17:11:06 +00:00
|
|
|
/ "_con._spawnmany(_aci,'MAIL',%1)",
|
2012-12-03 18:24:30 +00:00
|
|
|
money = cmd(D)
|
2013-06-13 17:11:06 +00:00
|
|
|
/ "_con._spawnmany(_aci,'MONEY',%1)",
|
2012-12-03 18:24:30 +00:00
|
|
|
paper = cmd(D)
|
2013-06-13 17:11:06 +00:00
|
|
|
/ "_con._spawnmany(_aci,'PAPER',%1)",
|
2012-12-03 18:24:30 +00:00
|
|
|
sleeptime = cmd(D)
|
|
|
|
/ ACS".timetosleep=%1",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-07 21:01:18 +00:00
|
|
|
eshoot = cmd(D)
|
2013-12-20 18:31:20 +00:00
|
|
|
/ "_gv.RETURN=_con.shoot(%1,_aci)",
|
2013-02-11 17:16:58 +00:00
|
|
|
eshootvar = cmd(R)
|
2013-12-20 18:31:20 +00:00
|
|
|
/ "_gv.RETURN=_con.shoot(%1,_aci)",
|
2013-02-07 21:01:18 +00:00
|
|
|
ezshoot = cmd(R,D)
|
2013-12-20 18:31:20 +00:00
|
|
|
/ "_gv.RETURN=_con.shoot(%2,_aci,%1)",
|
2013-02-07 21:01:18 +00:00
|
|
|
ezshootvar = cmd(R,R)
|
2013-12-20 18:31:20 +00:00
|
|
|
/ "_gv.RETURN=_con.shoot(%2,_aci,%1)",
|
2012-12-03 18:24:25 +00:00
|
|
|
shoot = cmd(D)
|
2013-12-20 18:31:20 +00:00
|
|
|
/ "_con.shoot(%1,_aci)",
|
2013-02-11 17:16:58 +00:00
|
|
|
shootvar = cmd(R)
|
2013-12-20 18:31:20 +00:00
|
|
|
/ "_con.shoot(%1,_aci)",
|
2013-02-07 21:01:18 +00:00
|
|
|
zshoot = cmd(R,D)
|
2013-12-20 18:31:20 +00:00
|
|
|
/ "_con.shoot(%2,_aci,%1)",
|
2013-02-07 21:01:18 +00:00
|
|
|
zshootvar = cmd(R,R)
|
2013-12-20 18:31:20 +00:00
|
|
|
/ "_con.shoot(%2,_aci,%1)",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-12-03 18:24:25 +00:00
|
|
|
fall = cmd()
|
2013-07-04 19:38:32 +00:00
|
|
|
/ "actor.fall(_aci)",
|
2012-12-09 13:24:39 +00:00
|
|
|
flash = cmd()
|
2013-01-02 22:33:37 +00:00
|
|
|
/ format("_con._flash(%s,%s)", SPS"", PLS""),
|
2012-12-03 18:24:30 +00:00
|
|
|
getlastpal = cmd()
|
|
|
|
/ "_con._getlastpal(_aci)",
|
2012-12-28 17:18:02 +00:00
|
|
|
insertspriteq = cmd()
|
|
|
|
/ "_con._addtodelqueue(_aci)",
|
2012-12-03 18:24:25 +00:00
|
|
|
killit = cmd() -- NLCF
|
|
|
|
/ "_con.killit()",
|
2012-12-03 18:24:30 +00:00
|
|
|
nullop = cmd()
|
|
|
|
/ "", -- NOTE: really generate no code
|
|
|
|
pkick = cmd()
|
2012-12-09 13:24:39 +00:00
|
|
|
/ format("_con._pkick(%s,%s)", PLS"", ACS""),
|
2012-12-03 18:24:25 +00:00
|
|
|
pstomp = cmd()
|
2013-01-13 16:40:21 +00:00
|
|
|
/ PLS":stomp(_aci)",
|
2012-11-30 18:57:46 +00:00
|
|
|
resetactioncount = cmd()
|
|
|
|
/ ACS":reset_acount()",
|
|
|
|
resetcount = cmd()
|
|
|
|
/ ACS":set_count(0)",
|
2012-12-03 18:24:25 +00:00
|
|
|
resetplayer = cmd() -- NLCF
|
|
|
|
/ "if (_con._VM_ResetPlayer2(_pli,_aci)) then _con.longjmp() end",
|
2012-12-03 18:24:30 +00:00
|
|
|
respawnhitag = cmd()
|
2013-01-02 22:33:37 +00:00
|
|
|
/ format("_con._respawnhitag(%s)", SPS""),
|
2012-11-30 18:57:46 +00:00
|
|
|
tip = cmd()
|
|
|
|
/ PLS".tipincs=26",
|
2012-12-03 18:24:30 +00:00
|
|
|
tossweapon = cmd()
|
2013-07-13 21:04:38 +00:00
|
|
|
/ "_con._tossweapon(_pli)",
|
2012-12-03 18:24:30 +00:00
|
|
|
wackplayer = cmd()
|
2013-07-04 19:38:32 +00:00
|
|
|
/ PLS":whack()",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-04-22 19:10:46 +00:00
|
|
|
-- player/sprite searching
|
2013-02-16 18:53:04 +00:00
|
|
|
findplayer = cmd(W)
|
2013-08-23 17:01:10 +00:00
|
|
|
/ "_gv.RETURN,%1=_con._findplayer(_pli,_aci)", -- player index, distance
|
2013-02-16 18:53:04 +00:00
|
|
|
findotherplayer = cmd(W)
|
2013-08-23 17:01:10 +00:00
|
|
|
/ "_gv.RETURN,%1=0,0x7fffffff", -- TODO_MP
|
2013-02-18 16:07:32 +00:00
|
|
|
findnearspritezvar = cmd(D,R,R,W)
|
|
|
|
/ "%4=_con._findnear(_aci,true,'z',%1,%2,%3)",
|
|
|
|
findnearspritez = cmd(D,D,D,W)
|
|
|
|
/ "%4=_con._findnear(_aci,true,'z',%1,%2,%3)",
|
|
|
|
findnearsprite3dvar = cmd(D,R,W)
|
|
|
|
/ "%3=_con._findnear(_aci,true,'d3',%1,%2)",
|
|
|
|
findnearsprite3d = cmd(D,D,W)
|
|
|
|
/ "%3=_con._findnear(_aci,true,'d3',%1,%2)",
|
|
|
|
findnearspritevar = cmd(D,R,W)
|
|
|
|
/ "%3=_con._findnear(_aci,true,'d2',%1,%2)",
|
|
|
|
findnearsprite = cmd(D,D,W)
|
|
|
|
/ "%3=_con._findnear(_aci,true,'d2',%1,%2)",
|
|
|
|
findnearactorzvar = cmd(D,R,R,W)
|
|
|
|
/ "%4=_con._findnear(_aci,false,'z',%1,%2,%3)",
|
|
|
|
findnearactorz = cmd(D,D,D,W)
|
|
|
|
/ "%4=_con._findnear(_aci,false,'z',%1,%2,%3)",
|
|
|
|
findnearactor3dvar = cmd(D,R,W)
|
|
|
|
/ "%3=_con._findnear(_aci,false,'d3',%1,%2)",
|
|
|
|
findnearactor3d = cmd(D,D,W)
|
|
|
|
/ "%3=_con._findnear(_aci,false,'d3',%1,%2)",
|
|
|
|
findnearactorvar = cmd(D,R,W)
|
|
|
|
/ "%3=_con._findnear(_aci,false,'d2',%1,%2)",
|
|
|
|
findnearactor = cmd(D,D,W)
|
|
|
|
/ "%3=_con._findnear(_aci,false,'d2',%1,%2)",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
-- quotes
|
2013-02-18 16:07:59 +00:00
|
|
|
qsprintf = sp1 * tok.rvar * sp1 * tok.rvar * (sp1 * tok.rvar)^-32
|
|
|
|
/ handle.qsprintf,
|
2013-02-18 16:07:51 +00:00
|
|
|
qgetsysstr = cmd(R,R)
|
2013-02-21 18:53:57 +00:00
|
|
|
/ "_con._qgetsysstr(%1,%2,_pli)",
|
2013-02-18 16:07:51 +00:00
|
|
|
qstrcat = cmd(R,R)
|
|
|
|
/ "_con._qstrcat(%1,%2)",
|
|
|
|
qstrcpy = cmd(R,R)
|
|
|
|
/ "_con._qstrcpy(%1,%2)",
|
|
|
|
qstrlen = cmd(W,R)
|
|
|
|
/ "%1=_con._qstrlen(%2)",
|
|
|
|
qstrncat = cmd(R,R)
|
|
|
|
/ handle.NYI,
|
2013-06-13 17:11:07 +00:00
|
|
|
qsubstr = cmd(R,R,R,R)
|
2013-02-18 16:07:51 +00:00
|
|
|
/ handle.NYI,
|
2013-02-18 16:07:32 +00:00
|
|
|
quote = cmd(D)
|
|
|
|
/ "_con._quote(_pli,%1)",
|
2013-02-18 16:07:51 +00:00
|
|
|
userquote = cmd(R)
|
|
|
|
/ "_con._userquote(%1)",
|
|
|
|
getkeyname = cmd(R,R,R)
|
|
|
|
/ "_con._getkeyname(%1,%2,%3)",
|
2013-02-24 16:05:22 +00:00
|
|
|
getpname = cmd(R,R) -- THISACTOR
|
2013-06-07 14:26:34 +00:00
|
|
|
/ function(qnum, pli)
|
|
|
|
return format("_con._getpname(%s,%s)", qnum, thisactor_to_pli(pli))
|
|
|
|
end,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
-- array stuff
|
2013-02-18 16:07:48 +00:00
|
|
|
copy = sp1 * tok.gamearray * arraypat * sp1 * tok.gamearray * arraypat * sp1 * tok.rvar
|
2013-07-09 18:23:43 +00:00
|
|
|
/ function(...) return handle.arraycmd("_con._gar_copy(%s,%s,%s,%s,%s)", 3, ...) end,
|
2013-02-18 16:07:48 +00:00
|
|
|
setarray = sp1 * tok.gamearray * arraypat * sp1 * tok.rvar
|
2013-07-09 18:23:43 +00:00
|
|
|
/ function(...) return handle.arraycmd("%s[%s]=%s", 1, ...) end,
|
2013-02-18 16:07:48 +00:00
|
|
|
resizearray = cmd(GARI,R)
|
2013-07-09 18:23:43 +00:00
|
|
|
/ function(...) return handle.arraycmd("%s:resize(%s)", 1, ...) end,
|
2013-02-18 16:07:48 +00:00
|
|
|
getarraysize = cmd(GARI,W)
|
2013-07-09 18:23:43 +00:00
|
|
|
/ function(ar, dst)
|
2013-07-13 21:04:41 +00:00
|
|
|
return format("%s=%s", dst, issysgar(ar) and tostring(C.MAXTILES) or ar.."._size")
|
2013-07-09 18:23:43 +00:00
|
|
|
end,
|
2013-02-24 16:05:22 +00:00
|
|
|
readarrayfromfile = cmd(GARI,D)
|
2013-07-09 18:23:43 +00:00
|
|
|
/ function(...) -- false: error on no file, nil: don't.
|
|
|
|
return handle.arraycmd("%s:read(%s,nil)", 1, ...)
|
|
|
|
end,
|
2013-02-24 16:05:22 +00:00
|
|
|
writearraytofile = cmd(GARI,D)
|
2013-07-09 18:23:43 +00:00
|
|
|
/ function(...)
|
|
|
|
return handle.arraycmd("%s:write(%s)", 1, ...)
|
|
|
|
end,
|
2013-02-24 16:05:22 +00:00
|
|
|
|
|
|
|
-- Persistence
|
|
|
|
clearmapstate = cmd(R)
|
2013-05-20 19:31:34 +00:00
|
|
|
/ handle.NYI,
|
2013-02-24 16:05:22 +00:00
|
|
|
loadmapstate = cmd()
|
2013-05-20 19:31:34 +00:00
|
|
|
/ "_con._loadmapstate()",
|
2013-02-24 16:05:22 +00:00
|
|
|
savemapstate = cmd()
|
2013-05-20 19:31:34 +00:00
|
|
|
/ "_con._savemapstate()",
|
2013-02-28 17:30:15 +00:00
|
|
|
savegamevar = cmd(I)
|
|
|
|
/ function(id) return handle.RSgamevar(id, true) end,
|
|
|
|
readgamevar = cmd(I)
|
|
|
|
/ function(id) return handle.RSgamevar(id, false) end,
|
2013-02-24 16:05:22 +00:00
|
|
|
savenn = cmd(D)
|
|
|
|
/ handle.dynNYI,
|
|
|
|
save = cmd(D)
|
|
|
|
/ handle.dynNYI,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-24 20:03:02 +00:00
|
|
|
addlogvar = cmd(R)
|
|
|
|
/ handle.addlogvar,
|
|
|
|
addlog = cmd() * #sp1
|
|
|
|
/ handle.addlog,
|
2013-01-24 20:02:57 +00:00
|
|
|
addweaponvar = cmd(R,R) -- NLCF
|
|
|
|
/ handle.addweapon,
|
2013-02-16 18:53:15 +00:00
|
|
|
cansee = cmd(R,R,R,R,R,R,R,R,W)
|
2013-03-13 10:48:23 +00:00
|
|
|
/ "%9=cansee(_IV(1,%1,%2,%3),%4, _IV(2,%5,%6,%7),%8) and 1 or 0",
|
2013-02-16 18:53:15 +00:00
|
|
|
canseespr = cmd(R,R,W)
|
|
|
|
/ "%3=_con._canseespr(%1,%2)",
|
2013-02-11 17:16:58 +00:00
|
|
|
changespritesect = cmd(R,R)
|
2013-03-24 18:53:48 +00:00
|
|
|
/ "sprite.changesect(%1,%2,true)",
|
2013-02-11 17:16:58 +00:00
|
|
|
changespritestat = cmd(R,R)
|
2013-03-24 18:53:48 +00:00
|
|
|
/ "sprite.changestat(%1,%2,true)",
|
2013-02-16 18:53:24 +00:00
|
|
|
displayrand = cmd(W)
|
|
|
|
/ "%1=_con._displayrand(32767)",
|
|
|
|
displayrandvar = cmd(W,D)
|
|
|
|
/ "%1=_con._displayrand(%2)",
|
|
|
|
displayrandvarvar = cmd(W,R)
|
|
|
|
/ "%1=_con._displayrand(%2)",
|
2013-02-16 18:53:15 +00:00
|
|
|
dist = cmd(W,R,R)
|
2013-03-03 16:06:16 +00:00
|
|
|
/ "%1=_xmath.dist(sprite[%2],sprite[%3])",
|
2013-02-16 18:53:15 +00:00
|
|
|
ldist = cmd(W,R,R)
|
2013-03-03 16:06:16 +00:00
|
|
|
/ "%1=_xmath.ldist(sprite[%2],sprite[%3])",
|
2013-02-16 18:53:24 +00:00
|
|
|
dragpoint = cmd(R,R,R)
|
2013-05-24 13:54:37 +00:00
|
|
|
/ "wall.dragto(%1,_IV(1,%2,%3,0))",
|
2013-02-16 18:53:24 +00:00
|
|
|
rotatepoint = cmd(R,R,R,R,R,W,W)
|
|
|
|
/ "%6,%7=_con._rotatepoint(%1,%2,%3,%4,%5)",
|
|
|
|
|
|
|
|
-- collision detection etc.
|
|
|
|
hitscan = cmd(R,R,R,R,R,R,R,W,W,W,W,W,W,R) -- 7R 6W 1R
|
|
|
|
/ handle.hitscan,
|
2013-05-24 13:54:37 +00:00
|
|
|
clipmove = cmd(W,W,W,R,W,R,R,R,R,R,R) -- 3W 1R 1W 6R
|
|
|
|
/ function(...) return handle.clipmove(0, ...) end,
|
|
|
|
clipmovenoslide = cmd(W,W,W,R,W,R,R,R,R,R,R) -- 3W 1R 1W 6R
|
|
|
|
/ function(...) return handle.clipmove(1, ...) end,
|
2013-02-16 18:53:24 +00:00
|
|
|
lineintersect = cmd(R,R,R,R,R,R,R,R,R,R,W,W,W,W) -- 10R 4W
|
|
|
|
/ handle.NYI,
|
|
|
|
rayintersect = cmd(R,R,R,R,R,R,R,R,R,R,W,W,W,W) -- 10R 4W
|
|
|
|
/ handle.NYI,
|
|
|
|
movesprite = cmd(R,R,R,R,R,W)
|
|
|
|
/ "%6=_con._movesprite(%1,%2,%3,%4,%5)",
|
|
|
|
neartag = cmd(R,R,R,R,R,W,W,W,W,R,R) -- 5R 4W 2R
|
|
|
|
/ handle.neartag,
|
|
|
|
getzrange = cmd(R,R,R,R,W,W,W,W,R,R)
|
2013-02-25 15:31:13 +00:00
|
|
|
/ handle.getzrange,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
-- screen text and numbers display
|
2013-06-01 20:09:45 +00:00
|
|
|
qstrdim = cmd(W,W,R,R,R,R,R,R,R,R,R,R,R,R,R,R,R,R) -- 2W 16R
|
|
|
|
/ function(...)
|
|
|
|
return format("%s,%s=_con._qstrdim("..n_s_fmt(16)..")", ...)
|
|
|
|
end,
|
|
|
|
screentext = cmd(R,R,R,R,R,R,R,R,R,R,R,R,R,R,R,R,R,R,R,R) -- 20 R
|
|
|
|
/ function(...)
|
|
|
|
return format("_con._screentext("..n_s_fmt(20)..")", ...)
|
|
|
|
end,
|
2013-02-18 16:07:42 +00:00
|
|
|
gametext = cmd(R,R,R,R,R,R,R,R,R,R,R) -- 11 R
|
|
|
|
/ function(...)
|
|
|
|
return format("_con._gametext("..n_s_fmt(11)..",65536)", ...)
|
|
|
|
end,
|
|
|
|
gametextz = cmd(R,R,R,R,R,R,R,R,R,R,R,R) -- 12 R
|
|
|
|
/ function(...)
|
|
|
|
return format("_con._gametext("..n_s_fmt(12)..")", ...)
|
|
|
|
end,
|
|
|
|
digitalnumber = cmd(R,R,R,R,R,R,R,R,R,R,R) -- 11R
|
|
|
|
/ function(...)
|
|
|
|
return format("_con._digitalnumber("..n_s_fmt(11)..",65536)", ...)
|
|
|
|
end,
|
|
|
|
digitalnumberz = cmd(R,R,R,R,R,R,R,R,R,R,R,R) -- 12R
|
|
|
|
/ function(...)
|
|
|
|
return format("_con._digitalnumber("..n_s_fmt(12)..")", ...)
|
|
|
|
end,
|
|
|
|
minitext = cmd(R,R,R,R,R)
|
|
|
|
/ "_con._minitext(%1,%2,%3,%4,%5)",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
palfrom = (sp1 * tok.define)^-4
|
|
|
|
/ handle.palfrom,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-16 18:53:04 +00:00
|
|
|
activatebysector = cmd(R,R)
|
|
|
|
/ "_con._activatebysector(%1,%2)",
|
2013-05-24 13:54:29 +00:00
|
|
|
activate = cmd(D) -- PRE13, THISACTOR already translated to cur. player
|
|
|
|
/ "_con._operateactivators(%d,_pli)",
|
2013-02-16 18:53:04 +00:00
|
|
|
operateactivators = cmd(R,R) -- THISACTOR
|
|
|
|
/ function(tag, pli)
|
2013-02-24 16:05:22 +00:00
|
|
|
return format("_con._operateactivators(%s,%s)", tag, thisactor_to_pli(pli))
|
2013-02-16 18:53:04 +00:00
|
|
|
end,
|
|
|
|
operatesectors = cmd(R,R)
|
|
|
|
/ "_con._operatesectors(%1,%2)",
|
2012-12-03 18:24:30 +00:00
|
|
|
operate = cmd() * #sp1
|
|
|
|
/ "_con._operate(_aci)",
|
2012-04-29 20:54:06 +00:00
|
|
|
|
2013-02-11 17:16:58 +00:00
|
|
|
myos = cmd(R,R,R,R,R)
|
|
|
|
/ "_con._myos(%1,%2,65536,%3,%4,%5)",
|
|
|
|
myosx = cmd(R,R,R,R,R)
|
|
|
|
/ "_con._myos(%1,%2,32768,%3,%4,%5)",
|
|
|
|
myospal = cmd(R,R,R,R,R,R)
|
|
|
|
/ "_con._myos(%1,%2,65536,%3,%4,%5,%6)",
|
|
|
|
myospalx = cmd(R,R,R,R,R,R)
|
|
|
|
/ "_con._myos(%1,%2,32768,%3,%4,%5,%6)",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-18 16:07:32 +00:00
|
|
|
headspritesect = cmd(W,R)
|
|
|
|
/ "%1=sprite._headspritesect[%2]",
|
|
|
|
headspritestat = cmd(W,R)
|
|
|
|
/ "%1=sprite._headspritestat[%2]",
|
|
|
|
nextspritesect = cmd(W,R)
|
|
|
|
/ "%1=sprite._nextspritesect[%2]",
|
|
|
|
nextspritestat = cmd(W,R)
|
|
|
|
/ "%1=sprite._nextspritestat[%2]",
|
|
|
|
prevspritesect = cmd(W,R)
|
|
|
|
/ "%1=sprite._prevspritesect[%2]",
|
|
|
|
prevspritestat = cmd(W,R)
|
|
|
|
/ "%1=sprite._prevspritestat[%2]",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-04-09 17:34:53 +00:00
|
|
|
-- NOTE: Yup, it's also an inner command. Do this one concession to
|
|
|
|
-- cleanness for backward compatibility (e.g. Sonic3D v0.3).
|
|
|
|
definequote = sp1 * tok.define * newline_term_string
|
|
|
|
/ Cmd.definequote,
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
redefinequote = sp1 * tok.define * newline_term_string
|
2013-01-05 13:09:19 +00:00
|
|
|
/ function(qnum, qstr) return format("_con._definequote(%d,%q)", qnum, stripws(qstr)) end,
|
2013-02-11 17:16:58 +00:00
|
|
|
rotatesprite = cmd(R,R,R,R,R,R,R,R,R,R,R,R) -- 12R
|
|
|
|
/ handle.rotatesprite,
|
|
|
|
rotatesprite16 = cmd(R,R,R,R,R,R,R,R,R,R,R,R) -- 12R
|
|
|
|
/ handle.rotatesprite16,
|
2013-03-25 04:33:03 +00:00
|
|
|
rotatespritea = cmd(R,R,R,R,R,R,R,R,R,R,R,R,R) -- 13R
|
|
|
|
/ handle.rotatespritea,
|
2013-02-16 18:53:04 +00:00
|
|
|
sectorofwall = cmd(W,R,R)
|
|
|
|
/ handle.NYI,
|
|
|
|
sectclearinterpolation = cmd(R)
|
|
|
|
/ "_con._togglesectinterp(%1,0)",
|
|
|
|
sectsetinterpolation = cmd(R)
|
|
|
|
/ "_con._togglesectinterp(%1,1)",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-11 17:16:58 +00:00
|
|
|
sectgethitag = cmd()
|
|
|
|
/ (CSV".HITAG=sector["..SPS".sectnum].hitag"),
|
|
|
|
sectgetlotag = cmd()
|
|
|
|
/ (CSV".LOTAG=sector["..SPS".sectnum].lotag"),
|
|
|
|
spgethitag = cmd()
|
|
|
|
/ (CSV".HITAG="..SPS".hitag"),
|
|
|
|
spgetlotag = cmd()
|
|
|
|
/ (CSV".LOTAG="..SPS".lotag"),
|
|
|
|
gettextureceiling = cmd()
|
|
|
|
/ (CSV".TEXTURE=sector["..SPS".sectnum].ceilingpicnum"),
|
|
|
|
gettexturefloor = cmd()
|
|
|
|
/ (CSV".TEXTURE=sector["..SPS".sectnum].floorpicnum"),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-16 18:53:24 +00:00
|
|
|
startlevel = cmd(R,R)
|
|
|
|
/ "_con._startlevel(%1,%2)",
|
|
|
|
starttrack = cmd(D)
|
|
|
|
/ "_con._starttrack(%1)",
|
|
|
|
starttrackvar = cmd(R)
|
|
|
|
/ "_con._starttrack(%1)",
|
|
|
|
|
2013-02-18 16:07:42 +00:00
|
|
|
setaspect = cmd(R,R)
|
|
|
|
/ "_con._setaspect(%1,%2)",
|
2013-02-25 15:31:09 +00:00
|
|
|
showview = cmd(R,R,R,R,R,R,R,R,R,R) -- 10R
|
2013-06-07 14:26:32 +00:00
|
|
|
/ function(...) return format("_con._showview("..n_s_fmt(10)..",0)", ...) end,
|
2013-02-25 15:31:09 +00:00
|
|
|
showviewunbiased = cmd(R,R,R,R,R,R,R,R,R,R) -- 10R
|
2013-06-07 14:26:32 +00:00
|
|
|
/ function(...) return format("_con._showview("..n_s_fmt(10)..",1)", ...) end,
|
2013-01-24 20:02:57 +00:00
|
|
|
smaxammo = cmd(R,R)
|
2013-04-07 15:20:37 +00:00
|
|
|
/ PLS".max_ammo_amount[%1]=%2",
|
2013-02-11 17:16:58 +00:00
|
|
|
gmaxammo = cmd(R,W)
|
|
|
|
/ ("%2="..PLS".max_ammo_amount[%1]"),
|
|
|
|
spriteflags = cmd(R) -- also see outer
|
|
|
|
/ ACS".flags=%1",
|
|
|
|
ssp = cmd(R,R)
|
2013-11-12 21:03:11 +00:00
|
|
|
/ "_ssp(%1,%2)",
|
2013-02-18 16:07:42 +00:00
|
|
|
setsprite = cmd(R,R,R,R)
|
2013-07-13 21:04:57 +00:00
|
|
|
/ "_setsprite(%1,_IV(1,%2,%3,%4))",
|
2013-02-18 16:07:42 +00:00
|
|
|
updatesector = cmd(R,R,W)
|
2013-03-13 10:48:23 +00:00
|
|
|
/ format("%%3=updatesector(_IV(1,%%1,%%2,0),%s)", SPS".sectnum"),
|
2013-02-18 16:07:42 +00:00
|
|
|
updatesectorz = cmd(R,R,R,W)
|
2013-03-13 10:48:23 +00:00
|
|
|
/ format("%%4=updatesectorz(_IV(1,%%1,%%2,%%3),%s)", SPS".sectnum"),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-11 17:16:58 +00:00
|
|
|
getactorangle = cmd(W)
|
|
|
|
/ ("%1="..SPS".ang"),
|
2013-02-16 18:53:24 +00:00
|
|
|
setactorangle = cmd(R)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ SPS".ang=_band(%1,2047)",
|
2013-02-11 17:16:58 +00:00
|
|
|
getplayerangle = cmd(W)
|
|
|
|
/ ("%1="..PLS".ang"),
|
2013-02-16 18:53:24 +00:00
|
|
|
setplayerangle = cmd(R)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ PLS".ang=_band(%1,2047)",
|
2013-02-11 17:16:58 +00:00
|
|
|
getangletotarget = cmd(W)
|
|
|
|
/ "%1=_con._angtotarget(_aci)",
|
|
|
|
|
|
|
|
getceilzofslope = cmd(R,R,R,W)
|
2013-03-13 10:48:23 +00:00
|
|
|
/ "%4=sector[%1]:ceilingzat(_IV(1,%2,%3,0))",
|
2013-02-11 17:16:58 +00:00
|
|
|
getflorzofslope = cmd(R,R,R,W)
|
2013-03-13 10:48:23 +00:00
|
|
|
/ "%4=sector[%1]:floorzat(_IV(1,%2,%3,0))",
|
2013-02-11 17:16:58 +00:00
|
|
|
getcurraddress = cmd(W)
|
|
|
|
/ handle.NYI, -- will never be
|
|
|
|
getticks = cmd(W)
|
2013-02-16 18:53:15 +00:00
|
|
|
/ "%1=_gv.getticks()",
|
2013-02-16 18:53:04 +00:00
|
|
|
gettimedate = cmd(W,W,W,W,W,W,W,W)
|
|
|
|
/ "%1,%2,%3,%4,%5,%6,%7,%8=_con._gettimedate()",
|
2012-04-07 20:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local Cif = {
|
2012-11-30 18:57:46 +00:00
|
|
|
ifai = cmd(AI)
|
|
|
|
/ ACS":has_ai(%1)",
|
|
|
|
ifaction = cmd(AC)
|
|
|
|
/ ACS":has_action(%1)",
|
|
|
|
ifmove = cmd(MV)
|
|
|
|
/ ACS":has_move(%1)",
|
|
|
|
|
|
|
|
ifrnd = cmd(D)
|
2012-12-03 18:24:25 +00:00
|
|
|
/ "_con.rnd(%1)",
|
2013-03-03 16:06:12 +00:00
|
|
|
ifpdistl = cmd(D) -- DEFER
|
|
|
|
/ function(val) return { "_dist<"..val, nil, "_con._sleepcheck(_aci,_dist)" } end,
|
|
|
|
ifpdistg = cmd(D) -- DEFER
|
|
|
|
/ function(val) return { "_dist>"..val, nil, "_con._sleepcheck(_aci,_dist)" } end,
|
2012-11-30 18:57:46 +00:00
|
|
|
ifactioncount = cmd(D)
|
2013-01-02 22:33:37 +00:00
|
|
|
/ ACS":get_acount()>=%1",
|
2012-11-30 18:57:46 +00:00
|
|
|
ifcount = cmd(D)
|
2013-01-02 22:33:37 +00:00
|
|
|
/ ACS":get_count()>=%1",
|
2012-11-30 18:57:46 +00:00
|
|
|
ifactor = cmd(D)
|
2012-12-09 13:24:28 +00:00
|
|
|
/ SPS".picnum==%1",
|
2012-11-30 18:57:46 +00:00
|
|
|
ifstrength = cmd(D)
|
2012-12-09 13:24:28 +00:00
|
|
|
/ SPS".extra<=%1",
|
2012-11-30 18:57:46 +00:00
|
|
|
ifspawnedby = cmd(D)
|
2012-12-09 13:24:28 +00:00
|
|
|
/ ACS".picnum==%1",
|
2012-11-30 18:57:46 +00:00
|
|
|
ifwasweapon = cmd(D)
|
2012-12-09 13:24:28 +00:00
|
|
|
/ ACS".picnum==%1",
|
2012-11-30 18:57:46 +00:00
|
|
|
ifgapzl = cmd(D) -- factor into a con.* function?
|
2013-04-05 17:53:21 +00:00
|
|
|
/ format("_arsh(%s-%s,8)<%%1", ACS".floorz", ACS".ceilingz"),
|
2012-11-30 18:57:46 +00:00
|
|
|
iffloordistl = cmd(D)
|
|
|
|
/ format("(%s-%s)<=256*%%1", ACS".floorz", SPS".z"),
|
|
|
|
ifceilingdistl = cmd(D)
|
|
|
|
/ format("(%s-%s)<=256*%%1", SPS".z", ACS".ceilingz"),
|
|
|
|
ifphealthl = cmd(D)
|
|
|
|
/ format("sprite[%s].extra<%%1", PLS".i"),
|
2013-05-24 13:54:29 +00:00
|
|
|
ifplayersl = cmd(D) -- PRE13
|
|
|
|
/ "1<%1", -- TODO_MP
|
2012-11-30 18:57:46 +00:00
|
|
|
ifspritepal = cmd(D)
|
|
|
|
/ SPS".pal==%1",
|
2012-12-03 18:24:30 +00:00
|
|
|
ifgotweaponce = cmd(D)
|
2013-02-18 16:07:32 +00:00
|
|
|
/ "false", -- TODO_MP
|
2012-12-03 18:24:30 +00:00
|
|
|
ifangdiffl = cmd(D)
|
|
|
|
/ format("_con._angdiffabs(%s,%s)<=%%1", PLS".ang", SPS".ang"),
|
2012-12-03 18:24:25 +00:00
|
|
|
ifsound = cmd(D)
|
2013-01-19 18:28:40 +00:00
|
|
|
/ "_con._soundplaying(_aci,%1)",
|
2012-12-03 18:24:30 +00:00
|
|
|
ifpinventory = cmd(D,D)
|
2013-01-24 20:02:57 +00:00
|
|
|
/ format("_con._checkpinventory(%s,%%1,%%2,_aci)", PLS""),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-19 18:28:40 +00:00
|
|
|
ifvarl = cmd(R,D)
|
|
|
|
/ "%1<%2",
|
|
|
|
ifvarg = cmd(R,D)
|
|
|
|
/ "%1>%2",
|
2013-01-05 13:09:19 +00:00
|
|
|
ifvare = cmd(R,D)
|
|
|
|
/ "%1==%2",
|
2013-01-19 18:28:40 +00:00
|
|
|
ifvarn = cmd(R,D)
|
|
|
|
/ "%1~=%2",
|
|
|
|
ifvarand = cmd(R,D)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ "_band(%1,%2)~=0",
|
2013-01-19 18:28:40 +00:00
|
|
|
ifvaror = cmd(R,D)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ "_bor(%1,%2)~=0",
|
2013-01-19 18:28:40 +00:00
|
|
|
ifvarxor = cmd(R,D)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ "_bxor(%1,%2)~=0",
|
2013-01-19 18:28:40 +00:00
|
|
|
ifvareither = cmd(R,D)
|
|
|
|
/ "%1~=0 or %2~=0",
|
|
|
|
|
|
|
|
ifvarvarl = cmd(R,R)
|
|
|
|
/ "%1<%2",
|
|
|
|
ifvarvarg = cmd(R,R)
|
|
|
|
/ "%1>%2",
|
|
|
|
ifvarvare = cmd(R,R)
|
|
|
|
/ "%1==%2",
|
|
|
|
ifvarvarn = cmd(R,R)
|
|
|
|
/ "%1~=%2",
|
|
|
|
ifvarvarand = cmd(R,R)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ "_band(%1,%2)~=0",
|
2013-01-19 18:28:40 +00:00
|
|
|
ifvarvaror = cmd(R,R)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ "_bor(%1,%2)~=0",
|
2013-01-19 18:28:40 +00:00
|
|
|
ifvarvarxor = cmd(R,R)
|
2013-04-05 17:53:21 +00:00
|
|
|
/ "_bxor(%1,%2)~=0",
|
2013-01-19 18:28:40 +00:00
|
|
|
ifvarvareither = cmd(R,R)
|
|
|
|
/ "%1~=0 or %2~=0",
|
|
|
|
|
|
|
|
ifactorsound = cmd(R,R)
|
|
|
|
/ "_con._soundplaying(%1,%2)",
|
2012-04-29 20:54:06 +00:00
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
ifp = (sp1 * tok.define)^1
|
2012-12-09 13:24:39 +00:00
|
|
|
/ function (...) return format("_con._ifp(%d,_pli,_aci)", bit.bor(...)) end,
|
2012-12-03 18:24:25 +00:00
|
|
|
ifsquished = cmd()
|
2013-04-05 17:52:59 +00:00
|
|
|
/ "_con._squished(_aci,_pli)",
|
2013-02-18 16:07:42 +00:00
|
|
|
ifserver = cmd()
|
|
|
|
/ "false", -- TODO_MP
|
2012-12-03 18:24:30 +00:00
|
|
|
ifrespawn = cmd()
|
2012-12-09 13:24:39 +00:00
|
|
|
/ format("_con._checkrespawn(%s)", SPS""),
|
2012-11-30 18:57:46 +00:00
|
|
|
ifoutside = cmd()
|
2013-04-05 17:53:21 +00:00
|
|
|
/ format("_band(sector[%s].ceilingstat,1)~=0", SPS".sectnum"),
|
2012-12-03 18:24:25 +00:00
|
|
|
ifonwater = cmd()
|
2012-12-23 19:24:16 +00:00
|
|
|
/ format("sector[%s].lotag==1 and _math.abs(%s-sector[%s].floorz)<32*256",
|
2012-12-03 18:24:25 +00:00
|
|
|
SPS".sectnum", SPS".z", SPS".sectnum"),
|
2012-12-03 18:24:30 +00:00
|
|
|
ifnotmoving = cmd()
|
2013-04-05 17:53:21 +00:00
|
|
|
/ "_band(actor[_aci]._movflag,49152)>16384",
|
2012-12-23 19:24:16 +00:00
|
|
|
ifnosounds = cmd()
|
2013-04-09 17:34:53 +00:00
|
|
|
/ "not _con._ianysound(_aci)",
|
2012-11-30 18:57:46 +00:00
|
|
|
ifmultiplayer = cmd()
|
2013-02-18 16:07:32 +00:00
|
|
|
/ "false", -- TODO_MP
|
2012-11-30 18:57:46 +00:00
|
|
|
ifinwater = cmd()
|
|
|
|
/ format("sector[%s].lotag==2", SPS".sectnum"),
|
2012-12-03 18:24:30 +00:00
|
|
|
ifinspace = cmd()
|
2012-12-09 13:24:39 +00:00
|
|
|
/ format("_con._checkspace(%s,false)", SPS".sectnum"),
|
2012-12-03 18:24:30 +00:00
|
|
|
ifinouterspace = cmd()
|
2012-12-09 13:24:39 +00:00
|
|
|
/ format("_con._checkspace(%s,true)", SPS".sectnum"),
|
2012-11-30 18:57:46 +00:00
|
|
|
ifhitweapon = cmd()
|
2013-01-01 15:24:22 +00:00
|
|
|
/ "_con._A_IncurDamage(_aci)>=0",
|
2012-12-03 18:24:30 +00:00
|
|
|
ifhitspace = cmd()
|
2013-07-04 19:38:42 +00:00
|
|
|
/ "player.holdskey(_pli,'OPEN')",
|
2012-11-30 18:57:46 +00:00
|
|
|
ifdead = cmd()
|
|
|
|
/ SPS".extra<=0",
|
2013-02-18 16:07:42 +00:00
|
|
|
ifclient = cmd()
|
|
|
|
/ "false", -- TODO_MP
|
2012-12-03 18:24:25 +00:00
|
|
|
ifcanshoottarget = cmd()
|
2012-12-09 13:24:39 +00:00
|
|
|
/ "_con._canshoottarget(_dist,_aci)",
|
2013-03-03 16:06:12 +00:00
|
|
|
ifcanseetarget = cmd() -- DEFER -- XXX: 1536 is SLEEPTIME
|
|
|
|
/ function()
|
|
|
|
return { format("_con._canseetarget(%s,%s)", SPS"", PLS""), ACS".timetosleep=1536" }
|
|
|
|
end,
|
2012-12-09 13:24:39 +00:00
|
|
|
ifcansee = cmd() * #sp1
|
|
|
|
/ format("_con._cansee(_aci,%s)", PLS""),
|
2012-12-03 18:24:30 +00:00
|
|
|
ifbulletnear = cmd()
|
|
|
|
/ "_con._bulletnear(_aci)",
|
|
|
|
ifawayfromwall = cmd()
|
|
|
|
/ format("_con._awayfromwall(%s,108)", SPS""),
|
2012-11-30 18:57:46 +00:00
|
|
|
ifactornotstayput = cmd()
|
2013-06-12 17:49:55 +00:00
|
|
|
/ ACS".stayputsect==-1",
|
2012-04-07 20:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 19:10:46 +00:00
|
|
|
----==== Tracing and reporting ====----
|
|
|
|
|
2012-06-10 18:56:21 +00:00
|
|
|
-- g_newlineidxs will contain the 1-based file offsets to "\n" characters
|
|
|
|
local g_newlineidxs = {}
|
2012-04-22 19:10:46 +00:00
|
|
|
|
|
|
|
-- Returns index into the sorted table tab such that
|
|
|
|
-- tab[index] <= searchelt < tab[index+1].
|
|
|
|
-- Preconditions:
|
2012-06-10 18:56:18 +00:00
|
|
|
-- tab[i] < tab[i+1] for 0 <= i < #tab
|
|
|
|
-- tab[0] <= searchelt < tab[#tab]
|
2012-05-13 16:04:45 +00:00
|
|
|
-- If #tab is less than 2, returns 0. This plays nicely with newline index
|
|
|
|
-- tables like { [0]=0, [1]=len+1 }, e.g. if the file doesn't contain any.
|
2012-04-22 19:10:46 +00:00
|
|
|
local function bsearch(tab, searchelt)
|
|
|
|
-- printf("bsearch(tab, %d)", searchelt)
|
2012-06-10 18:56:18 +00:00
|
|
|
local l, r = 0, #tab
|
2012-04-22 19:10:46 +00:00
|
|
|
local i
|
|
|
|
|
2012-05-13 16:04:45 +00:00
|
|
|
if (r < 2) then
|
|
|
|
return 0
|
2012-04-22 19:10:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
while (l ~= r) do
|
|
|
|
i = l + math.ceil((r-l)/2) -- l < i <= r
|
|
|
|
assert(l < i and i <= r)
|
|
|
|
local elt = tab[i]
|
|
|
|
-- printf("l=%d tab[%d]=%d r=%d", l, i, elt, r)
|
|
|
|
|
|
|
|
if (searchelt == elt) then
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
|
|
|
|
if (searchelt < elt) then
|
|
|
|
r = i-1
|
|
|
|
else -- (searchelt > elt)
|
|
|
|
l = i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- printf("return tab[%d]=%d", l, tab[l])
|
|
|
|
return l
|
|
|
|
end
|
|
|
|
|
2012-06-10 18:56:18 +00:00
|
|
|
function getlinecol(pos) -- local
|
2012-11-25 13:18:46 +00:00
|
|
|
assert(type(pos)=="number")
|
2012-06-10 18:56:21 +00:00
|
|
|
local line = bsearch(g_newlineidxs, pos)
|
|
|
|
assert(line and g_newlineidxs[line]<=pos and pos<g_newlineidxs[line+1])
|
|
|
|
local col = pos-g_newlineidxs[line]
|
2014-03-16 15:06:20 +00:00
|
|
|
if (col == 0) then
|
|
|
|
-- XXX: we probably have an off-by-one error somewhere and it would
|
|
|
|
-- need to be fixed instead of doing these ugly workarounds.
|
|
|
|
line = line-1
|
|
|
|
col = pos-g_newlineidxs[line]
|
|
|
|
end
|
|
|
|
assert(col >= 1)
|
2012-05-13 16:04:45 +00:00
|
|
|
return line+1, col-1
|
2012-04-22 19:10:46 +00:00
|
|
|
end
|
|
|
|
|
2012-07-01 22:11:17 +00:00
|
|
|
-- A generic trace function, prints a position together with the match content.
|
|
|
|
-- The 'doit' parameter can be used to temporarily enable/disable a particular
|
|
|
|
-- tracing function.
|
2012-04-22 19:10:46 +00:00
|
|
|
local function TraceFunc(pat, label, doit)
|
2012-07-01 22:11:17 +00:00
|
|
|
assert(doit ~= nil)
|
2012-04-07 20:10:03 +00:00
|
|
|
pat = Pat(pat)
|
|
|
|
|
2012-07-01 22:11:17 +00:00
|
|
|
if (doit) then
|
2012-04-22 19:10:46 +00:00
|
|
|
local function tfunc(subj, pos, a)
|
2012-06-10 18:56:21 +00:00
|
|
|
printf("%s:%s: %s", linecolstr(pos), label, a)
|
2012-04-22 19:10:46 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
pat = lpeg.Cmt(pat, tfunc)
|
2012-04-29 20:54:06 +00:00
|
|
|
elseif (label=="kw") then -- HACK
|
|
|
|
local function tfunc(subj, pos, a)
|
|
|
|
g_lastkwpos = pos
|
|
|
|
g_lastkw = a
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
-- XXX: is there a better way?
|
|
|
|
pat = lpeg.Cmt(pat, tfunc)
|
2012-04-07 20:10:03 +00:00
|
|
|
end
|
2012-04-29 20:54:06 +00:00
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
return pat
|
|
|
|
end
|
|
|
|
|
2012-06-10 18:56:18 +00:00
|
|
|
local function BadIdent(pat)
|
2012-04-29 20:54:06 +00:00
|
|
|
local function tfunc(subj, pos, a)
|
2012-12-03 18:24:33 +00:00
|
|
|
if (g_warn["bad-identifier"] and not g_badids[a]) then
|
2012-06-13 23:13:26 +00:00
|
|
|
warnprintf("bad identifier: %s", a)
|
2012-04-29 20:54:06 +00:00
|
|
|
g_badids[a] = true
|
|
|
|
end
|
2012-06-10 18:56:21 +00:00
|
|
|
return true
|
2012-04-29 20:54:06 +00:00
|
|
|
end
|
|
|
|
return lpeg.Cmt(Pat(pat), tfunc)
|
|
|
|
end
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
-- These are tracers for specific patterns which can be disabled
|
|
|
|
-- if desired.
|
2012-04-29 20:54:06 +00:00
|
|
|
local function Keyw(kwname) return TraceFunc(kwname, "kw", false) end
|
2013-03-03 16:06:16 +00:00
|
|
|
--local function NotKeyw(text) return TraceFunc(text, "!kw", false) end
|
2013-02-28 17:29:58 +00:00
|
|
|
--local function Ident(idname) return TraceFunc(idname, "id", false) end
|
2012-04-29 20:54:06 +00:00
|
|
|
local function Stmt(cmdpat) return TraceFunc(cmdpat, "st", false) end
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-05-13 16:04:45 +00:00
|
|
|
--local function Temp(kwname) return TraceFunc(kwname, "temp", true) end
|
2013-01-13 16:40:26 +00:00
|
|
|
--Cinner["myosx"] = Temp(Cinner["myosx"])
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-04-22 19:10:46 +00:00
|
|
|
----==== Translator continued ====----
|
2013-03-03 16:06:16 +00:00
|
|
|
local function attachlinenum(capts, pos)
|
|
|
|
capts[1] = capts[1].."--"..getlinecol(pos)
|
|
|
|
return capts[1]
|
|
|
|
end
|
2012-07-01 22:11:17 +00:00
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
local function after_inner_cmd_Cmt(subj, pos, ...)
|
2012-07-01 22:11:17 +00:00
|
|
|
if (g_numerrors == inf) then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
local capts = {...}
|
2013-03-17 18:11:44 +00:00
|
|
|
assert(type(capts[1])=="string" and capts[2]==nil)
|
|
|
|
return true, attachlinenum(capts, pos)
|
2012-11-30 18:57:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function after_if_cmd_Cmt(subj, pos, ...)
|
|
|
|
if (g_numerrors == inf) then
|
|
|
|
return nil
|
|
|
|
end
|
2013-01-19 18:28:40 +00:00
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
local capts = {...}
|
2013-03-17 18:11:44 +00:00
|
|
|
assert(capts[1] ~= nil)
|
|
|
|
assert(#capts <= 3)
|
2013-03-24 18:53:06 +00:00
|
|
|
|
|
|
|
for i=#capts,1, -1 do
|
|
|
|
assert(type(capts[i])=="string" or type(capts[i])=="table")
|
2012-07-01 22:11:17 +00:00
|
|
|
end
|
2013-01-19 18:28:40 +00:00
|
|
|
|
2013-03-24 18:53:06 +00:00
|
|
|
-- IF_LINE_NUMBERING
|
|
|
|
local firstistab = (type(capts[1])=="table")
|
|
|
|
attachlinenum(firstistab and capts[1] or capts, pos)
|
|
|
|
|
2013-03-17 18:11:44 +00:00
|
|
|
return true, unpack(capts)
|
2012-07-01 22:11:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function after_cmd_Cmt(subj, pos, ...)
|
2012-06-10 18:56:21 +00:00
|
|
|
if (g_numerrors == inf) then
|
|
|
|
-- print("Aborting parsing...")
|
|
|
|
return nil -- make the match fail, bail out of parsing
|
|
|
|
end
|
|
|
|
|
|
|
|
return true -- don't return any captures
|
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
-- Attach the command names at the front!
|
2012-11-30 18:57:46 +00:00
|
|
|
local function attachnames(kwtab, matchtimefunc)
|
2012-04-07 20:10:03 +00:00
|
|
|
for cmdname,cmdpat in pairs(kwtab) do
|
2013-02-21 18:54:02 +00:00
|
|
|
-- The match-time function capture at the end is so that every command
|
|
|
|
-- acts as a barrier to captures to delay (but not fully prevent) stack
|
|
|
|
-- overflow (and to make lpeg.match return a subject position at the
|
|
|
|
-- end)
|
2013-02-28 17:29:58 +00:00
|
|
|
local newpat = Keyw(cmdname) * cmdpat
|
|
|
|
if (cmdname~="break") then
|
|
|
|
kwtab[cmdname] = lpeg.Cmt(newpat, matchtimefunc)
|
|
|
|
else
|
|
|
|
-- Must not attack a Cmt to "break" because it would break the
|
|
|
|
-- while/switch sequencing.
|
|
|
|
kwtab[cmdname] = newpat
|
|
|
|
end
|
2012-04-07 20:10:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
attachnames(Couter, after_cmd_Cmt)
|
|
|
|
attachnames(Cinner, after_inner_cmd_Cmt)
|
2012-11-30 18:57:46 +00:00
|
|
|
attachnames(Cif, after_if_cmd_Cmt)
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
|
2012-06-17 19:45:37 +00:00
|
|
|
-- Takes one or more tables and +'s all its patterns together in reverse
|
|
|
|
-- lexicographical order.
|
|
|
|
-- Each such PATTAB must be a table that maps command names to their patterns.
|
2012-04-22 19:10:46 +00:00
|
|
|
local function all_alt_pattern(...)
|
2012-06-17 19:45:37 +00:00
|
|
|
local cmds = {}
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
local args = {...}
|
2012-06-17 19:45:37 +00:00
|
|
|
assert(#args <= 2)
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
for argi=1,#args do
|
|
|
|
local pattab = args[argi]
|
2012-06-17 19:45:37 +00:00
|
|
|
|
|
|
|
-- pairs() iterates in undefined order, so we first fill in the names...
|
|
|
|
for cmdname,_ in pairs(pattab) do
|
|
|
|
cmds[#cmds+1] = cmdname
|
2012-04-07 20:10:03 +00:00
|
|
|
end
|
|
|
|
end
|
2012-06-17 19:45:37 +00:00
|
|
|
|
|
|
|
-- ...and then sort them in ascending lexicographical order
|
|
|
|
table.sort(cmds)
|
|
|
|
|
|
|
|
local pat = Pat(false)
|
|
|
|
|
|
|
|
for i=1,#cmds do
|
|
|
|
local ourpat = args[1][cmds[i]] or args[2][cmds[i]]
|
|
|
|
-- shorter commands go at the end!
|
|
|
|
pat = pat + ourpat
|
|
|
|
end
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
return pat
|
|
|
|
end
|
|
|
|
|
|
|
|
-- actor ORGANTIC is greeting!
|
2013-03-15 16:55:59 +00:00
|
|
|
function on.lonely_else(pos)
|
2012-07-01 22:11:17 +00:00
|
|
|
pwarnprintf(pos, "found `else' with no `if'")
|
2012-06-22 21:40:01 +00:00
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
local con_inner_command = all_alt_pattern(Cinner)
|
2012-06-17 19:45:37 +00:00
|
|
|
local con_if_begs = all_alt_pattern(Cif)
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-03-15 16:55:59 +00:00
|
|
|
local lone_else = (POS() * "else" * sp1)/on.lonely_else
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
local stmt_list = Var("stmt_list")
|
|
|
|
-- possibly empty statement list:
|
2012-07-01 22:11:17 +00:00
|
|
|
local stmt_list_or_eps = lpeg.Ct((stmt_list * sp1)^-1)
|
2013-02-21 18:54:02 +00:00
|
|
|
local stmt_list_nosp_or_eps = lpeg.Ct((stmt_list * (sp1 * stmt_list)^0)^-1)
|
|
|
|
|
|
|
|
-- Reused LPeg patterns
|
|
|
|
local common = {}
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-06-17 19:45:43 +00:00
|
|
|
-- common to actor and useractor: <name/tilenum> [<strength> [<action> [<move> [<flags>... ]]]]
|
2013-02-21 18:54:02 +00:00
|
|
|
common.actor_end = sp1 * lpeg.Ct(tok.define *
|
2013-01-13 16:40:26 +00:00
|
|
|
(sp1 * tok.define *
|
|
|
|
(sp1 * tok.action *
|
|
|
|
(sp1 * tok.move *
|
|
|
|
(sp1 * tok.define)^0
|
2012-06-17 19:45:43 +00:00
|
|
|
)^-1
|
|
|
|
)^-1
|
2012-06-22 21:40:01 +00:00
|
|
|
)^-1)
|
2012-07-01 22:11:17 +00:00
|
|
|
* sp1 * stmt_list_or_eps * "enda"
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
common.block_begin = lpeg.Cc(nil) / function()
|
|
|
|
g_switchCode = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
common.block_end = lpeg.Cc(nil) / function()
|
|
|
|
if (#g_switchCode > 0) then
|
|
|
|
addcode(g_switchCode)
|
|
|
|
end
|
|
|
|
g_switchCode = nil
|
|
|
|
end
|
|
|
|
|
2013-01-19 18:28:55 +00:00
|
|
|
--== block delimiters (no syntactic recursion) ==--
|
2013-01-13 16:40:26 +00:00
|
|
|
local Cblock = {
|
2012-04-07 20:10:03 +00:00
|
|
|
-- actor (...)
|
2013-03-24 18:55:27 +00:00
|
|
|
actor = POS() * lpeg.Cc(nil) * common.actor_end / on.actor_end,
|
2012-04-07 20:10:03 +00:00
|
|
|
-- useractor <actortype> (...)
|
2013-03-24 18:55:27 +00:00
|
|
|
useractor = POS() * sp1 * tok.define * common.actor_end / on.actor_end,
|
2012-06-22 21:40:01 +00:00
|
|
|
-- eventloadactor <name/tilenum>
|
2013-03-24 18:55:27 +00:00
|
|
|
eventloadactor = POS() * sp1 * tok.define * sp1 * stmt_list_or_eps * "enda"
|
2013-02-21 18:54:13 +00:00
|
|
|
/ on.eventloadactor_end,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
onevent = POS() * sp1 * tok.define * sp1 * stmt_list_or_eps * "endevent"
|
2013-02-21 18:54:02 +00:00
|
|
|
/ on.event_end,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-03-24 18:55:27 +00:00
|
|
|
state = POS() * sp1 * (lpeg.Cmt(tok.identifier, on.state_begin_Cmt))
|
|
|
|
* sp1 * stmt_list_or_eps * tok.state_ends
|
2013-02-21 18:54:02 +00:00
|
|
|
/ on.state_end,
|
2012-04-07 20:10:03 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
for cmdname, cmdpat in pairs(Cblock) do
|
|
|
|
Cblock[cmdname] = common.block_begin * cmdpat * common.block_end
|
|
|
|
end
|
|
|
|
|
2013-01-13 16:40:26 +00:00
|
|
|
attachnames(Cblock, after_cmd_Cmt)
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
|
2012-04-29 20:54:06 +00:00
|
|
|
local t_good_identifier = Range("AZ", "az", "__") * Range("AZ", "az", "__", "09")^0
|
|
|
|
|
|
|
|
-- CON isaltok also has chars in "{}.", but these could potentially
|
2012-11-30 18:57:40 +00:00
|
|
|
-- interfere with *CON* syntax. The "]" is so that the number in e.g. array[80]
|
2012-04-29 20:54:06 +00:00
|
|
|
-- isn't considered a broken identifier.
|
|
|
|
-- "-" is somewhat problematic, but we allow it only as 2nd and up character, so
|
|
|
|
-- there's no ambiguity with unary minus. (Commands must be separated by spaces
|
|
|
|
-- in CON, so a trailing "-" is "OK", too.)
|
|
|
|
-- This is broken in itself, so we ought to make a compatibility/modern CON switch.
|
2013-01-13 16:40:26 +00:00
|
|
|
local t_broken_identifier = BadIdent(-((tok.number + t_good_identifier) * (sp1 + Set("[]:"))) *
|
2013-01-05 13:09:31 +00:00
|
|
|
(alphanum + Set(BAD_ID_CHARS0)) * (alphanum + Set(BAD_ID_CHARS1))^0)
|
2012-04-29 20:54:06 +00:00
|
|
|
|
2013-03-17 18:11:44 +00:00
|
|
|
---
|
|
|
|
local function do_flatten_codetab(code, intotab)
|
|
|
|
for i=1,math.huge do
|
|
|
|
local elt = code[i]
|
|
|
|
|
|
|
|
if (type(elt)=="string") then
|
|
|
|
intotab[#intotab+1] = elt
|
|
|
|
elseif (type(elt)=="table") then
|
|
|
|
do_flatten_codetab(elt, intotab)
|
|
|
|
else
|
|
|
|
assert(elt==nil)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Return a "string buffer" table that can be table.concat'ed
|
|
|
|
-- to get the code string.
|
|
|
|
local function flatten_codetab(codetab)
|
|
|
|
local tmpcode = {}
|
|
|
|
do_flatten_codetab(codetab, tmpcode)
|
|
|
|
return tmpcode
|
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
function on.if_else_end(ifconds, ifstmt, elsestmt, ...)
|
|
|
|
assert(#{...}==0)
|
|
|
|
assert(type(ifconds)=="table" and #ifconds>=1)
|
|
|
|
|
|
|
|
-- A condition may be a table carrying "deferred" code to add either
|
|
|
|
-- [1] after the 'if' or
|
|
|
|
-- [2] after the whole if/else block.
|
|
|
|
-- In CON, it's always the same code for the same kind of "deferedness",
|
|
|
|
-- and it's always idempotent (executing it multiple times has the same
|
|
|
|
-- effect as executing it once), so generate code for it only once, too.
|
|
|
|
local deferred = { nil, nil }
|
2013-03-24 18:53:06 +00:00
|
|
|
local linenum = ""
|
2013-03-03 16:06:12 +00:00
|
|
|
|
|
|
|
local ifcondstr = {}
|
|
|
|
for i=1,#ifconds do
|
|
|
|
local cond = ifconds[i]
|
|
|
|
local hasmore = type(cond=="table")
|
|
|
|
|
|
|
|
ifcondstr[i] = hasmore and cond[1] or cond
|
|
|
|
assert(type(ifcondstr[i])=="string")
|
|
|
|
|
2013-03-24 18:53:06 +00:00
|
|
|
-- IF_LINE_NUMBERING
|
|
|
|
local tlinum = assert(ifcondstr[i]:match("^.*(%-%-[0-9]+)$"))
|
|
|
|
ifcondstr[i] = assert(ifcondstr[i]:match("^(.*)%-%-[0-9]+$"))
|
|
|
|
if (linenum == "") then
|
|
|
|
linenum = tlinum
|
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
if (hasmore) then
|
|
|
|
for i=1,2 do
|
|
|
|
if (deferred[i]==nil) then
|
|
|
|
deferred[i] = cond[i+1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-01-02 22:33:37 +00:00
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
-- Construct a string of ANDed conditions
|
|
|
|
local conds = "(" .. table.concat(ifcondstr, ")and(") .. ")"
|
2013-01-01 15:24:28 +00:00
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
local code = {
|
2013-03-24 18:53:06 +00:00
|
|
|
format("if %s then%s", conds, linenum),
|
2013-03-17 18:11:44 +00:00
|
|
|
assert(ifstmt),
|
2013-03-03 16:06:12 +00:00
|
|
|
}
|
2013-01-02 22:33:37 +00:00
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
code[#code+1] = deferred[1]
|
2013-01-01 15:24:28 +00:00
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
if (elsestmt~=nil) then
|
2013-03-17 18:11:44 +00:00
|
|
|
local elseifp = false
|
|
|
|
|
|
|
|
if (type(elsestmt)=="table") then
|
|
|
|
elsestmt = flatten_codetab(elsestmt)
|
|
|
|
|
|
|
|
if (#elsestmt>=2 and elsestmt[1]:match("^if ") and elsestmt[#elsestmt]=="end") then
|
|
|
|
elsestmt[1] = elsestmt[1]:sub(4)
|
|
|
|
elsestmt[#elsestmt] = nil
|
|
|
|
elseifp = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
code[#code+1] = elseifp and "elseif" or "else"
|
2013-03-03 16:06:12 +00:00
|
|
|
code[#code+1] = elsestmt
|
2013-01-01 15:24:28 +00:00
|
|
|
end
|
2012-06-13 23:13:26 +00:00
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
code[#code+1] = "end"
|
|
|
|
code[#code+1] = deferred[2]
|
|
|
|
|
|
|
|
return code
|
2013-01-02 22:33:37 +00:00
|
|
|
end
|
|
|
|
|
2013-02-28 17:29:58 +00:00
|
|
|
function on.while_begin(v1, v2)
|
|
|
|
table.insert(g_isWhile, true)
|
|
|
|
return format("while (%s~=%s) do", v1, v2)
|
|
|
|
end
|
|
|
|
|
|
|
|
function on.while_end()
|
2013-02-28 17:30:15 +00:00
|
|
|
local whilenum = #g_isWhile
|
2013-02-28 17:29:58 +00:00
|
|
|
table.remove(g_isWhile)
|
2013-02-28 17:30:15 +00:00
|
|
|
return format("::l%d:: end", whilenum)
|
2013-02-28 17:29:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function on.switch_begin()
|
|
|
|
table.insert(g_isWhile, false)
|
|
|
|
end
|
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
function on.switch_end(testvar, blocks)
|
|
|
|
local SW = format("_SW[%d]", g_switchCount)
|
|
|
|
local swcode = { format("%s={", SW) }
|
|
|
|
local have = {}
|
|
|
|
local havedefault = false
|
|
|
|
|
2013-02-28 17:29:58 +00:00
|
|
|
table.remove(g_isWhile)
|
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
for i=1,#blocks do
|
|
|
|
local block = blocks[i]
|
|
|
|
assert(#block >= 1)
|
|
|
|
local isdefault = (#block==1)
|
|
|
|
local index = isdefault and "'default'" or tostring(block[1])
|
|
|
|
|
|
|
|
if (have[index]) then
|
|
|
|
if (isdefault) then
|
|
|
|
errprintf("duplicate 'default' block in switch statement")
|
|
|
|
return "_INVALIDSW()"
|
|
|
|
else
|
|
|
|
warnprintf("duplicate case %s in switch statement", index)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
have[index] = true
|
|
|
|
|
|
|
|
swcode[#swcode+1] = format("[%s]=function(_aci,_pli,_dist)", index)
|
2013-03-15 16:56:07 +00:00
|
|
|
swcode[#swcode+1] = get_cache_sap_code()
|
2013-02-21 18:54:02 +00:00
|
|
|
-- insert the case/default code:
|
|
|
|
swcode[#swcode+1] = block[#block]
|
|
|
|
swcode[#swcode+1] = "end,"
|
|
|
|
end
|
|
|
|
|
|
|
|
swcode[#swcode+1] = "}"
|
|
|
|
|
|
|
|
-- insert additional case test numbers (e.g. case 0: >>> case 1 <<<: <code...>)
|
|
|
|
for i=1,#blocks do
|
|
|
|
local block = blocks[i]
|
|
|
|
for j=2,#block-1 do
|
|
|
|
local index = tostring(block[j])
|
|
|
|
swcode[#swcode+1] = format("%s[%d]=%s[%d]", SW, index, SW, tostring(block[1]))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert(g_switchCode ~= nil)
|
|
|
|
g_switchCode[#g_switchCode+1] = swcode
|
|
|
|
|
|
|
|
-- The code for the switch statement itself:
|
|
|
|
local code = format("_con._switch(_SW[%d], %s, _aci,_pli,_dist)", g_switchCount, testvar)
|
|
|
|
g_switchCount = g_switchCount+1
|
|
|
|
return code
|
|
|
|
end
|
|
|
|
|
2012-06-13 23:13:26 +00:00
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
--- The final grammar!
|
|
|
|
local Grammar = Pat{
|
|
|
|
-- The starting symbol.
|
|
|
|
-- A translation unit is a (possibly empty) sequence of outer CON
|
|
|
|
-- commands, separated by at least one whitespace which may be
|
|
|
|
-- omitted at the EOF.
|
2013-01-13 16:40:26 +00:00
|
|
|
sp0 * (all_alt_pattern(Couter, Cblock) * sp1)^0,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-06-10 18:56:18 +00:00
|
|
|
-- Some often-used terminals follow. These appear here because we're
|
|
|
|
-- hitting a limit with LPeg else.
|
2012-04-07 20:10:03 +00:00
|
|
|
-- http://lua-users.org/lists/lua-l/2008-11/msg00462.html
|
2012-12-28 17:18:02 +00:00
|
|
|
|
2012-05-13 16:04:45 +00:00
|
|
|
-- NOTE: NW demo (NWSNOW.CON) contains a Ctrl-Z char (decimal 26)
|
2012-04-29 20:54:06 +00:00
|
|
|
whitespace = Set(" \t\r\26") + newline + Set("(),;") + comment + linecomment,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-13 16:40:21 +00:00
|
|
|
t_number = POS() * lpeg.C(
|
2013-01-13 16:40:26 +00:00
|
|
|
tok.maybe_minus * ((Pat("0x") + "0X") * Range("09", "af", "AF")^1 * Pat("h")^-1
|
2013-03-17 18:11:53 +00:00
|
|
|
+ Range("09")^1)
|
2013-01-13 16:40:21 +00:00
|
|
|
) / parse_number,
|
|
|
|
|
2013-01-24 20:03:06 +00:00
|
|
|
t_identifier_all = lpeg.C(t_broken_identifier + t_good_identifier),
|
2012-11-30 18:57:40 +00:00
|
|
|
-- NOTE: -conl.keyword alone would be wrong, e.g. "state breakobject":
|
2012-04-07 20:10:03 +00:00
|
|
|
-- NOTE 2: The + "[" is so that stuff like
|
|
|
|
-- getactor[THISACTOR].x x
|
|
|
|
-- getactor[THISACTOR].y y
|
|
|
|
-- is parsed correctly. (Compared with this:)
|
|
|
|
-- getactor[THISACTOR].x x
|
|
|
|
-- getactor [THISACTOR].y y
|
|
|
|
-- This is in need of cleanup!
|
2013-03-03 16:06:16 +00:00
|
|
|
t_identifier = -(conl.keyword * (sp1 + "[")) * tok.identifier_all,
|
2013-01-24 20:03:02 +00:00
|
|
|
-- TODO?: SST TC has e.g. "1267AT", relying on it to be parsed as a number "1267".
|
|
|
|
-- However, this conflicts with bad-identifiers, so it should be checked last.
|
|
|
|
-- This would also handle LNGA2's "00000000h", though would give problems with
|
|
|
|
-- e.g. "800h" (hex 0x800 or decimal 800?).
|
2013-01-24 20:03:10 +00:00
|
|
|
t_define = (POS() * lpeg.C(tok.maybe_minus) * tok.identifier / lookup.defined_label) + tok.number,
|
2013-06-02 14:07:52 +00:00
|
|
|
-- A defined label token, but returning the label if one was passed
|
|
|
|
-- (specially shoehorned into a string):
|
|
|
|
t_rawdefine = (POS() * lpeg.C(tok.maybe_minus) * tok.identifier / lookup.raw_defined_label) + tok.number,
|
2012-07-01 22:11:17 +00:00
|
|
|
|
2013-01-13 16:40:21 +00:00
|
|
|
-- Defines and constants can take the place of vars that are only read.
|
2013-01-13 16:40:26 +00:00
|
|
|
-- XXX: now, when tok.rvar fails, the tok.define failure message is printed.
|
2013-01-24 20:03:10 +00:00
|
|
|
t_rvar = Var("t_botharrayexp") + lpeg.Cmt(tok.identifier, maybe_gamevar_Cmt) + tok.define,
|
2013-01-24 20:03:06 +00:00
|
|
|
-- For written-to vars, only (non-parm2) array exprs and writable gamevars
|
|
|
|
-- are permitted. NOTE: C-CON doesn't support inline array exprs here.
|
|
|
|
t_wvar = Var("t_singlearrayexp") / function() errprintf("t_wvar: array exprs NYI") return "_NYIVAR" end
|
2013-02-10 16:23:59 +00:00
|
|
|
+ (tok.identifier / function(id) return lookup.gamevar(id, "_aci", true) end),
|
2013-01-13 16:40:21 +00:00
|
|
|
|
2013-02-18 16:07:48 +00:00
|
|
|
t_gamearray = Var("t_identifier") / lookup.gamearray,
|
|
|
|
|
2012-07-01 22:11:17 +00:00
|
|
|
t_move =
|
2013-01-24 20:03:10 +00:00
|
|
|
POS()*tok.identifier / function(...) return lookup.composite(LABEL.MOVE, ...) end +
|
2013-11-12 21:03:20 +00:00
|
|
|
POS()*tok.number / function(...) return check.composite_literal(LABEL.MOVE, ...) end,
|
2012-07-01 22:11:17 +00:00
|
|
|
|
|
|
|
t_ai =
|
2013-01-24 20:03:10 +00:00
|
|
|
POS()*tok.identifier / function(...) return lookup.composite(LABEL.AI, ...) end +
|
2013-11-12 21:03:20 +00:00
|
|
|
POS()*tok.number / function(...) return check.composite_literal(LABEL.AI, ...) end,
|
2012-06-17 19:45:43 +00:00
|
|
|
|
2012-07-01 22:11:17 +00:00
|
|
|
t_action =
|
2013-01-24 20:03:10 +00:00
|
|
|
POS()*tok.identifier / function(...) return lookup.composite(LABEL.ACTION, ...) end +
|
2013-11-12 21:03:20 +00:00
|
|
|
POS()*tok.number / function(...) return check.composite_literal(LABEL.ACTION, ...) end,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-01-24 20:03:06 +00:00
|
|
|
-- New-style inline arrays and structures.
|
2013-06-07 10:18:12 +00:00
|
|
|
t_botharrayexp = tok.identifier * arraypat * patt.bothmember^-1
|
2013-01-24 20:03:10 +00:00
|
|
|
/ function(...) return lookup.array_expr(false, ...) end,
|
2013-06-07 10:18:12 +00:00
|
|
|
t_singlearrayexp = tok.identifier * arraypat * patt.singlemember^-1,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-04-29 20:54:06 +00:00
|
|
|
-- SWITCH
|
2013-02-28 17:29:58 +00:00
|
|
|
switch_stmt = Keyw("switch") * sp1 * tok.rvar * (lpeg.Cc(nil)/on.switch_begin) *
|
2013-02-21 18:54:02 +00:00
|
|
|
lpeg.Ct((Var("case_block") + Var("default_block"))^0) * sp1 * "endswitch"
|
|
|
|
/ on.switch_end,
|
2012-04-29 20:54:06 +00:00
|
|
|
|
|
|
|
-- NOTE: some old DNWMD has "case: PIGCOP". I don't think I'll allow that.
|
2013-02-21 18:54:02 +00:00
|
|
|
case_block = lpeg.Ct((sp1 * Keyw("case") * sp1 * tok.define * (sp0*":")^-1)^1 * sp1 *
|
|
|
|
stmt_list_nosp_or_eps), -- * "break",
|
2012-04-29 20:54:06 +00:00
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
default_block = lpeg.Ct(sp1 * Keyw("default") * (sp0*":"*sp0 + sp1) *
|
|
|
|
stmt_list_nosp_or_eps), -- * "break",
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-03-03 16:06:12 +00:00
|
|
|
if_stmt = lpeg.Ct((con_if_begs * sp1)^1) * Var("single_stmt")
|
|
|
|
* (sp1 * Keyw("else") * sp1 * Var("single_stmt"))^-1 / on.if_else_end,
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-28 17:29:58 +00:00
|
|
|
while_stmt = Keyw("whilevarvarn") * sp1 * tok.rvar * sp1 * tok.rvar / on.while_begin
|
|
|
|
* sp1 * Var("single_stmt") * (lpeg.Cc(nil) / on.while_end)
|
|
|
|
+ Keyw("whilevarn") * sp1 * tok.rvar * sp1 * tok.define / on.while_begin
|
|
|
|
* sp1 * Var("single_stmt") * (lpeg.Cc(nil) / on.while_end),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-03-17 18:11:53 +00:00
|
|
|
stmt_common = Keyw("{") * sp1 * "}" / "" -- space separation of commands in CON is for a reason!
|
2013-06-30 20:38:39 +00:00
|
|
|
-- XXX: this do...end can lead to exceeding Lua nesting limits, see nightstrike's tan.con
|
2013-06-01 20:09:37 +00:00
|
|
|
+ lpeg.Ct(Keyw("{")/"do" * sp1 * stmt_list * sp1 * (Keyw("}")/"end"))
|
2013-03-03 16:06:12 +00:00
|
|
|
+ con_inner_command + Var("switch_stmt") + lpeg.Ct(Var("while_stmt")),
|
2013-01-05 13:09:25 +00:00
|
|
|
|
|
|
|
single_stmt = Stmt( lone_else^-1 * (Var("stmt_common") + Var("if_stmt")) ),
|
2012-04-07 20:10:03 +00:00
|
|
|
|
|
|
|
-- a non-empty statement/command list
|
|
|
|
stmt_list = Var("single_stmt") * (sp1 * Var("single_stmt"))^0,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 19:10:46 +00:00
|
|
|
local function setup_newlineidxs(contents)
|
2012-06-10 18:56:21 +00:00
|
|
|
local newlineidxs = {}
|
2012-04-22 19:10:46 +00:00
|
|
|
for i in string.gmatch(contents, "()\n") do
|
|
|
|
newlineidxs[#newlineidxs+1] = i
|
2012-04-07 20:10:03 +00:00
|
|
|
end
|
2012-05-13 16:04:45 +00:00
|
|
|
if (#newlineidxs == 0) then
|
|
|
|
-- try CR only (old Mac)
|
|
|
|
for i in string.gmatch(contents, "()\r") do
|
|
|
|
newlineidxs[#newlineidxs+1] = i
|
|
|
|
end
|
|
|
|
-- if (#newlineidxs > 0) then print('CR-only lineends detected.') end
|
|
|
|
end
|
2012-04-29 20:54:06 +00:00
|
|
|
-- dummy newlines at beginning and end
|
|
|
|
newlineidxs[#newlineidxs+1] = #contents+1
|
|
|
|
newlineidxs[0] = 0
|
2012-06-10 18:56:21 +00:00
|
|
|
|
|
|
|
return newlineidxs
|
2012-04-07 20:10:03 +00:00
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
|
|
|
|
--== Lua -> CON line number mapping for error messages ==--
|
|
|
|
|
|
|
|
local lineinfo_mt = {
|
|
|
|
__index = {
|
|
|
|
-- Get CON file name and CON line number from Lua line number.
|
|
|
|
getfline = function(self, lualine)
|
|
|
|
local llines, lfiles = self.llines, self.lfiles
|
|
|
|
assert(lualine >= 1 and lualine <= #llines)
|
|
|
|
|
|
|
|
-- Get the CON line number: a simple lookup.
|
|
|
|
local conline = llines[lualine]
|
|
|
|
|
|
|
|
-- Find the CON file name next.
|
|
|
|
local confile = nil
|
|
|
|
for i=1,#lfiles do
|
|
|
|
if (lfiles[i].line > lualine) then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
-- Shorten the file name by stripping the directory parts.
|
|
|
|
confile = lfiles[i].name:match("[^/]+$")
|
|
|
|
end
|
|
|
|
|
|
|
|
return confile or "???", conline
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
|
|
|
|
__metatable = true,
|
|
|
|
}
|
|
|
|
|
2013-05-19 19:29:21 +00:00
|
|
|
-- Handle a line of translated CON->Lua code. Return its CON line number.
|
|
|
|
local function lineinfo_handle_line(i, code, curline, curfile, lfiles)
|
|
|
|
local lnumstr = code:match("%-%-([0-9]+)$")
|
|
|
|
local begfn = lnumstr and nil or code:match("^%-%- BEGIN (.+)$")
|
|
|
|
local endfn = lnumstr and nil or code:match("^%-%- END (.+)$")
|
|
|
|
|
|
|
|
if (lnumstr) then
|
|
|
|
curline[#curline] = assert(tonumber(lnumstr))
|
|
|
|
elseif (begfn) then
|
|
|
|
curfile[#curfile+1] = begfn
|
|
|
|
curline[#curline+1] = 1
|
|
|
|
-- Begin an included file.
|
|
|
|
lfiles[#lfiles+1] = { line=i, name=begfn }
|
|
|
|
elseif (endfn) then
|
|
|
|
assert(endfn==curfile[#curfile]) -- assert proper nesting
|
|
|
|
curfile[#curfile] = nil
|
|
|
|
curline[#curline] = nil
|
|
|
|
-- End an included file, so reset the name to the includer's one.
|
|
|
|
lfiles[#lfiles+1] = { line=i, name=curfile[#curfile] }
|
|
|
|
end
|
|
|
|
|
|
|
|
return assert(curline[#curline])
|
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
-- Construct Lua->CON line mapping info. This walks the generated code and
|
|
|
|
-- looks for our inserted comment strings, so it's kind of hackish.
|
2013-05-19 19:29:21 +00:00
|
|
|
function get_lineinfo(flatcode)
|
2013-03-03 16:06:16 +00:00
|
|
|
local curline, curfile = { 0 }, { "<none>" } -- stacks
|
|
|
|
-- llines: [<Lua code line number>] = <CON code line number>
|
|
|
|
-- lfiles: [<sequence number>] = { line=<Lua line number>, name=<filename> }
|
|
|
|
local llines, lfiles = {}, {}
|
|
|
|
|
2013-05-19 19:29:21 +00:00
|
|
|
if (type(flatcode)=="table") then
|
|
|
|
for i=1,#flatcode do
|
|
|
|
llines[i] = lineinfo_handle_line(i, flatcode[i], curline, curfile, lfiles)
|
2013-03-03 16:06:16 +00:00
|
|
|
end
|
2013-05-19 19:29:21 +00:00
|
|
|
else
|
|
|
|
-- Already concat'ed code given.
|
|
|
|
assert(type(flatcode)=="string")
|
|
|
|
local olinestart = 1
|
|
|
|
|
|
|
|
for i=1,math.huge do
|
|
|
|
local curnli = flatcode:find("\n", olinestart, true)
|
|
|
|
local line
|
2013-03-03 16:06:16 +00:00
|
|
|
|
2013-05-19 19:29:21 +00:00
|
|
|
if (curnli ~= nil) then
|
|
|
|
line = flatcode:sub(olinestart, curnli-1)
|
|
|
|
olinestart = curnli+1
|
|
|
|
else
|
|
|
|
-- Last line
|
|
|
|
line = flatcode:sub(olinestart, -1)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
llines[i] = lineinfo_handle_line(i, line, curline, curfile, lfiles)
|
|
|
|
end
|
2013-03-03 16:06:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable({ llines=llines, lfiles=lfiles }, lineinfo_mt)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- <lineinfop>: Get line info?
|
|
|
|
local function get_code_string(codetab, lineinfop)
|
2013-11-08 18:08:37 +00:00
|
|
|
-- Create meta-info gamevar: which gamevars have bit NORESET set?
|
|
|
|
codetab[#codetab+1] = "_V._IS_NORESET_GAMEVAR={"
|
|
|
|
for identifier, gv in pairs(g_gamevar) do
|
|
|
|
if (bit.band(gv.flags, GVFLAG.NORESET) ~= 0) then
|
|
|
|
codetab[#codetab+1] = format("[%q]=true,", identifier)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
codetab[#codetab+1] = "}"
|
|
|
|
|
2013-06-12 17:49:47 +00:00
|
|
|
-- Return defined labels in a table...
|
2013-06-20 18:31:47 +00:00
|
|
|
codetab[#codetab+1] = "return {"
|
2013-06-12 17:49:47 +00:00
|
|
|
for label, val in pairs(g_labeldef) do
|
|
|
|
-- ... skipping 'NO' and those that are gamevars in C-CON.
|
|
|
|
if (g_labeltype[label]==LABEL.NUMBER and not g_labelspecial[label]) then
|
|
|
|
codetab[#codetab+1] = format("[%q]=%d,", label, val)
|
|
|
|
end
|
|
|
|
end
|
2013-06-30 20:38:41 +00:00
|
|
|
codetab[#codetab+1] = "},_C,_M,_I" -- CONCODE_RETURN
|
2013-06-12 17:49:47 +00:00
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
local flatcode = flatten_codetab(codetab)
|
|
|
|
local lineinfo = lineinfop and get_lineinfo(flatcode)
|
|
|
|
return table.concat(flatcode, "\n"), lineinfo
|
2012-12-29 15:21:24 +00:00
|
|
|
end
|
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
function on.parse_begin()
|
2013-02-28 17:29:58 +00:00
|
|
|
g_isWhile = {}
|
2013-01-13 16:40:21 +00:00
|
|
|
g_have_file[g_filename] = true
|
|
|
|
|
|
|
|
-- set up new state
|
|
|
|
-- TODO: pack into one "parser state" table?
|
|
|
|
g_lastkw, g_lastkwpos, g_numerrors = nil, nil, 0
|
|
|
|
g_recurslevel = g_recurslevel+1
|
|
|
|
end
|
|
|
|
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-05-13 16:05:16 +00:00
|
|
|
---=== EXPORTED FUNCTIONS ===---
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-06-10 18:56:21 +00:00
|
|
|
function parse(contents) -- local
|
|
|
|
-- save outer state
|
|
|
|
local lastkw, lastkwpos, numerrors = g_lastkw, g_lastkwpos, g_numerrors
|
|
|
|
local newlineidxs = g_newlineidxs
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2013-02-21 18:54:02 +00:00
|
|
|
on.parse_begin()
|
2012-06-13 23:13:26 +00:00
|
|
|
|
2012-06-10 18:56:21 +00:00
|
|
|
g_newlineidxs = setup_newlineidxs(contents)
|
|
|
|
|
2012-12-28 17:18:06 +00:00
|
|
|
addcodef("-- BEGIN %s", g_filename)
|
|
|
|
|
2012-05-13 16:05:16 +00:00
|
|
|
local idx = lpeg.match(Grammar, contents)
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-05-13 16:05:16 +00:00
|
|
|
if (not idx) then
|
2012-06-10 18:56:21 +00:00
|
|
|
printf("[%d] Match failed.", g_recurslevel)
|
2012-06-17 19:45:37 +00:00
|
|
|
g_numerrors = inf
|
2012-05-13 16:05:16 +00:00
|
|
|
elseif (idx == #contents+1) then
|
2012-06-10 18:56:21 +00:00
|
|
|
if (g_numerrors ~= 0) then
|
|
|
|
printf("[%d] Matched whole contents (%d errors).",
|
|
|
|
g_recurslevel, g_numerrors)
|
|
|
|
elseif (g_recurslevel==0) then
|
2012-12-28 17:18:06 +00:00
|
|
|
printf("[0] Matched whole contents.")
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
2012-05-13 16:05:16 +00:00
|
|
|
else
|
|
|
|
local i, col = getlinecol(idx)
|
2012-06-10 18:56:21 +00:00
|
|
|
local bi, ei = g_newlineidxs[i-1]+1, g_newlineidxs[i]-1
|
2012-04-07 20:10:03 +00:00
|
|
|
|
2012-12-28 17:18:06 +00:00
|
|
|
printf("[%d] Match succeeded up to line %d, col %d (pos=%d, len=%d)",
|
|
|
|
g_recurslevel, i, col, idx, #contents)
|
2012-06-17 19:45:37 +00:00
|
|
|
g_numerrors = inf
|
2012-04-22 19:10:46 +00:00
|
|
|
|
2012-05-13 16:05:16 +00:00
|
|
|
-- printf("Line goes from %d to %d", bi, ei)
|
2012-06-10 18:56:21 +00:00
|
|
|
local suffix = ""
|
|
|
|
if (ei-bi > 76) then
|
|
|
|
ei = bi+76
|
|
|
|
suffix = " (...)"
|
|
|
|
end
|
2012-12-28 17:18:06 +00:00
|
|
|
printf("%s%s", string.sub(contents, bi, ei), suffix)
|
2012-04-22 19:10:46 +00:00
|
|
|
|
2012-05-13 16:05:16 +00:00
|
|
|
if (g_lastkwpos) then
|
|
|
|
i, col = getlinecol(g_lastkwpos)
|
|
|
|
printf("Last keyword was at line %d, col %d: %s", i, col, g_lastkw)
|
2012-04-29 20:54:06 +00:00
|
|
|
end
|
|
|
|
end
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2014-02-08 14:37:47 +00:00
|
|
|
-- Check read/written status of all user gamevars.
|
|
|
|
if (idx == #contents+1 and g_recurslevel==0) then
|
|
|
|
local gvs = {}
|
|
|
|
for identifier, gv in pairs(g_gamevar) do
|
|
|
|
if (gv.used ~= 3) then
|
|
|
|
-- NOTE: read but not written to gamevar (gv.used == 1) has its
|
|
|
|
-- use in C-CON
|
|
|
|
if (gv.used == 0 and g_warn["never-used-gamevar"] or
|
|
|
|
gv.used == 2 and g_warn["never-read-gamevar"]) then
|
|
|
|
gv.id = identifier
|
|
|
|
gvs[#gvs+1] = gv
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function compare_gv(gva, gvb)
|
|
|
|
if (gva.loc[1] ~= gvb.loc[1]) then
|
|
|
|
return gva.loc[1] < gvb.loc[1]
|
|
|
|
end
|
|
|
|
return (gva.loc[2] < gvb.loc[2])
|
|
|
|
end
|
|
|
|
|
|
|
|
table.sort(gvs, compare_gv)
|
|
|
|
|
|
|
|
for i=1,#gvs do
|
|
|
|
local gv = gvs[i]
|
|
|
|
|
|
|
|
local loc = gv.loc
|
|
|
|
local locstr = loc and format("%s %d:%d: ", loc[1], loc[2], loc[3]) or ""
|
|
|
|
|
|
|
|
local perActor = (bit.band(gv.flags, GVFLAG.PERACTOR) ~= 0)
|
|
|
|
local perPlayer = (bit.band(gv.flags, GVFLAG.PERPLAYER) ~= 0)
|
|
|
|
local kindstr = perActor and "per-actor " or (perPlayer and "per-player " or "")
|
|
|
|
|
|
|
|
if (gv.used == 0) then
|
|
|
|
printf("%sWarning: never used %sgamevar `%s'", locstr,
|
|
|
|
kindstr, gv.id)
|
|
|
|
else
|
|
|
|
printf("%sWarning: never %s %sgamevar `%s'", locstr,
|
|
|
|
gv.used == 1 and "written to" or "read",
|
|
|
|
kindstr, gv.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-28 17:18:06 +00:00
|
|
|
addcodef("-- END %s", g_filename)
|
2012-06-10 18:56:21 +00:00
|
|
|
g_recurslevel = g_recurslevel-1
|
|
|
|
|
|
|
|
-- restore outer state
|
|
|
|
g_lastkw, g_lastkwpos = lastkw, lastkwpos
|
2013-02-21 18:54:02 +00:00
|
|
|
g_numerrors = math.max(g_numerrors, numerrors)
|
2012-06-10 18:56:21 +00:00
|
|
|
g_newlineidxs = newlineidxs
|
2012-04-07 20:10:03 +00:00
|
|
|
end
|
2012-05-13 16:05:16 +00:00
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
function reset.all()
|
|
|
|
reset.labels()
|
|
|
|
reset.gamedata()
|
|
|
|
reset.codegen()
|
2012-12-29 15:21:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function print_on_failure(msg)
|
|
|
|
if (g_lastkwpos ~= nil) then
|
|
|
|
printf("LAST KEYWORD POSITION: %s, %s", linecolstr(g_lastkwpos), g_lastkw)
|
|
|
|
end
|
|
|
|
print(msg)
|
|
|
|
end
|
|
|
|
|
2012-12-09 13:24:28 +00:00
|
|
|
if (string.dump) then
|
2012-12-29 15:21:24 +00:00
|
|
|
-- running stand-alone
|
2013-03-03 16:06:28 +00:00
|
|
|
local io = require("io")
|
2012-12-03 18:24:33 +00:00
|
|
|
|
2013-03-03 16:06:28 +00:00
|
|
|
local function compile(filename)
|
2013-11-12 21:03:20 +00:00
|
|
|
reset.all()
|
2012-06-10 18:56:21 +00:00
|
|
|
|
2013-03-03 16:06:32 +00:00
|
|
|
-- Construct file name for the output code: (...)/xxx/qwe.con -->
|
|
|
|
-- xxx_qwe.con, so that common root CON file names like EDUKE.CON will
|
|
|
|
-- result in distinct file names for different mods. From that name,
|
|
|
|
-- strip the extension.
|
|
|
|
local codedir = g_cgopt["gendir"]
|
|
|
|
local codefn = codedir and
|
|
|
|
codedir.."/"..filename:match("[^/]+/[^/]+$"):gsub('/','_')..".lua"
|
|
|
|
|
|
|
|
-- Get the directory part...
|
|
|
|
g_directory = filename:match(".*/") or ""
|
|
|
|
-- ...and the file name alone.
|
2012-06-10 18:56:21 +00:00
|
|
|
filename = filename:sub(#g_directory+1, -1)
|
|
|
|
|
2012-07-01 22:11:17 +00:00
|
|
|
-- NOTE: xpcall isn't useful here since the traceback won't give us
|
|
|
|
-- anything inner to the lpeg.match call
|
2013-05-24 13:54:33 +00:00
|
|
|
local ok, msg = pcall(do_include_file, g_directory, filename, true)
|
2012-11-25 13:18:46 +00:00
|
|
|
-- ^v Swap commenting (comment top, uncomment bottom line) to get backtraces
|
2013-05-24 13:54:33 +00:00
|
|
|
-- local ok, msg = true, do_include_file(g_directory, filename, true)
|
2012-07-01 22:11:17 +00:00
|
|
|
|
2012-06-10 18:56:21 +00:00
|
|
|
if (not ok) then
|
2012-12-29 15:21:24 +00:00
|
|
|
print_on_failure(msg)
|
2012-06-10 18:56:21 +00:00
|
|
|
end
|
2012-07-01 22:11:17 +00:00
|
|
|
|
2013-02-25 15:31:09 +00:00
|
|
|
if (not (g_cgopt["no"]==true)) then
|
|
|
|
local onlycheck = (g_cgopt["no"] == "onlycheck")
|
2013-03-03 16:06:32 +00:00
|
|
|
-- The file for the output messages:
|
|
|
|
local msgfile = onlycheck and io.stdout or io.stderr
|
2013-02-25 15:31:09 +00:00
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
local code, lineinfo = get_code_string(g_curcode, g_cgopt["debug-lineinfo"])
|
2013-02-25 15:31:09 +00:00
|
|
|
local func, errmsg = loadstring(code, "CON")
|
|
|
|
|
2013-03-03 16:06:32 +00:00
|
|
|
-- msgfile:write(format("-- GENERATED CODE for \"%s\":\n", filename))
|
2013-02-25 15:31:09 +00:00
|
|
|
if (func == nil) then
|
2013-06-30 20:38:39 +00:00
|
|
|
msgfile:write(format("-- %s%s: INVALID Lua CODE: %s\n",
|
|
|
|
g_directory, filename, errmsg))
|
2013-02-25 15:31:09 +00:00
|
|
|
end
|
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
if (lineinfo) then
|
|
|
|
for i=1,#lineinfo.llines do
|
2013-03-03 16:06:32 +00:00
|
|
|
msgfile:write(format("%d -> %s:%d\n", i, lineinfo:getfline(i)))
|
2013-03-03 16:06:16 +00:00
|
|
|
end
|
|
|
|
elseif (not onlycheck) then
|
2013-03-03 16:06:32 +00:00
|
|
|
-- The file for the generated code:
|
|
|
|
local codefile = codefn and assert(io.open(codefn, "w+")) or msgfile
|
|
|
|
|
|
|
|
codefile:write(code)
|
|
|
|
codefile:write("\n")
|
2013-02-25 15:31:09 +00:00
|
|
|
end
|
2012-07-01 22:11:17 +00:00
|
|
|
end
|
2012-05-13 16:05:16 +00:00
|
|
|
end
|
2013-03-03 16:06:28 +00:00
|
|
|
|
|
|
|
local havelists = false
|
|
|
|
|
|
|
|
for argi=1,#arg do
|
|
|
|
local filename = arg[argi]
|
|
|
|
|
|
|
|
if (filename=="@") then
|
|
|
|
-- Start file list processing from the next positional argument on.
|
|
|
|
havelists = true
|
|
|
|
elseif (havelists) then
|
|
|
|
printf("\n------ Handling list of CON files \"%s\"", filename)
|
|
|
|
for fn in io.lines(filename) do
|
|
|
|
-- A hash at the beginning of a line denotes a comment, an
|
|
|
|
-- empty line is skipped.
|
|
|
|
if (#fn>0 and not fn:match("^#")) then
|
|
|
|
compile(fn)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
compile(filename)
|
|
|
|
end
|
|
|
|
end
|
2012-12-29 15:21:24 +00:00
|
|
|
else
|
|
|
|
-- running from EDuke32
|
2013-07-13 21:04:50 +00:00
|
|
|
|
2013-01-13 16:40:07 +00:00
|
|
|
function compile(filenames)
|
2012-12-29 15:21:24 +00:00
|
|
|
-- TODO: pathsearchmode=1 set in G_CompileScripts
|
2013-01-13 16:40:07 +00:00
|
|
|
|
2013-11-12 21:03:20 +00:00
|
|
|
reset.all()
|
2013-01-13 16:40:07 +00:00
|
|
|
|
|
|
|
for _, fname in ipairs(filenames) do
|
2013-05-24 13:54:33 +00:00
|
|
|
local ok, msg = pcall(do_include_file, "", fname, true)
|
2013-02-21 18:53:49 +00:00
|
|
|
if (not ok or g_numerrors > 0) then
|
|
|
|
if (not ok) then
|
|
|
|
-- Unexpected error in the Lua code (i.e. a bug here).
|
|
|
|
print_on_failure(msg)
|
|
|
|
end
|
2013-01-13 16:40:07 +00:00
|
|
|
return nil
|
|
|
|
end
|
2012-12-29 15:21:24 +00:00
|
|
|
end
|
2013-01-13 16:40:07 +00:00
|
|
|
|
2013-03-03 16:06:16 +00:00
|
|
|
return get_code_string(g_curcode, true)
|
2012-12-29 15:21:24 +00:00
|
|
|
end
|
2012-05-13 16:05:16 +00:00
|
|
|
end
|