Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/mount_point.cc @ 10583

Last change on this file since 10583 was 10523, checked in by patrick, 18 years ago

tried fixing the segfault on tardis, emitter mount point attach

File size: 5.5 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#include "util/loading/load_param_xml.h"
22
23#include "weapons/weapon_slot.h"
24
25#include "particles/particle_system.h"
26
27#include "mount_point.h"
28#include "debug.h"
29#include "state.h"
30
31
32ObjectListDefinition(MountPoint);
33
34
35/**
36 * construct
37 */
38MountPoint::MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name)
39{
40  PRINTF(0)("Created mount point %s\n", name.c_str());
41  this->registerObject(this, MountPoint::_objectList);
42
43  this->_name = name;
44  this->setAbsCoor( center);
45  this->setAbsDir( Quaternion(forward, up));
46
47  this->init();
48}
49
50
51
52/**
53 * deconstructor
54 */
55MountPoint::~MountPoint ()
56{}
57
58
59/**
60 * initializing function
61 */
62void MountPoint::init()
63{
64  this->registerObject(this, MountPoint::_objectList);
65  this->toList(OM_GROUP_00);
66
67  this->_mount = NULL;
68}
69
70
71/**
72 * loads the Settings of a MD2Creature from an XML-element.
73 * @param root the XML-element to load the MD2Creature's properties from
74 */
75void MountPoint::initMountPoint(const TiXmlElement* root)
76{
77  if( root == NULL)
78  {
79    PRINTF(1)("MountPoint - initialization failed, since I got no valid xml element\n");
80    return;
81  }
82  // now get the first element
83  const TiXmlElement* element = root->FirstChildElement("MountPoints");
84  if( element == NULL)
85  {
86    PRINTF(1)("I am in section: %s, Object Information file is missing a proper 'MountPoints' section\n", root->Value());
87//     element = root->FirstChildElement( );
88//     PRINTF(0)("first child: %s\n", element->Value());
89  }
90  else
91  {
92    element = element->FirstChildElement();
93    // parse the information for this mount point
94
95    PRINTF(4)("Loading WorldEntities\n");
96    while( element != NULL)
97    {
98      std::string name = element->Value();
99
100      PRINTF(5)("checking %s against local %s\n", name.c_str(), this->_name.c_str());
101      // check if we got the right mount point
102      if( this->_name.find(name, 0) != std::string::npos)
103      {
104        PRINTF(5)("found mount point %s\n", this->_name.c_str());
105        // load it
106        this->loadParam(element);
107      }
108
109      element = element->NextSiblingElement();
110    }
111  }
112}
113
114
115
116/**
117 * load the parameters from the xml section
118 * @param root the root element of this xml branche
119 */
120void MountPoint::loadParam(const TiXmlElement* root)
121{
122  // first check for the description
123  LoadParam(root, "Description", this, MountPoint, setDescription)
124  .describe("Sets this mount point a description");
125
126  // now check for the orx class to create
127  LoadParam(root, "OrxClass", this, MountPoint, setOrxClass)
128  .describe("Sets the class this mount points should host");
129
130  LoadParamXML(root, "Details", this, MountPoint, loadDetails);
131}
132
133
134/**
135 * load the parameters from the world entity
136 * @param root the root element of this xml branche
137 */
138void MountPoint::loadDetails(const TiXmlElement* root)
139{
140  if( this->_mount != NULL)
141  {
142    PRINTF(0)("Got detail informations\n");
143    this->_mount->loadParams( root);
144
145    if( this->_mount->isA(ParticleSystem::staticClassID()))
146    {
147      PRINTF(0)("got particle system. attaching it to mp\n");
148      dynamic_cast<ParticleSystem*>(this->_mount)->attachEmmittersTo(this, Vector(0,0,0));
149    }
150  }
151}
152
153
154/**
155 * setst the description (optional) via xml tag
156 * @param description string containing the description
157 */
158void MountPoint::setDescription(const std::string& description)
159{
160  this->_description = description;
161}
162
163
164
165/**
166 * sets the class of this mount point
167 * @param orxClass class
168 */
169void MountPoint::setOrxClass(const std::string& orxClass)
170{
171  // create the object for this mount point
172  BaseObject* obj = Factory::fabricate(orxClass);
173  // check if the object is created correctly
174  if( obj != NULL)
175  {
176    if( obj->isA( WorldEntity::staticClassID()))
177    {
178      PRINTF(0)("Mount Point created a %s\n", obj->getCName());
179      // cast down the object to WE
180      this->_mount = dynamic_cast<WorldEntity*>(obj);
181
182      // now set the position, direction and reparent it to this node
183      this->_mount->setAbsCoor( this->getAbsCoor());
184      this->_mount->setAbsDir( this->getAbsDir());
185      this->_mount->setParent( this);
186
187      this->_mount->toList((OM_LIST)(this->getOMListNumber()));
188    }
189    else if( obj->isA( WeaponSlot::staticClassID()))
190    {
191      PRINTF(0)("=========+>we got a weapon slot\n");
192    }
193  }
194  else
195    PRINTF(1)("Couldn't create %s for this mount point (%s)\n", orxClass.c_str(), this->_name.c_str());
196}
197
198
199
200/**
201 * tick
202 * @param time  time passed since the last tick
203 */
204void MountPoint::tick (float time)
205{
206
207}
208
209
210/**
211 * draw this entity
212 */
213void MountPoint::draw() const
214{
215}
216
217
218
219/**
220 *  function called to draw the mount point itself for debug purposes only
221 */
222void MountPoint::debugDraw() const
223{
224  // invoke the underlying pnode debug draw
225  this->debugDraw();
226}
227
228
229/**
230 * adds an entity to this mount point
231 * @param entity entity to be added
232 */
233void MountPoint::mount(WorldEntity* entity)
234{
235  this->_mount = entity;
236}
237
238
239/**
240 * removes an entity from this mount point
241 */
242void MountPoint::unmount()
243{
244  this->_mount = NULL;
245}
246
Note: See TracBrowser for help on using the repository browser.