Changeset 10698 in orxonox.OLD for trunk/src/world_entities/world_entity.cc
- Timestamp:
- Jun 14, 2007, 5:33:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/world_entity.cc
r10618 r10698 75 75 this->aabbNode = NULL; 76 76 this->healthWidget = NULL; 77 this->electronicWidget = NULL; 78 this->shieldWidget = NULL; 77 79 this->healthMax = 1.0f; 78 80 this->health = 1.0f; … … 128 130 129 131 // Delete the obbTree 130 if( this->obbTree != NULL)132 if( this->obbTree) 131 133 delete this->obbTree; 132 134 133 if (this->healthWidget != NULL)135 if (this->healthWidget) 134 136 delete this->healthWidget; 137 138 if(this->shieldWidget) 139 delete this->shieldWidget; 140 141 if( this->electronicWidget) 142 delete this->electronicWidget; 135 143 136 144 this->unsubscribeReactions(); … … 776 784 this->updateHealthWidget(); 777 785 return 0.0; 778 779 } 786 } 787 780 788 781 789 /** … … 792 800 this->updateHealthWidget(); 793 801 } 802 803 804 805 /** 806 * @param shiled the Shieldstength to add. 807 * @returns the shield left (this->shieldMax - shiled + this->shield) 808 */ 809 float 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 */ 828 float 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 794 844 795 845 /** … … 813 863 } 814 864 865 866 /** 867 * @brief creates the ImplantWidget 868 * 869 * since not all entities need an ImpantWidget, it is only created on request. 870 */ 871 void 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 888 void 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 899 void 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 815 912 void WorldEntity::increaseHealthMax(float increaseHealth) 816 913 { … … 822 919 OrxGui::GLGuiWidget* WorldEntity::getHealthWidget() 823 920 { 824 this->createHealthWidget(); 921 if ( this->healthWidget == NULL) 922 this->createHealthWidget(); 825 923 return this->healthWidget; 826 924 } 925 926 927 928 OrxGui::GLGuiWidget* WorldEntity::getImplantWidget() 929 { 930 this->createImplantWidget(); 931 return this->implantWidget; 932 } 933 934 935 936 OrxGui::GLGuiWidget* WorldEntity::getShieldWidget() 937 { 938 if ( this->shieldWidget == NULL) 939 this->createShieldWidget(); 940 return this->shieldWidget; 941 } 942 943 944 OrxGui::GLGuiWidget* WorldEntity::getElectronicWidget() 945 { 946 if ( this->electronicWidget == NULL) 947 this->createElectronicWidget(); 948 return this->electronicWidget; 949 } 950 951 952 827 953 828 954 /** … … 830 956 * (creates the widget if needed) 831 957 */ 832 void WorldEntity::setHealthWidgetVisibilit (bool visibility)958 void WorldEntity::setHealthWidgetVisibility(bool visibility) 833 959 { 834 960 if (visibility) … … 890 1016 } 891 1017 } 1018 1019 /** 1020 * @brief updates the Electronic Widget 1021 */ 1022 //!< xferred from spaceship 1023 void 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 1046 void 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 892 1066 893 1067 … … 985 1159 } 986 1160 1161 1162 void 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.