Skip to content

Commit

Permalink
Simplify scripts adaptation
Browse files Browse the repository at this point in the history
  • Loading branch information
Drombeys committed Oct 28, 2024
1 parent d2dcdd1 commit 7e0c17a
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 108 deletions.
3 changes: 3 additions & 0 deletions gamedata/configs/mod_script_ixray.ltx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
![common]
>script = ixray_global
>class_registrators = ixray_global.register
71 changes: 45 additions & 26 deletions gamedata/scripts/_g.script
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
--// JIT init
if (jit == nil) then
profiler.setup_hook ()
end

math.randomseed(time_global())

isMarshal = marshal ~= nil
isLfs = lfs ~= nil

--// Some X-Ray block
DebugLog = false

function empty (container)
if (type(container) == "function") then
Expand All @@ -32,15 +24,6 @@ end
schemes = {} -- соответствие схем модулям
stypes = {} -- типы схем

function log(str)
if DebugLog then
SemiLog(str)
end
if DebuggerMode then
LuaPanda.printToVSCode(str,1,2)
end
end

-- Загружает схему из файла на диске и активирует в мотиваторе.
-- Здесь:
-- filename - имя файла, в котором реализована схема, без расширения
Expand Down Expand Up @@ -425,10 +408,23 @@ local stalker_classes = {}
local weapon_classes = {}
local artefact_classes = {}

IsMonster = function(object, class_id) return monster_classes [class_id or get_clsid(object) or -1] ~= nil end
IsStalker = function(object, class_id) return stalker_classes [class_id or get_clsid(object) or -1] ~= nil end
isWeapon = function(object, class_id) return weapon_classes [class_id or get_clsid(object) or -1] ~= nil end
isArtefact = function(object, class_id) return artefact_classes[class_id or get_clsid(object) or -1] ~= nil end
-- IX-Ray Refactor (Optional)
IsMonster = function(object, class_id)
return monster_classes[class_id or get_clsid(object) or -1] ~= nil
end

IsStalker = function(object, class_id)
return stalker_classes[class_id or get_clsid(object) or -1] ~= nil
end

isWeapon = function(object, class_id)
return weapon_classes[class_id or get_clsid(object) or -1] ~= nil
end

isArtefact = function(object, class_id)
return artefact_classes[class_id or get_clsid(object) or -1] ~= nil
end
-- END IX-Ray
-------------------------------------------------------------------------------------------
function get_object_community(obj)
if type(obj.id) == "function" then
Expand Down Expand Up @@ -487,6 +483,16 @@ function set_inactivate_input_time(delta)
level.disable_input()
end

-- Принимает: позицию положения, позицию куда смотреть, время сна в минутах.
--[[
function set_sleep_relocate(point, look, timeout)
db.storage[db.actor:id()].sleep_relocate_time = game.get_game_time()
db.storage[db.actor:id()].sleep_relocate_idle = timeout*60
db.storage[db.actor:id()].sleep_relocate_point = point
db.storage[db.actor:id()].sleep_relocate_look = look
end
]]--

-- проверяет целую часть числа на нечетность
function odd( x )
return math.floor( x * 0.5 ) * 2 == math.floor( x )
Expand Down Expand Up @@ -601,6 +607,9 @@ function start_game_callback()
sim_board.clear()
sr_light.clean_up ()
pda.add_quick_slot_items_on_game_start()
-- Tестирование оптимизации
--local test_object = test_object.test_object_class()
--test_object:test()
end

--' Усталость
Expand Down Expand Up @@ -697,14 +706,22 @@ function get_param_string(src_string , obj)
end
end

-- IX-Ray Hack: For backwards compatibility (Optional, for set_save_marker)
if not IsEditor then
IsEditor = function ()
return false
end
end

local save_markers = {}

-- Функции для проверки корректности сейв лоад
function set_save_marker(p, mode, check, prefix)
if (not IsEditor()) then
-- IX-Ray
if save and not IsEditor() then
save.set_stage(prefix)
end

-- END IX-Ray
-- определяем ключ маркера.
local result = ""
-- if debug ~= nil then
Expand All @@ -730,11 +747,13 @@ function set_save_marker(p, mode, check, prefix)
printf("WARNING! may be this is problem save point")
end
if dif >= 10240 then
-- IX-Ray
callstack()
if (not IsEditor()) then

if save and not IsEditor() then
save.call_error()
end
-- END IX-Ray
end
p:w_u16(dif)
else
Expand Down Expand Up @@ -861,4 +880,4 @@ function show_all_ui(show)
-- db.actor:hide_weapon()
db.actor:disable_hit_marks(true)
end
end
end
14 changes: 9 additions & 5 deletions gamedata/scripts/bind_anomaly_zone.script
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
--'******************************************************
--'* ?????? ??????? ???? ???????? .
--'* ������ ������� ���� �������� .
--'******************************************************
artefact_ways_by_id = {}
artefact_points_by_id = {}
parent_zones_by_artefact_id = {}
ANOMAL_ZONE_SECT = "anomal_zone"

function bind(obj)
-- IX-Ray: Added security check for multiplayer compatibility
if IsGameTypeSingle() or OnServer() then
obj:bind_object(anomaly_zone_binder(obj))
end
Expand Down Expand Up @@ -189,11 +190,13 @@ end
function anomaly_zone_binder:respawn_artefacts_and_replace_anomaly_zone()
local anom_fields = bind_anomaly_field.fields_by_names
self.respawn_artefacts = true


-- START IX-Ray: Added security check for multiplayer compatibility
if not IsGameTypeSingle() then
return
end

-- END IX-Ray

if(self.custom_placement) then
local layer = self.cur_layer
for k,v in pairs(self.fields_table[layer]) do
Expand Down Expand Up @@ -277,8 +280,9 @@ function anomaly_zone_binder:spawn_artefact_randomly()
parent_zones_by_artefact_id[artefact_obj.id] = self
self.spawned_count = self.spawned_count + 1

-- START IX-Ray
pda.change_anomalies_names()

-- END IX-Ray
end

function anomaly_zone_binder:get_artefact_path()
Expand Down Expand Up @@ -476,4 +480,4 @@ function anomaly_zone_binder:load(thread)
end
self.turned_off = thread:r_bool()
set_save_marker(thread, "load", true, "anomaly_zone_binder")
end
end
12 changes: 9 additions & 3 deletions gamedata/scripts/bind_stalker.script
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function actor_binder:net_spawn(data)
self.task_manager = task_manager.get_task_manager()
self.spawn_frame = device().frame
self.already_jumped = false
-- self.loaded = false
benchmark.main() --' Distemper 06.2008 --
return true
end
Expand Down Expand Up @@ -352,6 +353,11 @@ function actor_binder:update(delta)
-- Апдейт доступности для симуляции.
simulation_objects.get_sim_obj_registry():update_avaliability(alife():actor())

-- Not used
--if not self.loaded then
-- get_console():execute("dump_infos")
-- self.loaded = true
--end
treasure_manager.get_treasure_manager():update()

if not(primary_objects_filled) then
Expand All @@ -360,7 +366,7 @@ function actor_binder:update(delta)
end
pda.fill_sleep_zones()

SendScriptCallback("update")
SendScriptCallback("update") -- IX-Ray
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:save(packet)
Expand Down Expand Up @@ -429,7 +435,7 @@ function actor_binder:save(packet)
end
set_save_marker(packet, "save", true, "actor_binder")

SendScriptCallback("save", packet)
SendScriptCallback("save", packet) -- IX-Ray
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:load(reader)
Expand Down Expand Up @@ -487,7 +493,7 @@ function actor_binder:load(reader)
end
set_save_marker(reader, "load", true, "actor_binder")

SendScriptCallback("load", reader)
SendScriptCallback("load", reader) -- IX-Ray
end

--*************************************************************
Expand Down
3 changes: 1 addition & 2 deletions gamedata/scripts/class_registrator.script
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function register(object_factory)
-- ARTEFACTS --------------------------------------------------------------------------------------------------------------------------

cs_register (object_factory, "CElectricBall", "se_artefact.se_artefact", "SCRPTART", "artefact_s")
cs_register (object_factory, "CCar", "se_car.se_car", "SCRPTCAR", "car_s")

-- MONSTERS ---------------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -135,4 +134,4 @@ function register(object_factory)
-- ONLINE_OFFLINE_GROUP --------------------------------------------------------------------------------------------------------------

s_register (object_factory, "sim_squad_scripted.sim_squad_scripted", "ON_OFF_S", "online_offline_group_s")
end
end
2 changes: 1 addition & 1 deletion gamedata/scripts/gulag_general.script
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ local job_type_by_scheme = {
function add_exclusive_job(sect, work_field, smart_ini, job_table)
local work = utils.cfg_get_string(smart_ini, sect, work_field, nil, false, "")
if work == nil then return end
local ini_path = "scripts\\"..work
local ini_path = "\scripts\\"..work

local fs = getFS()
if fs:exist("$game_config$",ini_path) == nil then
Expand Down
25 changes: 25 additions & 0 deletions gamedata/scripts/ixray_global.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
math.randomseed(time_global())

_G.isMarshal = marshal ~= nil
_G.isLfs = lfs ~= nil

_G.bit_and = bit.band
_G.bit_or = bit.bor
_G.bit_xor = bit.bxor
_G.bit_not = bit.bnot

--// Some X-Ray block
_G.DebugLog = false

_G.log = function (str)
if DebugLog then
SemiLog(str)
end
if DebuggerMode then
LuaPanda.printToVSCode(str,1,2)
end
end

function register(object_factory)
class_registrator.cs_register(object_factory, "CCar", "se_car.se_car", "SCRPTCAR", "car_s")
end
Loading

0 comments on commit 7e0c17a

Please sign in to comment.