[Orxonox-commit 6930] r11551 - in code/branches/AsteroidMining_HS17: data/levels src/modules/asteroidmining

remartin at orxonox.net remartin at orxonox.net
Tue Nov 7 17:47:15 CET 2017


Author: remartin
Date: 2017-11-07 17:47:14 +0100 (Tue, 07 Nov 2017)
New Revision: 11551

Modified:
   code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
   code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
   code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
Log:
added method 'putStuff' for initialisation. Mesh has correct size (and a randomised shape), but the collision shape stopped getting initialised. Crashes occur somewhere in the death() method. 

Modified: code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
===================================================================
--- code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw	2017-11-07 12:04:27 UTC (rev 11550)
+++ code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw	2017-11-07 16:47:14 UTC (rev 11551)
@@ -89,7 +89,8 @@
 
     <!-----AsteroidMinable --->
 
-    <AsteroidMinable size=100 position="0,-500,0" />
+    <AsteroidMinable size=15 position="0,-500,0" />
+    <AsteroidMinable size=5 position="100,-500,100" />
 
     
 

Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	2017-11-07 12:04:27 UTC (rev 11550)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	2017-11-07 16:47:14 UTC (rev 11551)
@@ -38,7 +38,26 @@
 
 */
 
+/*
+Veraenderungstagebuch
+- Dynamische Definition von Argumenten funktioniert nicht (Immer auf default Values gesetzt)
+---> Was tut registerVariable? Wann werden die Argumente im XML-File angewendet?
+    (Fall Konstruktor -> Methoden: Beim ersten Tick initialisieren?)
+---> Mesh-Teil klappt, Hitbox noch nicht. 
+---> Maximale Hitpunkte = 200?
+---> Meshgroesse passt, aber Hitbox wird iwieso nicht mehr generiert. 
 
+- Neue Asteroiden generieren -> Absturz
+- Pickup spawning -> Absturz
+- Manchmal: Absturz bei Zerstoerung eines Asteroiden
+
+
+
+Erlegt:
+o Rand() geht bis zu riesigen Nummern!
+*/
+
+
 #include "../../orxonox/worldentities/pawns/Pawn.h"
 #include "../../orxonox/worldentities/WorldEntity.h"
 
@@ -69,18 +88,10 @@
 #include "../../orxonox/graphics/Model.h"
 
 
-/*
-Veraenderungstagebuch
-- Dynamische Definition von Argumenten funktioniert nicht
-- Death-Methode -> Absturz
 
 
 
 
-*/
-
-
-
 namespace orxonox
 {
     RegisterClass(AsteroidMinable);
@@ -88,73 +99,66 @@
     AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context)
     {
         RegisterObject(AsteroidMinable);
+
+        // Old stuff from pawn
         this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
         this->setRadarObjectShape(RadarViewable::Shape::Dot);
-
         this->setCollisionType(WorldEntity::CollisionType::Dynamic);
+        this->bAlive_ = true;
+        this->bVulnerable_ = true;
 
+
+
+        // Default Values
         this->generateSmaller = true;
         //this->size = this->getSize(); // Value doesn-t get accepted. Weird. 
-        this->size = 5;
+        this->size = 10;
         this->context = context;
+        this->initialised = false;
+        //this->roll = rand()*5; //etwas Drehung. richtige Variable
 
 
-        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";
+        // DELETE if other stuff works! (wrong size etc.)
+        SphereCollisionShape* cs = new SphereCollisionShape(this->context);
+        cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien 
+        this->attachCollisionShape(cs); 
 
 
-        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);
 
+        // Old from Pawn
+        this->registerVariables();
 
+    }
 
-        //      <Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
-/*
-            Model* slotModel = nullptr;
+    AsteroidMinable::~AsteroidMinable()
+    {
 
-            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();
-        }
-*/
+    void AsteroidMinable::putStuff(){
 
+        // Add Model
+        //<Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
+        Model* hull = new Model(this->context);
+        // random one of the 6 shapes
+        char meshThingy[] = "";
+        sprintf(meshThingy, "ast%.0f.mesh", (round((5*(double)rand()/(double)RAND_MAX))+1));
+        //    sprintf(str, "Value of Pi = %f", M_PI);
+        //char meshThingy[] = "ast5.mesh";
+        hull->setMeshSource(meshThingy);
+        hull->setScale(this->size);
+        this->attach(hull);
+        //hull->setPosition(this->getPosition());
 
+        // Collision shape
+        SphereCollisionShape* cs = new SphereCollisionShape(this->context);
+        cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien 
+        this->attachCollisionShape(cs); 
 
- 
-    }
 
-    AsteroidMinable::~AsteroidMinable()
-    {
 
+        this->initialised=true;
     }
 
     void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -169,7 +173,7 @@
     {
         SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode);
 
-        //XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
+        XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
     }
 
     void AsteroidMinable::registerVariables()
@@ -178,20 +182,24 @@
         registerVariable(this->bVulnerable_,       VariableDirection::ToClient);
         registerVariable(this->health_,            VariableDirection::ToClient);
         registerVariable(this->maxHealth_,         VariableDirection::ToClient);
+
+        registerVariable(this->size, VariableDirection::ToClient);
+        registerVariable(this->generateSmaller, VariableDirection::ToClient);
     }
 
     void AsteroidMinable::tick(float dt)
     {
-        SUPER(Pawn, tick, dt);
-        if(this->health_ <=0){
-            this->death();
-        }
+        // SUPER(Pawn, tick, dt);
+        if(!(this->initialised)){this->putStuff();}
 
+        if(this->health_ <=0){this->death();}
+
     }
 
     void AsteroidMinable::setSize(float s){
         this->size = s;
-        this->health_ = 200*s;
+        this->health_ = 5*s;// capped at 200 in pawn or smth?
+        this->setHealth(health_);
     }
 
     float AsteroidMinable::getSize(){
@@ -201,24 +209,25 @@
     void AsteroidMinable::death() //ueberschreiben
     {
 
-        // pawn -> addExplosionPart
-        // this.goWithStyle()
 
-        // Spawn Pickup
-        HealthPickup* hP = new HealthPickup(context);
+
+
+        //Spawn Pickup
+        HealthPickup* hP = new HealthPickup(this->context);
         //OFFEN: Add custom pickup 'resources' 
-        PickupSpawner* thingy = new PickupSpawner(context);
+        PickupSpawner* thingy = new PickupSpawner(this->context);
         thingy->setPosition(this->getPosition());
-        thingy->createDroppedPickup(context, hP, nullptr, 10);
+        thingy->createDroppedPickup(this->context, hP, nullptr, 10);
 
 //    /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance)
    
 
-
+        // Smaller Parts
         if(this->generateSmaller){
             this->spawnChildren();
         }
 
+
         // OFFEN: Sauber kapputten
         // just copied other stuff:
         this->setHealth(1);
@@ -225,7 +234,10 @@
         this->bAlive_ = false;
         this->destroyLater();
         this->setDestroyWhenPlayerLeft(false);
+        // pawn -> addExplosionPart
+        // this->goWithStyle();
 
+
         // if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
         // {
         //     // Set bAlive_ to false and wait for destroyLater() to do the destruction
@@ -239,9 +251,10 @@
 
 
 void AsteroidMinable::spawnChildren(){
-    // Spawn smaller Children
+    
+    // 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
+    int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one
     massRem = massRem-num;
     int extra = 0;
     for(int fisch=num; fisch>=1; fisch++){
@@ -249,18 +262,32 @@
         if(fisch==1){ 
             extra = massRem;
         }else{
-            extra = round(massRem*rand());
+            extra = round(massRem*(double)rand() / (double)RAND_MAX);
             massRem = massRem-extra;
         }
-        //Spawn this child
-        AsteroidMinable* child = new AsteroidMinable(context);
+
+
+
+        //Spawn this child  Game crashes!
+        AsteroidMinable* child = new AsteroidMinable(this->context);
         child->setSize(extra + 1);
             
         //OFFEN:Kollision der Kinder verhindern
         //Relativ zu Elternteil automatisch?
         //Typ position:rand()*Vektoriwas?
-        // pawn->getWorldPosition() + Vector3(30,0,-30);
+        //pawn->getWorldPosition() + Vector3(30,0,-30);
         child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
+
+
+                //         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());
+
+
     }
 }
 

Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h	2017-11-07 12:04:27 UTC (rev 11550)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h	2017-11-07 16:47:14 UTC (rev 11551)
@@ -61,19 +61,23 @@
 
         protected:
             // Da neue Argumente reinstellen
-            float asteroidVersion; // Bodenstrich-Konvention?, 
+            //float asteroidVersion; // Bodenstrich-Konvention?, 
             // Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form
             float size;
             bool generateSmaller;
-            virtual void death();
+            bool initialised;
 
+            Context* context;
 
+            virtual void death(); 
+            virtual void putStuff();
 
+
+
         private:
             void registerVariables();
             virtual void spawnChildren();
 
-            Context* context;
 
 
     }; // tolua_export



More information about the Orxonox-commit mailing list