Changeset 6430 in orxonox.OLD for trunk/src/world_entities/world_entity.cc
- Timestamp:
- Jan 8, 2006, 12:14:49 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/world_entity.cc
r6424 r6430 27 27 #include "obb_tree.h" 28 28 29 #include "glgui_bar.h" 30 29 31 #include "state.h" 30 32 … … 32 34 33 35 SHELL_COMMAND(model, WorldEntity, loadModel) 34 35 36 ->describe("sets the Model of the WorldEntity") 37 ->defaultValues(2, "models/ships/fighter.obj", 1.0); 36 38 37 39 SHELL_COMMAND(debugEntity, WorldEntity, debugWE); … … 43 45 * that can calls WorldEntities loadParams for itself. 44 46 */ 45 WorldEntity::WorldEntity( const TiXmlElement* root)46 : Synchronizeable()47 WorldEntity::WorldEntity() 48 : Synchronizeable() 47 49 { 48 50 this->setClassID(CL_WORLD_ENTITY, "WorldEntity"); 49 51 50 52 this->obbTree = NULL; 53 this->energyWidget = NULL; 54 this->energyMax = 1.0f; 55 this->energy = 1.0f; 51 56 52 57 this->md2TextureFileName = NULL; 53 58 54 if (root != NULL)55 this->loadParams(root);56 59 57 60 this->setVisibiliy(true); … … 72 75 delete this->obbTree; 73 76 77 if (this->energyWidget != NULL) 78 delete this->energyWidget; 79 74 80 // Delete the model (unregister it with the ResourceManager) 75 81 for (unsigned int i = 0; i < this->models.size(); i++) … … 89 95 90 96 LoadParam(root, "md2texture", this, WorldEntity, loadMD2Texture) 91 92 97 .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)") 98 .defaultValues(1, NULL); 93 99 94 100 // Model Loading 95 101 LoadParam(root, "model", this, WorldEntity, loadModel) 96 .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") 97 .defaultValues(3, NULL, 1.0f, 0); 102 .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") 103 .defaultValues(3, NULL, 1.0f, 0); 104 105 LoadParam(root, "maxEnergy", this, WorldEntity, setMaxEnergy) 106 .describe("The Maximum energy that can be loaded onto this entity") 107 .defaultValues(1, 1.0f); 108 109 LoadParam(root, "energy", this, WorldEntity, setEnergy) 110 .describe("The Energy the WorldEntity has at this moment") 111 .defaultValues(1, 1.0f); 98 112 } 99 113 … … 111 125 if ( fileName != NULL && strcmp(fileName, "") ) 112 126 { 113 // search for the special character # in the LoadParam127 // search for the special character # in the LoadParam 114 128 if (strchr(fileName, '#') != NULL) 115 129 { … … 147 161 PRINTF(4)("fetching MD2 file: %s\n", fileName); 148 162 Model* m = new MD2Model(fileName, this->md2TextureFileName); 149 163 //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0); 150 164 this->setModel(m, 0); 151 165 } … … 170 184 { 171 185 Resource* resource = ResourceManager::getInstance()->locateResourceByPointer(this->models[modelNumber]); 172 // if (resource != NULL)186 // if (resource != NULL) 173 187 ResourceManager::getInstance()->unload(resource, RP_LEVEL); 174 188 } … … 179 193 180 194 181 // if (this->model != NULL)182 // this->buildObbTree(4);195 // if (this->model != NULL) 196 // this->buildObbTree(4); 183 197 } 184 198 … … 251 265 * You can always define a default Action.... don't be affraid just test it :) 252 266 */ 253 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);267 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); 254 268 } 255 269 … … 260 274 */ 261 275 void WorldEntity::postSpawn () 262 { 263 } 276 {} 264 277 265 278 … … 273 286 */ 274 287 void WorldEntity::leftWorld () 275 { 276 } 288 {} 277 289 278 290 … … 284 296 */ 285 297 void WorldEntity::tick(float time) 286 { 287 } 298 {} 288 299 289 300 … … 296 307 void WorldEntity::draw() const 297 308 { 298 309 //PRINTF(0)("(%s::%s)\n", this->getClassName(), this->getName()); 299 310 // assert(!unlikely(this->models.empty())); 300 311 { … … 325 336 } 326 337 glPopMatrix(); 338 } 339 } 340 341 /** 342 * @param energy the Energy to add. 343 * @returns the energy left (this->energyMax - energy+this->energy) 344 */ 345 float WorldEntity::addEnergy(float energy) 346 { 347 this->energy += energy; 348 if (this->energy > this->energyMax) 349 { 350 float retEnergy = this->energyMax - this->energy; 351 this->energy = this->energyMax; 352 this->updateEnergyWidget(); 353 return retEnergy; 354 } 355 this->updateEnergyWidget(); 356 return 0.0; 357 } 358 359 /** 360 * @param energy the Energy to be removed 361 * @returns 0.0 or the rest, that was not substracted (bellow 0.0) 362 */ 363 float WorldEntity::removeEnergy(float energy) 364 { 365 this->energy -= energy; 366 367 if (this->energy < 0) 368 { 369 float retEnergy = -this->energy; 370 this->energy = 0.0f; 371 this->updateEnergyWidget(); 372 return retEnergy; 373 } 374 this->updateEnergyWidget(); 375 return 0.0; 376 377 } 378 379 /** 380 * @param maxEnergy the maximal energy that can be loaded onto the entity. 381 */ 382 void WorldEntity::setMaxEnergy(float maxEnergy) 383 { 384 this->energyMax = maxEnergy; 385 if (this->energy > this->energyMax) 386 { 387 PRINTF(3)("new maxEnergy is bigger as the old energy. Did you really intend to do this for (%s::%s)\n", this->getClassName(), this->getName()); 388 this->energy = this->energyMax; 389 } 390 this->updateEnergyWidget(); 391 } 392 393 void WorldEntity::createEnergyWidget() 394 { 395 if (this->energyWidget == NULL) 396 { 397 this->energyWidget = new GLGuiBar(); 398 this->energyWidget->setSize2D(30,400); 399 this->energyWidget->setAbsCoor2D(5,100); 400 401 this->updateEnergyWidget(); 402 } 403 else 404 PRINTF(3)("Allready created the EnergyWidget for %s::%s\n", this->getClassName(), this->getName()); 405 } 406 407 void WorldEntity::setEnergyWidgetVisibilit(bool visibility) 408 { 409 if (visibility) 410 { 411 if (this->energyWidget != NULL) 412 this->energyWidget->show(); 413 else 414 { 415 this->createEnergyWidget(); 416 this->updateEnergyWidget(); 417 this->energyWidget->show(); 418 } 419 } 420 else if (this->energyWidget != NULL) 421 this->energyWidget->hide(); 422 } 423 424 void WorldEntity::updateEnergyWidget() 425 { 426 if (this->energyWidget != NULL) 427 { 428 this->energyWidget->setMaximum(this->energyMax); 429 this->energyWidget->setValue(this->energy); 327 430 } 328 431 }
Note: See TracChangeset
for help on using the changeset viewer.