Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/BossFight_FS19/src/modules/asteroidmining/SpicedAsteroidField.cc @ 12397

Last change on this file since 12397 was 11781, checked in by landauf, 7 years ago

eol-style native (no changes in code)

  • Property svn:eol-style set to native
File size: 4.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 *      remartin
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30
31    @file
32    @author remartin
33    @brief Asteroid field with lots of parameters. Derived from asteroidField.lua
34
35    Generates a bunch of asteroids that may contain some stuff.
36    It is required to wait until all XML-arguments are set. That's why the actual
37    generation happens when tick() gets called for the first time.
38   
39*/
40
41
42#include "SpicedAsteroidField.h"
43#include "AsteroidMinable.h"
44
45#include <algorithm>
46
47#include "core/CoreIncludes.h"
48#include "core/XMLPort.h"
49#include "util/Math.h"
50
51#include "graphics/Billboard.h"
52
53
54namespace orxonox{
55
56    RegisterClass(SpicedAsteroidField);
57
58    SpicedAsteroidField::SpicedAsteroidField(Context* context) : BaseObject(context) {
59
60        RegisterObject(SpicedAsteroidField);
61
62        // Default Values:
63        this->count = 30; 
64        this->mDensity = 0.5;
65        this->position = Vector3(0,0,0);
66        this->maxSize = 40; 
67        this->minSize = 1; 
68        this->radius = 1000;
69        this->foggy = true; 
70        this->fogDensity = 0.5;
71    }
72
73    SpicedAsteroidField::~SpicedAsteroidField(){
74
75    }
76
77    void SpicedAsteroidField::create(){
78
79        float size;
80        float pX;
81        float pY;
82        float pZ;
83
84        for(int gertrud = 0; gertrud<count; ++gertrud){
85
86            AsteroidMinable* a = new AsteroidMinable(this->getContext());
87
88            size = roundf(rnd(this->maxSize - this->minSize)) + this->minSize;
89            a->setSize(size); 
90
91            pX = roundf(rnd(2*this->radius)) - radius;
92            pY = roundf(rnd(2*this->radius)) - radius;
93            pZ = roundf(rnd(2*this->radius)) - radius;
94            Vector3 relPos(pX, pY, pZ);
95            a->setPosition(this->position + relPos);
96
97            bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc.
98            a->setDropStuff(spiced);
99           
100            // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea)
101            if(this->foggy && mod(gertrud, 5) == 0){
102                Billboard* bb = new Billboard(this->getContext());
103                bb->setPosition(this->position + relPos);
104                bb->setMaterial("Smoke/Smoke");
105                bb->setScale(size);
106                bb->setColour(ColourValue(this->fogDensity, this->fogDensity, this->fogDensity));   
107            }
108        }
109    }
110
111    void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode){
112
113        SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); 
114
115        XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode);
116        XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
117        XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode);
118        XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
119        XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode);
120        XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode);
121        XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode);
122        XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
123
124    }
125
126    void SpicedAsteroidField::tick(float dt){
127
128        this->create();
129        this->destroyLater();
130    }
131
132}
Note: See TracBrowser for help on using the repository browser.