View Single Post
Old 08-11-06, 08:15 AM   #710
LoBlo
Subsim Diehard
 
Join Date: May 2006
Location: Texas!
Posts: 971
Downloads: 78
Uploads: 3
Default

Hi Luftwolf and Amizaur.

When playing through some self-made scenarios I've constantly noticed that subs are always avoiding torpedoes to the left and never right. I think its coded into their SubAvoidWep to evade left.

I've taken the liberty to randomize the torp evasion route a bit in the hope it provides less predictability.

Here are the changes that I've made to the SubAvoidWep Doctrine highlighted in orange. I think you'll like them.

__________________________________________________ ______________
; $Header: SubAvoidWeap.txt Thu Dec 30 16:55:05 EST 2004 mike $
; $Revision: 5 $
; $Copyrt1: Copyright (c) 2003, Sonalysts, Inc. All rights reserved. $
;
; SubAvoidWeap, modified by Amizaur, feet/meters miscalculation corrected
; AI behaviour when evading torpedo still needs improvements to avoid cavitation
; if torp below layer sub could run 5kts above layer and drop CMs, not run full speed cavitating
; Additional edits by LuftWolf, sub always drops active decoy and evades at 100-140 degrees
; Slight increase in recognition delay and decrease in max tgt evasion range
; Modded by LoBlo 8/6/2006 to randomize evasion routes a bit more.
var PreventingSnorkel
var PreventingComms
var LegTimer
var RecognitionDelay
var Snapshot
var LegCourse
var jammerIdx
var decoyIdx
var AvoidLeft
IF Init THEN {
PreventingSnorkel = false
PreventingComms = false
RecognitionDelay = ( Time + 15 + rnd 15 )
LegTimer = -1
Snapshot = false
jammerIdx = DBIdxFromRecNum 1414
decoyIdx = DBIdxFromRecNum 1412
If rnd 100 > 50 THEN {
AvoidLeft = True
DebugOut "Evading to the left"
} Else {
AvoidLeft = False
DebugOut "Evading to the right"
} ENDIF

} ELSEIF LegTimer == -1 THEN {
IF Time > RecognitionDelay THEN {
IF ( TgtRng < 12000 ) AND ( TgtSilos < 0 ) AND ( abs RelativeBearing TgtCrs ( TgtBrg + 180 mod 360 ) < 30 ) THEN {
DEBUGOUT "Sub Evading Torpedo!"
IF Not Snapshot THEN {
DEBUGOUT "Firing Back!"
FIREBEST
Snapshot = true
} ENDIF
IF NOT PreventingSnorkel THEN {
PreventingSnorkel = true
SetEntVar "TooBusyToSnorkel" ( GetEntVar "TooBusyToSnorkel" + 1 )
} ENDIF
IF NOT PreventingComms THEN {
PreventingComms = true
SetEntVar "TooBusyForComms" ( GetEntVar "TooBusyForComms" + 1 )
} ENDIF
LegTimer = ( 180 + RND 180 )
SetPriority 255
SetSpd MaxSpd
; LW Edit to 100 to 140
If AvoidLeft THEN {
LegCourse = ( TgtBrg + 100 + rnd 40 mod 360 )
} ELSE {
LegCourse = ( TgtBrg - 100 - rnd 40 mod 360 )
} ENDIF

; Set Depth Opposite Layer
IF TgtAlt < LAYER THEN {
SETALT ( -600 - RND 50 )
} ELSE {
SETALT ( LAYER - 400 )
; set depth to 400 ft below layer
} ENDIF
; Setalt ( ( MinAlt / 0.3048 ) + 100 )
; DebugOut "MinAlt + 100 feet set"
; Throw CM?
IF RND 10 > 0 THEN {
; Decoy or Jammer?
IF ( TgtSource $= "Active Intercept" ) OR ( rnd 100 > 65 ) THEN {
DEBUGOUT "CM Decoy"
CountermeasureIdx decoyIdx
} ELSE {
DEBUGOUT "CM Decoy II"
; LW always drop active CM
CountermeasureIdx decoyIdx
} ENDIF
} ELSE {
DEBUGOUT "Decoy failed random draw."
} ENDIF
LegTimer += Time
} ELSE {
IF PreventingSnorkel THEN {
PreventingSnorkel = false
SetEntVar "TooBusyToSnorkel" ( GetEntVar "TooBusyToSnorkel" - 1 )
} ENDIF
IF PreventingComms THEN {
PreventingComms = false
SetEntVar "TooBusyForComms" ( GetEntVar "TooBusyForComms" - 1 )
} ENDIF
} ENDIF
} ENDIF
} ELSEIF Time > LegTimer THEN {
LegTimer = -1
} ELSE {
SetPriority 255
SetCrs LegCourse
SetSpd MaxSpd
SETALT ( -600 - RND 50 )
} ENDIF
__________________________________________________ ________________

So far the initial test work great and subs avoid more unpredictably. In regards to surface avoidance, I've not run enough test to know if surface ships are also avoiding left as well. If so the above code may randomize there avoidance a bit as well.

Another approach rather than just avoiding left or right randomly is to code the subs to avoid in the direction that is most convient to where they are heading, though that makes weapon avoidance a little predictable...
__________________
"Seek not to offend or annoy... only to speak the truth"-a wise man

Last edited by LoBlo; 08-11-06 at 11:01 AM.
LoBlo is offline   Reply With Quote