Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 12, 2017, 8:29:52 PM (7 years ago)
Author:
remartin
Message:

Added tilting for the spicedAsteroidBelt. Finished commenting, polish up. Done.

File:
1 edited

Legend:

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

    r11664 r11667  
    2929/*
    3030
    31     @file AsteroidMinable.cc
    32 
    33 *
    34 *
    35 * An asteroid which can be destroyed. Some smaller asteroids are created and a pickup
    36 * spawns.
    37 *
    38 *
    39 *
    40 
    41 */
    42 
    43 /*
    44 Veraenderungstagebuch
    45 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    46 
    47 
    48 KNACKPUNKTE:
    49 o Super-XML-Argumente werden nicht richtig geparst (Velocity, Pitch, Yaw etc. )
    50 
    51 
    52 OFFEN:
    53 
    54 o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources.
    55 --> PickupTemplateName_ in PickupSpawner ist ein string. Wird via getBaseClassIdentifier ausgelesen, daraus wird ein Pickupable fabriziert.
    56 --> MunitionPickup erbt von Pickup erbt von collectiblePickup erbt von Pickupable
    57 ----> im MineralsPickup die isPickedUp()-Methode überschreiben?
    58 --> data_extern/images/effects: PNG's für die Pickups und GUI-Dinger.
     31    @file
     32    @author remartin
     33    @brief An asteroid which can be destroyed. Some smaller asteroids are created and a pickup spawns.
     34
     35HANDBUCH:
     36o Die Collision Shape kann nur im Konstruktor hinzugefügt werden. Die XML-Argumente werden aber erst nach dem Konstruktor gesetzt.
     37  Darum wird hier beim ersten Aufruf der tick()-Methode via putStuff() ein komplett neuer Asteroid generiert und der alte zerstört.
     38o im Level-File includes/pickups.oxi importieren.
     39
     40OFFEN/Weiterentwicklung:
     41o @TODO Add resource pickups.
     42--> data_extern/images/effects: PNG's für die Pickups
    5943--> https://www.orxonox.net/jenkins/view/Management/job/orxonox_doxygen_trunk/javadoc/group___pickup.html
    6044
    61 o Anfangsgeschwindigkeit fuers Asteroidenfeld
    6245o Density doesn't add up to 1...
    63 o set collisionDamage? Just for static entities?
    64 
    65 o Dokumentieren mit @brief?
    66 o unregister -empty- asteroids from radar. (or turn them green or whatever)
     46o Does collision damage work properly
    6747o Add sound effect (crunching etc. ) (No sound in space...)
    6848o Explosion parts
    6949
    70 HANDBUCH:
    71 o im Level-File includes/pickups.oxi importieren.
    72 o Bei der XML-Variante wird beim ersten Aufruf der Tick-Methode ein neuer Asteroid generiert,
    73   damit die Groesse der Collision Shape korrekt initialisiert wird.
    74 
    75 FREMDANPASSUNGEN:
     50ANDERORTS VERÄNDERTE SACHEN:
    7651Pickup-Zeug:
    77 o Pickup.h: Zugriffsänderung createSpawner
     52o Pickup.h: createSpawner() neu public statt private
    7853o PickupSpawner.h: Zugriffsrechte setPickupTemplateName() und setMaxSpawnedItems()
    79 o PickupSpawner.h: In Tick() zwei Testbedingungen eingefuegt.
     54o PickupSpawner.h: In Tick() zwei Testbedingungen eingefügt.
    8055o Pawn.h: Attribut acceptsPickups_ inklusive get/set.
    8156
    8257ERLEGTE FEHLER:
    83 o Rand() geht bis zu riesigen Nummern!
    84 o Pickupgenerierung: vgl. Fremdanpassungen.
    85 o Minimalbegrenzung fuer Masse vergessen.
    86 o Dynamische Definition -> putStuff-Methode, Werte noch nicht durchgesickert.
    87 o Error-Nachricht: Einfach Argumente leer lassen.
    88 o Pickups: setMaxSpawned funktioniert nicht -> Bastelloesung: Auf 2 statt eins setzen, erstes wird wohl direkt zerstoert.
    89 o setHealth: Wird mit Max verwurstelt, war 0.
    90 o Position nicht gesetzt -> alles im Ursprung, Kollision -> fliegt davon.
    91 o nimmt zuviel Schaden. -> wird mit maxHealth verwurstelt -> einfach auch setzen.
    92 
    93 o Groessenabhaengige Collison shape: Umweg ueber zweiten Konstruktor.
    94 o Absturz beim Asteroidengenerieren: Health war auf 0 gesetzt! Wurde nur bei der xml-Variante definiert.
     58o Grössenabhängige Collision Shape -> putStuff-Methode, Werte noch nicht durchgesickert.
     59o setHealth: maxHealth() des pawns setzen!
    9560o Asteroiden fressen Pickups: Argument in Pawn, Test darauf in Tick() von PickupSpawner.
    96 o Man kann keine Arrays der Groesse 0 initialisieren, aber auch nicht per IF 2x definieren.
    9761o i++ einfach ganz verhindern, ++i stattdessen.
    98 o Discusting mixup with array length, accessing element a[len]...
    99 o unitialised mass value -> obese asteroid, physics bug.
    100 
     62o Velocity didn-t get passed properly through the 2nd constructor. Used get/set instead.
     63o Rand() geht bis zu riesigen Nummern! rnd() ist zwischen 0 und 1
    10164
    10265NOTIZEN:
    103 o SUPER entspricht ueberladen, andere Argumente der Methode.
     66o SUPER
    10467o Warnungsverhinderung anderswo: (void)pickedUp; // To avoid compiler warning.
    105 
    106 Was ist das?         friend class Pickupable;
     68o friend class Pickupable;
    10769
    10870
     
    150112        this->acceptsPickups_ = false;
    151113
    152         //Noetig, damit nicht sofort zerstoert?
    153114        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    154115        this->enableCollisionCallback();
    155116
    156 
    157117        // Old from Pawn
    158118        this->registerVariables();
    159119
    160120        this->initialised = false;
    161 
    162121    }
    163122
    164123    // @brief Use this constructor with care. Mainly used internally, arguments are passed directly.
    165     AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, Vector3 v, bool dropStuff) : Pawn(c){
     124    AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, bool dropStuff) : Pawn(c){
    166125
    167126        RegisterObject(AsteroidMinable);
     
    172131            this->setRadarObjectShape(RadarViewable::Shape::Dot);
    173132        }else{
    174             // Somehow remove from radar?
     133            // Somehow remove from radar? (all pawns get registered automatically... )
     134            this->setRadarObjectColour(ColourValue(0.663f, 0.663f, 0.663f, 1.0f));
     135            this->setRadarObjectShape(RadarViewable::Shape::Dot);
    175136        }
    176137
     
    184145
    185146        this->setPosition(position);
    186         this->setVelocity(v);
    187147        //this->roll = rand()*5; //etwas Drehung. Richtige Variable?
    188148
    189149        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    190150        this->enableCollisionCallback();
    191 
    192151
    193152        // Add Model, random one of the 6 shapes
     
    214173    }
    215174
    216     // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc.
     175    // @brief Helper method.
    217176    void AsteroidMinable::putStuff(){
    218177
    219         // Just create a new asteroid to avoid Collision shape scale problems etc.
    220         AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->getVelocity(), this->dropStuff);
     178        AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->dropStuff);
     179        reborn->setVelocity(this->getVelocity());
     180        // reborn->setAngularVelocity(this->getAngularVelocity()); // Add all other stuff, too?
    221181        (void)reborn; // avoid compiler warning
     182
    222183        this->bAlive_ = false;
    223184        this->destroyLater();
     
    258219    }
    259220
    260     void AsteroidMinable::death(){ // ueberschreibt das Zeug in Pawn
     221    void AsteroidMinable::death(){ // @brief Überschreibt die Methode in Pawn
    261222
    262223        // just copied that from somewhere else.
     
    268229
    269230
    270         // Pickups which can be harvested.
     231        // Pickups which can be harvested. It's munition at the moment, could be changed/extended.
    271232        if(dropStuff){
    272233            PickupSpawner* thingy = new PickupSpawner(this->context);
    273             // OFFEN: more precise size relation in custom resource pickup.
     234
    274235            char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
    275236            if(this->size <= 5){
     
    291252    }
    292253
    293 
    294 void AsteroidMinable::spawnChildren(){// Spawn smaller Children
     254// @brief If the option generateSmaller is enabled, individual fragments are added with this method.
     255    void AsteroidMinable::spawnChildren(){
    295256
    296257    if (this->size <=1){return;} // Absicherung trivialer Fall
     
    298259    int massRem = this->size-1; //some mass is lost
    299260    int num = round(rnd()*(massRem-1)) + 1; // random number of children, at least one
    300     if(num > 10){num = 10;} // no max function in C!
    301     int masses[num]; // Masses of the asteroids, at least one.
    302 
     261    if(num > 10){num = 10;} // no max function in C?
     262    int masses[num]; // Masses of the asteroids
    303263    // orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
    304 
    305     massRem = massRem-num; // mass is at least one, add again below.
     264    massRem = massRem-num; // mass must be at least one, add later. 
    306265
    307266    // Randomnised spawning points for the new asteroids
     
    348307    //orxout() << "SpawnChildren(): Passed angle stuff. " << endl;
    349308
    350     // 'Triangular', discrete probability "density" with max at the expected value massRem/num at a. a+b = c
    351     if(massRem>0){ // Required to avoid array of size 0 or access problems
     309    // Triangular, discrete probability "density" with max at the average value massRem/num. 50% chance to be below that.
     310    if(massRem>0){
    352311        int c = massRem;
    353312        float probDensity[c];
     
    372331
    373332        // Distributing the mass to individual asteroids
    374         int result;
    375         float rVal;// between 0 and 1
    376         float probSum;
     333        int result; 
     334        float rVal; // between 0 and 1
     335        float probSum; // summing up until rval is reached.
    377336        for(int trav = 0; trav<num; ++trav){
    378             result = 0;// reset
    379             rVal = rnd();// between 0 and 1
     337            result = 0;
     338            rVal = rnd(); 
    380339            probSum = probDensity[0];
    381340
    382             while(rVal>probSum && result<massRem){// Not yet found && there-s smth left to distribute (Incrementing once inside!)
     341            while(rVal>probSum && result<massRem){// Not yet found && there-s smth left to distribute (Incrementing inside!)
    383342                if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error
    384343                ++result;
    385344            }
    386345
     346            masses[trav] = 1 +result; // Fragments have mass of at least one.
    387347            massRem = massRem-result;
    388             masses[trav] = 1 +result; // Fragments have mass of at least one.
     348
    389349        }
    390350    }else{
     
    404364        }
    405365       
    406         AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->getVelocity(), this->dropStuff);
     366        AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->dropStuff);
     367        child->setVelocity(this->getVelocity());
    407368
    408369        if(child == nullptr){
     
    414375}
    415376
    416 
     377// @brief overloading that to prevent asteroids from taking damage from each other (domino effect etc. )
    417378    void AsteroidMinable::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
    418379
    419         orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
    420 
    421         // Kollision mit anderem Asteroid oder Pickup verhindern. In diesem Fall einfach nichts tun.
    422         // Wird staending aufgerufen -> Rechenleistung?
     380        // orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
    423381        if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
    424382        this->damage(damage, healthdamage, shielddamage, originator, cs);
    425383        this->setVelocity(this->getVelocity() + force);
    426 
    427 
    428384
    429385        // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) )
     
    434390    }
    435391
     392// @brief overloading that to prevent asteroids from taking damage from each other (domino effect etc. )
    436393    void AsteroidMinable::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
    437394
    438395        //orxout() << "AsteroidMining::Hit(Variante 2) Dings aufgerufen. " << endl;
    439         // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
    440         // Wird staending aufgerufen -> Rechenleistung?
    441396        if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
    442 
    443         //orxout() << "Schaden. HP: " << this->health_ << " Dmg: " << damage << " hDmg: " << healthdamage << " sDmg: " << shielddamage << endl;
    444 
    445397        this->damage(damage, healthdamage, shielddamage, originator, cs);
    446 
    447 
    448 
    449398
    450399        // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) )
Note: See TracChangeset for help on using the changeset viewer.