Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc @ 11640

Last change on this file since 11640 was 11640, checked in by remartin, 6 years ago

Das Aufteilen funktioniert nun gut. AsteroidField fertiggestellt und mit dokumentieren begonnen.

File size: 9.7 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      Simon Miescher
26 *
27 */
28
29/*
30
31*
32*
33*<OFFEN Describe
34Math from asteroidField.lua used.
35*
36*
37
38
39DESCRIPTION
40o 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
82namespace 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
95        // Old from Pawn
96        this->registerVariables();
97
98
99        // this->create();
100        this->bAlive_ = false;
101        this->destroyLater();
102    }
103
104    SpicedAsteroidField::~SpicedAsteroidField(){
105
106    }
107
108    void SpicedAsteroidField::create(){
109
110        int size;
111        int pX;
112        int pY;
113        int pZ;
114
115        Vector3* relPos; 
116
117        for(int gertrud = 0; gertrud<count; ++gertrud){
118
119            AsteroidMinable* a = new AsteroidMinable(this->context);
120
121            size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize;
122            a->setSize(size);
123
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        this->bAlive_ = false;
204        this->destroyLater();
205    }
206
207
208
209
210
211}
212
213// --[[ fog generator
214// generates fog
215//     posX, posY, posZ - position in space
216//     size - size of billboard
217//     brightness - [0,1] fog brightness
218// --]]
219// function generateFog(posX, posY, posZ, size, brightness)
220//     print("<Billboard ")
221//         print("position = \"")
222//             print(posX) print(",")
223//             print(posY) print(",")
224//             print(posZ) print("\" ")
225//         print("colour=\"")
226//             print(brightness) print(",")
227//             print(brightness) print(",")
228//             print(brightness) print("\" ")
229//         print("material=\"Smoke/Smoke\" scale=")
230//         print(size)
231//     print(" />")
232// end
233
234// --[[ asteroid field generator
235// generates asteroid field
236//     posX, posY, posZ - position in space
237//     minSize, maxSize - size boundaries of each asteroid
238//     radius - size of the cube around position in space
239//     count - number of asteroids
240//     fog - enable fog 0/1
241// --]]
242// function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog)
243//     for i = 1, count, 1 do
244//         size = (math.random() * (maxSize - minSize)) + minSize
245//         pX = (2 * math.random() * radius) - radius + posX
246//         pY = (2 * math.random() * radius) - radius + posY
247//         pZ = (2 * math.random() * radius) - radius + posZ
248//         print("<StaticEntity ")
249
250//         print("position = \"")
251//         print(pX) print(",")
252//         print(pY) print(",")
253//         print(pZ) print("\" ")
254
255//         print("scale = \"") print(size) print("\" ")
256
257//         print("collisionType = static linearDamping = 0.8 angularDamping = 1 ")
258//         print("collisiondamage = 1000 enablecollisiondamage = true>")
259
260//         print("<attached>")
261//             print("<Model mass=\"") print(size * 10) print("\" ")
262//             print("mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" />")
263//         print("</attached>")
264
265//         print("<collisionShapes> ")
266//             print("<SphereCollisionShape radius=\"")
267//             print(size * 2.5) print("\" />")
268//         print("</collisionShapes>")
269
270//         print("</StaticEntity>")
271
272//         if fog == 1 and i % 5 == 0 then
273//             generateFog(pX, pY, pZ, radius*0.04, 0.2)
274//         end
275//     end
276// end
277
278
279// --[[ asteroid belt generator
280// generates asteroid belt
281//     posX, posY, posZ - position in space
282//     yaw, pitch - rotation
283//     minSize, maxSize - size boundaries of each asteroid
284//     radius0, radius1 - inner/outer radius
285//     count - number of asteroids
286//     fog - enable fog 0/1
287// --]]
288// function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog)
289//     dPhi = (2 * math.pi) / segments
290//     width = math.abs(radius1 - radius0)
291//     radius = (radius1 + radius0) / 2
292//     segmentCount = count / segments
293
294//     print("<StaticEntity collisionType=static yaw=") print(yaw)
295//     print(" pitch=") print(pitch)
296
297//     print(" position = \"")
298//         print(centerX) print(",")
299//         print(centerY) print(",")
300//         print(centerZ) print("\"")
301//     print(">")
302
303//     print("<attached>")
304
305//     for i = 0, segments - 1, 1 do
306//         asteroidField((radius * math.cos(i * dPhi)),
307//                     (radius * math.sin(i * dPhi)),
308//                     0, minSize, maxSize, width, segmentCount, fog)
309//     end
310
311//     print("</attached>")
312//     print("</StaticEntity>")
313// end
Note: See TracBrowser for help on using the repository browser.