Skip to content
Draft

4.3 #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions gamedata/scripts/igi_actions.script
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion gamedata/scripts/igi_generic_task.script
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ function quest_status(task_id)
local CACHE = get_cache(task_id)
---------------------------<ACTIONS>---------------------
igi_subtask.update_entities(CACHE)
igi_actions.update_actions(CACHE)
igi_subtask.process_subtasks(CACHE)
igi_callbacks.invoke_callbacks("on_task_update", CACHE)

Expand Down
6 changes: 6 additions & 0 deletions gamedata/scripts/igi_helper.script
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions gamedata/scripts/igi_subtask.script
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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
25 changes: 21 additions & 4 deletions gamedata/scripts/igi_taskdata.script
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions gamedata/scripts/igi_text_processor.script
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
94 changes: 94 additions & 0 deletions gamedata/scripts/wtf.script
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,97 @@ 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,

on_del = function (entity)
level.map_remove_object_spot(entity.id, mark)
end
}
end

ChangeFaction = function (faction)
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

Repair = function (new_condition)
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