[1.1.76] mining time off by one tick sometimes

Bugs that we were not able to reproduce, and/or are waiting for more detailed info.
proicop
Inserter
Inserter
Posts: 20
Joined: Wed Jul 22, 2020 9:27 am
Contact:

[1.1.76] mining time off by one tick sometimes

Post by proicop »

Hello :D

I have noticed that when the character is mining an entity, it finishes mining one tick faster than when it should based on the `mining_speed` and `mining_time` but only for some combinations of `mining_speed` and `mine_time`.

I have measured some combinations of `mining_speed` and `mine_time` but failed to notice a pattern.

measurements: https://docs.google.com/spreadsheets/d/ ... sp=sharing

I suspect inaccurate float representation and then a round down at the end but I am not sure.

I know that this is probably only problem for me because I'm trying to predict the mine times so if it is not worth developer time to fix this It would be awesome if someone noticed the pattern when the mine action takes one tick less.

code used for measurements:

Code: Select all

local last = false
local start = 0

script.on_event(defines.events.on_tick, function()
	---@type LuaPlayer
	local player = game.players[1]

	local now = player.mining_state.mining
	if now ~= last then
		if now then -- started mining
			start = game.tick

			local prototype = player.selected.prototype
			local mining_time = prototype.mineable_properties.mining_time
			local player_prototype = game.entity_prototypes['character']
			local mining_speed = player_prototype.mining_speed
			local prediction = (mining_time / mining_speed) * 60

			game.print('prediction: ' .. prediction ..
				' mining_time: ' .. mining_time ..
				' mining_speed: ' .. mining_speed
			)
		else -- stopped mining
			game.print('actual time: ' .. (game.tick - start) - 1)
			-- minus one because on the current tick the entity is already gone
		end
	end
	last = now
end)
Thanks!
lyvgbfh
Fast Inserter
Fast Inserter
Posts: 170
Joined: Fri Jul 10, 2020 6:48 pm
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by lyvgbfh »

I can't access the document, is it set to private by any chance?
proicop
Inserter
Inserter
Posts: 20
Joined: Wed Jul 22, 2020 9:27 am
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by proicop »

lyvgbfh wrote: Fri Jan 27, 2023 9:50 am I can't access the document, is it set to private by any chance?
oops sorry. should work now
mmmPI
Smart Inserter
Smart Inserter
Posts: 3803
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by mmmPI »

sorry if this is obvious in the game code, but looking at the excel document i was wondering what is the unit of the mining time, 0.1 is 100 ms ?
and if the mining speed is in the same unit or if it has no unit in game ? is it a ratio, like 0.1*base speed or is it an amount like time for 1 ore ?

sometimes it happens that one is in second, the other in tick and it hides the pattern.
proicop
Inserter
Inserter
Posts: 20
Joined: Wed Jul 22, 2020 9:27 am
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by proicop »

mmmPI wrote: Fri Jan 27, 2023 4:57 pm sorry if this is obvious in the game code, but looking at the excel document i was wondering what is the unit of the mining time, 0.1 is 100 ms ?
and if the mining speed is in the same unit or if it has no unit in game ? is it a ratio, like 0.1*base speed or is it an amount like time for 1 ore ?

sometimes it happens that one is in second, the other in tick and it hides the pattern.
My interpretation of the documentation is that `mine_time` is the amount of 'enery' required to mine the entity and `mining_speed` is the amount of 'energy' produced by the character per second.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3803
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by mmmPI »

I think i was originally confused an thought about mining related to ore and not mining an entity despite it being written.

I found this formula on the wiki : (1 + Mining Speed Modifier) * .5 / Mining time = Production rate (in resource/sec)
which is expanded
(1 + Force Modifier) * (1 + Character Modifier) * (Character mining speed) / Mining time = Rate

https://wiki.factorio.com/Mining

and from the page of the steel axe, it says

" Steel axe (research) increases the player's mining speed by 100%, from 0.5 to 1.0. "

now when looking at the formula and your code i'm not sure where to plug what, i think you consider Mining Speed Modifier is default as 0 and you replace the 0.5 that is the pre-steel-axe-research default value by 0.1 0.2 0.3 every time in a different test, where in each test you mined a set of different entities with different mining_time 0.1 0.2 0.3 right ?

which in this case the expected result for the diagonal cell C3, D4, E5 ... in the doc is 1 per second, and a cross means it was only 59 ticks before the entity was mined ?
proicop
Inserter
Inserter
Posts: 20
Joined: Wed Jul 22, 2020 9:27 am
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by proicop »

mmmPI wrote: Mon Jan 30, 2023 11:15 pm now when looking at the formula and your code i'm not sure where to plug what, i think you consider Mining Speed Modifier is default as 0 and you replace the 0.5 that is the pre-steel-axe-research default value by 0.1 0.2 0.3 every time in a different test, where in each test you mined a set of different entities with different mining_time 0.1 0.2 0.3 right ?

which in this case the expected result for the diagonal cell C3, D4, E5 ... in the doc is 1 per second, and a cross means it was only 59 ticks before the entity was mined ?
You are exactly right.

I totally forgot about force and character modifiers but they are both zero by default so I don't think they affect the results in this case.

The extra modifiers would be plugged into the `local prediction = (mining_time / mining_speed) * 60` line.
mmmPI
Smart Inserter
Smart Inserter
Posts: 3803
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by mmmPI »

well now i'm sure i can't see the pattern if there is one.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14594
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by Rseding91 »

This is the Lua equivalent of the C++ mining code that runs:

Code: Select all

local player = game.player
local force = player.force
local character = player.character
local prototype = character.prototype
local modifier = (1 + force.manual_mining_speed_modifier) * (1 + character.character_mining_speed_modifier)

mining_progress = mining_progress + ((prototype.mining_speed / 60) * modifier)

if (mining_progress > target.prototype.mineable_properties.mining_time) then
  mining_progress = 0
  -- mine the entity
end
The only thing that sticks out to me is the ">" check should probably be ">="
If you want to get ahold of me I'm almost always on Discord.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14594
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.76] mining time off by one tick sometimes

Post by Rseding91 »

Does anyone have reproduction steps to show any kind of timing issue?
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Pending”