Changeset 4953 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons/weapon_manager.cc
- Timestamp:
- Jul 25, 2005, 12:22:24 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/weapon_manager.cc
r4952 r4953 28 28 #include "list.h" 29 29 #include "t_animation.h" 30 #include "null_parent.h" 30 31 31 32 using namespace std; … … 36 37 * @param number of weapon slots of the model/ship <= 8 (limitied) 37 38 */ 38 WeaponManager::WeaponManager( unsigned int slotCount)39 WeaponManager::WeaponManager(PNode* parent) 39 40 { 40 41 this->init(); 41 this->set SlotCount(slotCount);42 this->setParent(parent); 42 43 } 43 44 … … 130 131 } 131 132 133 void WeaponManager::setParent(PNode* parent) 134 { 135 if (parent == NULL) 136 parent = NullParent::getInstance(); 137 this->parent = parent; 138 if (this->parent != NULL) 139 { 140 for (int i = 0; i < WM_MAX_SLOTS; i++) 141 this->parent->addChild(&this->currentSlotConfig[i].position); 142 } 143 144 } 132 145 133 146 /** … … 141 154 else 142 155 this->slotCount = WM_MAX_SLOTS; 156 } 157 158 void WeaponManager::setSlotPosition(int slot, const Vector& position) 159 { 160 if (slot < this->slotCount) 161 this->currentSlotConfig[slot].position.setRelCoor(position); 143 162 } 144 163 … … 174 193 } 175 194 } 195 196 //! @todo check if the weapon is already assigned to another config in another slot 197 176 198 this->configs[configID][slotID] = weapon; 199 if (this->parent != NULL) 200 weapon->setParent(parent); 177 201 PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID); 178 202 } … … 189 213 /** 190 214 * changes to the next weapon configuration 191 *192 * if there are multiple weapon configurations defined by the manager, use this to switch between them193 * this function will deactivate the weapons first, change the config and reactivate them later194 215 */ 195 216 void WeaponManager::nextWeaponConf() … … 199 220 this->currentConfigID = 0; 200 221 this->changeWeaponConfig(this->currentConfigID); 201 this->debug(); 202 } 203 222 } 223 224 /** 225 * changes to the previous configuration 226 */ 204 227 void WeaponManager::previousWeaponConfig() 205 228 { … … 208 231 this->currentConfigID = WM_MAX_CONFIGS -1; 209 232 this->changeWeaponConfig(this->currentConfigID); 210 this->debug(); 211 212 213 } 214 233 } 234 235 /** 236 * change to a desired configuration 237 * @param weaponConfig the configuration to jump to. 238 */ 215 239 void WeaponManager::changeWeaponConfig(int weaponConfig) 216 240 { … … 220 244 { 221 245 this->currentSlotConfig[i].nextWeapon = this->configs[currentConfigID][i]; 222 if (this->currentSlotConfig[i].currentWeapon != NULL && this->currentSlotConfig[i].currentWeapon != this->currentSlotConfig[i].nextWeapon) 223 (this->currentSlotConfig[i].currentWeapon->requestAction(WA_DEACTIVATE)); 246 if (this->currentSlotConfig[i].currentWeapon != this->currentSlotConfig[i].nextWeapon) 247 { 248 if (this->currentSlotConfig[i].currentWeapon != NULL) 249 (this->currentSlotConfig[i].currentWeapon->requestAction(WA_DEACTIVATE)); 250 if (this->currentSlotConfig[i].nextWeapon != NULL && this->currentSlotConfig[i].nextWeapon->isActive()) 251 this->currentSlotConfig[i].nextWeapon = NULL; 252 } 224 253 } 225 254 } … … 265 294 tickWeapon = this->currentSlotConfig[i].currentWeapon = this->currentSlotConfig[i].nextWeapon; 266 295 if (tickWeapon != NULL) 296 { 267 297 tickWeapon->requestAction(WA_ACTIVATE); 298 tickWeapon->setParent(&this->currentSlotConfig[i].position); 299 } 268 300 } 269 301 } … … 308 340 309 341 342 /** 343 * outputs some nice debug information about the WeaponManager 344 */ 310 345 void WeaponManager::debug() const 311 346 {
Note: See TracChangeset
for help on using the changeset viewer.