[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 | |
---|
[11664] | 31 | @file SpicedAsteroidField.cc |
---|
| 32 | @brief Asteroid field with lots of parameters. Derived from asteroidField.lua |
---|
[11610] | 33 | |
---|
[11640] | 34 | |
---|
[11610] | 35 | */ |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | #include "../../orxonox/worldentities/pawns/Pawn.h" |
---|
| 39 | #include "../../orxonox/worldentities/WorldEntity.h" |
---|
| 40 | |
---|
| 41 | #include "SpicedAsteroidField.h" |
---|
[11615] | 42 | #include "AsteroidMinable.h" |
---|
[11610] | 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" |
---|
[11615] | 51 | #include "util/Math.h" |
---|
[11610] | 52 | |
---|
[11664] | 53 | #include "../../orxonox/graphics/Billboard.h" |
---|
[11610] | 54 | |
---|
| 55 | |
---|
[11664] | 56 | namespace orxonox{ |
---|
[11615] | 57 | |
---|
[11610] | 58 | RegisterClass(SpicedAsteroidField); |
---|
| 59 | |
---|
[11640] | 60 | SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) { |
---|
[11610] | 61 | |
---|
| 62 | RegisterObject(SpicedAsteroidField); |
---|
[11664] | 63 | this->context = context; |
---|
[11610] | 64 | |
---|
[11664] | 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; |
---|
[11640] | 72 | this->foggy = true; |
---|
| 73 | this->fogDensity = 0.5; |
---|
[11610] | 74 | |
---|
| 75 | this->registerVariables(); |
---|
[11664] | 76 | } |
---|
[11610] | 77 | |
---|
[11664] | 78 | SpicedAsteroidField::SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD): Pawn(c){ |
---|
[11610] | 79 | |
---|
[11664] | 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 | |
---|
[11610] | 91 | } |
---|
| 92 | |
---|
[11664] | 93 | |
---|
[11610] | 94 | SpicedAsteroidField::~SpicedAsteroidField(){ |
---|
| 95 | |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void SpicedAsteroidField::create(){ |
---|
| 99 | |
---|
[11640] | 100 | int size; |
---|
| 101 | int pX; |
---|
| 102 | int pY; |
---|
| 103 | int pZ; |
---|
[11610] | 104 | |
---|
[11640] | 105 | Vector3* relPos; |
---|
[11610] | 106 | |
---|
[11664] | 107 | |
---|
[11640] | 108 | for(int gertrud = 0; gertrud<count; ++gertrud){ |
---|
[11610] | 109 | |
---|
[11640] | 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 | |
---|
[11664] | 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 | } |
---|
[11640] | 135 | } |
---|
[11610] | 136 | } |
---|
| 137 | |
---|
[11664] | 138 | void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode){ |
---|
| 139 | |
---|
| 140 | SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); |
---|
| 141 | |
---|
[11615] | 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); |
---|
[11640] | 149 | XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode); |
---|
[11610] | 150 | |
---|
| 151 | } |
---|
| 152 | |
---|
[11615] | 153 | |
---|
[11664] | 154 | void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){ |
---|
[11615] | 155 | |
---|
[11610] | 156 | } |
---|
| 157 | |
---|
[11664] | 158 | void SpicedAsteroidField::registerVariables(){ |
---|
[11610] | 159 | |
---|
[11640] | 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); |
---|
[11610] | 168 | |
---|
[11640] | 169 | } |
---|
[11610] | 170 | |
---|
[11640] | 171 | void SpicedAsteroidField::tick(float dt){ |
---|
[11610] | 172 | |
---|
[11640] | 173 | this->create(); |
---|
| 174 | this->bAlive_ = false; |
---|
| 175 | this->destroyLater(); |
---|
[11610] | 176 | } |
---|
| 177 | |
---|
[11640] | 178 | } |
---|