- Timestamp:
- Nov 7, 2017, 5:47:14 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
r11550 r11551 37 37 * 38 38 39 */ 40 41 /* 42 Veraenderungstagebuch 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 56 Erlegt: 57 o Rand() geht bis zu riesigen Nummern! 39 58 */ 40 59 … … 70 89 71 90 72 /* 73 Veraenderungstagebuch 74 - Dynamische Definition von Argumenten funktioniert nicht 75 - Death-Methode -> Absturz 76 77 78 79 80 */ 91 81 92 82 93 … … 89 100 { 90 101 RegisterObject(AsteroidMinable); 102 103 // Old stuff from pawn 91 104 this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f)); 92 105 this->setRadarObjectShape(RadarViewable::Shape::Dot); 93 94 106 this->setCollisionType(WorldEntity::CollisionType::Dynamic); 95 107 this->bAlive_ = true; 108 this->bVulnerable_ = true; 109 110 111 112 // Default Values 96 113 this->generateSmaller = true; 97 114 //this->size = this->getSize(); // Value doesn-t get accepted. Weird. 98 this->size = 5;115 this->size = 10; 99 116 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" /> 102 143 Model* hull = new Model(this->context); 103 144 // 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)); 106 147 // sprintf(str, "Value of Pi = %f", M_PI); 107 char meshThingy[] = "ast5.mesh"; 108 109 148 //char meshThingy[] = "ast5.mesh"; 110 149 hull->setMeshSource(meshThingy); 111 hull->setScale( size);150 hull->setScale(this->size); 112 151 this->attach(hull); 113 152 //hull->setPosition(this->getPosition()); 114 153 154 // Collision shape 115 155 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; 158 162 } 159 163 … … 170 174 SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode); 171 175 172 //XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);176 XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); 173 177 } 174 178 … … 179 183 registerVariable(this->health_, VariableDirection::ToClient); 180 184 registerVariable(this->maxHealth_, VariableDirection::ToClient); 185 186 registerVariable(this->size, VariableDirection::ToClient); 187 registerVariable(this->generateSmaller, VariableDirection::ToClient); 181 188 } 182 189 183 190 void AsteroidMinable::tick(float dt) 184 191 { 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();} 189 196 190 197 } … … 192 199 void AsteroidMinable::setSize(float s){ 193 200 this->size = s; 194 this->health_ = 200*s; 201 this->health_ = 5*s;// capped at 200 in pawn or smth? 202 this->setHealth(health_); 195 203 } 196 204 … … 202 210 { 203 211 204 // pawn -> addExplosionPart 205 // this.goWithStyle() 206 207 // 208 HealthPickup* hP = new HealthPickup( context);212 213 214 215 //Spawn Pickup 216 HealthPickup* hP = new HealthPickup(this->context); 209 217 //OFFEN: Add custom pickup 'resources' 210 PickupSpawner* thingy = new PickupSpawner( context);218 PickupSpawner* thingy = new PickupSpawner(this->context); 211 219 thingy->setPosition(this->getPosition()); 212 thingy->createDroppedPickup( context, hP, nullptr, 10);220 thingy->createDroppedPickup(this->context, hP, nullptr, 10); 213 221 214 222 // /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance) 215 223 216 224 217 225 // Smaller Parts 218 226 if(this->generateSmaller){ 219 227 this->spawnChildren(); 220 228 } 229 221 230 222 231 // OFFEN: Sauber kapputten … … 226 235 this->destroyLater(); 227 236 this->setDestroyWhenPlayerLeft(false); 237 // pawn -> addExplosionPart 238 // this->goWithStyle(); 239 228 240 229 241 // if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_)) … … 240 252 241 253 void AsteroidMinable::spawnChildren(){ 242 // Spawn smaller Children 254 255 // Spawn smaller Children 243 256 int massRem = this->size-1; //some mass is lost 244 int num = round((massRem-1)* rand())+1; // random number of children, at least one257 int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one 245 258 massRem = massRem-num; 246 259 int extra = 0; … … 250 263 extra = massRem; 251 264 }else{ 252 extra = round(massRem* rand());265 extra = round(massRem*(double)rand() / (double)RAND_MAX); 253 266 massRem = massRem-extra; 254 267 } 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); 257 273 child->setSize(extra + 1); 258 274 … … 260 276 //Relativ zu Elternteil automatisch? 261 277 //Typ position:rand()*Vektoriwas? 262 // 278 //pawn->getWorldPosition() + Vector3(30,0,-30); 263 279 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 264 291 } 265 292 }
Note: See TracChangeset
for help on using the changeset viewer.