Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6547 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Jan 18, 2006, 2:12:53 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the WeaponManager back to the trunk

Location:
trunk/src/world_entities
Files:
9 edited

Legend:

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

    r6444 r6547  
    2121#include "player.h"
    2222#include "state.h"
     23
     24#include "power_ups/weapon_power_up.h"
     25#include "power_ups/param_power_up.h"
    2326
    2427
     
    141144}
    142145
     146bool Playable::pickup(PowerUp* powerUp)
     147{
     148  if(powerUp->isA(CL_WEAPON_POWER_UP)) {
     149    Weapon* weapon = dynamic_cast<WeaponPowerUp*>(powerUp)->getWeapon();
     150    WeaponManager* manager = this->getWeaponManager();
     151    int slot = manager->getNextFreeSlot(2, weapon->getCapability());
     152    if(slot >= 0) {
     153      manager->addWeapon(weapon, 2, slot);
     154      return true;
     155    }
     156  }
     157  else if(powerUp->isA(CL_PARAM_POWER_UP)) {
     158    ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp);
     159    switch(ppu->getType()) {
     160      case POWERUP_PARAM_HEALTH:
     161        this->addEnergy(ppu->getValue());
     162        return true;
     163      case POWERUP_PARAM_MAX_HEALTH:
     164        this->setMaxEnergy(this->getMaxEnergy() + ppu->getValue());
     165        return true;
     166    }
     167  }
     168  return false;
     169}
     170
    143171/**
    144172 * add an event to the event list of events this Playable can capture
  • trunk/src/world_entities/playable.h

    r6444 r6547  
    88
    99#include "world_entity.h"
     10#include "extendable.h"
    1011#include "event.h"
    1112#include <list>
     
    2122 *
    2223 */
    23 class Playable : public WorldEntity
     24class Playable : public WorldEntity, public Extendable
    2425{
    2526  public:
     
    2930    virtual void enter()=0;
    3031    virtual void leave()=0;
     32
     33    virtual bool pickup(PowerUp* powerUp);
    3134
    3235    void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
  • trunk/src/world_entities/power_ups/param_power_up.cc

    r6512 r6547  
    3232
    3333const char* ParamPowerUp::paramTypes[] = {
    34   "shield"
     34  "shield",
     35  "max-shield",
     36  "health",
     37  "max-health",
    3538};
    3639
     
    7780}
    7881
    79 void ParamPowerUp::setValue(int value)
     82void ParamPowerUp::setValue(float value)
    8083{
    8184  this->value = value;
     
    8487void ParamPowerUp::setType(const char* type)
    8588{
    86   for(int i = 0; i < PARAM_size; ++i) {
     89  for(int i = 0; i < POWERUP_PARAM_size; ++i) {
    8790    if(strcmp(type, paramTypes[i]) == 0) {
    8891      this->type = (EnumParamPowerUpType)i;
     
    9295}
    9396
    94 void ParamPowerUp::setMaxValue(int value)
     97void ParamPowerUp::setMaxValue(float value)
    9598{
    9699  this->max_value = value;
    97100}
    98101
    99 void ParamPowerUp::setMinValue(int value)
     102void ParamPowerUp::setMinValue(float value)
    100103{
    101104  this->min_value = value;
    102105}
    103106
    104 int ParamPowerUp::getValue()
     107float ParamPowerUp::getValue()
    105108{
    106109  return this->value;
     
    116119  if(this->min_value != this->max_value)
    117120  {
    118     value = this->min_value + (int)(rand() * (this->max_value - this->min_value));
     121    this->value = this->min_value + rand() * (this->max_value - this->min_value);
    119122  }
    120123}
     
    132135  SYNCHELP_READ_INT( i );
    133136  this->type = (EnumParamPowerUpType)i;
    134   SYNCHELP_READ_INT( this->value );
     137  SYNCHELP_READ_FLOAT( this->value );
    135138
    136139  if ( this->value != 0 )
    137140  {
    138     SYNCHELP_READ_INT( this->min_value );
    139     SYNCHELP_READ_INT( this->max_value );
     141    SYNCHELP_READ_FLOAT( this->min_value );
     142    SYNCHELP_READ_FLOAT( this->max_value );
    140143    respawn();
    141144  }
     
    165168    int i = (int)this->type;
    166169    SYNCHELP_WRITE_INT( i );
    167     SYNCHELP_WRITE_INT( this->value );
     170    SYNCHELP_WRITE_FLOAT( this->value );
    168171
    169172    if ( this->value != 0 )
    170173    {
    171       SYNCHELP_WRITE_INT( this->min_value );
    172       SYNCHELP_WRITE_INT( this->max_value );
     174      SYNCHELP_WRITE_FLOAT( this->min_value );
     175      SYNCHELP_WRITE_FLOAT( this->max_value );
    173176    }
    174177
  • trunk/src/world_entities/power_ups/param_power_up.h

    r6512 r6547  
    1212
    1313typedef enum EnumParamPowerUpType {
    14   PARAM_SHIELD,
    15   PARAM_size
     14  POWERUP_PARAM_SHIELD,
     15  POWERUP_PARAM_MAX_SHIELD,
     16  POWERUP_PARAM_HEALTH,
     17  POWERUP_PARAM_MAX_HEALTH,
     18  POWERUP_PARAM_size
    1619} EnumParamPowerUpType;
    1720
     
    2326  virtual ~ParamPowerUp ();
    2427
    25   void setValue(int value);
    26   void setMaxValue(int value);
    27   void setMinValue(int value);
     28  void setValue(float value);
     29  void setMaxValue(float value);
     30  void setMinValue(float value);
    2831  void setType(const char* type);
    2932  EnumParamPowerUpType getType();
    30   int getValue();
     33  float getValue();
    3134
    3235  virtual int writeBytes(const byte* data, int length, int sender);
     
    4346  static const char* paramTypes[];
    4447  EnumParamPowerUpType type;
    45   int value;
    46   int max_value;
    47   int min_value;
     48  float value;
     49  float max_value;
     50  float min_value;
    4851};
    4952
  • trunk/src/world_entities/power_ups/power_up.cc

    r6512 r6547  
    6565void PowerUp::draw() const
    6666{
    67   glMatrixMode(GL_MODELVIEW);
     67  this->sphereMaterial->select();
     68  WorldEntity::draw();
     69  /*glMatrixMode(GL_MODELVIEW);
    6870  glPushMatrix();
    6971
    70   /* translate */
    7172  glTranslatef (this->getAbsCoor ().x,
    7273                this->getAbsCoor ().y,
     
    7879   this->getModel(0)->draw();
    7980
    80    glPopMatrix();
     81  glPopMatrix();*/
    8182}
    8283
  • trunk/src/world_entities/power_ups/weapon_power_up.cc

    r6512 r6547  
    5050void WeaponPowerUp::init()
    5151{
    52   weaponXML = NULL;
    53   weapon = NULL;
     52  this->setClassID(CL_WEAPON_POWER_UP, "WeaponPowerUp");
     53  this->weaponXML = NULL;
     54  this->weapon = NULL;
    5455}
    5556
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6532 r6547  
    123123  PRINTF(4)("SPACESHIP INIT\n");
    124124
    125   //EventHandler::getInstance()->grabEvents(true);
     125  EventHandler::getInstance()->grabEvents(true);
    126126
    127127  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
     
    450450     //this->setAbsDir(mouseDir);
    451451  }
    452 }
    453 
    454 /**
    455  *
    456  */
    457 bool SpaceShip::pickup(PowerUp* powerUp)
    458 {
    459   if(powerUp->isA(CL_WEAPON_POWER_UP)) {
    460     Weapon* weapon = dynamic_cast<WeaponPowerUp*>(powerUp)->getWeapon();
    461     WeaponManager* manager = this->getWeaponManager();
    462     int slot = manager->getNextFreeSlot(0, weapon->getCapability());
    463     if(slot >= 0) {
    464       manager->addWeapon(weapon, 0, slot);
    465       return true;
    466     }
    467   }
    468   else if(powerUp->isA(CL_PARAM_POWER_UP)) {
    469     ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp);
    470     switch(ppu->getType()) {
    471       case PARAM_SHIELD:
    472         break;
    473     }
    474   }
    475   return false;
    476452}
    477453
  • trunk/src/world_entities/space_ships/space_ship.h

    r6512 r6547  
    1515class Event;
    1616
    17 class SpaceShip : public Playable, public Extendable
     17class SpaceShip : public Playable
    1818{
    1919
     
    3939
    4040    virtual void process(const Event &event);
    41     bool pickup(PowerUp* powerUp);
    4241
    4342    virtual int       writeBytes(const byte* data, int length, int sender);
  • trunk/src/world_entities/weapons/turret.cc

    r6512 r6547  
    5454{
    5555  this->init();
    56   this->loadParams(root);
     56  if (root != NULL)
     57    this->loadParams(root);
    5758}
    5859
Note: See TracChangeset for help on using the changeset viewer.