File size: 2,059 Bytes
b6a38d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
function Unit:RoamHyenaLead(group_range)
group_range = group_range or 10 * guim
self:SetBehavior("RoamHyenaLead")
local groups_map = self:GetGroupsMap()
local animals = MapGet(self, group_range, "Unit", function(unit)
return unit.species == self.species and not unit:IsDead() and self:GroupsMatch(unit, groups_map)
end)
table.shuffle(animals, InteractionRand(nil, "HyenaRoam"))
local avail_pos = self.routine_spawner:GetAreaPositions("ignore occupied")
if #avail_pos == 0 then
self:IdleRoutine_StandStill()
return
end
local packed_pos = avail_pos[1 + self:Random(#avail_pos)]
local pos = point(point_unpack(packed_pos))
local dests = GetUnitsDestinations(animals, pos)
for idx, animal in ipairs(animals) do
dests[animal] = dests[idx] or packed_pos
end
table.remove_entry(animals, self)
for _, animal in ipairs(animals) do
animal:SetCommand("RoamHyenaFollow", GetPassSlab(point(point_unpack(dests[animal]))) or pos, self)
end
self:GotoSlab(GetPassSlab(point(point_unpack(dests[self]))) or pos)
self:IdleRoutine_StandStill(2000, "don't halt")
local animals_finished = {}
while #animals_finished < #animals do
for _, animal in ipairs(animals) do
local finished = (animal.command == "RoamHyenaWait") or (not IsValid(animal) or animal:IsDead())
if finished and not animals_finished[animal] then
table.insert(animals_finished, animal)
animals_finished[animal] = true
end
end
WaitMsg("UnitGoTo", 300)
end
for _, animal in ipairs(animals_finished) do
animal:SetCommand("Idle")
end
end
function Unit:RoamHyenaFollow(pos, leader)
self:PushDestructor(function() self:SetBehavior() end)
self:SetBehavior("RoamHyenaFollow")
Sleep(self:Random(200))
self:GotoSlab(pos)
if IsValid(leader) and not leader:IsDead() then
self:SetCommand("RoamHyenaWait", leader)
end
self:PopAndCallDestructor()
end
function Unit:RoamHyenaWait()
self:PushDestructor(function() self:SetBehavior() end)
self:SetBehavior("RoamHyenaWait")
self:IdleRoutine_StandStill(2000, "don't halt")
self:PopAndCallDestructor()
end |