1
Mods / Re: [0.96a] Automated Commands
« on: December 17, 2023, 01:13:52 AM »How difficult is it to implement a global CR and hull retreat order? I was looking at realistic combat file because they credited this mod for the auto retreat feature and the implementation seems trivial. I would like to add the global auto retreat to my game but I’m inexperienced with modding with this game and thus cant do it myself.
in one sense it is trivial (you implement it at the mod-level instead of the hullmod-level) and then each frame u get a list of ALL ships and have to test each ship firstly to determine if they are eligible for being tested (i.e. one of ur ships, currently deployed, not already issued an evac command, etc) and then apply the code that actually tests if it should evac.
what is not immediately obvious if you are not a programmer is that the game engine is ALREADY doing all of this to give ALL hullmods the ability to run their specific code on the relevant ships each frame ... and it only has to do it ONCE. Which is a LOT more efficient because it only needs to go through the list ONCE and it doesn't need to do any of the 'eligibility' testing that you needed to add above because the hullmod itself is proof of eligibility. Imagine if every hullmod tried to apply its effects globally instead of on a pre-marked basis (ships already marked by a hullmod) HUNDREDS of different mods will each run their own pieces of eligibility code (every single one of them testing if every single ship is a player owned ship, etc)
tl:dr
the correct way to implement this is instead of trying to globally apply the retreat property, apply the hullmod-is-automatically-outfitted property. There are currently (at least) 3 separate mods that use this but they are still a little bit hit and miss and also add some strange behaviors ... when this method of automatically applying is smoother and doesn't add additional strange behaviors i plan on asking the author for permission and using the method in my own mod.
Not only does this mean that you are not re-doing work the game engine already does but it also means that the 'global' code runs OUTSIDE of combat ... which is the most performance critical code of the game and the only code where slowdown is not only noticeable but game enjoyment braking.