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 | * Vedat Aydin |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | |
---|
30 | #include "ExplosionPart.h" |
---|
31 | #include "core/XMLPort.h" |
---|
32 | |
---|
33 | |
---|
34 | namespace orxonox |
---|
35 | { |
---|
36 | |
---|
37 | RegisterClass(ExplosionPart); |
---|
38 | |
---|
39 | ExplosionPart::ExplosionPart(Context* context) : MovableEntity(context) |
---|
40 | { |
---|
41 | RegisterObject(ExplosionPart); |
---|
42 | this->bStop_ = false; |
---|
43 | this->LOD_ = LODParticle::Normal; |
---|
44 | this->mesh_ = ""; |
---|
45 | this->effect1_ = ""; |
---|
46 | this->effect2_ = ""; |
---|
47 | this->model_= new Model(this->getContext()); |
---|
48 | this->effect1Particle_= NULL; |
---|
49 | this->effect2Particle_= NULL; |
---|
50 | this->explosionEntity_ = new MovableEntity(this->getContext()); |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | ExplosionPart::~ExplosionPart() |
---|
58 | { |
---|
59 | if (this->isInitialized()) |
---|
60 | { |
---|
61 | if (this->effect1Particle_) |
---|
62 | { |
---|
63 | this->model_->detachOgreObject(this->effect1Particle_->getParticleSystem()); |
---|
64 | delete this->effect1Particle_; |
---|
65 | } |
---|
66 | if (this->effect2Particle_) |
---|
67 | { |
---|
68 | this->model_->detachOgreObject(this->effect2Particle_->getParticleSystem()); |
---|
69 | delete this->effect2Particle_; |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
76 | { |
---|
77 | SUPER(ExplosionPart, XMLPort, xmlelement, mode); |
---|
78 | |
---|
79 | XMLPortParam(ExplosionPart, "mesh", setMesh, getMesh, xmlelement, mode).defaultValues(""); |
---|
80 | XMLPortParam(ExplosionPart, "minspeed", setMinSpeed, getMinSpeed, xmlelement, mode).defaultValues(50); |
---|
81 | XMLPortParam(ExplosionPart, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode).defaultValues(100); |
---|
82 | XMLPortParam(ExplosionPart, "effect1", setEffect1, getEffect1, xmlelement, mode).defaultValues(""); |
---|
83 | XMLPortParam(ExplosionPart, "effect2", setEffect2, getEffect2, xmlelement, mode).defaultValues(""); |
---|
84 | |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | void ExplosionPart::Explode() |
---|
90 | { |
---|
91 | orxout() << "Explode" << endl; |
---|
92 | |
---|
93 | |
---|
94 | this->model_->setVisible(true); |
---|
95 | |
---|
96 | //this->explosionEntity_->setSyncMode(0); |
---|
97 | |
---|
98 | //this->model_->setSyncMode(0); |
---|
99 | |
---|
100 | if(effect1_ != "") |
---|
101 | { |
---|
102 | this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_); |
---|
103 | this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem()); |
---|
104 | } |
---|
105 | |
---|
106 | if(effect2_ != "") |
---|
107 | { |
---|
108 | this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_); |
---|
109 | this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem()); |
---|
110 | } |
---|
111 | |
---|
112 | this->explosionEntity_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(minSpeed_,maxSpeed_)); |
---|
113 | this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
114 | this->explosionEntity_->setScale(4); |
---|
115 | |
---|
116 | this->explosionEntity_->attach(model_); |
---|
117 | |
---|
118 | this->attach(explosionEntity_); |
---|
119 | |
---|
120 | if (GameMode::isMaster()) |
---|
121 | { |
---|
122 | this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&ExplosionPart::stop, this))); |
---|
123 | } |
---|
124 | |
---|
125 | } |
---|
126 | |
---|
127 | void ExplosionPart::stop() |
---|
128 | { |
---|
129 | if (this->effect1Particle_) |
---|
130 | this->effect1Particle_->setEnabled(false); |
---|
131 | if (this->effect2Particle_) |
---|
132 | this->effect2Particle_->setEnabled(false); |
---|
133 | if (this->model_) |
---|
134 | this->model_->setVisible(false); |
---|
135 | |
---|
136 | if (GameMode::isMaster()) |
---|
137 | { |
---|
138 | this->bStop_ = true; |
---|
139 | this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&ExplosionPart::destroy, this))); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | void ExplosionPart::setMesh(const std::string& newString) |
---|
147 | { |
---|
148 | if(newString != "") |
---|
149 | { |
---|
150 | this->mesh_ = newString; |
---|
151 | this->model_->setMeshSource(mesh_); |
---|
152 | this->model_->setVisible(false); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | void ExplosionPart::setEffect1(const std::string& newString) |
---|
157 | { |
---|
158 | this->effect1_ = newString; |
---|
159 | } |
---|
160 | |
---|
161 | void ExplosionPart::setEffect2(const std::string& newString) |
---|
162 | { |
---|
163 | this->effect2_ = newString; |
---|
164 | } |
---|
165 | |
---|
166 | void ExplosionPart::setMinSpeed(float speed) |
---|
167 | { |
---|
168 | this->minSpeed_ = speed; |
---|
169 | } |
---|
170 | |
---|
171 | void ExplosionPart::setMaxSpeed(float speed) |
---|
172 | { |
---|
173 | this->maxSpeed_ = speed; |
---|
174 | } |
---|
175 | |
---|
176 | std::string& ExplosionPart::getMesh() |
---|
177 | { return this->mesh_; } |
---|
178 | |
---|
179 | std::string& ExplosionPart::getEffect1() |
---|
180 | { return this->effect1_; } |
---|
181 | |
---|
182 | std::string& ExplosionPart::getEffect2() |
---|
183 | { return this->effect2_; } |
---|
184 | |
---|
185 | float ExplosionPart::getMinSpeed() |
---|
186 | { |
---|
187 | return this->minSpeed_; |
---|
188 | } |
---|
189 | |
---|
190 | float ExplosionPart::getMaxSpeed() |
---|
191 | { |
---|
192 | return this->maxSpeed_; |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | } |
---|