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