Changeset 2379 for code/branches/weapon2
- Timestamp:
- Dec 10, 2008, 2:38:33 PM (16 years ago)
- Location:
- code/branches/weapon2/src/orxonox/objects
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.cc
r2232 r2379 46 46 } 47 47 48 unsigned int Munition::getBullets() 49 { return this->bullets_; } 48 bool Munition::bullets() 49 { 50 if (this->bullets_ > 0) 51 return true; 52 else 53 return false; 54 } 50 55 51 unsigned int Munition::getMagazines() 52 { return this->magazines_; } 56 bool Munition::magazines() 57 { 58 if (this->magazines_ > 0) 59 return true; 60 else 61 return false; 62 } 53 63 54 64 void Munition::setMaxBullets(unsigned int amount) … … 60 70 void Munition::removeBullets(unsigned int amount, Weapon * parentWeapon) 61 71 { 62 //if actual magazine is empty, decrement it and set the bullets amount to full (masBullets_)63 72 if ( this->bullets_ == 0 ) 64 73 { 65 74 this->removeMagazines(1); 66 parentWeapon->magazineTimer( );75 parentWeapon->magazineTimer(0); 67 76 this->bullets_ = this->maxBullets_; 68 77 } … … 85 94 } 86 95 else 87 this->magazines_ = this->magazines_ - amount; } 96 this->magazines_ = this->magazines_ - amount; 97 } 88 98 89 99 void Munition::addBullets(unsigned int amount) … … 108 118 109 119 120 void Munition::fillBullets() 121 { 122 this->bullets_ = this->maxBullets_; 123 } 124 125 void Munition::fillMagazines() 126 { 127 this->magazines_ = this->maxMagazines_; 128 } 129 110 130 void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode) 111 131 { -
code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.h
r2337 r2379 50 50 void setMaxMagazines(unsigned int amount); 51 51 52 unsigned int getBullets(); 53 unsigned int getMagazines(); 52 void fillBullets(); 53 void fillMagazines(); 54 55 bool bullets(); 56 bool magazines(); 54 57 55 58 void removeBullets(unsigned int k, Weapon * parentWeapon); -
code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.cc
r2366 r2379 60 60 } 61 61 62 void Weapon::setWeapon() 63 { 64 this->bulletLoadingTime_ = 0.5; 65 this->magazineLoadingTime_ = 3.0; 66 this->munition_->setMaxMagazines(100); 67 this->munition_->setMaxBullets(30); 68 this->munition_->fillBullets(); 69 this->munition_->fillMagazines(); 70 } 71 72 62 73 void Weapon::fire() 63 74 { 75 COUT(0) << "LaserGun::fire, this=" << this << std::endl; 76 if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ ) 77 { 78 COUT(0) << "LaserGun::fire - ready to shoot" << std::endl; 79 80 this->bulletReadyToShoot_ = false; 81 if ( this->munition_->bullets() ) 82 { 83 //shoot 84 this->takeBullets(); 85 this->createProjectile(); 86 } 87 //if there are no bullets, but magazines 88 else if ( this->munition_->magazines() && !this->munition_->bullets() ) 89 { 90 this->takeMagazines(); 91 } 92 } 93 else 94 { 95 COUT(0) << "LaserGun::fire - weapon not reloaded" << std::endl; 96 } 64 97 65 98 } 66 99 67 100 68 void Weapon::bulletTimer( )101 void Weapon::bulletTimer(float bulletLoadingTime) 69 102 { 70 this->bulletReloadTimer_.setTimer( this->bulletLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); 103 COUT(0) << "Weapon::bulletTimer started" << std::endl; 104 this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); 71 105 } 72 void Weapon::magazineTimer( )106 void Weapon::magazineTimer(float magazineLoadingTime) 73 107 { 74 this->magazineReloadTimer_.setTimer( this->magazineLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); 108 COUT(0) << "Weapon::magazineTimer started" << std::endl; 109 this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); 75 110 } 76 111 … … 79 114 80 115 void Weapon::magazineReloaded() 81 { this->magazineReadyToShoot_ = true; } 116 { 117 this->munition_->fillBullets(); 118 this->magazineReadyToShoot_ = true; 119 } 82 120 83 121 … … 104 142 105 143 106 /*get and set functions144 /*get and set functions 107 145 * 108 146 */ … … 123 161 return this->munition_; } 124 162 163 164 125 165 void Weapon::setBulletLoadingTime(float loadingTime) 126 166 { this->bulletLoadingTime_ = loadingTime; } … … 135 175 { return this->magazineLoadingTime_; } 136 176 137 void Weapon::setBulletReadyToShoot(bool b)138 { this->bulletReadyToShoot_ = b; }139 140 bool Weapon::getBulletReadyToShoot()141 { return this->bulletReadyToShoot_; }142 143 void Weapon::setMagazineReadyToShoot(bool b)144 { this->magazineReadyToShoot_ = b; }145 146 bool Weapon::getMagazineReadyToShoot()147 { return this->magazineReadyToShoot_; }148 177 149 178 Timer<Weapon> * Weapon::getBulletTimer() … … 152 181 Timer<Weapon> * Weapon::getMagazineTimer() 153 182 { return &this->magazineReloadTimer_; } 183 184 void Weapon::takeBullets() { }; 185 void Weapon::createProjectile() { }; 186 void Weapon::takeMagazines() { }; 187 154 188 } -
code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.h
r2366 r2379 55 55 56 56 //reloading 57 void bulletTimer( );58 void magazineTimer( );57 void bulletTimer(float bulletLoadingTime); 58 void magazineTimer(float magazineLoadingTime); 59 59 void bulletReloaded(); 60 60 void magazineReloaded(); … … 63 63 void setMagazineLoadingTime(float loadingTime); 64 64 float getMagazineLoadingTime(); 65 void setBulletReadyToShoot(bool b);66 bool getBulletReadyToShoot();67 void setMagazineReadyToShoot(bool b);68 bool getMagazineReadyToShoot();69 65 Timer<Weapon> *getBulletTimer(); 70 66 Timer<Weapon> *getMagazineTimer(); … … 72 68 virtual void setMunitionType(std::string munitionType); 73 69 virtual const std::string getMunitionType(); 70 71 virtual void takeBullets(); 72 virtual void takeMagazines(); 73 virtual void createProjectile(); 74 74 75 75 inline void setParentWeaponSlot(WeaponSlot *parentWeaponSlot) … … 81 81 inline WeaponSystem * getParentWeaponSystem() 82 82 { return this->parentWeaponSystem_; }; 83 84 //in future by XMLPort, 85 virtual void setWeapon(); 83 86 84 87 private: -
code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc
r2272 r2379 85 85 if (!this->isActive()) 86 86 return; 87 87 /* 88 88 float radius; 89 89 for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it) … … 114 114 } 115 115 } 116 */ 116 117 } 117 118 -
code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc
r2366 r2379 50 50 } 51 51 52 void LaserGun:: fire()52 void LaserGun::takeBullets() 53 53 { 54 COUT(0) << "LaserGun::fire, this=" << this << std::endl; 55 if ( this->getBulletReadyToShoot() && this->getMagazineReadyToShoot() ) 56 { 57 COUT(0) << "LaserGun::fire - ready to shoot" << std::endl; 58 //take munition 59 this->setBulletReadyToShoot(false); 60 Weapon::bulletTimer(); 61 this->getAttachedMunition(this->munitionType_)->removeBullets(1,this); 62 63 //create projectile 64 BillboardProjectile* projectile = new ParticleProjectile(this); 65 projectile->setOrientation(projectile->getOrientation()); 66 projectile->setPosition(projectile->getWorldPosition()); 67 projectile->setVelocity(WorldEntity::FRONT * this->speed_); 68 69 //projectile->setColour(this->getProjectileColour()); 70 } 71 else 72 { 73 //actions, when weapon is not reloaded if there are some 74 } 54 this->munition_->removeBullets(1,this); 55 this->bulletTimer(this->bulletLoadingTime_); 75 56 } 76 57 58 void LaserGun::takeMagazines() 59 { 60 this->munition_->removeMagazines(1); 61 this->magazineTimer(this->magazineLoadingTime_); 62 } 63 64 void LaserGun::createProjectile() 65 { 66 BillboardProjectile* projectile = new ParticleProjectile(this); 67 projectile->setOrientation(projectile->getOrientation()); 68 projectile->setPosition(projectile->getWorldPosition()); 69 projectile->setVelocity(WorldEntity::FRONT * this->speed_); 70 } 77 71 } -
code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h
r2366 r2379 47 47 LaserGun(BaseObject* creator); 48 48 virtual ~LaserGun(); 49 50 void fire(); 49 50 virtual void takeBullets(); 51 virtual void takeMagazines(); 52 virtual void createProjectile(); 51 53 52 54 private: -
code/branches/weapon2/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2366 r2379 53 53 this->lastHitOriginator_ = 0; 54 54 55 //WeaponSystem56 55 weaponSystem_ = new WeaponSystem(this); 57 /*58 WeaponSet * weaponSet1 = new WeaponSet(this,1);59 this->weaponSystem_->attachWeaponSet(weaponSet1);60 //totally bad solution...61 weaponSet1->setParentWeaponSystem(weaponSystem_);62 */63 56 64 57 this->registerVariables();
Note: See TracChangeset
for help on using the changeset viewer.