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