| 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * > www.orxonox.net < |
|---|
| 4 | * |
|---|
| 5 | * |
|---|
| 6 | * License notice: |
|---|
| 7 | * |
|---|
| 8 | * This program is free software; you can redistribute it and/or |
|---|
| 9 | * modify it under the terms of the GNU General Public License |
|---|
| 10 | * as published by the Free Software Foundation; either version 2 |
|---|
| 11 | * of the License, or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, |
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | * GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU General Public License |
|---|
| 19 | * along with this program; if not, write to the Free Software |
|---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 21 | * |
|---|
| 22 | * Author: |
|---|
| 23 | * Damian 'Mozork' Frick |
|---|
| 24 | * Co-authors: |
|---|
| 25 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | @file PickupManager.h |
|---|
| 31 | @brief Definition of the PickupManager class. |
|---|
| 32 | @ingroup Pickup |
|---|
| 33 | */ |
|---|
| 34 | |
|---|
| 35 | #ifndef _PickupManager_H__ |
|---|
| 36 | #define _PickupManager_H__ |
|---|
| 37 | |
|---|
| 38 | #include "PickupPrereqs.h" |
|---|
| 39 | |
|---|
| 40 | #include <map> |
|---|
| 41 | |
|---|
| 42 | #include "core/WeakPtr.h" |
|---|
| 43 | |
|---|
| 44 | #include "pickup/PickupIdentifier.h" |
|---|
| 45 | |
|---|
| 46 | #include "PickupRepresentation.h" |
|---|
| 47 | |
|---|
| 48 | #include "util/Singleton.h" |
|---|
| 49 | #include "interfaces/PickupListener.h" |
|---|
| 50 | |
|---|
| 51 | namespace orxonox // tolua_export |
|---|
| 52 | { // tolua_export |
|---|
| 53 | |
|---|
| 54 | // tolua_begin |
|---|
| 55 | struct PickupInventoryContainer |
|---|
| 56 | { |
|---|
| 57 | uint64_t pickup; |
|---|
| 58 | bool inUse; |
|---|
| 59 | bool pickedUp; |
|---|
| 60 | bool usable; |
|---|
| 61 | bool unusable; |
|---|
| 62 | uint32_t representationObjectId; |
|---|
| 63 | }; |
|---|
| 64 | // tolua_end |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | @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. |
|---|
| 70 | @author |
|---|
| 71 | Damian 'Mozork' Frick |
|---|
| 72 | */ |
|---|
| 73 | class _PickupExport PickupManager // tolua_export |
|---|
| 74 | : public Singleton<PickupManager>, public PickupListener |
|---|
| 75 | { // tolua_export |
|---|
| 76 | friend class Singleton<PickupManager>; |
|---|
| 77 | |
|---|
| 78 | public: |
|---|
| 79 | PickupManager(); |
|---|
| 80 | virtual ~PickupManager(); |
|---|
| 81 | |
|---|
| 82 | static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export |
|---|
| 83 | |
|---|
| 84 | 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 | 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); |
|---|
| 88 | PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier. |
|---|
| 89 | |
|---|
| 90 | // tolua_begin |
|---|
| 91 | orxonox::PickupRepresentation* getPickupRepresentation(uint64_t pickup); //!< Get the PickupRepresentation of an input Pickupable. |
|---|
| 92 | |
|---|
| 93 | int getNumPickups(void); //!< Update the list of picked up Pickupables and get the number of Pickupables in the list. |
|---|
| 94 | /** |
|---|
| 95 | @brief Get the next Pickupable in the list. |
|---|
| 96 | Use this, after having called getNumPickups() to access all the Pickupables individually and in succession. |
|---|
| 97 | @return Returns the next Pickupable in the list. |
|---|
| 98 | */ |
|---|
| 99 | orxonox::PickupInventoryContainer* popPickup(void) { return (this->pickupsIterator_++)->second; } |
|---|
| 100 | |
|---|
| 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. |
|---|
| 104 | // tolua_end |
|---|
| 105 | |
|---|
| 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); |
|---|
| 113 | |
|---|
| 114 | private: |
|---|
| 115 | static PickupManager* singletonPtr_s; |
|---|
| 116 | static const std::string guiName_s; //!< The name of the PickupInventory |
|---|
| 117 | bool guiLoaded_; |
|---|
| 118 | uint64_t pickupIndex_; |
|---|
| 119 | |
|---|
| 120 | 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 | |
|---|
| 124 | std::map<uint64_t, PickupInventoryContainer*> pickupInventoryContainers_; |
|---|
| 125 | std::map<uint64_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_. |
|---|
| 126 | |
|---|
| 127 | std::map<uint64_t, WeakPtr<Pickupable>*> pickups_; |
|---|
| 128 | std::map<Pickupable*, uint64_t> indexes_; |
|---|
| 129 | |
|---|
| 130 | void updateGUI(void); |
|---|
| 131 | uint64_t getPickupIndex(void); |
|---|
| 132 | |
|---|
| 133 | }; // tolua_export |
|---|
| 134 | |
|---|
| 135 | } // tolua_export |
|---|
| 136 | |
|---|
| 137 | #endif // _PickupManager_H__ |
|---|