Can anyone tell me how can I know whether an entity (e.g. inserter) is currently enabled or disabled due to circuit condition in 0.13?
I have tried entity.active and entity.operable but obviously they are not for this purpose.
I have also checked the CircuitCondition class, but it doesn't tell whether the condition is fulfilled, like entity.get_circuit_condition(connector).fulfilled in 0.12. (Hey, did the devs forget to include this in the 0.13 modding changelog?)
Any help is appreciated.
Edit: Thanks to Choumiko, I am now able to detect whether an inserter entity is enabled/disabled, or just not affected by the network signals according to its operation mode. Here is the code:
Code: Select all
-- Returns whether the given inserter entity is enabled according to its circuit network state as well as its logistic network state.
function is_inserter_enabled(inserter)
local control = inserter.get_control_behavior()
-- Does it have control behaviour? (Not connected = no control?)
if control and control.valid then
-- Check logistic network.
-- Is logistic network connected?
if control.connect_to_logistic_network then
-- Has logistic condition set?
if control.logistic_condition then
-- Condition fulfilled?
if not control.logistic_condition.fulfilled then
return false
end
else
-- Connected but no condition, hence not OK.
return false
end
end
-- Check circuit network.
-- Is connected by wire?
if control.get_circuit_network(defines.wire_type.red, defines.circuit_connector_id.inserter) or control.get_circuit_network(defines.wire_type.green, defines.circuit_connector_id.inserter) then
-- Is operation mode enable/disable?
if control.circuit_mode_of_operation == defines.control_behavior.inserter.circuit_mode_of_operation.enable_disable then
-- Has the circuit condition set?
if control.circuit_condition then
-- Condition fulfilled?
if not control.circuit_condition.fulfilled then
return false
end
else
-- Connected but no condition, hence not OK.
return false
end
end
end
end
-- No control? Because not connected to network?
return true
end