![]() |
SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997 |
|
|||||||||
|
|
Thread Tools | Display Modes |
04-30-12, 09:00 PM
|
#11 |
|
Black Magic
![]() |
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. |
|
|
| Thread Tools | |
| Display Modes | |
|
|
