inkoalawetrust

Early Tank Turret Code

Jan 22nd, 2021
866
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Class MainBattleTankTurret : Actor
  2. {
  3.     Default
  4.     {
  5.         Radius 48;
  6.         Height 28;
  7.         Scale 0.75;
  8.         DeathHeight 28;
  9.         Mass 20000;
  10.         FriendlySeeBlocks 256;
  11.         MaxTargetRange 10240; //The attack related flags and properties will probably go to the turret.
  12.         RipLevelMin 5;
  13.         Monster;
  14.         -ActivateMCross;
  15.         -CanUseWalls;
  16.         -CanPushWalls;
  17.         -IsMonster;
  18.         +LookAllAround;
  19.         +MissileMore;
  20.         +NeverRespawn; //Doesnt make sense for a tank to magically reappear.
  21.         +Telestomp;
  22.         +NoTelefrag;
  23.         +NoFear;
  24.         +DontSquash;
  25.         +DontHarmClass;
  26.         +DontDrain;
  27.         +NoBlood;
  28.         +NoPain;
  29.         +PuffOnActors;
  30.         +NeverTarget;
  31.         +NoTarget;
  32.         +NotAutoAimed;
  33.         +NoDamage;
  34.     }
  35.     enum TurretSoundChannels {CHAN_TURRET = 183745}
  36.     Override Void Tick()
  37.     {
  38.         Super.Tick();
  39.         //This is how the turret actually stays attached to the chassis.
  40.         If (Master) //Only warp to the master actor if it actually exists.
  41.         {
  42.             Warp (Master,zofs:60,flags:WARPF_NOCHECKPOSITION|WARPF_STOP|WARPF_INTERPOLATE|WARPF_USECALLERANGLE|WARPF_COPYPITCH);
  43.             A_CopyFriendliness(); //Oh and also copy whatever the chassis' affiliation is.
  44.         }
  45.         If (IsFrozen())
  46.         {
  47.             A_StopSound (CHAN_TURRET);
  48.             Return;
  49.         }
  50.         If (InStateSequence (CurState, ResolveState ("FaceTarget")))
  51.         {
  52.             A_StartSound ("MBT/TurretRotate",CHAN_TURRET,CHANF_LOOPING);
  53.         }
  54.     }
  55.     Override Int DamageMobj (Actor inflictor, Actor source, int damage, Name mod, int flags, double angle)
  56.     {
  57.         If (Master)
  58.         {
  59.             Master.DamageMobj (inflictor,source,damage,mod,flags,angle);
  60.         }
  61.         Return 0;
  62.     }
  63.     States
  64.     {
  65.         Spawn:
  66.             MBTI A 8 A_LookEx (maxseedist:10240+2048,maxheardist:3072,label:"FaceTarget");
  67.             Loop;
  68.         FaceTarget:
  69.             MBTI A 2
  70.             {
  71.                 //Add a small earthquake when the cannon fires.
  72.                 A_FaceTarget (4,5,flags:FAF_MIDDLE);
  73.                 FLineTraceData CanHitTarget;
  74.                 LineTrace (self.angle,10240,Clamp(self.pitch, -45, 45),TRF_THRUHITSCAN|TRF_NOSKY|TRF_SOLIDACTORS,data:CanHitTarget);
  75.                 If (CanHitTarget.HitActor && Target && CanHitTarget.HitActor == Target)
  76.                 {
  77.                     SetStateLabel ("FireCannon");
  78.                 }
  79.                 Return null;
  80.             }
  81.             Loop;
  82.         FireCannon: //Each MBTI frame is about a second
  83.             MBTI AAAAAAAAAAAAAAAA 2 A_FaceTarget (4,5,flags:FAF_MIDDLE);
  84.             MBTI AAAAAAAAAAAAAAAA 2 A_FaceTarget (4,5,flags:FAF_MIDDLE);
  85.             MBTI AAAAAAAAAAAAAAAA 2 A_FaceTarget (4,5,flags:FAF_MIDDLE);
  86.             MBTF A 4 Bright
  87.             {
  88.  
  89.                 A_SpawnProjectile ("Rocket"); //Placeholder
  90.                 A_StartSound ("MBT/TankShot",attenuation:0.25);
  91.             }
  92.             MBTF B 4 Bright A_StopSound (CHAN_TURRET); //Stop the rotating sound.
  93.             MBTF CDEFGH 4 Bright;
  94.             Goto Spawn;
  95.         Death: //Major placeholder, figure out how to make the turret die once the chassis dies first.
  96.             MBTD ABCD 4 Bright;
  97.             Loop;
  98.     }
  99. }
RAW Paste Data