
ACTOR RLMarksmanRifle : RLWeapon
{
  Obituary "%o was assassinated by %k's marksman rifle."
  Decal BulletChip
  Tag "Marksman Rifle"
  Weapon.SelectionOrder 25
  Weapon.SlotNumber 4
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLMarksmanRifleClip"
  Weapon.AmmoType2 "Clip"
  Inventory.Icon "MRKRICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleNanoMod",1,"NanoRegenCheck")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,2)
    MRKR A 1 A_WeaponReady (WRF_ALLOWRELOAD | WRF_ALLOWZOOM)
    Goto Ready
    ZOOM A 1 Bright A_WeaponReady (WRF_ALLOWRELOAD | WRF_ALLOWZOOM | WRF_NOBOB)
    Goto Ready
  NanoRegenCheck:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip",1,"NanoRegenCheckBegin")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,2)
    MRKR A 70 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
	Goto NanoRegenCheckBegin
    ZOOM B 70 Bright A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM | WRF_ALLOWRELOAD | WRF_NOBOB)
	Goto NanoRegenCheckBegin
  NanoRegenCheckBegin:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,2)
    MRKR A 70 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
	Goto NanoRegenCheckBegin2
    ZOOM A 70 Bright A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD | WRF_NOBOB)
	Goto NanoRegenCheckBegin2
  NanoRegenCheckBegin2:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip", 15, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip", 20, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip", 25, "Ready")
	Goto NanoRegen
  NanoRegen:
	TNT1 A 0 A_GiveInventory("RLMarksmanRifleClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleNanoMod",2,"NanoRegen2")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,2)
    MRKR A 17 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Goto NanoRegenCheckBegin2
    ZOOM A 17 Bright A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD | WRF_NOBOB)
    Goto NanoRegenCheckBegin2
  NanoRegen2:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,2)
    MRKR A 9 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Goto NanoRegenCheckBegin2
    ZOOM A 9 Bright A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD | WRF_NOBOB)
    Goto NanoRegenCheckBegin2
	
  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("RLMarksmanRifleZoom",1)
    TNT1 A 0 A_SetCrosshair (0)
	TNT1 A 0 A_ZoomFactor(1.0)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_TakeInventory("RLWeaponDrop",1)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleModLimit", 1, "WeaponDropModded")
	TNT1 A 0 A_SpawnItemEx("RLMarksmanRiflePickup", 0, 0, 40, 12, 0, 0, 0, SXF_SETMASTER)
	Goto WeaponDropRemoval
  WeaponDropModded:
	TNT1 A 2 A_SpawnItemEx("RLMarksmanRiflePickupModded", 0, 0, 40, 12, 0, 0, 0, SXF_SETMASTER)
  WeaponDropRemoval:
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleModLimit", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRiflePowerMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleBulkMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleAgilityMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleTechnicalMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHighPowerMarksmanRifleConfirm",1)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLMarksmanRifle",1)
	Stop
	
  AfterModDrop:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,2)
    MRKR 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:
    MRKR A 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
    Goto Ready
	
  Deselect:
	TNT1 A 0
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleZoom",1)
    TNT1 A 0 A_SetCrosshair (0)
	TNT1 A 0 A_ZoomFactor(1.0)
	TNT1 A 0 A_GiveInventory("RLDeselectionFunction",1)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    TNT1 A 0 A_Lower
    MRKR 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("RLRapidfireTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLSingleShotRifleTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLSuperiorWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLMarksmanRifleSelected", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    TNT1 A 0 A_Raise
    MRKR A 1 A_Raise
    Loop
	
  Fire:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerMarksmanRifleConfirm",1, "AssembleHighPowerMarksmanRifle")
	
	MRKR A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	MRKR A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	MRKR A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	MRKR A 0 A_JumpIfInventory("RLRestrictionHighTechOnly",1,"HighTechRestricted") // Cannot fire in levels that restrict it
	MRKR A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfNoAmmo("Reload")
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleSniperMod",1,"FireS")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRiflePowerMod",1,"FireP")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAgilityMod",1,"FireA")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",3,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0.5, 0.5, -1, 18 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0.5, 0.5, -1, 18 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireP:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRiflePowerMod",2,"FirePP")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAgilityMod",1,"FirePA")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",3,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0.5, 0.5, -1, 23 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0.5, 0.5, -1, 23 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireA:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRiflePowerMod",1,"FirePA")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAgilityMod",2,"FireAA")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",3,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, -1, 18 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, -1, 18 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FirePP:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",3,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0.5, 0.5, -1, 28 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0.5, 0.5, -1, 28 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FirePA:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",3,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, -1, 23 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, -1, 23 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireAA:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",3,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, -1, 18 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, -1, 18 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireS:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleSniperMod",2,"FireSS")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRiflePowerMod",1,"FireSP")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAgilityMod",1,"FireSA")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",4,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 18 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 18 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireSS:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",4,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 18 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 18 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireSP:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",4,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 23 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 23 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireSA:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",4,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 18 + random(1,3), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 18 + random(1,3), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
	
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLPlasmaShotgunRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/marksmanrifle", CHAN_WEAPON, 1, 0, 0.7)
    TNT1 A 0 A_PlaySound("weapons/marksmanrifle", 7, 0.05, 0, 0.20)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,"FireFinishPowerupCheck") // Check for powerups.
  FireFinishPowerupCheckDone: // No valid powerups detected.
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleFirestormMod",2,"FireFinishFF")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleFirestormMod",1,"FireFinishF")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,"FireFinishScoped")
    MRKR B 2 Bright A_GunFlash
    MRKR C 2 Bright
    MRKR D 2
    MRKR A 1
    Goto FireFinishContinue
  FireFinishF:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,"FireFinishFScoped")
    TNT1 A 0 A_SpawnItemEx ("RLBattleRifleRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MRKR B 2 Bright A_GunFlash
    MRKR C 2 Bright
    MRKR D 1
    Goto FireFinishContinue
  FireFinishFF:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,"FireFinishFFScoped")
    TNT1 A 0 A_SpawnItemEx ("RLBattleRifleRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MRKR B 1 Bright A_GunFlash ("FlashFF")
    MRKR C 1 Bright
    MRKR D 1
    Goto FireFinishContinue
	
  FireFinishScoped:
    ZOOM B 8 Bright A_GunFlash
    Goto FireFinishContinue
  FireFinishFScoped:
    ZOOM B 6 Bright A_GunFlash
    Goto FireFinishContinue
  FireFinishFFScoped:
    ZOOM B 4 Bright A_GunFlash ("FlashFF")
    Goto FireFinishContinue
	
  FireFinishContinue:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleAmmochain",3,2)
	TNT1 A 0 A_Jump(256,3)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleAmmochain",3)
    TNT1 A 0 A_ReFire
    Goto Ready
	TNT1 A 0 A_GiveInventory("RLMarksmanRifleAmmochain",1)
    TNT1 A 0 A_ReFire
    Goto Ready

//-------------------------------------------------------------------------------------------------
  FireFinishPowerupCheck: // Marine fires one Firestorm's worth faster while affected by powerups.
	TNT1 A 0 A_JumpIfInventory("PowerInvulnerable",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerInvisibility",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerIronFeet",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerLightAmp",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerInfiniteAmmo",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerDrain",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerRLBerserkResistance",1,"FireFinishPowerupCheckConfirmed")
	Goto FireFinishPowerupCheckDone
  FireFinishPowerupCheckConfirmed:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleFirestormMod",1,"FireFinishFF")
	Goto FireFinishF
//-------------------------------------------------------------------------------------------------
	
  ReloadCheckZoomed:
	ZOOM B 1 Bright A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM | WRF_NOBOB)
	Goto Reload+3
  Reload:
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,"ReloadCheckZoomed")
	MRKR A 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip", 15, "Ready")
	Goto ReloadStartingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip", 20, "Ready")
	Goto ReloadStartingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip", 25, "Ready")
  ReloadStartingAmmoCheck:
	TNT1 A 0 A_JumpIfInventory("Clip", 1, 1)
	Goto Ready
	TNT1 A 0 A_JumpIf(CallACS("DRLA_ScopeStay"), 2)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleZoom",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_JumpIfInventory("RLMarksmanRifleTechnicalMod",2,"Reload2")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleTechnicalMod",1,"Reload1")
    MRKR E 2
    MRKR F 2
    MRKR G 2
    MRKR H 2
    MRKR I 2
    TNT1 A 0 A_PlaySound("weapons/marksmanrifleunload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MRKR J 2
    MRKR K 2
    MRKR L 18
    MRKR M 2
    MRKR N 2
	Goto ReloadWorking
  Reload1:
    MRKR E 2
    MRKR F 2
    MRKR G 2
    MRKR H 2
    MRKR I 2
    TNT1 A 0 A_PlaySound("weapons/marksmanrifleunload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MRKR J 2
    MRKR K 2
    MRKR L 15
    MRKR M 2
    MRKR N 2
	Goto ReloadWorking
  Reload2:
    MRKR E 2
    MRKR F 2
    MRKR G 2
    MRKR H 2
    MRKR I 2
    TNT1 A 0 A_PlaySound("weapons/marksmanrifleunload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    MRKR J 2
    MRKR K 2
    MRKR L 12
    MRKR M 2
    MRKR N 2
	Goto ReloadWorking
  ReloadWorking:
	TNT1 A 0 A_TakeInventory("Clip", 1)
	TNT1 A 0 A_GiveInventory("RLMarksmanRifleClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip",15,5)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip",20,3)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleClip",25,2)
  ReloadWorkingAmmoCheck:
	TNT1 A 0 A_JumpIfInventory("Clip",1,2)
	TNT1 A 0
	Goto ReloadFinish
	TNT1 A 0
	Goto ReloadWorking
  ReloadFinish:
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadInRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/marksmanrifleload", 7)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleTechnicalMod",2,"ReloadFinish2")
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleTechnicalMod",1,"ReloadFinish1")
    MRKR O 2
    MRKR P 2
    MRKR Q 2
    MRKR R 2
    MRKR S 2
    TNT1 A 0 A_PlaySound("weapons/marksmanriflecock", CHAN_ITEM)
    MRKR T 2
    MRKR U 2
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,"ZoomInReload")
    MRKR A 2 A_Refire
	Goto Ready
  ReloadFinish1:
    MRKR O 2
    MRKR P 2
    MRKR Q 2
    MRKR R 2
    MRKR S 1
    TNT1 A 0 A_PlaySound("weapons/marksmanriflecock", CHAN_ITEM)
    MRKR T 1
    MRKR U 1
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,"ZoomInReload")
    MRKR A 2 A_Refire
	Goto Ready
  ReloadFinish2:
    MRKR O 2
    MRKR P 1
    MRKR Q 1
    MRKR R 1
    MRKR S 1
    TNT1 A 0 A_PlaySound("weapons/marksmanriflecock", CHAN_ITEM)
    MRKR T 1
    MRKR U 1
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleZoom",1,"ZoomInReload")
    MRKR A 2 A_Refire
	Goto Ready
	
  Flash:
    TNT1 A 1 A_Light2
    TNT1 A 1 A_Light1
    TNT1 A 0 A_Light0
    Goto LightDone
  FlashFF:
    TNT1 A 0 A_Jump (128, 3)
    TNT1 A 1 A_Light2
    TNT1 A 0 A_Light0
    Goto LightDone
    TNT1 A 1 A_Light1
    TNT1 A 0 A_Light0
    Goto LightDone
	
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLMarksmanRiflePickup",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("RLMarksmanRifleZoom",1,"ZoomOut")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerMarksmanRifleConfirm",1, "CancelAssembly")
	Goto ZoomIn
  ZoomIn:
	TNT1 A 0 A_GiveInventory("RLWeaponZoomCooldown",1)
	TNT1 A 0 A_GiveInventory("RLMarksmanRifleZoom",1)
  ZoomInReload:
    TNT1 A 0 A_PlaySound("weapons/marksmanriflezoomin", CHAN_ITEM, 1, 0, 4)
    TNT1 A 0 A_SetCrosshair (83)
	ZOOM B 1 Bright A_ZoomFactor(1.25)
	ZOOM B 1 Bright A_ZoomFactor(1.5)
	ZOOM B 1 Bright A_ZoomFactor(1.75)
	TNT1 A 0 A_ZoomFactor(2.0)
	Goto Ready
  ZoomOut:
	TNT1 A 0 A_GiveInventory("RLWeaponZoomCooldown",1)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleZoom",1)
    TNT1 A 0 A_PlaySound("weapons/marksmanriflezoomout", CHAN_ITEM, 1, 0, 4)
    TNT1 A 0 A_SetCrosshair (0)
	ZOOM B 1 Bright A_ZoomFactor(1.75)
	ZOOM B 1 Bright A_ZoomFactor(1.5)
	ZOOM B 1 Bright A_ZoomFactor(1.25)
	TNT1 A 0 A_ZoomFactor(1.0)
	Goto Ready
  CancelAssembly:
	TNT1 A 0 A_Print("Assembly canceled.")
  CancelAssembly2:
	TNT1 A 0 A_PlaySound("hud/assemblycancel", 5)
	TNT1 A 0 A_TakeInventory("RLHighPowerMarksmanRifleConfirm",1)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	Goto MisfirePrevention
  ModDiscombobulation:
	TNT1 A 0 A_Print("Applied Mod pack extracted from discarded weapon.")
	TNT1 A 0 ACS_NamedExecuteAlways("ScavengeMods", 0)
	TNT1 A 3
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleModLimit", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRiflePowerMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleBulkMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleAgilityMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleTechnicalMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleFirestormMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHighPowerMarksmanRifleConfirm",1)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	Goto ScavengerTimeEnd
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleZoom",1)
    TNT1 A 0 A_SetCrosshair (0)
	TNT1 A 0 A_ZoomFactor(1.0)
	TNT1 A 0 A_JumpIfInventory("RLMarksmanRifleModLimit",1,"ModDiscombobulation")
	TNT1 A 0 A_Print("Mod pack extracted from discarded weapon.")
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleModLimit", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRiflePowerMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleBulkMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleAgilityMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleTechnicalMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleFirestormMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHighPowerMarksmanRifleConfirm",1)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleZoom",1)
	TNT1 A 0 A_ZoomFactor(1.0)
    TNT1 A 0 A_StopSound(6)
	TNT1 A 0 A_GiveInventory("RLEmitScavengedModSuperior", 1) // Determines what mods this can generate when scavenged.
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLMarksmanRifle",1)
	Stop
  AssembleHighPowerMarksmanRifle:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerMarksmanRifle",1, "AlreadyHaveAssembly")
	TNT1 A 0 A_GiveInventory("RLDangerLevelBasicGiver",1, AAPTR_PLAYER1)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleZoom",1)
    TNT1 A 0 A_SetCrosshair (0)
	TNT1 A 0 A_ZoomFactor(1.0)
	TNT1 A 0 A_Print("\cvHigh Power Marksman Rifle \c-assembled.")
    TNT1 A 0 A_PlaySound("weapons/assembly", CHAN_ITEM)
	TNT1 A 0 A_TakeInventory("RLMarksmanRifleSelected", 1)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleModLimit", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRiflePowerMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleBulkMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleAgilityMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleTechnicalMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLMarksmanRifleNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHighPowerMarksmanRifleConfirm",1)
	TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, 2)
	TNT1 A 0 A_Jump(256, 2)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_GiveInventory("RLHighPowerMarksmanRifle",1)
	TNT1 A 0 A_SelectWeapon("RLHighPowerMarksmanRifle")
	TNT1 A 0 A_TakeInventory("RLMarksmanRifle",1)
	Stop
  }
}

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

Actor RLMarksmanRifleSelected : RLPermanentInventory {}
Actor RLMarksmanRifleZoom : RLPermanentInventory {}
Actor RLMarksmanRifleAmmochain : RLAmmochainDefault {}

Actor RLMarksmanRifleModLimit : RLSuperiorModAmount {}
Actor RLMarksmanRiflePowerMod : RLSuperiorModAmount {}
Actor RLMarksmanRifleBulkMod : RLSuperiorModAmount {}
Actor RLMarksmanRifleAgilityMod : RLSuperiorModAmount {}
Actor RLMarksmanRifleTechnicalMod : RLSuperiorModAmount {}
Actor RLMarksmanRifleFirestormMod : RLSuperiorModAmount {}
Actor RLMarksmanRifleNanoMod : RLSuperiorModAmount {}
Actor RLMarksmanRifleSniperMod : RLSuperiorModAmount {}

ACTOR RLMarksmanRifleClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 25
   Inventory.Icon ""
}

ACTOR RLMarksmanRiflePickup : RLSuperiorWeaponPickup 17000
{
	//$Sprite MRKRX0
	Tag "Marksman Rifle [Pickup]"
	States
	{
	SpawnFrame:
		MRKR X 4
	SpawnLoop:
		"####" "#" 0 A_JumpIf(Abs(VelZ) <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 1
		Loop
	FloorHit:
		"####" "#" 0 A_PlaySound("weapons/gundropmedium")
		"####" "#" 0 A_ScaleVelocity (0.5)
		"####" "#" 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("RLSynthFireReload",1,"AmmoPickup") // If the player is holding reload, pickup the gun for ammo.
		"####" "#" 0 A_JumpIfInventory("RLMarksmanRifle",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("RLMarksmanRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \ciMarksman Rifle.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_Jump(256, "NotPickupNothing")
		Goto NotPickupNothing
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("Clip",0,"NotPickupNothing")
		Goto AmmoPickup
	NotPickupNothing:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\ci= Marksman Rifle =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	AmmoPickup:
		"####" "#" 0
		"####" "#" 0 A_JumpIfInventory("Clip",0,"NotPickupNothing")
		"####" "#" 1 A_GiveInventory("Clip",15)
		Goto PickupSound
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/MarksmanRiflepickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonClip",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	}
}

ACTOR RLMarksmanRiflePickupModded : RLMarksmanRiflePickup
{
	+INVENTORY.TRANSFER
	+DONTGIB
	States
	{
	Spawn:
		TNT1 A 0 NoDelay ACS_NamedExecuteAlways("GetWeaponMods", 0)
		TNT1 A 0 A_JumpIf(CallACS("DRLA_specialstarts") == 0, "NoSpecialStartsStuff")
		"####" "#" 0 A_Jump(256, "SpecialStartsStuff")
		Goto SpecialStartsStuff
		
	SpawnFrame:
		MRKR X 4
	SpawnLoop:
		"####" "#" 0 A_JumpIf(VelZ <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 0 ACS_NamedExecuteAlways("RLWeaponModDisplay", 0)
		"####" "#" 1
		Loop
		
	Pickup:
		"####" "#" 0
		"####" "#" 0 A_JumpIfInventory("RLMarksmanRifle",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("RLMarksmanRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cbmodded \ciMarksman Rifle.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\ci= Marksman Rifle =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("RLMarksmanRifleModLimit", 1, "NotPickup_Modded")
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\ci= Marksman Rifle =\n\n\ccYou replace your unmodded\n\ccweapon with the one you picked up.", 5, "CONFONT")
		"####" "#" 0 A_GiveInventory("Clip",15)
		Goto PickupSound
	NotPickup_Modded:
		"####" "#" 0 A_Print("\ci= Marksman Rifle =\n\n\caYou are already carrying a modded\n\caweapon of this type", 5, "CONFONT")
		Fail
	}
}
