Changeset 7533
- Timestamp:
- Oct 13, 2010, 11:35:18 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/data/defaultConfig/keybindings.ini
r7163 r7533 51 51 KeyKana= 52 52 KeyKanji= 53 KeyL= dropItems53 KeyL= 54 54 KeyLeft="scale -1 moveRightLeft" 55 55 KeyLeftAlt= -
code/trunk/src/modules/pickup/CollectiblePickup.h
r7494 r7533 50 50 @author 51 51 Damian 'Mozork' Frick 52 53 @ingroup Pickup 52 54 */ 53 55 class _PickupExport CollectiblePickup : public Pickupable -
code/trunk/src/modules/pickup/DroppedPickup.h
r7493 r7533 51 51 @author 52 52 Damian 'Mozork' Frick 53 54 @ingroup Pickup 53 55 */ 54 56 class _PickupExport DroppedPickup : public PickupSpawner 55 57 { 56 58 public: 57 DroppedPickup(BaseObject* creator); //!< Default constructor.59 DroppedPickup(BaseObject* creator); 58 60 DroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance = 10.0); //!< Constructor. 59 virtual ~DroppedPickup(); //!< Destructor.61 virtual ~DroppedPickup(); 60 62 61 63 protected: -
code/trunk/src/modules/pickup/Pickup.cc
r7494 r7533 44 44 { 45 45 46 //! Initializing the static strings. 46 47 /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate"; 47 48 /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse"; -
code/trunk/src/modules/pickup/Pickup.h
r7494 r7533 48 48 { 49 49 50 //! Enum for the @ref orxonox::Pickup "Pickup" activation type. 50 /** 51 @brief 52 Enum for the @ref orxonox::Pickup "Pickup" activation type. 53 54 @ingroup Pickup 55 */ 51 56 namespace pickupActivationType 52 57 { … … 58 63 } 59 64 60 //! Enum for the @ref orxonox::Pickup "Pickup" duration type. 65 /** 66 @brief 67 Enum for the @ref orxonox::Pickup "Pickup" duration type. 68 69 @ingroup Pickup 70 */ 61 71 namespace pickupDurationType 62 72 { … … 84 94 @author 85 95 Damian 'Mozork' Frick 96 97 @ingroup Pickup 86 98 */ 87 99 class _PickupExport Pickup : public CollectiblePickup, public BaseObject -
code/trunk/src/modules/pickup/PickupCollection.cc
r7494 r7533 118 118 // Change used for all Pickupables this PickupCollection consists of. 119 119 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 120 {121 120 (*it)->setUsed(this->isUsed()); 122 } 121 123 122 this->processingUsed_ = false; 124 123 … … 176 175 // Change the pickedUp status for all Pickupables this PickupCollection consists of. 177 176 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 178 {179 177 (*it)->setPickedUp(this->isPickedUp()); 180 } 178 181 179 this->processingPickedUp_ = false; 182 180 -
code/trunk/src/modules/pickup/PickupCollection.h
r7494 r7533 65 65 @author 66 66 Damian 'Mozork' Frick 67 68 @ingroup Pickup 67 69 */ 68 70 class _PickupExport PickupCollection : public CollectiblePickup, public BaseObject -
code/trunk/src/modules/pickup/PickupCollectionIdentifier.cc
r7494 r7533 69 69 assert(identifier); 70 70 71 // Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.71 // Slight un-niceity to cast the const PickupIdentifier to a const PickupCollectionIdentifier, but since we cast to a const, there is no harm done. 72 72 PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier); 73 73 const PickupCollectionIdentifier* collectionIdentifier = orxonox_cast<PickupCollectionIdentifier*>(temp); … … 94 94 } 95 95 96 // Means they are equal.96 // This means they are equal. 97 97 return 0; 98 98 } -
code/trunk/src/modules/pickup/PickupCollectionIdentifier.h
r7494 r7533 51 51 52 52 @ref orxonox::Pickupable "Pickupables" (resp. @ref orxonox::CollectiblePickup "CollectiblePickups") can be added to the PickupCollectionIdentifier via the addPickup method. 53 53 54 @author 54 55 Damian 'Mozork' Frick 56 57 @ingroup Pickup 55 58 */ 56 59 class _PickupExport PickupCollectionIdentifier : public PickupIdentifier -
code/trunk/src/modules/pickup/PickupManager.cc
r7531 r7533 42 42 #include "network/Host.h" 43 43 #include "network/NetworkFunction.h" 44 44 45 #include "interfaces/PickupCarrier.h" 45 46 #include "infos/PlayerInfo.h" 46 47 #include "worldentities/pawns/Pawn.h" 48 47 49 #include "CollectiblePickup.h" 48 50 #include "PickupRepresentation.h" … … 57 59 ManageScopedSingleton(PickupManager, ScopeID::Root, false); 58 60 61 // Initialization of the name of the PickupInventory GUI. 59 62 /*static*/ const std::string PickupManager::guiName_s = "PickupInventory"; 60 63 64 // Register static newtork functions that are used to communicate changes to pickups over the network, such that the PickupInventory can display the information about the pickups properly. 61 65 registerStaticNetworkFunction(PickupManager::pickupChangedUsedNetwork); 62 66 registerStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork); … … 68 72 Constructor. Registers the PickupManager and creates the default PickupRepresentation. 69 73 */ 70 PickupManager::PickupManager() : guiLoaded_(false), pickup Index_(0), defaultRepresentation_(NULL)74 PickupManager::PickupManager() : guiLoaded_(false), pickupHighestIndex_(0), defaultRepresentation_(NULL) 71 75 { 72 76 RegisterObject(PickupManager); 73 77 78 //TODO: Only create if isMaster(). 74 79 this->defaultRepresentation_ = new PickupRepresentation(); 75 80 … … 80 85 @brief 81 86 Destructor. 82 Destroys the default PickupRepresentation .87 Destroys the default PickupRepresentation and does some cleanup. 83 88 */ 84 89 PickupManager::~PickupManager() 85 90 { 91 // Destroying the default representation. 86 92 if(this->defaultRepresentation_ != NULL) 87 93 this->defaultRepresentation_->destroy(); 88 94 89 95 this->representations_.clear(); 90 91 //TODO: Destroy properly... 96 this->representationsNetworked_.clear(); 97 98 //TODO: Destroying properly? 99 //TODO: Shouldnt these list be empty, to avoid problems when switching levels? 100 // Destroying all the PickupInventoryContainers that are still there. 101 for(std::map<uint32_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.begin(); it != this->pickupInventoryContainers_.end(); it++) 102 delete it->second; 103 this->pickupInventoryContainers_.clear(); 104 105 // Destroying all the WeakPointers that are still there. 106 for(std::map<uint32_t, WeakPtr<Pickupable>*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 107 delete it->second; 108 this->pickups_.clear(); 109 110 this->indexes_.clear(); 92 111 93 112 COUT(3) << "PickupManager destroyed." << std::endl; … … 96 115 /** 97 116 @brief 98 Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents .99 For every type of Pickupable (uniquely id netified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.117 Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode). 118 For every type of Pickupable (uniquely identified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered. 100 119 @param identifier 101 120 The PickupIdentifier identifying the Pickupable. … … 110 129 assert(representation); 111 130 112 if(!this->representations_.empty() && this->representations_.find(identifier) != this->representations_.end()) // If the Pickupable already has a Representation registered. 131 // If the list is not empty and Pickupable already has a Representation registered. 132 if(!this->representations_.empty() && this->representations_.find(identifier) != this->representations_.end()) 113 133 return false; 114 134 … … 119 139 } 120 140 121 bool PickupManager::registerRepresentation(PickupRepresentation* representation) 122 { 123 assert(representation); 124 125 if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end()) // If the PickupRepresentation is already registered. 126 return false; 127 128 this->representationsNetworked_[representation->getObjectID()] = representation; 129 return true; 130 } 131 132 /** 133 @brief 134 Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. 141 /** 142 @brief 143 Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode). 135 144 @param identifier 136 145 The PickupIdentifier identifying the Pickupable. … … 146 155 147 156 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier); 148 if(it == this->representations_.end()) // !<If the Pickupable is not registered in the first place.157 if(it == this->representations_.end()) // If the Pickupable is not registered in the first place. 149 158 return false; 150 159 … … 155 164 } 156 165 166 /** 167 @brief 168 Registers a PickupRepresentation on the host it was created. 169 @param representation 170 A pointer to the PickupRepresentation. 171 @return 172 Returns true if successful, false if not. 173 */ 174 bool PickupManager::registerRepresentation(PickupRepresentation* representation) 175 { 176 assert(representation); 177 178 // If the list is not empty and PickupRepresentation is already registered. 179 if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end()) 180 return false; 181 182 this->representationsNetworked_[representation->getObjectID()] = representation; 183 return true; 184 } 185 186 /** 187 @brief 188 Unregisters a PickupRepresentation on the host it is being destroyed (which is the same host on which it was created). 189 @param representation 190 A pointer to the Pickuprepresentation. 191 @return 192 Returns true if successful, false if not. 193 */ 157 194 bool PickupManager::unregisterRepresentation(PickupRepresentation* representation) 158 195 { … … 160 197 161 198 std::map<uint32_t, PickupRepresentation*>::iterator it = this->representationsNetworked_.find(representation->getObjectID()); 162 if(it == this->representationsNetworked_.end()) // !<If the Pickupable is not registered in the first place.199 if(it == this->representationsNetworked_.end()) // If the Pickupable is not registered in the first place. 163 200 return false; 164 201 … … 175 212 Returns a pointer to the PickupRepresentation. 176 213 */ 214 //TODO: Why not return a const? 177 215 PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier) 178 216 { 179 217 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier); 180 if(it == this->representations_.end()) 218 if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input PickupIdentifier. 181 219 { 182 220 COUT(4) << "PickupManager::getRepresentation() returned default representation." << std::endl; … … 189 227 /** 190 228 @brief 191 Get the PickupRepresentation of an input Pickupable. 192 This method spares us the hassle to export the PickupIdentifier class to lua. 193 @param pickup 194 The Pickupable whose PickupRepresentation should be returned. 195 @return 196 Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred. 197 */ 198 orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint64_t pickup) 199 { 200 this->representationsNetworked_.clear(); 201 for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it) 202 this->representationsNetworked_[it->getObjectID()] = *it; 203 204 std::map<uint64_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup); 205 if(it == this->pickupInventoryContainers_.end()) 206 return this->defaultRepresentation_; 207 208 std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId); 209 if(it2 == this->representationsNetworked_.end()) 210 return this->defaultRepresentation_; 211 212 return it2->second; 213 } 214 215 /** 216 @brief 217 Update the list of picked up Pickupables and get the number of Pickupables in the list. 218 This method is used in lua to populate the PickupInventory. The intended usage is to call this method to update the list of Pickupables and then use popPickup() to get the individual Pickupables. 219 @return 220 Returns the number of the players picked up Pickupables. 221 */ 222 int PickupManager::getNumPickups(void) 223 { 224 this->pickupsIterator_ = this->pickupInventoryContainers_.begin(); 225 return this->pickupInventoryContainers_.size(); 226 } 227 228 /** 229 @brief 230 Drop the input Pickupable. 231 This method checks whether the inout Pickupable still exists and drops it, if so. 232 @param pickup 233 The Pickupable to be dropped. 234 */ 235 void PickupManager::dropPickup(uint64_t pickup) 236 { 237 if(GameMode::isMaster() && !this->pickups_.empty()) 238 { 239 Pickupable* pickupable = this->pickups_.find(pickup)->second->get(); 240 if(pickupable != NULL) 241 pickupable->drop(); 242 } 243 else 244 { 245 callStaticNetworkFunction(PickupManager::dropPickupNetworked, 0, pickup); 246 } 247 } 248 249 /*static*/ void PickupManager::dropPickupNetworked(uint64_t pickup) 250 { 251 if(GameMode::isServer()) 252 { 253 PickupManager& manager = PickupManager::getInstance(); 254 if(manager.pickups_.empty()) 255 return; 256 Pickupable* pickupable = manager.pickups_.find(pickup)->second->get(); 257 if(pickupable != NULL) 258 pickupable->drop(); 259 } 260 } 261 262 /** 263 @brief 264 Use (or unuse) the input Pickupable. 265 This method checks whether the input Pickupable still exists and uses (or unuses) it, if so, 266 @param pickup 267 The Pickupable to be used (or unused). 268 @param use 269 If true the input Pickupable is used, if false it is unused. 270 */ 271 void PickupManager::usePickup(uint64_t pickup, bool use) 272 { 273 if(GameMode::isMaster() && !this->pickups_.empty()) 274 { 275 Pickupable* pickupable = this->pickups_.find(pickup)->second->get(); 276 if(pickupable != NULL) 277 pickupable->setUsed(use); 278 } 279 else 280 { 281 callStaticNetworkFunction(PickupManager::usePickupNetworked, 0, pickup, use); 282 } 283 } 284 285 /*static*/ void PickupManager::usePickupNetworked(uint64_t pickup, bool use) 286 { 287 if(GameMode::isServer()) 288 { 289 PickupManager& manager = PickupManager::getInstance(); 290 if(manager.pickups_.empty()) 291 return; 292 Pickupable* pickupable = manager.pickups_.find(pickup)->second->get(); 293 if(pickupable != NULL) 294 pickupable->setUsed(use); 295 } 296 } 297 298 /** 299 @brief 300 Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists. 301 @param pickup 302 The Pickupable. 303 @return 304 Returns true if the input Pickupable is still valid, false if not. 305 */ 306 bool PickupManager::isValidPickup(uint64_t pickup) 307 { 308 return this->pickups_.find(pickup) != this->pickups_.end(); 309 } 310 229 Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state. 230 @param pickup 231 The Pickupable whose used status changed. 232 @param used 233 The used status the Pickupable changed to. 234 */ 311 235 void PickupManager::pickupChangedUsed(Pickupable* pickup, bool used) 312 236 { … … 317 241 318 242 CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(pickup); 319 // If the Pic upable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is.243 // If the Pickupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is. 320 244 if(collectible != NULL && collectible->isInCollection()) 321 245 return; 322 246 247 // Getting clientId of the host this change of the pickup's used status concerns. 323 248 PickupCarrier* carrier = pickup->getCarrier(); 324 249 while(carrier->getCarrierParent() != NULL) … … 332 257 unsigned int clientId = info->getClientID(); 333 258 334 std::map<Pickupable*, uint64_t>::iterator it = this->indexes_.find(pickup); 259 // Get the number identifying the pickup. 260 std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup); 335 261 assert(it != this->indexes_.end()); 336 337 uint64_t index = it->second; 262 uint32_t index = it->second; 263 264 // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns. 338 265 if(GameMode::isStandalone() || Host::getPlayerID() == clientId) 339 266 { 340 267 PickupManager::pickupChangedUsedNetwork(index, used, pickup->isUsable(), pickup->isUnusable()); 341 268 } 269 // If the concerned host is somewhere in the network, we call pickupChangedUsedNetwork() on its PickupManager. 342 270 else 343 271 { … … 346 274 } 347 275 348 /*static*/ void PickupManager::pickupChangedUsedNetwork(uint64_t pickup, bool inUse, bool usable, bool unusable) 349 { 350 PickupManager& manager = PickupManager::getInstance(); 276 /** 277 @brief 278 Helper method to react to the change in the used status of a Pickupable. 279 Static method that is used by the server to inform the client it concerns about the status change. 280 The parameters that are given are used to update the information (i.e. the PickupInventoryContainer) the concerning PickupManager has about the Pickupable that changed. 281 @param pickup 282 A number identifying the Pickupable that changed its used status. 283 @param inUse 284 The used status the Pickupable changed to. (i.e. whether the Pickupable is in use or not). 285 @param usable 286 Whether the Pickupable's used status can be changed used in the PickupInventory. 287 @param unusable 288 Whether the Pickupable's used status can be changed to unused in the PickupInventory. 289 */ 290 /*static*/ void PickupManager::pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable) 291 { 292 PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host. 293 // If the input Pickupable (i.e its identifier) is not present in the list the PickupManager has. 351 294 if(manager.pickupInventoryContainers_.find(pickup) == manager.pickupInventoryContainers_.end()) 352 295 { … … 355 298 } 356 299 300 // Update the Pickupable's container with the information transferred. 357 301 manager.pickupInventoryContainers_[pickup]->inUse = inUse; 358 302 manager.pickupInventoryContainers_[pickup]->usable = usable; 359 303 manager.pickupInventoryContainers_[pickup]->unusable = unusable; 360 304 361 manager.updateGUI(); 362 } 363 305 manager.updateGUI(); // Tell the PickupInventory that something has changed. 306 } 307 308 /** 309 @brief 310 Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state. 311 @param pickup 312 The Pickupable whose pickedUp status changed. 313 @param pickedUp 314 The pickedUp status the Pickupable changed to. 315 */ 364 316 void PickupManager::pickupChangedPickedUp(Pickupable* pickup, bool pickedUp) 365 317 { 366 318 assert(pickup); 367 319 368 if(!GameMode::isMaster()) 320 if(!GameMode::isMaster()) // If this is neither standalone nor the server. 369 321 return; 370 322 371 323 CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(pickup); 372 // If the Pic upable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is.324 // If the Pickupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is. 373 325 if(collectible != NULL && collectible->isInCollection()) 374 326 return; 375 327 328 // Getting clientId of the host this change of the pickup's pickedUp status concerns. 376 329 PickupCarrier* carrier = pickup->getCarrier(); 377 330 while(carrier->getCarrierParent() != NULL) … … 380 333 if(pawn == NULL) 381 334 return; 382 PlayerInfo* info = pawn->get Player();335 PlayerInfo* info = pawn->getFormerPlayer(); 383 336 if(info == NULL) 384 337 return; 385 338 unsigned int clientId = info->getClientID(); 386 339 387 uint64_t index = 0; 388 if(pickedUp) 389 { 390 index = this->getPickupIndex(); 340 uint32_t index = 0; 341 if(pickedUp) // If the Pickupable has changed to picked up, it is added to the required lists. 342 { 343 index = this->getPickupIndex(); // Ge a new identifier (index) for the Pickupable. 344 // Add the Pickupable to the indexes_ and pickups_ lists. 391 345 this->indexes_[pickup] = index; 392 346 this->pickups_[index] = new WeakPtr<Pickupable>(pickup); 393 347 } 394 else 395 { 396 std::map<Pickupable*, uint64_t>::iterator it = this->indexes_.find(pickup); 348 else // If it was dropped, it is removed from the required lists. 349 { 350 // Get the indentifier (index) that identifies the input Pickupable. 351 std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup); 397 352 index = it->second; 353 354 // Remove the Pickupable form the indexes_ and pickups_ list. 398 355 WeakPtr<Pickupable>* ptr = this->pickups_[index]; 399 356 this->indexes_.erase(it); … … 402 359 } 403 360 361 // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns. 362 //TODO: Needs to be added to server even if is was not picked up by it? 404 363 if(GameMode::isStandalone() || Host::getPlayerID() == clientId) 405 364 { 365 // If there is no PickupRepresentation registered the default representation is used. 406 366 if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end()) 407 367 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp); … … 409 369 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp); 410 370 } 371 // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager. 411 372 else 412 373 { 374 // If there is no PickupRepresentation registered the default representation is used. 413 375 if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end()) 414 376 { … … 423 385 } 424 386 425 /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint64_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp) 426 { 427 PickupManager& manager = PickupManager::getInstance(); 387 /** 388 @brief 389 Helper method to react to the change in the pickedUp status of a Pickupable. 390 Static method that is used by the server to inform the client it concerns about the status change. 391 The parameters that are given are used to update the information (i.e. the PickupInventoryContainer) the concerning PickupManager has about the Pickupable that changed. 392 @param pickup 393 A number identifying the Pickupable that changed its pickedUp status. 394 @param unusable 395 Whether the Pickupable's used status can be changed to unused in the PickupInventory. 396 @param representationObjectId 397 The objectId identifying (over the network) the PickupRepresentation that represents this Pickupable. 398 @param pickedUp 399 The pickedUp status the Pickupable changed to. 400 */ 401 /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp) 402 { 403 PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host. 404 // If the Pickupable has been picked up, we create a new PickupInventoryContainer for it. 428 405 if(pickedUp) 429 406 { 407 // Create a new PickupInventoryContainer for the Pickupable and set all the necessary information. 430 408 PickupInventoryContainer* container = new PickupInventoryContainer; 431 409 container->pickup = pickup; … … 435 413 container->unusable = false; 436 414 container->representationObjectId = representationObjectId; 437 manager.pickupInventoryContainers_.insert(std::pair<uint64_t, PickupInventoryContainer*>(pickup, container)); 438 439 if(GameMode::showsGraphics()) 440 { 441 if(!manager.guiLoaded_) 442 { 443 GUIManager::getInstance().loadGUI(PickupManager::guiName_s); 444 manager.guiLoaded_ = true; 445 } 446 GUIManager::getInstance().getLuaState()->doString(PickupManager::guiName_s + ".update()"); 447 } 448 } 415 // Insert the container into the pickupInventoryContainers_ list. 416 manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container)); 417 418 manager.updateGUI(); // Tell the PickupInventory that something has changed. 419 } 420 // If the Pickupable has been dropped, we remove it from the pickupInventoryContainers_ list. 449 421 else 450 422 { 451 std::map<uint 64_t, PickupInventoryContainer*>::iterator it = manager.pickupInventoryContainers_.find(pickup);423 std::map<uint32_t, PickupInventoryContainer*>::iterator it = manager.pickupInventoryContainers_.find(pickup); 452 424 if(it != manager.pickupInventoryContainers_.end()) 453 425 delete it->second; 454 426 manager.pickupInventoryContainers_.erase(pickup); 455 427 456 manager.updateGUI(); 457 } 458 } 459 428 manager.updateGUI(); // Tell the PickupInventory that something has changed. 429 } 430 } 431 432 /** 433 @brief 434 Get the PickupRepresentation of an input Pickupable. 435 This method spares us the hassle to export the PickupIdentifier class to lua. 436 @param pickup 437 The number identifying the Pickupable whose PickupRepresentation should be returned. 438 @return 439 Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred. 440 */ 441 orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint32_t pickup) 442 { 443 // Clear and rebuild the representationsNetworked_ list. 444 //TODO: Better solution? 445 this->representationsNetworked_.clear(); 446 for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it) 447 this->representationsNetworked_[it->getObjectID()] = *it; 448 449 // Get the container belonging to the input pickup, if not found return the default representation. 450 std::map<uint32_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup); 451 if(it == this->pickupInventoryContainers_.end()) 452 return this->defaultRepresentation_; 453 454 // Get the PickupRepresentation of the input pickup (through the objecId of the representation stored in the PickupInventoryContainer belonging to the pickup), if not found return the default representation. 455 std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId); 456 if(it2 == this->representationsNetworked_.end()) 457 return this->defaultRepresentation_; 458 459 return it2->second; 460 } 461 462 /** 463 @brief 464 Get the number of pickups currently picked up by the player. 465 This method is used in lua to populate the PickupInventory. The intended usage is to call this method to reset the iterator of the list of PickupInventoryContainers and then use popPickup() to get the individual PickupInventoryContainers. 466 @return 467 Returns the number of the players picked up Pickupables. 468 */ 469 int PickupManager::getNumPickups(void) 470 { 471 this->pickupsIterator_ = this->pickupInventoryContainers_.begin(); // Reset iterator. 472 473 return this->pickupInventoryContainers_.size(); 474 } 475 476 /** 477 @brief 478 Drop the input Pickupable. 479 This method checks whether the input Pickupable still exists and drops it, if so. 480 @param pickup 481 The identifier of the Pickupable to be dropped. 482 */ 483 void PickupManager::dropPickup(uint32_t pickup) 484 { 485 // If we're either server or standalone and the list of pickups is not empty, we find and drop the input pickup. 486 if(GameMode::isMaster() && !this->pickups_.empty()) 487 { 488 Pickupable* pickupable = this->pickups_.find(pickup)->second->get(); 489 if(pickupable != NULL) 490 pickupable->drop(); 491 } 492 // If we're neither server nor standalone we drop the pickup by calling dropPickupNetworked() of the PickupManager on the server. 493 else 494 { 495 callStaticNetworkFunction(PickupManager::dropPickupNetworked, 0, pickup); 496 } 497 } 498 499 /** 500 @brief 501 Helper method to drop the input pickup on the server. 502 Static method that is used by clients to instruct the server to drop the input pickup. 503 @param pickup 504 The identifier of the Pickupable to be dropped. 505 */ 506 /*static*/ void PickupManager::dropPickupNetworked(uint32_t pickup) 507 { 508 if(GameMode::isServer()) // Obviously we only want to do this on the server. 509 { 510 PickupManager& manager = PickupManager::getInstance(); 511 //TODO: Just call dropPickup() on manager? 512 if(manager.pickups_.empty()) 513 return; 514 Pickupable* pickupable = manager.pickups_.find(pickup)->second->get(); 515 if(pickupable != NULL) 516 pickupable->drop(); 517 } 518 } 519 520 /** 521 @brief 522 Use (or unuse) the input Pickupable. 523 This method checks whether the input Pickupable still exists and uses (or unuses) it, if so, 524 @param pickup 525 The identifier of the Pickupable to be used (or unused). 526 @param use 527 If true the input Pickupable is used, if false it is unused. 528 */ 529 void PickupManager::usePickup(uint32_t pickup, bool use) 530 { 531 // If we're either server or standalone and the list of pickups is not empty, we find and change the used status of the input pickup. 532 if(GameMode::isMaster() && !this->pickups_.empty()) 533 { 534 Pickupable* pickupable = this->pickups_.find(pickup)->second->get(); 535 if(pickupable != NULL) 536 pickupable->setUsed(use); 537 } 538 // If we're neither server nor standalone we change the used status of the pickup by calling usePickupNetworked() of the PickupManager on the server. 539 else 540 { 541 callStaticNetworkFunction(PickupManager::usePickupNetworked, 0, pickup, use); 542 } 543 } 544 545 /** 546 @brief 547 Helper method to use (or unuse) the input Pickupable on the server. 548 Static method that is used by clients to instruct the server to use (or unuse) the input pickup. 549 @param pickup 550 The identifier of the Pickupable to be used (or unused). 551 @param use 552 If true the input Pickupable is used, if false it is unused. 553 */ 554 /*static*/ void PickupManager::usePickupNetworked(uint32_t pickup, bool use) 555 { 556 if(GameMode::isServer()) 557 { 558 PickupManager& manager = PickupManager::getInstance(); 559 //TODO: Just call usePickup() on manager? 560 if(manager.pickups_.empty()) 561 return; 562 Pickupable* pickupable = manager.pickups_.find(pickup)->second->get(); 563 if(pickupable != NULL) 564 pickupable->setUsed(use); 565 } 566 } 567 568 /** 569 @brief 570 Updates the PickupInventory GUI. 571 Also loads the PickupInventory GUI if is hasn't been done already. 572 */ 460 573 inline void PickupManager::updateGUI(void) 461 574 { 575 // We only need to update (and load) the GUI if this host shows graphics. 462 576 if(GameMode::showsGraphics()) 463 577 { 464 if(!this->guiLoaded_) 578 if(!this->guiLoaded_) // If the GUI hasn't been loaded, yet, we load it. 465 579 { 466 580 GUIManager::getInstance().loadGUI(PickupManager::guiName_s); 467 581 this->guiLoaded_ = true; 468 582 } 583 584 // Update the GUI. 469 585 GUIManager::getInstance().getLuaState()->doString(PickupManager::guiName_s + ".update()"); 470 586 } 471 587 } 472 588 473 uint64_t PickupManager::getPickupIndex(void) 474 { 475 if(this->pickupIndex_ == uint64_t(~0x0)-1) 476 this->pickupIndex_ = 0; 477 return this->pickupIndex_++; 589 /** 590 @brief 591 Get a new index for a Pickupable. 592 This will work as long as the number of Pickupables that are picked up is sufficiently small and as long as they don't exist forever. 593 @return 594 Returns the new index. 595 */ 596 uint32_t PickupManager::getPickupIndex(void) 597 { 598 if(this->pickupHighestIndex_ == uint32_t(~0x0)-1) // If we've reached the highest possible number, we wrap around. 599 this->pickupHighestIndex_ = 0; 600 return this->pickupHighestIndex_++; 478 601 } 479 602 -
code/trunk/src/modules/pickup/PickupManager.h
r7504 r7533 53 53 54 54 // tolua_begin 55 /** 56 @brief 57 Data structure to store collected data for one specific @ref orxonox::Pickupable "Pickupable". 58 This is used to not have to synchronise @ref orxonox::Pickupable "Pickupable" just to have the needed information for the PickupInventory available on all clients. Instead the information is sent over the network and stored in a PickupInventoryContainer. 59 60 @ingroup Pickup 61 */ 55 62 struct PickupInventoryContainer 56 63 { 57 uint 64_t pickup;58 bool inUse; 59 bool pickedUp; 60 bool usable; 61 bool unusable; 62 uint32_t representationObjectId; 64 uint32_t pickup; //!< An indentifier for the @ref orxonox::Pickupable "Pickupable" that is associated with the information stored here. 65 bool inUse; //!< Whether the @ref orxonox::Pickupable "Pickupable" is currently in use. 66 bool pickedUp; //!< Whether the @ref orxonox::Pickupable "Pickupable" is currently picked up. 67 bool usable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is usable. 68 bool unusable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is droppable. 69 uint32_t representationObjectId; //!< The objectId of the @ref orxonox::PickupRepresentation "PickupRepresentation" that represents the @ref orxonox::Pickupable "Pickupable". 63 70 }; 64 71 // tolua_end … … 66 73 /** 67 74 @brief 68 Manages Pickupables. 69 In essence has two tasks to fulfill. Firstly it must link Pickupables (through their PickupIdentifiers) and their PickupRepresentations. Secondly it manages the PickupInventory. 75 The PickupManager class manages @ref orxonox::Pickupable "Pickupables". 76 77 It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their @ref orxonox::PickupIdentifier "PickupIdentifiers") to their respective @ref orxonox:PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref roxonox::Pickupable "Pickupables" for the covenience of the user.) 78 79 @section PickupManagerTechnicalDetails Technical details 80 Unfortunately <em>under the hood</em> it isn't just as easy. At least the PickupInventory part isn't. To grasp why this is we need to have a brief look at how the pickups module works over the network: 81 82 The pickups module essentially just exists on the @ref orxonox::Server "Server", since it's all game logic. That means, a @ref orxonox::PickupSpawner "PickupSpawner" is always triggered on the server, the @ref orxonox::Pickupable "Pickupable" is then picked up (and maybe used already) on the server. The effects the pickup has are synchronised over the network, if they have to be, but this is the responsibility of the entities that are affected, not the pickups module, and normally this is already implemented. The only two things that need to be communicated over the network are the graphical component of the @ref orxonox::PickupSpawner "PickupSpawner", since it needs to be displayed on the @ref orxonox::Client "Clients" as well, and anything that is needed for the PickupInventory, since it exists for each @ref orxonox::Host "Host" seperatly. 83 84 Fortunately synchronising the @ref orxonox::PickupSpawner "PickupSpawner" is already being taken care of by the synchronisation of the @ref orxonox::StaticEntity "StaticEntity" (or parents thereof). 85 86 This leaves us with the PickupInventory component (and this is really the source of all the complexity). 87 88 Firstly there are a number of lists (where by list I really mean any kind of ordered data structure) kept. 89 - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with @ref orxonox::PickupIdentifier "PickupIdentifiers" and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list. 90 - The @ref orxonox::PickupManager::representationsNetworked_ "representationsNetworked_" list is the networked (hence the name) equivalent to the @ref orxonox::PickupManager::representations_ "representations_" list. It links an objectId of a @ref orxonox::PickupRepresentation "PickupRepresentation" to a @ref orxonox::PickupRepresentation "PickupRepresentation". This list is maintained on all hosts, each representation registers itself (in its constructor) with the PickupManager. Since the representations are synchronised they are created on each host. The "same" instance on each host is identified by the same objectId and that is why we store the representations with the objectId as key. We can then use this list to get a @ref orxonox::PickupRepresentation "PickupRepresentation" for a specific @ref orxonox::Pickupable "Pickupable" (or more precisely a number identifiying that particular pickup, but we'll see that, when we look at the next list) on a client to be used in the PickupInventory. 91 - The @ref orxonox::PickupManager::pickupInventoryContainers_ "pickupInventoryContainers_" list links a number identifying a @ref orxonox::Pickupable "Pickupable" to a data structure (the @ref orxonox::PickupInventoryContainer "PickupInventoryContainer"), which contains all necessary information about that @ref orxonox::Pickupable "Pickupable". This list is maintained on all hosts, a new container is inserted when a @ref orxonox::Pickupable "Pickupable" is picked up, but only if it has been picked up by the repsective host. This list is then used by the PickupInventory to access the required information and to get the correct @ref orxonox:.PickupRepresentation "PickupRepresentation". 92 - The @ref orxonox::PickupManager::pickups_ "pickups_" list links a number identifiying a @ref orxonox::Pickupable "Pickupable" to a (weak pointer to a) @ref orxonox::Pickupable "Pickupable". It is only maintained by the server (or in standalone mode), to be able to use, unuse and drop @ref orxonox::Pickupable "Pickupables" through the PickupInventory. Since @ref orxonox::Pickupable "Pickupables" only exist on the server a client that wants to change a pickups status has so send a request over the network (with the number identifying the pickup) to the server and then the server facilitates the change, using this list to map from the identifyer to the actual @ref orxonox::Pickupable "Pickupable". 93 - The @ref orxonox::PickupManager::indexes_ "indexes_" list links a @ref orxonox::Pickupable "Pickupable" to the number identifying it. This is only maintained on the server (or in standalone mode), and is used for the inverse mapping of the previous list, which means the server uses it identify pickups on clients when it communicates changes in pickups to clients. 94 95 There is communication in both directions. From server to client, when the server informs the client that the state of some @ref orxonox::Pickupable "Pickupable" has changed, during which all necessary information to create or update the PickupInventoryContainer for that pickup on the client is sent as well. Or from client to server, when the client wants the server to change the state of some @ref orxonox::Pickupable "Pickupable". 96 70 97 @author 71 98 Damian 'Mozork' Frick 99 100 @ingroup Pickup 72 101 */ 73 102 class _PickupExport PickupManager // tolua_export … … 77 106 78 107 public: 79 PickupManager(); 80 virtual ~PickupManager(); 108 PickupManager(); //!< Constructor. 109 virtual ~PickupManager(); //!< Destructor. 81 110 111 /** 112 @brief Get the instance of the PickupManager singleton. 113 @return Returns the instance of the PickupManager singleton. 114 */ 82 115 static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export 83 116 84 117 bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. 85 bool registerRepresentation(PickupRepresentation* representation);86 118 bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. 87 bool unregisterRepresentation(PickupRepresentation* representation); 119 120 bool registerRepresentation(PickupRepresentation* representation); //!< Registers a PickupRepresentation on the host it was created. 121 bool unregisterRepresentation(PickupRepresentation* representation); //!< Unregisters a PickupRepresentation on the host it is being destroyed. 122 88 123 PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier. 89 124 125 virtual void pickupChangedUsed(Pickupable* pickup, bool used); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state. 126 static void pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable); //!< Helper method to react to the change in the used status of a Pickupable. 127 virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state. 128 static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable. 129 130 // Methods to be used by the PickupInventory. 131 public: 90 132 // tolua_begin 91 orxonox::PickupRepresentation* getPickupRepresentation(uint 64_t pickup); //!< Get the PickupRepresentation of an inputPickupable.133 orxonox::PickupRepresentation* getPickupRepresentation(uint32_t pickup); //!< Get the PickupRepresentation of an input indentifier for Pickupable. 92 134 93 int getNumPickups(void); //!< Update the list of picked up Pickupables and get the number of Pickupables in the list.135 int getNumPickups(void); //!< Get the number of pickups currently picked up by the player. 94 136 /** 95 @brief Get the next Pickup ablein the list.96 Use this, after having called getNumPickups() to access all the Pickup ables individually and in succession.97 @return Returns the next Pickup ablein the list.137 @brief Get the next PickupInventoryContainer in the list. 138 Use this, after having called getNumPickups() to access all the PickupInventoryContainers individually and in succession. 139 @return Returns the next PickupInventoryContainer in the list. 98 140 */ 99 orxonox::PickupInventoryContainer* popPickup(void) { return (this->pickupsIterator_++)->second; } 141 orxonox::PickupInventoryContainer* popPickup(void) 142 { return (this->pickupsIterator_++)->second; } 100 143 101 void dropPickup(uint64_t pickup); //!< Drop the input Pickupable. 102 void usePickup(uint64_t pickup, bool use); //!< Use (or unuse) the input Pickupable. 103 bool isValidPickup(uint64_t pickup); //!< Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists. 144 void dropPickup(uint32_t pickup); //!< Drop the input Pickupable. 145 void usePickup(uint32_t pickup, bool use); //!< Use (or unuse) the input Pickupable. 146 /** 147 @brief Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists. 148 @param pickup The Pickupable. 149 @return Returns true if the input Pickupable is still valid, false if not. 150 */ 151 bool isValidPickup(uint32_t pickup) 152 { return this->pickups_.find(pickup) != this->pickups_.end(); } 104 153 // tolua_end 105 154 106 static void dropPickupNetworked(uint64_t pickup); 107 static void usePickupNetworked(uint64_t pickup, bool use); 108 109 virtual void pickupChangedUsed(Pickupable* pickup, bool used); 110 static void pickupChangedUsedNetwork(uint64_t pickup, bool inUse, bool usable, bool unusable); 111 virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp); 112 static void pickupChangedPickedUpNetwork(uint64_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp); 155 static void dropPickupNetworked(uint32_t pickup); //!< Helper method to drop the input pickup on the server. 156 static void usePickupNetworked(uint32_t pickup, bool use); //!< Helper method to use (or unuse) the input Pickupable on the server. 113 157 114 158 private: 115 159 static PickupManager* singletonPtr_s; 116 160 static const std::string guiName_s; //!< The name of the PickupInventory 117 bool guiLoaded_; 118 uint 64_t pickupIndex_;161 bool guiLoaded_; //!< Whether the PickupInventory GUI has been loaded, yet. 162 uint32_t pickupHighestIndex_; //!< The highest pickup index currently in use. (not taking wrap-around into account) 119 163 120 164 PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation. 121 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.122 std::map<uint32_t, PickupRepresentation*> representationsNetworked_;123 165 124 std::map< uint64_t, PickupInventoryContainer*> pickupInventoryContainers_;125 std::map<uint 64_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_.166 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking @ref oroxnox::PickupIdentifier "PickupIdentifiers" (representing types of @ref orxonox::Pickupable "Pickupables") and @ref orxonox::PickupRepresentation "PickupRepresentations". 167 std::map<uint32_t, PickupRepresentation*> representationsNetworked_; //!< Map linking the @ref orxonox::PickupRepresentation "PickupRepresentation's" objectId to the @ref orxonox::PickupRepresentation "PickupRepresentation" itself. It is used for networking purposes. 126 168 127 std::map<uint 64_t, WeakPtr<Pickupable>*> pickups_;128 std::map< Pickupable*, uint64_t> indexes_;169 std::map<uint32_t, PickupInventoryContainer*> pickupInventoryContainers_; //!< Map linking a number identifying a @ref orxonox::Pickupable "Pickupable" to a @ref orxonox::PickupInventoryContainer "PickupInventoryContainer", which contains all necessary information about that @ref orxonox::Pickupable "Pickupable". 170 std::map<uint32_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_. 129 171 130 void updateGUI(void); 131 uint64_t getPickupIndex(void); 172 std::map<uint32_t, WeakPtr<Pickupable>*> pickups_; //!< Map linking a number identifying a @ref orxonox::Pickupable "Pickupable" to a weak pointer of a @ref orxonox::Pickupable "Pickupable". 173 std::map<Pickupable*, uint32_t> indexes_;//!< Map linking @ref orxonox::Pickupable "Pickupable" to the number identifying it. 174 175 void updateGUI(void); //!< Updates the PickupInventory GUI. 176 uint32_t getPickupIndex(void); //!< Get a new index for a Pickupable. 132 177 133 178 }; // tolua_export -
code/trunk/src/modules/pickup/PickupRepresentation.cc
r7504 r7533 83 83 if(this->isInitialized()) 84 84 { 85 //TODO: Also (network) unregister for master. 85 86 if(GameMode::isMaster() && this->pickup_ != NULL) 86 87 { -
code/trunk/src/modules/pickup/items/MetaPickup.cc
r7163 r7533 125 125 if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier) 126 126 { 127 this->Pickupable::destroy(); //TODO: Needed? 127 128 Pawn* pawn = orxonox_cast<Pawn*>(carrier); 128 129 pawn->kill(); -
code/trunk/src/modules/pickup/items/MetaPickup.h
r7493 r7533 108 108 static const std::string metaTypeDestroyCarrier_s; 109 109 110 111 110 }; 112 111 -
code/trunk/src/orxonox/controllers/HumanController.cc
r7284 r7533 56 56 SetConsoleCommand("HumanController", "addBots", &HumanController::addBots ).addShortcut().defaultValues(1); 57 57 SetConsoleCommand("HumanController", "killBots", &HumanController::killBots ).addShortcut().defaultValues(0); 58 SetConsoleCommand("HumanController", "dropItems", &HumanController::dropItems ).addShortcut();59 SetConsoleCommand("HumanController", "useItem", &HumanController::useItem ).addShortcut();60 58 SetConsoleCommand("HumanController", "cycleNavigationFocus", &HumanController::cycleNavigationFocus).addShortcut(); 61 59 SetConsoleCommand("HumanController", "releaseNavigationFocus", &HumanController::releaseNavigationFocus).addShortcut(); … … 202 200 } 203 201 204 void HumanController::useItem()205 {206 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)207 HumanController::localController_s->controllableEntity_->useItem();208 }209 210 202 void HumanController::addBots(unsigned int amount) 211 203 { … … 218 210 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) 219 211 HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount); 220 }221 222 void HumanController::dropItems()223 {224 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)225 HumanController::localController_s->controllableEntity_->dropItems();226 212 } 227 213 -
code/trunk/src/orxonox/controllers/HumanController.h
r6417 r7533 68 68 static void switchCamera(); 69 69 static void mouseLook(); 70 static void dropItems();71 static void useItem();72 70 static void cycleNavigationFocus(); 73 71 static void releaseNavigationFocus(); -
code/trunk/src/orxonox/worldentities/ControllableEntity.cc
r7502 r7533 281 281 282 282 this->player_ = player; 283 this->formerPlayer_ = player; 283 284 this->playerID_ = player->getObjectID(); 284 285 this->bHasLocalController_ = player->isLocalPlayer(); -
code/trunk/src/orxonox/worldentities/ControllableEntity.h
r7163 r7533 55 55 inline PlayerInfo* getPlayer() const 56 56 { return this->player_; } 57 /** 58 @brief Get the player even after the ControllableEntity has stopped being the players ControllableEntity. 59 @return Returns the most recent PlayerInfo. 60 */ 61 inline PlayerInfo* getFormerPlayer() const 62 { return this->formerPlayer_; } 57 63 58 64 inline void setDestroyWhenPlayerLeft(bool bDestroy) … … 89 95 virtual void boost() {} 90 96 virtual void greet() {} 91 virtual void useItem() {}92 virtual void dropItems() {}93 97 virtual void switchCamera(); 94 98 virtual void mouseLook(); … … 204 208 205 209 PlayerInfo* player_; 210 PlayerInfo* formerPlayer_; 206 211 unsigned int playerID_; 207 212 -
code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
r7163 r7533 248 248 this->setDestroyWhenPlayerLeft(false); 249 249 250 this->dropItems();251 252 250 if (this->getGametype()) 253 251 this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
Note: See TracChangeset
for help on using the changeset viewer.