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