Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10698 in orxonox.OLD for trunk/src/world_entities/world_entity.cc


Ignore:
Timestamp:
Jun 14, 2007, 5:33:43 PM (17 years ago)
Author:
snellen
Message:

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/world_entity.cc

    r10618 r10698  
    7575  this->aabbNode = NULL;
    7676  this->healthWidget = NULL;
     77  this->electronicWidget = NULL;
     78  this->shieldWidget = NULL;
    7779  this->healthMax = 1.0f;
    7880  this->health = 1.0f;
     
    128130
    129131  // Delete the obbTree
    130   if( this->obbTree != NULL)
     132  if( this->obbTree)
    131133    delete this->obbTree;
    132134
    133   if (this->healthWidget != NULL)
     135  if (this->healthWidget)
    134136    delete this->healthWidget;
     137
     138  if(this->shieldWidget)
     139    delete this->shieldWidget;
     140
     141  if( this->electronicWidget)
     142    delete this->electronicWidget;
    135143
    136144  this->unsubscribeReactions();
     
    776784  this->updateHealthWidget();
    777785  return 0.0;
    778 
    779 }
     786}
     787
    780788
    781789/**
     
    792800  this->updateHealthWidget();
    793801}
     802
     803
     804
     805/**
     806 * @param shiled the Shieldstength to add.
     807 * @returns the shield left (this->shieldMax - shiled + this->shield)
     808 */
     809float WorldEntity::increaseShield(float shiled)
     810{
     811  this->shield += shield;
     812  if (this->shield > this->shieldTH * this->shieldMax) { this->bShieldActive = true; }
     813  if (this->shield > this->shieldMax)
     814  {
     815    float retShield = this->shieldMax - this->shield;
     816    this->shield = this->shieldMax;
     817//     this->updateShieldWidget();
     818    return retShield;
     819  }
     820//   this->updateShieldWidget();
     821  return 0.0;
     822}
     823
     824/**
     825 * @param shield the Shieldstrength to be removed
     826 * @returns 0.0 or the rest, if the shield drops belew 0.0
     827 */
     828float WorldEntity::decreaseShield(float shield)
     829{
     830  this->shield -= shield;
     831
     832  if (this->shield <= 0)
     833  {
     834    float retShield = -this->shield;
     835//     this->updateShieldWidget();
     836    this->bShieldActive = false;
     837    return retShield;
     838  }
     839//   this->updateShieldWidget();
     840  return 0.0;
     841}
     842
     843
    794844
    795845/**
     
    813863}
    814864
     865
     866/**
     867 * @brief creates the ImplantWidget
     868 *
     869 * since not all entities need an ImpantWidget, it is only created on request.
     870 */
     871void WorldEntity::createImplantWidget()
     872{
     873  if (this->implantWidget == NULL)
     874  {
     875    this->implantWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     876    //this->impantWidget->setDisplayedName("Implant");
     877    //this->impantWidget->setSize2D(100,20);
     878    //this->impantWidget->setAbsCoor2D(100,200);
     879
     880    //this->updateImplantWidget();
     881  }
     882  else
     883    PRINTF(3)("Allready created the ImlpantWidget for %s::%s\n", this->getClassCName(), this->getCName());
     884}
     885
     886
     887
     888void WorldEntity::createShieldWidget()
     889{
     890  if (this->shieldWidget == NULL)
     891  {
     892    this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     893    this->updateShieldWidget();
     894  }
     895  else
     896    PRINTF(3)("Allready created the ShieldWidget for %s::%s\n", this->getClassCName(), this->getCName());
     897}
     898
     899void WorldEntity::createElectronicWidget()
     900{
     901  if (this->electronicWidget == NULL)
     902  {
     903    this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     904    this->updateElectronicWidget();
     905  }
     906  else
     907    PRINTF(3)("Allready created the ElectronicWidget for %s::%s\n", this->getClassCName(), this->getCName());
     908}
     909
     910
     911
    815912void WorldEntity::increaseHealthMax(float increaseHealth)
    816913{
     
    822919OrxGui::GLGuiWidget* WorldEntity::getHealthWidget()
    823920{
    824   this->createHealthWidget();
     921  if ( this->healthWidget == NULL)
     922    this->createHealthWidget();
    825923  return this->healthWidget;
    826924}
     925
     926
     927
     928OrxGui::GLGuiWidget* WorldEntity::getImplantWidget()
     929{
     930  this->createImplantWidget();
     931  return this->implantWidget;
     932}
     933
     934
     935
     936OrxGui::GLGuiWidget* WorldEntity::getShieldWidget()
     937{
     938  if ( this->shieldWidget == NULL)
     939    this->createShieldWidget();
     940  return this->shieldWidget;
     941}
     942
     943
     944OrxGui::GLGuiWidget* WorldEntity::getElectronicWidget()
     945{
     946  if ( this->electronicWidget == NULL)
     947    this->createElectronicWidget();
     948  return this->electronicWidget;
     949}
     950
     951
     952
    827953
    828954/**
     
    830956 * (creates the widget if needed)
    831957 */
    832 void WorldEntity::setHealthWidgetVisibilit(bool visibility)
     958void WorldEntity::setHealthWidgetVisibility(bool visibility)
    833959{
    834960  if (visibility)
     
    8901016  }
    8911017}
     1018
     1019/**
     1020 * @brief updates the Electronic Widget
     1021 */
     1022//!< xferred from spaceship
     1023void WorldEntity::updateElectronicWidget(){
     1024  if (this->electronicWidget != NULL)
     1025  { //if it exists already: update it
     1026     this->electronicWidget->setMaximum(this->electronicMax);
     1027     this->electronicWidget->setValue(this->electronic);
     1028  }
     1029  else
     1030  { //create the widget
     1031    this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1032    this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1033    //this->electronicWidget->setDisplayedName("Electronics:");
     1034    //this->electronicWidget->setSize2D(100,20);
     1035    //this->electronicWidget->setAbsCoor2D(150,200);
     1036    this->updateElectronicWidget();
     1037//     if ( dynamic_cast<SpaceShip*>(this)->hasPlayer() )
     1038//       State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
     1039  }
     1040}
     1041
     1042/**
     1043 * @brief updates the ShieldWidget
     1044 */
     1045//!< xferred from spaceship
     1046void WorldEntity::updateShieldWidget()
     1047{
     1048  if (this->shieldWidget != NULL)
     1049  {
     1050    this->shieldWidget->setMaximum(this->shieldMax);
     1051    this->shieldWidget->setValue(this->shield);;
     1052  }
     1053  else
     1054  {
     1055    this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1056    this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1057    //this->shieldWidget->setDisplayedName("Shield:");
     1058    //his->shieldWidget->setSize2D(100,20);
     1059    //this->shieldWidget->setAbsCoor2D(200,200);
     1060    this->updateShieldWidget();
     1061//     if (dynamic_cast<SpaceShip*>(this)->hasPlayer())
     1062//       State::getPlayer()->hud().setShieldWidget(this->shieldWidget);
     1063  }
     1064}
     1065
    8921066
    8931067
     
    9851159}
    9861160
     1161
     1162void WorldEntity::regen(float time){
     1163  static float tmp;
     1164  increaseHealth(time * this->healthRegen);
     1165  increaseShield(time * this->shieldRegen);
     1166//   updateHealthWidget();
     1167//   updateShieldWidget();
     1168
     1169  //this->setHealth( this->shieldCur);      // FIXME currently just to test share system
     1170
     1171  if (this->electronic != this->electronicMax || this->electronicRegen != 0){
     1172    tmp = this->electronic + this->electronicRegen * time;
     1173    if ( tmp > electronicMax)
     1174      this->electronic = this->electronicMax;
     1175    else
     1176      this->electronic = tmp;
     1177
     1178    updateElectronicWidget();
     1179  }
     1180
     1181}
Note: See TracChangeset for help on using the changeset viewer.