[Orxonox-commit 6988] r11609 - in code/branches/AsteroidMining_HS17/src: modules/asteroidmining modules/pickup orxonox/worldentities/pawns

remartin at orxonox.net remartin at orxonox.net
Mon Nov 27 18:53:05 CET 2017


Author: remartin
Date: 2017-11-27 18:53:05 +0100 (Mon, 27 Nov 2017)
New Revision: 11609

Modified:
   code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
   code/branches/AsteroidMining_HS17/src/modules/pickup/PickupSpawner.cc
   code/branches/AsteroidMining_HS17/src/orxonox/worldentities/pawns/Pawn.cc
   code/branches/AsteroidMining_HS17/src/orxonox/worldentities/pawns/Pawn.h
Log:
Solved pickup problem with tiny adaptation in Pawn.h and PickupSpawner.cc. Started work on SpicedAsteroidField. 

Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	2017-11-27 16:00:59 UTC (rev 11608)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	2017-11-27 17:53:05 UTC (rev 11609)
@@ -43,32 +43,39 @@
 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 KNACKPUNKTE:
-o Der neu erscheinende Asteroid versucht, das Pickup aufzusammeln. 
---> Mathematisch genuegend Abstand?
---> Kollisions-Ausnahme richtig, mit Hit-Methode oder so, auch bei Pickup anpassen?
---> Den Fall im eigenen Pickup behandeln? 
---> Nur ein Pickup generieren, wenn die Groesse sowieso eins ist? -> Loest Kollisionsproblem nicht. 
 
-
 OFFEN: 
 o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources. 
+--> PickupTemplateName_ in PickupSpawner ist ein string. Wird via getBaseClassIdentifier ausgelesen, daraus wird ein Pickupable fabriziert. 
+--> MunitionPickup erbt von Pickup erbt von collectiblePickup erbt von Pickupable
+----> im MineralsPickup die isPickedUp()-Methode überschreiben? 
+--> data_extern/images/effects: PNG's für die Pickups und GUI-Dinger. 
+
 o Explosion parts
 o custom HUD
 o asteroidField.lua anpassen, mit 'Mineraliendichten-Parameter'. 
 
+o Dokumentieren mit @brief?
+
+o replace ugly random stuff with math.rnd()
+o set collisionDamage? Just for static entities?
+
 HANDBUCH:
 o im Level-File includes/pickups.oxi importieren. 
 o Bei der XML-Variante wird beim ersten Aufruf der Tick-Methode ein neuer Asteroid generiert, 
   damit die Groesse der Collision Shape korrekt initialisiert wird. 
 
-Anpassungen Pickup-Zeug: 
+FREMDANPASSUNGEN: 
+Pickup-Zeug: 
 o Pickup.h: Zugriffsänderung createSpawner
 o PickupSpawner.h: Zugriffsrechte setPickupTemplateName() und setMaxSpawnedItems()
+o PickupSpawner.h: In Tick() zwei Testbedingungen eingefuegt. 
+o Pawn.h: Attribut acceptsPickups_ inklusive get/set. 
 
 ERLEGT:
 o Rand() geht bis zu riesigen Nummern! 
-o Pickupgenerierung: vgl. Anpassungen. 
-o Dummes fisch-- statt fisch++ , Endlosschleife! 
+o Pickupgenerierung: vgl. Fremdanpassungen. 
+o Minimalbegrenzung fuer Masse vergessen. 
 o Dynamische Definition -> putStuff-Methode, Werte noch nicht durchgesickert. 
 o Error-Nachricht: Einfach Argumente leer lassen. 
 o Pickups: setMaxSpawned funktioniert nicht -> Bastelloesung: Auf 2 statt eins setzen, erstes wird wohl direkt zerstoert. 
@@ -78,10 +85,16 @@
 
 o Groessenabhaengige Collison shape: Umweg ueber zweiten Konstruktor. 
 o Absturz beim Asteroidengenerieren: Health war auf 0 gesetzt! Wurde nur bei der xml-Variante definiert. 
+o Asteroiden fressen Pickups: Argument in Pawn, Test darauf in Tick() von PickupSpawner. 
 
 NOTIZEN:
 o SUPER entspricht ueberladen, andere Argumente der Methode. 
+o Warnungsverhinderung anderswo: (void)pickedUp; // To avoid compiler warning.
 
+Was ist das?         friend class Pickupable;
+
+
+
 */
 
 
@@ -163,6 +176,8 @@
         this->size = size; // customSize
         this->health_ = 15*size;// capped at 200 in pawn or smth?
         this->maxHealth_ = this->health_;
+        this->acceptsPickups_ = false;
+
         this->setPosition(position);
         //this->roll = rand()*5; //etwas Drehung. richtige Variable
 
@@ -272,7 +287,7 @@
     void AsteroidMinable::death() //ueberschreiben
     {
 
-        orxout() << "AsteroidMinable::Death() aufgerufen." << endl;
+        // orxout() << "AsteroidMinable::Death() aufgerufen." << endl;
 
         // OFFEN: Sauber kapputten
         // just copied other stuff:
@@ -284,49 +299,31 @@
         // this->goWithStyle();
 
 
-        // // Stuff that can be harvested. 
-        // PickupSpawner* thingy = new PickupSpawner(this->context);
+        // Stuff that can be harvested. 
+        PickupSpawner* thingy = new PickupSpawner(this->context);
+        // 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");
+        }
+        thingy->setPickupTemplateName(tname);
+        thingy->setPosition(this->getPosition());
+        thingy->setMaxSpawnedItems(1); // Would be default anyways
+        thingy->setRespawnTime(0.2f);
 
-        // // 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");
-        // }
-        // thingy->setPickupTemplateName(tname);
-        // thingy->setPosition(this->getPosition());
-        // thingy->setMaxSpawnedItems(2); // The first somehow gets destroyed immediately. 
-        // thingy->setRespawnTime(0.5f);
-
         // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
 
-
         // Smaller Parts = 'Children'
         if(this->generateSmaller){
             this->spawnChildren();
         }
 
+        // orxout() << "Wieder retour in death() geschafft. " << endl;
 
-
-
-
-
-
-
-        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
-        //     this->bAlive_ = false;
-        //     this->destroyLater();
-
-        //     this->setDestroyWhenPlayerLeft(false);
-
-        // }
     }
 
 
@@ -334,17 +331,36 @@
     
     if (this->size <=1){return;} // Absicherung trivialer Fall
 
-
-
     // 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 // Tweak towards bigger junks?
+    if(num > 10){num = 10;} // no max function in C!
+
     // num = 1; // zum Testen mal nur einen generieren. 
-    
+
+    // // TODO: Check this draft for edge cases etc. 
+    // // 'Triangular', discrete probability density with max at massRem/num 
+    // // Max at a, value 1, subintervals a+b = c
+    // int c = massRem-num;
+    // float probDensity = [c]
+    // int a = round(massRem/num);
+    // int b = c-a;
+    // for(int z = 0; z<=a; z++){probDensity[z] = m*z/a; } // rising part
+    // for(z = a+1; z<c; z++){probDensity[z] = m - m*(z-a)/b;} // falling part
+
+    // double rand = (double)rand() / (double)RAND_MAX; // between 0 and 1
+    // double probSum = 0;
+    // int result = 0;
+    // while(rand>probSum){
+    //     probSum = probSum+probDensity[result];
+    //     result++:
+    // }
+
+
     massRem = massRem-num;    
+
     int extra = 0;
 
-
     //orxout() << "Number of Children: " << num << endl;
 
 
@@ -403,7 +419,7 @@
 
 
     }
-    orxout() << "Leaving spawnChildren() method. " << endl;
+    // orxout() << "Leaving spawnChildren() method. " << endl;
 }
 
 
@@ -428,12 +444,12 @@
 
     void AsteroidMinable::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
 
-        orxout() << "AsteroidMining::Hit(Variante 2) Dings aufgerufen. " << endl;
+        //orxout() << "AsteroidMining::Hit(Variante 2) Dings aufgerufen. " << endl;
         // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun. 
         // Wird staending aufgerufen -> Rechenleistung?
         if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
 
-        orxout() << "Schaden. HP: " << this->health_ << " Dmg: " << damage << " hDmg: " << healthdamage << " sDmg: " << shielddamage << endl;
+        //orxout() << "Schaden. HP: " << this->health_ << " Dmg: " << damage << " hDmg: " << healthdamage << " sDmg: " << shielddamage << endl;
 
         this->damage(damage, healthdamage, shielddamage, originator, cs);
 
@@ -452,13 +468,8 @@
 
 
 
-            // Cast-Test aus movableEntity():
-            // Pawn* victim = orxonox_cast<Pawn*>(otherObject);
-            // if (victim)
 
 
-
-
 //Pawn:
     // void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
     // {

Modified: code/branches/AsteroidMining_HS17/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/pickup/PickupSpawner.cc	2017-11-27 16:00:59 UTC (rev 11608)
+++ code/branches/AsteroidMining_HS17/src/modules/pickup/PickupSpawner.cc	2017-11-27 17:53:05 UTC (rev 11609)
@@ -157,9 +157,12 @@
             // Iterate trough all Pawns.
             for(Pawn* pawn : ObjectList<Pawn>())
             {
-                if(spawner == nullptr) // Stop if the PickupSpawner has been deleted (e.g. because it has run out of pickups to distribute).
+                // Stop if the PickupSpawner has been deleted (e.g. because it has run out of pickups to distribute). 2nd condition prevents a possible error in isTarget(...) below. 
+                if(spawner == nullptr || this->pickup_ == nullptr) 
                     break;
 
+                if(!(pawn->doesAcceptPickups())){continue;} // skip those pawns, e.g. AsteroidMinables. 
+
                 Vector3 distance = pawn->getWorldPosition() - this->getWorldPosition();
                 PickupCarrier* carrier = static_cast<PickupCarrier*>(pawn);
                 // If a PickupCarrier, that fits the target-range of the Pickupable spawned by this PickupSpawner, is in trigger-distance and the carrier is not blocked.

Modified: code/branches/AsteroidMining_HS17/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/orxonox/worldentities/pawns/Pawn.cc	2017-11-27 16:00:59 UTC (rev 11608)
+++ code/branches/AsteroidMining_HS17/src/orxonox/worldentities/pawns/Pawn.cc	2017-11-27 17:53:05 UTC (rev 11609)
@@ -83,6 +83,7 @@
 
         // set damage multiplier to default value 1, meaning nominal damage
         this->damageMultiplier_ = 1;
+        this->acceptsPickups_ = true;
 
         this->spawnparticleduration_ = 3.0f;
 

Modified: code/branches/AsteroidMining_HS17/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/orxonox/worldentities/pawns/Pawn.h	2017-11-27 16:00:59 UTC (rev 11608)
+++ code/branches/AsteroidMining_HS17/src/orxonox/worldentities/pawns/Pawn.h	2017-11-27 17:53:05 UTC (rev 11609)
@@ -198,6 +198,11 @@
             inline float getDamageMultiplier() const
                 { return this->damageMultiplier_; }
 
+            // Some pawns can-t harvest pickups (e.g. AsteroidMinables). Checked in PickupSpawner. 
+            inline void setPickupAcceptance(bool b)
+                { this->acceptsPickups_ = b; }
+            inline bool doesAcceptPickups()
+                { return this->acceptsPickups_;}
 
             virtual void startLocalHumanControl() override;
 
@@ -217,8 +222,10 @@
             inline const WeaponSystem* getWeaponSystem() const
                 { return this->weaponSystem_; }
 
-            static void consoleCommand_debugDrawWeapons(bool bDraw);
+            static void consoleCommand_debugDrawWeapons(bool bDraw); 
 
+
+
         protected:
             virtual void preDestroy() override;
 
@@ -255,6 +262,7 @@
             float shieldRechargeWaitCountdown_;
 
             float damageMultiplier_; ///< Used by the Damage Boost Pickup.
+            bool acceptsPickups_; // Added for the asteroidMinable class, avoid that they attempt to grab the resources
 
             WeakPtr<Pawn> lastHitOriginator_;
 



More information about the Orxonox-commit mailing list