[Orxonox-commit 6926] r11547 - in code/branches/AsteroidMining_HS17/src/modules: . asteroidmining

remartin at orxonox.net remartin at orxonox.net
Mon Nov 6 17:06:16 CET 2017


Author: remartin
Date: 2017-11-06 17:06:16 +0100 (Mon, 06 Nov 2017)
New Revision: 11547

Added:
   code/branches/AsteroidMining_HS17/src/modules/asteroidmining/
   code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
   code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
   code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt
Log:


Added: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	                        (rev 0)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	2017-11-06 16:06:16 UTC (rev 11547)
@@ -0,0 +1,312 @@
+
+ *   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 <algorithm>
+
+#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 position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
+/*
+            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<DroneController*>(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();
+            }
+        }
+    }

Added: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h	                        (rev 0)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h	2017-11-06 16:06:16 UTC (rev 11547)
@@ -0,0 +1,82 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+#ifndef _AsteroidMinable_H__
+#define _AsteroidMinable_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <string>
+#include <vector>
+#include "interfaces/PickupCarrier.h"
+#include "interfaces/RadarViewable.h"
+#include "worldentities/ControllableEntity.h"
+#include "worldentities/ExplosionPart.h"
+
+#include "../../orxonox/worldentities/pawns/Pawn.h"
+
+namespace orxonox // tolua_export
+{
+
+
+    // tolua_export
+    class _OrxonoxExport AsteroidMinable : public Pawn
+    { // tolua_export
+
+        public:
+            AsteroidMinable(Context* context);
+            virtual ~AsteroidMinable();
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
+            virtual void tick(float dt) override;
+
+            virtual void setSize(float f);
+            virtual float getSize();
+
+
+        protected:
+            // Da neue Argumente reinstellen
+            float asteroidVersion; // Bodenstrich-Konvention?, 
+            // Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form
+            float size;
+            bool generateSmaller;
+            virtual void death();
+
+
+
+        private:
+            void registerVariables();
+            virtual void spawnChildren();
+
+            Context* context;
+
+
+    }; // tolua_export
+} // tolua_export
+
+#endif /* _AsteroidMinable_H__ */

Added: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt	                        (rev 0)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt	2017-11-06 16:06:16 UTC (rev 11547)
@@ -0,0 +1,17 @@
+SET_SOURCE_FILES(PICKUP_SRC_FILES
+  AsteroidMinable.cc
+)
+
+ORXONOX_ADD_LIBRARY(asteroidmining
+  MODULE
+  FIND_HEADER_FILES
+  TOLUA_FILES
+
+  PCH_FILE
+
+  LINK_LIBRARIES
+    overlays
+    orxonox
+    pickup
+  SOURCE_FILES ${PICKUP_SRC_FILES}
+)



More information about the Orxonox-commit mailing list