[2036] | 1 | |
---|
| 2 | |
---|
[4570] | 3 | /* |
---|
[2036] | 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
[10314] | 14 | main-programmer: Patrick Boenzli |
---|
| 15 | main-programmer: Benjamin Grauer |
---|
| 16 | co-programmer: Christian Meier |
---|
[2036] | 17 | */ |
---|
[5300] | 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
[2036] | 19 | |
---|
| 20 | #include "world_entity.h" |
---|
[5208] | 21 | #include "shell_command.h" |
---|
[5143] | 22 | |
---|
[9869] | 23 | #include "util/loading/resource_manager.h" |
---|
| 24 | #include "resource_obj.h" |
---|
[8490] | 25 | #include "md2/md2Model.h" |
---|
| 26 | #include "md3/md3_model.h" |
---|
| 27 | |
---|
[10147] | 28 | #include "oif/object_information_file.h" |
---|
| 29 | #include "mount_point.h" |
---|
| 30 | |
---|
[8724] | 31 | #include "aabb_tree_node.h" |
---|
| 32 | |
---|
[7193] | 33 | #include "util/loading/load_param.h" |
---|
[10368] | 34 | #include "loading/load_param_xml.h" |
---|
| 35 | #include "util/loading/factory.h" |
---|
| 36 | |
---|
[4682] | 37 | #include "obb_tree.h" |
---|
[3608] | 38 | |
---|
[8974] | 39 | #include "elements/glgui_energywidget.h" |
---|
[10368] | 40 | #include "elements/glgui_energywidgetvertical.h" |
---|
[6430] | 41 | |
---|
[6002] | 42 | #include "state.h" |
---|
[7014] | 43 | #include "camera.h" |
---|
[6002] | 44 | |
---|
[10013] | 45 | #include "collision_filter.h" |
---|
[8190] | 46 | #include "collision_event.h" |
---|
[8777] | 47 | #include "game_rules.h" |
---|
| 48 | #include "kill.h" |
---|
[9869] | 49 | #include "debug.h" |
---|
[7927] | 50 | |
---|
[10368] | 51 | #include "track/track.h" |
---|
| 52 | |
---|
[9869] | 53 | #include "projectiles/projectile.h" |
---|
[7927] | 54 | |
---|
[5208] | 55 | SHELL_COMMAND(model, WorldEntity, loadModel) |
---|
[6430] | 56 | ->describe("sets the Model of the WorldEntity") |
---|
[7711] | 57 | ->defaultValues("models/ships/fighter.obj", 1.0f); |
---|
[5208] | 58 | |
---|
[6424] | 59 | SHELL_COMMAND(debugEntity, WorldEntity, debugWE); |
---|
[5208] | 60 | |
---|
[9869] | 61 | |
---|
| 62 | ObjectListDefinition(WorldEntity); |
---|
[2043] | 63 | /** |
---|
[4836] | 64 | * Loads the WordEntity-specific Part of any derived Class |
---|
[5498] | 65 | * |
---|
| 66 | * @param root: Normally NULL, as the Derived Entities define a loadParams Function themeselves, |
---|
| 67 | * that can calls WorldEntities loadParams for itself. |
---|
| 68 | */ |
---|
[6430] | 69 | WorldEntity::WorldEntity() |
---|
[10391] | 70 | : Synchronizeable(), _collisionFilter(this) |
---|
[2190] | 71 | { |
---|
[9869] | 72 | this->registerObject(this, WorldEntity::_objectList); |
---|
[4597] | 73 | |
---|
[4682] | 74 | this->obbTree = NULL; |
---|
[8724] | 75 | this->aabbNode = NULL; |
---|
[6700] | 76 | this->healthWidget = NULL; |
---|
| 77 | this->healthMax = 1.0f; |
---|
| 78 | this->health = 1.0f; |
---|
[8190] | 79 | this->damage = 0.0f; // no damage dealt by a default entity |
---|
[6695] | 80 | this->scaling = 1.0f; |
---|
[10147] | 81 | this->oiFile = NULL; |
---|
[10314] | 82 | // add 10 members to this array |
---|
| 83 | this->mountPoints.reserve(10); |
---|
[4261] | 84 | |
---|
[6695] | 85 | /* OSOLETE */ |
---|
| 86 | this->bVisible = true; |
---|
| 87 | this->bCollide = true; |
---|
| 88 | |
---|
[6142] | 89 | this->objectListNumber = OM_INIT; |
---|
[9003] | 90 | this->lastObjectListNumber = OM_INIT; |
---|
[6142] | 91 | |
---|
[10013] | 92 | this->_bOnGround = false; |
---|
[8190] | 93 | |
---|
[10368] | 94 | // Track of this entity |
---|
| 95 | this->entityTrack = NULL; |
---|
| 96 | |
---|
[8190] | 97 | // registering default reactions: |
---|
[10013] | 98 | this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID()); |
---|
[8190] | 99 | |
---|
[6142] | 100 | this->toList(OM_NULL); |
---|
[9235] | 101 | |
---|
[10013] | 102 | this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) ); |
---|
| 103 | this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) ); |
---|
| 104 | this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) ); |
---|
| 105 | this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) ); |
---|
[9235] | 106 | |
---|
[10013] | 107 | this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) ); |
---|
| 108 | this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) ); |
---|
[2190] | 109 | } |
---|
[2043] | 110 | |
---|
| 111 | /** |
---|
[4836] | 112 | * standard destructor |
---|
[2043] | 113 | */ |
---|
[2190] | 114 | WorldEntity::~WorldEntity () |
---|
[2036] | 115 | { |
---|
[7125] | 116 | State::getObjectManager()->toList(this, OM_INIT); |
---|
| 117 | |
---|
| 118 | // Delete the model (unregister it with the ResourceManager) |
---|
| 119 | for (unsigned int i = 0; i < this->models.size(); i++) |
---|
| 120 | this->setModel(NULL, i); |
---|
| 121 | |
---|
[10147] | 122 | // remove the object information file |
---|
| 123 | if( this->oiFile) |
---|
| 124 | delete this->oiFile; |
---|
| 125 | // and clear all monut points |
---|
| 126 | this->mountPoints.clear(); |
---|
| 127 | |
---|
[5498] | 128 | // Delete the obbTree |
---|
[5302] | 129 | if( this->obbTree != NULL) |
---|
[4814] | 130 | delete this->obbTree; |
---|
[5994] | 131 | |
---|
[6700] | 132 | if (this->healthWidget != NULL) |
---|
| 133 | delete this->healthWidget; |
---|
[8190] | 134 | |
---|
[10013] | 135 | this->unsubscribeReactions(); |
---|
[3531] | 136 | } |
---|
| 137 | |
---|
[5498] | 138 | /** |
---|
| 139 | * loads the WorldEntity Specific Parameters. |
---|
| 140 | * @param root: the XML-Element to load the Data From |
---|
| 141 | */ |
---|
[4436] | 142 | void WorldEntity::loadParams(const TiXmlElement* root) |
---|
| 143 | { |
---|
[5498] | 144 | // Do the PNode loading stuff |
---|
[6512] | 145 | PNode::loadParams(root); |
---|
[5498] | 146 | |
---|
[6222] | 147 | LoadParam(root, "md2texture", this, WorldEntity, loadMD2Texture) |
---|
[6430] | 148 | .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)") |
---|
[7198] | 149 | .defaultValues(""); |
---|
[6222] | 150 | |
---|
[4436] | 151 | // Model Loading |
---|
[5671] | 152 | LoadParam(root, "model", this, WorldEntity, loadModel) |
---|
[6430] | 153 | .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") |
---|
[7198] | 154 | .defaultValues("", 1.0f, 0); |
---|
[6430] | 155 | |
---|
[10314] | 156 | LoadParam(root, "mountpoints", this, WorldEntity, loadMountPoints) |
---|
| 157 | .describe("the fileName of the object information file (optional)"); |
---|
| 158 | |
---|
[10368] | 159 | // Entity Attributes |
---|
[6700] | 160 | LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax) |
---|
| 161 | .describe("The Maximum health that can be loaded onto this entity") |
---|
[7198] | 162 | .defaultValues(1.0f); |
---|
[6430] | 163 | |
---|
[6700] | 164 | LoadParam(root, "health", this, WorldEntity, setHealth) |
---|
| 165 | .describe("The Health the WorldEntity has at this moment") |
---|
[7198] | 166 | .defaultValues(1.0f); |
---|
[9656] | 167 | |
---|
| 168 | LoadParam(root, "list", this, WorldEntity, toListS); |
---|
[10368] | 169 | |
---|
| 170 | |
---|
| 171 | // Track |
---|
| 172 | LoadParamXML(root, "Track", this, WorldEntity, addTrack) |
---|
[10391] | 173 | .describe("creates and adds a track to this WorldEntity"); |
---|
[4436] | 174 | } |
---|
| 175 | |
---|
[6222] | 176 | |
---|
[3531] | 177 | /** |
---|
[10368] | 178 | * this functions adds a track to this workd entity. This can be usefull, if you like this WE to follow a some waypoints. |
---|
| 179 | * here the track is created and further initializing left for the Track itself |
---|
| 180 | */ |
---|
| 181 | void WorldEntity::addTrack(const TiXmlElement* root) |
---|
| 182 | { |
---|
| 183 | // The problem we have is most likely here. The track should be constructed WITH the XML-Code |
---|
| 184 | this->entityTrack = new Track(root); |
---|
| 185 | this->setParent(this->entityTrack->getTrackNode()); |
---|
| 186 | this->entityTrack->getTrackNode()->setParentMode(PNODE_ALL); |
---|
| 187 | /*LOAD_PARAM_START_CYCLE(root, element); |
---|
| 188 | { |
---|
| 189 | PRINTF(4)("element is: %s\n", element->Value()); |
---|
| 190 | Factory::fabricate(element); |
---|
| 191 | } |
---|
| 192 | LOAD_PARAM_END_CYCLE(element);*/ |
---|
| 193 | |
---|
[10391] | 194 | |
---|
[10368] | 195 | } |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | /** |
---|
[4885] | 199 | * loads a Model onto a WorldEntity |
---|
[4836] | 200 | * @param fileName the name of the model to load |
---|
[5057] | 201 | * @param scaling the Scaling of the model |
---|
[7711] | 202 | * |
---|
| 203 | * FIXME |
---|
| 204 | * @todo: separate the obb tree generation from the model |
---|
[7221] | 205 | */ |
---|
[7711] | 206 | void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber, unsigned int obbTreeDepth) |
---|
[4261] | 207 | { |
---|
[6695] | 208 | this->modelLODName = fileName; |
---|
[6424] | 209 | this->scaling = scaling; |
---|
[7954] | 210 | |
---|
| 211 | std::string name = fileName; |
---|
| 212 | |
---|
[9869] | 213 | if ( name.find( Resources::ResourceManager::getInstance()->mainGlobalPath().name() ) == 0 ) |
---|
[7954] | 214 | { |
---|
[9869] | 215 | name.erase(Resources::ResourceManager::getInstance()->mainGlobalPath().name().size()); |
---|
[7954] | 216 | } |
---|
| 217 | |
---|
| 218 | this->modelFileName = name; |
---|
| 219 | |
---|
[7221] | 220 | if (!fileName.empty()) |
---|
[6142] | 221 | { |
---|
[6430] | 222 | // search for the special character # in the LoadParam |
---|
[7221] | 223 | if (fileName.find('#') != std::string::npos) |
---|
[6222] | 224 | { |
---|
[7221] | 225 | PRINTF(4)("Found # in %s... searching for LOD's\n", fileName.c_str()); |
---|
| 226 | std::string lodFile = fileName; |
---|
| 227 | unsigned int offset = lodFile.find('#'); |
---|
[6720] | 228 | for (unsigned int i = 0; i < 3; i++) |
---|
[6005] | 229 | { |
---|
[7221] | 230 | lodFile[offset] = 48+(int)i; |
---|
[9869] | 231 | if (Resources::ResourceManager::getInstance()->checkFileInMainPath( lodFile)) |
---|
[6222] | 232 | this->loadModel(lodFile, scaling, i); |
---|
[6005] | 233 | } |
---|
[6222] | 234 | return; |
---|
| 235 | } |
---|
[6720] | 236 | if (this->scaling <= 0.0) |
---|
[6424] | 237 | { |
---|
[7193] | 238 | PRINTF(1)("YOU GAVE ME A CRAPY SCALE resetting to 1.0\n"); |
---|
[6720] | 239 | this->scaling = 1.0; |
---|
[6424] | 240 | } |
---|
[9869] | 241 | /// LOADING AN OBJ FILE |
---|
[7221] | 242 | if(fileName.find(".obj") != std::string::npos) |
---|
[6222] | 243 | { |
---|
[7221] | 244 | PRINTF(4)("fetching OBJ file: %s\n", fileName.c_str()); |
---|
[10147] | 245 | // creating the model and loading it |
---|
[9869] | 246 | StaticModel* model = new StaticModel(); |
---|
| 247 | *model = ResourceOBJ(fileName, this->scaling); |
---|
[10314] | 248 | |
---|
| 249 | // check if ther is a valid model and load other stuff |
---|
[9869] | 250 | if (model->getVertexCount() > 0) |
---|
| 251 | { |
---|
| 252 | this->setModel(model, modelNumber); |
---|
[10314] | 253 | |
---|
[10391] | 254 | if( modelNumber == 0) |
---|
[10314] | 255 | { |
---|
[10391] | 256 | this->buildObbTree(obbTreeDepth); |
---|
[10314] | 257 | } |
---|
[9869] | 258 | } |
---|
[7221] | 259 | else |
---|
[9869] | 260 | delete model; |
---|
[6222] | 261 | } |
---|
[9869] | 262 | /// LOADING AN MD2-model |
---|
[7221] | 263 | else if(fileName.find(".md2") != std::string::npos) |
---|
[6222] | 264 | { |
---|
[7221] | 265 | PRINTF(4)("fetching MD2 file: %s\n", fileName.c_str()); |
---|
[7055] | 266 | Model* m = new MD2Model(fileName, this->md2TextureFileName, this->scaling); |
---|
[6430] | 267 | //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0); |
---|
[6222] | 268 | this->setModel(m, 0); |
---|
[7068] | 269 | |
---|
| 270 | if( m != NULL) |
---|
[7711] | 271 | this->buildObbTree(obbTreeDepth); |
---|
[6222] | 272 | } |
---|
[9869] | 273 | /// LOADING AN MD3-MODEL. |
---|
[9235] | 274 | else if(fileName.find(".md3") != std::string::npos) |
---|
[8490] | 275 | { |
---|
| 276 | PRINTF(4)("fetching MD3 file: %s\n", fileName.c_str()); |
---|
[10391] | 277 | // Model* m = new md3::MD3Model(fileName, this->scaling); |
---|
| 278 | // this->setModel(m, 0); |
---|
[8490] | 279 | |
---|
[9869] | 280 | // if( m != NULL) |
---|
| 281 | // this->buildObbTree(obbTreeDepth); |
---|
[8490] | 282 | } |
---|
[4732] | 283 | } |
---|
| 284 | else |
---|
[6341] | 285 | { |
---|
[5995] | 286 | this->setModel(NULL); |
---|
[6341] | 287 | } |
---|
[4261] | 288 | } |
---|
| 289 | |
---|
[5061] | 290 | /** |
---|
[5994] | 291 | * sets a specific Model for the Object. |
---|
| 292 | * @param model The Model to set |
---|
| 293 | * @param modelNumber the n'th model in the List to get. |
---|
| 294 | */ |
---|
| 295 | void WorldEntity::setModel(Model* model, unsigned int modelNumber) |
---|
| 296 | { |
---|
[5995] | 297 | if (this->models.size() <= modelNumber) |
---|
| 298 | this->models.resize(modelNumber+1, NULL); |
---|
| 299 | |
---|
| 300 | if (this->models[modelNumber] != NULL) |
---|
[6004] | 301 | { |
---|
[9869] | 302 | delete this->models[modelNumber]; |
---|
[5994] | 303 | } |
---|
[6222] | 304 | |
---|
[5995] | 305 | this->models[modelNumber] = model; |
---|
[5994] | 306 | } |
---|
| 307 | |
---|
| 308 | |
---|
[10147] | 309 | |
---|
[5994] | 310 | /** |
---|
[10147] | 311 | * loads the object information file for this model |
---|
| 312 | * @param fileName the name of the file |
---|
| 313 | */ |
---|
[10314] | 314 | void WorldEntity::loadMountPoints(const std::string& fileName) |
---|
[10147] | 315 | { |
---|
[10314] | 316 | PRINTF(5)("loading the oif File: %s\n", fileName.c_str()); |
---|
[10147] | 317 | |
---|
[10314] | 318 | // now load the object information file |
---|
[10147] | 319 | this->oiFile = new ObjectInformationFile(fileName); |
---|
[10314] | 320 | |
---|
| 321 | // get the model to load |
---|
| 322 | Model* model = this->getModel(); |
---|
| 323 | |
---|
| 324 | // extract the mount points |
---|
| 325 | model->extractMountPoints(); |
---|
| 326 | |
---|
| 327 | // first get all mount points from the model |
---|
| 328 | const std::list<mountPointSkeleton> mpList = model->getMountPoints(); |
---|
| 329 | // for each skeleton create a mounting point world entity |
---|
| 330 | std::list<mountPointSkeleton>::const_iterator it = mpList.begin(); |
---|
| 331 | |
---|
| 332 | for( ; it != mpList.end(); it++) |
---|
| 333 | { |
---|
| 334 | // create the mount points world entity |
---|
| 335 | MountPoint* mp = new MountPoint( (*it).up, (*it).forward, (*it).center, (*it).name); |
---|
| 336 | // parent it to this WE |
---|
| 337 | mp->setParent( this); |
---|
| 338 | // now add to the right group |
---|
| 339 | mp->toList( (OM_LIST)(this->getOMListNumber()+1)); |
---|
| 340 | // now get the number and add the mount point to the slot |
---|
| 341 | std::string nrStr = (*it).name.substr(3, 2); |
---|
| 342 | // add the mount point |
---|
| 343 | this->addMountPoint(atoi(nrStr.c_str()), mp); |
---|
| 344 | |
---|
| 345 | // now fill the mount point |
---|
| 346 | mp->initMountPoint( this->oiFile->getMountPointDescription()); |
---|
| 347 | } |
---|
| 348 | |
---|
[10147] | 349 | } |
---|
| 350 | |
---|
| 351 | |
---|
| 352 | /** |
---|
[5061] | 353 | * builds the obb-tree |
---|
| 354 | * @param depth the depth to calculate |
---|
| 355 | */ |
---|
[7711] | 356 | bool WorldEntity::buildObbTree(int depth) |
---|
[5061] | 357 | { |
---|
[9494] | 358 | if( this->obbTree != NULL) |
---|
| 359 | { |
---|
[5428] | 360 | delete this->obbTree; |
---|
[9494] | 361 | this->obbTree = NULL; |
---|
| 362 | } |
---|
[5428] | 363 | |
---|
[5995] | 364 | if (this->models[0] != NULL) |
---|
[7711] | 365 | this->obbTree = new OBBTree(depth, models[0]->getModelInfo(), this); |
---|
[5428] | 366 | else |
---|
| 367 | { |
---|
[7711] | 368 | PRINTF(1)("could not create obb-tree, because no model was loaded yet\n"); |
---|
[5428] | 369 | this->obbTree = NULL; |
---|
| 370 | return false; |
---|
| 371 | } |
---|
[8724] | 372 | |
---|
| 373 | |
---|
| 374 | // create the axis aligned bounding box |
---|
| 375 | if( this->aabbNode != NULL) |
---|
| 376 | { |
---|
| 377 | delete this->aabbNode; |
---|
| 378 | this->aabbNode = NULL; |
---|
| 379 | } |
---|
| 380 | |
---|
[9869] | 381 | if( this->models[0] != NULL) |
---|
| 382 | { |
---|
[8724] | 383 | this->aabbNode = new AABBTreeNode(); |
---|
| 384 | this->aabbNode->spawnBVTree(this->models[0]); |
---|
| 385 | } |
---|
[9494] | 386 | else |
---|
| 387 | { |
---|
| 388 | PRINTF(1)("could not create aabb bounding box, because no model was loaded yet\n"); |
---|
| 389 | this->aabbNode = NULL; |
---|
| 390 | return false; |
---|
| 391 | } |
---|
[8724] | 392 | return true; |
---|
[5061] | 393 | } |
---|
[5057] | 394 | |
---|
[7927] | 395 | |
---|
[6142] | 396 | /** |
---|
[10147] | 397 | * adds a mount point to the end of the list |
---|
| 398 | * @param mountPoint point to be added |
---|
| 399 | */ |
---|
| 400 | void WorldEntity::addMountPoint(MountPoint* mountPoint) |
---|
| 401 | { |
---|
| 402 | // add the mount point at the last position |
---|
| 403 | this->mountPoints.push_back(mountPoint); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | /** |
---|
| 407 | * adds a mount point to a world entity |
---|
| 408 | * @param mountPoint point to be added |
---|
| 409 | */ |
---|
| 410 | void WorldEntity::addMountPoint(int slot, MountPoint* mountPoint) |
---|
| 411 | { |
---|
[10314] | 412 | if( this->mountPoints.capacity() < (unsigned int)slot) |
---|
[10147] | 413 | { |
---|
[10314] | 414 | // reserve 5 more slots than needed so this function is called as rare as possible |
---|
| 415 | this->mountPoints.reserve(slot + 5); |
---|
[10147] | 416 | } |
---|
[10314] | 417 | else if( this->mountPoints[slot] != NULL) |
---|
| 418 | { |
---|
| 419 | PRINTF(4)("adding a mount point to a slot, that already is occupied! ignoring - maybe some object did not get connected well (object: %s)\n", this->getClassCName()); |
---|
| 420 | } |
---|
[10147] | 421 | |
---|
| 422 | // just connect the mount point |
---|
| 423 | this->mountPoints[slot] = mountPoint; |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | |
---|
| 427 | /** |
---|
| 428 | * mounts a world entity on a specified mount point (~socket) |
---|
| 429 | * @param entity entity to be connected |
---|
| 430 | */ |
---|
| 431 | void WorldEntity::mount(int slot, WorldEntity* entity) |
---|
| 432 | { |
---|
| 433 | if( this->mountPoints[slot] == NULL) |
---|
| 434 | { |
---|
| 435 | PRINTF(0)("you tried to add an entity to a mount point that doesn't exist (slot %i)\n", slot); |
---|
| 436 | return; |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | // mount the entity |
---|
| 440 | this->mountPoints[slot]->mount(entity); |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | |
---|
| 444 | /** |
---|
| 445 | * removes a mount point from a specified mount point |
---|
| 446 | * @param mountPoint entity to be unconnected |
---|
| 447 | */ |
---|
| 448 | void WorldEntity::unmount(int slot) |
---|
| 449 | { |
---|
[10391] | 450 | if( this->mountPoints[slot] == NULL) |
---|
[10147] | 451 | { |
---|
| 452 | PRINTF(0)("you tried to remove an entity from a mount point that doesn't exist (slot %i)\n", slot); |
---|
| 453 | return; |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | // unmount the entity |
---|
| 457 | this->mountPoints[slot]->unmount(); |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | |
---|
| 461 | /** |
---|
[7927] | 462 | * subscribes this world entity to a collision reaction |
---|
| 463 | * @param type the type of reaction to subscribe to |
---|
[8190] | 464 | * @param target1 a filter target (classID) |
---|
| 465 | */ |
---|
[10013] | 466 | void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1) |
---|
[8190] | 467 | { |
---|
[10013] | 468 | this->_collisionFilter.subscribeReaction(type, target1); |
---|
[8190] | 469 | } |
---|
| 470 | |
---|
| 471 | |
---|
| 472 | /** |
---|
| 473 | * subscribes this world entity to a collision reaction |
---|
| 474 | * @param type the type of reaction to subscribe to |
---|
| 475 | * @param target1 a filter target (classID) |
---|
| 476 | */ |
---|
[10013] | 477 | void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2) |
---|
[8190] | 478 | { |
---|
[10013] | 479 | this->_collisionFilter.subscribeReaction(type, target1, target2); |
---|
[8190] | 480 | } |
---|
| 481 | |
---|
| 482 | |
---|
| 483 | /** |
---|
| 484 | * subscribes this world entity to a collision reaction |
---|
| 485 | * @param type the type of reaction to subscribe to |
---|
| 486 | * @param target1 a filter target (classID) |
---|
| 487 | */ |
---|
[10013] | 488 | void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3) |
---|
[8190] | 489 | { |
---|
[10013] | 490 | this->_collisionFilter.subscribeReaction(type, target1, target2, target3); |
---|
[8190] | 491 | } |
---|
| 492 | |
---|
| 493 | |
---|
| 494 | /** |
---|
| 495 | * unsubscribes a specific reaction from the worldentity |
---|
| 496 | * @param type the reaction to unsubscribe |
---|
| 497 | */ |
---|
[10013] | 498 | void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type) |
---|
[8190] | 499 | { |
---|
[10013] | 500 | this->_collisionFilter.unsubscribeReaction(type); |
---|
[8190] | 501 | } |
---|
| 502 | |
---|
| 503 | |
---|
| 504 | /** |
---|
| 505 | * unsubscribes all collision reactions |
---|
| 506 | */ |
---|
[10013] | 507 | void WorldEntity::unsubscribeReactions() |
---|
[8190] | 508 | { |
---|
[10013] | 509 | this->_collisionFilter.unsubscribeReactions(); |
---|
[8190] | 510 | } |
---|
| 511 | |
---|
| 512 | |
---|
| 513 | /** |
---|
[6142] | 514 | * @brief moves this entity to the List OM_List |
---|
| 515 | * @param list the list to set this Entity to. |
---|
| 516 | * |
---|
| 517 | * this is the same as a call to State::getObjectManager()->toList(entity , list); |
---|
| 518 | * directly, but with an easier interface. |
---|
| 519 | * |
---|
| 520 | * @todo inline this (peut etre) |
---|
| 521 | */ |
---|
| 522 | void WorldEntity::toList(OM_LIST list) |
---|
| 523 | { |
---|
| 524 | State::getObjectManager()->toList(this, list); |
---|
| 525 | } |
---|
[5061] | 526 | |
---|
[9656] | 527 | void WorldEntity::toListS(const std::string& listName) |
---|
| 528 | { |
---|
| 529 | OM_LIST id = ObjectManager::StringToOMList(listName); |
---|
| 530 | if (id != OM_NULL) |
---|
| 531 | this->toList(id); |
---|
| 532 | else |
---|
| 533 | PRINTF(2)("List %s not found\n", listName.c_str()); |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | |
---|
[8037] | 537 | void WorldEntity::toReflectionList() |
---|
| 538 | { |
---|
| 539 | State::getObjectManager()->toReflectionList( this ); |
---|
| 540 | } |
---|
[6142] | 541 | |
---|
[8037] | 542 | void removeFromReflectionList() |
---|
| 543 | { |
---|
[9869] | 544 | /// TODO |
---|
| 545 | /// State::getObject |
---|
[8037] | 546 | } |
---|
[6142] | 547 | |
---|
[4261] | 548 | /** |
---|
[4885] | 549 | * sets the character attributes of a worldentity |
---|
[4836] | 550 | * @param character attributes |
---|
[4885] | 551 | * |
---|
| 552 | * these attributes don't have to be set, only use them, if you need them |
---|
[2043] | 553 | */ |
---|
[5498] | 554 | //void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr) |
---|
| 555 | //{} |
---|
[2036] | 556 | |
---|
[3583] | 557 | |
---|
[2043] | 558 | /** |
---|
[5029] | 559 | * this function is called, when two entities collide |
---|
| 560 | * @param entity: the world entity with whom it collides |
---|
| 561 | * |
---|
| 562 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 563 | */ |
---|
| 564 | void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 565 | { |
---|
[5498] | 566 | /** |
---|
| 567 | * THIS IS A DEFAULT COLLISION-Effect. |
---|
| 568 | * IF YOU WANT TO CREATE A SPECIFIC COLLISION ON EACH OBJECT |
---|
| 569 | * USE:: |
---|
| 570 | * if (entity->isA(CL_WHAT_YOU_ARE_LOOKING_FOR)) { printf "dothings"; }; |
---|
| 571 | * |
---|
| 572 | * You can always define a default Action.... don't be affraid just test it :) |
---|
| 573 | */ |
---|
[9406] | 574 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z); |
---|
[5029] | 575 | } |
---|
| 576 | |
---|
[2043] | 577 | |
---|
| 578 | /** |
---|
[8186] | 579 | * this function is called, when two entities collide |
---|
| 580 | * @param entity: the world entity with whom it collides |
---|
| 581 | * |
---|
| 582 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 583 | */ |
---|
| 584 | void WorldEntity::collidesWithGround(const Vector& location) |
---|
| 585 | { |
---|
[9406] | 586 | PRINTF(0)("BSP_GROUND: %s collides \n", this->getClassCName() ); |
---|
[8186] | 587 | } |
---|
| 588 | |
---|
| 589 | void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2) |
---|
| 590 | { |
---|
[8190] | 591 | |
---|
[9406] | 592 | // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassCName() ); |
---|
[8190] | 593 | |
---|
[8186] | 594 | Vector v = this->getAbsDirX(); |
---|
[8490] | 595 | v.x *= 10.1; |
---|
| 596 | v.y *= 10.1; |
---|
| 597 | v.z *= 10.1; |
---|
| 598 | Vector u = Vector(0.0,-20.0,0.0); |
---|
[8190] | 599 | |
---|
[8490] | 600 | |
---|
| 601 | if(!(this->getAbsCoor().x == ray_2.x && this->getAbsCoor().y == ray_2.y && this->getAbsCoor().z == ray_2.z) ) |
---|
[8186] | 602 | { |
---|
[8190] | 603 | |
---|
[9869] | 604 | this->setAbsCoor(ray_2 - v); |
---|
[8490] | 605 | |
---|
[8186] | 606 | } |
---|
[9869] | 607 | else |
---|
[8186] | 608 | { |
---|
| 609 | if(ray_1.x == this->getAbsCoor().x + v.x && ray_1.y == this->getAbsCoor().y + v.y + 0.1 && ray_1.z ==this->getAbsCoor().z + v.z) |
---|
| 610 | { |
---|
[8190] | 611 | this->setAbsCoor(feet -u ); |
---|
[8186] | 612 | } |
---|
[8190] | 613 | |
---|
| 614 | this->setAbsCoor(ray_2 - v); |
---|
| 615 | |
---|
[8186] | 616 | } |
---|
[8490] | 617 | |
---|
| 618 | |
---|
[8186] | 619 | } |
---|
| 620 | |
---|
| 621 | /** |
---|
[5498] | 622 | * this is called immediately after the Entity has been constructed, initialized and then Spawned into the World |
---|
[4885] | 623 | * |
---|
[5498] | 624 | */ |
---|
[3229] | 625 | void WorldEntity::postSpawn () |
---|
[6430] | 626 | {} |
---|
[2043] | 627 | |
---|
[3583] | 628 | |
---|
[2043] | 629 | /** |
---|
[6959] | 630 | * this method is called by the world if the WorldEntity leaves the game |
---|
[5498] | 631 | */ |
---|
[6959] | 632 | void WorldEntity::leaveWorld () |
---|
[6430] | 633 | {} |
---|
[2043] | 634 | |
---|
[3583] | 635 | |
---|
[2190] | 636 | /** |
---|
[7085] | 637 | * resets the WorldEntity to its initial values. eg. used for multiplayer games: respawning |
---|
| 638 | */ |
---|
| 639 | void WorldEntity::reset() |
---|
[9235] | 640 | { |
---|
| 641 | this->setHealth( this->getHealthMax() ); |
---|
| 642 | } |
---|
[7085] | 643 | |
---|
| 644 | /** |
---|
[4836] | 645 | * this method is called every frame |
---|
| 646 | * @param time: the time in seconds that has passed since the last tick |
---|
[4885] | 647 | * |
---|
| 648 | * Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
[2043] | 649 | */ |
---|
[4570] | 650 | void WorldEntity::tick(float time) |
---|
[10391] | 651 | {} |
---|
[3583] | 652 | |
---|
[5498] | 653 | |
---|
[3583] | 654 | /** |
---|
[4836] | 655 | * the entity is drawn onto the screen with this function |
---|
[4885] | 656 | * |
---|
| 657 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
| 658 | * Just override this function with whatever you want to be drawn. |
---|
[3365] | 659 | */ |
---|
[5500] | 660 | void WorldEntity::draw() const |
---|
[3803] | 661 | { |
---|
[9406] | 662 | //PRINTF(0)("(%s::%s)\n", this->getClassCName(), this->getName()); |
---|
[6281] | 663 | // assert(!unlikely(this->models.empty())); |
---|
[6002] | 664 | { |
---|
| 665 | glMatrixMode(GL_MODELVIEW); |
---|
| 666 | glPushMatrix(); |
---|
[4570] | 667 | |
---|
[6002] | 668 | /* translate */ |
---|
| 669 | glTranslatef (this->getAbsCoor ().x, |
---|
| 670 | this->getAbsCoor ().y, |
---|
| 671 | this->getAbsCoor ().z); |
---|
[6004] | 672 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 673 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[2043] | 674 | |
---|
[6004] | 675 | |
---|
| 676 | // This Draws the LOD's |
---|
[7014] | 677 | float cameraDistance = State::getCamera()->distance(this); |
---|
[6004] | 678 | if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL) |
---|
[6002] | 679 | { |
---|
[6222] | 680 | this->models[2]->draw(); |
---|
[6004] | 681 | } |
---|
| 682 | else if (cameraDistance > 10 && this->models.size() >= 2 && this->models[1] != NULL) |
---|
[6002] | 683 | { |
---|
| 684 | this->models[1]->draw(); |
---|
[6004] | 685 | } |
---|
| 686 | else if (this->models.size() >= 1 && this->models[0] != NULL) |
---|
[6002] | 687 | { |
---|
| 688 | this->models[0]->draw(); |
---|
| 689 | } |
---|
[10391] | 690 | |
---|
[10368] | 691 | //if (this->entityTrack) |
---|
[10391] | 692 | //this->entityTrack->drawGraph(0.02); |
---|
[8724] | 693 | |
---|
[9869] | 694 | // if( this->aabbNode != NULL) |
---|
| 695 | // this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true); |
---|
[8724] | 696 | |
---|
[6002] | 697 | glPopMatrix(); |
---|
| 698 | } |
---|
[3803] | 699 | } |
---|
[3583] | 700 | |
---|
[10391] | 701 | |
---|
[6430] | 702 | /** |
---|
[10391] | 703 | * the entity is drawn onto the screen with this function |
---|
| 704 | * |
---|
| 705 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
| 706 | * Just override this function with whatever you want to be drawn. |
---|
| 707 | */ |
---|
| 708 | void WorldEntity::draw(const Model* model) const |
---|
| 709 | { |
---|
| 710 | glMatrixMode(GL_MODELVIEW); |
---|
| 711 | glPushMatrix(); |
---|
| 712 | |
---|
| 713 | /* translate */ |
---|
| 714 | glTranslatef (this->getAbsCoor ().x, |
---|
| 715 | this->getAbsCoor ().y, |
---|
| 716 | this->getAbsCoor ().z); |
---|
| 717 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 718 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 719 | |
---|
| 720 | |
---|
| 721 | // This Draws the LOD's |
---|
| 722 | if( model != NULL) |
---|
| 723 | model->draw(); |
---|
| 724 | |
---|
| 725 | glPopMatrix(); |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | |
---|
| 729 | /** |
---|
[6700] | 730 | * @param health the Health to add. |
---|
| 731 | * @returns the health left (this->healthMax - health+this->health) |
---|
[6430] | 732 | */ |
---|
[6700] | 733 | float WorldEntity::increaseHealth(float health) |
---|
[6430] | 734 | { |
---|
[6700] | 735 | this->health += health; |
---|
| 736 | if (this->health > this->healthMax) |
---|
[6430] | 737 | { |
---|
[6700] | 738 | float retHealth = this->healthMax - this->health; |
---|
| 739 | this->health = this->healthMax; |
---|
| 740 | this->updateHealthWidget(); |
---|
| 741 | return retHealth; |
---|
[6430] | 742 | } |
---|
[6700] | 743 | this->updateHealthWidget(); |
---|
[6430] | 744 | return 0.0; |
---|
| 745 | } |
---|
[6281] | 746 | |
---|
[5498] | 747 | /** |
---|
[6700] | 748 | * @param health the Health to be removed |
---|
[6430] | 749 | * @returns 0.0 or the rest, that was not substracted (bellow 0.0) |
---|
| 750 | */ |
---|
[6700] | 751 | float WorldEntity::decreaseHealth(float health) |
---|
[6430] | 752 | { |
---|
[6700] | 753 | this->health -= health; |
---|
[6430] | 754 | |
---|
[6700] | 755 | if (this->health < 0) |
---|
[6430] | 756 | { |
---|
[6700] | 757 | float retHealth = -this->health; |
---|
| 758 | this->health = 0.0f; |
---|
| 759 | this->updateHealthWidget(); |
---|
| 760 | return retHealth; |
---|
[6430] | 761 | } |
---|
[6700] | 762 | this->updateHealthWidget(); |
---|
[6430] | 763 | return 0.0; |
---|
| 764 | |
---|
| 765 | } |
---|
| 766 | |
---|
| 767 | /** |
---|
[6700] | 768 | * @param maxHealth the maximal health that can be loaded onto the entity. |
---|
[6430] | 769 | */ |
---|
[6700] | 770 | void WorldEntity::setHealthMax(float healthMax) |
---|
[6430] | 771 | { |
---|
[6700] | 772 | this->healthMax = healthMax; |
---|
| 773 | if (this->health > this->healthMax) |
---|
[6430] | 774 | { |
---|
[9406] | 775 | PRINTF(3)("new maxHealth is bigger as the old health. Did you really intend to do this for (%s::%s)\n", this->getClassCName(), this->getCName()); |
---|
[6700] | 776 | this->health = this->healthMax; |
---|
[6430] | 777 | } |
---|
[6700] | 778 | this->updateHealthWidget(); |
---|
[6430] | 779 | } |
---|
| 780 | |
---|
[6431] | 781 | /** |
---|
[6700] | 782 | * @brief creates the HealthWidget |
---|
[6431] | 783 | * |
---|
[6700] | 784 | * since not all entities need an HealthWidget, it is only created on request. |
---|
[6431] | 785 | */ |
---|
[6700] | 786 | void WorldEntity::createHealthWidget() |
---|
[6430] | 787 | { |
---|
[6700] | 788 | if (this->healthWidget == NULL) |
---|
[6430] | 789 | { |
---|
[10368] | 790 | this->healthWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
| 791 | //this->healthWidget->setDisplayedName("Health"); |
---|
| 792 | //this->healthWidget->setSize2D(100,20); |
---|
| 793 | //this->healthWidget->setAbsCoor2D(100,200); |
---|
[6430] | 794 | |
---|
[6700] | 795 | this->updateHealthWidget(); |
---|
[6430] | 796 | } |
---|
| 797 | else |
---|
[9406] | 798 | PRINTF(3)("Allready created the HealthWidget for %s::%s\n", this->getClassCName(), this->getCName()); |
---|
[6430] | 799 | } |
---|
| 800 | |
---|
[6700] | 801 | void WorldEntity::increaseHealthMax(float increaseHealth) |
---|
[6440] | 802 | { |
---|
[6700] | 803 | this->healthMax += increaseHealth; |
---|
| 804 | this->updateHealthWidget(); |
---|
[6440] | 805 | } |
---|
| 806 | |
---|
[6700] | 807 | |
---|
[7779] | 808 | OrxGui::GLGuiWidget* WorldEntity::getHealthWidget() |
---|
[6700] | 809 | { |
---|
| 810 | this->createHealthWidget(); |
---|
| 811 | return this->healthWidget; |
---|
| 812 | } |
---|
| 813 | |
---|
[6431] | 814 | /** |
---|
[6700] | 815 | * @param visibility shows or hides the health-bar |
---|
[6431] | 816 | * (creates the widget if needed) |
---|
| 817 | */ |
---|
[6700] | 818 | void WorldEntity::setHealthWidgetVisibilit(bool visibility) |
---|
[6430] | 819 | { |
---|
[7198] | 820 | if (visibility) |
---|
| 821 | { |
---|
| 822 | if (this->healthWidget != NULL) |
---|
| 823 | this->healthWidget->show(); |
---|
| 824 | else |
---|
[6430] | 825 | { |
---|
[7198] | 826 | this->createHealthWidget(); |
---|
| 827 | this->updateHealthWidget(); |
---|
| 828 | this->healthWidget->show(); |
---|
[6430] | 829 | } |
---|
[7198] | 830 | } |
---|
| 831 | else if (this->healthWidget != NULL) |
---|
| 832 | this->healthWidget->hide(); |
---|
[6430] | 833 | } |
---|
| 834 | |
---|
[8724] | 835 | |
---|
[6431] | 836 | /** |
---|
[8724] | 837 | * hit the world entity with |
---|
| 838 | * @param damage damage to be dealt |
---|
| 839 | */ |
---|
[9008] | 840 | void WorldEntity::hit(float damage, WorldEntity* killer) |
---|
[8724] | 841 | { |
---|
[10368] | 842 | |
---|
[8724] | 843 | this->decreaseHealth(damage); |
---|
| 844 | |
---|
[9406] | 845 | PRINTF(5)("Hit me: %s::%s now only %f/%f health\n", this->getClassCName(), this->getCName(), this->getHealth(), this->getHealthMax()); |
---|
[8777] | 846 | |
---|
[8724] | 847 | if( this->getHealth() > 0) |
---|
| 848 | { |
---|
| 849 | // any small explosion animaitions |
---|
| 850 | } |
---|
| 851 | else |
---|
| 852 | { |
---|
[9235] | 853 | this->destroy( killer ); |
---|
[8724] | 854 | } |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | |
---|
| 858 | /** |
---|
[8777] | 859 | * destoys the world entity |
---|
| 860 | */ |
---|
[9235] | 861 | void WorldEntity::destroy(WorldEntity* killer) |
---|
[8777] | 862 | { |
---|
| 863 | this->toList(OM_DEAD); |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | |
---|
| 867 | /** |
---|
[6700] | 868 | * @brief updates the HealthWidget |
---|
[6431] | 869 | */ |
---|
[6700] | 870 | void WorldEntity::updateHealthWidget() |
---|
[6430] | 871 | { |
---|
[6700] | 872 | if (this->healthWidget != NULL) |
---|
[6430] | 873 | { |
---|
[6700] | 874 | this->healthWidget->setMaximum(this->healthMax); |
---|
| 875 | this->healthWidget->setValue(this->health); |
---|
[6430] | 876 | } |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | |
---|
| 880 | /** |
---|
[5498] | 881 | * DEBUG-DRAW OF THE BV-Tree. |
---|
| 882 | * @param depth What depth to draw |
---|
| 883 | * @param drawMode the mode to draw this entity under |
---|
| 884 | */ |
---|
[7711] | 885 | void WorldEntity::drawBVTree(int depth, int drawMode) const |
---|
[4684] | 886 | { |
---|
| 887 | glMatrixMode(GL_MODELVIEW); |
---|
| 888 | glPushMatrix(); |
---|
| 889 | /* translate */ |
---|
| 890 | glTranslatef (this->getAbsCoor ().x, |
---|
| 891 | this->getAbsCoor ().y, |
---|
| 892 | this->getAbsCoor ().z); |
---|
| 893 | /* rotate */ |
---|
[4998] | 894 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 895 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[4684] | 896 | |
---|
[7711] | 897 | |
---|
[4684] | 898 | if (this->obbTree) |
---|
| 899 | this->obbTree->drawBV(depth, drawMode); |
---|
[7711] | 900 | |
---|
| 901 | |
---|
[4684] | 902 | glPopMatrix(); |
---|
| 903 | } |
---|
[6341] | 904 | |
---|
[6424] | 905 | |
---|
[10314] | 906 | |
---|
[6341] | 907 | /** |
---|
[10314] | 908 | * draw the mounting points |
---|
| 909 | */ |
---|
| 910 | void WorldEntity::debugDrawMountPoints() const |
---|
| 911 | { |
---|
| 912 | |
---|
| 913 | std::vector<MountPoint*>::const_iterator it = this->mountPoints.begin(); |
---|
| 914 | for( ; it < this->mountPoints.end(); it++) |
---|
| 915 | { |
---|
| 916 | if( (*it) != NULL) |
---|
| 917 | { |
---|
| 918 | (*it)->debugDraw(); |
---|
| 919 | } |
---|
| 920 | } |
---|
| 921 | } |
---|
| 922 | |
---|
| 923 | |
---|
| 924 | /** |
---|
[6424] | 925 | * Debug the WorldEntity |
---|
| 926 | */ |
---|
| 927 | void WorldEntity::debugEntity() const |
---|
| 928 | { |
---|
[9406] | 929 | PRINT(0)("WorldEntity %s::%s (DEBUG)\n", this->getClassCName(), this->getCName()); |
---|
[6424] | 930 | this->debugNode(); |
---|
[9656] | 931 | PRINT(0)("List: %s ; ModelCount %d - ", ObjectManager::OMListToString(this->objectListNumber).c_str(), this->models.size()); |
---|
[6424] | 932 | for (unsigned int i = 0; i < this->models.size(); i++) |
---|
| 933 | { |
---|
| 934 | if (models[i] != NULL) |
---|
[9406] | 935 | PRINT(0)(" : %d:%s", i, this->models[i]->getCName()); |
---|
[6424] | 936 | } |
---|
| 937 | PRINT(0)("\n"); |
---|
| 938 | |
---|
| 939 | } |
---|
| 940 | |
---|
| 941 | |
---|
| 942 | /** |
---|
[7954] | 943 | * handler for changes on registred vars |
---|
| 944 | * @param id id's which changed |
---|
[6341] | 945 | */ |
---|
[7954] | 946 | void WorldEntity::varChangeHandler( std::list< int > & id ) |
---|
[6341] | 947 | { |
---|
[7954] | 948 | if ( std::find( id.begin(), id.end(), modelFileName_handle ) != id.end() || |
---|
| 949 | std::find( id.begin(), id.end(), scaling_handle ) != id.end() |
---|
| 950 | ) |
---|
[6341] | 951 | { |
---|
[7954] | 952 | loadModel( modelFileName, scaling ); |
---|
[6341] | 953 | } |
---|
| 954 | |
---|
[9008] | 955 | if ( std::find( id.begin(), id.end(), list_handle ) != id.end() ) |
---|
| 956 | { |
---|
| 957 | this->toList( (OM_LIST)list_write ); |
---|
| 958 | } |
---|
[9235] | 959 | |
---|
[9110] | 960 | if ( std::find( id.begin(), id.end(), health_handle ) != id.end() ) |
---|
| 961 | { |
---|
| 962 | this->setHealth( health_write ); |
---|
| 963 | } |
---|
[9235] | 964 | |
---|
[9110] | 965 | if ( std::find( id.begin(), id.end(), healthMax_handle ) != id.end() ) |
---|
| 966 | { |
---|
| 967 | this->setHealthMax( healthMax_write ); |
---|
| 968 | } |
---|
[9008] | 969 | |
---|
[7954] | 970 | PNode::varChangeHandler( id ); |
---|
[6341] | 971 | } |
---|
| 972 | |
---|