Index: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	(revision 11614)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc	(revision 11615)
@@ -43,5 +43,8 @@
 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
-KNACKPUNKTE:
+KNACKPUNKTE: 
+
+o Floating point exception
+o math.pi richtig einbinden. 
 
 OFFEN: 
@@ -87,4 +90,7 @@
 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. 
+o Man kann keine Arrays der Groesse 0 initialisieren, aber auch nicht per IF 2x definieren. 
+o i++ einfach ganz verhindern, ++i stattdessen. 
+
 
 NOTIZEN:
@@ -110,5 +116,7 @@
 #include "core/XMLPort.h"
 #include "core/EventIncludes.h"
-#include "network/NetworkFunction.h"
+#include "network/NetworkFunction.h" 
+#include "util/Math.h"
+
 
 // #include "infos/PlayerInfo.h"
@@ -128,4 +136,5 @@
 #include "../objects/collisionshapes/SphereCollisionShape.h"
 #include "../../orxonox/graphics/Model.h"
+
 
 
@@ -328,74 +337,91 @@
 
 
-void AsteroidMinable::spawnChildren(){
+void AsteroidMinable::spawnChildren(){// Spawn smaller Children 
+
     
     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?
+    int num = round(rnd()*(massRem-1)) + 1; // random number of children, at least one
     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;
-
-
-    for(int fisch=num; fisch>=1; --fisch){
-        // to distribute remaining mass
-
-        //orxout() << "AsteroidMining::spawnChildren(): Fisch-Variable: " << fisch << endl;
-
-        if(fisch==1){ 
-            extra = massRem;
-        }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);
-        int newMass = extra+1; 
-        AsteroidMinable* child = new AsteroidMinable(this->context, newMass, this->getPosition() + Vector3(fisch*newMass*2.5, 0, 0));
-        // if(!(child == nullptr)){//Errorgebastel
-
-        // Position zu spaet gesetzt? Tick nicht atomar -> falsche Groesse evtl?
-
-        // 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));
-        // //child->setPosition(Vector3(0,0,0));
+    int masses[num] = {1}; // Masses of the asteroids, at least one. 
+    massRem = massRem-num; 
+
+    orxout() << "SpawnChildren(): passed basic stuff. num = " << num << endl;
+
+    // Randomnised spawning points for the new asteroids
+    float phi[num] = {0.0}; // assuming that it gets initialised to 0. Add (= {0.0})?
+    float theta[num] = {0.0};
+    float pi = 3.14159;//math.pi;
+
+    float d_p = 2*pi/num;
+    float d_t = pi/num;
+    float p = d_p/2;
+    float t = d_t/2;
+    // float phiOffset = rnd()*2*pi; // Added everywhere to become independent of the coordinate system
+    // float thetaOffset = rnd()*pi;
+    float rScaling = tan(t); // scale radius to prevent asteroids from touching. (distance=AsteroidRadius/tan(sector/2))
+
+    int pos;
+    for(int it = 0; it<num; ++it){
+        orxout() << "SpawnChildren(): Entering For. " << endl;
+
+        pos = mod((int)(rnd()*num),num); 
+        orxout() << "SpawnChildren(): Trying position: " << pos << endl;
+
+        while(phi[pos] != 0.0){// find empty spot in array
+            pos = (int)mod(++pos, num);
+            orxout() << "SpawnChildren(): Inside, testing position: " << pos << endl;
+        }
+        phi[pos] = p + it*d_p;// set angle there
+
+        pos = mod((int)(rnd()*num),num);
+        while(theta[pos] != 0.0){
+            pos = (int)mod(++pos, num);
+        }
+        theta[pos] = t + it*d_t;
+    }
+
+    orxout() << "SpawnChildren(): passed angle stuff. " << endl;
+
+    // 'Triangular', discrete probability density with max at the expected value massRem/num at a. a+b = c
+    if(massRem>0){ // Required to avoid array of size 0 or access problems
+        int c = massRem;
+        float probDensity[c] = {0.0};
+
+        int a = round(massRem/num);
+        int b = c-a;
+        int m = 2/c; // Peak value, is reached at the average size. 
+        int z = 0;
+        for(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
+    
+        // Distributing the mass
+        for(int trav = 0; trav<num && massRem>0; ++trav){
+
+            int result = 0;
+            float rVal = rnd();// between 0 and 1
+            float probSum = probDensity[0];
+            while(rVal>probSum){
+                probSum = probSum+probDensity[result+1];
+                ++result;
+            }
+            if(result>massRem){result = massRem;}
+
+            massRem = massRem-result;
+            masses[trav] = masses[trav]+result; 
+
+        }
+    }
+        
+    orxout() << "SpawnChildren(): passed Mass stuff. " << endl;
+
+    for(int fisch = 0; fisch<num; ++fisch){// create the children
+
+        // Position offset:
+        float r = masses[fisch]/rScaling;
+        Vector3* pos = new Vector3(r*sin(theta[fisch])*cos(phi[fisch]), r*sin(theta[fisch])*sin(phi[fisch]), r*cos(theta[fisch]));
+
+        AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos);
 
         if(child == nullptr){
@@ -403,22 +429,6 @@
         }
 
-
-
-        //orxout() << "Done: Creating new Asteroid" << endl;
-
-        // }
-
-
-                //         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());
-
-
-    }
-    // orxout() << "Leaving spawnChildren() method. " << endl;
+    }
+    orxout() << "Leaving spawnChildren() method. " << endl;
 }
 
Index: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc	(revision 11614)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc	(revision 11615)
@@ -42,4 +42,5 @@
 
 #include "SpicedAsteroidField.h"
+#include "AsteroidMinable.h"
 
 #include <algorithm>
@@ -50,4 +51,5 @@
 #include "core/EventIncludes.h"
 #include "network/NetworkFunction.h"
+#include "util/Math.h"
 
 // #include "infos/PlayerInfo.h"
@@ -61,7 +63,5 @@
 // #include "controllers/FormationController.h"
 
-#include "../pickup/items/HealthPickup.h"
-#include "../pickup/PickupSpawner.h"
-#include "../pickup/Pickup.h"
+
 //#include "../pickup/pickup ..... pickupable
 #include "../objects/collisionshapes/SphereCollisionShape.h"
@@ -110,7 +110,17 @@
         SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode);
         //        XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode);
-        XMLPortParam(SpicedAsteroidField, "size", setSize, getSize, xmlelement, mode);
+        XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode);
+        XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
+        XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode);
+        XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
+        XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode);
+        XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode);
+        XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode);
+
 
     }
+
+
+
 
     void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
@@ -151,11 +161,5 @@
     }
 
-    void SpicedAsteroidField::setSize(float s){
-        this->size = s;
-    }
 
-    float SpicedAsteroidField::getSize(){
-        return this->size;
-    }
 
 
Index: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h	(revision 11614)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h	(revision 11615)
@@ -58,8 +58,24 @@
 
 
+            inline void setCount(float s){this->count = s;}
+            inline float getCount(){return this->count;}
 
-            virtual void setSize(float f);
-            virtual float getSize();
+            inline void setMineralDensity(float d){this->mDensity = d;}
+            inline float getMineralDensity(){return this->mDensity;}
 
+            inline void setPosition(Vector3 v){this->position = v;}
+            inline Vector3 getPosition(){returrn this->position;}
+
+            inline void setMaxSize(int i){this->maxSize = i;}
+            inline int getMaxSize(){return this->maxSize;}
+
+            inline void setMinSize(int i){this->minSize = i;}
+            inline int getMinSize(){return this->minSize;}
+
+            inline void setRadius(float r){this->radius = r;}
+            inline int getRadius(){return this->radius;}
+
+            inline void setFog(bool f){this->foggy = f;}
+            inline bool isFoggy(){return this->foggy;}
 
         protected:
@@ -67,9 +83,15 @@
             //float asteroidVersion; // Bodenstrich-Konvention?, 
             // Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form
-            float size;
-            bool generateSmaller;
+            float count;
+            float mDensity; // Mineral density, between 0 and 1;
+
+            Vector3 position;
             bool initialised;
+            Context* context;
+            int maxSize;
+            int minSize;
 
-            Context* context;
+            float radius; 
+            bool foggy;
 
             virtual void create();
