Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6711 for code/trunk/src


Ignore:
Timestamp:
Apr 13, 2010, 10:16:10 AM (15 years ago)
Author:
dafrick
Message:

Merged pickup4 branch back to trunk.

Location:
code/trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pickup/CMakeLists.txt

    r6524 r6711  
    1515  FIND_HEADER_FILES
    1616  TOLUA_FILES
     17    PickupManager.h
     18    PickupRepresentation.h
    1719  DEFINE_SYMBOL
    1820    "PICKUP_SHARED_BUILD"
  • code/trunk/src/modules/pickup/PickupManager.cc

    r6540 r6711  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "core/LuaState.h"
     38#include "core/GUIManager.h"
    3739#include "core/ScopedSingletonManager.h"
    3840#include "core/Identifier.h"
    3941#include "interfaces/PickupCarrier.h"
     42#include "infos/PlayerInfo.h"
    4043#include "worldentities/pawns/Pawn.h"
    4144#include "PickupRepresentation.h"
    4245
     46#include "ToluaBindPickup.h"
     47
    4348namespace orxonox
    4449{
    45 
     50    // Register tolua_open function when loading the library
     51    DeclareToluaInterface(Pickup);
     52   
    4653    ManageScopedSingleton(PickupManager, ScopeID::Root, false);
     54   
     55    /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
    4756   
    4857    /**
     
    110119    }
    111120   
     121    PickupCarrier* PickupManager::getPawn(void)
     122    {
     123        Pawn* pawn = dynamic_cast<Pawn*>(GUIManager::getInstancePtr()->getPlayer(PickupManager::guiName_s)->getControllableEntity());
     124        if(pawn == NULL)
     125            return NULL;
     126        return dynamic_cast<PickupCarrier*>(pawn);
     127    }
     128   
     129    int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
     130    {
     131        if(carrier == NULL)
     132            return 0;
     133        return carrier->getNumCarrierChildren();
     134    }
     135           
     136    PickupCarrier* PickupManager::getCarrierChild(int index, PickupCarrier* carrier)
     137    {
     138        if(carrier == NULL)
     139            return NULL;
     140        return carrier->getCarrierChild(index);
     141    }
     142   
     143    const std::string& PickupManager::getCarrierName(orxonox::PickupCarrier* carrier)
     144    {
     145        if(carrier == NULL)
     146            return BLANKSTRING;
     147        return carrier->getCarrierName();
     148    }
     149   
     150    PickupRepresentation* PickupManager::getPickupRepresentation(int index, PickupCarrier* carrier)
     151    {
     152        Pickupable* pickup = carrier->getPickup(index);
     153        if(pickup == NULL)
     154            return NULL;
     155       
     156        return this->getRepresentation(pickup->getPickupIdentifier());
     157    }
     158   
     159    int PickupManager::getNumPickups(PickupCarrier* carrier)
     160    {
     161        if(carrier == NULL)
     162            return 0;
     163        return carrier->getNumPickups();
     164    }
     165   
     166    void PickupManager::dropPickup(int index, PickupCarrier* carrier)
     167    {
     168        Pickupable* pickup = carrier->getPickup(index);
     169        carrier->drop(pickup);
     170    }
     171   
     172    void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use)
     173    {
     174        Pickupable* pickup = carrier->getPickup(index);
     175        pickup->setUsed(use);
     176    }
     177   
    112178}
  • code/trunk/src/modules/pickup/PickupManager.h

    r6540 r6711  
    4444#include "core/OrxonoxClass.h"
    4545
    46 namespace orxonox
    47 {
     46namespace orxonox // tolua_export
     47{ // tolua_export
    4848
    4949    /**
    5050    @brief
    5151        Manages Pickupables.
    52         In essence has two tasks to fulfill. Firstly it must link Pickupables (through their PickupIdentifiers) and their PickupRepresentations. Secondly it manages the Pickup GUI.
     52        In essence has two tasks to fulfill. Firstly it must link Pickupables (through their PickupIdentifiers) and their PickupRepresentations. Secondly it manages the PickupInventory.
    5353        //TODO: Manage Pickup GUI.
    5454    @author
    5555        Damian 'Mozork' Frick
    5656    */
    57     class _PickupExport PickupManager : public Singleton<PickupManager>, public OrxonoxClass
    58     {
     57    class _PickupExport PickupManager // tolua_export
     58        : public Singleton<PickupManager>, public OrxonoxClass
     59    { // tolua_export
    5960        friend class Singleton<PickupManager>;
    6061       
     
    6364            virtual ~PickupManager();
    6465           
    65             static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); }
     66            static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export
    6667           
    6768            bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    6869            PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    6970           
     71            // tolua_begin
     72            orxonox::PickupCarrier* getPawn(void);
     73           
     74            int getNumCarrierChildren(orxonox::PickupCarrier* carrier);
     75            orxonox::PickupCarrier* getCarrierChild(int index, orxonox::PickupCarrier* carrier);
     76           
     77            const std::string& getCarrierName(orxonox::PickupCarrier* carrier);
     78           
     79            int getNumPickups(orxonox::PickupCarrier* carrier);
     80            PickupRepresentation* getPickupRepresentation(int index, orxonox::PickupCarrier* carrier);
     81            void dropPickup(int index, orxonox::PickupCarrier* carrier);
     82            void usePickup(int index, orxonox::PickupCarrier* carrier, bool use);
     83            // tolua_end
     84           
    7085        private:
    7186            static PickupManager* singletonPtr_s;
     87            static const std::string guiName_s;
    7288           
    7389            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    7490            std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
    7591       
    76     };
     92    }; // tolua_export
    7793   
    78 }
     94} // tolua_export
    7995
    8096#endif // _PickupManager_H__
  • code/trunk/src/modules/pickup/PickupPrereqs.h

    r6710 r6711  
    6565namespace orxonox
    6666{
    67 
     67   
    6868    class DroppedPickup;
    6969    class Pickup;
  • code/trunk/src/modules/pickup/PickupRepresentation.cc

    r6676 r6711  
    8686        this->name_ = "Pickup";
    8787        this->spawnerTemplate_ = "";
     88        this->inventoryRepresentation_ = "Default";
    8889        this->pickup_ = NULL;
    8990    }
     
    9798        SUPER(PickupRepresentation, XMLPort, xmlelement, mode);
    9899       
    99         XMLPortParam(PickupRepresentation, "name", setName, getName, xmlelement, mode);
    100         XMLPortParam(PickupRepresentation, "description", setDescription, getDescription, xmlelement, mode);
     100        XMLPortParam(PickupRepresentation, "pickupName", setPickupName, getPickupName, xmlelement, mode);
     101        XMLPortParam(PickupRepresentation, "pickupDescription", setPickupDescription, getPickupDescription, xmlelement, mode);
    101102        XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
     103        XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode);
    102104        XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
    103105        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
  • code/trunk/src/modules/pickup/PickupRepresentation.h

    r6540 r6711  
    4545#include "core/BaseObject.h"
    4646
    47 namespace orxonox
    48 {
     47namespace orxonox // tolua_export
     48{ // tolua_export
    4949
    5050    /**
     
    5353        They are created through XML and are registered with the PickupManager.
    5454    */
    55     class _PickupExport PickupRepresentation : public BaseObject
    56     {
     55    class _PickupExport PickupRepresentation // tolua_export
     56        : public BaseObject
     57    { // tolua_export
    5758       
    5859        public:
     
    6768            @param name The name.
    6869            */
    69             inline void setName(const std::string& name)
     70            inline void setPickupName(const std::string& name)
    7071                { this->name_ = name; }
    7172            /**
     
    7374            @param description The Description.
    7475            */
    75             inline void setDescription(const std::string& description)
     76            inline void setPickupDescription(const std::string& description)
    7677                { this->description_ = description; }
    7778            /**
     
    9091                { this->spawnerRepresentation_ = representation; }
    9192            /**
     93            @brief Set the image representing the pickup in the PickupInventory.
     94            @param image A string with the name of the image representing the pickup.
     95            */
     96            inline void setInventoryRepresentation(const std::string& image)
     97                { this->inventoryRepresentation_ = image; }
     98            /**
    9299            @brief Set the Pickupable that is represented by this PickupRepresentation.
    93100            @param pickup A pointer to the Pickupable.
     
    100107            @return Returns the name.
    101108            */
    102             inline const std::string& getName(void)
    103                 { return this->name_; }
     109            inline const std::string& getPickupName(void) { return this->name_; } // tolua_export
    104110            /**
    105111            @brief Get the description of the Pickupable represented by this PickupRepresentation.
    106112            @return Returns the description.
    107113            */
    108             inline const std::string& getDescription(void)
    109                 { return this->description_; }
     114            inline const std::string& getPickupDescription(void) { return this->description_; } // tolua_export
    110115            /**
    111116            @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation.
     
    121126            inline const StaticEntity* getSpawnerRepresentationIndex(unsigned int index)
    122127                { if(index == 0) return this->spawnerRepresentation_; return NULL; }
     128            /**
     129            @brief Get the name of the image representing the pickup in the PickupInventory.
     130            @return Returns the name of the image as a string.
     131            */
     132            inline const std::string& getInventoryRepresentation(void) { return this->inventoryRepresentation_; } // tolua_export
    123133            /**
    124134            @brief Get the Pickupable represented by this PickupRepresentation.
     
    139149            std::string spawnerTemplate_; //!<  The name of the template of this PickupRepresentation.
    140150            StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation.
     151            std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. TODO: Exact format and placement of image?
    141152           
    142153            Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
    143154           
    144     };
     155    }; // tolua_export
    145156
    146 }
     157} // tolua_export
    147158   
    148159#endif // _PickupRepresentation_H__
  • code/trunk/src/modules/pickup/PickupSpawner.cc

    r6563 r6711  
    180180            {
    181181                Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
     182                PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(*it);
    182183                //! If a Pawn, that fits the target-range of the item spawned by this Pickup, is in trigger-distance.
    183                 if (distance.length() < this->triggerDistance_ && this->pickup_->isTarget(*it))
     184                if (distance.length() < this->triggerDistance_ && carrier != NULL && carrier->isTarget(this->pickup_))
    184185                {
    185186                    this->trigger(*it);
  • code/trunk/src/orxonox/CMakeLists.txt

    r6524 r6711  
    5858    MoodManager.h
    5959    controllers/HumanController.h
     60    interfaces/PickupCarrier.h
    6061    sound/SoundManager.h
    6162  DEFINE_SYMBOL
  • code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc

    r6534 r6711  
    6060        RegisterRootObject(PickupCarrier);
    6161       
     62        this->setCarrierName("PickupCarrier");
    6263    }
    6364   
  • code/trunk/src/orxonox/interfaces/PickupCarrier.h

    r6710 r6711  
    4545#include "core/OrxonoxClass.h"
    4646
    47 namespace orxonox
    48 {
     47namespace orxonox // tolua_export
     48{ // tolua_export
    4949
    5050    //! Forward-declarations.
     51    class PickupManager;
    5152    class Pickup;
    5253    class HealthPickup;
     
    6162        Damian 'Mozork' Frick
    6263    */
    63     class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
    64     {
     64    class _OrxonoxExport PickupCarrier  // tolua_export
     65        : virtual public OrxonoxClass
     66    { // tolua_export
    6567        //! So that the different Pickupables have full access to their PickupCarrier.
     68        friend class Pickupable;
     69        friend class PickupManager;
    6670        //! Friends.
    67         friend class Pickupable;
    6871        friend class Pickup;
    6972        friend class HealthPickup;
     
    120123
    121124                    //! Go recursively through all children to check whether they are a target.
    122                     std::list<PickupCarrier*>* children = this->getCarrierChildren();
    123                     for(std::list<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
     125                    std::vector<PickupCarrier*>* children = this->getCarrierChildren();
     126                    for(std::vector<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
    124127                    {
    125128                        if((*it)->isTarget(pickup))
     
    147150
    148151                    //! Go recursively through all children to check whether they are the target.
    149                     std::list<PickupCarrier*>* children = this->getCarrierChildren();
    150                     for(std::list<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
     152                    std::vector<PickupCarrier*>* children = this->getCarrierChildren();
     153                    for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
    151154                    {
    152155                        if(pickup->isTarget(*it))
     
    166169            */
    167170            virtual const Vector3& getCarrierPosition(void) = 0;
    168 
    169         protected:
     171           
     172            /**
     173            @brief Get the name of this PickupCarrier.
     174            @return Returns the name as a string.
     175            */
     176            const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export
     177           
     178        protected:       
    170179            /**
    171180            @brief Get all direct children of this PickupSpawner.
     
    174183            @return Returns a pointer to a list of all direct children.
    175184            */
    176             virtual std::list<PickupCarrier*>* getCarrierChildren(void) = 0;
     185            virtual std::vector<PickupCarrier*>* getCarrierChildren(void) = 0;
    177186            /**
    178187            @brief Get the parent of this PickupSpawner
     
    188197            std::set<Pickupable*>& getPickups(void)
    189198                { return this->pickups_; }
    190 
     199               
     200            /**
     201            @brief Set the name of this PickupCarrier.
     202                   The name needs to be set in the constructor of every class inheriting from PickupCarrier, by calling setCarrierName().
     203            @param name The name to be set.
     204            */
     205            void setCarrierName(const std::string& name)
     206                { this->carrierName_ = name; }
     207       
    191208        private:
    192209            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    193 
    194     };
    195 }
     210            std::string carrierName_; //!< The name of the PickupCarrier, as displayed in the PickupInventory.
     211           
     212            /**
     213            @brief Get the number of carrier children this PickupCarrier has.
     214            @return Returns the number of carrier children.
     215            */
     216            unsigned int getNumCarrierChildren(void)
     217                {
     218                    std::vector<PickupCarrier*>* list = this->getCarrierChildren();
     219                    unsigned int size = list->size();
     220                    delete list;
     221                    return size;
     222                }
     223           
     224            /**
     225            @brief Get the index-th child of this PickupCarrier.
     226            @param index The index of the child to return.
     227            @return Returns the index-th child.
     228            */
     229            PickupCarrier* getCarrierChild(unsigned int index)
     230                {
     231                    std::vector<PickupCarrier*>* list = this->getCarrierChildren();
     232                    if(list->size() < index)
     233                        return NULL;
     234                    PickupCarrier* carrier = (*list)[index];
     235                    delete list;
     236                    return carrier;
     237                }
     238           
     239            /**
     240            @brief Get the number of Pickupables this PickupCarrier carries.
     241            @return returns the number of pickups.
     242            */
     243            unsigned int getNumPickups(void)
     244                { return this->pickups_.size(); }
     245           
     246            /**
     247            @brief Get the index-th Pickupable of this PickupCarrier.
     248            @param index The index of the Pickupable to return.
     249            @return Returns the index-th pickup.
     250            */
     251            Pickupable* getPickup(unsigned int index)
     252                {
     253                    std::set<Pickupable*>::iterator it;
     254                    for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++)
     255                        index--;
     256                    if(it == this->pickups_.end())
     257                        return NULL;
     258                    return *it;
     259                }
     260           
     261    }; // tolua_export
     262} // tolua_export
    196263
    197264#endif /* _PickupCarrier_H__ */
  • code/trunk/src/orxonox/items/Engine.cc

    r6709 r6711  
    6464        this->boostBlur_ = 0;
    6565
     66        this->setCarrierName("Engine");
    6667        this->speedAdd_ = 0.0;
    6768        this->speedMultiply_ = 1.0;
  • code/trunk/src/orxonox/items/Engine.h

    r6709 r6711  
    122122
    123123        protected:
    124             virtual std::list<PickupCarrier*>* getCarrierChildren(void)
    125                 { return new std::list<PickupCarrier*>(); }
     124            virtual std::vector<PickupCarrier*>* getCarrierChildren(void)
     125                { return new std::vector<PickupCarrier*>(); }
    126126            virtual PickupCarrier* getCarrierParent(void);
    127127
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc

    r6502 r6711  
    327327        {
    328328            OrxonoxOverlay* overlay= it->second;
     329            COUT(1) << "MUP" << std::endl;
    329330            if(overlay->isVisible())
     331            {
    330332                overlay->hide();
     333                COUT(1) << "HIDE " << name << std::endl;
     334            }
    331335            else
     336            {
    332337                overlay->show();
     338                COUT(1) << "SHOW " << name << std::endl;
     339            }
    333340        }
    334341    }
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r6540 r6711  
    7878        else
    7979            this->weaponSystem_ = 0;
     80       
     81        this->setCarrierName("Pawn");
    8082
    8183        this->setRadarObjectColour(ColourValue::Red);
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r6540 r6711  
    3737#include "worldentities/ControllableEntity.h"
    3838
    39 namespace orxonox
    40 {
    41     class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable, public PickupCarrier
    42     {
     39namespace orxonox // tolua_export
     40{ // tolua_export
     41    class _OrxonoxExport Pawn // tolua_export
     42        : public ControllableEntity, public RadarViewable, public PickupCarrier
     43    { // tolua_export
    4344        friend class WeaponSystem;
    4445
     
    132133            bool bAlive_;
    133134
    134             virtual std::list<PickupCarrier*>* getCarrierChildren(void)
    135                 { return new std::list<PickupCarrier*>(); }
     135            virtual std::vector<PickupCarrier*>* getCarrierChildren(void)
     136                { return new std::vector<PickupCarrier*>(); }
    136137            virtual PickupCarrier* getCarrierParent(void)
    137138                { return NULL; }
     
    155156
    156157            Vector3 aimPosition_;
    157     };
    158 }
     158    }; // tolua_export
     159} // tolua_export
    159160
    160161#endif /* _Pawn_H__ */
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc

    r6709 r6711  
    221221    }
    222222
    223     std::list<PickupCarrier*>* SpaceShip::getCarrierChildren(void)
    224     {
    225         std::list<PickupCarrier*>* list = new std::list<PickupCarrier*>();
    226         list->push_front(this->engine_);
     223    std::vector<PickupCarrier*>* SpaceShip::getCarrierChildren(void)
     224    {
     225        std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>();
     226        list->push_back(this->engine_);
    227227        return list;
    228228    }
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h

    r6709 r6711  
    8686
    8787        protected:
    88             virtual std::list<PickupCarrier*>* getCarrierChildren(void);
     88            virtual std::vector<PickupCarrier*>* getCarrierChildren(void);
    8989            bool bInvertYAxis_;
    9090
Note: See TracChangeset for help on using the changeset viewer.