Divergent/mods/Duty Expansion/gamedata/scripts/gameplay_duty_outpost.script

149 lines
4.2 KiB
Plaintext
Raw Permalink Normal View History

local HI = has_alife_info
local GI = give_info
local DI = disable_info
function NI(str)
return not (has_alife_info(str))
end
local storage_data = {}
function reinforce_squad(actor,obj,p)
local squad = p and p[1] and get_story_se_object(p[1])
local smart = squad and squad.smart_id and db.smart_terrain_by_id[squad.smart_id]
if not (squad and smart) then
return
end
local lst = ini_sys:r_string_ex(squad:section_name(),"npc_random")
lst = lst and parse_names(lst)
local str = ini_sys:r_string_ex(squad:section_name(),"npc_in_squad")
str = str and str_explode(str,",")
local num = str and (tonumber(str[2]) or tonumber(str[1]))
--printf("GhenTuong: refill_squad %s",squad:section_name())
if (lst and num) then
local n = tonumber(p[2]) or 1
for k=1,n do
if (squad:npc_count() < num) then
local sec = lst[math.random(#lst)]
local commander = alife_object(squad:commander_id())
if (sec and ini_sys:section_exist(sec) and commander) then
local pos = commander.position
local vid = commander.m_level_vertex_id
local gid = commander.m_game_vertex_id
local id = squad:add_squad_member(sec,pos,vid,gid)
local se = id and alife_object(id)
if (se) then
smart:register_npc(se)
SIMBOARD:setup_squad_and_group(se)
end
squad:update()
end
end
end
end
end
function clean_mess(actor,smart,p)
if (HI("duty_outpost_clean_mess")) then
return
end
local zone = db.zone_by_name["red_smart_terrain_bridge_surge_hide_a1"]
if (smart and zone) then
local section_list = {
["physic_destroyable_object"] = true,
["explosive_barrel_low"] = true,
["explosive_hide"] = true,
}
for id=1,65534 do
local se = alife():object(id)
if (se and section_list[se:section_name()] and simulation_objects.is_on_the_same_level(se,smart) and zone:inside(se.position)) then
safe_release_manager.release(se)
printf("Release [%s]",se:name())
end
end
GI("duty_outpost_clean_mess")
end
end
function play_sound(actor,obj,p)
if (p and p[1]) then
local snd = xr_sound.set_sound_play(obj:id(),p[1])
if (snd and tonumber(p[2]) and (snd.volume ~= tonumber(p[2]))) then
snd.volume = tonumber(p[2])
end
end
end
function level_is_red_forest()
return (level.name() == "l05_bar")
end
function npcs_friendly_to_community(npc_1,npc_2,com)
local com_1 = npc_1 and character_community(npc_1)
local com_2 = npc_2 and character_community(npc_2)
--printf("GhenTuong: %s %s %s %s %s",com_1,com_2,com,game_relations.is_factions_enemies(com_1,com),game_relations.is_factions_enemies(com_2,com))
if (com_1 and com_2 and (not game_relations.is_factions_enemies(com_1,com)) and (not game_relations.is_factions_enemies(com_2,com))) then
return true
end
return false
end
function npc_on_before_hit(npc,shit,bone_id,flags)
if not (HI("red_bridge_outpost") and level_is_red_forest()) then
return
end
if (storage_data.actor_crime) then
return
end
if (shit and shit.draftsman) then
if (shit.draftsman:id() == AC_ID) then
if (npcs_friendly_to_community(npc,shit.draftsman,"dolg")) then
storage_data.actor_crime = true
end
end
end
end
function on_enemy_eval(npc,ene,flags)
if not (HI("red_bridge_outpost") and level_is_red_forest()) then
return
end
if not (IsStalker(npc) and IsStalker(ene)) then
return
end
if (npcs_friendly_to_community(npc,ene,"dolg")) then
if (storage_data.actor_crime and (ene:id() == AC_ID)) then
return
end
flags.override = true
flags.result = false
end
end
function save_state(m_data)
m_data.gameplay_duty_outpost_storage_data = storage_data
end
function load_state(m_data)
storage_data = m_data.gameplay_duty_outpost_storage_data or {}
end
function on_level_changing()
storage_data.actor_crime = nil
end
--[[----------------------------------------------------------------------------------------------------
Registers
------------------------------------------------------------------------------------------------------]]
function on_game_start()
RegisterScriptCallback("save_state",save_state)
RegisterScriptCallback("load_state",load_state)
RegisterScriptCallback("on_level_changing",on_level_changing)
RegisterScriptCallback("npc_on_before_hit",npc_on_before_hit)
RegisterScriptCallback("on_enemy_eval",on_enemy_eval)
end