Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10556 was 10551, checked in by patrick, 18 years ago

much less debug out. mounting weapons works now

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
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->_center = center;
48  this->_up = up;
49  this->_forward = forward;
50
51  this->init();
52}
53
54
55
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);
70
71  this->_mount = NULL;
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 */
79void MountPoint::initMountPoint(const TiXmlElement* root)
80{
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  }
116}
117
118
119
120/**
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  {
146//     PRINTF(0)("Got detailed informations\n");
147    this->_mount->loadParams( root);
148
149    if( this->_mount->isA(ParticleSystem::staticClassID()))
150    {
151//       PRINTF(0)("got particle system. attaching it to mp\n");
152      dynamic_cast<ParticleSystem*>(this->_mount)->attachEmmittersTo(this, Vector(0,0,0),
153                                    this->getRelDir()*Quaternion(M_PI, Vector(0,1,0)));
154    }
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    {
183//       PRINTF(0)("Mount Point created a %s\n", obj->getCName());
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
192      dynamic_cast<WorldEntity*>(this->_mount)->toList((OM_LIST)(this->getOMListNumber()));
193    }
194    else if( obj->isA( WeaponSlot::staticClassID()))
195    {
196//       PRINTF(0)("=========+>we got a weapon slot at\n");
197//       this->getAbsCoor().debug();
198// //       this->_center.debug();
199
200
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
205      this->_mount->setAbsCoor( this->_center);
206      this->_mount->setAbsDir( Quaternion(_forward, _up));
207      this->_mount->setParent( this);
208    }
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/**
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{
240  // invoke the underlying pnode debug draw
241  this->debugDraw();
242}
243
244
245/**
246 * adds an entity to this mount point
247 * @param entity entity to be added
248 */
249void MountPoint::mount(PNode* entity)
250{
251  this->_mount = entity;
252}
253
254
255/**
256 * removes an entity from this mount point
257 */
258void MountPoint::unmount()
259{
260  this->_mount = NULL;
261}
262
Note: See TracBrowser for help on using the repository browser.