---------------------------

function Gameplay.setup()
	if not Gameplay.connections.respawnCharacterAddedConn then
		Gameplay.connections.respawnCharacterAddedConn = Players.LocalPlayer.CharacterAdded:Connect(function()
			Gameplay.setup()
		end)
	end

	WeaponsSystem.setGetTeamCallback(function(player)
		return PlayerMatchInfo.GetField(player, "teamNumber")
	end)

	BuildingSystem.setEnabled(false)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

	local skydiver = Skydiver.new()
	skydiver:setEnabled(false)
	skydiver:setOnDisabled(Gameplay.onSkydiverDisabled)

	if not PlayerMatchInfo.GetField(Players.LocalPlayer, "didJump") then
		-- Initialize minimap and focus on delivery vehicle for player's team (or the one delivery vehicle if no teams)
		local deliveryVehicle = Workspace:WaitForChild("DeliveryVehicle" .. tostring(PlayerMatchInfo.GetField(Players.LocalPlayer, "teamNumber")))
		Util.setClientFocus(deliveryVehicle)

		-- Get orientation of delivery vehicle to give to minimap for dividing line in team mode
		local dividingAngle = nil
		if Conf.num_teams == 2 then
			dividingAngle = 90 - deliveryVehicle:WaitForChild("Root").Orientation.Y
		end
		MinimapGui.start(dividingAngle)

		-- Focus the camera on the bus
		WeaponsSystem.camera:setEnabled(false)
		WeaponsSystem.gui:setEnabled(false)
		Workspace.CurrentCamera.CameraSubject = deliveryVehicle:WaitForChild("Root")
		Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		Players.LocalPlayer.CameraMinZoomDistance = MIN_DELIVERY_CAMERA_DISTANCE

		-- Wait for it to be safe to skydive
		local readyValue = deliveryVehicle:WaitForChild("Ready")
		if not readyValue.Value then
			readyValue.Changed:Wait()
		end

		-- Display the prompt and allow the player to jump out of the bus
		skydiver:setWaitingForJump(true)

		-- Yield until the player jumps out of the bus
		skydiver:waitForJumped()

		-- Mark the player as having jumped out of the bus
		PlayerMatchInfo.UpdateField(Players.LocalPlayer, "didJump", true)
	end

	-- Start skydiving
	skydiver:setEnabled(true)

	-- Focus minimap on player instead of bus
	Util.setClientFocus(Players.LocalPlayer.Character)

	-- Reenable the weapon system camera now that the player is skydiving
	WeaponsSystem.camera:setEnabled(true)
	Players.LocalPlayer.CameraMinZoomDistance = StarterPlayer.CameraMinZoomDistance

	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, Conf.gameplay.gameplay_chat_enabled)
end

function Gameplay.onSkydiverDisabled()
	BuildingSystem.setEnabled(true)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
end

function Gameplay.shutdown()
end
