
/*---------------------------------------------------------
   Clientside Vehicles Base
---------------------------------------------------------*/

// Note: Vehicles aren't done yet. This is all just a placeholder.


ENT.Base			= "base_anim"
ENT.Type 			= "vehicle"


function ENT:SetupModel()

	self.Entity:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )

end


function ENT:SetupPhysics()

	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetCollisionGroup( COLLISION_GROUP_NONE )
	
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	
end

function ENT:SetupPhysicsShadow()

	self.Entity:SetMoveType( MOVETYPE_NONE )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:SetCollisionGroup( COLLISION_GROUP_INTERACTIVE )
	
	self.Entity:PhysicsInitShadow( false, false )
	
end

function ENT:SharedInitialize()

	// In singleplayer we do all the controls and stuff on the server
	// In multiplayer we do it all on the client and grab
	self.DoProcessing = false
	if (CLIENT && !SinglePlayer() || SERVER && SinglePlayer()) then
		self.DoProcessing = true
	end
	
	self:SetupModel()
	self:ReConfigurePhysics()

end

//
// Reconfigures the physics situation. 
// This needs to be called every time the driver changes
//
function ENT:ReConfigurePhysics()

	if ( CLIENT ) then
	
		if ( self:GetDriver() == LocalPlayer() && !SinglePlayer() ) then
			// If the current driver is the local player then predict the physics object
			self:SetupPhysics()
		else
			// Else make a physics shadow (so other objects can bump into us)
			self:SetupPhysicsShadow()
		end
	
	else
	
		if ( SinglePlayer() ) then
			// If we're in singleplayer the vehicle is 100% serverside
			self:SetupPhysics()
		else
			// If not we're a shadow on the server
			self:SetupPhysicsShadow()
		end
	
	end

end


function ENT:GetDriver()
	return self.Entity:GetNetworkedEntity( "driver" )
end


function ENT:SetDriver( ply )

	self.Entity:SetNetworkedEntity( "driver", ply )
	ply:SetNetworkedEntity( "vehicle", self.Entity )
	
	ply:Spectate( OBS_MODE_CHASE )
	ply:SpectateEntity( self.Entity )
	ply:SetPos( self.Entity:GetPos() )
	ply:SetParent( self.Entity )
	
	if ( !SinglePlayer() ) then
		ply:SetClientsideVehicle( self.Entity )
	end
	
	self:ReConfigurePhysics()

end

function ENT:Think()

	// The client needs to pick up on new drivers
	if ( CLIENT && self.OldDriver != self:GetDriver() ) then
	
		self:ReConfigurePhysics()
		self.OldDriver = self:GetDriver()
	
	end

end
