Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2009, 12:05:01 AM (16 years ago)
Author:
landauf
Message:

More changes in the WeaponSystem:

  • WeaponSets can now contain several WeaponPacks
  • WeaponPacks can now belong to several WeaponSets

(until now this seemingly was a 1:1 relationship… now it's n:m)

  • Started support for multiple weaponmodes
  • Added some code to the destructor of some classes… according to some legends, this helps destroying objects. (WeaponSets and WeaponPacks weren't deleted before…)

Not yet finished, but I have to synchronize desktop computer and notebook.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2912 r2914  
    3131#include "core/CoreIncludes.h"
    3232#include "core/XMLPort.h"
    33 #include "objects/worldentities/pawns/Pawn.h"
    3433
    35 #include "Weapon.h"
    36 #include "WeaponSlot.h"
     34#include "WeaponSystem.h"
    3735#include "WeaponPack.h"
    38 #include "WeaponSystem.h"
    3936
    4037namespace orxonox
     
    4239    CreateFactory(WeaponSet);
    4340
    44     WeaponSet::WeaponSet(BaseObject* creator, int k) : BaseObject(creator)
     41    WeaponSet::WeaponSet(BaseObject* creator) : BaseObject(creator)
    4542    {
    4643        RegisterObject(WeaponSet);
    4744
    4845        this->weaponSystem_ = 0;
    49         this->attachedWeaponPack_ = 0;
     46        this->desiredFiremode_ = WeaponSystem::FIRE_MODE_UNASSIGNED;
    5047
    5148COUT(0) << "+WeaponSet" << std::endl;
     
    5552    {
    5653COUT(0) << "~WeaponSet" << std::endl;
     54
     55        if (this->isInitialized() && this->weaponSystem_)
     56            this->weaponSystem_->removeWeaponSet(this);
    5757    }
    5858
     
    6161        SUPER(WeaponSet, XMLPort, xmlelement, mode);
    6262
    63         XMLPortParam(WeaponSet, "firemode", setFireMode, getFireMode, xmlelement, mode);
     63        XMLPortParam(WeaponSet, "firemode", setDesiredFiremode, getDesiredFiremode, xmlelement, mode);
    6464    }
    65 
     65/*
    6666    void WeaponSet::attachWeaponPack(WeaponPack *wPack)
    6767    {
     
    100100        }
    101101    }
    102 
     102*/
    103103
    104104    void WeaponSet::fire()
    105105    {
    106         //fires all WeaponSlots available for this weaponSet attached from the WeaponPack
    107         if (this->attachedWeaponPack_)
    108             this->attachedWeaponPack_->fire();
     106        // fire all WeaponPacks with their defined weaponmode
     107        for (std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.begin(); it != this->weaponpacks_.end(); ++it)
     108            if (it->second != WeaponSystem::WEAPON_MODE_UNASSIGNED)
     109                it->first->fire(it->second);
     110    }
     111
     112    void WeaponSet::setWeaponmodeLink(WeaponPack* weaponpack, unsigned int weaponmode)
     113    {
     114        this->weaponpacks_[weaponpack] = weaponmode;
     115    }
     116
     117    void WeaponSet::removeWeaponmodeLink(WeaponPack* weaponpack)
     118    {
     119        this->weaponpacks_.erase(weaponpack);
     120    }
     121
     122    unsigned int WeaponSet::getWeaponmodeLink(WeaponPack* weaponpack)
     123    {
     124        std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.find(weaponpack);
     125        if (it != this->weaponpacks_.end())
     126            return it->second;
     127        else
     128            return WeaponSystem::WEAPON_MODE_UNASSIGNED;
    109129    }
    110130}
Note: See TracChangeset for help on using the changeset viewer.