
/*---------------------------------------------------------

  Sandbox Gamemode

  This is GMod's default gamemode

---------------------------------------------------------*/


GM.Name 	= "Sandbox"
GM.Author 	= "TEAM GARRY"
GM.Email 	= "teamgarry@garrysmod.com"
GM.Website 	= "www.garrysmod.com"

cleanup.Register( "props" )
cleanup.Register( "ragdolls" )
cleanup.Register( "effects" )
cleanup.Register( "npcs" )
cleanup.Register( "constraints" )
cleanup.Register( "ropeconstraints" )
cleanup.Register( "sents" )

include( "player_extension.lua" )

/*---------------------------------------------------------
   Name: gamemode:CanConstrain( ply, trace, mode )
   Return true if the player is allowed to do this constrain
---------------------------------------------------------*/
function GM:CanConstrain( ply, trace, mode )

	// Not allowed to constrain their fellow players
	if (trace.Entity:IsValid() && trace.Entity:IsPlayer()) then
		return false
	end
	
	// Give the entity a chance to decide
	if ( trace.Entity:GetTable().CanConstrain ) then
		return trace.Entity:GetTable():CanConstrain( ply, trace, mode )
	end
	
	//Msg( "Can Constrain "..mode.."\n" )

	return true
	
end

/*---------------------------------------------------------
   Name: gamemode:CanConstruct( ply, trace, mode )
   Return true if the player is allowed to do this construction
---------------------------------------------------------*/
function GM:CanConstruct( ply, trace, mode )

	if ( mode == "remover" && !trace.Entity:IsValid()) then
		return false
	end
	
	// The jeep spazzes out when applying something
	// todo: Find out what it's reacting badly to and change it in _physprops
	if ( mode == "physprop" && trace.Entity:IsValid() && trace.Entity:GetClass() == "prop_vehicle_jeep" ) then
		return false
	end
	
	// Give the entity a chance to decide
	if ( trace.Entity:GetTable().CanConstruct ) then
		return trace.Entity:GetTable():CanConstruct( ply, trace, mode )
	end

	return true
	
end

/*---------------------------------------------------------
   Name: gamemode:CanPose( ply, trace, mode )
   Return true if the player is allowed to do this constrain
---------------------------------------------------------*/
function GM:CanPose( ply, trace, mode )
	return true
end

/*---------------------------------------------------------
   Name: gamemode:CanRender( ply, trace, mode )
   Return true if the player is allowed to do this constrain
---------------------------------------------------------*/
function GM:CanRender( ply, trace, mode )
	return true
end

/*---------------------------------------------------------
   Name: gamemode:CanTool( ply, trace, mode )
   Return true if the player is allowed to use this tool
---------------------------------------------------------*/
function GM:CanTool( ply, trace, mode )

	// The jeep spazzes out when applying something
	// todo: Find out what it's reacting badly to and change it in _physprops
	if ( mode == "physprop" && trace.Entity:IsValid() && trace.Entity:GetClass() == "prop_vehicle_jeep" ) then
		return false
	end
	
	// Give the entity a chance to decide
	if ( trace.Entity:GetTable().CanTool ) then
		return trace.Entity:GetTable():CanTool( ply, trace, mode )
	end

	return true
	
end


/*---------------------------------------------------------
   Name: gamemode:GravGunPunt( )
   Desc: We're about to punt an entity (primary fire).
		 Return true if we're allowed to.
---------------------------------------------------------*/
function GM:GravGunPunt( ply, ent )

	if ( ent:IsValid() && ent:GetTable().GravGunPunt ) then
		return ent:GetTable():GravGunPunt( ply )
	end

	return self.BaseClass:GravGunPunt( ply, ent )
	
end

/*---------------------------------------------------------
   Name: gamemode:GravGunPickupAllowed( )
   Desc: Return true if we're allowed to pickup entity
---------------------------------------------------------*/
function GM:GravGunPickupAllowed( ply, ent )

	if ( ent:IsValid() && ent:GetTable().GravGunPickupAllowed ) then
		return ent:GetTable():GravGunPickupAllowed( ply )
	end

	return self.BaseClass:GravGunPickupAllowed( ply, ent )
	
end

/*---------------------------------------------------------
   Name: gamemode:PhysgunPickup( )
   Desc: Return true if player can pickup entity
---------------------------------------------------------*/
function GM:PhysgunPickup( ply, ent )

	if ( ent:IsValid() && ent:GetTable().PhysgunPickup ) then
		return ent:GetTable():PhysgunPickup( ply )
	end

	return self.BaseClass:PhysgunPickup( ply, ent )
	
end
