- Timestamp:
- Apr 9, 2009, 3:18:11 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.