Changeset 4951 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons/weapon_manager.cc
- Timestamp:
- Jul 24, 2005, 11:15:00 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/weapon_manager.cc
r4949 r4951 13 13 main-programmer: Patrick Boenzli 14 14 co-programmer: Benjamin Grauer 15 16 2005-07-24: Benjamin Grauer: restructurate, so it can handle the new Weapons. 15 17 */ 16 18 … … 34 36 * @param number of weapon slots of the model/ship <= 8 (limitied) 35 37 */ 36 WeaponManager::WeaponManager( int slotCount)38 WeaponManager::WeaponManager(unsigned int slotCount) 37 39 { 38 40 this->init(); 39 this->s lotCount = slotCount;41 this->setSlotCount(slotCount); 40 42 } 41 43 … … 51 53 WeaponManager::~WeaponManager() 52 54 { 53 /*54 i dont have to delete the weapons itself, because they are55 worldentities and therefore in the entities list of the world.56 world will clean them up for me57 */58 for(int i = 0; i < WM_MAX_CONFIGS; ++i)59 {60 this->configs[i].bUsed = false;61 for(int j = 0; j < WM_MAX_SLOTS; ++j)62 this->configs[i].slots[j] = NULL;63 }64 65 55 // crosshair being a PNode it must not be deleted (this is because PNodes delete themselves.) 66 56 //delete this->crosshair; … … 74 64 this->setClassID(CL_WEAPON_MANAGER, "WeaponManager"); 75 65 76 for(int i = 0; i < WM_MAX_CONFIGS; ++i) 77 { 78 this->configs[i].bUsed = false; 79 for(int j = 0; j < WM_MAX_SLOTS; ++j) 80 this->configs[i].slots[j] = NULL; 81 } 82 this->currConfID = WM_CONFIG0; 83 84 85 86 66 this->parent = NULL; 67 68 for (int i = 0; i < WM_MAX_CONFIGS; i++) 69 for (int j = 0; j < WM_MAX_SLOTS; j++) 70 this->configs[i][j] = NULL; 71 72 for (int i = 0; i < WM_MAX_SLOTS; i++) 73 { 74 this->currentSlotConfig[i].capability = WM_SLOTC_ALL; 75 this->currentSlotConfig[i].currentWeapon = NULL; 76 this->currentSlotConfig[i].nextWeapon = NULL; 77 } 78 79 for (int i = 0; i < WM_MAX_LOADED_WEAPONS; i++) 80 this->availiableWeapons[i] = NULL; 81 82 83 this->currentConfigID = 0; 84 this->slotCount = 2; 85 this->weaponChange; 86 87 // CROSSHAIR INITIALISATION 87 88 this->crosshair = new Crosshair(); 88 89 … … 101 102 { 102 103 static_cast<BaseObject*>(this)->loadParams(root); 103 104 /* 104 105 LoadParam<WeaponManager>(root, "slot-count", this, &WeaponManager::setSlotCount) 105 106 .describe("how many slots(cannons) the WeaponManager can handle"); … … 111 112 // LoadParam<WeaponManager>(root, "Weapon", this, &WeaponManager::addWeapon); 112 113 113 LOAD_PARAM_END_CYCLE; 114 LOAD_PARAM_END_CYCLE;*/ 114 115 } 115 116 … … 134 135 * @param slotCount the number of slots 135 136 */ 136 void WeaponManager::setSlotCount(int slotCount) 137 { 138 this->slotCount = slotCount; 137 void WeaponManager::setSlotCount(unsigned int slotCount) 138 { 139 if (slotCount <= WM_MAX_SLOTS) 140 this->slotCount = slotCount; 141 else 142 this->slotCount = WM_MAX_SLOTS; 139 143 } 140 144 … … 152 156 void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID) 153 157 { 154 if( slotID == WM_FREE_SLOT) 155 { 156 int freeSlot = this->getNextFreeSlot( configID); 157 if( freeSlot < 0 || freeSlot >= this->slotCount) 158 if (unlikely(configID >= WM_MAX_CONFIGS || slotID >= (int)this->slotCount)) 159 { 160 PRINTF(2)("Slot %d of config %d is not availiabe\n", slotID, configID); 161 return; 162 } 163 164 if (this->configs[configID][slotID] != NULL && configID > 0 && slotID > 0) 165 PRINTF(3)("Weapon-slot %d/%d of %s already poulated, overwriting\n", configID, slotID, this->getName()); 166 167 if (slotID == -1) // WM_FREE_SLOT 168 { 169 slotID = this->getNextFreeSlot(configID); 170 if( slotID < 0 || slotID >= this->slotCount) 158 171 { 159 172 PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n"); 160 173 return; 161 174 } 162 PRINTF(3)("Added new Weapon to Config:%i/Slot:%i\n", configID, freeSlot); 163 this->configs[configID].bUsed = true; 164 this->configs[configID].slots[freeSlot] = weapon; 165 return; 166 } 167 this->configs[configID].bUsed = true; 168 this->configs[configID].slots[slotID] = weapon; 175 } 176 this->configs[configID][slotID] = weapon; 169 177 PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID); 170 178 } … … 187 195 void WeaponManager::nextWeaponConf() 188 196 { 189 PRINTF(4)("Changing weapon configuration: from %i to next\n", this->currConfID); 190 191 int i, lastConfID; 192 lastConfID = this->currConfID; 193 for(i = this->currConfID + 1; i < WM_MAX_CONFIGS && !this->configs[i].bUsed; ++i); 194 if( i == WM_MAX_CONFIGS) this->currConfID = WM_CONFIG0; 195 else this->currConfID = i; 196 197 198 Weapon *w1, *w2; 199 for(int j = 0; j < WM_MAX_SLOTS; ++j) 200 { 201 w1 = this->configs[lastConfID].slots[j]; 202 w2 = this->configs[this->currConfID].slots[j]; 203 204 if( w1 == w2) 197 PRINTF(4)("Changing weapon configuration: from %i to next\n", this->currentConfigID); 198 199 ++this->currentConfigID; 200 if (this->currentConfigID >= WM_MAX_CONFIGS) 201 this->currentConfigID = 0; 202 203 for (int i = 0; i < WM_MAX_SLOTS; i++) 204 { 205 this->currentSlotConfig[i].nextWeapon = this->configs[currentConfigID][i]; 206 if (this->currentSlotConfig[i].currentWeapon != this->currentSlotConfig[i].nextWeapon && this->currentSlotConfig[i].currentWeapon != NULL) 207 (this->currentSlotConfig[i].currentWeapon->requestAction(WA_DEACTIVATE)); 208 } 209 210 this->debug(); 211 } 212 213 214 /** 215 * triggers fire of all weapons in the current weaponconfig 216 */ 217 void WeaponManager::fire() 218 { 219 Weapon* firingWeapon; 220 for(int i = 0; i < this->slotCount; i++) 221 { 222 firingWeapon = this->currentSlotConfig[i].currentWeapon; 223 if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT); 224 } 225 this->crosshair->setRotationSpeed(500); 226 this->crossHairSizeAnim->replay(); 227 } 228 229 230 /** 231 * triggers tick of all weapons in the current weaponconfig 232 * @param second passed since last tick 233 */ 234 void WeaponManager::tick(float dt) 235 { 236 Weapon* tickWeapon; 237 238 // all weapons 239 for(int i = 0; i < this->slotCount; i++) 240 { 241 242 tickWeapon = this->currentSlotConfig[i].currentWeapon; 243 if (tickWeapon != this->currentSlotConfig[i].nextWeapon) // if no change occures 205 244 { 206 printf("no need for change\n"); 207 } 208 else 209 { 210 if( w1 != NULL ) 245 if (tickWeapon != NULL && tickWeapon->isActive()) 211 246 { 212 w1->requestAction(WA_DEACTIVATE); 213 printf("deactivating %i,%i\n", j,lastConfID); 247 tickWeapon->requestAction(WA_DEACTIVATE); 214 248 } 215 if( w2 != NULL)249 else 216 250 { 217 w2->requestAction(WA_ACTIVATE); 218 printf("activating %i,%i\n", j, this->currConfID); 251 tickWeapon = this->currentSlotConfig[i].currentWeapon = this->currentSlotConfig[i].nextWeapon; 252 if (tickWeapon != NULL) 253 tickWeapon->requestAction(WA_ACTIVATE); 219 254 } 220 255 } 221 } 222 } 223 224 225 /** 226 * triggers fire of all weapons in the current weaponconfig 227 */ 228 void WeaponManager::fire() 229 { 230 Weapon* firingWeapon; 231 for(int i = 0; i < WM_MAX_SLOTS; ++i) 232 { 233 firingWeapon = this->configs[this->currConfID].slots[i]; 234 if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT); 235 } 236 this->crosshair->setRotationSpeed(500); 237 this->crossHairSizeAnim->replay(); 238 } 239 240 241 /** 242 * triggers tick of all weapons in the current weaponconfig 243 * @param second passed since last tick 244 */ 245 void WeaponManager::tick(float dt) 246 { 247 Weapon* w; 248 for(int i = 0; i < WM_MAX_SLOTS; ++i) 249 { 250 w = this->configs[this->currConfID].slots[i]; 251 if( w != NULL && w->isActive()) 252 w->tickW(dt); 256 257 if( tickWeapon != NULL && tickWeapon->isActive()) 258 tickWeapon->tickW(dt); 253 259 } 254 260 … … 260 266 * triggers draw of all weapons in the current weaponconfig 261 267 */ 262 void WeaponManager::draw() 263 { 264 Weapon* w; 265 for (int j = 0; j < 4; ++j ) 266 for(int i = 0; i < WM_MAX_SLOTS; ++i) 267 { 268 w = this->configs[j].slots[i]; 269 if( w != NULL && w->isVisible()) 270 w->draw(); 268 void WeaponManager::draw() const 269 { 270 Weapon* drawWeapon; 271 for (int i = 0; i < this->slotCount; i++) 272 { 273 drawWeapon = this->currentSlotConfig[i].currentWeapon; 274 if( drawWeapon != NULL && drawWeapon->isVisible()) 275 drawWeapon->draw(); 271 276 } 272 277 } … … 279 284 int WeaponManager::getNextFreeSlot(int configID) 280 285 { 281 for( int i = 0; i < WM_MAX_SLOTS; ++i)282 { 283 if( this->configs[configID] .slots[i] == NULL)286 for( int i = 0; i < this->slotCount; ++i) 287 { 288 if( this->configs[configID][i] == NULL) 284 289 return i; 285 290 } … … 287 292 } 288 293 294 295 296 void WeaponManager::debug() const 297 { 298 PRINT(3)("WeaponManager Debug Information\n"); 299 PRINT(3)("-------------------------------\n"); 300 PRINT(3)("current Config is %d\n", this->currentConfigID); 301 for (int i = 0; i < WM_MAX_CONFIGS; i++) 302 { 303 PRINT(3)("Listing Weapons in Configuration %d\n", i); 304 for (int j = 0; j < WM_MAX_SLOTS; j++) 305 { 306 if (this->configs[i][j] != NULL) 307 PRINT(3)("Slot %d loaded a %s\n", j, this->configs[i][j]->getClassName()); 308 } 309 } 310 }
Note: See TracChangeset
for help on using the changeset viewer.