Changeset 2915 for code/branches/weapons/src/orxonox/objects
- Timestamp:
- Apr 12, 2009, 12:34:55 AM (16 years ago)
- Location:
- code/branches/weapons/src/orxonox/objects/weaponSystem
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt
r2710 r2915 6 6 WeaponSlot.cc 7 7 WeaponSystem.cc 8 DefaultWeaponmodeLink.cc 8 9 ) 9 10 -
code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc
r2914 r2915 34 34 35 35 #include "Munition.h" 36 #include "WeaponPack.h" 36 37 #include "WeaponSystem.h" 37 38 … … 64 65 { 65 66 COUT(0) << "~Weapon" << std::endl; 67 if (this->isInitialized() && this->weaponPack_) 68 this->weaponPack_->removeWeapon(this); 66 69 } 67 70 … … 69 72 { 70 73 SUPER(Weapon, XMLPort, xmlelement, mode); 74 71 75 XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode); 72 76 XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode); -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
r2914 r2915 23 23 * Martin Polak 24 24 * Co-authors: 25 * ... * 25 * ... 26 * 26 27 */ 27 28 … … 36 37 #include "WeaponSlot.h" 37 38 #include "WeaponSystem.h" 39 #include "DefaultWeaponmodeLink.h" 38 40 39 41 namespace orxonox … … 55 57 56 58 if (this->isInitialized() && this->weaponSystem_) 59 { 57 60 this->weaponSystem_->removeWeaponPack(this); 61 62 while (!this->weapons_.empty()) 63 delete (*this->weapons_.begin()); 64 65 for (std::set<DefaultWeaponmodeLink*>::iterator it = this->links_.begin(); it != this->links_.end(); ) 66 delete (*(it++)); 67 } 58 68 } 59 69 … … 63 73 64 74 XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode); 75 XMLPortObject(WeaponPack, DefaultWeaponmodeLink, "links", addDefaultWeaponmodeLink, getDefaultWeaponmodeLink, xmlelement, mode); 65 76 } 66 77 … … 80 91 } 81 92 93 void WeaponPack::removeWeapon(Weapon * weapon) 94 { 95 if (!weapon) 96 return; 97 98 this->weapons_.erase(weapon); 99 weapon->setWeaponPack(0); 100 } 101 82 102 Weapon * WeaponPack::getWeapon(unsigned int index) const 83 103 { … … 94 114 } 95 115 96 void WeaponPack::setWeaponSystemToAllWeapons( WeaponSystem * weaponSystem)116 void WeaponPack::setWeaponSystemToAllWeapons() 97 117 { 98 118 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 99 (*it)->setWeaponSystem( weaponSystem);119 (*it)->setWeaponSystem(this->weaponSystem_); 100 120 } 101 121 … … 108 128 } 109 129 } 130 131 void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link) 132 { 133 this->links_.insert(link); 134 } 135 136 DefaultWeaponmodeLink* WeaponPack::getDefaultWeaponmodeLink(unsigned int index) const 137 { 138 unsigned int i = 0; 139 for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it) 140 { 141 if (i == index) 142 return (*it); 143 144 ++i; 145 } 146 return 0; 147 } 148 149 unsigned int WeaponPack::getDesiredWeaponmode(unsigned int firemode) const 150 { 151 for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it) 152 if ((*it)->getFiremode() == firemode) 153 return (*it)->getWeaponmode(); 154 155 return WeaponSystem::WEAPON_MODE_UNASSIGNED; 156 } 110 157 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h
r2914 r2915 50 50 51 51 void addWeapon(Weapon * weapon); 52 void removeWeapon(Weapon * weapon); 52 53 Weapon * getWeapon(unsigned int index) const; 53 54 … … 55 56 { return this->weapons_.size(); } 56 57 57 unsigned int getDesiredWeaponmode(unsigned int firemode) { return 0; } // TODO 58 void addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link); 59 DefaultWeaponmodeLink* getDefaultWeaponmodeLink(unsigned int index) const; 58 60 59 void attachNeededMunitionToAllWeapons();61 unsigned int getDesiredWeaponmode(unsigned int firemode) const; 60 62 61 63 inline void setWeaponSystem(WeaponSystem *weaponSystem) 62 { this->weaponSystem_ = weaponSystem; this->setWeaponSystemToAllWeapons(weaponSystem); } 64 { 65 this->weaponSystem_ = weaponSystem; 66 this->setWeaponSystemToAllWeapons(); 67 this->attachNeededMunitionToAllWeapons(); 68 } 63 69 inline WeaponSystem * getWeaponSystem() const 64 70 { return this->weaponSystem_; } 65 71 66 72 private: 67 void setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem); 73 void setWeaponSystemToAllWeapons(); 74 void attachNeededMunitionToAllWeapons(); 68 75 69 76 std::set<Weapon *> weapons_; 77 std::set<DefaultWeaponmodeLink *> links_; 70 78 WeaponSystem * weaponSystem_; 71 79 }; -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc
r2914 r2915 23 23 * Martin Polak 24 24 * Co-authors: 25 * ... * 25 * ... 26 * 26 27 */ 27 28 -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc
r2914 r2915 63 63 this->pawn_->setWeaponSystem(0); 64 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++)); 65 // for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ) 66 // delete (it++)->second; 67 while (!this->weaponSets_.empty()) 68 delete (this->weaponSets_.begin()->second); 69 70 // for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ) 71 // delete (*(it++)); 72 while (!this->weaponPacks_.empty()) 73 delete (*this->weaponPacks_.begin()); 74 75 // for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ) 76 // delete (*(it++)); 77 while (!this->weaponSlots_.empty()) 78 delete (*this->weaponSlots_.begin()); 73 79 } 74 80 } … … 79 85 return; 80 86 81 this->weaponSlots_. insert(wSlot);87 this->weaponSlots_.push_back(wSlot); 82 88 wSlot->setWeaponSystem(this); 83 89 } … … 91 97 this->removeWeaponPack(wSlot->getWeapon()->getWeaponPack()); 92 98 93 this->weaponSlots_.erase(wSlot); 99 for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it) 100 { 101 if ((*it) == wSlot) 102 { 103 this->weaponSlots_.erase(it); 104 break; 105 } 106 } 94 107 } 95 108 … … 97 110 { 98 111 unsigned int i = 0; 99 for (std:: set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)112 for (std::vector<WeaponSlot*>::const_iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it) 100 113 { 101 114 ++i; … … 159 172 160 173 unsigned int freeSlots = 0; 161 for (std:: set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)174 for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it) 162 175 { 163 176 if (!(*it)->isOccupied()) … … 175 188 // Attach all weapons to the first free slots (and to the Pawn) 176 189 unsigned int i = 0; 177 for (std:: set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)190 for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it) 178 191 { 179 192 if (!(*it)->isOccupied() && i < wPack->getNumWeapons()) … … 196 209 this->weaponPacks_.insert(wPack); 197 210 wPack->setWeaponSystem(this); 198 wPack->attachNeededMunitionToAllWeapons(); // TODO - what is this?199 211 200 212 return true; … … 231 243 bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2) 232 244 { 233 // TODO 245 if (!wSlot1 || !wSlot2) 246 return false; 247 248 Weapon* weapon1 = wSlot1->getWeapon(); 249 Weapon* weapon2 = wSlot2->getWeapon(); 250 251 wSlot1->attachWeapon(weapon2); 252 wSlot2->attachWeapon(weapon1); 253 254 return true; 255 // In the future, certain weapons might not fit to some slots. Swapping would then be 256 // impossible and the returnvalue would be false. 234 257 } 235 258 -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h
r2914 r2915 35 35 #include <set> 36 36 #include <map> 37 #include <vector> 37 38 38 39 #include "core/BaseObject.h" … … 93 94 private: 94 95 std::map<unsigned int, WeaponSet *> weaponSets_; 95 std:: set<WeaponSlot *> weaponSlots_;96 std::vector<WeaponSlot *> weaponSlots_; 96 97 std::set<WeaponPack *> weaponPacks_; 97 98 std::map<std::string, Munition *> munitionSet_;
Note: See TracChangeset
for help on using the changeset viewer.