What is the concept behind UFO detection? Is it assumed each radar individually tries to detect it with its own chance? If so then this function seems to implement something different.
I understand it could be vanilla legacy. However, if logic was incorrectly implemented and is easy to fix, would it make sense to rewrite it?
UfoDetection Base::detect(const Ufo *target, const SavedGame *save, bool alreadyTracked) const
Things those seem off to me.
#1
Normal and hyperwave detection use different logic. Normal radars chances are added and their sum is used as a combined normal detection chance. Hyperwave radars chances are multiplied as it would correctly be when each of them has independent detection attempt.
#2
Not clear why detection chance for hyperwave is set to 100 when at least one of such radar passed the detection check?
What is detectionChance variable anyway? If this is resulting detection chance with all radars trying to detect UFO? If so, why it is hardcoded to 100 for hyperwave?
#3
Because of the above, parameters sent to the script is somewhat confusing. They could be only 100 for hyperwave but could be any number for normal.
#4
I didn't find radar chance is capped to 0-100 anywhere in the code. Should it be?
#5
The UFO visibility is additive. It could get as low as -50. Does it mean that very small UFO flying at the very low altitude won't ever be detected by say single small radar?
I am not telling anybody what to do. Just thinking what I would do if I need to program it. Can present change draft, of course, if anyone is interested.
- Compute normal and hyperwave detection chances separately by multiplying individual radar chances.
- Do two RNG rolls for normal and hyperwave detection chances. Either succeeding would detect UFO. Hyperwave succeeded would also uncover hyperwave info, obviously.
- Make UFO visibility modifiers multiplicative to avoid going out of 0 - 100 bound.
- Pass both parameters to script assuming the actual detection is not yet happened and script can change these values before detecting.