add game&rawdata
This commit is contained in:
parent
0133cd976c
commit
49b34b5546
45731 changed files with 709831 additions and 0 deletions
574
gamedata/scripts/move_mgr.script
Normal file
574
gamedata/scripts/move_mgr.script
Normal file
|
|
@ -0,0 +1,574 @@
|
|||
function printf()
|
||||
end
|
||||
|
||||
local dist_walk = 10 -- < dist_run
|
||||
local dist_run = 2500
|
||||
|
||||
local walk_min_time = 3000
|
||||
local run_min_time = 2000
|
||||
|
||||
local keep_state_min_time = 1500 -- ïåðåêëþ÷èâøèñü â ñîñòîÿíèå (áåã, õîäüáà, ñïðèíò), íå ïåðåêëþ÷àòüñÿ â äðóãîå N ms
|
||||
|
||||
local default_wait_time = 10000
|
||||
local default_state_standing = "guard"
|
||||
local default_state_moving1 = "patrol"
|
||||
local default_state_moving2 = "patrol"
|
||||
local default_state_moving3 = "patrol"
|
||||
|
||||
arrival_before_rotation = 0
|
||||
arrival_after_rotation = 1
|
||||
|
||||
local state_none = 0
|
||||
local state_moving = 1
|
||||
local state_standing = 2
|
||||
|
||||
local sync = {}
|
||||
-------------------------------------------------------------------------------------------------------------------------
|
||||
function choose_look_point(patrol_look, path_look_info, search_for)
|
||||
local this_val -- çíà÷åíèå ôëàãîâ òåêóùåé òî÷êè
|
||||
local pts_found_total_weight = 0 -- êîëè÷åñòâî íàéäåííûõ òî÷åê (ñ íóæíûìè ôëàãàìè)
|
||||
local pt_chosen_idx = nil -- èíäåêñ âûáðàííîé òî÷êè
|
||||
local r
|
||||
local num_equal_pts = 0
|
||||
for look_idx = 0, patrol_look:count() - 1 do
|
||||
this_val = path_look_info[look_idx].flags
|
||||
if this_val:equal(search_for) then
|
||||
num_equal_pts = num_equal_pts + 1
|
||||
-- Íàøëè òî÷êó ñ íóæíûìè ôëàãàìè, íî ïîñêîëüêó â ïóòè ìîãóò áûòü åùå òàêèå-æå
|
||||
-- òî÷êè, âîçüìåì òåêóùóþ òîëüêî ñ íåêîòîðîé âåðîÿòíîñòüþ:
|
||||
-- Øàíñ, ñ êîòîðûì íà òî÷êó ïîñìîòðèò ïåðñîíàæ:
|
||||
local point_look_weight = path_look_info[look_idx]["p"]
|
||||
if point_look_weight then
|
||||
point_look_weight = tonumber(point_look_weight)
|
||||
else
|
||||
point_look_weight = 100 -- ïî óìîë÷àíèþ ó âñåõ òî÷åê âåñ = 100
|
||||
end
|
||||
pts_found_total_weight = pts_found_total_weight + point_look_weight
|
||||
r = math.random(1, pts_found_total_weight)
|
||||
if r <= point_look_weight then
|
||||
pt_chosen_idx = look_idx
|
||||
end
|
||||
end
|
||||
end
|
||||
return pt_chosen_idx, num_equal_pts
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------
|
||||
class "move_mgr"
|
||||
function move_mgr:__init(npc)
|
||||
if npc == nil then
|
||||
abort("move_mgr:__init() - npc is nil, please update the script")
|
||||
end
|
||||
self.object = npc
|
||||
end
|
||||
|
||||
function move_mgr:initialize(npc)
|
||||
if npc ~= nil then
|
||||
abort("Wrong arguments passed to move_mgr:initialize(), please update the script")
|
||||
end
|
||||
--printf("move_mgr:initialize()")
|
||||
|
||||
self.object:set_callback(callback.patrol_path_in_point, self.waypoint_callback, self)
|
||||
end
|
||||
--' Óäîñòîâåðÿåòñÿ, ÷òî ïóòè è ôëàæêè íà íèõ ïðîñòàâëåíû êîððåêòíî
|
||||
function move_mgr:validate_paths()
|
||||
if self.no_validation then
|
||||
return
|
||||
end
|
||||
local patrol_walk_count = self.patrol_walk:count()
|
||||
if patrol_walk_count == 1 then
|
||||
if self.path_walk_info[0].flags:get() == 0 then
|
||||
abort("object '%s': path_walk '%s' has 1 waypoint, but has no flags",
|
||||
self.object:name(), self.path_walk)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function move_mgr:extrapolate_callback(npc)
|
||||
self.can_use_get_current_point_index = true
|
||||
self.current_point_init_time = time_global()
|
||||
self.current_point_index = self.object:get_current_point_index()
|
||||
end
|
||||
|
||||
function move_mgr:standing_on_terminal_waypoint()
|
||||
for idx = 0, self.patrol_walk:count() - 1 do
|
||||
if utils.stalker_at_waypoint(self.object, self.patrol_walk, idx) and
|
||||
self.patrol_walk:terminal(idx) then
|
||||
return true, idx
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--' Ìîæåò áûòü âûçâàíî âíåøíèì ñêðèïòîì ïîñëå âûçîâà reset() è äî âûçîâà finalize()
|
||||
--' Âîçâðàùàåò true, åñëè ïåðñîíàæ ïðèáûë â êîíå÷íóþ òî÷êó ïóòè
|
||||
function move_mgr:at_terminal_waypoint()
|
||||
return self.at_terminal_waypoint_flag
|
||||
end
|
||||
|
||||
--' Èç move_cb âåðíóòü true, ÷òîáû ïðèîñòàíîâèòü ðàáîòó ñõåìû. ×òîáû ïðîäîëæèòü äâèæåíèå,
|
||||
--' íóæíî âûçâàòü ìåòîä set_movement_state, êîòîðûé âêëþ÷èò ïåðåìåùåíèå ïî âåéïîèíòàì ñ íóæíîé
|
||||
--' ñêîðîñòüþ.
|
||||
function move_mgr:reset(path_walk, path_walk_info, path_look, path_look_info, team, suggested_state, move_cb_info, no_validation, continue, use_default_sound)
|
||||
printf("move_mgr:reset() [%s]", self.object:name())
|
||||
|
||||
--' ñêîëüêî æäàòü â òî÷êå, ãäå èãðàåì àíèìàöèþ
|
||||
self.pt_wait_time = default_wait_time
|
||||
|
||||
--' Çàïîìèíàåì ìàññèâ öåëèêîì íà ñëó÷àé, åñëè ïðèäåòñÿ ñåáÿ ñáðîñèòü, ïîâòîðíî
|
||||
--' âûçâàâ reset():
|
||||
self.suggested_state = suggested_state
|
||||
--' Ïîñëå ýòîãî ðàñïàðñèâàåì ìàññèâ:
|
||||
if not suggested_state then
|
||||
self.default_state_standing = default_state_standing
|
||||
self.default_state_moving1 = default_state_moving1
|
||||
self.default_state_moving2 = default_state_moving2
|
||||
self.default_state_moving3 = default_state_moving3
|
||||
else
|
||||
self.default_state_standing = if_then_else(suggested_state.standing, suggested_state.standing, default_state_standing)
|
||||
self.default_state_moving1 = if_then_else(suggested_state.moving, suggested_state.moving, default_state_moving1)
|
||||
self.default_state_moving2 = if_then_else(suggested_state.moving, suggested_state.moving, default_state_moving2)
|
||||
self.default_state_moving3 = if_then_else(suggested_state.moving, suggested_state.moving, default_state_moving3)
|
||||
end
|
||||
|
||||
self.default_state_standing = xr_logic.parse_condlist(self.object, "move_mgr", "def_state", self.default_state_standing)
|
||||
self.default_state_moving1 = xr_logic.parse_condlist(self.object, "move_mgr", "def_state", self.default_state_moving1)
|
||||
self.default_state_moving2 = xr_logic.parse_condlist(self.object, "move_mgr", "def_state", self.default_state_moving2)
|
||||
self.default_state_moving3 = xr_logic.parse_condlist(self.object, "move_mgr", "def_state", self.default_state_moving3)
|
||||
|
||||
--' Ñ ìîìåíòà âêëþ÷åíèÿ ñõåìû äîëæíà ïðîéòè êàê ìèíèìóì ñåêóíäà, ïðåæäå ÷åì
|
||||
--' ïðîâåðÿòü ñîñòîÿíèå ñèíõðîíèçàöèè ñ äðóãèìè ñòàëêåðàìè (èíà÷å ïîñëå ëîàäà
|
||||
--' îíè ìîãóò íå óñïåòü çàñïàâíèòüñÿ).
|
||||
self.syn_signal_set_tm = time_global() + 1000
|
||||
self.syn_signal = nil
|
||||
|
||||
self.move_cb_info = move_cb_info
|
||||
|
||||
--' Âîçìîæíûå èçìåíåíèÿ
|
||||
--' Èçìåíèëàñü êîìàíäà
|
||||
if team ~= self.team then
|
||||
self.team = team
|
||||
if self.team then
|
||||
local s = sync[self.team]
|
||||
if not s then
|
||||
sync[self.team] = {}
|
||||
s = sync[self.team]
|
||||
end
|
||||
s[self.object:id()] = false -- not synchronized
|
||||
end
|
||||
end
|
||||
|
||||
--' Èçìåíèëèñü ïóòè
|
||||
if self.path_walk ~= path_walk or self.path_look ~= path_look then
|
||||
|
||||
self.no_validation = no_validation
|
||||
|
||||
self.path_walk = path_walk
|
||||
self.patrol_walk = patrol(path_walk)
|
||||
if not self.patrol_walk then
|
||||
abort("object '%s': unable to find path_walk '%s' on the map",
|
||||
self.object:name(), path_walk)
|
||||
end
|
||||
if not path_walk_info then
|
||||
abort("object '%s': path_walk ('%s') field was supplied, but path_walk_info field is nil",
|
||||
self.object:name(), path_walk)
|
||||
end
|
||||
self.path_walk_info = path_walk_info
|
||||
|
||||
if path_look then
|
||||
if not path_look_info then
|
||||
abort("object '%s': path_look ('%s') field was supplied, but path_look_info field is nil",
|
||||
self.object:name(), path_look)
|
||||
end
|
||||
self.patrol_look = patrol(path_look)
|
||||
if not self.patrol_look then
|
||||
abort("object '%s': unable to find path_look '%s' on the map",
|
||||
self.object:name(), path_look)
|
||||
end
|
||||
else
|
||||
self.patrol_look = nil
|
||||
end
|
||||
self.path_look = path_look
|
||||
self.path_look_info = path_look_info
|
||||
|
||||
--'self:validate_paths()
|
||||
|
||||
self.at_terminal_waypoint_flag = false
|
||||
|
||||
self.cur_state_standing = xr_logic.pick_section_from_condlist(db.actor, self.object, self.default_state_standing)
|
||||
self.cur_state_moving = xr_logic.pick_section_from_condlist(db.actor, self.object, self.default_state_moving1)
|
||||
|
||||
self.retval_after_rotation = nil
|
||||
self.sound_after_anim_start = nil
|
||||
|
||||
--' Ïîêà ýòîò ôëàã íå ñòàíåò true (îí áóäåò óñòàíîâëåí â extrapolate_callback), íåëüçÿ èñïîëüçîâàòü
|
||||
--' çíà÷åíèå, êîòîðîå âîçâðàùàåò get_current_point_index().
|
||||
self.can_use_get_current_point_index = false
|
||||
self.current_point_index = nil
|
||||
self.walk_until = time_global() + walk_min_time
|
||||
self.run_until = time_global() + walk_min_time + run_min_time
|
||||
self.keep_state_until = time_global()
|
||||
|
||||
|
||||
self.last_index = nil
|
||||
self.last_look_index = nil
|
||||
|
||||
self.use_default_sound = use_default_sound
|
||||
|
||||
self.object:patrol_path_make_inactual()
|
||||
end
|
||||
self:setup_movement_by_patrol_path()
|
||||
end
|
||||
|
||||
--' ïðîäîëæèòü äâèæåíèå ñî ñëåäóþùåé òî÷êè, à íå ñ áëèæàéøåé.
|
||||
--' ñîñòîÿíèå move manager-a íå ñáðàñûâàåòñÿ.
|
||||
function move_mgr:continue()
|
||||
printf("_bp: object '%s': continue moving", self.object:name())
|
||||
self:setup_movement_by_patrol_path()
|
||||
end
|
||||
|
||||
function move_mgr:setup_movement_by_patrol_path()
|
||||
self.object:set_path_type(game_object.patrol_path)
|
||||
self.object:set_detail_path_type(move.line)
|
||||
|
||||
if self.current_point_index then
|
||||
self.object:set_start_point(self.current_point_index)
|
||||
self.object:set_patrol_path(self.path_walk, patrol.next, patrol.continue, true)
|
||||
else
|
||||
self.object:set_patrol_path(self.path_walk, patrol.nearest, patrol.continue, true)
|
||||
end
|
||||
|
||||
self.state = state_moving
|
||||
|
||||
local is_term, idx = self:standing_on_terminal_waypoint()
|
||||
if is_term then
|
||||
printf("_bp: object '%s': TERMINAL WAYPOINT", self.object:name())
|
||||
-- Ñòîèì íà òåðìèíàëüíîé âåðøèíå ïóòè - ñðàçó èììèòèðîâàòü ïðèáûòèå
|
||||
self:waypoint_callback(self.object, nil, idx)
|
||||
else
|
||||
-- Ðåàëüíî èäåì â âåðøèíó
|
||||
self:update_movement_state()
|
||||
end
|
||||
|
||||
local sect = self.object:section()
|
||||
end
|
||||
|
||||
function move_mgr:arrived_to_first_waypoint()
|
||||
return self.last_index ~= nil
|
||||
end
|
||||
|
||||
|
||||
--' Ïðîâåðêà ñèíõðîíèçàöèè ñ îñòàëüíûìè ñîëäàòàìè íà ïóòè.
|
||||
--' Âîçâðàùàåò true, åñëè äàëüíåéøåå äâèæåíèå ðàçðåøåíî.
|
||||
function move_mgr:sync_ok()
|
||||
if self.team then
|
||||
local s = sync[self.team]
|
||||
local self_id = self.object:id()
|
||||
|
||||
for k, v in pairs(s) do
|
||||
local obj = level.object_by_id(k)
|
||||
if obj and obj:alive() then
|
||||
if v ~= true then
|
||||
return false
|
||||
end
|
||||
else
|
||||
sync[self.team][k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function move_mgr:update()
|
||||
--printf("move_mgr:update(self.state == %s)", utils.to_str(self.state))
|
||||
--printf("move_mgr:update(self.object:anims == %d)", self.object:animation_count())
|
||||
|
||||
if self.syn_signal and time_global() >= self.syn_signal_set_tm then
|
||||
if self:sync_ok() then
|
||||
self:scheme_set_signal(self.syn_signal)
|
||||
self.syn_signal = nil
|
||||
end
|
||||
end
|
||||
|
||||
if self.can_use_get_current_point_index and not self:arrived_to_first_waypoint() then
|
||||
local t = time_global()
|
||||
if t >= self.keep_state_until then
|
||||
self.keep_state_until = t + keep_state_min_time
|
||||
|
||||
local cur_pt = self.current_point_index
|
||||
-- self.patrol_walk çäåñü ïî èäåå òî æå ñàìîå, ÷òî âåðíåò patrol(self.object:patrol()),
|
||||
-- ïîýòîìó èñïîëüçóþ åãî äëÿ îïòèìèçàöèè.
|
||||
local dist = self.object:position():distance_to(self.patrol_walk:point(cur_pt))
|
||||
--printf("_bp: move_mgr: distance to destination waypoint: %d", dist)
|
||||
if dist <= dist_walk or t < self.walk_until then
|
||||
self.cur_state_moving = xr_logic.pick_section_from_condlist(db.actor, self.object, self.default_state_moving1)
|
||||
elseif dist <= dist_run or t < self.run_until then
|
||||
self.cur_state_moving = xr_logic.pick_section_from_condlist(db.actor, self.object, self.default_state_moving2)
|
||||
else
|
||||
self.cur_state_moving = xr_logic.pick_section_from_condlist(db.actor, self.object, self.default_state_moving3)
|
||||
end
|
||||
self:update_movement_state()
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
function move_mgr:set_current_state_moving(state)
|
||||
self.cur_state_moving = state
|
||||
self:update_movement_state()
|
||||
end
|
||||
|
||||
function move_mgr:finalize(npc)
|
||||
if self.team then
|
||||
sync[self.team][self.object:id()] = nil
|
||||
end
|
||||
-- ÷òîáû èçáåæàòü äàëüíåéøåãî äâèæåíèÿ ïî ïóòè ïðè óñòàíîâêå ðåñòðèêòîðîâ
|
||||
self.object:set_path_type(game_object.level_path)
|
||||
end
|
||||
|
||||
--'-----------------------------------------------------------------------------
|
||||
--' IMPLEMENTATION
|
||||
--'-----------------------------------------------------------------------------
|
||||
function move_mgr:update_movement_state()
|
||||
--printf("%s UPDATE movement state to %s", self.object:name(), self.cur_state_moving)
|
||||
state_mgr.set_state(self.object, self.cur_state_moving, nil, nil, nil)
|
||||
end
|
||||
|
||||
function move_mgr:update_standing_state(look_pos, snd)
|
||||
--printf("_bp [%s]: update_standing_state: snd='%s', pt_wait_time = %s path = %s", self.object:name(), utils.to_str(snd), utils.to_str(self.pt_wait_time), self.path_walk)
|
||||
state_mgr.set_state(self.object, self.cur_state_standing,
|
||||
{ obj = self, func = self.time_callback, turn_end_func = self.turn_end_callback },
|
||||
self.pt_wait_time,
|
||||
{ look_position = look_pos },
|
||||
nil,
|
||||
snd )
|
||||
end
|
||||
|
||||
function move_mgr:time_callback()
|
||||
--printf("_bp [%s]: time_callback", self.object:name())
|
||||
local sigtm = self.path_look_info[self.last_look_index]["sigtm"]
|
||||
if sigtm then
|
||||
self:scheme_set_signal(sigtm)
|
||||
end
|
||||
--' Åñëè íåò àêòèâíîé ñõåìû - èãíîðèðîâàòü.
|
||||
if db.storage[self.object:id()].active_scheme == nil then
|
||||
return
|
||||
end
|
||||
if self.last_index and self.patrol_walk:terminal(self.last_index) then
|
||||
if utils.stalker_at_waypoint(self.object, self.patrol_walk, self.last_index) then
|
||||
--' Åñëè ñòîèì íà êîíå÷íîé òî÷êå ïóòè è ñ íåå íèêóäà íå ñäâèíóëèñü,
|
||||
--' ñðàçó èììèòèðóåì callback íà ïðèáûòèå, ÷òîáû âêëþ÷èòü look.
|
||||
self:waypoint_callback(self.object, nil, self.last_index)
|
||||
return
|
||||
end
|
||||
--' Ñòîèì íà êîíå÷íîé òî÷êå ïóòè, íî íåòî÷íî. ×òîáû âåðíóòüñÿ íà áëèæàéøóþ
|
||||
--' òî÷êó ïóòè, ñáðàñûâàåì ñõåìó. Îáðàòèòå âíèìàèíå, ÷òî çäåñü íåëüçÿ
|
||||
--' ïðîñòî âûçâàòü update_movement_state, ïîòîìó ÷òî ìû ÓÆÅ áûëè â
|
||||
--' êîíå÷íîé òî÷êå ïóòè è äàëüøå èäòè íåêóäà, à reset_scheme ñáðîñèò
|
||||
--' íàñòðîéêè movement manager-à è âûáåðåò áëèæàéøóþ òî÷êó, êóäà è ïîéäåò.
|
||||
self:reset(self.path_walk, self.path_walk_info,
|
||||
self.path_look, self.path_look_info,
|
||||
self.team,
|
||||
self.suggested_state,
|
||||
self.move_cb_info,
|
||||
self.no_validation)
|
||||
else
|
||||
self:update_movement_state() -- èäòè äàëüøå
|
||||
local syn = self.path_look_info[self.last_look_index]["syn"]
|
||||
if syn then
|
||||
abort("object '%s': path_walk '%s': syn flag used on non-terminal waypoint",
|
||||
self.object:name(), self.path_walk)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function move_mgr:scheme_set_signal(sig)
|
||||
local npc_id = self.object:id()
|
||||
local stor = db.storage[npc_id]
|
||||
--printf("_bp: object '%s': move_mgr: scheme_set_signal '%s', active scheme '%s'",
|
||||
-- self.object:name(), sig, utils.to_str(stor.active_scheme))
|
||||
if stor ~= nil and stor[stor.active_scheme] ~= nil then
|
||||
local signals = stor[stor.active_scheme].signals
|
||||
if signals ~= nil then
|
||||
signals[sig] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function move_mgr:turn_end_callback()
|
||||
local syn = self.path_look_info[self.last_look_index]["syn"]
|
||||
if syn then
|
||||
self.syn_signal = self.path_look_info[self.last_look_index]["sig"]
|
||||
if not self.syn_signal then
|
||||
abort("object '%s': path_look '%s': syn flag uset without sig flag", self.object:name(), self.path_look)
|
||||
end
|
||||
|
||||
-- Îòìåòèòü, ÷òî ìû ñàìè óæå ïðèáûëè â òî÷êó ñèíõðîíèçàöèè:
|
||||
if self.team then
|
||||
sync[self.team][self.object:id()] = true
|
||||
end
|
||||
|
||||
else
|
||||
local sig = self.path_look_info[self.last_look_index]["sig"]
|
||||
if sig then
|
||||
self:scheme_set_signal(sig)
|
||||
else
|
||||
self:scheme_set_signal("turn_end")
|
||||
end
|
||||
end
|
||||
|
||||
local anim_synced_snd = nil
|
||||
if self.sound_after_anim_start then
|
||||
-- Ïðîèãðàòü çâóê ñðàçó ïîñëå îêîí÷àíèÿ ïîâîðîòà:
|
||||
anim_synced_snd = self.sound_after_anim_start
|
||||
self.sound_after_anim_start = nil
|
||||
end
|
||||
|
||||
if self.retval_after_rotation then
|
||||
if not self.move_cb_info then
|
||||
abort("object '%s': path_look '%s': ret flag is set, but " ..
|
||||
"callback function wasn't registered in move_mgr:reset()",
|
||||
self.object:name(), self.path_look)
|
||||
end
|
||||
--' Îòêëþ÷àåì òàéìåð ïóòåì óñòàíîâêè òîãî æå ñàìîãî ñîñòîÿíèÿ, íî áåç òàéìåðà,
|
||||
--' çàòåì âûçûâàåì callback.
|
||||
--' Åñëè callback âåðíóë false, ò.å. ðåøèë íå âìåøèâàòüñÿ â ïåðåìåùåíèå,
|
||||
--' òî âêëþ÷àåì îïÿòü òàéìåð.
|
||||
--' Åñëè callback âåðíóë true - íå âîññòàíàâëèâàåì òàéìåð ò.ê. ýòî ìîãëè ñäåëàòü â
|
||||
--' ñàìîì callback-å.
|
||||
|
||||
--' 1) Îòêëþ÷àåì òàéìåð
|
||||
state_mgr.set_state(self.object, self.cur_state_standing, nil, nil, nil)
|
||||
--' 2) Âûçûâàåì callback
|
||||
if not self.move_cb_info then
|
||||
abort("object '%s': path_look '%s': ret flag is set, but " ..
|
||||
"callback function wasn't registered in move_mgr:reset()",
|
||||
self.object:name(), self.path_look)
|
||||
end
|
||||
|
||||
if self.move_cb_info.func(self.move_cb_info.obj, this.arrival_after_rotation, self.retval_after_rotation, self.last_index)
|
||||
then
|
||||
--' Callback ðåøèë ïåðåõâàòèòü óïðàâëåíèå ïåðåìåùåíèåì, íå âîññòàíàâëèâàåì òàéìåð
|
||||
return
|
||||
end
|
||||
--' Callback íå ïåðåõâàòèë óïðàâëåíèå, íóæíî âîññòàíîâèòü òàéìåð:
|
||||
local look_pos = self.patrol_look:point(self.last_look_index)
|
||||
self:update_standing_state(look_pos, anim_synced_snd)
|
||||
end
|
||||
end
|
||||
|
||||
function move_mgr:waypoint_callback(obj, action_type, index)
|
||||
--printf("move_mgr:waypoint_callback(): name=%s, index=%d", self.object:name(), index)
|
||||
|
||||
if index == -1 or index == nil then
|
||||
--printf("ERROR: move_mgr: waypoint_callback: index is -1 or nil")
|
||||
return
|
||||
end
|
||||
|
||||
self.last_index = index
|
||||
|
||||
if self.patrol_walk:terminal(index) then
|
||||
self.at_terminal_waypoint_flag = true
|
||||
end
|
||||
|
||||
local suggested_state_moving = self.path_walk_info[index]["a"]
|
||||
if suggested_state_moving then
|
||||
self.cur_state_moving = xr_logic.pick_section_from_condlist(db.actor, self.object, suggested_state_moving)
|
||||
if tostring(self.cur_state_moving) == "true" then
|
||||
print_table(suggested_state_moving)
|
||||
abort("!!!!!")
|
||||
end
|
||||
else
|
||||
self.cur_state_moving = xr_logic.pick_section_from_condlist(db.actor, self.object, self.default_state_moving1)
|
||||
if tostring(self.cur_state_moving) == "true" then
|
||||
abort("!!!!!")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local retv = self.path_walk_info[index]["ret"]
|
||||
if retv then
|
||||
--printf("retv = %s", retv)
|
||||
local retv_num = tonumber(retv)
|
||||
|
||||
if not self.move_cb_info then
|
||||
abort("object '%s': path_walk '%s': ret flag is set, but " ..
|
||||
"callback function wasn't registered in move_mgr:reset()",
|
||||
self.object:name(), self.path_walk)
|
||||
end
|
||||
if self.move_cb_info.func(self.move_cb_info.obj, this.arrival_before_rotation, retv_num, index) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local sig = self.path_walk_info[index]["sig"]
|
||||
if sig then
|
||||
self:scheme_set_signal(sig)
|
||||
elseif index == #self.path_walk_info -1 then
|
||||
self:scheme_set_signal("path_end")
|
||||
end
|
||||
|
||||
local stop_probability = self.path_walk_info[index]["p"]
|
||||
|
||||
if not self.patrol_look or
|
||||
(stop_probability and tonumber(stop_probability) < math.random(1, 100)) then
|
||||
self:update_movement_state() --' èäòè äàëüøå
|
||||
return
|
||||
end
|
||||
|
||||
-- Çíà÷åíèå ôëàãîâ òî÷êè, êîòîðóþ áóäåì èñêàòü:
|
||||
local search_for = self.path_walk_info[index].flags
|
||||
|
||||
if search_for:get() == 0 then
|
||||
self:update_movement_state() --' èäòè äàëüøå
|
||||
return
|
||||
end
|
||||
|
||||
local pt_chosen_idx, num_equal_pts = choose_look_point(self.patrol_look, self.path_look_info, search_for)
|
||||
--printf("_bp [%s]: pt_chosen_idx = %s", self.object:name(), utils.to_str(pt_chosen_idx))
|
||||
if pt_chosen_idx then
|
||||
local suggested_anim_set = self.path_look_info[pt_chosen_idx]["a"]
|
||||
if suggested_anim_set then
|
||||
self.cur_state_standing = xr_logic.pick_section_from_condlist(db.actor, self.object, suggested_anim_set)
|
||||
else
|
||||
self.cur_state_standing = xr_logic.pick_section_from_condlist(db.actor, self.object, self.default_state_standing)
|
||||
end
|
||||
|
||||
local suggested_wait_time = self.path_look_info[pt_chosen_idx]["t"]
|
||||
if suggested_wait_time then
|
||||
if suggested_wait_time == '*' then
|
||||
self.pt_wait_time = nil -- -1
|
||||
else
|
||||
local tm = tonumber(suggested_wait_time)
|
||||
if tm ~= 0 and (tm < 1000 or tm > 45000) then
|
||||
abort("object '%s': path_look '%s': flag 't': incorrect time specified (* or number in interval [1000, 45000] is expected)",
|
||||
self.object:name(), self.path_look)
|
||||
end
|
||||
self.pt_wait_time = tm
|
||||
end
|
||||
else
|
||||
self.pt_wait_time = default_wait_time
|
||||
end
|
||||
|
||||
local retv = self.path_look_info[pt_chosen_idx]["ret"]
|
||||
if retv then
|
||||
self.retval_after_rotation = tonumber(retv)
|
||||
else
|
||||
self.retval_after_rotation = nil
|
||||
end
|
||||
|
||||
local look_pos = self.patrol_look:point(pt_chosen_idx)
|
||||
self.last_look_index = pt_chosen_idx
|
||||
self:update_standing_state(look_pos, self.sound_after_anim_start)
|
||||
|
||||
self.state = state_standing
|
||||
|
||||
--' Ñðàçó æå ñòàðòîâàòü update, íå æäàòü execute. Òîãäà, åñëè ìû óæå ñìîòðèì
|
||||
--' â íóæíóþ ñòîðîíó - íå áóäåò ïàóçû â íåñêîëüêî ìèëëèñåêóíä íà ïîâîðîò.
|
||||
self:update()
|
||||
else
|
||||
abort("object '%s': path_walk '%s', index %d: cannot find corresponding point(s) on path_look '%s'",
|
||||
self.object:name(), tostring(self.path_walk), tostring(index), tostring(self.path_look))
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue