Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/worldentities/pawns/Pawn.cc @ 12035

Last change on this file since 12035 was 11783, checked in by landauf, 7 years ago

merged Presentation_HS17_merge back to trunk

  • Property svn:eol-style set to native
File size: 21.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"
[11052]36#include "core/EventIncludes.h"
[3196]37#include "network/NetworkFunction.h"
38
[5735]39#include "infos/PlayerInfo.h"
[6417]40#include "controllers/Controller.h"
[5735]41#include "gametypes/Gametype.h"
[5737]42#include "graphics/ParticleSpawner.h"
[5735]43#include "worldentities/ExplosionChunk.h"
[11052]44#include "worldentities/ExplosionPart.h"
[5735]45#include "weaponsystem/WeaponSystem.h"
46#include "weaponsystem/WeaponSlot.h"
47#include "weaponsystem/WeaponPack.h"
48#include "weaponsystem/WeaponSet.h"
[11052]49#include "weaponsystem/Munition.h"
[9939]50#include "sound/WorldSound.h"
[11176]51#include "core/object/ObjectListIterator.h"
[2072]52
[9625]53#include "controllers/FormationController.h"
54
[2072]55namespace orxonox
56{
[9667]57    RegisterClass(Pawn);
[2072]58
[11176]59    SetConsoleCommand("Pawn", "debugDrawWeapons", &Pawn::consoleCommand_debugDrawWeapons).addShortcut();
60
[9667]61    Pawn::Pawn(Context* context)
62        : ControllableEntity(context)
63        , RadarViewable(this, static_cast<WorldEntity*>(this))
[2072]64    {
65        RegisterObject(Pawn);
66
[2662]67        this->bAlive_ = true;
[11052]68        this->bVulnerable_ = true;
[2072]69
70        this->health_ = 0;
71        this->maxHealth_ = 0;
72        this->initialHealth_ = 0;
[8706]73
[7163]74        this->shieldHealth_ = 0;
[8706]75        this->initialShieldHealth_ = 0;
76        this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max
[7163]77        this->shieldAbsorption_ = 0.5;
[11052]78        this->shieldRechargeRate_ = 0;
79        this->shieldRechargeWaitTime_ = 1.0f;
80        this->shieldRechargeWaitCountdown_ = 0;
[2072]81
[11071]82        this->lastHitOriginator_ = nullptr;
[2072]83
[9348]84        // set damage multiplier to default value 1, meaning nominal damage
85        this->damageMultiplier_ = 1;
[11783]86        this->acceptsPickups_ = true;
[9348]87
[2662]88        this->spawnparticleduration_ = 3.0f;
[2098]89
[6417]90        this->aimPosition_ = Vector3::ZERO;
91
[11071]92        //this->explosionPartList_ = nullptr;
[11052]93
[2896]94        if (GameMode::isMaster())
[2662]95        {
[9667]96            this->weaponSystem_ = new WeaponSystem(this->getContext());
[3053]97            this->weaponSystem_->setPawn(this);
[2662]98        }
99        else
[11071]100            this->weaponSystem_ = nullptr;
[2662]101
102        this->setRadarObjectColour(ColourValue::Red);
[11071]103        this->setRadarObjectShape(RadarViewable::Shape::Dot);
[2662]104
[2072]105        this->registerVariables();
[3089]106
107        this->isHumanShip_ = this->hasLocalController();
[8891]108
[8329]109        this->setSyncMode(ObjectDirection::Bidirectional); // needed to synchronise e.g. aimposition
[9939]110
111        if (GameMode::isMaster())
112        {
113            this->explosionSound_ = new WorldSound(this->getContext());
114            this->explosionSound_->setVolume(1.0f);
115        }
116        else
117        {
[11071]118            this->explosionSound_ = nullptr;
[9939]119        }
[2072]120    }
121
122    Pawn::~Pawn()
123    {
[2662]124        if (this->isInitialized())
125        {
126            if (this->weaponSystem_)
[5929]127                this->weaponSystem_->destroy();
[2662]128        }
[2072]129    }
130
131    void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode)
132    {
133        SUPER(Pawn, XMLPort, xmlelement, mode);
134
[2662]135        XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
[2072]136        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
137        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
[7163]138
139        XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
[8706]140        XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
141        XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
[7163]142        XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
143
[11052]144        XMLPortParam(Pawn, "vulnerable", setVulnerable, isVulnerable, xmlelement, mode).defaultValues(true);
145
[2662]146        XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
147        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
[11052]148        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(0);
[2662]149
[3053]150        XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode);
151        XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
[11052]152        XMLPortObject(Pawn, WeaponPack, "weaponpacks", addWeaponPackXML, getWeaponPack, xmlelement, mode);
153        XMLPortObject(Pawn, Munition, "munition", addMunitionXML, getMunitionXML, xmlelement, mode);
[8706]154
[11052]155        XMLPortObject(Pawn, ExplosionPart, "explosion", addExplosionPart, getExplosionPart, xmlelement, mode);
156        XMLPortParam(Pawn, "shieldrechargerate", setShieldRechargeRate, getShieldRechargeRate, xmlelement, mode).defaultValues(0);
157        XMLPortParam(Pawn, "shieldrechargewaittime", setShieldRechargeWaitTime, getShieldRechargeWaitTime, xmlelement, mode).defaultValues(1.0f);
[9254]158
[9939]159        XMLPortParam(Pawn, "explosionSound",  setExplosionSound,  getExplosionSound,  xmlelement, mode);
160
[9257]161        XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode );
[2072]162    }
163
[11052]164    void Pawn::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
165    {
166        SUPER(Pawn, XMLEventPort, xmlelement, mode);
167
168        XMLPortEventState(Pawn, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
169    }
170
[2072]171    void Pawn::registerVariables()
172    {
[11052]173        registerVariable(this->bAlive_,            VariableDirection::ToClient);
[11176]174        registerVariable(this->bVulnerable_,       VariableDirection::ToClient);
[11052]175        registerVariable(this->health_,            VariableDirection::ToClient);
176        registerVariable(this->maxHealth_,         VariableDirection::ToClient);
177        registerVariable(this->shieldHealth_,      VariableDirection::ToClient);
178        registerVariable(this->maxShieldHealth_,   VariableDirection::ToClient);
179        registerVariable(this->shieldAbsorption_,  VariableDirection::ToClient);
180        registerVariable(this->aimPosition_,       VariableDirection::ToServer);  // For the moment this variable gets only transfered to the server
[2072]181    }
182
183    void Pawn::tick(float dt)
184    {
[11052]185        //BigExplosion* chunk = new BigExplosion(this->getContext());
[2809]186        SUPER(Pawn, tick, dt);
[2072]187
[11052]188        // Recharge the shield
[8706]189        // TODO: use the existing timer functions instead
[11052]190        if(this->shieldRechargeWaitCountdown_ > 0)
[8706]191        {
[11052]192            this->decreaseShieldRechargeCountdownTime(dt);
[8706]193        }
194        else
195        {
[11052]196            this->addShieldHealth(this->getShieldRechargeRate() * dt);
197            this->resetShieldRechargeCountdown();
[8706]198        }
199
[3084]200        if (GameMode::isMaster())
[8706]201        {
[3087]202            if (this->health_ <= 0 && bAlive_)
[6864]203            {
[8706]204                this->fireEvent(); // Event to notify anyone who wants to know about the death.
[3087]205                this->death();
[6864]206            }
[8706]207        }
[2072]208    }
209
[7889]210    void Pawn::preDestroy()
211    {
212        // yay, multiple inheritance!
213        this->ControllableEntity::preDestroy();
214        this->PickupCarrier::preDestroy();
215    }
216
[2826]217    void Pawn::setPlayer(PlayerInfo* player)
218    {
219        ControllableEntity::setPlayer(player);
220
221        if (this->getGametype())
222            this->getGametype()->playerStartsControllingPawn(player, this);
223    }
224
225    void Pawn::removePlayer()
226    {
227        if (this->getGametype())
228            this->getGametype()->playerStopsControllingPawn(this->getPlayer(), this);
229
230        ControllableEntity::removePlayer();
231    }
232
[8706]233
[2072]234    void Pawn::setHealth(float health)
235    {
[8706]236        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]237    }
238
[8706]239    void Pawn::setShieldHealth(float shieldHealth)
[2072]240    {
[8706]241        this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_);
242    }
243
244    void Pawn::setMaxShieldHealth(float maxshieldhealth)
245    {
246        this->maxShieldHealth_ = maxshieldhealth;
247    }
248
[11052]249    void Pawn::setShieldRechargeRate(float shieldRechargeRate)
[8706]250    {
[11052]251        this->shieldRechargeRate_ = shieldRechargeRate;
[8706]252    }
253
[11052]254    void Pawn::setShieldRechargeWaitTime(float shieldRechargeWaitTime)
[8706]255    {
[11052]256        this->shieldRechargeWaitTime_ = shieldRechargeWaitTime;
[8706]257    }
258
[11052]259    void Pawn::decreaseShieldRechargeCountdownTime(float dt)
[8706]260    {
[11052]261        this->shieldRechargeWaitCountdown_ -= dt;
[8706]262    }
263
[11052]264    void Pawn::changedVulnerability()
265    {
266
267    }
268
[10216]269    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
[8706]270    {
[11052]271        // A pawn can only get damaged if it is vulnerable
272        if (!isVulnerable())
273        {
274            return;
275        }
276
[9348]277        // Applies multiplier given by the DamageBoost Pickup.
278        if (originator)
279            damage *= originator->getDamageMultiplier();
280
[2826]281        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
282        {
[11052]283            // Health-damage cannot be absorbed by shields.
284            // Shield-damage only reduces shield health.
285            // Normal damage can be (partially) absorbed by shields.
286
[8706]287            if (shielddamage >= this->getShieldHealth())
[7163]288            {
289                this->setShieldHealth(0);
[8706]290                this->setHealth(this->health_ - (healthdamage + damage));
[7163]291            }
[8706]292            else
293            {
294                this->setShieldHealth(this->shieldHealth_ - shielddamage);
[7163]295
[8706]296                // remove remaining shieldAbsorpton-Part of damage from shield
297                shielddamage = damage * this->shieldAbsorption_;
298                shielddamage = std::min(this->getShieldHealth(),shielddamage);
299                this->setShieldHealth(this->shieldHealth_ - shielddamage);
[7163]300
[8706]301                // set remaining damage to health
302                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
[7163]303            }
304
[2826]305            this->lastHitOriginator_ = originator;
306        }
[2072]307    }
308
[8706]309// TODO: Still valid?
310/* HIT-Funktionen
311    Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte)
312
313*/
[10216]314    void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
[2072]315    {
[6417]316        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
[2826]317        {
[10216]318            this->damage(damage, healthdamage, shielddamage, originator, cs);
[2826]319            this->setVelocity(this->getVelocity() + force);
320        }
[2072]321    }
322
[10216]323    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
[6417]324    {
325        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
326        {
[10216]327            this->damage(damage, healthdamage, shielddamage, originator, cs);
[6417]328
329            if ( this->getController() )
[8706]330                this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
[6417]331        }
332    }
333
[2072]334    void Pawn::kill()
335    {
[9945]336        this->damage(this->health_);
[2072]337        this->death();
338    }
339
[2662]340    void Pawn::spawneffect()
[2072]341    {
342        // play spawn effect
[6417]343        if (!this->spawnparticlesource_.empty())
[2662]344        {
[9667]345            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
[2662]346            effect->setPosition(this->getPosition());
347            effect->setOrientation(this->getOrientation());
348            effect->setDestroyAfterLife(true);
349            effect->setSource(this->spawnparticlesource_);
350            effect->setLifetime(this->spawnparticleduration_);
351        }
[2072]352    }
353
354    void Pawn::death()
355    {
[3033]356        this->setHealth(1);
[2826]357        if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
358        {
[10624]359            // Set bAlive_ to false and wait for destroyLater() to do the destruction
[2826]360            this->bAlive_ = false;
[10624]361            this->destroyLater();
[2662]362
[2826]363            this->setDestroyWhenPlayerLeft(false);
[2662]364
[2826]365            if (this->getGametype())
366                this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
[2662]367
[3038]368            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
[9625]369            {
[9663]370                // Start to control a new entity if you're the master of a formation
371                if(this->hasSlaves())
372                {
373                    Controller* slave = this->getSlave();
374                    ControllableEntity* entity = slave->getControllableEntity();
[2072]375
[9625]376
[9663]377                    if(!entity->hasHumanController())
378                    {
[9666]379                        // delete the AIController // <-- TODO: delete? nothing is deleted here... should we delete the controller?
[11071]380                        slave->setControllableEntity(nullptr);
[9625]381
[9663]382                        // set a new master within the formation
383                        orxonox_cast<FormationController*>(this->getController())->setNewMasterWithinFormation(orxonox_cast<FormationController*>(slave));
[9625]384
[9663]385                        // start to control a slave
386                        this->getPlayer()->startControl(entity);
387                    }
388                    else
389                    {
390                        this->getPlayer()->stopControl();
391                    }
[9625]392
[9663]393                }
394                else
395                {
396                    this->getPlayer()->stopControl();
397                }
[9625]398            }
[2896]399            if (GameMode::isMaster())
[3087]400            {
401                this->goWithStyle();
402            }
[2826]403        }
[2662]404    }
[3087]405    void Pawn::goWithStyle()
406    {
[11052]407
[3087]408        this->bAlive_ = false;
409        this->setDestroyWhenPlayerLeft(false);
[2072]410
[11052]411        while(!explosionPartList_.empty())
[2662]412        {
[11052]413            explosionPartList_.back()->setPosition(this->getPosition());
414            explosionPartList_.back()->setVelocity(this->getVelocity());
415            explosionPartList_.back()->setOrientation(this->getOrientation());
416            explosionPartList_.back()->Explode();
417            explosionPartList_.pop_back();
[2662]418        }
[11052]419
[2662]420        for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
421        {
[9667]422            ExplosionChunk* chunk = new ExplosionChunk(this->getContext());
[2662]423            chunk->setPosition(this->getPosition());
424        }
[11052]425
426        this->explosionSound_->setPosition(this->getPosition());
427        this->explosionSound_->play();
[2072]428    }
429
[10650]430    /**
431    @brief
[11099]432        Check whether the Pawn has a @ref orxonox::WeaponSystem and fire it with the specified firemode if it has one.
[10650]433    */
[11052]434
[6417]435    void Pawn::fired(unsigned int firemode)
[2098]436    {
[6417]437        if (this->weaponSystem_)
438            this->weaponSystem_->fire(firemode);
[2098]439    }
440
[2072]441    void Pawn::postSpawn()
442    {
443        this->setHealth(this->initialHealth_);
[2896]444        if (GameMode::isMaster())
[2662]445            this->spawneffect();
[2072]446    }
[2662]447
[11052]448
449    void Pawn::addExplosionPart(ExplosionPart* ePart)
450    {this->explosionPartList_.push_back(ePart);}
451
452
453    ExplosionPart * Pawn::getExplosionPart()
454    {return this->explosionPartList_.back();}
455
456
457
[2893]458    /* WeaponSystem:
459    *   functions load Slot, Set, Pack from XML and make sure all parent-pointers are set.
460    *   with setWeaponPack you can not just load a Pack from XML but if a Pack already exists anywhere, you can attach it.
461    *       --> e.g. Pickup-Items
462    */
[3053]463    void Pawn::addWeaponSlot(WeaponSlot * wSlot)
[2662]464    {
465        this->attach(wSlot);
466        if (this->weaponSystem_)
[3053]467            this->weaponSystem_->addWeaponSlot(wSlot);
[2662]468    }
469
470    WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const
471    {
472        if (this->weaponSystem_)
[3053]473            return this->weaponSystem_->getWeaponSlot(index);
[2662]474        else
[11071]475            return nullptr;
[2662]476    }
477
[3053]478    void Pawn::addWeaponSet(WeaponSet * wSet)
[2662]479    {
480        if (this->weaponSystem_)
[3053]481            this->weaponSystem_->addWeaponSet(wSet);
[2662]482    }
483
[3053]484    WeaponSet * Pawn::getWeaponSet(unsigned int index) const
[2662]485    {
486        if (this->weaponSystem_)
[3053]487            return this->weaponSystem_->getWeaponSet(index);
[2662]488        else
[11071]489            return nullptr;
[2662]490    }
491
[3053]492    void Pawn::addWeaponPack(WeaponPack * wPack)
[2662]493    {
494        if (this->weaponSystem_)
[7163]495        {
[3053]496            this->weaponSystem_->addWeaponPack(wPack);
[7163]497            this->addedWeaponPack(wPack);
498        }
[2662]499    }
500
[6417]501    void Pawn::addWeaponPackXML(WeaponPack * wPack)
502    {
503        if (this->weaponSystem_)
[7163]504        {
[6417]505            if (!this->weaponSystem_->addWeaponPack(wPack))
506                wPack->destroy();
[7163]507            else
508                this->addedWeaponPack(wPack);
509        }
[6417]510    }
511
[3053]512    WeaponPack * Pawn::getWeaponPack(unsigned int index) const
[2662]513    {
514        if (this->weaponSystem_)
[3053]515            return this->weaponSystem_->getWeaponPack(index);
[2662]516        else
[11071]517            return nullptr;
[2662]518    }
519
[11052]520    void Pawn::addMunitionXML(Munition* munition)
521    {
522        if (this->weaponSystem_ && munition)
523        {
524            this->weaponSystem_->addMunition(munition);
525        }
526    }
527
528    Munition* Pawn::getMunitionXML() const
529    {
[11071]530        return nullptr;
[11052]531    }
532
533    Munition* Pawn::getMunition(SubclassIdentifier<Munition> * identifier)
534    {
535        if (weaponSystem_)
536        {
537            return weaponSystem_->getMunition(identifier);
538        }
539
[11071]540        return nullptr;
[11052]541    }
542
[3089]543    //Tell the Map (RadarViewable), if this is a playership
544    void Pawn::startLocalHumanControl()
545    {
[11052]546//        SUPER(ControllableEntity, startLocalHumanControl());
[3089]547        ControllableEntity::startLocalHumanControl();
548        this->isHumanShip_ = true;
549    }
[8891]550
551    void Pawn::changedVisibility(void)
552    {
553        SUPER(Pawn, changedVisibility);
[9254]554
555        // enable proper radarviewability when the visibility is changed
556        this->RadarViewable::settingsChanged();
[8891]557    }
558
[9625]559
560    // A function to check if this pawn's controller is the master of any formationcontroller
561    bool Pawn::hasSlaves()
562    {
[11071]563        for (FormationController* controller : ObjectList<FormationController>())
[9663]564        {
565            // checks if the pawn's controller has a slave
[11071]566            if (this->hasHumanController() && controller->getMaster() == this->getPlayer()->getController())
[9663]567                return true;
568        }
569        return false;
[9625]570    }
571
572    // A function that returns a slave of the pawn's controller
573    Controller* Pawn::getSlave(){
[11071]574        for (FormationController* controller : ObjectList<FormationController>())
[9663]575        {
[11071]576            if (this->hasHumanController() && controller->getMaster() == this->getPlayer()->getController())
577                return controller->getController();
[9663]578        }
[11071]579        return nullptr;
[9625]580    }
581
582
[9939]583    void Pawn::setExplosionSound(const std::string &explosionSound)
584    {
585        if(explosionSound_ )
586            explosionSound_->setSource(explosionSound);
587        else
588            assert(0); // This should never happen, because soundpointer is only available on master
589    }
[9625]590
[9939]591    const std::string& Pawn::getExplosionSound()
592    {
593        if( explosionSound_ )
594            return explosionSound_->getSource();
595        else
596            assert(0);
597        return BLANKSTRING;
598    }
[11176]599
600    void Pawn::drawWeapons(bool bDraw)
601    {
602        if (bDraw)
603        {
604            std::vector<WeaponSlot*> weaponSlots = weaponSystem_->getAllWeaponSlots();
605            int numWeaponSlots = weaponSlots.size();
606            Vector3 slotPosition = Vector3::ZERO;
607            Quaternion slotOrientation = Quaternion::IDENTITY;
608            Model* slotModel = nullptr;
609
610            for (int i = 0; i < numWeaponSlots; ++i)
611            {
612                slotPosition = weaponSlots.at(i)->getPosition();
613                slotOrientation = weaponSlots.at(i)->getOrientation();
614                slotModel = new Model(this->getContext());
615                slotModel->setMeshSource("Coordinates.mesh");
616                slotModel->setScale(3.0f);
617                slotModel->setOrientation(slotOrientation);
618                slotModel->setPosition(slotPosition);
619
620                this->attach(slotModel);
621                debugWeaponSlotModels_.push_back(slotModel);
622            }
623        }
624        else
625        {
626            // delete all debug models
627            for(Model* model : debugWeaponSlotModels_) 
628            {
629                model->destroy();
630            }
631            debugWeaponSlotModels_.clear();
632        }
633    }
634
635    /*static*/ void Pawn::consoleCommand_debugDrawWeapons(bool bDraw)
636    {
637        if (bDraw)
638        {
639            orxout() << "WeaponSlot visualization enabled." << endl;
640        }
641        else
642        {
643            orxout() << "WeaponSlot visualization disabled." << endl;
644        }
645
646        ObjectList<Pawn> pawnList;
647        for (ObjectListIterator<Pawn> it = pawnList.begin(); it != pawnList.end(); ++it)
648        {
649            it->drawWeapons(bDraw);
650        }
651    }
652}
Note: See TracBrowser for help on using the repository browser.