SWAG98

FTD LUA SubControll

Feb 4th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.70 KB | None | 0 0
  1. --Written for 1 AI Mainframe--
  2.  
  3. --SystemValues for Operation--
  4. isStuck = false;
  5. bDeploy=7;
  6. bRetract=8;
  7. pitchNoseUp=2;
  8. pitchNoseDown=1;
  9. altDown=6;
  10. altUp=5;
  11. rollLeft=3;
  12. rollRight=4;
  13. actAltUp=AltUp;
  14. actAltDown=AltDown;
  15. -- END--
  16.  
  17. --Settings Start Here--
  18. missileSlot=1             --Slot of Missiles
  19. healthBasedDive=false;    --true:healthbasedDive false:targetbasedDive
  20. ecoVal=50;                --% of Power that will be used (higher values means higher Fuel Efficiency but lower Speed and Shields)
  21. maxAlt=80;                --Maximum Altitude before diving
  22. minAlt=70;                --MinimumAltitude before floating up
  23. emAlt=40;                 --Emergency Altitude (Altitude to release Ballons)
  24. maxPit=1;                 --MaximumPitch in °
  25. maxRoll=1;                --Maximum Roll in °
  26. emVel=3;                  --Emergency Velocity (below this Velocity the ship thinks it is stuck)
  27. emHealthProcentage=99;    --% of Health before diving in Health Controlled Mode
  28. diveOnly=false;           --Diving all the time
  29. --Setings End Here--
  30.  
  31. function Update(I)
  32.  shpr = I:Component_GetCount(10);
  33.  wrn = I:GetNumberOfWarnings(0);
  34.  I:ClearLogs();
  35.  if healthBasedDive then
  36.   HealthControlledDive(I);
  37.  else
  38.   TargetControlledDive(I);
  39.  end
  40.  Missiles(I);
  41.  Fuel(I);
  42.  Shield(I);
  43.  Pitch(I);
  44.  Roll(I);
  45.  Fail(I);
  46.  Depth(I);
  47.  ammo=I:GetAmmoFraction()*100;
  48.  health=I:GetHealthFraction()*100;
  49.  I:Log("Missiles Incomming:"..wrn.." Fuel:"..fuel.." Shields:"..shieldAdj.." FuelAdjustValue:"..flAdj);
  50.  I:Log("A:"..alt.." Dive:"..dive.." Ammo:"..ammo.."% Health:"..health.."%");
  51.  I:Log("P:"..pit);
  52.  I:Log("R:"..roll.." DiveMode:"..diveMode);
  53.  I:Log("ShieldProjectorCount:"..shpr.."  Stuck:"..stu.."  System at:"..ecoVal.."%  Velocity:"..vel);
  54. end
  55.  
  56. function Depth(I)
  57.  pos = I:GetConstructPosition();
  58.  alt = pos.y - I:GetTerrainAltitudeForPosition(pos);
  59.  if alt < actMinAlt then
  60.   I:RequestComplexControllerStimulus(actAltUp);
  61.   dive="false";
  62.  end
  63.  if alt > actMaxAlt then
  64.   I:RequestComplexControllerStimulus(actAltDown);
  65.   dive="true";
  66.   if not isStuck then
  67.    I:RequestComplexControllerStimulus(bRetract);
  68.   end
  69.  end
  70.  if alt < emAlt then
  71.   I:RequestComplexControllerStimulus(bDeploy);
  72.   dive="false";
  73.  end
  74. end
  75.  
  76. function Pitch(I)
  77.  pit = I:GetConstructPitch();
  78.  if pit > 180 then
  79.   pit = pit - 360;
  80.  end
  81.  if pit > maxPit then
  82.   I:RequestComplexControllerStimulus(pitchNoseDown);
  83.  end
  84.  if pit < -maxPit then
  85.   I:RequestComplexControllerStimulus(pitchNoseUp);
  86.  end
  87. end
  88.  
  89. function Roll(I)
  90.  roll = I:GetConstructRoll();
  91.  if roll > 180 then
  92.   roll = roll - 360;
  93.  end
  94.  if roll > maxRoll then
  95.   I:RequestComplexControllerStimulus(rollRight);
  96.  end
  97.  if roll < -maxRoll then
  98.   I:RequestComplexControllerStimulus(rollLeft);
  99.  end
  100. end
  101.  
  102. function Fail(I)
  103.  vel = I:GetForwardsVelocityMagnitude();
  104.  if vel < emVel then
  105.   isStuck = true;
  106.   I:RequestWaterForwards(2*flAdj);
  107.  else
  108.   isStuck = false;
  109.   I:RequestWaterForwards(5*flAdj);
  110.  end
  111.  if isStuck then
  112.   stu = "true";
  113.  else
  114.   stu = "false";
  115.  end
  116. end
  117.  
  118. function Shield(I)
  119.  if wrn > 0 then
  120.   shieldAdj=2*flAdj;
  121.   I:RequestWaterForwards(2*flAdj);
  122.  else
  123.   shieldAdj=5*flAdj;
  124.   I:RequestWaterForwards(5*flAdj);
  125.  end
  126.  I:Component_SetFloatLogicAll(10, shieldAdj);
  127. end
  128.  
  129. function Fuel(I)
  130.  fuel = I:GetFuelFraction();
  131.  if fuel < 0.5 then
  132.   flAdj = fuel+0.5*(ecoVal/100);
  133.  else
  134.   flAdj = 1*(ecoVal/100);
  135.  end
  136.  I:Component_SetFloatLogicAll(9, flAdj);
  137. end
  138.  
  139. function Missiles(I)
  140.  if I:GetNumberOfTargets(0) > 0 then
  141.   for t = 0,I:GetLuaTransceiverCount() do
  142.    for m = 0,I:GetLuaControlledMissileCount(t) do
  143.     targetPos=I:GetTargetInfo(0,0).Position;
  144.     I:SetLuaControlledMissileAimPoint(t,m,targetPos.x,targetPos.y,targetPos.z);
  145.     for weaponIndex = 0, I:GetWeaponCount(0) - 1 do
  146.      I:FireWeapon(weaponIndex, missileSlot);
  147.     end
  148.    end
  149.   end
  150.  end
  151. end
  152.  
  153. function HealthControlledDive(I)
  154.  if diveOnly then
  155.   diveMode = "diveOnly";
  156.   actMinAlt=minAlt;
  157.   actMaxAlt=maxAlt;
  158.   actAltUp=altUp;
  159.   actAltDown=altDown;
  160.  else
  161.   diveMode="HealthBased";
  162.   if I:GetHealthFraction() > emHealthProcentage/100 then
  163.    actMaxAlt=1000;
  164.    actMinAlt=1000;
  165.    actAltUp=altUp;
  166.    actAltDown=altDown;
  167.   else
  168.    actMaxAlt=maxAlt;
  169.    actMinAlt=minAlt;
  170.    actAltUp=altUp;
  171.    actAltDown=altDown;
  172.   end
  173.  end
  174. end
  175.  
  176. function TargetControlledDive(I)
  177.  if diveOnly then
  178.   diveMode = "diveOnly";
  179.   actMinAlt=minAlt;
  180.   actMaxAlt=maxAlt;
  181.   actAltUp=altUp;
  182.   actAltDown=altDown;
  183.  else
  184.   diveOnlyInd = "false";
  185.   diveMode="TargetBased";
  186.   if I:GetNumberOfTargets(0)>0 then
  187.    actMaxAlt=maxAlt;
  188.    actMinAlt=minAlt;
  189.    actAltUp=altUp;
  190.    actAltDown=altDown;
  191.   else
  192.    actMaxAlt=1000;
  193.    actMinAlt=1000;
  194.    actAltUp=altUp;
  195.    actAltDown=altDown;
  196.   end
  197.  end
  198. end
Add Comment
Please, Sign In to add comment