Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 5, 2007, 2:48:15 PM (18 years ago)
Author:
nicolasc
Message:

moved "ship attributes" to world entity
electronic and shield widget not yet working

Location:
branches/vs-enhencements/src/world_entities/space_ships
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/vs-enhencements/src/world_entities/space_ships/space_ship.cc

    r10669 r10670  
    161161  this->secWeaponMan.setSlotCount(6);
    162162
    163   this->weaponMan.createWeaponSlot(0, 3.006, 1.028, .155, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    164   this->weaponMan.createWeaponSlot(1, 3.006, 1.028, -.155, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    165   this->weaponMan.createWeaponSlot(2, 4.03, .063, .876, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    166   this->weaponMan.createWeaponSlot(3, 4.03, -.063, -.876, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    167   this->weaponMan.createWeaponSlot(4, 1.431, -.612, 2.691, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    168   this->weaponMan.createWeaponSlot(5, 1.431, -.612, -2.691, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    169   this->weaponMan.createWeaponSlot(6, 1.431, -.612, 3.254, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    170   this->weaponMan.createWeaponSlot(7, 1.431, -.612, -3.254, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     163  this->weaponMan.createWeaponSlot(0, 3.270, 1.028, .155, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     164  this->weaponMan.createWeaponSlot(1, 3.270, 1.028, -.155, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     165  this->weaponMan.createWeaponSlot(2, 4.385, .063, .876, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     166  this->weaponMan.createWeaponSlot(3, 4.385, -.063, -.876, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     167  this->weaponMan.createWeaponSlot(4, 1.635, -.612, 2.691, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     168  this->weaponMan.createWeaponSlot(5, 1.536, -.612, -2.691, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     169  this->weaponMan.createWeaponSlot(6, 1.536, -.612, 3.254, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     170  this->weaponMan.createWeaponSlot(7, 1.536, -.612, -3.254, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    171171
    172172
     
    212212
    213213
    214   setEnergyShare(.3,.3,.4);
    215   setShield(100, 100, .2, 2);
    216   setArmor(100, 100);
    217   setElectronic(50, 50, .7, 3.0);
     214//   loadEnergyShare(.3,.3,.4);
     215//   loadShield(80, 100, .2, 2);
     216//   loadHealth(100, 100, 0);
     217//   loadElectronic(40, 50, .7, 3.0);
    218218
    219219//   this->loadModel("models/spaceships/fighter_redesign9.obj");
     
    232232
    233233
    234   this->electronicWidget = NULL;
    235   this->shieldWidget = NULL;
     234//   this->electronicWidget = NULL;
     235//   this->shieldWidget = NULL;
    236236
    237237  //add events to the eventlist
     
    290290
    291291
    292   this->toList(OM_GROUP_00);
     292//   this->toList(OM_GROUP_00);
     293
     294  if ( this->hasPlayer() ){
     295    State::getPlayer()->hud().setShieldWidget(this->getShieldWidget());
     296    State::getPlayer()->hud().setEnergyWidget(this->getElectronicWidget());
     297  }
    293298}
    294299
     
    313318  LoadParam(root, "setReactor", this, SpaceShip, setReactor)
    314319  .describe("set reactor output");
    315   LoadParam(root, "setShield", this, SpaceShip, setShield)
     320  LoadParam(root, "loadShield", this, WorldEntity, loadShield)
    316321  .describe("set shield parameters: current strenght , max strenght, threshhold value (0..1), regeneration rate");
    317   LoadParam(root, "setArmor", this, SpaceShip, setArmor)
     322  LoadParam(root, "loadHealth", this, WorldEntity, loadHealth)
    318323  .describe("set armor/health parameters: current strenght , max strenght");
    319   LoadParam(root, "setElectronic", this, SpaceShip, setElectronic)
     324  LoadParam(root, "loadElectronic", this, WorldEntity, loadElectronic)
    320325  .describe("set electronics parameters: current strenght , max strenght, threshhold value (0..1), regeneration rate");
    321326  LoadParam(root, "setEngine", this, SpaceShip, setEngine)
    322327  .describe("set base speed");
    323   LoadParam(root, "setEnergyShare", this, SpaceShip, setEnergyShare)
     328  LoadParam(root, "loadEnergyShare", this, SpaceShip, loadEnergyShare)
    324329  .describe("set energy partitioning: shield, weapons, engine (sum should be 1)");
    325330  LoadParam(root, "setWeapon", this, SpaceShip, setWeapon)
     
    352357  bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
    353358
    354 
    355 //   this->armorCur = this->armorMax;
    356   this->setHealth(this->getHealthMax());
    357   this->shieldCur = this->shieldMax;
    358   this->shieldActive = true;
    359   this->electronicCur = this->electronicMax;
    360 //   this->updateHealth();
     359  this->resetHealth();
     360  this->resetShield();
     361  this->resetElectronic();
    361362  this->velocity = Vector(0.0, 0.0, 0.0);
    362363}
     
    664665  PRINTF(5)("ship hit for (%f,%f) \n",pDamage,eDamage);
    665666
    666   if( this->shieldActive) {
    667     if( this->shieldCur > pDamage) {
    668       this->shieldCur = this->shieldCur - pDamage;
    669     }
    670     else { // shield <= pDamage
    671       this->shieldCur -=pDamage;
    672       this->shieldActive = false; //shield collapses
    673       pDamage += this->shieldCur;
    674       if( !this->shieldActive) {
    675         this->decreaseHealth( pDamage / 2); // remaining damages hits armor at half rate
    676         this->electronicCur -= eDamage;
    677       }
    678     }
    679   }
    680   else {
    681     this->decreaseHealth(pDamage);
    682     this->electronicCur = this->electronicCur - eDamage;
    683   }
    684   if( this->getHealth() <= 0) { /* FIXME implement shipcrash*/ }
     667  static float tmp = this->decreaseShield(pDamage);
     668  if( tmp > 0)
     669  if ( this->decreaseHealth(tmp / 2) )
    685670    this->destroy(this);
    686671
    687   updateElectronicWidget();
    688   updateShieldWidget();
    689 
    690 //   this->setHealth( this->armorCur);
    691 }
    692 
    693 
    694 void SpaceShip::regen(float time){
    695   static float tmp, armorCur, armorMax;
    696   if (armorCur != armorMax || this->armorRegen != 0){
    697     tmp = armorCur + armorRegen * time;
    698     if ( tmp > armorMax)
    699       armorCur = armorMax;
    700     else
    701       armorCur = tmp;
    702   }
    703   if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){
    704     tmp =  this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time;
    705     if( tmp > shieldMax)
    706       this->shieldCur = this->shieldMax;
    707     else
    708       this->shieldCur = tmp;
    709     this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH);
    710 
    711     updateShieldWidget();
    712   }
    713 
    714   this->setHealth( this->shieldCur);      // FIXME currently just to test share system
    715 
    716   if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){
    717     tmp = this->electronicCur + this->electronicRegen * time;
    718     if ( tmp > electronicMax)
    719       this->electronicCur = this->electronicMax;
    720     else
    721       this->electronicCur = tmp;
    722 
    723     updateElectronicWidget();
    724   }
    725 
    726 }
     672}
     673
    727674
    728675
     
    733680void SpaceShip::weaponRegen(float time)
    734681{
    735   float energy  = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time;
     682  float energy = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time ;
    736683  Weapon* weapon;
    737   for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++)
    738   {
     684  int weaponCount = 0;
     685  for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++) {
    739686    weapon = this->weaponMan.getWeapon(i);
    740     if( weapon != NULL && weapon->isActive())
    741     {
     687    if( weapon != NULL && weapon->isActive()) {
     688      weaponCount++;
     689    }
     690  }
     691
     692  if (weaponCount == 0)
     693    return;
     694  energy *= ( this->weaponMan.getSlotCount() / (float)weaponCount );
     695
     696  for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++) {
     697    weapon = this->weaponMan.getWeapon(i);
     698    if( weapon != NULL && weapon->isActive()) {
    742699      weapon->increaseEnergy( energy);
    743700    }
    744 
    745701  }
    746702  // weaponMan.increaseAmmunition( weapon, energy);
     
    748704
    749705
    750 void SpaceShip::enterPlaymode(Playable::Playmode playmode)
    751 {
     706void SpaceShip::enterPlaymode(Playable::Playmode playmode){
    752707  switch(playmode)
    753708  {
     
    810765      break;
    811766
    812    
     767
    813768    case Playable::Vertical:
    814769    {
     
    832787        //this->setCameraMode(Camera::ViewNormal);
    833788        State::getCamera()->setEventHandling(false);
    834        
     789
    835790        PRINTF(0)("\n\n\n\n\n\n\n\nSETCAMERA %x\n\n\n\n\n\n\n", State::getCamera());
    836791        State::getCamera()->setViewMode(Camera::ViewNormal);
     
    838793        State::getCamera()->setParent(this);
    839794
    840        
    841        
     795
    842796        registerEvent(KeyMapper::PEV_VIEW0);
    843797        registerEvent(KeyMapper::PEV_VIEW1);
     
    848802
    849803        State::getCamera()->setParentMode(PNODE_ALL);
    850      
     804
    851805      break;
    852806    }
    853      
     807
    854808    default:
    855809      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
     
    1020974      }
    1021975      ActionBox * box = entityTrack->getActionBox();
    1022      
     976
    1023977      this->travelVelocity = Vector(0, 0, 0);
    1024978      float ssss = 50;
     
    1039993        this->travelVelocity += Vector( 0, 0, ssss );
    1040994      }
    1041      
     995
    1042996      Vector ds = this->travelVelocity*dt;
    1043997      Vector newPos = this->getRelCoor() + ds;
     
    10921046}
    10931047
    1094 void SpaceShip::updateElectronicWidget()
    1095 {
    1096   if (this->electronicWidget != NULL)
    1097   { //if it exists already: update it
    1098      this->electronicWidget->setMaximum(this->electronicMax);
    1099      this->electronicWidget->setValue(this->electronicCur);
    1100   }
    1101   else
    1102   { //create the widget
    1103     this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
    1104     this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
    1105     //this->electronicWidget->setDisplayedName("Electronics:");
    1106     //this->electronicWidget->setSize2D(100,20);
    1107     //this->electronicWidget->setAbsCoor2D(150,200);
    1108     this->updateElectronicWidget();
    1109     if (this->hasPlayer())
    1110       State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
    1111   }
    1112 }
    1113 
    1114 void SpaceShip::updateShieldWidget()
    1115 {
    1116   if (this->shieldWidget != NULL)
    1117   {
    1118     this->shieldWidget->setMaximum(this->shieldMax);
    1119     this->shieldWidget->setValue(this->shieldCur);;
    1120   }
    1121   else
    1122   {
    1123     this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
    1124     this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
    1125     //this->shieldWidget->setDisplayedName("Shield:");
    1126     //his->shieldWidget->setSize2D(100,20);
    1127     //this->shieldWidget->setAbsCoor2D(200,200);
    1128     this->updateShieldWidget();
    1129     if (this->hasPlayer())
    1130       State::getPlayer()->hud().setShiledWidget(this->shieldWidget);
    1131   }
    1132 }
     1048// void SpaceShip::updateElectronicWidget()
     1049// {
     1050//   if (this->electronicWidget != NULL)
     1051//   { //if it exists already: update it
     1052//      this->electronicWidget->setMaximum(this->electronicMax);
     1053//      this->electronicWidget->setValue(this->electronicCur);
     1054//   }
     1055//   else
     1056//   { //create the widget
     1057//     this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1058//     this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1059//     //this->electronicWidget->setDisplayedName("Electronics:");
     1060//     //this->electronicWidget->setSize2D(100,20);
     1061//     //this->electronicWidget->setAbsCoor2D(150,200);
     1062//     this->updateElectronicWidget();
     1063//     if (this->hasPlayer())
     1064//       State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
     1065//   }
     1066// }
     1067//
     1068// void SpaceShip::updateShieldWidget()
     1069// {
     1070//   if (this->shieldWidget != NULL)
     1071//   {
     1072//     this->shieldWidget->setMaximum(this->shieldMax);
     1073//     this->shieldWidget->setValue(this->shieldCur);;
     1074//   }
     1075//   else
     1076//   {
     1077//     this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1078//     this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1079//     //this->shieldWidget->setDisplayedName("Shield:");
     1080//     //his->shieldWidget->setSize2D(100,20);
     1081//     //this->shieldWidget->setAbsCoor2D(200,200);
     1082//     this->updateShieldWidget();
     1083//     if (this->hasPlayer())
     1084//       State::getPlayer()->hud().setShiledWidget(this->shieldWidget);
     1085//   }
     1086// }
    11331087
    11341088void SpaceShip::setCameraDistance(float dist)
     
    11831137};
    11841138
    1185 // void SpaceShip::addWeaponToSlot(int wm, int config, int slot, const std::string& weaponName){
    1186 //   if (wm == 1) { this->weaponMan.addWeapon( Weapon::createWeapon( weaponName ), config, slot); }
    1187 //   if (wm == 1) { this->weaponMan.addWeapon( Weapon::createWeapon( weaponName ), config, slot); }
    1188 //   else return;
    1189 // }
    1190 
     1139
  • branches/vs-enhencements/src/world_entities/space_ships/space_ship.h

    r10669 r10670  
    1212#include "playable.h"
    1313#include "extendable.h"
     14#include "world_entity.h"
    1415
    1516// Forward Declaration
     
    6465
    6566    //!< functions for XML loading
    66     inline void setReactor(float output) {this->reactorOutput = output; };
    67     inline void setShield(float cur, float max, float th, float regen)
    68         { this->shieldCur = cur; this->shieldMax = max; this->shieldTH = th; this->shieldRegen = regen;};
    69     inline void setArmor(float cur, float max) { this->setHealth(cur); this->setHealthMax(max); };
    70     inline void setElectronic(float cur, float max, float th, float regen)
    71         { this->electronicCur = cur; this->electronicMax = max; this->electronicTH = th; this->electronicRegen = regen; };
    72     inline void setEngine( float speedBase) {this->engineSpeedBase = speedBase; };
    73     inline void setEnergyShare(float shield, float weapon, float engine)
     67    void setReactor(float output) {this->reactorOutput = output; };
     68    void setEngine( float speedBase) {this->engineSpeedBase = speedBase; };
     69    void loadEnergyShare(float shield, float weapon, float engine)
    7470        { float tmp = shield + weapon + engine; if (unlikely (tmp > 1)) { tmp = 1/tmp; }
    75           // dirty safety hack, prevents total share being bigger than 1!!
     71          // HACK dirty safety hack, prevents total share being bigger than 1!!
    7672          this->shieldEnergyShare = shield * tmp;
    7773          this->weaponEnergyShare = weapon * tmp;
     
    7975    inline void setWeapon(float regen) { this->weaponEnergyRegen = regen; };
    8076
    81     //!< Resynchonizes armor with health in WE!!
    82 //     inline void updateHealth() { this->setHealth(this->armorCur); this->setHealthMax(this->armorMax); };
    83 
    8477    void addWeaponToSlot(int wm, int config, int slot, const std::string& weaponName);
    85 
    86     //Functions for GUI
    87     inline float getShieldCur() { return this->shieldCur; };        //!< returns current shield value
    88     inline float getShieldMax() { return this->shieldMax; };        //!< returns maximum shield value
    89 
    90     inline float getArmorCur() { return this->getHealth(); };          //!< returns current armor value
    91     inline float getArmorMax() { return this->getHealthMax(); };          //!< returns current armor value
    92 
    93     inline float getElectronicCur() { return this->electronicCur; }; //!< returns current electronic value
    94     inline float getElectronicMax() { return this->electronicMax; }; //!< returns current electronic value
    9578
    9679    inline PNode* getTravelNode() { return this->travelNode; };
     
    121104    //void calculateVelocity(float time);
    122105
    123     void regen(float time);  //!< handler for shield and electronic regeneration
     106//    void regen(float time);  //!< handler for shield and electronic regeneration
    124107
    125108    void weaponRegen(float time);   //!< weapon energy regeneration
    126109
    127     inline bool systemFailure() {  return (this->electronicCur < float(rand())/float(RAND_MAX) * this->electronicTH); };
    128 
    129     void updateElectronicWidget();
    130     void updateShieldWidget();
     110//     inline bool systemFailure() {  return (this->getElectronic() < float(rand())/float(RAND_MAX) * this->getElectronicTH()); };
     111
     112//     void updateElectronicWidget();
     113//     void updateShieldWidget();
    131114
    132115    //WeaponManager         weaponMan;      //!< the primary weapon manager: managing a list of energy weapons to wepaon-slot mapping
     
    136119
    137120    //ship atributes
    138     float       shieldCur;          //!< current shield
    139     float       shieldMax;          //!< maximum shield
    140     float       shieldEnergyShare;  //!< percentage of reactor output
    141     float       shieldRegen;        //!< shield regeneration rate per second
    142     float       shieldTH;           //!< shield threshhold for reactivation
    143     bool        shieldActive;       //!< wheather the shield is working
    144     OrxGui::GLGuiEnergyWidgetVertical* shieldWidget; //!< holds the widget that shows the shield bar
     121//    float       shieldCur;          //!< current shield
     122//    float       shieldMax;          //!< maximum shield
     123//    float       shieldRegen;        //!< shield regeneration rate per second
     124//    float       shieldTH;           //!< shield threshhold for reactivation
     125//    bool        shieldActive;       //!< wheather the shield is working
     126//    OrxGui::GLGuiEnergyWidgetVertical* shieldWidget; //!< holds the widget that shows the shield bar
    145127
    146128//    float       armorCur;           //!< current armor
    147129//    float       armorMax;           //!< maximum armor
    148     float       armorRegen;         //!< armor regeneration per tick (usable on bioships?)
     130//    float       armorRegen;         //!< armor regeneration per tick (usable on bioships?)
    149131    //note that the armor widget is set on the health- widget in world- entity (see in player.cc)
    150132
    151     float       electronicCur;      //!< current electronic
    152     float       electronicMax;      //!< maximum electronic
    153     float       electronicRegen;    //!< electronic regenration rate per tick
    154     float       electronicTH;       //!< Threshhold for electronic failure
    155     OrxGui::GLGuiEnergyWidgetVertical* electronicWidget; //!< holds the widget that shows the electronic bar
     133//    float       electronicCur;      //!< current electronic
     134//    float       electronicMax;      //!< maximum electronic
     135//    float       electronicRegen;    //!< electronic regenration rate per tick
     136//    float       electronicTH;       //!< Threshhold for electronic failure
     137//    OrxGui::GLGuiEnergyWidgetVertical* electronicWidget; //!< holds the widget that shows the electronic bar
    156138
    157139    float       engineSpeedCur;     //!< speed output for movement = speed base + energy share part
     
    159141    int         enginePowerConsume; //!< energy needed
    160142    float       engineEnergyShare;  //!< percentage of reactor output
     143    float       shieldEnergyShare;  //!< percentage of reactor output
    161144
    162145    int         weaponEnergySlot;   //!< number of energy weapon slots
Note: See TracChangeset for help on using the changeset viewer.