
ACTOR RLAntiMaterielRifle : RLWeapon
{
  Obituary "%k thought it was overkill, but sniped %o anyway."
  Decal BulletChip
  Tag "Anti-materiel Rifle"
  Weapon.Kickback 1000
  Weapon.SelectionOrder 1900
  Weapon.SlotNumber 4
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLAntiMaterielRifleClip"
  Weapon.AmmoType2 "Clip"
  Inventory.Icon "AMRFICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleZoom",1,2)
    AMRF A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Goto Ready+1
    ZOOM A 1 Bright A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD | WRF_NOBOB)
    Goto Ready+1
    Loop
  ReadyExtra:
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleZoom",1,2)
    AMRF A 1 A_WeaponReady (WRF_ALLOWZOOM)
    Goto Ready
    ZOOM A 1 Bright A_WeaponReady (WRF_ALLOWZOOM | WRF_NOBOB)
    Goto Ready
	
  ScavengerDrop:
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"WeaponDropConfirm")
	TNT1 A 0 A_GiveInventory("RLScavengerDrop",1)
	TNT1 A 0 A_Print("Press again to drop current weapon,\nor press \crAlt Fire\c- to scrap it to retrieve a Mod Pack.")
	Goto AfterModDrop
  WeaponDropConfirm:
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_TakeInventory("RLWeaponDrop",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
	TNT1 A 0 A_SpawnItemEx("RLAntiMaterielRiflePickup", 0, 0, 40, 8, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleSelected", 1)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleZoom",1)
	TNT1 A 0 A_ZoomFactor(1.0)
    TNT1 A 0 A_SetCrosshair (0)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLAntiMaterielRifle",1)
	Stop
	
  AfterModDrop:
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleZoom",1,2)
    AMRF A 8 A_WeaponReady (WRF_NOSECONDARY | WRF_ALLOWRELOAD)
    Goto Ready
    ZOOM A 8 Bright A_WeaponReady (WRF_NOSECONDARY | WRF_ALLOWRELOAD | WRF_NOBOB)
    Goto Ready
  MisfirePrevention:
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleZoom",1,3)
    AMRF A 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
    Goto Ready
    ZOOM A 1 Bright A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
    Goto Ready
	
  Deselect:
	TNT1 A 0
	TNT1 A 0 A_GiveInventory("RLDeselectionFunction",1)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleSelected", 1)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleZoom",1)
	TNT1 A 0 A_ZoomFactor(1.0)
    TNT1 A 0 A_SetCrosshair (0)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    TNT1 A 0 A_Lower
    AMRF A 1 A_Lower
    Loop
  DeselectRenegade:
    TNT1 A 0 A_Lower
    loop
  SelectRenegade: 
    TNT1 A 0 A_Raise
    loop
  SelectSetWeapon:
	TNT1 A 0 A_GiveInventory("RLMasterAssemblyTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLEfficientAmmoTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLSingleShotRifleTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLAntiMaterielRifleSelected", 1)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 1)
    Goto SelectLoop
	TNT1 A 0 A_GiveInventory("PowerRLTechnicianMasterDamage", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    TNT1 A 0 A_Raise
    AMRF A 1 A_Raise
    Loop
	
  Fire:
	AMRF A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	AMRF A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	AMRF A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	AMRF A 0 A_JumpIfInventory("RLRestrictionHighTechOnly",1,"HighTechRestricted") // Cannot fire in levels that restrict it
	AMRF A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleClip", 1, 1)
	Goto Reload
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 A_JumpIf(CallACS("DRLA_originalamr") == 1, "PILLOWBLASTERDEMANDSYOURBLOOD") // Uses the original OP AMR attack
	TNT1 AAAAAA 0 A_FireBullets(0, 0, -1, 100, "RLAMRPuff", FBF_USEAMMO | FBF_NORANDOM)
	TNT1 A 0 A_RailAttack (0, 0, 0, "DarkGray", "None", RGF_SILENT | RGF_NOPIERCING, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 16, 15, 0, "RLAntiMaterielRifleSmokeTrail", 0, 0)
	TNT1 A 0 A_RailAttack (0, 0, 0, "None", "DarkGray", RGF_SILENT | RGF_NOPIERCING, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 16, 15, 0, "RLAntiMaterielRifleSmokeRing", 0, 0)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleClip",1)
    Goto FireFinish
  PILLOWBLASTERDEMANDSYOURBLOOD:
	TNT1 A 0 A_RailAttack (100 * random(10,12), 0, 0, "DarkGray", "None", RGF_SILENT, 0, "RLAMRPuff", 0, 0, 0, 16, 15, 0, "RLAntiMaterielRifleSmokeTrail", 0, 0)
	TNT1 A 0 A_RailAttack (0, 0, 0, "None", "DarkGray", RGF_SILENT, 0, "RLParticleBeamCannonPuff2", 0, 0, 0, 16, 15, 0, "RLAntiMaterielRifleSmokeRing", 0, 0)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleClip",1)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLAMRRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/antimaterielrifle", CHAN_WEAPON, 1, 0, 0.3)
    TNT1 A 0 A_PlaySound("weapons/antimaterielrifle", 7, 0.05, 0, 0.10)
	TNT1 A 0 A_CheckFloor (2)
	TNT1 A 0 A_Jump(256,4)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingSteelBootsToken",1,4)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingProtectiveBootsToken",1,3)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingPlasteelBootsToken",1,2)
    TNT1 A 0 A_ChangeVelocity (Cos(Pitch) * -20, 0, Sin(Pitch) * 20, 1)
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleZoom",1,"FireFinishZoom")
    AMRF B 2 Bright A_GunFlash
    AMRF C 2 Bright
    AMRF DEFGHIJKA 2
	TNT1 A 0 A_JumpIf(CallACS("DRLA_AutoReload"), "Reload")
    Goto Ready
  FireFinishZoom:
    ZOOM B 22 Bright A_GunFlash
	TNT1 A 0 A_JumpIf(CallACS("DRLA_AutoReload"), "Reload")
    Goto Ready
	
  Reload:
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleClip", 1, "ReadyExtra")
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,2)
	TNT1 A 0 A_JumpIfInventory("Clip", 10, "ReloadCheck")
	Goto ReadyExtra
	TNT1 A 0 A_JumpIfInventory("Clip", 5, "ReloadCheck")
	Goto ReadyExtra
  ReloadCheck:
	TNT1 A 0 A_JumpIf(CallACS("DRLA_ScopeStay"), 2)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleZoom",1)
	TNT1 A 0 A_ZoomFactor(1.0)
    TNT1 A 0 A_SetCrosshair (0)
	TNT1 A 0 // Play the reload animation.
	TNT1 A 0 A_PlaySound("weapons/antimaterielrifleboltup", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLAMRReloadRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    AMRF L 2
    AMRF M 2
    AMRF N 4
	TNT1 A 0 A_PlaySound("weapons/antimaterielrifleboltback", CHAN_ITEM)
    AMRF O 2
    AMRF P 2
    AMRF Q 2
    AMRF R 6
  ReloadWorking:
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,3)
	TNT1 A 0 A_TakeInventory("Clip", 10, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_GiveInventory("RLAntiMaterielRifleClip", 1)
	Goto ReloadFinish
	TNT1 A 0 A_TakeInventory("Clip", 5, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_GiveInventory("RLAntiMaterielRifleClip", 1)
	Goto ReloadFinish
  ReloadFinish:
	TNT1 A 0 A_PlaySound("weapons/antimaterielrifleboltforward", CHAN_ITEM)
    AMRF S 2
    AMRF T 2
    AMRF U 4
	TNT1 A 0 A_PlaySound("weapons/antimaterielrifleboltdown", CHAN_ITEM)
    AMRF V 2
    AMRF W 2
    AMRF A 4
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleZoom",1,"ZoomInReload")
	Goto Ready
  Flash:
    TNT1 A 1 A_Light2
    TNT1 A 1 A_Light (5)
    TNT1 A 1 A_Light1
    TNT1 A 0 A_Light0
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLAntiMaterielRiflePickup",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION, 0, tid)
    Stop
	
  Altfire:
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate",1, "ArmorModConversion")
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"ScavengerTime")
	TNT1 A 0 A_JumpIfInventory("RLWeaponZoomCooldown",1,"Ready")
	TNT1 A 0 A_JumpIfInventory("RLAntiMaterielRifleZoom",1,"ZoomOut")
	Goto ZoomIn
  ZoomIn:
	TNT1 A 0 A_GiveInventory("RLWeaponZoomCooldown",1)
	TNT1 A 0 A_GiveInventory("RLAntiMaterielRifleZoom",1)
  ZoomInReload:
    TNT1 A 0 A_SetCrosshair (83)
    TNT1 A 0 A_PlaySound("weapons/antimaterielriflezoom", CHAN_ITEM, 1, 0, 4)
	ZOOM B 1 Bright A_ZoomFactor(1.25)
	ZOOM B 1 Bright A_ZoomFactor(2)
	ZOOM B 1 Bright A_ZoomFactor(3)
	ZOOM B 1 Bright A_ZoomFactor(3.75)
	TNT1 A 0 A_ZoomFactor(4.0)
	Goto Ready
  ZoomOut:
	TNT1 A 0 A_GiveInventory("RLWeaponZoomCooldown",1)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleZoom",1)
    TNT1 A 0 A_PlaySound("weapons/antimaterielriflezoom", CHAN_ITEM, 1, 0, 4)
	ZOOM B 1 Bright A_ZoomFactor(3.75)
	ZOOM B 1 Bright A_ZoomFactor(3)
	ZOOM B 1 Bright A_ZoomFactor(2)
	ZOOM B 1 Bright A_ZoomFactor(1.25)
	TNT1 A 0 A_ZoomFactor(1.0)
    TNT1 A 0 A_SetCrosshair (0)
	Goto Ready
	
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
    TNT1 A 0 A_GiveInventory("RLAntiMaterielRifleAssemblyLearntToken", 1) // Assembly is now listed in the HUD menus
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleZoom",1)
	TNT1 A 0 A_ZoomFactor(1.0)
    TNT1 A 0 A_SetCrosshair (0)
	TNT1 A 0 A_Print("Mod pack extracted from discarded weapon.")
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLAntiMaterielRifleSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
	TNT1 A 0 A_Jump(256,1,2,3,4)
	TNT1 A 0 A_FireCustomMissile("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLAgilityMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLSniperMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLAntiMaterielRifle",1)
	Stop
  }
}

//-------------------------------------------------------------------
//		PROJECTILES

ACTOR RLAntiMaterielRifleSmokeTrail
{
	+NOGRAVITY
	+NOCLIP
	+NOINTERACTION
	+FORCEXYBILLBOARD
	Alpha 0.5
	Scale 0.4
	RenderStyle Translucent
   States
   {
   Spawn:
      TNT1 A 0
      TNT1 A 0 A_SetScale (frandom(0.02, 0.4))
   Spawn2:
      GAUX FGHIJKL random(3,5) Bright A_FadeTo(0, frandom(0.01,0.08), 1)
      Stop
   }
}

ACTOR RLAntiMaterielRifleSmokeRing : RLAntiMaterielRifleSmokeTrail
{
	Alpha 0.4
   States
   {
   Spawn:
      TNT1 A 0
      TNT1 A 0 A_SetScale (frandom(0.75, 1.4))
   Spawn2:
      AMRS ABCDEF random(3,5) Bright A_FadeTo(0, frandom(0.05,0.2), 1)
      Stop
   }
}

//-------------------------------------------------------------------
//		MECHANICS

Actor RLAntiMaterielRifleSelected : RLPermanentInventory {}
Actor RLAntiMaterielRifleZoom : RLPermanentInventory {}

ACTOR RLAntiMaterielRifleClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 1
   Inventory.Icon ""
}

//-------------------------------------------------------------------
//		PICKUPS

ACTOR RLAntiMaterielRiflePickup : RLMasterAssembledWeaponPickup
{
	//$Sprite AMRFX0
	Tag "Anti-materiel Rifle [Pickup]"
	States
	{
	SpawnFrame:
		AMRF X 4
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
	SpawnLoop:
		"####" "#" 0 A_JumpIf(Abs(VelZ) <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 1
		Loop
	FloorHit:
		"####" "#" 0 A_PlaySound("weapons/gundropbig")
		"####" "#" 0 A_ScaleVelocity (0.25)
		"####" "#" 0 A_ChangeFlag("SPECIAL", true)
		"####" "#" 0 A_ChangeFlag("THRUACTORS", false)
		"####" "#" 0 A_SetUserVar("user_floorhit", 1)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Stop
	Pickup:
		"####" "#" 0
		"####" "#" 0 A_JumpIfInventory("RLAntiMaterielRifle",1,"NotPickup") // If the player already has this weapon, they are not given the weapon
		"####" "#" 0 A_JumpIfInventory("RLWeaponLimit",0,"NotPickupLimit") // The absolute max limit check for weapons
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLAntiMaterielRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up an \cvAnti-materiel Rifle.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_Jump(256, "NotPickup")
		Goto NotPickup
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= Anti-materiel Rifle =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/AntiMaterielRiflepickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonGrenades",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	SuperweaponStuff:
		"####" "#" 0 A_Jump(256, "NoSpecialStartsStuff")
		Goto NoSpecialStartsStuff
	}
}

ACTOR RLAntiMaterielRifleWorldSpawnPickup : RLAntiMaterielRiflePickup 17841
{
	States
	{
	NoSpecialStartsStuff:
		TNT1 A 0 A_JumpIf(CallACS("DRLA_opengl"), 3) // If enabled, rarity beam will be cyan, rather than blue
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamAssembledWorld", 0, 0, 0, 0, 0, 0, 0, SXF_SETMASTER)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamAssembledWorldDRPG", 0, 0, 0, 0, 0, 0, 0, SXF_SETMASTER)
		TNT1 A 0 A_JumpIf(CallACS("DRPGCheckTiem"), "DRPGInit")
	SpawnFrame:
		AMRF X 4
		"####" "#" 0 A_GiveInventory("RLMasterItemSpawnMessageSender",1)
		"####" "#" 0 A_PlaySound("weapons/masterspawned", 7, 0.25, 0, 0)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
		
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLAntiMaterielRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up an \cvAnti-materiel Rifle.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}
