Changeset 2912 for code/branches/weapons
- Timestamp:
- Apr 9, 2009, 3:18:11 AM (16 years ago)
- Location:
- code/branches/weapons/src/orxonox
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weapons/src/orxonox/OrxonoxPrereqs.h
r2896 r2912 73 73 }; 74 74 } 75 76 //put here all existing munitionTypes77 namespace MunitionType78 {79 enum Enum80 { laserGunMunition };81 }82 83 //put here all weapon fire modes.84 //they have to be added to Pawn and HumanController, too.85 namespace WeaponMode86 {87 enum Enum88 {89 fire = 0x1,90 altFire = 0x2,91 altFire2 = 0x492 };93 }94 95 75 96 76 class GraphicsManager; -
code/branches/weapons/src/orxonox/objects/controllers/AIController.cc
r2896 r2912 111 111 112 112 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0)) 113 this->getControllableEntity()->fire( WeaponMode::fire);113 this->getControllableEntity()->fire(0); 114 114 115 115 SUPER(AIController, tick, dt); -
code/branches/weapons/src/orxonox/objects/controllers/HumanController.cc
r2872 r2912 46 46 SetConsoleCommand(HumanController, rotateRoll, true).setAsInputCommand(); 47 47 SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); 48 SetConsoleCommand(HumanController, altFire, true).keybindMode(KeybindMode::OnHold);49 48 SetConsoleCommand(HumanController, boost, true).keybindMode(KeybindMode::OnHold); 50 49 SetConsoleCommand(HumanController, greet, true); … … 109 108 } 110 109 111 void HumanController::fire( )110 void HumanController::fire(unsigned int firemode) 112 111 { 113 112 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 114 HumanController::localController_s->controllableEntity_->fire(WeaponMode::fire); 115 } 116 117 void HumanController::altFire() 118 { 119 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 120 HumanController::localController_s->controllableEntity_->fire(WeaponMode::altFire); 113 HumanController::localController_s->controllableEntity_->fire(firemode); 121 114 } 122 115 -
code/branches/weapons/src/orxonox/objects/controllers/HumanController.h
r2662 r2912 51 51 static void rotateRoll(const Vector2& value); 52 52 53 static void fire(); 54 static void altFire(); 53 static void fire(unsigned int firemode); 55 54 56 55 static void boost(); -
code/branches/weapons/src/orxonox/objects/weaponSystem/Munition.cc
r2893 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "Munition.h" 30 31 31 32 #include "core/CoreIncludes.h" 32 #include "core/XMLPort.h"33 #include "util/Debug.h"34 35 #include "Munition.h"36 33 37 34 namespace orxonox … … 42 39 { 43 40 RegisterObject(Munition); 41 42 COUT(0) << "+Munition" << std::endl; 44 43 } 45 44 46 45 Munition::~Munition() 47 46 { 47 COUT(0) << "~Munition" << std::endl; 48 48 } 49 49 … … 112 112 this->magazines_ = this->maxMagazines_; 113 113 } 114 115 void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode)116 {117 SUPER(Munition, XMLPort, xmlelement, mode);118 }119 120 114 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/Munition.h
r2662 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 33 #include "core/BaseObject.h" 35 36 #include "Weapon.h"37 38 34 39 35 namespace orxonox … … 44 40 Munition(BaseObject* creator); 45 41 virtual ~Munition(); 46 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);48 42 49 43 void setMaxBullets(unsigned int amount); -
code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc
r2893 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "Weapon.h" 30 31 31 32 #include "core/CoreIncludes.h" 32 33 #include "core/XMLPort.h" 33 #include "util/Debug.h" 34 35 #include "Weapon .h"34 35 #include "Munition.h" 36 #include "WeaponSystem.h" 36 37 37 38 namespace orxonox … … 45 46 this->bulletReadyToShoot_ = true; 46 47 this->magazineReadyToShoot_ = true; 47 this-> parentWeaponSystem_ = 0;48 this->weaponSystem_ = 0; 48 49 this->attachedToWeaponSlot_ = 0; 49 50 this->bulletLoadingTime_ = 0; … … 55 56 this->unlimitedMunition_ = false; 56 57 this->setObjectMode(0x0); 58 59 COUT(0) << "+Weapon" << std::endl; 57 60 } 58 61 59 62 Weapon::~Weapon() 60 63 { 61 } 62 64 COUT(0) << "~Weapon" << std::endl; 65 } 63 66 64 67 void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 152 155 153 156 154 void Weapon::attachNeededMunition( std::stringmunitionName)157 void Weapon::attachNeededMunition(const std::string& munitionName) 155 158 { 156 159 /* 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 160 */ 158 if (this-> parentWeaponSystem_)161 if (this->weaponSystem_) 159 162 { 160 163 //getMunitionType returns 0 if there is no such munitionType 161 Munition* munition = this-> parentWeaponSystem_->getMunitionType(munitionName);164 Munition* munition = this->weaponSystem_->getMunitionType(munitionName); 162 165 if ( munition ) 163 166 { … … 170 173 this->munitionIdentifier_ = ClassByString(munitionName); 171 174 this->munition_ = this->munitionIdentifier_.fabricate(this); 172 this-> parentWeaponSystem_->setNewMunition(munitionName, this->munition_);175 this->weaponSystem_->setNewMunition(munitionName, this->munition_); 173 176 this->setMunition(); 174 177 } … … 177 180 178 181 179 Munition * Weapon::getAttachedMunition( std::stringmunitionType)180 { 181 this->munition_ = this-> parentWeaponSystem_->getMunitionType(munitionType);182 Munition * Weapon::getAttachedMunition(const std::string& munitionType) 183 { 184 this->munition_ = this->weaponSystem_->getMunitionType(munitionType); 182 185 return this->munition_; 183 186 } … … 193 196 194 197 //get and set functions for XMLPort 195 void Weapon::setMunitionType( std::stringmunitionType)198 void Weapon::setMunitionType(const std::string& munitionType) 196 199 { this->munitionType_ = munitionType; } 197 200 198 const std::string Weapon::getMunitionType()201 const std::string& Weapon::getMunitionType() const 199 202 { return this->munitionType_; } 200 203 … … 202 205 { this->bulletLoadingTime_ = loadingTime; } 203 206 204 const float Weapon::getBulletLoadingTime() 207 const float Weapon::getBulletLoadingTime() const 205 208 { return this->bulletLoadingTime_; } 206 209 … … 208 211 { this->magazineLoadingTime_ = loadingTime; } 209 212 210 const float Weapon::getMagazineLoadingTime() 213 const float Weapon::getMagazineLoadingTime() const 211 214 { return this->magazineLoadingTime_; } 212 215 … … 214 217 { this->bulletAmount_ = amount; } 215 218 216 const unsigned int Weapon::getBulletAmount() 219 const unsigned int Weapon::getBulletAmount() const 217 220 { return this->bulletAmount_; } 218 221 … … 220 223 { this->magazineAmount_ = amount; } 221 224 222 const unsigned int Weapon::getMagazineAmount() 225 const unsigned int Weapon::getMagazineAmount() const 223 226 { return this->magazineAmount_; } 224 227 … … 226 229 { this->unlimitedMunition_ = unlimitedMunition; } 227 230 228 const bool Weapon::getUnlimitedMunition() 231 const bool Weapon::getUnlimitedMunition() const 229 232 { return this->unlimitedMunition_; } 230 233 -
code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.h
r2893 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "objects/worldentities/StaticEntity.h" 33 34 34 #include "core/BaseObject.h"35 #include "tools/BillboardSet.h"36 35 #include "tools/Timer.h" 37 36 #include "core/Identifier.h" 38 39 #include "WeaponSystem.h"40 #include "Munition.h"41 42 #include "objects/worldentities/StaticEntity.h"43 37 44 38 namespace orxonox … … 53 47 54 48 virtual void fire(); 55 void attachNeededMunition( std::stringmunitionType);56 Munition * getAttachedMunition( std::stringmunitiontype);49 void attachNeededMunition(const std::string& munitionType); 50 Munition * getAttachedMunition(const std::string& munitiontype); 57 51 58 52 //reloading … … 63 57 64 58 //XMLPort functions 65 virtual void setMunitionType( std::stringmunitionType);66 virtual const std::string getMunitionType();59 virtual void setMunitionType(const std::string& munitionType); 60 virtual const std::string& getMunitionType() const; 67 61 virtual void setBulletLoadingTime(float loadingTime); 68 virtual const float getBulletLoadingTime() ;62 virtual const float getBulletLoadingTime() const; 69 63 virtual void setMagazineLoadingTime(float loadingTime); 70 virtual const float getMagazineLoadingTime() ;64 virtual const float getMagazineLoadingTime() const; 71 65 virtual void setBulletAmount(unsigned int amount); 72 virtual const unsigned int getBulletAmount() ;66 virtual const unsigned int getBulletAmount() const; 73 67 virtual void setMagazineAmount(unsigned int amount); 74 virtual const unsigned int getMagazineAmount() ;68 virtual const unsigned int getMagazineAmount() const; 75 69 virtual void setUnlimitedMunition(bool unlimitedMunition); 76 virtual const bool getUnlimitedMunition() ;70 virtual const bool getUnlimitedMunition() const; 77 71 78 72 //weapon actions … … 86 80 virtual void setWeapon(); 87 81 virtual void setMunition(); 88 89 inline void set ParentWeaponSystem(WeaponSystem *parentWeaponSystem)90 { this-> parentWeaponSystem_=parentWeaponSystem; };91 inline WeaponSystem * get ParentWeaponSystem()92 { return this-> parentWeaponSystem_; };82 83 inline void setWeaponSystem(WeaponSystem *weaponSystem) 84 { this->weaponSystem_ = weaponSystem; }; 85 inline WeaponSystem * getWeaponSystem() const 86 { return this->weaponSystem_; }; 93 87 94 88 inline void setAttachedToWeaponSlot(WeaponSlot * wSlot) 95 89 { this->attachedToWeaponSlot_ = wSlot; } 96 inline WeaponSlot * getAttachedToWeaponSlot() 90 inline WeaponSlot * getAttachedToWeaponSlot() const 97 91 { return this->attachedToWeaponSlot_; } 98 99 100 private:101 92 102 93 protected: … … 113 104 WeaponSlot * attachedToWeaponSlot_; 114 105 Munition * munition_; 115 WeaponSystem * parentWeaponSystem_;106 WeaponSystem * weaponSystem_; 116 107 117 108 SubclassIdentifier<Munition> munitionIdentifier_; -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
r2893 r2912 27 27 28 28 #include "OrxonoxStableHeaders.h" 29 30 #include <vector> 29 #include "WeaponPack.h" 31 30 32 31 #include "core/CoreIncludes.h" 33 32 #include "core/XMLPort.h" 34 #include " util/Debug.h"33 #include "objects/worldentities/pawns/Pawn.h" 35 34 36 #include "Weapon Pack.h"37 #include " objects/worldentities/pawns/Pawn.h"35 #include "Weapon.h" 36 #include "WeaponSlot.h" 38 37 39 38 namespace orxonox … … 45 44 RegisterObject(WeaponPack); 46 45 47 this-> parentWeaponSystem_ = 0;46 this->weaponSystem_ = 0; 48 47 this->firemode_ = 0; 49 48 49 COUT(0) << "+WeaponPack" << std::endl; 50 50 } 51 51 52 52 WeaponPack::~WeaponPack() 53 53 { 54 COUT(0) << "~WeaponPack" << std::endl; 54 55 } 55 56 56 int WeaponPack::getSize() 57 void WeaponPack::XMLPort(Element& xmlelement, XMLPort::Mode mode) 58 { 59 SUPER(WeaponPack, XMLPort, xmlelement, mode); 60 61 XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode); 62 XMLPortParam(WeaponPack, "firemode", setFireMode, getFireMode, xmlelement, mode); 63 } 64 65 int WeaponPack::getSize() const 57 66 { 58 67 return this->weapons_.size(); … … 67 76 } 68 77 69 Weapon * WeaponPack::getWeaponPointer(unsigned int n) 78 Weapon * WeaponPack::getWeaponPointer(unsigned int n) const 70 79 { 71 80 return this->weapons_[n]; 72 }73 74 void WeaponPack::XMLPort(Element& xmlelement, XMLPort::Mode mode)75 {76 SUPER(WeaponPack, XMLPort, xmlelement, mode);77 78 XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);79 XMLPortParam(WeaponPack, "firemode", setFireMode, getFireMode, xmlelement, mode);80 81 } 81 82 … … 85 86 } 86 87 87 unsigned int WeaponPack::getFireMode() 88 unsigned int WeaponPack::getFireMode() const 88 89 { 89 90 return this->firemode_; … … 95 96 } 96 97 97 const Weapon * WeaponPack::getWeapon(unsigned int index) 98 const Weapon * WeaponPack::getWeapon(unsigned int index) const 98 99 { 99 100 return weapons_[index]; 100 101 } 101 102 102 void WeaponPack::set ParentWeaponSystemToAllWeapons(WeaponSystem * weaponSystem)103 void WeaponPack::setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem) 103 104 { 104 for (int i=0; i < (int) this->weapons_.size(); i++) 105 { 106 this->weapons_[i]->setParentWeaponSystem(weaponSystem); 107 } 108 105 for (size_t i = 0; i < this->weapons_.size(); i++) 106 this->weapons_[i]->setWeaponSystem(weaponSystem); 109 107 } 110 108 111 109 void WeaponPack::attachNeededMunitionToAllWeapons() 112 110 { 113 for ( int i=0; i < (int)this->weapons_.size(); i++)111 for (size_t i = 0; i < this->weapons_.size(); i++) 114 112 { 115 113 this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType()); 116 114 this->weapons_[i]->setWeapon(); 117 115 } 118 119 116 } 120 121 117 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h
r2893 r2912 33 33 #include "OrxonoxPrereqs.h" 34 34 35 #include <vector> 36 35 37 #include "core/BaseObject.h" 36 37 #include "Weapon.h"38 39 38 40 39 namespace orxonox … … 50 49 void fire(); 51 50 52 Weapon * getWeaponPointer(unsigned int n) ;53 int getSize() ;51 Weapon * getWeaponPointer(unsigned int n) const; 52 int getSize() const; 54 53 55 54 void setFireMode(unsigned int firemode); 56 unsigned int getFireMode() ;55 unsigned int getFireMode() const; 57 56 58 57 void addWeapon(Weapon * weapon); 59 const Weapon * getWeapon(unsigned int index); 58 const Weapon * getWeapon(unsigned int index) const; 59 60 void attachNeededMunitionToAllWeapons(); 60 61 61 62 //functions with effect to all weapons of the weaponPack 62 63 //functions needed for creating Pointer to the right objects (-->Pawn.cc) 63 void setParentWeaponSystemToAllWeapons(WeaponSystem * weaponSystem); 64 void attachNeededMunitionToAllWeapons(); 65 66 inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem) 67 { parentWeaponSystem_=parentWeaponSystem; } 68 inline WeaponSystem * getParentWeaponSystem() 69 { return parentWeaponSystem_; } 64 inline void setWeaponSystem(WeaponSystem *weaponSystem) 65 { this->weaponSystem_ = weaponSystem; this->setWeaponSystemToAllWeapons(weaponSystem); } 66 inline WeaponSystem * getWeaponSystem() const 67 { return this->weaponSystem_; } 70 68 71 69 private: 70 void setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem); 71 72 72 std::vector<Weapon *> weapons_; 73 WeaponSystem * parentWeaponSystem_;73 WeaponSystem *weaponSystem_; 74 74 unsigned int firemode_; 75 75 }; -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc
r2893 r2912 27 27 28 28 #include "OrxonoxStableHeaders.h" 29 30 #include <vector> 29 #include "WeaponSet.h" 31 30 32 31 #include "core/CoreIncludes.h" 33 32 #include "core/XMLPort.h" 34 #include "util/Debug.h"35 33 #include "objects/worldentities/pawns/Pawn.h" 36 34 37 #include "WeaponSet.h" 35 #include "Weapon.h" 36 #include "WeaponSlot.h" 38 37 #include "WeaponPack.h" 38 #include "WeaponSystem.h" 39 39 40 40 namespace orxonox … … 46 46 RegisterObject(WeaponSet); 47 47 48 this-> parentWeaponSystem_ = 0;48 this->weaponSystem_ = 0; 49 49 this->attachedWeaponPack_ = 0; 50 51 COUT(0) << "+WeaponSet" << std::endl; 50 52 } 51 53 52 54 WeaponSet::~WeaponSet() 53 55 { 56 COUT(0) << "~WeaponSet" << std::endl; 57 } 58 59 void WeaponSet::XMLPort(Element& xmlelement, XMLPort::Mode mode) 60 { 61 SUPER(WeaponSet, XMLPort, xmlelement, mode); 62 63 XMLPortParam(WeaponSet, "firemode", setFireMode, getFireMode, xmlelement, mode); 54 64 } 55 65 56 66 void WeaponSet::attachWeaponPack(WeaponPack *wPack) 57 67 { 58 if ( this-> parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) )68 if ( this->weaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->weaponSystem_->getWeaponSlotSize() ) ) 59 69 { 60 70 this->attachedWeaponPack_ = wPack; 61 71 int wPackWeapon = 0; //WeaponCounter for Attaching 62 72 63 73 //should be possible to choose which slot to use 64 74 //attach every weapon of the weaponPack to a weaponSlot … … 67 77 //at the moment this function only works for one weaponPack in the entire WeaponSystem... 68 78 //it also takes the first free weaponSlot... 69 if ( this-> parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() == 0 && this->parentWeaponSystem_->getWeaponSlotPointer(i) != 0) //if slot not full79 if ( this->weaponSystem_->getWeaponSlot(i)->getAttachedWeapon() == 0 && this->weaponSystem_->getWeaponSlot(i) != 0) //if slot not full 70 80 { 71 this->setWeaponSlots_.push_back( this-> parentWeaponSystem_->getWeaponSlotPointer(i) );72 this-> parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );73 this-> parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );81 this->setWeaponSlots_.push_back( this->weaponSystem_->getWeaponSlot(i) ); 82 this->weaponSystem_->getWeaponSlot(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) ); 83 this->weaponSystem_->getPawn()->attach( wPack->getWeaponPointer(wPackWeapon) ); 74 84 wPackWeapon++; 75 85 } 76 86 else 77 87 { 78 for (int k=0; k < this-> parentWeaponSystem_->getWeaponSlotSize(); k++)88 for (int k=0; k < this->weaponSystem_->getWeaponSlotSize(); k++) 79 89 { 80 if ( this-> parentWeaponSystem_->getWeaponSlotPointer(k)->getAttachedWeapon() == 0 )90 if ( this->weaponSystem_->getWeaponSlot(k)->getAttachedWeapon() == 0 ) 81 91 { 82 this->setWeaponSlots_.push_back( this-> parentWeaponSystem_->getWeaponSlotPointer(k) );83 this-> parentWeaponSystem_->getWeaponSlotPointer(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );84 this-> parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );92 this->setWeaponSlots_.push_back( this->weaponSystem_->getWeaponSlot(k) ); 93 this->weaponSystem_->getWeaponSlot(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) ); 94 this->weaponSystem_->getPawn()->attach( wPack->getWeaponPointer(wPackWeapon) ); 85 95 wPackWeapon++; 86 96 } … … 98 108 this->attachedWeaponPack_->fire(); 99 109 } 100 101 void WeaponSet::setFireMode(const unsigned int firemode)102 { this->firemode_ = firemode; }103 104 const unsigned int WeaponSet::getFireMode() const105 { return this->firemode_; }106 107 void WeaponSet::XMLPort(Element& xmlelement, XMLPort::Mode mode)108 {109 SUPER(WeaponSet, XMLPort, xmlelement, mode);110 XMLPortParam(WeaponSet, "firemode", setFireMode, getFireMode, xmlelement, mode);111 }112 113 110 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.h
r2662 r2912 33 33 #include "OrxonoxPrereqs.h" 34 34 35 #include <vector> 36 35 37 #include "core/BaseObject.h" 36 37 #include "WeaponSlot.h"38 39 38 40 39 namespace orxonox … … 51 50 void fire(); 52 51 53 void setFireMode(const unsigned int firemode); 54 const unsigned int getFireMode() const; 52 inline void setFireMode(const unsigned int firemode) 53 { this->firemode_ = firemode; } 54 inline unsigned int getFireMode() const 55 { return this->firemode_; } 55 56 56 inline void set ParentWeaponSystem(WeaponSystem *parentWeaponSystem)57 { parentWeaponSystem_=parentWeaponSystem; }58 inline WeaponSystem * get ParentWeaponSystem()59 { return parentWeaponSystem_; }57 inline void setWeaponSystem(WeaponSystem *weaponSystem) 58 { this->weaponSystem_ = weaponSystem; } 59 inline WeaponSystem * getWeaponSystem() const 60 { return this->weaponSystem_; } 60 61 61 62 private: 62 WeaponSystem * parentWeaponSystem_;63 WeaponSystem *weaponSystem_; 63 64 std::vector<WeaponSlot *> setWeaponSlots_; 64 65 unsigned int firemode_; -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSlot.cc
r2662 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "WeaponSlot.h" 30 31 31 32 #include "core/CoreIncludes.h" 32 33 #include "core/XMLPort.h" 33 #include "util/Debug.h"34 34 35 #include "WeaponSlot.h" 36 35 #include "Weapon.h" 37 36 38 37 namespace orxonox … … 47 46 this->attachedWeapon_ = 0; 48 47 this->setObjectMode(0x0); 48 49 COUT(0) << "+WeaponSlot" << std::endl; 49 50 } 50 51 51 52 WeaponSlot::~WeaponSlot() 52 53 { 54 COUT(0) << "~WeaponSlot" << std::endl; 53 55 } 54 56 57 void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode) 58 { 59 SUPER(WeaponSlot, XMLPort, xmlelement, mode); 60 } 55 61 56 62 /*sets the munition type … … 71 77 } 72 78 73 74 void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode)75 {76 SUPER(WeaponSlot, XMLPort, xmlelement, mode);77 }78 79 79 void WeaponSlot::attachWeapon(Weapon *weapon) 80 80 { -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSlot.h
r2662 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "Weapon.h"35 33 #include "objects/worldentities/StaticEntity.h" 36 34 … … 50 48 void fire(); 51 49 52 inline void set ParentWeaponSystem(WeaponSystem *parentWeaponSystem)53 { parentWeaponSystem_=parentWeaponSystem; }54 inline WeaponSystem * get ParentWeaponSystem()55 { return parentWeaponSystem_; }50 inline void setWeaponSystem(WeaponSystem *weaponSystem) 51 { this->weaponSystem_ = weaponSystem; } 52 inline WeaponSystem * getWeaponSystem() const 53 { return this->weaponSystem_; } 56 54 57 55 … … 60 58 bool unlimitedAmmo_; 61 59 62 WeaponSystem * parentWeaponSystem_;60 WeaponSystem *weaponSystem_; 63 61 }; 64 62 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc
r2896 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 31 #include <vector> 30 #include "WeaponSystem.h" 32 31 33 32 #include "core/CoreIncludes.h" 34 #include "core/XMLPort.h" 35 #include "util/Debug.h" 33 #include "objects/worldentities/pawns/Pawn.h" 36 34 37 #include "WeaponSystem.h" 38 35 #include "WeaponSlot.h" 36 #include "WeaponPack.h" 37 #include "WeaponSet.h" 39 38 40 39 /* WeaponSystem … … 51 50 RegisterObject(WeaponSystem); 52 51 53 this->parentPawn_ = 0; 52 this->pawn_ = 0; 53 COUT(0) << "+WeaponSystem" << std::endl; 54 54 } 55 55 56 56 WeaponSystem::~WeaponSystem() 57 57 { 58 COUT(0) << "~WeaponSystem" << std::endl; 59 if (this->isInitialized()) 60 { 61 if (this->pawn_) 62 this->pawn_->setWeaponSystem(0); 63 } 58 64 } 59 65 60 void WeaponSystem::attachWeapon Pack(WeaponPack *wPack, unsigned int firemode)66 void WeaponSystem::attachWeaponSet(WeaponSet *wSet) 61 67 { 62 if (firemode < this->weaponSets_.size()) 63 this->weaponSets_[firemode]->attachWeaponPack(wPack); 64 this->weaponPacks_.push_back(wPack); 68 if (!wSet) 69 return; 70 71 this->weaponSets_[wSet->getFireMode()] = wSet; 72 wSet->setWeaponSystem(this); 73 } 74 75 WeaponSet * WeaponSystem::getWeaponSet(unsigned int index) const 76 { 77 unsigned int i = 0; 78 for (std::map<unsigned int, WeaponSet*>::const_iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it) 79 { 80 ++i; 81 if (i > index) 82 return it->second; 83 } 84 return 0; 65 85 } 66 86 67 87 void WeaponSystem::attachWeaponSlot(WeaponSlot *wSlot) 68 88 { 69 wSlot->setParentWeaponSystem(this); 70 this->weaponSlots_.push_back(wSlot); 89 if (!wSlot) 90 return; 91 92 this->weaponSlots_.insert(wSlot); 93 wSlot->setWeaponSystem(this); 71 94 } 72 95 73 void WeaponSystem::attachWeaponSet(WeaponSet *wSet)96 WeaponSlot * WeaponSystem::getWeaponSlot(unsigned int index) const 74 97 { 75 wSet->setParentWeaponSystem(this); 76 this->weaponSets_.push_back(wSet); 98 unsigned int i = 0; 99 for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it) 100 { 101 ++i; 102 if (i > index) 103 return (*it); 104 } 105 return 0; 77 106 } 78 107 79 void WeaponSystem::setNewMunition(std::string munitionType, Munition * munitionToAdd) 108 void WeaponSystem::attachWeaponPack(WeaponPack *wPack, unsigned int wSetNumber) 109 { 110 if (!wPack) 111 return; 112 113 std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.find(wSetNumber); 114 if (it != this->weaponSets_.end() && it->second) 115 it->second->attachWeaponPack(wPack); 116 117 this->weaponPacks_.insert(wPack); 118 wPack->setWeaponSystem(this); 119 wPack->attachNeededMunitionToAllWeapons(); // TODO - what is this? 120 } 121 122 WeaponPack * WeaponSystem::getWeaponPack(unsigned int index) const 123 { 124 unsigned int i = 0; 125 for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it) 126 { 127 ++i; 128 if (i > index) 129 return (*it); 130 } 131 return 0; 132 } 133 134 void WeaponSystem::setNewMunition(const std::string& munitionType, Munition * munitionToAdd) 80 135 { 81 136 this->munitionSet_[munitionType] = munitionToAdd; … … 84 139 85 140 //returns the Pointer to the munitionType, if this munitionType doesn't exist returns 0, see Weapon::attachNeededMunition 86 Munition * WeaponSystem::getMunitionType( std::string munitionType)141 Munition * WeaponSystem::getMunitionType(const std::string& munitionType) const 87 142 { 88 143 std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType); … … 97 152 //SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode) 98 153 //in future this could be well defined and not only for 3 different WeaponModes 99 void WeaponSystem::fire( WeaponMode::Enum n)154 void WeaponSystem::fire(unsigned int firemode) 100 155 { 101 int set = 0; 102 switch (n) 103 { 104 case WeaponMode::fire: 105 set = 0; 106 break; 107 case WeaponMode::altFire: 108 set = 1; 109 break; 110 case WeaponMode::altFire2: 111 set = 2; 112 break; 113 } 114 if (set < (int)this->weaponSets_.size()) 115 this->weaponSets_[set]->fire(); 156 std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.find(firemode); 157 if (it != this->weaponSets_.end() && it->second) 158 it->second->fire(); 116 159 } 117 118 119 WeaponSet * WeaponSystem::getWeaponSetPointer(unsigned int n)120 {121 if (n < this->weaponSets_.size())122 return this->weaponSets_[n];123 else124 return 0;125 }126 127 WeaponSlot * WeaponSystem::getWeaponSlotPointer(unsigned int n)128 {129 if (n < this->weaponSlots_.size())130 return this->weaponSlots_[n];131 else132 return 0;133 }134 135 WeaponPack * WeaponSystem::getWeaponPackPointer(unsigned int n)136 {137 if (n < this->weaponPacks_.size())138 return this->weaponPacks_[n];139 else140 return 0;141 }142 143 void WeaponSystem::XMLPort(Element& xmlelement, XMLPort::Mode mode)144 {145 SUPER(WeaponSystem, XMLPort, xmlelement, mode);146 }147 148 160 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h
r2896 r2912 33 33 #include "OrxonoxPrereqs.h" 34 34 35 #include <set> 36 #include <map> 37 35 38 #include "core/BaseObject.h" 36 37 #include "WeaponSet.h"38 #include "WeaponPack.h"39 39 40 40 namespace orxonox 41 41 { 42 const unsigned int MAX_FIRE_MODES = 8; 42 43 43 44 class _OrxonoxExport WeaponSystem : public BaseObject … … 47 48 virtual ~WeaponSystem(); 48 49 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 void attachWeaponSlot(WeaponSlot * wSlot); 51 WeaponSlot * getWeaponSlot(unsigned int index) const; 50 52 51 void attachWeaponSlot(WeaponSlot *wSlot); 52 void attachWeaponSet(WeaponSet *wSet); 53 //void fire(); 54 void fire(WeaponMode::Enum fireMode); 55 void attachWeaponPack(WeaponPack * wPack, unsigned int firemode); 56 WeaponSet * getWeaponSetPointer(unsigned int n); 57 WeaponSlot * getWeaponSlotPointer(unsigned int n); 58 WeaponPack * getWeaponPackPointer(unsigned int n); 59 void setNewMunition(std::string munitionType, Munition * munitionToAdd); 60 void setNewSharedMunition(std::string munitionType, Munition * munitionToAdd); 61 Munition * getMunitionType(std::string munitionType); 53 void attachWeaponSet(WeaponSet * wSet); 54 WeaponSet * getWeaponSet(unsigned int index) const; 62 55 63 inline void setParentPawn(Pawn *parentPawn) 64 { parentPawn_=parentPawn; } 65 inline Pawn * getParentPawn() 66 { return parentPawn_; } 56 void attachWeaponPack(WeaponPack * wPack, unsigned int wSetNumber); 57 WeaponPack * getWeaponPack(unsigned int index) const; 67 58 68 inline int getWeaponSlotSize() 59 void fire(unsigned int firemode); 60 61 void setNewMunition(const std::string& munitionType, Munition * munitionToAdd); 62 void setNewSharedMunition(const std::string& munitionType, Munition * munitionToAdd); 63 Munition * getMunitionType(const std::string& munitionType) const; 64 65 inline void setPawn(Pawn * pawn) 66 { this->pawn_ = pawn; } 67 inline Pawn * getPawn() const 68 { return this->pawn_; } 69 70 inline int getWeaponSlotSize() const 69 71 { return this->weaponSlots_.size(); } 70 72 73 static inline unsigned int getMaxFireModes() 74 { return MAX_FIRE_MODES; } 75 static inline unsigned int getFireModeMask(unsigned int firemode) 76 { return (0x1 << firemode); } 77 71 78 private: 72 std:: vector<WeaponSet *> weaponSets_;73 std:: vector<WeaponSlot *> weaponSlots_;74 std:: vector<WeaponPack *> weaponPacks_;79 std::map<unsigned int, WeaponSet *> weaponSets_; 80 std::set<WeaponSlot *> weaponSlots_; 81 std::set<WeaponPack *> weaponPacks_; 75 82 std::map<std::string, Munition *> munitionSet_; 76 Pawn * parentPawn_;83 Pawn * pawn_; 77 84 }; 78 85 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/FusionMunition.cc
r2894 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "FusionMunition.h" 30 31 31 32 #include "core/CoreIncludes.h" 32 #include "core/XMLPort.h"33 #include "util/Debug.h"34 35 #include "FusionMunition.h"36 33 37 34 namespace orxonox -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/FusionMunition.h
r2894 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "core/BaseObject.h" 35 #include "../Munition.h" 33 #include "objects/weaponSystem/Munition.h" 36 34 37 35 namespace orxonox -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.cc
r2893 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "LaserGunMunition.h" 30 31 31 32 #include "core/CoreIncludes.h" 32 #include "core/XMLPort.h"33 #include "util/Debug.h"34 35 #include "LaserGunMunition.h"36 33 37 34 namespace orxonox -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.h
r2662 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "core/BaseObject.h" 35 #include "../Munition.h" 33 #include "objects/weaponSystem/Munition.h" 36 34 37 35 namespace orxonox -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/Fusion.cc
r2710 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "Fusion.h" 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "core/XMLPort.h"34 #include "util/Debug.h"35 33 36 #include "Fusion.h" 37 34 #include "objects/weaponSystem/Munition.h" 35 #include "objects/weaponSystem/projectiles/ParticleProjectile.h" 36 #include "objects/weaponSystem/WeaponSystem.h" 38 37 39 38 namespace orxonox … … 73 72 projectile->setPosition(this->getWorldPosition()); 74 73 projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_); 75 projectile->setOwner(this->get ParentWeaponSystem()->getParentPawn());74 projectile->setOwner(this->getWeaponSystem()->getPawn()); 76 75 } 77 76 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/Fusion.h
r2710 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "core/BaseObject.h" 35 36 #include "../munitions/LaserGunMunition.h" 37 #include "util/Math.h" 38 #include "../Weapon.h" 39 #include "../projectiles/BillboardProjectile.h" 40 #include "../projectiles/ParticleProjectile.h" 33 #include "objects/weaponSystem/Weapon.h" 41 34 42 35 namespace orxonox -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/HsW01.cc
r2901 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "HsW01.h" 31 31 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/XMLPort.h" 34 #include "util/Debug.h"35 36 #include "HsW01.h"37 38 34 39 35 namespace orxonox … … 79 75 projectile->setPosition(this->getWorldPosition()); 80 76 projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_); 81 projectile->setOwner(this->get ParentWeaponSystem()->getParentPawn());77 projectile->setOwner(this->getWeaponSystem()->getPawn()); 82 78 } 83 79 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc
r2893 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "LaserGun.h" 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "core/XMLPort.h"34 #include "util/Debug.h"35 33 36 #include "LaserGun.h" 37 34 #include "objects/weaponSystem/Munition.h" 35 #include "objects/weaponSystem/projectiles/ParticleProjectile.h" 36 #include "objects/weaponSystem/WeaponSystem.h" 38 37 39 38 namespace orxonox … … 79 78 projectile->setPosition(this->getWorldPosition()); 80 79 projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_); 81 projectile->setOwner(this->get ParentWeaponSystem()->getParentPawn());80 projectile->setOwner(this->getWeaponSystem()->getPawn()); 82 81 } 83 82 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/LaserGun.h
r2893 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "core/BaseObject.h" 35 36 #include "../munitions/LaserGunMunition.h" 37 #include "util/Math.h" 38 #include "../Weapon.h" 39 #include "../projectiles/BillboardProjectile.h" 40 #include "../projectiles/ParticleProjectile.h" 33 #include "objects/weaponSystem/Weapon.h" 41 34 42 35 namespace orxonox -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/Missile.cc
r2097 r2912 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 31 #include <list> 30 #include "Missile.h" 32 31 33 32 #include "core/CoreIncludes.h" 34 33 #include "core/XMLPort.h" 35 #include "util/Debug.h"36 37 34 38 35 namespace orxonox -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/Missile.h
r2106 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 33 #include "objects/weaponSystem/Weapon.h" 35 36 34 37 35 namespace orxonox -
code/branches/weapons/src/orxonox/objects/worldentities/ControllableEntity.h
r2851 r2912 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 33 #include "MobileEntity.h" 35 #include "objects/weaponSystem/WeaponSystem.h"36 34 37 35 namespace orxonox … … 83 81 { this->rotateRoll(Vector2(value, 0)); } 84 82 85 virtual void fire(WeaponMode::Enum fireMode) {} 86 virtual void altFire(WeaponMode::Enum fireMode) {} 83 virtual void fire(unsigned int firemode) {} 87 84 88 85 virtual void boost() {} -
code/branches/weapons/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2896 r2912 39 39 #include "objects/worldentities/ParticleSpawner.h" 40 40 #include "objects/worldentities/ExplosionChunk.h" 41 #include "objects/weaponSystem/WeaponSystem.h" 42 #include "objects/weaponSystem/WeaponSlot.h" 43 #include "objects/weaponSystem/WeaponPack.h" 44 #include "objects/weaponSystem/WeaponSet.h" 41 45 42 46 namespace orxonox … … 66 70 { 67 71 this->weaponSystem_ = new WeaponSystem(this); 68 this->weaponSystem_->setPa rentPawn(this);72 this->weaponSystem_->setPawn(this); 69 73 } 70 74 else … … 100 104 XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7); 101 105 102 XMLPortObject(Pawn, WeaponSlot, "weaponslots", setWeaponSlot, getWeaponSlot, xmlelement, mode);103 XMLPortObject(Pawn, WeaponSet, "weaponsets", setWeaponSet, getWeaponSet, xmlelement, mode);104 XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode);106 XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode); 107 XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode); 108 XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPack, getWeaponPack, xmlelement, mode); 105 109 } 106 110 … … 119 123 if (this->weaponSystem_) 120 124 { 121 if (this->fire_ & WeaponMode::fire) 122 this->weaponSystem_->fire(WeaponMode::fire); 123 if (this->fire_ & WeaponMode::altFire) 124 this->weaponSystem_->fire(WeaponMode::altFire); 125 if (this->fire_ & WeaponMode::altFire2) 126 this->weaponSystem_->fire(WeaponMode::altFire2); 125 for (unsigned int firemode = 0; firemode < WeaponSystem::getMaxFireModes(); firemode++) 126 if (this->fire_ & WeaponSystem::getFireModeMask(firemode)) 127 this->weaponSystem_->fire(firemode); 127 128 } 128 129 this->fire_ = this->firehack_; … … 252 253 } 253 254 254 void Pawn::fire( WeaponMode::Enum fireMode)255 { 256 this->firehack_ |= fireMode;255 void Pawn::fire(unsigned int firemode) 256 { 257 this->firehack_ |= WeaponSystem::getFireModeMask(firemode); 257 258 } 258 259 … … 275 276 * --> e.g. Pickup-Items 276 277 */ 277 void Pawn:: setWeaponSlot(WeaponSlot * wSlot)278 void Pawn::addWeaponSlot(WeaponSlot * wSlot) 278 279 { 279 280 this->attach(wSlot); … … 285 286 { 286 287 if (this->weaponSystem_) 287 return this->weaponSystem_->getWeaponSlot Pointer(index);288 return this->weaponSystem_->getWeaponSlot(index); 288 289 else 289 290 return 0; 290 291 } 291 292 292 void Pawn::setWeaponPack(WeaponPack * wPack) 293 { 294 if (this->weaponSystem_) 295 { 296 wPack->setParentWeaponSystem(this->weaponSystem_); 297 wPack->setParentWeaponSystemToAllWeapons(this->weaponSystem_); 298 this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() ); 299 wPack->attachNeededMunitionToAllWeapons(); 300 } 293 void Pawn::addWeaponPack(WeaponPack * wPack) 294 { 295 if (this->weaponSystem_) 296 this->weaponSystem_->attachWeaponPack(wPack, wPack->getFireMode()); 301 297 } 302 298 … … 304 300 { 305 301 if (this->weaponSystem_) 306 return this->weaponSystem_->getWeaponPack Pointer(firemode);302 return this->weaponSystem_->getWeaponPack(firemode); 307 303 else 308 304 return 0; 309 305 } 310 306 311 void Pawn:: setWeaponSet(WeaponSet * wSet)307 void Pawn::addWeaponSet(WeaponSet * wSet) 312 308 { 313 309 if (this->weaponSystem_) … … 318 314 { 319 315 if (this->weaponSystem_) 320 return this->weaponSystem_->getWeaponSet Pointer(index);316 return this->weaponSystem_->getWeaponSet(index); 321 317 else 322 318 return 0; -
code/branches/weapons/src/orxonox/objects/worldentities/pawns/Pawn.h
r2826 r2912 34 34 #include "objects/worldentities/ControllableEntity.h" 35 35 #include "objects/RadarViewable.h" 36 #include "objects/weaponSystem/WeaponSystem.h"37 36 38 37 namespace orxonox … … 40 39 class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable 41 40 { 41 friend class WeaponSystem; 42 42 43 public: 43 44 Pawn(BaseObject* creator); … … 79 80 virtual void kill(); 80 81 81 virtual void fire( WeaponMode::Enum fireMode);82 virtual void fire(unsigned int firemode); 82 83 virtual void postSpawn(); 83 84 84 void setWeaponSlot(WeaponSlot * wSlot);85 void addWeaponSlot(WeaponSlot * wSlot); 85 86 WeaponSlot * getWeaponSlot(unsigned int index) const; 86 void setWeaponPack(WeaponPack * wPack);87 void addWeaponPack(WeaponPack * wPack); 87 88 WeaponPack * getWeaponPack(unsigned int firemode) const; 88 void setWeaponSet(WeaponSet * wSet);89 void addWeaponSet(WeaponSet * wSet); 89 90 WeaponSet * getWeaponSet(unsigned int index) const; 90 91 … … 134 135 float spawnparticleduration_; 135 136 unsigned int numexplosionchunks_; 137 138 private: 139 inline void setWeaponSystem(WeaponSystem* weaponsystem) 140 { this->weaponSystem_ = weaponsystem; } 136 141 }; 137 142 -
code/branches/weapons/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2896 r2912 196 196 } 197 197 198 void Spectator::fire( WeaponMode::Enum fireMode)198 void Spectator::fire(unsigned int firemode) 199 199 { 200 200 if (this->getPlayer()) -
code/branches/weapons/src/orxonox/objects/worldentities/pawns/Spectator.h
r2662 r2912 57 57 virtual void rotateRoll(const Vector2& value); 58 58 59 virtual void fire( WeaponMode::Enum fireMode);59 virtual void fire(unsigned int firemode); 60 60 virtual void greet(); 61 61
Note: See TracChangeset
for help on using the changeset viewer.