Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 13, 2017, 4:34:53 PM (7 years ago)
Author:
remartin
Message:

Pickup generating works now after changing privacy settings of set methods in PickupSpawner.h. Added lots of debugging messages, spawnChildren does lead to a crash, still.

File:
1 edited

Legend:

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

    r11553 r11561  
    4141/*
    4242Veraenderungstagebuch
    43 - Dynamische Definition von Argumenten funktioniert nicht (Immer auf default Values gesetzt)
    44 ---> Was tut registerVariable? Wann werden die Argumente im XML-File angewendet?
    45     (Fall Konstruktor -> Methoden: Beim ersten Tick initialisieren?)
    46 ---> Mesh-Teil klappt, Hitbox noch nicht.
    47 ---> Maximale Hitpunkte = 200?
    48 ---> Meshgroesse passt, aber Hitbox wird iwieso nicht mehr generiert.
    49 
    50 - Neue Asteroiden generieren -> Absturz
    51 - Pickup spawning -> Absturz
    52 
    53 o hat's mit den Context-Eingenschaften zu tun? Je einen Neuen/Aktuellen besorgen?
    54 
    55 Nicht Pointer uebergeben?
    56 - Manchmal: Absturz bei Zerstoerung eines Asteroiden
    57 - Was tut 'Register Variables'?
    58 
    59 o Error messages: change context::pickups to something else
     43++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     44
     45KNACKPUNKTE:
     46o Collision Shape-Problem (Funktioniert nur, wenn im Konstruktor)
     47o Maximale Hitpunkte = 200?
     48
     49o Neue Asteroiden generieren -> Absturz
     50---> Weil Elterndings zerstoert wird?
     51---> Nicht moeglich, zur Laufzeit zu generieren?
     52
     53o Pickups: setMaxSpawned funktioniert nicht
    6054
    6155
    6256OFFEN:
    63 o Add custom pickup 'resources'
    64 
    65 
    66 
    67 Erlegt:
    68 o Rand() geht bis zu riesigen Nummern!
     57o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources.
     58o Explosion parts
     59o custom HUD
     60
     61HANDBUCH:
     62o im Level-File includes/pickups.oxi importieren.
     63
     64Anpassungen Pickup-Zeug:
     65o Pickup.h: Zugriffsänderung createSpawner
     66o PickupSpawner.h: Zugriffsrechte setPickupTemplateName() und setMaxSpawnedItems()
     67
     68ERLEGT:
     69o Rand() geht bis zu riesigen Nummern!
     70o Pickupgenerierung: vgl. Anpassungen.
     71o Dummes fisch-- statt fisch++ , Endlosschleife!
     72o Dynamische Definition -> putStuff-Methode, Werte noch nicht durchgesickert.
     73o Error-Nachricht: Einfach Argumente leer lassen.
    6974*/
    7075
     
    120125        this->bVulnerable_ = true;
    121126
    122 
    123 
    124127        // Default Values
    125128        this->generateSmaller = true;
    126         //this->size = this->getSize(); // Value doesn-t get accepted. Weird.
    127         this->size = 10;
     129        this->size = 10; // customSize
    128130        this->context = context;
    129131        this->initialised = false;
    130132        //this->roll = rand()*5; //etwas Drehung. richtige Variable
    131 
    132 
    133 
    134 
    135 
    136133
    137134
     
    142139        cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien
    143140        this->attachCollisionShape(cs);
    144 
    145 
    146141
    147142
     
    165160        // random one of the 6 shapes
    166161        char meshThingy[] = "";
    167         sprintf(meshThingy, "ast%.0f.mesh", (round((5*(double)rand()/(double)RAND_MAX))+1));
    168         //    sprintf(str, "Value of Pi = %f", M_PI);
    169         //char meshThingy[] = "ast5.mesh";
     162        sprintf(meshThingy, "ast%.0f.mesh", (round((5*(double)rand()/(double)RAND_MAX))+1)); //    sprintf(str, "Value of Pi = %f", M_PI);
    170163        hull->setMeshSource(meshThingy);
    171164        hull->setScale(this->size);
    172165        this->attach(hull);
    173         //hull->setPosition(this->getPosition());
    174166
    175167        // Collision shape
     
    240232    {
    241233
    242 
    243         //Spawn Pickup // Create at start already? ( Hidden in CollisionShape)
    244         HealthPickup* hP = new HealthPickup(this->context);
    245         if(hP == nullptr){
    246             orxout(internal_error, context::pickups) << "Weird, can't create new HealthPickup." << endl;
     234        // Stuff that can be harvested.
     235        PickupSpawner* thingy = new PickupSpawner(this->context);
     236
     237        // OFFEN: more precise size relation in custom resource pickup.
     238        char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
     239        if(this->size <= 5){
     240            strcat(tname, "smallmunitionpickup");
     241        }else if(this->size <= 20){
     242            strcat(tname, "mediummunitionpickup");
     243        }else{
     244            strcat(tname, "hugemunitionpickup");
    247245        }
    248         // hP->setPosition(this->getPosition()); // Does not have a member named 'setPosition' (Inherits from Pickup//BAse Object)
    249 
    250         // invoke spawnPickup on the pikcup itself? (returns bool, creates the hideous thing)
    251         // HealthPickup inherits from Pickup.
    252         // createSpawner is protected ->can be used as well in inheriting classes, but not here!
    253         // bool unnecessary = hP->createSpawner();
    254         // hP->setPosition(this->getPosition());
    255         //OFFEN: Add custom pickup 'resources'
    256 
    257         // createPickup is private, hP is of type Pickup!
    258         // CreateDroppedPickup returns a PickupSpawner!
    259         // PickupSpawner don't have public set methods, just that ugly 'factory method' which returns another PickupSpawner
    260         // PickupSpawner* thingy = new PickupSpawner(this->context);
    261         // What is Pickupable? says: Interface, no way to set type. Why do I even need the spawner? Trigger Distance?
     246        //orxout() << "Zeugsname:" << tname << endl;
     247        thingy->setPickupTemplateName(tname);
     248        thingy->setPosition(this->getPosition());
     249        //thingy->setMaxSpawnedItems(1); // Somehow doesn-t work yet.
     250        thingy->setRespawnTime(0.1f);// instantly
    262251       
    263 
    264         // Plan: Solve the Pickupable mystery, try to adapt the spawner somehow. Ask to modify it if that fails. (Change method types)
    265 
    266 
    267         // PickupSpawner* thingy = (new PickupSpawner(this->context))->createDroppedPickup(this->context, hP, nullptr, 10);
    268 //    /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance)
    269 
    270 
    271 
    272         // if(thingy == nullptr){
    273         //     orxout(internal_error, context::pickups) << "Weird, can't create new PickupSpawner." << endl;
    274         // }
    275         // thingy->setPosition(this->getPosition());
    276         // thingy->setMaxSpawnedItems(1);//Default is 1 already, private anyways
    277        
    278    
    279 
    280         // // Smaller Parts
    281         // if(this->generateSmaller){
    282         //     this->spawnChildren();
    283         // }
     252        orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
     253
     254
     255
     256
     257
     258        // Smaller Parts = 'Children'
     259        if(this->generateSmaller){
     260            this->spawnChildren();
     261        }
     262
     263
     264
    284265
    285266
     
    290271        this->destroyLater();
    291272        this->setDestroyWhenPlayerLeft(false);
     273
     274
    292275        // pawn -> addExplosionPart
    293276        // this->goWithStyle();
    294 
     277        orxout() << "Wieder retour in death() geschafft. " << endl;
    295278
    296279        // if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
     
    310293    // Spawn smaller Children
    311294    int massRem = this->size-1; //some mass is lost
    312     int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one
    313     massRem = massRem-num;
     295    int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one // Tweak towards bigger junks?
     296    num = 1; // zum Testen mal nur einen generieren.
     297   
     298    massRem = massRem-num;   
    314299    int extra = 0;
    315     for(int fisch=num; fisch>=1; fisch++){
     300
     301
     302    orxout() << "Number of Children: " << num << endl;
     303
     304
     305    for(int fisch=num; fisch>=1; fisch--){
    316306        // to distribute remaining mass
    317307        if(fisch==1){
     
    320310            extra = round(massRem*(double)rand() / (double)RAND_MAX);
    321311            massRem = massRem-extra;
     312
    322313        }
    323314
    324 
     315        orxout() << "Mass chosen: " << extra+1 << endl;
     316
     317        orxout() << "AsteroidMining::spawnChildren(): Inside for-loop." << endl;
    325318
    326319        //Spawn this child  Game crashes!
     
    328321        // if(!(child == nullptr)){//Errorgebastel
    329322
    330 
     323        // Position zu spaet gesetzt? Tick nicht atomar -> falsche Groesse evtl?
    331324
    332325            if(child == nullptr){
     
    342335            child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
    343336
     337
     338        orxout() << "Done: Creating new Asteroid" << endl;
     339
    344340        // }
    345341
     
    355351
    356352    }
     353    orxout() << "Leaving spawnChildren() method. " << endl;
    357354}
    358355
Note: See TracChangeset for help on using the changeset viewer.