brains/penguinbrain.lua
456789
require "behaviours/panic"
require "behaviours/standstill"
require "behaviours/attackwall"
local SEE_DIST = 30
local MIN_FOLLOW_DIST = 1
45678910
require "behaviours/panic"
require "behaviours/standstill"
require "behaviours/attackwall"
require "behaviours/leash"
local SEE_DIST = 30
local MIN_FOLLOW_DIST = 1
252627282930
local MIN_TIME_TILL_NEXT_DROP = 60
local PenguinBrain = Class(Brain, function(self, inst)
Brain._ctor(self, inst)
end)
262728293031323334
local MIN_TIME_TILL_NEXT_DROP = 60
local LEASH_RETURN_DIST = 5
local LEASH_MAX_DIST = 10
local PenguinBrain = Class(Brain, function(self, inst)
Brain._ctor(self, inst)
end)
111112113114115116117
not item.components.inventoryitem:IsHeld() and
item:IsOnValidGround() and
(item.HasTag == "penguin_egg" or item.prefab == "bird_egg") then
return char:GetDistanceSqToInst(item) <= TOOCLOSE*TOOCLOSE
end
end)
115116117118119120121
not item.components.inventoryitem:IsHeld() and
item:IsOnValidGround() and
(item.HasTag == "penguin_egg" or item.prefab == "bird_egg") then
return char:IsNear(item, TOOCLOSE)
end
end)
119120121122123124125
target = lst[math.random(1,#lst)]
end
end
if target and not target:IsInLimbo() and char:GetDistanceSqToInst(target) <= TOOCLOSE*TOOCLOSE then
dprint("===== Steal:",target)
if inst.components.knownlocations.ForgetLocation then
inst.components.knownlocations:ForgetLocation("myegg")
123124125126127128129
target = lst[math.random(1,#lst)]
end
end
if target and not target:IsInLimbo() and char:IsNear(target, TOOCLOSE) then
dprint("===== Steal:",target)
if inst.components.knownlocations.ForgetLocation then
inst.components.knownlocations:ForgetLocation("myegg")
131132133134135136137138139140141142143144145146147
end
local function MigrateAction(inst)
local homePos = inst.components.knownlocations.GetLocation and
(inst.components.knownlocations:GetLocation("rookery") or
inst.components.knownlocations:GetLocation("home"))
if homePos and
not inst.components.combat.target then
return BufferedAction(inst, nil, ACTIONS.WALKTO, nil, homePos)
end
end
local function EatFoodAction(inst)
local target = nil
135136137138139140141142143144145146147148149150
end
local function GetMigrateLeashPos(inst)
if inst.components.teamattacker.teamleader or inst.components.combat.target then
return nil
end
local homePos = inst.components.knownlocations and
(inst.components.knownlocations:GetLocation("rookery") or
inst.components.knownlocations:GetLocation("home"))
return homePos
end
local function EatFoodAction(inst)
local target = nil
185186187188189190191
local delay
local egg = CheckMyEgg(inst)
local nearest = GetClosestInstWithTag("scarytoprey", inst, TOOCLOSE) or GetPlayer()
if nearest:GetDistanceSqToInst(inst) <= TOOCLOSE*TOOCLOSE then
-- IOprint("\rTOO CLOSE")
return
end
188189190191192193194
local delay
local egg = CheckMyEgg(inst)
local nearest = GetClosestInstWithTag("scarytoprey", inst, TOOCLOSE) or GetPlayer()
if nearest:IsNear(inst, TOOCLOSE) then
-- IOprint("\rTOO CLOSE")
return
end
208209210211212213214
nearest = GetClosestInstWithTag("scarytoprey", inst, TOOCLOSE) or GetPlayer()
if PrepareForNight(inst) or not AtRookery(inst) or
nearest:GetDistanceSqToInst(inst) <= TOOCLOSE*TOOCLOSE then
return
end
211212213214215216217
nearest = GetClosestInstWithTag("scarytoprey", inst, TOOCLOSE) or GetPlayer()
if PrepareForNight(inst) or not AtRookery(inst) or
nearest:IsNear(inst, TOOCLOSE) then
return
end
232233234235236237238
if PrepareForNight(inst) or not AtRookery(inst) or
(GetSeasonManager():IsWinter() and GetSeasonManager():GetCurrentTemperature() <= -15) and
nearest:GetDistanceSqToInst(inst) <= TOOCLOSE*TOOCLOSE then
return
end
235236237238239240241
if PrepareForNight(inst) or not AtRookery(inst) or
(GetSeasonManager():IsWinter() and GetSeasonManager():GetCurrentTemperature() <= -15) and
nearest:IsNear(inst, TOOCLOSE) then
return
end
268269270271272273274
not item.components.inventoryitem:IsHeld() and
item:IsOnValidGround() and
(item.HasTag == "penguin_egg" or item.prefab == "bird_egg") then
return inst:GetDistanceSqToInst(item) <= 4
end
end)
271272273274275276277
not item.components.inventoryitem:IsHeld() and
item:IsOnValidGround() and
(item.HasTag == "penguin_egg" or item.prefab == "bird_egg") then
return inst:IsNear(item, 2)
end
end)
370371372373374375376377378379380
AttackWall(self.inst),
-- If not fighting or eating or protecting eggs, migrate to the rookery
WhileNode(function()
return not AtRookery(self.inst) and self.inst.components.teamattacker.teamleader == nil
end,
"Migrating ",
DoAction(self.inst, MigrateAction, "Migrating Action", false )),
-- When at the rookery, lay egg - but not if it's too cold!
WhileNode(function()
373374375376377378379
AttackWall(self.inst),
-- If not fighting or eating or protecting eggs, migrate to the rookery
Leash(self.inst, GetMigrateLeashPos, LEASH_MAX_DIST, LEASH_RETURN_DIST),
-- When at the rookery, lay egg - but not if it's too cold!
WhileNode(function()