[11547] | 1 | |
---|
[11550] | 2 | /* ORXONOX - the hottest 3D action shooter ever to exist |
---|
[11547] | 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * Simon Miescher |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /* |
---|
[11550] | 30 | |
---|
[11547] | 31 | * |
---|
| 32 | * |
---|
| 33 | * An asteroid which can be destroyed. Some smaller asteroids are created and a pickup |
---|
| 34 | * spawns. |
---|
| 35 | * |
---|
| 36 | * |
---|
| 37 | * |
---|
| 38 | |
---|
| 39 | */ |
---|
| 40 | |
---|
[11551] | 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. |
---|
[11547] | 49 | |
---|
[11551] | 50 | - Neue Asteroiden generieren -> Absturz |
---|
| 51 | - Pickup spawning -> Absturz |
---|
[11553] | 52 | |
---|
| 53 | o hat's mit den Context-Eingenschaften zu tun? Je einen Neuen/Aktuellen besorgen? |
---|
| 54 | |
---|
| 55 | Nicht Pointer uebergeben? |
---|
[11551] | 56 | - Manchmal: Absturz bei Zerstoerung eines Asteroiden |
---|
[11553] | 57 | - Was tut 'Register Variables'? |
---|
[11551] | 58 | |
---|
[11553] | 59 | o Error messages: change context::pickups to something else |
---|
[11551] | 60 | |
---|
| 61 | |
---|
[11553] | 62 | OFFEN: |
---|
| 63 | o Add custom pickup 'resources' |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
[11551] | 67 | Erlegt: |
---|
| 68 | o Rand() geht bis zu riesigen Nummern! |
---|
| 69 | */ |
---|
| 70 | |
---|
| 71 | |
---|
[11547] | 72 | #include "../../orxonox/worldentities/pawns/Pawn.h" |
---|
| 73 | #include "../../orxonox/worldentities/WorldEntity.h" |
---|
| 74 | |
---|
| 75 | #include "AsteroidMinable.h" |
---|
| 76 | |
---|
| 77 | #include <algorithm> |
---|
| 78 | |
---|
| 79 | #include "core/CoreIncludes.h" |
---|
| 80 | #include "core/GameMode.h" |
---|
| 81 | #include "core/XMLPort.h" |
---|
| 82 | #include "core/EventIncludes.h" |
---|
| 83 | #include "network/NetworkFunction.h" |
---|
| 84 | |
---|
| 85 | // #include "infos/PlayerInfo.h" |
---|
| 86 | // #include "controllers/Controller.h" |
---|
| 87 | // #include "gametypes/Gametype.h" |
---|
| 88 | // #include "graphics/ParticleSpawner.h" |
---|
| 89 | // #include "worldentities/ExplosionChunk.h" |
---|
| 90 | // #include "worldentities/ExplosionPart.h" |
---|
| 91 | |
---|
| 92 | // #include "core/object/ObjectListIterator.h" |
---|
| 93 | // #include "controllers/FormationController.h" |
---|
| 94 | |
---|
| 95 | #include "../pickup/items/HealthPickup.h" |
---|
| 96 | #include "../pickup/PickupSpawner.h" |
---|
| 97 | #include "../pickup/Pickup.h" |
---|
[11553] | 98 | //#include "../pickup/pickup ..... pickupable |
---|
[11547] | 99 | #include "../objects/collisionshapes/SphereCollisionShape.h" |
---|
| 100 | #include "../../orxonox/graphics/Model.h" |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | namespace orxonox |
---|
| 108 | { |
---|
| 109 | RegisterClass(AsteroidMinable); |
---|
| 110 | |
---|
| 111 | AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context) |
---|
| 112 | { |
---|
| 113 | RegisterObject(AsteroidMinable); |
---|
[11551] | 114 | |
---|
| 115 | // Old stuff from pawn |
---|
[11547] | 116 | this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f)); |
---|
| 117 | this->setRadarObjectShape(RadarViewable::Shape::Dot); |
---|
| 118 | this->setCollisionType(WorldEntity::CollisionType::Dynamic); |
---|
[11551] | 119 | this->bAlive_ = true; |
---|
| 120 | this->bVulnerable_ = true; |
---|
[11547] | 121 | |
---|
[11551] | 122 | |
---|
| 123 | |
---|
| 124 | // Default Values |
---|
[11547] | 125 | this->generateSmaller = true; |
---|
| 126 | //this->size = this->getSize(); // Value doesn-t get accepted. Weird. |
---|
[11551] | 127 | this->size = 10; |
---|
[11547] | 128 | this->context = context; |
---|
[11551] | 129 | this->initialised = false; |
---|
| 130 | //this->roll = rand()*5; //etwas Drehung. richtige Variable |
---|
[11547] | 131 | |
---|
| 132 | |
---|
[11553] | 133 | |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|
[11551] | 140 | // DELETE if other stuff works! (wrong size etc.) |
---|
| 141 | SphereCollisionShape* cs = new SphereCollisionShape(this->context); |
---|
| 142 | cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien |
---|
| 143 | this->attachCollisionShape(cs); |
---|
[11547] | 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | |
---|
[11553] | 148 | |
---|
| 149 | |
---|
[11551] | 150 | // Old from Pawn |
---|
| 151 | this->registerVariables(); |
---|
[11547] | 152 | |
---|
[11551] | 153 | } |
---|
[11547] | 154 | |
---|
[11551] | 155 | AsteroidMinable::~AsteroidMinable() |
---|
| 156 | { |
---|
[11547] | 157 | |
---|
[11551] | 158 | } |
---|
[11547] | 159 | |
---|
[11551] | 160 | void AsteroidMinable::putStuff(){ |
---|
[11547] | 161 | |
---|
[11551] | 162 | // Add Model |
---|
| 163 | //<Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" /> |
---|
| 164 | Model* hull = new Model(this->context); |
---|
| 165 | // random one of the 6 shapes |
---|
| 166 | 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"; |
---|
| 170 | hull->setMeshSource(meshThingy); |
---|
| 171 | hull->setScale(this->size); |
---|
| 172 | this->attach(hull); |
---|
| 173 | //hull->setPosition(this->getPosition()); |
---|
[11547] | 174 | |
---|
[11551] | 175 | // Collision shape |
---|
| 176 | SphereCollisionShape* cs = new SphereCollisionShape(this->context); |
---|
[11553] | 177 | cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien. 2.5 in AsteroidField.lua |
---|
[11551] | 178 | this->attachCollisionShape(cs); |
---|
[11547] | 179 | |
---|
| 180 | |
---|
[11551] | 181 | this->initialised=true; |
---|
[11547] | 182 | } |
---|
| 183 | |
---|
| 184 | void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 185 | { |
---|
| 186 | SUPER(AsteroidMinable, XMLPort, xmlelement, mode); |
---|
| 187 | // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); |
---|
| 188 | XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode); |
---|
| 189 | |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 193 | { |
---|
| 194 | SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode); |
---|
| 195 | |
---|
[11551] | 196 | XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); |
---|
[11547] | 197 | } |
---|
| 198 | |
---|
| 199 | void AsteroidMinable::registerVariables() |
---|
| 200 | { |
---|
| 201 | registerVariable(this->bAlive_, VariableDirection::ToClient); |
---|
| 202 | registerVariable(this->bVulnerable_, VariableDirection::ToClient); |
---|
| 203 | registerVariable(this->health_, VariableDirection::ToClient); |
---|
| 204 | registerVariable(this->maxHealth_, VariableDirection::ToClient); |
---|
[11551] | 205 | |
---|
| 206 | registerVariable(this->size, VariableDirection::ToClient); |
---|
| 207 | registerVariable(this->generateSmaller, VariableDirection::ToClient); |
---|
[11553] | 208 | |
---|
| 209 | registerVariable(this->initialised, VariableDirection::ToClient); |
---|
| 210 | //registerVariable(this->context, VariableDirection::ToClient); // can't link that since it's a context |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | // float size; |
---|
| 214 | // bool generateSmaller; |
---|
| 215 | // bool initialised; |
---|
| 216 | |
---|
| 217 | // Context* context; |
---|
[11547] | 218 | } |
---|
| 219 | |
---|
| 220 | void AsteroidMinable::tick(float dt) |
---|
| 221 | { |
---|
[11551] | 222 | // SUPER(Pawn, tick, dt); |
---|
| 223 | if(!(this->initialised)){this->putStuff();} |
---|
[11547] | 224 | |
---|
[11551] | 225 | if(this->health_ <=0){this->death();} |
---|
| 226 | |
---|
[11547] | 227 | } |
---|
| 228 | |
---|
| 229 | void AsteroidMinable::setSize(float s){ |
---|
| 230 | this->size = s; |
---|
[11551] | 231 | this->health_ = 5*s;// capped at 200 in pawn or smth? |
---|
| 232 | this->setHealth(health_); |
---|
[11547] | 233 | } |
---|
| 234 | |
---|
| 235 | float AsteroidMinable::getSize(){ |
---|
| 236 | return this->size; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | void AsteroidMinable::death() //ueberschreiben |
---|
| 240 | { |
---|
| 241 | |
---|
| 242 | |
---|
[11553] | 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; |
---|
| 247 | } |
---|
| 248 | // hP->setPosition(this->getPosition()); // Does not have a member named 'setPosition' (Inherits from Pickup//BAse Object) |
---|
[11551] | 249 | |
---|
[11553] | 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()); |
---|
[11547] | 255 | //OFFEN: Add custom pickup 'resources' |
---|
| 256 | |
---|
[11553] | 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? |
---|
| 262 | |
---|
| 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); |
---|
[11547] | 268 | // /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance) |
---|
[11553] | 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 | |
---|
[11547] | 278 | |
---|
| 279 | |
---|
[11553] | 280 | // // Smaller Parts |
---|
| 281 | // if(this->generateSmaller){ |
---|
| 282 | // this->spawnChildren(); |
---|
| 283 | // } |
---|
[11547] | 284 | |
---|
[11551] | 285 | |
---|
[11547] | 286 | // OFFEN: Sauber kapputten |
---|
| 287 | // just copied other stuff: |
---|
| 288 | this->setHealth(1); |
---|
| 289 | this->bAlive_ = false; |
---|
| 290 | this->destroyLater(); |
---|
| 291 | this->setDestroyWhenPlayerLeft(false); |
---|
[11551] | 292 | // pawn -> addExplosionPart |
---|
| 293 | // this->goWithStyle(); |
---|
[11547] | 294 | |
---|
[11551] | 295 | |
---|
[11547] | 296 | // if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_)) |
---|
| 297 | // { |
---|
| 298 | // // Set bAlive_ to false and wait for destroyLater() to do the destruction |
---|
| 299 | // this->bAlive_ = false; |
---|
| 300 | // this->destroyLater(); |
---|
| 301 | |
---|
| 302 | // this->setDestroyWhenPlayerLeft(false); |
---|
| 303 | |
---|
| 304 | // } |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | void AsteroidMinable::spawnChildren(){ |
---|
[11551] | 309 | |
---|
| 310 | // Spawn smaller Children |
---|
[11547] | 311 | int massRem = this->size-1; //some mass is lost |
---|
[11551] | 312 | int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one |
---|
[11547] | 313 | massRem = massRem-num; |
---|
| 314 | int extra = 0; |
---|
| 315 | for(int fisch=num; fisch>=1; fisch++){ |
---|
| 316 | // to distribute remaining mass |
---|
| 317 | if(fisch==1){ |
---|
| 318 | extra = massRem; |
---|
| 319 | }else{ |
---|
[11551] | 320 | extra = round(massRem*(double)rand() / (double)RAND_MAX); |
---|
[11547] | 321 | massRem = massRem-extra; |
---|
| 322 | } |
---|
[11551] | 323 | |
---|
| 324 | |
---|
| 325 | |
---|
| 326 | //Spawn this child Game crashes! |
---|
| 327 | AsteroidMinable* child = new AsteroidMinable(this->context); |
---|
[11553] | 328 | // if(!(child == nullptr)){//Errorgebastel |
---|
[11551] | 329 | |
---|
| 330 | |
---|
[11553] | 331 | |
---|
| 332 | if(child == nullptr){ |
---|
| 333 | orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | child->setSize(extra + 1); |
---|
| 337 | |
---|
| 338 | //OFFEN:Kollision der Kinder verhindern |
---|
| 339 | //Relativ zu Elternteil automatisch? |
---|
| 340 | //Typ position:rand()*Vektoriwas? |
---|
| 341 | //pawn->getWorldPosition() + Vector3(30,0,-30); |
---|
| 342 | child->setPosition(this->getPosition() + Vector3(num*5, 0, 0)); |
---|
| 343 | |
---|
| 344 | // } |
---|
| 345 | |
---|
| 346 | |
---|
[11551] | 347 | // Pawn* pawn = this->carrierToPawnHelper(); |
---|
| 348 | // if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. |
---|
| 349 | // this->Pickupable::destroy(); |
---|
| 350 | |
---|
| 351 | // //Attach to pawn |
---|
| 352 | // Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something) |
---|
| 353 | // drone->addTemplate(this->getDroneTemplate()); |
---|
| 354 | |
---|
| 355 | |
---|
[11547] | 356 | } |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | |
---|
| 365 | |
---|
| 366 | |
---|
| 367 | |
---|
| 368 | /* |
---|
| 369 | void DronePickup::changedUsed(void) |
---|
| 370 | { |
---|
| 371 | SUPER(DronePickup, changedUsed); |
---|
| 372 | |
---|
| 373 | // If the pickup has transited to used. |
---|
| 374 | if(this->isUsed()) |
---|
| 375 | { |
---|
| 376 | |
---|
| 377 | Pawn* pawn = this->carrierToPawnHelper(); |
---|
| 378 | if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. |
---|
| 379 | this->Pickupable::destroy(); |
---|
| 380 | |
---|
| 381 | //Attach to pawn |
---|
| 382 | Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something) |
---|
| 383 | drone->addTemplate(this->getDroneTemplate()); |
---|
| 384 | |
---|
| 385 | Controller* controller = drone->getController(); |
---|
| 386 | DroneController* droneController = orxonox_cast<DroneController*>(controller); |
---|
| 387 | if(droneController != nullptr) |
---|
| 388 | { |
---|
| 389 | droneController->setOwner(pawn); |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30); |
---|
| 393 | drone->setPosition(spawnPosition); |
---|
| 394 | |
---|
| 395 | // The pickup has been used up. |
---|
| 396 | this->setUsed(false); |
---|
| 397 | } |
---|
| 398 | else |
---|
| 399 | { |
---|
| 400 | // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused. |
---|
| 401 | if(this->isOnce() || (this->isContinuous() )) |
---|
| 402 | { |
---|
| 403 | this->Pickupable::destroy(); |
---|
| 404 | } |
---|
| 405 | } |
---|
| 406 | } |
---|
[11550] | 407 | */ |
---|