- green light when the drill is running
- yellow when it's idle because it cannot output the mined ore
- red light when the resource is depleted, or a burner drill is out of fuel
Code: Select all
if entity.mining_target == nil
Code: Select all
if entity.mining_target == nil
Unfortunately, neither of those would work. The problem is distinguishing between idle states. The drill remains "active", even when the resource is depleted, and it isn't drawing any power when it is output congested.aubergine18 wrote:Well, it will automatically stop functioning when depleted, so you could potentially check the .active state or it's .power_usage, etc?
The patch an entity is currently mining is given by entity.mining_target. This is nil, when the resource is depleted, but in some rare cases, it can also be nil if it has just depleted a single square, even though there are other resources around. This would normally be resolved on the next tick, but if the drill cannot offload its newly mined material, it might stay in this state for a while.aubergine18 wrote:Does the mining machine output any signals relating to quantity of resources it has remaining? If so those could be queried by script...?
That is exactly the "find_entities search" that I mentioned that I wanted to avoid...Ranakastrasz wrote:Well.....
The brute force solution, (also known as the worst solution) is that, assuming you can access the mining radius, is to just check the resource values of each tile it is in range of.
Expensive, naturally.
That doesn't distinguish between "red" and "yellow" states, as described above. It would simply say "isn't currently running". This is actually how I am currently distinguishing between "yellow" and "green".Klonan wrote:You could check the mining progress of the drill,
/c game.print(game.player.selected.mining_progress)
If you check over 2 ticks, and the value is the same, then you know that it cannot output (or that it has no power/ is disconnected)
Code: Select all
-- pseudo code
if state isn't already confirmed as red, yellow or green, then
if mining target is nil then
if search doesn't find ore then
set red state
That solution falls under the category of "weird special case" in my mod. It might be the right way to do it, but it actually both listens for on_resource_depleted, and does a find_entities search.anarchyinc wrote:You could check into "AutoDeconstruct" and see how he does it. Seems like both mods are trying to detect the same thing.