| [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 | |
|---|
| 32 | ObjectListDefinition(MountPoint); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * construct |
|---|
| 37 | */ |
|---|
| [10314] | 38 | MountPoint::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 | |
|---|
| 47 | this->init(); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| [10314] | 51 | |
|---|
| [10050] | 52 | /** |
|---|
| 53 | * deconstructor |
|---|
| 54 | */ |
|---|
| 55 | MountPoint::~MountPoint () |
|---|
| 56 | {} |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | * initializing function |
|---|
| 61 | */ |
|---|
| 62 | void MountPoint::init() |
|---|
| 63 | { |
|---|
| 64 | this->registerObject(this, MountPoint::_objectList); |
|---|
| 65 | this->toList(OM_GROUP_00); |
|---|
| [10057] | 66 | |
|---|
| [10058] | 67 | this->_mount = NULL; |
|---|
| [10050] | 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 | */ |
|---|
| [10314] | 75 | void MountPoint::initMountPoint(const TiXmlElement* root) |
|---|
| [10050] | 76 | { |
|---|
| [10314] | 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 | } |
|---|
| [10050] | 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | /** |
|---|
| [10314] | 117 | * load the parameters from the xml section |
|---|
| 118 | * @param root the root element of this xml branche |
|---|
| 119 | */ |
|---|
| 120 | void 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 | */ |
|---|
| 138 | void MountPoint::loadDetails(const TiXmlElement* root) |
|---|
| 139 | { |
|---|
| 140 | if( this->_mount != NULL) |
|---|
| 141 | { |
|---|
| [10542] | 142 | // PRINTF(0)("Got detailed informations\n"); |
|---|
| [10314] | 143 | this->_mount->loadParams( root); |
|---|
| [10523] | 144 | |
|---|
| 145 | if( this->_mount->isA(ParticleSystem::staticClassID())) |
|---|
| 146 | { |
|---|
| [10542] | 147 | // PRINTF(0)("got particle system. attaching it to mp\n"); |
|---|
| [10529] | 148 | dynamic_cast<ParticleSystem*>(this->_mount)->attachEmmittersTo(this, Vector(0,0,0), |
|---|
| 149 | this->getRelDir()*Quaternion(M_PI, Vector(0,1,0))); |
|---|
| [10523] | 150 | } |
|---|
| [10314] | 151 | } |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | /** |
|---|
| 156 | * setst the description (optional) via xml tag |
|---|
| 157 | * @param description string containing the description |
|---|
| 158 | */ |
|---|
| 159 | void 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 | */ |
|---|
| 170 | void 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 | { |
|---|
| [10542] | 179 | // PRINTF(0)("Mount Point created a %s\n", obj->getCName()); |
|---|
| [10314] | 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 | |
|---|
| [10534] | 188 | dynamic_cast<WorldEntity*>(this->_mount)->toList((OM_LIST)(this->getOMListNumber())); |
|---|
| [10314] | 189 | } |
|---|
| [10440] | 190 | else if( obj->isA( WeaponSlot::staticClassID())) |
|---|
| 191 | { |
|---|
| [10546] | 192 | PRINTF(0)("=========+>we got a weapon slot at\n"); |
|---|
| 193 | this->getRelCoor().debug(); |
|---|
| [10534] | 194 | |
|---|
| [10546] | 195 | |
|---|
| [10534] | 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 |
|---|
| [10546] | 200 | this->_mount->setRelCoor( this->getRelCoor()); |
|---|
| 201 | this->_mount->setRelDir( this->getRelDir()); |
|---|
| [10534] | 202 | this->_mount->setParent( this); |
|---|
| [10440] | 203 | } |
|---|
| [10314] | 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 | /** |
|---|
| [10050] | 212 | * tick |
|---|
| 213 | * @param time time passed since the last tick |
|---|
| 214 | */ |
|---|
| 215 | void MountPoint::tick (float time) |
|---|
| 216 | { |
|---|
| 217 | |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | /** |
|---|
| 222 | * draw this entity |
|---|
| 223 | */ |
|---|
| 224 | void MountPoint::draw() const |
|---|
| 225 | { |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | /** |
|---|
| 231 | * function called to draw the mount point itself for debug purposes only |
|---|
| 232 | */ |
|---|
| 233 | void MountPoint::debugDraw() const |
|---|
| 234 | { |
|---|
| [10314] | 235 | // invoke the underlying pnode debug draw |
|---|
| 236 | this->debugDraw(); |
|---|
| [10050] | 237 | } |
|---|
| [10057] | 238 | |
|---|
| 239 | |
|---|
| 240 | /** |
|---|
| 241 | * adds an entity to this mount point |
|---|
| 242 | * @param entity entity to be added |
|---|
| 243 | */ |
|---|
| [10534] | 244 | void MountPoint::mount(PNode* entity) |
|---|
| [10058] | 245 | { |
|---|
| 246 | this->_mount = entity; |
|---|
| 247 | } |
|---|
| [10057] | 248 | |
|---|
| 249 | |
|---|
| 250 | /** |
|---|
| 251 | * removes an entity from this mount point |
|---|
| 252 | */ |
|---|
| 253 | void MountPoint::unmount() |
|---|
| [10058] | 254 | { |
|---|
| 255 | this->_mount = NULL; |
|---|
| 256 | } |
|---|
| 257 | |
|---|