Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 1, 2006, 3:48:03 PM (19 years ago)
Author:
manuel
Message:

powerups work but bugs in weaponmanager

Location:
branches/powerups/src/world_entities/power_ups
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/powerups/src/world_entities/power_ups/power_up.cc

    r6815 r6945  
    2121#include "primitive_model.h"
    2222
    23 #include "assert.h"
     23#include "load_param.h"
    2424
    2525using namespace std;
     
    2929  this->setClassID(CL_POWER_UP, "PowerUp");
    3030
    31   this->respawnType = RESPAWN_NONE;
     31  this->respawnType = RESPAWN_TIME;
    3232  this->respawnStart = 10;
    3333  this->model = NULL;
     
    3939  this->buildObbTree( 4);
    4040  this->sphereMaterial = new Material;
    41   this->sphereMaterial->setTransparency(.1);
     41  this->sphereMaterial->setTransparency(.8);
    4242  this->sphereMaterial->setDiffuse(r, g, b);
    4343  this->toList(OM_COMMON);
     
    5353{
    5454  WorldEntity::loadParams(root);
     55  LoadParam(root, "respawnType", this, PowerUp, setRespawnType);
     56  LoadParam(root, "respawnTime", this, PowerUp, setRespawnTime);
    5557}
    5658
     
    6264    if(dynamic_cast<Extendable*>(entity)->pickup(this))
    6365    {
    64       this->respawnTime = this->respawnStart;
    65       this->toList(OM_DEAD_TICK);
     66      switch(respawnType) {
     67        case RESPAWN_NONE:
     68          this->toList(OM_DEAD);
     69          break;
     70        case RESPAWN_TIME:
     71          this->toList(OM_DEAD_TICK);
     72          this->respawnTime = this->respawnStart;
     73          break;
     74      }
    6675    }
    6776  }
     
    7281    this->respawnTime -= dt;
    7382    if(this->respawnTime <= 0) {
    74       this->respawn();
    7583      this->toList(OM_COMMON);
    7684    }
     
    110118}
    111119
     120void PowerUp::setRespawnTime(const float respawnTime)
     121{
     122  this->respawnStart = respawnTime;
     123}
    112124
    113125
  • branches/powerups/src/world_entities/power_ups/power_up.h

    r6589 r6945  
    2626  virtual void tick(float dt);
    2727  void setRespawnType(const char* type);
     28  void setRespawnTime(const float respawn);
    2829
    2930  int       writeState(const byte* data, int length, int sender);
     
    3334  PowerUp(float r, float g, float b);
    3435  virtual ~PowerUp ();
    35   virtual void respawn() {};
    3636  Model* model;
    3737
  • branches/powerups/src/world_entities/power_ups/weapon_power_up.cc

    r6815 r6945  
    5353  this->setClassID(CL_WEAPON_POWER_UP, "WeaponPowerUp");
    5454  this->weaponXML = NULL;
    55   this->weaponID = CL_NULL;
    5655  this->weapon = NULL;
    5756}
     
    6564  {
    6665    this->weaponXML = elem;
    67     respawn();
     66    newWeapon();
    6867  }
    6968  else
     
    7877}
    7978
    80 void WeaponPowerUp::respawn()
     79bool WeaponPowerUp::process(WeaponManager* manager)
     80{
     81  if(manager->addWeapon(this->weapon)) {
     82    newWeapon();
     83  }
     84  else {
     85    manager->increaseAmmunition(this->weapon->getProjectileType(), this->weapon->getEnergy());
     86  }
     87  return true;
     88}
     89
     90void WeaponPowerUp::newWeapon()
    8191{
    8292  this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL)
    83       ? Factory::fabricate(static_cast<ClassID>(weaponID))
     93      ? Factory::fabricate(static_cast<ClassID>(this->weapon->getLeafClassID()))
    8494      : Factory::fabricate((TiXmlElement*)this->getXmlElem()->FirstChildElement("weapon")));
    8595  this->model = this->weapon->getModel(0);
     
    8999{
    90100  this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));
    91   this->weaponID = (ClassID)this->weapon->getLeafClassID();
    92101  this->model = this->weapon->getModel(0);
    93102}
  • branches/powerups/src/world_entities/power_ups/weapon_power_up.h

    r6710 r6945  
    99#include "power_up.h"
    1010#include "weapons/weapon.h"
     11#include "weapons/weapon_manager.h"
    1112
    1213/* FORWARD DEFINITION */
     
    2728  virtual int readBytes(byte* data, int maxLength, int * reciever );
    2829
    29 protected:
    30   virtual void respawn();
     30  bool process(WeaponManager* manager);
    3131
    3232private:
    3333  void init();
     34  void newWeapon();
    3435private:
    3536  Weapon* weapon;
    36   ClassID weaponID;
    3737  const TiXmlElement* weaponXML;
    3838
Note: See TracChangeset for help on using the changeset viewer.