Changeset 2804 for code/branches/weaponsystem/src/orxonox
- Timestamp:
- Mar 19, 2009, 4:55:08 PM (16 years ago)
- Location:
- code/branches/weaponsystem/src/orxonox/objects
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/Munition.cc
r2662 r2804 105 105 void Munition::fillBullets() 106 106 { 107 //COUT(0) << "Munition::fillBullets maxBullets_=" << this->maxBullets_ << std::endl;108 107 this->bullets_ = this->maxBullets_; 109 108 } -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc
r2778 r2804 42 42 { 43 43 RegisterObject(Weapon); 44 44 45 this->bulletReadyToShoot_ = true; 45 46 this->magazineReadyToShoot_ = true; 46 47 this->parentWeaponSystem_ = 0; 47 48 this->attachedToWeaponSlot_ = 0; 48 this->munition_ = 0;49 49 this->bulletLoadingTime_ = 0; 50 50 this->magazineLoadingTime_ = 0; 51 51 this->bReloading_ = false; 52 52 this->bulletAmount_= 0; 53 this->magazineAmount_ = 0; 54 this->munition_ = 0; 55 this->unlimitedMunition_ = false; 53 56 this->setObjectMode(0x0); 54 57 } … … 66 69 XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode); 67 70 XMLPortParam(Weapon, "bSharedMunition", setSharedMunition, getSharedMunition, xmlelement, mode); 71 XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode); 72 XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode); 73 XMLPortParam(Weapon, "unlimitedMunition", setUnlimitedMunition, getUnlimitedMunition, xmlelement, mode); 68 74 } 69 75 … … 74 80 } 75 81 82 void Weapon::setMunition() 83 { 84 this->munition_->setMaxBullets(this->bulletAmount_); 85 this->munition_->setMaxMagazines(this->magazineAmount_); 86 } 76 87 77 88 void Weapon::fire() 78 89 { 79 //COUT(0) << "LaserGun::fire, this=" << this<< std::endl;90 COUT(0) << "Weapon::fire" << std::endl; 80 91 if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_) 81 92 { 82 //COUT(0) << "LaserGun::fire - ready to shoot" << std::endl; 83 //COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl; 93 COUT(0) << "Weapon::fire 2" << std::endl; 84 94 this->bulletReadyToShoot_ = false; 85 if ( this->munition_->bullets() > 0) 86 { 95 if ( this->unlimitedMunition_== true ) 96 { 97 COUT(0) << "Weapon::fire 3" << std::endl; 87 98 //shoot 88 this-> takeBullets();99 this->reloadBullet(); 89 100 this->createProjectile(); 90 101 } 91 //if there are no bullets, but magazines92 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )93 {94 //COUT(0) << "LaserGun::fire - no bullets" << std::endl;95 this->takeMagazines();96 }97 102 else 98 103 { 99 //COUT(0) << "LaserGun::fire - no magazines" << std::endl; 100 //no magazines 104 COUT(0) << "Weapon::fire 4" << std::endl; 105 if ( this->munition_->bullets() > 0) 106 { 107 COUT(0) << "Weapon::fire 5" << std::endl; 108 //shoot 109 this->takeBullets(); 110 this->reloadBullet(); 111 this->createProjectile(); 112 } 113 //if there are no bullets, but magazines 114 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 ) 115 { 116 COUT(0) << "Weapon::fire 6" << std::endl; 117 this->takeMagazines(); 118 this->reloadMagazine(); 119 } 120 else 121 { 122 //no magazines 123 } 101 124 } 102 125 } 103 126 else 104 127 { 105 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets()<< std::endl;128 COUT(0) << "Weapon::fire not reloaded" << std::endl; 106 129 //weapon not reloaded 107 130 } … … 109 132 } 110 133 111 134 /* 135 * weapon reloading 136 */ 112 137 void Weapon::bulletTimer(float bulletLoadingTime) 113 138 { 114 //COUT(0) << "Weapon::bulletTimer started" << std::endl;115 139 this->bReloading_ = true; 116 140 this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); … … 118 142 void Weapon::magazineTimer(float magazineLoadingTime) 119 143 { 120 //COUT(0) << "Weapon::magazineTimer started" << std::endl;121 144 this->bReloading_ = true; 122 145 this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); … … 140 163 void Weapon::attachNeededMunition(std::string munitionName) 141 164 { 142 //COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl; 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 165 /* 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 166 * if the weapon shares one munitionType put it into sharedMunitionSet else to munitionSet 167 */ 146 168 if (this->parentWeaponSystem_) 147 169 { … … 154 176 else 155 177 { 156 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;157 178 //getMunitionType returns 0 if there is no such munitionType 158 179 Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); … … 162 183 { 163 184 //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 185 this->munitionIdentifier_ = ClassByString(munitionName); 166 186 this->munition_ = this->munitionIdentifier_.fabricate(this); … … 168 188 } 169 189 } 190 this->setMunition(); 170 191 } 171 192 } 193 194 195 Munition * Weapon::getAttachedMunition(std::string munitionType) 196 { 197 this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); 198 return this->munition_; 199 } 200 201 202 //these function are defined in the weapon classes 203 void Weapon::takeBullets() { }; 204 void Weapon::createProjectile() { }; 205 void Weapon::takeMagazines() { }; 206 void Weapon::reloadBullet() { }; 207 void Weapon::reloadMagazine() { }; 172 208 173 209 … … 175 211 * 176 212 */ 177 178 213 void Weapon::setMunitionType(std::string munitionType) 179 214 { this->munitionType_ = munitionType; } … … 200 235 { return this->bSharedMunition_; } 201 236 202 203 Munition * Weapon::getAttachedMunition(std::string munitionType) 204 { 205 //COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl; 206 this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); 207 //COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl; 208 return this->munition_; 209 } 210 211 void Weapon::takeBullets() { }; 212 void Weapon::createProjectile() { }; 213 void Weapon::takeMagazines() { }; 237 void Weapon::setBulletAmount(unsigned int amount) 238 { this->bulletAmount_ = amount; } 239 240 const unsigned int Weapon::getBulletAmount() 241 { return this->bulletAmount_; } 242 243 void Weapon::setMagazineAmount(unsigned int amount) 244 { this->magazineAmount_ = amount; } 245 246 const unsigned int Weapon::getMagazineAmount() 247 { return this->magazineAmount_; } 248 249 void Weapon::setUnlimitedMunition(bool unlimitedMunition) 250 { this->unlimitedMunition_ = unlimitedMunition; } 251 252 const bool Weapon::getUnlimitedMunition() 253 { return this->unlimitedMunition_; } 214 254 215 255 } -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h
r2778 r2804 62 62 void magazineReloaded(); 63 63 64 //XMLPort functions 64 65 virtual void setMunitionType(std::string munitionType); 65 66 virtual const std::string getMunitionType(); … … 70 71 virtual void setSharedMunition(bool bSharedMunition); 71 72 virtual const bool getSharedMunition(); 73 virtual void setBulletAmount(unsigned int amount); 74 virtual const unsigned int getBulletAmount(); 75 virtual void setMagazineAmount(unsigned int amount); 76 virtual const unsigned int getMagazineAmount(); 77 virtual void setUnlimitedMunition(bool unlimitedMunition); 78 virtual const bool getUnlimitedMunition(); 72 79 80 //weapon actions 73 81 virtual void takeBullets(); 74 82 virtual void takeMagazines(); 75 83 virtual void createProjectile(); 84 virtual void reloadBullet(); 85 virtual void reloadMagazine(); 76 86 87 //manually set or reset 88 virtual void setWeapon(); 89 virtual void setMunition(); 90 77 91 inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem) 78 92 { this->parentWeaponSystem_=parentWeaponSystem; }; … … 85 99 { return this->attachedToWeaponSlot_; } 86 100 87 virtual void setWeapon();88 101 89 102 private: … … 94 107 bool magazineReadyToShoot_; 95 108 bool bSharedMunition_; 109 bool unlimitedMunition_; 96 110 float bulletLoadingTime_; 97 111 float magazineLoadingTime_; 112 unsigned int bulletAmount_; 113 unsigned int magazineAmount_; 98 114 std::string munitionType_; 99 115 -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.cc
r2710 r2804 63 63 for (int i=0; i < (int) this->weapons_.size(); i++) 64 64 { 65 //COUT(0) << "WeaponPack::fire (attached from WeaponSet) from Weapon: "<< i << std::endl;66 65 this->weapons_[i]->getAttachedToWeaponSlot()->fire(); 67 66 } … … 83 82 void WeaponPack::setFireMode(unsigned int firemode) 84 83 { 85 //COUT(0) << "WeaponPack::setFireMode " << std::endl;86 84 this->firemode_ = firemode; 87 85 } … … 94 92 void WeaponPack::addWeapon(Weapon * weapon) 95 93 { 96 //COUT(0) << "WeaponPack::addWeapon:" << weapon << " munition " << weapon->getMunitionType() << std::endl;97 94 this->weapons_.push_back(weapon); 98 95 } … … 117 114 { 118 115 this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType()); 119 //hack!120 116 this->weapons_[i]->setWeapon(); 121 117 } -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.h
r2710 r2804 59 59 const Weapon * getWeapon(unsigned int index); 60 60 61 //functions with effect to all weapons of the weaponPack 61 62 //functions needed for creating Pointer to the right objects (-->Pawn.cc) 62 63 void setParentWeaponSystemToAllWeapons(WeaponSystem * weaponSystem); -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc
r2778 r2804 60 60 this->attachedWeaponPack_ = wPack; 61 61 int wPackWeapon = 0; //WeaponCounter for Attaching 62 62 63 //should be possible to choose which slot to use 63 64 64 //attach every weapon of the weaponPack to a weaponSlot 65 65 for ( int i=0; i < wPack->getSize() ; i++ ) … … 80 80 if ( this->parentWeaponSystem_->getWeaponSlotPointer(k)->getAttachedWeapon() == 0 ) 81 81 { 82 //COUT(0) << "WeaponSet::attachWeaponPack mode 2 k="<< k << std::endl;83 82 this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(k) ); 84 83 this->parentWeaponSystem_->getWeaponSlotPointer(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) ); … … 96 95 { 97 96 //fires all WeaponSlots available for this weaponSet attached from the WeaponPack 98 //COUT(0) << "WeaponSet::fire from Pack: " << this->attachedWeaponPack_ << std::endl;99 97 if (this->attachedWeaponPack_) 100 98 this->attachedWeaponPack_->fire(); -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc
r2778 r2804 51 51 RegisterObject(WeaponSystem); 52 52 53 this->activeWeaponSet_ = 0;54 53 this->parentPawn_ = 0; 55 54 } … … 91 90 Munition * WeaponSystem::getMunitionType(std::string munitionType) 92 91 { 93 //COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl;94 92 std::map<std::string, Munition *>::const_iterator it = this->munitionSharedSet_.find(munitionType); 95 93 if (it != this->munitionSharedSet_.end()) … … 105 103 //n is the n'th weaponSet, starting with zero 106 104 //SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode) 105 //in future this could be well defined and not only for 3 different WeaponModes 107 106 void WeaponSystem::fire(WeaponMode::Enum n) 108 107 { … … 120 119 break; 121 120 } 122 //COUT(0) << "WeaponSystem::fire" << std::endl;123 121 if (set < (int)this->weaponSets_.size()) 124 //COUT(0) << "WeaponSystem::fire - after if" << std::endl;125 122 this->weaponSets_[set]->fire(); 126 123 } -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h
r2778 r2804 75 75 std::map<std::string, Munition *> munitionSharedSet_; 76 76 std::map<std::string, Munition *> munitionSet_; 77 WeaponSet *activeWeaponSet_;78 77 Pawn *parentPawn_; 79 78 }; -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc
r2662 r2804 53 53 } 54 54 55 void LaserGun::reloadBullet() 56 { 57 this->bulletTimer(this->bulletLoadingTime_); 58 } 59 60 void LaserGun::reloadMagazine() 61 { 62 this->magazineTimer(this->magazineLoadingTime_); 63 } 64 55 65 void LaserGun::takeBullets() 56 66 { 57 //COUT(0) << "LaserGun::takeBullets" << std::endl;58 67 this->munition_->removeBullets(1); 59 this->bulletTimer(this->bulletLoadingTime_);60 68 } 61 69 … … 63 71 { 64 72 this->munition_->removeMagazines(1); 65 this->magazineTimer(this->magazineLoadingTime_);66 73 } 67 74 68 75 void LaserGun::createProjectile() 69 76 { 70 //COUT(0) << "LaserGun::createProjectile" << std::endl;71 77 BillboardProjectile* projectile = new ParticleProjectile(this); 72 78 projectile->setOrientation(this->getWorldOrientation()); -
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h
r2662 r2804 51 51 virtual void takeMagazines(); 52 52 virtual void createProjectile(); 53 virtual void reloadBullet(); 54 virtual void reloadMagazine(); 53 55 54 56 private: -
code/branches/weaponsystem/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2662 r2804 222 222 ExplosionChunk* chunk = new ExplosionChunk(this->getCreator()); 223 223 chunk->setPosition(this->getPosition()); 224 225 224 } 226 225 } … … 243 242 } 244 243 244 245 /* WeaponSystem: 246 * functions load Slot, Set, Pack from XML and make sure all parent-pointers are set. 247 * with setWeaponPack you can not just load a Pack from XML but if a Pack already exists anywhere, you can attach it. 248 * --> e.g. Pickup-Items 249 */ 245 250 void Pawn::setWeaponSlot(WeaponSlot * wSlot) 246 251 {
Note: See TracChangeset
for help on using the changeset viewer.