- Timestamp:
- Dec 11, 2017, 6:05:17 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
r11641 r11664 28 28 29 29 /* 30 31 @file AsteroidMinable.cc 30 32 31 33 * … … 45 47 46 48 KNACKPUNKTE: 49 o Super-XML-Argumente werden nicht richtig geparst (Velocity, Pitch, Yaw etc. ) 50 47 51 48 52 OFFEN: … … 58 62 o Density doesn't add up to 1... 59 63 o set collisionDamage? Just for static entities? 60 o AsteroidBelt?61 64 62 65 o Dokumentieren mit @brief? … … 64 67 o Add sound effect (crunching etc. ) (No sound in space...) 65 68 o Explosion parts 66 o custom HUD67 68 69 69 70 HANDBUCH: … … 124 125 #include "util/Math.h" 125 126 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"138 127 #include "../pickup/PickupSpawner.h" 139 128 #include "../pickup/Pickup.h" 140 //#include "../pickup/pickup ..... pickupable 129 141 130 #include "../objects/collisionshapes/SphereCollisionShape.h" 142 131 #include "../../orxonox/graphics/Model.h" 143 132 144 133 145 146 147 148 149 150 namespace orxonox 151 { 134 namespace orxonox{ 135 152 136 RegisterClass(AsteroidMinable); 153 137 … … 156 140 157 141 RegisterObject(AsteroidMinable); 158 159 142 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; 162 151 163 152 //Noetig, damit nicht sofort zerstoert? 164 153 this->setCollisionType(WorldEntity::CollisionType::Dynamic); 154 this->enableCollisionCallback(); 155 165 156 166 157 // Old from Pawn 167 158 this->registerVariables(); 168 159 169 //orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl;160 this->initialised = false; 170 161 171 162 } … … 184 175 } 185 176 186 this->setCollisionType(WorldEntity::CollisionType::Dynamic);187 this->enableCollisionCallback();188 189 // Default Values190 177 this->context = c; 191 178 this->size = size; … … 197 184 198 185 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 204 194 Model* hull = new Model(this->context); 205 // random one of the 6 shapes206 195 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); 208 197 hull->setMeshSource(meshThingy); 209 198 hull->setScale(this->size); … … 212 201 // Collision shape 213 202 SphereCollisionShape* cs = new SphereCollisionShape(this->context); 214 cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien. 2.5 in AsteroidField.lua203 cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien. 215 204 this->attachCollisionShape(cs); 216 205 217 // Old from Pawn218 206 this->registerVariables(); 219 207 220 208 this->initialised=true; 221 209 222 //orxout() << "AsteroidMining:: Initialisierung Zweitkonstruktor abgeschlosssssen." << endl;223 224 210 } 225 211 … … 227 213 228 214 } 215 229 216 // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc. 230 217 void AsteroidMinable::putStuff(){ … … 232 219 // Just create a new asteroid to avoid Collision shape scale problems etc. 233 220 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 235 222 this->bAlive_ = false; 236 223 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 245 231 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 251 239 SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode); 252 240 253 XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); 254 } 255 256 void AsteroidMinable::registerVariables() 257 { 241 } 242 243 void AsteroidMinable::registerVariables(){ 258 244 259 245 registerVariable(this->size, VariableDirection::ToClient); 260 246 registerVariable(this->generateSmaller, VariableDirection::ToClient); 261 247 registerVariable(this->dropStuff, VariableDirection::ToClient); 262 248 registerVariable(this->initialised, VariableDirection::ToClient); 263 249 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 273 254 if(!(this->initialised)){this->putStuff();} 274 255 … … 277 258 } 278 259 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. 290 263 this->bAlive_ = false; 291 264 this->destroyLater(); … … 312 285 thingy->setRespawnTime(0.2f); 313 286 } 314 // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;315 287 316 288 // Smaller Parts = 'Children' 317 289 if(this->generateSmaller){this->spawnChildren();} 318 290 319 // orxout() << "Wieder retour in death() geschafft. " << endl;320 321 291 } 322 292 … … 324 294 void AsteroidMinable::spawnChildren(){// Spawn smaller Children 325 295 326 327 296 if (this->size <=1){return;} // Absicherung trivialer Fall 328 297 … … 331 300 if(num > 10){num = 10;} // no max function in C! 332 301 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; 334 304 335 305 massRem = massRem-num; // mass is at least one, add again below. 336 306 337 307 // 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 340 314 float piG = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so. 341 342 315 float d_p = 2*piG/num; 343 316 float d_t = piG/num; … … 347 320 // float thetaOffset = rnd()*pi; 348 321 float rScaling; // scale radius to prevent asteroids from touching. (distance=AsteroidRadius/tan(sector/2)) 322 349 323 if(num == 1 ){ 350 324 rScaling = 1; // avoid tan(90). Unused. … … 404 378 result = 0;// reset 405 379 rVal = rnd();// between 0 and 1 406 // orxout() << "Random Value picked: " << rVal << endl;407 380 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!) 411 383 if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error 412 384 ++result; 413 // orxout() << "Sum so far: " << probSum << ". Just added " << probDensity[result+1] << endl;414 385 } 415 386 416 387 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;} 425 392 } 426 393 … … 437 404 } 438 405 439 // orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;440 406 AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->getVelocity(), this->dropStuff); 441 407
Note: See TracChangeset
for help on using the changeset viewer.