include( "shared.lua" );

AddCSLuaFile( "cl_init.lua" );
AddCSLuaFile( "shared.lua" );

function ENT:Initialize()
	self:SetSolid( SOLID_NONE );
	self:SetNotSolid( true );
	self:SetMoveType( MOVETYPE_NONE );
	self:SetCollisionBounds( Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
end

function ENT:OnTakeDamage( damageInfo ) end;
function ENT:PhysicsCollide( data, physicsObject ) end;
function ENT:Touch( entity ) end;
function ENT:Use( activator, caller ) end;

function ENT:OnRemove()
	if ( self:GetOwner() ) then
		self:GetOwner().AnimatedLegs = nil;
	end;
end;

function ENT:Think()
	local curTime = CurTime();
	local owner = self:GetOwner();
	
	if ( owner and owner:Alive() ) then
		local playerYaw = owner:GetPoseParameter( "move_yaw" );
		local legsYaw = self:GetPoseParameter( "move_yaw" );
		
		if ( playerYaw != legsYaw ) then
			self:SetPoseParameter( "move_yaw", playerYaw );
		end;
		
		local velocity = owner:GetVelocity():Length();
		local sequence = owner:GetSequence();
		local model = owner:GetModel();
		
		if ( owner:InVehicle() ) then
			local vehicle = owner:GetVehicle();
			local entityModel = string.lower( vehicle:GetModel() );
			
			if ( ValidEntity( vehicle ) ) then
				if ( !string.find( entityModel, "prisoner" ) ) then
					self:SetPoseParameter( "vehicle_steer", owner:GetVehicle():GetPoseParameter( "vehicle_steer" ) );
				end;
			end;
		end;
		
		if ( !self.NextSecond or curTime >= self.NextSecond ) then
			self.NextSecond = curTime + 1;
			
			self:SetSkin( owner:GetSkin() );
			self:SetColor( owner:GetColor() );
			self:SetMaterial( owner:GetMaterial() );
		end;
		
		if ( self.Animation != sequence ) then
			self.Animation = sequence;
			
			self:SetPlaybackRate( owner:GetKeyValues().playbackrate );
			self:ResetSequence( self.Animation );
			self:SetCycle( 0 );
		end;
		
		if ( self:GetModel() != model ) then
			self:SetModel( model );
		end;
		
		self:SetAngles( owner:GetAngles() );
		self:NextThink( curTime );
		
		return true;
	else
		self:Remove();
	end;
end;