Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/questsystem/QuestListener.cc @ 8858

Last change on this file since 8858 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
  • Property svn:eol-style set to native
File size: 6.3 KB
RevLine 
[2329]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[2352]29/**
[7456]30    @file QuestListener.cc
[2352]31    @brief Implementation of the QuestListener class.
32*/
33
[2329]34#include "QuestListener.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
[7456]38
[2329]39#include "Quest.h"
40#include "QuestManager.h"
41
[2435]42namespace orxonox
43{
[2329]44    CreateFactory(QuestListener);
45
[7462]46    // Initialization of the static variables for the modes as strings.
[7456]47    /*static*/ const std::string QuestListener::ALL = "all";
48    /*static*/ const std::string QuestListener::START = "start";
49    /*static*/ const std::string QuestListener::FAIL = "fail";
50    /*static*/ const std::string QuestListener::COMPLETE = "complete";
51
[2352]52    /**
53    @brief
54        Constructor. Registers the object and initializes variables.
55    */
[2329]56    QuestListener::QuestListener(BaseObject* creator) : BaseObject(creator)
57    {
58        RegisterObject(QuestListener);
[6417]59
[3280]60        this->mode_ = QuestListenerMode::All;
[2346]61        this->quest_ = NULL;
[2329]62    }
[6417]63
[2352]64    /**
65    @brief
66        Destructor.
67    */
[2329]68    QuestListener::~QuestListener()
69    {
70    }
[6417]71
[2329]72    /**
73    @brief
74        Method for creating a Quest object through XML.
75    */
76    void QuestListener::XMLPort(Element& xmlelement, XMLPort::Mode mode)
77    {
78        SUPER(QuestListener, XMLPort, xmlelement, mode);
79
80        XMLPortParam(QuestListener, "questId", setQuestId, getQuestId, xmlelement, mode);
[2352]81        XMLPortParam(QuestListener, "mode", setMode, getMode, xmlelement, mode);
[2329]82
[7163]83        if(this->quest_ != NULL)
[7456]84            this->quest_->addListener(this); // Adds the QuestListener to the Quests list of listeners.
[6417]85
[8858]86        orxout(verbose, context::quests) << "QuestListener created for quest: {" << this->quest_->getId() << "} with mode '" << this->getMode() << "'." << endl;
[2329]87    }
[6417]88
[2352]89    /**
90    @brief
[3370]91        Makes all QuestListener in the list aware that a certain status change has occurred and executes them if the status change affects them.
[2352]92    @param listeners
93        The list of QuestListeners that have to be made aware of the status change.
94    @param status
95        The status that has changed. Can be 'start' (if the Quest was started), 'complete' (if the Quest was completed) or 'fail' (if the Quest was failed).
96    */
97    /* static */ void QuestListener::advertiseStatusChange(std::list<QuestListener*> & listeners, const std::string & status)
[2329]98    {
[7456]99        for (std::list<QuestListener*>::iterator it = listeners.begin(); it != listeners.end(); ++it) // Iterate through all QuestListeners
[2329]100        {
101            QuestListener* listener = *it;
[7456]102            if(listener->getMode() == status || listener->getMode() == QuestListener::ALL) // Check whether the status change affects the give QuestListener.
[2329]103                listener->execute();
104        }
105    }
[6417]106
[2352]107    /**
108    @brief
109        Sets the questId of the Quest the QuestListener reacts to.
110    @param id
111        The questId of the Quest the QUestListener reacts to.
112    @return
113        Returns true if successful.
114    */
[2329]115    bool QuestListener::setQuestId(const std::string & id)
116    {
[7456]117        this->quest_ = QuestManager::getInstance().findQuest(id); // Find the Quest corresponding to the given questId.
[6417]118
[7456]119        if(this->quest_ == NULL) // If there is no such Quest.
[2329]120        {
[2383]121            ThrowException(Argument, "This is bad! The QuestListener has not found a Quest with a corresponding id..");
[2329]122            return false;
123        }
[6417]124
[2329]125        return true;
126    }
[6417]127
[2352]128    /**
129    @brief
130        Sets the mode of the QuestListener.
131    @param mode
132        The mode to be set. Can be eighter 'all', 'start', 'fail' or 'complete'.
133    @return
134        Returns true if successful.
135    */
136    bool QuestListener::setMode(const std::string & mode)
[2329]137    {
[7456]138        if(mode == QuestListener::ALL)
[3280]139            this->mode_ = QuestListenerMode::All;
[7456]140        else if(mode == QuestListener::START)
[3280]141            this->mode_ = QuestListenerMode::Start;
[7456]142        else if(mode == QuestListener::FAIL)
[3280]143            this->mode_ = QuestListenerMode::Fail;
[7456]144        else if(mode == QuestListener::COMPLETE)
[3280]145            this->mode_ = QuestListenerMode::Complete;
[2329]146        else
147        {
[8858]148            orxout(internal_warning, context::quests) << "QuestListener with invalid mode '" << mode << "' created. Mode set to 'all'." << endl;
[7456]149            this->mode_ = QuestListenerMode::All;
150            return false;
[2329]151        }
[6417]152
[2352]153        return true;
[2329]154    }
[6417]155
[2352]156    /**
157    @brief
158        Get the mode of the QuestListener.
159    @return
[7456]160        Return the mode of the QuestListener. Can be either 'all', 'start', 'fail' or 'complete'.
[2352]161    */
[3196]162    std::string QuestListener::getMode(void)
[2329]163    {
[7456]164        switch(this->mode_)
[2329]165        {
[7456]166            case QuestListenerMode::All:
167                return QuestListener::ALL;
168            case QuestListenerMode::Start:
169                return QuestListener::START;
170            case QuestListenerMode::Fail:
171                return QuestListener::FAIL;
172            case QuestListenerMode::Complete:
173                return QuestListener::COMPLETE;
174            default: // This will never happen.
175                return QuestListener::ALL;
[2352]176        }
[2329]177    }
178
[2352]179    /**
180    @brief
[3196]181        Get the questId of the Quest the QuestListener reacts to.
182    @return
183        Returns the questId of the Quest the QuestListener reacts to.
184    */
[6417]185    const std::string & QuestListener::getQuestId(void)
[3196]186    {
187        return this->quest_->getId();
188    }
189
190    /**
191    @brief
[2352]192        Executes the QuestListener, resp. fires an Event.
193    @return
194        Returns true if successful.
195    */
196    bool QuestListener::execute()
197    {
[2383]198        this->fireEvent(true);
[2352]199        return true;
200    }
[2329]201
202}
Note: See TracBrowser for help on using the repository browser.