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