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 SpicedAsteroidBelt.cc |
---|
32 | @brief Asteroid belt 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 "SpicedAsteroidBelt.h" |
---|
42 | #include "SpicedAsteroidField.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 | namespace orxonox{ |
---|
54 | |
---|
55 | RegisterClass(SpicedAsteroidBelt); |
---|
56 | |
---|
57 | SpicedAsteroidBelt::SpicedAsteroidBelt(Context* context) : Pawn(context) { |
---|
58 | |
---|
59 | RegisterObject(SpicedAsteroidBelt); |
---|
60 | |
---|
61 | this->context = context; |
---|
62 | |
---|
63 | // Default Values: |
---|
64 | this->count = 250; |
---|
65 | this->position = Vector3(0,0,0); |
---|
66 | // this->yaw = 0; |
---|
67 | // this->pitch = 0; |
---|
68 | this->segments = 30; |
---|
69 | this->minSize = 1; |
---|
70 | this->maxSize = 50; |
---|
71 | this->radius0 = 7190; |
---|
72 | this->radius1 = 7800; |
---|
73 | |
---|
74 | this->mDensity = 0.3; |
---|
75 | this->fogDensity = 0.5; |
---|
76 | |
---|
77 | // Old from Pawn |
---|
78 | this->registerVariables(); |
---|
79 | |
---|
80 | } |
---|
81 | |
---|
82 | SpicedAsteroidBelt::~SpicedAsteroidBelt(){ |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | void SpicedAsteroidBelt::create(){ |
---|
87 | |
---|
88 | float myPi = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so. |
---|
89 | float dPhi = (2 * myPi) / segments; |
---|
90 | float width = radius1 - radius0; if(width<0){width = -width;} // predefined abs? |
---|
91 | float radius = (radius1 + radius0) / 2.0; |
---|
92 | int segmentCount = round(count / segments); |
---|
93 | |
---|
94 | SpicedAsteroidField* af[segments]; |
---|
95 | (void)af[0]; // avoid nasty compiler warning |
---|
96 | |
---|
97 | for(int s = 0; s<segments; ++s){ |
---|
98 | Vector3* pos = new Vector3(radius*cos(s*dPhi), radius*sin(s*dPhi),0); |
---|
99 | af[s] = new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity); |
---|
100 | } |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | void SpicedAsteroidBelt::XMLPort(Element& xmlelement, XMLPort::Mode mode){ |
---|
105 | |
---|
106 | SUPER(SpicedAsteroidBelt, XMLPort, xmlelement, mode); |
---|
107 | |
---|
108 | XMLPortParam(SpicedAsteroidBelt, "count", setCount, getCount, xmlelement, mode); |
---|
109 | XMLPortParam(SpicedAsteroidBelt, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode); |
---|
110 | XMLPortParam(SpicedAsteroidBelt, "position", setPosition, getPosition, xmlelement, mode); |
---|
111 | // XMLPortParam(SpicedAsteroidBelt, "yaw", setYaw, getYaw, xmlelement, mode); |
---|
112 | // XMLPortParam(SpicedAsteroidBelt, "pitch", setPitch, getPitch, xmlelement, mode); |
---|
113 | XMLPortParam(SpicedAsteroidBelt, "segments", setSegments, getSegments, xmlelement, mode); |
---|
114 | |
---|
115 | XMLPortParam(SpicedAsteroidBelt, "maxSize", setMaxSize, getMaxSize, xmlelement, mode); |
---|
116 | XMLPortParam(SpicedAsteroidBelt, "minSize", setMinSize, getMinSize, xmlelement, mode); |
---|
117 | XMLPortParam(SpicedAsteroidBelt, "radius0", setRadius0, getRadius0, xmlelement, mode); |
---|
118 | XMLPortParam(SpicedAsteroidBelt, "radius1", setRadius1, getRadius1, xmlelement, mode); |
---|
119 | XMLPortParam(SpicedAsteroidBelt, "foggy", setFog, isFoggy, xmlelement, mode); |
---|
120 | XMLPortParam(SpicedAsteroidBelt, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode); |
---|
121 | |
---|
122 | } |
---|
123 | |
---|
124 | void SpicedAsteroidBelt::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){ |
---|
125 | |
---|
126 | } |
---|
127 | |
---|
128 | void SpicedAsteroidBelt::registerVariables(){ |
---|
129 | |
---|
130 | registerVariable(this->count, VariableDirection::ToClient); |
---|
131 | registerVariable(this->mDensity, VariableDirection::ToClient); |
---|
132 | registerVariable(this->position, VariableDirection::ToClient); |
---|
133 | // registerVariable(this->yaw, VariableDirection::ToClient); |
---|
134 | // registerVariable(this->pitch, VariableDirection::ToClient); |
---|
135 | registerVariable(this->segments, VariableDirection::ToClient); |
---|
136 | |
---|
137 | registerVariable(this->maxSize, VariableDirection::ToClient); |
---|
138 | registerVariable(this->minSize, VariableDirection::ToClient); |
---|
139 | registerVariable(this->radius0, VariableDirection::ToClient); |
---|
140 | registerVariable(this->radius1, VariableDirection::ToClient); |
---|
141 | registerVariable(this->foggy, VariableDirection::ToClient); |
---|
142 | registerVariable(this->fogDensity, VariableDirection::ToClient); |
---|
143 | |
---|
144 | } |
---|
145 | |
---|
146 | void SpicedAsteroidBelt::tick(float dt){ |
---|
147 | |
---|
148 | this->create(); |
---|
149 | this->bAlive_ = false; |
---|
150 | this->destroyLater(); |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | } |
---|
155 | |
---|
156 | |
---|