- Timestamp:
- Apr 8, 2009, 12:36:08 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
r2662 r2907 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 } … … 65 68 XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode); 66 69 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); 67 73 } 68 74 … … 73 79 } 74 80 81 void Weapon::setMunition() 82 { 83 this->munition_->setMaxBullets(this->bulletAmount_); 84 this->munition_->setMaxMagazines(this->magazineAmount_); 85 } 75 86 76 87 void Weapon::fire() 77 88 { 78 //COUT(0) << "LaserGun::fire, this=" << this << std::endl;79 89 if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_) 80 90 { 81 //COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;82 //COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;83 91 this->bulletReadyToShoot_ = false; 84 if ( this-> munition_->bullets() > 0)92 if ( this->unlimitedMunition_== true ) 85 93 { 86 94 //shoot 87 this-> takeBullets();95 this->reloadBullet(); 88 96 this->createProjectile(); 89 97 } 90 //if there are no bullets, but magazines91 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )92 {93 //COUT(0) << "LaserGun::fire - no bullets" << std::endl;94 this->takeMagazines();95 }96 98 else 97 99 { 98 //COUT(0) << "LaserGun::fire - no magazines" << std::endl; 99 //actions 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 } 100 118 } 101 119 } 102 120 else 103 121 { 104 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl; 105 //actions 122 //weapon not reloaded 106 123 } 107 124 … … 109 126 110 127 128 //weapon reloading 111 129 void Weapon::bulletTimer(float bulletLoadingTime) 112 130 { 113 //COUT(0) << "Weapon::bulletTimer started" << std::endl;114 131 this->bReloading_ = true; 115 132 this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); … … 117 134 void Weapon::magazineTimer(float magazineLoadingTime) 118 135 { 119 //COUT(0) << "Weapon::magazineTimer started" << std::endl;120 136 this->bReloading_ = true; 121 137 this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); … … 132 148 this->bReloading_ = false; 133 149 this->munition_->fillBullets(); 134 this->magazineReadyToShoot_ = true; 135 this->bulletReadyToShoot_ = true; 136 } 150 } 151 137 152 138 153 139 154 void Weapon::attachNeededMunition(std::string munitionName) 140 155 { 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 WeaponSystem156 /* 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 */ 143 158 if (this->parentWeaponSystem_) 144 159 { 145 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl; 160 //getMunitionType returns 0 if there is no such munitionType 146 161 Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); 147 162 if ( munition ) 163 { 148 164 this->munition_ = munition; 165 this->setMunition(); 166 } 149 167 else 150 168 { 151 //create new munition with identifier 152 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl; 169 //create new munition with identifier because there is no such munitionType 153 170 this->munitionIdentifier_ = ClassByString(munitionName); 154 171 this->munition_ = this->munitionIdentifier_.fabricate(this); 155 172 this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_); 173 this->setMunition(); 156 174 } 157 175 } … … 159 177 160 178 161 /*get and set functions162 *163 */164 165 void Weapon::setMunitionType(std::string munitionType)166 { this->munitionType_ = munitionType; }167 168 const std::string Weapon::getMunitionType()169 { return this->munitionType_; }170 171 void Weapon::setBulletLoadingTime(float loadingTime)172 { this->bulletLoadingTime_ = loadingTime; }173 174 const float Weapon::getBulletLoadingTime()175 { return this->bulletLoadingTime_; }176 177 void Weapon::setMagazineLoadingTime(float loadingTime)178 { this->magazineLoadingTime_ = loadingTime; }179 180 const float Weapon::getMagazineLoadingTime()181 { return this->magazineLoadingTime_; }182 183 184 179 Munition * Weapon::getAttachedMunition(std::string munitionType) 185 180 { 186 //COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;187 181 this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); 188 //COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;189 182 return this->munition_; 190 183 } 191 184 185 186 //these function are defined in the weapon classes 192 187 void Weapon::takeBullets() { }; 193 188 void Weapon::createProjectile() { }; 194 189 void Weapon::takeMagazines() { }; 190 void Weapon::reloadBullet() { }; 191 void Weapon::reloadMagazine() { }; 192 193 194 //get and set functions for XMLPort 195 void Weapon::setMunitionType(std::string munitionType) 196 { this->munitionType_ = munitionType; } 197 198 const std::string Weapon::getMunitionType() 199 { return this->munitionType_; } 200 201 void Weapon::setBulletLoadingTime(float loadingTime) 202 { this->bulletLoadingTime_ = loadingTime; } 203 204 const float Weapon::getBulletLoadingTime() 205 { return this->bulletLoadingTime_; } 206 207 void Weapon::setMagazineLoadingTime(float loadingTime) 208 { this->magazineLoadingTime_ = loadingTime; } 209 210 const float Weapon::getMagazineLoadingTime() 211 { return this->magazineLoadingTime_; } 212 213 void Weapon::setBulletAmount(unsigned int amount) 214 { this->bulletAmount_ = amount; } 215 216 const unsigned int Weapon::getBulletAmount() 217 { return this->bulletAmount_; } 218 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_; } 195 230 196 231 }
Note: See TracChangeset
for help on using the changeset viewer.