Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10550 was 10549, checked in by patrick, 18 years ago

more on mounting weapons

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