Jump to content

spider_waterbrain didn't receive food searching optimizations that spiderbrain received


hoxi
  • Fixed

Also, something to keep in mind is that the order of these checks (from spiderbrain.lua) could be changed to further optimize things a bit more:

local function IsFoodValid(item, inst)
    return inst.components.eater:CanEat(item)
        and item:IsOnValidGround()
        and item:GetTimeAlive() > TUNING.SPIDER_EAT_DELAY
end

To:

local function IsFoodValid(item, inst)
    return item:GetTimeAlive() > TUNING.SPIDER_EAT_DELAY -- number comparison in lua
        and inst.components.eater:CanEat(item) -- potential multiple C calls for tags
        and item:IsOnValidGround() -- C call (probably expensive given it's map-related)
end

And another thing to keep in mind is that spider_waterbrain food searching could be further tweaked to not use IsOnValidGround and use something else instead, as those spiders can't even eat food on boats or floating on the ocean because of it, only on land. On the ocean they can only eat live fish swimming around through a separate action, but they could both be consolidated into a single food searching action that prioritizes ocean fish.

 

Also, more related to the eater component, both of these functions (or the component in general) could be optimized to use a single HasAnyTag call instead of multiple HasTag calls, which would be worth looking into:

function Eater:TestFood(food, testvalues)
    if food ~= nil and food.components.edible ~= nil then
        for i, v in ipairs(testvalues) do
            if type(v) == "table" then
                for i2, v2 in ipairs(v.types) do
                    if food:HasTag("edible_"..v2) then
                        return true
                    end
                end
            elseif food:HasTag("edible_"..v) then
                return true
            end
        end
    end
end

function Eater:PrefersToEat(food)
    if food.prefab == "winter_food4" and self.inst:HasTag("player") then
        --V2C: fruitcake hack. see how long this code stays untouched - _-"
        return false
    elseif self.nospoiledfood and (food.components.perishable and food.components.perishable:IsSpoiled()) then
        return false
    elseif self.preferseatingtags ~= nil then
        --V2C: now it has the warly hack for only eating prepared foods ;-D
        local preferred = false
        for i, v in ipairs(self.preferseatingtags) do
            if food:HasTag(v) then
                preferred = true
                break
            end
        end
        if not preferred then
            return false
        end
    end
    return self:TestFood(food, self.preferseating)
end

And regarding that fruitcake hack, you could give the fruitcake a unique tag to make it inedible by players and check for it here! Would work better for mod support too!


Steps to Reproduce

See above.




User Feedback


A developer has marked this issue as fixed. This means that the issue has been addressed in the current development build and will likely be in the next update.


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...