Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

SpicedAsteroidBelt erstellt, kosmetische Veränderungen. Offener Punkt um velocity, ansonsten fehlt nur noch das dokumentieren.

File size: 5.5 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    @file SpicedAsteroidField.cc
32    @brief Asteroid field with lots of parameters. Derived from asteroidField.lua
33
34
35*/
36
37
38#include "../../orxonox/worldentities/pawns/Pawn.h"
39#include "../../orxonox/worldentities/WorldEntity.h"
40
41#include "SpicedAsteroidField.h"
42#include "AsteroidMinable.h"
43
44#include <algorithm>
45
46#include "core/CoreIncludes.h"
47#include "core/GameMode.h"
48#include "core/XMLPort.h"
49#include "core/EventIncludes.h"
50#include "network/NetworkFunction.h"
51#include "util/Math.h"
52
53#include "../../orxonox/graphics/Billboard.h"
54
55
56namespace orxonox{
57
58    RegisterClass(SpicedAsteroidField);
59
60    SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) {
61
62        RegisterObject(SpicedAsteroidField);
63        this->context = context;
64
65        // Default Values:
66        this->count = 30; 
67        this->mDensity = 0.5;
68        this->position = Vector3(0,0,0);
69        this->maxSize = 40; 
70        this->minSize = 1; 
71        this->radius = 1000;
72        this->foggy = true; 
73        this->fogDensity = 0.5;
74
75        this->registerVariables();
76    }
77
78    SpicedAsteroidField::SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD): Pawn(c){
79
80        this->context = c;
81        this->position = p; 
82        this->minSize = minS; 
83        this->maxSize = maxS; 
84        this->radius = w; 
85        this->count = count; 
86        this->foggy = f; 
87
88        this->mDensity = mD;
89        this->fogDensity = fD; 
90
91    }
92
93
94    SpicedAsteroidField::~SpicedAsteroidField(){
95
96    }
97
98    void SpicedAsteroidField::create(){
99
100        int size;
101        int pX;
102        int pY;
103        int pZ;
104
105        Vector3* relPos; 
106
107
108        for(int gertrud = 0; gertrud<count; ++gertrud){
109
110            AsteroidMinable* a = new AsteroidMinable(this->context);
111
112            size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize;
113            a->setSize(size);
114            pX = round(rnd()*2*this->radius) - radius;
115            pY = round(rnd()*2*this->radius) - radius;
116            pZ = round(rnd()*2*this->radius) - radius;
117            relPos = new Vector3(pX, pY, pZ);
118            a->setPosition(this->position + *relPos);
119
120            bool spiced = (rnd() < (this->mDensity)); // does drop pickups etc.
121            a->toggleDropStuff(spiced);
122
123            // A problem
124            a->setVelocity(this->getVelocity());
125           
126            // Fog is iplemented with billboards.
127            Billboard* bb;
128            if(this->foggy && mod(gertrud, 5) == 0){
129                bb = new Billboard(this->context);
130                bb->setPosition(this->position + *relPos);
131                bb->setMaterial("Smoke/Smoke");
132                bb->setScale(size);
133                bb->setColour(ColourValue(this->fogDensity, this->fogDensity, this->fogDensity));   
134            }
135        }
136    }
137
138    void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode){
139
140        SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); 
141
142        XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode);
143        XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
144        XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode);
145        XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
146        XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode);
147        XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode);
148        XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode);
149        XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
150
151    }
152
153
154    void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
155
156    }
157
158    void SpicedAsteroidField::registerVariables(){
159
160        registerVariable(this->count, VariableDirection::ToClient);
161        registerVariable(this->mDensity, VariableDirection::ToClient);
162        registerVariable(this->position, VariableDirection::ToClient);
163        registerVariable(this->maxSize, VariableDirection::ToClient);
164        registerVariable(this->minSize, VariableDirection::ToClient);
165        registerVariable(this->radius, VariableDirection::ToClient);
166        registerVariable(this->foggy, VariableDirection::ToClient);
167        registerVariable(this->fogDensity, VariableDirection::ToClient);
168
169    }
170
171    void SpicedAsteroidField::tick(float dt){
172
173        this->create();
174        this->bAlive_ = false;
175        this->destroyLater();
176    }
177
178}
Note: See TracBrowser for help on using the repository browser.