Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Written for 1 AI Mainframe--
- --SystemValues for Operation--
- isStuck = false;
- bDeploy=7;
- bRetract=8;
- pitchNoseUp=2;
- pitchNoseDown=1;
- altDown=6;
- altUp=5;
- rollLeft=3;
- rollRight=4;
- actAltUp=AltUp;
- actAltDown=AltDown;
- -- END--
- --Settings Start Here--
- missileSlot=1 --Slot of Missiles
- healthBasedDive=false; --true:healthbasedDive false:targetbasedDive
- ecoVal=50; --% of Power that will be used (higher values means higher Fuel Efficiency but lower Speed and Shields)
- maxAlt=80; --Maximum Altitude before diving
- minAlt=70; --MinimumAltitude before floating up
- emAlt=40; --Emergency Altitude (Altitude to release Ballons)
- maxPit=1; --MaximumPitch in °
- maxRoll=1; --Maximum Roll in °
- emVel=3; --Emergency Velocity (below this Velocity the ship thinks it is stuck)
- emHealthProcentage=99; --% of Health before diving in Health Controlled Mode
- diveOnly=false; --Diving all the time
- --Setings End Here--
- function Update(I)
- shpr = I:Component_GetCount(10);
- wrn = I:GetNumberOfWarnings(0);
- I:ClearLogs();
- if healthBasedDive then
- HealthControlledDive(I);
- else
- TargetControlledDive(I);
- end
- Missiles(I);
- Fuel(I);
- Shield(I);
- Pitch(I);
- Roll(I);
- Fail(I);
- Depth(I);
- ammo=I:GetAmmoFraction()*100;
- health=I:GetHealthFraction()*100;
- I:Log("Missiles Incomming:"..wrn.." Fuel:"..fuel.." Shields:"..shieldAdj.." FuelAdjustValue:"..flAdj);
- I:Log("A:"..alt.." Dive:"..dive.." Ammo:"..ammo.."% Health:"..health.."%");
- I:Log("P:"..pit);
- I:Log("R:"..roll.." DiveMode:"..diveMode);
- I:Log("ShieldProjectorCount:"..shpr.." Stuck:"..stu.." System at:"..ecoVal.."% Velocity:"..vel);
- end
- function Depth(I)
- pos = I:GetConstructPosition();
- alt = pos.y - I:GetTerrainAltitudeForPosition(pos);
- if alt < actMinAlt then
- I:RequestComplexControllerStimulus(actAltUp);
- dive="false";
- end
- if alt > actMaxAlt then
- I:RequestComplexControllerStimulus(actAltDown);
- dive="true";
- if not isStuck then
- I:RequestComplexControllerStimulus(bRetract);
- end
- end
- if alt < emAlt then
- I:RequestComplexControllerStimulus(bDeploy);
- dive="false";
- end
- end
- function Pitch(I)
- pit = I:GetConstructPitch();
- if pit > 180 then
- pit = pit - 360;
- end
- if pit > maxPit then
- I:RequestComplexControllerStimulus(pitchNoseDown);
- end
- if pit < -maxPit then
- I:RequestComplexControllerStimulus(pitchNoseUp);
- end
- end
- function Roll(I)
- roll = I:GetConstructRoll();
- if roll > 180 then
- roll = roll - 360;
- end
- if roll > maxRoll then
- I:RequestComplexControllerStimulus(rollRight);
- end
- if roll < -maxRoll then
- I:RequestComplexControllerStimulus(rollLeft);
- end
- end
- function Fail(I)
- vel = I:GetForwardsVelocityMagnitude();
- if vel < emVel then
- isStuck = true;
- I:RequestWaterForwards(2*flAdj);
- else
- isStuck = false;
- I:RequestWaterForwards(5*flAdj);
- end
- if isStuck then
- stu = "true";
- else
- stu = "false";
- end
- end
- function Shield(I)
- if wrn > 0 then
- shieldAdj=2*flAdj;
- I:RequestWaterForwards(2*flAdj);
- else
- shieldAdj=5*flAdj;
- I:RequestWaterForwards(5*flAdj);
- end
- I:Component_SetFloatLogicAll(10, shieldAdj);
- end
- function Fuel(I)
- fuel = I:GetFuelFraction();
- if fuel < 0.5 then
- flAdj = fuel+0.5*(ecoVal/100);
- else
- flAdj = 1*(ecoVal/100);
- end
- I:Component_SetFloatLogicAll(9, flAdj);
- end
- function Missiles(I)
- if I:GetNumberOfTargets(0) > 0 then
- for t = 0,I:GetLuaTransceiverCount() do
- for m = 0,I:GetLuaControlledMissileCount(t) do
- targetPos=I:GetTargetInfo(0,0).Position;
- I:SetLuaControlledMissileAimPoint(t,m,targetPos.x,targetPos.y,targetPos.z);
- for weaponIndex = 0, I:GetWeaponCount(0) - 1 do
- I:FireWeapon(weaponIndex, missileSlot);
- end
- end
- end
- end
- end
- function HealthControlledDive(I)
- if diveOnly then
- diveMode = "diveOnly";
- actMinAlt=minAlt;
- actMaxAlt=maxAlt;
- actAltUp=altUp;
- actAltDown=altDown;
- else
- diveMode="HealthBased";
- if I:GetHealthFraction() > emHealthProcentage/100 then
- actMaxAlt=1000;
- actMinAlt=1000;
- actAltUp=altUp;
- actAltDown=altDown;
- else
- actMaxAlt=maxAlt;
- actMinAlt=minAlt;
- actAltUp=altUp;
- actAltDown=altDown;
- end
- end
- end
- function TargetControlledDive(I)
- if diveOnly then
- diveMode = "diveOnly";
- actMinAlt=minAlt;
- actMaxAlt=maxAlt;
- actAltUp=altUp;
- actAltDown=altDown;
- else
- diveOnlyInd = "false";
- diveMode="TargetBased";
- if I:GetNumberOfTargets(0)>0 then
- actMaxAlt=maxAlt;
- actMinAlt=minAlt;
- actAltUp=altUp;
- actAltDown=altDown;
- else
- actMaxAlt=1000;
- actMinAlt=1000;
- actAltUp=altUp;
- actAltDown=altDown;
- end
- end
- end
Add Comment
Please, Sign In to add comment