Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 7, 2017, 5:47:14 PM (7 years ago)
Author:
remartin
Message:

added method 'putStuff' for initialisation. Mesh has correct size (and a randomised shape), but the collision shape stopped getting initialised. Crashes occur somewhere in the death() method.

Location:
code/branches/AsteroidMining_HS17
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw

    r11546 r11551  
    9090    <!-----AsteroidMinable --->
    9191
    92     <AsteroidMinable size=100 position="0,-500,0" />
     92    <AsteroidMinable size=15 position="0,-500,0" />
     93    <AsteroidMinable size=5 position="100,-500,100" />
    9394
    9495   
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc

    r11550 r11551  
    3737*
    3838
     39*/
     40
     41/*
     42Veraenderungstagebuch
     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- Manchmal: Absturz bei Zerstoerung eines Asteroiden
     53
     54
     55
     56Erlegt:
     57o Rand() geht bis zu riesigen Nummern!
    3958*/
    4059
     
    7089
    7190
    72 /*
    73 Veraenderungstagebuch
    74 - Dynamische Definition von Argumenten funktioniert nicht
    75 - Death-Methode -> Absturz
    76 
    77 
    78 
    79 
    80 */
     91
    8192
    8293
     
    89100    {
    90101        RegisterObject(AsteroidMinable);
     102
     103        // Old stuff from pawn
    91104        this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
    92105        this->setRadarObjectShape(RadarViewable::Shape::Dot);
    93 
    94106        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    95 
     107        this->bAlive_ = true;
     108        this->bVulnerable_ = true;
     109
     110
     111
     112        // Default Values
    96113        this->generateSmaller = true;
    97114        //this->size = this->getSize(); // Value doesn-t get accepted. Weird.
    98         this->size = 5;
     115        this->size = 10;
    99116        this->context = context;
    100 
    101 
     117        this->initialised = false;
     118        //this->roll = rand()*5; //etwas Drehung. richtige Variable
     119
     120
     121        // DELETE if other stuff works! (wrong size etc.)
     122        SphereCollisionShape* cs = new SphereCollisionShape(this->context);
     123        cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien
     124        this->attachCollisionShape(cs);
     125
     126
     127
     128
     129        // Old from Pawn
     130        this->registerVariables();
     131
     132    }
     133
     134    AsteroidMinable::~AsteroidMinable()
     135    {
     136
     137    }
     138
     139    void AsteroidMinable::putStuff(){
     140
     141        // Add Model
     142        //<Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
    102143        Model* hull = new Model(this->context);
    103144        // random one of the 6 shapes
    104         //char meshThingy[] = "";
    105         //sprintf(meshThingy, "ast%f.mesh", round(rand()*5)+1);
     145        char meshThingy[] = "";
     146        sprintf(meshThingy, "ast%.0f.mesh", (round((5*(double)rand()/(double)RAND_MAX))+1));
    106147        //    sprintf(str, "Value of Pi = %f", M_PI);
    107         char meshThingy[] = "ast5.mesh";
    108 
    109 
     148        //char meshThingy[] = "ast5.mesh";
    110149        hull->setMeshSource(meshThingy);
    111         hull->setScale(size);
     150        hull->setScale(this->size);
    112151        this->attach(hull);
    113152        //hull->setPosition(this->getPosition());
    114153
     154        // Collision shape
    115155        SphereCollisionShape* cs = new SphereCollisionShape(this->context);
    116         cs->setRadius(size*2); //OFFEN: Feinabstimmung der Radien
    117         this->attachCollisionShape(cs);
    118 
    119 
    120 
    121         //      <Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
    122 /*
    123             Model* slotModel = nullptr;
    124 
    125             for (int i = 0; i < numWeaponSlots; ++i)
    126             {
    127                 slotPosition = weaponSlots.at(i)->getPosition();
    128                 slotOrientation = weaponSlots.at(i)->getOrientation();
    129                 slotModel = new Model(this->getContext());
    130                 slotModel->setMeshSource("Coordinates.mesh");
    131                 slotModel->setScale(3.0f);
    132                 slotModel->setOrientation(slotOrientation);
    133                 slotModel->setPosition(slotPosition);
    134 
    135                 this->attach(slotModel);
    136                 debugWeaponSlotModels_.push_back(slotModel);
    137             }
    138         }
    139         else
    140         {
    141             // delete all debug models
    142             for(Model* model : debugWeaponSlotModels_)
    143             {
    144                 model->destroy();
    145             }
    146             debugWeaponSlotModels_.clear();
    147         }
    148 */
    149 
    150 
    151 
    152  
    153     }
    154 
    155     AsteroidMinable::~AsteroidMinable()
    156     {
    157 
     156        cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien
     157        this->attachCollisionShape(cs);
     158
     159
     160
     161        this->initialised=true;
    158162    }
    159163
     
    170174        SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode);
    171175
    172         //XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
     176        XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
    173177    }
    174178
     
    179183        registerVariable(this->health_,            VariableDirection::ToClient);
    180184        registerVariable(this->maxHealth_,         VariableDirection::ToClient);
     185
     186        registerVariable(this->size, VariableDirection::ToClient);
     187        registerVariable(this->generateSmaller, VariableDirection::ToClient);
    181188    }
    182189
    183190    void AsteroidMinable::tick(float dt)
    184191    {
    185         SUPER(Pawn, tick, dt);
    186         if(this->health_ <=0){
    187             this->death();
    188         }
     192        // SUPER(Pawn, tick, dt);
     193        if(!(this->initialised)){this->putStuff();}
     194
     195        if(this->health_ <=0){this->death();}
    189196
    190197    }
     
    192199    void AsteroidMinable::setSize(float s){
    193200        this->size = s;
    194         this->health_ = 200*s;
     201        this->health_ = 5*s;// capped at 200 in pawn or smth?
     202        this->setHealth(health_);
    195203    }
    196204
     
    202210    {
    203211
    204         // pawn -> addExplosionPart
    205         // this.goWithStyle()
    206 
    207         // Spawn Pickup
    208         HealthPickup* hP = new HealthPickup(context);
     212
     213
     214
     215        //Spawn Pickup
     216        HealthPickup* hP = new HealthPickup(this->context);
    209217        //OFFEN: Add custom pickup 'resources'
    210         PickupSpawner* thingy = new PickupSpawner(context);
     218        PickupSpawner* thingy = new PickupSpawner(this->context);
    211219        thingy->setPosition(this->getPosition());
    212         thingy->createDroppedPickup(context, hP, nullptr, 10);
     220        thingy->createDroppedPickup(this->context, hP, nullptr, 10);
    213221
    214222//    /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance)
    215223   
    216224
    217 
     225        // Smaller Parts
    218226        if(this->generateSmaller){
    219227            this->spawnChildren();
    220228        }
     229
    221230
    222231        // OFFEN: Sauber kapputten
     
    226235        this->destroyLater();
    227236        this->setDestroyWhenPlayerLeft(false);
     237        // pawn -> addExplosionPart
     238        // this->goWithStyle();
     239
    228240
    229241        // if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
     
    240252
    241253void AsteroidMinable::spawnChildren(){
    242     // Spawn smaller Children
     254   
     255    // Spawn smaller Children
    243256    int massRem = this->size-1; //some mass is lost
    244     int num = round((massRem-1)*rand())+1; // random number of children, at least one
     257    int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one
    245258    massRem = massRem-num;
    246259    int extra = 0;
     
    250263            extra = massRem;
    251264        }else{
    252             extra = round(massRem*rand());
     265            extra = round(massRem*(double)rand() / (double)RAND_MAX);
    253266            massRem = massRem-extra;
    254267        }
    255         //Spawn this child
    256         AsteroidMinable* child = new AsteroidMinable(context);
     268
     269
     270
     271        //Spawn this child  Game crashes!
     272        AsteroidMinable* child = new AsteroidMinable(this->context);
    257273        child->setSize(extra + 1);
    258274           
     
    260276        //Relativ zu Elternteil automatisch?
    261277        //Typ position:rand()*Vektoriwas?
    262         // pawn->getWorldPosition() + Vector3(30,0,-30);
     278        //pawn->getWorldPosition() + Vector3(30,0,-30);
    263279        child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
     280
     281
     282                //         Pawn* pawn = this->carrierToPawnHelper();
     283                // if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
     284                //     this->Pickupable::destroy();
     285
     286                // //Attach to pawn
     287                // Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something)
     288                // drone->addTemplate(this->getDroneTemplate());
     289
     290
    264291    }
    265292}
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h

    r11547 r11551  
    6262        protected:
    6363            // Da neue Argumente reinstellen
    64             float asteroidVersion; // Bodenstrich-Konvention?,
     64            //float asteroidVersion; // Bodenstrich-Konvention?,
    6565            // Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form
    6666            float size;
    6767            bool generateSmaller;
    68             virtual void death();
     68            bool initialised;
     69
     70            Context* context;
     71
     72            virtual void death();
     73            virtual void putStuff();
    6974
    7075
     
    7479            virtual void spawnChildren();
    7580
    76             Context* context;
    7781
    7882
Note: See TracChangeset for help on using the changeset viewer.