218 lines
6.0 KiB
Plaintext
218 lines
6.0 KiB
Plaintext
|
--[[
|
||
|
scheme_type: generic
|
||
|
author: Alundaio
|
||
|
--]]
|
||
|
--------------------------------------
|
||
|
actid = 188120
|
||
|
evaid = 188120
|
||
|
--------------------------------------
|
||
|
|
||
|
local is_box = {
|
||
|
--["dynamics\\box\\box_1a"] = false,
|
||
|
--["dynamics\\box\\box_1b"] = false,
|
||
|
--["dynamics\\box\\box_1c"] = false,
|
||
|
["dynamics\\box\\box_wood_01"] = false,
|
||
|
--["dynamics\\box\\box_wood_02"] = false
|
||
|
}
|
||
|
selected = {}
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
-- EVALUATOR NPC vs BOX
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
class "evaluator_npc_vs_box" (property_evaluator)
|
||
|
function evaluator_npc_vs_box:__init(npc,name,storage) super (nil, name)
|
||
|
self.st = storage
|
||
|
end
|
||
|
|
||
|
function evaluator_npc_vs_box:evaluate()
|
||
|
--utils_data.debug_write("eva_npc_vs_box")
|
||
|
local npc = self.object
|
||
|
|
||
|
if not (npc:alive()) then
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
if (IsWounded(npc)) then
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
if not (npc:active_item()) then
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
local ret = false
|
||
|
local itr = function(id)
|
||
|
if not (ret) then
|
||
|
local obj = id and db.storage[id] and db.storage[id].object
|
||
|
if (obj and is_box[obj:get_visual_name()] and obj:position():distance_to_sqr(npc:position()) < 2) then
|
||
|
ret = true
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
npc:iterate_feel_touch(itr)
|
||
|
|
||
|
return ret
|
||
|
end
|
||
|
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
-- ACTION NPC vs BOX
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
class "action_npc_vs_box" (action_base)
|
||
|
function action_npc_vs_box:__init (npc,name,storage) super (nil,name)
|
||
|
self.st = storage
|
||
|
end
|
||
|
function action_npc_vs_box:initialize()
|
||
|
action_base.initialize(self)
|
||
|
local npc = self.object
|
||
|
npc:set_desired_position()
|
||
|
npc:set_desired_direction()
|
||
|
local bw = self.object:best_weapon()
|
||
|
if (bw) then
|
||
|
self.object:set_item(object.aim1,bw)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function action_npc_vs_box:execute()
|
||
|
action_base.execute(self)
|
||
|
local obj
|
||
|
local itr = function(id)
|
||
|
if not (obj) then
|
||
|
local o = id and db.storage[id] and db.storage[id].object
|
||
|
if (o and is_box[o:get_visual_name()]) then
|
||
|
obj = o
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
self.object:iterate_feel_touch(itr)
|
||
|
|
||
|
if not (obj) then
|
||
|
return
|
||
|
end
|
||
|
|
||
|
self.st.__tmr = self.st.__tmr or time_global()+8000
|
||
|
if (time_global() > self.st.__tmr) then
|
||
|
alife_release_id(obj:id())
|
||
|
self.st.__tmr = nil
|
||
|
end
|
||
|
|
||
|
local pos = vector():set(obj:position())
|
||
|
pos.y = pos.y + 0.4
|
||
|
|
||
|
local st = db.storage[self.object:id()].state_mgr
|
||
|
self.object:clear_animations()
|
||
|
st:set_state("idle", nil, nil, nil, {fast_set = true})
|
||
|
st.animation:set_state(nil, true)
|
||
|
st.animation:set_control()
|
||
|
|
||
|
self.object:set_mental_state(anim.danger)
|
||
|
--self.object:set_body_state(move.crouch)
|
||
|
self.object:set_movement_type(move.stand)
|
||
|
self.object:set_sight(look.fire_point,pos)
|
||
|
local bw = self.object:best_weapon()
|
||
|
if (bw) then
|
||
|
if (self.object:is_body_turning()) then
|
||
|
self.object:set_item(object.aim1,bw)
|
||
|
else
|
||
|
self.object:set_item(object.fire1,bw,1,30)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function action_npc_vs_box:finalize()
|
||
|
action_base.finalize(self)
|
||
|
local bw = self.object:best_weapon()
|
||
|
if (bw) then
|
||
|
self.object:set_item(object.idle,bw)
|
||
|
end
|
||
|
self.st.__tmr = nil
|
||
|
self.object:set_sight(look.direction, self.object:direction() , 0)
|
||
|
self.object:set_desired_position()
|
||
|
self.object:set_desired_direction()
|
||
|
end
|
||
|
|
||
|
---------------------------------------------------------
|
||
|
---------------------- binder ---------------------------
|
||
|
function setup_generic_scheme(npc,ini,scheme,section,stype,temp)
|
||
|
local st = xr_logic.assign_storage_and_bind(npc,ini,"npc_vs_box",section,temp)
|
||
|
end
|
||
|
|
||
|
function add_to_binder(npc,ini,scheme,section,storage,temp)
|
||
|
if not npc then return end
|
||
|
local manager = npc:motivation_action_manager()
|
||
|
if not manager then return end
|
||
|
|
||
|
if (not npc:alive()) or (character_community(npc) == "zombied" or npc:section() == "actor_visual_stalker") then
|
||
|
manager:add_evaluator(evaid,property_evaluator_const(false))
|
||
|
temp.needs_configured = false
|
||
|
return
|
||
|
end
|
||
|
|
||
|
local evaluator = evaluator_npc_vs_box(npc,"eva_npc_vs_box",storage)
|
||
|
temp.action = action_npc_vs_box(npc,"act_npc_vs_box",storage)
|
||
|
|
||
|
if not evaluator or not temp.action then return end
|
||
|
manager:add_evaluator(evaid,evaluator)
|
||
|
|
||
|
temp.action:add_precondition(world_property(stalker_ids.property_alive,true))
|
||
|
temp.action:add_precondition(world_property(stalker_ids.property_danger, false))
|
||
|
temp.action:add_precondition(world_property(evaid,true))
|
||
|
|
||
|
temp.action:add_effect(world_property(evaid,false))
|
||
|
|
||
|
manager:add_action(actid,temp.action)
|
||
|
end
|
||
|
|
||
|
function configure_actions(npc,ini,scheme,section,stype,temp)
|
||
|
if not npc then return end
|
||
|
local manager = npc:motivation_action_manager()
|
||
|
if not manager or not temp.action then return end
|
||
|
|
||
|
--temp.action:add_precondition(world_property(xr_evaluators_id.state_mgr + 1,true))
|
||
|
temp.action:add_precondition(world_property(xr_evaluators_id.sidor_wounded_base,false))
|
||
|
temp.action:add_precondition(world_property(xr_evaluators_id.wounded_exist,false))
|
||
|
|
||
|
--[[
|
||
|
if (_G.schemes["rx_ff"]) then
|
||
|
temp.action:add_precondition(world_property(rx_ff.evaid,false))
|
||
|
end
|
||
|
--]]
|
||
|
|
||
|
if (_G.schemes["gl"]) then
|
||
|
temp.action:add_precondition(world_property(rx_gl.evid_gl_reload,false))
|
||
|
end
|
||
|
|
||
|
--[[
|
||
|
if (_G.schemes["facer"]) then
|
||
|
temp.action:add_precondition(world_property(xrs_facer.evid_facer,false))
|
||
|
temp.action:add_precondition(world_property(xrs_facer.evid_steal_up_facer,false))
|
||
|
end
|
||
|
--]]
|
||
|
|
||
|
local action
|
||
|
local p = {
|
||
|
stalker_ids.action_combat_planner,
|
||
|
--xr_actions_id.state_mgr + 1,
|
||
|
xr_actions_id.state_mgr + 2,
|
||
|
xr_actions_id.alife
|
||
|
}
|
||
|
|
||
|
for i=1,#p do
|
||
|
--printf("ACTION_ALIFE_ID(axr_npc_vs_box.configure_actions): " .. tostring(p[i]))
|
||
|
action = manager:action(p[i])
|
||
|
if (action) then
|
||
|
action:add_precondition(world_property(evaid,false))
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function disable_generic_scheme(npc,scheme,stype)
|
||
|
local st = db.storage[npc:id()][scheme]
|
||
|
if st then
|
||
|
st.enabled = false
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function npc_add_precondition(action)
|
||
|
if not action then return end
|
||
|
action:add_precondition(world_property(evaid,false))
|
||
|
end
|