Changeset 2662 for code/trunk/src/orxonox/objects/weaponSystem/Weapon.cc
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/weaponSystem/Weapon.cc
r2098 r2662 37 37 namespace orxonox 38 38 { 39 Weapon::Weapon(BaseObject* creator) : BaseObject(creator) 39 CreateFactory(Weapon); 40 41 Weapon::Weapon(BaseObject* creator) : StaticEntity(creator) 40 42 { 41 43 RegisterObject(Weapon); 44 this->bulletReadyToShoot_ = true; 45 this->magazineReadyToShoot_ = true; 46 this->parentWeaponSystem_ = 0; 47 this->attachedToWeaponSlot_ = 0; 48 this->munition_ = 0; 49 this->bulletLoadingTime_ = 0; 50 this->magazineLoadingTime_ = 0; 51 this->bReloading_ = false; 42 52 43 this->loadingTime_ = 0; 44 this->munition_ = 0; 45 53 this->setObjectMode(0x0); 46 54 } 47 55 … … 50 58 } 51 59 52 void Weapon::addMunition() 60 61 void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode) 53 62 { 63 SUPER(Weapon, XMLPort, xmlelement, mode); 64 XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode); 65 XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode); 66 XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode); 67 } 68 69 void Weapon::setWeapon() 70 { 71 this->munition_->fillBullets(); 72 this->munition_->fillMagazines(); 73 } 74 75 76 void Weapon::fire() 77 { 78 //COUT(0) << "LaserGun::fire, this=" << this << std::endl; 79 if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_) 80 { 81 //COUT(0) << "LaserGun::fire - ready to shoot" << std::endl; 82 //COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl; 83 this->bulletReadyToShoot_ = false; 84 if ( this->munition_->bullets() > 0) 85 { 86 //shoot 87 this->takeBullets(); 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(); 95 } 96 else 97 { 98 //COUT(0) << "LaserGun::fire - no magazines" << std::endl; 99 //actions 100 } 101 } 102 else 103 { 104 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl; 105 //actions 106 } 54 107 55 108 } 56 109 57 void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode) 110 111 void Weapon::bulletTimer(float bulletLoadingTime) 58 112 { 59 113 //COUT(0) << "Weapon::bulletTimer started" << std::endl; 114 this->bReloading_ = true; 115 this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); 116 } 117 void Weapon::magazineTimer(float magazineLoadingTime) 118 { 119 //COUT(0) << "Weapon::magazineTimer started" << std::endl; 120 this->bReloading_ = true; 121 this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); 60 122 } 61 123 62 void Weapon:: fire()124 void Weapon::bulletReloaded() 63 125 { 126 this->bReloading_ = false; 127 this->bulletReadyToShoot_ = true; 128 } 64 129 130 void Weapon::magazineReloaded() 131 { 132 this->bReloading_ = false; 133 this->munition_->fillBullets(); 134 this->magazineReadyToShoot_ = true; 135 this->bulletReadyToShoot_ = true; 65 136 } 137 138 139 void Weapon::attachNeededMunition(std::string munitionName) 140 { 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 143 if (this->parentWeaponSystem_) 144 { 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; 153 this->munitionIdentifier_ = ClassByString(munitionName); 154 this->munition_ = this->munitionIdentifier_.fabricate(this); 155 this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_); 156 } 157 } 158 } 159 160 161 /*get and set functions 162 * 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 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 } 191 192 void Weapon::takeBullets() { }; 193 void Weapon::createProjectile() { }; 194 void Weapon::takeMagazines() { }; 195 66 196 }
Note: See TracChangeset
for help on using the changeset viewer.