Changeset 2778
- Timestamp:
- Mar 12, 2009, 5:05:18 PM (16 years ago)
- Location:
- code/branches/weaponsystem/src/orxonox/objects/weaponSystem
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc
r2662 r2778 65 65 XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode); 66 66 XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode); 67 XMLPortParam(Weapon, "bSharedMunition", setSharedMunition, getSharedMunition, xmlelement, mode); 67 68 } 68 69 … … 97 98 { 98 99 //COUT(0) << "LaserGun::fire - no magazines" << std::endl; 99 // actions100 //no magazines 100 101 } 101 102 } … … 103 104 { 104 105 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl; 105 // actions106 //weapon not reloaded 106 107 } 107 108 … … 141 142 //COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl; 142 143 //if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem 144 //if the weapon shares one munitionType put it into sharedMunitionSet 145 //else to munitionSet 143 146 if (this->parentWeaponSystem_) 144 147 { 145 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl; 146 Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); 147 if ( munition ) 148 this->munition_ = munition; 149 else 150 { 151 //create new munition with identifier 152 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl; 148 if (this->bSharedMunition_ == false) 149 { 153 150 this->munitionIdentifier_ = ClassByString(munitionName); 154 151 this->munition_ = this->munitionIdentifier_.fabricate(this); 155 152 this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_); 156 153 } 154 else 155 { 156 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl; 157 //getMunitionType returns 0 if there is no such munitionType 158 Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); 159 if ( munition ) 160 this->munition_ = munition; 161 else 162 { 163 //create new munition with identifier because there is no such munitionType 164 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl; 165 this->munitionIdentifier_ = ClassByString(munitionName); 166 this->munition_ = this->munitionIdentifier_.fabricate(this); 167 this->parentWeaponSystem_->setNewSharedMunition(munitionName, this->munition_); 168 } 169 } 157 170 } 158 171 } … … 180 193 const float Weapon::getMagazineLoadingTime() 181 194 { return this->magazineLoadingTime_; } 195 196 void Weapon::setSharedMunition(bool bSharedMunition) 197 { this->bSharedMunition_ = bSharedMunition; } 198 199 const bool Weapon::getSharedMunition() 200 { return this->bSharedMunition_; } 182 201 183 202 -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h
r2662 r2778 68 68 virtual void setMagazineLoadingTime(float loadingTime); 69 69 virtual const float getMagazineLoadingTime(); 70 virtual void setSharedMunition(bool bSharedMunition); 71 virtual const bool getSharedMunition(); 70 72 71 73 virtual void takeBullets(); … … 91 93 bool bulletReadyToShoot_; 92 94 bool magazineReadyToShoot_; 95 bool bSharedMunition_; 93 96 float bulletLoadingTime_; 94 97 float magazineLoadingTime_; -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc
r2662 r2778 56 56 void WeaponSet::attachWeaponPack(WeaponPack *wPack) 57 57 { 58 //COUT(0) << "WeaponSet::attachWeaponPack" << std::endl;59 //COUT(0) << "........ parentWeaponSystem_=" << this->parentWeaponSystem_ << std::endl;60 //COUT(0) << "........ this->parentWeaponSystem_->getWeaponSlotSize()" << this->parentWeaponSystem_->getWeaponSlotSize() << std::endl;61 //COUT(0) << "........ wPack->getSize()" << wPack->getSize() << std::endl;62 58 if ( this->parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) ) 63 59 { 64 //COUT(0) << "WeaponSet::attachWeaponPack after if" << std::endl;65 60 this->attachedWeaponPack_ = wPack; 66 61 int wPackWeapon = 0; //WeaponCounter for Attaching 67 62 //should be possible to choose which slot to use 63 64 //attach every weapon of the weaponPack to a weaponSlot 68 65 for ( int i=0; i < wPack->getSize() ; i++ ) 69 66 { 70 67 //at the moment this function only works for one weaponPack in the entire WeaponSystem... 68 //it also takes the first free weaponSlot... 71 69 if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() == 0 && this->parentWeaponSystem_->getWeaponSlotPointer(i) != 0) //if slot not full 72 70 { 73 //COUT(0) << "WeaponSet::attachWeaponPack attaching Weapon" << std::endl;74 71 this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) ); 75 72 this->parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) ); -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc
r2710 r2778 38 38 39 39 40 /* WEAPONSYSTEM 41 * creates the WeaponSystem and the ability to use weapons and munition 42 * loads the weapon the whole weaponSystem setting from an xml file 40 /* WeaponSystem 43 41 * 42 * www.orxonox.net/wiki/WeaponSystem 44 43 */ 45 44 … … 84 83 } 85 84 86 //returns the Pointer to the munitionType 85 void WeaponSystem::setNewSharedMunition(std::string munitionType, Munition * munitionToAdd) 86 { 87 this->munitionSharedSet_[munitionType] = munitionToAdd; 88 } 89 90 //returns the Pointer to the munitionType, if this munitionType doesn't exist returns 0, see Weapon::attachNeededMunition 87 91 Munition * WeaponSystem::getMunitionType(std::string munitionType) 88 92 { 89 93 //COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl; 90 std::map<std::string, Munition *>::const_iterator it = this->munitionS et_.find(munitionType);91 if (it != this->munitionS et_.end())94 std::map<std::string, Munition *>::const_iterator it = this->munitionSharedSet_.find(munitionType); 95 if (it != this->munitionSharedSet_.end()) 92 96 return it->second; 93 97 else … … 96 100 97 101 98 /* 99 //the first weaponSet is at n=0 100 void WeaponSystem::setActiveWeaponSet(unsigned int n) 101 { 102 if (n < this->weaponSets_.size()) 103 this->activeWeaponSet_ = this->weaponSets_[n]; 104 else 105 this->activeWeaponSet_ = this->weaponSets_[0]; 106 } 107 */ 102 108 103 109 104 110 105 //n is the n'th weaponSet, starting with zero 111 //SpaceShip.cc only needs to have the keybinding to a specific Set-number n 106 //SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode) 112 107 void WeaponSystem::fire(WeaponMode::Enum n) 113 108 { -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h
r2710 r2778 53 53 //void fire(); 54 54 void fire(WeaponMode::Enum fireMode); 55 //void setActiveWeaponSet(unsigned int n);56 55 void attachWeaponPack(WeaponPack * wPack, unsigned int firemode); 57 56 WeaponSet * getWeaponSetPointer(unsigned int n); … … 59 58 WeaponPack * getWeaponPackPointer(unsigned int n); 60 59 void setNewMunition(std::string munitionType, Munition * munitionToAdd); 60 void setNewSharedMunition(std::string munitionType, Munition * munitionToAdd); 61 61 Munition * getMunitionType(std::string munitionType); 62 62 … … 73 73 std::vector<WeaponSlot *> weaponSlots_; 74 74 std::vector<WeaponPack *> weaponPacks_; 75 std::map<std::string, Munition *> munitionSharedSet_; 75 76 std::map<std::string, Munition *> munitionSet_; 76 77 WeaponSet *activeWeaponSet_;
Note: See TracChangeset
for help on using the changeset viewer.