View Single Post
Old 10-21-13, 08:39 AM   #10861
tscharlii
Watch
 
Join Date: Dec 2011
Posts: 26
Downloads: 17
Uploads: 0
Default

Quote:
Originally Posted by plj View Post
I can confirm the bugreport as a valid one. TDW used true bearing where he should have used relative bearing.
Good thing you asked in the other thread, how confident I am with the fix proposal. I looked at it again, and I think the code that selects the hydrophone contact to follow deserves even more reviewing.

TDWs original Code in HydrophoneFollowNearestContact(): (/data/Scripts/Stations/Hydrophone.py)
Code:
        for contact in contacts:
            if sub.HeadingDEGToContact( contact ) >= ( hydroangle - sweeprange ) and sub.HeadingDEGToContact( contact ) <= ( hydroangle + sweeprange ) and sub.RangeToContact( contact ) <= maxrange:
                if hydrocontact == None:
                    hydrocontact = contact
                else:
                    if sub.HeadingDEGToContact( contact ) <= sub.HeadingDEGToContact( hydrocontact ) and sub.RangeToContact( contact ) < sub.RangeToContact( hydrocontact ):
                        hydrocontact = contact
In my opinion it should read (Be careful, if you copy paste from here, the indentation has to be done using tabs, not spaces. Python is quite picky about this. Better download the mod below):
Code:
        for contact in contacts:
            if TDWUtils.GetContactHeading( sub.HeadingDEGToContact( contact ) - sub.HeadingDEG ) >= ( hydroangle - sweeprange ) and TDWUtils.GetContactHeading( sub.HeadingDEGToContact( contact ) - sub.HeadingDEG ) <= ( hydroangle + sweeprange ) and sub.RangeToContact( contact ) <= maxrange:
                if hydrocontact == None:
                    hydrocontact = contact
                else:
                    if sub.RangeToContact( contact ) < sub.RangeToContact( hydrocontact ):
                        hydrocontact = contact
The semantics of this is: Follow the nearest contact within maxrange on hydrophone needle bearing plus-minus sweeprange

The change in the second line ensures the code deals with bearings relative to the sub's course instead of true, north-aligned bearings.
The change in the sixth line ommits a bogus if-condition. Why only select the nearest contact, if it also happens to be at a lesser bearing than other contacts in that area, and otherwise follow a contact further away. The command is called "Hydrophone follow nearest contact", after all.

This fix is available as a mod, activate it via JSGME after TDWs NewUIs:
http://www.deguero.de/jel/Hydrophone..._0_To_7_5_0.7z
tscharlii is offline   Reply With Quote