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