Tags: Circuit network, Electric network, Logistics network
Author: Kikkers
This mod is the successor to Smart Circuit Systems, with some functionality removed (because of obsoletion) or merged into other structures, and of course some new bits. As before, I'm hoping eventually all objects in this mod will be replaced with equivalent vanilla ones, but that might still take a while. Note that this mod actually consists of several smaller mods for purposes of maintainability. You can pick some and omit others, because there is no cross-dependency between them, but I recommend just picking all because you're probably going to use them together (at least until vanilla replacements are here).
Long Description
You will get access to 5 new items to place:
Directional Sensor
The Directional Sensor displays the contents of many types of objects it's pointing at, and it can be attached to the circuit network. The most obvious use is detecting the inventory contents of a target other than logistics or smart chests. A few other uses are showing the 'energy' stat of most objects in kiloJoules, which is the most logical for an accumulators' current charge. Many other objects show energy too, but this might not reflect the "energy" that you want to find, so I'd recommend experimenting with it. A few other uses, and a few things of note are as follows:
The inventory contents of trains are displayed as well, but only when the train is stationary.
The resources remaining of mining drills is shown, which includes pumpjacks showing the 'remaining' amount of fluid at the source as 'fluid units'.
Objects on belts can be detected, but only how many and on which side on the belt. I'm unsure if it's possible to find out what specific items are on the belt without interfering with them (sounds a bit like a hypothetical cat in a box).
When used with the pressure floor, more sensor options become available. See the description below on how to use it.
Includes a config file in which you can change some values related to update times. Useful for large factories.
Electric Switch
The Electric Switch is in essence a pair of electric poles that can toggle the copper wire connection between them (In SCS, red and green wires were also toggled, but due to changes in Factorio 0.12.x this is no longer possible). The input is any input signal that a smart inserter can work with. The Switch Interface is the middle of the structure, which is where you can attach red or green wires and set the switch's condition. The main use of the Electric Switch is to connect or disconnect extra power production or power hungry parts of a factory, a very powerful feature.
Directional Actuator
The Directional Actuator is capable of toggling objects that it is pointing at. What toggling means depends on the targeted object, but in most cases it will toggle between activating and deactivating the object. The input is again any input signal that a smart inserter can work with. This works on a number of structures, such as miners, assemblers, etc. A few special cases include:
Trains - Toggling manual mode, temporarily preventing them from continuing on their schedule.
Belts - Flipping their direction, making it possible to block or redirect the contents on the belt.
Gates - Makes a gate unresponsive to nearby movement, instead reacting exclusively to the actuator's input signal. This will require building the complete gate first, before attaching an actuator.
Micro Accumulator
The Micro Accumulator is essentially just a normal accumulator, only with a tiny capacity and a more rapid charge and discharge. Use this in combination with the directional sensor to detect, for example, when other accumulators in the network start or stop charging.
Pressure Floor
The Pressure Floor is a concrete-like variant of floor that has additional functionality when coupled with the Directional Sensor. When set up properly, it can detect objects moving or standing on it, along with their contents. A proper setup works as follows:
Place a square area of Pressure Floor. There is a maximum detection area of around 25x50 tiles, depending on Directional Sensor placement.
Place a Directional Sensor on the edge of the Pressure Floor area, pointing to one of the edge tiles. This edge tile MUST NOT have any other entity on it that the sensor might pick up on.
The area will be connected to the sensor, and the exact region is highlighted for a short moment.
One thing of note: As we don't have script events that involve tile placement or removal, I'm not actively checking if the pressure floor remains intact. Instead, I've opted to just allow the player to replace the floor after the sensor is placed, the sensor will remain functional for the area it was initially created with.
Finding the square area is determined as follows (complicated details for those interested):
The placement direction and target tile of the sensor are used as input.
Find the strip of continuous Pressure Floor tiles starting from the target tile, in the direction of the sensor.
More strips of equal will be added to both the left and right sides of the sensor, until no more strips of equal length can be found.
In effect, the above algorithm is guaranteed to find a square area, so you'd have the most control of the detecting area by always making it square.
Examples
Instead of more pictures, you could look at the example save file included in the download.
This list shows a number of specific uses for the items in this mod, some of which are demonstrated in the example save:
Remotely or automatically switch off parts of the factory (electric switch), depending on current accumulator charge (sensor on an accumulator)
Start backup power by connecting steam engines back on the network (electric switch), depending on accumulator charge (sensor on an accumulator)
Set a train schedule to wait at stations for 0 seconds, and instead only allow it to leave once it's full or empty (sensor on cargo wagons, actuator somewhere on the train, optionally some conventional combinators to determine the correct condition for the actuator)
Don't fill up a locomotive completely by checking how much fuel it has already (sensor on the locomotive)
Open and close gates only on a condition instead of a nearby player or train (actuator on a gate)
Close gates when a train is coming (actuator on a gate and a sensor a bit down the train tracks)
Flip the orientation of a belt (actuator on a belt or splitter, not sure if the splitter thing is in any way useful, but there you go) (idea from the Logic Belts mod)
Add robots to your network up to a customizable limit (since factorio 0.12.5 / mod 0.4.6, sensor on a roboport will show available and/or busy robots in a network. Smart inserter putting robots in the roboport will fix the rest.)
Disable or enable groups of turrets depending on if an attack is happening (something with sensors and laser turrets probably, maybe throw in a micro accumulator)
Changelog
0.4.9
Updated for the script change in the 0.12.12 patch
Attempt to prevent a game crash related to a missing x value
0.4.8
Oversight in function call that generated a nil error, now fixed thanks to jaguilar.
Added config file for the sensor.
0.4.7
Bugfix included from github user theit8514, where the sensor signal would not always clear properly
Sensor also shows the count of specific items on both sides of a belt, not just on which side.
0.4.6
Sensor compatibility bug with 0.12.5 resolved
Done away with using a smart chest for the sensor, replaced it with a constant combinator. This also made it possible to refactor some items into virtual-signal type objects. NOTE: this WILL break some red/green wire connections and conditions in migrating saves.
More information available when using a sensor on a roboport.
0.4.5
Had to re-add a proper migration script, i thought they worked different.
Shouldn't crash on special cases with fluidboxes, like those introduced with the rail tanker mod. Might still have some issues, but I'm unable to test that right now.
0.4.4
mining-drill type entities are now available as valid sensor targets.
Added fluid and heat units back in (from SCS) as a side effect of getting pumpjacks functional with the sensor.
Slight improvement in how functions are buffered across saves. They refresh on load now which prevents a few strange errors.
0.4.3
Another attempt on getting trains stopped properly by actuators.
Sensor now has a special behavior for the Micro Accumulator specifically, to allow for more reliability.
Sensor now detects biters and spitters through a pressure floor, like it should.
Added a save file to the repository showing some examples.
0.4.2
An attempt on getting trains stopped properly by actuators so inserters will work correctly while the train is in manualmode. They are apparently quite strict in their train speed sensing behavior.
0.4.1
Pressure floor added (see long description)
Changed vehicle detecting behavior for Directional Sensors, now shows the relevant type of vehicle always, and the contents as well when it's stationary.
0.4.0
first release (counting from the last version of Smart Circuit Systems)
If you find any bugs, have any suggestions, or know of any other interesting uses for the mod, you can leave them in this thread.
Some specific suggestions I'm actively looking for is entity type specific behaviors (for the actuator or sensor). As I've manually added behavior for some specific types, there might be some types I forgot about.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Thu Aug 13, 2015 6:15 pm
by Darloth
Is it possible for you to add a pressure pad, please?
Emits a (configurable) signal when an entity is on top of it, otherwise doesn't.
Entities would include players, biters and cars... maybe trains? not sure if that's possible. I wouldn't care either way about trains on pressure pads (we have other sensors for trains in here, yay) but some people might.
A mechanical switch (rightclick to toggle between emitting a signal or not) would also be useful, but probably more difficult, and I have no idea how you'd configure which signal it would emit.
Edit: Oh, oh - attaching a sensor to a mining drill should emit the amount and type of expected remaining resources!
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Thu Aug 13, 2015 6:58 pm
by GopherAtl
ooh, this sounds nice, I will have to play with these a bit later on.
re: pressure plates, definitely possible, did a simple proof-of-concept last night in the console. Hopefully someone else will make them soon - Too many mod ideas, not enough time XD - but if nobody beats me to it, I'll make my own eventually. Smart Mining Drill is definitely also doable and a good idea, I will add that to my candidate list as well if Kikkers' (or anyone else) doesn't do it first.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Thu Aug 13, 2015 7:41 pm
by Kikkers
Darloth wrote:... maybe trains?
Trains in motion can already be detected using the sensor btw, just place it pointing to the tracks.
Darloth wrote:A mechanical switch
Could be worth looking at the switch mod form 0.11.x, that'll probably still work with minor changes. I personally dislike its graphics, so I never used it.
Darloth wrote:Is it possible for you to add a pressure pad, please?
GopherAtl wrote:re: pressure plates, definitely possible
What size of pressure pad would be practical? Also, I think I'd prefer a perimeter sensor instead (with the same functionality), having a non-collidable entity seems cheaty to me.
Darloth wrote:Oh, oh - attaching a sensor to a mining drill should emit the amount and type of expected remaining resources!
I'm hoping there's a simple method to get this information from a mining drill type entity, as I don't feel that a piece of code that keeps track of individual pieces of ore is fun to write.
Thanks for the ideas guys. I think that the pressure pad or perimeter sensor seems like the most necessary addition, so I might look into that in the coming days.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Thu Aug 13, 2015 8:18 pm
by GopherAtl
Kikkers wrote:I'm hoping there's a simple method to get this information from a mining drill type entity, as I don't feel that a piece of code that keeps track of individual pieces of ore is fun to write.
Ooh, I didn't think that far into it, just poked one with a stick and if that info is available, I couldn't find it. Code wouldn't be too bad, though, and it wouldn't have to poll them too frequently, so shouldn't be a performance concern, either.
re: pressure plate, if you don't like it being non-collidable, just make it collide in the item layer, and occupy one tile. So you can't belt over it, or build most things over it, but you can walk/drive over it (and set it off). There's something to be said for both a pressure plate - which is visually distinct, and you know you're stepping on it - versus proximity detection, where it is less obvious. Both would have their uses.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Thu Aug 13, 2015 8:47 pm
by Kikkers
GopherAtl wrote:Ooh, I didn't think that far into it, just poked one with a stick and if that info is available, I couldn't find it. Code wouldn't be too bad, though, and it wouldn't have to poll them too frequently, so shouldn't be a performance concern, either.
Any idea if it's possible then to get the mining area used by the drill? Isn't that stored in the entity prototype?
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Thu Aug 13, 2015 9:00 pm
by GopherAtl
hmm. Probably not; easy enough to just guess with vanilla, though. If you were thinking of making a sensor object placed by the mine, you'd have to support any other mods' mines specifically. I was picturing it being a "smart mining drill" object that was directly circuit-connectable, which would also require specific support for other mods' drills, but that would kind of go without saying in that case.
:edit: I was derping there, just remembered, yes, you absolutely can access prototypes at run-time, some of my utility console functions do it. So a sensor-object version could pull the area from anything, if the area is indeed in the prototype (and if it's not, it's probably hard-coded and you can assume burner mine = 2x2, electric=5x5)
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Fri Aug 14, 2015 3:13 am
by therapist
THANK YOU!!!!!!!!!!
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Fri Aug 14, 2015 1:48 pm
by Kikkers
There, we have a pressure plate. Hopefully it doesn't produce critical bugs, but we'll see. Keep your autosave engaged just in case.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Fri Aug 14, 2015 5:58 pm
by Darloth
Thankyou!
That said, it doesn't seem to be in the linked zip, and I can't see it in your github repo anywhere. I'm assuming it's going to be its own micromod like the others, or in sensor, but I can't find it.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Fri Aug 14, 2015 9:08 pm
by Kikkers
Derp, forgot to push.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Sat Aug 15, 2015 12:18 pm
by Darloth
Actuator in the folder 4.2 has the info saying it's 4.0
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Sat Aug 15, 2015 12:22 pm
by Kikkers
I messed up again. It -should- work now...
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Sun Aug 16, 2015 1:02 pm
by Kikkers
GopherAtl wrote:hmm. Probably not; easy enough to just guess with vanilla, though. If you were thinking of making a sensor object placed by the mine, you'd have to support any other mods' mines specifically. I was picturing it being a "smart mining drill" object that was directly circuit-connectable, which would also require specific support for other mods' drills, but that would kind of go without saying in that case.
:edit: I was derping there, just remembered, yes, you absolutely can access prototypes at run-time, some of my utility console functions do it. So a sensor-object version could pull the area from anything, if the area is indeed in the prototype (and if it's not, it's probably hard-coded and you can assume burner mine = 2x2, electric=5x5)
I looked into this a bit. It seems that entity prototypes at runtime don't have all the information available that you can find in the prototype lua files. The value we would need for mining drills is the 'resource_searching_radius' field, which does not seem to be available at runtime. If that's the case, it's not currently possible to fetch remaining resources in the way that I would prefer (without hardcoding per specific mining drill object, including those added by other mods).
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Sun Aug 16, 2015 1:14 pm
by SirRichie
I have not tried this and do not know of the top of my head if this is possible, but here is an idea:
in data.lua (or its variants), you can walk through all mini drills and there you have access to the mining radius. You could build a lookup table there, which you store in a global variable (not sure if you have access to global in data.lua).
You could then use this lookup table in the control.lua part.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Sun Aug 16, 2015 1:17 pm
by Choumiko
Kikkers wrote:I looked into this a bit. It seems that entity prototypes at runtime don't have all the information available that you can find in the prototype lua files. The value we would need for mining drills is the 'resource_searching_radius' field, which does not seem to be available at runtime. If that's the case, it's not currently possible to fetch remaining resources in the way that I would prefer (without hardcoding per specific mining drill object, including those added by other mods).
You could work around that by using a data-final-fixes. Loop through all entites of type mining drill, for each one create a dummy recipe/item/technology/whatever (i believe technologies can be completely hidden ingame using .enabled = false). Set the name to that of the drill and a value that's readable at runtime to the searching radius. Ugly but it could work?
Edit: nearly ninja'd
SirRichie wrote:which you store in a global variable (not sure if you have access to global in data.lua)
There's no global in data.lua
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Sun Aug 16, 2015 7:52 pm
by Kikkers
Thanks for the ideas, this actually seems to work. I've added them to 4.4
The final solution was to store the resource_searching_radius in a dummy technology's time cost, which is actually accessible through a force's technology list as the research_unit_unergy field (multiplied by 60 due to ticks).
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Mon Aug 17, 2015 1:12 pm
by aklesey1
How to use pressure floor? and how to remove it?
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Mon Aug 17, 2015 4:56 pm
by Kikkers
aklesey1 wrote:How to use pressure floor? and how to remove it?
Did you have trouble under standing the "long description" in the top post? I might need to make that a bit clearer if you do.
Re: [MOD 0.12.x] Smarter Circuitry
Posted: Mon Aug 17, 2015 5:01 pm
by billw
Hey if this can detect number of robots in a roboport then it solves the issue of resupplying a limited number of construction bots to outposts and you are my hero.
I'm going to test tonight and report back, but if it doesn't then consider this a suggestion!