Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/particleEffectsHS15/src/modules/weapons/projectiles/MineProjectile.cc @ 10897

Last change on this file since 10897 was 10897, checked in by landauf, 8 years ago

register event-source

File size: 5.2 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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file MineProjectile.h
31    @brief Implementation of the MineProjectile class.
32*/
33
34#include "MineProjectile.h"
35
36#include "core/CoreIncludes.h"
37#include "core/command/Executor.h"
38#include "core/EventIncludes.h"
39#include "graphics/Model.h"
40
41namespace orxonox
42{
43    RegisterClass(MineProjectile);
44
45    MineProjectile::MineProjectile(Context* context) : MovableEntity(context), BasicProjectile()
46    {
47        RegisterObject(MineProjectile);
48
49        this->bActive_ = false;
50        this->maxTimeUntilExplosion_ = 10.0f;
51        this->timeUntilActivation_ = 1.0f;
52
53        rings_ = new MovableEntity(this->getContext());
54        this->attach(rings_);
55        rings_->setPosition(Vector3(0.0,0.0,0.0));
56        rings_->setAngularVelocity(Vector3(0.0,5.0,0.0));
57
58        modelCore_ = new Model(this->getContext());
59        modelCore_->setMeshSource("Mine_Core.mesh");
60        modelCore_->setScale(15.0);
61        this->attach(modelCore_);
62        modelCore_->setPosition(Vector3(0,0,0));
63
64        modelRing1_ = new Model(this->getContext());
65        modelRing1_->setMeshSource("Mine_Ring.mesh");
66        modelRing1_->setScale(15.0);
67        rings_->attach(modelRing1_);
68        modelRing1_->setPosition(Vector3(0,0,0));
69        modelRing1_->yaw(Degree(0));
70
71        modelRing2_ = new Model(this->getContext());
72        modelRing2_->setMeshSource("Mine_Ring.mesh");
73        modelRing2_->setScale(15.0);
74        rings_->attach(modelRing2_);
75        modelRing2_->setPosition(Vector3(0,0,0));
76        modelRing2_->yaw(Degree(180));
77
78        if (GameMode::isMaster())
79        {
80            this->setMass(10.0f);
81            this->setFriction(100.0f);
82            this->enableCollisionCallback();
83            this->setCollisionResponse(false);
84            this->setCollisionType(Dynamic);
85
86            // Create a sphere collision shape and attach it to the projectile.
87            collisionShape_ = new SphereCollisionShape(this->getContext());
88            collisionShape_->setRadius(10.0f);
89            this->attachCollisionShape(collisionShape_);
90
91            // Create a distance trigger and attach it to the projectile.
92            distanceTrigger_ = new DistanceTrigger(this->getContext());
93            this->attach(distanceTrigger_);
94            distanceTrigger_->setPosition(Vector3(0,0,0));
95            distanceTrigger_->setDistance(40.0f);
96            distanceTrigger_->addTarget("Pawn");
97            distanceTrigger_->setStayActive(true);
98
99            this->addEventSource(distanceTrigger_, "explode");
100        }
101    }
102
103    MineProjectile::~MineProjectile()
104    {
105        if (this->isInitialized())
106        {
107            /*if (modelCore_ != NULL)
108            {
109                modelCore_->destroy();
110            }*/
111            if (distanceTrigger_)
112                distanceTrigger_->destroy();
113        }
114    }
115
116    void MineProjectile::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
117    {
118        SUPER(MineProjectile, XMLEventPort, xmlelement, mode);
119        XMLPortEventState(MineProjectile, BaseObject, "explode", Explode, xmlelement, mode);
120    }
121
122    /**
123    @brief
124        TODO
125    */
126    void MineProjectile::setMaxTimeUntilExplosion(float maxTimeUntilExplosion)
127    {
128        if (maxTimeUntilExplosion >= 0)
129        {
130            this->maxTimeUntilExplosion_ = maxTimeUntilExplosion;
131            if (GameMode::isMaster())
132            {
133                this->explodeTimer_.setTimer(this->maxTimeUntilExplosion_, false, createExecutor(createFunctor(&MineProjectile::Explode, this)));
134            }
135        }
136        else
137        {
138            this->maxTimeUntilExplosion_ = 0;
139        }
140    }
141
142    /**
143    @brief
144        TODO
145    */
146    void MineProjectile::setTimeUntilActivation(float timeUntilActivation)
147    {
148        timeUntilActivation_ = timeUntilActivation;
149
150        if (GameMode::isMaster())
151        {
152            this->activationTimer_.setTimer(this->timeUntilActivation_, false, createExecutor(createFunctor(&MineProjectile::Activate, this)));
153        }
154    }
155
156    /**
157    @brief
158        TODO
159    */
160    void MineProjectile::Explode()
161    {
162        orxout() << "MineProjectile::Explode" << endl;
163
164        this->destroyLater();
165
166
167    }
168
169    /**
170    @brief
171        TODO
172    */
173    void MineProjectile::Activate()
174    {
175        orxout() << "MineProjectile::Activate" << endl;
176
177        bActive_ = true;
178    }
179}
Note: See TracBrowser for help on using the repository browser.