Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12380 was 12028, checked in by merholzl, 6 years ago

added scriptable controller

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