Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/questsystem/QuestManager.cc @ 6060

Last change on this file since 6060 was 5929, checked in by rgrieder, 15 years ago

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

  • Property svn:eol-style set to native
File size: 7.9 KB
RevLine 
[1996]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
[2261]29/**
[3196]30    @file
[2662]31    @brief Implementation of the QuestManager class.
[2261]32*/
33
[2105]34#include "QuestManager.h"
35
[5748]36#include <CEGUIWindow.h>
37
[3196]38#include "util/Exception.h"
[1996]39#include "core/CoreIncludes.h"
[5693]40#include "core/GUIManager.h"
[5745]41#include "core/ConsoleCommand.h"
[5755]42#include "core/LuaState.h"
[5929]43#include "core/ScopedSingletonManager.h"
[5748]44#include "infos/PlayerInfo.h"
[5745]45#include "overlays/GUIOverlay.h"
[2105]46
[5755]47#include "ToluaBindQuestsystem.h"
[2095]48#include "Quest.h"
49#include "QuestHint.h"
[5748]50#include "QuestItem.h"
[1996]51
[2662]52namespace orxonox
53{
[5755]54    // Register tolua_open function when loading the library
55    DeclareToluaInterface(Questsystem);
56
[2911]57    //! Pointer to the current (and single) instance of this class.
[3370]58    /*static*/ QuestManager* QuestManager::singletonPtr_s = NULL;
[5929]59    ManageScopedSingleton(QuestManager, ScopeID::Root, false);
[1996]60
[2261]61    /**
62    @brief
63        Constructor. Registers the object.
[2911]64    @todo
65        Is inheriting from BaseObject proper?
[2261]66    */
[2911]67    QuestManager::QuestManager()
[1996]68    {
[2911]69        RegisterRootObject(QuestManager);
[1996]70    }
[2092]71
[2261]72    /**
73    @brief
74        Destructor.
75    */
[1996]76    QuestManager::~QuestManager()
77    {
[5745]78        for(std::map<PlayerInfo*, QuestGUI*>::iterator it = this->questGUIs_.begin(); it != this->questGUIs_.end(); it++)
79        {
[5929]80            (*it).second->destroy();
[5745]81        }
82        this->questGUIs_.clear();
[1996]83    }
84
85    /**
86    @brief
[5745]87        Retreive all Quests.
88    @return
89        Returns a map with all Quests indexed by their id's.
90    */
91    std::map<std::string, Quest*> & QuestManager::getQuests(void)
92    {
93        return this->questMap_;
94    }
95
96    /**
97    @brief
[2261]98        Registers a Quest with the QuestManager to make it globally accessable.
99        Uses it's id to make sure to be able to be identify and retrieve it later.
[1996]100    @param quest
[2261]101        The Quest that is to be registered.
[1996]102    @return
103        Returns true if successful, false if not.
104    */
[2911]105    bool QuestManager::registerQuest(Quest* quest)
[1996]106    {
[2261]107        if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers.
[2068]108        {
109            COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl;
110            return false;
[2093]111        }
[2092]112
[2261]113        std::pair<std::map<std::string, Quest*>::iterator,bool> result;
[2911]114        result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
[2092]115
[2261]116        if(result.second) //!< If inserting was a success.
[2068]117        {
118            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
119            return true;
[2093]120        }
121        else
122        {
123           COUT(2) << "Quest with the same id was already present." << std::endl;
124           return false;
125        }
[1996]126    }
[2092]127
[1996]128    /**
129    @brief
130        Registers a QuestHint with the QuestManager to make it globally accessable.
[2261]131        Uses it's id to make sure to be able to be identify and retrieve it later.
[1996]132    @param hint
133        The QuestHint to be registered.
134    @return
135        Returns true if successful, false if not.
136    */
[2911]137    bool QuestManager::registerHint(QuestHint* hint)
[1996]138    {
[2261]139        if(hint == NULL) //!< Still not liking NULL-pointers.
[2068]140        {
141            COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl;
142            return false;
143        }
[2092]144
[2261]145        std::pair<std::map<std::string, QuestHint*>::iterator,bool> result;
[2911]146        result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
[2092]147
[2261]148        if(result.second) //!< If inserting was a success.
[2068]149        {
150            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
151            return true;
[2093]152        }
153        else
154        {
155           COUT(2) << "QuestHint with the same id was already present." << std::endl;
156           return false;
157        }
[1996]158    }
[2092]159
[1996]160    /**
161    @brief
[2261]162        Finds a Quest with the given id.
[1996]163    @param questId
[2261]164        The id of the Quest sought for.
[1996]165    @return
[2261]166        Returns a pointer to the Quest with the input id.
167        Returns NULL if there is no Quest with the given questId.
[2068]168    @throws
169        Throws an exception if the given questId is invalid.
[1996]170    */
[2911]171    Quest* QuestManager::findQuest(const std::string & questId)
[1996]172    {
[2261]173        if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
[2093]174        {
[2068]175            ThrowException(Argument, "Invalid questId.");
[2093]176        }
[2092]177
[1996]178        Quest* quest;
[2911]179        std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId);
180        if (it != this->questMap_.end()) //!< If the Quest is registered.
[2093]181        {
182            quest = it->second;
183        }
184        else
185        {
186           quest = NULL;
187           COUT(2) << "The quest with id {" << questId << "} is nowhere to be found." << std::endl;
188        }
[2092]189
[2093]190        return quest;
[1996]191
192    }
[2092]193
[1996]194    /**
195    @brief
[2261]196        Finds a QuestHint with the given id.
[1996]197    @param hintId
[2261]198        The id of the QuestHint sought for.
[1996]199    @return
[2261]200        Returns a pointer to the QuestHint with the input id.
201        Returns NULL if there is no QuestHint with the given hintId.
[2068]202    @throws
203        Throws an exception if the given hintId is invalid.
[1996]204    */
[2911]205    QuestHint* QuestManager::findHint(const std::string & hintId)
[1996]206    {
[2261]207        if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
[2093]208        {
[2068]209            ThrowException(Argument, "Invalid hintId.");
[2093]210        }
[2092]211
[1996]212        QuestHint* hint;
[2911]213        std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId);
214        if (it != this->hintMap_.end()) //!< If the QuestHint is registered.
[2093]215        {
216            hint = it->second;
217        }
218        else
219        {
220           hint = NULL;
221           COUT(2) << "The hint with id {" << hintId << "} is nowhere to be found." << std::endl;
222        }
[2092]223
[2093]224        return hint;
[1996]225
226    }
227
[2993]228    /**
229    @brief
[5745]230        Retreive the main window for the GUI.
231        This is for the use in the lua script tu start the QuestGUI.
232    @param guiName
233        The name of the GUI.
[2993]234    @return
[5745]235        Returns a CEGUI Window.
[2993]236    */
[5745]237    CEGUI::Window* QuestManager::getQuestGUI(const std::string & guiName)
[2963]238    {
[5745]239        PlayerInfo* player = this->retreivePlayer(guiName);
[5693]240
[5745]241        if(this->questGUIs_.find(player) == this->questGUIs_.end()) //!< Create a new GUI, if there is none, yet.
242            this->questGUIs_[player] = new QuestGUI(player);
[5693]243
[5745]244        return this->questGUIs_[player]->getGUI();
[2963]245    }
246
[2993]247    /**
248    @brief
[5745]249        Retrieve the player for a certain GUI.
250    @param guiName
251        The name of the GUI the player is retrieved for.
[2993]252    @return
[5745]253        Returns the player.
254    @todo
255        This very well might be outdated. So: Check if still needed, and update if necessary.
[2993]256    */
[5745]257    PlayerInfo* QuestManager::retreivePlayer(const std::string & guiName)
[2963]258    {
[5745]259        PlayerInfo* player = GUIManager::getInstance().getPlayer(guiName);
260        if(player == NULL)
[2963]261        {
[5745]262            COUT(1) << "Error: GUIOverlay with name '" << guiName << "' has no player." << std::endl;
[2993]263            return NULL;
264        }
[5693]265
[5745]266        return player;
[2963]267    }
268
[1996]269}
Note: See TracBrowser for help on using the repository browser.