View Single Post
Old 03-06-10, 05:21 AM   #14
JU_88
Silent Hunter
 
Join Date: Jan 2006
Location: UK
Posts: 3,814
Downloads: 11
Uploads: 0
Default

Quote:
Originally Posted by piri_reis View Post
I mean look at the AI Sub Script !
Lots of tactics implemented already.
Run or attack based on time of day and enemy strength, torpedo/guns attack percentage, Get into firing position (there's your wolfpack!), etc.

Perhaps this script can be modified to keep shadowing a convoy and contact BDU/other boats with radio, with all this scripting I would bet it's possible!

Code:
strategy SubStrategies(Sub)
{
    strategies
    {
        Attack,
        Navigate
    }
}
 
# Attacks an enemy contact
strategy Attack(Sub)
{
    precond
    {
        Sub:CanFire()
    }
    strategies
    {
        ShipAttack,
        SubmarineAttack
    }
}
 
strategy ShipAttack(Sub)
{
    precond
    {
        !Sub:ContactIs(SUBMARINE)
    }
    strategies
    {
        TorpedoAttack,
        CannonAttack
    }
}
 
# how to attack a submarine
strategy SubmarineAttack(Sub)
{
    precond
    {
        Sub:ContactIs(SUBMARINE)
    }
 
    strategies
    {
        # cum functioneaza pentru submarine mai grele de 1000 de tone?
        exclusive
        {
            TorpedoAttack (8),
            CannonAttack (2)
        }
    }
}
 
strategy TorpedoAttack(Sub)
{
    precond
    {
        Sub:ContactIs(SUBMARINE) or (Sub:GetContactWeight() >= fLightWeight)
        and (!Sub:ContactIsMoving() or (Sub:FacingTargetTrajectory() and Sub:ContactIsMoving() ))
    }
    strategies
    {
        TorpedoDayAttack,
        TorpedoNightAttack
    }
}
 
strategy TorpedoDayAttack(Sub)
{
    precond 
    {
        Sub:IsDay()
    }
    action
    {  
        Sub:Dive(periscopeDepth, true);
        Sub:RaisePeriscope(2);
        Sub:FireTorpedoes();
    }
}
 
strategy TorpedoNightAttack(Sub)
{
    precond
    {
        !Sub:IsDay()
    }
    action
    {
        Sub:FireTorpedoes();
    }
}
 
strategy CannonAttack(Sub)
{
    precond
    {        
        (Sub:GetContactWeight() < fLightWeight  or Sub:ContactIs(SUBMARINE))
        and (!Sub:AreEnemiesPresent(ESCORT))
        and (!Sub:AreEnemiesPresent(BATTLESHIP))
        and (Sub:GetContactRelDist() < 3000.0)
    }
    action
    {
        Sub:SetThrottleRatio(1.0);
        Sub:Dive(0.0, true);
        Sub:MoveAroundCannonTarget(fRadius);
        Sub:FireCannons();
    }
}
 
strategy Navigate(Sub)
{    
    strategies
    {
        AdvancedNavigation,
        SubFollowWaypoint
    }
}
 
strategy AdvancedNavigation(Sub)
{
    precond
    {
        Sub:GetCrewRatingSub() > CREW_POOR
    }
    strategies
    {
        Hide, 
        HandleContact,    
        Check,
        Surface
    }
}
strategy Hide(Sub)
{
    # 0 e in loc de Sub:EnemyDangerous()
    # sau contact too close to attack
    precond
    {     Sub:ContactDetected() and (!Sub:CheckDepth(hideDepth)) 
            and (Sub:GetContactRelDist() <= (Sub:GetContactAvoidDist() * 0.98))
            and (!Sub:PersuingTarget())
        or (Sub:ContactIs(ESCORT) and ((Sub:IsDay() and (Sub:GetContactRelDist() < DAY_ESCORT_EVADE_DIST)) 
                or (!Sub:IsDay() and Sub:GetContactRelDist() < NIGHT_ESCORT_EVADE_DIST)) )
    }
    action
    {
        Sub:Dive(hideDepth, true);
        Sub:WaitAction(30.0); #wait 30 min
    }
}
 
# We check for contacts using the periscope.
# for this we need to go to periscope depth (after waiting underwater for 30 min)
# Once the periscope is raised, keep checking for 12 sec.
strategy Check(sub)
{
  precond
  {
    (!Sub:ContactDetected()) and (Sub:GetDepth() < periscopeDepth - 1) 
  }
  action
  {
    Sub:Dive(periscopeDepth, false);
    Sub:RaisePeriscope(periscope);
    Sub:WaitAction(5.0); # wait 12 seconds
  }
}
 
 
#We surface if we have no contact detected
strategy Surface(Sub)
{
    strategies
    {
        SurfaceCheck,
        SurfaceDamaged
    }
}
 
strategy SurfaceCheck(Sub)
{
  precond 
  { !Sub:ContactDetected() and Sub:CheckDepth(periscopeDepth)
    or (Sub:GetContactRelDist() >= Sub:GetContactAvoidDist())
  }
  action
  { 
    Sub:Dive(0.0, false);  #Surface the boat
  }
}
 
#Emergency surface if Damage > 50%
strategy SurfaceDamaged(Sub)
{
    precond
    {
        Sub:GetDamage() > 0.5
    }
    action
    {
        Sub:Dive(0.0, true); 
    }
}
 
# Strategies for aproaching and attacking an enemy contact
strategy HandleContact(Sub)
{
    precond 
    { 
        Sub:ContactDetected()
    }
    strategies
    {
        EvadeDetection,
        PositionToFire
    }
}
 
# Evades enemy visual detection (day and night time)
strategy EvadeDetection(Sub)
{
#the only difference between day and night evasion is the EVADE_DIST. 
    strategies
    {    
        EvadeDetectionDay, 
        EvadeDetectionNight,
        EvadeDefault
    }
}
 
# Evades from contact sight during day time
strategy EvadeDetectionDay(Sub)
{
    precond
    {
        Sub:IsDay()
    }
    strategies
    {
        EvadeEscortDay,        
    }
}
 
# Evades from contact sight at night
strategy EvadeDetectionNight(Sub)
{
    precond
    {
        !Sub:IsDay()
    }
    strategies
    {
        EvadeEscortNight,
    }    
}
 
# Evades escorts (night version)
strategy EvadeEscortNight(Sub)
{
    precond
    {
        Sub:ContactIs(ESCORT)
    }
    strategies
    {
        EvadeCloseEscortNight,
        EvadeFarEscortNight
    }
}
 
# Evades escort if not too far away during night time
strategy EvadeCloseEscortNight(Sub)
{
    precond
    {
        Sub:GetContactRelDist() < NIGHT_ESCORT_EVADE_DIST
    }
    action
    {
        Sub:Dive(-90.0, true);
        Sub:SetThrottleRatio(0.33);
        Sub:MoveOutsideDetectionArea(); #do try to attack contact after evade was done
    }
}
 
# Evades far escort during night time
strategy EvadeFarEscortNight(Sub)
{
    precond
    {
        Sub:GetContactRelDist() >= NIGHT_ESCORT_EVADE_DIST
        or (Sub:InSpotLight())
    }
    action
    {
        Sub:SetThrottleRatio(1.0);
        Sub:MoveOutsideDetectionArea(); #do try to attack contact after evade was done
    }
}
 
# Evades escorts (day version)
strategy EvadeEscortDay(Sub)
{
    precond { Sub:ContactIs(ESCORT)}
    strategies
    {
        EvadeCloseEscortDay,
        EvadeFarEscortDay,
        EvadeDefault
    }
}
 
# Evades an enemy escort if not too far away (day time)
strategy EvadeCloseEscortDay(Sub)
{
    precond    { Sub:GetContactRelDist() < DAY_ESCORT_EVADE_DIST }
    action
    {
        Sub:SetThrottle(0.33);
        Sub:MoveOutsideDetectionArea(); #do try to attack contact after evade was done
    }
}
 
# Evades far enemy escorts (day time)
strategy EvadeFarEscortDay(Sub)
{
    precond{ Sub:GetContactRelDist() >= DAY_ESCORT_EVADE_DIST }
    action
    {
        Sub:SetThrottleRatio(1.0);
        Sub:MoveOutsideDetectionArea();
    }
}
 
# Evade enemy contacts if they are not escorts
strategy EvadeDefault(Sub)
{
    precond 
    { 
        (!Sub:ContactIs(ESCORT)) and (!Sub:ContactIs(ESCORT)) and (Sub:GetContactRelDist() <= (Sub:GetContactAvoidDist() * 0.98) ) and 
        (!Sub:CanFire()) and (!Sub:PersuingTarget())
    }
    action
    {
        Sub:MoveOutsideDetectionArea();
    }
}
 
strategy PositionToFire(Sub)
{
    precond
    {
        Sub:PersuingTarget() and ( Sub:GetSubMaxSpeed() > Sub:GetContactSpeed() )
    }
    strategies
    {
        PositionToFireCannons,
        PositionToFireTorpedos
    }
}
 
# Positions the sub in a good firing position
strategy PositionToFireTorpedos(Sub)
{
    precond
    {
        !Sub:CanFire()
        and ( (Sub:GetContactWeight() >= fLightWeight) or Sub:ContactIs(SUBMARINE) )
    }
    action
    {
        Sub:SetThrottleRatio(1.0);
    }
    strategies
    {
        MoveNearDetectionArea,
        MoveIntoPosition,
        TurnToFaceTargetTrajectory,    
        ApproachStillTarget,
    }
}
 
strategy PositionToFireCannons(Sub)
{
    precond
    {
        Sub:GetContactWeight() < fLightWeight
        and Sub:GetContactRelDist() > 2500.0
    }
    action
    {
        Sub:ApproachStillTarget();    
    }
}
 
# Approaches the target's detection area before trying to get in front of it
strategy MoveNearDetectionArea(Sub)
{
    precond
    {
        (Sub:GetContactRelDist() >= (Sub:GetContactAvoidDist() * 1.10)) and 
        Sub:ContactIsMoving() and Sub:PersuingTarget()
    }
    action
    {
        Sub:MoveNearDetectionArea();
    }
}
 
# Tries to get in front of a moving ship and also keep away from it's
# visual detection area
strategy MoveIntoPosition(Sub)
{    
    precond
    {
        Sub:PersuingTarget() and Sub:ContactIsMoving() 
        and (!Sub:SubInFrontOfContact())
    }
    action
    {    
        Sub:MoveIntoPosition();
    }
}
 
 
 
# Turns the sub towards target trajectory so that the angle between the perpendicular 
# to the trajectory and the sub's heading vector is less than 10 degrees
strategy TurnToFaceTargetTrajectory(Sub)
{
    precond
    {
        Sub:ContactIsMoving() and Sub:SubInFrontOfContact() 
        and (!Sub:FacingTargetTrajectory()) and Sub:PersuingTarget()
    }
    action
    {
        Sub:TurnToFaceTargetTrajectory();
    }
}
 
# Approaches a target which has a speed less than 0.1
strategy ApproachStillTarget(Sub)
{
    precond
    {
        (!Sub:ContactIsMoving()) and (Sub:GetContactRelDist() >= 2000.0)
    }
    action
    {
        Sub:ApproachStillTarget();
    }
}
 
strategy SubFollowWaypoint(Sub)
{
    precond
    {
        Sub:CanFollowWaypoint() and !Sub:ContactDetected()
    }
    action
    {
        Sub:FollowWp();
    }
}

Awesome...
Now i Just to finnish this mother off and get her in as an AI/player unit.

(The T-Class = British equivilent of the Type IX & Gato ... gotta love those 11 torpedo tubes )



JU_88 is offline   Reply With Quote