//////////////////////////////////////////////////////////////////////////////
//
// Asura_Platform_Rewards_System.cpp
//
// Copyright (c) 2009 Rebellion. All rights reserved.
//
// Description:
//
//     Engine class to unify platform Reward (achievement) systems
//
//////////////////////////////////////////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

#include "Core/Asura.h"

#ifdef ASURA_USE_REWARDS

// This file's header.
#include "Rewards/Asura_Rewards_System.h"

#include "Network/Steamworks/Asura_PC_SteamworksAchievements.h"

void Asura_Rewards_System::Platform_Initialise()
{
	Asura_PC_SteamworksAchievements::Initialise();
}

void Asura_Rewards_System::Platform_Shutdown()
{
	Asura_PC_SteamworksAchievements::Shutdown();
}

void Asura_Rewards_System::Platform_Reset()
{
	// NY - 31 March 2009 - not meaningful on steam - use can't change user while we're running, and there's no reason to reset the current user.
}

void Asura_Rewards_System::Platform_UnlockReward(u_int uRewardIndex)
{
	// NY - 31 March 2009 - silently fail if reward does not exist for PC
	const char* szAchievement = Asura_PC_SteamworksAchievements::Project_ConvertReward(uRewardIndex);
	if (szAchievement)
	{
		Asura_PC_SteamworksAchievements::UnlockAchievement(szAchievement);
	}
}

void Asura_Rewards_System::Platform_RewardProgress(u_int uRewardIndex, u_int uProgress, u_int uTarget)
{
	// NY - 31 March 2009 - silently fail if reward does not exist for PC
	// since PC is the only platform to show progress at the minute, this would be a bit odd however
	const char* szAchievement = Asura_PC_SteamworksAchievements::Project_ConvertReward(uRewardIndex);
	if (szAchievement)
	{
		Asura_PC_SteamworksAchievements::AchievementProgress(szAchievement, uProgress, uTarget);
	}
}

bool Asura_Rewards_System::Platform_IsRewardUnlocked(u_int uRewardIndex)
{
	// NY - 31 March 2009 - silently return locked if reward does not exist for PC
	const char* szAchievement = Asura_PC_SteamworksAchievements::Project_ConvertReward(uRewardIndex);
	if (!szAchievement)
	{
		return false;
	}
	return Asura_PC_SteamworksAchievements::IsAchievementUnlocked(szAchievement);
}

bool Asura_Rewards_System::Platform_IsRewardAvailable(u_int uRewardIndex)
{
	return Asura_PC_SteamworksAchievements::Project_ConvertReward(uRewardIndex) != 0;
}

bool Asura_Rewards_System::Platform_IsInitComplete()
{
	return Asura_PC_SteamworksAchievements::IsInitComplete();
}

bool Asura_Rewards_System::Platform_IsReadyToUnlock()
{
	// NY - 31 March 2009 - steamworks is threaded out, so init needs to have finished. this also covers steam being missing etc.
	return Asura_PC_SteamworksAchievements::IsInitComplete();
}



#endif // #ifdef ASURA_USE_REWARDS
