diff --git a/gamedata/configs/mod_script_amx.ltx b/gamedata/configs/mod_script_amx.ltx new file mode 100644 index 000000000..eebff96c0 --- /dev/null +++ b/gamedata/configs/mod_script_amx.ltx @@ -0,0 +1,3 @@ +![common] +script = xr.compiler, xr.lua, amx, _G, _g_patches, xr.classes, xr.processes, dxml_core +>class_registrators = amx.registrator.register diff --git a/gamedata/configs/mod_script_dxml.ltx b/gamedata/configs/mod_script_dxml.ltx deleted file mode 100644 index 9e2ccf861..000000000 --- a/gamedata/configs/mod_script_dxml.ltx +++ /dev/null @@ -1,3 +0,0 @@ -![common] ->script = _g_patches, dxml_core ->class_registrators = class_registrator_modded_exes.register diff --git a/gamedata/scripts/amx/init.lua b/gamedata/scripts/amx/init.lua new file mode 100644 index 000000000..25a4c1a75 --- /dev/null +++ b/gamedata/scripts/amx/init.lua @@ -0,0 +1,13 @@ +-- Anomaly Modded eXes Entrypoint +-- Extends base X-Ray script functionality + +--- Setup unlocalizer data model +require(_PACKAGE .. ".unlocalize") + +--- Patch xr/lua compiler with modded exes extensions +require(_PACKAGE .. ".lua") + +--- Export registrator from module to allow foo.bar.baz syntax in script.ltx +return { + registrator = require(_PACKAGE .. ".registrator") +} diff --git a/gamedata/scripts/amx/lua/init.lua b/gamedata/scripts/amx/lua/init.lua new file mode 100644 index 000000000..dcf92eaa8 --- /dev/null +++ b/gamedata/scripts/amx/lua/init.lua @@ -0,0 +1,20 @@ +-- AMX Lua Compiler +-- Patches unlocalization onto the base XR Lua compiler + +local xr_lua = require("xr.lua") +local unlocalize = require(_PACKAGE .. ".unlocalize").unlocalize + +function xr_lua.loadstring(src, namespace_name, script_name) + if namespace_name then + print("* [" .. _PACKAGE .. "] compiling " .. namespace_name) + end + + return xr_lua.compile( + unlocalize(src, namespace_name), + namespace_name, + script_name + ) +end + +-- Run unit tests +require("amx.lua.tests") diff --git a/gamedata/scripts/amx/lua/tests.lua b/gamedata/scripts/amx/lua/tests.lua new file mode 100644 index 000000000..f19f2139a --- /dev/null +++ b/gamedata/scripts/amx/lua/tests.lua @@ -0,0 +1,110 @@ +local run_tests = require("tests.util").run_tests +local unlocalize_with = require("amx.lua.unlocalize").unlocalize_with + +local SRC = { + declare_function = [[ +local function x(a, b, c) -- define a function + return a, b, c +end + ]], + + declare_var_single = [[ +local a -- declare a single var + ]], + + define_var_single = [[ +local a = 1 -- define a single var + ]], + declare_var_multi = [[ +local a, b, c -- declare multiple vars + ]], + define_var_multi = [[ +local a, b, c = 1, 2, 3 -- define multiple vars + ]], + declare_var_single_sequence = [[ +local a; local b; local c; -- declare a sequence of vars + ]], + define_var_single_sequence = [[ +local a = 1; local b = 2; local c = 3; define a sequence of vars + ]], +} + +local PASSES = { + declare_function = [[ +function x(a, b, c) -- define a function + return a, b, c +end + ]], + + declare_var_single = [[ +a = nil -- declare a single var + ]], + + define_var_single = [[ +a = 1 -- define a single var + ]], + declare_var_multi = [[ +a, b, c = nil -- declare multiple vars + ]], + define_var_multi = [[ +a, b, c = 1, 2, 3 -- define multiple vars + ]], +} + +local FAILS = { + declare_var_single_sequence = [[ +a = nil; b = nil; c = nil; -- declare a sequence of vars + ]], + define_var_single_sequence = [[ +a = 1; b = 2; c = 3; -- define a sequence of vars + ]], +} + +local unlocalizer = {"x", "a", "b", "c"} + +local tests = {} + +local ERR_MISMATCHED = +[[Mismatched unlocalizer output +src: +%s +unlocalized: +%s +target: +%s]] + +for k,targ in pairs(PASSES) do + tests[k] = function() + local src = SRC[k] + local res = unlocalize_with(src, unlocalizer) + + if res == targ then + return true + else + return false, string.format(ERR_MISMATCHED, v, res, targ) + end + end +end + +local ERR_UNEXPECTED = +[[Unexpected unlocalizer output +src: +%s +unlocalized: +%s +target: +%s]] + +for k,targ in pairs(FAILS) do + tests[k .. " (unsupported)"] = function() + local src = SRC[k] + local res = unlocalize_with(src, unlocalizer) + if res ~= targ then + return true + else + return false, string.format(ERR_UNEXPECTED, src, res, targ) + end + end +end + +run_tests("amx/lua", tests) diff --git a/gamedata/scripts/amx/lua/unlocalize.lua b/gamedata/scripts/amx/lua/unlocalize.lua new file mode 100644 index 000000000..1f39a6e51 --- /dev/null +++ b/gamedata/scripts/amx/lua/unlocalize.lua @@ -0,0 +1,121 @@ +-- Unlocalizer for xr/lua scripts + +local DEBUG = false + +local function string_trim(s, v) + if v == nil then + v = " \t\n\r\f\v" + end + local pattern = string.format("^[%s]*([^%s]*)[%s]*$", v, v, v) + return string.match(s, pattern) +end + +local function contains(lst, a) + for _,b in ipairs(lst) do + if a == b then + return true + end + end + + return false +end + +local function unlocalize_with(src, unlocalizer) + local unlocal_performed = false + + local temp = src + local tokens = {} + for line in string.gmatch(temp, "[^\n\r]+") do + table.insert(tokens, line) + end + + for i,s in ipairs(tokens) do + s = string_trim(s, "\n\r") + tokens[i] = s + + if s == "" then + goto next_token + end + + -- local function x(a,b,c) + local _, _, c, d, e, f, g = string.match( + s, + [[^(local)([\t ]+)(function)([\t ]+)([_a-zA-Z].*)([\t ]*)(%(.*)$]] + ) + + if e then + if contains(unlocalizer, e) then + if DEBUG then + print("[unlocal_regex] found variable " .. e .. " to unlocal") + end + tokens[i] = c .. d .. e .. f .. g + unlocal_performed = true + end + goto next_token + end + + -- local a = ... + -- local a + -- local a,b,c = ... (if one of a,b,c is in unlocalizers list - all of them will be unlocalized) + -- local x; local y; - unsupported yet + local c = string.match(s, [[^local%s+(.*)]]) or "" + if #c > 0 then + local r = [[(.*)--.*]] + local nc = string.match(c, r) + if nc then + c = nc + end + end + + local variables = string.match(c, [[^([^=]+)]]) + local values = string.match(c, [[=([^=]+)$]]) + if variables then + for v in string.gmatch(variables, "[^, ]+") do + v = string_trim(v) + if contains(unlocalizer, v) then + unlocal_performed = true + if DEBUG then + print("found variable", v, "to unlocal") + end + s = c + if not values then + local lhs, rhs = string.match(s, [[([^-]+)(%-%-[^-]*)]]) + if lhs and rhs then + s = lhs .. "= nil " .. rhs + else + s = s .. "= nil" + end + end + tokens[i] = s + break + end + end + end + + ::next_token:: + end + + if unlocal_performed then + return table.concat(tokens, "\n") + end + + return src +end + +local function unlocalize(src, namespace_name) + if not namespace_name then + return src + end + + local unlocalizer = require("amx.unlocalize").get(namespace_name) + if not unlocalizer then + return src + end + + return unlocalize_with(src, unlocalizer) +end + +return { + unlocalize_with = unlocalize_with, + unlocalize = unlocalize, +} diff --git a/gamedata/scripts/amx/registrator.lua b/gamedata/scripts/amx/registrator.lua new file mode 100644 index 000000000..951aa09fe --- /dev/null +++ b/gamedata/scripts/amx/registrator.lua @@ -0,0 +1,33 @@ +-- AMX Class Registrator +-- Add custom classes for registration here + +local function cs_register(factory, ...) + factory:register(...) +end + +local function c_register(factory, ...) + if editor() == false then + factory:register(...) + end +end + +local function s_register(factory, ...) + factory:register(...) +end + +local function register(object_factory) + cs_register( + object_factory, + "CWeaponSSRS", + "se_item.se_weapon_magazined", + "_WP_SSRS", + "wpn_ssrs_s" + ) +end + +return { + cs_register = cs_register, + c_register = c_register, + s_register = s_register, + register = register, +} diff --git a/gamedata/scripts/amx/unlocalize.lua b/gamedata/scripts/amx/unlocalize.lua new file mode 100644 index 000000000..a4174fd7e --- /dev/null +++ b/gamedata/scripts/amx/unlocalize.lua @@ -0,0 +1,68 @@ +-- AMX Unlocalizer Storage +-- Loads unlocalizers from disk and exposes them via `get` + +local unlocalizers = {} + +local function update() + local fs = getFS() + local list = fs:file_list_open( + "$game_config$", + "unlocalizers\\", + bit_or( + FS.FS_ListFiles, + FS.FS_RootOnly + ) + ) + + if not list then + return + end + + local count = list:Size() or 0 + if count == 0 then + return + end + + for i=1,count do + local id = list:GetAt(i - 1) + + if #id < 4 then + goto next_filename + end + + if string.sub(id, #id - 3, #id) ~= ".ltx" then + goto next_filename + end + + print("opening file:", id) + + local config = ini_file("unlocalizers\\" .. id) + config:section_for_each(function(section) + local name = string.lower(section) + local count = config:line_count(name) + for j=0,count-1 do + local res, sec = config:r_line(name, j) + if not res then + goto next_line + end + unlocalizers[name] = unlocalizers[name] or {} + table.insert(unlocalizers[name], sec) + + ::next_line:: + end + end) + + ::next_filename:: + end +end + +local function get(k) + return unlocalizers[k] +end + +update() + +return { + update = update, + get = get +} diff --git a/gamedata/scripts/boot/function_object.lua b/gamedata/scripts/boot/function_object.lua new file mode 100644 index 000000000..98ab22189 --- /dev/null +++ b/gamedata/scripts/boot/function_object.lua @@ -0,0 +1,28 @@ +-- Engine interface +-- Behaves like _G-aware `require` with recursive . indexing + +function function_object(str) + local path = {} + for v in string.gmatch(str, "[^%.]+") do + v = v:gsub("/", ".") + table.insert(path, v) + end + + local mod_name = table.remove(path, 1) + + local mod = nil + if mod_name == "_G" then + mod = _G + elseif _G[mod_name] then + mod = _G[mod_name] + else + mod = require(mod_name) + end + + local val = mod + for _, seg in ipairs(path) do + val = val[seg] + end + + return val +end diff --git a/gamedata/scripts/boot/init.lua b/gamedata/scripts/boot/init.lua new file mode 100644 index 000000000..070003591 --- /dev/null +++ b/gamedata/scripts/boot/init.lua @@ -0,0 +1,22 @@ +--- Boot Kernel +--- Establishes a functioning X-Ray Lua environment + +_PACKAGE = "boot" + +-- Disable unsafe Lua primitives +require("boot.sandbox") + +-- Setup package.path machinery +require("boot.paths") + +-- Setup package.loaders machinery +require("boot.loader") + +-- Setup engine interface +require("boot.function_object") + +-- Ensure _G loads on first require +package.loaded._G = nil + +-- Run startup modules defined in script.ltx +require("boot.scripts") diff --git a/gamedata/scripts/boot/loader.lua b/gamedata/scripts/boot/loader.lua new file mode 100644 index 000000000..58ffe33c2 --- /dev/null +++ b/gamedata/scripts/boot/loader.lua @@ -0,0 +1,120 @@ +-- Boot Loader +-- Configures package.loaders with support for X-Ray FS + +_PACKAGE = "boot/loader" + +local state = { + callbacks = {} +} + +-- X-Ray FS Loader +function _LOADERS.fs(name) + -- Check whether the target is known to not exist on the FS + local io_miss = _SCRIPT_STORAGE:get("io_loader", name) + if io_miss then + -- If so, early out + return io_miss + end + + -- Allocate error storage + local errs = "" + + -- Fetch filesystem handle + local fs = getFS() + + -- Update the FS' view of our script directory + local base = fs:update_path("$game_scripts$", "") + + -- Iterate over our search paths + for seg in package.path:gmatch("[^;]+") do + -- If the segment begins with our base directory + if seg:sub(1, #base) == base then + -- Strip the base path, interpolate package name, + -- and replace separators to produce a filename + local sname = name:gsub("%.", "\\") + local fname = seg:sub(#base + 1) + fname = fname:gsub("?", sname) + + -- Get an xray path from our filename + local path = fs:update_path("$game_scripts$", fname) + + -- If the path is valid and exists... + if path and fs:exist(path) then + -- Load the corresponding file into a string + local src = _LOAD_FILE(path) + + -- Compile it into a Lua function + local mac, err = loadstring(src, name, path) + + -- If we don't have a result... + if not mac then + -- Print and throw the corresponding error + print(err) + error(err) + end + + -- Cache any loaded copy of this package + local already_loaded = package.loaded[name] + + -- Evaluate the compiled Lua function + local res = mac() + + -- Emplace the result in package.loaded so callbacks can see it + package.loaded[name] = res + + -- If this package wasn't already loaded... + if already_loaded == nil then + -- Fire on-load callbacks + for _,f in ipairs(state.callbacks) do + f(name) + end + end + + -- Finally, return a function that populates package.loaded + -- with the result and returns it, + -- to ensure `require` returns the correct value + -- regardless of re-entrant loading that may occur in the interim + return function() + package.loaded[name] = res + return res + end + else + -- Otherwise, add to our error accumulator + errs = errs .. "\n\tNo db entry: " .. path + end + end + end + + -- Cache the IO miss for later + _SCRIPT_STORAGE:set("io_loader", name, errs) + + -- Return error accumulator + return errs +end + +function memoize(f) + local cache = {} + return function(v) + if cache[v] then + return cache[v] + end + + local out = f(v) + cache[v] = out + + return out + end +end + +-- Replace the loader list with the preloader plus our FS loader +package.loaders = { _LOADERS.pre, _LOADERS.fs, memoize(_LOADERS.bin) } + +-- Define callback registrator +local function register_on_load_callback(f) + table.insert(state.callbacks, f) +end + +-- Return final module +return { + register_on_load_callback = register_on_load_callback +} diff --git a/gamedata/scripts/boot/paths.lua b/gamedata/scripts/boot/paths.lua new file mode 100644 index 000000000..5c700ed4e --- /dev/null +++ b/gamedata/scripts/boot/paths.lua @@ -0,0 +1,36 @@ +-- Boot Paths +-- Configures package.path to root at gamedata/scripts, +-- and gamedata/scripts/packages + +_PACKAGE = "boot/paths" + +-- Cache default paths for later +_DEFAULT_PATH = package.path +_DEFAULT_CPATH = package.cpath + +-- Define load path registrator +function _REGISTER_PATHS(...) + local ps = {...} + for i=#ps,1,-1 do + local p = getFS():update_path("$game_scripts$", ps[i]) + package.path = p .. ";" .. package.path + end +end + +-- Fetch filesystem handle +local fs = getFS() + +-- Get base scripts folder path +local base = fs:update_path("$game_scripts$", "") + +-- Search for lua files in scripts, and scripts/packages/lib +package.path = base .. [[?.lua]] + .. ";" .. base .. [[?\init.lua]] + .. ";" .. base .. [[packages\lib\?.lua]] + .. ";" .. base .. [[packages\lib\?\init.lua]] + +-- Search for binary libraries in packages/bin +package.cpath = base .. [[packages\bin\?.dll]] + .. ";" .. base .. [[packages\bin\?\init.dll]] + .. ";" .. base .. [[packages\bin\?.so]] + .. ";" .. base .. [[packages\bin\?\init.so]] diff --git a/gamedata/scripts/boot/sandbox.lua b/gamedata/scripts/boot/sandbox.lua new file mode 100644 index 000000000..23d97203d --- /dev/null +++ b/gamedata/scripts/boot/sandbox.lua @@ -0,0 +1,22 @@ +-- Boot Sandbox +-- Disables dangerous Lua primitives + +-- Map from package name to dangerous primitives +local disabled = { + os = { + "execute", + "rename", + "remove", + "exit", + }, + io = { + "popen" + } +} + +-- Iterate disabled map and nil corresponding primitives +for k,v in pairs(disabled) do + for i=1,#v do + _G[k][v[i]] = nil + end +end diff --git a/gamedata/scripts/boot/scripts.lua b/gamedata/scripts/boot/scripts.lua new file mode 100644 index 000000000..ce25e92d1 --- /dev/null +++ b/gamedata/scripts/boot/scripts.lua @@ -0,0 +1,38 @@ +-- Boot Scripts +-- Loads scripts specified in script.ltx + +local DISABLE_SCRIPTS = false + +if DISABLE_SCRIPTS then + return +end + +-- Open script.ltx +local ini = ini_file("script.ltx") +if not ini then + return +end + +-- Check for the common section +if not ini:section_exist("common") then + error("Missing common section") +end + +-- Check for the script list +if not ini:line_exist("common", "script") then + error("Missing script line") +end + +-- Read the script list +local scripts = ini:r_string("common", "script", "") + +-- Iterate scripts, requiring each one and optionally calling an init function +for script in scripts:gmatch("[^,]+") do + local mod = require(script) + if type(mod) == "table" then + local init = mod[script .. "_initialize"] + if init then + init() + end + end +end diff --git a/gamedata/scripts/init.lua b/gamedata/scripts/init.lua new file mode 100644 index 000000000..68ac855e7 --- /dev/null +++ b/gamedata/scripts/init.lua @@ -0,0 +1,147 @@ +--- Lua Entrypoint +--- Called by CScriptEngine at the end of Lua initialization + +_PACKAGE = "init" + +--- Store default Lua loaders for later +_LOADERS = { + pre = package.loaders[1], + lib = package.loaders[2], + bin = package.loaders[3], + aio = package.loaders[4], +} + +-- Emplace working print function +function print(...) + local str = "" + for _,v in ipairs({...}) do + if #str > 0 then + str = str .. " " + end + + local s = nil + if (type(v) == 'userdata') then + s = 'userdata' + else + s = tostring(v) + end + + str = str .. s + end + + if (log) then + log(str) + else + get_console():execute("load ~#debug msg:" .. str) + end +end + +--- Customizable environment for .lua files +--- Needed so .script files can propagate their extended _G when requiring .lua +_LUA_G = _G + +--- Emplace an error-checked lua compiler with customizable environment +_LOADSTRING = loadstring +function loadstring(src, namespace_name, script_name) + print("* [lua] loading " .. namespace_name) + + local f, err = _LOADSTRING(src, namespace_name) + if not f then + err = "init: error loading " .. namespace_name .. ":\n\n" + .. err .. "\n" + err = debug.traceback(err, 2) + print(err) + return nil, err + end + + local mac = setfenv( + f, + setmetatable( + { + _PACKAGE = namespace_name, + _FILE = script_name, + }, + { + __index = _LUA_G, + __newindex = _LUA_G, + } + ) + ) + + return function(...) + local args = {...} + + local _, out = xpcall( + function() + return mac(unpack(args)) + end, + function(err) + err = debug.traceback(err, 2) + print(err) + error(err) + end + ) + + return out + end +end + +-- Redirect load through loadstring +load = function(f, name) + local src = "" + + while true do + local part = f() + if part == nil then + break + elseif type(part == "string") then + if #part == 0 then + break + end + + src = src .. part + end + end + + return loadstring(src, name) +end + +-- Redirect loadfile through loadstring +loadfile = function(path) + local file = io.input(path) + local src = file:read("*a") + file:close() + return loadstring(src) +end + + +--- Emplace minimal X-Ray FS loader +function _LOADERS.init(name) + local fs = getFS() + local sname = name:gsub("%.", "\\") + local path = fs:update_path("$game_scripts$", sname) + if not path then + return "\n\tInvalid path " .. path + end + + if fs:exist(path .. ".lua") then + path = path .. ".lua" + elseif + fs:exist(path .. "\\init.lua") then + path = path .. "\\init.lua" + else + return "\n\tNo such package: " .. name + end + + local res, err = loadstring(_LOAD_FILE(path), name, path) + if res then + return res + end + + return err +end + +package.loaders = { _LOADERS.init } + +--- Hand control to the boot module +require("boot") diff --git a/gamedata/scripts/tests/init.lua b/gamedata/scripts/tests/init.lua new file mode 100644 index 000000000..9b464d82d --- /dev/null +++ b/gamedata/scripts/tests/init.lua @@ -0,0 +1,5 @@ +--- Unit testing framework + +-- Currently just a container for reusable code. +-- Can be extended into a robust test runner once +-- nested directory machinery is implemented. diff --git a/gamedata/scripts/tests/util.lua b/gamedata/scripts/tests/util.lua new file mode 100644 index 000000000..edc862c6b --- /dev/null +++ b/gamedata/scripts/tests/util.lua @@ -0,0 +1,28 @@ +-- Given a named set of tests, run them and report their results +function run_tests(name, tests) + print("+ [TEST] " .. name) + + local passes = {} + local fails = {} + + for k,v in pairs(tests) do + local res, err = v() + if res then + table.insert(passes, k) + else + table.insert(fails, k .. ": " .. err) + end + end + + for _,v in ipairs(passes) do + print("- [PASS] " .. v) + end + + for _,v in ipairs(fails) do + print("! [FAIL] " .. v) + end +end + +return { + run_tests = run_tests, +} diff --git a/gamedata/scripts/xr/classes.lua b/gamedata/scripts/xr/classes.lua new file mode 100644 index 000000000..91f884f93 --- /dev/null +++ b/gamedata/scripts/xr/classes.lua @@ -0,0 +1,30 @@ +-- XR Class Registration + +-- Open script.ltx +local ini = ini_file("script.ltx") +if not ini then + return +end + +-- Check for the `common` section +if not ini:section_exist("common") then + error("Missing common section") +end + +-- Check for class registrators +if not ini:line_exist("common", "class_registrators") then + error("Missing class_registrators line") +end + +-- Read class registrators +local regs = ini:r_string("common", "class_registrators", "") + +-- Iterate, load from environment, and invoke each with the object factory +for reg_path in regs:gmatch("[^,]+") do + local reg = function_object(reg_path) + reg(_OBJECT_FACTORY) +end + +-- Invoke object factory registration method +_OBJECT_FACTORY:register_script() + diff --git a/gamedata/scripts/xr/compiler.lua b/gamedata/scripts/xr/compiler.lua new file mode 100644 index 000000000..14a6498c1 --- /dev/null +++ b/gamedata/scripts/xr/compiler.lua @@ -0,0 +1,72 @@ +-- XR Compiler Dispatch +-- Extends loadstring with extension-aware dispatch + +local PATTERN_FILE_PATH = "^(.-)([^\\/]-)%.([^\\/%.]-)%.?$" +local PATTERN_MACRO_TAG = "[^ ]+ +=%*= +lang: +([^ ]+) +=%*=[^\n]*(\n.*)" + +-- Store the original loadstring implementation into a compiler module +local default = { loadstring = loadstring } + +-- Map from file extension to compiler module +local extensions = {} + +-- Associate the default loadstring implementation with the lua file extension +extensions.lua = default + +-- Override loadstring with extensible dispatch +function loadstring(src, namespace_name, script_name) + local mod = nil + + if script_name then + local _,_,ext = script_name:match(PATTERN_FILE_PATH) + if extensions[ext] then + mod = extensions[ext] + end + end + + local tag,rest = src:match(PATTERN_MACRO_TAG) + if tag ~= nil then + src = rest + mod = require(tag) + end + + if mod == nil then + mod = default + end + + return mod.loadstring(src, namespace_name, script_name) +end + +-- Associate a file extension with a compiler module +local function register_extension(k, mod) + print(_PACKAGE .. ": registering extension: " .. k) + _REGISTER_PATHS( + "?." .. k, + "?\\init." .. k + ) + extensions[k] = mod +end + +-- Return a list of registered extensions +local function get_extensions() + local out = {} + for k in pairs(extensions) do + table.insert(out, k) + end + return out +end + +-- Set the default compiler module +local function set_default_module(mod) + print(_PACKAGE .. ": setting default module...") + default = mod +end + +-- Return module result +return { + PATTERN_FILE_PATH = PATTERN_FILE_PATH, + PATTERN_MACRO_TAG = PATTERN_MACRO_TAG, + register_extension = register_extension, + get_extensions = get_extensions, + set_default_module = set_default_module +} diff --git a/gamedata/scripts/xr/init.lua b/gamedata/scripts/xr/init.lua new file mode 100644 index 000000000..f47d2cdb0 --- /dev/null +++ b/gamedata/scripts/xr/init.lua @@ -0,0 +1,2 @@ +-- X-Ray Lua Core +-- Submodules are loaded by script.ltx for flexible initialization order diff --git a/gamedata/scripts/xr/lua/init.lua b/gamedata/scripts/xr/lua/init.lua new file mode 100644 index 000000000..dd2f8bb85 --- /dev/null +++ b/gamedata/scripts/xr/lua/init.lua @@ -0,0 +1,202 @@ +--- XR Lua Compiler +--- The original X-Ray script environment, reimplemented as a loadstring wrapper + +local compiler = require("xr.compiler") + +local XR_LOADERS = { + _LOADERS.pre, + _LOADERS.lib, + _LOADERS.bin, + _LOADERS.aio, +} + +-- `package` module override for X-Ray Lua scripts +local XR_PACKAGE = setmetatable( + { + -- Use unconfigured Lua loaders + loaders = XR_LOADERS, + }, + { + __index = package, + } +) + +-- Global scope wrapper for X-Ray Lua scripts +-- Indirects through `_G`, and `package.loaded` via `require` +local XR_G = setmetatable( + { + -- Indirect package to our wrapper + package = XR_PACKAGE, + }, + { + -- Override key reads + __index = function(self, key) + -- If the index is _G, indirect back to this object + if key == "_G" then + return self + end + + -- Check the real _G for our key and return the result if valid + local gv = _G[key] + if gv ~= nil then + return gv + end + + -- Otherwise, try to auto-load via the global package.path + local res, out = pcall(require, key) + if res then + return out + end + + -- Otherwise, try to auto-load via xr/lua's local package.path + local package_path_old = package.path + local package_cpath_old = package.cpath + package.path = _DEFAULT_PATH + package.cpath = _DEFAULT_CPATH + res, out = pcall(require, key) + package.path = package_path_old + package.cpath = package_cpath_old + if res then + return out + end + end, + -- Send key writes straight to `_G` + __newindex = _G + } +) + +-- Error pretty-printer +local function format_error(msg, err, stack_level) + stack_level = stack_level or 2 + + err = "! " .. _PACKAGE .. ": " + .. msg .. ":\n\n" + .. err + .. "\n" + + return debug.traceback(err, stack_level) +end + +-- Error handler constructor +local function handle_error(msg, namespace_name) + return function(err) + if namespace_name then + package.loaded[namespace_name] = nil + end + + err = format_error(msg, err, 3) + + print(err) + error(err) + end +end + +-- `loadstring` replacement specialized to X-Ray scripts +local function compile(src, namespace_name, script_name) + -- Construct our script's environment table + local env = { + _PACKAGE = namespace_name, + _FILE = script_name, + } + + -- Create a wrapper around lua's base loadstring that runs in our environment + local function base_loadstring(s, name) + return setfenv( + _LOADSTRING(s, name), + env + ) + end + + -- Construct the metatable for our environment + local mt = { + __index = function(self, key) + -- Dynamically indirect to our loadstring wrapper + if key == "loadstring" then + return base_loadstring + end + + -- Otherwise, indirect to XR_G + return XR_G[key] + end + } + + -- If we're loading _g.script, forward environment writes to _G + if namespace_name == "_G" then + mt.__newindex = XR_G + end + + -- Associate our environment with its metatable + setmetatable(env, mt) + + -- If we have a namespace name, inject locals that derive from it + if namespace_name then + src = "local this = _G[script_name()] " .. src + src = "local script_name = function() return \"" .. namespace_name .. "\" end " .. src + end + + -- Load the resulting script, using the filename to ensure `debug` compat + local mod, err = _LOADSTRING(src, script_name and ("@" .. script_name)) + + -- On load failure, annotate the error and early-out + if not mod then + err = format_error("error loading " .. (namespace_name or "script"), err) + return nil, err + end + + -- Apply our environment to the resulting function + local mac = setfenv(mod, env) + + -- Return a package constructor for the loaded module + return function() + -- Prepopulate `package.loaded` in case of reentrancy + if namespace_name then + package.loaded[namespace_name] = env + end + + local lua_g_old = _LUA_G + _LUA_G = env + + -- Call our script function with an appropriate error handler + local _, out = xpcall( + mac, + handle_error( + "error evaluating " .. (namespace_name or "script"), + namespace_name + ) + ) + + _LUA_G = lua_g_old + + -- If we have a namespace name... + if namespace_name then + -- Return the prepopulated package + return package.loaded[namespace_name] + else + -- Otherwise, return the module output directly + return out + end + end +end + +local function loadstring(src, namespace_name, script_name) + if namespace_name then + print("* [" .. _PACKAGE .. "] compiling " .. namespace_name) + end + + return compile(src, namespace_name, script_name) +end + +-- Prepare module value +local mod = { + compile = compile, + loadstring = loadstring +} + +-- Register this as the compiler for .script files +compiler.register_extension("script", mod) + +-- Register this as the default compiler +compiler.set_default_module(mod) + +-- Return module value +return mod diff --git a/gamedata/scripts/xr/processes/init.lua b/gamedata/scripts/xr/processes/init.lua new file mode 100644 index 000000000..591a949c8 --- /dev/null +++ b/gamedata/scripts/xr/processes/init.lua @@ -0,0 +1,81 @@ +-- Engine interface to domain-scoped coroutines +-- Formerly part of CScriptManager + +local ScriptProcess = require("xr.processes.process") + +-- Script processes class +local ScriptProcesses = {} + +-- Constructor +function ScriptProcesses.new() + return setmetatable( + { + processes = {} + }, + { + __index = ScriptProcesses, + __tostring = function(self) + return "ScriptProcesses {" + .. "\n processes: " .. tostring(self.processes) + .. "\n}" + end + } + ) +end + +-- Add a script process by name, with a set of scripts to add by default +function ScriptProcesses:add(name, scripts) + self.processes[name] = ScriptProcess.new(name, scripts) +end + +-- Remove a script process by name +function ScriptProcesses:remove(name) + self.processes[name] = nil +end + +-- Test the existence of a script process by name +function ScriptProcesses:has(name) + return self.processes[name] ~= nil +end + +-- Get a script process by name +function ScriptProcesses:get(name) + return self.processes[name] +end + +-- Prepare package output +local processes = ScriptProcesses.new() + +-- Setup game process +do + local ini_script = ini_file("configs\\script.ltx") + + local game_scripts = "" + if ini_script:section_exist("single") + and ini_script:line_exist("single", "script") + then + game_scripts = ini_script:r_string("single", "script"); + end + + processes:add("game", game_scripts) +end + +-- If a level exists... +if level.present() then + -- Setup level process + local ini_level = ini_file( + string.format("levels\\%s\\level.ltx", level.name()) + ) + + local level_scripts = "" + if ini_level:section_exist("level_scripts") + and ini_level:line_exist("level_scripts", "script") + then + level_scripts = ini_level:r_string("level_scripts", "script"); + end + + processes:add("level", level_scripts) +end + +-- Return package output +return processes diff --git a/gamedata/scripts/xr/processes/process.lua b/gamedata/scripts/xr/processes/process.lua new file mode 100644 index 000000000..a4c34ca31 --- /dev/null +++ b/gamedata/scripts/xr/processes/process.lua @@ -0,0 +1,143 @@ +-- A collection of domain-scoped coroutines, +-- with time-sliced update logic to process one per frame. +-- +-- Formerly CScriptProcess and CScriptThread + +local DEBUG = false +local DISABLE_SCRIPTS = false + +-- Script process class +ScriptProcess = {} + +-- Constructor +function ScriptProcess.new(name, scripts) + if DEBUG then + print("* Initializing " .. name .. " script process") + end + + local out = setmetatable( + { + name = name, + coroutines = {}, + iterator = 0, + }, + { + __index = ScriptProcess, + __tostring = function(self) + return string.format( + "ScriptProcess {" + .. "\n name = " .. self.name + .. "\n coroutines = " .. tostring(self.coroutines) + .. "\n iterator = " .. tostring(self.iterator) + .. "\n}" + ) + end + } + ) + + for script in scripts:gmatch("[^;]+") do + out:add_script(script) + end + + return out +end + +-- Update entrypoint, called by the engine +function ScriptProcess:update() + if DISABLE_SCRIPTS then + while #self.coroutines > 0 do + table.remove(self.coroutines) + end + end + + if #self.coroutines == 0 then + self.iterator = 0 + return + end + + local co = self.coroutines[self.iterator + 1] + + if not co then + return + end + + local res, err = coroutine.resume(co) + + if res then + self.iterator = (self.iterator + 1) % #self.coroutines + else + if err ~= "cannot resume dead coroutine" then + print("! ScriptProcess: " .. err) + end + table.remove(self.coroutines, self.iterator + 1) + end +end + +-- Add a raw coroutine to the process +function ScriptProcess:add_coroutine(co) + if DEBUG then + print( + "* Adding coroutine " .. tostring(co) + .. " to " .. self.name + .. " script process" + ) + end + + table.insert(self.coroutines, co) +end + +-- Add a function to the process as a coroutine +function ScriptProcess:add_function(f) + if DEBUG then + print( + "* Adding function " .. tostring(f) + .. " to " .. self.name + .. " script process" + ) + end + + self:add_coroutine(coroutine.create(f)) +end + +-- Add a string of source code to the script process +function ScriptProcess:add_string(src) + if DEBUG then + print( + "* Adding string ".. src .. " to " .. self.name .. " script process" + ) + end + + self:add_function(loadstring(src, nil, "console command")) +end + +-- Add a package's main function to the process by name +-- Optionally force-reloading it +function ScriptProcess:add_script(script_name, reload) + if DEBUG then + print("* Adding script ".. script_name .. " to " .. self.name .. " script process") + end + + self:add_function( + function() + if reload then + package.loaded[script_name] = nil + end + + local res = require(script_name) + + if type(res) ~= "table" then + return + end + + local main = res.main + if type(main) ~= "function" then + return + end + + main() + end + ) +end + +-- Return class as package value +return ScriptProcess diff --git a/src/engine-vs2022.sln b/src/engine-vs2022.sln index 79fb40121..9682646e9 100644 --- a/src/engine-vs2022.sln +++ b/src/engine-vs2022.sln @@ -110,8 +110,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{8EC4 ..\gamedata\scripts\class_registrator_modded_exes.script = ..\gamedata\scripts\class_registrator_modded_exes.script ..\gamedata\scripts\dxml_core.script = ..\gamedata\scripts\dxml_core.script ..\gamedata\scripts\fakelens.script = ..\gamedata\scripts\fakelens.script + ..\gamedata\scripts\imgui_helper.script = ..\gamedata\scripts\imgui_helper.script + ..\gamedata\scripts\init.lua = ..\gamedata\scripts\init.lua ..\gamedata\scripts\ltx_help_ex.script = ..\gamedata\scripts\ltx_help_ex.script ..\gamedata\scripts\lua_help_ex.script = ..\gamedata\scripts\lua_help_ex.script + ..\gamedata\scripts\lua_help_imgui.script = ..\gamedata\scripts\lua_help_imgui.script ..\gamedata\scripts\modxml_inject_keybinds.script = ..\gamedata\scripts\modxml_inject_keybinds.script ..\gamedata\scripts\modxml_test.script = ..\gamedata\scripts\modxml_test.script ..\gamedata\scripts\options_builder.script = ..\gamedata\scripts\options_builder.script @@ -251,6 +254,20 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imgui", "3rd party\imgui\im {A0F7D1FB-59A7-4717-A7E4-96F37E91998E} = {A0F7D1FB-59A7-4717-A7E4-96F37E91998E} EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "amx", "amx", "{04EC24DC-AB94-4F19-8056-23DE855052D7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "boot", "boot", "{2B4D82D1-8DFD-4CF4-A8B5-923ED00EFFC1}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7188B178-0BAC-4DB1-80EE-0B3C32775905}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "xr", "xr", "{277AEE51-4F38-46F9-BF6E-78F198D718B5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lua", "lua", "{EC96D3E8-1D33-4EAD-9D67-01A07903C3FC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lua", "lua", "{3CC5A577-05F4-4C38-946B-FB99F37CCA19}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "processes", "processes", "{96150BF0-7065-45D8-8ACB-47D2B6646849}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution DX10|x64 = DX10|x64 @@ -1053,6 +1070,13 @@ Global {44A08F7F-E393-4E0B-B9E6-94AF30774CE7} = {8537520E-5391-4DA0-A369-D7B22852C696} {91413BC1-731E-470B-AA8C-8C1F6290D8D7} = {44A08F7F-E393-4E0B-B9E6-94AF30774CE7} {D0843040-7706-4FBF-A931-582748BAFBB1} = {2BFC806B-CE92-4EA4-8FE8-5F2EA54BA348} + {04EC24DC-AB94-4F19-8056-23DE855052D7} = {8EC462FD-D22E-90A8-E5CE-7E832BA40C5D} + {2B4D82D1-8DFD-4CF4-A8B5-923ED00EFFC1} = {8EC462FD-D22E-90A8-E5CE-7E832BA40C5D} + {7188B178-0BAC-4DB1-80EE-0B3C32775905} = {8EC462FD-D22E-90A8-E5CE-7E832BA40C5D} + {277AEE51-4F38-46F9-BF6E-78F198D718B5} = {8EC462FD-D22E-90A8-E5CE-7E832BA40C5D} + {EC96D3E8-1D33-4EAD-9D67-01A07903C3FC} = {04EC24DC-AB94-4F19-8056-23DE855052D7} + {3CC5A577-05F4-4C38-946B-FB99F37CCA19} = {277AEE51-4F38-46F9-BF6E-78F198D718B5} + {96150BF0-7065-45D8-8ACB-47D2B6646849} = {277AEE51-4F38-46F9-BF6E-78F198D718B5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {76CF157A-A169-443B-AE3A-F17AD29325C6} diff --git a/src/xrGame/Inventory.cpp b/src/xrGame/Inventory.cpp index c83accaa7..59aa5cdde 100644 --- a/src/xrGame/Inventory.cpp +++ b/src/xrGame/Inventory.cpp @@ -1265,7 +1265,7 @@ CInventoryItem* CInventory::tpfGetObjectByIndex(int iIndex) } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "invalid inventory index!"); + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "invalid inventory index!"); return (0); } R_ASSERT(false); diff --git a/src/xrGame/Level.cpp b/src/xrGame/Level.cpp index 869b04bc9..bec44df7b 100644 --- a/src/xrGame/Level.cpp +++ b/src/xrGame/Level.cpp @@ -15,7 +15,6 @@ #include "ShootingObject.h" #include "GameTaskManager.h" #include "Level_Bullet_Manager.h" -#include "script_process.h" #include "script_engine.h" #include "script_engine_space.h" #include "team_base_zone.h" @@ -253,8 +252,6 @@ CLevel::~CLevel() xr_delete(m_autosave_manager); xr_delete(m_debug_renderer); delete_data(m_debug_render_queue); - if (!g_dedicated_server) - ai().script_engine().remove_script_process(ScriptEngine::eScriptProcessorLevel); xr_delete(game); xr_delete(game_events); xr_delete(m_pBulletManager); @@ -729,8 +726,10 @@ void CLevel::OnFrame() #endif g_pGamePersistent->Environment().SetGameTime(GetEnvironmentGameDayTimeSec(), game->GetEnvironmentGameTimeFactor()); - if (!g_dedicated_server) - ai().script_engine().script_process(ScriptEngine::eScriptProcessorLevel)->update(); + + if (!g_dedicated_server && ai().script_engine().script_processes().has("level")) + ai().script_engine().script_processes().get("level").update(); + m_ph_commander->update(); m_ph_commander_scripts->update(); Device.Statistic->TEST0.Begin(); diff --git a/src/xrGame/Level_load.cpp b/src/xrGame/Level_load.cpp index bccd55c9b..f9153acaa 100644 --- a/src/xrGame/Level_load.cpp +++ b/src/xrGame/Level_load.cpp @@ -2,7 +2,6 @@ #include "LevelGameDef.h" #include "ai_space.h" #include "ParticlesObject.h" -#include "script_process.h" #include "script_engine.h" #include "script_engine_space.h" #include "level.h" @@ -161,20 +160,6 @@ bool CLevel::Load_GameSpecific_After() } } - if (!g_dedicated_server) - { - // loading scripts - ai().script_engine().remove_script_process(ScriptEngine::eScriptProcessorLevel); - - if (pLevel->section_exist("level_scripts") && pLevel->line_exist("level_scripts", "script")) - ai().script_engine().add_script_process(ScriptEngine::eScriptProcessorLevel, - xr_new( - "level", pLevel->r_string("level_scripts", "script"))); - else - ai().script_engine().add_script_process(ScriptEngine::eScriptProcessorLevel, - xr_new("level", "")); - } - BlockCheatLoad(); g_pGamePersistent->Environment().SetGameTime(GetEnvironmentGameDayTimeSec(), game->GetEnvironmentGameTimeFactor()); diff --git a/src/xrGame/ai/stalker/ai_stalker_script_entity.cpp b/src/xrGame/ai/stalker/ai_stalker_script_entity.cpp index 796eeff0c..852fa657e 100644 --- a/src/xrGame/ai/stalker/ai_stalker_script_entity.cpp +++ b/src/xrGame/ai/stalker/ai_stalker_script_entity.cpp @@ -251,7 +251,7 @@ bool CAI_Stalker::bfAssignObject(CScriptEntityAction* tpEntityAction) l_tObjectAction.m_bCompleted = true; } else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "cannot reload active item because it is not selected!"); // if (inventory().ActiveItem()) { @@ -306,7 +306,7 @@ bool CAI_Stalker::bfAssignObject(CScriptEntityAction* tpEntityAction) { if (inventory().GetItemFromInventory(*l_tObjectAction.m_tpObject->cName())) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "item is already in the inventory!"); return ((l_tObjectAction.m_bCompleted = true) == false); } @@ -318,7 +318,7 @@ bool CAI_Stalker::bfAssignObject(CScriptEntityAction* tpEntityAction) { if (!inventory().GetItemFromInventory(*l_tObjectAction.m_tpObject->cName())) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "item is not in the inventory!"); + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "item is not in the inventory!"); return ((l_tObjectAction.m_bCompleted = true) == false); } DropItemSendMessage(l_tObjectAction.m_tpObject); diff --git a/src/xrGame/ai_space.cpp b/src/xrGame/ai_space.cpp index b0022b3ea..d35473ee7 100644 --- a/src/xrGame/ai_space.cpp +++ b/src/xrGame/ai_space.cpp @@ -67,11 +67,6 @@ void CAI_Space::init() VERIFY(!m_script_engine); m_script_engine = xr_new(); script_engine().init(); - -#ifndef NO_SINGLE - extern string4096 g_ca_stdout; - setvbuf(stderr, g_ca_stdout,_IOFBF, sizeof(g_ca_stdout)); -#endif //#ifndef NO_SINGLE } CAI_Space::~CAI_Space() diff --git a/src/xrGame/console_commands.cpp b/src/xrGame/console_commands.cpp index 65c717d58..14b457d5a 100644 --- a/src/xrGame/console_commands.cpp +++ b/src/xrGame/console_commands.cpp @@ -7,7 +7,6 @@ #include "xrMessages.h" #include "xrserver.h" #include "level.h" -#include "script_debugger.h" #include "ai_debug.h" #include "alife_simulator.h" #include "game_cl_base.h" @@ -20,7 +19,6 @@ #include "customzone.h" #include "script_engine.h" #include "script_engine_space.h" -#include "script_process.h" #include "xrServer_Objects.h" #include "ui/UIMainIngameWnd.h" //#include "../xrphysics/PhysicsGamePars.h" @@ -1673,8 +1671,8 @@ class CCC_Script : public IConsole_Command P->m_Flags.set(FS_Path::flNeedRescan, TRUE); FS.rescan_pathes(); // run script - if (ai().script_engine().script_process(ScriptEngine::eScriptProcessorLevel)) - ai().script_engine().script_process(ScriptEngine::eScriptProcessorLevel)->add_script(args, false, true); + if (ai().script_engine().script_processes().has("level")) + ai().script_engine().script_processes().get("level").add_script(args, true); } } @@ -1700,33 +1698,22 @@ class CCC_ScriptCommand : public IConsole_Command virtual void Execute(LPCSTR args) { + // Early out if no arguments were provided if (!xr_strlen(args)) - Log("* Specify string to run!"); - else { - if (ai().script_engine().script_process(ScriptEngine::eScriptProcessorLevel)) - { - ai().script_engine().script_process(ScriptEngine::eScriptProcessorLevel)->add_script(args, true, true); - return; - } - - string4096 S; - shared_str m_script_name = "console command"; - xr_sprintf(S, "%s\n", args); - int l_iErrorCode = luaL_loadbuffer(ai().script_engine().lua(), S, xr_strlen(S), "@console_command"); - if (!l_iErrorCode) - { - l_iErrorCode = lua_pcall(ai().script_engine().lua(), 0, 0, 0); - if (l_iErrorCode) - { - ai().script_engine().print_output(ai().script_engine().lua(), *m_script_name, l_iErrorCode); - ai().script_engine().on_error(ai().script_engine().lua()); - return; - } - } + Log("* Specify string to run!"); + return; + } - ai().script_engine().print_output(ai().script_engine().lua(), *m_script_name, l_iErrorCode); + // If we have a level script processor, use it to run the command as a coroutine + if (ai().script_engine().script_processes().has("level")) + { + ai().script_engine().script_processes().get("level").add_string(args); + return; } + + // Otherwise, + ai().script_engine().do_string(args, "console command"); } //void Execute virtual void Status(TStatus& S) @@ -1749,6 +1736,20 @@ class CCC_ScriptCommand : public IConsole_Command IConsole_Command::fill_tips(tips, mode); } }; + +class CCC_EvalCommand : public CCC_ScriptCommand +{ +public: + CCC_EvalCommand(LPCSTR N) : CCC_ScriptCommand(N) {} + + virtual void Execute(LPCSTR args) + { + string4096 S; + xr_sprintf(S, "print(%s)", args); + CCC_ScriptCommand::Execute(S); + } +}; + class CCC_FreezeTime : public IConsole_Command { public: @@ -2521,7 +2522,7 @@ void CCC_RegisterCommands() CMD3(CCC_Mask, "g_unlimitedammo", &psActorFlags, AF_UNLIMITEDAMMO); CMD1(CCC_Script, "run_script"); CMD1(CCC_ScriptCommand, "run_string"); - CMD1(CCC_TimeFactor, "time_factor"); + CMD1(CCC_EvalCommand, "eval"); #endif // DEBUG /* AVO: changing restriction to -dbg key instead of DEBUG */ @@ -2534,6 +2535,7 @@ void CCC_RegisterCommands() CMD3(CCC_Mask, "g_unlimitedammo", &psActorFlags, AF_UNLIMITEDAMMO); CMD1(CCC_Script, "run_script"); CMD1(CCC_ScriptCommand, "run_string"); + CMD1(CCC_EvalCommand, "eval"); //CMD3(CCC_Mask, "g_no_clip", &psActorFlags, AF_NO_CLIP); CMD1(CCC_PHGravity, "ph_gravity"); CMD3(CCC_Mask, "log_missing_ini", &FS.m_Flags, FS.flPrintLTX); diff --git a/src/xrGame/fs_registrator_script.cpp b/src/xrGame/fs_registrator_script.cpp index 5f775e77d..65943ae54 100644 --- a/src/xrGame/fs_registrator_script.cpp +++ b/src/xrGame/fs_registrator_script.cpp @@ -131,8 +131,8 @@ class FS_file_list_ex FS_file_list_ex::FS_file_list_ex(LPCSTR path, u32 flags, LPCSTR mask) { FS_Path* P = FS.get_path(path); - P->m_Flags.set(FS_Path::flNeedRescan,TRUE); - FS.m_Flags.set(CLocatorAPI::flNeedCheck,TRUE); + P->m_Flags.set(FS_Path::flNeedRescan, !(flags & FS_RootOnly)); + FS.m_Flags.set(CLocatorAPI::flNeedCheck, flags & FS_RootOnly); FS.rescan_pathes(); FS_FileSet files; diff --git a/src/xrGame/game_sv_base.cpp b/src/xrGame/game_sv_base.cpp index 6d52f1eba..b3fae4a4b 100644 --- a/src/xrGame/game_sv_base.cpp +++ b/src/xrGame/game_sv_base.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" #include "LevelGameDef.h" -#include "script_process.h" #include "xrServer_Objects_ALife_Monsters.h" #include "script_engine.h" #include "script_engine_space.h" @@ -448,27 +447,6 @@ void game_sv_GameState::Create(shared_str& options) FS.r_close(F); } - if (!g_dedicated_server) - { - // loading scripts - ai().script_engine().remove_script_process(ScriptEngine::eScriptProcessorGame); - string_path S; - FS.update_path(S, "$game_config$", "script.ltx"); - CInifile* l_tpIniFile = xr_new(S); - R_ASSERT(l_tpIniFile); - - if (l_tpIniFile->section_exist(type_name())) - if (l_tpIniFile->r_string(type_name(), "script")) - ai().script_engine().add_script_process(ScriptEngine::eScriptProcessorGame, - xr_new( - "game", l_tpIniFile->r_string(type_name(), "script"))); - else - ai().script_engine().add_script_process(ScriptEngine::eScriptProcessorGame, - xr_new("game", "")); - - xr_delete(l_tpIniFile); - } - //--------------------------------------------------------------------- ConsoleCommands_Create(); //--------------------------------------------------------------------- @@ -669,11 +647,9 @@ void game_sv_GameState::Update() if (!g_dedicated_server) { - if (Level().game) + if (Level().game && ai().script_engine().script_processes().has("game")) { - CScriptProcess* script_process = ai().script_engine().script_process(ScriptEngine::eScriptProcessorGame); - if (script_process) - script_process->update(); + ai().script_engine().script_processes().get("game").update(); } } } @@ -700,7 +676,7 @@ game_sv_GameState::game_sv_GameState() game_sv_GameState::~game_sv_GameState() { if (!g_dedicated_server) - ai().script_engine().remove_script_process(ScriptEngine::eScriptProcessorGame); + ai().script_engine().script_processes().remove("game"); xr_delete(m_event_queue); SaveMapList(); diff --git a/src/xrGame/level_script.cpp b/src/xrGame/level_script.cpp index ac115b0ce..09ab83df2 100644 --- a/src/xrGame/level_script.cpp +++ b/src/xrGame/level_script.cpp @@ -991,7 +991,7 @@ int g_get_general_goodwill_between(u16 from, u16 to) if (!from_obj || !to_obj) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "RELATION_REGISTRY::get_general_goodwill_between : cannot convert obj to CSE_ALifeTraderAbstract!"); return (0); } diff --git a/src/xrGame/relation_registry.cpp b/src/xrGame/relation_registry.cpp index 5703aa719..4ee23d7cf 100644 --- a/src/xrGame/relation_registry.cpp +++ b/src/xrGame/relation_registry.cpp @@ -167,7 +167,7 @@ void RELATION_REGISTRY::ForceSetGoodwill(u16 from, u16 to, CHARACTER_GOODWILL go if (!from_obj || !to_obj) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "RELATION_REGISTRY::ForceSetGoodwill : cannot convert obj to CSE_ALifeTraderAbstract!"); return; } diff --git a/src/xrGame/script_bind_macroses.h b/src/xrGame/script_bind_macroses.h index 10175dfc8..520631221 100644 --- a/src/xrGame/script_bind_macroses.h +++ b/src/xrGame/script_bind_macroses.h @@ -22,7 +22,7 @@ #define CAST_OBJECT(Z,A,B)\ B *l_tpEntity = smart_cast(Z);\ if (!l_tpEntity) {\ - ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"%s : cannot access class member %s!",#B,#A); + ai().script_engine().script_log (ScriptEngine::eLuaMessageTypeError,"%s : cannot access class member %s!",#B,#A); #define CAST_OBJECT0(Z,A,B)\ CAST_OBJECT(Z,A,B)\ diff --git a/src/xrGame/script_binder.cpp b/src/xrGame/script_binder.cpp index 268069089..b6654e70b 100644 --- a/src/xrGame/script_binder.cpp +++ b/src/xrGame/script_binder.cpp @@ -93,7 +93,7 @@ void CScriptBinder::reload(LPCSTR section) luabind::functor lua_function; if (!ai().script_engine().functor(pSettings->r_string(section, "script_binding"), lua_function)) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "function %s is not loaded!", + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "function %s is not loaded!", pSettings->r_string(section, "script_binding")); return; } diff --git a/src/xrGame/script_engine_help.cpp b/src/xrGame/script_engine_help.cpp deleted file mode 100644 index 5cd80d8a6..000000000 --- a/src/xrGame/script_engine_help.cpp +++ /dev/null @@ -1,300 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_engine_help.cpp -// Created : 01.04.2004 -// Modified : 01.04.2004 -// Author : Dmitriy Iassenev -// Description : Script Engine help -//////////////////////////////////////////////////////////////////////////// - -#include "pch_script.h" - -#ifdef DEBUG - -#ifndef BOOST_NO_STRINGSTREAM -//# include -#else -//# include -#endif - -xr_string to_string (luabind::object const& o) -{ - using namespace luabind; - if (o.type() == LUA_TSTRING) return object_cast(o).c_str(); - lua_State* L = o.lua_state(); - LUABIND_CHECK_STACK(L); - - if (o.type() == LUA_TNUMBER) - { - char buffer[_CVTBUFSIZE]; - _gcvt_s( buffer, object_cast(o), 16); - return buffer; - } - - return xr_string("<") + lua_typename(L, o.type()) + ">"; -} - -void strreplaceall (xr_string &str, LPCSTR S, LPCSTR N) -{ - LPCSTR A; - int S_len = xr_strlen(S); - while ((A = strstr(str.c_str(),S)) != 0) - str.replace(A - str.c_str(),S_len,N); -} - -xr_string &process_signature (xr_string &str) -{ - strreplaceall (str,"custom [",""); - strreplaceall (str,"]",""); - strreplaceall (str,"float","number"); - strreplaceall (str,"lua_State*, ",""); - strreplaceall (str," ,lua_State*",""); - return (str); -} - -xr_string member_to_string (luabind::object const& e, LPCSTR function_signature) -{ -#if 1 || !defined(LUABIND_NO_ERROR_CHECKING) - using namespace luabind; - lua_State* L = e.lua_state(); - LUABIND_CHECK_STACK(L); - - if (e.type() == LUA_TFUNCTION) - { - e.pushvalue(); - detail::stack_pop p(L, 1); - - { - if (lua_getupvalue(L, -1, 3) == 0) return to_string(e); - detail::stack_pop p2(L, 1); - if (lua_touserdata(L, -1) != reinterpret_cast(0x1337)) return to_string(e); - } - -// #ifdef BOOST_NO_STRINGSTREAM -// std::strstream s; -// #else -// std::stringstream s; -// #endif - xr_string s = ""; - - { - lua_getupvalue(L, -1, 2); - detail::stack_pop p2(L, 1); - } - - { - lua_getupvalue(L, -1, 1); - detail::stack_pop p2(L, 1); - detail::method_rep* m = static_cast(lua_touserdata(L, -1)); - - for (std::vector::const_iterator i = m->overloads().begin(); - i != m->overloads().end(); ++i) - { - luabind::internal_string str; - i->get_signature(L, str); - if (i != m->overloads().begin()) - s += "\n"; - - xr_string xr_str(str.c_str()); - s += function_signature + process_signature(xr_str) + ";"; - } - } -#ifdef BOOST_NO_STRINGSTREAM - s += "\n";// std::ends; -#endif - return s; - } - - return to_string(e); -#else - return ""; -#endif -} - -void print_class (lua_State *L, luabind::detail::class_rep *crep) -{ - xr_string S; - // print class and bases - { - S = (crep->get_class_type() != luabind::detail::class_rep::cpp_class) ? "LUA class " : "C++ class "; - S.append (crep->name()); - typedef luabind::internal_vector BASES; - const BASES &bases = crep->bases(); - BASES::const_iterator I = bases.begin(), B = I; - BASES::const_iterator E = bases.end(); - if (B != E) - S.append (" : "); - for ( ; I != E; ++I) { - if (I != B) - S.append(","); - S.append ((*I).base->name()); - } - Msg ("%s {",S.c_str()); - } - // print class constants - { - const luabind::detail::class_rep::STATIC_CONSTANTS &constants = crep->static_constants(); - luabind::detail::class_rep::STATIC_CONSTANTS::const_iterator I = constants.begin(); - luabind::detail::class_rep::STATIC_CONSTANTS::const_iterator E = constants.end(); - for ( ; I != E; ++I) -#ifndef USE_NATIVE_LUA_STRINGS - Msg (" const %s = %d;",(*I).first,(*I).second); -#else - Msg (" const %s = %d;",getstr((*I).first.m_object),(*I).second); -#endif - if (!constants.empty()) - Msg (" "); - } - // print class properties - { -#ifndef USE_NATIVE_LUA_STRINGS - typedef luabind::internal_map PROPERTIES; -#else - typedef luabind::detail::class_rep::callback_map PROPERTIES; -#endif - const PROPERTIES &properties = crep->properties(); - PROPERTIES::const_iterator I = properties.begin(); - PROPERTIES::const_iterator E = properties.end(); - for ( ; I != E; ++I) -#ifndef USE_NATIVE_LUA_STRINGS - Msg (" property %s;",(*I).first); -#else - Msg (" property %s;",getstr((*I).first.m_object)); -#endif - if (!properties.empty()) - Msg (" "); - } - // print class constructors - { - typedef luabind::internal_vector Constructors; - const Constructors &constructors = crep->constructors().overloads; - Constructors::const_iterator I = constructors.begin(); - Constructors::const_iterator E = constructors.end(); - for ( ; I != E; ++I) { - luabind::internal_string luaS; - (*I).get_signature(L,luaS); - xr_string S(luaS.c_str()); - strreplaceall (S,"custom [",""); - strreplaceall (S,"]",""); - strreplaceall (S,"float","number"); - strreplaceall (S,"lua_State*, ",""); - strreplaceall (S," ,lua_State*",""); - Msg (" %s %s;",crep->name(),S.c_str()); - } - if (!constructors.empty()) - Msg (" "); - } - // print class methods - { - crep->get_table (L); - luabind::object table(L); - table.set (); - for (luabind::object::iterator i = table.begin(); i != table.end(); ++i) { - luabind::object object = *i; - xr_string S; - S = " function "; - S.append (to_string(i.key()).c_str()); - - strreplaceall (S,"function __add","operator +"); - strreplaceall (S,"function __sub","operator -"); - strreplaceall (S,"function __mul","operator *"); - strreplaceall (S,"function __div","operator /"); - strreplaceall (S,"function __pow","operator ^"); - strreplaceall (S,"function __lt","operator <"); - strreplaceall (S,"function __le","operator <="); - strreplaceall (S,"function __gt","operator >"); - strreplaceall (S,"function __ge","operator >="); - strreplaceall (S,"function __eq","operator =="); - Msg ("%s",member_to_string(object,S.c_str()).c_str()); - } - } - Msg ("};\n"); -} - -void print_free_functions (lua_State *L, const luabind::object &object, LPCSTR header, const xr_string &indent) -{ - u32 count = 0; - luabind::object::iterator I = object.begin(); - luabind::object::iterator E = object.end(); - for ( ; I != E; ++I) { - if ((*I).type() != LUA_TFUNCTION) - continue; - (*I).pushvalue(); - luabind::detail::free_functions::function_rep* rep = 0; - if (lua_iscfunction(L, -1)) - { - if (lua_getupvalue(L, -1, 2) != 0) - { - // check the magic number that identifies luabind's functions - if (lua_touserdata(L, -1) == (void*)0x1337) - { - if (lua_getupvalue(L, -2, 1) != 0) - { - if (!count) - Msg("\n%snamespace %s {",indent.c_str(),header); - ++count; - rep = static_cast(lua_touserdata(L, -1)); - std::vector::const_iterator i = rep->overloads().begin(); - std::vector::const_iterator e = rep->overloads().end(); - for ( ; i != e; ++i) { - luabind::internal_string luaS; - (*i).get_signature(L,luaS); - xr_string S(luaS.c_str()); - Msg(" %sfunction %s%s;",indent.c_str(),rep->name(),process_signature(S).c_str()); - } - lua_pop(L, 1); - } - } - lua_pop(L, 1); - } - } - lua_pop(L, 1); - } - { - xr_string _indent = indent; - _indent.append (" "); - object.pushvalue(); - lua_pushnil (L); - while (lua_next(L, -2) != 0) { - if (lua_type(L, -1) == LUA_TTABLE) { - LPCSTR S = lua_tostring(L, -2); - if (xr_strcmp("_G",S) && xr_strcmp("package",S)) { - luabind::object object(L); - object.set (); - if (!xr_strcmp("security",S)) { - S = S; - } - print_free_functions(L,object,S,_indent); - } - } -#pragma todo("Dima to Dima : Remove this hack if find out why") - if (lua_isnumber(L,-2)) { - lua_pop(L,1); - lua_pop(L,1); - break; - } - lua_pop (L, 1); - } - } - if (count) - Msg("%s};",indent.c_str()); -} - -void print_help (lua_State *L) -{ - Msg ("\nList of the classes exported to LUA\n"); - luabind::detail::class_registry::get_registry(L)->iterate_classes(L,&print_class); - Msg ("End of list of the classes exported to LUA\n"); - Msg ("\nList of the namespaces exported to LUA\n"); - print_free_functions(L,luabind::get_globals(L),"",""); - Msg ("End of list of the namespaces exported to LUA\n"); -} -#else -void print_help(lua_State* L) -{ - Msg("! Release build doesn't support lua-help :("); -} -#endif - -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// diff --git a/src/xrGame/script_game_object.cpp b/src/xrGame/script_game_object.cpp index 9fb3447b5..029a71052 100644 --- a/src/xrGame/script_game_object.cpp +++ b/src/xrGame/script_game_object.cpp @@ -49,6 +49,8 @@ #include "player_hud.h" #include "script_attachment_manager.h" +using namespace ScriptEngine; + class CScriptBinderObject; ////////////////////////////////////////////////////////////////////////// @@ -182,7 +184,7 @@ void CScriptGameObject::ResetActionQueue() { CScriptEntity* l_tpScriptMonster = smart_cast(&object()); if (!l_tpScriptMonster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member ResetActionQueue!"); else l_tpScriptMonster->ClearActionQueue(); @@ -192,7 +194,7 @@ CScriptEntityAction* CScriptGameObject::GetCurrentAction() const { CScriptEntity* l_tpScriptMonster = smart_cast(&object()); if (!l_tpScriptMonster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member GetCurrentAction!"); else if (l_tpScriptMonster->GetCurrentAction()) return (xr_new(l_tpScriptMonster->GetCurrentAction())); @@ -203,7 +205,7 @@ void CScriptGameObject::AddAction(const CScriptEntityAction* tpEntityAction, boo { CScriptEntity* l_tpScriptMonster = smart_cast(&object()); if (!l_tpScriptMonster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member AddAction!"); else l_tpScriptMonster->AddAction(tpEntityAction, bHighPriority); @@ -214,7 +216,7 @@ const CScriptEntityAction* CScriptGameObject::GetActionByIndex(u32 action_index) CScriptEntity* l_tpScriptMonster = smart_cast(&object()); if (!l_tpScriptMonster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptEntity : cannot access class member GetActionByIndex!"); return (0); } @@ -245,7 +247,7 @@ CHelicopter* CScriptGameObject::get_helicopter() CHelicopter* helicopter = smart_cast(&object()); if (!helicopter) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member get_helicopter!"); NODEFAULT; } @@ -257,7 +259,7 @@ CHangingLamp* CScriptGameObject::get_hanging_lamp() CHangingLamp* lamp = smart_cast(&object()); if (!lamp) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CGameObject : it is not a lamp!"); + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : it is not a lamp!"); NODEFAULT; } return lamp; @@ -268,7 +270,7 @@ CHolderCustom* CScriptGameObject::get_custom_holder() CHolderCustom* holder = smart_cast(&object()); if (!holder) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CGameObject : it is not a holder!"); + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : it is not a holder!"); } return holder; } @@ -286,7 +288,7 @@ LPCSTR CScriptGameObject::WhoHitName() : NULL; else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member WhoHitName()"); return NULL; } @@ -301,7 +303,7 @@ LPCSTR CScriptGameObject::WhoHitSectionName() : NULL; else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member WhoHitName()"); return NULL; } @@ -312,7 +314,7 @@ bool CScriptGameObject::CheckObjectVisibility(const CScriptGameObject* tpLuaGame CEntityAlive* entity_alive = smart_cast(&object()); if (entity_alive && !entity_alive->g_Alive()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot check visibility of dead object!"); return (false); } @@ -323,7 +325,7 @@ bool CScriptGameObject::CheckObjectVisibility(const CScriptGameObject* tpLuaGame CActor* actor = smart_cast(&object()); if (!actor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member CheckObjectVisibility!"); return (false); } @@ -351,7 +353,7 @@ void CScriptGameObject::set_previous_point(int point_index) { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member set_previous_point!"); else monster->movement().patrol().set_previous_point(point_index); @@ -361,7 +363,7 @@ void CScriptGameObject::set_start_point(int point_index) { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member set_start_point!"); else monster->movement().patrol().set_start_point(point_index); @@ -372,7 +374,7 @@ u32 CScriptGameObject::get_current_patrol_point_index() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot call [get_current_patrol_point_index()]!"); return (u32(-1)); } @@ -697,7 +699,7 @@ void CScriptGameObject::SetQueueSize(u32 queue_size) CWeaponMagazined* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeaponMagazined : cannot access class member SetQueueSize!"); return; } @@ -713,7 +715,7 @@ u32 CScriptGameObject::Cost() const CInventoryItem* inventory_item = smart_cast(&object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member Cost!"); return (false); } @@ -725,7 +727,7 @@ float CScriptGameObject::GetCondition() const CInventoryItem* inventory_item = smart_cast(&object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member GetCondition!"); return (false); } @@ -737,7 +739,7 @@ void CScriptGameObject::SetCondition(float val) CInventoryItem* inventory_item = smart_cast(&object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member SetCondition!"); return; } @@ -750,7 +752,7 @@ float CScriptGameObject::GetPowerCritical() const CInventoryItem* inventory_item = smart_cast(&object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member GetPowerCritical!"); return 0.f; } @@ -762,7 +764,7 @@ float CScriptGameObject::GetPsyFactor() const CPda* pda = smart_cast(&object()); if (!pda) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member GetPsyFactor!"); return 0.f; } @@ -774,7 +776,7 @@ void CScriptGameObject::SetPsyFactor(float val) CPda* pda = smart_cast(&object()); if (!pda) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member SetPsyFactor!"); return; } @@ -785,7 +787,7 @@ void CScriptGameObject::eat(CScriptGameObject* item) { if (!item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member eat!"); return; } @@ -793,7 +795,7 @@ void CScriptGameObject::eat(CScriptGameObject* item) CInventoryItem* inventory_item = smart_cast(&item->object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member eat!"); return; } @@ -801,7 +803,7 @@ void CScriptGameObject::eat(CScriptGameObject* item) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member eat!"); return; } @@ -814,7 +816,7 @@ bool CScriptGameObject::inside(const Fvector& position, float epsilon) const CSpaceRestrictor* space_restrictor = smart_cast(&object()); if (!space_restrictor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSpaceRestrictor : cannot access class member inside!"); return (false); } @@ -834,7 +836,7 @@ void CScriptGameObject::set_patrol_extrapolate_callback(const luabind::functor(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member set_patrol_extrapolate_callback!"); return; } @@ -847,7 +849,7 @@ void CScriptGameObject::set_patrol_extrapolate_callback(const luabind::functor(&this->object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member set_patrol_extrapolate_callback!"); return; } @@ -859,7 +861,7 @@ void CScriptGameObject::set_patrol_extrapolate_callback() CCustomMonster* monster = smart_cast(&this->object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member set_patrol_extrapolate_callback!"); return; } @@ -871,7 +873,7 @@ void CScriptGameObject::extrapolate_length(float extrapolate_length) CCustomMonster* monster = smart_cast(&this->object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member extrapolate_length!"); return; } @@ -883,7 +885,7 @@ float CScriptGameObject::extrapolate_length() const CCustomMonster* monster = smart_cast(&this->object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member extrapolate_length!"); return (0.f); } @@ -895,7 +897,7 @@ void CScriptGameObject::set_fov(float new_fov) CCustomMonster* monster = smart_cast(&this->object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member set_fov!"); return; } @@ -907,7 +909,7 @@ void CScriptGameObject::set_range(float new_range) CCustomMonster* monster = smart_cast(&this->object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member set_range!"); return; } @@ -919,14 +921,14 @@ u32 CScriptGameObject::vertex_in_direction(u32 level_vertex_id, Fvector directio CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member vertex_in_direction!"); return (u32(-1)); } if (!monster->movement().restrictions().accessible(level_vertex_id)) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster::vertex_in_direction - start vertex id is not accessible!"); return (u32(-1)); } @@ -947,7 +949,7 @@ bool CScriptGameObject::invulnerable() const CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member invulnerable!"); return (false); } @@ -960,7 +962,7 @@ void CScriptGameObject::invulnerable(bool invulnerable) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member invulnerable!"); return; } @@ -973,7 +975,7 @@ LPCSTR CScriptGameObject::get_smart_cover_description() const smart_cover::object* smart_cover_object = smart_cast(&object()); if (!smart_cover_object) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "smart_cover::object : cannot access class member get_smart_cover_description!"); return (0); } diff --git a/src/xrGame/script_game_object2.cpp b/src/xrGame/script_game_object2.cpp index 4a95ae02c..b488d43ed 100644 --- a/src/xrGame/script_game_object2.cpp +++ b/src/xrGame/script_game_object2.cpp @@ -41,18 +41,20 @@ #include "InventoryOwner.h" #include "CharacterPhysicsSupport.h" +using namespace ScriptEngine; + void CScriptGameObject::explode(u32 level_time) { CExplosive* explosive = smart_cast(&object()); if (object().H_Parent()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CExplosive : cannot explode object wiht parent!"); return; } if (!explosive) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CExplosive : cannot access class member explode!"); else { @@ -68,7 +70,7 @@ bool CScriptGameObject::active_zone_contact(u16 id) CScriptZone* script_zone = smart_cast(&object()); if (!script_zone) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptZone : cannot access class member active_zone_contact!"); return (false); } @@ -80,7 +82,7 @@ CScriptGameObject* CScriptGameObject::best_weapon() CObjectHandler* object_handler = smart_cast(&object()); if (!object_handler) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptEntity : cannot access class member best_weapon!"); return (0); } @@ -102,7 +104,7 @@ void CScriptGameObject::set_item(MonsterSpace::EObjectAction object_action) { CObjectHandler* object_handler = smart_cast(&object()); if (!object_handler) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CObjectHandler : cannot access class member set_item!"); else object_handler->set_goal(object_action); @@ -112,7 +114,7 @@ void CScriptGameObject::set_item(MonsterSpace::EObjectAction object_action, CScr { CObjectHandler* object_handler = smart_cast(&object()); if (!object_handler) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CObjectHandler : cannot access class member set_item!"); else object_handler->set_goal(object_action, lua_game_object ? &lua_game_object->object() : 0); @@ -123,7 +125,7 @@ void CScriptGameObject::set_item(MonsterSpace::EObjectAction object_action, CScr { CObjectHandler* object_handler = smart_cast(&object()); if (!object_handler) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CObjectHandler : cannot access class member set_item!"); else object_handler->set_goal(object_action, lua_game_object ? &lua_game_object->object() : 0, queue_size, @@ -135,7 +137,7 @@ void CScriptGameObject::set_item(MonsterSpace::EObjectAction object_action, CScr { CObjectHandler* object_handler = smart_cast(&object()); if (!object_handler) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CObjectHandler : cannot access class member set_item!"); else object_handler->set_goal(object_action, lua_game_object ? &lua_game_object->object() : 0, queue_size, @@ -151,13 +153,13 @@ void CScriptGameObject::play_cycle(LPCSTR anim, bool mix_in) if (m) sa->PlayCycle(m, (BOOL)mix_in); else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CGameObject : has not cycle %s", + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : has not cycle %s", anim); } } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CGameObject : is not animated object"); + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : is not animated object"); } } @@ -232,7 +234,7 @@ u32 CScriptGameObject::memory_time(const CScriptGameObject& lua_game_object) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptEntity : cannot access class member memory!"); return (0); } @@ -245,7 +247,7 @@ Fvector CScriptGameObject::memory_position(const CScriptGameObject& lua_game_obj CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptEntity : cannot access class member memory!"); return (Fvector().set(0.f, 0.f, 0.f)); } @@ -257,7 +259,7 @@ void CScriptGameObject::enable_memory_object(CScriptGameObject* game_object, boo { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member enable_memory_object!"); else monster->memory().enable(&game_object->object(), enable); @@ -268,7 +270,7 @@ const xr_vector& CScriptGameObject::not_yet_visible_object CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member not_yet_visible_objects!"); NODEFAULT; } @@ -280,7 +282,7 @@ float CScriptGameObject::visibility_threshold() const CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member visibility_threshold!"); NODEFAULT; } @@ -292,7 +294,7 @@ void CScriptGameObject::enable_vision(bool value) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CVisualMemoryManager : cannot access class member enable_vision!"); return; } @@ -304,7 +306,7 @@ bool CScriptGameObject::vision_enabled() const CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CVisualMemoryManager : cannot access class member vision_enabled!"); return (false); } @@ -316,7 +318,7 @@ void CScriptGameObject::set_sound_threshold(float value) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundMemoryManager : cannot access class member set_sound_threshold!"); return; } @@ -328,7 +330,7 @@ void CScriptGameObject::restore_sound_threshold() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundMemoryManager : cannot access class member restore_sound_threshold!"); return; } @@ -381,7 +383,7 @@ void CScriptGameObject::SetActorPosition(Fvector pos, bool bskip_collision_corre } } else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ScriptGameObject : attempt to call SetActorPosition method for non-actor object"); } @@ -399,7 +401,7 @@ void CScriptGameObject::SetNpcPosition(Fvector pos) // actor->XFORM().c = pos; } else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ScriptGameObject : attempt to call SetActorPosition method for non-CCustomMonster object"); } @@ -412,7 +414,7 @@ void CScriptGameObject::SetActorDirection(float dir, float pitch, float roll) actor->cam_Active()->Set(dir, pitch, roll); // actor->XFORM().setXYZ(0,dir,0); } else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ScriptGameObject : attempt to call SetActorDirection method for non-actor object"); } @@ -438,7 +440,7 @@ void CScriptGameObject::DisableHitMarks(bool disable) if (actor) actor->DisableHitMarks(disable); else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ScriptGameObject : attempt to call DisableHitMarks method for non-actor object"); } @@ -449,7 +451,7 @@ bool CScriptGameObject::DisableHitMarks() const return actor->DisableHitMarks(); else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ScriptGameObject : attempt to call DisableHitMarks method for non-actor object"); return false; } @@ -460,7 +462,7 @@ Fvector CScriptGameObject::GetMovementSpeed() const CActor* actor = smart_cast(&object()); if (!actor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ScriptGameObject : attempt to call GetMovementSpeed method for non-actor object"); NODEFAULT; } @@ -474,7 +476,7 @@ void CScriptGameObject::SetMovementSpeed(Fvector vel) CActor* actor = smart_cast(&object()); if (!actor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ScriptGameObject : attempt to call SetMovementSpeed method for non-actor object"); return; } @@ -496,7 +498,7 @@ void CScriptGameObject::set_ignore_monster_threshold(float ignore_monster_thresh CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_ignore_monster_threshold!"); return; } @@ -509,7 +511,7 @@ void CScriptGameObject::restore_ignore_monster_threshold() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member restore_ignore_monster_threshold!"); return; } @@ -521,7 +523,7 @@ float CScriptGameObject::ignore_monster_threshold() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member ignore_monster_threshold!"); return (0.f); } @@ -533,7 +535,7 @@ void CScriptGameObject::set_max_ignore_monster_distance(const float& max_ignore_ CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_max_ignore_monster_distance!"); return; } @@ -545,7 +547,7 @@ void CScriptGameObject::restore_max_ignore_monster_distance() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member restore_max_ignore_monster_distance!"); return; } @@ -557,7 +559,7 @@ float CScriptGameObject::max_ignore_monster_distance() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member max_ignore_monster_distance!"); return (0.f); } @@ -569,7 +571,7 @@ CCar* CScriptGameObject::get_car() CCar* car = smart_cast(&object()); if (!car) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member get_car!"); NODEFAULT; } @@ -581,7 +583,7 @@ void CScriptGameObject::debug_planner (const script_planner *planner) { CAI_Stalker *stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CAI_Stalker : cannot access class member debug_planner!"); + ai().script_engine().script_log (eLuaMessageTypeError,"CAI_Stalker : cannot access class member debug_planner!"); return; } @@ -593,7 +595,7 @@ u32 CScriptGameObject::location_on_path(float distance, Fvector* location) { if (!location) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : location_on_path -> specify destination location!"); return (u32(-1)); } @@ -601,7 +603,7 @@ u32 CScriptGameObject::location_on_path(float distance, Fvector* location) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member location_on_path!"); return (u32(-1)); } @@ -615,7 +617,7 @@ bool CScriptGameObject::is_there_items_to_pickup() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member is_there_items_to_pickup!"); return false; } @@ -713,7 +715,7 @@ CScriptGameObject* CScriptGameObject::get_talking_npc() { CInventoryOwner* pInvOwner = smart_cast(&object()); if (!pInvOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : get_talking_npc works only with CInventoryOwner!"); return nullptr; } @@ -733,14 +735,14 @@ luabind::object CScriptGameObject::get_scope_ui() { luabind::object table = luabind::newtable(ai().script_engine().lua()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : get_scope_ui works only with CWeapon object!"); return table; } auto& zoomTextureWndList = weapon->ZoomTexture()->GetChildWndList(); if (zoomTextureWndList.empty()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : get_scope_ui, no scope texture found for %s!", weapon->cNameSect().c_str()); return table; } @@ -750,7 +752,7 @@ luabind::object CScriptGameObject::get_scope_ui() { for (int i = 0; i < zoomTextureWndList.size(); i++) { CUIStatic* staticWnd = smart_cast(zoomTextureWndList[i]); if (!staticWnd) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : get_scope_ui, can't cast scope texture %d to CUIStatic for %s!", i, weapon->cNameSect().c_str()); } else { staticChildren[i + 1] = staticWnd; @@ -768,14 +770,14 @@ void CScriptGameObject::set_scope_ui(LPCSTR scope_texture) { CWeapon* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : set_scope_ui works only with CWeapon object!"); return; } auto wnd = weapon->ZoomTexture(); if (!wnd) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : set_scope_ui no scope found for %s!", weapon->cNameSect().c_str()); return; } diff --git a/src/xrGame/script_game_object3.cpp b/src/xrGame/script_game_object3.cpp index 5ae097ab0..498ec87eb 100644 --- a/src/xrGame/script_game_object3.cpp +++ b/src/xrGame/script_game_object3.cpp @@ -56,6 +56,8 @@ #include "Torch.h" #include "Flashlight.h" +using namespace ScriptEngine; + namespace MemorySpace { struct CVisibleObject; @@ -69,7 +71,7 @@ const CCoverPoint* CScriptGameObject::best_cover(const Fvector& position, const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member best_cover!"); return (0); } @@ -83,7 +85,7 @@ const CCoverPoint* CScriptGameObject::safe_cover(const Fvector& position, float CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member best_cover!"); return (0); } @@ -97,7 +99,7 @@ const xr_vector& CScriptGameObject::memory_visible_ CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member memory_visible_objects!"); NODEFAULT; } @@ -109,7 +111,7 @@ const xr_vector& CScriptGameObject::memory_sound_obje CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member memory_sound_objects!"); NODEFAULT; } @@ -121,7 +123,7 @@ const xr_vector& CScriptGameObject::memory_hit_objects( CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member memory_hit_objects!"); NODEFAULT; } @@ -132,7 +134,7 @@ void CScriptGameObject::ChangeTeam(u8 team, u8 squad, u8 group) { CCustomMonster* custom_monster = smart_cast(&object()); if (!custom_monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster: cannot access class member ChangeTeam!"); else custom_monster->ChangeTeam(team, squad, group); @@ -142,7 +144,7 @@ void CScriptGameObject::SetVisualMemoryEnabled(bool enabled) { CCustomMonster* custom_monster = smart_cast(&object()); if (!custom_monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster: cannot access class member ChangeTeam!"); else custom_monster->memory().visual().enable(enabled); @@ -160,7 +162,7 @@ CScriptGameObject* CScriptGameObject::GetEnemy() const } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member GetEnemy!"); return (0); } @@ -176,7 +178,7 @@ CScriptGameObject* CScriptGameObject::GetCorpse() const else return (0); else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member GetCorpse!"); return (0); } @@ -189,7 +191,7 @@ bool CScriptGameObject::CheckTypeVisibility(const char* section_name) return (l_tpCustomMonster->CheckTypeVisibility(section_name)); else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member CheckTypeVisibility!"); return (false); } @@ -200,7 +202,7 @@ CScriptGameObject* CScriptGameObject::GetCurrentWeapon() const CAI_Stalker* l_tpStalker = smart_cast(&object()); if (!l_tpStalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member GetCurrentWeapon!"); return (0); } @@ -213,7 +215,7 @@ void CScriptGameObject::deadbody_closed(bool status) CInventoryOwner* inventoryOwner = smart_cast(&object()); if (!inventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member deadbody_closed!"); return; } @@ -225,7 +227,7 @@ bool CScriptGameObject::deadbody_closed_status() CInventoryOwner* inventoryOwner = smart_cast(&object()); if (!inventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member deadbody_closed_status!"); return (0); } @@ -237,7 +239,7 @@ void CScriptGameObject::can_select_weapon(bool status) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member can_select_weapon!"); return; } @@ -249,7 +251,7 @@ bool CScriptGameObject::can_select_weapon() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member can_select_weapon!"); return (0); } @@ -261,7 +263,7 @@ void CScriptGameObject::deadbody_can_take(bool status) CInventoryOwner* inventoryOwner = smart_cast(&object()); if (!inventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member deadbody_can_take!"); return; } @@ -273,7 +275,7 @@ bool CScriptGameObject::deadbody_can_take_status() CInventoryOwner* inventoryOwner = smart_cast(&object()); if (!inventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member deadbody_can_take_status!"); return (0); } @@ -287,7 +289,7 @@ CScriptGameObject* CScriptGameObject::GetCurrentOutfit() const CInventoryOwner* inventoryOwner = smart_cast(&object()); if (!inventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member GetCurrentOutfit!"); return (0); } @@ -301,7 +303,7 @@ float CScriptGameObject::GetCurrentOutfitProtection(int hit_type) CInventoryOwner* inventoryOwner = smart_cast(&object()); if (!inventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member GetCurrentOutfitProtection!"); return (0); } @@ -317,7 +319,7 @@ CScriptGameObject* CScriptGameObject::GetFood() const CAI_Stalker* l_tpStalker = smart_cast(&object()); if (!l_tpStalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member GetFood!"); return (0); } @@ -330,7 +332,7 @@ CScriptGameObject* CScriptGameObject::GetMedikit() const CAI_Stalker* l_tpStalker = smart_cast(&object()); if (!l_tpStalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member GetCurrentWeapon!"); return (0); } @@ -346,7 +348,7 @@ LPCSTR CScriptGameObject::GetPatrolPathName() CScriptEntity* script_monster = smart_cast(&object()); if (!script_monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member GetPatrolPathName!"); return (""); } @@ -362,7 +364,7 @@ void CScriptGameObject::add_animation(LPCSTR animation, bool hand_usage, bool us CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member add_animation!"); return; } @@ -395,7 +397,7 @@ void CScriptGameObject::add_animation(LPCSTR animation, bool hand_usage, Fvector CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member add_animation!"); return; } @@ -427,7 +429,7 @@ void CScriptGameObject::clear_animations() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member clear_animations!"); return; } @@ -439,7 +441,7 @@ int CScriptGameObject::animation_count() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member clear_animations!"); return (-1); } @@ -466,7 +468,7 @@ void CScriptGameObject::set_patrol_path(LPCSTR path_name, const PatrolPathManage { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else stalker->movement().patrol().set_path(path_name, patrol_start_type, patrol_route_type, random); @@ -476,7 +478,7 @@ void CScriptGameObject::inactualize_patrol_path() { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else stalker->movement().patrol().make_inactual(); @@ -486,21 +488,21 @@ void CScriptGameObject::set_dest_level_vertex_id(u32 level_vertex_id) { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_dest_level_vertex_id!"); else { if (!ai().level_graph().valid_vertex_id(level_vertex_id)) { #ifdef DEBUG - ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CAI_Stalker : invalid vertex id being setup by action %s!",stalker->brain().CStalkerPlanner::current_action().m_action_name); + ai().script_engine().script_log (eLuaMessageTypeError,"CAI_Stalker : invalid vertex id being setup by action %s!",stalker->brain().CStalkerPlanner::current_action().m_action_name); #endif return; } if (!stalker->movement().restrictions().accessible(level_vertex_id)) { ai().script_engine().script_log( - ScriptStorage::eLuaMessageTypeError, + eLuaMessageTypeError, "! you are trying to setup destination for the stalker %s, which is not accessible by its restrictors in[%s] out[%s]", stalker->cName().c_str(), Level().space_restriction_manager().in_restrictions(stalker->ID()).c_str(), @@ -516,14 +518,14 @@ void CScriptGameObject::set_dest_game_vertex_id(GameGraph::_GRAPH_ID game_vertex { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_dest_game_vertex_id!"); else { if (!ai().game_graph().valid_vertex_id(game_vertex_id)) { #ifdef DEBUG - ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CAI_Stalker : invalid vertex id being setup by action %s!",stalker->brain().CStalkerPlanner::current_action().m_action_name); + ai().script_engine().script_log (eLuaMessageTypeError,"CAI_Stalker : invalid vertex id being setup by action %s!",stalker->brain().CStalkerPlanner::current_action().m_action_name); #endif return; } @@ -535,7 +537,7 @@ void CScriptGameObject::set_movement_selection_type(ESelectionType selection_typ { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_movement_selection_type!"); stalker->movement().game_selector().set_selection_type(selection_type); } @@ -545,7 +547,7 @@ CHARACTER_RANK_VALUE CScriptGameObject::GetRank() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member GetRank!"); return (CHARACTER_RANK_VALUE(0)); } @@ -557,7 +559,7 @@ void CScriptGameObject::set_desired_position() { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else stalker->movement().set_desired_position(0); @@ -567,7 +569,7 @@ void CScriptGameObject::set_desired_position(const Fvector* desired_position) { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else { @@ -580,7 +582,7 @@ void CScriptGameObject::set_desired_direction() { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else stalker->movement().set_desired_direction(0); @@ -590,18 +592,18 @@ void CScriptGameObject::set_desired_direction(const Fvector* desired_direction) { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else { if (fsimilar(desired_direction->magnitude(), 0.f)) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : [%s] set_desired_direction - you passed zero direction!", stalker->cName().c_str()); else { if (!fsimilar(desired_direction->magnitude(), 1.f)) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : [%s] set_desired_direction - you passed non-normalized direction!", stalker->cName().c_str()); } @@ -617,7 +619,7 @@ void CScriptGameObject::set_body_state(EBodyState body_state) THROW((body_state == eBodyStateStand) || (body_state == eBodyStateCrouch)); CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else stalker->movement().set_body_state(body_state); @@ -627,7 +629,7 @@ void CScriptGameObject::set_movement_type(EMovementType movement_type) { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else stalker->movement().set_movement_type(movement_type); @@ -637,7 +639,7 @@ void CScriptGameObject::set_mental_state(EMentalState mental_state) { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else { @@ -645,7 +647,7 @@ void CScriptGameObject::set_mental_state(EMentalState mental_state) if (mental_state != eMentalStateDanger) { if (stalker->brain().initialized()) { if (stalker->brain().current_action_id() == StalkerDecisionSpace::eWorldOperatorCombatPlanner) { - ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CAI_Stalker : set_mental_state is used during universal combat!, object[%s]", stalker->cName().c_str()); + ai().script_engine().script_log (eLuaMessageTypeError,"CAI_Stalker : set_mental_state is used during universal combat!, object[%s]", stalker->cName().c_str()); // return; } } @@ -659,7 +661,7 @@ void CScriptGameObject::set_path_type(MovementManager::EPathType path_type) { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else stalker->movement().set_path_type(path_type); @@ -669,7 +671,7 @@ void CScriptGameObject::set_detail_path_type(DetailPathManager::EDetailPathType { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement!"); else stalker->movement().set_detail_path_type(detail_path_type); @@ -680,7 +682,7 @@ MonsterSpace::EBodyState CScriptGameObject::body_state() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member body_state!"); return (MonsterSpace::eBodyStateStand); } @@ -692,7 +694,7 @@ MonsterSpace::EBodyState CScriptGameObject::target_body_state() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member body_state!"); return (MonsterSpace::eBodyStateStand); } @@ -704,7 +706,7 @@ MonsterSpace::EMovementType CScriptGameObject::movement_type() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement_type!"); return (MonsterSpace::eMovementTypeStand); } @@ -716,7 +718,7 @@ MonsterSpace::EMovementType CScriptGameObject::target_movement_type() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member target_movement_type!"); return (MonsterSpace::eMovementTypeStand); } @@ -728,7 +730,7 @@ MonsterSpace::EMentalState CScriptGameObject::mental_state() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member mental_state!"); return (MonsterSpace::eMentalStateDanger); } @@ -740,7 +742,7 @@ MonsterSpace::EMentalState CScriptGameObject::target_mental_state() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member mental_state!"); return (MonsterSpace::eMentalStateDanger); } @@ -752,7 +754,7 @@ MovementManager::EPathType CScriptGameObject::path_type() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member path_type!"); return (MovementManager::ePathTypeNoPath); } @@ -764,7 +766,7 @@ DetailPathManager::EDetailPathType CScriptGameObject::detail_path_type() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member detail_path_type!"); return (DetailPathManager::eDetailPathTypeSmooth); } @@ -775,7 +777,7 @@ void CScriptGameObject::set_sight(SightManager::ESightType sight_type, Fvector* { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else { @@ -793,7 +795,7 @@ void CScriptGameObject::set_sight(SightManager::ESightType sight_type, bool tors { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else stalker->sight().setup(sight_type, torso_look, path); @@ -803,7 +805,7 @@ void CScriptGameObject::set_sight(SightManager::ESightType sight_type, Fvector& { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else { @@ -821,7 +823,7 @@ void CScriptGameObject::set_sight(SightManager::ESightType sight_type, Fvector* { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else { @@ -839,7 +841,7 @@ void CScriptGameObject::set_sight(CScriptGameObject* object_to_look) { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else stalker->sight().setup(&object_to_look->object()); @@ -849,7 +851,7 @@ void CScriptGameObject::set_sight(CScriptGameObject* object_to_look, bool torso_ { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else stalker->sight().setup(&object_to_look->object(), torso_look); @@ -859,7 +861,7 @@ void CScriptGameObject::set_sight(CScriptGameObject* object_to_look, bool torso_ { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else stalker->sight().setup(&object_to_look->object(), torso_look, fire_object); @@ -869,7 +871,7 @@ void CScriptGameObject::set_sight(CScriptGameObject* object_to_look, bool torso_ { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else stalker->sight().setup(CSightAction(&object_to_look->object(), torso_look, fire_object, no_pitch)); @@ -879,7 +881,7 @@ void CScriptGameObject::set_sight(const CMemoryInfo* memory_object, bool torso_l { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSightManager : cannot access class member set_sight!"); else stalker->sight().setup(memory_object, torso_look); @@ -897,7 +899,7 @@ u32 CScriptGameObject::GetInventoryObjectCount() const return (l_tpInventoryOwner->inventory().dwfGetObjectCount()); else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member obj_count!"); return (0); } @@ -913,7 +915,7 @@ CScriptGameObject* CScriptGameObject::GetActiveItem() return (0); else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member activge_item!"); return (0); } @@ -947,7 +949,7 @@ CScriptGameObject* CScriptGameObject::GetObjectByName(LPCSTR caObjectName) const } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member object!"); return (0); } @@ -967,7 +969,7 @@ CScriptGameObject* CScriptGameObject::GetObjectByIndex(int iIndex) const } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member object!"); return (0); } @@ -1003,7 +1005,7 @@ CScriptGameObject* CScriptGameObject::GetObjectById(u16 id) const } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member object_id!"); return (0); } @@ -1099,7 +1101,7 @@ bool CScriptGameObject::weapon_strapped() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member weapon_strapped!"); return (false); } @@ -1114,7 +1116,7 @@ bool CScriptGameObject::weapon_unstrapped() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member weapon_unstrapped!"); return (false); } @@ -1128,7 +1130,7 @@ bool CScriptGameObject::path_completed() const CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member path_completed!"); return (false); } @@ -1140,7 +1142,7 @@ void CScriptGameObject::patrol_path_make_inactual() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member patrol_path_make_inactual!"); return; } @@ -1153,7 +1155,7 @@ Fvector CScriptGameObject::head_orientation() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member head_orientation!"); return (Fvector().set(flt_max,flt_max,flt_max)); } @@ -1180,7 +1182,7 @@ void CScriptGameObject::jump(const Fvector& position, float factor) CBaseMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot process jump for not a monster!"); return; } @@ -1194,7 +1196,7 @@ void CScriptGameObject::make_object_visible_somewhen(CScriptGameObject* object) CAI_Stalker* stalker = smart_cast(&this->object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member make_object_visible_somewhen!"); return; } @@ -1202,7 +1204,7 @@ void CScriptGameObject::make_object_visible_somewhen(CScriptGameObject* object) CEntityAlive* entity_alive = smart_cast(&object->object()); if (!entity_alive) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CEntityAlive : cannot access class member make_object_visible_somewhen!"); return; } @@ -1215,7 +1217,7 @@ void CScriptGameObject::sell_condition(CScriptIniFile* ini_file, LPCSTR section) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member sell_condition!"); return; } @@ -1228,7 +1230,7 @@ void CScriptGameObject::sell_condition(float friend_factor, float enemy_factor) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member sell_condition!"); return; } @@ -1247,7 +1249,7 @@ void CScriptGameObject::buy_condition(CScriptIniFile* ini_file, LPCSTR section) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member buy_condition!"); return; } @@ -1260,7 +1262,7 @@ void CScriptGameObject::buy_condition(float friend_factor, float enemy_factor) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member buy_condition!"); return; } @@ -1279,7 +1281,7 @@ void CScriptGameObject::show_condition(CScriptIniFile* ini_file, LPCSTR section) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member show_condition!"); return; } @@ -1296,7 +1298,7 @@ void CScriptGameObject::buy_supplies(CScriptIniFile* ini_file, LPCSTR section) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member buy_condition!"); return; } @@ -1312,7 +1314,7 @@ void CScriptGameObject::buy_item_condition_factor(float factor) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member buy_item_condition_factor!"); return; } @@ -1325,7 +1327,7 @@ void CScriptGameObject::buy_item_exponent(float factor) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member buy_item_exponent!"); return; } @@ -1338,7 +1340,7 @@ void CScriptGameObject::sell_item_exponent(float factor) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member sell_item_exponent!"); return; } @@ -1388,7 +1390,7 @@ LPCSTR CScriptGameObject::sound_prefix() const CCustomMonster* custom_monster = smart_cast(&object()); if (!custom_monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member sound_prefix!"); return (0); } @@ -1401,7 +1403,7 @@ void CScriptGameObject::sound_prefix(LPCSTR sound_prefix) CCustomMonster* custom_monster = smart_cast(&object()); if (!custom_monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member sound_prefix!"); return; } @@ -1413,7 +1415,7 @@ bool CScriptGameObject::is_weapon_going_to_be_strapped(CScriptGameObject const* { if (!object) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member is_weapon_going_to_be_strapped (object passed is null)!"); return false; } @@ -1421,7 +1423,7 @@ bool CScriptGameObject::is_weapon_going_to_be_strapped(CScriptGameObject const* CAI_Stalker const* stalker = smart_cast(&this->object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member is_weapon_going_to_be_strapped!"); return false; } @@ -1579,7 +1581,7 @@ void CScriptGameObject::AttachVehicle(CScriptGameObject* veh, bool bForce) if (vehicle) actor->use_HolderEx(vehicle, bForce); else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CGameObject : cannot be cast to CHolderCustom!"); + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot be cast to CHolderCustom!"); } } @@ -1811,7 +1813,7 @@ void CScriptGameObject::ForceSetAngle(Fvector ang, bool bActivate) else { LPCSTR text = "force_set_angleHPB: object %s has no physics shell!"; - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, text, object().Name()); + ai().script_engine().script_log(eLuaMessageTypeError, text, object().Name()); } } @@ -1918,7 +1920,7 @@ bool CScriptGameObject::get_enable_anomalies_pathfinding() auto stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member m_enable_anomalies_pathfinding!"); return false; } @@ -1929,7 +1931,7 @@ void CScriptGameObject::set_enable_anomalies_pathfinding(bool v) auto stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member m_enable_anomalies_pathfinding!"); return; } @@ -1940,7 +1942,7 @@ bool CScriptGameObject::get_enable_anomalies_damage() auto stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member m_enable_anomalies_damage!"); return false; } @@ -1951,7 +1953,7 @@ void CScriptGameObject::set_enable_anomalies_damage(bool v) auto stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member m_enable_anomalies_damage!"); return; } diff --git a/src/xrGame/script_game_object4.cpp b/src/xrGame/script_game_object4.cpp index bbf540738..7caba56a7 100644 --- a/src/xrGame/script_game_object4.cpp +++ b/src/xrGame/script_game_object4.cpp @@ -51,6 +51,8 @@ #include "antirad.h" #include "BottleItem.h" +using namespace ScriptEngine; + class CWeapon; ////////////////////////////////////////////////////////////////////////// @@ -62,7 +64,7 @@ bool CScriptGameObject::is_body_turning() const CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member is_turning!"); return (false); } @@ -88,7 +90,7 @@ u32 CScriptGameObject::add_sound(LPCSTR prefix, u32 max_count, ESoundTypes type, CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member add!"); return (0); } @@ -102,7 +104,7 @@ u32 CScriptGameObject::add_combat_sound(LPCSTR prefix, u32 max_count, ESoundType CAI_Stalker* const stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member add!"); return (0); } @@ -121,7 +123,7 @@ void CScriptGameObject::remove_sound(u32 internal_type) { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member add!"); else monster->sound().remove(internal_type); @@ -131,7 +133,7 @@ void CScriptGameObject::set_sound_mask(u32 sound_mask) { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member set_sound_mask!"); else { @@ -148,7 +150,7 @@ void CScriptGameObject::play_sound(u32 internal_type) { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member play!"); else monster->sound().play(internal_type); @@ -158,7 +160,7 @@ void CScriptGameObject::play_sound(u32 internal_type, u32 max_start_time) { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member play!"); else monster->sound().play(internal_type, max_start_time); @@ -168,7 +170,7 @@ void CScriptGameObject::play_sound(u32 internal_type, u32 max_start_time, u32 mi { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member play!"); else monster->sound().play(internal_type, max_start_time, min_start_time); @@ -178,7 +180,7 @@ void CScriptGameObject::play_sound(u32 internal_type, u32 max_start_time, u32 mi { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member play!"); else monster->sound().play(internal_type, max_start_time, min_start_time, max_stop_time); @@ -189,7 +191,7 @@ void CScriptGameObject::play_sound(u32 internal_type, u32 max_start_time, u32 mi { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member play!"); else monster->sound().play(internal_type, max_start_time, min_start_time, max_stop_time, min_stop_time); @@ -200,7 +202,7 @@ void CScriptGameObject::play_sound(u32 internal_type, u32 max_start_time, u32 mi { CCustomMonster* monster = smart_cast(&object()); if (!monster) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSoundPlayer : cannot access class member play!"); else monster->sound().play(internal_type, max_start_time, min_start_time, max_stop_time, min_stop_time, id); @@ -211,7 +213,7 @@ int CScriptGameObject::active_sound_count(bool only_playing) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CGameObject : cannot access class member active_sound_count!"); return (-1); } @@ -229,7 +231,7 @@ bool CScriptGameObject::wounded() const const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member wounded!"); return (false); } @@ -242,7 +244,7 @@ void CScriptGameObject::wounded(bool value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member wounded!"); return; } @@ -256,7 +258,7 @@ void CScriptGameObject::set_enable_movement_collision(bool value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot set_enable_movement_collision for non CAI_Stalker objects"); return; } @@ -269,7 +271,7 @@ CSightParams CScriptGameObject::sight_params() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member sight_params!"); CSightParams result; @@ -292,7 +294,7 @@ bool CScriptGameObject::critically_wounded() CCustomMonster* custom_monster = smart_cast(&object()); if (!custom_monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member critically_wounded!"); return (false); } @@ -418,7 +420,7 @@ void CScriptGameObject::start_particles(LPCSTR pname, LPCSTR bone) if (K->LL_GetBoneVisible(play_bone)) PP->StartParticles(pname, play_bone, Fvector().set(0, 1, 0), 9999); else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "Cant start particles, bone [%s] is not visible now", bone); } @@ -439,7 +441,7 @@ void CScriptGameObject::stop_particles(LPCSTR pname, LPCSTR bone) if (K->LL_GetBoneVisible(play_bone)) PP->StopParticles(9999, play_bone, true); else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "Cant stop particles, bone [%s] is not visible now", bone); } diff --git a/src/xrGame/script_game_object_inventory_owner.cpp b/src/xrGame/script_game_object_inventory_owner.cpp index 26ea93fe9..f6532b5cd 100644 --- a/src/xrGame/script_game_object_inventory_owner.cpp +++ b/src/xrGame/script_game_object_inventory_owner.cpp @@ -66,6 +66,8 @@ #include "Flashlight.h" #include "CharacterPhysicsSupport.h" +using namespace ScriptEngine; + bool CScriptGameObject::GiveInfoPortion(LPCSTR info_id) { CInventoryOwner* pInventoryOwner = smart_cast(&object()); @@ -231,7 +233,7 @@ void CScriptGameObject::ForEachInventoryItems(const luabind::functor& func CInventoryOwner* owner = smart_cast(&object()); if (!owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::ForEachInventoryItems non-CInventoryOwner object !!!"); return; } @@ -258,7 +260,7 @@ void CScriptGameObject::IterateInventory(luabind::functor functor, luabind CInventoryOwner* inventory_owner = smart_cast(&this->object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::IterateInventory non-CInventoryOwner object !!!"); return; } @@ -275,7 +277,7 @@ void CScriptGameObject::IterateRuck(luabind::functor functor, luabind::obj CInventoryOwner* inventory_owner = smart_cast(&this->object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::IterateRuck non-CInventoryOwner object !!!"); return; } @@ -292,7 +294,7 @@ void CScriptGameObject::IterateBelt(luabind::functor functor, luabind::obj CInventoryOwner* inventory_owner = smart_cast(&this->object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::IterateBelt non-CInventoryOwner object !!!"); return; } @@ -309,7 +311,7 @@ void CScriptGameObject::IterateInventoryBox(luabind::functor functor, luab CInventoryBox* inventory_box = smart_cast(&this->object()); if (!inventory_box) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::IterateInventoryBox non-CInventoryBox object !!!"); return; } @@ -330,7 +332,7 @@ void CScriptGameObject::MarkItemDropped(CScriptGameObject* item, bool flag) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::MarkItemDropped non-CInventoryOwner object !!!"); return; } @@ -338,7 +340,7 @@ void CScriptGameObject::MarkItemDropped(CScriptGameObject* item, bool flag) CInventoryItem* inventory_item = smart_cast(&item->object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::MarkItemDropped non-CInventoryItem object !!!"); return; } @@ -351,7 +353,7 @@ bool CScriptGameObject::MarkedDropped(CScriptGameObject* item) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::MarkedDropped non-CInventoryOwner object !!!"); return (false); } @@ -359,7 +361,7 @@ bool CScriptGameObject::MarkedDropped(CScriptGameObject* item) CInventoryItem* inventory_item = smart_cast(&item->object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::MarkedDropped non-CInventoryItem object !!!"); return (false); } @@ -372,7 +374,7 @@ void CScriptGameObject::UnloadMagazine(bool bKeepAmmo) CWeaponMagazined* weapon_magazined = smart_cast(&object()); if (!weapon_magazined) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::UnloadMagazine non-CWeaponMagazined object !!!"); return; } @@ -389,7 +391,7 @@ void CScriptGameObject::ForceUnloadMagazine(bool bKeepAmmo) CWeaponMagazined* weapon_magazined = smart_cast(&object()); if (!weapon_magazined) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::UnloadMagazine non-CWeaponMagazined object !!!"); return; } @@ -404,7 +406,7 @@ void CScriptGameObject::SetCanBeHarmed(bool state) CEntityAlive* ent = smart_cast(&object()); if (!ent) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CEntityAlive : cannot access class member set_can_be_harmed!"); return; } @@ -417,7 +419,7 @@ bool CScriptGameObject::CanBeHarmed() CEntityAlive* ent = smart_cast(&object()); if (!ent) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CEntityAlive : cannot access class member can_be_harmed!"); return false; } @@ -431,7 +433,7 @@ void CScriptGameObject::DropItem(CScriptGameObject* pItem) CInventoryItem* item = smart_cast(&pItem->object()); if (!owner || !item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::DropItem non-CInventoryOwner object !!!"); return; } @@ -483,7 +485,7 @@ void CScriptGameObject::MoveItemToRuck(CScriptGameObject* pItem) CInventoryItem* item = smart_cast(&pItem->object()); if (!owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::MoveItemToRuck non-CInventoryOwner object !!!"); return; } @@ -503,7 +505,7 @@ void CScriptGameObject::MoveItemToSlot(CScriptGameObject* pItem, u16 slot_id) CInventoryItem* item = smart_cast(&pItem->object()); if (!owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::MoveItemToSlot non-CInventoryOwner object !!!"); return; } @@ -512,7 +514,7 @@ void CScriptGameObject::MoveItemToSlot(CScriptGameObject* pItem, u16 slot_id) /* if (!owner->inventory().CanPutInSlot(item, slot_id)) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::MoveItemToSlot can't put in slot !!!"); return; } @@ -540,7 +542,7 @@ void CScriptGameObject::MoveItemToBelt(CScriptGameObject* pItem) CInventoryItem* item = smart_cast(&pItem->object()); if (!owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::MoveItemToBelt non-CInventoryOwner object !!!"); return; } @@ -560,7 +562,7 @@ void CScriptGameObject::ItemAllowTrade(CScriptGameObject* pItem) CInventoryItem* item = smart_cast(&pItem->object()); if (!owner || !item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::ItemAllowTrade non-CInventoryOwner object !!!"); return; } @@ -573,7 +575,7 @@ void CScriptGameObject::ItemDenyTrade(CScriptGameObject* pItem) CInventoryItem* item = smart_cast(&pItem->object()); if (!owner || !item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::ItemAllowTrade non-CInventoryOwner object !!!"); return; } @@ -585,7 +587,7 @@ void CScriptGameObject::TransferItem(CScriptGameObject* pItem, CScriptGameObject { if (!pItem || !pForWho) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "cannot transfer NULL item"); + ai().script_engine().script_log(eLuaMessageTypeError, "cannot transfer NULL item"); return; } @@ -593,7 +595,7 @@ void CScriptGameObject::TransferItem(CScriptGameObject* pItem, CScriptGameObject if (!pIItem) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "Cannot transfer not CInventoryItem item"); + ai().script_engine().script_log(eLuaMessageTypeError, "Cannot transfer not CInventoryItem item"); return; } @@ -613,14 +615,14 @@ void CScriptGameObject::TakeItem(CScriptGameObject* pItem) { if (!pItem) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "!CScriptGameObject::TakeItem | cannot take NULL item"); + ai().script_engine().script_log(eLuaMessageTypeError, "!CScriptGameObject::TakeItem | cannot take NULL item"); return; } CInventoryItem* pIItem = smart_cast(&pItem->object()); if (!pIItem) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "!CScriptGameObject::TakeItem | Cannot take not CInventoryItem item"); + ai().script_engine().script_log(eLuaMessageTypeError, "!CScriptGameObject::TakeItem | Cannot take not CInventoryItem item"); return; } @@ -644,7 +646,7 @@ void CScriptGameObject::TakeItem(CScriptGameObject* pItem) } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "!CScriptGameObject::TakeItem | Unknown parent type found?"); + ai().script_engine().script_log(eLuaMessageTypeError, "!CScriptGameObject::TakeItem | Unknown parent type found?"); } return; // added return here just in case parent isn't identified as inventory owner or a box @@ -665,7 +667,7 @@ void CScriptGameObject::TransferMoney(int money, CScriptGameObject* pForWho) { if (!pForWho) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "cannot transfer money for NULL object"); + ai().script_engine().script_log(eLuaMessageTypeError, "cannot transfer money for NULL object"); return; } CInventoryOwner* pOurOwner = smart_cast(&object()); @@ -675,7 +677,7 @@ void CScriptGameObject::TransferMoney(int money, CScriptGameObject* pForWho) if (pOurOwner->get_money() - money < 0) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "Character does not have enought money"); + ai().script_engine().script_log(eLuaMessageTypeError, "Character does not have enought money"); return; } @@ -700,7 +702,7 @@ int CScriptGameObject::GetGoodwill(CScriptGameObject* pToWho) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "GetGoodwill available only for InventoryOwner"); return 0; } @@ -713,7 +715,7 @@ void CScriptGameObject::SetGoodwill(int goodwill, CScriptGameObject* pWhoToSet) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetGoodwill available only for InventoryOwner"); return; } @@ -726,7 +728,7 @@ void CScriptGameObject::ForceSetGoodwill(int goodwill, CScriptGameObject* pWhoTo if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ForceSetGoodwill available only for InventoryOwner"); return; } @@ -739,7 +741,7 @@ void CScriptGameObject::ChangeGoodwill(int delta_goodwill, CScriptGameObject* pW if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ChangeGoodwill available only for InventoryOwner"); return; } @@ -754,7 +756,7 @@ void CScriptGameObject::SetRelation(ALife::ERelationType relation, CScriptGameOb if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetRelation available only for InventoryOwner"); return; } @@ -763,7 +765,7 @@ void CScriptGameObject::SetRelation(ALife::ERelationType relation, CScriptGameOb VERIFY(pOthersInventoryOwner); if (!pOthersInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetRelation available only for InventoryOwner"); return; } @@ -776,7 +778,7 @@ float CScriptGameObject::GetSympathy() if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "GetSympathy available only for InventoryOwner"); return 0.0f; } @@ -789,7 +791,7 @@ void CScriptGameObject::SetSympathy(float sympathy) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetSympathy available only for InventoryOwner"); return; } @@ -802,7 +804,7 @@ int CScriptGameObject::GetCommunityGoodwill_obj(LPCSTR community) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "GetCommunityGoodwill available only for InventoryOwner"); return 0; } @@ -818,7 +820,7 @@ void CScriptGameObject::SetCommunityGoodwill_obj(LPCSTR community, int goodwill) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetCommunityGoodwill available only for InventoryOwner"); return; } @@ -846,7 +848,7 @@ LPCSTR CScriptGameObject::ProfileName() CInventoryOwner* pInventoryOwner = smart_cast(&object()); if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ProfileName available only for InventoryOwner"); return NULL; } @@ -864,7 +866,7 @@ LPCSTR CScriptGameObject::CharacterName() if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CharacterName available only for InventoryOwner"); return NULL; } @@ -877,7 +879,7 @@ LPCSTR CScriptGameObject::CharacterIcon() if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CharacterIconName available only for InventoryOwner"); return NULL; } @@ -893,7 +895,7 @@ int CScriptGameObject::CharacterRank() CInventoryOwner* pInventoryOwner = smart_cast(&object()); if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CharacterRank available only for InventoryOwner and BaseMonster"); return 0; } @@ -910,7 +912,7 @@ luabind::object CScriptGameObject::CharacterDialogs() if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CharacterDialogs available only for InventoryOwner"); return table; } @@ -930,7 +932,7 @@ void CScriptGameObject::SetCharacterRank(int char_rank) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetCharacterRank available only for InventoryOwner"); return; } @@ -943,7 +945,7 @@ void CScriptGameObject::ChangeCharacterRank(int char_rank) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ChangeCharacterRank available only for InventoryOwner"); return; } @@ -956,7 +958,7 @@ int CScriptGameObject::CharacterReputation() if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CharacterReputation available only for InventoryOwner"); return 0; } @@ -969,7 +971,7 @@ void CScriptGameObject::ChangeCharacterReputation(int char_rep) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "ChangeCharacterReputation available only for InventoryOwner"); return; } @@ -982,7 +984,7 @@ void CScriptGameObject::SetCharacterReputation(int char_rep) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetCharacterReputation available only for InventoryOwner"); return; } @@ -995,7 +997,7 @@ LPCSTR CScriptGameObject::CharacterCommunity() if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CharacterCommunity available only for InventoryOwner"); return NULL; } @@ -1009,7 +1011,7 @@ void CScriptGameObject::SetCharacterCommunity(LPCSTR comm, int squad, int group) if (!pInventoryOwner || !entity) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetCharacterCommunity available only for InventoryOwner"); return; } @@ -1017,7 +1019,7 @@ void CScriptGameObject::SetCharacterCommunity(LPCSTR comm, int squad, int group) community.set(comm); if (community.index() < 0) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "SetCharacterCommunity failed for '%'", + ai().script_engine().script_log(eLuaMessageTypeError, "SetCharacterCommunity failed for '%'", comm); return; } @@ -1030,7 +1032,7 @@ LPCSTR CScriptGameObject::sound_voice_prefix() const CInventoryOwner* pInventoryOwner = smart_cast(&object()); if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "sound_voice_prefix available only for InventoryOwner"); return NULL; } @@ -1108,7 +1110,7 @@ void CScriptGameObject::RunTalkDialog(CScriptGameObject* pToWho, bool disable_br if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "RunTalkDialog applicable only for actor"); + ai().script_engine().script_log(eLuaMessageTypeError, "RunTalkDialog applicable only for actor"); return; } @@ -1152,7 +1154,7 @@ void CScriptGameObject::add_restrictions(LPCSTR out, LPCSTR in) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member add_restrictions!"); return; } @@ -1166,7 +1168,7 @@ void CScriptGameObject::remove_restrictions(LPCSTR out, LPCSTR in) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member remove_restrictions!"); return; } @@ -1180,7 +1182,7 @@ void CScriptGameObject::remove_all_restrictions() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member remove_all_restrictions!"); return; } @@ -1194,7 +1196,7 @@ LPCSTR CScriptGameObject::in_restrictions() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member in_restrictions!"); return (""); } @@ -1206,7 +1208,7 @@ LPCSTR CScriptGameObject::out_restrictions() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member out_restrictions!"); return (""); } @@ -1218,7 +1220,7 @@ LPCSTR CScriptGameObject::base_in_restrictions() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member base_in_restrictions!"); return (""); } @@ -1230,7 +1232,7 @@ LPCSTR CScriptGameObject::base_out_restrictions() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member base_out_restrictions!"); return (""); } @@ -1242,7 +1244,7 @@ bool CScriptGameObject::accessible_position(const Fvector& position) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member accessible!"); return (false); } @@ -1254,7 +1256,7 @@ bool CScriptGameObject::accessible_vertex_id(u32 level_vertex_id) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member accessible!"); return (false); } @@ -1270,13 +1272,13 @@ u32 CScriptGameObject::accessible_nearest(const Fvector& position, Fvector& resu CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : cannot access class member accessible!"); return (u32(-1)); } if (monster->movement().restrictions().accessible(position)) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CRestrictedObject : you use accessible_nearest when position is already accessible!"); return (u32(-1)); } @@ -1288,7 +1290,7 @@ void CScriptGameObject::enable_attachable_item(bool value) CAttachableItem* attachable_item = smart_cast(&object()); if (!attachable_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAttachableItem : cannot access class member enable_attachable_item!"); return; } @@ -1300,7 +1302,7 @@ bool CScriptGameObject::attachable_item_enabled() const CAttachableItem* attachable_item = smart_cast(&object()); if (!attachable_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAttachableItem : cannot access class member attachable_item_enabled!"); return (false); } @@ -1312,7 +1314,7 @@ void CScriptGameObject::night_vision_allowed(bool value) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member enable_night_vision!"); return; } @@ -1324,7 +1326,7 @@ void CScriptGameObject::enable_night_vision(bool value) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member enable_night_vision!"); return; } @@ -1336,7 +1338,7 @@ bool CScriptGameObject::night_vision_enabled() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member enable_night_vision!"); return (false); } @@ -1348,7 +1350,7 @@ void CScriptGameObject::enable_torch(bool value) CTorch* torch = smart_cast(&object()); if (!torch) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CTorch : cannot access class member enable_torch!"); return; } @@ -1360,7 +1362,7 @@ bool CScriptGameObject::torch_enabled() const CTorch* torch = smart_cast(&object()); if (!torch) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CTorch : cannot access class member torch_enabled!"); return (false); } @@ -1373,7 +1375,7 @@ void CScriptGameObject::update_torch() CTorch* torch = smart_cast(&object()); if (!torch) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CTorch : cannot access class member enable_torch!"); return; } @@ -1385,7 +1387,7 @@ void CScriptGameObject::attachable_item_load_attach(LPCSTR section) CAttachableItem* attachable_item = smart_cast(&object()); if (!attachable_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAttachableItem : cannot access class member attachable_item_load_attach!"); return; } @@ -1423,7 +1425,7 @@ int CScriptGameObject::Weapon_GrenadeLauncher_Status() CWeapon* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_GrenadeLauncher_Status!"); return (false); } @@ -1435,7 +1437,7 @@ int CScriptGameObject::Weapon_Scope_Status() CWeapon* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_Scope_Status!"); return (false); } @@ -1447,7 +1449,7 @@ int CScriptGameObject::Weapon_Silencer_Status() CWeapon* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_Silencer_Status!"); return (false); } @@ -1459,7 +1461,7 @@ bool CScriptGameObject::Weapon_IsGrenadeLauncherAttached() CWeapon* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_IsGrenadeLauncherAttached!"); return (false); } @@ -1471,7 +1473,7 @@ bool CScriptGameObject::Weapon_IsScopeAttached() CWeapon* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_IsScopeAttached!"); return (false); } @@ -1483,7 +1485,7 @@ bool CScriptGameObject::Weapon_IsSilencerAttached() CWeapon* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_IsSilencerAttached!"); return (false); } @@ -1500,7 +1502,7 @@ int CScriptGameObject::animation_slot() const CHudItem* hud_item = smart_cast(&object()); if (!hud_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CHudItem : cannot access class member animation_slot!"); return (u32(-1)); } @@ -1512,7 +1514,7 @@ CScriptGameObject* CScriptGameObject::active_device() const CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member active_detector!"); return (0); } @@ -1533,7 +1535,7 @@ void CScriptGameObject::show_device(bool bFast) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member show_device!"); return; } @@ -1552,7 +1554,7 @@ void CScriptGameObject::hide_device(bool bFast) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member hide_device!"); return; } @@ -1571,7 +1573,7 @@ void CScriptGameObject::force_hide_device() CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member force_hide_device!"); return; } @@ -1590,7 +1592,7 @@ CScriptGameObject* CScriptGameObject::item_in_slot(u32 slot_id) const CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member item_in_slot!"); return (0); } @@ -1626,7 +1628,7 @@ u32 CScriptGameObject::active_slot() CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member active_slot!"); return (0); } @@ -1638,7 +1640,7 @@ void CScriptGameObject::activate_slot(u32 slot_id) CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member activate_slot!"); return; } @@ -1650,7 +1652,7 @@ void CScriptGameObject::enable_movement(bool enable) CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member movement_enabled!"); return; } @@ -1663,7 +1665,7 @@ bool CScriptGameObject::movement_enabled() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member movement_enabled!"); return (false); } @@ -1676,7 +1678,7 @@ bool CScriptGameObject::can_throw_grenades() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member can_throw_grenades!"); return (false); } @@ -1689,7 +1691,7 @@ void CScriptGameObject::can_throw_grenades(bool can_throw_grenades) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member can_throw_grenades!"); return; } @@ -1702,7 +1704,7 @@ u32 CScriptGameObject::throw_time_interval() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member throw_time_interval!"); return (0); } @@ -1715,7 +1717,7 @@ void CScriptGameObject::throw_time_interval(u32 throw_time_interval) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member throw_time_interval!"); return; } @@ -1728,7 +1730,7 @@ u32 CScriptGameObject::group_throw_time_interval() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member group_throw_time_interval!"); return (0); } @@ -1741,7 +1743,7 @@ void CScriptGameObject::group_throw_time_interval(u32 throw_time_interval) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member group_throw_time_interval!"); return; } @@ -1754,7 +1756,7 @@ void CScriptGameObject::aim_time(CScriptGameObject* weapon, u32 aim_time) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member aim_time!"); return; } @@ -1762,7 +1764,7 @@ void CScriptGameObject::aim_time(CScriptGameObject* weapon, u32 aim_time) CWeapon* weapon_ = smart_cast(&weapon->object()); if (!weapon_) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member aim_time (not a weapon passed)!"); return; } @@ -1775,7 +1777,7 @@ u32 CScriptGameObject::aim_time(CScriptGameObject* weapon) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member aim_time!"); return (u32(-1)); } @@ -1783,7 +1785,7 @@ u32 CScriptGameObject::aim_time(CScriptGameObject* weapon) CWeapon* weapon_ = smart_cast(&weapon->object()); if (!weapon_) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member aim_time (not a weapon passed)!"); return (u32(-1)); } @@ -1796,7 +1798,7 @@ void CScriptGameObject::special_danger_move(bool value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member special_danger_move!"); return; } @@ -1809,7 +1811,7 @@ bool CScriptGameObject::special_danger_move() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member special_danger_move!"); return (false); } @@ -1822,7 +1824,7 @@ void CScriptGameObject::sniper_update_rate(bool value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member sniper_update_rate!"); return; } @@ -1835,7 +1837,7 @@ bool CScriptGameObject::sniper_update_rate() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member sniper_update_rate!"); return (false); } @@ -1848,7 +1850,7 @@ void CScriptGameObject::sniper_fire_mode(bool value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member sniper_fire_mode!"); return; } @@ -1861,7 +1863,7 @@ bool CScriptGameObject::sniper_fire_mode() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member sniper_fire_mode!"); return (false); } @@ -1874,7 +1876,7 @@ void CScriptGameObject::aim_bone_id(LPCSTR bone_id) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member aim_bone_id!"); return; } @@ -1887,7 +1889,7 @@ LPCSTR CScriptGameObject::aim_bone_id() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member aim_bone_id!"); return (false); } @@ -1900,7 +1902,7 @@ void CScriptGameObject::register_in_combat() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member register_in_combat!"); return; } @@ -1913,7 +1915,7 @@ void CScriptGameObject::unregister_in_combat() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member unregister_in_combat!"); return; } @@ -1926,7 +1928,7 @@ CCoverPoint const* CScriptGameObject::find_best_cover(Fvector position_to_cover_ CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member find_best_cover!"); return (0); } @@ -1938,7 +1940,7 @@ bool CScriptGameObject::suitable_smart_cover(CScriptGameObject* object) { if (!object) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker::suitable_smart_cover null smart cover specified!"); return (false); } @@ -1946,7 +1948,7 @@ bool CScriptGameObject::suitable_smart_cover(CScriptGameObject* object) CAI_Stalker* stalker = smart_cast(&this->object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member suitable_smart_cover!"); return (false); } @@ -1954,7 +1956,7 @@ bool CScriptGameObject::suitable_smart_cover(CScriptGameObject* object) smart_cover::object const* const smart_object = smart_cast(&object->object()); if (!smart_object) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : suitable_smart_cover: passed non-smart_cover object!"); return (false); } @@ -1979,7 +1981,7 @@ void CScriptGameObject::take_items_enabled(bool const value) CAI_Stalker* const stalker = smart_cast(&this->object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member take_items_enabled!"); return; } @@ -1992,7 +1994,7 @@ bool CScriptGameObject::take_items_enabled() const CAI_Stalker* stalker = smart_cast(&this->object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member take_items_enabled!"); return (false); } @@ -2005,7 +2007,7 @@ void CScriptGameObject::SetPlayShHdRldSounds(bool val) CInventoryOwner* owner = smart_cast(&object()); if (!owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member SetPlayShHdRldSounds!"); return; } @@ -2017,7 +2019,7 @@ void CScriptGameObject::death_sound_enabled(bool const value) CAI_Stalker* const stalker = smart_cast(&this->object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member death_sound_enabled!"); return; } @@ -2030,7 +2032,7 @@ bool CScriptGameObject::death_sound_enabled() const CAI_Stalker* stalker = smart_cast(&this->object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member death_sound_enabled!"); return (false); } @@ -2108,14 +2110,14 @@ void CScriptGameObject::Weapon_AddonAttach(CScriptGameObject* item) CWeaponMagazined* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeaponMagazined : cannot access class member Weapon_AddonAttach!"); return; } CInventoryItem* pItm = item->object().cast_inventory_item(); if (!pItm) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeaponMagazined : trying to attach non-CInventoryItem!"); return; } @@ -2130,7 +2132,7 @@ void CScriptGameObject::Weapon_AddonDetach(LPCSTR item_section, bool b_spawn_ite CWeaponMagazined* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeaponMagazined : cannot access class member Weapon_AddonDetach!"); return; } @@ -2146,7 +2148,7 @@ void CScriptGameObject::Weapon_SetCurrentScope(u8 type) CWeaponMagazined* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeaponMagazined : cannot access class member Weapon_SetCurrentScope!"); return; } @@ -2159,7 +2161,7 @@ u8 CScriptGameObject::Weapon_GetCurrentScope() CWeaponMagazined* weapon = smart_cast(&object()); if (!weapon) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CWeaponMagazined : cannot access class member Weapon_GetCurrentScope!"); return 255; } @@ -2171,7 +2173,7 @@ bool CScriptGameObject::InstallUpgrade(LPCSTR upgrade) CInventoryItem* item = smart_cast(&object()); if (!item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryItem : cannot access class member InstallUpgrade!"); return false; } @@ -2187,7 +2189,7 @@ bool CScriptGameObject::HasUpgrade(LPCSTR upgrade) CInventoryItem* item = smart_cast(&object()); if (!item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryItem : cannot access class member HasUpgrade!"); return false; } @@ -2220,7 +2222,7 @@ CScriptGameObject* CScriptGameObject::ItemOnBelt(u32 item_id) const CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member item_on_belt!"); return (0); } @@ -2228,7 +2230,7 @@ CScriptGameObject* CScriptGameObject::ItemOnBelt(u32 item_id) const TIItemContainer* belt = &(inventory_owner->inventory().m_belt); if (belt->size() < item_id) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "item_on_belt: item id outside belt!"); + ai().script_engine().script_log(eLuaMessageTypeError, "item_on_belt: item id outside belt!"); return (0); } @@ -2242,7 +2244,7 @@ bool CScriptGameObject::IsOnBelt(CScriptGameObject* obj) const CInventoryItem* inventory_item = smart_cast(&(obj->object())); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryItem : cannot access class member is_on_belt!"); return (0); } @@ -2250,7 +2252,7 @@ bool CScriptGameObject::IsOnBelt(CScriptGameObject* obj) const CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member is_on_belt!"); return (0); } @@ -2263,7 +2265,7 @@ u32 CScriptGameObject::BeltSize() const CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member move_to_belt!"); return (0); } @@ -2276,7 +2278,7 @@ float CScriptGameObject::GetActorMaxWeight() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorMaxWeight!"); return (false); } @@ -2288,7 +2290,7 @@ void CScriptGameObject::SetActorMaxWeight(float max_weight) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorMaxWeight!"); return; } @@ -2301,7 +2303,7 @@ float CScriptGameObject::GetActorMaxWalkWeight() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorMaxWalkWeight!"); return (false); } @@ -2313,7 +2315,7 @@ void CScriptGameObject::SetActorMaxWalkWeight(float max_walk_weight) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorMaxWalkWeight!"); return; } @@ -2328,7 +2330,7 @@ float CScriptGameObject::GetAdditionalMaxWeight() const CBackpack* pBackpack = smart_cast(&object()); if (!outfit && !pBackpack) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomOutfit : cannot access class member GetAdditionalMaxWeight!"); return (false); } @@ -2345,7 +2347,7 @@ float CScriptGameObject::GetAdditionalMaxWalkWeight() const CBackpack* pBackpack = smart_cast(&object()); if (!outfit && !pBackpack) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomOutfit : cannot access class member GetAdditionalMaxWalkWeight!"); return (false); } @@ -2361,7 +2363,7 @@ void CScriptGameObject::SetAdditionalMaxWeight(float add_max_weight) CBackpack* pBackpack = smart_cast(&object()); if (!outfit && !pBackpack) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomOutfit : cannot access class member SetAdditionalMaxWeight!"); return; } @@ -2378,7 +2380,7 @@ void CScriptGameObject::SetAdditionalMaxWalkWeight(float add_max_walk_weight) CBackpack* pBackpack = smart_cast(&object()); if (!outfit && !pBackpack) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomOutfit : cannot access class member SetAdditionalMaxWalkWeight!"); return; } @@ -2397,7 +2399,7 @@ float CScriptGameObject::GetTotalWeight() const CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member GetTotalWeight!"); return (false); } @@ -2410,7 +2412,7 @@ void CScriptGameObject::UpdateWeight() const CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member GetTotalWeightForceUpdate!"); return; } @@ -2422,7 +2424,7 @@ float CScriptGameObject::GetTotalWeightForceUpdate() const CInventoryOwner* inventory_owner = smart_cast(&object()); if (!inventory_owner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CInventoryOwner : cannot access class member GetTotalWeightForceUpdate!"); return (false); } @@ -2436,7 +2438,7 @@ float CScriptGameObject::Weight() const CInventoryItem* inventory_item = smart_cast(&object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member Weight!"); return (false); } @@ -2448,7 +2450,7 @@ void CScriptGameObject::SetWeight(float w) CInventoryItem* inventory_item = smart_cast(&object()); if (!inventory_item) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member SetWeight!"); return; } @@ -2461,7 +2463,7 @@ float CScriptGameObject::GetActorUILuminosity() CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject::GetActorLuminosity, object is not actor"); return 0.f; } @@ -2473,7 +2475,7 @@ float CScriptGameObject::GetActorJumpSpeed() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorJumpSpeed!"); return (false); } @@ -2485,7 +2487,7 @@ void CScriptGameObject::SetActorJumpSpeed(float jump_speed) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorJumpSpeed!"); return; } @@ -2498,7 +2500,7 @@ float CScriptGameObject::GetActorSprintKoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorJumpSpeed!"); return (false); } @@ -2510,7 +2512,7 @@ void CScriptGameObject::SetActorSprintKoef(float sprint_koef) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorJumpSpeed!"); return; } @@ -2522,7 +2524,7 @@ float CScriptGameObject::GetActorRunCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorJumpSpeed!"); return (false); } @@ -2534,7 +2536,7 @@ void CScriptGameObject::SetActorRunCoef(float run_coef) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorJumpSpeed!"); return; } @@ -2546,7 +2548,7 @@ float CScriptGameObject::GetActorRunBackCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorJumpSpeed!"); return (false); } @@ -2558,7 +2560,7 @@ void CScriptGameObject::SetActorRunBackCoef(float run_back_coef) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorJumpSpeed!"); return; } @@ -2570,7 +2572,7 @@ void CScriptGameObject::SetActorCamBoxYOffset(u32 box_num, float offset) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorCamBoxYOffset!"); return; } @@ -2583,7 +2585,7 @@ float CScriptGameObject::GetActorWalkAccel() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorWalkAccel!"); return (false); } @@ -2594,7 +2596,7 @@ void CScriptGameObject::SetActorWalkAccel(float val) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorWalkAccel!"); return; } @@ -2607,7 +2609,7 @@ float CScriptGameObject::GetActorWalkBackCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorWalkBackCoef!"); return (false); } @@ -2618,7 +2620,7 @@ void CScriptGameObject::SetActorWalkBackCoef(float val) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorWalkBackCoef!"); return; } @@ -2632,7 +2634,7 @@ void CScriptGameObject::SetCharacterIcon(LPCSTR iconName) if (!pInventoryOwner) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetCharacterIcon available only for InventoryOwner"); return; } @@ -2645,7 +2647,7 @@ float CScriptGameObject::GetActorLookoutCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorLookoutCoef!"); return (false); } @@ -2656,7 +2658,7 @@ void CScriptGameObject::SetActorLookoutCoef(float val) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorLookoutCoef!"); return; } @@ -2669,7 +2671,7 @@ float CScriptGameObject::GetActorCrouchCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorCrouchCoef!"); return (false); } @@ -2680,7 +2682,7 @@ void CScriptGameObject::SetActorCrouchCoef(float val) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorCrouchCoef!"); return; } @@ -2691,7 +2693,7 @@ float CScriptGameObject::GetActorClimbCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorClimbCoef!"); return (false); } @@ -2702,7 +2704,7 @@ void CScriptGameObject::SetActorClimbCoef(float val) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorClimbCoef!"); return; } @@ -2713,7 +2715,7 @@ float CScriptGameObject::GetActorWalkStrafeCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorWalkStrafeCoef!"); return (false); } @@ -2724,7 +2726,7 @@ void CScriptGameObject::SetActorWalkStrafeCoef(float val) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorWalkStrafeCoef!"); return; } @@ -2735,7 +2737,7 @@ float CScriptGameObject::GetActorRunStrafeCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorRunStrafeCoef!"); return (false); } @@ -2746,7 +2748,7 @@ void CScriptGameObject::SetActorRunStrafeCoef(float val) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorRunStrafeCoef!"); return; } @@ -2757,7 +2759,7 @@ float CScriptGameObject::GetActorSprintStrafeCoef() const CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorSprintStrafeCoef!"); return (false); } @@ -2768,7 +2770,7 @@ void CScriptGameObject::SetActorSprintStrafeCoef(float val) CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member SetActorSprintStrafeCoef!"); return; } @@ -2780,7 +2782,7 @@ CScriptGameObject* CScriptGameObject::GetActorObjectLookingAt() CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorObjectLookingAt!"); return nullptr; } @@ -2796,7 +2798,7 @@ CScriptGameObject* CScriptGameObject::GetActorPersonLookingAt() CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetActorPersonLookingAt!"); return nullptr; } @@ -2816,7 +2818,7 @@ LPCSTR CScriptGameObject::GetActorDefaultActionForObject() CActor* pActor = smart_cast(&object()); if (!pActor) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CActor : cannot access class member GetDefaultActionForObject!"); return nullptr; } diff --git a/src/xrGame/script_game_object_smart_covers.cpp b/src/xrGame/script_game_object_smart_covers.cpp index b55d63482..2d6a07672 100644 --- a/src/xrGame/script_game_object_smart_covers.cpp +++ b/src/xrGame/script_game_object_smart_covers.cpp @@ -14,12 +14,14 @@ #include "script_callback_ex.h" #include "smart_cover.h" +using namespace ScriptEngine; + bool CScriptGameObject::use_smart_covers_only() const { CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member use_smart_covers_only!"); return (false); } @@ -32,7 +34,7 @@ void CScriptGameObject::use_smart_covers_only(bool value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member use_smart_covers_only!"); return; } @@ -45,7 +47,7 @@ void CScriptGameObject::set_smart_cover_target_selector() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_smart_cover_target_selector!"); return; } @@ -58,7 +60,7 @@ void CScriptGameObject::set_smart_cover_target_selector(luabind::functor f CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_smart_cover_target_selector!"); return; } @@ -73,7 +75,7 @@ void CScriptGameObject::set_smart_cover_target_selector(luabind::functor f CAI_Stalker* stalker = smart_cast(&this->object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_smart_cover_target_selector!"); return; } @@ -88,14 +90,14 @@ void CScriptGameObject::set_smart_cover_target_idle() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member smart_cover_setup_idle_target!"); return; } if (!stalker->g_Alive()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : do not call smart_cover_setup_idle_target when stalker is dead!"); return; } @@ -108,14 +110,14 @@ void CScriptGameObject::set_smart_cover_target_lookout() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member smart_cover_setup_lookout_target!"); return; } if (!stalker->g_Alive()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : do not call smart_cover_setup_lookout_target when stalker is dead!"); return; } @@ -128,14 +130,14 @@ void CScriptGameObject::set_smart_cover_target_fire() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member smart_cover_setup_fire_target!"); return; } if (!stalker->g_Alive()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : do not call smart_cover_setup_fire_target when stalker is dead!"); return; } @@ -148,14 +150,14 @@ void CScriptGameObject::set_smart_cover_target_fire_no_lookout() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member smart_cover_setup_fire_no_lookout_target!"); return; } if (!stalker->g_Alive()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : do not call set_smart_cover_target_fire_no_lookout when stalker is dead!"); return; } @@ -168,14 +170,14 @@ void CScriptGameObject::set_smart_cover_target_default(bool value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_smart_cover_target_default!"); return; } if (!stalker->g_Alive()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : do not call set_smart_cover_target_default when stalker is dead!"); return; } @@ -188,7 +190,7 @@ bool CScriptGameObject::in_smart_cover() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member in_smart_cover_mode!"); return (""); } @@ -201,7 +203,7 @@ void CScriptGameObject::set_dest_smart_cover(LPCSTR cover_id) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_dest_smart_cover!"); return; } @@ -214,7 +216,7 @@ void CScriptGameObject::set_dest_smart_cover() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_dest_smart_cover!"); return; } @@ -227,7 +229,7 @@ CCoverPoint const* CScriptGameObject::get_dest_smart_cover() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member get_dest_smart_cover!"); return (0); } @@ -240,7 +242,7 @@ LPCSTR CScriptGameObject::get_dest_smart_cover_name() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member get_dest_smart_cover!"); return (0); } @@ -253,7 +255,7 @@ void CScriptGameObject::set_dest_loophole(LPCSTR loophole_id) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_dest_loophole!"); return; } @@ -266,7 +268,7 @@ void CScriptGameObject::set_dest_loophole() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_dest_loophole!"); return; } @@ -279,7 +281,7 @@ void CScriptGameObject::set_smart_cover_target(Fvector value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_smart_cover_target!"); return; } @@ -292,7 +294,7 @@ void CScriptGameObject::set_smart_cover_target() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_smart_cover_target!"); return; } @@ -305,7 +307,7 @@ void CScriptGameObject::set_smart_cover_target(CScriptGameObject* enemy_object) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member set_smart_cover_target!"); return; } @@ -318,7 +320,7 @@ bool CScriptGameObject::in_loophole_fov(LPCSTR cover_id, LPCSTR loophole_id, Fve CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member object_in_loophole_fov!"); return (false); } @@ -331,7 +333,7 @@ bool CScriptGameObject::in_current_loophole_fov(Fvector object_position) const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member object_in_loophole_fov!"); return (false); } @@ -344,7 +346,7 @@ bool CScriptGameObject::in_loophole_range(LPCSTR cover_id, LPCSTR loophole_id, F CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member object_in_loophole_range!"); return (false); } @@ -357,7 +359,7 @@ bool CScriptGameObject::in_current_loophole_range(Fvector object_position) const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member object_in_loophole_range!"); return (false); } @@ -370,7 +372,7 @@ float const CScriptGameObject::idle_min_time() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member idle_min_time!"); return (flt_max); } @@ -383,7 +385,7 @@ void CScriptGameObject::idle_min_time(float value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member idle_min_time!"); return; } @@ -396,7 +398,7 @@ float const CScriptGameObject::idle_max_time() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member idle_max_time!"); return (flt_max); } @@ -409,7 +411,7 @@ void CScriptGameObject::idle_max_time(float value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member idle_max_time!"); return; } @@ -422,7 +424,7 @@ float const CScriptGameObject::lookout_min_time() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member lookout_min_time!"); return (flt_max); } @@ -435,7 +437,7 @@ void CScriptGameObject::lookout_min_time(float value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member lookout_min_time!"); return; } @@ -448,7 +450,7 @@ float const CScriptGameObject::lookout_max_time() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member lookout_max_time!"); return (flt_max); } @@ -461,7 +463,7 @@ void CScriptGameObject::lookout_max_time(float value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member lookout_max_time!"); return; } @@ -474,7 +476,7 @@ float CScriptGameObject::apply_loophole_direction_distance() const CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member smart_cover_enter_distance!"); return (flt_max); } @@ -487,7 +489,7 @@ void CScriptGameObject::apply_loophole_direction_distance(float value) CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member smart_cover_enter_distance!"); return; } @@ -500,7 +502,7 @@ bool CScriptGameObject::movement_target_reached() CAI_Stalker* stalker = smart_cast(&object()); if (!stalker) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member movement_target_reached!"); return (false); } diff --git a/src/xrGame/script_game_object_trader.cpp b/src/xrGame/script_game_object_trader.cpp index 9d86f6895..006a414e1 100644 --- a/src/xrGame/script_game_object_trader.cpp +++ b/src/xrGame/script_game_object_trader.cpp @@ -8,12 +8,14 @@ #include "ai/trader/ai_trader.h" #include "ai/trader/trader_animation.h" +using namespace ScriptEngine; + void CScriptGameObject::set_trader_global_anim(LPCSTR anim) { CAI_Trader* trader = smart_cast(&object()); if (!trader) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "Cannot cast sctipt game object to trader!"); return; } @@ -25,7 +27,7 @@ void CScriptGameObject::set_trader_head_anim(LPCSTR anim) CAI_Trader* trader = smart_cast(&object()); if (!trader) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "Cannot cast sctipt game object to trader!"); return; } @@ -37,7 +39,7 @@ void CScriptGameObject::set_trader_sound(LPCSTR sound, LPCSTR anim) CAI_Trader* trader = smart_cast(&object()); if (!trader) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "Cannot cast sctipt game object to trader!"); return; } @@ -49,7 +51,7 @@ void CScriptGameObject::external_sound_start(LPCSTR sound) CAI_Trader* trader = smart_cast(&object()); if (!trader) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "Cannot cast sctipt game object to trader!"); return; } @@ -61,7 +63,7 @@ void CScriptGameObject::external_sound_stop() CAI_Trader* trader = smart_cast(&object()); if (!trader) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "Cannot cast sctipt game object to trader!"); return; } diff --git a/src/xrGame/script_game_object_use.cpp b/src/xrGame/script_game_object_use.cpp index 419cf871d..fda263718 100644 --- a/src/xrGame/script_game_object_use.cpp +++ b/src/xrGame/script_game_object_use.cpp @@ -3,7 +3,6 @@ #include "script_game_object_impl.h" #include "UsableScriptObject.h" #include "GameObject.h" -#include "script_storage_space.h" #include "script_engine.h" #include "stalker_planner.h" #include "ai/stalker/ai_stalker.h" @@ -20,11 +19,13 @@ #include "../xrphysics/iphworld.h" #include "doors_manager.h" +using namespace ScriptEngine; + void CScriptGameObject::SetTipText(LPCSTR tip_text) { CUsableScriptObject* l_tpUseableScriptObject = smart_cast(&object()); if (!l_tpUseableScriptObject) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetTipText. Reason: the object is not usable"); else l_tpUseableScriptObject->set_tip_text(tip_text); } @@ -33,7 +34,7 @@ void CScriptGameObject::SetTipTextDefault() { CUsableScriptObject* l_tpUseableScriptObject = smart_cast(&object()); if (!l_tpUseableScriptObject) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetTipTextDefault . Reason: the object is not usable"); else l_tpUseableScriptObject->set_tip_text_default(); } @@ -42,7 +43,7 @@ void CScriptGameObject::SetNonscriptUsable(bool nonscript_usable) { CUsableScriptObject* l_tpUseableScriptObject = smart_cast(&object()); if (!l_tpUseableScriptObject) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "SetNonscriptUsable . Reason: the object is not usable"); else l_tpUseableScriptObject->set_nonscript_usable(nonscript_usable); } @@ -53,7 +54,7 @@ Fvector CScriptGameObject::GetCurrentDirection() CProjector* obj = smart_cast(&object()); if (!obj) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "Script Object : cannot access class member GetCurrentDirection!"); return Fvector().set(0.f, 0.f, 0.f); } @@ -111,14 +112,14 @@ void CScriptGameObject::Kill(CScriptGameObject* who, CEntity* l_tpEntity = smart_cast(&object()); if (!l_tpEntity) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "%s cannot access class member Kill!", + ai().script_engine().script_log(eLuaMessageTypeError, "%s cannot access class member Kill!", *object().cName()); return; } if (!l_tpEntity->AlreadyDie()) l_tpEntity->KillEntity(who ? who->object().ID() : object().ID(), bypass_actor_check ? 1 : 0); else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "attempt to kill dead object %s", + ai().script_engine().script_log(eLuaMessageTypeError, "attempt to kill dead object %s", *object().cName()); } @@ -127,7 +128,7 @@ bool CScriptGameObject::Alive() const CEntity* entity = smart_cast(&object()); if (!entity) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CSciptEntity : cannot access class member Alive!"); return (false); } @@ -139,7 +140,7 @@ ALife::ERelationType CScriptGameObject::GetRelationType(CScriptGameObject* who) CEntityAlive* l_tpEntityAlive1 = smart_cast(&object()); if (!l_tpEntityAlive1) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "%s cannot access class member GetRelationType!", *object().cName()); return ALife::eRelationTypeDummy; } @@ -147,7 +148,7 @@ ALife::ERelationType CScriptGameObject::GetRelationType(CScriptGameObject* who) CEntityAlive* l_tpEntityAlive2 = smart_cast(&who->object()); if (!l_tpEntityAlive2) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "%s cannot apply GetRelationType method for non-alive object!", *who->object().cName()); return ALife::eRelationTypeDummy; @@ -162,7 +163,7 @@ IC T* CScriptGameObject::action_planner() CAI_Stalker* manager = smart_cast(&object()); if (!manager) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Stalker : cannot access class member action_planner!"); return (0); } @@ -179,7 +180,7 @@ void CScriptGameObject::set_enemy_callback(const luabind::functor& functor CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member set_enemy_callback!"); return; } @@ -191,7 +192,7 @@ void CScriptGameObject::set_enemy_callback(const luabind::functor& functor CCustomMonster* monster = smart_cast(&this->object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member set_enemy_callback!"); return; } @@ -203,7 +204,7 @@ void CScriptGameObject::set_enemy_callback() CCustomMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CCustomMonster : cannot access class member set_enemy_callback!"); return; } @@ -242,13 +243,13 @@ void CScriptGameObject::set_const_force(const Fvector& dir, float value, u32 tim // shell->set_LinearVel( Fvector().set(0,0,0) ); if (!physics_world()) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "set_const_force : ph_world do not exist!"); return; } if (!shell) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "set_const_force : object %s has no physics shell!", *object().cName()); return; } diff --git a/src/xrGame/script_game_object_use2.cpp b/src/xrGame/script_game_object_use2.cpp index db35433fa..53ddd6ae3 100644 --- a/src/xrGame/script_game_object_use2.cpp +++ b/src/xrGame/script_game_object_use2.cpp @@ -10,6 +10,8 @@ #include "ai/monsters/monster_home.h" #include "ai/monsters/control_animation_base.h" +using namespace ScriptEngine; + ////////////////////////////////////////////////////////////////////////// // Burer @@ -18,7 +20,7 @@ void CScriptGameObject::set_force_anti_aim(bool force) CBaseMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "object is not CBaseMonster to call set_force_anti_aim"); return; } @@ -31,7 +33,7 @@ bool CScriptGameObject::get_force_anti_aim() CBaseMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "object is not CBaseMonster to call get_force_anti_aim"); return false; } @@ -44,7 +46,7 @@ void CScriptGameObject::burer_set_force_gravi_attack(bool force) CBurer* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "object is not CBurer to call burer_set_force_gravi_attack"); return; } @@ -57,7 +59,7 @@ bool CScriptGameObject::burer_get_force_gravi_attack() CBurer* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "object is not CBurer to call burer_set_force_gravi_attack"); return false; } @@ -73,7 +75,7 @@ void CScriptGameObject::poltergeist_set_actor_ignore(bool ignore) CPoltergeist* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "object is not Poltergeist to call poltergeist_set_actor_ignore"); return; } @@ -86,7 +88,7 @@ bool CScriptGameObject::poltergeist_get_actor_ignore() CPoltergeist* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "object is not Poltergeist to call poltergeist_get_actor_ignore"); return false; } @@ -102,7 +104,7 @@ void CScriptGameObject::force_visibility_state(int state) CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member force_visibility_state!"); return; } @@ -115,7 +117,7 @@ int CScriptGameObject::get_visibility_state() CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member get_visibility_state!"); return CAI_Bloodsucker::full_visibility; } @@ -128,7 +130,7 @@ void CScriptGameObject::set_override_animation(pcstr anim_name) CBaseMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "object is not of CBaseMonster class!"); + ai().script_engine().script_log(eLuaMessageTypeError, "object is not of CBaseMonster class!"); return; } @@ -140,7 +142,7 @@ void CScriptGameObject::set_override_animation(u32 AnimType, u32 AnimIndex) CBaseMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "object is not of CBaseMonster class!"); + ai().script_engine().script_log(eLuaMessageTypeError, "object is not of CBaseMonster class!"); return; } @@ -152,7 +154,7 @@ void CScriptGameObject::clear_override_animation() CBaseMonster* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "object is not of CBaseMonster class!"); + ai().script_engine().script_log(eLuaMessageTypeError, "object is not of CBaseMonster class!"); return; } @@ -164,7 +166,7 @@ void CScriptGameObject::force_stand_sleep_animation(u32 index) CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member force_stand_sleep_animation!"); return; } @@ -177,7 +179,7 @@ void CScriptGameObject::release_stand_sleep_animation() CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member release_stand_sleep_animation!"); return; } @@ -190,7 +192,7 @@ void CScriptGameObject::set_invisible(bool val) CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member set_invisible!"); return; } @@ -203,7 +205,7 @@ void CScriptGameObject::set_manual_invisibility(bool val) CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member set_manual_invisible!"); return; } @@ -215,7 +217,7 @@ void CScriptGameObject::bloodsucker_drag_jump(CScriptGameObject* e, LPCSTR e_str CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot process drag, anim, jump for CAI_Bloodsucker!"); return; } @@ -233,7 +235,7 @@ void CScriptGameObject::set_enemy(CScriptGameObject* e) CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member set_enemy!"); return; } @@ -247,7 +249,7 @@ void CScriptGameObject::set_vis_state(float val) CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member set_vis_state!"); return; } @@ -266,7 +268,7 @@ void CScriptGameObject::off_collision(bool val) CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member set_vis_state!"); return; } @@ -278,7 +280,7 @@ void CScriptGameObject::set_alien_control(bool val) CAI_Bloodsucker* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CAI_Bloodsucker : cannot access class member alien_control_activate!"); return; } @@ -306,7 +308,7 @@ CScriptSoundInfo CScriptGameObject::GetSoundInfo() } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member GetSoundInfo!"); } return (ret_val); @@ -328,7 +330,7 @@ CScriptMonsterHitInfo CScriptGameObject::GetMonsterHitInfo() } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CScriptGameObject : cannot access class member GetMonsterHitInfo!"); } return (ret_val); @@ -365,7 +367,7 @@ bool CScriptGameObject::fake_death_fall_down() CZombie* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CZombie : cannot access class member fake_death_fall_down!"); return false; } @@ -378,7 +380,7 @@ void CScriptGameObject::fake_death_stand_up() CZombie* monster = smart_cast(&object()); if (!monster) { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(eLuaMessageTypeError, "CZombie : cannot access class member fake_death_fall_down!"); return; } diff --git a/src/xrGame/script_property_evaluator_wrapper.cpp b/src/xrGame/script_property_evaluator_wrapper.cpp index ca2a03269..30cacafd0 100644 --- a/src/xrGame/script_property_evaluator_wrapper.cpp +++ b/src/xrGame/script_property_evaluator_wrapper.cpp @@ -41,7 +41,7 @@ bool CScriptPropertyEvaluatorWrapper::evaluate() catch (...) { //Alundaio: m_evaluator_name - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "SCRIPT RUNTIME ERROR : evaluator [%s] returns value with not a bool type!", m_evaluator_name); } diff --git a/src/xrGame/script_sound.cpp b/src/xrGame/script_sound.cpp index c44ad35ad..208336924 100644 --- a/src/xrGame/script_sound.cpp +++ b/src/xrGame/script_sound.cpp @@ -22,7 +22,7 @@ CScriptSound::CScriptSound(LPCSTR caSoundName, ESoundTypes sound_type) m_sound.create(caSoundName, st_Effect, sound_type); else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "File not found \"%s\"!", l_caFileName); + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "File not found \"%s\"!", l_caFileName); m_sound.create("$no_sound.ogg", st_Effect, sound_type); } } @@ -44,7 +44,7 @@ Fvector CScriptSound::GetPosition() const return (l_tpSoundParams->position); else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "Sound was not launched, can't get position!"); return (Fvector().set(0, 0, 0)); } diff --git a/src/xrGame/script_sound_action.cpp b/src/xrGame/script_sound_action.cpp index 901e55634..d8cde2d3b 100644 --- a/src/xrGame/script_sound_action.cpp +++ b/src/xrGame/script_sound_action.cpp @@ -28,7 +28,7 @@ void CScriptSoundAction::SetSound(LPCSTR caSoundToPlay) } else { - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "File not found \"%s\"!", l_caFileName); + ai().script_engine().script_log(ScriptEngine::eLuaMessageTypeError, "File not found \"%s\"!", l_caFileName); m_bStartedToPlay = true; m_bCompleted = true; } diff --git a/src/xrGame/ui/UIInventoryUpgradeWnd.cpp b/src/xrGame/ui/UIInventoryUpgradeWnd.cpp index 2f02649a8..8be61279f 100644 --- a/src/xrGame/ui/UIInventoryUpgradeWnd.cpp +++ b/src/xrGame/ui/UIInventoryUpgradeWnd.cpp @@ -15,7 +15,6 @@ #include "../string_table.h" #include "../actor.h" -#include "../../xrServerEntities/script_process.h" #include "../inventory.h" #include "ai_space.h" diff --git a/src/xrGame/vs2022/xrGame.vcxproj b/src/xrGame/vs2022/xrGame.vcxproj index 5a2393d9c..cd60a00d8 100644 --- a/src/xrGame/vs2022/xrGame.vcxproj +++ b/src/xrGame/vs2022/xrGame.vcxproj @@ -307,8 +307,6 @@ - - @@ -333,10 +331,6 @@ - - - - @@ -349,22 +343,15 @@ - - + - - - - - - @@ -1936,10 +1923,6 @@ - - pch_script.h - $(IntDir)$(ProjectName)_script.pch - pch_script.h @@ -1959,9 +1942,6 @@ $(IntDir)$(ProjectName)_script.pch - - - pch_script.h $(IntDir)$(ProjectName)_script.pch @@ -1995,18 +1975,10 @@ pch_script.h $(IntDir)$(ProjectName)_script.pch - - pch_script.h - $(IntDir)$(ProjectName)_script.pch - pch_script.h $(IntDir)$(ProjectName)_script.pch - - pch_script.h - $(IntDir)$(ProjectName)_script.pch - pch_script.h $(IntDir)$(ProjectName)_script.pch @@ -2019,18 +1991,8 @@ pch_script.h $(IntDir)$(ProjectName)_script.pch - - pch_script.h - $(IntDir)$(ProjectName)_script.pch - - - pch_script.h - $(IntDir)$(ProjectName)_script.pch - - - pch_script.h - $(IntDir)$(ProjectName)_script.pch - + + pch_script.h @@ -3346,10 +3308,6 @@ pch_script.h $(IntDir)$(ProjectName)_script.pch - - pch_script.h - $(IntDir)$(ProjectName)_script.pch - pch_script.h $(IntDir)$(ProjectName)_script.pch diff --git a/src/xrGame/vs2022/xrGame.vcxproj.filters b/src/xrGame/vs2022/xrGame.vcxproj.filters index 4d3352f16..3505cb374 100644 --- a/src/xrGame/vs2022/xrGame.vcxproj.filters +++ b/src/xrGame/vs2022/xrGame.vcxproj.filters @@ -1342,27 +1342,12 @@ {7461340c-f13a-4ba4-a432-e8aeca7393cf} - - {a1df39ed-f84f-4b5e-9aa6-7310378e3614} - {c64d88d0-2cc0-440e-bed2-367ebd29671c} - - {2bfb6ae4-1fec-4054-bc45-5a6ed56f73ed} - {8ce0ad22-cee7-419e-b54c-65da67769b68} - - {0126fd57-f558-4910-ad5e-f63e20a12940} - - - {2f517721-a4fd-4e92-aee2-7c703d7b2abe} - - - {91189d3e-089f-4e5c-a9f4-b41fb1136e69} - {a568c889-96b8-41c7-9bee-0d4f24d1a47e} @@ -2494,9 +2479,6 @@ {8d6475ec-c185-4ebb-9ba6-e7dc1644c4c1} - - {c14ffa0c-947d-49b9-8e01-269569b48371} - @@ -5199,63 +5181,12 @@ AI\AScript\ScriptClasses\ScriptSound - - AI\AScript\ScriptDebugger - - - AI\AScript\ScriptDebugger - - - AI\AScript\ScriptDebugger - - - AI\AScript\ScriptDebugger - - - AI\AScript\ScriptDebugger - - - AI\AScript\ScriptDebugger - AI\AScript\ScriptEngine - - AI\AScript\ScriptEngine - AI\AScript\ScriptEngine - - AI\AScript\ScriptProcess - - - AI\AScript\ScriptProcess - - - AI\AScript\ScriptStorage - - - AI\AScript\ScriptStorage - - - AI\AScript\ScriptStorage - - - AI\AScript\ScriptThread - - - AI\AScript\ScriptThread - - - AI\AScript\ScriptThread\ScriptStackTracker - - - AI\AScript\ScriptThread\ScriptStackTracker - - - AI\AScript\lua_studio - AI\ASound @@ -7398,11 +7329,17 @@ UI\Cursor - - UI\Common\ImGui + + AI\AScript\ScriptStorage + + + AI\AScript\ScriptEngine + + + AI\AScript\ScriptEngine - - UI\Common\ImGui + + AI\AScript\ScriptEngine @@ -8798,45 +8735,15 @@ AI\AScript\ScriptClasses\ScriptSound - - AI\AScript\ScriptDebugger - - - AI\AScript\ScriptDebugger - - - AI\AScript\ScriptDebugger - - - AI\AScript\ScriptDebugger - AI\AScript\ScriptEngine AI\AScript\ScriptEngine - - AI\AScript\ScriptEngine - AI\AScript\ScriptEngine - - AI\AScript\ScriptProcess - - - AI\AScript\ScriptStorage - - - AI\AScript\ScriptThread - - - AI\AScript\ScriptThread\ScriptStackTracker - - - AI\AScript\lua_studio - AI\ASound @@ -11099,8 +11006,11 @@ UI\Cursor - - UI\Common\ImGui + + AI\AScript\ScriptStorage + + + AI\AScript\ScriptEngine diff --git a/src/xrServerEntities/lua_studio.cpp b/src/xrServerEntities/lua_studio.cpp deleted file mode 100644 index 8f3a7a60d..000000000 --- a/src/xrServerEntities/lua_studio.cpp +++ /dev/null @@ -1,854 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : lua_studio.cpp -// Created : 21.08.2008 -// Modified : 21.08.2008 -// Author : Dmitriy Iassenev -// Description : lua studio engine class (copied from the lua studio SDK) -//////////////////////////////////////////////////////////////////////////// - -#include "pch_script.h" -#include "lua_studio.h" - -#define pstr LPSTR -#define pcstr LPCSTR -#define pcvoid void const* -#define sz_cmp xr_strcmp -#define vector_class luabind::internal_vector -#define engine lua_studio_engine - -inline pstr sz_cpy(pstr destination, const u32& size, pcstr source) -{ - xr_strcpy(destination, size, source); - return (destination); -} - -template -inline pstr sz_cpy(char (&destination)[size], pcstr source) -{ - xr_strcpy(destination, size, source); - return (destination); -} - -inline pstr sz_cat(pstr destination, const u32& size, pcstr source) -{ - xr_strcat(destination, size, source); - return (destination); -} - -template -inline pstr sz_cat(char (&destination)[size], pcstr source) -{ - xr_strcat(destination, size, source); - return (destination); -} - -inline u32 sz_len(pcstr string) -{ - return ((u32)xr_strlen(string)); -} - -//////////////////////////////////////////////////////////////////////////// - -int engine::luaL_loadstring(lua_State* L, const char* s) -{ - return (::luaL_loadstring(L, s)); -} - -int engine::luaL_newmetatable(lua_State* L, const char* tname) -{ - return (::luaL_newmetatable(L, tname)); -} - -void engine::lua_createtable(lua_State* L, int narray, int nrec) -{ - return (::lua_createtable(L, narray, nrec)); -} - -int engine::lua_sethook(lua_State* L, lua_Hook func, lua_mask_type mask, int count) -{ - return (::lua_sethook(L, func, mask, count)); -} - -engine::lua_Hook engine::lua_gethook(lua_State* L) -{ - return (::lua_gethook(L)); -} - -int engine::lua_getinfo(lua_State* L, const char* what, lua_Debug* ar) -{ - return (::lua_getinfo(L, what, ar)); -} - -void engine::lua_getfenv(lua_State* L, int idx) -{ - return (::lua_getfenv(L, idx)); -} - -void engine::lua_getfield(lua_State* L, int idx, const char* k) -{ - return (::lua_getfield(L, idx, k)); -} - -char const* engine::lua_getlocal(lua_State* L, const lua_Debug* ar, int n) -{ - return (::lua_getlocal(L, ar, n)); -} - -void engine::lua_gettable(lua_State* L, int idx) -{ - return (::lua_gettable(L, idx)); -} - -int engine::lua_getstack(lua_State* L, int level, lua_Debug* ar) -{ - return (::lua_getstack(L, level, ar)); -} - -int engine::lua_gettop(lua_State* L) -{ - return (::lua_gettop(L)); -} - -char const* engine::lua_getupvalue(lua_State* L, int funcindex, int n) -{ - return (::lua_getupvalue(L, funcindex, n)); -} - -int engine::lua_iscfunction(lua_State* L, int idx) -{ - return (::lua_iscfunction(L, idx)); -} - -int engine::lua_next(lua_State* L, int idx) -{ - return (::lua_next(L, idx)); -} - -int engine::lua_pcall(lua_State* L, int nargs, int nresults, int errfunc) -{ - return (::lua_pcall(L, nargs, nresults, errfunc)); -} - -void engine::lua_pushcclosure(lua_State* L, lua_CFunction fn, int n) -{ - return (::lua_pushcclosure(L, fn, n)); -} - -void engine::lua_pushnil(lua_State* L) -{ - return (::lua_pushnil(L)); -} - -void engine::lua_pushstring(lua_State* L, const char* s) -{ - return (::lua_pushstring(L, s)); -} - -void engine::lua_pushvalue(lua_State* L, int idx) -{ - return (::lua_pushvalue(L, idx)); -} - -void engine::lua_pushnumber(lua_State* L, lua_Number idx) -{ - return (::lua_pushnumber(L, idx)); -} - -void engine::lua_remove(lua_State* L, int idx) -{ - return (::lua_remove(L, idx)); -} - -void engine::lua_replace(lua_State* L, int idx) -{ - return (::lua_replace(L, idx)); -} - -int engine::lua_setfenv(lua_State* L, int idx) -{ - return (::lua_setfenv(L, idx)); -} - -int engine::lua_setmetatable(lua_State* L, int objindex) -{ - return (::lua_setmetatable(L, objindex)); -} - -void engine::lua_settable(lua_State* L, int idx) -{ - return (::lua_settable(L, idx)); -} - -void engine::lua_settop(lua_State* L, int idx) -{ - return (::lua_settop(L, idx)); -} - -int engine::lua_toboolean(lua_State* L, int idx) -{ - return (::lua_toboolean(L, idx)); -} - -engine::lua_Integer engine::lua_tointeger(lua_State* L, int idx) -{ - return (::lua_tointeger(L, idx)); -} - -char const* engine::lua_tolstring(lua_State* L, int idx, size_t* len) -{ - return (::lua_tolstring(L, idx, len)); -} - -lua_Number engine::lua_tonumber(lua_State* L, int idx) -{ - return (::lua_tonumber(L, idx)); -} - -const void* engine::lua_topointer(lua_State* L, int idx) -{ - return (::lua_topointer(L, idx)); -} - -bool engine::lua_isnumber(lua_State* L, int idx) -{ - return (!!::lua_isnumber(L, idx)); -} - -int engine::lua_type(lua_State* L, int idx) -{ - return (::lua_type(L, idx)); -} - -char const* engine::lua_typename(lua_State* L, int t) -{ - return (::lua_typename(L, t)); -} - -lua_Debug* engine::lua_debug_create() -{ - VERIFY(m_instance_count < sizeof(m_instances)/sizeof(m_instances[0])); - return (&m_instances[m_instance_count++]); -} - -void engine::lua_debug_destroy(lua_Debug*& instance) -{ - instance = 0; - --m_instance_count; -} - -char const* engine::lua_debug_get_name(lua_Debug& instance) -{ - return (instance.name); -} - -char const* engine::lua_debug_get_source(lua_Debug& instance) -{ - return (instance.source); -} - -char const* engine::lua_debug_get_short_source(lua_Debug& instance) -{ - return (instance.short_src); -} - -int engine::lua_debug_get_current_line(lua_Debug& instance) -{ - return (instance.currentline); -} - -void engine::log(log_message_types const message_type, char const* const message) -{ -} - -char* engine::class_name(char* const buffer, unsigned int const size, luabind::detail::class_rep& class_rep) -{ - switch (class_rep.get_class_type()) - { - case luabind::detail::class_rep::cpp_class: - { - return (sz_cpy(buffer, size, "C++ class")); - } - case luabind::detail::class_rep::lua_class: - { - return (sz_cpy(buffer, size, "Lua class")); - } - default: NODEFAULT; - } -#ifdef DEBUG - return (sz_cpy(buffer, size, "unknown user data")); -#endif // #ifdef DEBUG -} - -void engine::type_convert_class(char* const buffer, unsigned int const size, lua_State* state, int index) -{ - luabind::detail::object_rep* object = luabind::detail::is_class_object(state, index); - VERIFY2(object, "invalid object userdata"); - - sz_cpy(buffer, size, ""); - sz_cat(buffer, size, "class \""); - sz_cat(buffer, size, object->crep()->name()); - sz_cat(buffer, size, "\" ("); - - u32 const length = sz_len(buffer); - class_name(buffer + length, size - length, *object->crep()); - - sz_cat(buffer, size, " instance)"); -} - -static bool is_luabind_class(lua_State* state, int const index) -{ - luabind::detail::class_rep* class_rep = static_cast(lua_touserdata(state, index)); - if (!class_rep) - return (false); - - if (class_rep->get_class_type() == luabind::detail::class_rep::lua_class) - return (true); - - if (luabind::detail::class_registry::get_registry(state)->find_class(class_rep->type()) != class_rep) - return (false); - - return (true); -} - -bool engine::type_convert_instance(char* buffer, unsigned int const size, lua_State* state, int index) -{ - if (!is_luabind_class(state, index)) - return (false); - - class_name(buffer, size, *static_cast(lua_touserdata(state, index))); - - return (true); -} - -void engine::type_convert_userdata(char* buffer, unsigned int const size, lua_State* state, int index) -{ - if (luabind::detail::is_class_object(state, index)) - { - type_convert_class(buffer, size, state, index); - return; - } - - if (type_convert_instance(buffer, size, state, index)) - return; - - sz_cpy(buffer, size, "unrecognized user data"); -} - -bool engine::type_to_string(char* const buffer, unsigned int const size, lua_State* const state, int const index, - bool& use_in_description) -{ - switch (lua_type(state, index)) - { - case engine::lua_type_string: - case engine::lua_type_table: - case engine::lua_type_nil: - case engine::lua_type_boolean: - case engine::lua_type_number: - case engine::lua_type_function: - case engine::lua_type_coroutine: - return (false); - case engine::lua_type_light_user_data: - case engine::lua_type_user_data: - { - type_convert_userdata(buffer, size, state, index); - return (true); - } - default: NODEFAULT; - } // switch (lua_type(state, index)) - -#ifdef DEBUG - return (false); -#endif // #ifdef DEBUG -} - -void engine::fill_class_info(cs::lua_studio::backend& backend, char* const buffer, unsigned int const size, - luabind::detail::object_rep* object, luabind::detail::class_rep* class_rep, - lua_State* state) -{ - pstr stream = buffer; - - stream += xr_sprintf(stream, size - (stream - buffer), "{"); - - typedef luabind::detail::class_rep::property_map property_map; - property_map::const_iterator I = class_rep->properties().begin(); - property_map::const_iterator E = class_rep->properties().end(); - for (u32 i = 0; I != E; ++I) - { - if (i == 3) - { - stream += xr_sprintf(stream, size - (stream - buffer), "..."); - break; - } - lua_pushstring(state, (*I).first); - lua_insert(state, 1); - lua_pushlightuserdata(state, object); - lua_insert(state, 1); - (*I).second.func(state, (*I).second.pointer_offset); - - string4096 type; - bool use_in_description; - backend.type_to_string(type, sizeof(type), state, -1, use_in_description); - - string4096 value; - cs::lua_studio::icon_type icon_type; - backend.value_to_string(value, sizeof(value), state, -1, icon_type, false); - - lua_pop_value(state, 1); - lua_remove(state, 1); - lua_remove(state, 1); - - if (use_in_description) - stream += xr_sprintf(stream, size - (stream - buffer), "%s[%s]=%s ", (*I).first, type, value); - else - stream += xr_sprintf(stream, size - (stream - buffer), "%s=%s ", (*I).first, value); - - ++i; - } - - stream += xr_sprintf(stream, size - (stream - buffer), "}%c", 0); -} - -void engine::value_convert_class(cs::lua_studio::backend& backend, char* buffer, unsigned int size, - luabind::detail::class_rep* class_rep, lua_State* state, int index, - cs::lua_studio::icon_type& icon_type, bool const full_description) -{ - icon_type = cs::lua_studio::icon_type_class; - - if (!full_description) - { - sz_cpy(buffer, size, "{...}"); - return; - } - - if (!class_rep->bases().empty()) - { - sz_cpy(buffer, size, "{...}"); - return; - } - - if (class_rep->properties().empty()) - { - sz_cpy(buffer, size, "{}"); - return; - } - - luabind::detail::object_rep* object = luabind::detail::is_class_object(state, index); - if (!object) - { - sz_cpy(buffer, size, "{...}"); - return; - } - - fill_class_info(backend, buffer, size, object, class_rep, state); -} - -bool engine::value_convert_instance(cs::lua_studio::backend& backend, char* buffer, unsigned int size, - luabind::detail::object_rep* object, lua_State* state) -{ - typedef luabind::detail::lua_reference lua_reference; - lua_reference const& tbl = object->get_lua_table(); - if (!tbl.is_valid()) - return (false); - - pstr stream = buffer; - stream += xr_sprintf(stream, size - (stream - buffer), "{"); - - tbl.get(state); - int i; - lua_pushnil(state); - for (i = 0; lua_next(state, -2); ++i) - { - if (i == 3) - { - lua_pop_value(state, 2); - stream += xr_sprintf(stream, size - (stream - buffer), "..."); - break; - } - - pcstr name = lua_to_string(state, -2); - - string4096 type; - bool use_in_description; - backend.type_to_string(type, sizeof(type), state, -1, use_in_description); - - string4096 value; - cs::lua_studio::icon_type icon_type; - backend.value_to_string(value, sizeof(value), state, -1, icon_type, false); - - if (use_in_description) - stream += xr_sprintf(stream, size - (stream - buffer), "%s[%s]=%s ", name, type, value); - else - stream += xr_sprintf(stream, size - (stream - buffer), "%s=%s ", name, value); - - lua_pop_value(state, 1); - } - - lua_pop_value(state, 1); - - if (!i) - return (false); - - stream += xr_sprintf(stream, size - (stream - buffer), "}%c", 0); - - return (true); -} - -bool engine::value_convert_instance(cs::lua_studio::backend& backend, char* buffer, unsigned int size, lua_State* state, - int index, cs::lua_studio::icon_type& icon_type, bool full_description) -{ - luabind::detail::object_rep* object = luabind::detail::is_class_object(state, index); - if (!object) - return (false); - - if (full_description && !value_convert_instance(backend, buffer, size, object, state)) - value_convert_class(backend, buffer, size, object->crep(), state, index, icon_type, full_description); - else - sz_cpy(buffer, size, " "); - - icon_type = cs::lua_studio::icon_type_class_instance; - - return (true); -} - -bool engine::value_to_string(cs::lua_studio::backend& backend, char* const buffer, unsigned int const size, - lua_State* const state, int const index, cs::lua_studio::icon_type& icon_type, - bool const full_description) -{ - switch (lua_type(state, index)) - { - case engine::lua_type_string: - case engine::lua_type_table: - case engine::lua_type_nil: - case engine::lua_type_boolean: - case engine::lua_type_number: - case engine::lua_type_function: - case engine::lua_type_coroutine: - return (false); - case engine::lua_type_light_user_data: - case engine::lua_type_user_data: - { - if (!luabind::detail::is_class_object(state, index)) - { - if (!is_luabind_class(state, index)) - { - icon_type = cs::lua_studio::icon_type_unknown; - pcvoid user_data = lua_topointer(state, index); - xr_sprintf(buffer, size, "0x%08x", *(u32 const*)&user_data); - return (true); - } - - luabind::detail::class_rep* class_rep = static_cast(lua_touserdata( - state, index)); - VERIFY(class_rep); - value_convert_class(backend, buffer, size, class_rep, state, index, icon_type, full_description); - return (true); - } - - if (value_convert_instance(backend, buffer, size, state, index, icon_type, full_description)) - return (true); - - icon_type = cs::lua_studio::icon_type_unknown; - pcvoid user_data = lua_topointer(state, index); - xr_sprintf(buffer, size, "0x%08x", *(u32 const*)&user_data); - return (true); - } - default: NODEFAULT; - } // switch (lua_type(state, index)) - -#ifdef DEBUG - return (false); -#endif // #ifdef DEBUG -} - -void engine::push_class(lua_State* const state, char const* const id) -{ - luabind::detail::object_rep* object = luabind::detail::is_class_object(state, -1); - VERIFY(object); - - luabind::detail::class_rep* class_rep = object->crep(); - R_ASSERT2(class_rep, "null class userdata"); - - R_ASSERT(!sz_cmp(class_rep->name(), id)); - lua_pushlightuserdata(state, class_rep); -} - -void engine::push_class_base(lua_State* const state, char const* const id) -{ - luabind::detail::class_rep* class_rep = static_cast(lua_touserdata(state, -1)); - VERIFY(class_rep); - - typedef luabind::detail::class_rep::base_info base_info; - typedef vector_class Bases; - Bases const& bases = class_rep->bases(); - Bases::const_iterator I = bases.begin(); - Bases::const_iterator E = bases.end(); - for (; I != E; ++I) - { - pcstr name = (*I).base->name(); - if (sz_cmp(id, name)) - continue; - - lua_pop_value(state, 1); - lua_pushlightuserdata(state, (*I).base); - return; - } - - NODEFAULT; -} - -void engine::push_class_instance(lua_State* const state, char const* const id) -{ - luabind::detail::object_rep* object = luabind::detail::is_class_object(state, -1); - if (!object) - { - lua_pop_value(state, 1); - object = luabind::detail::is_class_object(state, -1); - VERIFY(object); - } - - lua_insert(state, 1); - lua_pushstring(state, id); - lua_insert(state, 2); - object->crep()->gettable(state); - lua_remove(state, 2); - lua_pushvalue(state, 1); - lua_remove(state, 1); - lua_pushvalue(state, -2); - lua_remove(state, -3); - lua_remove(state, -2); -} - -void engine::push_user_data(lua_State* const state, char const* const id, cs::lua_studio::icon_type const icon_type) -{ - switch (icon_type) - { - case cs::lua_studio::icon_type_class: - { - push_class(state, id); - break; - } - case cs::lua_studio::icon_type_class_base: - { - push_class_base(state, id); - break; - } - case cs::lua_studio::icon_type_unknown: - case cs::lua_studio::icon_type_table: - case cs::lua_studio::icon_type_class_instance: - { - push_class_instance(state, id); - break; - } - default: NODEFAULT; - } -} - -bool engine::push_value(lua_State* const state, char const* const id, cs::lua_studio::icon_type const icon_type) -{ - switch (lua_type(state, -1)) - { - case engine::lua_type_table: - return (false); - case engine::lua_type_light_user_data: - case engine::lua_type_user_data: - { - push_user_data(state, id, icon_type); - return (true); - } - default: NODEFAULT; - } -#ifdef DEBUG - return (false); -#endif // #ifdef DEBUG -} - -void engine::fill_class_data( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value_to_expand, - lua_State* const state -) -{ - luabind::detail::object_rep* object = static_cast(lua_touserdata(state, -2)); - luabind::detail::class_rep* _class = static_cast(lua_touserdata(state, -1)); - R_ASSERT2(_class, "invalid class userdata"); - - { - string4096 type; - typedef luabind::detail::class_rep::base_info base_info; - vector_class::const_iterator i = _class->bases().begin(); - vector_class::const_iterator e = _class->bases().end(); - for (; i != e; ++i) - value_to_expand.add_value( - (*i).base->name(), - class_name(type, sizeof(type), *(*i).base), - "{...}", - cs::lua_studio::icon_type_class_base - ); - } - - if (!object) - return; - - typedef luabind::detail::class_rep::property_map property_map; - property_map::const_iterator i = _class->properties().begin(); - property_map::const_iterator e = _class->properties().end(); - for (; i != e; ++i) - { - lua_pushstring(state, (*i).first); - lua_insert(state, 1); - lua_pushlightuserdata(state, object); - lua_insert(state, 1); - (*i).second.func(state, (*i).second.pointer_offset); - - bool use_in_description; - - string4096 type; - backend.type_to_string(type, sizeof(type), state, -1, use_in_description); - - cs::lua_studio::icon_type icon_type; - string4096 value; - backend.value_to_string(value, sizeof(value), state, -1, icon_type, true); - - lua_pop_value(state, 1); - lua_remove(state, 1); - lua_remove(state, 1); - - value_to_expand.add_value( - (*i).first, - type, - value, - icon_type - ); - } -} - -void engine::expand_class( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value, - lua_State* const state -) -{ - int start = lua_gettop(state); - - luabind::detail::class_rep* class_object = static_cast(lua_touserdata(state, -1)); - R_ASSERT2(class_object, "invalid class userdata"); - - fill_class_data(backend, value, state); - - luabind::detail::object_rep* object = luabind::detail::is_class_object(state, -2); - if (!object) - lua_pushnil(state); - - if (lua_gettop(state) <= start + 1) - return; - - lua_pop_value(state, 1); -} - -void engine::expand_class_instance( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value_to_expand, - lua_State* const state -) -{ - typedef luabind::detail::object_rep object_rep; - object_rep* object = luabind::detail::is_class_object(state, -1); - VERIFY2(object, "invalid object userdata"); - - if (object->crep()) - { - luabind::detail::class_rep* class_rep = object->crep(); - - string4096 type; - class_name(type, sizeof(type), *class_rep); - - cs::lua_studio::icon_type icon_type; - string4096 value; - backend.value_to_string(value, sizeof(value), state, -1, icon_type, true); - value_to_expand.add_value( - class_rep->name(), - type, - value, - cs::lua_studio::icon_type_class - ); - } - - typedef luabind::detail::lua_reference lua_reference; - lua_reference const& tbl = object->get_lua_table(); - if (!tbl.is_valid()) - return; - - tbl.get(state); - int i; - lua_pushnil(state); - for (i = 0; lua_next(state, -2); ++i) - { - cs::lua_studio::icon_type icon_type; - bool use_in_description; - pcstr name = lua_to_string(state, -2); - - string4096 type; - backend.type_to_string(type, sizeof(type), state, -1, use_in_description); - - string4096 value; - backend.value_to_string(value, sizeof(value), state, -1, icon_type, true); - value_to_expand.add_value( - name, - type, - value, - icon_type - ); - - lua_pop_value(state, 1); - } - - lua_pop_value(state, 1); -} - -void engine::expand_user_data( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value, - lua_State* const state -) -{ - luabind::detail::object_rep* object = luabind::detail::is_class_object(state, -1); - if (object) - { - expand_class_instance(backend, value, state); - lua_pop_value(state, 1); - return; - } - - expand_class(backend, value, state); - lua_pop_value(state, 2); -} - -bool engine::expand_value( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value, - lua_State* const state -) -{ - switch (lua_type(state, -1)) - { - case engine::lua_type_nil: - case engine::lua_type_table: - return (false); - case engine::lua_type_light_user_data: - case engine::lua_type_user_data: - { - expand_user_data(backend, value, state); - return (true); - } - default: NODEFAULT; - } - -#ifdef DEBUG - return (false); -#endif // #ifdef DEBUG -} - -engine::engine() : - m_instance_count(0) -{ -} diff --git a/src/xrServerEntities/lua_studio.h b/src/xrServerEntities/lua_studio.h deleted file mode 100644 index 1b74cabab..000000000 --- a/src/xrServerEntities/lua_studio.h +++ /dev/null @@ -1,154 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : lua_studio.h -// Created : 21.08.2008 -// Modified : 21.08.2008 -// Author : Dmitriy Iassenev -// Description : lua studio engine class (copied from the lua studio SDK) -//////////////////////////////////////////////////////////////////////////// - -#ifndef LUA_STUDIO_H_INCLUDED -#define LUA_STUDIO_H_INCLUDED - -#ifdef DEBUG -# define CS_LUA_DEBUGGER_USE_DEBUG_LIBRARY -#endif// #ifdef DEBUG - -#include -#include - -namespace luabind -{ - namespace detail - { - class class_rep; - } // namespace detail -} // namespace luabind - -class lua_studio_engine : - public cs::lua_studio::engine, - private boost::noncopyable -{ -public: - virtual int CS_LUA_STUDIO_BACKEND_CALL luaL_loadstring(lua_State* L, const char* s); - virtual int CS_LUA_STUDIO_BACKEND_CALL luaL_newmetatable(lua_State* L, const char* tname); - -public: - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_createtable(lua_State* L, int narray, int nrec); - - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_sethook(lua_State* L, lua_Hook func, lua_mask_type mask, int count); - virtual lua_Hook CS_LUA_STUDIO_BACKEND_CALL lua_gethook(lua_State* L); - - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_getinfo(lua_State* L, const char* what, lua_Debug* ar); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_getfenv(lua_State* L, int idx); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_getfield(lua_State* L, int idx, const char* k); - virtual char const* CS_LUA_STUDIO_BACKEND_CALL lua_getlocal(lua_State* L, const lua_Debug* ar, int n); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_gettable(lua_State* L, int idx); - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_getstack(lua_State* L, int level, lua_Debug* ar); - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_gettop(lua_State* L); - virtual char const* CS_LUA_STUDIO_BACKEND_CALL lua_getupvalue(lua_State* L, int funcindex, int n); - - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_iscfunction(lua_State* L, int idx); - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_next(lua_State* L, int idx); - - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_pcall(lua_State* L, int nargs, int nresults, int errfunc); - - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_pushcclosure(lua_State* L, lua_CFunction fn, int n); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_pushnil(lua_State* L); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_pushstring(lua_State* L, const char* s); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_pushvalue(lua_State* L, int idx); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_pushnumber(lua_State* L, lua_Number idx); - - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_remove(lua_State* L, int idx); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_replace(lua_State* L, int idx); - - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_setfenv(lua_State* L, int idx); - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_setmetatable(lua_State* L, int objindex); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_settable(lua_State* L, int idx); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_settop(lua_State* L, int idx); - - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_toboolean(lua_State* L, int idx); - virtual lua_Integer CS_LUA_STUDIO_BACKEND_CALL lua_tointeger(lua_State* L, int idx); - virtual char const* CS_LUA_STUDIO_BACKEND_CALL lua_tolstring(lua_State* L, int idx, size_t* len); - virtual lua_Number CS_LUA_STUDIO_BACKEND_CALL lua_tonumber(lua_State* L, int idx); - virtual const void* CS_LUA_STUDIO_BACKEND_CALL lua_topointer(lua_State* L, int idx); - - virtual bool CS_LUA_STUDIO_BACKEND_CALL lua_isnumber(lua_State* L, int idx); - - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_type(lua_State* L, int idx); - virtual char const* CS_LUA_STUDIO_BACKEND_CALL lua_typename(lua_State* L, int t); - -public: - virtual lua_Debug* CS_LUA_STUDIO_BACKEND_CALL lua_debug_create(); - virtual void CS_LUA_STUDIO_BACKEND_CALL lua_debug_destroy(lua_Debug*& instance); - virtual char const* CS_LUA_STUDIO_BACKEND_CALL lua_debug_get_name(lua_Debug& instance); - virtual char const* CS_LUA_STUDIO_BACKEND_CALL lua_debug_get_source(lua_Debug& instance); - virtual char const* CS_LUA_STUDIO_BACKEND_CALL lua_debug_get_short_source(lua_Debug& instance); - virtual int CS_LUA_STUDIO_BACKEND_CALL lua_debug_get_current_line(lua_Debug& instance); - -public: - virtual void CS_LUA_STUDIO_BACKEND_CALL log(log_message_types message_type, char const* message); - virtual bool CS_LUA_STUDIO_BACKEND_CALL type_to_string(char* buffer, unsigned int size, lua_State* state, int index, - bool& use_in_description); - virtual bool CS_LUA_STUDIO_BACKEND_CALL value_to_string(cs::lua_studio::backend& backend, char* buffer, - unsigned int size, lua_State* state, int index, - cs::lua_studio::icon_type& icon_type, - bool full_description); - virtual bool CS_LUA_STUDIO_BACKEND_CALL expand_value(cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value, lua_State* state); - virtual bool CS_LUA_STUDIO_BACKEND_CALL push_value(lua_State* state, char const* id, - cs::lua_studio::icon_type icon_type); - -public: - lua_studio_engine(); - -private: - void type_convert_class(char* buffer, unsigned int size, lua_State* state, int index); - bool type_convert_instance(char* buffer, unsigned int size, lua_State* state, int index); - void type_convert_userdata(char* buffer, unsigned int size, lua_State* state, int index); - static char* class_name(char* buffer, unsigned int size, luabind::detail::class_rep& class_rep); - -private: - void fill_class_info(cs::lua_studio::backend& backend, char* buffer, unsigned int size, - luabind::detail::object_rep* object, luabind::detail::class_rep* class_rep, lua_State* state); - void value_convert_class(cs::lua_studio::backend& backend, char* buffer, unsigned int size, - luabind::detail::class_rep* class_rep, lua_State* state, int index, - cs::lua_studio::icon_type& icon_type, bool full_description); - bool value_convert_instance(cs::lua_studio::backend& backend, char* buffer, unsigned int size, - luabind::detail::object_rep* object, lua_State* state); - bool value_convert_instance(cs::lua_studio::backend& backend, char* buffer, unsigned int size, lua_State* state, - int index, cs::lua_studio::icon_type& icon_type, bool full_description); - -private: - void push_class(lua_State* state, char const* id); - void push_class_base(lua_State* state, char const* id); - void push_class_instance(lua_State* state, char const* id); - void push_user_data(lua_State* state, char const* id, cs::lua_studio::icon_type icon_type); - -private: - void fill_class_data( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value_to_expand, - lua_State* const state - ); - void expand_class( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value, - lua_State* const state - ); - void expand_class_instance( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value_to_expand, - lua_State* const state - ); - void expand_user_data( - cs::lua_studio::backend& backend, - cs::lua_studio::value_to_expand& value, - lua_State* const state - ); - -private: - lua_Debug m_instances[2]; - u32 m_instance_count; -}; - -#endif // #ifndef LUA_STUDIO_H_INCLUDED diff --git a/src/xrServerEntities/object_factory_script.cpp b/src/xrServerEntities/object_factory_script.cpp index d727d13a6..0c885080a 100644 --- a/src/xrServerEntities/object_factory_script.cpp +++ b/src/xrServerEntities/object_factory_script.cpp @@ -105,6 +105,7 @@ void CObjectFactory::script_register(lua_State* L) .def("register", (void (CObjectFactory::*)(LPCSTR, LPCSTR, LPCSTR, LPCSTR))(&CObjectFactory::register_script_class)) .def("register", (void (CObjectFactory::*)(LPCSTR, LPCSTR, LPCSTR))(&CObjectFactory::register_script_class)) + .def("register_script", &CObjectFactory::register_script) ]; } diff --git a/src/xrServerEntities/script_callStack.cpp b/src/xrServerEntities/script_callStack.cpp deleted file mode 100644 index 37228cb12..000000000 --- a/src/xrServerEntities/script_callStack.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "stdafx.h" - -#include "script_CallStack.h" -#include "script_debugger.h" - -CScriptCallStack::CScriptCallStack(CScriptDebugger* d) - : m_debugger(d) -{ -} - -CScriptCallStack::~CScriptCallStack() -{ -} - -/* -int CCallStack::OnSci(CScintillaView* pView, SCNotification* pNotify) -{ - CLuaEditor* pEditor = ((CScintillaView*)GetView(0))->GetEditor(); - - CPoint pt; - int nLine; - CString strLine; - switch (pNotify->nmhdr.code) - { - case SCN_DOUBLECLICK: - GetCursorPos(&pt); - pEditor->ScreenToClient(&pt); - nLine = pEditor->LineFromPoint(pt); - GotoStackTraceLevel(nLine-1); - break; - }; - - return 0; -} -*/ - -void CScriptCallStack::Clear() -{ - m_nCurrentLevel = -1; - m_lines.clear(); - m_files.clear(); -} - -void CScriptCallStack::Add(const char* szDesc, const char* szFile, int nLine) -{ - m_lines.push_back(nLine); - - SPath sp; - sp.path[0] = 0; - m_files.push_back(sp); - xr_strcat(m_files.back().path, szFile); -} - -void CScriptCallStack::SetStackTraceLevel(int nLevel) -{ - m_nCurrentLevel = nLevel; - VERIFY(nLevel>=0 || (u32)nLevel < m_files.size()); -} - -void CScriptCallStack::GotoStackTraceLevel(int nLevel) -{ - if (nLevel < 0 || (u32)nLevel >= m_files.size()) - return; - - m_nCurrentLevel = nLevel; - - char* ppath = m_files[nLevel].path; - m_debugger->_SendMessage(DMSG_GOTO_FILELINE, - (WPARAM)ppath, - (LPARAM)m_lines[nLevel]); -} diff --git a/src/xrServerEntities/script_callStack.h b/src/xrServerEntities/script_callStack.h deleted file mode 100644 index 5fce60e90..000000000 --- a/src/xrServerEntities/script_callStack.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -class CScriptDebugger; - -struct SPath -{ - string_path path; -}; - -class CScriptCallStack -{ -public: - CScriptDebugger* m_debugger; - void GotoStackTraceLevel(int nLevel); - void Add(const char* szDesc, const char* szFile, int nLine); - void Clear(); - CScriptCallStack(CScriptDebugger* d); - ~CScriptCallStack(); - - int GetLevel() { return m_nCurrentLevel; }; - void SetStackTraceLevel(int); -protected: - int m_nCurrentLevel; - xr_vector m_levels; - xr_vector m_lines; - xr_vector m_files; -}; diff --git a/src/xrServerEntities/script_debugger.cpp b/src/xrServerEntities/script_debugger.cpp deleted file mode 100644 index cf28e4001..000000000 --- a/src/xrServerEntities/script_debugger.cpp +++ /dev/null @@ -1,583 +0,0 @@ -#include "stdafx.h" -#include "script_debugger.h" -#include "script_lua_helper.h" -#include "mslotutils.h" -// #include "../xrEngine/XR_IOConsole.h" - -//CScriptDebugger* CScriptDebugger::m_pDebugger = NULL; - - -void CScriptDebugger::SendMessageToIde(CMailSlotMsg& msg) -{ - if (CheckExisting(IDE_MAIL_SLOT)) - { - SendMailslotMessage(IDE_MAIL_SLOT, msg); - m_bIdePresent = true; - } - else - m_bIdePresent = false; -} - -LRESULT CScriptDebugger::_SendMessage(u32 message, WPARAM wParam, LPARAM lParam) -{ - // if ( (m_pDebugger)&&(m_pDebugger->Active())&&(message >= _DMSG_FIRST_MSG && message <= _DMSG_LAST_MSG) ) - // return m_pDebugger->DebugMessage(message, wParam, lParam); - if ((Active()) && (message >= _DMSG_FIRST_MSG && message <= _DMSG_LAST_MSG)) - return DebugMessage(message, wParam, lParam); - - return 0; -} - -LRESULT CScriptDebugger::DebugMessage(UINT nMsg, WPARAM wParam, LPARAM lParam) -{ - CMailSlotMsg msg; - - switch (nMsg) - { - case DMSG_NEW_CONNECTION: - { - msg.w_int(DMSG_NEW_CONNECTION); - SendMessageToIde(msg); - } - break; - - case DMSG_CLOSE_CONNECTION: - { - msg.w_int(DMSG_CLOSE_CONNECTION); - SendMessageToIde(msg); - } - break; - - case DMSG_WRITE_DEBUG: - { - msg.w_int(DMSG_WRITE_DEBUG); - msg.w_string((char*)wParam); - SendMessageToIde(msg); - } - break; - - case DMSG_GOTO_FILELINE: - { - msg.w_int(DMSG_GOTO_FILELINE); - msg.w_string((char*)wParam); - msg.w_int((int)lParam); - SendMessageToIde(msg); - } - break; - - case DMSG_DEBUG_BREAK: - { - msg.w_int(DMSG_ACTIVATE_IDE); - SendMessageToIde(msg); - WaitForReply(true); - } - break; - - case DMSG_CLEAR_STACKTRACE: - { - m_callStack->Clear(); - msg.w_int(DMSG_CLEAR_STACKTRACE); - SendMessageToIde(msg); - } - break; - - case DMSG_ADD_STACKTRACE: - { - m_callStack->Add(((StackTrace*)wParam)->szDesc, - ((StackTrace*)wParam)->szFile, - ((StackTrace*)wParam)->nLine); - - msg.w_int(DMSG_ADD_STACKTRACE); - msg.w_buff((StackTrace*)wParam, sizeof(StackTrace)); - SendMessageToIde(msg); - } - break; - - case DMSG_GOTO_STACKTRACE_LEVEL: - { - m_callStack->GotoStackTraceLevel((int)wParam); - StackLevelChanged(); - } - break; - - case DMSG_CLEAR_LOCALVARIABLES: - { - msg.w_int(DMSG_CLEAR_LOCALVARIABLES); - SendMessageToIde(msg); - } - break; - - case DMSG_ADD_LOCALVARIABLE: - { - msg.w_int(DMSG_ADD_LOCALVARIABLE); - msg.w_buff((void*)wParam, sizeof(Variable)); - SendMessageToIde(msg); - } - break; - - case DMSG_CLEAR_THREADS: - { - msg.w_int(DMSG_CLEAR_THREADS); - SendMessageToIde(msg); - } - break; - - case DMSG_ADD_THREAD: - { - msg.w_int(DMSG_ADD_THREAD); - msg.w_buff((void*)wParam, sizeof(SScriptThread)); - SendMessageToIde(msg); - } - break; - - case DMSG_THREAD_CHANGED: - { - int nThreadID = (int)wParam; - DrawThreadInfo(nThreadID); - } - break; - - case DMSG_GET_VAR_TABLE: - { - DrawVariableInfo((char*)wParam); - } - break; - - - case DMSG_EVAL_WATCH: - { - string2048 res; - res[0] = 0; - Eval((const char*)wParam, res, sizeof(res)); - - msg.w_int(DMSG_EVAL_WATCH); - msg.w_string(res); - msg.w_string((const char*)wParam); - SendMessageToIde(msg); - } - break; - } //case - - return 0; -} - - -BOOL CScriptDebugger::Active() -{ - return m_bIdePresent; -} - -CScriptDebugger::CScriptDebugger() -{ - m_threads = xr_new(this); - m_callStack = xr_new(this); - m_lua = xr_new(this); - - ZeroMemory(m_curr_connected_mslot, sizeof(m_curr_connected_mslot)); - // m_pDebugger = this; - m_nLevel = 0; - m_mailSlot = CreateMailSlotByName(DEBUGGER_MAIL_SLOT); - - if (m_mailSlot == INVALID_HANDLE_VALUE) - { - m_bIdePresent = false; - return; - } - Connect(IDE_MAIL_SLOT); -} - -void CScriptDebugger::Connect(LPCSTR mslot_name) -{ - m_bIdePresent = CheckExisting(IDE_MAIL_SLOT); - ZeroMemory(m_curr_connected_mslot, sizeof(m_curr_connected_mslot)); - if (Active()) - { - _SendMessage(DMSG_NEW_CONNECTION, 0, 0); - CMailSlotMsg msg; - msg.w_int(DMSG_GET_BREAKPOINTS); - SendMessageToIde(msg); - WaitForReply(false); - xr_strcat(m_curr_connected_mslot, mslot_name); - } -} - -CScriptDebugger::~CScriptDebugger() -{ - if (Active()) - _SendMessage(DMSG_CLOSE_CONNECTION, 0, 0); - - CloseHandle(m_mailSlot); - - xr_delete(m_threads); - xr_delete(m_callStack); - xr_delete(m_lua); -} - -void CScriptDebugger::UnPrepareLua(lua_State* l, int idx) -{ - if (idx == -1) return; // !Active() - m_lua->UnPrepareLua(l, idx); -} - -int CScriptDebugger::PrepareLua(lua_State* l) -{ - // call this function immediatly before calling lua_pcall. - //returns index in stack for errorFunc - if (!Active())return -1; - - m_nMode = DMOD_NONE; - return m_lua->PrepareLua(l); -} - -BOOL CScriptDebugger::PrepareLuaBind() -{ - if (!Active())return FALSE; - - m_lua->PrepareLuaBind(); - m_nMode = DMOD_NONE; - - return TRUE; -} - -void CScriptDebugger::initiateDebugBreak() -{ - m_nMode = DMOD_BREAK; -} - -void CScriptDebugger::Write(const char* szMsg) -{ - _SendMessage(DMSG_WRITE_DEBUG, (WPARAM)szMsg, 0); -} - -void CScriptDebugger::LineHook(const char* szFile, int nLine) -{ - CheckNewMessages(); - if (m_nMode == DMOD_STOP) - { - // Console->Execute("quit"); - return; - } - - if ( - HasBreakPoint(szFile, nLine) || - m_nMode == DMOD_STEP_INTO || - m_nMode == DMOD_BREAK || - (m_nMode == DMOD_STEP_OVER && m_nLevel <= 0) || - (m_nMode == DMOD_STEP_OUT && m_nLevel < 0) || - (m_nMode == DMOD_RUN_TO_CURSOR && - xr_strcmp(m_strPathName, szFile) && - m_nLine == nLine)) - { - DebugBreak(szFile, nLine); - GetBreakPointsFromIde(); - } -} - -void CScriptDebugger::FunctionHook(const char* szFile, int nLine, BOOL bCall) -{ - if (m_nMode == DMOD_STOP) - return; - - m_nLevel += (bCall ? 1 : -1); -} - -void CScriptDebugger::DrawThreadInfo(int nThreadID) -{ - //find corresponding lua_state - lua_State* ls = m_threads->FindScript(nThreadID); - if (!ls) - return; - m_lua->set_lua(ls); - DrawCurrentState(); -} - -void CScriptDebugger::DrawCurrentState() -{ - m_lua->DrawStackTrace(); - m_callStack->SetStackTraceLevel(0); - m_lua->DrawGlobalVariables(); - _SendMessage(DMSG_GOTO_STACKTRACE_LEVEL, GetStackTraceLevel(), 0); -} - -void CScriptDebugger::DebugBreak(const char* szFile, int nLine) -{ - m_nMode = DMOD_NONE; - - m_threads->Fill(); - m_threads->DrawThreads(); - - DrawCurrentState(); - - _SendMessage(DMSG_DEBUG_BREAK, 0, 0); -} - -void CScriptDebugger::GetBreakPointsFromIde() -{ - CMailSlotMsg msg; - msg.w_int(DMSG_GET_BREAKPOINTS); - SendMessageToIde(msg); - WaitForReply(false); -} - -void CScriptDebugger::ErrorBreak(const char* szFile, int nLine) -{ - if (Active()) - DebugBreak(szFile, nLine); -} - -void CScriptDebugger::ClearStackTrace() -{ - _SendMessage(DMSG_CLEAR_STACKTRACE, 0, 0); -} - -void CScriptDebugger::AddStackTrace(const char* szDesc, const char* szFile, int nLine) -{ - StackTrace st; - xr_strcat(st.szDesc, szDesc); - xr_strcat(st.szFile, szFile); - st.nLine = nLine; - _SendMessage(DMSG_ADD_STACKTRACE, (WPARAM)&st, 0); -} - -int CScriptDebugger::GetStackTraceLevel() -{ - return m_callStack->GetLevel(); -} - -void CScriptDebugger::StackLevelChanged() -{ - m_lua->DrawLocalVariables(); -} - -void CScriptDebugger::DrawVariableInfo(char* varName) -{ - m_lua->DrawVariableInfo(varName); -} - -void CScriptDebugger::ClearLocalVariables() -{ - _SendMessage(DMSG_CLEAR_LOCALVARIABLES, 0, 0); -} - -void CScriptDebugger::AddLocalVariable(const Variable& var) -{ - _SendMessage(DMSG_ADD_LOCALVARIABLE, (WPARAM)&var, 0); -} - -void CScriptDebugger::ClearGlobalVariables() -{ - _SendMessage(DMSG_CLEAR_GLOBALVARIABLES, 0, 0); -} - -void CScriptDebugger::AddGlobalVariable(const char* name, const char* type, const char* value) -{ - Variable var; - xr_strcat(var.szName, name); - xr_strcat(var.szType, type); - xr_strcat(var.szValue, value); - _SendMessage(DMSG_ADD_GLOBALVARIABLE, (WPARAM)&var, 0); -} - - -void CScriptDebugger::Eval(const char* strCode, char* res, int res_sz) -{ - string1024 strCodeFull; - strCodeFull[0] = 0; - const char* r = "return "; - strconcat(sizeof(strCodeFull), strCodeFull, r, strCode); - m_lua->Eval(strCodeFull, res, res_sz); -} - -void CScriptDebugger::CheckNewMessages() -{ - CMailSlotMsg msg; - while (CheckMailslotMessage(m_mailSlot, msg)) - { - TranslateIdeMessage(&msg); - }; -} - -void CScriptDebugger::WaitForReply(bool bWaitForModalResult) //UINT nMsg) -{ - bool mr = false; - do - { - CMailSlotMsg msg; - while (true) - { - if (CheckMailslotMessage(m_mailSlot, msg)) break; - Sleep(10); - }; - R_ASSERT(msg.GetLen()); - - mr = TranslateIdeMessage(&msg); //mr--is this an ide modalResult ? - } - while (bWaitForModalResult && !mr); -} - -bool CScriptDebugger::TranslateIdeMessage(CMailSlotMsg* msg) -{ - int nType; - msg->r_int(nType); - switch (nType) - { - case DMSG_DEBUG_GO: - { - m_nMode = DMOD_NONE; - return true; - } - break; - - case DMSG_DEBUG_BREAK: - { - m_nMode = DMOD_BREAK; - return true; - } - break; - - case DMSG_DEBUG_STEP_INTO: - { - m_nMode = DMOD_STEP_INTO; - return true; - } - break; - - case DMSG_DEBUG_STEP_OVER: - { - m_nLevel = 0; - m_nMode = DMOD_STEP_OVER; - return true; - } - break; - - case DMSG_DEBUG_STEP_OUT: - { - m_nLevel = 0; - m_nMode = DMOD_STEP_OUT; - return true; - } - break; - - case DMSG_DEBUG_RUN_TO_CURSOR: - { - //DMOD_RUN_TO_CURSOR; - return true; - } - break; - - case DMSG_STOP_DEBUGGING: - { - m_nMode = DMOD_STOP; - // Console->Execute("quit"); - return true; - } - break; - - case DMSG_GOTO_STACKTRACE_LEVEL: - { - int nLevel; - msg->r_int(nLevel); - _SendMessage(DMSG_GOTO_STACKTRACE_LEVEL, nLevel, 0); - return false; - } - break; - - case DMSG_GET_BREAKPOINTS: - { - FillBreakPointsIn(msg); - return false; - } - break; - - case DMSG_THREAD_CHANGED: - { - int nThreadID; - msg->r_int(nThreadID); - _SendMessage(DMSG_THREAD_CHANGED, nThreadID, 0); - return false; - } - break; - - case DMSG_GET_VAR_TABLE: - { - string512 varName; - varName[0] = 0; - msg->r_string(varName); - _SendMessage(DMSG_GET_VAR_TABLE, (WPARAM)varName, 0); - return false; - } - break; - - - case DMSG_EVAL_WATCH: - { - string2048 watch; - watch[0] = 0; - int iItem; - msg->r_string(watch); - msg->r_int(iItem); - _SendMessage(DMSG_EVAL_WATCH, (WPARAM)watch, (LPARAM)iItem); - return false; - } - break; - - - default: - return false; - } -} - -bool CScriptDebugger::HasBreakPoint(const char* fileName, s32 lineNum) -{ - string256 sFileName; - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - char ext[_MAX_EXT]; - - _splitpath(fileName, drive, dir, sFileName, ext); - - - for (u32 i = 0; i < m_breakPoints.size(); ++i) - { - SBreakPoint bp(m_breakPoints[i]); - if (bp.nLine == lineNum) - if (xr_strlen(bp.fileName) == xr_strlen(sFileName)) - { - if (stricmp(*bp.fileName, sFileName) == 0) - return true; - } - } - return false; -} - -void CScriptDebugger::FillBreakPointsIn(CMailSlotMsg* msg) -{ - m_breakPoints.clear(); - s32 nCount = 0; - msg->r_int(nCount); - for (s32 i = 0; i < nCount; ++i) - { - SBreakPoint bp; - string256 fn; - msg->r_string(fn); - bp.fileName = fn; - s32 bpCount = 0; - msg->r_int(bpCount); - - for (s32 j = 0; j < bpCount; ++j) - { - msg->r_int(bp.nLine); - m_breakPoints.push_back(bp); - } - } -} - -void CScriptDebugger::ClearThreads() -{ - _SendMessage(DMSG_CLEAR_THREADS, 0, 0); -} - -void CScriptDebugger::AddThread(SScriptThread& th) -{ - _SendMessage(DMSG_ADD_THREAD, (WPARAM)(&th), 0); -} diff --git a/src/xrServerEntities/script_debugger.h b/src/xrServerEntities/script_debugger.h deleted file mode 100644 index 66b41f20b..000000000 --- a/src/xrServerEntities/script_debugger.h +++ /dev/null @@ -1,110 +0,0 @@ -#pragma once - -#include "script_lua_helper.h" -#include "script_debugger_threads.h" -#include "script_CallStack.h" -#include "script_debugger_messages.h" -//#include "script_debugger_utils.h" - -class CMailSlotMsg; -struct lua_State; - -#define DMOD_NONE 0 -#define DMOD_STEP_INTO 1 -#define DMOD_STEP_OVER 2 -#define DMOD_STEP_OUT 3 -#define DMOD_RUN_TO_CURSOR 4 -//#define DMOD_SHOW_STACK_LEVEL 5 - -#define DMOD_BREAK 10 -#define DMOD_STOP 11 - -struct SBreakPoint -{ - shared_str fileName; - s32 nLine; - SBreakPoint() { nLine = 0; }; - - SBreakPoint(const SBreakPoint& other) - { - operator =(other); - }; - - SBreakPoint& operator =(const SBreakPoint& other) - { - fileName = other.fileName; - nLine = other.nLine; - return *this; - } -}; - -class CScriptDebugger -{ -public: - void Connect(LPCSTR mslot_name); - void Eval(const char* strCode, char* res, int res_sz); - void AddLocalVariable(const Variable& var); - void ClearLocalVariables(); - void AddGlobalVariable(const char* name, const char* type, const char* value); - void ClearGlobalVariables(); - void StackLevelChanged(); - void initiateDebugBreak(); - void DebugBreak(const char* szFile, int nLine); - void ErrorBreak(const char* szFile = 0, int nLine = 0); - void LineHook(const char* szFile, int nLine); - void FunctionHook(const char* szFile, int nLine, BOOL bCall); - void Write(const char* szMsg); - - int PrepareLua(lua_State*); - void UnPrepareLua(lua_State* l, int idx); - BOOL PrepareLuaBind(); - - CScriptDebugger(); - virtual ~CScriptDebugger(); - - void Go(); - void StepInto(); - void StepOver(); - void StepOut(); - void RunToCursor(); - - void ClearThreads(); - void AddThread(SScriptThread&); - - void ClearStackTrace(); - void AddStackTrace(const char* strDesc, const char* strFile, int nLine); - int GetStackTraceLevel(); - - BOOL Active(); - // static CScriptDebugger* GetDebugger () { return m_pDebugger; }; - LRESULT _SendMessage(UINT message, WPARAM wParam, LPARAM lParam); - -protected: - void DrawVariableInfo(char* varName); - void DrawCurrentState(); - void DrawThreadInfo(int nThreadID); - void GetBreakPointsFromIde(); - void FillBreakPointsIn(CMailSlotMsg* msg); - bool HasBreakPoint(const char* fileName, s32 lineNum); - void CheckNewMessages(); - LRESULT DebugMessage(UINT nMsg, WPARAM wParam, LPARAM lParam); - void WaitForReply(bool bWaitForModalResult); - bool TranslateIdeMessage(CMailSlotMsg*); - void SendMessageToIde(CMailSlotMsg&); - - - CDbgScriptThreads* m_threads; - CDbgLuaHelper* m_lua; - CScriptCallStack* m_callStack; - // static CScriptDebugger* m_pDebugger; - int m_nMode; - int m_nLevel; //for step into/over/out - string_path m_strPathName; //for run_to_line_number - int m_nLine; //for run_to_line_number - - HANDLE m_mailSlot; - BOOL m_bIdePresent; - - xr_vector m_breakPoints; - string_path m_curr_connected_mslot; -}; diff --git a/src/xrServerEntities/script_debugger_messages.h b/src/xrServerEntities/script_debugger_messages.h deleted file mode 100644 index cc0993da4..000000000 --- a/src/xrServerEntities/script_debugger_messages.h +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once - -struct StackTrace -{ - char szDesc[255]; - char szFile[255]; - int nLine; - - StackTrace() - { - szDesc[0] = 0; - szFile[0] = 0; - nLine = 0; - }; -}; - -struct Variable -{ - char szName[255]; - char szType[50]; - char szValue[255]; - - Variable() - { - szName[0] = 0; - szType[0] = 0; - szValue[0] = 0; - }; -}; - -struct lua_State; - -struct SScriptThread -{ - // void* pScript; - lua_State* lua; - int scriptID; - bool active; - char name[255]; - char process[255]; - - SScriptThread():/**pScript(0),/**/lua(0), scriptID(-1), active(false) - { - name[0] = 0; - process[0] = 0; - }; - - SScriptThread(const SScriptThread& other) - { - operator =(other); - }; - - SScriptThread& operator =(const SScriptThread& other) - { - // pScript = other.pScript; - lua = other.lua; - scriptID = other.scriptID; - active = other.active; - name[0] = 0; - process[0] = 0; - xr_strcat(name, other.name); - xr_strcat(process, other.process); - - return *this; - } -}; - - -#define DEBUGGER_MAIL_SLOT "\\\\.\\mailslot\\script_debugger_mailslot" -#define IDE_MAIL_SLOT "\\\\.\\mailslot\\script_ide_mailslot" - -enum dbg_messages -{ - _DMSG_FIRST_MSG =WM_USER + 1, - DMSG_WRITE_DEBUG, - DMSG_HAS_BREAKPOINT, - DMSG_GOTO_FILELINE, - DMSG_DEBUG_START, - DMSG_DEBUG_BREAK, - DMSG_DEBUG_END, - DMSG_CLEAR_STACKTRACE, - DMSG_ADD_STACKTRACE, - DMSG_GOTO_STACKTRACE_LEVEL, - DMSG_GET_STACKTRACE_LEVEL, - DMSG_CLEAR_LOCALVARIABLES, - DMSG_ADD_LOCALVARIABLE, - DMSG_CLEAR_GLOBALVARIABLES, - DMSG_ADD_GLOBALVARIABLE, - DMSG_EVAL_WATCH, - DMSG_ACTIVATE_IDE, - DMSG_DEBUG_STEP_INTO, - DMSG_DEBUG_STEP_OVER, - DMSG_DEBUG_STEP_OUT, - DMSG_DEBUG_RUN_TO_CURSOR, - DMSG_STOP_DEBUGGING, - DMSG_GOTO_IDE_STACKTRACE_LEVEL, - DMSG_NEW_CONNECTION, - DMSG_DEBUG_GO, - DMSG_GET_BREAKPOINTS, - DMSG_CLEAR_THREADS, - DMSG_ADD_THREAD, - DMSG_THREAD_CHANGED, - DMSG_GET_VAR_TABLE, - DMSG_CLOSE_CONNECTION, - - _DMSG_LAST_MSG, -}; diff --git a/src/xrServerEntities/script_debugger_threads.cpp b/src/xrServerEntities/script_debugger_threads.cpp deleted file mode 100644 index 1d9702785..000000000 --- a/src/xrServerEntities/script_debugger_threads.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "stdafx.h" -#include "script_debugger_threads.h" -#include "ai_space.h" -#include "script_process.h" -#include "script_engine.h" -#include "script_engine_space.h" -#include "script_thread.h" -#include "script_debugger.h" - - -u32 CDbgScriptThreads::Fill() -{ - u32 res = 0; - -#ifdef XRGAME_EXPORTS - CScriptProcess* sp = ai().script_engine().script_process(ScriptEngine::eScriptProcessorGame); - - if (sp) - res += FillFrom(sp); - - sp = ai().script_engine().script_process(ScriptEngine::eScriptProcessorLevel); - if (sp) - res += FillFrom(sp); - - return res; -#else - return res; -#endif -} - -u32 CDbgScriptThreads::FillFrom(CScriptProcess* sp) -{ - m_threads.clear(); - const CScriptProcess::SCRIPT_REGISTRY& vScripts = sp->scripts(); - CScriptProcess::SCRIPT_REGISTRY::const_iterator It = vScripts.begin(); - for (; It != vScripts.end(); ++It) - { - SScriptThread th; - // th.pScript = (*It); - th.lua = (*It)->lua(); - th.scriptID = (*It)->thread_reference(); - th.active = (*It)->active(); - xr_strcat(th.name, *(*It)->script_name()); - xr_strcat(th.process, *sp->name()); - m_threads.push_back(th); - } - return m_threads.size(); -} - -lua_State* CDbgScriptThreads::FindScript(int nThreadID) -{ - xr_vector::iterator It = m_threads.begin(); - for (; It != m_threads.end(); ++It) - { - if ((*It).scriptID == nThreadID) - return (*It).lua; - } - return 0; -} - -void CDbgScriptThreads::DrawThreads() -{ - //CScriptDebugger::GetDebugger()->ClearThreads(); - m_debugger->ClearThreads(); - xr_vector::iterator It = m_threads.begin(); - for (; It != m_threads.end(); ++It) - { - SScriptThread th; - th = *It; - m_debugger->AddThread(th); - } -} diff --git a/src/xrServerEntities/script_debugger_threads.h b/src/xrServerEntities/script_debugger_threads.h deleted file mode 100644 index d88aba7b1..000000000 --- a/src/xrServerEntities/script_debugger_threads.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "script_debugger_messages.h" - -class CScriptProcess; -class CScriptDebugger; -struct lua_State; - -class CDbgScriptThreads -{ - xr_vector m_threads; -public: - CScriptDebugger* m_debugger; - - CDbgScriptThreads(CScriptDebugger* d): m_debugger(d) - { - }; - - ~CDbgScriptThreads() - { - }; - u32 FillFrom(CScriptProcess*); - u32 Fill(); - lua_State* FindScript(int nthreadID); - void DrawThreads(); -}; diff --git a/src/xrServerEntities/script_engine.cpp b/src/xrServerEntities/script_engine.cpp index a5bb90ff1..c839b3d61 100644 --- a/src/xrServerEntities/script_engine.cpp +++ b/src/xrServerEntities/script_engine.cpp @@ -8,606 +8,953 @@ #include "pch_script.h" #include "script_engine.h" +#include "script_storage.h" #include "ai_space.h" #include "object_factory.h" -#include "script_process.h" #include "../build_config_defines.h" -#include "script_storage.h" +#include "../xrCore/mezz_stringbuffer.h" +#include #include #include +#include +#include "luabind/object.hpp" +#include "luabind/functor.hpp" -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO -# include "script_debugger.h" -# else //USE_LUA_STUDIO -# include "lua_studio.h" -typedef cs::lua_studio::create_world_function_type create_world_function_type; -typedef cs::lua_studio::destroy_world_function_type destroy_world_function_type; - -static create_world_function_type s_create_world = 0; -static destroy_world_function_type s_destroy_world = 0; -static HMODULE s_script_debugger_handle = 0; -static LogCallback s_old_log_callback = 0; -# endif //!USE_LUA_STUDIO -#endif +using namespace ScriptEngine; -#ifndef XRSE_FACTORY_EXPORTS -# ifdef DEBUG -# include "ai_debug.h" -extern Flags32 psAI_Flags; -# endif //-DEBUG -#endif //!XRSE_FACTORY_EXPORTS +#if !defined(DEBUG) && defined(USE_LUAJIT_ONE) +# include "opt.lua.h" +# include "opt_inline.lua.h" +#endif //!DEBUG && USE_LUAJIT_ONE +#ifndef USE_LUAJIT_ONE #include "lua.hpp" - -#ifdef USE_LUAJIT_ONE -void jit_command(lua_State*, LPCSTR); #endif -#if defined(USE_DEBUGGER) && defined(USE_LUA_STUDIO) -static void log_callback (LPCSTR message) -{ - if (s_old_log_callback) - s_old_log_callback (message); +#ifndef ENGINE_BUILD +# include "script_engine.h" +# include "ai_space.h" +#else //ENGINE_BUILD +# define NO_XRGAME_SCRIPT_ENGINE +#endif //!ENGINE_BUILD - if (!ai().script_engine().debugger()) - return; +#ifndef XRGAME_EXPORTS +# define NO_XRGAME_SCRIPT_ENGINE +#endif //!XRGAME_EXPORTS - ai().script_engine().debugger()->add_log_line (message); -} +#ifndef NO_XRGAME_SCRIPT_ENGINE +# include "ai_debug.h" +#endif //!NO_XRGAME_SCRIPT_ENGINE -static void initialize_lua_studio ( lua_State* state, cs::lua_studio::world*& world, lua_studio_engine*& engine) +#ifndef PURE_ALLOC +//# ifndef USE_MEMORY_MONITOR +//# define USE_DL_ALLOCATOR +//# endif //!USE_MEMORY_MONITOR +#endif //!PURE_ALLOC + +extern void export_classes(lua_State* L); +extern int luaopen_lua_extensions(lua_State* L); + +struct raii_guard : private boost::noncopyable { - engine = 0; - world = 0; + int m_error_code; + LPCSTR const& m_error_description; - u32 const old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS); - s_script_debugger_handle = LoadLibrary(CS_LUA_STUDIO_BACKEND_FILE_NAME); - SetErrorMode (old_error_mode); - if (!s_script_debugger_handle) { - Msg ("! cannot load %s dynamic library", CS_LUA_STUDIO_BACKEND_FILE_NAME); - return; + raii_guard(int error_code, LPCSTR const& m_description) : m_error_code(error_code), + m_error_description(m_description) + { } - R_ASSERT2 (s_script_debugger_handle, "can't load script debugger library"); + ~raii_guard() + { +#ifdef DEBUG + static bool const break_on_assert = !!strstr(Core.Params, "-break_on_assert"); +#else //!DEBUG + static bool const break_on_assert = false; //Alundaio: Can't get a proper stack trace with this enabled +#endif //-DEBUG + if (!m_error_code) + return; + + if (break_on_assert) + R_ASSERT2(!m_error_code, m_error_description); + else + Msg("! [SCRIPT ERROR]: %s", m_error_description); + } +}; //-struct raii_guard - s_create_world = (create_world_function_type) - GetProcAddress( - s_script_debugger_handle, - "_cs_lua_studio_backend_create_world@12" - ); - R_ASSERT2 (s_create_world, "can't find function \"cs_lua_studio_backend_create_world\""); +#ifndef USE_DL_ALLOCATOR +static void* lua_alloc(void* ud, void* ptr, size_t osize, size_t nsize) +{ + (void)ud; + (void)osize; + if (nsize == 0) + { + xr_free(ptr); + return NULL; + } + else +#ifdef DEBUG_MEMORY_NAME + return Memory.mem_realloc(ptr, nsize, "LUA"); +#else // DEBUG_MEMORY_MANAGER + return Memory.mem_realloc(ptr, nsize); +#endif // DEBUG_MEMORY_MANAGER +} - s_destroy_world = (destroy_world_function_type) - GetProcAddress( - s_script_debugger_handle, - "_cs_lua_studio_backend_destroy_world@4" - ); - R_ASSERT2 (s_destroy_world, "can't find function \"cs_lua_studio_backend_destroy_world\" in the library"); +u32 game_lua_memory_usage() +{ + return (0); +} +#else //USE_DL_ALLOCATOR - engine = xr_new(); - world = s_create_world( *engine, false, false ); - VERIFY (world); +# ifdef USE_ARENA_ALLOCATOR +static const u32 s_arena_size = 96 * 1024 * 1024; +static char s_fake_array[s_arena_size]; +// static doug_lea_allocator s_allocator( s_fake_array, s_arena_size, "lua" ); +# else //-USE_ARENA_ALLOCATOR +// static doug_lea_allocator s_allocator(0, 0, "lua"); +# endif //-USE_ARENA_ALLOCATOR - s_old_log_callback = SetLogCB(&log_callback); +static void* lua_alloc(void* ud, void* ptr, size_t osize, size_t nsize) +{ +#ifndef USE_MEMORY_MONITOR + (void)ud; + (void)osize; + if (!nsize) + { + s_allocator.free_impl(ptr); + return 0; + } + if (!ptr) + return s_allocator.malloc_impl((u32)nsize); + + return s_allocator.realloc_impl(ptr, (u32)nsize); +#else //USE_MEMORY_MONITOR + if (!nsize) { + memory_monitor::monitor_free(ptr); + s_allocator.free_impl(ptr); + return NULL; + } -#ifdef USE_LUAJIT_ONE - jit_command (state, "debug=2"); - jit_command (state, "off"); -#else - luaJIT_setmode(state, 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_OFF); -#endif + if (!ptr) { + void* const result = s_allocator.malloc_impl((u32)nsize); + memory_monitor::monitor_alloc(result, nsize, "LUA"); + return result; + } - world->add (state); + memory_monitor::monitor_free(ptr); + void* const result = s_allocator.realloc_impl(ptr, (u32)nsize); + memory_monitor::monitor_alloc(result, nsize, "LUA"); + return result; +#endif //!USE_MEMORY_MONITOR } -static void finalize_lua_studio ( lua_State* state, cs::lua_studio::world*& world, lua_studio_engine*& engine) +u32 game_lua_memory_usage() { - world->remove (state); - - VERIFY (world); - s_destroy_world (world); - world = 0; + return (s_allocator.get_allocated_size()); +} +#endif //!USE_DL_ALLOCATOR - VERIFY (engine); - xr_delete (engine); +static LPVOID __cdecl luabind_allocator( + luabind::memory_allocation_function_parameter const, + void const* const pointer, + size_t const size +) +{ + if (!size) + { + LPVOID non_const_pointer = const_cast(pointer); + xr_free(non_const_pointer); + return (0); + } - FreeLibrary (s_script_debugger_handle); - s_script_debugger_handle = 0; + if (!pointer) + { +#ifdef DEBUG + return (Memory.mem_alloc(size, "luabind")); +#else //!DEBUG + return (Memory.mem_alloc(size)); +#endif //-DEBUG + } - SetLogCB (s_old_log_callback); + LPVOID non_const_pointer = const_cast(pointer); +#ifdef DEBUG + return (Memory.mem_realloc(non_const_pointer, size, "luabind")); +#else //!DEBUG + return (Memory.mem_realloc(non_const_pointer, size)); +#endif //-DEBUG } -void CScriptEngine::try_connect_to_debugger () +void setup_luabind_allocator() { - if (m_lua_studio_world) - return; - - initialize_lua_studio ( lua(), m_lua_studio_world, m_lua_studio_engine ); + luabind::allocator = &luabind_allocator; + luabind::allocator_parameter = 0; } -void CScriptEngine::disconnect_from_debugger () -{ - if (!m_lua_studio_world) - return; - finalize_lua_studio ( lua(), m_lua_studio_world, m_lua_studio_engine ); -} -#endif //-(USE_DEBUGGER) && defined(USE_LUA_STUDIO) +#ifdef USE_LUAJIT_ONE // [1/14/2015 Andrey] -CScriptEngine::CScriptEngine() +/* ---- start of LuaJIT extensions */ +static void l_message(lua_State* state, const char* msg) { - m_stack_level = 0; - m_reload_modules = false; - m_last_no_file_length = 0; - *m_last_no_file = 0; - -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - m_scriptDebugger = NULL; - restartDebugger (); -# else //USE_LUA_STUDIO - m_lua_studio_world = 0; -# endif //!USE_LUA_STUDIO -#endif + Msg("! [LUA_JIT] %s", msg); } -CScriptEngine::~CScriptEngine() -{ - while (!m_script_processes.empty()) - remove_script_process(m_script_processes.begin()->first); -#ifdef LUA_DEBUG_PRINT - flush_log(); -#endif //-LUA_DEBUG_PRINT +static int report(lua_State* L, int status) +{ + if (status && !lua_isnil(L, -1)) + { + const char* msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(L, msg); + lua_pop(L, 1); + } + return status; +} + +static int loadjitmodule(lua_State* L, const char* notfound) +{ + lua_getglobal(L, "require"); + lua_pushliteral(L, "jit."); + lua_pushvalue(L, -3); + lua_concat(L, 2); + if (lua_pcall(L, 1, 1, 0)) + { + const char* msg = lua_tostring(L, -1); + if (msg && !strncmp(msg, "module ", 7)) + { + l_message(L, notfound); + return 1; + } + else + return report(L, 1); + } + lua_getfield(L, -1, "start"); + lua_remove(L, -2); /* drop module table */ + return 0; +} + +/* JIT engine control command: try jit library first or load add-on module */ +static int dojitcmd(lua_State* L, const char* cmd) +{ + const char* val = strchr(cmd, '='); + lua_pushlstring(L, cmd, val ? val - cmd : xr_strlen(cmd)); + lua_getglobal(L, "jit"); /* get jit.* table */ + lua_pushvalue(L, -2); + lua_gettable(L, -2); /* lookup library function */ + if (!lua_isfunction(L, -1)) + { + lua_pop(L, 2); /* drop non-function and jit.* table, keep module name */ + if (loadjitmodule(L, "unknown luaJIT command")) + return 1; + } + else + { + lua_remove(L, -2); /* drop jit.* table */ + } + lua_remove(L, -2); /* drop module name */ + if (val) lua_pushstring(L, val + 1); + return report(L, lua_pcall(L, val ? 1 : 0, 0, 0)); +} -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - xr_delete (m_scriptDebugger); -# else // #ifndef USE_LUA_STUDIO - disconnect_from_debugger(); -# endif // #ifndef USE_LUA_STUDIO -#endif +void jit_command(lua_State* state, LPCSTR command) +{ + dojitcmd(state, command); } -void CScriptEngine::unload() +#ifndef DEBUG +/* start optimizer */ +static int dojitopt(lua_State* L, const char* opt) { - lua_settop(lua(), m_stack_level); - m_last_no_file_length = 0; - *m_last_no_file = 0; + lua_pushliteral(L, "opt"); + if (loadjitmodule(L, "LuaJIT optimizer module not installed")) + return 1; + lua_remove(L, -2); /* drop module name */ + if (*opt) lua_pushstring(L, opt); + return report(L, lua_pcall(L, *opt ? 1 : 0, 0, 0)); } -int CScriptEngine::lua_panic(lua_State* L) +static void put_function(lua_State* state, u8 const* buffer, u32 const buffer_size, LPCSTR package_id) { - ai().script_engine().print_stack(); - print_output(L, "PANIC", LUA_ERRRUN); - return (0); + lua_getglobal(state, "package"); + lua_pushstring(state, "preload"); + lua_gettable(state, -2); + + lua_pushstring(state, package_id); + luaL_loadbuffer(state, (char*)buffer, buffer_size, package_id); + lua_settable(state, -3); } +/* ---- end of LuaJIT extensions */ +#endif //!DEBUG +#endif //-USE_LUAJIT_ONE + // demonized: get lua stack in array static std::vector get_lua_stack(lua_State* L) { - std::vector res; - lua_Debug l_tDebugInfo; - for (int i = 0; lua_getstack(L, i, &l_tDebugInfo); ++i) - { - lua_getinfo(L, "nSlu", &l_tDebugInfo); - if (!l_tDebugInfo.name) - { - res.push_back(make_string("%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, "")); - } else - { - if (!xr_strcmp(l_tDebugInfo.what, "C")) - { - res.push_back(make_string("%2d : [C ] %s", i, l_tDebugInfo.name)); - } else - { - res.push_back(make_string("%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, l_tDebugInfo.name)); - } - } - } - return res; -} - -void CScriptEngine::lua_error(lua_State* L) -{ - ai().script_engine().print_stack(); - print_output(L, "", LUA_ERRRUN); - ai().script_engine().on_error(L); - - // demonized: print first line with lua error - auto stack = get_lua_stack(L); - std::string lua_error_line = ""; - for (auto const& s : stack) { - if (s.find("[Lua]") != std::string::npos) { - lua_error_line = s; - break; - } - } - - auto error_str = make_string("\n%s\n\nLUA error: %s\n\nCheck log for details", lua_error_line.c_str(), lua_tostring(L, -1)); - LPCSTR error_msg = error_str.c_str(); - -#if !XRAY_EXCEPTIONS - Debug.fatal(DEBUG_INFO, error_msg); -#else - throw lua_tostring(L,-1); -#endif + std::vector res; + lua_Debug l_tDebugInfo; + for (int i = 0; lua_getstack(L, i, &l_tDebugInfo); ++i) + { + lua_getinfo(L, "nSlu", &l_tDebugInfo); + if (!l_tDebugInfo.name) + { + res.push_back(make_string("%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, "")); + } + else + { + if (!xr_strcmp(l_tDebugInfo.what, "C")) + { + res.push_back(make_string("%2d : [C ] %s", i, l_tDebugInfo.name)); + } + else + { + res.push_back(make_string("%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, l_tDebugInfo.name)); + } + } + } + return res; } void printLuaStack() { - ai().script_engine().print_stack(); + ai().script_engine().print_stack(); } -int CScriptEngine::lua_pcall_failed(lua_State* L) +void on_lua_error(lua_State* L) { - ai().script_engine().print_stack(); - print_output(L, "", LUA_ERRRUN); - ai().script_engine().on_error(L); + ai().script_engine().print_stack(); + ai().script_engine().print_output(L, "", LUA_ERRRUN); + ai().script_engine().on_error(L); - // demonized: print first line with lua error - auto stack = get_lua_stack(L); - std::string lua_error_line = ""; - for (auto const& s : stack) { - if (s.find("[Lua]") != std::string::npos) { - lua_error_line = s; - break; - } - } + // demonized: print first line with lua error + auto stack = get_lua_stack(L); + std::string lua_error_line = ""; + for (auto const& s : stack) { + if (s.find("[Lua]") != std::string::npos) { + lua_error_line = s; + break; + } + } - auto error_str = make_string("\n%s\n\nLUA error: %s\n\nCheck log for details", lua_error_line.c_str(), lua_isstring(L, -1) ? lua_tostring(L, -1) : ""); - LPCSTR error_msg = error_str.c_str(); + auto error_str = make_string("\n%s\n\nLUA error: %s\n\nCheck log for details", lua_error_line.c_str(), lua_tostring(L, -1)); + LPCSTR error_msg = error_str.c_str(); #if !XRAY_EXCEPTIONS - Debug.fatal(DEBUG_INFO, error_msg); + Debug.fatal(DEBUG_INFO, error_msg); +#else + throw lua_tostring(L, -1); #endif - if (lua_isstring(L, -1)) - lua_pop(L, 1); - return (LUA_ERRRUN); } -void lua_cast_failed(lua_State* L, LUABIND_TYPE_INFO info) +int on_lua_pcall_failed(lua_State* L) { - CScriptEngine::print_output(L, "", LUA_ERRRUN); + ai().script_engine().print_stack(); + ai().script_engine().print_output(L, "", LUA_ERRRUN); + ai().script_engine().on_error(L); - Debug.fatal(DEBUG_INFO, "LUA error: cannot cast lua value to %s", info->name()); -} + // demonized: print first line with lua error + auto stack = get_lua_stack(L); + std::string lua_error_line = ""; + for (auto const& s : stack) { + if (s.find("[Lua]") != std::string::npos) { + lua_error_line = s; + break; + } + } -void CScriptEngine::setup_callbacks() -{ -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - if( debugger() ) - debugger()->PrepareLuaBind (); -# endif // #ifndef USE_LUA_STUDIO -#endif + auto error_str = make_string("\n%s\n\nLUA error: %s\n\nCheck log for details", lua_error_line.c_str(), lua_isstring(L, -1) ? lua_tostring(L, -1) : ""); + LPCSTR error_msg = error_str.c_str(); -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - if (!debugger() || !debugger()->Active() ) -# endif // #ifndef USE_LUA_STUDIO -#endif - { #if !XRAY_EXCEPTIONS - luabind::set_error_callback(CScriptEngine::lua_error); + Debug.fatal(DEBUG_INFO, error_msg); #endif + if (lua_isstring(L, -1)) + lua_pop(L, 1); + return (LUA_ERRRUN); +} - luabind::set_pcall_callback(CScriptEngine::lua_pcall_failed); - } - -#if !XRAY_EXCEPTIONS - luabind::set_cast_failed_callback(lua_cast_failed); -#endif - lua_atpanic(lua(), CScriptEngine::lua_panic); +int on_lua_panic(lua_State* L) +{ + ai().script_engine().print_stack(); + ai().script_engine().print_output(L, "PANIC", LUA_ERRRUN); + return (0); } -#ifdef DEBUG -# include "script_thread.h" -void CScriptEngine::lua_hook_call (lua_State *L, lua_Debug *dbg) +void on_lua_cast_failed(lua_State* L, LUABIND_TYPE_INFO info) { - if (ai().script_engine().current_thread()) - ai().script_engine().current_thread()->script_hook(L,dbg); - else - ai().script_engine().m_stack_is_ready = true; + CScriptEngine::print_output(L, "", LUA_ERRRUN); + Debug.fatal(DEBUG_INFO, "LUA error: cannot cast lua value to %s", info->name()); } -#endif -int auto_load(lua_State* L) +CScriptEngine::CScriptEngine() { - if ((lua_gettop(L) < 2) || !lua_istable(L, 1) || !lua_isstring(L, 2)) - { - lua_pushnil(L); - return (1); - } +#ifdef DEBUG + m_stack_is_ready = false; +#endif //-DEBUG - ai().script_engine().process_file_if_exists(lua_tostring(L, 2), false); - lua_rawget(L, 1); - return (1); + m_virtual_machine = 0; + m_stack_level = 0; } -void CScriptEngine::setup_auto_load() +CScriptEngine::~CScriptEngine() { - luaL_newmetatable(lua(), "XRAY_AutoLoadMetaTable"); - lua_pushstring(lua(), "__index"); - lua_pushcfunction(lua(), auto_load); - lua_settable(lua(), -3); - lua_pushstring(lua(), "_G"); - lua_gettable(lua(), LUA_GLOBALSINDEX); - luaL_getmetatable(lua(), "XRAY_AutoLoadMetaTable"); - lua_setmetatable(lua(), -2); - //. ?????????? - // lua_settop (lua(),-0); +#ifdef LUA_DEBUG_PRINT + flush_log(); +#endif //-LUA_DEBUG_PRINT + + if (m_virtual_machine) + lua_close(m_virtual_machine); } -extern void export_classes(lua_State* L); -extern xr_unordered_map> unlocalizers; -extern bool unlocalizerPassed; +// Low level path -> string content loader to work around intractable Lua IReader::r_stringZ behaviour +static int load_file(lua_State* L) +{ + LPCSTR path = lua_tostring(L, 1); + if (!path) + FATAL("Invalid path"); + + IReader* file = FS.r_open(path); + + if (!file) + FATAL("Invalid file"); + + lua_pushlstring(L, (LPCSTR)file->pointer(), file->length()); + + FS.r_close(file); + + return (1); +} void CScriptEngine::init() { -#ifdef USE_LUA_STUDIO - bool lua_studio_connected = !!m_lua_studio_world; - if (lua_studio_connected) - m_lua_studio_world->remove (lua()); -#endif // #ifdef USE_LUA_STUDIO + CScriptEngine::reinit(); - CScriptStorage::reinit(); + luabind::open(lua()); + setup_callbacks(); + export_classes(lua()); -#ifdef USE_LUA_STUDIO - if (m_lua_studio_world || strstr(Core.Params, "-lua_studio")) { - if (!lua_studio_connected) - try_connect_to_debugger (); - else { -#ifdef USE_LUAJIT_ONE - jit_command (lua(), "debug=2"); - jit_command (lua(), "off"); -#else - luaJIT_setmode(lua(), 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_OFF); +#ifdef DEBUG + m_stack_is_ready = true; #endif - m_lua_studio_world->add (lua()); - } + + // lua_sethook(lua(), lua_hook_call, LUA_MASKLINE|LUA_MASKCALL|LUA_MASKRET, 0); + + // Emplace the object factory + luabind::object(lua(), const_cast(&object_factory())).pushvalue(); + lua_setglobal(lua(), "_OBJECT_FACTORY"); + + // Emplace script storage + CScriptStorage::script_register(lua()); + luabind::object(lua(), const_cast(&ScriptStorage())).pushvalue(); + lua_setglobal(lua(), "_SCRIPT_STORAGE"); + + lua_pushcfunction(lua(), load_file); + lua_setglobal(lua(), "_LOAD_FILE"); + + Msg("* engine: loading init.lua"); + + // Fetch init.lua's path from the FS + string_path path; + FS.update_path(path, "$game_scripts$", "init.lua"); + if (!path) + FATAL("* engine: invalid init.lua path"); + + // Open a file handle and read it into a string + auto file = FS.r_open(path); + if (!file) + FATAL("* engine: failed to load init.lua"); + std::string src((char*)file->pointer(), file->length()); + FS.r_close(file); + + // Run the resulting source + if (luaL_dostring(lua(), src.c_str())) + { + LPCSTR e = lua_tostring(lua(), -1); + lua_pop(lua(), 1); + FATAL((std::string("! engine: error loading init.lua:\n") + e).c_str()); } -#endif // #ifdef USE_LUA_STUDIO - luabind::open(lua()); - setup_callbacks(); - export_classes(lua()); - setup_auto_load(); + m_stack_level = lua_gettop(lua()); +} + +void CScriptEngine::reinit() +{ + if (m_virtual_machine) + lua_close(m_virtual_machine); + +#ifdef USE_GSC_MEM_ALLOC + m_virtual_machine = lua_newstate(lua_alloc, NULL); +#else + m_virtual_machine = luaL_newstate(); +#endif //-USE_GSC_MEM_ALLOC + + if (!m_virtual_machine) + { + Msg("! ERROR : Cannot initialize script virtual machine!"); + return; + } + +#ifndef USE_LUAJIT_ONE + luaL_openlibs(lua()); + if (strstr(Core.Params, "-nojit")) + luaJIT_setmode(lua(), 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_OFF); +#else // USE_LUAJIT_ONE + // initialize lua standard library functions + struct luajit + { + static void open_lib(lua_State* L, pcstr module_name, lua_CFunction function) + { + lua_pushcfunction(L, function); + lua_pushstring(L, module_name); + lua_call(L, 1, 0); + } + }; // struct lua; + + luajit::open_lib(lua(), "", luaopen_base); + luajit::open_lib(lua(), LUA_LOADLIBNAME, luaopen_package); + luajit::open_lib(lua(), LUA_TABLIBNAME, luaopen_table); + luajit::open_lib(lua(), LUA_IOLIBNAME, luaopen_io); + luajit::open_lib(lua(), LUA_OSLIBNAME, luaopen_os); + luajit::open_lib(lua(), LUA_MATHLIBNAME, luaopen_math); + luajit::open_lib(lua(), LUA_STRLIBNAME, luaopen_string); #ifdef DEBUG - m_stack_is_ready = true; + luajit::open_lib(lua(), LUA_DBLIBNAME, luaopen_debug); +#else //!DEBUG + + if (strstr(Core.Params, "-dbg")) + luajit::open_lib(lua(), LUA_DBLIBNAME, luaopen_debug); +#endif //-DEBUG + + if (!strstr(Core.Params, "-nojit")) + { + luajit::open_lib(lua(), LUA_JITLIBNAME, luaopen_jit); +#ifndef DEBUG + put_function(lua(), opt_lua_binary, sizeof(opt_lua_binary), "jit.opt"); + put_function(lua(), opt_inline_lua_binary, sizeof(opt_lua_binary), "jit.opt_inline"); + dojitopt(lua(), "2"); +#endif //!DEBUG + } + +#endif //!USE_LUAJIT_ONE + + luaopen_lua_extensions(lua()); +} + +void CScriptEngine::unload() +{ + // Restore original stack level + lua_settop(lua(), m_stack_level); +} + +void CScriptEngine::setup_callbacks() +{ +#if !XRAY_EXCEPTIONS + luabind::set_error_callback(on_lua_error); #endif -#ifndef USE_LUA_STUDIO -# ifdef DEBUG -# if defined(USE_DEBUGGER) && !defined(USE_LUA_STUDIO) - if( !debugger() || !debugger()->Active() ) -# endif // #if defined(USE_DEBUGGER) && !defined(USE_LUA_STUDIO) - lua_sethook (lua(),lua_hook_call, LUA_MASKLINE|LUA_MASKCALL|LUA_MASKRET, 0); -# endif // #ifdef DEBUG -#endif // #ifndef USE_LUA_STUDIO - // lua_sethook (lua(), lua_hook_call, LUA_MASKLINE|LUA_MASKCALL|LUA_MASKRET, 0); - - unlocalizers.clear(); - unlocalizerPassed = false; - bool save = m_reload_modules; - m_reload_modules = true; - process_file_if_exists("_G", false); - m_reload_modules = save; - - register_script_classes(); - object_factory().register_script(); - -#ifdef XRGAME_EXPORTS - load_common_scripts(); + luabind::set_pcall_callback(on_lua_pcall_failed); + +#if !XRAY_EXCEPTIONS + luabind::set_cast_failed_callback(on_lua_cast_failed); #endif - m_stack_level = lua_gettop(lua()); + lua_atpanic(lua(), on_lua_panic); } -void CScriptEngine::remove_script_process(const EScriptProcessors& process_id) +int CScriptEngine::load_string( + LPCSTR caString, + LPCSTR caScriptName, + LPCSTR caNameSpaceName +) { - CScriptProcessStorage::iterator I = m_script_processes.find(process_id); - if (I != m_script_processes.end()) - { - xr_delete((*I).second); - m_script_processes.erase(I); - } + // Use the Lua-side loadstring primitive, since luaL_loadstring would step around script compiler machinery + lua_getglobal(lua(), "loadstring"); + if (!lua_isfunction(lua(), -1)) + { + FATAL("loadstring not available"); + } + + lua_pushstring(lua(), caString); + lua_pushstring(lua(), caNameSpaceName); + lua_pushstring(lua(), caScriptName); + int l_iErrorCode = lua_pcall(lua(), 3, 1, 0); + if (l_iErrorCode) + { + //#ifdef DEBUG + if (strstr(Core.Params, "-dbg")) print_output(lua(), caScriptName, l_iErrorCode); + //#endif //-DEBUG + on_error(lua()); + } + return l_iErrorCode; } -void CScriptEngine::load_common_scripts() +int CScriptEngine::do_string( + LPCSTR caString, + LPCSTR caScriptName, + LPCSTR caNameSpaceName +) +{ + int l_iErrorCode; + + l_iErrorCode = load_string(caString, caScriptName, caNameSpaceName); + if (l_iErrorCode) + { + ai().script_engine().print_output(ai().script_engine().lua(), caScriptName, l_iErrorCode); + ai().script_engine().on_error(ai().script_engine().lua()); + return l_iErrorCode; + } + + l_iErrorCode = lua_pcall(ai().script_engine().lua(), 0, 0, 0); + if (l_iErrorCode) + { + ai().script_engine().print_output(ai().script_engine().lua(), caScriptName, l_iErrorCode); + ai().script_engine().on_error(ai().script_engine().lua()); + return l_iErrorCode; + } + + return l_iErrorCode; +} + +int CScriptEngine::vscript_log(ELuaMessageType tLuaMessageType, LPCSTR caFormat, va_list marker) +{ +#ifndef NO_XRGAME_SCRIPT_ENGINE +# ifdef DEBUG + if (!psAI_Flags.test(aiLua) && (tLuaMessageType != eLuaMessageTypeError)) + return(0); +# endif //-DEBUG +#endif //!NO_XRGAME_SCRIPT_ENGINE + + //#ifndef PRINT_CALL_STACK + //return (0); + //#else //PRINT_CALL_STACK +# ifndef NO_XRGAME_SCRIPT_ENGINE + //AVO: allow LUA debug prints (i.e.: ai().script_engine().script_log(eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_IsScopeAttached!");) +# ifndef DEBUG + + if (!strstr(Core.Params, "-dbg")) + return (0); +# endif //!DEBUG +# ifndef LUA_DEBUG_PRINT +# ifdef DEBUG + if (!psAI_Flags.test(aiLua) && (tLuaMessageType != eLuaMessageTypeError)) + return(0); +# endif //-DEBUG +# else //!LUA_DEBUG_PRINT + if (!psAI_Flags.test(aiLua) && (tLuaMessageType != eLuaMessageTypeError)) + return(0); +# endif //-LUA_DEBUG_PRINT +#endif //-NO_XRGAME_SCRIPT_ENGINE + + LPCSTR S = "", SS = ""; + LPSTR S1; + string4096 S2; + switch (tLuaMessageType) + { + case eLuaMessageTypeInfo: + { + S = "* [LUA] "; + SS = "[INFO] "; + break; + } + case eLuaMessageTypeError: + { + S = "! [LUA] "; + SS = "[ERROR] "; + break; + } + case eLuaMessageTypeMessage: + { + S = "~ [LUA] "; + SS = "[MESSAGE] "; + break; + } + case eLuaMessageTypeHookCall: + { + S = "[LUA][HOOK_CALL] "; + SS = "[CALL] "; + break; + } + case eLuaMessageTypeHookReturn: + { + S = "[LUA][HOOK_RETURN] "; + SS = "[RETURN] "; + break; + } + case eLuaMessageTypeHookLine: + { + S = "[LUA][HOOK_LINE] "; + SS = "[LINE] "; + break; + } + case eLuaMessageTypeHookCount: + { + S = "[LUA][HOOK_COUNT] "; + SS = "[COUNT] "; + break; + } + case eLuaMessageTypeHookTailReturn: + { + S = "[LUA][HOOK_TAIL_RETURN] "; + SS = "[TAIL_RETURN] "; + break; + } + default: NODEFAULT; + } + + xr_strcpy(S2, S); + S1 = S2 + xr_strlen(S); + int l_iResult = vsprintf(S1, caFormat, marker); + Msg("%s", S2); + + xr_strcpy(S2, SS); + S1 = S2 + xr_strlen(SS); + vsprintf(S1, caFormat, marker); + xr_strcat(S2, "\r\n"); + +#ifdef LUA_DEBUG_PRINT //DEBUG +# ifndef ENGINE_BUILD + ai().script_engine().m_output.w(S2, xr_strlen(S2) * sizeof(char)); +# endif //!ENGINE_BUILD +#endif //-LUA_DEBUG_PRINT DEBUG + + return (l_iResult); + //#endif //-PRINT_CALL_STACK +} + +//#ifdef PRINT_CALL_STACK +void CScriptEngine::print_stack() { -#ifdef DBG_DISABLE_SCRIPTS - return; -#endif - string_path S; - FS.update_path(S, "$game_config$", "script.ltx"); - CInifile* l_tpIniFile = xr_new(S); - R_ASSERT(l_tpIniFile); - if (!l_tpIniFile->section_exist("common")) - { - xr_delete(l_tpIniFile); - return; - } - - if (l_tpIniFile->line_exist("common", "script")) - { - LPCSTR caScriptString = l_tpIniFile->r_string("common", "script"); - u32 n = _GetItemCount(caScriptString); - string256 I; - for (u32 i = 0; i < n; ++i) - { - process_file(_GetItem(caScriptString, i, I)); - xr_strcat(I, "_initialize"); - if (object("_G", I, LUA_TFUNCTION)) - { - // lua_dostring (lua(),xr_strcat(I,"()")); - luabind::functor f; - R_ASSERT(functor(I, f)); - f(); - } - } - } - - xr_delete(l_tpIniFile); -} - -void CScriptEngine::process_file_if_exists(LPCSTR file_name, bool warn_if_not_exist) -{ - u32 string_length = xr_strlen(file_name); - if (!warn_if_not_exist && no_file_exists(file_name, string_length)) - return; - - string_path S, S1; - if (m_reload_modules || (*file_name && !namespace_loaded(file_name))) - { - FS.update_path(S, "$game_scripts$", strconcat(sizeof(S1), S1, file_name, ".script")); - if (!warn_if_not_exist && !FS.exist(S)) - { #ifdef DEBUG -# ifndef XRSE_FACTORY_EXPORTS - if (psAI_Flags.test(aiNilObjectAccess)) -# endif + if (!m_stack_is_ready) + return; + + m_stack_is_ready = false; +#endif //-DEBUG + + lua_State* L = lua(); + lua_Debug l_tDebugInfo; + for (int i = 0; lua_getstack(L, i, &l_tDebugInfo); ++i) + { + lua_getinfo(L, "nSlu", &l_tDebugInfo); + if (!l_tDebugInfo.name) + { + script_log_no_stack(eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, + l_tDebugInfo.short_src, l_tDebugInfo.currentline, ""); + //script_log(eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, ""); + } + else + { + if (!xr_strcmp(l_tDebugInfo.what, "C")) { - print_stack (); - Msg ("* trying to access variable %s, which doesn't exist, or to load script %s, which doesn't exist too",file_name,S); - m_stack_is_ready = true; + script_log_no_stack(eLuaMessageTypeError, "%2d : [C ] %s", i, l_tDebugInfo.name); + //script_log(eLuaMessageTypeError, "%2d : [C ] %s", i, l_tDebugInfo.name); } -#endif - add_no_file(file_name, string_length); - return; - } - //#ifndef MASTER_GOLD - if (strstr(Core.Params, "-dbg")) - Msg("* loading script %s", S1); - //#endif // MASTER_GOLD - m_reload_modules = false; - load_file_into_namespace(S, *file_name ? file_name : "_G"); - } + else + { + script_log_no_stack(eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, + l_tDebugInfo.short_src, l_tDebugInfo.currentline, l_tDebugInfo.name); + //script_log(eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, l_tDebugInfo.name); + } + } + } } -void CScriptEngine::process_file(LPCSTR file_name) +//#endif //-PRINT_CALL_STACK + +//AVO: added to stop duplicate stack output prints in log +int __cdecl CScriptEngine::script_log_no_stack(ELuaMessageType tLuaMessageType, LPCSTR caFormat, ...) { - process_file_if_exists(file_name, true); + va_list marker; + va_start(marker, caFormat); + int result = vscript_log(tLuaMessageType, caFormat, marker); + va_end(marker); + return result; } -void CScriptEngine::process_file(LPCSTR file_name, bool reload_modules) +//-AVO + +int __cdecl CScriptEngine::script_log(ELuaMessageType tLuaMessageType, LPCSTR caFormat, ...) { - m_reload_modules = reload_modules; - process_file_if_exists(file_name, true); - m_reload_modules = false; + va_list marker; + va_start(marker, caFormat); + int result = vscript_log(tLuaMessageType, caFormat, marker); + va_end(marker); + + static bool reenterability = false; + if (!reenterability) + { + reenterability = true; + if (tLuaMessageType == eLuaMessageTypeError) { + ai().script_engine().print_stack(); + } + else { + reenterability = false; + } + } + + // #ifdef PRINT_CALL_STACK + // # ifndef ENGINE_BUILD + // static bool reenterability = false; + // if (!reenterability) + // { + // reenterability = true; + // if (eLuaMessageTypeError == tLuaMessageType) + // ai().script_engine().print_stack(); + // reenterability = false; + // } + // # endif //!ENGINE_BUILD + // #endif //-PRINT_CALL_STACK + + return (result); } -void CScriptEngine::register_script_classes() + +bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int iErorCode) { -#ifdef DBG_DISABLE_SCRIPTS - return; -#endif - string_path S; - FS.update_path(S, "$game_config$", "script.ltx"); - CInifile* l_tpIniFile = xr_new(S); - R_ASSERT(l_tpIniFile); - - if (!l_tpIniFile->section_exist("common")) - { - xr_delete(l_tpIniFile); - return; - } - - m_class_registrators = READ_IF_EXISTS(l_tpIniFile, r_string, "common", "class_registrators", ""); - xr_delete(l_tpIniFile); - - u32 n = _GetItemCount(*m_class_registrators); - string256 I; - for (u32 i = 0; i < n; ++i) - { - _GetItem(*m_class_registrators, i, I); - luabind::functor result; - if (!functor(I, result)) - { - script_log(eLuaMessageTypeError, "Cannot load class registrator %s!", I); - continue; - } - result(const_cast(&object_factory())); - } -} - -bool CScriptEngine::function_object(LPCSTR function_to_call, luabind::object& object, int type) -{ - if (!xr_strlen(function_to_call)) - return (false); - - string256 name_space, function; - - parse_script_namespace(function_to_call, name_space, sizeof(name_space), function, sizeof(function)); - if (xr_strcmp(name_space, "_G")) - { - LPSTR file_name = strchr(name_space, '.'); - if (!file_name) - process_file(name_space); - else - { - *file_name = 0; - process_file(name_space); - *file_name = '.'; - } - } - - if (!this->object(name_space, function, type)) - return (false); - - luabind::object lua_namespace = this->name_space(name_space); - object = lua_namespace[function]; - return (true); -} - -#if defined(USE_DEBUGGER) && !defined(USE_LUA_STUDIO) -void CScriptEngine::stopDebugger () -{ - if (debugger()){ - xr_delete (m_scriptDebugger); - Msg ("Script debugger succesfully stoped."); + if (iErorCode) + print_error(L, iErorCode); + + LPCSTR S = "see call_stack for details!"; + + raii_guard guard(iErorCode, S); + + if (!lua_isstring(L, -1)) + return (false); + + S = lua_tostring(L, -1); + if (!xr_strcmp(S, "cannot resume dead coroutine")) + { + VERIFY2("Please do not return any values from main!!!", caScriptFileName); } else - Msg ("Script debugger not present."); + { + if (!iErorCode) + script_log(eLuaMessageTypeInfo, "Output from %s", caScriptFileName); + script_log(iErorCode ? eLuaMessageTypeError : eLuaMessageTypeMessage, "%s", S); + } + return (true); } -void CScriptEngine::restartDebugger () +void CScriptEngine::print_error(lua_State* L, int iErrorCode) { - if(debugger()) - stopDebugger(); + switch (iErrorCode) + { + case LUA_ERRRUN: + { + script_log(eLuaMessageTypeError, "SCRIPT RUNTIME ERROR"); + break; + } + case LUA_ERRMEM: + { + script_log(eLuaMessageTypeError, "SCRIPT ERROR (memory allocation)"); + break; + } + case LUA_ERRERR: + { + script_log(eLuaMessageTypeError, "SCRIPT ERROR (while running the error handler function)"); + break; + } + case LUA_ERRFILE: + { + script_log(eLuaMessageTypeError, "SCRIPT ERROR (while running file)"); + break; + } + case LUA_ERRSYNTAX: + { + script_log(eLuaMessageTypeError, "SCRIPT SYNTAX ERROR"); + break; + } + case LUA_YIELD: + { + script_log(eLuaMessageTypeInfo, "Thread is yielded"); + break; + } + default: NODEFAULT; + } +} - m_scriptDebugger = xr_new(); - debugger()->PrepareLuaBind(); - Msg ("Script debugger succesfully restarted."); +#ifdef LUA_DEBUG_PRINT //DEBUG +void CScriptEngine::flush_log() +{ + string_path log_file_name; + strconcat(sizeof(log_file_name), log_file_name, Core.ApplicationName, "_", Core.UserName, "_lua.log"); + FS.update_path(log_file_name, "$logs$", log_file_name); + m_output.save_to(log_file_name); } -#endif // #if defined(USE_DEBUGGER) && !defined(USE_LUA_STUDIO) +#endif //-LUA_DEBUG_PRINT DEBUG -bool CScriptEngine::no_file_exists(LPCSTR file_name, u32 string_length) +int CScriptEngine::error_log(LPCSTR format, ...) { - if (m_last_no_file_length != string_length) - return (false); + va_list marker; + va_start(marker, format); + + LPCSTR S = "! [LUA][ERROR] "; + LPSTR S1; + string4096 S2; + xr_strcpy(S2, S); + S1 = S2 + xr_strlen(S); - return (!memcmp(m_last_no_file, file_name, string_length * sizeof(char))); + int result = vsprintf(S1, format, marker); + va_end(marker); + + Msg("%s", S2); + + return (result); +} + +#ifndef XRSE_FACTORY_EXPORTS +# ifdef DEBUG +# include "ai_debug.h" +extern Flags32 psAI_Flags; +# endif //-DEBUG +#endif //!XRSE_FACTORY_EXPORTS +#include "lua.hpp" + +#ifdef USE_LUAJIT_ONE +void jit_command(lua_State*, LPCSTR); +#endif + +#ifdef DEBUG +void CScriptEngine::lua_hook_call(lua_State *L, lua_Debug *dbg) +{ + ai().script_engine().m_stack_is_ready = true; +} +#endif + +bool CScriptEngine::function_object(LPCSTR function_to_call, luabind::object& out, int type) +{ + int start = lua_gettop(lua()); + lua_getglobal(lua(), "function_object"); + lua_pushstring(lua(), function_to_call); + + int l_iErrorCode = lua_pcall(lua(), 1, 1, 0); + VERIFY(lua_gettop(lua()) == start + 1); + if (l_iErrorCode) + { + lua_pop(lua(), 1); + VERIFY(lua_gettop(lua()) == start); + return false; + } + + bool is_type = lua_type(lua(), -1) == type; + out = luabind::object(lua()); + out.set(); + + return is_type; } -void CScriptEngine::add_no_file(LPCSTR file_name, u32 string_length) +CScriptProcesses CScriptEngine::script_processes() { - m_last_no_file_length = string_length; - CopyMemory(m_last_no_file, file_name, (string_length + 1)*sizeof(char)); + return CScriptProcesses(lua()); } void CScriptEngine::collect_all_garbage() { - lua_gc(lua(), LUA_GCCOLLECT, 0); - lua_gc(lua(), LUA_GCCOLLECT, 0); + lua_gc(lua(), LUA_GCCOLLECT, 0); } -void CScriptEngine::on_error(lua_State* state) +void CScriptEngine::on_error(lua_State* L) { -#if defined(USE_DEBUGGER) && defined(USE_LUA_STUDIO) - if (!debugger()) - return; - - debugger()->on_error ( state ); -#endif // #if defined(USE_DEBUGGER) && defined(USE_LUA_STUDIO) + CScriptEngine::print_output(L, "", LUA_ERRRUN); + FATAL("LUA error"); } diff --git a/src/xrServerEntities/script_engine.h b/src/xrServerEntities/script_engine.h index beed1e9cb..1fb254c84 100644 --- a/src/xrServerEntities/script_engine.h +++ b/src/xrServerEntities/script_engine.h @@ -8,11 +8,11 @@ #pragma once -#include "script_storage.h" +#include "script_engine_space.h" #include "script_export_space.h" #include "script_space_forward.h" +#include "script_processes.h" #include "associative_vector.h" -#include "script_storage.h" //AVO: lua re-org #include "lua.hpp" @@ -23,102 +23,108 @@ //#define DBG_DISABLE_SCRIPTS -#include "script_engine_space.h" +#ifdef XRGAME_EXPORTS +# ifndef MASTER_GOLD +# define PRINT_CALL_STACK +# endif //-!MASTER_GOLD +#else //!XRGAME_EXPORTS +# ifndef NDEBUG +# define PRINT_CALL_STACK +# endif // #ifndef NDEBUG +#endif //-XRGAME_EXPORTS + +//AVO: allow LUA debug prints (i.e.: ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_IsScopeAttached!");) +#include "..\build_config_defines.h" +#ifndef DEBUG +# ifdef LUA_DEBUG_PRINT +# define PRINT_CALL_STACK +# endif +#endif //-!DEBUG +//-AVO + +using namespace ScriptEngine; -class CScriptProcess; -class CScriptThread; struct lua_State; struct lua_Debug; -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - class CScriptDebugger; -# else // #ifndef USE_LUA_STUDIO - namespace cs { - namespace lua_studio { - struct world; - } // namespace lua_studio - } // namespace cs - - class lua_studio_engine; -# endif // #ifndef USE_LUA_STUDIO -#endif - -class CScriptEngine : public CScriptStorage +class CScriptEngine { -public: - typedef CScriptStorage inherited; - typedef ScriptEngine::EScriptProcessors EScriptProcessors; - typedef associative_vector CScriptProcessStorage; - private: - bool m_reload_modules; + lua_State* m_virtual_machine; protected: - CScriptProcessStorage m_script_processes; int m_stack_level; - shared_str m_class_registrators; - -protected: -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - CScriptDebugger *m_scriptDebugger; -# else // #ifndef USE_LUA_STUDIO - cs::lua_studio::world* m_lua_studio_world; - lua_studio_engine* m_lua_studio_engine; -# endif // #ifndef USE_LUA_STUDIO -#endif // #ifdef USE_DEBUGGER -private: - string128 m_last_no_file; - u32 m_last_no_file_length; +#ifdef DEBUG +public: + bool m_stack_is_ready; +#endif //-DEBUG - bool no_file_exists(LPCSTR file_name, u32 string_length); - void add_no_file(LPCSTR file_name, u32 string_length); +#ifdef LUA_DEBUG_PRINT//PRINT_CALL_STACK +protected: + CMemoryWriter m_output; +#else +# ifdef DEBUG +protected: + CMemoryWriter m_output; +# endif //-DEBUG +#endif //-LUA_DEBUG_PRINT PRINT_CALL_STACK public: CScriptEngine(); - virtual ~CScriptEngine(); + ~CScriptEngine(); + void init(); - virtual void unload(); - static int lua_panic(lua_State* L); - static void lua_error(lua_State* L); - static int lua_pcall_failed(lua_State* L); + void setup_callbacks(); + void unload(); + + IC lua_State* lua() { return m_virtual_machine; } + CScriptProcesses script_processes(); + #ifdef DEBUG - static void lua_hook_call (lua_State *L, lua_Debug *dbg); + static void lua_hook_call(lua_State* L, lua_Debug* dbg); #endif // #ifdef DEBUG - void setup_callbacks(); - void load_common_scripts(); - bool load_file(LPCSTR caScriptName, LPCSTR namespace_name); - IC CScriptProcess* script_process(const EScriptProcessors& process_id) const; - IC void add_script_process(const EScriptProcessors& process_id, CScriptProcess* script_process); - void remove_script_process(const EScriptProcessors& process_id); - void setup_auto_load(); - void process_file_if_exists(LPCSTR file_name, bool warn_if_not_exist); - void process_file(LPCSTR file_name); - void process_file(LPCSTR file_name, bool reload_modules); + + int load_string( + LPCSTR caString, + LPCSTR caScriptName, + LPCSTR caNameSpaceName = 0 + ); + + int do_string( + LPCSTR caString, + LPCSTR caScriptName, + LPCSTR caNameSpaceName = 0 + ); + + int error_log(LPCSTR caFormat, ...); + static int __cdecl script_log(ELuaMessageType message, LPCSTR caFormat, ...); + static bool print_output(lua_State* L, LPCSTR caScriptName, int iErorCode = 0); + static void print_error(lua_State* L, int iErrorCode); + void on_error(lua_State* L); + +#ifdef LUA_DEBUG_PRINT //DEBUG + void flush_log(); +#endif //-LUA_DEBUG_PRINT DEBUG + bool function_object(LPCSTR function_to_call, luabind::object& object, int type = LUA_TFUNCTION); - void register_script_classes(); - IC void parse_script_namespace(LPCSTR function_to_call, LPSTR name_space, u32 const namespace_size, LPSTR function, - u32 const function_size); template - IC bool functor(LPCSTR function_to_call, luabind::functor<_result_type>& lua_function); - -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - void stopDebugger (); - void restartDebugger (); - CScriptDebugger *debugger (); -# else // ifndef USE_LUA_STUDIO - void try_connect_to_debugger (); - void disconnect_from_debugger (); - inline cs::lua_studio::world* debugger () const { return m_lua_studio_world; } -# endif // ifndef USE_LUA_STUDIO -#endif - virtual void on_error(lua_State* state); + bool functor(LPCSTR function_to_call, luabind::functor<_result_type>& lua_function); + + //#ifdef PRINT_CALL_STACK + void print_stack(); + //AVO: added to stop duplicate stack output prints in log + static int __cdecl script_log_no_stack(ELuaMessageType tLuaMessageType, LPCSTR caFormat, ...); + //-AVO + //#endif //-PRINT_CALL_STACK + void collect_all_garbage(); +protected: + void reinit(); + static int vscript_log(ELuaMessageType tLuaMessageType, LPCSTR caFormat, va_list marker); + DECLARE_SCRIPT_REGISTER_FUNCTION }; diff --git a/src/xrServerEntities/script_engine_inline.h b/src/xrServerEntities/script_engine_inline.h index 1770f0d6b..2af6fedbb 100644 --- a/src/xrServerEntities/script_engine_inline.h +++ b/src/xrServerEntities/script_engine_inline.h @@ -8,42 +8,6 @@ #pragma once -IC void CScriptEngine::add_script_process(const EScriptProcessors& process_id, CScriptProcess* script_process) -{ - // CScriptProcessStorage::const_iterator I = m_script_processes.find(process_id); - // VERIFY (I == m_script_processes.end()); - m_script_processes.insert(std::make_pair(process_id, script_process)); -} - -CScriptProcess* CScriptEngine::script_process(const EScriptProcessors& process_id) const -{ - CScriptProcessStorage::const_iterator I = m_script_processes.find(process_id); - if ((I != m_script_processes.end())) - return ((*I).second); - return (0); -} - -IC void CScriptEngine::parse_script_namespace(LPCSTR function_to_call, LPSTR name_space, u32 const namespace_size, - LPSTR function, u32 const function_size) -{ - LPCSTR I = function_to_call, J = 0; - for (; ; J = I, ++I) - { - I = strchr(I, '.'); - if (!I) - break; - } - xr_strcpy(name_space, namespace_size, "_G"); - if (!J) - xr_strcpy(function, function_size, function_to_call); - else - { - CopyMemory(name_space, function_to_call, u32(J - function_to_call)*sizeof(char)); - name_space[u32(J - function_to_call)] = 0; - xr_strcpy(function, function_size, J + 1); - } -} - template IC bool CScriptEngine::functor(LPCSTR function_to_call, luabind::functor<_result_type>& lua_function) { @@ -62,13 +26,3 @@ IC bool CScriptEngine::functor(LPCSTR function_to_call, luabind::functor<_result return (true); } - -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - IC CScriptDebugger *CScriptEngine::debugger () - { - return (m_scriptDebugger); - } -# else // ifndef USE_LUA_STUDIO -# endif // ifndef USE_LUA_STUDIO -#endif // #ifdef USE_DEBUGGER diff --git a/src/xrServerEntities/script_engine_script.cpp b/src/xrServerEntities/script_engine_script.cpp index 2d23b2131..6f3de0e1f 100644 --- a/src/xrServerEntities/script_engine_script.cpp +++ b/src/xrServerEntities/script_engine_script.cpp @@ -9,7 +9,6 @@ #include "pch_script.h" #include "script_engine.h" #include "ai_space.h" -#include "script_debugger.h" #include "new_sds.h" using namespace luabind; @@ -73,9 +72,9 @@ void FlushLogs() #endif // DEBUG } -void verify_if_thread_is_running() -{ - THROW2(ai().script_engine().current_thread(), "coroutine.yield() is called outside the LUA thread!"); +void verify_if_thread_is_running() { + // Dummied, as it is unused; only callsite is in _g, and commented out + // Lua threads (coroutines) are now managed by Lua, so should be verified in script } bool is_editor() @@ -83,7 +82,7 @@ bool is_editor() #ifdef XRGAME_EXPORTS return (false); #else - return (true); + return (true); #endif } @@ -121,7 +120,9 @@ LPCSTR user_name() void prefetch_module(LPCSTR file_name) { - ai().script_engine().process_file(file_name); + lua_getglobal(ai().script_engine().lua(), "require"); + lua_pushstring(ai().script_engine().lua(), file_name); + lua_call(ai().script_engine().lua(), 1, 0); } struct profile_timer_script diff --git a/src/xrServerEntities/script_engine_space.h b/src/xrServerEntities/script_engine_space.h index 78f55bd9a..4c1fe630e 100644 --- a/src/xrServerEntities/script_engine_space.h +++ b/src/xrServerEntities/script_engine_space.h @@ -10,10 +10,15 @@ namespace ScriptEngine { - enum EScriptProcessors + enum ELuaMessageType { - eScriptProcessorLevel = u32(0), - eScriptProcessorGame, - eScriptProcessorDummy = u32(-1), + eLuaMessageTypeInfo = u32(0), + eLuaMessageTypeError, + eLuaMessageTypeMessage, + eLuaMessageTypeHookCall, + eLuaMessageTypeHookReturn, + eLuaMessageTypeHookLine, + eLuaMessageTypeHookCount, + eLuaMessageTypeHookTailReturn = u32(-1), }; }; diff --git a/src/xrServerEntities/script_lua_helper.cpp b/src/xrServerEntities/script_lua_helper.cpp deleted file mode 100644 index e16d7cf1d..000000000 --- a/src/xrServerEntities/script_lua_helper.cpp +++ /dev/null @@ -1,553 +0,0 @@ -#include "pch_script.h" -#include "script_lua_helper.h" -#include "script_debugger.h" - -CDbgLuaHelper* CDbgLuaHelper::m_pThis = NULL; -lua_State* CDbgLuaHelper::L = NULL; - -CDbgLuaHelper::CDbgLuaHelper(CScriptDebugger* d) - : m_debugger(d) -{ - m_pThis = this; -} - -CDbgLuaHelper::~CDbgLuaHelper() -{ - m_pThis = NULL; -} - -void CDbgLuaHelper::UnPrepareLua(lua_State* l, int idx) -{ - lua_remove(l, idx); -} - -int CDbgLuaHelper::PrepareLua(lua_State* l) -{ - // call this function immediatly before calling lua_pcall. - //returns index in stack for errorFunc - // return 0; - lua_register(l, "DEBUGGER_ERRORMESSAGE", errormessageLua); - lua_sethook(l, hookLua, LUA_MASKLINE | LUA_MASKCALL | LUA_MASKRET, 0); - - int top = lua_gettop(l); - lua_getglobal(l, "DEBUGGER_ERRORMESSAGE"); - lua_insert(l, top); - return top; -} - - -void CDbgLuaHelper::PrepareLuaBind() -{ - luabind::set_pcall_callback(hookLuaBind); -#if !XRAY_EXCEPTIONS - luabind::set_error_callback(errormessageLuaBind); -#endif -} - - -int CDbgLuaHelper::OutputTop(lua_State* L) -{ - if (!m_pThis)return 0; - m_pThis->debugger()->Write(luaL_checkstring(L, -1)); - m_pThis->debugger()->Write("\n"); - return 0; -} - -#define LEVELS1 12 /* size of the first part of the stack */ -#define LEVELS2 10 /* size of the second part of the stack */ - -void CDbgLuaHelper::errormessageLuaBind(lua_State* l) -{ - if (!m_pThis)return; - L = l; - - char err_msg[8192]; - xr_sprintf(err_msg, "%s",lua_tostring(L, -1)); - m_pThis->debugger()->Write(err_msg); - m_pThis->debugger()->Write("\n"); - m_pThis->debugger()->ErrorBreak(); - FATAL("LUABIND error"); -} - -int CDbgLuaHelper::errormessageLua(lua_State* l) -{ - if (!m_pThis)return 0; - L = l; - int level = 1; /* skip level 0 (it's this function) */ - - int firstpart = 1; /* still before eventual `...' */ - lua_Debug ar; - if (!lua_isstring(L, 1)) - return lua_gettop(L); - lua_settop(L, 1); - lua_pushliteral(L, "\n"); - lua_pushliteral(L, "stack traceback:\n"); - while (lua_getstack(L, level++, &ar)) - { - char buff[10]; - if (level > LEVELS1 && firstpart) - { - /* no more than `LEVELS2' more levels? */ - if (!lua_getstack(L, level + LEVELS2, &ar)) - level--; /* keep going */ - else - { - lua_pushliteral(L, " ...\n"); /* too many levels */ - while (lua_getstack(L, level + LEVELS2, &ar)) /* find last levels */ - level++; - } - firstpart = 0; - continue; - } - - xr_sprintf(buff, "%4d- ", level - 1); - lua_pushstring(L, buff); - lua_getinfo(L, "Snl", &ar); - lua_pushfstring(L, "%s:", ar.short_src); - if (ar.currentline > 0) - lua_pushfstring(L, "%d:", ar.currentline); - switch (*ar.namewhat) - { - case 'g': /* global */ - case 'l': /* local */ - case 'f': /* field */ - case 'm': /* method */ - lua_pushfstring(L, " in function `%s'", ar.name); - break; - default: - { - if (*ar.what == 'm') /* main? */ - lua_pushfstring(L, " in main chunk"); - else if (*ar.what == 'C') /* C function? */ - lua_pushfstring(L, "%s", ar.short_src); - else - lua_pushfstring(L, " in function <%s:%d>", ar.short_src, ar.linedefined); - } - } - - lua_pushliteral(L, "\n"); - lua_concat(L, lua_gettop(L)); - } - - lua_concat(L, lua_gettop(L)); - - OutputTop(L); - const char* szSource = NULL; - if (ar.source[0] == '@') - szSource = ar.source + 1; - m_pThis->debugger()->ErrorBreak(szSource, ar.currentline); - FATAL("LUA error"); - - return 0; -} - -void CDbgLuaHelper::set_lua(lua_State* l) -{ - if (!m_pThis) return; - m_pThis->L = l; -} - -void CDbgLuaHelper::line_hook(lua_State* l, lua_Debug* ar) -{ - if (!m_pThis) return; - lua_getinfo(L, "lnuS", ar); - m_pThis->m_pAr = ar; - - if (ar->source[0] == '@') - { - m_pThis->debugger()->LineHook(ar->source + 1, ar->currentline); - } -} - -void CDbgLuaHelper::func_hook(lua_State* l, lua_Debug* ar) -{ - if (!m_pThis) return; - lua_getinfo(L, "lnuS", ar); - m_pThis->m_pAr = ar; - - const char* szSource = NULL; - if (ar->source[0] == '@') - { - szSource = ar->source + 1; - }; - m_pThis->debugger()->FunctionHook(szSource, ar->currentline, ar->event == LUA_HOOKCALL); -} - -void print_stack(lua_State* L) -{ - Msg(" "); - for (int i = 0; lua_type(L, -i - 1); i++) - Msg("%2d : %s", -i - 1, lua_typename(L, lua_type(L, -i - 1))); -} - -int CDbgLuaHelper::hookLuaBind(lua_State* l) -{ - if (!m_pThis) return 0; - L = l; - int top1 = lua_gettop(L); - - Msg("hookLuaBind start"); - print_stack(L); - - if (lua_isstring(L, -1)) - errormessageLuaBind(L); - // Msg("Tope string %s",lua_tostring(L,-1)); - - lua_Debug ar; - lua_getstack(L, 0, &ar); - lua_getinfo(L, "lnuS", &ar); - hookLua(L, &ar); - - Msg("hookLuaBind end"); - print_stack(L); - - if (lua_isstring(L, -1)) - Msg("Tope string %s",lua_tostring(L, -1)); - - int top2 = lua_gettop(L); - VERIFY(top2==top1); - return 0; -} - -void CDbgLuaHelper::hookLua(lua_State* l, lua_Debug* ar) -{ - if (!m_pThis) return; - L = l; - int top1 = lua_gettop(L); - - // Msg ("hookLua start"); - // print_stack(L); - - switch (ar->event) - { - case LUA_HOOKTAILRET: - case LUA_HOOKRET: - case LUA_HOOKCALL: - func_hook(L, ar); - break; - case LUA_HOOKLINE: - line_hook(L, ar); - break; - } - - // Msg ("hookLua end"); - // print_stack(L); - - int top2 = lua_gettop(L); - VERIFY(top2==top1); -} - -const char* CDbgLuaHelper::GetSource() -{ - return m_pAr->source + 1; -}; - - -void CDbgLuaHelper::DrawStackTrace() -{ - debugger()->ClearStackTrace(); - - int nLevel = 0; - lua_Debug ar; - char szDesc[256]; - while (lua_getstack(L, nLevel, &ar)) - { - lua_getinfo(L, "lnuS", &ar); - if (ar.source[0] == '@') - { - szDesc[0] = '\0'; - /* if ( ar.name ) - xr_strcat(szDesc, ar.name); - xr_strcat(szDesc, ","); - if ( ar.namewhat ) - xr_strcat(szDesc, ar.namewhat); - xr_strcat(szDesc, ","); - if ( ar.what ) - xr_strcat(szDesc, ar.what); - xr_strcat(szDesc, ","); - */ - if (ar.name) - { - xr_strcat(szDesc, ar.name); - xr_strcat(szDesc, " "); - } - - char szTmp[6]; - - xr_strcat(szDesc, itoa(ar.currentline, szTmp, 10)); - xr_strcat(szDesc, " "); - - if (ar.short_src) - xr_strcat(szDesc, ar.short_src); - - debugger()->AddStackTrace(szDesc, ar.source + 1, ar.currentline); - } - - ++nLevel; - }; -} - -void CDbgLuaHelper::DrawLocalVariables() -{ - debugger()->ClearLocalVariables(); - - int nLevel = debugger()->GetStackTraceLevel(); - lua_Debug ar; - if (lua_getstack(L, nLevel, &ar)) - { - int i = 1; - const char* name; - while ((name = lua_getlocal(L, &ar, i++)) != NULL) - { - DrawVariable(L, name, true); - - lua_pop(L, 1); /* remove variable value */ - } - } -} - -void CDbgLuaHelper::DrawGlobalVariables() -{ - debugger()->ClearGlobalVariables(); - - lua_pushvalue(L, LUA_GLOBALSINDEX); - - lua_pushnil(L); /* first key */ - string1024 var; - var[0] = 0; - while (lua_next(L, -2)) - { - //!!!! TRACE2("%s - %s\n", lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1))); - // xr_sprintf(var, "%s-%s", lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1)) ); - // CScriptDebugger::GetDebugger()->AddLocalVariable(var, "global", "_g_"); - lua_pop(L, 1); // pop value, keep key for next iteration; - } - lua_pop(L, 1); // pop table of globals; -}; - -bool CDbgLuaHelper::GetCalltip(const char* szWord, char* szCalltip, int sz_calltip) -{ - int nLevel = debugger()->GetStackTraceLevel(); - lua_Debug ar; - if (lua_getstack(L, nLevel, &ar)) - { - int i = 1; - const char* name; - while ((name = lua_getlocal(L, &ar, i++)) != NULL) - { - if (xr_strcmp(name, szWord) == 0) - { - char szRet[64]; - Describe(szRet, -1, sizeof(szRet)); - xr_sprintf(szCalltip, sz_calltip, "local %s : %s ", name, szRet); - lua_pop(L, 1); /* remove variable value */ - return true; - } - - lua_pop(L, 1); /* remove variable value */ - } - } - - lua_pushvalue(L, LUA_GLOBALSINDEX); - - lua_pushnil(L); /* first key */ - while (lua_next(L, -2)) - { - const char* name = lua_tostring(L, -2); - if (xr_strcmp(name, szWord) == 0) - { - char szRet[64]; - Describe(szRet, -1, sizeof(szRet)); - xr_sprintf(szCalltip, sz_calltip, "global %s : %s ", name, szRet); - - lua_pop(L, 3); /* remove table, key, value */ - - return true; - } - - lua_pop(L, 1); // pop value, keep key for next iteration; - } - lua_pop(L, 1); // pop table of globals; - - return false; -} - - -bool CDbgLuaHelper::Eval(const char* szCode, char* szRet, int szret_size) -{ - CoverGlobals(); - - int top = lua_gettop(L); - int status = luaL_loadbuffer(L, szCode, xr_strlen(szCode), szCode); - if (status) - xr_sprintf(szRet, szret_size, "%s", luaL_checkstring(L, -1)); - else - { - status = lua_pcall(L, 0, LUA_MULTRET, 0); /* call main */ - if (status) - { - const char* szErr = luaL_checkstring(L, -1); - const char* szErr2 = strstr(szErr, ": "); - xr_sprintf(szRet, szret_size, "%s", szErr2 ? (szErr2 + 2) : szErr); - } - else - Describe(szRet, -1, szret_size); - } - - lua_settop(L, top); - - RestoreGlobals(); - - return !status; -} - -void CDbgLuaHelper::Describe(char* szRet, int nIndex, int szRet_size) -{ - int ntype = lua_type(L, nIndex); - const char* type = lua_typename(L, ntype); - char value[64]; - - switch (ntype) - { - case LUA_TNUMBER: - xr_sprintf(value, "%f", lua_tonumber(L, nIndex)); - break; - case LUA_TSTRING: - xr_sprintf(value, "%.63s", lua_tostring(L, nIndex)); - break; - case LUA_TBOOLEAN: - xr_sprintf(value, "%s", lua_toboolean(L, nIndex) ? "true" : "false"); - break; - default: - value[0] = '\0'; - break; - } - xr_sprintf(szRet, szRet_size, "%s : %.64s", type, value); -} - -void CDbgLuaHelper::CoverGlobals() -{ - lua_newtable(L); // save there globals covered by locals - - int nLevel = debugger()->GetStackTraceLevel(); - lua_Debug ar; - if (lua_getstack(L, nLevel, &ar)) - { - int i = 1; - const char* name; - while ((name = lua_getlocal(L, &ar, i++)) != NULL) - { - /* SAVE lvalue */ - lua_pushstring(L, name); /* SAVE lvalue name */ - lua_pushvalue(L, -1); /* SAVE lvalue name name */ - lua_pushvalue(L, -1); /* SAVE lvalue name name name */ - lua_insert(L, -4); /* SAVE name lvalue name name */ - lua_rawget(L, LUA_GLOBALSINDEX); /* SAVE name lvalue name gvalue */ - - lua_rawset(L, -5); // save global value in local table - /* SAVE name lvalue */ - - lua_rawset(L, LUA_GLOBALSINDEX); /* SAVE */ - } - } -} - -void CDbgLuaHelper::RestoreGlobals() -{ - // there is table of covered globals on top - - lua_pushnil(L); /* first key */ - /* SAVE nil */ - while (lua_next(L, -2)) /* SAVE key value */ - { - lua_pushvalue(L, -2); /* SAVE key value key */ - lua_insert(L, -2); /* SAVE key key value */ - - lua_rawset(L, LUA_GLOBALSINDEX); // restore global - /* SAVE key */ - } - - lua_pop(L, 1); // pop table of covered globals; -} - -void CDbgLuaHelper::DrawVariable(lua_State* l, const char* name, bool bOpenTable) -{ - Variable var; - xr_strcpy(var.szName, name); - - const char* type; - int ntype = lua_type(l, -1); - type = lua_typename(l, ntype); - xr_strcpy(var.szType, type); - - char value[64]; - - switch (ntype) - { - case LUA_TNUMBER: - xr_sprintf(value, "%f", lua_tonumber(l, -1)); - xr_strcpy(var.szValue, value); - break; - - case LUA_TBOOLEAN: - xr_sprintf(value, "%s", lua_toboolean(L, -1) ? "true" : "false"); - xr_strcpy(var.szValue, value); - break; - - case LUA_TSTRING: - xr_sprintf(value, "%.63s", lua_tostring(l, -1)); - xr_strcpy(var.szValue, value); - break; - - - case LUA_TTABLE: - var.szValue[0] = 0; - debugger()->AddLocalVariable(var); - if (bOpenTable) - DrawTable(l, name, false); - return; - break; - - - /* case LUA_TUSERDATA:{ - luabind::detail::object_rep* obj = static_cast(lua_touserdata(L, -1)); - luabind::detail::lua_reference& r = obj->get_lua_table(); - lua_State * ls = NULL; - r.get(ls); - DrawTable(ls, name); - return; - }break;*/ - - default: - value[0] = '\0'; - break; - } - - debugger()->AddLocalVariable(var); -} - -void CDbgLuaHelper::DrawTable(lua_State* l, LPCSTR S, bool bRecursive) -{ - // char str[1024]; - - if (!lua_istable(l, -1)) - return; - - lua_pushnil(l); /* first key */ - while (lua_next(l, -2) != 0) - { - char stype[256]; - char sname[256]; - char sFullName[256]; - xr_sprintf(stype, "%s", lua_typename(l, lua_type(l, -1))); - xr_sprintf(sname, "%s",lua_tostring(l, -2)); - xr_sprintf(sFullName, "%s.%s", S, sname); - DrawVariable(l, sFullName, false); - - lua_pop(l, 1); /* removes `value'; keeps `key' for next iteration */ - } -} - -void CDbgLuaHelper::DrawVariableInfo(char* varName) -{ -} diff --git a/src/xrServerEntities/script_lua_helper.h b/src/xrServerEntities/script_lua_helper.h deleted file mode 100644 index a4835706c..000000000 --- a/src/xrServerEntities/script_lua_helper.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -struct lua_State; -struct Proto; -struct lua_Debug; -class CScriptFile; -class CScriptDebugger; - -class CDbgLuaHelper -{ -public: - void RestoreGlobals(); - void CoverGlobals(); - void Describe(char* szRet, int nIndex, int szRet_size); - bool Eval(const char* szCode, char* szRet, int szret_size); - bool GetCalltip(const char* szWord, char* szCalltip, int sz_calltip); - void DrawGlobalVariables(); - void DrawLocalVariables(); - const char* GetSource(); - - CDbgLuaHelper(CScriptDebugger* d); - virtual ~CDbgLuaHelper(); - - // debugger functions - int PrepareLua(lua_State*); - void UnPrepareLua(lua_State*, int); - void PrepareLuaBind(); - - - void DrawStackTrace(); - static int OutputTop(lua_State*); - - static void hookLua(lua_State*, lua_Debug*); - static int hookLuaBind(lua_State*); - - static int errormessageLua(lua_State*); - static void errormessageLuaBind(lua_State*); - static void line_hook(lua_State*, lua_Debug*); - static void func_hook(lua_State*, lua_Debug*); - static void set_lua(lua_State*); - void DrawVariable(lua_State* l, const char* name, bool bOpenTable); - void DrawTable(lua_State* l, const char* name, bool bRecursive = true); - void DrawVariableInfo(char*); - CScriptDebugger* debugger() { return m_debugger; } -protected: - CScriptDebugger* m_debugger; - static CDbgLuaHelper* m_pThis; - - - static lua_State* L; - lua_Debug* m_pAr; -}; diff --git a/src/xrServerEntities/script_process.cpp b/src/xrServerEntities/script_process.cpp deleted file mode 100644 index 7daf32c5c..000000000 --- a/src/xrServerEntities/script_process.cpp +++ /dev/null @@ -1,103 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_process.cpp -// Created : 19.09.2003 -// Modified : 29.06.2004 -// Author : Dmitriy Iassenev -// Description : Script process class -//////////////////////////////////////////////////////////////////////////// - -#include "pch_script.h" -#include "script_engine.h" -#include "script_process.h" -#include "script_thread.h" -#include "ai_space.h" -#include "object_broker.h" - -string4096 g_ca_stdout; - -CScriptProcess::CScriptProcess(shared_str name, shared_str scripts) : - m_name(name) -{ -#ifdef DEBUG - Msg ("* Initializing %s script process",*m_name); -#endif - - string256 I; - for (u32 i = 0, n = _GetItemCount(*scripts); i < n; ++i) - add_script(_GetItem(*scripts, i, I), false, false); - - m_iterator = 0; -} - -CScriptProcess::~CScriptProcess() -{ - delete_data(m_scripts); -} - -void CScriptProcess::run_scripts() -{ - LPSTR S; - for (; !m_scripts_to_run.empty();) - { - LPSTR I = m_scripts_to_run.back().m_script_name; - bool do_string = m_scripts_to_run.back().m_do_string; - bool reload = m_scripts_to_run.back().m_reload; - S = xr_strdup(I); - m_scripts_to_run.pop_back(); - - CScriptThread* script = xr_new(S, do_string, reload); - xr_free(S); - - if (script->active()) - m_scripts.push_back(script); - else - xr_delete(script); - } -} - -// Oles: -// changed to process one script per-frame -// changed log-output to stack-based buffer (avoid persistent 4K storage) -void CScriptProcess::update() -{ -#ifdef DBG_DISABLE_SCRIPTS - m_scripts_to_run.clear(); - return; -#endif - - run_scripts(); - - if (m_scripts.empty()) - return; - - // update script - g_ca_stdout[0] = 0; - u32 _id = (++m_iterator) % m_scripts.size(); - if (!m_scripts[_id]->update()) - { - xr_delete(m_scripts[_id]); - m_scripts.erase(m_scripts.begin() + _id); - --m_iterator; // try to avoid skipping - } - - if (g_ca_stdout[0]) - { - fputc(0,stderr); - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeInfo, "%s", g_ca_stdout); - fflush(stderr); - } - -#if defined(DEBUG) - try { -#pragma todo ("Dima cant find this function 'lua_setgcthreshold' ") - lua_gc (ai().script_engine().lua(), LUA_GCSTEP, 0); - } - catch(...) { - } -#endif -} - -void CScriptProcess::add_script(LPCSTR script_name, bool do_string, bool reload) -{ - m_scripts_to_run.push_back(CScriptToRun(script_name, do_string, reload)); -} diff --git a/src/xrServerEntities/script_process.h b/src/xrServerEntities/script_process.h index 3948a3e8e..8c137a518 100644 --- a/src/xrServerEntities/script_process.h +++ b/src/xrServerEntities/script_process.h @@ -1,68 +1,37 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_process.h -// Created : 19.09.2003 -// Modified : 29.06.2004 -// Author : Dmitriy Iassenev -// Description : Script process class -//////////////////////////////////////////////////////////////////////////// - -#pragma once - -class CScriptThread; +#include +// Luabind wrapper for xr/processes/process class CScriptProcess { -public: - typedef xr_vector SCRIPT_REGISTRY; - private: - struct CScriptToRun - { - LPSTR m_script_name; - bool m_do_string; - bool m_reload; - - IC CScriptToRun(LPCSTR script_name, bool do_string, bool reload = false) - { - m_script_name = xr_strdup(script_name); - m_do_string = do_string; - m_reload = reload; - } - - IC CScriptToRun(const CScriptToRun& script) - { - m_script_name = xr_strdup(script.m_script_name); - m_do_string = script.m_do_string; - m_reload = script.m_reload; - } - - virtual ~CScriptToRun() - { - xr_free(m_script_name); - } - }; + luabind::object m_obj; public: - typedef xr_vector SCRIPTS_TO_RUN; - -protected: - SCRIPT_REGISTRY m_scripts; - SCRIPTS_TO_RUN m_scripts_to_run; - shared_str m_name; - -protected: - u32 m_iterator; // Oles: iterative update - -protected: - void run_scripts(); - -public: - CScriptProcess(shared_str anme, shared_str scripts); - virtual ~CScriptProcess(); - void update(); - void add_script(LPCSTR script_name, bool string, bool reload); - IC const SCRIPT_REGISTRY& scripts() const; - IC shared_str name() const; + CScriptProcess(luabind::object obj) + { + m_obj = obj; + } + + ~CScriptProcess() {} + + template + luabind::functor functor(LPCSTR field) + { + return luabind::object_cast>(m_obj[field]); + } + + void update() + { + functor("update")(m_obj); + } + + void add_script(LPCSTR name, bool reload) + { + functor("add_script")(m_obj, name, reload); + } + + void add_string(LPCSTR src) + { + functor("add_string")(m_obj, src); + } }; - -#include "script_process_inline.h" diff --git a/src/xrServerEntities/script_process_inline.h b/src/xrServerEntities/script_process_inline.h deleted file mode 100644 index b20c03310..000000000 --- a/src/xrServerEntities/script_process_inline.h +++ /dev/null @@ -1,19 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_process_inline.h -// Created : 19.09.2003 -// Modified : 29.06.2004 -// Author : Dmitriy Iassenev -// Description : Script process class inline functions -//////////////////////////////////////////////////////////////////////////// - -#pragma once - -IC const CScriptProcess::SCRIPT_REGISTRY& CScriptProcess::scripts() const -{ - return (m_scripts); -} - -IC shared_str CScriptProcess::name() const -{ - return (m_name); -} diff --git a/src/xrServerEntities/script_processes.h b/src/xrServerEntities/script_processes.h new file mode 100644 index 000000000..7f9b33900 --- /dev/null +++ b/src/xrServerEntities/script_processes.h @@ -0,0 +1,48 @@ +#include +#include "script_process.h" + +// Luabind wrapper for xr/processes +class CScriptProcesses +{ +private: + luabind::object m_obj; + +public: + CScriptProcesses(lua_State* L) + { + lua_getglobal(L, "require"); + lua_pushstring(L, "xr.processes"); + lua_call(L, 1, 1); + + m_obj = luabind::object(L); + m_obj.set(); + } + + ~CScriptProcesses() {} + + template + luabind::functor functor(LPCSTR field) + { + return luabind::object_cast>(m_obj[field]); + } + + void add(LPCSTR name, LPCSTR scripts) + { + functor("add")(m_obj, name, scripts); + } + + void remove(LPCSTR name) + { + functor("remove")(m_obj, name); + } + + bool has(LPCSTR name) + { + return functor("has")(m_obj, name); + } + + CScriptProcess get(LPCSTR name) + { + return CScriptProcess(functor("get")(m_obj, name)); + } +}; \ No newline at end of file diff --git a/src/xrServerEntities/script_stack_tracker.cpp b/src/xrServerEntities/script_stack_tracker.cpp deleted file mode 100644 index b7b1eaf7c..000000000 --- a/src/xrServerEntities/script_stack_tracker.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_stack_tracker.cpp -// Created : 21.04.2004 -// Modified : 21.04.2004 -// Author : Dmitriy Iassenev -// Description : Script stack tracker -//////////////////////////////////////////////////////////////////////////// - -#include "pch_script.h" -#include "script_stack_tracker.h" -#include "script_storage_space.h" -#include "ai_space.h" -#include "script_engine.h" - -CScriptStackTracker::CScriptStackTracker() -{ - m_current_stack_level = 0; - for (int i = 0; i < max_stack_size; ++i) - m_stack[i] = xr_new(); -} - -CScriptStackTracker::~CScriptStackTracker() -{ - for (int i = 0; i < max_stack_size; ++i) - xr_delete(m_stack[i]); -} - -void CScriptStackTracker::script_hook(lua_State* L, lua_Debug* dbg) -{ - VERIFY(L); // && (m_virtual_machine == L)); - - switch (dbg->event) - { - case LUA_HOOKCALL: - { - if (m_current_stack_level >= max_stack_size) - return; - if (!lua_getstack(L, 0, m_stack[m_current_stack_level])) - break; - lua_getinfo(L, "nSlu", m_stack[m_current_stack_level]); - if (m_current_stack_level && lua_getstack(L, 1, m_stack[m_current_stack_level - 1])) - lua_getinfo(L, "nSlu", m_stack[m_current_stack_level - 1]); - ++m_current_stack_level; - break; - } - case LUA_HOOKRET: - { - if (m_current_stack_level > 0) - --m_current_stack_level; - break; - } - case LUA_HOOKTAILRET: - { - if (m_current_stack_level > 0) - --m_current_stack_level; - break; - } - case LUA_HOOKLINE: - { - lua_getinfo(L, "l", dbg); - m_stack[m_current_stack_level]->currentline = dbg->currentline; - break; - } - case LUA_HOOKCOUNT: - { - lua_getinfo(L, "l", dbg); - m_stack[m_current_stack_level]->currentline = dbg->currentline; - break; - } - default: NODEFAULT; - } -} - -void CScriptStackTracker::print_stack(lua_State* L) -{ - VERIFY(L); // && (m_virtual_machine == L)); - - for (int j = m_current_stack_level - 1, k = 0; j >= 0; --j, ++k) - { - lua_Debug l_tDebugInfo = *m_stack[j]; - if (!l_tDebugInfo.name) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", k, - l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, ""); - else if (!xr_strcmp(l_tDebugInfo.what, "C")) - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "%2d : [C ] %s", k, - l_tDebugInfo.name); - else - ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", k, - l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, - l_tDebugInfo.name); - } - m_current_stack_level = 0; -} diff --git a/src/xrServerEntities/script_stack_tracker.h b/src/xrServerEntities/script_stack_tracker.h deleted file mode 100644 index 53d9e64cb..000000000 --- a/src/xrServerEntities/script_stack_tracker.h +++ /dev/null @@ -1,33 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_stack_tracker.h -// Created : 21.04.2004 -// Modified : 21.04.2004 -// Author : Dmitriy Iassenev -// Description : Script stack tracker -//////////////////////////////////////////////////////////////////////////// - -#pragma once - -struct lua_Debug; -struct lua_State; - -class CScriptStackTracker -{ -protected: - enum consts - { - max_stack_size = u32(256), - }; - -protected: - lua_Debug* m_stack[max_stack_size]; - int m_current_stack_level; - -public: - CScriptStackTracker(); - virtual ~CScriptStackTracker(); - void script_hook(lua_State* L, lua_Debug* dbg); - void print_stack(lua_State* L); -}; - -#include "script_stack_tracker_inline.h" diff --git a/src/xrServerEntities/script_stack_tracker_inline.h b/src/xrServerEntities/script_stack_tracker_inline.h deleted file mode 100644 index a9647ebea..000000000 --- a/src/xrServerEntities/script_stack_tracker_inline.h +++ /dev/null @@ -1,9 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_stack_tracker_inline.h -// Created : 21.04.2004 -// Modified : 21.04.2004 -// Author : Dmitriy Iassenev -// Description : Script stack tracker inline functions -//////////////////////////////////////////////////////////////////////////// - -#pragma once diff --git a/src/xrServerEntities/script_storage.cpp b/src/xrServerEntities/script_storage.cpp index 6f16bf430..89addee1f 100644 --- a/src/xrServerEntities/script_storage.cpp +++ b/src/xrServerEntities/script_storage.cpp @@ -1,1230 +1,24 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_storage.cpp -// Created : 01.04.2004 -// Modified : [1/14/2015 Andrey] -// Author : Dmitriy Iassenev -// Description : XRay Script Storage -//////////////////////////////////////////////////////////////////////////// - -#include "pch_script.h" +#include "stdafx.h" #include "script_storage.h" -#include "script_thread.h" -#include "../xrCore/mezz_stringbuffer.h" -#include -#include -#include -#include -#include - -#if !defined(DEBUG) && defined(USE_LUAJIT_ONE) -# include "opt.lua.h" -# include "opt_inline.lua.h" -#endif //!DEBUG && USE_LUAJIT_ONE -#ifndef USE_LUAJIT_ONE -#include "lua.hpp" -#endif - -LPCSTR file_header_old = - "\ - local function script_name() \ - return \"%s\" \ - end \ - local this = {} \ - %s this %s \ - setmetatable(this, {__index = _G}) \ - setfenv(1, this) \ - "; - -LPCSTR file_header_new = - "\ - local function script_name() \ - return \"%s\" \ - end \ - local this = {} \ - this._G = _G \ - %s this %s \ - setfenv(1, this) \ - "; - -LPCSTR file_header = 0; - -#ifndef ENGINE_BUILD -# include "script_engine.h" -# include "ai_space.h" -#else //ENGINE_BUILD -# define NO_XRGAME_SCRIPT_ENGINE -#endif //!ENGINE_BUILD - -#ifndef XRGAME_EXPORTS -# define NO_XRGAME_SCRIPT_ENGINE -#endif //!XRGAME_EXPORTS -#ifndef NO_XRGAME_SCRIPT_ENGINE -# include "ai_debug.h" -#endif //!NO_XRGAME_SCRIPT_ENGINE - -#ifdef USE_DEBUGGER -# include "script_debugger.h" -#endif - -#ifndef PURE_ALLOC -//# ifndef USE_MEMORY_MONITOR -//# define USE_DL_ALLOCATOR -//# endif //!USE_MEMORY_MONITOR -#endif //!PURE_ALLOC - -#ifndef USE_DL_ALLOCATOR -static void* lua_alloc(void* ud, void* ptr, size_t osize, size_t nsize) +LPCSTR CScriptStorage::get(LPCSTR name_space, LPCSTR key) { - (void)ud; - (void)osize; - if (nsize == 0) - { - xr_free(ptr); + auto cache = &m_cache[name_space]; + if (cache->find(key) == cache->end()) return NULL; - } - else -#ifdef DEBUG_MEMORY_NAME - return Memory.mem_realloc (ptr, nsize, "LUA"); -#else // DEBUG_MEMORY_MANAGER - return Memory.mem_realloc(ptr, nsize); -#endif // DEBUG_MEMORY_MANAGER -} - -u32 game_lua_memory_usage() -{ - return (0); -} -#else //USE_DL_ALLOCATOR - -# ifdef USE_ARENA_ALLOCATOR - static const u32 s_arena_size = 96*1024*1024; - static char s_fake_array[s_arena_size]; -// static doug_lea_allocator s_allocator( s_fake_array, s_arena_size, "lua" ); -# else //-USE_ARENA_ALLOCATOR -// static doug_lea_allocator s_allocator(0, 0, "lua"); -# endif //-USE_ARENA_ALLOCATOR - -static void *lua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) -{ -#ifndef USE_MEMORY_MONITOR - (void)ud; - (void) osize; - if (!nsize) - { - s_allocator.free_impl(ptr); - return 0; - } - if (!ptr) - return s_allocator.malloc_impl((u32) nsize); - - return s_allocator.realloc_impl(ptr, (u32) nsize); -#else //USE_MEMORY_MONITOR - if ( !nsize ) { - memory_monitor::monitor_free(ptr); - s_allocator.free_impl (ptr); - return NULL; - } - - if ( !ptr ) { - void* const result = s_allocator.malloc_impl((u32)nsize); - memory_monitor::monitor_alloc (result,nsize,"LUA"); - return result; - } - - memory_monitor::monitor_free (ptr); - void* const result = s_allocator.realloc_impl(ptr, (u32)nsize); - memory_monitor::monitor_alloc (result,nsize,"LUA"); - return result; -#endif //!USE_MEMORY_MONITOR -} - -u32 game_lua_memory_usage() -{ - return (s_allocator.get_allocated_size()); -} -#endif //!USE_DL_ALLOCATOR - -static LPVOID __cdecl luabind_allocator( - luabind::memory_allocation_function_parameter const, - void const* const pointer, - size_t const size -) -{ - if (!size) - { - LPVOID non_const_pointer = const_cast(pointer); - xr_free(non_const_pointer); - return (0); - } - - if (!pointer) - { -#ifdef DEBUG - return ( Memory.mem_alloc(size, "luabind") ); -#else //!DEBUG - return (Memory.mem_alloc(size)); -#endif //-DEBUG - } - - LPVOID non_const_pointer = const_cast(pointer); -#ifdef DEBUG - return ( Memory.mem_realloc(non_const_pointer, size, "luabind") ); -#else //!DEBUG - return (Memory.mem_realloc(non_const_pointer, size)); -#endif //-DEBUG -} - -void setup_luabind_allocator() -{ - luabind::allocator = &luabind_allocator; - luabind::allocator_parameter = 0; -} - - -#ifdef USE_LUAJIT_ONE // [1/14/2015 Andrey] - -/* ---- start of LuaJIT extensions */ -static void l_message(lua_State* state, const char *msg) -{ - Msg("! [LUA_JIT] %s", msg); -} - - -static int report(lua_State *L, int status) -{ - if (status && !lua_isnil(L, -1)) - { - const char *msg = lua_tostring(L, -1); - if (msg == NULL) msg = "(error object is not a string)"; - l_message(L, msg); - lua_pop(L, 1); - } - return status; -} - -static int loadjitmodule(lua_State *L, const char *notfound) -{ - lua_getglobal(L, "require"); - lua_pushliteral(L, "jit."); - lua_pushvalue(L, -3); - lua_concat(L, 2); - if (lua_pcall(L, 1, 1, 0)) - { - const char *msg = lua_tostring(L, -1); - if (msg && !strncmp(msg, "module ", 7)) - { - l_message(L, notfound); - return 1; - } - else - return report(L, 1); - } - lua_getfield(L, -1, "start"); - lua_remove(L, -2); /* drop module table */ - return 0; -} - -/* JIT engine control command: try jit library first or load add-on module */ -static int dojitcmd(lua_State *L, const char *cmd) -{ - const char *val = strchr(cmd, '='); - lua_pushlstring(L, cmd, val ? val - cmd : xr_strlen(cmd)); - lua_getglobal(L, "jit"); /* get jit.* table */ - lua_pushvalue(L, -2); - lua_gettable(L, -2); /* lookup library function */ - if (!lua_isfunction(L, -1)) - { - lua_pop(L, 2); /* drop non-function and jit.* table, keep module name */ - if (loadjitmodule(L, "unknown luaJIT command")) - return 1; - } - else - { - lua_remove(L, -2); /* drop jit.* table */ - } - lua_remove(L, -2); /* drop module name */ - if (val) lua_pushstring(L, val + 1); - return report(L, lua_pcall(L, val ? 1 : 0, 0, 0)); -} - -void jit_command(lua_State* state, LPCSTR command) -{ - dojitcmd(state, command); -} - -#ifndef DEBUG -/* start optimizer */ -static int dojitopt(lua_State *L, const char *opt) -{ - lua_pushliteral(L, "opt"); - if (loadjitmodule(L, "LuaJIT optimizer module not installed")) - return 1; - lua_remove(L, -2); /* drop module name */ - if (*opt) lua_pushstring(L, opt); - return report(L, lua_pcall(L, *opt ? 1 : 0, 0, 0)); -} - -static void put_function(lua_State* state, u8 const* buffer, u32 const buffer_size, LPCSTR package_id) -{ - lua_getglobal(state, "package"); - lua_pushstring(state, "preload"); - lua_gettable(state, -2); - - lua_pushstring(state, package_id); - luaL_loadbuffer(state, (char*) buffer, buffer_size, package_id); - lua_settable(state, -3); -} - -/* ---- end of LuaJIT extensions */ -#endif //!DEBUG -#endif //-USE_LUAJIT_ONE - - -CScriptStorage::CScriptStorage() -{ - m_current_thread = 0; - -#ifdef DEBUG - m_stack_is_ready = false; -#endif //-DEBUG - - m_virtual_machine = 0; - -#ifdef USE_LUA_STUDIO -# ifndef USE_DEBUGGER - STATIC_CHECK( false, Do_Not_Define_USE_LUA_STUDIO_macro_without_USE_DEBUGGER_macro ); -# endif //!USE_DEBUGGER -#endif //-USE_LUA_STUDIO -} - -CScriptStorage::~CScriptStorage() -{ - if (m_virtual_machine) - lua_close(m_virtual_machine); -} - -extern int luaopen_lua_extensions(lua_State* L); - -void disable_os_funcs(lua_State* L) -{ - lua_getglobal(L, "os"); - lua_pushnil(L); - lua_setfield(L, -2, "execute"); - lua_pushnil(L); - lua_setfield(L, -2, "rename"); - lua_pushnil(L); - lua_setfield(L, -2, "remove"); - lua_pushnil(L); - lua_setfield(L, -2, "exit"); - lua_pop(L, 1); - - lua_getglobal(L, "io"); - lua_pushnil(L); - lua_setfield(L, -2, "popen"); - lua_pop(L, 1); -} - -void CScriptStorage::reinit() -{ - if (m_virtual_machine) - lua_close(m_virtual_machine); - -#ifdef USE_GSC_MEM_ALLOC - m_virtual_machine = lua_newstate(lua_alloc, NULL); -#else - m_virtual_machine = luaL_newstate(); -#endif //-USE_GSC_MEM_ALLOC - - if (!m_virtual_machine) - { - Msg("! ERROR : Cannot initialize script virtual machine!"); - return; - } - - -#ifndef USE_LUAJIT_ONE - luaL_openlibs(lua()); - if (strstr(Core.Params, "-nojit")) - luaJIT_setmode(lua(), 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_OFF); -#else // USE_LUAJIT_ONE - // initialize lua standard library functions - struct luajit - { - static void open_lib(lua_State *L, pcstr module_name, lua_CFunction function) - { - lua_pushcfunction(L, function); - lua_pushstring(L, module_name); - lua_call(L, 1, 0); - } - }; // struct lua; - - luajit::open_lib(lua(), "", luaopen_base); - luajit::open_lib(lua(), LUA_LOADLIBNAME, luaopen_package); - luajit::open_lib(lua(), LUA_TABLIBNAME, luaopen_table); - luajit::open_lib(lua(), LUA_IOLIBNAME, luaopen_io); - luajit::open_lib(lua(), LUA_OSLIBNAME, luaopen_os); - luajit::open_lib(lua(), LUA_MATHLIBNAME, luaopen_math); - luajit::open_lib(lua(), LUA_STRLIBNAME, luaopen_string); - -#ifdef DEBUG - luajit::open_lib(lua(), LUA_DBLIBNAME, luaopen_debug); -#else //!DEBUG - - if (strstr(Core.Params, "-dbg")) - luajit::open_lib(lua(), LUA_DBLIBNAME, luaopen_debug); -#endif //-DEBUG - - if (!strstr(Core.Params, "-nojit")) - { - luajit::open_lib(lua(), LUA_JITLIBNAME, luaopen_jit); -#ifndef DEBUG - put_function(lua(), opt_lua_binary, sizeof(opt_lua_binary), "jit.opt"); - put_function(lua(), opt_inline_lua_binary, sizeof(opt_lua_binary), "jit.opt_inline"); - dojitopt(lua(), "2"); -#endif //!DEBUG - } - -#endif //!USE_LUAJIT_ONE - - luaopen_lua_extensions(lua()); - disable_os_funcs(lua()); - - if (strstr(Core.Params, "-_g")) - file_header = file_header_new; //AVO: I get fatal crash at the start if this is used - else - file_header = file_header_old; -} - -int CScriptStorage::vscript_log(ScriptStorage::ELuaMessageType tLuaMessageType, LPCSTR caFormat, va_list marker) -{ -#ifndef NO_XRGAME_SCRIPT_ENGINE -# ifdef DEBUG - if (!psAI_Flags.test(aiLua) && (tLuaMessageType != ScriptStorage::eLuaMessageTypeError)) - return(0); -# endif //-DEBUG -#endif //!NO_XRGAME_SCRIPT_ENGINE - - //#ifndef PRINT_CALL_STACK - //return (0); - //#else //PRINT_CALL_STACK -# ifndef NO_XRGAME_SCRIPT_ENGINE - //AVO: allow LUA debug prints (i.e.: ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_IsScopeAttached!");) -# ifndef DEBUG - - if (!strstr(Core.Params, "-dbg")) - return (0); -# endif //!DEBUG -# ifndef LUA_DEBUG_PRINT -# ifdef DEBUG - if (!psAI_Flags.test(aiLua) && (tLuaMessageType != ScriptStorage::eLuaMessageTypeError)) - return(0); -# endif //-DEBUG -# else //!LUA_DEBUG_PRINT - if (!psAI_Flags.test(aiLua) && (tLuaMessageType != ScriptStorage::eLuaMessageTypeError)) - return(0); -# endif //-LUA_DEBUG_PRINT -#endif //-NO_XRGAME_SCRIPT_ENGINE - - LPCSTR S = "", SS = ""; - LPSTR S1; - string4096 S2; - switch (tLuaMessageType) - { - case ScriptStorage::eLuaMessageTypeInfo: - { - S = "* [LUA] "; - SS = "[INFO] "; - break; - } - case ScriptStorage::eLuaMessageTypeError: - { - S = "! [LUA] "; - SS = "[ERROR] "; - break; - } - case ScriptStorage::eLuaMessageTypeMessage: - { - S = "~ [LUA] "; - SS = "[MESSAGE] "; - break; - } - case ScriptStorage::eLuaMessageTypeHookCall: - { - S = "[LUA][HOOK_CALL] "; - SS = "[CALL] "; - break; - } - case ScriptStorage::eLuaMessageTypeHookReturn: - { - S = "[LUA][HOOK_RETURN] "; - SS = "[RETURN] "; - break; - } - case ScriptStorage::eLuaMessageTypeHookLine: - { - S = "[LUA][HOOK_LINE] "; - SS = "[LINE] "; - break; - } - case ScriptStorage::eLuaMessageTypeHookCount: - { - S = "[LUA][HOOK_COUNT] "; - SS = "[COUNT] "; - break; - } - case ScriptStorage::eLuaMessageTypeHookTailReturn: - { - S = "[LUA][HOOK_TAIL_RETURN] "; - SS = "[TAIL_RETURN] "; - break; - } - default: NODEFAULT; - } - - xr_strcpy(S2, S); - S1 = S2 + xr_strlen(S); - int l_iResult = vsprintf(S1, caFormat, marker); - Msg("%s", S2); - - xr_strcpy(S2, SS); - S1 = S2 + xr_strlen(SS); - vsprintf(S1, caFormat, marker); - xr_strcat(S2, "\r\n"); - -#ifdef LUA_DEBUG_PRINT //DEBUG -# ifndef ENGINE_BUILD - ai().script_engine().m_output.w(S2,xr_strlen(S2)*sizeof(char)); -# endif //!ENGINE_BUILD -#endif //-LUA_DEBUG_PRINT DEBUG - - return (l_iResult); - //#endif //-PRINT_CALL_STACK -} - -//#ifdef PRINT_CALL_STACK -void CScriptStorage::print_stack() -{ -#ifdef DEBUG - if (!m_stack_is_ready) - return; - - m_stack_is_ready = false; -#endif //-DEBUG - lua_State* L = lua(); - lua_Debug l_tDebugInfo; - for (int i = 0; lua_getstack(L, i, &l_tDebugInfo); ++i) - { - lua_getinfo(L, "nSlu", &l_tDebugInfo); - if (!l_tDebugInfo.name) - { - script_log_no_stack(ScriptStorage::eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, - l_tDebugInfo.short_src, l_tDebugInfo.currentline, ""); - //script_log(ScriptStorage::eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, ""); - } - else - { - if (!xr_strcmp(l_tDebugInfo.what, "C")) - { - script_log_no_stack(ScriptStorage::eLuaMessageTypeError, "%2d : [C ] %s", i, l_tDebugInfo.name); - //script_log(ScriptStorage::eLuaMessageTypeError, "%2d : [C ] %s", i, l_tDebugInfo.name); - } - else - { - script_log_no_stack(ScriptStorage::eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, - l_tDebugInfo.short_src, l_tDebugInfo.currentline, l_tDebugInfo.name); - //script_log(ScriptStorage::eLuaMessageTypeError, "%2d : [%s] %s(%d) : %s", i, l_tDebugInfo.what, l_tDebugInfo.short_src, l_tDebugInfo.currentline, l_tDebugInfo.name); - } - } - } + return cache->at(std::string(key)).c_str(); } -//#endif //-PRINT_CALL_STACK - -//AVO: added to stop duplicate stack output prints in log -int __cdecl CScriptStorage::script_log_no_stack(ScriptStorage::ELuaMessageType tLuaMessageType, LPCSTR caFormat, ...) -{ - va_list marker; - va_start(marker, caFormat); - int result = vscript_log(tLuaMessageType, caFormat, marker); - va_end(marker); - return result; -} - -//-AVO - -int __cdecl CScriptStorage::script_log(ScriptStorage::ELuaMessageType tLuaMessageType, LPCSTR caFormat, ...) -{ - va_list marker; - va_start(marker, caFormat); - int result = vscript_log(tLuaMessageType, caFormat, marker); - va_end(marker); - - static bool reenterability = false; - if (!reenterability) - { - reenterability = true; - if (tLuaMessageType == ScriptStorage::eLuaMessageTypeError) { - ai().script_engine().print_stack(); - } else { - reenterability = false; - } - } - - // #ifdef PRINT_CALL_STACK - // # ifndef ENGINE_BUILD - // static bool reenterability = false; - // if (!reenterability) - // { - // reenterability = true; - // if (eLuaMessageTypeError == tLuaMessageType) - // ai().script_engine().print_stack(); - // reenterability = false; - // } - // # endif //!ENGINE_BUILD - // #endif //-PRINT_CALL_STACK - - return (result); -} - -bool CScriptStorage::parse_namespace(LPCSTR caNamespaceName, LPSTR b, u32 const b_size, LPSTR c, u32 const c_size) -{ - *b = 0; - *c = 0; - LPSTR S2; - STRCONCAT(S2, caNamespaceName); - LPSTR S = S2; - for (int i = 0;; ++i) - { - if (!xr_strlen(S)) - { - script_log(ScriptStorage::eLuaMessageTypeError, "the namespace name %s is incorrect!", caNamespaceName); - return (false); - } - LPSTR S1 = strchr(S, '.'); - if (S1) - *S1 = 0; - - if (i) - xr_strcat(b, b_size, "{"); - xr_strcat(b, b_size, S); - xr_strcat(b, b_size, "="); - if (i) - xr_strcat(c, c_size, "}"); - if (S1) - S = ++S1; - else - break; - } - - return (true); -} - -bool CScriptStorage::load_buffer(lua_State* L, LPCSTR caBuffer, size_t tSize, LPCSTR caScriptName, - LPCSTR caNameSpaceName) -{ - int l_iErrorCode; - if (caNameSpaceName && xr_strcmp("_G", caNameSpaceName)) - { - string512 insert, a, b; - - LPCSTR header = file_header; - - if (!parse_namespace(caNameSpaceName, a, sizeof(a), b, sizeof(b))) - return (false); - - xr_sprintf(insert, header, caNameSpaceName, a, b); - u32 str_len = xr_strlen(insert); - u32 const total_size = str_len + tSize; - LPSTR script = 0; - bool dynamic_allocation = false; - - __try - { - if (total_size < 768 * 1024) - script = (LPSTR)_alloca(total_size); - else - { -#ifdef DEBUG - script = (LPSTR)Memory.mem_alloc(total_size, "lua script file"); -#else //!DEBUG - script = (LPSTR)Memory.mem_alloc(total_size); -#endif //-DEBUG - dynamic_allocation = true; - } - } - __except (GetExceptionCode() == STATUS_STACK_OVERFLOW) - { - int errcode = _resetstkoflw(); - R_ASSERT2(errcode, "Could not reset the stack after \"Stack overflow\" exception!"); -#ifdef DEBUG - script = (LPSTR)Memory.mem_alloc(total_size, "lua script file (after exception)"); -#else //#ifdef DEBUG - script = (LPSTR)Memory.mem_alloc(total_size); -#endif //#ifdef DEBUG - dynamic_allocation = true; - }; - - xr_strcpy(script, total_size, insert); - CopyMemory(script + str_len, caBuffer, u32(tSize)); - - l_iErrorCode = luaL_loadbuffer(L, script, tSize + str_len, caScriptName); - - if (dynamic_allocation) - xr_free(script); - } - else - { - // try - { - l_iErrorCode = luaL_loadbuffer(L, caBuffer, tSize, caScriptName); - } - // catch(...) { - // l_iErrorCode= LUA_ERRSYNTAX; - // } - } - - if (l_iErrorCode) - { -//#ifdef DEBUG - if (strstr(Core.Params, "-dbg")) print_output(L,caScriptName,l_iErrorCode); -//#endif //-DEBUG - on_error(L); - return (false); - } - return (true); -} - -xr_unordered_map> unlocalizers; -bool unlocalizerPassed = false; - -static std::string join_list(const std::vector& items_vec, std::string delim = "\n") { - std::string ret; - for (const auto& i : items_vec) { - if (!ret.empty()) { - ret += delim; - } - ret += i; - } - return ret; -}; - -static bool unlocalRegex(std::set& unlocals, std::string& s, const std::regex& pattern, const int group, const std::string& replacement) { - if (std::regex_match(s, pattern)) { - //Msg("matching local function pattern"); - std::smatch match; - std::regex_search(s, match, pattern); - std::string variable = match[group]; - if (unlocals.find(variable) != unlocals.end()) { - Msg("[unlocalRegex] found variable %s to unlocal", variable.c_str()); - s = std::regex_replace(s, pattern, replacement); - return true; - } - } else { - return false; - } - return false; -}; - -bool CScriptStorage::do_file(LPCSTR caScriptName, LPCSTR caNameSpaceName) -{ - if (!unlocalizerPassed) { - auto file_list = FS.file_list_open("$game_config$", "unlocalizers\\", FS_RootOnly | FS_ListFiles); - if (!file_list) { - unlocalizerPassed = true; - } else { - xr_string id; - auto i = file_list->begin(); - auto e = file_list->end(); - for (; i != e; ++i) - { - u32 length = xr_strlen(*i); - - if (!((length >= 4) && - ((*i)[length - 4] == '.') && - ((*i)[length - 3] == 'l') && - ((*i)[length - 2] == 't') && - ((*i)[length - 1] == 'x'))) - continue; - - id.assign(*i, length - 4); - - string_path file_name; - FS.update_path(file_name, "$game_config$", (xr_string("unlocalizers\\") + id).c_str()); - xr_strcat(file_name, ".ltx"); - - Msg("opening file %s", file_name); - auto config = xr_new(file_name); - - typedef CInifile::Root sections_type; - sections_type& sections = config->sections(); - - sections_type::const_iterator i = sections.begin(); - sections_type::const_iterator e = sections.end(); - for (; i != e; ++i) - { - auto sectionName = std::string((*i)->Name.c_str()); - toLowerCase(sectionName); - if (unlocalizers.find(sectionName) == unlocalizers.end()) { - - // construct set that contains top level variables to delocalize by section name - unlocalizers[sectionName].clear(); - Msg("creating unlocalizer for script %s", sectionName.c_str()); - } - auto& data = (*i)->Data; - for (auto& item : data) { - unlocalizers[sectionName].insert(std::string(item.first.c_str())); - Msg("adding variable %s for unlocalizer for script %s", item.first.c_str(), sectionName.c_str()); - } - } - xr_delete(config); - } - FS.file_list_close(file_list); - unlocalizerPassed = true; - } - } - int start = lua_gettop(lua()); - string_path l_caLuaFileName; - IReader* l_tpFileReader = FS.r_open(caScriptName); - - if (!l_tpFileReader) - { - script_log(eLuaMessageTypeError, "Cannot open file \"%s\"", caScriptName); - return (false); - } - - // Unlocalize variables in the script defined by unlocalizers map - auto scriptContents = static_cast(l_tpFileReader->pointer()); - auto scriptLength = (size_t)l_tpFileReader->length(); - bool unlocalPerformed = false; - std::string unlocalizerResult; - std::string loweredNameSpaceName = caNameSpaceName; - toLowerCase(loweredNameSpaceName); - if (unlocalizers.find(loweredNameSpaceName) != unlocalizers.end()) { - Msg("found script %s in unlocalizers data", caNameSpaceName); - - // Get contents of the script file and split by lines - std::vector tokens; - std::string temp; - while (!l_tpFileReader->eof()) - { - char c = l_tpFileReader->r_u8(); - temp += c; - } - - std::stringstream stringStream(temp); - std::string line; - tokens.clear(); - while (std::getline(stringStream, line)) { - tokens.push_back(line); - } - - // Iterate lines and unlocalize variables - auto& unlocals = unlocalizers[loweredNameSpaceName]; - - /*for (auto& u : unlocals) { - Msg("%s", u); - }*/ - - for (auto& s : tokens) { - - //Msg("%s", s.c_str()); - - trim(s, "\n\r"); - if (s.empty()) { - continue; - } - - std::regex pattern; - - //local function x(a,b,c) - pattern = std::regex(R"((^local)([\t ]+)(function)([\t ]+)([_a-zA-Z].*)([\t ]*)(\(.*$))"); - if (unlocalRegex(unlocals, s, pattern, 5, "$3$4$5$6$7")) { - unlocalPerformed = true; - continue; - } - - //local a = ... - //local a - //local a,b,c = ... (if one of a,b,c is in unlocalizers list - all of them will be unlocalized) - //local x; local y; - unsupported yet - pattern = std::regex(R"((^local)([\t ]+)(.*))"); - if (std::regex_match(s, pattern)) { - std::smatch match; - std::regex_search(s, match, pattern); - std::string m = match[3]; - - // strip comments - std::regex r = std::regex(R"((.*)--.*)"); - if (std::regex_match(m, r)) { - //Msg("found comments\n"); - std::smatch noncomments; - std::regex_search(m, noncomments, r); - m = noncomments[1]; - } - - auto variablesAndValues = splitStringLimit(m, "=", 1); - bool hasValue = variablesAndValues.size() > 1; - auto variables = splitStringMulti(variablesAndValues[0], ","); - for (auto v : variables) { - trim(v); - //Msg("%s\n", v.c_str()); - if (unlocals.find(v) != unlocals.end()) { - unlocalPerformed = true; - Msg("found variable %s to unlocal", v.c_str()); - s = std::regex_replace(s, pattern, "$3"); - if (!hasValue) { - - // strip comments - std::regex r = std::regex(R"((.*)(--.*))"); - if (std::regex_match(s, r)) { - //Msg("found comments\n"); - std::smatch noncomments; - std::regex_search(s, noncomments, r); - s = std::string(noncomments[1]) + "= nil " + std::string(noncomments[2]); - } else { - s += " = nil"; - } - } - break; - } - } - } - } - - // Store result back - /*for (auto& s : tokens) { - Msg("%s", s.c_str()); - }*/ - - unlocalizerResult = join_list(tokens); - scriptContents = unlocalizerResult.c_str(); - scriptLength = strlen(scriptContents); - } - - strconcat(sizeof(l_caLuaFileName), l_caLuaFileName, "@", caScriptName); - - bool bufferLoaded = false; - if (unlocalPerformed) { - bufferLoaded = load_buffer(lua(), scriptContents, scriptLength, l_caLuaFileName, caNameSpaceName); - } else { - l_tpFileReader->rewind(); - bufferLoaded = load_buffer(lua(), static_cast(l_tpFileReader->pointer()), (size_t)l_tpFileReader->length(), l_caLuaFileName, caNameSpaceName); - } - - if (!bufferLoaded) - { - // VERIFY (lua_gettop(lua()) >= 4); - // lua_pop (lua(),4); - // VERIFY (lua_gettop(lua()) == start - 3); - lua_settop(lua(), start); - FS.r_close(l_tpFileReader); - return (false); - } - FS.r_close(l_tpFileReader); - - int errFuncId = -1; -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - if( ai().script_engine().debugger() ) - errFuncId = ai().script_engine().debugger()->PrepareLua(lua()); -# endif // #ifndef USE_LUA_STUDIO -#endif // #ifdef USE_DEBUGGER - if (0) //. - { - for (int i = 0; lua_type(lua(), -i - 1); i++) - Msg("%2d : %s", -i - 1, lua_typename(lua(), lua_type(lua(), -i - 1))); - } - - // because that's the first and the only call of the main chunk - there is no point to compile it - // luaJIT_setmode (lua(),0,LUAJIT_MODE_ENGINE|LUAJIT_MODE_OFF); // Oles - int l_iErrorCode = lua_pcall(lua(), 0, 0, (-1 == errFuncId) ? 0 : errFuncId); // new_Andy - // luaJIT_setmode (lua(),0,LUAJIT_MODE_ENGINE|LUAJIT_MODE_ON); // Oles - -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - if( ai().script_engine().debugger() ) - ai().script_engine().debugger()->UnPrepareLua(lua(),errFuncId); -# endif // #ifndef USE_LUA_STUDIO -#endif // #ifdef USE_DEBUGGER - if (l_iErrorCode) - { -//#ifdef DEBUG - if (strstr(Core.Params, "-dbg")) print_output(lua(),caScriptName,l_iErrorCode); -//#endif - on_error(lua()); - lua_settop(lua(), start); - return (false); - } - - return (true); -} - -bool CScriptStorage::load_file_into_namespace(LPCSTR caScriptName, LPCSTR caNamespaceName) -{ - int start = lua_gettop(lua()); - if (!do_file(caScriptName, caNamespaceName)) - { - Msg("! [ERROR] --- Failed to load script %s", caNamespaceName); - lua_settop(lua(), start); - return (false); - } - VERIFY(lua_gettop(lua()) == start); - return (true); -} - -bool CScriptStorage::namespace_loaded(LPCSTR N, bool remove_from_stack) -{ - int start = lua_gettop(lua()); - lua_pushstring(lua(), "_G"); - lua_rawget(lua(), LUA_GLOBALSINDEX); - string256 S2; - xr_strcpy(S2, N); - LPSTR S = S2; - for (;;) - { - if (!xr_strlen(S)) - { - VERIFY(lua_gettop(lua()) >= 1); - lua_pop(lua(), 1); - VERIFY(start == lua_gettop(lua())); - return (false); - } - LPSTR S1 = strchr(S, '.'); - if (S1) - *S1 = 0; - lua_pushstring(lua(), S); - lua_rawget(lua(), -2); - if (lua_isnil(lua(), -1)) - { - // lua_settop (lua(),0); - VERIFY(lua_gettop(lua()) >= 2); - lua_pop(lua(), 2); - VERIFY(start == lua_gettop(lua())); - return (false); // there is no namespace! - } - else if (!lua_istable(lua(), -1)) - { - // lua_settop (lua(),0); - VERIFY(lua_gettop(lua()) >= 1); - lua_pop(lua(), 1); - VERIFY(start == lua_gettop(lua())); - FATAL(" Error : the namespace name is already being used by the non-table object!\n"); - return (false); - } - lua_remove(lua(), -2); - if (S1) - S = ++S1; - else - break; - } - if (!remove_from_stack) - { - VERIFY(lua_gettop(lua()) == start + 1); - } - else - { - VERIFY(lua_gettop(lua()) >= 1); - lua_pop(lua(), 1); - VERIFY(lua_gettop(lua()) == start); - } - return (true); -} - -bool CScriptStorage::object(LPCSTR identifier, int type) -{ - int start = lua_gettop(lua()); - lua_pushnil(lua()); - while (lua_next(lua(), -2)) - { - if ((lua_type(lua(), -1) == type) && !xr_strcmp(identifier, lua_tostring(lua(), -2))) - { - VERIFY(lua_gettop(lua()) >= 3); - lua_pop(lua(), 3); - VERIFY(lua_gettop(lua()) == start - 1); - return (true); - } - lua_pop(lua(), 1); - } - VERIFY(lua_gettop(lua()) >= 1); - lua_pop(lua(), 1); - VERIFY(lua_gettop(lua()) == start - 1); - return (false); -} - -bool CScriptStorage::object(LPCSTR namespace_name, LPCSTR identifier, int type) -{ - int start = lua_gettop(lua()); - if (xr_strlen(namespace_name) && !namespace_loaded(namespace_name, false)) - { - VERIFY(lua_gettop(lua()) == start); - return (false); - } - bool result = object(identifier, type); - VERIFY(lua_gettop(lua()) == start); - return (result); -} - -luabind::object CScriptStorage::name_space(LPCSTR namespace_name) +void CScriptStorage::set(LPCSTR name_space, LPCSTR key, LPCSTR val) { - string256 S1; - xr_strcpy(S1, namespace_name); - LPSTR S = S1; - luabind::object lua_namespace = luabind::get_globals(lua()); - for (;;) - { - if (!xr_strlen(S)) - return (lua_namespace); - LPSTR I = strchr(S, '.'); - if (!I) - return (lua_namespace[S]); - *I = 0; - lua_namespace = lua_namespace[S]; - S = I + 1; - } + auto cache = &m_cache[name_space]; + if (key && val) + cache->insert(std::pair(std::string(key), std::string(val))); } -#include - -struct raii_guard : private boost::noncopyable -{ - int m_error_code; - LPCSTR const& m_error_description; - - raii_guard(int error_code, LPCSTR const& m_description) : m_error_code(error_code), - m_error_description(m_description) - { - } - - ~raii_guard() - { -#ifdef DEBUG - bool lua_studio_connected = !!ai().script_engine().debugger(); - if (!lua_studio_connected) -#endif //-DEBUG - { -#ifdef DEBUG - static bool const break_on_assert = !!strstr(Core.Params,"-break_on_assert"); -#else //!DEBUG - static bool const break_on_assert = false; //Alundaio: Can't get a proper stack trace with this enabled -#endif //-DEBUG - if (!m_error_code) - return; - - if (break_on_assert) - R_ASSERT2(!m_error_code, m_error_description); - else - Msg("! [SCRIPT ERROR]: %s", m_error_description); - } - } -}; //-struct raii_guard - -bool CScriptStorage::print_output(lua_State* L, LPCSTR caScriptFileName, int iErorCode) +CScriptStorage g_script_storage; +CScriptStorage& ScriptStorage() { - if (iErorCode) - print_error(L, iErorCode); - - LPCSTR S = "see call_stack for details!"; - - raii_guard guard(iErorCode, S); - - if (!lua_isstring(L, -1)) - return (false); - - S = lua_tostring(L, -1); - if (!xr_strcmp(S, "cannot resume dead coroutine")) - { - VERIFY2("Please do not return any values from main!!!", caScriptFileName); -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - if(ai().script_engine().debugger() && ai().script_engine().debugger()->Active() ){ - ai().script_engine().debugger()->Write(S); - ai().script_engine().debugger()->ErrorBreak(); - } -# endif //!USE_LUA_STUDIO -#endif //-USE_DEBUGGER - } - else - { - if (!iErorCode) - script_log(ScriptStorage::eLuaMessageTypeInfo, "Output from %s", caScriptFileName); - script_log(iErorCode ? ScriptStorage::eLuaMessageTypeError : ScriptStorage::eLuaMessageTypeMessage, "%s", S); -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO - if (ai().script_engine().debugger() && ai().script_engine().debugger()->Active()) { - ai().script_engine().debugger()->Write (S); - ai().script_engine().debugger()->ErrorBreak (); - } -# endif //!USE_LUA_STUDIO -#endif //-USE_DEBUGGER - } - return (true); -} - -void CScriptStorage::print_error(lua_State* L, int iErrorCode) -{ - switch (iErrorCode) - { - case LUA_ERRRUN: - { - script_log(ScriptStorage::eLuaMessageTypeError, "SCRIPT RUNTIME ERROR"); - break; - } - case LUA_ERRMEM: - { - script_log(ScriptStorage::eLuaMessageTypeError, "SCRIPT ERROR (memory allocation)"); - break; - } - case LUA_ERRERR: - { - script_log(ScriptStorage::eLuaMessageTypeError, "SCRIPT ERROR (while running the error handler function)"); - break; - } - case LUA_ERRFILE: - { - script_log(ScriptStorage::eLuaMessageTypeError, "SCRIPT ERROR (while running file)"); - break; - } - case LUA_ERRSYNTAX: - { - script_log(ScriptStorage::eLuaMessageTypeError, "SCRIPT SYNTAX ERROR"); - break; - } - case LUA_YIELD: - { - script_log(ScriptStorage::eLuaMessageTypeInfo, "Thread is yielded"); - break; - } - default: NODEFAULT; - } -} - -#ifdef LUA_DEBUG_PRINT //DEBUG -void CScriptStorage::flush_log() -{ - string_path log_file_name; - strconcat (sizeof(log_file_name),log_file_name,Core.ApplicationName,"_",Core.UserName,"_lua.log"); - FS.update_path (log_file_name,"$logs$",log_file_name); - m_output.save_to (log_file_name); -} -#endif //-LUA_DEBUG_PRINT DEBUG - -int CScriptStorage::error_log(LPCSTR format, ...) -{ - va_list marker; - va_start(marker, format); - - LPCSTR S = "! [LUA][ERROR] "; - LPSTR S1; - string4096 S2; - xr_strcpy(S2, S); - S1 = S2 + xr_strlen(S); - - int result = vsprintf(S1, format, marker); - va_end(marker); - - Msg("%s", S2); - - return (result); -} + return g_script_storage; +} \ No newline at end of file diff --git a/src/xrServerEntities/script_storage.h b/src/xrServerEntities/script_storage.h index 351ade5ed..6fd93f8be 100644 --- a/src/xrServerEntities/script_storage.h +++ b/src/xrServerEntities/script_storage.h @@ -1,103 +1,23 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_storage.h -// Created : 01.04.2004 -// Modified : [1/14/2015 Andrey] -// Author : Dmitriy Iassenev -// Description : XRay Script Storage -//////////////////////////////////////////////////////////////////////////// - #pragma once -#include "script_storage_space.h" -#include "script_space_forward.h" - -struct lua_State; -class CScriptThread; - -#ifndef MASTER_GOLD -# define USE_DEBUGGER -# define USE_LUA_STUDIO -#endif //-!MASTER_GOLD - -#ifdef XRGAME_EXPORTS -# ifndef MASTER_GOLD -# define PRINT_CALL_STACK -# endif //-!MASTER_GOLD -#else //!XRGAME_EXPORTS -# ifndef NDEBUG -# define PRINT_CALL_STACK -# endif // #ifndef NDEBUG -#endif //-XRGAME_EXPORTS - -//AVO: allow LUA debug prints (i.e.: ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "CWeapon : cannot access class member Weapon_IsScopeAttached!");) -#include "..\build_config_defines.h" -#ifndef DEBUG -# ifdef LUA_DEBUG_PRINT -# define PRINT_CALL_STACK -# endif -#endif //-!DEBUG -//-AVO - -using namespace ScriptStorage; +#include "script_export_space.h" +#include +#include +// Persistent storage for the Lua environment class CScriptStorage { private: - lua_State* m_virtual_machine; - CScriptThread* m_current_thread; - BOOL m_jit; - -#ifdef DEBUG + std::map> m_cache; public: - bool m_stack_is_ready ; -#endif //-DEBUG - -#ifdef LUA_DEBUG_PRINT//PRINT_CALL_STACK -protected: - CMemoryWriter m_output; -#else -# ifdef DEBUG -protected: - CMemoryWriter m_output; -# endif //-DEBUG -#endif //-LUA_DEBUG_PRINT PRINT_CALL_STACK + LPCSTR get(LPCSTR name_space, LPCSTR key); + void set(LPCSTR name_space, LPCSTR key, LPCSTR value); -protected: - static int vscript_log(ScriptStorage::ELuaMessageType tLuaMessageType, LPCSTR caFormat, va_list marker); - bool parse_namespace(LPCSTR caNamespaceName, LPSTR b, u32 const b_size, LPSTR c, u32 const c_size); - bool do_file(LPCSTR caScriptName, LPCSTR caNameSpaceName); - void reinit(); - -public: - //#ifdef PRINT_CALL_STACK - void print_stack(); - //AVO: added to stop duplicate stack output prints in log - static int __cdecl script_log_no_stack(ScriptStorage::ELuaMessageType tLuaMessageType, LPCSTR caFormat, ...); - //-AVO - //#endif //-PRINT_CALL_STACK - -public: - CScriptStorage(); - virtual ~CScriptStorage(); - IC lua_State* lua(); - IC void current_thread(CScriptThread* thread); - IC CScriptThread* current_thread() const; - bool load_buffer(lua_State* L, LPCSTR caBuffer, size_t tSize, LPCSTR caScriptName, LPCSTR caNameSpaceName = 0); - bool load_file_into_namespace(LPCSTR caScriptName, LPCSTR caNamespaceName); - bool namespace_loaded(LPCSTR caName, bool remove_from_stack = true); - bool object(LPCSTR caIdentifier, int type); - bool object(LPCSTR caNamespaceName, LPCSTR caIdentifier, int type); - luabind::object name_space(LPCSTR namespace_name); - int error_log(LPCSTR caFormat, ...); - static int __cdecl script_log(ELuaMessageType message, LPCSTR caFormat, ...); - static bool print_output(lua_State* L, LPCSTR caScriptName, int iErorCode = 0); - static void print_error(lua_State* L, int iErrorCode); - virtual void on_error(lua_State* L) = 0; - -#ifdef LUA_DEBUG_PRINT //DEBUG -public: - void flush_log(); -#endif //-LUA_DEBUG_PRINT DEBUG +DECLARE_SCRIPT_REGISTER_FUNCTION }; -#include "script_storage_inline.h" +CScriptStorage& ScriptStorage(); + +add_to_type_list(CScriptStorage) +#undef script_type_list +#define script_type_list save_type_list(CScriptStorage) diff --git a/src/xrServerEntities/script_storage_inline.h b/src/xrServerEntities/script_storage_inline.h deleted file mode 100644 index 8cd778846..000000000 --- a/src/xrServerEntities/script_storage_inline.h +++ /dev/null @@ -1,25 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_storage_inline.h -// Created : 01.04.2004 -// Modified : 01.04.2004 -// Author : Dmitriy Iassenev -// Description : XRay Script Storage inline functions -//////////////////////////////////////////////////////////////////////////// - -#pragma once - -IC lua_State* CScriptStorage::lua() -{ - return (m_virtual_machine); -} - -IC void CScriptStorage::current_thread(CScriptThread* thread) -{ - VERIFY((thread && !m_current_thread) || !thread); - m_current_thread = thread; -} - -IC CScriptThread* CScriptStorage::current_thread() const -{ - return (m_current_thread); -} diff --git a/src/xrServerEntities/script_storage_script.cpp b/src/xrServerEntities/script_storage_script.cpp new file mode 100644 index 000000000..b30ead042 --- /dev/null +++ b/src/xrServerEntities/script_storage_script.cpp @@ -0,0 +1,20 @@ +#include "stdafx.h" + +#include "luabind/luabind.hpp" +#include "script_storage.h" +#include "ai_space.h" +#include "script_engine.h" +#include "object_item_script.h" + +using namespace luabind; + +#pragma optimize("s",on) +void CScriptStorage::script_register(lua_State* L) +{ + module(L) + [ + class_("CScriptStorage") + .def("get", &CScriptStorage::get) + .def("set", &CScriptStorage::set) + ]; +} \ No newline at end of file diff --git a/src/xrServerEntities/script_storage_space.h b/src/xrServerEntities/script_storage_space.h deleted file mode 100644 index 9b0fcf702..000000000 --- a/src/xrServerEntities/script_storage_space.h +++ /dev/null @@ -1,24 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_storage_space.h -// Created : 01.04.2004 -// Modified : 01.04.2004 -// Author : Dmitriy Iassenev -// Description : XRay Script Storage space -//////////////////////////////////////////////////////////////////////////// - -#pragma once - -namespace ScriptStorage -{ - enum ELuaMessageType - { - eLuaMessageTypeInfo = u32(0), - eLuaMessageTypeError, - eLuaMessageTypeMessage, - eLuaMessageTypeHookCall, - eLuaMessageTypeHookReturn, - eLuaMessageTypeHookLine, - eLuaMessageTypeHookCount, - eLuaMessageTypeHookTailReturn = u32(-1), - }; -} diff --git a/src/xrServerEntities/script_thread.cpp b/src/xrServerEntities/script_thread.cpp deleted file mode 100644 index eee8178b9..000000000 --- a/src/xrServerEntities/script_thread.cpp +++ /dev/null @@ -1,194 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_thread.cpp -// Created : 19.09.2003 -// Modified : 29.06.2004 -// Author : Dmitriy Iassenev -// Description : Script thread class -//////////////////////////////////////////////////////////////////////////// - -#include "pch_script.h" -//AVO: lua re-org -#include "lua.hpp" -/*extern "C" { - #include "lua/lua.h" -};*/ -//-AVO -#include "script_engine.h" -#include "script_thread.h" -#include "ai_space.h" - -#define LUABIND_HAS_BUGS_WITH_LUA_THREADS - -#ifdef USE_DEBUGGER -# ifndef USE_LUA_STUDIO -# include "script_debugger.h" -# else // #ifndef USE_LUA_STUDIO -# include "lua_studio.h" -# endif // #ifndef USE_LUA_STUDIO -#endif - -const LPCSTR main_function = "console_command_run_string_main_thread_function"; - -//void print_stack_(lua_State *L) -//{ -// Msg(" "); -// for (int i=0; lua_type(L, -i-1); i++) -// Msg("%2d : %s",-i-1,lua_typename(L, lua_type(L, -i-1))); -//} - -//extern "C" __declspec(dllimport) lua_State *lua_newcthread(lua_State *OL, int cstacksize); - -CScriptThread::CScriptThread(LPCSTR caNamespaceName, bool do_string, bool reload) -{ - m_virtual_machine = 0; - m_active = false; - - try - { - string256 S; - if (!do_string) - { - m_script_name = caNamespaceName; - ai().script_engine().process_file(caNamespaceName, reload); - } - else - { - m_script_name = "console command"; - xr_sprintf(S, "function %s()\n%s\nend\n", main_function, caNamespaceName); - int l_iErrorCode = luaL_loadbuffer(ai().script_engine().lua(), S, xr_strlen(S), "@console_command"); - if (!l_iErrorCode) - { - l_iErrorCode = lua_pcall(ai().script_engine().lua(), 0, 0, 0); - if (l_iErrorCode) - { - ai().script_engine().print_output(ai().script_engine().lua(), *m_script_name, l_iErrorCode); - ai().script_engine().on_error(ai().script_engine().lua()); - return; - } - } - else - { - ai().script_engine().print_output(ai().script_engine().lua(), *m_script_name, l_iErrorCode); - ai().script_engine().on_error(ai().script_engine().lua()); - return; - } - } - - // print_stack_ (ai().script_engine().lua()); - m_virtual_machine = lua_newthread(ai().script_engine().lua()); - // m_virtual_machine = lua_newcthread(ai().script_engine().lua(),0); - VERIFY2(lua(), "Cannot create new Lua thread"); -#if defined(USE_DEBUGGER) && defined(USE_LUA_STUDIO) - if ( ai().script_engine().debugger() ) - ai().script_engine().debugger()->add ( m_virtual_machine ); -#endif // #if defined(USE_DEBUGGER) && defined(USE_LUA_STUDIO) - // print_stack_ (ai().script_engine().lua()); - // m_thread_reference = luaL_ref(ai().script_engine().lua(),LUA_REGISTRYINDEX); - // print_stack_ (ai().script_engine().lua()); - - // if (g_ca_stdout[0]) { - // fputc (0,stderr); - // ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeInfo,"%s",g_ca_stdout); - // fflush (stderr); - // } - // Msg ("lua get top %d",lua_gettop(ai().script_engine().lua())); - // print_stack_ (ai().script_engine().lua()); - -#ifndef USE_LUA_STUDIO -# ifdef DEBUG -# ifdef USE_DEBUGGER - if (ai().script_engine().debugger() && ai().script_engine().debugger()->Active()) - lua_sethook (lua(), CDbgLuaHelper::hookLua, LUA_MASKLINE|LUA_MASKCALL|LUA_MASKRET, 0); - else -# endif // #ifdef USE_DEBUGGER - lua_sethook (lua(),CScriptEngine::lua_hook_call, LUA_MASKLINE|LUA_MASKCALL|LUA_MASKRET, 0); -# endif // #ifdef DEBUG -#endif // #ifndef USE_LUA_STUDIO - - if (!do_string) - xr_sprintf(S, "%s.main()", caNamespaceName); - else - xr_sprintf(S, "%s()", main_function); - - if (!ai().script_engine().load_buffer(lua(), S, xr_strlen(S), "@_thread_main")) - return; - - m_active = true; - } - catch (...) - { - m_active = false; - } -} - -CScriptThread::~CScriptThread() -{ -#ifdef DEBUG - Msg ("* Destroying script thread %s",*m_script_name); -#endif - try - { -#if defined(USE_DEBUGGER) && defined(USE_LUA_STUDIO) - if (ai().script_engine().debugger()) - ai().script_engine().debugger()->remove ( m_virtual_machine ); -#endif // #if defined(USE_DEBUGGER) && defined(USE_LUA_STUDIO) -#ifndef LUABIND_HAS_BUGS_WITH_LUA_THREADS - luaL_unref (ai().script_engine().lua(),LUA_REGISTRYINDEX,m_thread_reference); -#endif - } - catch (...) - { - } -} - -bool CScriptThread::update() -{ - if (!m_active) - R_ASSERT2(false, "Cannot resume dead Lua thread!"); - - try - { - ai().script_engine().current_thread(this); - - int l_iErrorCode = lua_resume(lua(), 0); - - if (l_iErrorCode && (l_iErrorCode != LUA_YIELD)) - { - ai().script_engine().print_output(lua(), *script_name(), l_iErrorCode); - ai().script_engine().on_error(ai().script_engine().lua()); -#ifdef DEBUG - print_stack (lua()); -#endif - m_active = false; - } - else - { - if (l_iErrorCode != LUA_YIELD) - { -#ifdef DEBUG - if (m_current_stack_level) { - ai().script_engine().print_output (lua(),*script_name(),l_iErrorCode); - ai().script_engine().on_error (ai().script_engine().lua()); -// print_stack (lua()); - } -#endif // DEBUG - m_active = false; -#ifdef DEBUG - ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeInfo,"Script %s is finished!",*m_script_name); -#endif // DEBUG - } - else - { - VERIFY2(!lua_gettop(lua()), "Do not pass any value to coroutine.yield()!"); - } - } - - ai().script_engine().current_thread(0); - } - catch (...) - { - ai().script_engine().current_thread(0); - m_active = false; - } - return (m_active); -} diff --git a/src/xrServerEntities/script_thread.h b/src/xrServerEntities/script_thread.h deleted file mode 100644 index 67012ed77..000000000 --- a/src/xrServerEntities/script_thread.h +++ /dev/null @@ -1,44 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_thread.h -// Created : 19.09.2003 -// Modified : 29.06.2004 -// Author : Dmitriy Iassenev -// Description : Script thread class -//////////////////////////////////////////////////////////////////////////// - -#pragma once - -#ifdef DEBUG -# include "script_stack_tracker.h" -#endif - -struct lua_State; - -#ifdef DEBUG - class CScriptThread : public CScriptStackTracker -#else -class CScriptThread -#endif -{ -private: - shared_str m_script_name; - int m_thread_reference; - bool m_active; - lua_State* m_virtual_machine; - -#ifdef DEBUG -protected: - static void lua_hook_call (lua_State *L, lua_Debug *dbg); -#endif - -public: - CScriptThread(LPCSTR caNamespaceName, bool do_string = false, bool reload = false); - virtual ~CScriptThread(); - bool update(); - IC bool active() const; - IC shared_str script_name() const; - IC int thread_reference() const; - IC lua_State* lua() const; -}; - -#include "script_thread_inline.h" diff --git a/src/xrServerEntities/script_thread_inline.h b/src/xrServerEntities/script_thread_inline.h deleted file mode 100644 index eb5a07751..000000000 --- a/src/xrServerEntities/script_thread_inline.h +++ /dev/null @@ -1,29 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Module : script_thread_inline.h -// Created : 19.09.2003 -// Modified : 29.06.2004 -// Author : Dmitriy Iassenev -// Description : Script thread class inline functions -//////////////////////////////////////////////////////////////////////////// - -#pragma once - -IC bool CScriptThread::active() const -{ - return (m_active); -} - -IC shared_str CScriptThread::script_name() const -{ - return (m_script_name); -} - -IC int CScriptThread::thread_reference() const -{ - return (m_thread_reference); -} - -IC lua_State* CScriptThread::lua() const -{ - return (m_virtual_machine); -}