/* ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * Simon Miescher * */ /** @file @author remartin @brief Asteroid field with lots of parameters. Derived from asteroidField.lua Generates a bunch of asteroids that may contain some stuff. It is required to wait until all XML-arguments are set. That's why the actual generation happens when tick() gets called for the first time. */ #include "../../orxonox/worldentities/pawns/Pawn.h" #include "../../orxonox/worldentities/WorldEntity.h" #include "SpicedAsteroidField.h" #include "AsteroidMinable.h" #include #include "core/CoreIncludes.h" #include "core/GameMode.h" #include "core/XMLPort.h" #include "core/EventIncludes.h" #include "network/NetworkFunction.h" #include "util/Math.h" #include "../../orxonox/graphics/Billboard.h" namespace orxonox{ RegisterClass(SpicedAsteroidField); SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) { RegisterObject(SpicedAsteroidField); this->context = context; // Default Values: this->count = 30; this->mDensity = 0.5; this->position = Vector3(0,0,0); this->maxSize = 40; this->minSize = 1; this->radius = 1000; this->foggy = true; this->fogDensity = 0.5; this->registerVariables(); } SpicedAsteroidField::SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD): Pawn(c){ this->context = c; this->position = p; this->minSize = minS; this->maxSize = maxS; this->radius = w; this->count = count; this->foggy = f; this->mDensity = mD; this->fogDensity = fD; } SpicedAsteroidField::~SpicedAsteroidField(){ } void SpicedAsteroidField::create(){ int size; int pX; int pY; int pZ; Vector3* relPos; for(int gertrud = 0; gertrudcontext); size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize; a->setSize(size); pX = round(rnd()*2*this->radius) - radius; pY = round(rnd()*2*this->radius) - radius; pZ = round(rnd()*2*this->radius) - radius; relPos = new Vector3(pX, pY, pZ); a->setPosition(this->position + *relPos); bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc. a->toggleDropStuff(spiced); a->setVelocity(this->getVelocity()); // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea) Billboard* bb; if(this->foggy && mod(gertrud, 5) == 0){ bb = new Billboard(this->context); bb->setPosition(this->position + *relPos); bb->setMaterial("Smoke/Smoke"); bb->setScale(size); bb->setColour(ColourValue(this->fogDensity, this->fogDensity, this->fogDensity)); } } } void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode){ SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode); } void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){ } void SpicedAsteroidField::registerVariables(){ registerVariable(this->count, VariableDirection::ToClient); registerVariable(this->mDensity, VariableDirection::ToClient); registerVariable(this->position, VariableDirection::ToClient); registerVariable(this->maxSize, VariableDirection::ToClient); registerVariable(this->minSize, VariableDirection::ToClient); registerVariable(this->radius, VariableDirection::ToClient); registerVariable(this->foggy, VariableDirection::ToClient); registerVariable(this->fogDensity, VariableDirection::ToClient); } void SpicedAsteroidField::tick(float dt){ this->create(); this->bAlive_ = false; this->destroyLater(); } }