* 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 * */ /* * * * An asteroid which can be destroyed. Some smaller asteroids are created and a pickup * spawns. * * * */ #include "../../orxonox/worldentities/pawns/Pawn.h" #include "../../orxonox/worldentities/WorldEntity.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 "infos/PlayerInfo.h" // #include "controllers/Controller.h" // #include "gametypes/Gametype.h" // #include "graphics/ParticleSpawner.h" // #include "worldentities/ExplosionChunk.h" // #include "worldentities/ExplosionPart.h" // #include "core/object/ObjectListIterator.h" // #include "controllers/FormationController.h" #include "../pickup/items/HealthPickup.h" #include "../pickup/PickupSpawner.h" #include "../pickup/Pickup.h" #include "../objects/collisionshapes/SphereCollisionShape.h" #include "../../orxonox/graphics/Model.h" /*Veraenderungstagebuch - Dynamische Definition von Argumenten funktioniert nicht - Death-Methode -> Absturz */ namespace orxonox { RegisterClass(AsteroidMinable); AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context) { RegisterObject(AsteroidMinable); this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f)); this->setRadarObjectShape(RadarViewable::Shape::Dot); this->setCollisionType(WorldEntity::CollisionType::Dynamic); this->generateSmaller = true; //this->size = this->getSize(); // Value doesn-t get accepted. Weird. this->size = 5; this->context = context; Model* hull = new Model(this->context); // random one of the 6 shapes //char meshThingy[] = ""; //sprintf(meshThingy, "ast%f.mesh", round(rand()*5)+1); // sprintf(str, "Value of Pi = %f", M_PI); char meshThingy[] = "ast5.mesh"; hull->setMeshSource(meshThingy); hull->setScale(size); this->attach(hull); //hull->setPosition(this->getPosition()); SphereCollisionShape* cs = new SphereCollisionShape(this->context); cs->setRadius(size*2); //OFFEN: Feinabstimmung der Radien this->attachCollisionShape(cs); // /* Model* slotModel = nullptr; for (int i = 0; i < numWeaponSlots; ++i) { slotPosition = weaponSlots.at(i)->getPosition(); slotOrientation = weaponSlots.at(i)->getOrientation(); slotModel = new Model(this->getContext()); slotModel->setMeshSource("Coordinates.mesh"); slotModel->setScale(3.0f); slotModel->setOrientation(slotOrientation); slotModel->setPosition(slotPosition); this->attach(slotModel); debugWeaponSlotModels_.push_back(slotModel); } } else { // delete all debug models for(Model* model : debugWeaponSlotModels_) { model->destroy(); } debugWeaponSlotModels_.clear(); } */ } AsteroidMinable::~AsteroidMinable() { } void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(AsteroidMinable, XMLPort, xmlelement, mode); // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode); } void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode); //XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); } void AsteroidMinable::registerVariables() { registerVariable(this->bAlive_, VariableDirection::ToClient); registerVariable(this->bVulnerable_, VariableDirection::ToClient); registerVariable(this->health_, VariableDirection::ToClient); registerVariable(this->maxHealth_, VariableDirection::ToClient); } void AsteroidMinable::tick(float dt) { SUPER(Pawn, tick, dt); if(this->health_ <=0){ this->death(); } } void AsteroidMinable::setSize(float s){ this->size = s; this->health_ = 200*s; } float AsteroidMinable::getSize(){ return this->size; } void AsteroidMinable::death() //ueberschreiben { // pawn -> addExplosionPart // this.goWithStyle() // Spawn Pickup HealthPickup* hP = new HealthPickup(context); //OFFEN: Add custom pickup 'resources' PickupSpawner* thingy = new PickupSpawner(context); thingy->setPosition(this->getPosition()); thingy->createDroppedPickup(context, hP, nullptr, 10); // /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance) if(this->generateSmaller){ this->spawnChildren(); } // OFFEN: Sauber kapputten // just copied other stuff: this->setHealth(1); this->bAlive_ = false; this->destroyLater(); this->setDestroyWhenPlayerLeft(false); // if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_)) // { // // Set bAlive_ to false and wait for destroyLater() to do the destruction // this->bAlive_ = false; // this->destroyLater(); // this->setDestroyWhenPlayerLeft(false); // } } void AsteroidMinable::spawnChildren(){ // Spawn smaller Children int massRem = this->size-1; //some mass is lost int num = round((massRem-1)*rand())+1; // random number of children, at least one massRem = massRem-num; int extra = 0; for(int fisch=num; fisch>=1; fisch++){ // to distribute remaining mass if(fisch==1){ extra = massRem; }else{ extra = round(massRem*rand()); massRem = massRem-extra; } //Spawn this child AsteroidMinable* child = new AsteroidMinable(context); child->setSize(extra + 1); //OFFEN:Kollision der Kinder verhindern //Relativ zu Elternteil automatisch? //Typ position:rand()*Vektoriwas? // pawn->getWorldPosition() + Vector3(30,0,-30); child->setPosition(this->getPosition() + Vector3(num*5, 0, 0)); } } } /* void DronePickup::changedUsed(void) { SUPER(DronePickup, changedUsed); // If the pickup has transited to used. if(this->isUsed()) { Pawn* pawn = this->carrierToPawnHelper(); if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. this->Pickupable::destroy(); //Attach to pawn Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something) drone->addTemplate(this->getDroneTemplate()); Controller* controller = drone->getController(); DroneController* droneController = orxonox_cast(controller); if(droneController != nullptr) { droneController->setOwner(pawn); } Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30); drone->setPosition(spawnPosition); // The pickup has been used up. this->setUsed(false); } else { // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused. if(this->isOnce() || (this->isContinuous() )) { this->Pickupable::destroy(); } } }