Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 3, 2008, 4:40:00 PM (17 years ago)
Author:
dafrick
Message:
  • Created QuestListeners, they can be used to affect Objects due to status changes of quests.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem3/src/orxonox/objects/quest/Quest.cc

    r2261 r2328  
    4343#include "QuestHint.h"
    4444#include "QuestEffect.h"
     45#include "QuestListener.h"
    4546
    4647namespace orxonox {
     
    363364        return this->getStatus(player) == questStatus::completed;
    364365    }
     366   
     367    /**
     368    @brief
     369        Fails the Quest for an input player.
     370    @param player
     371        The player.
     372    @return
     373        Returns true if the Quest could be failed, false if not.
     374    */
     375    bool Quest::fail(PlayerInfo* player)
     376    {
     377        QuestListener::advertiseStatusChange(this->listeners_, "fail"); //!< Tells the QuestListeners, that the status has changed to failed.
     378        this->setStatus(player, questStatus::failed);
     379        return true;
     380    }
     381   
     382    /**
     383    @brief
     384        Completes the Quest for an input player.
     385    @param player
     386        The player.
     387    @return
     388        Returns true if the Quest could be completed, false if not.
     389    */
     390    bool Quest::complete(PlayerInfo* player)
     391    {
     392        QuestListener::advertiseStatusChange(this->listeners_, "complete"); //!< Tells the QuestListeners, that the status has changed to completed.
     393        this->setStatus(player, questStatus::completed);
     394        return true;
     395    }
    365396
    366397    /**
     
    374405    bool Quest::start(PlayerInfo* player)
    375406    {
    376         if(this->isStartable(player)) //!< Checks whether the quest can be started.
    377         {
    378             this->setStatus(player, questStatus::active);
    379             return true;
    380         }
    381        
    382         COUT(4) << "A non-startable quest was trying to be started." << std::endl;
    383         return false;
     407        if(!this->isStartable(player)) //!< Checks whether the quest can be started.
     408        {
     409            COUT(4) << "A non-startable quest was trying to be started." << std::endl;
     410            return false;
     411        }
     412       
     413        QuestListener::advertiseStatusChange(this->listeners_, "start"); //!< Tells the QuestListeners, that the status has changed to active.
     414       
     415        this->setStatus(player, questStatus::active);
     416        return true;
     417    }
     418   
     419    /**
     420    @brief
     421        Adds a QuestListener to the list of QuestListeners listening to this Quest.
     422    @param listener
     423        The QuestListener to be added.
     424    @return
     425        Returns true if successful, false if not.
     426    */
     427    bool Quest::addListener(QuestListener* listener)
     428    {
     429        if(listener == NULL)
     430        {
     431            COUT(2) << "A NULL-QuestListener was trying to be added to a Quests listeners." << std::endl;
     432            return false;
     433        }
     434       
     435        this->listeners_.push_back(listener);
     436        return true;
    384437    }
    385438
Note: See TracChangeset for help on using the changeset viewer.