Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2009, 4:19:14 AM (15 years ago)
Author:
landauf
Message:

merged weapons 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

    r3038 r3053  
    3939#include "objects/worldentities/ParticleSpawner.h"
    4040#include "objects/worldentities/ExplosionChunk.h"
     41#include "objects/weaponsystem/WeaponSystem.h"
     42#include "objects/weaponsystem/WeaponSlot.h"
     43#include "objects/weaponsystem/WeaponPack.h"
     44#include "objects/weaponsystem/WeaponSet.h"
    4145
    4246namespace orxonox
     
    5256        this->fire_ = 0x0;
    5357        this->firehack_ = 0x0;
     58        this->bReload_ = false;
    5459
    5560        this->health_ = 0;
     
    6671        {
    6772            this->weaponSystem_ = new WeaponSystem(this);
    68             this->weaponSystem_->setParentPawn(this);
     73            this->weaponSystem_->setPawn(this);
    6974        }
    7075        else
     
    100105        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
    101106
    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);
     107        XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode);
     108        XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
     109        XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPack, getWeaponPack, xmlelement, mode);
    105110    }
    106111
     
    111116        registerVariable(this->initialHealth_, variableDirection::toclient);
    112117        registerVariable(this->fire_,          variableDirection::toserver);
     118        registerVariable(this->bReload_,       variableDirection::toserver);
    113119    }
    114120
     
    117123        SUPER(Pawn, tick, dt);
    118124
    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         }
     125        if (this->weaponSystem_ && GameMode::isMaster())
     126        {
     127            for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++)
     128                if (this->fire_ & WeaponSystem::getFiremodeMask(firemode))
     129                    this->weaponSystem_->fire(firemode);
     130
     131            if (this->bReload_)
     132                this->weaponSystem_->reload();
     133        }
     134
    128135        this->fire_ = this->firehack_;
    129136        this->firehack_ = 0x0;
     137        this->bReload_ = false;
    130138
    131139        if (this->health_ <= 0)
     
    251259    }
    252260
    253     void Pawn::fire(WeaponMode::Enum fireMode)
    254     {
    255         this->firehack_ |= fireMode;
     261    void Pawn::fire(unsigned int firemode)
     262    {
     263        this->firehack_ |= WeaponSystem::getFiremodeMask(firemode);
     264    }
     265
     266    void Pawn::reload()
     267    {
     268        this->bReload_ = true;
    256269    }
    257270
     
    274287    *       --> e.g. Pickup-Items
    275288    */
    276     void Pawn::setWeaponSlot(WeaponSlot * wSlot)
     289    void Pawn::addWeaponSlot(WeaponSlot * wSlot)
    277290    {
    278291        this->attach(wSlot);
    279292        if (this->weaponSystem_)
    280             this->weaponSystem_->attachWeaponSlot(wSlot);
     293            this->weaponSystem_->addWeaponSlot(wSlot);
    281294    }
    282295
     
    284297    {
    285298        if (this->weaponSystem_)
    286             return this->weaponSystem_->getWeaponSlotPointer(index);
     299            return this->weaponSystem_->getWeaponSlot(index);
    287300        else
    288301            return 0;
    289302    }
    290303
    291     void Pawn::setWeaponPack(WeaponPack * wPack)
    292     {
    293         if (this->weaponSystem_)
    294         {
    295             wPack->setParentWeaponSystem(this->weaponSystem_);
    296             wPack->setParentWeaponSystemToAllWeapons(this->weaponSystem_);
    297             this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() );
    298             wPack->attachNeededMunitionToAllWeapons();
    299         }
    300     }
    301 
    302     WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const
    303     {
    304         if (this->weaponSystem_)
    305             return this->weaponSystem_->getWeaponPackPointer(firemode);
     304    void Pawn::addWeaponSet(WeaponSet * wSet)
     305    {
     306        if (this->weaponSystem_)
     307            this->weaponSystem_->addWeaponSet(wSet);
     308    }
     309
     310    WeaponSet * Pawn::getWeaponSet(unsigned int index) const
     311    {
     312        if (this->weaponSystem_)
     313            return this->weaponSystem_->getWeaponSet(index);
    306314        else
    307315            return 0;
    308316    }
    309317
    310     void Pawn::setWeaponSet(WeaponSet * wSet)
    311     {
    312         if (this->weaponSystem_)
    313             this->weaponSystem_->attachWeaponSet(wSet);
    314     }
    315 
    316     WeaponSet * Pawn::getWeaponSet(unsigned int index) const
    317     {
    318         if (this->weaponSystem_)
    319             return this->weaponSystem_->getWeaponSetPointer(index);
     318    void Pawn::addWeaponPack(WeaponPack * wPack)
     319    {
     320        if (this->weaponSystem_)
     321            this->weaponSystem_->addWeaponPack(wPack);
     322    }
     323
     324    WeaponPack * Pawn::getWeaponPack(unsigned int index) const
     325    {
     326        if (this->weaponSystem_)
     327            return this->weaponSystem_->getWeaponPack(index);
    320328        else
    321329            return 0;
Note: See TracChangeset for help on using the changeset viewer.