Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/objects/Projectile.cc @ 1342

Last change on this file since 1342 was 1030, checked in by landauf, 17 years ago

extracted all config-value related macros from CoreIncludes.h and moved them to ConfigValueIncludes.h.

ConfigValueContainer can now handle std::vector<x> where 'x' is is any type supported by MultiTypeMath (all primitives, pointer, string, vector2, vector3, quaternion, colourvalue, radian, degree).

the vectors size is currently limited to 256 elements. this is just a practical limit, it can be raised if it's necessary. the reason for the limit is: you can add new elements to a vector by simply typing 'set classname varname index value' into the console or adding a new entry in the config-file. if 'index' is bigger than the vectors size, all elements up to 'index' are inserted. if the user accidentally enters a big number, he could end up with >4*109 elements in his config-file, resulting in 10-100gb on the hdd and a completely filled memory. and that's not exactly what i want ;)

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 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "OrxonoxStableHeaders.h"
29
30#include "core/CoreIncludes.h"
31#include "core/Executor.h"
32#include "core/ConfigValueIncludes.h"
33
34#include "SpaceShip.h"
35#include "Explosion.h"
36#include "Model.h"
37
38#include "Projectile.h"
39
40namespace orxonox
41{
42    CreateFactory(Projectile);
43
44    Projectile::Projectile(SpaceShip* owner)
45    {
46        RegisterObject(Projectile);
47
48        this->setConfigValues();
49
50        this->owner_ = owner;
51
52        this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
53        this->attachObject(this->billboard_.getBillboardSet());
54        this->scale(0.5);
55
56        if (this->owner_)
57        {
58            this->setStatic(false);
59            this->setOrientation(this->owner_->getOrientation());
60            this->setPosition(this->owner_->getPosition());
61            this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
62            this->setVelocity(Vector3(1, 0, 0) * this->speed_);
63        }
64
65        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
66    }
67
68    Projectile::~Projectile()
69    {
70    }
71
72    void Projectile::setConfigValues()
73    {
74        SetConfigValue(lifetime_, 10.0).description("The time in seconds a projectile stays alive");
75        SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second");
76
77        this->setVelocity(Vector3(1, 0, 0) * this->speed_);
78    }
79
80    void Projectile::tick(float dt)
81    {
82        WorldEntity::tick(dt);
83
84        float radius;
85        for (Iterator<Model> it = ObjectList<Model>::start(); it; ++it)
86        {
87            if ((*it) != this->owner_)
88            {
89                radius = it->getScale().x * 3.0;
90
91                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
92                {
93                    new Explosion(this);
94                    delete this;
95                    return;
96                }
97            }
98        }
99    }
100
101    void Projectile::destroyObject()
102    {
103        delete this;
104    }
105}
Note: See TracBrowser for help on using the repository browser.