Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/ammo_container.cc @ 6669

Last change on this file since 6669 was 6669, checked in by bensch, 18 years ago

some WeaponManager remake

File size: 1.8 KB
RevLine 
[4744]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[6655]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[6655]18#include "ammo_container.h"
[1853]19
[6655]20#include "weapon.h"
21
22#include <assert.h>
23
[1856]24using namespace std;
[1853]25
[3245]26/**
[4838]27 * standard constructor
28 * @todo this constructor is not jet implemented - do it
[3245]29*/
[6655]30AmmoContainer::AmmoContainer (ClassID projectileType, float maxEnergy)
[3365]31{
[6655]32   this->setClassID(CL_AMMO_CONTAINER, "AmmoContainer");
[4320]33
[6669]34   this->energy = 0.0;
35   this->maxEnergy = maxEnergy;
[3365]36}
[1853]37
38
[3245]39/**
[4838]40 * standard deconstructor
[3245]41*/
[6655]42AmmoContainer::~AmmoContainer ()
[3543]43{
44  // delete what has to be deleted here
45}
[6655]46
47
48
49float AmmoContainer::increaseEnergy(float energy)
50{
51  this->energy += energy;
52
53  if (unlikely(this->energy > this->maxEnergy))
54  {
55    float retEnergy = this->energy - this->maxEnergy;
56    this->energy = this->maxEnergy;
57    return retEnergy;
58  }
59  else
60    return 0.0f;
61}
62
63
64float AmmoContainer::decreaseEnergy(float energy)
65{
66  this->energy -= energy;
67
68  if (unlikely(this->energy < 0))
69  {
70    float retEnergy = 0 - this->energy;
71    this->energy = 0;
72    return retEnergy;
73  }
74  else
75    return 0.0f;
76}
77
78bool AmmoContainer::weaponValid(const Weapon* weapon)
79{
80  return (weapon->isA(this->projectileType));
81}
82
83
84void AmmoContainer::fillWeapon(Weapon* weapon)
85{
86  assert (weapon != NULL);
[6664]87  assert (this->weaponValid(weapon));
[6655]88
89  float fillEnergy = weapon->getEnergyMax();
90
91  float restEnergy = weapon->increaseEnergy(fillEnergy);
92  this->decreaseEnergy(fillEnergy - restEnergy);
93}
Note: See TracBrowser for help on using the repository browser.