Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/mount_point.cc @ 10546

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

debug, and better slot pos

File size: 5.9 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->setRelCoor( center);
45  this->setRelDir( 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 detailed 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                                    this->getRelDir()*Quaternion(M_PI, Vector(0,1,0)));
150    }
151  }
152}
153
154
155/**
156 * setst the description (optional) via xml tag
157 * @param description string containing the description
158 */
159void MountPoint::setDescription(const std::string& description)
160{
161  this->_description = description;
162}
163
164
165
166/**
167 * sets the class of this mount point
168 * @param orxClass class
169 */
170void MountPoint::setOrxClass(const std::string& orxClass)
171{
172  // create the object for this mount point
173  BaseObject* obj = Factory::fabricate(orxClass);
174  // check if the object is created correctly
175  if( obj != NULL)
176  {
177    if( obj->isA( WorldEntity::staticClassID()))
178    {
179//       PRINTF(0)("Mount Point created a %s\n", obj->getCName());
180      // cast down the object to WE
181      this->_mount = dynamic_cast<WorldEntity*>(obj);
182
183      // now set the position, direction and reparent it to this node
184      this->_mount->setAbsCoor( this->getAbsCoor());
185      this->_mount->setAbsDir( this->getAbsDir());
186      this->_mount->setParent( this);
187
188      dynamic_cast<WorldEntity*>(this->_mount)->toList((OM_LIST)(this->getOMListNumber()));
189    }
190    else if( obj->isA( WeaponSlot::staticClassID()))
191    {
192      PRINTF(0)("=========+>we got a weapon slot at\n");
193      this->getRelCoor().debug();
194
195
196      // cast down the object to WE
197      this->_mount = dynamic_cast<WeaponSlot*>(obj);
198
199      // now set the position, direction and reparent it to this node
200      this->_mount->setRelCoor( this->getRelCoor());
201      this->_mount->setRelDir( this->getRelDir());
202      this->_mount->setParent( this);
203    }
204  }
205  else
206    PRINTF(1)("Couldn't create %s for this mount point (%s)\n", orxClass.c_str(), this->_name.c_str());
207}
208
209
210
211/**
212 * tick
213 * @param time  time passed since the last tick
214 */
215void MountPoint::tick (float time)
216{
217
218}
219
220
221/**
222 * draw this entity
223 */
224void MountPoint::draw() const
225{
226}
227
228
229
230/**
231 *  function called to draw the mount point itself for debug purposes only
232 */
233void MountPoint::debugDraw() const
234{
235  // invoke the underlying pnode debug draw
236  this->debugDraw();
237}
238
239
240/**
241 * adds an entity to this mount point
242 * @param entity entity to be added
243 */
244void MountPoint::mount(PNode* entity)
245{
246  this->_mount = entity;
247}
248
249
250/**
251 * removes an entity from this mount point
252 */
253void MountPoint::unmount()
254{
255  this->_mount = NULL;
256}
257
Note: See TracBrowser for help on using the repository browser.