Jump to content

penguinbrain issues


hoxi
  • Pending

Despite Pengulls and Moonrock Pengulls being intended to lay up to two eggs each:

local MAX_EGGS = 2  -- max number of eggs this penguin can lay

They're able to lay up to 3 due to a small oversight:

if not inst.nesting or (inst.eggsLayed and inst.eggsLayed > MAX_EGGS) then  -- egg laying season over
    return
end

The inst.eggsLayed > MAX_EGGS check should be using >= instead. The MAX_EGGS local could be changed to 3 to keep things as they were if desired.

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Another issue is that due to Moonrock Pengulls having the "scarytoprey" tag, and the brain file not being updated to account for this, they scare each other off constantly or think they're "egg stealers". This prevents them from nesting and doing most things properly.

This can be fixed by replacing the following function calls in the file:

GetClosestInstWithTag(SCARY_TAGS, inst, TOOCLOSE)

With:

FindClosestEntity(inst, TOOCLOSE, nil, SCARY_TAGS, SCARY_CANT_TAGS, nil, nil)

I moved SCARY_TAGS to the top of the file below the rest of the locals there and added SCARY_CANT_TAGS so they look like this.

local SCARY_TAGS = { "scarytoprey" }
local SCARY_CANT_TAGS = { "penguin" }

Given that both Pengulls and Moonrock Pengulls use the "penguin" tag to exclude combat targets (found in the penguin prefab), I think it makes sense to use it here too.

Then, the following line in PenguinBrain:OnStart():

RunAway(self.inst, "scarytoprey", SEE_PLAYER_DIST, STOP_RUN_DIST,

Should be changed to:

RunAway(self.inst, { tags = SCARY_TAGS, notags = RUN_AWAY_CANT_TAGS }, SEE_PLAYER_DIST, STOP_RUN_DIST,

With RUN_AWAY_CANT_TAGS being defined right above the OnStart function, as it's not needed for other functions. And it looks like this:

local RUN_AWAY_CANT_TAGS = { "penguin", "NOCLICK" } -- for consistency with the old code, since sending a string to RunAway uses NOCLICK for notags by default, this might be unnecessary though

If the "NOCLICK" tag isn't needed, then SCARY_CANT_TAGS could be used instead.

Anyhow, this would result in MoonRock Pengulls not fleeing from each other constantly and allow them to properly nest and lay (rotten) eggs and behave more similarly to Pengulls.

This would also technically allow Pengulls and Moonrock Pengulls to coexist with each other as well, but given that they currently wouldn't attack each other, I think that's fine?

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Lastly, both Pengulls and Moonrock Pengulls have some issues when it comes to egg laying and caretaking. They're not supposed to lay eggs if it's too cold, and they're supposed to pick up their eggs if it's too cold or if it's about to be night. However they don't do this due to a few oversights.

Shouldn't these nodes:

        -- When at the rookery, lay egg - but not if it's too cold!
        WhileNode(function()
                        return  AtRookery(self.inst) and
                                not self.inst.layingEgg and
                                not TheWorld.state.isnight and
                                self.inst.components.teamattacker.teamleader == nil
                        end,
                    "Laying Egg ",
                    DoAction(self.inst, LayEggAction, "Laying Egg Action", false )),


        -- Don't leave the egg lying around to freeze
        WhileNode(function()
                        return AtRookery(self.inst) and
                               self.inst.components.teamattacker.teamleader == nil and
                               not HasEgg(self.inst) and
                               (((TheWorld.state.iswinter and TheWorld.state.temperature <= -10))  or
                                PrepareForNight(self.inst))
                        end,
                    "PickUp Egg",
                    DoAction(self.inst, PickUpEggAction, "Pickup Egg", false )),

Look more like this?

        -- When at the rookery, lay egg - but not if it's too cold!
        WhileNode(function()
                        return  AtRookery(self.inst) and
                                self.inst.components.teamattacker.teamleader == nil and
                                not self.inst.layingEgg and
                                not PrepareForNight(self.inst) and
                                not (TheWorld.state.iswinter and TheWorld.state.temperature <= -15)
                        end,
                    "Laying Egg ",
                    DoAction(self.inst, LayEggAction, "Laying Egg Action", false )),


        -- Don't leave the egg lying around to freeze
        WhileNode(function()
                        return AtRookery(self.inst) and
                               self.inst.components.teamattacker.teamleader == nil and
                               not HasEgg(self.inst) and
                               ((TheWorld.state.iswinter and TheWorld.state.temperature <= -15) or
                                PrepareForNight(self.inst))
                        end,
                    "PickUp Egg",
                    DoAction(self.inst, PickUpEggAction, "Pickup Egg", false )),

(the -10 temperature check would result in weird behavior of laying an egg and then picking it up again due to differing temperature checks, so it needs to be the same value)

And these checks in the LayEggAction() function, for the scheduled egg laying tasks:

                                if PrepareForNight(inst) or not AtRookery(inst) or
                                (nearest and nearest:IsNear(inst, TOOCLOSE)) then
                                   return
                                end
                                if PrepareForNight(inst) or not AtRookery(inst) or
                                   (TheWorld.state.iswinter and TheWorld.state.temperature <= -15) and -- oversight here, this should be or
                                   (nearest and nearest:IsNear(inst, TOOCLOSE)) then
                                   return
                                end

Should both look more like this:

                                if PrepareForNight(inst) or not AtRookery(inst) or
                                   (TheWorld.state.iswinter and TheWorld.state.temperature <= -15) or
                                   (nearest and nearest:IsNear(inst, TOOCLOSE)) then
                                   return
                                end


Fixing all of these (as well as the scary tags issue when it comes to Moonrock Pengulls), will allow them all to lay eggs, unless it's too cold or it's about to be night, and make them pick them up in said conditions and not drop them again, as most of the code there implies they're supposed to.


I'm attaching a modified version of the file with these fixes in case that'd make it easier than reading all this.

penguinbrain.lua


Steps to Reproduce

For the max amount of eggs they can lay being 3 instead of the intended 2:

  1. Leave a single Pengull alive to make this test easier.
  2. Stay away and let them lay an egg.
  3. Put them to sleep and steal the egg.
  4. Repeat and count the amount of eggs.

For Moonrock Pengulls scaring each other constantly and being unable to nest and lay eggs properly:

  1. Don't get close and follow them around.
  2. Notice how whenever they get close to each other, they move away and are unable to lay eggs. It could happen if one is on their own for long enough though.
  3. Optionally, kill all but one and notice how they're now able to lay a (rotten) egg, if other usual conditions allow it of course.

For the egg laying conditions, not much to say really:

  1. You can play normally and check the world temperature and time of day through debug commands, and observe them without getting close.
  2. Notice how they can leave their eggs on the ground even when that's not supposed to be the case.



User Feedback


There are no comments to display.



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