Achievements start

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13608 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx
2013-08-30 22:28:57 +00:00
parent 7e8d167a89
commit cd7e986486
6 changed files with 312 additions and 1 deletions

9
data/achievements.xml Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<achievements>
<achievement id="1" type="map" title="Christoffel Columbus" description="Play every official track at least once." >
<entry key="mapid1" />
<entry key="mapid2" />
</achievement>
<achievement id="2" type="single" goal="1" title="Strike!" description="Hit a kart with a bowling-ball." />
</achievements>

View File

@@ -0,0 +1,88 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "achievements/achievement.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include <sstream>
#include <stdlib.h>
#include <assert.h>
// ============================================================================
Achievement::Achievement(const XMLNode * input)
{
input->get("id", &m_id);
m_achieved = false;
}
// ============================================================================
Achievement::~Achievement()
{
}
// ============================================================================
void Achievement::onAchieving()
{
if(!m_achieved)
{
//show achievement
//send to server
m_achieved = true;
}
}
// ============================================================================
SingleAchievement::SingleAchievement(const XMLNode * input)
: Achievement(input)
{
}
// ============================================================================
void SingleAchievement::check()
{
if(m_achieved)
return;
if(m_progress >= m_goal)
onAchieving();
}
// ============================================================================
MapAchievement::MapAchievement(const XMLNode * input)
: Achievement(input)
{
}
// ============================================================================
void MapAchievement::check()
{
if(m_achieved)
return;
ProgressMap::iterator iter;
for (iter = m_progress_map.begin(); iter != m_progress_map.end(); ++iter)
{
if (!iter->second)
return;
}
onAchieving();
}

View File

@@ -0,0 +1,75 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_ACHIEVEMENT_HPP
#define HEADER_ACHIEVEMENT_HPP
#include "utils/types.hpp"
#include <irrString.h>
#include <string>
#include "io/xml_writer.hpp"
// ============================================================================
/**
* \brief
* \ingroup
*/
class Achievement
{
private:
uint32_t m_id;
bool m_achieved;
virtual void check() = 0;
void onAchieving();
public:
Achievement (const XMLNode * input);
virtual ~Achievement ();
uint32_t getID() const { return m_id; }
}; // class Achievement
class SingleAchievement : public Achievement
{
private:
virtual void check();
int m_goal;
int m_progress;
public:
SingleAchievement (const XMLNode * input);
virtual ~SingleAchievement ();
}; // class Achievement
class MapAchievement : public Achievement
{
private:
virtual void check();
typedef std::map<std::string, bool> ProgressMap;
ProgressMap m_progress_map;
public:
MapAchievement (const XMLNode * input);
virtual ~MapAchievement ();
}; // class Achievement
#endif
/*EOF*/

View File

@@ -0,0 +1,86 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "achievements/achievements_manager.hpp"
#include "achievements/achievement.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include "io/file_manager.hpp"
#include "io/xml_writer.hpp"
#include <sstream>
#include <stdlib.h>
#include <assert.h>
static AchievementsManager* achievements_manager_singleton(NULL);
AchievementsManager* AchievementsManager::get()
{
if (achievements_manager_singleton == NULL)
achievements_manager_singleton = new AchievementsManager();
return achievements_manager_singleton;
}
void AchievementsManager::deallocate()
{
delete achievements_manager_singleton;
achievements_manager_singleton = NULL;
} // deallocate
// ============================================================================
AchievementsManager::AchievementsManager()
{
parseAchievements();
}
// ============================================================================
AchievementsManager::~AchievementsManager()
{
}
// ============================================================================
void AchievementsManager::parseAchievements()
{
const std::string file_name = file_manager->getDataFile("items.xml");
const XMLNode *root = file_manager->createXMLTree(file_name);
unsigned int num_nodes = root->getNumNodes();
for(unsigned int i = 0; i < num_nodes; i++)
{
const XMLNode *node = root->getNode(i);
std::string type("");
node->get("type", &type);
Achievement * achievement;
if(type == "single")
{
achievement = new SingleAchievement(node);
}
else if(type == "map")
{
achievement = new MapAchievement(node);
}
else
{
Log::error("AchievementsManager::parseAchievements","Non-existent achievement type. Skipping - definitely results in unwanted behaviour.");
continue;
}
m_achievements[achievement->getID()] = achievement;
}
if(num_nodes != m_achievements.count())
Log::error("AchievementsManager::parseAchievements","Multiple achievements with the same id!");
} // parseAchievements

View File

@@ -0,0 +1,53 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_ACHIEVEMENTS_MANAGER_HPP
#define HEADER_ACHIEVEMENTS_MANAGER_HPP
#include "utils/types.hpp"
#include "achievements/achievement.hpp"
#include <irrString.h>
#include <string>
// ============================================================================
/**
* \brief Class that takes care of online profiles
* \ingroup online
*/
class AchievementsManager
{
private:
AchievementsManager ();
~AchievementsManager ();
void parseAchievements();
std::map<uint32_t, * Achievement> m_achievements;
public:
/**Singleton */
static AchievementsManager * get();
static void deallocate();
}; // class AchievementsManager
#endif
/*EOF*/

View File

@@ -616,7 +616,7 @@ namespace Online{
void CurrentUser::onSTKQuit() const
{
if(m_state != US_SIGNED_OUT)
if(isRegisteredUser())
{
HTTPRequest * request = new HTTPRequest(true, HTTPManager::MAX_PRIORITY);
request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");