[6474] | 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 | /** |
---|
[6540] | 30 | @file PickupManager.h |
---|
[6474] | 31 | @brief Definition of the PickupManager class. |
---|
[7456] | 32 | @ingroup Pickup |
---|
[6474] | 33 | */ |
---|
| 34 | |
---|
| 35 | #ifndef _PickupManager_H__ |
---|
| 36 | #define _PickupManager_H__ |
---|
| 37 | |
---|
| 38 | #include "PickupPrereqs.h" |
---|
| 39 | |
---|
| 40 | #include <map> |
---|
[7504] | 41 | |
---|
[7163] | 42 | #include "core/WeakPtr.h" |
---|
[7504] | 43 | |
---|
[6474] | 44 | #include "pickup/PickupIdentifier.h" |
---|
[7504] | 45 | |
---|
[6474] | 46 | #include "PickupRepresentation.h" |
---|
| 47 | |
---|
[7504] | 48 | #include "util/Singleton.h" |
---|
| 49 | #include "interfaces/PickupListener.h" |
---|
[6474] | 50 | |
---|
[6711] | 51 | namespace orxonox // tolua_export |
---|
| 52 | { // tolua_export |
---|
[6474] | 53 | |
---|
[7504] | 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 | |
---|
[6474] | 66 | /** |
---|
| 67 | @brief |
---|
| 68 | Manages Pickupables. |
---|
[6711] | 69 | In essence has two tasks to fulfill. Firstly it must link Pickupables (through their PickupIdentifiers) and their PickupRepresentations. Secondly it manages the PickupInventory. |
---|
[6474] | 70 | @author |
---|
| 71 | Damian 'Mozork' Frick |
---|
| 72 | */ |
---|
[6711] | 73 | class _PickupExport PickupManager // tolua_export |
---|
[7504] | 74 | : public Singleton<PickupManager>, public PickupListener |
---|
[6711] | 75 | { // tolua_export |
---|
[6474] | 76 | friend class Singleton<PickupManager>; |
---|
[7163] | 77 | |
---|
[6474] | 78 | public: |
---|
| 79 | PickupManager(); |
---|
| 80 | virtual ~PickupManager(); |
---|
[7163] | 81 | |
---|
[6711] | 82 | static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export |
---|
[7163] | 83 | |
---|
[6475] | 84 | bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. |
---|
[7504] | 85 | bool registerRepresentation(PickupRepresentation* representation); |
---|
[6725] | 86 | bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. |
---|
[7504] | 87 | bool unregisterRepresentation(PickupRepresentation* representation); |
---|
[6474] | 88 | PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier. |
---|
[7163] | 89 | |
---|
[6711] | 90 | // tolua_begin |
---|
[7504] | 91 | orxonox::PickupRepresentation* getPickupRepresentation(uint64_t pickup); //!< Get the PickupRepresentation of an input Pickupable. |
---|
[7206] | 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 | */ |
---|
[7504] | 99 | orxonox::PickupInventoryContainer* popPickup(void) { return (this->pickupsIterator_++)->second; } |
---|
[7163] | 100 | |
---|
[7504] | 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. |
---|
[6711] | 104 | // tolua_end |
---|
[7163] | 105 | |
---|
[7504] | 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 | |
---|
[6474] | 114 | private: |
---|
| 115 | static PickupManager* singletonPtr_s; |
---|
[7206] | 116 | static const std::string guiName_s; //!< The name of the PickupInventory |
---|
[7504] | 117 | bool guiLoaded_; |
---|
| 118 | uint64_t pickupIndex_; |
---|
[7163] | 119 | |
---|
[6474] | 120 | PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation. |
---|
[6475] | 121 | std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations. |
---|
[7504] | 122 | std::map<uint32_t, PickupRepresentation*> representationsNetworked_; |
---|
[7163] | 123 | |
---|
[7504] | 124 | std::map<uint64_t, PickupInventoryContainer*> pickupInventoryContainers_; |
---|
| 125 | std::map<uint64_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_. |
---|
[7163] | 126 | |
---|
[7504] | 127 | std::map<uint64_t, WeakPtr<Pickupable>*> pickups_; |
---|
| 128 | std::map<Pickupable*, uint64_t> indexes_; |
---|
[7163] | 129 | |
---|
[7504] | 130 | void updateGUI(void); |
---|
| 131 | uint64_t getPickupIndex(void); |
---|
| 132 | |
---|
[6711] | 133 | }; // tolua_export |
---|
[7163] | 134 | |
---|
[6711] | 135 | } // tolua_export |
---|
[6474] | 136 | |
---|
| 137 | #endif // _PickupManager_H__ |
---|