Changeset 2914
- Timestamp:
- Apr 10, 2009, 12:05:01 AM (16 years ago)
- Location:
- code/branches/weapons/src/orxonox/objects
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc
r2912 r2914 47 47 this->magazineReadyToShoot_ = true; 48 48 this->weaponSystem_ = 0; 49 this->attachedToWeaponSlot_ = 0; 49 this->weaponPack_ = 0; 50 this->weaponSlot_ = 0; 50 51 this->bulletLoadingTime_ = 0; 51 52 this->magazineLoadingTime_ = 0; -
code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.h
r2912 r2914 86 86 { return this->weaponSystem_; }; 87 87 88 inline void setAttachedToWeaponSlot(WeaponSlot * wSlot) 89 { this->attachedToWeaponSlot_ = wSlot; } 90 inline WeaponSlot * getAttachedToWeaponSlot() const 91 { return this->attachedToWeaponSlot_; } 88 inline void setWeaponPack(WeaponPack *weaponPack) 89 { this->weaponPack_ = weaponPack; }; 90 inline WeaponPack * getWeaponPack() const 91 { return this->weaponPack_; }; 92 93 inline void setWeaponSlot(WeaponSlot * wSlot) 94 { this->weaponSlot_ = wSlot; } 95 inline WeaponSlot * getWeaponSlot() const 96 { return this->weaponSlot_; } 92 97 93 98 protected: … … 102 107 std::string munitionType_; 103 108 104 WeaponSlot * attachedToWeaponSlot_;109 WeaponSlot * weaponSlot_; 105 110 Munition * munition_; 106 111 WeaponSystem * weaponSystem_; 112 WeaponPack* weaponPack_; 107 113 108 114 SubclassIdentifier<Munition> munitionIdentifier_; -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
r2912 r2914 35 35 #include "Weapon.h" 36 36 #include "WeaponSlot.h" 37 #include "WeaponSystem.h" 37 38 38 39 namespace orxonox … … 45 46 46 47 this->weaponSystem_ = 0; 47 this->firemode_ = 0;48 48 49 49 COUT(0) << "+WeaponPack" << std::endl; … … 53 53 { 54 54 COUT(0) << "~WeaponPack" << std::endl; 55 56 if (this->isInitialized() && this->weaponSystem_) 57 this->weaponSystem_->removeWeaponPack(this); 55 58 } 56 59 … … 60 63 61 64 XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode); 62 XMLPortParam(WeaponPack, "firemode", setFireMode, getFireMode, xmlelement, mode);63 65 } 64 66 65 int WeaponPack::getSize() const67 void WeaponPack::fire(unsigned int weaponmode) 66 68 { 67 return this->weapons_.size(); 68 } 69 70 void WeaponPack::fire() 71 { 72 for (int i=0; i < (int) this->weapons_.size(); i++) 73 { 74 this->weapons_[i]->getAttachedToWeaponSlot()->fire(); 75 } 76 } 77 78 Weapon * WeaponPack::getWeaponPointer(unsigned int n) const 79 { 80 return this->weapons_[n]; 81 } 82 83 void WeaponPack::setFireMode(unsigned int firemode) 84 { 85 this->firemode_ = firemode; 86 } 87 88 unsigned int WeaponPack::getFireMode() const 89 { 90 return this->firemode_; 69 for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 70 (*it)->fire(); 91 71 } 92 72 93 73 void WeaponPack::addWeapon(Weapon * weapon) 94 74 { 95 this->weapons_.push_back(weapon); 75 if (!weapon) 76 return; 77 78 this->weapons_.insert(weapon); 79 weapon->setWeaponPack(this); 96 80 } 97 81 98 constWeapon * WeaponPack::getWeapon(unsigned int index) const82 Weapon * WeaponPack::getWeapon(unsigned int index) const 99 83 { 100 return weapons_[index]; 84 unsigned int i = 0; 85 86 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 87 { 88 if (i == index) 89 return (*it); 90 ++i; 91 } 92 93 return 0; 101 94 } 102 95 103 96 void WeaponPack::setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem) 104 97 { 105 for (s ize_t i = 0; i < this->weapons_.size(); i++)106 this->weapons_[i]->setWeaponSystem(weaponSystem);98 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 99 (*it)->setWeaponSystem(weaponSystem); 107 100 } 108 101 109 102 void WeaponPack::attachNeededMunitionToAllWeapons() 110 103 { 111 for (s ize_t i = 0; i < this->weapons_.size(); i++)104 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 112 105 { 113 this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType());114 this->weapons_[i]->setWeapon();106 (*it)->attachNeededMunition((*it)->getMunitionType()); 107 (*it)->setWeapon(); 115 108 } 116 109 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h
r2912 r2914 33 33 #include "OrxonoxPrereqs.h" 34 34 35 #include < vector>35 #include <set> 36 36 37 37 #include "core/BaseObject.h" … … 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 49 void fire(); 50 51 Weapon * getWeaponPointer(unsigned int n) const; 52 int getSize() const; 53 54 void setFireMode(unsigned int firemode); 55 unsigned int getFireMode() const; 49 void fire(unsigned int weaponmode); 56 50 57 51 void addWeapon(Weapon * weapon); 58 const Weapon * getWeapon(unsigned int index) const; 52 Weapon * getWeapon(unsigned int index) const; 53 54 inline size_t getNumWeapons() const 55 { return this->weapons_.size(); } 56 57 unsigned int getDesiredWeaponmode(unsigned int firemode) { return 0; } // TODO 59 58 60 59 void attachNeededMunitionToAllWeapons(); 61 60 62 //functions with effect to all weapons of the weaponPack63 //functions needed for creating Pointer to the right objects (-->Pawn.cc)64 61 inline void setWeaponSystem(WeaponSystem *weaponSystem) 65 62 { this->weaponSystem_ = weaponSystem; this->setWeaponSystemToAllWeapons(weaponSystem); } … … 70 67 void setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem); 71 68 72 std::vector<Weapon *> weapons_; 73 WeaponSystem *weaponSystem_; 74 unsigned int firemode_; 69 std::set<Weapon *> weapons_; 70 WeaponSystem * weaponSystem_; 75 71 }; 76 72 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc
r2912 r2914 31 31 #include "core/CoreIncludes.h" 32 32 #include "core/XMLPort.h" 33 #include "objects/worldentities/pawns/Pawn.h"34 33 35 #include "Weapon.h" 36 #include "WeaponSlot.h" 34 #include "WeaponSystem.h" 37 35 #include "WeaponPack.h" 38 #include "WeaponSystem.h"39 36 40 37 namespace orxonox … … 42 39 CreateFactory(WeaponSet); 43 40 44 WeaponSet::WeaponSet(BaseObject* creator , int k) : BaseObject(creator)41 WeaponSet::WeaponSet(BaseObject* creator) : BaseObject(creator) 45 42 { 46 43 RegisterObject(WeaponSet); 47 44 48 45 this->weaponSystem_ = 0; 49 this-> attachedWeaponPack_ = 0;46 this->desiredFiremode_ = WeaponSystem::FIRE_MODE_UNASSIGNED; 50 47 51 48 COUT(0) << "+WeaponSet" << std::endl; … … 55 52 { 56 53 COUT(0) << "~WeaponSet" << std::endl; 54 55 if (this->isInitialized() && this->weaponSystem_) 56 this->weaponSystem_->removeWeaponSet(this); 57 57 } 58 58 … … 61 61 SUPER(WeaponSet, XMLPort, xmlelement, mode); 62 62 63 XMLPortParam(WeaponSet, "firemode", set FireMode, getFireMode, xmlelement, mode);63 XMLPortParam(WeaponSet, "firemode", setDesiredFiremode, getDesiredFiremode, xmlelement, mode); 64 64 } 65 65 /* 66 66 void WeaponSet::attachWeaponPack(WeaponPack *wPack) 67 67 { … … 100 100 } 101 101 } 102 102 */ 103 103 104 104 void WeaponSet::fire() 105 105 { 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; 109 129 } 110 130 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.h
r2912 r2914 33 33 #include "OrxonoxPrereqs.h" 34 34 35 #include < vector>35 #include <map> 36 36 37 37 #include "core/BaseObject.h" … … 42 42 { 43 43 public: 44 WeaponSet(BaseObject* creator , int k = 0);44 WeaponSet(BaseObject* creator); 45 45 virtual ~WeaponSet(); 46 46 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 49 void attachWeaponPack(WeaponPack *wPack); 49 // void attachWeaponPack(WeaponPack *wPack); 50 50 51 void fire(); 51 52 52 inline void setFireMode(const unsigned int firemode) 53 { this->firemode_ = firemode; } 54 inline unsigned int getFireMode() const 55 { return this->firemode_; } 53 void setWeaponmodeLink(WeaponPack* weaponpack, unsigned int weaponmode); 54 void removeWeaponmodeLink(WeaponPack* weaponpack); 55 unsigned int getWeaponmodeLink(WeaponPack* weaponpack); 56 57 inline void setDesiredFiremode(const unsigned int firemode) 58 { this->desiredFiremode_ = firemode; } 59 inline unsigned int getDesiredFiremode() const 60 { return this->desiredFiremode_; } 56 61 57 62 inline void setWeaponSystem(WeaponSystem *weaponSystem) … … 62 67 private: 63 68 WeaponSystem *weaponSystem_; 64 std::vector<WeaponSlot *> setWeaponSlots_; 65 unsigned int firemode_; 66 WeaponPack * attachedWeaponPack_; 69 unsigned int desiredFiremode_; 70 std::map<WeaponPack*, unsigned int> weaponpacks_; 67 71 }; 68 72 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSlot.cc
r2912 r2914 34 34 35 35 #include "Weapon.h" 36 #include "WeaponSystem.h" 36 37 37 38 namespace orxonox … … 43 44 RegisterObject(WeaponSlot); 44 45 45 this->unlimitedAmmo_ = false; 46 this->attachedWeapon_ = 0; 46 this->weaponSystem_ = 0; 47 this->weapon_ = 0; 48 47 49 this->setObjectMode(0x0); 48 50 … … 53 55 { 54 56 COUT(0) << "~WeaponSlot" << std::endl; 57 58 if (this->isInitialized() && this->weaponSystem_) 59 this->weaponSystem_->removeWeaponSlot(this); 55 60 } 56 61 … … 58 63 { 59 64 SUPER(WeaponSlot, XMLPort, xmlelement, mode); 60 }61 65 62 /*sets the munition type 63 *unlimited: true 64 *limited: false (in this case there will be munition) 65 */ 66 void WeaponSlot::setAmmoType(bool isUnlimited) 67 { 68 unlimitedAmmo_ = isUnlimited; 69 } 70 71 72 void WeaponSlot::fire() 73 { 74 if ( this->attachedWeapon_ ) 75 //COUT(0) << "WeaponSlot::fire" << std::endl; 76 this->attachedWeapon_->fire(); 66 // ... 77 67 } 78 68 79 69 void WeaponSlot::attachWeapon(Weapon *weapon) 80 70 { 81 this->attachedWeapon_ = weapon; 82 weapon->setAttachedToWeaponSlot(this); 83 //COUT(0) << "WeaponSlot::attachWeapon position=" << this->getWorldPosition() << std::endl; 84 weapon->setPosition(this->getPosition()); 71 if (this->weapon_) 72 this->removeWeapon(); 73 74 this->weapon_ = weapon; 75 76 if (this->weapon_) 77 { 78 this->weapon_->setWeaponSlot(this); 79 this->weapon_->setPosition(this->getPosition()); 80 } 85 81 } 86 82 87 Weapon * WeaponSlot::getAttachedWeapon() const83 void WeaponSlot::removeWeapon() 88 84 { 89 return this->attachedWeapon_; 85 if (this->weapon_) 86 { 87 this->weapon_->setWeaponSlot(0); 88 this->weapon_ = 0; 89 } 90 90 } 91 91 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSlot.h
r2912 r2914 43 43 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 44 44 45 void attachWeapon(Weapon * weapon);46 Weapon * getAttachedWeapon() const;47 void setAmmoType(bool isUnlimited);48 void fire();45 void attachWeapon(Weapon * weapon); 46 void removeWeapon(); 47 Weapon * getWeapon() const 48 { return this->weapon_; } 49 49 50 inline void setWeaponSystem(WeaponSystem *weaponSystem) 50 inline bool isOccupied() const 51 { return (this->weapon_ != 0); } 52 53 inline void setWeaponSystem(WeaponSystem * weaponSystem) 51 54 { this->weaponSystem_ = weaponSystem; } 52 55 inline WeaponSystem * getWeaponSystem() const … … 55 58 56 59 private: 57 Weapon *attachedWeapon_; 58 bool unlimitedAmmo_; 59 60 WeaponSystem *weaponSystem_; 60 WeaponSystem * weaponSystem_; 61 Weapon * weapon_; 61 62 }; 62 63 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc
r2912 r2914 36 36 #include "WeaponPack.h" 37 37 #include "WeaponSet.h" 38 #include "Weapon.h" 38 39 39 40 /* WeaponSystem … … 61 62 if (this->pawn_) 62 63 this->pawn_->setWeaponSystem(0); 63 } 64 } 65 66 void WeaponSystem::attachWeaponSet(WeaponSet *wSet) 67 { 68 if (!wSet) 69 return; 70 71 this->weaponSets_[wSet->getFireMode()] = wSet; 72 wSet->setWeaponSystem(this); 64 65 for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ) 66 delete (it++)->second; 67 68 for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ) 69 delete (*(it++)); 70 71 for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ) 72 delete (*(it++)); 73 } 74 } 75 76 void WeaponSystem::addWeaponSlot(WeaponSlot * wSlot) 77 { 78 if (!wSlot) 79 return; 80 81 this->weaponSlots_.insert(wSlot); 82 wSlot->setWeaponSystem(this); 83 } 84 85 void WeaponSystem::removeWeaponSlot(WeaponSlot * wSlot) 86 { 87 if (!wSlot) 88 return; 89 90 if (wSlot->getWeapon()) 91 this->removeWeaponPack(wSlot->getWeapon()->getWeaponPack()); 92 93 this->weaponSlots_.erase(wSlot); 94 } 95 96 WeaponSlot * WeaponSystem::getWeaponSlot(unsigned int index) const 97 { 98 unsigned int i = 0; 99 for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it) 100 { 101 ++i; 102 if (i > index) 103 return (*it); 104 } 105 return 0; 106 } 107 108 bool WeaponSystem::addWeaponSet(WeaponSet * wSet) 109 { 110 if (wSet) 111 return this->addWeaponSet(wSet, wSet->getDesiredFiremode()); 112 else 113 return false; 114 } 115 116 bool WeaponSystem::addWeaponSet(WeaponSet * wSet, unsigned int firemode) 117 { 118 if (!wSet || firemode >= WeaponSystem::MAX_FIRE_MODES) 119 return false; 120 121 std::map<unsigned int, WeaponSet*>::const_iterator it = this->weaponSets_.find(firemode); 122 if (it == this->weaponSets_.end()) 123 { 124 this->weaponSets_[firemode] = wSet; 125 wSet->setWeaponSystem(this); 126 return true; 127 } 128 129 return false; 130 } 131 132 void WeaponSystem::removeWeaponSet(WeaponSet * wSet) 133 { 134 for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ) 135 { 136 if (it->second == wSet) 137 this->weaponSets_.erase(it++); 138 else 139 ++it; 140 } 73 141 } 74 142 … … 85 153 } 86 154 87 void WeaponSystem::attachWeaponSlot(WeaponSlot *wSlot) 88 { 89 if (!wSlot) 90 return; 91 92 this->weaponSlots_.insert(wSlot); 93 wSlot->setWeaponSystem(this); 94 } 95 96 WeaponSlot * WeaponSystem::getWeaponSlot(unsigned int index) const 97 { 98 unsigned int i = 0; 155 bool WeaponSystem::canAddWeaponPack(WeaponPack * wPack) 156 { 157 if (!wPack) 158 return false; 159 160 unsigned int freeSlots = 0; 99 161 for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it) 162 { 163 if (!(*it)->isOccupied()) 164 ++freeSlots; 165 } 166 167 return (freeSlots >= wPack->getNumWeapons()); 168 } 169 170 bool WeaponSystem::addWeaponPack(WeaponPack * wPack) 171 { 172 if (!this->canAddWeaponPack(wPack)) 173 return false; 174 175 // Attach all weapons to the first free slots (and to the Pawn) 176 unsigned int i = 0; 177 for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it) 178 { 179 if (!(*it)->isOccupied() && i < wPack->getNumWeapons()) 180 { 181 Weapon* weapon = wPack->getWeapon(i); 182 (*it)->attachWeapon(weapon); 183 this->getPawn()->attach(weapon); 184 ++i; 185 } 186 } 187 188 // Assign the desired weaponmode to the firemodes 189 for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it) 190 { 191 unsigned int weaponmode = wPack->getDesiredWeaponmode(it->first); 192 if (weaponmode != WeaponSystem::WEAPON_MODE_UNASSIGNED) 193 it->second->setWeaponmodeLink(wPack, weaponmode); 194 } 195 196 this->weaponPacks_.insert(wPack); 197 wPack->setWeaponSystem(this); 198 wPack->attachNeededMunitionToAllWeapons(); // TODO - what is this? 199 200 return true; 201 } 202 203 void WeaponSystem::removeWeaponPack(WeaponPack * wPack) 204 { 205 // Remove all weapons from their WeaponSlot 206 unsigned int i = 0; 207 Weapon* weapon = 0; 208 while (weapon = wPack->getWeapon(i++)) 209 weapon->getWeaponSlot()->removeWeapon(); 210 211 // Remove all added links from the WeaponSets 212 for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it) 213 it->second->removeWeaponmodeLink(wPack); 214 215 // Remove the WeaponPack from the WeaponSystem 216 this->weaponPacks_.erase(wPack); 217 } 218 219 WeaponPack * WeaponSystem::getWeaponPack(unsigned int index) const 220 { 221 unsigned int i = 0; 222 for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it) 100 223 { 101 224 ++i; … … 106 229 } 107 230 108 void WeaponSystem::attachWeaponPack(WeaponPack *wPack, unsigned int wSetNumber) 109 { 110 if (!wPack) 111 return; 112 113 std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.find(wSetNumber); 114 if (it != this->weaponSets_.end() && it->second) 115 it->second->attachWeaponPack(wPack); 116 117 this->weaponPacks_.insert(wPack); 118 wPack->setWeaponSystem(this); 119 wPack->attachNeededMunitionToAllWeapons(); // TODO - what is this? 120 } 121 122 WeaponPack * WeaponSystem::getWeaponPack(unsigned int index) const 123 { 124 unsigned int i = 0; 125 for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it) 126 { 127 ++i; 128 if (i > index) 129 return (*it); 130 } 131 return 0; 132 } 231 bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2) 232 { 233 // TODO 234 } 235 236 void WeaponSystem::changeWeaponmode(WeaponPack * wPack, WeaponSet * wSet, unsigned int weaponmode) 237 { 238 if (!wPack || !wSet) 239 return; 240 241 // Check if the WeaponPack belongs to this WeaponSystem 242 std::set<WeaponPack *>::iterator it1 = this->weaponPacks_.find(wPack); 243 if (it1 == this->weaponPacks_.end()) 244 return; 245 246 // Check if the WeaponSet belongs to this WeaponSystem 247 bool foundWeaponSet = false; 248 for (std::map<unsigned int, WeaponSet *>::iterator it2 = this->weaponSets_.begin(); it2 != this->weaponSets_.end(); ++it2) 249 { 250 if (it2->second == wSet) 251 { 252 foundWeaponSet = true; 253 break; 254 } 255 } 256 if (!foundWeaponSet) 257 return; 258 259 // Finally set the link between firemode and weaponmode 260 wSet->setWeaponmodeLink(wPack, weaponmode); 261 } 133 262 134 263 void WeaponSystem::setNewMunition(const std::string& munitionType, Munition * munitionToAdd) … … 148 277 } 149 278 150 151 //n is the n'th weaponSet, starting with zero152 //SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode)153 //in future this could be well defined and not only for 3 different WeaponModes154 279 void WeaponSystem::fire(unsigned int firemode) 155 280 { -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h
r2912 r2914 40 40 namespace orxonox 41 41 { 42 const unsigned int MAX_FIRE_MODES = 8;43 44 42 class _OrxonoxExport WeaponSystem : public BaseObject 45 43 { … … 48 46 virtual ~WeaponSystem(); 49 47 50 void attachWeaponSlot(WeaponSlot * wSlot); 48 // adding and removing WeaponSlots 49 void addWeaponSlot(WeaponSlot * wSlot); 50 void removeWeaponSlot(WeaponSlot * wSlot); 51 51 WeaponSlot * getWeaponSlot(unsigned int index) const; 52 52 53 void attachWeaponSet(WeaponSet * wSet); 53 // adding and removing WeaponSets 54 bool addWeaponSet(WeaponSet * wSet); 55 bool addWeaponSet(WeaponSet * wSet, unsigned int firemode); 56 void removeWeaponSet(WeaponSet * wSet); 54 57 WeaponSet * getWeaponSet(unsigned int index) const; 55 58 56 void attachWeaponPack(WeaponPack * wPack, unsigned int wSetNumber); 59 // adding and removing WeaponPacks 60 bool canAddWeaponPack(WeaponPack * wPack); 61 bool addWeaponPack(WeaponPack * wPack); 62 void removeWeaponPack(WeaponPack * wPack); 57 63 WeaponPack * getWeaponPack(unsigned int index) const; 58 64 65 // configure slots and firemodes 66 bool swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2); 67 void changeWeaponmode(WeaponPack * wPack, WeaponSet * wSet, unsigned int weaponmode); 68 59 69 void fire(unsigned int firemode); 70 60 71 61 72 void setNewMunition(const std::string& munitionType, Munition * munitionToAdd); … … 71 82 { return this->weaponSlots_.size(); } 72 83 73 static inline unsigned int getMaxFireModes() 74 { return MAX_FIRE_MODES; } 75 static inline unsigned int getFireModeMask(unsigned int firemode) 84 static inline unsigned int getFiremodeMask(unsigned int firemode) 76 85 { return (0x1 << firemode); } 86 87 static const unsigned int MAX_FIRE_MODES = 8; 88 static const unsigned int FIRE_MODE_UNASSIGNED = (unsigned int)-1; 89 90 static const unsigned int MAX_WEAPON_MODES = 8; 91 static const unsigned int WEAPON_MODE_UNASSIGNED = (unsigned int)-1; 77 92 78 93 private: -
code/branches/weapons/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2912 r2914 123 123 if (this->weaponSystem_) 124 124 { 125 for (unsigned int firemode = 0; firemode < WeaponSystem:: getMaxFireModes(); firemode++)126 if (this->fire_ & WeaponSystem::getFire ModeMask(firemode))125 for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++) 126 if (this->fire_ & WeaponSystem::getFiremodeMask(firemode)) 127 127 this->weaponSystem_->fire(firemode); 128 128 } … … 255 255 void Pawn::fire(unsigned int firemode) 256 256 { 257 this->firehack_ |= WeaponSystem::getFire ModeMask(firemode);257 this->firehack_ |= WeaponSystem::getFiremodeMask(firemode); 258 258 } 259 259 … … 280 280 this->attach(wSlot); 281 281 if (this->weaponSystem_) 282 this->weaponSystem_->a ttachWeaponSlot(wSlot);282 this->weaponSystem_->addWeaponSlot(wSlot); 283 283 } 284 284 … … 291 291 } 292 292 293 void Pawn::addWeaponSet(WeaponSet * wSet) 294 { 295 if (this->weaponSystem_) 296 this->weaponSystem_->addWeaponSet(wSet); 297 } 298 299 WeaponSet * Pawn::getWeaponSet(unsigned int index) const 300 { 301 if (this->weaponSystem_) 302 return this->weaponSystem_->getWeaponSet(index); 303 else 304 return 0; 305 } 306 293 307 void Pawn::addWeaponPack(WeaponPack * wPack) 294 308 { 295 309 if (this->weaponSystem_) 296 this->weaponSystem_->attachWeaponPack(wPack, wPack->getFireMode()); 297 } 298 299 WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const 300 { 301 if (this->weaponSystem_) 302 return this->weaponSystem_->getWeaponPack(firemode); 303 else 304 return 0; 305 } 306 307 void Pawn::addWeaponSet(WeaponSet * wSet) 308 { 309 if (this->weaponSystem_) 310 this->weaponSystem_->attachWeaponSet(wSet); 311 } 312 313 WeaponSet * Pawn::getWeaponSet(unsigned int index) const 314 { 315 if (this->weaponSystem_) 316 return this->weaponSystem_->getWeaponSet(index); 310 this->weaponSystem_->addWeaponPack(wPack); 311 } 312 313 WeaponPack * Pawn::getWeaponPack(unsigned int index) const 314 { 315 if (this->weaponSystem_) 316 return this->weaponSystem_->getWeaponPack(index); 317 317 else 318 318 return 0; -
code/branches/weapons/src/orxonox/objects/worldentities/pawns/Pawn.h
r2912 r2914 85 85 void addWeaponSlot(WeaponSlot * wSlot); 86 86 WeaponSlot * getWeaponSlot(unsigned int index) const; 87 void addWeaponPack(WeaponPack * wPack);88 WeaponPack * getWeaponPack(unsigned int firemode) const;89 87 void addWeaponSet(WeaponSet * wSet); 90 88 WeaponSet * getWeaponSet(unsigned int index) const; 89 void addWeaponPack(WeaponPack * wPack); 90 WeaponPack * getWeaponPack(unsigned int index) const; 91 91 92 92 inline const WorldEntity* getWorldEntity() const
Note: See TracChangeset
for help on using the changeset viewer.