- Timestamp:
- Apr 8, 2009, 12:58:47 AM (16 years ago)
- Location:
- code/branches/questsystem5
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5
- Property svn:mergeinfo changed
-
code/branches/questsystem5/src/orxonox/objects/weaponSystem/Weapon.cc
r2907 r2908 42 42 { 43 43 RegisterObject(Weapon); 44 45 44 this->bulletReadyToShoot_ = true; 46 45 this->magazineReadyToShoot_ = true; 47 46 this->parentWeaponSystem_ = 0; 48 47 this->attachedToWeaponSlot_ = 0; 48 this->munition_ = 0; 49 49 this->bulletLoadingTime_ = 0; 50 50 this->magazineLoadingTime_ = 0; 51 51 this->bReloading_ = false; 52 this->bulletAmount_= 0; 53 this->magazineAmount_ = 0; 54 this->munition_ = 0; 55 this->unlimitedMunition_ = false; 52 56 53 this->setObjectMode(0x0); 57 54 } … … 68 65 XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode); 69 66 XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode); 70 XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode);71 XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode);72 XMLPortParam(Weapon, "unlimitedMunition", setUnlimitedMunition, getUnlimitedMunition, xmlelement, mode);73 67 } 74 68 … … 79 73 } 80 74 81 void Weapon::setMunition()82 {83 this->munition_->setMaxBullets(this->bulletAmount_);84 this->munition_->setMaxMagazines(this->magazineAmount_);85 }86 75 87 76 void Weapon::fire() 88 77 { 78 //COUT(0) << "LaserGun::fire, this=" << this << std::endl; 89 79 if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_) 90 80 { 81 //COUT(0) << "LaserGun::fire - ready to shoot" << std::endl; 82 //COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl; 91 83 this->bulletReadyToShoot_ = false; 92 if ( this-> unlimitedMunition_== true)84 if ( this->munition_->bullets() > 0) 93 85 { 94 86 //shoot 95 this-> reloadBullet();87 this->takeBullets(); 96 88 this->createProjectile(); 89 } 90 //if there are no bullets, but magazines 91 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 ) 92 { 93 //COUT(0) << "LaserGun::fire - no bullets" << std::endl; 94 this->takeMagazines(); 97 95 } 98 96 else 99 97 { 100 if ( this->munition_->bullets() > 0) 101 { 102 //shoot and reload 103 this->takeBullets(); 104 this->reloadBullet(); 105 this->createProjectile(); 106 } 107 //if there are no bullets, but magazines 108 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 ) 109 { 110 //reload magazine 111 this->takeMagazines(); 112 this->reloadMagazine(); 113 } 114 else 115 { 116 //no magazines 117 } 98 //COUT(0) << "LaserGun::fire - no magazines" << std::endl; 99 //actions 118 100 } 119 101 } 120 102 else 121 103 { 122 //weapon not reloaded 104 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl; 105 //actions 123 106 } 124 107 … … 126 109 127 110 128 //weapon reloading129 111 void Weapon::bulletTimer(float bulletLoadingTime) 130 112 { 113 //COUT(0) << "Weapon::bulletTimer started" << std::endl; 131 114 this->bReloading_ = true; 132 115 this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); … … 134 117 void Weapon::magazineTimer(float magazineLoadingTime) 135 118 { 119 //COUT(0) << "Weapon::magazineTimer started" << std::endl; 136 120 this->bReloading_ = true; 137 121 this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); … … 148 132 this->bReloading_ = false; 149 133 this->munition_->fillBullets(); 134 this->magazineReadyToShoot_ = true; 135 this->bulletReadyToShoot_ = true; 150 136 } 151 152 137 153 138 154 139 void Weapon::attachNeededMunition(std::string munitionName) 155 140 { 156 /* 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 157 */141 //COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl; 142 //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 158 143 if (this->parentWeaponSystem_) 159 144 { 160 //getMunitionType returns 0 if there is no such munitionType 145 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl; 161 146 Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); 162 147 if ( munition ) 163 {164 148 this->munition_ = munition; 165 this->setMunition();166 }167 149 else 168 150 { 169 //create new munition with identifier because there is no such munitionType 151 //create new munition with identifier 152 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl; 170 153 this->munitionIdentifier_ = ClassByString(munitionName); 171 154 this->munition_ = this->munitionIdentifier_.fabricate(this); 172 155 this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_); 173 this->setMunition();174 156 } 175 157 } … … 177 159 178 160 179 Munition * Weapon::getAttachedMunition(std::string munitionType) 180 { 181 this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); 182 return this->munition_; 183 } 161 /*get and set functions 162 * 163 */ 184 164 185 186 //these function are defined in the weapon classes187 void Weapon::takeBullets() { };188 void Weapon::createProjectile() { };189 void Weapon::takeMagazines() { };190 void Weapon::reloadBullet() { };191 void Weapon::reloadMagazine() { };192 193 194 //get and set functions for XMLPort195 165 void Weapon::setMunitionType(std::string munitionType) 196 166 { this->munitionType_ = munitionType; } … … 211 181 { return this->magazineLoadingTime_; } 212 182 213 void Weapon::setBulletAmount(unsigned int amount)214 { this->bulletAmount_ = amount; }215 183 216 const unsigned int Weapon::getBulletAmount() 217 { return this->bulletAmount_; } 184 Munition * Weapon::getAttachedMunition(std::string munitionType) 185 { 186 //COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl; 187 this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); 188 //COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl; 189 return this->munition_; 190 } 218 191 219 void Weapon::setMagazineAmount(unsigned int amount) 220 { this->magazineAmount_ = amount; } 221 222 const unsigned int Weapon::getMagazineAmount() 223 { return this->magazineAmount_; } 224 225 void Weapon::setUnlimitedMunition(bool unlimitedMunition) 226 { this->unlimitedMunition_ = unlimitedMunition; } 227 228 const bool Weapon::getUnlimitedMunition() 229 { return this->unlimitedMunition_; } 192 void Weapon::takeBullets() { }; 193 void Weapon::createProjectile() { }; 194 void Weapon::takeMagazines() { }; 230 195 231 196 }
Note: See TracChangeset
for help on using the changeset viewer.