Your code, around line 30 of your control, assumes that any newly created force has a spawn position.
My mod https://mods.factorio.com/mod/Factorio-Tiberium makes a force that does not. And I imagine there are several others as well.
Before you go trying to use something's, well, anything, you should be checking that it exists first.
if turret.prepare_range then turret.prepare_range = turret.prepare_range*2 end
That checks for the existence of a turret's prepare_range, and then does stuff, if it exists.
If you need more than that, i can help.