Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 11, 2017, 6:05:17 PM (7 years ago)
Author:
remartin
Message:

SpicedAsteroidBelt erstellt, kosmetische Veränderungen. Offener Punkt um velocity, ansonsten fehlt nur noch das dokumentieren.

File:
1 edited

Legend:

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

    r11641 r11664  
    2828
    2929/*
     30
     31    @file AsteroidMinable.cc
    3032
    3133*
     
    4547
    4648KNACKPUNKTE:
     49o Super-XML-Argumente werden nicht richtig geparst (Velocity, Pitch, Yaw etc. )
     50
    4751
    4852OFFEN:
     
    5862o Density doesn't add up to 1...
    5963o set collisionDamage? Just for static entities?
    60 o AsteroidBelt?
    6164
    6265o Dokumentieren mit @brief?
     
    6467o Add sound effect (crunching etc. ) (No sound in space...)
    6568o Explosion parts
    66 o custom HUD
    67 
    6869
    6970HANDBUCH:
     
    124125#include "util/Math.h"
    125126
    126 
    127 // #include "infos/PlayerInfo.h"
    128 // #include "controllers/Controller.h"
    129 // #include "gametypes/Gametype.h"
    130 // #include "graphics/ParticleSpawner.h"
    131 // #include "worldentities/ExplosionChunk.h"
    132 // #include "worldentities/ExplosionPart.h"
    133 
    134 // #include "core/object/ObjectListIterator.h"
    135 // #include "controllers/FormationController.h"
    136 
    137 #include "../pickup/items/HealthPickup.h"
    138127#include "../pickup/PickupSpawner.h"
    139128#include "../pickup/Pickup.h"
    140 //#include "../pickup/pickup ..... pickupable
     129
    141130#include "../objects/collisionshapes/SphereCollisionShape.h"
    142131#include "../../orxonox/graphics/Model.h"
    143132
    144133
    145 
    146 
    147 
    148 
    149 
    150 namespace orxonox
    151 {
     134namespace orxonox{
     135
    152136    RegisterClass(AsteroidMinable);
    153137
     
    156140
    157141        RegisterObject(AsteroidMinable);
    158 
    159142        this->context = context;
    160         this->initialised = false;
    161         this->dropStuff = true; // Default
     143
     144        // Default Values:
     145        this->size = 10;
     146        this->dropStuff = true;
     147        this->generateSmaller = true;
     148        this->health_ = 15*size;
     149        this->maxHealth_ = this->health_;
     150        this->acceptsPickups_ = false;
    162151
    163152        //Noetig, damit nicht sofort zerstoert?
    164153        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
     154        this->enableCollisionCallback();
     155
    165156
    166157        // Old from Pawn
    167158        this->registerVariables();
    168159
    169         //orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl;
     160        this->initialised = false;
    170161
    171162    }
     
    184175        }
    185176
    186         this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    187         this->enableCollisionCallback();
    188 
    189         // Default Values
    190177        this->context = c;
    191178        this->size = size;
     
    197184
    198185        this->setPosition(position);
    199         this->setVelocity(v); // velocity = v; // The right one?
    200         //this->roll = rand()*5; //etwas Drehung. richtige Variable
    201 
    202 
    203         // Add Model    //<Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
     186        this->setVelocity(v);
     187        //this->roll = rand()*5; //etwas Drehung. Richtige Variable?
     188
     189        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
     190        this->enableCollisionCallback();
     191
     192
     193        // Add Model, random one of the 6 shapes
    204194        Model* hull = new Model(this->context);
    205         // random one of the 6 shapes
    206195        char meshThingy[] = "";
    207         sprintf(meshThingy, "ast%.0f.mesh", round(5*rnd())+1); //    sprintf(str, "Value of Pi = %f", M_PI);
     196        sprintf(meshThingy, "ast%.0f.mesh", round(5*rnd())+1);
    208197        hull->setMeshSource(meshThingy);
    209198        hull->setScale(this->size);
     
    212201        // Collision shape
    213202        SphereCollisionShape* cs = new SphereCollisionShape(this->context);
    214         cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien. 2.5 in AsteroidField.lua
     203        cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien.
    215204        this->attachCollisionShape(cs);
    216205
    217         // Old from Pawn
    218206        this->registerVariables();
    219207
    220208        this->initialised=true;
    221209
    222         //orxout() << "AsteroidMining:: Initialisierung Zweitkonstruktor abgeschlosssssen." << endl;
    223 
    224210    }
    225211
     
    227213
    228214    }
     215
    229216    // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc.
    230217    void AsteroidMinable::putStuff(){
     
    232219        // Just create a new asteroid to avoid Collision shape scale problems etc.
    233220        AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->getVelocity(), this->dropStuff);
    234         reborn->toggleShattering(true); // mainly here to avoid 'unused' warning.
     221        (void)reborn; // avoid compiler warning
    235222        this->bAlive_ = false;
    236223        this->destroyLater();
    237         //this->~AsteroidMinable(); // seems dangerous, yields warning.  Necessary for efficiency?
    238 
    239     }
    240 
    241     void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    242     {
    243         SUPER(AsteroidMinable, XMLPort, xmlelement, mode);
    244         //        XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode);
     224
     225    }
     226
     227    void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode){
     228
     229        SUPER(AsteroidMinable, XMLPort, xmlelement, mode);
     230
    245231        XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode);
    246 
    247     }
    248 
    249     void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
    250     {
     232        XMLPortParam(AsteroidMinable, "generateSmaller", toggleShattering, doesShatter, xmlelement, mode);
     233        XMLPortParam(AsteroidMinable, "dropStuff", toggleDropStuff, doesDropStuff, xmlelement, mode);
     234
     235    }
     236
     237    void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
     238
    251239        SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode);
    252240
    253         XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
    254     }
    255 
    256     void AsteroidMinable::registerVariables()
    257     {
     241    }
     242
     243    void AsteroidMinable::registerVariables(){
    258244
    259245        registerVariable(this->size, VariableDirection::ToClient);
    260246        registerVariable(this->generateSmaller, VariableDirection::ToClient);
    261 
     247        registerVariable(this->dropStuff, VariableDirection::ToClient);
    262248        registerVariable(this->initialised, VariableDirection::ToClient);
    263249
    264             //         float size;
    265             // bool generateSmaller;
    266             // bool initialised;
    267 
    268             // Context* context;
    269     }
    270 
    271     void AsteroidMinable::tick(float dt)
    272     {
     250    }
     251
     252    void AsteroidMinable::tick(float dt){
     253
    273254        if(!(this->initialised)){this->putStuff();}
    274255
     
    277258    }
    278259
    279 
    280 
    281 
    282     void AsteroidMinable::death() //ueberschreiben
    283     {
    284 
    285         // orxout() << "AsteroidMinable::Death() aufgerufen." << endl;
    286 
    287         // OFFEN: Sauber kapputten
    288         // just copied other stuff:
    289         // this->setHealth(1);
     260    void AsteroidMinable::death(){ // ueberschreibt das Zeug in Pawn
     261
     262        // just copied that from somewhere else.
    290263        this->bAlive_ = false;
    291264        this->destroyLater();
     
    312285            thingy->setRespawnTime(0.2f);
    313286        }
    314         // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
    315287
    316288        // Smaller Parts = 'Children'
    317289        if(this->generateSmaller){this->spawnChildren();}
    318290
    319         // orxout() << "Wieder retour in death() geschafft. " << endl;
    320 
    321291    }
    322292
     
    324294void AsteroidMinable::spawnChildren(){// Spawn smaller Children
    325295
    326    
    327296    if (this->size <=1){return;} // Absicherung trivialer Fall
    328297
     
    331300    if(num > 10){num = 10;} // no max function in C!
    332301    int masses[num]; // Masses of the asteroids, at least one.
    333     //orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
     302
     303    // orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
    334304
    335305    massRem = massRem-num; // mass is at least one, add again below.
    336306
    337307    // Randomnised spawning points for the new asteroids
    338     float phi[num]; // assuming that it gets initialised to 0. Add (= {0.0})?
    339     float theta[num];
     308    float phi[num];
     309    float theta[num];
     310
     311    // Discusting C stuff -> use that to initialise dynamic array values to 0.
     312    for(int twat = 0; twat<num; ++twat){masses[twat] = 0; phi[twat] = 0.0; theta[twat] = 0.0;}
     313
    340314    float piG = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
    341 
    342315    float d_p = 2*piG/num;
    343316    float d_t = piG/num;
     
    347320    // float thetaOffset = rnd()*pi;
    348321    float rScaling; // scale radius to prevent asteroids from touching. (distance=AsteroidRadius/tan(sector/2))
     322
    349323    if(num == 1 ){
    350324        rScaling = 1; // avoid tan(90). Unused.
     
    404378            result = 0;// reset
    405379            rVal = rnd();// between 0 and 1
    406             // orxout() << "Random Value picked: " << rVal << endl;
    407380            probSum = probDensity[0];
    408             //orxout() << "Sum at start: " << probSum << endl;
    409 
    410             while(rVal>probSum && result<massRem){// Not yet found && there-s smth to distribute (Incrementing once inside!)
     381
     382            while(rVal>probSum && result<massRem){// Not yet found && there-s smth left to distribute (Incrementing once inside!)
    411383                if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error
    412384                ++result;
    413                 // orxout() << "Sum so far: " << probSum << ". Just added " << probDensity[result+1] <<  endl;
    414385            }
    415386
    416387            massRem = massRem-result;
    417             masses[trav] = 1 +result; // at least one
    418             // orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl;
    419 
    420         }
    421     }else{// Everyone has mass 1. Initialising the array to 1 doesn-t seem to work. Hideous C language!
    422         for(int schnaegg = 0; schnaegg<num; ++schnaegg){
    423             masses[schnaegg] = 1;
    424         }
     388            masses[trav] = 1 +result; // Fragments have mass of at least one.
     389        }
     390    }else{
     391        for(int schnaegg = 0; schnaegg<num; ++schnaegg){masses[schnaegg] = 1;}
    425392    }
    426393
     
    437404        }
    438405       
    439         // orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;
    440406        AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->getVelocity(), this->dropStuff);
    441407
Note: See TracChangeset for help on using the changeset viewer.