Smart Artillery Wagons


Toggles auto-firing of artillery wagons when a circuit signal is received at a train stop.

Content
23 days ago
0.17 - 2.0
1.08K
Trains Combat Circuit network

b Artillery Signal interfering with Train Limit?

3 years ago
(updated 3 years ago)

I'm experiencing a weird behavior after adding the train limit function to my artillery outposts in Factorio 1.1.5:

I have supply boxes (for example turrets) hooked up to a circuit so the train limit is set to 1 if there is less than x of a certain item. This calls 1 train into the outpost, the train stays until there are a few seconds of inactivity, ie. the missing item has been unloaded and then the train leaves. I also enable the artillery signal with a similar circuitry (for example ammo), so the artillery only fires if the outpost can defend itself.

Separately, both of these functions work perfectly fine. As soon as I combine them, the following happens:

Take out item out of box to test. Train limit is increased to 1 and Train A moves to Outpost. Train A enters Outpost Station and the artillery is enabled. Now train A is not recognizing its reservation of the station anymore. It says "Destination full", but still wants to go to the outpost. Additionally, Train B from the Main base is now reserving the spot inside the outpost and is driving to it, but can't enter, because train A is physically inside the Outpost. Train A is also not being unloaded. It's as if as soon as it enters the station, it's being kicked out. My suspicion is that somehow, this "kick" is related to this mod and its signal check.

If I send train A back to main base manually, train B enters the outpost. Upon entering, the artillery is enabled AND I get the message: "Destination full". This means that train B is also being "kicked out" of its reservation and wants to enter the Outpost even though it's inside the Outpost station. However, since there are only 2 trains available and train A is on its way back to main base, the reservation "reverts back" to train B and it's properly unloaded.

I did a few tests to confirm that the issue has something to do with the Artillery signal:

  1. Remove the artillery signal from the outpost.
    Result: problem gone

  2. Keep artillery signal, but enable artillery with the signal in main base (instead of disabling it). So the artillery still gets a signal, but it's not one to change its state.
    Result: problem gone

  3. Do the test with an item that is also part of the artillery signal circuitry, ie ammo. This means that the artillery signal isn't present upon entering the station, but only gets send to the train once enough ammo has been unloaded.
    Result: problem appears as soon as the signal is sent. Now train A gives the purple warning "Destination fulL" as soon as the ammo is unloaded and it receives the signal to enable artillery. It still wants to go to the outpost, but can't. When actually, it could leave 15 seconds after the ammo has been unloaded. Also train B isn't called, because the train limit isn't set to 1 anymore, since the ammo has been refilled.

  4. Switch from enabling at Outpost and disabling at main base to disabling at Outpost and enabling at main base.
    Result: same error

  5. Set train B to manual mode.
    Result: Problem gone. It's the same as when the other train is on its way back to main base - it's not available to go to the Outpost, so it can't "steal" the reservation.

As soon as I can replicate this bug without this mod, I'm going to post a bug report on the Factorio forum. But so far I've only seen this happening if the artillery signal changes a train from manual to auto or from auto to manual.

3 years ago

Thanks for the detailed report. This isn't entirely unexpected. When they artillery are enabled and disabled, the mod actually has to delete the wagons, build new ones, and set the train back to auto. (Auto targeting is a prototype option for each entity that cannot be changed.) There's a space of time during that process where the outpost stop thinks it does not have a train but needs one, so Train B is dispatched. This might be a few ticks, or just part of a tick.

You might be able to time the two signals so that no new train is requested while the train is changing state. The trick would be to make sure Train A still stays at the outpost afterwards.

Have you tried disabling the outpost by the old "disable" condition, rather than setting train limit to zero?

I'm not sure there's actually any change to be made in the game's train dispatching code. This is kind of a weird case.

Can you share your save file so I can take a look?

3 years ago
(updated 3 years ago)

Have you tried disabling the outpost by the old "disable" condition, rather than setting train limit to zero?

Wait, I'm confused. If I disable the station, the artillery signal cannot be send to the train.
I'm going to test again with setting a constant train limit of 1 and disabling the station if there is no need for a train (but not if a train is present),

3 years ago

It's really complicated when you rebuild trains automatically. Normally, if a train arrives at a stop and waits for a circuit condition, it doesn't matter if the stop Disables. The train will keep waiting and keep receiving the circuit signal until it leaves. But if the train is set to manual and back to automatic while sitting at the stop, it won't be able to instantly repath to the now-disabled stop.

I think you may need to resort to having more than one physical stop at your outpost so that the train limit and artillery logic can be separated. I do this all the time when using Automatic Coupling System and other scheduling mods. If this doesn't make sense, it's probably easier for me to show than explain. If you link a save file I'll try modifying to see if I can make it work.

3 years ago
(updated 3 years ago)

News: it could be that you are seeing a symptom of this bug, where the train reservation did not properly account for trains being destroyed while driving to or waiting at a stop with a train limit set.
Will he worth testing again after it is fixed. https://forums.factorio.com/viewtopic.php?f=30&t=92761

3 years ago

OK, finally back at the game and testing 1.1 and the mod.

As you suggested, I have now separated the train and artillery logic. However, now I'm running into a related problem. Since you have experience building "double stations", maybe you can help?

This is my setup:
- Idea is still to have Artillery disabled between Main Base and Outposts and on the way back from Outposts to Main Base
- 3 Stations inside the Outpost
- Railway Signal within the outpost, Red signal indicating a train is inside the Outpost

Station A
- Train Limit set to 1
- Station A is enabled upon circuit condition (no ammo in box)
- Station A is disabled when train is present and when no circuit condition is met
- Train waits for 1s inactivity (after unloading)

Station B
- Station enables itself if signal within the outpost is red AND the outpost has enough ammo in the box - this should only occur if a train just finished unloading at Station A
- Artillery signal enables Artillery on train, if the Outpost has enough ammo and oil to defend itself
- Train waits 1s for inactivity (after firing the artillery)

Station C
- Station C is enabled on the same conditions as Station B
- Constant negative Artillery signal disables Artillery
- Train waits for 1s

So the idea is to call the train if something is missing and then make it move to the Artillery Enabler Station B, have it stay there until inactivity and then move to Artillery Disabler Station C. This setup works in principle as most of the time, the train inside the Outpost on Station A is the one "catching" the schedule to go to Station B and then C. However, this is far from perfect and sometimes other trains still in Main Base catch the schedule. Now a train might be waiting in front of the outpost to go to the Disabler Station, while the train inside the Outpost is still shooting on Station B. The second train now gets destroyed....

If you use "Double Stations", how do you make sure the correct train and only that train catches the schedule?

3 years ago

The problem appears to be that you disable the first station at the outpost bit not the others. When I use a setup like this, I only enable the secondary outpost stops when a train is occupying track inside the outpost.

Also for the first stop, you can try setting train limit to zero rather than disabling. That way, trains that already pathed to it can finish their trip and not stop halfway. And make sure there's enough space for one train to wait outside the outpost while another one exits, just in case. You can put that waiting spot a ways away if you need to avoid biters.

New response