From 6d88eeb73192be2de9f0dcd186e32676f3e131a1 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 4 May 2025 12:29:08 +0200 Subject: [PATCH 1/5] ADD: igi_helper.give_to_actor --- gamedata/scripts/igi_helper.script | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gamedata/scripts/igi_helper.script b/gamedata/scripts/igi_helper.script index 8cea33c..d902092 100644 --- a/gamedata/scripts/igi_helper.script +++ b/gamedata/scripts/igi_helper.script @@ -164,3 +164,9 @@ function is_valid_section(section_name) igi_helper.trace_assert(type(section_name) == "string", "Section is not a string", section_name) return ini_sys:section_exist(section_name) end + +function give_to_actor(section_name) + local id = alife_create_item(section_name, alife_object(0)).id + news_manager.relocate_item(db.actor, "in", section_name, 1) + return id +end From d8fa060f669a9c81a709041b2f2b75491ae7fa9c Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 4 May 2025 13:24:06 +0200 Subject: [PATCH 2/5] FIX: framework crash due to bad handling of this --- gamedata/scripts/igi_text_processor.script | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gamedata/scripts/igi_text_processor.script b/gamedata/scripts/igi_text_processor.script index 3a67541..cda8e0c 100644 --- a/gamedata/scripts/igi_text_processor.script +++ b/gamedata/scripts/igi_text_processor.script @@ -166,7 +166,9 @@ local function resolve_all_links(links, level, link_context, transient_fields) local macro = Macro:new(before) if macro then macro:assert_level(level) + local this_before = link_context.this local out = macro:resolve(link_context:set_this(tbl)) + link_context:set_this(this_before) if macro.is_auto then transient_fields[tbl] = transient_fields[tbl] or {} From 610f1f70bf92a682314431f80fe989762de0f328 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 4 May 2025 14:11:07 +0200 Subject: [PATCH 3/5] ADD: helpers --- gamedata/scripts/igi_subtask.script | 14 +++++ gamedata/scripts/igi_taskdata.script | 25 ++++++-- gamedata/scripts/wtf.script | 89 ++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 4 deletions(-) diff --git a/gamedata/scripts/igi_subtask.script b/gamedata/scripts/igi_subtask.script index e38c821..569ae97 100644 --- a/gamedata/scripts/igi_subtask.script +++ b/gamedata/scripts/igi_subtask.script @@ -85,6 +85,8 @@ function get_task_status(entities, CACHE) end function update_entity_status(entity, CACHE) + run_helpers(entity, CACHE, "status") + local controller = igi_taskdata.get_controller(entity, CACHE) if not controller.status then return false end local new_status = controller.status(entity) @@ -152,6 +154,8 @@ function disable_entity(key, CACHE) controller.on_del(target) end + run_helpers(target, CACHE, "on_del") + local link_context = igi_text_processor.get_link_context(CACHE) igi_text_processor.resolve_table_macros(target, "del", link_context) @@ -172,6 +176,8 @@ function init_entities(key, CACHE) local link_context = igi_text_processor.get_link_context(CACHE, entity) igi_text_processor.resolve_table_macros(entity, "init", link_context) + run_helpers(entity, CACHE, "on_init") + local controller = igi_taskdata.get_controller(entity, CACHE) if controller.on_init then controller.on_init(entity) @@ -190,3 +196,11 @@ function invoke_controller(callback, CACHE, ...) end end end + +function run_helpers(entity, CACHE, method) + for _, controller in ipairs(igi_taskdata.get_helpers(entity, CACHE)) do + if controller[method] then + controller[method](entity) + end + end +end diff --git a/gamedata/scripts/igi_taskdata.script b/gamedata/scripts/igi_taskdata.script index 0274300..a124b96 100644 --- a/gamedata/scripts/igi_taskdata.script +++ b/gamedata/scripts/igi_taskdata.script @@ -114,12 +114,29 @@ function finalize_task_cache(task_data, task_id, tg_id) return CACHE end +local function eval_controller(macro, CACHE, entity) + local link_context = igi_text_processor.get_link_context(CACHE, entity) + local controller = igi_text_processor.eval_logic_macro(macro, link_context) + trace_assert(type(controller) == "table", "Controller is not a table", macro) + return controller +end + local NO_CONTROLLER = {} function get_controller(entity, CACHE) if not entity.CONTROLLER then return NO_CONTROLLER end trace_assert(CACHE, "get_controller: no cache") - local link_context = igi_text_processor.get_link_context(CACHE, entity) - local controller = igi_text_processor.eval_logic_macro(entity.CONTROLLER, link_context) - trace_assert(type(controller) == "table", "Controller is not a table", entity.CONTROLLER) - return controller + return eval_controller(entity.CONTROLLER, CACHE, entity) +end + +function get_helpers(entity, CACHE) + if not entity.HELPERS then return {} end + trace_assert(CACHE, "get_helpers: no cache") + trace_assert(type(entity.HELPERS) == "table", "get_helpers: HELPERS is not a table", entity) + + local out = {} + for _, macro in ipairs(entity.HELPERS) do + trace_assert(type(macro) == "string", "get_helpers: helper is not a macro", macro) + out[#out+1] = eval_controller(macro, CACHE, entity) + end + return out end diff --git a/gamedata/scripts/wtf.script b/gamedata/scripts/wtf.script index ab0ecfa..0ecb560 100644 --- a/gamedata/scripts/wtf.script +++ b/gamedata/scripts/wtf.script @@ -56,3 +56,92 @@ function shuffle(tbl) end return t end + +CreateSquad = { + on_init = function (entity) + igi_helper.trace_assert(type(entity.section_name) == "string", "section_name is not a string", entity) + igi_helper.trace_assert(igi_helper.is_valid_section(entity.section_name), "section does not exist", entity) + igi_helper.trace_assert(type(entity.smart_id) == "number", "smart_id is not a number") + + local smart_name = alife_object(entity.smart_id):name() + entity.id = utils_obj.create_squad(entity.section_name, smart_name).id + end, + + on_del = function (entity) + local se_obj = alife_object(entity.id) + if se_obj then + se_obj.scripted_target = nil + end + end +} + +ForceOnline = { + on_init = function (entity) + igi_helper.trace_assert(type(entity.id) == "number", "id is not a number", entity) + local se_obj = alife_object(entity.id) + + igi_helper.trace_assert(se_obj ~= nil, "no server object for given id", entity) + se_obj.force_online = true + end, + + on_del = function (entity) + local se_obj = alife_object(entity.id) + if se_obj then + se_obj.force_online = false + end + end, +} + +NoOfflineCombat = { + on_init = function (entity) + igi_helper.trace_assert(type(entity.id) == "number", "id is not a number", entity) + local se_obj = alife_object(entity.id) + + igi_helper.trace_assert(se_obj ~= nil, "no server object for given id", entity) + sim_offline_combat.task_squads[entity.id] = true + end, + + on_del = function (entity) + sim_offline_combat.task_squads[entity.id] = nil + end +} + +PinToSmart = { + status = function (entity) + local se_obj = alife_object(entity.id) + if se_obj then + se_obj.stay_time = game.get_game_time() + end + end +} + +MapIcon = function (mark) + return { + status = function (entity) + igi_actions.update_mark(entity.id, mark) + end + } +end + +ChangeFaction = function (faction) + local t = {} + t.status = function (entity) + if t._done then return end + if igi_actions.is_online(entity.id) then + igi_actions.change_faction(entity.id, faction) + t._done = true + end + end + return t +end + +Repair = function (new_condition) + local t = {} + t.status = function (entity) + if t._done then return end + if igi_actions.is_low_condition(entity.id, new_condition) then + get_object_by_id(entity.id):set_condition(new_condition) + t._done = true + end + end +end From 652306b5e0b45e3b096e21884977117afda0a556 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 4 May 2025 15:04:28 +0200 Subject: [PATCH 4/5] REF: remove actions system --- gamedata/scripts/igi_actions.script | 20 -------------------- gamedata/scripts/igi_generic_task.script | 1 - 2 files changed, 21 deletions(-) diff --git a/gamedata/scripts/igi_actions.script b/gamedata/scripts/igi_actions.script index 57673af..2ae2df0 100644 --- a/gamedata/scripts/igi_actions.script +++ b/gamedata/scripts/igi_actions.script @@ -1,25 +1,5 @@ local trace_dbg = igi_helper.trace_dbg -function update_actions(CACHE) - for _, entity in pairs(CACHE.entities) do - process_actions(entity.actions, igi_text_processor.get_link_context(CACHE, entity)) - end - - process_actions(CACHE.actions, igi_text_processor.get_link_context(CACHE)) -end - -function process_actions(actions, link_context) - if type(actions) ~= "table" then return end - for _, action in pairs(actions) do - if (not action._done) then - if igi_text_processor.eval_logic_macro(action.when, link_context) then - trace_dbg("Run action", action) - action._done = not igi_text_processor.eval_logic_macro(action.run, link_context) - end - end - end -end - function change_faction(id, faction) local se_squad = alife_object(id) if not se_squad or not se_squad.squad_members then return end diff --git a/gamedata/scripts/igi_generic_task.script b/gamedata/scripts/igi_generic_task.script index bae5ce4..3499f1b 100644 --- a/gamedata/scripts/igi_generic_task.script +++ b/gamedata/scripts/igi_generic_task.script @@ -138,7 +138,6 @@ function quest_status(task_id) local CACHE = get_cache(task_id) ------------------------------------------------ igi_subtask.update_entities(CACHE) - igi_actions.update_actions(CACHE) igi_subtask.process_subtasks(CACHE) igi_callbacks.invoke_callbacks("on_task_update", CACHE) From 494728737ee1f2a64c2cbcf436d7fed6b00f28ba Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 4 May 2025 15:12:53 +0200 Subject: [PATCH 5/5] FIX: oneshot helpers shotting more than once --- gamedata/scripts/wtf.script | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/gamedata/scripts/wtf.script b/gamedata/scripts/wtf.script index 0ecb560..57f4004 100644 --- a/gamedata/scripts/wtf.script +++ b/gamedata/scripts/wtf.script @@ -119,29 +119,34 @@ MapIcon = function (mark) return { status = function (entity) igi_actions.update_mark(entity.id, mark) + end, + + on_del = function (entity) + level.map_remove_object_spot(entity.id, mark) end } end ChangeFaction = function (faction) - local t = {} - t.status = function (entity) - if t._done then return end - if igi_actions.is_online(entity.id) then - igi_actions.change_faction(entity.id, faction) - t._done = true + return { + status = function (entity) + if entity._changefaction_done then return end + if igi_actions.is_online(entity.id) then + igi_actions.change_faction(entity.id, faction) + entity._changefaction_done = true + end end - end - return t + } end Repair = function (new_condition) - local t = {} - t.status = function (entity) - if t._done then return end - if igi_actions.is_low_condition(entity.id, new_condition) then - get_object_by_id(entity.id):set_condition(new_condition) - t._done = true + return { + status = function (entity) + if entity._repair_done then return end + if igi_actions.is_low_condition(entity.id, new_condition) then + get_object_by_id(entity.id):set_condition(new_condition) + entity._repair_done = true + end end - end + } end