Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6655 in orxonox.OLD


Ignore:
Timestamp:
Jan 23, 2006, 2:02:22 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: ammoContainer added

Location:
trunk/src
Files:
1 added
4 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r6637 r6655  
    209209
    210210  CL_WEAPON_MANAGER             =    0x00000503,
     211  CL_AMMO_CONTAINER             =    0x00000504,
    211212  CL_HUD                        =    0x00000520,
    212213
  • trunk/src/util/loading/resource_manager.cc

    r6651 r6655  
    2222
    2323#include <algorithm>
     24#include <assert.h>
    2425
    2526// different resource Types
  • trunk/src/world_entities/Makefile.am

    r6637 r6655  
    2727                  \
    2828                  world_entities/weapons/weapon_manager.cc \
     29                  world_entities/weapons/ammo_container.cc \
    2930                  world_entities/weapons/weapon.cc \
    3031                  world_entities/weapons/test_gun.cc \
     
    7980                 \
    8081                 world_entities/weapons/weapon_manager.h \
     82                 world_entities/weapons/ammo_container.h \
    8183                 world_entities/weapons/weapon.h \
    8284                 world_entities/weapons/test_gun.h \
  • trunk/src/world_entities/items/item_container.cc

    r6653 r6655  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
     
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "proto_class.h"
     18#include "item_container.h"
    1919
    2020using namespace std;
     
    2525 * @todo this constructor is not jet implemented - do it
    2626*/
    27 ProtoClass::ProtoClass ()
     27ItemContainer::ItemContainer ()
    2828{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
     29   this->setClassID(CL_ITEM_CONTAINER, "ItemContainer");
    3030
    3131   /* If you make a new class, what is most probably the case when you write this file
     
    4545 * standard deconstructor
    4646*/
    47 ProtoClass::~ProtoClass ()
     47ItemContainer::~ItemContainer ()
    4848{
    4949  // delete what has to be deleted here
  • trunk/src/world_entities/items/item_container.h

    r6653 r6655  
    11/*!
    2  * @file proto_class.h
    3  * @brief Definition of ...
    4 */
     2 * @file item_container.h
     3 * @brief Definition of a Container for Items one can pick up
     4 */
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
     6#ifndef _ITEM_CONTAINER_H
     7#define _ITEM_CONTAINER_H
    88
    99#include "base_object.h"
     
    1313
    1414
    15 //! A class for ...
    16 class ProtoClass : public BaseObject {
     15//! A class for storing collected Items.
     16class ItemContainer : public BaseObject {
    1717
    1818 public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
     19  ItemContainer();
     20  virtual ~ItemContainer();
    2121
    2222
     
    2525};
    2626
    27 #endif /* _PROTO_CLASS_H */
     27#endif /* _ITEM_CONTAINER_H */
  • trunk/src/world_entities/projectiles/laser.cc

    r6622 r6655  
    1717
    1818#include "laser.h"
     19#include <assert.h>
     20
    1921
    2022#include "fast_factory.h"
     
    2628#include "particle_emitter.h"
    2729#include "sprite_particles.h"
     30
    2831
    2932
  • trunk/src/world_entities/weapons/ammo_container.cc

    r6653 r6655  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
     
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "proto_class.h"
     18#include "ammo_container.h"
     19
     20#include "weapon.h"
     21
     22#include <assert.h>
    1923
    2024using namespace std;
    21 
    2225
    2326/**
     
    2528 * @todo this constructor is not jet implemented - do it
    2629*/
    27 ProtoClass::ProtoClass ()
     30AmmoContainer::AmmoContainer (ClassID projectileType, float maxEnergy)
    2831{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
     32   this->setClassID(CL_AMMO_CONTAINER, "AmmoContainer");
    3033
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
    3534
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
    4135}
    4236
     
    4539 * standard deconstructor
    4640*/
    47 ProtoClass::~ProtoClass ()
     41AmmoContainer::~AmmoContainer ()
    4842{
    4943  // delete what has to be deleted here
    5044}
     45
     46
     47
     48float AmmoContainer::increaseEnergy(float energy)
     49{
     50  this->energy += energy;
     51
     52  if (unlikely(this->energy > this->maxEnergy))
     53  {
     54    float retEnergy = this->energy - this->maxEnergy;
     55    this->energy = this->maxEnergy;
     56    return retEnergy;
     57  }
     58  else
     59    return 0.0f;
     60}
     61
     62
     63float AmmoContainer::decreaseEnergy(float energy)
     64{
     65  this->energy -= energy;
     66
     67  if (unlikely(this->energy < 0))
     68  {
     69    float retEnergy = 0 - this->energy;
     70    this->energy = 0;
     71    return retEnergy;
     72  }
     73  else
     74    return 0.0f;
     75}
     76
     77bool AmmoContainer::weaponValid(const Weapon* weapon)
     78{
     79  return (weapon->isA(this->projectileType));
     80}
     81
     82
     83void AmmoContainer::fillWeapon(Weapon* weapon)
     84{
     85  assert (weapon != NULL);
     86
     87  float fillEnergy = weapon->getEnergyMax();
     88
     89  float restEnergy = weapon->increaseEnergy(fillEnergy);
     90  this->decreaseEnergy(fillEnergy - restEnergy);
     91}
  • trunk/src/world_entities/weapons/ammo_container.h

    r6653 r6655  
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
     6#ifndef _AMMO_CONTAINER_H
     7#define _AMMO_CONTAINER_H
    88
    99#include "base_object.h"
    1010
     11
    1112// FORWARD DECLARATION
     13class Weapon;
     14
     15#define DEFAULT_MAX_ENERGY 100
     16
     17//! A class for Storing energy of Projectiles.
     18class AmmoContainer : public BaseObject {
     19
     20 public:
     21  AmmoContainer(ClassID projectileType, float maxEnergy = DEFAULT_MAX_ENERGY);
     22  virtual ~AmmoContainer();
     23
     24  ClassID getProjectileType() const { return this->projectileType; };
    1225
    1326
     27  float increaseEnergy(float energy);
     28  float decreaseEnergy(float energy);
    1429
    15 //! A class for ...
    16 class ProtoClass : public BaseObject {
     30  float getMaxEnergy() const { return this->maxEnergy; };
    1731
    18  public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
     32  void increaseMaxEnergy(float increase);
     33
     34  bool weaponValid(const Weapon* weapon);
     35  void fillWeapon(Weapon* weapon);
    2136
    2237
    2338 private:
     39   float  energy;
     40   float  maxEnergy;
    2441
     42   ClassID projectileType;
    2543};
    2644
    27 #endif /* _PROTO_CLASS_H */
     45#endif /* _AMMO_CONTAINER_H */
Note: See TracChangeset for help on using the changeset viewer.