Jump to content

Varglets don't properly set their hound spawn limit on load


hoxi
  • Pending

Varglets are intended to summon a maximum of 3 hounds, after they do so, they can't summon any more hounds. This means in general, not that they can only have 3 follower hounds at a time.

The value that tracks this and limits the amount of hounds to spawn works fine and is saved properly, but there's a check used on preload that prevents the saved value from applying, allowing them to spawn more after saving and loading.

local function OnPreLoad(inst, data)--, newents)
    if data ~= nil and data.reanimated then
        inst.max_hound_spawns = data.max_hound_spawns
    end
end

The reanimated flag is never set (it seems to be from the Clay Varg).

Simply removing it will fix it, though I do have a small suggestion, with the following function:

local TARGETS_MUST_TAGS = {"player"}
local TARGETS_CANT_TAGS = {"playerghost"}
local function NumHoundsToSpawn(inst)
    local numHounds = inst.base_hound_num 

    local pt = Vector3(inst.Transform:GetWorldPosition())
    local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, TARGETS_MUST_TAGS, TARGETS_CANT_TAGS)
    for i,player in ipairs(ents) do
        local playerAge = player.components.age:GetAgeInDays()
        local addHounds = math.clamp(Lerp(1, 4, playerAge/100), 1, 4)
        if inst.spawn_fewer_hounds then
            addHounds = math.ceil(addHounds/2)
        end
        numHounds = numHounds + addHounds
    end
    local numFollowers = inst.components.leader:CountFollowers()
    local num = math.min(numFollowers+numHounds/2, numHounds) -- only spawn half the hounds per howl
    num = (math.log(num)/0.4)+1 -- 0.4 is approx log(1.5)

    num = RoundToNearest(num, 1)

    if inst.max_hound_spawns then
        num = math.min(num,inst.max_hound_spawns)
    end

    return num - numFollowers
end

Given how this function can be called often and from multiple places (for both warg and warglet, so check both, since they both have their own private function), wouldn't it be ideal to perform a check with max_hound_spawns at the top of the function?

local function NumHoundsToSpawn(inst)
    if inst.max_hound_spawns and inst.max_hound_spawns <= 0 then
        return 0
    end

    --rest of the function

This would skip both the entity finding operation and all the calculations if not needed, as max_hound_spawns will set the results to 0 or negatives anyway with how it works currently.


Steps to Reproduce
  1. Spawn a Varglet, naturally or through the console.
  2. Wait until it has spawned 3 hounds. Kill them as they arrive (as the number of followers can prevent the Varglet from summoning more).
  3. Notice how the Varglet won't howl anymore and is unable to spawn any more hounds.
  4. End the session and start it again.
  5. Notice how the Varglet is now able to summon more hounds, up to the usual limit of 3.
  6. Repeat steps from point 2 to keep reproducing if needed.
  • Like 1



User Feedback




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...