Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sound2/src/orxonox/objects/Level.cc @ 3050

Last change on this file since 3050 was 3013, checked in by bknecht, 16 years ago

merged sound changes into sound2 use sound2 from now on

  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/lodfinal/src/orxonox/objects/Level.ccmergedeligible
    /code/branches/sound/src/orxonox/objects/Level.ccmergedeligible
    /code/trunk/src/orxonox/objects/Level.ccmergedeligible
    /code/branches/buildsystem2/src/orxonox/objects/Level.cc2506-2658
    /code/branches/buildsystem3/src/orxonox/objects/Level.cc2662-2708
    /code/branches/gui/src/orxonox/objects/Level.cc2795-2894
    /code/branches/miniprojects/src/orxonox/objects/Level.cc2754-2824
    /code/branches/network/src/orxonox/objects/Level.cc2356
    /code/branches/network64/src/orxonox/objects/Level.cc2210-2355
    /code/branches/objecthierarchy2/src/orxonox/objects/Level.cc2171-2479
    /code/branches/physics_merge/src/orxonox/objects/Level.cc2436-2457
    /code/branches/presentation/src/orxonox/objects/Level.cc2369-2652,​2654-2660
    /code/branches/questsystem5/src/orxonox/objects/Level.cc2776-2905
    /code/branches/weaponsystem/src/orxonox/objects/Level.cc2742-2890
File size: 5.8 KB
RevLine 
[2072]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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "Level.h"
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34#include "core/Loader.h"
35#include "core/XMLFile.h"
36#include "core/Template.h"
[2710]37#include "core/Core.h"
[2072]38
39#include "LevelManager.h"
[2169]40#include "objects/infos/PlayerInfo.h"
[2072]41#include "objects/gametypes/Gametype.h"
[2168]42#include "overlays/OverlayGroup.h"
[3013]43#include "sound/SoundBase.h"
[2072]44
45#include "util/Math.h"
46
47namespace orxonox
48{
49    CreateFactory(Level);
50
[2169]51    Level::Level(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
[2072]52    {
53        RegisterObject(Level);
54
55        this->registerVariables();
56        this->xmlfilename_ = this->getFilename();
57
[2710]58        if (this->xmlfilename_.length() >= Core::getMediaPathString().length())
59            this->xmlfilename_ = this->xmlfilename_.substr(Core::getMediaPathString().length());
[2072]60    }
61
62    Level::~Level()
63    {
64        if (this->isInitialized())
65        {
[2168]66            if (LevelManager::getInstancePtr())
67                LevelManager::getInstance().releaseActivity(this);
[2072]68
69            if (this->xmlfile_)
70                Loader::unload(this->xmlfile_);
[3013]71
72            if(this->ambientsound_ != NULL)
73                delete this->ambientsound_;
[2072]74        }
75    }
76
77    void Level::XMLPort(Element& xmlelement, XMLPort::Mode mode)
78    {
79        SUPER(Level, XMLPort, xmlelement, mode);
80
81        XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
82        XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
83
[3013]84        XMLPortParamLoadOnly(Level, "ambientsound", loadAmbientSound, xmlelement, mode);
85
[2072]86        XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
87    }
88
89    void Level::registerVariables()
90    {
[2662]91        registerVariable(this->xmlfilename_, variableDirection::toclient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
92        registerVariable(this->name_,        variableDirection::toclient, new NetworkCallback<Level>(this, &Level::changedName));
93        registerVariable(this->description_, variableDirection::toclient);
[2072]94    }
95
96    void Level::networkcallback_applyXMLFile()
97    {
98        COUT(0) << "Loading level \"" << this->xmlfilename_ << "\"..." << std::endl;
99
100        ClassTreeMask mask;
101        mask.exclude(Class(BaseObject));
102        mask.include(Class(Template));
[2168]103        mask.include(Class(OverlayGroup)); // HACK to include the ChatOverlay
[2072]104
[2710]105        this->xmlfile_ = new XMLFile(Core::getMediaPathString() + this->xmlfilename_, mask);
[2072]106
107        Loader::open(this->xmlfile_);
108    }
109
110    void Level::setGametypeString(const std::string& gametype)
111    {
112        Identifier* identifier = ClassByString(gametype);
[2826]113
114        if (!identifier || !identifier->isA(Class(Gametype)))
[2072]115        {
[2826]116            COUT(0) << "Error: \"" << gametype << "\" is not a valid gametype." << std::endl;
117            identifier = Class(Gametype);
118            this->gametype_ = "Gametype";
119        }
120        else
[2072]121            this->gametype_ = gametype;
122
[2826]123std::cout << "Load Gametype: " << this->gametype_ << std::endl;
[2072]124
[2826]125        Gametype* rootgametype = dynamic_cast<Gametype*>(identifier->fabricate(this));
126        this->setGametype(rootgametype);
[2072]127
[2826]128std::cout << "root gametype: " << rootgametype->getIdentifier()->getName() << std::endl;
129
130        for (std::list<BaseObject*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
131            (*it)->setGametype(rootgametype);
132
133        if (LevelManager::getInstancePtr())
134            LevelManager::getInstance().requestActivity(this);
[2072]135    }
136
137
138    void Level::addObject(BaseObject* object)
139    {
140        this->objects_.push_back(object);
141        object->setGametype(this->getGametype());
142    }
143
144    BaseObject* Level::getObject(unsigned int index) const
145    {
146        unsigned int i = 0;
147        for (std::list<BaseObject*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
148        {
149            if (i == index)
150                return (*it);
151            ++i;
152        }
153        return 0;
154    }
155
[3013]156    void Level::loadAmbientSound(const std::string& filename)
157    {
158        if(filename == "") return;
159        else
160        {
161            if(this->ambientsound_ == NULL)
162            {
163                this->ambientsound_ = new SoundBase();
164            }
165
166            this->ambientsound_->loadFile(filename);
167            this->ambientsound_->play(true);
168        }
169    }
170
[2072]171    void Level::playerEntered(PlayerInfo* player)
172    {
[2662]173        COUT(3) << "player entered level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl;
[2072]174        player->setGametype(this->getGametype());
175    }
176
177    void Level::playerLeft(PlayerInfo* player)
178    {
[2662]179        COUT(3) << "player left level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl;
[2072]180        player->setGametype(0);
181    }
182}
Note: See TracBrowser for help on using the repository browser.