[Orxonox-commit 6940] r11561 - in code/branches/AsteroidMining_HS17: data/levels src/modules/asteroidmining src/modules/pickup

remartin at orxonox.net remartin at orxonox.net
Mon Nov 13 16:34:53 CET 2017


Author: remartin
Date: 2017-11-13 16:34:53 +0100 (Mon, 13 Nov 2017)
New Revision: 11561

Modified:
   code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
   code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
   code/branches/AsteroidMining_HS17/src/modules/pickup/Pickup.h
   code/branches/AsteroidMining_HS17/src/modules/pickup/PickupSpawner.h
Log:
Pickup generating works now after changing privacy settings of set methods in PickupSpawner.h. Added lots of debugging messages, spawnChildren does lead to a crash, still.

Modified: code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
===================================================================
--- code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw	2017-11-13 15:20:31 UTC (rev 11560)
+++ code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw	2017-11-13 15:34:53 UTC (rev 11561)
@@ -2,7 +2,7 @@
  name = "AsteroidFarming"
  description = "Testing the Asteroid Mining Project, PPS HS 17"
  tags = "test"
- screenshot = "mytestlevel.png"
+ screenshot = "AsteroidFarming.png"
 />
 
 <?lua
@@ -23,11 +23,16 @@
   </templates>
   <?lua include("includes/notifications.oxi") ?>
 
+
   <Scene
     ambientlight = "0.8, 0.8, 0.8"
     skybox       = "Orxonox/Starbox"
   >
 
+  <?lua
+      include("includes/pickups.oxi")
+  ?>
+
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
     <SpawnPoint team=0 position="0,0,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
     

Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	2017-11-13 15:20:31 UTC (rev 11560)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	2017-11-13 15:34:53 UTC (rev 11561)
@@ -40,32 +40,37 @@
 
 /*
 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
+KNACKPUNKTE:
+o Collision Shape-Problem (Funktioniert nur, wenn im Konstruktor)
+o Maximale Hitpunkte = 200?
 
-o hat's mit den Context-Eingenschaften zu tun? Je einen Neuen/Aktuellen besorgen? 
+o Neue Asteroiden generieren -> Absturz
+---> Weil Elterndings zerstoert wird? 
+---> Nicht moeglich, zur Laufzeit zu generieren?
 
-Nicht Pointer uebergeben?
-- Manchmal: Absturz bei Zerstoerung eines Asteroiden
-- Was tut 'Register Variables'?
+o Pickups: setMaxSpawned funktioniert nicht
 
-o Error messages: change context::pickups to something else
 
-
 OFFEN: 
-o Add custom pickup 'resources' 
+o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources. 
+o Explosion parts
+o custom HUD
 
+HANDBUCH:
+o im Level-File includes/pickups.oxi importieren. 
 
+Anpassungen Pickup-Zeug: 
+o Pickup.h: Zugriffsänderung createSpawner
+o PickupSpawner.h: Zugriffsrechte setPickupTemplateName() und setMaxSpawnedItems()
 
-Erlegt:
-o Rand() geht bis zu riesigen Nummern!
+ERLEGT:
+o Rand() geht bis zu riesigen Nummern! 
+o Pickupgenerierung: vgl. Anpassungen. 
+o Dummes fisch-- statt fisch++ , Endlosschleife! 
+o Dynamische Definition -> putStuff-Methode, Werte noch nicht durchgesickert. 
+o Error-Nachricht: Einfach Argumente leer lassen. 
 */
 
 
@@ -119,12 +124,9 @@
         this->bAlive_ = true;
         this->bVulnerable_ = true;
 
-
-
         // Default Values
         this->generateSmaller = true;
-        //this->size = this->getSize(); // Value doesn-t get accepted. Weird. 
-        this->size = 10;
+        this->size = 10; // customSize
         this->context = context;
         this->initialised = false;
         //this->roll = rand()*5; //etwas Drehung. richtige Variable
@@ -132,11 +134,6 @@
 
 
 
-
-
-
-
-
         // DELETE if other stuff works! (wrong size etc.)
         SphereCollisionShape* cs = new SphereCollisionShape(this->context);
         cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien 
@@ -145,8 +142,6 @@
 
 
 
-
-
         // Old from Pawn
         this->registerVariables();
 
@@ -164,13 +159,10 @@
         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";
+        sprintf(meshThingy, "ast%.0f.mesh", (round((5*(double)rand()/(double)RAND_MAX))+1)); //    sprintf(str, "Value of Pi = %f", M_PI);
         hull->setMeshSource(meshThingy);
         hull->setScale(this->size);
         this->attach(hull);
-        //hull->setPosition(this->getPosition());
 
         // Collision shape
         SphereCollisionShape* cs = new SphereCollisionShape(this->context);
@@ -239,50 +231,39 @@
     void AsteroidMinable::death() //ueberschreiben
     {
 
+        // Stuff that can be harvested. 
+        PickupSpawner* thingy = new PickupSpawner(this->context);
 
-        //Spawn Pickup // Create at start already? ( Hidden in CollisionShape)
-        HealthPickup* hP = new HealthPickup(this->context);
-        if(hP == nullptr){
-            orxout(internal_error, context::pickups) << "Weird, can't create new HealthPickup." << endl;
+        // OFFEN: more precise size relation in custom resource pickup. 
+        char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
+        if(this->size <= 5){
+            strcat(tname, "smallmunitionpickup");
+        }else if(this->size <= 20){
+            strcat(tname, "mediummunitionpickup");
+        }else{
+            strcat(tname, "hugemunitionpickup");
         }
-        // hP->setPosition(this->getPosition()); // Does not have a member named 'setPosition' (Inherits from Pickup//BAse Object)
+        //orxout() << "Zeugsname:" << tname << endl;
+        thingy->setPickupTemplateName(tname);
+        thingy->setPosition(this->getPosition());
+        //thingy->setMaxSpawnedItems(1); // Somehow doesn-t work yet. 
+        thingy->setRespawnTime(0.1f);// instantly
+        
+        orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
 
-        // invoke spawnPickup on the pikcup itself? (returns bool, creates the hideous thing)
-        // HealthPickup inherits from Pickup. 
-        // createSpawner is protected ->can be used as well in inheriting classes, but not here!
-        // bool unnecessary = hP->createSpawner();
-        // hP->setPosition(this->getPosition());
-        //OFFEN: Add custom pickup 'resources' 
 
-        // createPickup is private, hP is of type Pickup!
-        // CreateDroppedPickup returns a PickupSpawner! 
-        // PickupSpawner don't have public set methods, just that ugly 'factory method' which returns another PickupSpawner
-        // PickupSpawner* thingy = new PickupSpawner(this->context); 
-        // What is Pickupable? says: Interface, no way to set type. Why do I even need the spawner? Trigger Distance?
-        
 
-        // Plan: Solve the Pickupable mystery, try to adapt the spawner somehow. Ask to modify it if that fails. (Change method types)
 
 
-        // PickupSpawner* thingy = (new PickupSpawner(this->context))->createDroppedPickup(this->context, hP, nullptr, 10);
-//    /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance)
+        // Smaller Parts = 'Children'
+        if(this->generateSmaller){
+            this->spawnChildren();
+        }
 
 
 
-        // if(thingy == nullptr){
-        //     orxout(internal_error, context::pickups) << "Weird, can't create new PickupSpawner." << endl;
-        // }
-        // thingy->setPosition(this->getPosition());
-        // thingy->setMaxSpawnedItems(1);//Default is 1 already, private anyways
-        
-   
 
-        // // Smaller Parts
-        // if(this->generateSmaller){
-        //     this->spawnChildren();
-        // }
 
-
         // OFFEN: Sauber kapputten
         // just copied other stuff:
         this->setHealth(1);
@@ -289,10 +270,12 @@
         this->bAlive_ = false;
         this->destroyLater();
         this->setDestroyWhenPlayerLeft(false);
+
+
         // pawn -> addExplosionPart
         // this->goWithStyle();
+        orxout() << "Wieder retour in death() geschafft. " << endl;
 
-
         // if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
         // {
         //     // Set bAlive_ to false and wait for destroyLater() to do the destruction
@@ -309,10 +292,17 @@
     
     // Spawn smaller Children 
     int massRem = this->size-1; //some mass is lost
-    int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one
-    massRem = massRem-num;
+    int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one // Tweak towards bigger junks?
+    num = 1; // zum Testen mal nur einen generieren. 
+    
+    massRem = massRem-num;    
     int extra = 0;
-    for(int fisch=num; fisch>=1; fisch++){
+
+
+    orxout() << "Number of Children: " << num << endl;
+
+
+    for(int fisch=num; fisch>=1; fisch--){
         // to distribute remaining mass
         if(fisch==1){ 
             extra = massRem;
@@ -319,16 +309,19 @@
         }else{
             extra = round(massRem*(double)rand() / (double)RAND_MAX);
             massRem = massRem-extra;
+
         }
 
+        orxout() << "Mass chosen: " << extra+1 << endl;
 
+        orxout() << "AsteroidMining::spawnChildren(): Inside for-loop." << endl;
 
         //Spawn this child  Game crashes!
         AsteroidMinable* child = new AsteroidMinable(this->context);
         // if(!(child == nullptr)){//Errorgebastel
 
+        // Position zu spaet gesetzt? Tick nicht atomar -> falsche Groesse evtl?
 
-
             if(child == nullptr){
                 orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
             }
@@ -341,6 +334,9 @@
             //pawn->getWorldPosition() + Vector3(30,0,-30);
             child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
 
+
+        orxout() << "Done: Creating new Asteroid" << endl;
+
         // }
 
 
@@ -354,6 +350,7 @@
 
 
     }
+    orxout() << "Leaving spawnChildren() method. " << endl;
 }
 
 

Modified: code/branches/AsteroidMining_HS17/src/modules/pickup/Pickup.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/pickup/Pickup.h	2017-11-13 15:20:31 UTC (rev 11560)
+++ code/branches/AsteroidMining_HS17/src/modules/pickup/Pickup.h	2017-11-13 15:34:53 UTC (rev 11561)
@@ -144,9 +144,12 @@
 
             virtual void changedPickedUp(void) override; //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
 
-        protected:
+
             virtual bool createSpawner(void) override; //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
 
+
+        protected:
+
             /**
             @brief Sets the representation name which refers to the name of the PickupRepresentation that is used to represent this pickup.
             */

Modified: code/branches/AsteroidMining_HS17/src/modules/pickup/PickupSpawner.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/pickup/PickupSpawner.h	2017-11-13 15:20:31 UTC (rev 11560)
+++ code/branches/AsteroidMining_HS17/src/modules/pickup/PickupSpawner.h	2017-11-13 15:34:53 UTC (rev 11561)
@@ -113,6 +113,14 @@
             inline Template* getPickupTemplate() const
                 {return this->pickupTemplate_; }
 
+
+            void setPickupTemplateName(const std::string& name);
+            void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items.
+
+            inline void setRespawnTime(float time)
+                { this->respawnTime_ = time; }
+
+
         private:
             void initialize(void);
 
@@ -140,12 +148,9 @@
             @brief Set the time to respawn.
             @param time New time after which this gets re-actived.
             */
-            inline void setRespawnTime(float time)
-                { this->respawnTime_ = time; }
 
-            void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items.
 
-            void setPickupTemplateName(const std::string& name);
+
             void setPickupTemplate(Template* temp);
 
             Pickupable* createPickup(void); //!< Creates a new Pickupable.



More information about the Orxonox-commit mailing list