Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 4, 2017, 4:38:17 PM (7 years ago)
Author:
remartin
Message:

Das Aufteilen funktioniert nun gut. AsteroidField fertiggestellt und mit dokumentieren begonnen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc

    r11618 r11640  
    4343++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    4444
    45 FRAGEN:
    46 * Zeilen-Loeschung beim output
    47 * orxout()-Problem
    48 * dokumentieren mit @brief?
    49 * Warnumg aus Asteroidenzerstoerung
    50 
    5145
    5246KNACKPUNKTE:
    5347
    54 
    5548OFFEN:
    56 
    57 o Mass distribution -> weird for bigger asteroids
    58 --> more testing
    59 
    60 o SpicedAsteroidField fertigstellen, Mineraldichten-Parameter
    6149
    6250o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources.
     
    6553----> im MineralsPickup die isPickedUp()-Methode überschreiben?
    6654--> data_extern/images/effects: PNG's für die Pickups und GUI-Dinger.
    67 
    68 o inherit parent velocity
     55--> https://www.orxonox.net/jenkins/view/Management/job/orxonox_doxygen_trunk/javadoc/group___pickup.html
     56
     57o Anfangsgeschwindigkeit fuers Asteroidenfeld
     58o Density doesn't add up to 1...
    6959o set collisionDamage? Just for static entities?
     60o AsteroidBelt?
     61
    7062o Dokumentieren mit @brief?
    71 
     63o unregister -empty- asteroids from radar. (or turn them green or whatever)
     64o Add sound effect (crunching etc. ) (No sound in space...)
    7265o Explosion parts
    7366o custom HUD
     67
    7468
    7569HANDBUCH:
     
    8579o Pawn.h: Attribut acceptsPickups_ inklusive get/set.
    8680
    87 ERLEGT:
     81ERLEGTE FEHLER:
    8882o Rand() geht bis zu riesigen Nummern!
    8983o Pickupgenerierung: vgl. Fremdanpassungen.
     
    158152    RegisterClass(AsteroidMinable);
    159153
    160 
    161     // This constructor is for XML access only.
     154    // @brief Standard constructor
    162155    AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context){
    163156
    164         // Da auch noetig? Wegen set in XML-Code?
    165157        RegisterObject(AsteroidMinable);
    166158
    167159        this->context = context;
    168160        this->initialised = false;
     161        this->dropStuff = true; // Default
    169162
    170163        //Noetig, damit nicht sofort zerstoert?
     
    178171    }
    179172
    180     // Call this one from other C-files. Takes arguments.
    181     AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position) : Pawn(c){
     173    // @brief Use this constructor with care. Mainly used internally, arguments are passed directly.
     174    AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, Vector3 v, bool dropStuff) : Pawn(c){
    182175
    183176        RegisterObject(AsteroidMinable);
    184177
    185         // Old stuff from pawn
    186         this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
    187         this->setRadarObjectShape(RadarViewable::Shape::Dot);
     178        // The radar is able to detect whether an asteroid contains resources....
     179        if(dropStuff){
     180            this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
     181            this->setRadarObjectShape(RadarViewable::Shape::Dot);
     182        }else{
     183            // Somehow remove from radar?
     184        }
     185
    188186        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    189 
    190187        this->enableCollisionCallback();
    191188
    192189        // Default Values
    193         this->generateSmaller = true;
    194190        this->context = c;
    195191        this->size = size;
    196192        this->health_ = 15*size;
    197193        this->maxHealth_ = this->health_;
    198         this->acceptsPickups_ = false;
     194        this->acceptsPickups_ = false;
     195        this->generateSmaller = true;
     196        this->dropStuff = dropStuff;
    199197
    200198        this->setPosition(position);
     199        this->setVelocity(v); // velocity = v; // The right one?
    201200        //this->roll = rand()*5; //etwas Drehung. richtige Variable
    202201
     
    228227
    229228    }
    230 
     229    // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc.
    231230    void AsteroidMinable::putStuff(){
    232231
    233232        // Just create a new asteroid to avoid Collision shape scale problems etc.
    234         AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition());
     233        AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->getVelocity(), this->dropStuff);
    235234        reborn->toggleShattering(true); // mainly here to avoid 'unused' warning.
    236         this->~AsteroidMinable(); // seems dangerous, yields warning.  Necessary for efficiency?
     235        this->bAlive_ = false;
     236        this->destroyLater();
     237        //this->~AsteroidMinable(); // seems dangerous, yields warning.  Necessary for efficiency?
    237238
    238239    }
     
    276277    }
    277278
    278     void AsteroidMinable::setSize(float s){
    279         this->size = s;
    280     }
    281 
    282     float AsteroidMinable::getSize(){
    283         return this->size;
    284     }
    285 
    286     void AsteroidMinable::toggleShattering(bool b){
    287         this->generateSmaller = b;
    288     }
     279
    289280
    290281
     
    304295
    305296
    306         // Stuff that can be harvested.
    307         PickupSpawner* thingy = new PickupSpawner(this->context);
    308         // OFFEN: more precise size relation in custom resource pickup.
    309         char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
    310         if(this->size <= 5){
    311             strcat(tname, "smallmunitionpickup");
    312         }else if(this->size <= 20){
    313             strcat(tname, "mediummunitionpickup");
    314         }else{
    315             strcat(tname, "hugemunitionpickup");
    316         }
    317         thingy->setPickupTemplateName(tname);
    318         thingy->setPosition(this->getPosition());
    319         thingy->setMaxSpawnedItems(1); // Would be default anyways
    320         thingy->setRespawnTime(0.2f);
    321 
     297        // Pickups which can be harvested.
     298        if(dropStuff){
     299            PickupSpawner* thingy = new PickupSpawner(this->context);
     300            // OFFEN: more precise size relation in custom resource pickup.
     301            char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
     302            if(this->size <= 5){
     303                strcat(tname, "smallmunitionpickup");
     304            }else if(this->size <= 20){
     305                strcat(tname, "mediummunitionpickup");
     306            }else{
     307                strcat(tname, "hugemunitionpickup");
     308            }
     309            thingy->setPickupTemplateName(tname);
     310            thingy->setPosition(this->getPosition());
     311            thingy->setMaxSpawnedItems(1); // Would be default anyways
     312            thingy->setRespawnTime(0.2f);
     313        }
    322314        // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
    323315
     
    339331    if(num > 10){num = 10;} // no max function in C!
    340332    int masses[num]; // Masses of the asteroids, at least one.
    341     orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
     333    //orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
    342334
    343335    massRem = massRem-num; // mass is at least one, add again below.
     
    346338    float phi[num] = {0.0}; // assuming that it gets initialised to 0. Add (= {0.0})?
    347339    float theta[num] = {0.0};
    348     float piG = pi; // ist statisch oder so.
     340    float piG = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
    349341
    350342    float d_p = 2*piG/num;
     
    380372    //orxout() << "SpawnChildren(): Phi: "; printArrayString(phi);
    381373    //orxout() << "SpawnChildren(): Theta: "; printArrayString(theta);
    382     orxout() << "SpawnChildren(): Passed angle stuff. " << endl;
    383 
    384     // 'Triangular', discrete probability density with max at the expected value massRem/num at a. a+b = c
     374    //orxout() << "SpawnChildren(): Passed angle stuff. " << endl;
     375
     376    // 'Triangular', discrete probability "density" with max at the expected value massRem/num at a. a+b = c
    385377    if(massRem>0){ // Required to avoid array of size 0 or access problems
    386378        int c = massRem;
     
    397389        for(z = 0; z<b; ++z){probDensity[c-z] = (z+1)*dProbB;} // falling part
    398390   
    399         // Testing
    400         for(int globi = 0; globi<c; ++globi){
    401             orxout() << "pDensity at [" << globi << "] is: " << probDensity[globi] << endl;
    402         }
     391        // // Just for testing:
     392        // float sum = 0.0;
     393        // for(int globi = 0; globi<c; ++globi){
     394        //     orxout() << "pDensity at [" << globi << "] is: " << probDensity[globi] << endl;
     395        //     sum = sum+ probDensity[globi];
     396        // }
     397        // orxout() << "Sum of densities should b 1, it is: " << sum << endl;
    403398
    404399        // Distributing the mass to individual asteroids
     
    409404            result = 0;// reset
    410405            rVal = rnd();// between 0 and 1
    411             orxout() << "Random Value picked: " << rVal << endl;
     406            // orxout() << "Random Value picked: " << rVal << endl;
    412407            probSum = probDensity[0];
    413408            //orxout() << "Sum at start: " << probSum << endl;
    414409
    415410            while(rVal>probSum && result<massRem){// Not yet found && there-s smth to distribute (Incrementing once inside!)
    416                 if(result<(num-2)){probSum = probSum+probDensity[result+1];} // avoid logical/acess error
     411                if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error
    417412                ++result;
    418                 //orxout() << "Sum so far: " << probSum << endl;
     413                // orxout() << "Sum so far: " << probSum << ". Just added " << probDensity[result+1] << endl;
    419414            }
    420415
    421416            massRem = massRem-result;
    422417            masses[trav] = 1 +result; // at least one
    423             orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl;
     418            // orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl;
    424419
    425420        }
     
    430425    }
    431426
    432     //orxout() << "SpawnChildren(): Masses: "; printArrayString(masses);
    433     orxout() << "SpawnChildren(): Passed mass stuff. " << endl;
     427    // orxout() << "SpawnChildren(): Masses: "; printArrayString(masses);
     428    // orxout() << "SpawnChildren(): Passed mass stuff. " << endl;
    434429
    435430    // Creating the 'chlidren':
     
    442437        }
    443438       
    444         //orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;
    445         AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos);
     439        // orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;
     440        AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->getVelocity(), this->dropStuff);
    446441
    447442        if(child == nullptr){
     
    450445
    451446    }
    452     orxout() << "Leaving spawnChildren() method. " << endl;
     447    // orxout() << "Leaving spawnChildren() method. " << endl;
    453448}
    454449
     
    458453        orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
    459454
    460         // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
     455        // Kollision mit anderem Asteroid oder Pickup verhindern. In diesem Fall einfach nichts tun.
    461456        // Wird staending aufgerufen -> Rechenleistung?
    462457        if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
     
    496491    }
    497492
     493    // @brief Just for testing. Don-t work anyways.
    498494    void AsteroidMinable::printArrayString(float thingy[]){ // Don-t work!
    499495
     
    509505    }
    510506
     507    // @brief Just for testing. Don-t work anyways.
    511508    void AsteroidMinable::printArrayString(int thingy[]){
    512509
     
    524521    }
    525522
    526 
    527523    // void AsteroidMinable::printArrayString(int thingy[]){
    528 
    529524    //     char res[] = "[";
    530525    //     //strcat(res, "[");
     
    547542    // }
    548543
    549 
    550 
    551 //Pawn:
    552     // void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
    553     // {
    554     //     if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    555     //     {
    556     //         this->damage(damage, healthdamage, shielddamage, originator, cs);
    557     //         this->setVelocity(this->getVelocity() + force);
    558     //     }
    559     // }
    560 
    561     // void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
    562     // {
    563     //     if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    564     //     {
    565     //         this->damage(damage, healthdamage, shielddamage, originator, cs);
    566 
    567     //         if ( this->getController() )
    568     //             this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
    569     //     }
    570     // }
    571 
    572 
    573 
    574 
    575             // /**
    576             // @brief
    577             //     Virtual function that gets called when this object collides with another.
    578             // @param otherObject
    579             //     The object this one has collided into.
    580             // @param ownCollisionShape
    581             //     The collision shape of the other object
    582             // @param contactPoint
    583             //     Contact point provided by Bullet. Holds more information and can me modified. See return value.
    584             // @return
    585             //     Returning false means that no modification to the contactPoint has been made. Return true otherwise!
    586             // @note
    587             //     Condition is that enableCollisionCallback() was called.
    588             // */
    589             // virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
    590             //     { return false; } /* With false, Bullet assumes no modification to the collision objects. */
    591 
    592             // //! Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise!
    593             // inline void enableCollisionCallback()
    594             //     { this->bCollisionCallbackActive_ = true; this->collisionCallbackActivityChanged(); }
    595 
    596 
    597 
    598             // //! Disables the collidesAgainst(.) function. @see enableCollisionCallback()
    599             // inline void disableCollisionCallback()
    600             //     { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); }
    601 
    602 
    603             // //! Tells whether there could be a collision callback via collidesAgainst(.)
    604             // inline bool isCollisionCallbackActive() const
    605             //     { return this->bCollisionCallbackActive_; }
    606 
    607             // //! Enables or disables collision response (default is of course on)
    608             // inline void setCollisionResponse(bool value)
    609             //     { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); }
    610 
    611 
    612             // //! Tells whether there could be a collision response
    613             // inline bool hasCollisionResponse()
    614             //     { return this->bCollisionResponseActive_; }
    615 
    616 
    617544}
    618 
    619 
    620 
    621 
    622 
    623 /*
    624     void DronePickup::changedUsed(void)
    625     {
    626         SUPER(DronePickup, changedUsed);
    627 
    628         // If the pickup has transited to used.
    629         if(this->isUsed())
    630         {
    631 
    632                 Pawn* pawn = this->carrierToPawnHelper();
    633                 if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    634                     this->Pickupable::destroy();
    635 
    636                 //Attach to pawn
    637                 Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something)
    638                 drone->addTemplate(this->getDroneTemplate());
    639 
    640                 Controller* controller = drone->getController();
    641                 DroneController* droneController = orxonox_cast<DroneController*>(controller);
    642                 if(droneController != nullptr)
    643                 {
    644                     droneController->setOwner(pawn);
    645                 }
    646 
    647                 Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30);
    648                 drone->setPosition(spawnPosition);
    649 
    650                 // The pickup has been used up.
    651                 this->setUsed(false);
    652         }
    653         else
    654         {
    655             // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
    656             if(this->isOnce() || (this->isContinuous() ))
    657             {
    658                 this->Pickupable::destroy();
    659             }
    660         }
    661     }
    662 */
Note: See TracChangeset for help on using the changeset viewer.