Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud2/src/orxonox/objects/weapon/BulletManager.cc @ 1180

Last change on this file since 1180 was 927, checked in by scheusso, 17 years ago

Made various changes to Classes WorldEntity, Model, SpaceShip,
BulletManager and AmmunitionDump in order to make them really
synchronisable.
I hope, that everythings still working now. I only did some small tests
(ie no segfault when running/starting and acting)

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