Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/core/BaseObject.cc @ 1989

Last change on this file since 1989 was 1989, checked in by landauf, 16 years ago
  • added ControllableEntity, the baseclass of all players, vehicles and ships.
  • moved Template to core
  • some changes in Camera
  • added 6 constants to WorldEntity to identify relative directions
  • changed vom Radian to Degree as default angle unit
  • Property svn:eol-style set to native
File size: 3.6 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/**
30    @file
31    @brief Implementation of the BaseObject class.
32*/
33
34#include "BaseObject.h"
35#include "tinyxml/tinyxml.h"
36#include "CoreIncludes.h"
37#include "XMLPort.h"
38#include "Level.h"
39#include "Template.h"
40
41namespace orxonox
42{
43    CreateFactory(BaseObject);
44
45    /**
46        @brief Constructor: Registers the object in the BaseObject-list.
47    */
48    BaseObject::BaseObject() : bInitialized_(false)
49    {
50        RegisterRootObject(BaseObject);
51
52        this->bInitialized_ = true;
53
54        this->bActive_ = true;
55        this->bVisible_ = true;
56
57        this->level_ = 0;
58        this->namespace_ = 0;
59    }
60
61    /**
62        @brief Destructor
63    */
64    BaseObject::~BaseObject()
65    {
66    }
67
68    /**
69        @brief XML loading and saving.
70        @param xmlelement The XML-element
71        @param loading Loading (true) or saving (false)
72        @return The XML-element
73    */
74    void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        XMLPortParam(BaseObject, "name", setName, getName, xmlelement, mode);
77        XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
78        XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
79
80        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, const std::string&);
81    }
82
83    /**
84        @brief Returns the levelfile that loaded this object.
85        @return The levelfile
86    */
87    const std::string& BaseObject::getLevelfile() const
88    {
89        return this->level_->getFile();
90    }
91
92    /**
93        @brief Adds a Template to the object.
94        @param name The name of the Template
95    */
96    void BaseObject::addTemplate(const std::string& name)
97    {
98        Template* temp = Template::getTemplate(name);
99        if (temp)
100            this->addTemplate(temp);
101        else
102            COUT(1) << "Error: \"" << name << "\" is not a valid Template name (in class: " << this->getIdentifier()->getName() << ", name: " << this->getName() << ")." << std::endl;
103    }
104
105    /**
106        @brief Adds a Template to the object.
107        @param temp The Template
108    */
109    void BaseObject::addTemplate(Template* temp)
110    {
111        this->templates_.insert(temp);
112        temp->applyOn(this);
113    }
114
115    /**
116        @brief Returns the Template with the given index.
117        @param index The index
118    */
119    Template* BaseObject::getTemplate(unsigned int index) const
120    {
121        unsigned int i = 0;
122        for (std::set<Template*>::const_iterator it = this->templates_.begin(); it != this->templates_.end(); ++it)
123        {
124            if (i == index)
125                return (*it);
126            i++;
127        }
128        return 0;
129    }
130}
Note: See TracBrowser for help on using the repository browser.