Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc @ 10001

Last change on this file since 10001 was 10001, checked in by noep, 10 years ago

Tried (and failed) to fix output of CollisionShape-structure

  • Property svn:eol-style set to native
File size: 25.4 KB
RevLine 
[2072]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
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:
[8706]25 *      Simon Miescher
[2072]26 *
27 */
28
29#include "Pawn.h"
30
[3280]31#include <algorithm>
32
[3196]33#include "core/CoreIncludes.h"
[2896]34#include "core/GameMode.h"
[2072]35#include "core/XMLPort.h"
[3196]36#include "network/NetworkFunction.h"
37
[5735]38#include "infos/PlayerInfo.h"
[6417]39#include "controllers/Controller.h"
[5735]40#include "gametypes/Gametype.h"
[5737]41#include "graphics/ParticleSpawner.h"
[5735]42#include "worldentities/ExplosionChunk.h"
43#include "worldentities/BigExplosion.h"
44#include "weaponsystem/WeaponSystem.h"
45#include "weaponsystem/WeaponSlot.h"
46#include "weaponsystem/WeaponPack.h"
47#include "weaponsystem/WeaponSet.h"
[9939]48#include "sound/WorldSound.h"
[2072]49
[9625]50#include "controllers/FormationController.h"
51
[9997]52#include "collisionshapes/WorldEntityCollisionShape.h"
[10001]53#include <BulletCollision/CollisionShapes/btCollisionShape.h>
[9997]54
[2072]55namespace orxonox
56{
[9667]57    RegisterClass(Pawn);
[2072]58
[9667]59    Pawn::Pawn(Context* context)
60        : ControllableEntity(context)
61        , RadarViewable(this, static_cast<WorldEntity*>(this))
[2072]62    {
63        RegisterObject(Pawn);
64
[2662]65        this->bAlive_ = true;
[3053]66        this->bReload_ = false;
[2072]67
68        this->health_ = 0;
69        this->maxHealth_ = 0;
70        this->initialHealth_ = 0;
[8706]71
[7163]72        this->shieldHealth_ = 0;
[8706]73        this->initialShieldHealth_ = 0;
74        this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max
[7163]75        this->shieldAbsorption_ = 0.5;
[2072]76
[8706]77        this->reloadRate_ = 0;
78        this->reloadWaitTime_ = 1.0f;
79        this->reloadWaitCountdown_ = 0;
80
[2072]81        this->lastHitOriginator_ = 0;
82
[9348]83        // set damage multiplier to default value 1, meaning nominal damage
84        this->damageMultiplier_ = 1;
85
[2662]86        this->spawnparticleduration_ = 3.0f;
[2098]87
[6417]88        this->aimPosition_ = Vector3::ZERO;
89
[2896]90        if (GameMode::isMaster())
[2662]91        {
[9667]92            this->weaponSystem_ = new WeaponSystem(this->getContext());
[3053]93            this->weaponSystem_->setPawn(this);
[2662]94        }
95        else
96            this->weaponSystem_ = 0;
97
98        this->setRadarObjectColour(ColourValue::Red);
99        this->setRadarObjectShape(RadarViewable::Dot);
100
[2072]101        this->registerVariables();
[3089]102
103        this->isHumanShip_ = this->hasLocalController();
[8891]104
[8329]105        this->setSyncMode(ObjectDirection::Bidirectional); // needed to synchronise e.g. aimposition
[9939]106
107        if (GameMode::isMaster())
108        {
109            this->explosionSound_ = new WorldSound(this->getContext());
110            this->explosionSound_->setVolume(1.0f);
111        }
112        else
113        {
114            this->explosionSound_ = 0;
115        }
[2072]116    }
117
118    Pawn::~Pawn()
119    {
[2662]120        if (this->isInitialized())
121        {
122            if (this->weaponSystem_)
[5929]123                this->weaponSystem_->destroy();
[2662]124        }
[2072]125    }
126
127    void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode)
128    {
129        SUPER(Pawn, XMLPort, xmlelement, mode);
130
[2662]131        XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
[2072]132        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
133        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
[7163]134
135        XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
[8706]136        XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
137        XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
[7163]138        XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
139
[2662]140        XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
141        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
142        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
143
[3053]144        XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode);
145        XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
[6417]146        XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode);
[8706]147
148        XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
149        XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
[9254]150
[9939]151        XMLPortParam(Pawn, "explosionSound",  setExplosionSound,  getExplosionSound,  xmlelement, mode);
152
[9257]153        XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode );
[2072]154    }
155
156    void Pawn::registerVariables()
157    {
[7163]158        registerVariable(this->bAlive_,           VariableDirection::ToClient);
159        registerVariable(this->health_,           VariableDirection::ToClient);
[8706]160        registerVariable(this->maxHealth_,        VariableDirection::ToClient);
[7163]161        registerVariable(this->shieldHealth_,     VariableDirection::ToClient);
[8706]162        registerVariable(this->maxShieldHealth_,  VariableDirection::ToClient);
[7163]163        registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
164        registerVariable(this->bReload_,          VariableDirection::ToServer);
165        registerVariable(this->aimPosition_,      VariableDirection::ToServer);  // For the moment this variable gets only transfered to the server
[2072]166    }
167
168    void Pawn::tick(float dt)
169    {
[2809]170        SUPER(Pawn, tick, dt);
[2072]171
[3053]172        this->bReload_ = false;
[2662]173
[8706]174        // TODO: use the existing timer functions instead
175        if(this->reloadWaitCountdown_ > 0)
176        {
177            this->decreaseReloadCountdownTime(dt);
178        }
179        else
180        {
181            this->addShieldHealth(this->getReloadRate() * dt);
182            this->resetReloadCountdown();
183        }
184
[3084]185        if (GameMode::isMaster())
[8706]186        {
[3087]187            if (this->health_ <= 0 && bAlive_)
[6864]188            {
[8706]189                this->fireEvent(); // Event to notify anyone who wants to know about the death.
[3087]190                this->death();
[6864]191            }
[8706]192        }
[2072]193    }
194
[7889]195    void Pawn::preDestroy()
196    {
197        // yay, multiple inheritance!
198        this->ControllableEntity::preDestroy();
199        this->PickupCarrier::preDestroy();
200    }
201
[2826]202    void Pawn::setPlayer(PlayerInfo* player)
203    {
204        ControllableEntity::setPlayer(player);
205
206        if (this->getGametype())
207            this->getGametype()->playerStartsControllingPawn(player, this);
208    }
209
210    void Pawn::removePlayer()
211    {
212        if (this->getGametype())
213            this->getGametype()->playerStopsControllingPawn(this->getPlayer(), this);
214
215        ControllableEntity::removePlayer();
216    }
217
[8706]218
[2072]219    void Pawn::setHealth(float health)
220    {
[8706]221        this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit
[2072]222    }
223
[8706]224    void Pawn::setShieldHealth(float shieldHealth)
[2072]225    {
[8706]226        this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_);
227    }
228
229    void Pawn::setMaxShieldHealth(float maxshieldhealth)
230    {
231        this->maxShieldHealth_ = maxshieldhealth;
232    }
233
234    void Pawn::setReloadRate(float reloadrate)
235    {
236        this->reloadRate_ = reloadrate;
237    }
238
239    void Pawn::setReloadWaitTime(float reloadwaittime)
240    {
241        this->reloadWaitTime_ = reloadwaittime;
242    }
243
244    void Pawn::decreaseReloadCountdownTime(float dt)
245    {
246        this->reloadWaitCountdown_ -= dt;
247    }
248
249    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator)
250    {
[9348]251        // Applies multiplier given by the DamageBoost Pickup.
252        if (originator)
253            damage *= originator->getDamageMultiplier();
254
[2826]255        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
256        {
[8706]257            if (shielddamage >= this->getShieldHealth())
[7163]258            {
259                this->setShieldHealth(0);
[8706]260                this->setHealth(this->health_ - (healthdamage + damage));
[7163]261            }
[8706]262            else
263            {
264                this->setShieldHealth(this->shieldHealth_ - shielddamage);
[7163]265
[8706]266                // remove remaining shieldAbsorpton-Part of damage from shield
267                shielddamage = damage * this->shieldAbsorption_;
268                shielddamage = std::min(this->getShieldHealth(),shielddamage);
269                this->setShieldHealth(this->shieldHealth_ - shielddamage);
[7163]270
[8706]271                // set remaining damage to health
272                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
[7163]273            }
274
[2826]275            this->lastHitOriginator_ = originator;
276        }
[2072]277    }
278
[9995]279    void Pawn::customDamage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
280    {
[10001]281        orxout() << "damage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl;
282
[9997]283        int collisionShapeIndex = this->isMyCollisionShape(cs);
284        orxout() << collisionShapeIndex << endl;
285
[9995]286        // Applies multiplier given by the DamageBoost Pickup.
287        if (originator)
288            damage *= originator->getDamageMultiplier();
289
290        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
291        {
292            if (shielddamage >= this->getShieldHealth())
293            {
294                this->setShieldHealth(0);
295                this->setHealth(this->health_ - (healthdamage + damage));
296            }
297            else
298            {
299                this->setShieldHealth(this->shieldHealth_ - shielddamage);
300
301                // remove remaining shieldAbsorpton-Part of damage from shield
302                shielddamage = damage * this->shieldAbsorption_;
303                shielddamage = std::min(this->getShieldHealth(),shielddamage);
304                this->setShieldHealth(this->shieldHealth_ - shielddamage);
305
306                // set remaining damage to health
307                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
308            }
309
310            this->lastHitOriginator_ = originator;
311        }
312    }
313
[8706]314// TODO: Still valid?
315/* HIT-Funktionen
316    Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte)
317
318*/
319    void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage)
[2072]320    {
[6417]321        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
[2826]322        {
[8706]323            this->damage(damage, healthdamage, shielddamage, originator);
[2826]324            this->setVelocity(this->getVelocity() + force);
325        }
[2072]326    }
327
[9995]328    void Pawn::customHit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
329    {
330        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
331        {
332            this->customDamage(damage, healthdamage, shielddamage, originator, cs);
333            this->setVelocity(this->getVelocity() + force);
334        }
335    }
[8706]336
337    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage)
[6417]338    {
339        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
340        {
[8706]341            this->damage(damage, healthdamage, shielddamage, originator);
[6417]342
343            if ( this->getController() )
[8706]344                this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
[6417]345        }
346    }
347
[9995]348    void Pawn::customHit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
349    {
350        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
351        {
352            this->customDamage(damage, healthdamage, shielddamage, originator, cs);
[8706]353
[9995]354            if ( this->getController() )
355                this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
356        }
357    }
358
359
[2072]360    void Pawn::kill()
361    {
[9945]362        this->damage(this->health_);
[2072]363        this->death();
364    }
365
[2662]366    void Pawn::spawneffect()
[2072]367    {
368        // play spawn effect
[6417]369        if (!this->spawnparticlesource_.empty())
[2662]370        {
[9667]371            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
[2662]372            effect->setPosition(this->getPosition());
373            effect->setOrientation(this->getOrientation());
374            effect->setDestroyAfterLife(true);
375            effect->setSource(this->spawnparticlesource_);
376            effect->setLifetime(this->spawnparticleduration_);
377        }
[2072]378    }
379
[9625]380
[2072]381    void Pawn::death()
382    {
[3033]383        this->setHealth(1);
[2826]384        if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
385        {
[9945]386            // Set bAlive_ to false and wait for PawnManager to do the destruction
[2826]387            this->bAlive_ = false;
[2662]388
[2826]389            this->setDestroyWhenPlayerLeft(false);
[2662]390
[2826]391            if (this->getGametype())
392                this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
[2662]393
[3038]394            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
[9625]395            {
[9663]396                // Start to control a new entity if you're the master of a formation
397                if(this->hasSlaves())
398                {
399                    Controller* slave = this->getSlave();
400                    ControllableEntity* entity = slave->getControllableEntity();
[2072]401
[9625]402
[9663]403                    if(!entity->hasHumanController())
404                    {
[9666]405                        // delete the AIController // <-- TODO: delete? nothing is deleted here... should we delete the controller?
[9663]406                        slave->setControllableEntity(0);
[9625]407
[9663]408                        // set a new master within the formation
409                        orxonox_cast<FormationController*>(this->getController())->setNewMasterWithinFormation(orxonox_cast<FormationController*>(slave));
[9625]410
[9663]411                        // start to control a slave
412                        this->getPlayer()->startControl(entity);
413                    }
414                    else
415                    {
416                        this->getPlayer()->stopControl();
417                    }
[9625]418
[9663]419                }
420                else
421                {
422                    this->getPlayer()->stopControl();
423                }
[9625]424            }
[2896]425            if (GameMode::isMaster())
[3087]426            {
427//                this->deathEffect();
428                this->goWithStyle();
429            }
[2826]430        }
[2662]431    }
[3087]432    void Pawn::goWithStyle()
433    {
434        this->bAlive_ = false;
435        this->setDestroyWhenPlayerLeft(false);
[2072]436
[9949]437        BigExplosion* chunk = new BigExplosion(this->getContext());
[3087]438        chunk->setPosition(this->getPosition());
[9949]439        chunk->setVelocity(this->getVelocity());
[3087]440
[9947]441        this->explosionSound_->setPosition(this->getPosition());
442        this->explosionSound_->play();
[3087]443    }
[2662]444    void Pawn::deatheffect()
445    {
[2072]446        // play death effect
[2662]447        {
[9667]448            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
[2662]449            effect->setPosition(this->getPosition());
450            effect->setOrientation(this->getOrientation());
451            effect->setDestroyAfterLife(true);
452            effect->setSource("Orxonox/explosion2b");
453            effect->setLifetime(4.0f);
454        }
455        {
[9667]456            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
[2662]457            effect->setPosition(this->getPosition());
458            effect->setOrientation(this->getOrientation());
459            effect->setDestroyAfterLife(true);
460            effect->setSource("Orxonox/smoke6");
461            effect->setLifetime(4.0f);
462        }
463        {
[9667]464            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
[2662]465            effect->setPosition(this->getPosition());
466            effect->setOrientation(this->getOrientation());
467            effect->setDestroyAfterLife(true);
468            effect->setSource("Orxonox/sparks");
469            effect->setLifetime(4.0f);
470        }
471        for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
472        {
[9667]473            ExplosionChunk* chunk = new ExplosionChunk(this->getContext());
[2662]474            chunk->setPosition(this->getPosition());
475        }
[2072]476    }
477
[6417]478    void Pawn::fired(unsigned int firemode)
[2098]479    {
[6417]480        if (this->weaponSystem_)
481            this->weaponSystem_->fire(firemode);
[2098]482    }
483
[3053]484    void Pawn::reload()
485    {
486        this->bReload_ = true;
487    }
488
[2072]489    void Pawn::postSpawn()
490    {
491        this->setHealth(this->initialHealth_);
[2896]492        if (GameMode::isMaster())
[2662]493            this->spawneffect();
[2072]494    }
[2662]495
[2893]496    /* WeaponSystem:
497    *   functions load Slot, Set, Pack from XML and make sure all parent-pointers are set.
498    *   with setWeaponPack you can not just load a Pack from XML but if a Pack already exists anywhere, you can attach it.
499    *       --> e.g. Pickup-Items
500    */
[3053]501    void Pawn::addWeaponSlot(WeaponSlot * wSlot)
[2662]502    {
503        this->attach(wSlot);
504        if (this->weaponSystem_)
[3053]505            this->weaponSystem_->addWeaponSlot(wSlot);
[2662]506    }
507
508    WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const
509    {
510        if (this->weaponSystem_)
[3053]511            return this->weaponSystem_->getWeaponSlot(index);
[2662]512        else
513            return 0;
514    }
515
[3053]516    void Pawn::addWeaponSet(WeaponSet * wSet)
[2662]517    {
518        if (this->weaponSystem_)
[3053]519            this->weaponSystem_->addWeaponSet(wSet);
[2662]520    }
521
[3053]522    WeaponSet * Pawn::getWeaponSet(unsigned int index) const
[2662]523    {
524        if (this->weaponSystem_)
[3053]525            return this->weaponSystem_->getWeaponSet(index);
[2662]526        else
527            return 0;
528    }
529
[3053]530    void Pawn::addWeaponPack(WeaponPack * wPack)
[2662]531    {
532        if (this->weaponSystem_)
[7163]533        {
[3053]534            this->weaponSystem_->addWeaponPack(wPack);
[7163]535            this->addedWeaponPack(wPack);
536        }
[2662]537    }
538
[6417]539    void Pawn::addWeaponPackXML(WeaponPack * wPack)
540    {
541        if (this->weaponSystem_)
[7163]542        {
[6417]543            if (!this->weaponSystem_->addWeaponPack(wPack))
544                wPack->destroy();
[7163]545            else
546                this->addedWeaponPack(wPack);
547        }
[6417]548    }
549
[3053]550    WeaponPack * Pawn::getWeaponPack(unsigned int index) const
[2662]551    {
552        if (this->weaponSystem_)
[3053]553            return this->weaponSystem_->getWeaponPack(index);
[2662]554        else
555            return 0;
556    }
557
[3089]558    //Tell the Map (RadarViewable), if this is a playership
559    void Pawn::startLocalHumanControl()
560    {
561//        SUPER(ControllableEntity, changedPlayer());
562        ControllableEntity::startLocalHumanControl();
563        this->isHumanShip_ = true;
564    }
[8891]565
566    void Pawn::changedVisibility(void)
567    {
568        SUPER(Pawn, changedVisibility);
[9254]569
570        // enable proper radarviewability when the visibility is changed
571        this->RadarViewable::settingsChanged();
[8891]572    }
573
[9625]574
575    // A function to check if this pawn's controller is the master of any formationcontroller
576    bool Pawn::hasSlaves()
577    {
[9663]578        for (ObjectList<FormationController>::iterator it =
579             ObjectList<FormationController>::begin();
580             it != ObjectList<FormationController>::end(); ++it )
581        {
582            // checks if the pawn's controller has a slave
583            if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController())
584                return true;
585        }
586        return false;
[9625]587    }
588
589    // A function that returns a slave of the pawn's controller
590    Controller* Pawn::getSlave(){
[9663]591        for (ObjectList<FormationController>::iterator it =
592                ObjectList<FormationController>::begin();
593                it != ObjectList<FormationController>::end(); ++it )
594        {
595            if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController())
596                return it->getController();
597        }
598        return 0;
[9625]599    }
600
601
[9939]602    void Pawn::setExplosionSound(const std::string &explosionSound)
603    {
604        if(explosionSound_ )
605            explosionSound_->setSource(explosionSound);
606        else
607            assert(0); // This should never happen, because soundpointer is only available on master
608    }
[9625]609
[9939]610    const std::string& Pawn::getExplosionSound()
611    {
612        if( explosionSound_ )
613            return explosionSound_->getSource();
614        else
615            assert(0);
616        return BLANKSTRING;
617    }
618
[9997]619    // WIP function that (once I get it working) determines to which attached entity a collisionshape belongs.
620    // Shame that this doesn't seem to work as intended. It behaves differently (different number of childshapes) every reload. D:
621    int Pawn::isMyCollisionShape(const btCollisionShape* cs)
622    {
623        // This entities WECS
624        WorldEntityCollisionShape* ownWECS = this->getWorldEntityCollisionShape();
[9939]625
[9997]626        // e.g. "Box 4: Searching for CS 0x1ad49200"
[10001]627        orxout() << this->getRadarName() << ": Searching for btCS* " << cs << endl;
[9997]628        // e.g. "Box 4 is WorldEntityCollisionShape 0x126dd060"
[10001]629        orxout() << "  " << this->getRadarName() << " is WorldEntityCollisionShape* " << ownWECS << endl;
630        // e.g. "Box 4 is btCollisionShape 0x126dd060"
631        orxout() << "  " << this->getRadarName() << " is btCollisionShape* " << ownWECS->getCollisionShape() << endl;
[9997]632        // e.g. "Box 4 is objectID 943"
633        orxout() << "  " << this->getRadarName() << " is objectID " << this->getObjectID() << endl;
634
635        // print child shapes of this WECS
[10001]636        // printChildShapes(ownWECS, 2, 0);
637        printChildShapeMap(ownWECS->getShapesMap());
[9997]638
[10001]639
[9997]640        // end
641        orxout() << "  " << this->getRadarName() << ": no matching CS found." << endl;
642        return -1;
643    }
644
645    void Pawn::printChildShapes(CompoundCollisionShape* cs, int indent, int subshape)
646    {
[10001]647        for (int i=0; i < cs->getNumChildShapes(); i++)
648        {
649            orxout() << "" << endl;
650        }
651        /*
[9997]652        // e.g. "  Childshape 1 (WECS 0x126dc8c0) has 2 childshapes:"
[10001]653        printSpaces(indent);  orxout() << "Childshape " << subshape << " (CS* " << cs << ") has " << cs->getNumChildShapes() << " childshapes:" << endl;
[9997]654
[10001]655        // e.g. "Box 4 is WorldEntityCollisionShape 0x126dd060"
656        printSpaces(indent);  orxout() << "Childshape " << subshape << " is btCollisionShape* " << cs->getCollisionShape() << endl;
657
[9997]658        for (int i=0; i < cs->getNumChildShapes(); i++)
659        {
[10001]660            printSpaces(indent+2);  orxout() << "- " << i << " - - -" << endl;
661            printSpaces(indent+2);  orxout() << "This Shape is a ";
662            if (orxonox_cast<WorldEntityCollisionShape*>(cs->getAttachedShape(i)))
663                orxout() << "WECS ";
664            if (orxonox_cast<CompoundCollisionShape*>(cs->getAttachedShape(i)))
665                orxout() << "CCS ";
666            if (orxonox_cast<CollisionShape*>(cs->getAttachedShape(i)))
667                orxout() << "CS ";
668            orxout() << endl;
669
[9997]670            // For each childshape, print:
[10001]671
672            // parentID of the CollisionShape
673            printSpaces(indent+2);  orxout() << "ParentID: " << cs->getAttachedShape(i)->getObjectID() << endl;
674
675            // parentID of the CollisionShape
676            printSpaces(indent+2);  orxout() << "ParentID: " << cs->getAttachedShape(i)->getParentID() << endl;
677
678            // parent of the CollisionShape
679            printSpaces(indent+2);  orxout() << "ParentCCS*: " << cs->getAttachedShape(i)->getParent() << endl;
680
[9997]681            // pointer to the btCollisionShape
[10001]682            printSpaces(indent+2);  orxout() << "btCollisionShape*: " << cs->getAttachedShape(i)->getCollisionShape() << endl;
[9997]683
684            // pointer to the CollisionShape
[10001]685            printSpaces(indent+2);  orxout() << "CollisionShape*: " << cs->getAttachedShape(i) << endl;
[9997]686
[10001]687            if (cs->getAttachedShape(i)->getCollisionShape() != NULL)
688            {
689                // pointer to the user of the btCollisionShape
690                printSpaces(indent+2);  orxout() << "bt: getUserPointer: " << cs->getAttachedShape(i)->getCollisionShape()->getUserPointer() << endl;
[9997]691
[10001]692                //
693                printSpaces(indent+2);  orxout() << "bt: isCompound: " << cs->getAttachedShape(i)->getCollisionShape()->isCompound() << endl;
694            }
695
[9997]696            // if the childshape is a CompoundCollisionShape, print its children.
697            if (orxonox_cast<CompoundCollisionShape*>(cs->getAttachedShape(i)))
698            {
699                printChildShapes((CompoundCollisionShape*)(cs->getAttachedShape(i)), indent+2, i);
700            }
[10001]701            */
[9997]702        }
703    }
704
[10001]705    void Pawn::printChildShapeMap(std::map<CollisionShape*, btCollisionShape*> map)
706    {
707        orxout() << endl;
708    }
709
[9997]710    void Pawn::printSpaces(int number)
711    {
712        for(int i=0; i<number; i++)
713            orxout() << " ";
714    }
[2072]715}
Note: See TracBrowser for help on using the repository browser.