Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2009, 10:17:35 PM (15 years ago)
Author:
rgrieder
Message:

Merged presentation branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2171 r2662  
    3030#include "Pawn.h"
    3131
     32#include "core/Core.h"
    3233#include "core/CoreIncludes.h"
    3334#include "core/XMLPort.h"
    3435#include "util/Math.h"
     36#include "PawnManager.h"
    3537#include "objects/infos/PlayerInfo.h"
    3638#include "objects/gametypes/Gametype.h"
    37 #include "objects/weaponSystem/WeaponSystem.h"
     39#include "objects/worldentities/ParticleSpawner.h"
     40#include "objects/worldentities/ExplosionChunk.h"
    3841
    3942namespace orxonox
     
    4548        RegisterObject(Pawn);
    4649
    47         this->bAlive_ = false;
     50        PawnManager::touch();
     51        this->bAlive_ = true;
     52        this->fire_ = 0x0;
     53        this->firehack_ = 0x0;
    4854
    4955        this->health_ = 0;
     
    5258
    5359        this->lastHitOriginator_ = 0;
    54         this->weaponSystem_ = 0;
    55 
    56         /*
    57         //WeaponSystem
    58         weaponSystem_ = new WeaponSystem();
    59         WeaponSet * weaponSet1 = new WeaponSet(1);
    60         this->weaponSystem_->attachWeaponSet(weaponSet1);
    61         this->weaponSystem_->getWeaponSetPointer(0)->getWeaponSlotPointer(0)->setAmmoType(true);
    62         */
     60
     61        this->spawnparticleduration_ = 3.0f;
     62
     63        this->getPickUp().setPlayer(this);
     64
     65        if (Core::isMaster())
     66        {
     67            this->weaponSystem_ = new WeaponSystem(this);
     68            this->weaponSystem_->setParentPawn(this);
     69        }
     70        else
     71            this->weaponSystem_ = 0;
     72
     73        this->setRadarObjectColour(ColourValue::Red);
     74        this->setRadarObjectShape(RadarViewable::Dot);
    6375
    6476        this->registerVariables();
     
    6779    Pawn::~Pawn()
    6880    {
     81        if (this->isInitialized())
     82        {
     83            for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
     84                it->destroyedPawn(this);
     85
     86            if (this->weaponSystem_)
     87                delete this->weaponSystem_;
     88        }
    6989    }
    7090
     
    7393        SUPER(Pawn, XMLPort, xmlelement, mode);
    7494
    75         XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
     95        XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
    7696        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
    7797        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
     98        XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
     99        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
     100        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
     101
     102        XMLPortObject(Pawn, WeaponSlot, "weaponslots", setWeaponSlot, getWeaponSlot, xmlelement, mode);
     103        XMLPortObject(Pawn, WeaponSet, "weaponsets", setWeaponSet, getWeaponSet, xmlelement, mode);
     104        XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode);
    78105    }
    79106
    80107    void Pawn::registerVariables()
    81108    {
    82         REGISTERDATA(this->bAlive_, direction::toclient);
    83         REGISTERDATA(this->health_, direction::toclient);
     109        registerVariable(this->bAlive_,        variableDirection::toclient);
     110        registerVariable(this->health_,        variableDirection::toclient);
     111        registerVariable(this->initialHealth_, variableDirection::toclient);
     112        registerVariable(this->fire_,          variableDirection::toserver);
    84113    }
    85114
     
    87116    {
    88117        SUPER(Pawn, tick, dt);
     118
     119        if (this->weaponSystem_)
     120        {
     121            if (this->fire_ & WeaponMode::fire)
     122                this->weaponSystem_->fire(WeaponMode::fire);
     123            if (this->fire_ & WeaponMode::altFire)
     124                this->weaponSystem_->fire(WeaponMode::altFire);
     125            if (this->fire_ & WeaponMode::altFire2)
     126                this->weaponSystem_->fire(WeaponMode::altFire2);
     127        }
     128        this->fire_ = this->firehack_;
     129        this->firehack_ = 0x0;
    89130
    90131        if (this->health_ <= 0)
     
    119160    }
    120161
    121     void Pawn::spawn()
     162    void Pawn::spawneffect()
    122163    {
    123164        // play spawn effect
     165        if (this->spawnparticlesource_ != "")
     166        {
     167            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     168            effect->setPosition(this->getPosition());
     169            effect->setOrientation(this->getOrientation());
     170            effect->setDestroyAfterLife(true);
     171            effect->setSource(this->spawnparticlesource_);
     172            effect->setLifetime(this->spawnparticleduration_);
     173        }
    124174    }
    125175
    126176    void Pawn::death()
    127177    {
     178        // Set bAlive_ to false and wait for PawnManager to do the destruction
    128179        this->bAlive_ = false;
     180
     181        this->setDestroyWhenPlayerLeft(false);
     182
    129183        if (this->getGametype())
    130184            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
     185
    131186        if (this->getPlayer())
    132187            this->getPlayer()->stopControl(this);
    133188
    134         delete this;
    135 
     189        if (Core::isMaster())
     190            this->deatheffect();
     191    }
     192
     193    void Pawn::deatheffect()
     194    {
    136195        // play death effect
    137     }
    138 
    139     void Pawn::fire()
    140     {
    141         if (this->weaponSystem_)
    142             this->weaponSystem_->fire();
     196        {
     197            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     198            effect->setPosition(this->getPosition());
     199            effect->setOrientation(this->getOrientation());
     200            effect->setDestroyAfterLife(true);
     201            effect->setSource("Orxonox/explosion2b");
     202            effect->setLifetime(4.0f);
     203        }
     204        {
     205            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     206            effect->setPosition(this->getPosition());
     207            effect->setOrientation(this->getOrientation());
     208            effect->setDestroyAfterLife(true);
     209            effect->setSource("Orxonox/smoke6");
     210            effect->setLifetime(4.0f);
     211        }
     212        {
     213            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     214            effect->setPosition(this->getPosition());
     215            effect->setOrientation(this->getOrientation());
     216            effect->setDestroyAfterLife(true);
     217            effect->setSource("Orxonox/sparks");
     218            effect->setLifetime(4.0f);
     219        }
     220        for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
     221        {
     222            ExplosionChunk* chunk = new ExplosionChunk(this->getCreator());
     223            chunk->setPosition(this->getPosition());
     224
     225        }
     226    }
     227
     228    void Pawn::fire(WeaponMode::Enum fireMode)
     229    {
     230        this->firehack_ |= fireMode;
    143231    }
    144232
     
    146234    {
    147235        this->setHealth(this->initialHealth_);
    148         this->spawn();
     236        if (Core::isMaster())
     237            this->spawneffect();
     238    }
     239
     240    void Pawn::dropItems()
     241    {
     242        pickUp.eraseAll();
     243    }
     244
     245    void Pawn::setWeaponSlot(WeaponSlot * wSlot)
     246    {
     247        this->attach(wSlot);
     248        if (this->weaponSystem_)
     249            this->weaponSystem_->attachWeaponSlot(wSlot);
     250    }
     251
     252    WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const
     253    {
     254        if (this->weaponSystem_)
     255            return this->weaponSystem_->getWeaponSlotPointer(index);
     256        else
     257            return 0;
     258    }
     259
     260    void Pawn::setWeaponPack(WeaponPack * wPack)
     261    {
     262        if (this->weaponSystem_)
     263        {
     264            wPack->setParentWeaponSystem(this->weaponSystem_);
     265            wPack->setParentWeaponSystemToAllWeapons(this->weaponSystem_);
     266            this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() );
     267            wPack->attachNeededMunitionToAllWeapons();
     268        }
     269    }
     270
     271    WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const
     272    {
     273        if (this->weaponSystem_)
     274            return this->weaponSystem_->getWeaponPackPointer(firemode);
     275        else
     276            return 0;
     277    }
     278
     279    void Pawn::setWeaponSet(WeaponSet * wSet)
     280    {
     281        if (this->weaponSystem_)
     282            this->weaponSystem_->attachWeaponSet(wSet);
     283    }
     284
     285    WeaponSet * Pawn::getWeaponSet(unsigned int index) const
     286    {
     287        if (this->weaponSystem_)
     288            return this->weaponSystem_->getWeaponSetPointer(index);
     289        else
     290            return 0;
     291    }
     292
     293
     294    ///////////////////
     295    // Pawn Listener //
     296    ///////////////////
     297    PawnListener::PawnListener()
     298    {
     299        RegisterRootObject(PawnListener);
    149300    }
    150301}
Note: See TracChangeset for help on using the changeset viewer.