Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shader/src/orxonox/objects/weapon/BulletManager.cc @ 2274

Last change on this file since 2274 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "BulletManager.h"
31
32#include "Bullet.h"
33#include "core/CoreIncludes.h"
34
35
36namespace orxonox {
37  CreateFactory(BulletManager);
38
39  BulletManager::BulletManager() : bulletsSize_(8), bulletsIndex_(0)
40  {
41    RegisterObject(BulletManager);
42    registerAllVariables();
43    bullets_ = new Bullet*[bulletsSize_];
44  }
45
46
47  BulletManager::~BulletManager()
48  {
49    // clean up the bullet list
50    if (bullets_)
51    {
52      for (int i = 0; i < bulletsIndex_; i++)
53        delete bullets_[i];
54      delete bullets_;
55    }
56  }
57
58
59  void BulletManager::addBullet(Bullet *bullet)
60  {
61    // resize array if neccessary (double the size then)
62    if (bulletsIndex_ >= bulletsSize_)
63    {
64      // redimension the array
65      Bullet **tempArray = new Bullet*[2*bulletsSize_];
66      for (int i = 0; i < bulletsSize_; i++)
67        tempArray[i] = bullets_[i];
68      bulletsSize_ *= 2;
69      delete bullets_;
70      bullets_ = tempArray;
71    }
72
73    // add the bullet to the list
74    bullets_[bulletsIndex_++] = bullet;
75  }
76
77
78  void BulletManager::tick(float dt)
79  {
80    // update the bullet positions
81    for (int i = 0; i < bulletsIndex_; i++)
82    {
83      bullets_[i]->getNode()->translate(bullets_[i]->getVelocity()*dt);
84      //bullets_[i]->getNode()->yaw(Degree(dt*100));
85      //bullets_[i]->getNode()->roll(Degree(dt*300));
86    }
87  }
88
89  int BulletManager::getAmmunitionID(const std::string &ammoName)
90  {
91    std::string ammoTypes[] = { "Energy Cell", "Barrel", "Lead Shot" };
92    int ammoTypesLength = 3;
93
94    for (int i = 0; i < ammoTypesLength; i++)
95    {
96      if (ammoTypes[i] == ammoName)
97        return i;
98    }
99    return -1;
100  }
101
102  int BulletManager::getNumberOfAmmos()
103  {
104    return 3;
105  }
106
107  void BulletManager::registerAllVariables(){
108    registerVar(&bulletsSize_, sizeof(int), network::DATA);
109    registerVar(&bulletsIndex_, sizeof(int), network::DATA);
110    // TODO we got a problem here:
111    // there is no possibility (so far) to synchronise pointers to objects
112  }
113
114}
Note: See TracBrowser for help on using the repository browser.