Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/tools/mount_point.cc @ 10763

Last change on this file since 10763 was 10698, checked in by snellen, 18 years ago

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

File size: 6.1 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#include "weapons/weapon.h"
25
26#include "particles/particle_system.h"
27
28#include "mount_point.h"
29#include "debug.h"
30#include "state.h"
31
32
33ObjectListDefinition(MountPoint);
34
35
36/**
37 * construct
38 */
39MountPoint::MountPoint (const Vector& up, const Vector& forward, const Vector& center,  const std::string& name)
40{
41//   PRINTF(0)("Created mount point %s\n", name.c_str());
42  this->registerObject(this, MountPoint::_objectList);
43
44  this->_name = name;
45  this->setRelCoor( center);
46  this->setRelDir( Quaternion(forward, up));
47
48  this->_center = center;
49  this->_up = up;
50  this->_forward = forward;
51
52  this->init();
53}
54
55
56
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);
71
72  this->_mount = NULL;
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 */
80void MountPoint::initMountPoint(const TiXmlElement* root)
81{
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  }
117}
118
119
120
121/**
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  {
147//     PRINTF(0)("Got detailed informations\n");
148    this->_mount->loadParams( root);
149
150    if( this->_mount->isA(ParticleSystem::staticClassID()))
151    {
152//       PRINTF(0)("got particle system. attaching it to mp\n");
153      dynamic_cast<ParticleSystem*>(this->_mount)->attachEmmittersTo(this, Vector(0,0,0),
154                                    this->getRelDir()*Quaternion(M_PI, Vector(0,1,0)));
155    }
156
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    {
185//       PRINTF(0)("Mount Point created a %s\n", obj->getCName());
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
194      dynamic_cast<WorldEntity*>(this->_mount)->toList((OM_LIST)(this->getOMListNumber()));
195    }
196    else if( obj->isA( WeaponSlot::staticClassID()))
197    {
198//       PRINTF(0)("=========+>we got a weapon slot at\n");
199//       this->getAbsCoor().debug();
200// //       this->_center.debug();
201
202
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
207      this->_mount->setAbsCoor( this->_center);
208      this->_mount->setAbsDir( Quaternion(_forward, _up));
209      this->_mount->setParent( this);
210    }
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/**
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{
242  // invoke the underlying pnode debug draw
243  this->debugDraw();
244}
245
246
247/**
248 * adds an entity to this mount point
249 * @param entity entity to be added
250 */
251void MountPoint::mount(PNode* entity)
252{
253  this->_mount = entity;
254}
255
256
257/**
258 * removes an entity from this mount point
259 */
260void MountPoint::unmount()
261{
262  this->_mount = NULL;
263}
264
Note: See TracBrowser for help on using the repository browser.