Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/mount_points/src/world_entities/mount_point.cc @ 10240

Last change on this file since 10240 was 10240, checked in by patrick, 17 years ago

not checkinf for invalid xml files. runs again

File size: 4.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific
12   main-programmer: Patrick Boenzli, patrick@orxonox.net
13   co-programmer:
14*/
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
16
17
18#include "executor/executor.h"
19#include "util/loading/factory.h"
20#include "util/loading/load_param.h"
21
22
23#include "mount_point.h"
24#include "debug.h"
25#include "state.h"
26
27
28ObjectListDefinition(MountPoint);
29
30
31/**
32 * construct
33 */
34MountPoint::MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name)
35{
36  PRINTF(0)("Created mount point %s\n", name.c_str());
37
38  this->_name = name;
39  this->setAbsCoor( center);
40  this->setAbsDir( Quaternion(forward, up));
41
42  this->init();
43}
44
45
46
47/**
48 * deconstructor
49 */
50MountPoint::~MountPoint ()
51{}
52
53
54/**
55 * initializing function
56 */
57void MountPoint::init()
58{
59  this->registerObject(this, MountPoint::_objectList);
60  this->toList(OM_GROUP_00);
61
62  this->_mount = NULL;
63}
64
65
66/**
67 * loads the Settings of a MD2Creature from an XML-element.
68 * @param root the XML-element to load the MD2Creature's properties from
69 */
70void MountPoint::initMountPoint(const TiXmlElement* root)
71{
72  if( root == NULL)
73  {
74    PRINTF(1)("MountPoint - initialization failed, since I got no valid xml element\n");
75    return;
76  }
77  // now get the first element
78  const TiXmlElement* element = root->FirstChildElement("MountPoints");
79  if( element == NULL)
80  {
81    PRINTF(1)("Object Information file is missing a proper 'MountPoints' section\n");
82  }
83  else
84  {
85    element = element->FirstChildElement();
86    // parse the information for this mount point
87
88    PRINTF(4)("Loading WorldEntities\n");
89    while( element != NULL)
90    {
91      std::string name = element->Value();
92
93      // check if we got the right mount point
94      if( name == this->_name)
95      {
96        // load it
97        this->loadParam(element);
98      }
99
100      element = element->NextSiblingElement();
101    }
102  }
103}
104
105
106
107/**
108 * load the parameters from the xml section
109 * @param root the root element of this xml branche
110 */
111void MountPoint::loadParam(const TiXmlElement* root)
112{
113  // first check for the description
114  LoadParam(root, "Description", this, MountPoint, setDescription)
115  .describe("Sets this mount point a description");
116
117  // now check for the orx class to create
118  LoadParam(root, "OrxClass", this, MountPoint, setOrxClass)
119  .describe("Sets the class this mount points should host");
120}
121
122
123
124/**
125 * setst the description (optional) via xml tag
126 * @param description string containing the description
127 */
128void MountPoint::setDescription(const std::string& description)
129{
130  this->_description = description;
131}
132
133
134
135/**
136 * sets the class of this mount point
137 * @param orxClass class
138 */
139void MountPoint::setOrxClass(const std::string& orxClass)
140{
141  // create the object for this mount point
142  BaseObject* obj = Factory::fabricate(orxClass);
143  // check if the object is created correctly
144  if( this->_mount != NULL)
145  {
146    if( obj->isA( WorldEntity::staticClassID()))
147    {
148      this->_mount = dynamic_cast<WorldEntity*>(obj);
149    }
150  }
151  else
152    PRINTF(1)("Couldn't create %s for this mount point (%s)\n", orxClass.c_str(), this->_name.c_str());
153}
154
155
156
157/**
158 * tick
159 * @param time  time passed since the last tick
160 */
161void MountPoint::tick (float time)
162{
163
164}
165
166
167/**
168 * draw this entity
169 */
170void MountPoint::draw() const
171{
172}
173
174
175
176/**
177 *  function called to draw the mount point itself for debug purposes only
178 */
179void MountPoint::debugDraw() const
180{
181  // invoke the underlying pnode debug draw
182  this->debugDraw();
183}
184
185
186/**
187 * adds an entity to this mount point
188 * @param entity entity to be added
189 */
190void MountPoint::mount(WorldEntity* entity)
191{
192  this->_mount = entity;
193}
194
195
196/**
197 * removes an entity from this mount point
198 */
199void MountPoint::unmount()
200{
201  this->_mount = NULL;
202}
203
Note: See TracBrowser for help on using the repository browser.