Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Private Types | Private Member Functions | Private Attributes
UnlockManager Class Reference

#include <unlock_manager.hpp>

Collaboration diagram for UnlockManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 UnlockManager ()
void load (const lisp::Lisp *)
 This is called from user_config when reading the config file.
void save (lisp::Writer *writer)
std::vector< const Challenge * > getActiveChallenges ()
const std::vector< const
Challenge * > 
getUnlockedFeatures ()
void clearUnlocked ()
void raceFinished ()
 This is called when a race is finished.
void grandPrixFinished ()
void unlockFeature (Challenge *c, bool save=true)
void lockFeature (Challenge *challenge)
bool isLocked (const std::string &feature)

Private Types

typedef std::map< std::string,
Challenge * > 
AllChallengesType

Private Member Functions

ChallengegetChallenge (const std::string &id)
void computeActive ()

Private Attributes

AllChallengesType m_all_challenges
std::map< std::string, bool > m_locked_features
std::vector< const Challenge * > m_unlocked_features

Detailed Description

Definition at line 30 of file unlock_manager.hpp.


Member Typedef Documentation

typedef std::map<std::string, Challenge*> UnlockManager::AllChallengesType [private]

Definition at line 33 of file unlock_manager.hpp.


Constructor & Destructor Documentation

Definition at line 39 of file unlock_manager.cpp.

{
    // The global variable 'unlock_manager' is needed in the challenges,
    // but it's not set yet - so we define it here (and it gets re-assign
    // in main).
    unlock_manager=this;

    // Add all challenges:
    Challenge *c;
    c=new EnergyMathClass(); m_all_challenges[c->getId()]=c;
    c=new PenguinPlaygroundGP(); m_all_challenges[c->getId()]=c;
    c=new RaceTrackTime();   m_all_challenges[c->getId()]=c;
    c=new TollwayTime();     m_all_challenges[c->getId()]=c;
    c=new JungleFollow();    m_all_challenges[c->getId()]=c;
    c=new EnergyShiftingSands(); m_all_challenges[c->getId()]=c;
    c=new MoonAndBackGP();   m_all_challenges[c->getId()]=c;
    c=new CityTime();        m_all_challenges[c->getId()]=c;
    c=new IslandFollow();        m_all_challenges[c->getId()]=c;
    c=new WorldsEndGP();        m_all_challenges[c->getId()]=c;
    c=new TollwayHead2Head(); m_all_challenges[c->getId()]=c;
    
    computeActive();
}   // UnlockManager

Here is the call graph for this function:


Member Function Documentation

void UnlockManager::clearUnlocked ( ) [inline]

Definition at line 48 of file unlock_manager.hpp.

{m_unlocked_features.clear(); }

Here is the caller graph for this function:

void UnlockManager::computeActive ( ) [private]

Definition at line 107 of file unlock_manager.cpp.

{
    for(AllChallengesType::iterator i =m_all_challenges.begin(); 
                                    i!=m_all_challenges.end();  i++)
    {
        // Changed challenge
        // -----------------
        if((i->second)->isSolved()) 
        {
            // The constructor calls computeActive, which actually locks 
            // all features, so unlock the solved ones (and don't try to
            // save the state, since we are currently reading it)
            
            unlockFeature(i->second, /*save*/ false);
            continue;
        }

        // Otherwise lock the feature, and check if the challenge is active
        // ----------------------------------------------------------------
        lockFeature(i->second);
        std::vector<std::string> pre_req=(i->second)->getPrerequisites();
        bool allSolved=true;
        for(std::vector<std::string>::iterator pre =pre_req.begin();
                                               pre!=pre_req.end(); pre++)
        {
            const Challenge*p = getChallenge(*pre);
            if(!p)
            {
                fprintf(stderr,"Challenge prerequisite '%s' of '%s' not found - ignored\n",
                        pre->c_str(), i->first.c_str());
                continue;
            }
            if(!p->isSolved())
            {
                allSolved=false;
                break;
            }
        }   // for all pre in pre_req
        if(allSolved)
        {
            i->second->setActive();
        }   // if solved
    }   // for i
    clearUnlocked();
}   // computeActive

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< const Challenge * > UnlockManager::getActiveChallenges ( )

Definition at line 64 of file unlock_manager.cpp.

{
    computeActive();
    std::vector<const Challenge*> all_active;
    for(AllChallengesType::iterator i =m_all_challenges.begin(); 
                                    i!=m_all_challenges.end();  i++)
    {
        if(i->second->isActive()) all_active.push_back(i->second);
    }
    return all_active;
}   // getActiveChallenges

Here is the call graph for this function:

Here is the caller graph for this function:

Challenge * UnlockManager::getChallenge ( const std::string &  id) [private]

Definition at line 77 of file unlock_manager.cpp.

{
    if(m_all_challenges.find(id)==m_all_challenges.end()) return NULL;
    return m_all_challenges[id];
}   // getChallenge

Here is the caller graph for this function:

const std::vector<const Challenge*> UnlockManager::getUnlockedFeatures ( ) [inline]

Definition at line 46 of file unlock_manager.hpp.

Here is the caller graph for this function:

Definition at line 170 of file unlock_manager.cpp.

{
    for(AllChallengesType::iterator i =m_all_challenges.begin(); 
                                    i!=m_all_challenges.end();  i++)
    {
        if(i->second->isActive() &&i->second->grandPrixFinished())
        {
            unlockFeature(i->second);
        }
    }
    race_manager->setCoinTarget(0);
}   // grandPrixFinished

Here is the call graph for this function:

Here is the caller graph for this function:

bool UnlockManager::isLocked ( const std::string &  feature)

Definition at line 218 of file unlock_manager.cpp.

{
    return m_locked_features.find(feature)!=m_locked_features.end();
}  // featureIsLocked

Here is the caller graph for this function:

void UnlockManager::load ( const lisp::Lisp config)

This is called from user_config when reading the config file.

Definition at line 86 of file unlock_manager.cpp.

{
    for(AllChallengesType::iterator i =m_all_challenges.begin(); 
                                    i!=m_all_challenges.end();  i++)
    {
        i->second->load(config);
    }
    computeActive();
}   // load

Here is the call graph for this function:

Here is the caller graph for this function:

void UnlockManager::lockFeature ( Challenge challenge)

Definition at line 184 of file unlock_manager.cpp.

{
    const unsigned int amount = challenge->getFeatures().size();
    for(unsigned int n=0; n<amount; n++)
        m_locked_features[challenge->getFeatures()[n].name]=true;
}   // lockFeature

Here is the call graph for this function:

Here is the caller graph for this function:

This is called when a race is finished.

Call all active challenges

Definition at line 156 of file unlock_manager.cpp.

{
    for(AllChallengesType::iterator i =m_all_challenges.begin(); 
                                    i!=m_all_challenges.end();  i++)
    {
        if(i->second->isActive() && i->second->raceFinished())
        {
            unlockFeature(i->second);
        }   // if isActive && challenge solved
    }
    race_manager->setCoinTarget(0);  //reset
}   // raceFinished

Here is the call graph for this function:

Here is the caller graph for this function:

void UnlockManager::save ( lisp::Writer writer)

Definition at line 97 of file unlock_manager.cpp.

{
    for(AllChallengesType::iterator i =m_all_challenges.begin(); 
                                    i!=m_all_challenges.end();  i++)
    {
        i->second->save(writer);
    }   // for i in m_all_challenges
}   // save

Here is the caller graph for this function:

void UnlockManager::unlockFeature ( Challenge c,
bool  save = true 
)

Definition at line 193 of file unlock_manager.cpp.

{
    const unsigned int amount = c->getFeatures().size();
    for(unsigned int n=0; n<amount; n++)
    {
        std::string feature = c->getFeatures()[n].name;
        std::map<std::string,bool>::iterator p=m_locked_features.find(feature);
        if(p==m_locked_features.end())
        {
            //fprintf(stderr,"Unlocking feature '%s' failed: feature is not locked.\n",
            //        (feature).c_str());
            return;
        }
        m_locked_features.erase(p);
    }
    
    // Add to list of recently unlocked features
    m_unlocked_features.push_back(c);
    c->setSolved();  // reset isActive flag
    
    // Save the new unlock information
    if(save) user_config->saveConfig();
}   // unlockFeature

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 34 of file unlock_manager.hpp.

std::map<std::string, bool> UnlockManager::m_locked_features [private]

Definition at line 35 of file unlock_manager.hpp.

std::vector<const Challenge*> UnlockManager::m_unlocked_features [private]

Definition at line 36 of file unlock_manager.hpp.


The documentation for this class was generated from the following files: