if GS_RAILS_SKINS==nil rawset(_G,"GS_RAILS_SKINS",{}) end --Make sure your own lump has this line too!

local RAIL = GS_RAILS if RAIL and RAIL.blockload return end --Don't include this part in your own file

--Now for Samus support. This one's a bit tough...
for i = 1,2
	local NAME = (i==2) and "samus" or "basesamus"
	if GS_RAILS_SKINS[NAME]==nil 
		GS_RAILS_SKINS[NAME] = {}
		local SKIN = GS_RAILS_SKINS[NAME]
		
		SKIN["S_SKIN"] = {
		AIRDRAG = 16,
		CROUCH = true,
		CROUCHBUTTON = BT_CUSTOM1|BT_SPIN,
		AUTOBALANCE = false,
		
		ACCELCAP = 120, --Only do-able during Morph Ball.
		HEROESTWIST = 26, --Only do-able outside of Morph Ball.
		TWISTBUTTON = BT_CUSTOM1|BT_SPIN,
		
		AUTOVERTICALAIM = false, --Obviously Samus wants to be able to aim.
		NOFUNALLOWED = true, --Causes issues, unfortunately. Will add some custom behaviour instead.
		}
		
		--Let's keep Samus the right size here.
		SKIN["CustomAnim"] = function(p, s, GS, rail, POSTTHINK, ANIMCALL) 
		
			if p.sammorphed and (MetroidVanguard) --Don't be morphed!
				MetroidVanguard.UnMorph(s)
			end
			p.sams_morphcd = 5
			
			if GS.flipanim
				if POSTTHINK==true GS.animcall = "stop" end
				return --
			end
			if type(ANIMCALL)=="string" return end
			
			local SAMSKIN = GS_RAILS_SKINS[s.skin]
			s.sprite = SPR_SAMU
			
			if (p.cmd.buttons & (BT_TOSSFLAG|BT_CUSTOM1|BT_CUSTOM2)) --Fake MorphBall mode. 
				local TIME = leveltime or 0
				s.frame = ($ & ~FF_FRAMEMASK)|((TIME%4==0) and E or (TIME%3==0) and D or (TIME%2==0) and C or B)	
				s.spritexscale,s.spriteyscale,s.spriteyoffset = 26000,26000,0 --Fake MorphBall!
				GS.stretch = {timer = 2, Xspeed = 1, Yspeed = 1}	
				SAMSKIN.ACCELSPEED = 50	
				SAMSKIN.HEROESTWIST = 0
				SAMSKIN.CROUCH = false
				SAMSKIN.AUTOBALANCE = true
				p.sams_mshotcd, p.sams_shotcd, p.weapondelay = 11,11,11
			else --Use shooting pose for grinding.
				s.frame = ($ & ~FF_FRAMEMASK)|((s.skin=="basesamus") and F or A)
				SAMSKIN.ACCELSPEED = 0
				SAMSKIN.HEROESTWIST = 26
				SAMSKIN.CROUCH = true
				SAMSKIN.AUTOBALANCE = false
				s.mirrored = false
			end	
			if (POSTTHINK!=true) 
				if (abs(GS.railspeed or 0) > 39<<16) --Feels a bit like Zero Mission this way.
					local ghs = P_SpawnGhostMobj(s)
					ghs.scale = s.scale
					ghs.color,ghs.colorized = (leveltime%2) and s.color or SKINCOLOR_KETCHUP, true
					ghs.blendmode = AST_ADD
					ghs.fuse,ghs.tics = 7,8
					ghs.destscale = 1
				end 
				return false --
			end
			GS.animcall = "stop"
		end		
	end
end