Perhabs it's time to turn these transports into Q-Ships.
This could be an amusing idea for the Black Lance, actually. TBH, at some point, I worked on the Zartoth EW variant of the Vaktoth, featured in Saga. The idea was that it could have built "subsystems" that would look like transports or capital ships to the enemy to mess with them. Never got it to work, though. I'd have to try it again with what I know now. To make for a good ambush ship, you would need to get a reinforced convoy mechanic, IMO, for juicy targets to appear.
Now, on to the CTD bug, it feels nastier than I initially thought. I tried getting between every instruction of the code creating the missiles, decoys and managing them a "print" instruction so I could see at precisely which point of the logic chain the whole thing broke down. The result is that it doesn't break
within a script but right after a decoy management script. And all of this with varying numbers of missiles and decoys sent, so it's not a hard number. But at the same time, it
does occur when the shipID, the single identifier for the ships and ship-missiles that I use to track stats such as missile fuel or decoy battery, is around 3,000. So it might be some addressing issue, particularly as I use the shipID value as a reference for the big data table. I will have to try and check whether modifying the way I reference the shipID helps in any way.
It really seems to be a tricky thing, and I honestly doubt anyone in the modding community faced it before, given that I'm getting on entirely new grounds for the game with this.
(sorry for bothering you all with the debug quest, but I find that it helps a lot describing the issues, and maybe getting some alternate points of view)
EDIT: stranger and stranger. I started a game with 150 (!) Arrow for me and a bot, pushing the shipID way over 5,000 (no, I won't make the "it's over nine thousand!" joke, so sue me), and it worked fine, except for some expected lag as everything updated.
The good news is that it isn't some sort of hard limit for the addressing (which would have been a complete disaster, as you can imagine), but the obviously bad news is that I am no closer to finding the source of the CTD.
EDIT 2: I went into slideshow battle mode, with all these squadrons fighting and dropping decoys at once, and it crashed way later than I expected, after dropping literally nine times more decoys and missiles than in all previous crashes, with the shipID for these missiles and decoys reaching 17,500. This means the shipID hypothesis must be scratched entirely, as there is no relation whatsoever between the number of weapons/decoys deployed, the identification number of these and the crash.
I need more coffee.
Bonus shot:
The triangles are fighters, the inverted Y are missiles or decoys. The decoy code was activated a bit more than 4,000 times before the crash, and there were, within these 15 seconds or so, around one thousand missiles and decoys flying around. If I can find and fix the issue causing the CTD, I bet you can imagine the kind of things that could be done with a more modern computer.
EDIT: well, crap. I'm currently at a loss trying to understand what is going wrong. Deactivating the decoys didn't remove the CTD, and it seems to happen between the execution of ships' scripts, with no clear pattern to identify.
EDIT 2: I located another issue linked to how the missile/torpedo script considers its targets if you select a
group of targets. It also influences decoy drop as all fighters of the group will "feel" attacked if a missile is sent at any of them. Worse, if the group selected contains, say, 50 Arrow and 1 Frigate, it will be valid for torpedo targeting and the torpedo will likely be sent at an Arrow. I'll edit the code to reduce the targeted group to a single craft and see how it works out; with a bit of luck, it will eliminate the issue altogether as well as the CTD bug.
EDIT 3: I rewrote the missile code as well as increased the time between code updates. It
seems to have done the trick. Honestly, I have no clue what happened. I'll do the same things for decoys and keep my fingers crossed.
EDIT 4: false hope, people. The stress test makes the game crash as usual. I will have to see if there is a stability limit under which the game can still run reliably.