Jump to content

Winbots don't teleport back to spawn (deploy) point after deactivating offscreen


hoxi
  • Fixed

This results in them being very unreliable to recharge when walking away, despite deploying them in range of a generator. The solution is to simply teleport them back a frame after they're considered offscreen:

local function DoSleepTeleport(inst)
	inst._offscreenteleporttask = nil

	-- check that we're still in a good state to teleport
	if inst._deployed
		and not inst:IsInLimbo()
		and not (inst.components.inventoryitem ~= nil and inst.components.inventoryitem:IsHeld())
	then
		local spawn_pt = StorageRobotCommon.GetSpawnPoint(inst)

		if spawn_pt ~= nil then
			if inst.Physics ~= nil then
				inst.Physics:Teleport(spawn_pt:Get())
			else
				inst.Transform:SetPosition(spawn_pt:Get())
			end
		end
	end
end

local function OnEntitySleep(inst)
	if inst._ledblinktask then
		inst._ledblinktasktime = GetTaskRemaining(inst._ledblinktask)
		inst._ledblinktask:Cancel()
		inst._ledblinktask = nil
	end
	if inst.brain then
		inst.brain:UnignoreItem()
	end
	StopWatchForReactivate(inst)
	if inst.sg and inst._offscreendeactivatetask == nil then
		inst._offscreenteleporttask = inst:DoTaskInTime(0, DoSleepTeleport) -- HERE, schedule teleport along with deactivation task
		inst._offscreendeactivatetask = inst:DoTaskInTime(OFFSCREEN_DEACTIVATE_DELAY, inst.OnDeactivateRobot)
	end
end

local function OnEntityWake(inst)
	if inst._ledblinktasktime then
		inst._ledblinktask = inst:DoTaskInTime(inst._ledblinktasktime, OnLedBlink)
		inst._ledblinktasktime = nil
	end
	if inst._offscreendeactivatetask then
		inst._offscreendeactivatetask:Cancel()
		inst._offscreendeactivatetask = nil
	end
	if inst._offscreenteleporttask ~= nil then -- HERE, cancel the task if we became awake in one frame before it went through
		inst._offscreenteleporttask:Cancel()
		inst._offscreenteleporttask = nil
	end
	TryWatchForReactivate(inst)
end

We want to wait 1 frame to avoid issues mentioned here.

There's also some powerload/circuit inconsistency issues with Winbot (and other devices) that I reported here a while ago, I updated the report just now with updated information and code.

 

Keep in mind that, if you do the teleport on calling inst.OnDeactivateRobot, you will have to account for the entity waking up right after teleporting and stop the code there, otherwise you might cause similar issues to Wobot mentioned in the first link.

Not only that, if the teleport happens after deactivating Winbot, you'd also have to force-disconnect from circuits and check for circuits again to be accurate to Winbot's position (and ensure the entity is still asleep), like this:

if inst:IsAsleep() then
	inst.components.circuitnode:Disconnect()
	inst.components.circuitnode:ConnectTo("engineeringbattery")
end

Teleporting a frame after going asleep with a task is both safe and prevents having to account for all this, as Winbot will be in the intended position and either go awake and act as usual without issues, or stay asleep, eventually deactivate in the right location, and connect to a circuit node (if there's one there).


Steps to Reproduce
  • Deploy a Winbot within a generator's range.
  • Place a container, and drop an item near the edge of Winbot's range.
  • Teleport or go away fast so that Winbot deactivates outside of the generator's range.
  • Notice that after Winbot deactivates 2 seconds after going offscreen, it will be wherever Winbot was, which potentially means no connection to the generator, which means not charging (well, this might depend on other issues mentioned here with links being fixed or not).
  • Like 2



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