Advertisement
inkoalawetrust

Buggy VTOL

Mar 3rd, 2021
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.39 KB | None | 0 0
  1. //The problem with the code is that for some reason when the VTOL moves back, it does so way too fast not matter what I try.
  2. //Now it doesn't even do it when it enters its' "BackOff" state, it does it when it enters the state where fire its' plasma gun!
  3.  
  4. Class StealthCraft : Actor
  5. {
  6.     Default
  7.     {
  8.         Health 5000;
  9.         Radius 128;
  10.         Height 100;
  11.         Mass 7000;
  12.         DamageFactor 0.9;
  13.         Gravity 0.5;
  14.         Friction 0.05;
  15.         FloatBobStrength 0.5;
  16.         Species "MarineAlly";
  17.         Obituary "%o was killed by a VTOL";
  18.         Monster;
  19.         +NoGravity;
  20.         +MissileEvenMore;
  21.         +Float;
  22.         +AvoidMelee;
  23.         +Telestomp;
  24.         +FloatBob;
  25.         +NoBlood;
  26.         +PuffOnActors;
  27.     }
  28.     Static Vector3 GetLocalVel(Actor a) //Function by Cherno, I know fuck all about math.
  29.     {
  30.         double relativeVelX = (sin(a.angle) * a.vel.y) + (cos(a.angle) * a.vel.x);
  31.         double relativeVelY = ((cos(a.angle) * a.vel.y) - (sin(a.angle) * (a.vel.x))) * -1;
  32.         return (relativeVelX,relativeVelY,a.vel.z);
  33.     }
  34.     static bool AreTherePlayersAround(double dist, actor source) //Function by Agent_Ash, this code is so alien to me that I don't even know how to fix the formatting without breaking it.
  35.     {
  36.       for (int pn = 0; pn < MAXPLAYERS; pn++)
  37.       {
  38.         if (!players[pn].mo || !playerInGame[pn])
  39.           continue;
  40.         PlayerPawn plr = players[pn].mo;
  41.         if (!plr)
  42.           continue;
  43.         if (source.Distance3D(plr) <= dist)
  44.         {
  45.           return true;
  46.           break;
  47.         }
  48.       }
  49.       return false;
  50.     }
  51.     Vector3 ForwardVel; //Used to store the crafts' forward velocity, to make it visual lean forward or back if this vector is too low or high.
  52.     Int MayBackAway; //A variable used to determine the chance of the craft to move away from its' target.
  53.     Int MayThrustUp; //A variable used to determine the chance of the craft to go up.
  54.     Int MayThrustDown; //A variable used to determine the chance of the craft to go down.
  55.     Int RandomSwerve; //A variable used to give the VTOL a random delay before swerving when attacking instead of standing still.
  56.     Int VerticalMovementCooldown; //A variable used as a cooldown so the craft doesn't move up the immediately go down or vice versa.
  57.     Int MissileFiringChance; //This variable determines if the VTOL should launch its' missiles instead of firing its' plasma gun, it is used for the DecideAttack state.
  58.     enum AircraftSoundChannels
  59.     {
  60.         CHAN_ENGINE = 18273
  61.     }
  62.     Override Void PostBeginPlay()
  63.     {
  64.         Super.PostBeginPlay();
  65.         RandomSwerve = RandomPick (35*1,35*2,35*3,35*4,35*5); //Initializes the first random delay before the VTOL swerves.
  66.     }
  67.     Override Void Tick()
  68.     {
  69.         Super.Tick();
  70.         //If it's moving forward too fast, then produce a counterforce to slow it down.
  71.         If (Self.ForwardVel.x >= 24) {A_ChangeVelocity (-1,flags:CVF_RELATIVE); a_log ("IS THIS FUCKING LINE THE ISSUE ? JUST TELL ME WHAT IT FUCKING IS");}
  72.         //If moving up too fast up, then slow down.
  73.         If (Self.Vel.z >= 12) {A_ChangeVelocity (z:-1,flags:CVF_RELATIVE);}
  74.         If (Target)
  75.         {
  76.             If (CheckIfTargetInLOS (140,JLOSF_CLOSENOJUMP,dist_close:512) && InStateSequence (CurState, ResolveState ("See")))
  77.             {Return;}
  78.             Else //If the target isn't in the LOS while chased, slow down to not fly away uncontrollably and face it faster.
  79.             {
  80.                 MayBackAway = Random (0,256);
  81.                 A_FaceTarget (16);
  82.                 A_ChangeVelocity (-3,flags:CVF_RELATIVE);
  83.                 //A random chance for the craft to enter its' back off state where it backs away.
  84.                 If (MayBackAway == 27 && InStateSequence (CurState, ResolveState ("See"))) {SetStateLabel ("BackOff");}
  85.             }
  86.         }
  87.         //If the VTOL is attacking with its' plasma gun, then have a random chance of moving left or right not avoid being hit.
  88.         If (InStateSequence (CurState,ResolveState ("FirePlasma")))
  89.         {
  90.             A_ChangeVelocity (0,flags:CVF_REPLACE);
  91.             RandomSwerve--;
  92.             If (RandomSwerve <= 0)
  93.             {
  94.                 A_LOG ("STOP FLYING BACK YOU STUPID PIECE OF SHIT");
  95.                 A_ChangeVelocity (y:RandomPick (-32,32),flags:CVF_RELATIVE);
  96.                 RandomSwerve = RandomPick (35*1,35*2,35*3,35*4,35*5); //Pick another delay before thje next swerve.
  97.             }
  98.         }
  99.     }
  100.     Private Void A_LeanTowardsMovementDirection()
  101.     {
  102.         ForwardVel = StealthCraft.GetLocalVel (Self);
  103.         //If it's moving forward too fast, change the sprite sheet to the forwards leaning one.
  104.         If (ForwardVel.x >= 16) {Sprite = GetSpriteIndex ("FLFM");}
  105.         //If it's moving backwards too fast, change the sprite sheet to the backwards leaning one.
  106.         If (ForwardVel.x <= -16) {Sprite = GetSpriteIndex ("FLBM"); a_log ("leaning back");}
  107.         //If its' speed is in between both of the above, change the sheet back to the idle flying one.
  108.         If (ForwardVel.x <= 16 && ForwardVel.x >= 16) {Sprite = GetSpriteIndex ("FLSA");}
  109.     }
  110.     States
  111.     {
  112.         Spawn:
  113.             TNT1 A 0 NoDelay A_StartSound ("StealthCraft/EngineOn",CHAN_ENGINE,CHANF_LOOPING,attenuation:0.75);
  114.             Goto IdleFly;
  115.         IdleFly:
  116.             FLSA AB 8 A_LookEx (maxheardist:3072);
  117.             Loop;
  118.         See:
  119.             FLSA AB 8
  120.             {
  121.                 //If the VTOL is stuck on the ground, then leap up.
  122.                 If (pos.z - FloorZ <= 0) {a_log ("way too low");A_ChangeVelocity (z:4,flags:CVF_RELATIVE);}
  123.                 A_Chase(null,"DecideAttack");
  124.                 A_ChangeVelocity (2,flags:CVF_RELATIVE);
  125.                 A_LeanTowardsMovementDirection();
  126.                 A_FaceTarget (4);
  127.                 VerticalMovementCooldown--; //Decrements the cooldown every time the functions here are executed.
  128.                 MayThrustUp = Random (0,128);
  129.                 MayThrustDown = Random (0,128);
  130.                 //A random chance for the VTOL to thrust down, must also be at least 48 or more MU above the ground for it to thrust down.
  131.                 If (MayThrustDown >= 126 && VerticalMovementCooldown <= 0 && pos.z - GetZAt () >= 48)
  132.                 {
  133.                     A_ChangeVelocity (z:FRandom (-4.0,-12.0),CVF_RELATIVE);
  134.                     a_log ("going down");
  135.                     MayThrustUp = 0; //Reset the variable to 0 so if it does decide to fly down, it won't immediately fly back up.
  136.                     VerticalMovementCooldown = 12;
  137.                 }
  138.                 //May randomly decide to fly upwards, to not just stick on the same height.
  139.                 If (MayThrustUp >= 127 && VerticalMovementCooldown <= 0)
  140.                 {
  141.                     a_log ("going up");
  142.                     A_ChangeVelocity (z:FRandom (4.0,10.0),CVF_RELATIVE);
  143.                     VerticalMovementCooldown = 12;
  144.                 }
  145.             }
  146.             Goto See+1;
  147.         BackOff:
  148.             FLBM ABABAB 8
  149.             {
  150.                 vel.x = vel.x * cos(angle) + vel.y * sin(angle) -0.2;
  151.                 console.printf ("the velocity is %d", vel);
  152.                 A_FaceTarget (24);
  153.             }
  154.             Goto See;
  155.         DecideAttack:
  156.             TNT1 A 0 {If (Target == Null) {SetStateLabel ("See");}} //If there's no target, go back to looking for one.
  157.             TNT1 A 0
  158.             {
  159.                 MissileFiringChance = Random (0,384); //Randomize the chance of firing missiles.
  160.                 Console.PrintF ("The initial RNG for MissileFiringChance is %d", MissileFiringChance);
  161.                
  162.                
  163.                 //In short, this checks the actors around the VTOL's target, and increases its' chance of
  164.                 //firing a missile slightly for every nearby actor that meets the following conditions:
  165.                 //The actor is a monster.
  166.                 //The actor has 20 HP or more.
  167.                 //The actor is hostile. (If the VTOL is friendly it'll count non-friendly NPCs, if it is NOT friendly, it'll count friendly NPCs.)
  168.                 BlockThingsIterator CheckAroundTarget = BlockThingsIterator.Create (Target,512);
  169.                 Actor FoundActor;
  170.                 While (CheckAroundTarget.Next())
  171.                 {
  172.                     FoundActor = CheckAroundTarget.Thing;
  173.                     If (FoundActor && bIsMonster == True && FoundActor.Health >= 20 && IsHostile (FoundActor))
  174.                     {
  175.                         MissileFiringChance += Random (1,3);
  176.                     }
  177.                 }
  178.                 Console.PrintF ("MissileFiringChance after the first calculation of the amount of enemies around the target is %d", MissileFiringChance);
  179.  
  180.                 //In theory at least, this should further increase the chance of the VTOL firing a missile based on how high the targets' own health is.
  181.                 MissileFiringChance += Target.Health/5;
  182.                 Console.PrintF ("The RNG for MissileFiringChance after also being calculated based on the actors' health is %d", MissileFiringChance);
  183.                
  184.                 If (self.bFriendly == True && AreTherePlayersAround (512,target) == True) {a_log ("player is too close to the missiles' blast radius");SetStateLabel ("FirePlasma");} //If there's a player near the target and the VTOL is friendly, then fire the plasma gun instead.
  185.                
  186.                 If (MissileFiringChance >= 370) {SetStateLabel ("FireMissiles");}
  187.             }
  188.             TNT1 A 0;
  189.             Goto FirePlasmaGun; //If the above checks' conditions are not met, fire the plasma gun instead.
  190.         FirePlasmaGun:
  191.         tnt1 a 0 a_log ("you dun goofed");
  192.             //FLSA A 0 A_Jump (2,"FireMissiles"); //A small chance for the VTOL to fire its' missiles anyway, even if the check on DecideAttack decided to not do so.
  193.             FLSA A 8 A_StartSound ("StealthCraft/PlasmaCharge",CHAN_WEAPON,attenuation:/*0.8*/0,starttime:0.474);
  194.             FLSA BABABABABABABABABABAB 8; //This is perfectly timed so the VTOL begins firing right when the charging sound ends.
  195.             FLFP ABABABABABABABABABABABABABABABABABABABAB 8
  196.             {
  197.                 A_SpawnProjectile ("StealthCraftPlasma",4,angle:FRandom (0.5,-0.5),CMF_TRACKOWNER|CMF_OFFSETPITCH,FRandom (0.5,-0.5));
  198.                 A_SpawnProjectile ("StealthCraftPlasma",4,angle:FRandom (0.5,-0.5),CMF_TRACKOWNER|CMF_OFFSETPITCH,FRandom (0.5,-0.5));
  199.             }
  200.             Goto See;
  201.         FireMissiles:
  202.             tnt1 a 0 a_log ("missile placeholder");
  203.             stop;
  204.     }
  205. }
  206.  
  207. Class StealthCraftPlasma : Actor
  208. {
  209.     Default
  210.     {
  211.         Height 12;
  212.         Radius 6;
  213.         DamageFunction RandomPick (8,12); //Either 8 or 12 damage is dealt.
  214.         Speed 32;
  215.         FastSpeed 64;
  216.         Alpha 0.80;
  217.         Decal "PlasmaScorch";
  218.         Translation "194:207=193:200", "241:241=194:194";
  219.         Obituary "%o was pulverized by a VTOL's plasma !";
  220.         DamageType "Plasma";
  221.         RenderStyle "Add";
  222.         DeathSound "Weapons/PlasmaX";
  223.         Projectile;
  224.         +Randomize;
  225.     }
  226.     Override Void PostBeginPlay()
  227.     {
  228.         Super.PostBeginPlay();
  229.         A_StartSound ("StealthCraft/PlasmaFired");
  230.         A_AttachLight ("PlasmaLight",DynamicLight.PulseLight,"6B63FF",32,36,DynamicLight.LF_Attenuate,param:0.25);
  231.     }
  232.     States
  233.     {
  234.         Spawn:
  235.             PLSS AB 4 Bright;
  236.             Loop;
  237.         Death: //Implement several lights that get increasingly smaller on these death frames.
  238.             TNT1 A 0 A_RemoveLight ("PlasmaLight");
  239.             PLSE ABCDE 6 Bright;
  240.             Stop;
  241.     }
  242. }
  243.  
  244. Class StealthCraftMissile : Actor
  245. {
  246.     Default
  247.     {
  248.         Height 24;
  249.         Radius 16;
  250.         Damage 120;
  251.         Speed 64;
  252.         FastSpeed 128;
  253.         Mass 50;
  254.         SeeSound "StealthCraft/MissileFired";
  255.         Obituary "%o was blown up by a VTOL's missile";
  256.         Translation "96:111=#[0,255,128]", "89:95=#[0,255,128]";
  257.         Projectile;
  258.         +RocketTrail;
  259.         +SeekerMissile;
  260.         +ScreenSeeker;
  261.         +ExtremeDeath;
  262.         +SpawnSoundSource;
  263.     }
  264.     Double TrailXVel;
  265.     Double TrailYVel;
  266.     Double TrailZVel;
  267.     Double RandMult; //Random multiplier
  268.     Override Void Tick()
  269.     {
  270.         Super.Tick();
  271.         //Don't spawn particles and play the missile sound if the game is frozen or the missile is exploding.
  272.         If (IsFrozen() || InStateSequence (CurState,ResolveState ("Death")) || InStateSequence (CurState,ResolveState ("Death.Air"))) {A_StopSound (17263); Return;}
  273.  
  274.         TrailXVel = FRandom (0.0,-4.0); TrailYVel = FRandom (4.0,-4.0); TrailZVel = FRandom (4.0,-4.0); //Random velocity for all 3 axes.
  275.         A_SpawnItemEx ("StealthCraftMissileParticle",64,xvel:TrailXVel,TrailYVel,TrailZVel,Self.Angle-180+Random (8,-8),SXF_SETMASTER|SXF_ABSOLUTEANGLE|SXF_ORIGINATOR);
  276.  
  277.         TrailXVel = FRandom (0.0,-4.0); TrailYVel = FRandom (4.0,-4.0); TrailZVel = FRandom (4.0,-4.0);
  278.         RandMult = FRandom (2.0,8.0);
  279.         A_SpawnItemEx ("StealthCraftMissileParticle",64+24,xvel:TrailXVel*RandMult,TrailYVel*RandMult,TrailZVel,Self.Angle-180+Random (8,-8),SXF_SETMASTER|SXF_ABSOLUTEANGLE|SXF_ORIGINATOR);
  280.     }
  281.     States
  282.     {
  283.         Spawn:
  284.             TNT1 A 0 NoDelay A_StartSound ("StealthCraft/MissileMoving",17263,CHANF_LOOPING,attenuation:0.75);
  285.             FLMI A 4 Bright Light ("StealthCraftMissileLight") A_SeekerMissile (0,2,SMF_PRECISE);
  286.             Goto Spawn+1;
  287.         Death:
  288.             TNT1 A 0
  289.             {
  290.                 A_StopSound (17263);
  291.                 If ((pos.z - FloorZ) >= 128) //If the missile impacted away from the floor, use the air explosion sprites instead.
  292.                 {
  293.                     SetStateLabel ("Death.Air");
  294.                 }
  295.             }
  296.             tnt1 a 0 a_log ("died near the floor");
  297.             MISL B 4 A_Explode (Random(500,600),512,alert:True,100);
  298.             MISC C 4;
  299.             MISL D 4;
  300.             Stop;
  301.         Death.Air:
  302.             tnt1 a 0 a_log ("died far from the floor");
  303.             MISL B 4 A_Explode (Random(500,600),512,alert:True,100);
  304.             MISL C 4;
  305.             MISL D 4;
  306.             Stop;
  307.     }
  308. }
  309.  
  310.  
  311.  
  312. Class StealthCraftMissileParticle : Actor
  313. {
  314.     Default
  315.     {
  316.         RenderStyle "Add";
  317.         Alpha 0.75;
  318.         +NoInteraction;
  319.     }
  320.     States
  321.     {
  322.         Spawn:
  323.             FLMS ABCDEFGHIJKL 1 Bright;
  324.             Stop;
  325.     }
  326. }
  327.  
  328. Class StealthCraftSprites : Actor
  329. {
  330.     States
  331.     {
  332.         Spawn:
  333.             FLFM AB 0; //VTOL is leaning forward
  334.             FLBM AB 0; //VTOL is leaning backwards
  335.             Stop;
  336.     }
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement