Changeset 2662 for code/trunk/src/orxonox/objects/weaponSystem
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 23 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/weaponSystem/CMakeLists.txt
r2131 r2662 2 2 Munition.cc 3 3 Weapon.cc 4 WeaponPack.cc 4 5 WeaponSet.cc 5 6 WeaponSlot.cc … … 7 8 ) 8 9 9 #ADD_SOURCE_DIRECTORY(SRC_FILES munitions)10 #ADD_SOURCE_DIRECTORY(SRC_FILES projectiles)11 #ADD_SOURCE_DIRECTORY(SRC_FILES weapons)10 ADD_SOURCE_DIRECTORY(SRC_FILES munitions) 11 ADD_SOURCE_DIRECTORY(SRC_FILES projectiles) 12 ADD_SOURCE_DIRECTORY(SRC_FILES weapons) 12 13 13 14 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/weaponSystem/Munition.cc
r2097 r2662 37 37 namespace orxonox 38 38 { 39 CreateFactory(Munition); 40 39 41 Munition::Munition(BaseObject* creator) : BaseObject(creator) 40 42 { … … 46 48 } 47 49 50 unsigned int Munition::bullets() 51 { 52 if (this->bullets_ > 0) 53 return bullets_; 54 else 55 return 0; 56 } 57 58 unsigned int Munition::magazines() 59 { 60 if (this->magazines_ > 0) 61 return magazines_; 62 else 63 return 0; 64 } 65 66 void Munition::setMaxBullets(unsigned int amount) 67 { this->maxBullets_ = amount; } 68 69 void Munition::setMaxMagazines(unsigned int amount) 70 { this->maxMagazines_ = amount; } 71 72 void Munition::removeBullets(unsigned int amount) 73 { 74 if ( this->bullets_ != 0 ) 75 this->bullets_ = this->bullets_ - amount; 76 } 77 78 void Munition::removeMagazines(unsigned int amount) 79 { 80 if ( this->magazines_ != 0 ) 81 this->magazines_ = this->magazines_ - amount; 82 } 83 84 void Munition::addBullets(unsigned int amount) 85 { 86 if ( this->bullets_ == this->maxBullets_ ) 87 { 88 //cannot add bullets to actual magazine 89 } 90 else 91 this->bullets_ = this->bullets_ + amount; 92 } 93 94 void Munition::addMagazines(unsigned int amount) 95 { 96 if ( this->magazines_ == this->maxMagazines_ ) 97 { 98 //no more capacity for another magazine 99 } 100 else 101 this->magazines_ = this->magazines_ + amount; 102 } 103 104 105 void Munition::fillBullets() 106 { 107 //COUT(0) << "Munition::fillBullets maxBullets_=" << this->maxBullets_ << std::endl; 108 this->bullets_ = this->maxBullets_; 109 } 110 111 void Munition::fillMagazines() 112 { 113 this->magazines_ = this->maxMagazines_; 114 } 115 48 116 void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode) 49 117 { 50 118 SUPER(Munition, XMLPort, xmlelement, mode); 51 119 } 52 120 -
code/trunk/src/orxonox/objects/weaponSystem/Munition.h
r2106 r2662 34 34 #include "core/BaseObject.h" 35 35 36 #include "Weapon.h" 37 36 38 37 39 namespace orxonox … … 45 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 48 49 void setMaxBullets(unsigned int amount); 50 void setMaxMagazines(unsigned int amount); 51 52 void fillBullets(); 53 void fillMagazines(); 54 55 unsigned int bullets(); 56 unsigned int magazines(); 57 58 void removeBullets(unsigned int k); 59 void removeMagazines(unsigned int k); 60 void addBullets(unsigned int k); 61 void addMagazines(unsigned int k); 47 62 48 63 private: 49 64 50 65 protected: 66 unsigned int bullets_; 67 unsigned int magazines_; 68 unsigned int maxBullets_; 69 unsigned int maxMagazines_; 51 70 }; 52 71 } -
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 } -
code/trunk/src/orxonox/objects/weaponSystem/Weapon.h
r2106 r2662 33 33 34 34 #include "core/BaseObject.h" 35 #include "tools/BillboardSet.h" 36 #include "tools/Timer.h" 37 #include "core/Identifier.h" 35 38 39 #include "WeaponSystem.h" 40 #include "Munition.h" 41 42 #include "objects/worldentities/StaticEntity.h" 36 43 37 44 namespace orxonox 38 45 { 39 class _OrxonoxExport Weapon : public BaseObject46 class _OrxonoxExport Weapon : public StaticEntity 40 47 { 41 48 public: … … 45 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 53 47 void addMunition();48 54 virtual void fire(); 55 void attachNeededMunition(std::string munitionType); 56 Munition * getAttachedMunition(std::string munitiontype); 57 58 //reloading 59 void bulletTimer(float bulletLoadingTime); 60 void magazineTimer(float magazineLoadingTime); 61 void bulletReloaded(); 62 void magazineReloaded(); 63 64 virtual void setMunitionType(std::string munitionType); 65 virtual const std::string getMunitionType(); 66 virtual void setBulletLoadingTime(float loadingTime); 67 virtual const float getBulletLoadingTime(); 68 virtual void setMagazineLoadingTime(float loadingTime); 69 virtual const float getMagazineLoadingTime(); 70 71 virtual void takeBullets(); 72 virtual void takeMagazines(); 73 virtual void createProjectile(); 74 75 inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem) 76 { this->parentWeaponSystem_=parentWeaponSystem; }; 77 inline WeaponSystem * getParentWeaponSystem() 78 { return this->parentWeaponSystem_; }; 79 80 inline void setAttachedToWeaponSlot(WeaponSlot * wSlot) 81 { this->attachedToWeaponSlot_ = wSlot; } 82 inline WeaponSlot * getAttachedToWeaponSlot() 83 { return this->attachedToWeaponSlot_; } 84 85 virtual void setWeapon(); 49 86 50 87 private: 51 int loadingTime_;52 Munition *munition_;53 88 89 protected: 90 bool bReloading_; 91 bool bulletReadyToShoot_; 92 bool magazineReadyToShoot_; 93 float bulletLoadingTime_; 94 float magazineLoadingTime_; 95 std::string munitionType_; 54 96 97 WeaponSlot * attachedToWeaponSlot_; 98 Munition * munition_; 99 WeaponSystem * parentWeaponSystem_; 55 100 101 SubclassIdentifier<Munition> munitionIdentifier_; 102 103 Timer<Weapon> bulletReloadTimer_; 104 Timer<Weapon> magazineReloadTimer_; 56 105 }; 57 106 } -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSet.cc
r2098 r2662 33 33 #include "core/XMLPort.h" 34 34 #include "util/Debug.h" 35 #include "objects/worldentities/pawns/Pawn.h" 35 36 36 37 #include "WeaponSet.h" 38 #include "WeaponPack.h" 37 39 38 40 namespace orxonox 39 41 { 42 CreateFactory(WeaponSet); 43 40 44 WeaponSet::WeaponSet(BaseObject* creator, int k) : BaseObject(creator) 41 45 { … … 43 47 44 48 this->parentWeaponSystem_ = 0; 45 46 for (int i=0;i<k;i++) 47 { 48 attachWeaponSlot(new WeaponSlot(this)); 49 } 49 this->attachedWeaponPack_ = 0; 50 50 } 51 51 … … 54 54 } 55 55 56 //Vorwärtsdeklaration 57 WeaponSystem * parentWeaponSystem_; 56 void WeaponSet::attachWeaponPack(WeaponPack *wPack) 57 { 58 //COUT(0) << "WeaponSet::attachWeaponPack" << std::endl; 59 //COUT(0) << "........ parentWeaponSystem_=" << this->parentWeaponSystem_ << std::endl; 60 //COUT(0) << "........ this->parentWeaponSystem_->getWeaponSlotSize()" << this->parentWeaponSystem_->getWeaponSlotSize() << std::endl; 61 //COUT(0) << "........ wPack->getSize()" << wPack->getSize() << std::endl; 62 if ( this->parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) ) 63 { 64 //COUT(0) << "WeaponSet::attachWeaponPack after if" << std::endl; 65 this->attachedWeaponPack_ = wPack; 66 int wPackWeapon = 0; //WeaponCounter for Attaching 67 //should be possible to choose which slot to use 68 for ( int i=0; i < wPack->getSize() ; i++ ) 69 { 70 //at the moment this function only works for one weaponPack in the entire WeaponSystem... 71 if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() == 0 && this->parentWeaponSystem_->getWeaponSlotPointer(i) != 0) //if slot not full 72 { 73 //COUT(0) << "WeaponSet::attachWeaponPack attaching Weapon" << std::endl; 74 this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) ); 75 this->parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) ); 76 this->parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) ); 77 wPackWeapon++; 78 } 79 else 80 { 81 for (int k=0; k < this->parentWeaponSystem_->getWeaponSlotSize(); k++) 82 { 83 if ( this->parentWeaponSystem_->getWeaponSlotPointer(k)->getAttachedWeapon() == 0 ) 84 { 85 //COUT(0) << "WeaponSet::attachWeaponPack mode 2 k="<< k << std::endl; 86 this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(k) ); 87 this->parentWeaponSystem_->getWeaponSlotPointer(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) ); 88 this->parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) ); 89 wPackWeapon++; 90 } 91 } 92 } 93 } 94 } 95 } 58 96 59 void WeaponSet::attachWeaponSlot(WeaponSlot *wSlot)60 {61 this->weaponSlots_.push_back(wSlot);62 }63 97 64 98 void WeaponSet::fire() 65 99 { 66 for (int i=0; i < (int) this->weaponSlots_.size(); i++)67 { 68 this->weaponSlots_[i]->fire();69 }100 //fires all WeaponSlots available for this weaponSet attached from the WeaponPack 101 //COUT(0) << "WeaponSet::fire from Pack: " << this->attachedWeaponPack_ << std::endl; 102 if (this->attachedWeaponPack_) 103 this->attachedWeaponPack_->fire(); 70 104 } 71 105 72 WeaponSlot * WeaponSet::getWeaponSlotPointer(unsigned int n) 73 { 74 if (n < this->weaponSlots_.size()) 75 return this->weaponSlots_[n]; 76 else 77 return 0; 78 } 106 void WeaponSet::setFireMode(const unsigned int firemode) 107 { this->firemode_ = firemode; } 79 108 109 const unsigned int WeaponSet::getFireMode() const 110 { return this->firemode_; } 80 111 81 112 void WeaponSet::XMLPort(Element& xmlelement, XMLPort::Mode mode) 82 113 { 83 114 SUPER(WeaponSet, XMLPort, xmlelement, mode); 115 XMLPortParam(WeaponSet, "firemode", setFireMode, getFireMode, xmlelement, mode); 84 116 } 85 117 -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSet.h
r2106 r2662 48 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 49 50 void attachWeapon Slot(WeaponSlot *wSlot);50 void attachWeaponPack(WeaponPack *wPack); 51 51 void fire(); 52 WeaponSlot * getWeaponSlotPointer(unsigned int n); 52 53 void setFireMode(const unsigned int firemode); 54 const unsigned int getFireMode() const; 53 55 54 56 inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem) … … 58 60 59 61 private: 60 std::vector<WeaponSlot *> weaponSlots_;61 62 WeaponSystem *parentWeaponSystem_; 63 std::vector<WeaponSlot *> setWeaponSlots_; 64 unsigned int firemode_; 65 WeaponPack * attachedWeaponPack_; 62 66 }; 63 67 } -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSlot.cc
r2098 r2662 36 36 37 37 38 39 38 namespace orxonox 40 39 { 41 WeaponSlot::WeaponSlot(BaseObject* creator) : BaseObject(creator) 40 CreateFactory(WeaponSlot); 41 42 WeaponSlot::WeaponSlot(BaseObject* creator) : StaticEntity(creator) 42 43 { 43 44 RegisterObject(WeaponSlot); 44 45 45 46 this->unlimitedAmmo_ = false; 46 47 47 this->attachedWeapon_ = 0; 48 this-> parentWeaponSet_ = 0;48 this->setObjectMode(0x0); 49 49 } 50 50 … … 53 53 } 54 54 55 void WeaponSlot::attachWeapon(Weapon *weaponName)56 {57 58 }59 55 60 56 /*sets the munition type … … 67 63 } 68 64 65 69 66 void WeaponSlot::fire() 70 67 { 68 if ( this->attachedWeapon_ ) 69 //COUT(0) << "WeaponSlot::fire" << std::endl; 70 this->attachedWeapon_->fire(); 71 } 71 72 72 }73 73 74 74 void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode) 75 75 { 76 SUPER(WeaponSlot, XMLPort, xmlelement, mode); 77 } 76 78 79 void WeaponSlot::attachWeapon(Weapon *weapon) 80 { 81 this->attachedWeapon_ = weapon; 82 weapon->setAttachedToWeaponSlot(this); 83 //COUT(0) << "WeaponSlot::attachWeapon position=" << this->getWorldPosition() << std::endl; 84 weapon->setPosition(this->getPosition()); 85 } 86 87 Weapon * WeaponSlot::getAttachedWeapon() const 88 { 89 return this->attachedWeapon_; 77 90 } 78 91 } -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSlot.h
r2106 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "core/BaseObject.h"35 36 37 34 #include "Weapon.h" 38 35 #include "objects/worldentities/StaticEntity.h" 39 36 40 37 namespace orxonox 41 38 { 42 class _OrxonoxExport WeaponSlot : public BaseObject39 class _OrxonoxExport WeaponSlot : public StaticEntity 43 40 { 44 41 public: … … 48 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 46 50 void attachWeapon(Weapon *weaponName); 47 void attachWeapon(Weapon *weapon); 48 Weapon * getAttachedWeapon() const; 51 49 void setAmmoType(bool isUnlimited); 52 50 void fire(); 53 51 54 inline void setParentWeaponSet(WeaponSet *parentWeaponSet) 55 { parentWeaponSet_=parentWeaponSet; } 56 inline WeaponSet * getParentWeaponSet() 57 { return parentWeaponSet_; } 58 52 inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem) 53 { parentWeaponSystem_=parentWeaponSystem; } 54 inline WeaponSystem * getParentWeaponSystem() 55 { return parentWeaponSystem_; } 59 56 60 57 … … 63 60 bool unlimitedAmmo_; 64 61 65 WeaponS et *parentWeaponSet_;62 WeaponSystem *parentWeaponSystem_; 66 63 }; 67 64 } -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.cc
- Property svn:mergeinfo changed
r2261 r2662 37 37 #include "WeaponSystem.h" 38 38 39 39 40 /* WEAPONSYSTEM 40 41 * creates the WeaponSystem and the ability to use weapons and munition … … 45 46 namespace orxonox 46 47 { 48 CreateFactory(WeaponSystem); 49 47 50 WeaponSystem::WeaponSystem(BaseObject* creator) : BaseObject(creator) 48 51 { … … 50 53 51 54 this->activeWeaponSet_ = 0; 52 this->parent SpaceShip_ = 0;55 this->parentPawn_ = 0; 53 56 } 54 57 … … 57 60 } 58 61 59 //creates empty weaponSet 62 void WeaponSystem::attachWeaponPack(WeaponPack *wPack, unsigned int firemode) 63 { 64 if (firemode < this->weaponSets_.size()) 65 this->weaponSets_[firemode]->attachWeaponPack(wPack); 66 this->weaponPacks_.push_back(wPack); 67 } 68 69 void WeaponSystem::attachWeaponSlot(WeaponSlot *wSlot) 70 { 71 wSlot->setParentWeaponSystem(this); 72 this->weaponSlots_.push_back(wSlot); 73 } 74 60 75 void WeaponSystem::attachWeaponSet(WeaponSet *wSet) 61 76 { 77 wSet->setParentWeaponSystem(this); 62 78 this->weaponSets_.push_back(wSet); 63 wSet->setParentWeaponSystem(this);64 79 } 65 80 81 void WeaponSystem::setNewMunition(std::string munitionType, Munition * munitionToAdd) 82 { 83 this->munitionSet_[munitionType] = munitionToAdd; 84 } 85 86 //returns the Pointer to the munitionType 87 Munition * WeaponSystem::getMunitionType(std::string munitionType) 88 { 89 //COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl; 90 std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType); 91 if (it != this->munitionSet_.end()) 92 return it->second; 93 else 94 return 0; 95 } 96 97 98 /* 66 99 //the first weaponSet is at n=0 67 100 void WeaponSystem::setActiveWeaponSet(unsigned int n) … … 69 102 if (n < this->weaponSets_.size()) 70 103 this->activeWeaponSet_ = this->weaponSets_[n]; 104 else 105 this->activeWeaponSet_ = this->weaponSets_[0]; 106 } 107 */ 108 109 110 //n is the n'th weaponSet, starting with zero 111 //SpaceShip.cc only needs to have the keybinding to a specific Set-number n 112 void WeaponSystem::fire(WeaponMode::Enum n) 113 { 114 int set = 0; 115 switch (n) 116 { 117 case WeaponMode::fire: 118 set = 0; 119 break; 120 case WeaponMode::altFire: 121 set = 1; 122 break; 123 case WeaponMode::altFire2: 124 set = 2; 125 break; 126 } 127 //COUT(0) << "WeaponSystem::fire" << std::endl; 128 if (set < (int)this->weaponSets_.size()) 129 //COUT(0) << "WeaponSystem::fire - after if" << std::endl; 130 this->weaponSets_[set]->fire(); 71 131 } 72 132 73 //n is the n'th weaponSet, starting with zero74 //Spaceship.cc only needs to have the keybinding to a specific Set-number n75 void WeaponSystem::fire(unsigned int n)76 {77 if (n < this->weaponSets_.size())78 this->weaponSets_[n]->fire();79 }80 81 void WeaponSystem::fire()82 {83 if (this->activeWeaponSet_)84 this->activeWeaponSet_->fire();85 }86 133 87 134 WeaponSet * WeaponSystem::getWeaponSetPointer(unsigned int n) … … 93 140 } 94 141 142 WeaponSlot * WeaponSystem::getWeaponSlotPointer(unsigned int n) 143 { 144 if (n < this->weaponSlots_.size()) 145 return this->weaponSlots_[n]; 146 else 147 return 0; 148 } 149 150 WeaponPack * WeaponSystem::getWeaponPackPointer(unsigned int n) 151 { 152 if (n < this->weaponPacks_.size()) 153 return this->weaponPacks_[n]; 154 else 155 return 0; 156 } 157 95 158 void WeaponSystem::XMLPort(Element& xmlelement, XMLPort::Mode mode) 96 159 { 97 160 SUPER(WeaponSystem, XMLPort, xmlelement, mode); 98 161 } 99 162 -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.h
- Property svn:mergeinfo changed
r2261 r2662 36 36 37 37 #include "WeaponSet.h" 38 #include "WeaponPack.h" 38 39 39 40 namespace orxonox 40 41 { 42 41 43 class _OrxonoxExport WeaponSystem : public BaseObject 42 44 { … … 47 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 50 51 void attachWeaponSlot(WeaponSlot *wSlot); 49 52 void attachWeaponSet(WeaponSet *wSet); 50 void fire(); 51 void fire(unsigned int n); 52 void setActiveWeaponSet(unsigned int n); 53 //void fire(); 54 void fire(WeaponMode::Enum fireMode); 55 //void setActiveWeaponSet(unsigned int n); 56 void attachWeaponPack(WeaponPack * wPack, unsigned int firemode); 53 57 WeaponSet * getWeaponSetPointer(unsigned int n); 58 WeaponSlot * getWeaponSlotPointer(unsigned int n); 59 WeaponPack * getWeaponPackPointer(unsigned int n); 60 void setNewMunition(std::string munitionType, Munition * munitionToAdd); 61 Munition * getMunitionType(std::string munitionType); 54 62 55 inline void setParent SpaceShip(SpaceShip *parentSpaceShip)56 { parent SpaceShip_=parentSpaceShip; }57 inline SpaceShip * getParentSpaceShip()58 { return parent SpaceShip_; }63 inline void setParentPawn(Pawn *parentPawn) 64 { parentPawn_=parentPawn; } 65 inline Pawn * getParentPawn() 66 { return parentPawn_; } 59 67 68 inline int getWeaponSlotSize() 69 { return this->weaponSlots_.size(); } 60 70 61 71 private: 62 72 std::vector<WeaponSet *> weaponSets_; 73 std::vector<WeaponSlot *> weaponSlots_; 74 std::vector<WeaponPack *> weaponPacks_; 75 std::map<std::string, Munition *> munitionSet_; 63 76 WeaponSet *activeWeaponSet_; 64 65 SpaceShip *parentSpaceShip_; 77 Pawn *parentPawn_; 66 78 }; 67 79 } -
code/trunk/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.cc
r2097 r2662 37 37 namespace orxonox 38 38 { 39 LaserGunMunition::LaserGunMunition(BaseObject* creator) : BaseObject(creator) 39 CreateFactory(LaserGunMunition); 40 41 LaserGunMunition::LaserGunMunition(BaseObject* creator) : Munition(creator) 40 42 { 41 43 RegisterObject(LaserGunMunition); 44 45 this->maxBullets_ = 40; 46 this->maxMagazines_ = 100; 42 47 } 43 48 -
code/trunk/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.h
r2106 r2662 33 33 34 34 #include "core/BaseObject.h" 35 35 #include "../Munition.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport LaserGunMunition : public BaseObject39 class _OrxonoxExport LaserGunMunition : public Munition 40 40 { 41 41 public: … … 47 47 48 48 private: 49 int bullets_;50 int magazines_;51 int maxBullets_;52 int maxMagazines_;53 49 54 50 -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc
r2099 r2662 30 30 #include "BillboardProjectile.h" 31 31 32 #include <OgreBillboard .h>32 #include <OgreBillboardSet.h> 33 33 34 #include "core/Core.h" 34 35 #include "core/CoreIncludes.h" 36 #include "objects/Scene.h" 35 37 36 38 namespace orxonox … … 38 40 CreateFactory(BillboardProjectile); 39 41 40 BillboardProjectile::BillboardProjectile(BaseObject* creator , Weapon* owner) : Projectile(creator, owner)42 BillboardProjectile::BillboardProjectile(BaseObject* creator) : Projectile(creator) 41 43 { 42 44 RegisterObject(BillboardProjectile); 43 45 44 this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); 45 this->attachObject(this->billboard_.getBillboardSet()); 46 this->scale(0.5); 46 if (Core::showsGraphics()) 47 { 48 assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity 49 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(0.5, 0.5, 0.7, 0.8), 1); 50 this->attachOgreObject(this->billboard_.getBillboardSet()); 51 } 52 53 this->setScale(0.2); 47 54 } 48 55 49 56 BillboardProjectile::~BillboardProjectile() 50 57 { 51 if (this->isInitialized() && this->owner_)52 this->detachO bject(this->billboard_.getBillboardSet());58 if (this->isInitialized() && Core::showsGraphics() && this->billboard_.getBillboardSet()) 59 this->detachOgreObject(this->billboard_.getBillboardSet()); 53 60 } 54 61 55 62 void BillboardProjectile::setColour(const ColourValue& colour) 56 63 { 57 this->billboard_. getBillboardSet()->getBillboard(0)->setColour(colour);64 this->billboard_.setColour(colour); 58 65 } 59 66 … … 61 68 { 62 69 SUPER(BillboardProjectile, changedVisibility); 70 63 71 this->billboard_.setVisible(this->isVisible()); 64 72 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.h
r2099 r2662 41 41 { 42 42 public: 43 BillboardProjectile(BaseObject* creator , Weapon* owner = 0);43 BillboardProjectile(BaseObject* creator); 44 44 virtual ~BillboardProjectile(); 45 45 -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc
r2099 r2662 30 30 #include "ParticleProjectile.h" 31 31 32 #include "SpaceShip.h" 32 #include <OgreParticleSystem.h> 33 #include <OgreParticleEmitter.h> 34 35 #include "core/Core.h" 33 36 #include "core/CoreIncludes.h" 34 37 #include "core/ConfigValueIncludes.h" 38 #include "objects/Scene.h" 35 39 36 40 namespace orxonox … … 38 42 CreateFactory(ParticleProjectile); 39 43 40 ParticleProjectile::ParticleProjectile(BaseObject* creator , Weapon* owner) : BillboardProjectile(creator, owner)44 ParticleProjectile::ParticleProjectile(BaseObject* creator) : BillboardProjectile(creator) 41 45 { 42 46 RegisterObject(ParticleProjectile); 43 47 44 this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal); 45 this->particles_->addToSceneNode(this->getNode()); 46 this->particles_->setKeepParticlesInLocalSpace(true); 47 if (this->owner_) 48 if (Core::showsGraphics()) 48 49 { 50 this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::normal); 51 this->attachOgreObject(this->particles_->getParticleSystem()); 52 this->particles_->setKeepParticlesInLocalSpace(0); 53 54 this->particles_->getAllEmitters()->setDirection(-WorldEntity::FRONT); 49 55 } 50 // else 51 // { 52 // this->particles_ = 0; 53 // } 54 55 this->setConfigValues(); 56 else 57 this->particles_ = 0; 56 58 } 57 59 … … 59 61 { 60 62 if (this->isInitialized() && this->particles_) 63 { 64 this->detachOgreObject(this->particles_->getParticleSystem()); 61 65 delete this->particles_; 62 } 63 64 void ParticleProjectile::setConfigValues() 65 { 66 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback((Projectile*)this, &ParticleProjectile::speedChanged); 66 } 67 67 } 68 68 … … 70 70 { 71 71 SUPER(ParticleProjectile, changedVisibility); 72 this->particles_->setEnabled(this->isVisible());73 }74 72 75 bool ParticleProjectile::create(){ 76 if(!Projectile::create()) 77 return false; 78 this->particles_->getAllEmitters()->setDirection(-this->getOrientation()*Vector3(1,0,0)); 79 return true; 73 if (this->particles_) 74 this->particles_->setEnabled(this->isVisible()); 80 75 } 81 76 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.h
r2099 r2662 41 41 { 42 42 public: 43 ParticleProjectile(BaseObject* creator , Weapon* owner = 0);43 ParticleProjectile(BaseObject* creator); 44 44 virtual ~ParticleProjectile(); 45 45 virtual void changedVisibility(); 46 void setConfigValues();47 48 virtual bool create();49 46 50 47 private: -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc
r2100 r2662 40 40 #include "objects/worldentities/Model.h" 41 41 #include "objects/worldentities/ParticleSpawner.h" 42 #include "Settings.h" 42 #include "objects/collisionshapes/SphereCollisionShape.h" 43 #include "core/Core.h" 43 44 44 45 namespace orxonox 45 46 { 46 float Projectile::speed_s = 5000; 47 48 Projectile::Projectile(BaseObject* creator, Weapon* owner) : MovableEntity(creator), owner_(owner) 47 Projectile::Projectile(BaseObject* creator) : MovableEntity(creator) 49 48 { 50 49 RegisterObject(Projectile); 51 50 52 51 this->setConfigValues(); 53 this-> explosionTemplateName_ = "Orxonox/explosion3";54 this-> smokeTemplateName_ = "Orxonox/smoke4";52 this->bDestroy_ = false; 53 this->owner_ = 0; 55 54 56 this->setStatic(false); 57 this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL); 55 // Get notification about collisions 58 56 59 if ( this->owner_)57 if (Core::isMaster()) 60 58 { 61 this->setOrientation(this->owner_->getOrientation()); 62 this->setPosition(this->owner_->getPosition()); 63 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 59 this->enableCollisionCallback(); 60 61 this->setCollisionType(Kinematic); 62 63 SphereCollisionShape* shape = new SphereCollisionShape(this); 64 shape->setRadius(10); 65 this->attachCollisionShape(shape); 66 67 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 64 68 } 65 66 if(!orxonox::Settings::isClient()) //only if not on client67 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));68 69 } 69 70 … … 76 77 SetConfigValue(damage_, 15.0).description("The damage caused by the projectile"); 77 78 SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive"); 78 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(this, &Projectile::speedChanged);79 79 } 80 80 81 void Projectile::speedChanged()82 {83 Projectile::speed_s = this->speed_;84 if (this->owner_)85 this->setVelocity(this->owner_->getInitialDir() * this->speed_);86 }87 81 88 82 void Projectile::tick(float dt) … … 93 87 return; 94 88 95 float radius; 96 for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it) 97 { 98 // if ((*it) != this->owner_) 99 { 100 radius = it->getScale3D().x * 3.0; 101 102 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius)) 103 { 104 // hit 105 ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0); 106 explosion->setPosition(this->getPosition()); 107 explosion->create(); 108 ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0); 109 smoke->setPosition(this->getPosition()); 110 // smoke->getParticleInterface()->setSpeedFactor(3.0); 111 smoke->create(); 112 delete this; 113 return; 114 } 115 } 116 } 89 if (this->bDestroy_) 90 delete this; 117 91 } 118 92 119 93 void Projectile::destroyObject() 120 94 { 121 delete this; 95 if (Core::isMaster()) 96 delete this; 122 97 } 123 98 124 bool Projectile::create(){ 125 return WorldEntity::create(); 99 bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 100 { 101 if (!this->bDestroy_ && Core::isMaster()) 102 { 103 this->bDestroy_ = true; 104 105 if (this->owner_) 106 { 107 { 108 ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); 109 effect->setPosition(this->getPosition()); 110 effect->setOrientation(this->getOrientation()); 111 effect->setDestroyAfterLife(true); 112 effect->setSource("Orxonox/explosion3"); 113 effect->setLifetime(2.0f); 114 } 115 { 116 ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); 117 effect->setPosition(this->getPosition()); 118 effect->setOrientation(this->getOrientation()); 119 effect->setDestroyAfterLife(true); 120 effect->setSource("Orxonox/smoke4"); 121 effect->setLifetime(3.0f); 122 } 123 } 124 125 Pawn* victim = dynamic_cast<Pawn*>(otherObject); 126 if (victim) 127 victim->damage(this->damage_, this->owner_); 128 } 129 return false; 130 } 131 132 void Projectile::destroyedPawn(Pawn* pawn) 133 { 134 if (this->owner_ == pawn) 135 this->owner_ = 0; 126 136 } 127 137 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.h
r2099 r2662 33 33 34 34 #include "objects/worldentities/MovableEntity.h" 35 #include "objects/worldentities/pawns/Pawn.h" 35 36 #include "tools/Timer.h" 36 37 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport Projectile : public MovableEntity 40 class _OrxonoxExport Projectile : public MovableEntity, public PawnListener 40 41 { 41 42 public: 43 Projectile(BaseObject* creator); 42 44 virtual ~Projectile(); 45 43 46 void setConfigValues(); 44 void speedChanged();45 47 void destroyObject(); 48 46 49 virtual void tick(float dt); 50 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 51 virtual void destroyedPawn(Pawn* pawn); 47 52 48 virtual bool create(); 49 50 static float getSpeed() 51 { return Projectile::speed_s; } 52 53 protected: 54 Projectile(BaseObject* creator, Weapon* owner = 0); 55 SpaceShip* owner_; 53 inline void setOwner(Pawn* owner) 54 { this->owner_ = owner; } 55 inline Pawn* getOwner() const 56 { return this->owner_; } 56 57 57 58 private: 58 std::string explosionTemplateName_; 59 std::string smokeTemplateName_; 60 protected: 61 static float speed_s; 62 float speed_; 63 private: 59 Pawn* owner_; 64 60 float lifetime_; 65 61 float damage_; 62 bool bDestroy_; 66 63 Timer<Projectile> destroyTimer_; 67 64 }; -
code/trunk/src/orxonox/objects/weaponSystem/weapons/CMakeLists.txt
r2131 r2662 1 1 SET( SRC_FILES 2 Fusion.cc 2 3 LaserGun.cc 3 Missile.cc4 # Missile.cc 4 5 ) 5 6 -
code/trunk/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc
r2097 r2662 34 34 #include "util/Debug.h" 35 35 36 #include "LaserGun.h" 37 36 38 37 39 namespace orxonox 38 40 { 41 CreateFactory(LaserGun); 42 39 43 LaserGun::LaserGun(BaseObject* creator) : Weapon(creator) 40 44 { 41 45 RegisterObject(LaserGun); 42 46 43 projectileColor_ = ColourValue(1.0, 1.0, 0.5) 47 this->speed_ = 1250; 48 44 49 } 45 50 … … 48 53 } 49 54 50 LaserGun::fire()55 void LaserGun::takeBullets() 51 56 { 52 BillboardProjectile* projectile = new ParticleProjectile(this); 53 projectile->setColour(this->projectileColor_); 54 projectile->create(); 55 if (projectile->getClassID() == 0) 56 { 57 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output 58 } 59 60 projectile->setObjectMode(0x3); 57 //COUT(0) << "LaserGun::takeBullets" << std::endl; 58 this->munition_->removeBullets(1); 59 this->bulletTimer(this->bulletLoadingTime_); 61 60 } 62 61 63 LaserGun::addMunition()62 void LaserGun::takeMagazines() 64 63 { 65 //this->munition_ = ; 64 this->munition_->removeMagazines(1); 65 this->magazineTimer(this->magazineLoadingTime_); 66 66 } 67 67 68 void LaserGun:: XMLPort(Element& xmlelement, XMLPort::Mode mode)68 void LaserGun::createProjectile() 69 69 { 70 71 }72 73 ColorValue LaserGun::getProjectileColor()74 {75 return projectileColor_;70 //COUT(0) << "LaserGun::createProjectile" << std::endl; 71 BillboardProjectile* projectile = new ParticleProjectile(this); 72 projectile->setOrientation(this->getWorldOrientation()); 73 projectile->setPosition(this->getWorldPosition()); 74 projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_); 75 projectile->setOwner(this->getParentWeaponSystem()->getParentPawn()); 76 76 } 77 77 } -
code/trunk/src/orxonox/objects/weaponSystem/weapons/LaserGun.h
r2106 r2662 34 34 #include "core/BaseObject.h" 35 35 36 #include "LaserGunMunition.h" 37 #include "tools/BillboardSet.h" 36 #include "../munitions/LaserGunMunition.h" 38 37 #include "util/Math.h" 38 #include "../Weapon.h" 39 #include "../projectiles/BillboardProjectile.h" 40 #include "../projectiles/ParticleProjectile.h" 39 41 40 42 namespace orxonox … … 46 48 virtual ~LaserGun(); 47 49 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);49 50 ColourValue LaserGun::getProjectileColour();50 virtual void takeBullets(); 51 virtual void takeMagazines(); 52 virtual void createProjectile(); 51 53 52 54 private: 53 ColorValue projectileColor_; 54 55 55 float speed_; 56 56 57 57 };
Note: See TracChangeset
for help on using the changeset viewer.