[11610] | 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 | |
---|
[11664] | 29 | /** |
---|
[11610] | 30 | |
---|
[11667] | 31 | @file |
---|
| 32 | @author remartin |
---|
[11664] | 33 | @brief Asteroid field with lots of parameters. Derived from asteroidField.lua |
---|
[11610] | 34 | |
---|
[11667] | 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 | |
---|
[11610] | 39 | */ |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | #include "../../orxonox/worldentities/pawns/Pawn.h" |
---|
| 43 | #include "../../orxonox/worldentities/WorldEntity.h" |
---|
| 44 | |
---|
| 45 | #include "SpicedAsteroidField.h" |
---|
[11615] | 46 | #include "AsteroidMinable.h" |
---|
[11610] | 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" |
---|
[11615] | 55 | #include "util/Math.h" |
---|
[11610] | 56 | |
---|
[11664] | 57 | #include "../../orxonox/graphics/Billboard.h" |
---|
[11610] | 58 | |
---|
| 59 | |
---|
[11664] | 60 | namespace orxonox{ |
---|
[11615] | 61 | |
---|
[11610] | 62 | RegisterClass(SpicedAsteroidField); |
---|
| 63 | |
---|
[11640] | 64 | SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) { |
---|
[11610] | 65 | |
---|
| 66 | RegisterObject(SpicedAsteroidField); |
---|
[11664] | 67 | this->context = context; |
---|
[11610] | 68 | |
---|
[11664] | 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; |
---|
[11640] | 76 | this->foggy = true; |
---|
| 77 | this->fogDensity = 0.5; |
---|
[11610] | 78 | |
---|
| 79 | this->registerVariables(); |
---|
[11664] | 80 | } |
---|
[11610] | 81 | |
---|
[11664] | 82 | SpicedAsteroidField::SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD): Pawn(c){ |
---|
[11610] | 83 | |
---|
[11664] | 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 | |
---|
[11610] | 95 | } |
---|
| 96 | |
---|
[11664] | 97 | |
---|
[11610] | 98 | SpicedAsteroidField::~SpicedAsteroidField(){ |
---|
| 99 | |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void SpicedAsteroidField::create(){ |
---|
| 103 | |
---|
[11640] | 104 | int size; |
---|
| 105 | int pX; |
---|
| 106 | int pY; |
---|
| 107 | int pZ; |
---|
[11610] | 108 | |
---|
[11640] | 109 | Vector3* relPos; |
---|
[11610] | 110 | |
---|
[11640] | 111 | for(int gertrud = 0; gertrud<count; ++gertrud){ |
---|
[11610] | 112 | |
---|
[11640] | 113 | AsteroidMinable* a = new AsteroidMinable(this->context); |
---|
| 114 | |
---|
| 115 | size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize; |
---|
[11667] | 116 | a->setSize(size); |
---|
| 117 | |
---|
[11640] | 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 | |
---|
[11667] | 124 | bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc. |
---|
[11640] | 125 | a->toggleDropStuff(spiced); |
---|
[11664] | 126 | |
---|
[11667] | 127 | a->setVelocity(this->getVelocity()); |
---|
| 128 | |
---|
| 129 | // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea) |
---|
[11664] | 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 | } |
---|
[11640] | 138 | } |
---|
[11610] | 139 | } |
---|
| 140 | |
---|
[11664] | 141 | void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode){ |
---|
| 142 | |
---|
| 143 | SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); |
---|
| 144 | |
---|
[11615] | 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); |
---|
[11640] | 152 | XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode); |
---|
[11610] | 153 | |
---|
| 154 | } |
---|
| 155 | |
---|
[11615] | 156 | |
---|
[11664] | 157 | void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){ |
---|
[11615] | 158 | |
---|
[11610] | 159 | } |
---|
| 160 | |
---|
[11664] | 161 | void SpicedAsteroidField::registerVariables(){ |
---|
[11610] | 162 | |
---|
[11640] | 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); |
---|
[11610] | 171 | |
---|
[11640] | 172 | } |
---|
[11610] | 173 | |
---|
[11640] | 174 | void SpicedAsteroidField::tick(float dt){ |
---|
[11610] | 175 | |
---|
[11640] | 176 | this->create(); |
---|
| 177 | this->bAlive_ = false; |
---|
| 178 | this->destroyLater(); |
---|
[11610] | 179 | } |
---|
| 180 | |
---|
[11640] | 181 | } |
---|