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 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * Simon Miescher |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /* |
---|
30 | |
---|
31 | * |
---|
32 | * |
---|
33 | *<OFFEN Describe |
---|
34 | Math from asteroidField.lua used. |
---|
35 | * |
---|
36 | * |
---|
37 | |
---|
38 | |
---|
39 | DESCRIPTION |
---|
40 | o Andere: Simpel wie in asteroidField.lua, oder einfach Asteroiden, die nichts abwerfen? |
---|
41 | --> Letzteres scheint passender, simpler. |
---|
42 | |
---|
43 | |
---|
44 | */ |
---|
45 | |
---|
46 | |
---|
47 | #include "../../orxonox/worldentities/pawns/Pawn.h" |
---|
48 | #include "../../orxonox/worldentities/WorldEntity.h" |
---|
49 | |
---|
50 | #include "SpicedAsteroidField.h" |
---|
51 | #include "AsteroidMinable.h" |
---|
52 | |
---|
53 | #include <algorithm> |
---|
54 | |
---|
55 | #include "core/CoreIncludes.h" |
---|
56 | #include "core/GameMode.h" |
---|
57 | #include "core/XMLPort.h" |
---|
58 | #include "core/EventIncludes.h" |
---|
59 | #include "network/NetworkFunction.h" |
---|
60 | #include "util/Math.h" |
---|
61 | |
---|
62 | // #include "infos/PlayerInfo.h" |
---|
63 | // #include "controllers/Controller.h" |
---|
64 | // #include "gametypes/Gametype.h" |
---|
65 | // #include "graphics/ParticleSpawner.h" |
---|
66 | // #include "worldentities/ExplosionChunk.h" |
---|
67 | // #include "worldentities/ExplosionPart.h" |
---|
68 | |
---|
69 | // #include "core/object/ObjectListIterator.h" |
---|
70 | // #include "controllers/FormationController.h" |
---|
71 | |
---|
72 | |
---|
73 | //#include "../pickup/pickup ..... pickupable |
---|
74 | #include "../objects/collisionshapes/SphereCollisionShape.h" |
---|
75 | #include "../../orxonox/graphics/Model.h" |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | namespace orxonox |
---|
83 | { |
---|
84 | RegisterClass(SpicedAsteroidField); |
---|
85 | |
---|
86 | SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) { |
---|
87 | |
---|
88 | // Da auch noetig? Wegen set in XML-Code? |
---|
89 | RegisterObject(SpicedAsteroidField); |
---|
90 | |
---|
91 | this->context = context; |
---|
92 | this->foggy = true; |
---|
93 | this->fogDensity = 0.5; |
---|
94 | this->count = 0; |
---|
95 | |
---|
96 | // Old from Pawn |
---|
97 | this->registerVariables(); |
---|
98 | |
---|
99 | |
---|
100 | // this->create(); |
---|
101 | this->bAlive_ = false; |
---|
102 | this->destroyLater(); |
---|
103 | } |
---|
104 | |
---|
105 | SpicedAsteroidField::~SpicedAsteroidField(){ |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | void SpicedAsteroidField::create(){ |
---|
110 | |
---|
111 | int size; |
---|
112 | int pX; |
---|
113 | int pY; |
---|
114 | int pZ; |
---|
115 | |
---|
116 | Vector3* relPos; |
---|
117 | |
---|
118 | for(int gertrud = 0; gertrud<count; ++gertrud){ |
---|
119 | |
---|
120 | AsteroidMinable* a = new AsteroidMinable(this->context); |
---|
121 | |
---|
122 | size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize; |
---|
123 | a->setSize(size); |
---|
124 | pX = round(rnd()*2*this->radius) - radius; |
---|
125 | pY = round(rnd()*2*this->radius) - radius; |
---|
126 | pZ = round(rnd()*2*this->radius) - radius; |
---|
127 | relPos = new Vector3(pX, pY, pZ); |
---|
128 | a->setPosition(this->position + *relPos); |
---|
129 | |
---|
130 | bool spiced = (rnd() < (this->mDensity)); // does drop pickups etc. |
---|
131 | a->toggleDropStuff(spiced); |
---|
132 | |
---|
133 | // @TODO: Fox Fog stuff, error due to billbord |
---|
134 | |
---|
135 | // Billboard* bb; |
---|
136 | // if(this->foggy && mod(gertrud, 5) == 0){ |
---|
137 | // bb = new Billboard(this->context); |
---|
138 | // bb->setPosition(this-position + *relPos); |
---|
139 | // bb->setMaterial("Smoke/Smoke"); |
---|
140 | // bb->setScale(size); // tricky? |
---|
141 | |
---|
142 | // bb->setColour(ColourValue(this-fogDensity, this->fogDensity, this->fogDensity)); // 4rd argument = transparency? |
---|
143 | |
---|
144 | // // print("<Billboard ") |
---|
145 | // // print("position = \"") |
---|
146 | // // print(posX) print(",") |
---|
147 | // // print(posY) print(",") |
---|
148 | // // print(posZ) print("\" ") |
---|
149 | // // print("colour=\"") |
---|
150 | // // print(brightness) print(",") |
---|
151 | // // print(brightness) print(",") |
---|
152 | // // print(brightness) print("\" ") |
---|
153 | // // print("material=\"Smoke/Smoke\" scale=") |
---|
154 | // // print(size) |
---|
155 | // // print(" />") |
---|
156 | // } |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
161 | { |
---|
162 | // SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); |
---|
163 | // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); |
---|
164 | XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode); |
---|
165 | XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode); |
---|
166 | XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode); |
---|
167 | XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode); |
---|
168 | XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode); |
---|
169 | XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode); |
---|
170 | XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode); |
---|
171 | XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode); |
---|
172 | |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | |
---|
178 | void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
179 | { |
---|
180 | // SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode); |
---|
181 | |
---|
182 | XMLPortEventState(SpicedAsteroidField, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); |
---|
183 | } |
---|
184 | |
---|
185 | void SpicedAsteroidField::registerVariables() |
---|
186 | { |
---|
187 | |
---|
188 | registerVariable(this->count, VariableDirection::ToClient); |
---|
189 | registerVariable(this->mDensity, VariableDirection::ToClient); |
---|
190 | registerVariable(this->position, VariableDirection::ToClient); |
---|
191 | registerVariable(this->maxSize, VariableDirection::ToClient); |
---|
192 | registerVariable(this->minSize, VariableDirection::ToClient); |
---|
193 | registerVariable(this->radius, VariableDirection::ToClient); |
---|
194 | registerVariable(this->foggy, VariableDirection::ToClient); |
---|
195 | registerVariable(this->fogDensity, VariableDirection::ToClient); |
---|
196 | |
---|
197 | |
---|
198 | } |
---|
199 | |
---|
200 | void SpicedAsteroidField::tick(float dt){ |
---|
201 | |
---|
202 | this->create(); |
---|
203 | // orxout() << "SpicedAsteroidField is done. " << endl; |
---|
204 | |
---|
205 | this->bAlive_ = false; |
---|
206 | this->destroyLater(); |
---|
207 | } |
---|
208 | |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | } |
---|
214 | |
---|
215 | // --[[ fog generator |
---|
216 | // generates fog |
---|
217 | // posX, posY, posZ - position in space |
---|
218 | // size - size of billboard |
---|
219 | // brightness - [0,1] fog brightness |
---|
220 | // --]] |
---|
221 | // function generateFog(posX, posY, posZ, size, brightness) |
---|
222 | // print("<Billboard ") |
---|
223 | // print("position = \"") |
---|
224 | // print(posX) print(",") |
---|
225 | // print(posY) print(",") |
---|
226 | // print(posZ) print("\" ") |
---|
227 | // print("colour=\"") |
---|
228 | // print(brightness) print(",") |
---|
229 | // print(brightness) print(",") |
---|
230 | // print(brightness) print("\" ") |
---|
231 | // print("material=\"Smoke/Smoke\" scale=") |
---|
232 | // print(size) |
---|
233 | // print(" />") |
---|
234 | // end |
---|
235 | |
---|
236 | // --[[ asteroid field generator |
---|
237 | // generates asteroid field |
---|
238 | // posX, posY, posZ - position in space |
---|
239 | // minSize, maxSize - size boundaries of each asteroid |
---|
240 | // radius - size of the cube around position in space |
---|
241 | // count - number of asteroids |
---|
242 | // fog - enable fog 0/1 |
---|
243 | // --]] |
---|
244 | // function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog) |
---|
245 | // for i = 1, count, 1 do |
---|
246 | // size = (math.random() * (maxSize - minSize)) + minSize |
---|
247 | // pX = (2 * math.random() * radius) - radius + posX |
---|
248 | // pY = (2 * math.random() * radius) - radius + posY |
---|
249 | // pZ = (2 * math.random() * radius) - radius + posZ |
---|
250 | // print("<StaticEntity ") |
---|
251 | |
---|
252 | // print("position = \"") |
---|
253 | // print(pX) print(",") |
---|
254 | // print(pY) print(",") |
---|
255 | // print(pZ) print("\" ") |
---|
256 | |
---|
257 | // print("scale = \"") print(size) print("\" ") |
---|
258 | |
---|
259 | // print("collisionType = static linearDamping = 0.8 angularDamping = 1 ") |
---|
260 | // print("collisiondamage = 1000 enablecollisiondamage = true>") |
---|
261 | |
---|
262 | // print("<attached>") |
---|
263 | // print("<Model mass=\"") print(size * 10) print("\" ") |
---|
264 | // print("mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" />") |
---|
265 | // print("</attached>") |
---|
266 | |
---|
267 | // print("<collisionShapes> ") |
---|
268 | // print("<SphereCollisionShape radius=\"") |
---|
269 | // print(size * 2.5) print("\" />") |
---|
270 | // print("</collisionShapes>") |
---|
271 | |
---|
272 | // print("</StaticEntity>") |
---|
273 | |
---|
274 | // if fog == 1 and i % 5 == 0 then |
---|
275 | // generateFog(pX, pY, pZ, radius*0.04, 0.2) |
---|
276 | // end |
---|
277 | // end |
---|
278 | // end |
---|
279 | |
---|
280 | |
---|
281 | // --[[ asteroid belt generator |
---|
282 | // generates asteroid belt |
---|
283 | // posX, posY, posZ - position in space |
---|
284 | // yaw, pitch - rotation |
---|
285 | // minSize, maxSize - size boundaries of each asteroid |
---|
286 | // radius0, radius1 - inner/outer radius |
---|
287 | // count - number of asteroids |
---|
288 | // fog - enable fog 0/1 |
---|
289 | // --]] |
---|
290 | // function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog) |
---|
291 | // dPhi = (2 * math.pi) / segments |
---|
292 | // width = math.abs(radius1 - radius0) |
---|
293 | // radius = (radius1 + radius0) / 2 |
---|
294 | // segmentCount = count / segments |
---|
295 | |
---|
296 | // print("<StaticEntity collisionType=static yaw=") print(yaw) |
---|
297 | // print(" pitch=") print(pitch) |
---|
298 | |
---|
299 | // print(" position = \"") |
---|
300 | // print(centerX) print(",") |
---|
301 | // print(centerY) print(",") |
---|
302 | // print(centerZ) print("\"") |
---|
303 | // print(">") |
---|
304 | |
---|
305 | // print("<attached>") |
---|
306 | |
---|
307 | // for i = 0, segments - 1, 1 do |
---|
308 | // asteroidField((radius * math.cos(i * dPhi)), |
---|
309 | // (radius * math.sin(i * dPhi)), |
---|
310 | // 0, minSize, maxSize, width, segmentCount, fog) |
---|
311 | // end |
---|
312 | |
---|
313 | // print("</attached>") |
---|
314 | // print("</StaticEntity>") |
---|
315 | // end |
---|