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 63 64 65 66 67 68 69 70 71 72 73 74 75
|
-- An initial boot behaviour that takes over a unit initially,
-- makes it wait 3-4 seconds idle after it's been built, then
-- releases control
--
-- This helps prevent units in factories from immediatley building
-- things or doing stuff before they've left the factory and
-- blocking the factory from building the next unit
BootBehaviour = class(Behaviour)
local CMD_MOVE_STATE = 50
local MOVESTATE_HOLDPOS = 0
function BootBehaviour:Init()
self.waiting = true
self.id = self.unit:Internal():ID()
self.name = self.unit:Internal():Name()
self.finished = false
self.count = 150
self.unit:ElectBehaviour()
end
function BootBehaviour:UnitBuilt(unit)
if unit.engineID == self.unit.engineID then
self.finished = true
end
end
function BootBehaviour:Update()
if self.waiting == false then
return
end
if self.finished then
self.count = self.count - 1
if self.count < 1 then
self.waiting = false
self.unit:ElectBehaviour()
end
end
end
function BootBehaviour:Activate()
self.active = true
end
function BootBehaviour:Deactivate()
self.active = false
end
function BootBehaviour:Priority()
-- don't apply to starting units
if game:Frame() < 5 then
return 0
end
-- don't apply to structures
if self.unit:CanMove() == false then
return 0
end
if self.waiting then
return 500
else
return 0
end
end
-- set to hold position while being repaired after resurrect
function BootBehaviour:SetMoveState()
local thisUnit = self.unit
if thisUnit then
local floats = api.vectorFloat()
floats:push_back(MOVESTATE_HOLDPOS)
thisUnit:Internal():ExecuteCustomCommand(CMD_MOVE_STATE, floats)
end
end
|