- Timestamp:
- Dec 4, 2017, 4:38:17 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
r11618 r11640 43 43 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 44 44 45 FRAGEN:46 * Zeilen-Loeschung beim output47 * orxout()-Problem48 * dokumentieren mit @brief?49 * Warnumg aus Asteroidenzerstoerung50 51 45 52 46 KNACKPUNKTE: 53 47 54 55 48 OFFEN: 56 57 o Mass distribution -> weird for bigger asteroids58 --> more testing59 60 o SpicedAsteroidField fertigstellen, Mineraldichten-Parameter61 49 62 50 o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources. … … 65 53 ----> im MineralsPickup die isPickedUp()-Methode überschreiben? 66 54 --> 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 57 o Anfangsgeschwindigkeit fuers Asteroidenfeld 58 o Density doesn't add up to 1... 69 59 o set collisionDamage? Just for static entities? 60 o AsteroidBelt? 61 70 62 o Dokumentieren mit @brief? 71 63 o unregister -empty- asteroids from radar. (or turn them green or whatever) 64 o Add sound effect (crunching etc. ) (No sound in space...) 72 65 o Explosion parts 73 66 o custom HUD 67 74 68 75 69 HANDBUCH: … … 85 79 o Pawn.h: Attribut acceptsPickups_ inklusive get/set. 86 80 87 ERLEGT :81 ERLEGTE FEHLER: 88 82 o Rand() geht bis zu riesigen Nummern! 89 83 o Pickupgenerierung: vgl. Fremdanpassungen. … … 158 152 RegisterClass(AsteroidMinable); 159 153 160 161 // This constructor is for XML access only. 154 // @brief Standard constructor 162 155 AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context){ 163 156 164 // Da auch noetig? Wegen set in XML-Code?165 157 RegisterObject(AsteroidMinable); 166 158 167 159 this->context = context; 168 160 this->initialised = false; 161 this->dropStuff = true; // Default 169 162 170 163 //Noetig, damit nicht sofort zerstoert? … … 178 171 } 179 172 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){ 182 175 183 176 RegisterObject(AsteroidMinable); 184 177 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 188 186 this->setCollisionType(WorldEntity::CollisionType::Dynamic); 189 190 187 this->enableCollisionCallback(); 191 188 192 189 // Default Values 193 this->generateSmaller = true;194 190 this->context = c; 195 191 this->size = size; 196 192 this->health_ = 15*size; 197 193 this->maxHealth_ = this->health_; 198 this->acceptsPickups_ = false; 194 this->acceptsPickups_ = false; 195 this->generateSmaller = true; 196 this->dropStuff = dropStuff; 199 197 200 198 this->setPosition(position); 199 this->setVelocity(v); // velocity = v; // The right one? 201 200 //this->roll = rand()*5; //etwas Drehung. richtige Variable 202 201 … … 228 227 229 228 } 230 229 // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc. 231 230 void AsteroidMinable::putStuff(){ 232 231 233 232 // 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); 235 234 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? 237 238 238 239 } … … 276 277 } 277 278 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 289 280 290 281 … … 304 295 305 296 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 } 322 314 // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl; 323 315 … … 339 331 if(num > 10){num = 10;} // no max function in C! 340 332 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; 342 334 343 335 massRem = massRem-num; // mass is at least one, add again below. … … 346 338 float phi[num] = {0.0}; // assuming that it gets initialised to 0. Add (= {0.0})? 347 339 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. 349 341 350 342 float d_p = 2*piG/num; … … 380 372 //orxout() << "SpawnChildren(): Phi: "; printArrayString(phi); 381 373 //orxout() << "SpawnChildren(): Theta: "; printArrayString(theta); 382 orxout() << "SpawnChildren(): Passed angle stuff. " << endl;383 384 // 'Triangular', discrete probability densitywith max at the expected value massRem/num at a. a+b = c374 //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 385 377 if(massRem>0){ // Required to avoid array of size 0 or access problems 386 378 int c = massRem; … … 397 389 for(z = 0; z<b; ++z){probDensity[c-z] = (z+1)*dProbB;} // falling part 398 390 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; 403 398 404 399 // Distributing the mass to individual asteroids … … 409 404 result = 0;// reset 410 405 rVal = rnd();// between 0 and 1 411 orxout() << "Random Value picked: " << rVal << endl;406 // orxout() << "Random Value picked: " << rVal << endl; 412 407 probSum = probDensity[0]; 413 408 //orxout() << "Sum at start: " << probSum << endl; 414 409 415 410 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 error411 if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error 417 412 ++result; 418 // orxout() << "Sum so far: " << probSum <<endl;413 // orxout() << "Sum so far: " << probSum << ". Just added " << probDensity[result+1] << endl; 419 414 } 420 415 421 416 massRem = massRem-result; 422 417 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; 424 419 425 420 } … … 430 425 } 431 426 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; 434 429 435 430 // Creating the 'chlidren': … … 442 437 } 443 438 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); 446 441 447 442 if(child == nullptr){ … … 450 445 451 446 } 452 orxout() << "Leaving spawnChildren() method. " << endl;447 // orxout() << "Leaving spawnChildren() method. " << endl; 453 448 } 454 449 … … 458 453 orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl; 459 454 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. 461 456 // Wird staending aufgerufen -> Rechenleistung? 462 457 if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;} … … 496 491 } 497 492 493 // @brief Just for testing. Don-t work anyways. 498 494 void AsteroidMinable::printArrayString(float thingy[]){ // Don-t work! 499 495 … … 509 505 } 510 506 507 // @brief Just for testing. Don-t work anyways. 511 508 void AsteroidMinable::printArrayString(int thingy[]){ 512 509 … … 524 521 } 525 522 526 527 523 // void AsteroidMinable::printArrayString(int thingy[]){ 528 529 524 // char res[] = "["; 530 525 // //strcat(res, "["); … … 547 542 // } 548 543 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 // @brief577 // Virtual function that gets called when this object collides with another.578 // @param otherObject579 // The object this one has collided into.580 // @param ownCollisionShape581 // The collision shape of the other object582 // @param contactPoint583 // Contact point provided by Bullet. Holds more information and can me modified. See return value.584 // @return585 // Returning false means that no modification to the contactPoint has been made. Return true otherwise!586 // @note587 // 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() const605 // { 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 response613 // inline bool hasCollisionResponse()614 // { return this->bCollisionResponseActive_; }615 616 617 544 } 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 pawn637 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 else654 {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.