[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" |
---|
[10618] | 29 | #include "tools/mount_point.h" |
---|
[10147] | 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" |
---|
[10618] | 43 | #include "tools/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; |
---|
[10698] | 77 | this->electronicWidget = NULL; |
---|
| 78 | this->shieldWidget = NULL; |
---|
[6700] | 79 | this->healthMax = 1.0f; |
---|
| 80 | this->health = 1.0f; |
---|
[8190] | 81 | this->damage = 0.0f; // no damage dealt by a default entity |
---|
[6695] | 82 | this->scaling = 1.0f; |
---|
[10147] | 83 | this->oiFile = NULL; |
---|
[10314] | 84 | // add 10 members to this array |
---|
| 85 | this->mountPoints.reserve(10); |
---|
[4261] | 86 | |
---|
[6695] | 87 | /* OSOLETE */ |
---|
| 88 | this->bVisible = true; |
---|
| 89 | this->bCollide = true; |
---|
| 90 | |
---|
[6142] | 91 | this->objectListNumber = OM_INIT; |
---|
[9003] | 92 | this->lastObjectListNumber = OM_INIT; |
---|
[6142] | 93 | |
---|
[10013] | 94 | this->_bOnGround = false; |
---|
[8190] | 95 | |
---|
[10368] | 96 | // Track of this entity |
---|
| 97 | this->entityTrack = NULL; |
---|
[10449] | 98 | this->bDrawTrack = false; |
---|
[10708] | 99 | |
---|
| 100 | this->forwardDamageToParent = false; |
---|
[10368] | 101 | |
---|
[8190] | 102 | // registering default reactions: |
---|
[10013] | 103 | this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID()); |
---|
[8190] | 104 | |
---|
[6142] | 105 | this->toList(OM_NULL); |
---|
[9235] | 106 | |
---|
[10013] | 107 | this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) ); |
---|
| 108 | this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) ); |
---|
| 109 | this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) ); |
---|
| 110 | this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) ); |
---|
[9235] | 111 | |
---|
[10013] | 112 | this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) ); |
---|
| 113 | this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) ); |
---|
[2190] | 114 | } |
---|
[2043] | 115 | |
---|
| 116 | /** |
---|
[4836] | 117 | * standard destructor |
---|
[2043] | 118 | */ |
---|
[2190] | 119 | WorldEntity::~WorldEntity () |
---|
[2036] | 120 | { |
---|
[7125] | 121 | State::getObjectManager()->toList(this, OM_INIT); |
---|
| 122 | |
---|
| 123 | // Delete the model (unregister it with the ResourceManager) |
---|
| 124 | for (unsigned int i = 0; i < this->models.size(); i++) |
---|
| 125 | this->setModel(NULL, i); |
---|
| 126 | |
---|
[10147] | 127 | // remove the object information file |
---|
| 128 | if( this->oiFile) |
---|
| 129 | delete this->oiFile; |
---|
| 130 | // and clear all monut points |
---|
| 131 | this->mountPoints.clear(); |
---|
| 132 | |
---|
[5498] | 133 | // Delete the obbTree |
---|
[10698] | 134 | if( this->obbTree) |
---|
[4814] | 135 | delete this->obbTree; |
---|
[5994] | 136 | |
---|
[10698] | 137 | if (this->healthWidget) |
---|
[6700] | 138 | delete this->healthWidget; |
---|
[8190] | 139 | |
---|
[10698] | 140 | if(this->shieldWidget) |
---|
| 141 | delete this->shieldWidget; |
---|
| 142 | |
---|
| 143 | if( this->electronicWidget) |
---|
| 144 | delete this->electronicWidget; |
---|
| 145 | |
---|
[10013] | 146 | this->unsubscribeReactions(); |
---|
[3531] | 147 | } |
---|
| 148 | |
---|
[5498] | 149 | /** |
---|
| 150 | * loads the WorldEntity Specific Parameters. |
---|
| 151 | * @param root: the XML-Element to load the Data From |
---|
| 152 | */ |
---|
[4436] | 153 | void WorldEntity::loadParams(const TiXmlElement* root) |
---|
| 154 | { |
---|
[5498] | 155 | // Do the PNode loading stuff |
---|
[6512] | 156 | PNode::loadParams(root); |
---|
[5498] | 157 | |
---|
[6222] | 158 | LoadParam(root, "md2texture", this, WorldEntity, loadMD2Texture) |
---|
[6430] | 159 | .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)") |
---|
[7198] | 160 | .defaultValues(""); |
---|
[6222] | 161 | |
---|
[4436] | 162 | // Model Loading |
---|
[5671] | 163 | LoadParam(root, "model", this, WorldEntity, loadModel) |
---|
[6430] | 164 | .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") |
---|
[7198] | 165 | .defaultValues("", 1.0f, 0); |
---|
[6430] | 166 | |
---|
[10314] | 167 | LoadParam(root, "mountpoints", this, WorldEntity, loadMountPoints) |
---|
| 168 | .describe("the fileName of the object information file (optional)"); |
---|
| 169 | |
---|
[10368] | 170 | // Entity Attributes |
---|
[6700] | 171 | LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax) |
---|
| 172 | .describe("The Maximum health that can be loaded onto this entity") |
---|
[7198] | 173 | .defaultValues(1.0f); |
---|
[6430] | 174 | |
---|
[6700] | 175 | LoadParam(root, "health", this, WorldEntity, setHealth) |
---|
| 176 | .describe("The Health the WorldEntity has at this moment") |
---|
[7198] | 177 | .defaultValues(1.0f); |
---|
[9656] | 178 | |
---|
| 179 | LoadParam(root, "list", this, WorldEntity, toListS); |
---|
[10368] | 180 | |
---|
[10449] | 181 | LoadParam(root, "drawTrack", this, WorldEntity, drawDebugTrack) |
---|
| 182 | .describe("draws the track for debugging purposes"); |
---|
[10708] | 183 | |
---|
| 184 | LoadParam(root, "forwardDamageToParent", this, WorldEntity, setForwardDamageToParent); |
---|
[10368] | 185 | |
---|
| 186 | // Track |
---|
| 187 | LoadParamXML(root, "Track", this, WorldEntity, addTrack) |
---|
[10391] | 188 | .describe("creates and adds a track to this WorldEntity"); |
---|
[4436] | 189 | } |
---|
| 190 | |
---|
[6222] | 191 | |
---|
[3531] | 192 | /** |
---|
[10368] | 193 | * this functions adds a track to this workd entity. This can be usefull, if you like this WE to follow a some waypoints. |
---|
| 194 | * here the track is created and further initializing left for the Track itself |
---|
| 195 | */ |
---|
| 196 | void WorldEntity::addTrack(const TiXmlElement* root) |
---|
| 197 | { |
---|
| 198 | // The problem we have is most likely here. The track should be constructed WITH the XML-Code |
---|
| 199 | this->entityTrack = new Track(root); |
---|
| 200 | this->setParent(this->entityTrack->getTrackNode()); |
---|
| 201 | this->entityTrack->getTrackNode()->setParentMode(PNODE_ALL); |
---|
| 202 | /*LOAD_PARAM_START_CYCLE(root, element); |
---|
| 203 | { |
---|
| 204 | PRINTF(4)("element is: %s\n", element->Value()); |
---|
| 205 | Factory::fabricate(element); |
---|
| 206 | } |
---|
| 207 | LOAD_PARAM_END_CYCLE(element);*/ |
---|
| 208 | |
---|
[10391] | 209 | |
---|
[10368] | 210 | } |
---|
| 211 | |
---|
[10498] | 212 | void WorldEntity::pauseTrack(bool stop) |
---|
| 213 | { |
---|
| 214 | if(this->entityTrack) |
---|
| 215 | this->entityTrack->pauseTrack(stop); |
---|
| 216 | } |
---|
[10368] | 217 | |
---|
[10498] | 218 | |
---|
[10368] | 219 | /** |
---|
[4885] | 220 | * loads a Model onto a WorldEntity |
---|
[4836] | 221 | * @param fileName the name of the model to load |
---|
[5057] | 222 | * @param scaling the Scaling of the model |
---|
[7711] | 223 | * |
---|
| 224 | * FIXME |
---|
| 225 | * @todo: separate the obb tree generation from the model |
---|
[7221] | 226 | */ |
---|
[7711] | 227 | void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber, unsigned int obbTreeDepth) |
---|
[4261] | 228 | { |
---|
[6695] | 229 | this->modelLODName = fileName; |
---|
[6424] | 230 | this->scaling = scaling; |
---|
[7954] | 231 | |
---|
| 232 | std::string name = fileName; |
---|
| 233 | |
---|
[9869] | 234 | if ( name.find( Resources::ResourceManager::getInstance()->mainGlobalPath().name() ) == 0 ) |
---|
[7954] | 235 | { |
---|
[9869] | 236 | name.erase(Resources::ResourceManager::getInstance()->mainGlobalPath().name().size()); |
---|
[7954] | 237 | } |
---|
| 238 | |
---|
| 239 | this->modelFileName = name; |
---|
| 240 | |
---|
[7221] | 241 | if (!fileName.empty()) |
---|
[6142] | 242 | { |
---|
[6430] | 243 | // search for the special character # in the LoadParam |
---|
[7221] | 244 | if (fileName.find('#') != std::string::npos) |
---|
[6222] | 245 | { |
---|
[7221] | 246 | PRINTF(4)("Found # in %s... searching for LOD's\n", fileName.c_str()); |
---|
| 247 | std::string lodFile = fileName; |
---|
| 248 | unsigned int offset = lodFile.find('#'); |
---|
[6720] | 249 | for (unsigned int i = 0; i < 3; i++) |
---|
[6005] | 250 | { |
---|
[7221] | 251 | lodFile[offset] = 48+(int)i; |
---|
[9869] | 252 | if (Resources::ResourceManager::getInstance()->checkFileInMainPath( lodFile)) |
---|
[6222] | 253 | this->loadModel(lodFile, scaling, i); |
---|
[6005] | 254 | } |
---|
[6222] | 255 | return; |
---|
| 256 | } |
---|
[6720] | 257 | if (this->scaling <= 0.0) |
---|
[6424] | 258 | { |
---|
[7193] | 259 | PRINTF(1)("YOU GAVE ME A CRAPY SCALE resetting to 1.0\n"); |
---|
[6720] | 260 | this->scaling = 1.0; |
---|
[6424] | 261 | } |
---|
[9869] | 262 | /// LOADING AN OBJ FILE |
---|
[7221] | 263 | if(fileName.find(".obj") != std::string::npos) |
---|
[6222] | 264 | { |
---|
[7221] | 265 | PRINTF(4)("fetching OBJ file: %s\n", fileName.c_str()); |
---|
[10147] | 266 | // creating the model and loading it |
---|
[9869] | 267 | StaticModel* model = new StaticModel(); |
---|
| 268 | *model = ResourceOBJ(fileName, this->scaling); |
---|
[10314] | 269 | |
---|
| 270 | // check if ther is a valid model and load other stuff |
---|
[9869] | 271 | if (model->getVertexCount() > 0) |
---|
| 272 | { |
---|
| 273 | this->setModel(model, modelNumber); |
---|
[10314] | 274 | |
---|
[10391] | 275 | if( modelNumber == 0) |
---|
[10314] | 276 | { |
---|
[10391] | 277 | this->buildObbTree(obbTreeDepth); |
---|
[10314] | 278 | } |
---|
[9869] | 279 | } |
---|
[7221] | 280 | else |
---|
[9869] | 281 | delete model; |
---|
[6222] | 282 | } |
---|
[9869] | 283 | /// LOADING AN MD2-model |
---|
[7221] | 284 | else if(fileName.find(".md2") != std::string::npos) |
---|
[6222] | 285 | { |
---|
[7221] | 286 | PRINTF(4)("fetching MD2 file: %s\n", fileName.c_str()); |
---|
[7055] | 287 | Model* m = new MD2Model(fileName, this->md2TextureFileName, this->scaling); |
---|
[6430] | 288 | //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0); |
---|
[6222] | 289 | this->setModel(m, 0); |
---|
[7068] | 290 | |
---|
| 291 | if( m != NULL) |
---|
[7711] | 292 | this->buildObbTree(obbTreeDepth); |
---|
[6222] | 293 | } |
---|
[9869] | 294 | /// LOADING AN MD3-MODEL. |
---|
[9235] | 295 | else if(fileName.find(".md3") != std::string::npos) |
---|
[8490] | 296 | { |
---|
| 297 | PRINTF(4)("fetching MD3 file: %s\n", fileName.c_str()); |
---|
[10391] | 298 | // Model* m = new md3::MD3Model(fileName, this->scaling); |
---|
| 299 | // this->setModel(m, 0); |
---|
[8490] | 300 | |
---|
[9869] | 301 | // if( m != NULL) |
---|
| 302 | // this->buildObbTree(obbTreeDepth); |
---|
[8490] | 303 | } |
---|
[4732] | 304 | } |
---|
| 305 | else |
---|
[6341] | 306 | { |
---|
[5995] | 307 | this->setModel(NULL); |
---|
[6341] | 308 | } |
---|
[4261] | 309 | } |
---|
| 310 | |
---|
[5061] | 311 | /** |
---|
[5994] | 312 | * sets a specific Model for the Object. |
---|
| 313 | * @param model The Model to set |
---|
| 314 | * @param modelNumber the n'th model in the List to get. |
---|
| 315 | */ |
---|
| 316 | void WorldEntity::setModel(Model* model, unsigned int modelNumber) |
---|
| 317 | { |
---|
[5995] | 318 | if (this->models.size() <= modelNumber) |
---|
| 319 | this->models.resize(modelNumber+1, NULL); |
---|
| 320 | |
---|
| 321 | if (this->models[modelNumber] != NULL) |
---|
[6004] | 322 | { |
---|
[9869] | 323 | delete this->models[modelNumber]; |
---|
[5994] | 324 | } |
---|
[6222] | 325 | |
---|
[5995] | 326 | this->models[modelNumber] = model; |
---|
[5994] | 327 | } |
---|
| 328 | |
---|
| 329 | |
---|
[10147] | 330 | |
---|
[5994] | 331 | /** |
---|
[10147] | 332 | * loads the object information file for this model |
---|
| 333 | * @param fileName the name of the file |
---|
| 334 | */ |
---|
[10314] | 335 | void WorldEntity::loadMountPoints(const std::string& fileName) |
---|
[10147] | 336 | { |
---|
[10314] | 337 | PRINTF(5)("loading the oif File: %s\n", fileName.c_str()); |
---|
[10147] | 338 | |
---|
[10314] | 339 | // now load the object information file |
---|
[10147] | 340 | this->oiFile = new ObjectInformationFile(fileName); |
---|
[10314] | 341 | |
---|
| 342 | // get the model to load |
---|
| 343 | Model* model = this->getModel(); |
---|
| 344 | |
---|
| 345 | // extract the mount points |
---|
[10535] | 346 | if(model != NULL) |
---|
| 347 | model->extractMountPoints(); |
---|
[10536] | 348 | else |
---|
| 349 | { |
---|
[10537] | 350 | PRINTF(0)("Worldentity %s has no mount points", (this->getName()).c_str()); |
---|
[10536] | 351 | return; |
---|
| 352 | } |
---|
[10314] | 353 | |
---|
| 354 | // first get all mount points from the model |
---|
| 355 | const std::list<mountPointSkeleton> mpList = model->getMountPoints(); |
---|
| 356 | // for each skeleton create a mounting point world entity |
---|
| 357 | std::list<mountPointSkeleton>::const_iterator it = mpList.begin(); |
---|
| 358 | |
---|
| 359 | for( ; it != mpList.end(); it++) |
---|
| 360 | { |
---|
| 361 | // create the mount points world entity |
---|
| 362 | MountPoint* mp = new MountPoint( (*it).up, (*it).forward, (*it).center, (*it).name); |
---|
| 363 | // parent it to this WE |
---|
| 364 | mp->setParent( this); |
---|
| 365 | // now add to the right group |
---|
| 366 | mp->toList( (OM_LIST)(this->getOMListNumber()+1)); |
---|
| 367 | // now get the number and add the mount point to the slot |
---|
| 368 | std::string nrStr = (*it).name.substr(3, 2); |
---|
| 369 | // add the mount point |
---|
| 370 | this->addMountPoint(atoi(nrStr.c_str()), mp); |
---|
| 371 | |
---|
| 372 | // now fill the mount point |
---|
| 373 | mp->initMountPoint( this->oiFile->getMountPointDescription()); |
---|
| 374 | } |
---|
| 375 | |
---|
[10147] | 376 | } |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | /** |
---|
[5061] | 380 | * builds the obb-tree |
---|
| 381 | * @param depth the depth to calculate |
---|
| 382 | */ |
---|
[7711] | 383 | bool WorldEntity::buildObbTree(int depth) |
---|
[5061] | 384 | { |
---|
[9494] | 385 | if( this->obbTree != NULL) |
---|
| 386 | { |
---|
[5428] | 387 | delete this->obbTree; |
---|
[9494] | 388 | this->obbTree = NULL; |
---|
| 389 | } |
---|
[5428] | 390 | |
---|
[5995] | 391 | if (this->models[0] != NULL) |
---|
[7711] | 392 | this->obbTree = new OBBTree(depth, models[0]->getModelInfo(), this); |
---|
[5428] | 393 | else |
---|
| 394 | { |
---|
[7711] | 395 | PRINTF(1)("could not create obb-tree, because no model was loaded yet\n"); |
---|
[5428] | 396 | this->obbTree = NULL; |
---|
| 397 | return false; |
---|
| 398 | } |
---|
[8724] | 399 | |
---|
| 400 | |
---|
| 401 | // create the axis aligned bounding box |
---|
| 402 | if( this->aabbNode != NULL) |
---|
| 403 | { |
---|
| 404 | delete this->aabbNode; |
---|
| 405 | this->aabbNode = NULL; |
---|
| 406 | } |
---|
| 407 | |
---|
[9869] | 408 | if( this->models[0] != NULL) |
---|
| 409 | { |
---|
[8724] | 410 | this->aabbNode = new AABBTreeNode(); |
---|
| 411 | this->aabbNode->spawnBVTree(this->models[0]); |
---|
| 412 | } |
---|
[9494] | 413 | else |
---|
| 414 | { |
---|
| 415 | PRINTF(1)("could not create aabb bounding box, because no model was loaded yet\n"); |
---|
| 416 | this->aabbNode = NULL; |
---|
| 417 | return false; |
---|
| 418 | } |
---|
[8724] | 419 | return true; |
---|
[5061] | 420 | } |
---|
[5057] | 421 | |
---|
[7927] | 422 | |
---|
[6142] | 423 | /** |
---|
[10147] | 424 | * adds a mount point to the end of the list |
---|
| 425 | * @param mountPoint point to be added |
---|
| 426 | */ |
---|
| 427 | void WorldEntity::addMountPoint(MountPoint* mountPoint) |
---|
| 428 | { |
---|
| 429 | // add the mount point at the last position |
---|
[10540] | 430 | // this->mountPointMap[](mountPoint); |
---|
| 431 | assert(false); |
---|
[10147] | 432 | } |
---|
| 433 | |
---|
| 434 | /** |
---|
| 435 | * adds a mount point to a world entity |
---|
| 436 | * @param mountPoint point to be added |
---|
| 437 | */ |
---|
| 438 | void WorldEntity::addMountPoint(int slot, MountPoint* mountPoint) |
---|
| 439 | { |
---|
[10546] | 440 | if( this->mountPointMap.find(slot) != this->mountPointMap.end()) |
---|
[10147] | 441 | { |
---|
[10540] | 442 | PRINTF(2)("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()); |
---|
[10147] | 443 | } |
---|
| 444 | |
---|
| 445 | // just connect the mount point |
---|
[10540] | 446 | this->mountPointMap[slot] = mountPoint; |
---|
[10147] | 447 | } |
---|
| 448 | |
---|
| 449 | |
---|
| 450 | /** |
---|
| 451 | * mounts a world entity on a specified mount point (~socket) |
---|
| 452 | * @param entity entity to be connected |
---|
| 453 | */ |
---|
| 454 | void WorldEntity::mount(int slot, WorldEntity* entity) |
---|
| 455 | { |
---|
[10546] | 456 | if( this->mountPointMap.find(slot) != this->mountPointMap.end()) |
---|
[10147] | 457 | { |
---|
| 458 | PRINTF(0)("you tried to add an entity to a mount point that doesn't exist (slot %i)\n", slot); |
---|
| 459 | return; |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | // mount the entity |
---|
| 463 | this->mountPoints[slot]->mount(entity); |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | |
---|
| 467 | /** |
---|
| 468 | * removes a mount point from a specified mount point |
---|
| 469 | * @param mountPoint entity to be unconnected |
---|
| 470 | */ |
---|
| 471 | void WorldEntity::unmount(int slot) |
---|
| 472 | { |
---|
[10391] | 473 | if( this->mountPoints[slot] == NULL) |
---|
[10147] | 474 | { |
---|
| 475 | PRINTF(0)("you tried to remove an entity from a mount point that doesn't exist (slot %i)\n", slot); |
---|
| 476 | return; |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | // unmount the entity |
---|
| 480 | this->mountPoints[slot]->unmount(); |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | |
---|
| 484 | /** |
---|
[7927] | 485 | * subscribes this world entity to a collision reaction |
---|
| 486 | * @param type the type of reaction to subscribe to |
---|
[8190] | 487 | * @param target1 a filter target (classID) |
---|
| 488 | */ |
---|
[10013] | 489 | void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1) |
---|
[8190] | 490 | { |
---|
[10013] | 491 | this->_collisionFilter.subscribeReaction(type, target1); |
---|
[8190] | 492 | } |
---|
| 493 | |
---|
| 494 | |
---|
| 495 | /** |
---|
| 496 | * subscribes this world entity to a collision reaction |
---|
| 497 | * @param type the type of reaction to subscribe to |
---|
| 498 | * @param target1 a filter target (classID) |
---|
| 499 | */ |
---|
[10013] | 500 | void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2) |
---|
[8190] | 501 | { |
---|
[10013] | 502 | this->_collisionFilter.subscribeReaction(type, target1, target2); |
---|
[8190] | 503 | } |
---|
| 504 | |
---|
| 505 | |
---|
| 506 | /** |
---|
| 507 | * subscribes this world entity to a collision reaction |
---|
| 508 | * @param type the type of reaction to subscribe to |
---|
| 509 | * @param target1 a filter target (classID) |
---|
| 510 | */ |
---|
[10013] | 511 | void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3) |
---|
[8190] | 512 | { |
---|
[10013] | 513 | this->_collisionFilter.subscribeReaction(type, target1, target2, target3); |
---|
[8190] | 514 | } |
---|
| 515 | |
---|
| 516 | |
---|
| 517 | /** |
---|
| 518 | * unsubscribes a specific reaction from the worldentity |
---|
| 519 | * @param type the reaction to unsubscribe |
---|
| 520 | */ |
---|
[10013] | 521 | void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type) |
---|
[8190] | 522 | { |
---|
[10013] | 523 | this->_collisionFilter.unsubscribeReaction(type); |
---|
[8190] | 524 | } |
---|
| 525 | |
---|
| 526 | |
---|
| 527 | /** |
---|
| 528 | * unsubscribes all collision reactions |
---|
| 529 | */ |
---|
[10013] | 530 | void WorldEntity::unsubscribeReactions() |
---|
[8190] | 531 | { |
---|
[10013] | 532 | this->_collisionFilter.unsubscribeReactions(); |
---|
[8190] | 533 | } |
---|
| 534 | |
---|
| 535 | |
---|
| 536 | /** |
---|
[6142] | 537 | * @brief moves this entity to the List OM_List |
---|
| 538 | * @param list the list to set this Entity to. |
---|
| 539 | * |
---|
| 540 | * this is the same as a call to State::getObjectManager()->toList(entity , list); |
---|
| 541 | * directly, but with an easier interface. |
---|
| 542 | * |
---|
| 543 | * @todo inline this (peut etre) |
---|
| 544 | */ |
---|
| 545 | void WorldEntity::toList(OM_LIST list) |
---|
| 546 | { |
---|
| 547 | State::getObjectManager()->toList(this, list); |
---|
| 548 | } |
---|
[5061] | 549 | |
---|
[9656] | 550 | void WorldEntity::toListS(const std::string& listName) |
---|
| 551 | { |
---|
| 552 | OM_LIST id = ObjectManager::StringToOMList(listName); |
---|
| 553 | if (id != OM_NULL) |
---|
| 554 | this->toList(id); |
---|
| 555 | else |
---|
| 556 | PRINTF(2)("List %s not found\n", listName.c_str()); |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | |
---|
[8037] | 560 | void WorldEntity::toReflectionList() |
---|
| 561 | { |
---|
| 562 | State::getObjectManager()->toReflectionList( this ); |
---|
| 563 | } |
---|
[6142] | 564 | |
---|
[8037] | 565 | void removeFromReflectionList() |
---|
| 566 | { |
---|
[9869] | 567 | /// TODO |
---|
| 568 | /// State::getObject |
---|
[8037] | 569 | } |
---|
[6142] | 570 | |
---|
[4261] | 571 | /** |
---|
[4885] | 572 | * sets the character attributes of a worldentity |
---|
[4836] | 573 | * @param character attributes |
---|
[4885] | 574 | * |
---|
| 575 | * these attributes don't have to be set, only use them, if you need them |
---|
[2043] | 576 | */ |
---|
[5498] | 577 | //void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr) |
---|
| 578 | //{} |
---|
[2036] | 579 | |
---|
[3583] | 580 | |
---|
[2043] | 581 | /** |
---|
[5029] | 582 | * this function is called, when two entities collide |
---|
| 583 | * @param entity: the world entity with whom it collides |
---|
| 584 | * |
---|
| 585 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 586 | */ |
---|
| 587 | void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 588 | { |
---|
[5498] | 589 | /** |
---|
| 590 | * THIS IS A DEFAULT COLLISION-Effect. |
---|
| 591 | * IF YOU WANT TO CREATE A SPECIFIC COLLISION ON EACH OBJECT |
---|
| 592 | * USE:: |
---|
| 593 | * if (entity->isA(CL_WHAT_YOU_ARE_LOOKING_FOR)) { printf "dothings"; }; |
---|
| 594 | * |
---|
| 595 | * You can always define a default Action.... don't be affraid just test it :) |
---|
| 596 | */ |
---|
[9406] | 597 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z); |
---|
[5029] | 598 | } |
---|
| 599 | |
---|
[2043] | 600 | |
---|
| 601 | /** |
---|
[8186] | 602 | * this function is called, when two entities collide |
---|
| 603 | * @param entity: the world entity with whom it collides |
---|
| 604 | * |
---|
| 605 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 606 | */ |
---|
| 607 | void WorldEntity::collidesWithGround(const Vector& location) |
---|
| 608 | { |
---|
[9406] | 609 | PRINTF(0)("BSP_GROUND: %s collides \n", this->getClassCName() ); |
---|
[8186] | 610 | } |
---|
| 611 | |
---|
| 612 | void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2) |
---|
| 613 | { |
---|
[8190] | 614 | |
---|
[9406] | 615 | // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassCName() ); |
---|
[8190] | 616 | |
---|
[8186] | 617 | Vector v = this->getAbsDirX(); |
---|
[8490] | 618 | v.x *= 10.1; |
---|
| 619 | v.y *= 10.1; |
---|
| 620 | v.z *= 10.1; |
---|
| 621 | Vector u = Vector(0.0,-20.0,0.0); |
---|
[8190] | 622 | |
---|
[8490] | 623 | |
---|
| 624 | if(!(this->getAbsCoor().x == ray_2.x && this->getAbsCoor().y == ray_2.y && this->getAbsCoor().z == ray_2.z) ) |
---|
[8186] | 625 | { |
---|
[8190] | 626 | |
---|
[9869] | 627 | this->setAbsCoor(ray_2 - v); |
---|
[8490] | 628 | |
---|
[8186] | 629 | } |
---|
[9869] | 630 | else |
---|
[8186] | 631 | { |
---|
| 632 | 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) |
---|
| 633 | { |
---|
[8190] | 634 | this->setAbsCoor(feet -u ); |
---|
[8186] | 635 | } |
---|
[8190] | 636 | |
---|
| 637 | this->setAbsCoor(ray_2 - v); |
---|
| 638 | |
---|
[8186] | 639 | } |
---|
[8490] | 640 | |
---|
| 641 | |
---|
[8186] | 642 | } |
---|
| 643 | |
---|
| 644 | /** |
---|
[5498] | 645 | * this is called immediately after the Entity has been constructed, initialized and then Spawned into the World |
---|
[4885] | 646 | * |
---|
[5498] | 647 | */ |
---|
[3229] | 648 | void WorldEntity::postSpawn () |
---|
[6430] | 649 | {} |
---|
[2043] | 650 | |
---|
[3583] | 651 | |
---|
[2043] | 652 | /** |
---|
[6959] | 653 | * this method is called by the world if the WorldEntity leaves the game |
---|
[5498] | 654 | */ |
---|
[6959] | 655 | void WorldEntity::leaveWorld () |
---|
[6430] | 656 | {} |
---|
[2043] | 657 | |
---|
[3583] | 658 | |
---|
[2190] | 659 | /** |
---|
[7085] | 660 | * resets the WorldEntity to its initial values. eg. used for multiplayer games: respawning |
---|
| 661 | */ |
---|
| 662 | void WorldEntity::reset() |
---|
[9235] | 663 | { |
---|
| 664 | this->setHealth( this->getHealthMax() ); |
---|
| 665 | } |
---|
[7085] | 666 | |
---|
| 667 | /** |
---|
[4836] | 668 | * this method is called every frame |
---|
| 669 | * @param time: the time in seconds that has passed since the last tick |
---|
[4885] | 670 | * |
---|
| 671 | * Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
[2043] | 672 | */ |
---|
[4570] | 673 | void WorldEntity::tick(float time) |
---|
[10391] | 674 | {} |
---|
[3583] | 675 | |
---|
[5498] | 676 | |
---|
[3583] | 677 | /** |
---|
[4836] | 678 | * the entity is drawn onto the screen with this function |
---|
[4885] | 679 | * |
---|
| 680 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
| 681 | * Just override this function with whatever you want to be drawn. |
---|
[3365] | 682 | */ |
---|
[5500] | 683 | void WorldEntity::draw() const |
---|
[3803] | 684 | { |
---|
[9406] | 685 | //PRINTF(0)("(%s::%s)\n", this->getClassCName(), this->getName()); |
---|
[6281] | 686 | // assert(!unlikely(this->models.empty())); |
---|
[6002] | 687 | { |
---|
| 688 | glMatrixMode(GL_MODELVIEW); |
---|
| 689 | glPushMatrix(); |
---|
[4570] | 690 | |
---|
[6002] | 691 | /* translate */ |
---|
| 692 | glTranslatef (this->getAbsCoor ().x, |
---|
| 693 | this->getAbsCoor ().y, |
---|
| 694 | this->getAbsCoor ().z); |
---|
[6004] | 695 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 696 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[2043] | 697 | |
---|
[6004] | 698 | |
---|
| 699 | // This Draws the LOD's |
---|
[7014] | 700 | float cameraDistance = State::getCamera()->distance(this); |
---|
[6004] | 701 | if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL) |
---|
[6002] | 702 | { |
---|
[6222] | 703 | this->models[2]->draw(); |
---|
[6004] | 704 | } |
---|
| 705 | else if (cameraDistance > 10 && this->models.size() >= 2 && this->models[1] != NULL) |
---|
[6002] | 706 | { |
---|
| 707 | this->models[1]->draw(); |
---|
[6004] | 708 | } |
---|
| 709 | else if (this->models.size() >= 1 && this->models[0] != NULL) |
---|
[6002] | 710 | { |
---|
| 711 | this->models[0]->draw(); |
---|
| 712 | } |
---|
[10391] | 713 | |
---|
[10368] | 714 | //if (this->entityTrack) |
---|
[10391] | 715 | //this->entityTrack->drawGraph(0.02); |
---|
[8724] | 716 | |
---|
[9869] | 717 | // if( this->aabbNode != NULL) |
---|
| 718 | // this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true); |
---|
[8724] | 719 | |
---|
[6002] | 720 | glPopMatrix(); |
---|
| 721 | } |
---|
[3803] | 722 | } |
---|
[3583] | 723 | |
---|
[10391] | 724 | |
---|
[6430] | 725 | /** |
---|
[10391] | 726 | * the entity is drawn onto the screen with this function |
---|
| 727 | * |
---|
| 728 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
| 729 | * Just override this function with whatever you want to be drawn. |
---|
| 730 | */ |
---|
| 731 | void WorldEntity::draw(const Model* model) const |
---|
| 732 | { |
---|
[10511] | 733 | if(bVisible) |
---|
| 734 | { |
---|
[10391] | 735 | glMatrixMode(GL_MODELVIEW); |
---|
| 736 | glPushMatrix(); |
---|
| 737 | |
---|
| 738 | /* translate */ |
---|
| 739 | glTranslatef (this->getAbsCoor ().x, |
---|
| 740 | this->getAbsCoor ().y, |
---|
| 741 | this->getAbsCoor ().z); |
---|
| 742 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 743 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 744 | |
---|
| 745 | |
---|
| 746 | // This Draws the LOD's |
---|
| 747 | if( model != NULL) |
---|
| 748 | model->draw(); |
---|
| 749 | |
---|
| 750 | glPopMatrix(); |
---|
[10511] | 751 | } |
---|
[10391] | 752 | } |
---|
| 753 | |
---|
| 754 | |
---|
| 755 | /** |
---|
[6700] | 756 | * @param health the Health to add. |
---|
| 757 | * @returns the health left (this->healthMax - health+this->health) |
---|
[6430] | 758 | */ |
---|
[6700] | 759 | float WorldEntity::increaseHealth(float health) |
---|
[6430] | 760 | { |
---|
[6700] | 761 | this->health += health; |
---|
| 762 | if (this->health > this->healthMax) |
---|
[6430] | 763 | { |
---|
[6700] | 764 | float retHealth = this->healthMax - this->health; |
---|
| 765 | this->health = this->healthMax; |
---|
| 766 | this->updateHealthWidget(); |
---|
| 767 | return retHealth; |
---|
[6430] | 768 | } |
---|
[6700] | 769 | this->updateHealthWidget(); |
---|
[6430] | 770 | return 0.0; |
---|
| 771 | } |
---|
[6281] | 772 | |
---|
[5498] | 773 | /** |
---|
[6700] | 774 | * @param health the Health to be removed |
---|
[6430] | 775 | * @returns 0.0 or the rest, that was not substracted (bellow 0.0) |
---|
| 776 | */ |
---|
[6700] | 777 | float WorldEntity::decreaseHealth(float health) |
---|
[6430] | 778 | { |
---|
[6700] | 779 | this->health -= health; |
---|
[6430] | 780 | |
---|
[6700] | 781 | if (this->health < 0) |
---|
[6430] | 782 | { |
---|
[6700] | 783 | float retHealth = -this->health; |
---|
| 784 | this->health = 0.0f; |
---|
| 785 | this->updateHealthWidget(); |
---|
| 786 | return retHealth; |
---|
[6430] | 787 | } |
---|
[6700] | 788 | this->updateHealthWidget(); |
---|
[6430] | 789 | return 0.0; |
---|
| 790 | } |
---|
| 791 | |
---|
[10698] | 792 | |
---|
[6430] | 793 | /** |
---|
[6700] | 794 | * @param maxHealth the maximal health that can be loaded onto the entity. |
---|
[6430] | 795 | */ |
---|
[6700] | 796 | void WorldEntity::setHealthMax(float healthMax) |
---|
[6430] | 797 | { |
---|
[6700] | 798 | this->healthMax = healthMax; |
---|
| 799 | if (this->health > this->healthMax) |
---|
[6430] | 800 | { |
---|
[9406] | 801 | 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] | 802 | this->health = this->healthMax; |
---|
[6430] | 803 | } |
---|
[6700] | 804 | this->updateHealthWidget(); |
---|
[6430] | 805 | } |
---|
| 806 | |
---|
[10698] | 807 | |
---|
| 808 | |
---|
[6431] | 809 | /** |
---|
[10698] | 810 | * @param shiled the Shieldstength to add. |
---|
| 811 | * @returns the shield left (this->shieldMax - shiled + this->shield) |
---|
| 812 | */ |
---|
| 813 | float WorldEntity::increaseShield(float shiled) |
---|
| 814 | { |
---|
| 815 | this->shield += shield; |
---|
| 816 | if (this->shield > this->shieldTH * this->shieldMax) { this->bShieldActive = true; } |
---|
| 817 | if (this->shield > this->shieldMax) |
---|
| 818 | { |
---|
| 819 | float retShield = this->shieldMax - this->shield; |
---|
| 820 | this->shield = this->shieldMax; |
---|
| 821 | // this->updateShieldWidget(); |
---|
| 822 | return retShield; |
---|
| 823 | } |
---|
| 824 | // this->updateShieldWidget(); |
---|
| 825 | return 0.0; |
---|
| 826 | } |
---|
| 827 | |
---|
| 828 | /** |
---|
| 829 | * @param shield the Shieldstrength to be removed |
---|
| 830 | * @returns 0.0 or the rest, if the shield drops belew 0.0 |
---|
| 831 | */ |
---|
| 832 | float WorldEntity::decreaseShield(float shield) |
---|
| 833 | { |
---|
| 834 | this->shield -= shield; |
---|
| 835 | |
---|
| 836 | if (this->shield <= 0) |
---|
| 837 | { |
---|
| 838 | float retShield = -this->shield; |
---|
| 839 | // this->updateShieldWidget(); |
---|
| 840 | this->bShieldActive = false; |
---|
| 841 | return retShield; |
---|
| 842 | } |
---|
| 843 | // this->updateShieldWidget(); |
---|
| 844 | return 0.0; |
---|
| 845 | } |
---|
| 846 | |
---|
| 847 | |
---|
| 848 | |
---|
| 849 | /** |
---|
[6700] | 850 | * @brief creates the HealthWidget |
---|
[6431] | 851 | * |
---|
[6700] | 852 | * since not all entities need an HealthWidget, it is only created on request. |
---|
[6431] | 853 | */ |
---|
[6700] | 854 | void WorldEntity::createHealthWidget() |
---|
[6430] | 855 | { |
---|
[6700] | 856 | if (this->healthWidget == NULL) |
---|
[6430] | 857 | { |
---|
[10368] | 858 | this->healthWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
| 859 | //this->healthWidget->setDisplayedName("Health"); |
---|
| 860 | //this->healthWidget->setSize2D(100,20); |
---|
| 861 | //this->healthWidget->setAbsCoor2D(100,200); |
---|
[6430] | 862 | |
---|
[6700] | 863 | this->updateHealthWidget(); |
---|
[6430] | 864 | } |
---|
| 865 | else |
---|
[9406] | 866 | PRINTF(3)("Allready created the HealthWidget for %s::%s\n", this->getClassCName(), this->getCName()); |
---|
[6430] | 867 | } |
---|
| 868 | |
---|
[10698] | 869 | |
---|
| 870 | /** |
---|
| 871 | * @brief creates the ImplantWidget |
---|
| 872 | * |
---|
| 873 | * since not all entities need an ImpantWidget, it is only created on request. |
---|
| 874 | */ |
---|
| 875 | void WorldEntity::createImplantWidget() |
---|
| 876 | { |
---|
| 877 | if (this->implantWidget == NULL) |
---|
| 878 | { |
---|
| 879 | this->implantWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
| 880 | //this->impantWidget->setDisplayedName("Implant"); |
---|
| 881 | //this->impantWidget->setSize2D(100,20); |
---|
| 882 | //this->impantWidget->setAbsCoor2D(100,200); |
---|
| 883 | |
---|
| 884 | //this->updateImplantWidget(); |
---|
| 885 | } |
---|
| 886 | else |
---|
| 887 | PRINTF(3)("Allready created the ImlpantWidget for %s::%s\n", this->getClassCName(), this->getCName()); |
---|
| 888 | } |
---|
| 889 | |
---|
| 890 | |
---|
| 891 | |
---|
| 892 | void WorldEntity::createShieldWidget() |
---|
| 893 | { |
---|
| 894 | if (this->shieldWidget == NULL) |
---|
| 895 | { |
---|
| 896 | this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
| 897 | this->updateShieldWidget(); |
---|
| 898 | } |
---|
| 899 | else |
---|
| 900 | PRINTF(3)("Allready created the ShieldWidget for %s::%s\n", this->getClassCName(), this->getCName()); |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | void WorldEntity::createElectronicWidget() |
---|
| 904 | { |
---|
| 905 | if (this->electronicWidget == NULL) |
---|
| 906 | { |
---|
| 907 | this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
| 908 | this->updateElectronicWidget(); |
---|
| 909 | } |
---|
| 910 | else |
---|
| 911 | PRINTF(3)("Allready created the ElectronicWidget for %s::%s\n", this->getClassCName(), this->getCName()); |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | |
---|
| 915 | |
---|
[6700] | 916 | void WorldEntity::increaseHealthMax(float increaseHealth) |
---|
[6440] | 917 | { |
---|
[6700] | 918 | this->healthMax += increaseHealth; |
---|
| 919 | this->updateHealthWidget(); |
---|
[6440] | 920 | } |
---|
| 921 | |
---|
[6700] | 922 | |
---|
[7779] | 923 | OrxGui::GLGuiWidget* WorldEntity::getHealthWidget() |
---|
[6700] | 924 | { |
---|
[10698] | 925 | if ( this->healthWidget == NULL) |
---|
| 926 | this->createHealthWidget(); |
---|
[6700] | 927 | return this->healthWidget; |
---|
| 928 | } |
---|
| 929 | |
---|
[10698] | 930 | |
---|
| 931 | |
---|
| 932 | OrxGui::GLGuiWidget* WorldEntity::getImplantWidget() |
---|
| 933 | { |
---|
| 934 | this->createImplantWidget(); |
---|
| 935 | return this->implantWidget; |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | |
---|
| 939 | |
---|
| 940 | OrxGui::GLGuiWidget* WorldEntity::getShieldWidget() |
---|
| 941 | { |
---|
| 942 | if ( this->shieldWidget == NULL) |
---|
| 943 | this->createShieldWidget(); |
---|
| 944 | return this->shieldWidget; |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | |
---|
| 948 | OrxGui::GLGuiWidget* WorldEntity::getElectronicWidget() |
---|
| 949 | { |
---|
| 950 | if ( this->electronicWidget == NULL) |
---|
| 951 | this->createElectronicWidget(); |
---|
| 952 | return this->electronicWidget; |
---|
| 953 | } |
---|
| 954 | |
---|
| 955 | |
---|
| 956 | |
---|
| 957 | |
---|
[6431] | 958 | /** |
---|
[6700] | 959 | * @param visibility shows or hides the health-bar |
---|
[6431] | 960 | * (creates the widget if needed) |
---|
| 961 | */ |
---|
[10698] | 962 | void WorldEntity::setHealthWidgetVisibility(bool visibility) |
---|
[6430] | 963 | { |
---|
[7198] | 964 | if (visibility) |
---|
| 965 | { |
---|
| 966 | if (this->healthWidget != NULL) |
---|
| 967 | this->healthWidget->show(); |
---|
| 968 | else |
---|
[6430] | 969 | { |
---|
[7198] | 970 | this->createHealthWidget(); |
---|
| 971 | this->updateHealthWidget(); |
---|
| 972 | this->healthWidget->show(); |
---|
[6430] | 973 | } |
---|
[7198] | 974 | } |
---|
| 975 | else if (this->healthWidget != NULL) |
---|
| 976 | this->healthWidget->hide(); |
---|
[6430] | 977 | } |
---|
| 978 | |
---|
[8724] | 979 | |
---|
[6431] | 980 | /** |
---|
[8724] | 981 | * hit the world entity with |
---|
| 982 | * @param damage damage to be dealt |
---|
| 983 | */ |
---|
[9008] | 984 | void WorldEntity::hit(float damage, WorldEntity* killer) |
---|
[8724] | 985 | { |
---|
[10708] | 986 | PRINTF(0)("TESTS: %i %i %i\n", (forwardDamageToParent), (this->getParent() != NullParent::getNullParent()), (this->getParent()->isA( WorldEntity::staticClassID() ))); |
---|
| 987 | if ( forwardDamageToParent && this->getParent() != NullParent::getNullParent() && this->getParent()->isA( WorldEntity::staticClassID() ) ) |
---|
| 988 | { |
---|
| 989 | WorldEntity* pa = dynamic_cast<WorldEntity*>(this->getParent()); |
---|
| 990 | pa->hit( damage, killer ); |
---|
| 991 | return; |
---|
| 992 | } |
---|
| 993 | |
---|
| 994 | bool dead = this->getHealth()<=0; |
---|
| 995 | |
---|
[8724] | 996 | this->decreaseHealth(damage); |
---|
| 997 | |
---|
[10704] | 998 | PRINTF(0)("Hit me: %s::%s now only %f/%f health\n", this->getClassCName(), this->getCName(), this->getHealth(), this->getHealthMax()); |
---|
[8777] | 999 | |
---|
[8724] | 1000 | if( this->getHealth() > 0) |
---|
| 1001 | { |
---|
| 1002 | // any small explosion animaitions |
---|
| 1003 | } |
---|
| 1004 | else |
---|
| 1005 | { |
---|
[10708] | 1006 | if ( !dead ) |
---|
| 1007 | this->destroy( killer ); |
---|
[8724] | 1008 | } |
---|
| 1009 | } |
---|
| 1010 | |
---|
| 1011 | |
---|
| 1012 | /** |
---|
[8777] | 1013 | * destoys the world entity |
---|
| 1014 | */ |
---|
[9235] | 1015 | void WorldEntity::destroy(WorldEntity* killer) |
---|
[8777] | 1016 | { |
---|
| 1017 | this->toList(OM_DEAD); |
---|
| 1018 | } |
---|
| 1019 | |
---|
| 1020 | |
---|
| 1021 | /** |
---|
[6700] | 1022 | * @brief updates the HealthWidget |
---|
[6431] | 1023 | */ |
---|
[6700] | 1024 | void WorldEntity::updateHealthWidget() |
---|
[6430] | 1025 | { |
---|
[6700] | 1026 | if (this->healthWidget != NULL) |
---|
[6430] | 1027 | { |
---|
[6700] | 1028 | this->healthWidget->setMaximum(this->healthMax); |
---|
| 1029 | this->healthWidget->setValue(this->health); |
---|
[6430] | 1030 | } |
---|
| 1031 | } |
---|
| 1032 | |
---|
[10698] | 1033 | /** |
---|
| 1034 | * @brief updates the Electronic Widget |
---|
| 1035 | */ |
---|
| 1036 | //!< xferred from spaceship |
---|
| 1037 | void WorldEntity::updateElectronicWidget(){ |
---|
| 1038 | if (this->electronicWidget != NULL) |
---|
| 1039 | { //if it exists already: update it |
---|
| 1040 | this->electronicWidget->setMaximum(this->electronicMax); |
---|
| 1041 | this->electronicWidget->setValue(this->electronic); |
---|
| 1042 | } |
---|
| 1043 | else |
---|
| 1044 | { //create the widget |
---|
| 1045 | this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
| 1046 | this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1)); |
---|
| 1047 | //this->electronicWidget->setDisplayedName("Electronics:"); |
---|
| 1048 | //this->electronicWidget->setSize2D(100,20); |
---|
| 1049 | //this->electronicWidget->setAbsCoor2D(150,200); |
---|
| 1050 | this->updateElectronicWidget(); |
---|
| 1051 | // if ( dynamic_cast<SpaceShip*>(this)->hasPlayer() ) |
---|
| 1052 | // State::getPlayer()->hud().setEnergyWidget(this->electronicWidget); |
---|
| 1053 | } |
---|
| 1054 | } |
---|
[6430] | 1055 | |
---|
| 1056 | /** |
---|
[10698] | 1057 | * @brief updates the ShieldWidget |
---|
| 1058 | */ |
---|
| 1059 | //!< xferred from spaceship |
---|
| 1060 | void WorldEntity::updateShieldWidget() |
---|
| 1061 | { |
---|
| 1062 | if (this->shieldWidget != NULL) |
---|
| 1063 | { |
---|
| 1064 | this->shieldWidget->setMaximum(this->shieldMax); |
---|
| 1065 | this->shieldWidget->setValue(this->shield);; |
---|
| 1066 | } |
---|
| 1067 | else |
---|
| 1068 | { |
---|
| 1069 | this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
| 1070 | this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1)); |
---|
| 1071 | //this->shieldWidget->setDisplayedName("Shield:"); |
---|
| 1072 | //his->shieldWidget->setSize2D(100,20); |
---|
| 1073 | //this->shieldWidget->setAbsCoor2D(200,200); |
---|
| 1074 | this->updateShieldWidget(); |
---|
| 1075 | // if (dynamic_cast<SpaceShip*>(this)->hasPlayer()) |
---|
| 1076 | // State::getPlayer()->hud().setShieldWidget(this->shieldWidget); |
---|
| 1077 | } |
---|
| 1078 | } |
---|
| 1079 | |
---|
| 1080 | |
---|
| 1081 | |
---|
| 1082 | /** |
---|
[5498] | 1083 | * DEBUG-DRAW OF THE BV-Tree. |
---|
| 1084 | * @param depth What depth to draw |
---|
| 1085 | * @param drawMode the mode to draw this entity under |
---|
| 1086 | */ |
---|
[7711] | 1087 | void WorldEntity::drawBVTree(int depth, int drawMode) const |
---|
[4684] | 1088 | { |
---|
| 1089 | glMatrixMode(GL_MODELVIEW); |
---|
| 1090 | glPushMatrix(); |
---|
| 1091 | /* translate */ |
---|
| 1092 | glTranslatef (this->getAbsCoor ().x, |
---|
| 1093 | this->getAbsCoor ().y, |
---|
| 1094 | this->getAbsCoor ().z); |
---|
| 1095 | /* rotate */ |
---|
[4998] | 1096 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 1097 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[4684] | 1098 | |
---|
[7711] | 1099 | |
---|
[4684] | 1100 | if (this->obbTree) |
---|
| 1101 | this->obbTree->drawBV(depth, drawMode); |
---|
[7711] | 1102 | |
---|
| 1103 | |
---|
[4684] | 1104 | glPopMatrix(); |
---|
| 1105 | } |
---|
[6341] | 1106 | |
---|
[6424] | 1107 | |
---|
[10314] | 1108 | |
---|
[6341] | 1109 | /** |
---|
[10314] | 1110 | * draw the mounting points |
---|
| 1111 | */ |
---|
| 1112 | void WorldEntity::debugDrawMountPoints() const |
---|
| 1113 | { |
---|
| 1114 | |
---|
| 1115 | std::vector<MountPoint*>::const_iterator it = this->mountPoints.begin(); |
---|
| 1116 | for( ; it < this->mountPoints.end(); it++) |
---|
| 1117 | { |
---|
| 1118 | if( (*it) != NULL) |
---|
| 1119 | { |
---|
| 1120 | (*it)->debugDraw(); |
---|
| 1121 | } |
---|
| 1122 | } |
---|
| 1123 | } |
---|
| 1124 | |
---|
| 1125 | |
---|
| 1126 | /** |
---|
[6424] | 1127 | * Debug the WorldEntity |
---|
| 1128 | */ |
---|
| 1129 | void WorldEntity::debugEntity() const |
---|
| 1130 | { |
---|
[9406] | 1131 | PRINT(0)("WorldEntity %s::%s (DEBUG)\n", this->getClassCName(), this->getCName()); |
---|
[6424] | 1132 | this->debugNode(); |
---|
[9656] | 1133 | PRINT(0)("List: %s ; ModelCount %d - ", ObjectManager::OMListToString(this->objectListNumber).c_str(), this->models.size()); |
---|
[6424] | 1134 | for (unsigned int i = 0; i < this->models.size(); i++) |
---|
| 1135 | { |
---|
| 1136 | if (models[i] != NULL) |
---|
[9406] | 1137 | PRINT(0)(" : %d:%s", i, this->models[i]->getCName()); |
---|
[6424] | 1138 | } |
---|
| 1139 | PRINT(0)("\n"); |
---|
| 1140 | |
---|
| 1141 | } |
---|
| 1142 | |
---|
| 1143 | |
---|
| 1144 | /** |
---|
[7954] | 1145 | * handler for changes on registred vars |
---|
| 1146 | * @param id id's which changed |
---|
[6341] | 1147 | */ |
---|
[7954] | 1148 | void WorldEntity::varChangeHandler( std::list< int > & id ) |
---|
[6341] | 1149 | { |
---|
[7954] | 1150 | if ( std::find( id.begin(), id.end(), modelFileName_handle ) != id.end() || |
---|
| 1151 | std::find( id.begin(), id.end(), scaling_handle ) != id.end() |
---|
| 1152 | ) |
---|
[6341] | 1153 | { |
---|
[7954] | 1154 | loadModel( modelFileName, scaling ); |
---|
[6341] | 1155 | } |
---|
| 1156 | |
---|
[9008] | 1157 | if ( std::find( id.begin(), id.end(), list_handle ) != id.end() ) |
---|
| 1158 | { |
---|
| 1159 | this->toList( (OM_LIST)list_write ); |
---|
| 1160 | } |
---|
[9235] | 1161 | |
---|
[9110] | 1162 | if ( std::find( id.begin(), id.end(), health_handle ) != id.end() ) |
---|
| 1163 | { |
---|
| 1164 | this->setHealth( health_write ); |
---|
| 1165 | } |
---|
[9235] | 1166 | |
---|
[9110] | 1167 | if ( std::find( id.begin(), id.end(), healthMax_handle ) != id.end() ) |
---|
| 1168 | { |
---|
| 1169 | this->setHealthMax( healthMax_write ); |
---|
| 1170 | } |
---|
[9008] | 1171 | |
---|
[7954] | 1172 | PNode::varChangeHandler( id ); |
---|
[6341] | 1173 | } |
---|
| 1174 | |
---|
[10698] | 1175 | |
---|
| 1176 | void WorldEntity::regen(float time){ |
---|
| 1177 | static float tmp; |
---|
| 1178 | increaseHealth(time * this->healthRegen); |
---|
| 1179 | increaseShield(time * this->shieldRegen); |
---|
| 1180 | // updateHealthWidget(); |
---|
| 1181 | // updateShieldWidget(); |
---|
| 1182 | |
---|
| 1183 | //this->setHealth( this->shieldCur); // FIXME currently just to test share system |
---|
| 1184 | |
---|
| 1185 | if (this->electronic != this->electronicMax || this->electronicRegen != 0){ |
---|
| 1186 | tmp = this->electronic + this->electronicRegen * time; |
---|
| 1187 | if ( tmp > electronicMax) |
---|
| 1188 | this->electronic = this->electronicMax; |
---|
| 1189 | else |
---|
| 1190 | this->electronic = tmp; |
---|
| 1191 | |
---|
| 1192 | updateElectronicWidget(); |
---|
| 1193 | } |
---|
| 1194 | |
---|
| 1195 | } |
---|