Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Output (printing) of CollisionShape-Structure now works. It uses the btCompoundShape-structure instead of the (Orxonox)CompoundCollisionShape

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