Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 17, 2008, 2:10:11 AM (15 years ago)
Author:
landauf
Message:

merged weapon2 branch to presentation

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2485 r2493  
    3737#include "objects/infos/PlayerInfo.h"
    3838#include "objects/gametypes/Gametype.h"
    39 #include "objects/weaponSystem/WeaponSystem.h"
    4039#include "objects/worldentities/ParticleSpawner.h"
    4140#include "objects/worldentities/ExplosionChunk.h"
     
    5251
    5352        this->bAlive_ = true;
     53        this->fire_ = 0x0;
    5454
    5555        this->health_ = 0;
     
    5858
    5959        this->lastHitOriginator_ = 0;
    60         this->weaponSystem_ = 0;
    6160
    6261        this->spawnparticleduration_ = 3.0f;
    6362
    64         /*
    65         //WeaponSystem
    66         weaponSystem_ = new WeaponSystem();
    67         WeaponSet * weaponSet1 = new WeaponSet(1);
    68         this->weaponSystem_->attachWeaponSet(weaponSet1);
    69         this->weaponSystem_->getWeaponSetPointer(0)->getWeaponSlotPointer(0)->setAmmoType(true);
    70         */
     63        if (Core::isMaster())
     64        {
     65            this->weaponSystem_ = new WeaponSystem(this);
     66            this->weaponSystem_->setParentPawn(this);
     67        }
     68        else
     69            this->weaponSystem_ = 0;
    7170
    7271        this->setRadarObjectColour(ColourValue::Red);
     
    8281            for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
    8382                it->destroyedPawn(this);
     83
     84            if (this->weaponSystem_)
     85                delete this->weaponSystem_;
    8486        }
    8587    }
     
    9597        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
    9698        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
     99
     100        XMLPortObject(Pawn, WeaponSlot, "weaponslots", setWeaponSlot, getWeaponSlot, xmlelement, mode);
     101        XMLPortObject(Pawn, WeaponSet, "weaponsets", setWeaponSet, getWeaponSet, xmlelement, mode);
     102        XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode);
    97103    }
    98104
     
    102108        registerVariable(this->health_,        variableDirection::toclient);
    103109        registerVariable(this->initialHealth_, variableDirection::toclient);
     110        registerVariable(this->fire_,          variableDirection::toclient);
    104111    }
    105112
     
    107114    {
    108115        SUPER(Pawn, tick, dt);
     116
     117        if (this->weaponSystem_)
     118        {
     119            if (this->fire_ & WeaponMode::fire)
     120                this->weaponSystem_->fire(WeaponMode::fire);
     121            if (this->fire_ & WeaponMode::altFire)
     122                this->weaponSystem_->fire(WeaponMode::altFire);
     123            if (this->fire_ & WeaponMode::altFire2)
     124                this->weaponSystem_->fire(WeaponMode::altFire2);
     125        }
     126        this->fire_ = 0x0;
    109127
    110128        if (this->health_ <= 0)
     
    205223    }
    206224
    207     void Pawn::fire()
    208     {
    209         if (this->weaponSystem_)
    210             this->weaponSystem_->fire();
     225    void Pawn::fire(WeaponMode::Enum fireMode)
     226    {
     227        this->fire_ |= fireMode;
    211228    }
    212229
     
    217234            this->spawneffect();
    218235    }
     236
     237    void Pawn::setWeaponSlot(WeaponSlot * wSlot)
     238    {
     239        this->attach(wSlot);
     240        if (this->weaponSystem_)
     241            this->weaponSystem_->attachWeaponSlot(wSlot);
     242    }
     243
     244    WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const
     245    {
     246        if (this->weaponSystem_)
     247            return this->weaponSystem_->getWeaponSlotPointer(index);
     248        else
     249            return 0;
     250    }
     251
     252    void Pawn::setWeaponPack(WeaponPack * wPack)
     253    {
     254        if (this->weaponSystem_)
     255        {
     256            wPack->setParentWeaponSystem(this->weaponSystem_);
     257            wPack->setParentWeaponSystemToAllWeapons(this->weaponSystem_);
     258            this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() );
     259            wPack->attachNeededMunitionToAllWeapons();
     260        }
     261    }
     262
     263    WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const
     264    {
     265        if (this->weaponSystem_)
     266            return this->weaponSystem_->getWeaponPackPointer(firemode);
     267        else
     268            return 0;
     269    }
     270
     271    void Pawn::setWeaponSet(WeaponSet * wSet)
     272    {
     273        if (this->weaponSystem_)
     274            this->weaponSystem_->attachWeaponSet(wSet);
     275    }
     276
     277    WeaponSet * Pawn::getWeaponSet(unsigned int index) const
     278    {
     279        if (this->weaponSystem_)
     280            return this->weaponSystem_->getWeaponSetPointer(index);
     281        else
     282            return 0;
     283    }
     284
    219285
    220286    ///////////////////
Note: See TracChangeset for help on using the changeset viewer.