Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/tools/mount_point.cc

Last change on this file was 10698, checked in by snellen, 17 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

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