SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SH5 Mods Workshop
Forget password? Reset here

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 04-30-12, 09:00 PM   #11
TheDarkWraith
Black Magic
 
Join Date: Jun 2007
Posts: 11,959
Downloads: 147
Uploads: 5


Default

Today I finally narrowed down the routine that checks the torpedo impact angle when it collides with an object. I have to say my first reaction to the code was a huge WTF? I'm still trying to digest and figure out what the hell they were thinking. There's a lot of multiplication of fractions into the result that I can't for the life of me figure out why. It should be a simple test of:

for all min and max angles defined:
if max angle < torp impact angle < min angle then get random value. If random value < dud % chance torp is dud

But no, they have this complicated mess of multiplications and taking the cos value of something I have to try and figure out what this mess means.

For testing I set the dud % chance to 100% in the torpedo sim file for every angles defined. That way I know for sure I should have a dud on impact. But stepping through the debugger I always see the code say no dud So for fun I changed the code so that every torpedo impact was a dud. This is interesting: instead of 'dying' and sinking to the bottom it kept bouncing on the side of the ship until it could get by and then just kept going. I got the message that torpedo was a dud also. Not quite sure what to make of that

Maybe you all can help me figure this out:

So game says collision imminent! Code jumps to routine that checks for impact. Impact detected. Now it checks torpedo impact angle:

first thing it does is appears to store the torpedo impact angle on the floating point stack (-0.9527535438537597656 in this case)
next it stores 0.0174532923847436905 on the floating point stack (does this constant mean anything to anyone?)
then it loads the max angle allowed to the floating point stack (90.0 in this case)
then it multiplies these two values together (0.0174532923847436905 X 90.0). Why? Is this trying to convert to radians?
the result of that multiplication is 1.5707963146269321440 (looks like a radian value)
then it takes the COS of that value
result of that is 1.2167964475064260060E-08
then it swaps the torpedo impact angle ST2 (-0.9527535438537597656) with the result ST0 (1.2167964475064260060E-08) so that the torpedo impact angle is at top of floating point stack (result resides in ST2, torpedo impact angle in ST0)
then a floating point compare is performed of ST2 (1.2167964475064260060E-08) against the stack top ST0 (-0.9527535438537597656) and stores the results in the Integer FLAGS (EFLAGS) register
then ST2 is popped from the floating point stack
then if result of compare is below (CF=1 of EFLAGS register) then it increments a counter and loads pointers to the next set of angles. I see a problem here: the other angle of the set is never checked. The only time the second angle (which would be the min angle) is checked is if the floating compare is above (CF=0). Then if the result of that second angle is not below (CF=0) then jump to calculate dud % chance else torp explodes.

As you can see this will always jump to torpedo impact! Something is wacky here and I'm just not seeing it...

It needs to be coded so that it's checking the min and max angles before jumping to next set of angles. This way if the torp angle falls within the min and max angles then the dud % chance can be calculated. With the code as it is it never even checks the dud % chance thus we never get any duds

Last edited by TheDarkWraith; 04-30-12 at 09:52 PM.
TheDarkWraith is offline   Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 1995- 2026 Subsim®
"Subsim" is a registered trademark, all rights reserved.