Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/infos/Level.cc @ 2662

Last change on this file since 2662 was 2103, checked in by rgrieder, 16 years ago

Merged r2101 (objecthierarchy) to trunk.

  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/objecthierarchy/src/orxonox/objects/infos/Level.cc2100
    /code/trunk/src/orxonox/objects/infos/Level.cc2-1925
File size: 4.5 KB
Line 
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"
37
38#include "Settings.h"
39#include "LevelManager.h"
40#include "PlayerInfo.h"
41#include "objects/gametypes/Gametype.h"
42
43#include "util/Math.h"
44
45namespace orxonox
46{
47    CreateFactory(Level);
48
49    Level::Level(BaseObject* creator) : Info(creator)
50    {
51        RegisterObject(Level);
52
53        this->registerVariables();
54        this->xmlfilename_ = this->getFilename();
55
56        if (this->xmlfilename_.length() >= Settings::getDataPath().length())
57            this->xmlfilename_ = this->xmlfilename_.substr(Settings::getDataPath().length());
58    }
59
60    Level::~Level()
61    {
62        if (this->isInitialized())
63        {
64            LevelManager::getInstance().releaseActivity(this);
65
66            if (this->xmlfile_)
67                Loader::unload(this->xmlfile_);
68        }
69    }
70
71    void Level::XMLPort(Element& xmlelement, XMLPort::Mode mode)
72    {
73        SUPER(Level, XMLPort, xmlelement, mode);
74
75        XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
76        XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
77
78        XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
79    }
80
81    void Level::registerVariables()
82    {
83        REGISTERSTRING(this->xmlfilename_, network::direction::toclient, new network::NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
84        REGISTERSTRING(this->name_,        network::direction::toclient, new network::NetworkCallback<Level>(this, &Level::changedName));
85        REGISTERSTRING(this->description_, network::direction::toclient);
86    }
87
88    void Level::networkcallback_applyXMLFile()
89    {
90        COUT(0) << "Loading level \"" << this->xmlfilename_ << "\"..." << std::endl;
91
92        ClassTreeMask mask;
93        mask.exclude(Class(BaseObject));
94        mask.include(Class(Template));
95
96        this->xmlfile_ = new XMLFile(Settings::getDataPath() + this->xmlfilename_, mask);
97
98        Loader::open(this->xmlfile_);
99    }
100
101    void Level::setGametypeString(const std::string& gametype)
102    {
103        Identifier* identifier = ClassByString(gametype);
104        if (identifier && identifier->isA(Class(Gametype)))
105        {
106            this->gametype_ = gametype;
107
108            Gametype* rootgametype = dynamic_cast<Gametype*>(identifier->fabricate(this));
109            this->setGametype(rootgametype);
110
111            for (std::list<BaseObject*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
112                (*it)->setGametype(rootgametype);
113
114            LevelManager::getInstance().requestActivity(this);
115        }
116    }
117
118
119    void Level::addObject(BaseObject* object)
120    {
121        this->objects_.push_back(object);
122        object->setGametype(this->getGametype());
123    }
124
125    BaseObject* Level::getObject(unsigned int index) const
126    {
127        unsigned int i = 0;
128        for (std::list<BaseObject*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
129        {
130            if (i == index)
131                return (*it);
132            ++i;
133        }
134        return 0;
135    }
136
137    void Level::playerEntered(PlayerInfo* player)
138    {
139        COUT(3) << "player entered level" << std::endl;
140        player->setGametype(this->getGametype());
141    }
142
143    void Level::playerLeft(PlayerInfo* player)
144    {
145        COUT(3) << "player left level" << std::endl;
146        player->setGametype(0);
147    }
148}
Note: See TracBrowser for help on using the repository browser.