Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 26, 2009, 10:06:54 AM (15 years ago)
Author:
dafrick
Message:

Some Documenting and bug fixes.

Location:
code/branches/pickup3/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup3/src/modules/pickup/DroppedItem.cc

    r6419 r6421  
    2929#include "DroppedItem.h"
    3030
    31 #include "util/Math.h"
    3231#include "core/CoreIncludes.h"
    33 #include "core/Executor.h"
    34 #include "BaseItem.h"
    35 #include "graphics/Billboard.h"
     32#include "interfaces/Pickupable.h"
    3633#include "graphics/Model.h"
    37 #include "worldentities/pawns/Pawn.h"
    3834
    3935namespace orxonox
    4036{
    41     CreateFactory(DroppedItem); //TODO: This isn't needed, is it?
    42 
    4337    /**
    4438    @brief
     
    4741    DroppedItem::DroppedItem(BaseObject* creator) : PickupSpawner(creator)
    4842    {
    49         RegisterObject(DroppedItem);
     43        this->initialize();
    5044    }
    5145
    52     DroppedItem::DroppedItem(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems) : PickupSpawner(creator, item, triggerDistance, respawnTime, maxSpawnedItems)
     46    DroppedItem::DroppedItem(BaseObject* creator, Pickupable* item, const Vector3& position, float triggerDistance) : PickupSpawner(creator, item, triggerDistance, 0, 1)
     47    {   
     48        this->initialize();
     49       
     50        this->createDrop(position);
     51    }
     52   
     53    void DroppedItem::initialize(void)
    5354    {
    5455        RegisterObject(DroppedItem);
    55         this->item_ = item;
     56       
     57        this->gotPickedUp_ = false;
    5658    }
    5759
     
    6264    DroppedItem::~DroppedItem()
    6365    {
    64        
     66        if(this->gotPickedUp_ && this->pickup_ != NULL)
     67        {
     68            this->pickup_ = NULL;
     69        }
    6570    }
    6671
    67     BaseItem* DroppedItem::getItem(void)
     72    Pickupable* DroppedItem::getPickup(void)
    6873    {
    69         return this->item_;
     74        return this->pickup_;
     75    }
     76   
     77    void DroppedItem::createDrop(const Vector3& position)
     78    {
     79        this->setPosition(position);
     80       
     81        //TODO: Make this work.
     82        //const Model& model = PickupManager::getModel(item->getPickupIdentifier());
     83        //this->attach(model);
    7084    }
    7185
    72     /**
    73     @brief
    74        
    75     */
     86//TODO: Remove.
    7687    //TODO: Comment.
    7788    //Each pickup should have a XML template where the Model and Billboard, and so on, is specified.
    78     /*static*/ DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive)
    79     {
    80         //TODO: triggerDistance?
    81         float triggerDistance = 20.0;
    82         DroppedItem* droppedItem = new DroppedItem(item, item, triggerDistance, 0, 1);
    83        
    84         //TODO: Do this somehwere else?
    85         Model* model = new Model(item);
    86         Billboard* billboard = new Billboard(item);
     89//    /*static*/ DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive)
     90//     {
     91//         //TODO: triggerDistance?
     92//         float triggerDistance = 20.0;
     93//         DroppedItem* droppedItem = new DroppedItem(item, item, triggerDistance, 0, 1);
     94//         
     95//         //TODO: Do this somehwere else?
     96//         Model* model = new Model(item);
     97//         Billboard* billboard = new Billboard(item);
     98//
     99//         model->setMeshSource("sphere.mesh");
     100//         model->setScale(3.0f);
     101//
     102//         billboard->setMaterial("Examples/Flare");
     103//         billboard->setColour(flareColour);
     104//         billboard->setScale(0.5f);
     105//
     106//         droppedItem->setPosition(position);
     107//         droppedItem->attach(model);
     108//         droppedItem->attach(billboard);
     109//
     110//         COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl;
     111//
     112//         return droppedItem;
     113//     }
    87114
    88         model->setMeshSource("sphere.mesh");
    89         model->setScale(3.0f);
    90 
    91         billboard->setMaterial("Examples/Flare");
    92         billboard->setColour(flareColour);
    93         billboard->setScale(0.5f);
    94 
    95         droppedItem->setPosition(position);
    96         droppedItem->attach(model);
    97         droppedItem->attach(billboard);
    98 
    99         COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << ',' << position.y << ',' << position.z << ")." << std::endl;
    100 
    101         return droppedItem;
    102     }
    103 
    104     /**
    105     @brief
    106 
    107     */
    108115    //TODO: See one function above.
    109     DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive)
    110     {
    111         Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f);
    112         return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive);
    113     }
     116//     DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive)
     117//     {
     118//         Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f);
     119//         return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive);
     120//     }
    114121}
  • code/branches/pickup3/src/modules/pickup/DroppedItem.h

    r6419 r6421  
    3535#define _DroppedItem_H__
    3636
    37 #include "OrxonoxPrereqs.h"
     37#include "pickup/PickupPrereqs.h"
    3838
    3939#include "PickupSpawner.h"
     
    4545        public:
    4646            DroppedItem(BaseObject* creator);
    47             DroppedItem(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems);
     47            DroppedItem(BaseObject* creator, Pickupable* item, const Vector3& position, float triggerDistance);
    4848            virtual ~DroppedItem();
    4949
    50             static DroppedItem* createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour = ColourValue(0.5f, 1.0f, 0.3f), float timeToLive = 0);
    51             static DroppedItem* createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour = ColourValue(0.5f, 1.0f, 0.3f), float timeToLive = 0);
    52 
    5350        protected:
    54             virtual BaseItem* getItem(void);
    55 
     51            virtual Pickupable* getPickup(void);
     52           
    5653        private:
    57 
    58             BaseItem* item_; //!< The dropped item.
     54            void initialize(void);
     55            void createDrop(const Vector3& position);
     56           
     57            bool gotPickedUp_;
    5958
    6059    };
  • code/branches/pickup3/src/modules/pickup/PickupCollection.cc

    r6420 r6421  
    5858    {
    5959        //! Destroy all Pickupables constructing this PickupCollection.
    60         for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     60        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    6161        {
    6262            delete *it;
     
    8989            return false;
    9090       
    91         this->pickups_.insert(pickup);
     91        this->pickups_.push_back(pickup);
    9292        return true;
    9393    }
     
    101101        Returns a pointer to the Pickupable at the index given by index.
    102102    */
    103     Pickupable* PickupCollection::getPickupable(unsigned int index)
     103    const Pickupable* PickupCollection::getPickupable(unsigned int index)
    104104    {
    105105        return this->pickups_[index]; //TODO. Does this work?
     
    112112       
    113113        //! Change used for all Pickupables this PickupCollection consists of.
    114         for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     114        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    115115        {
    116116            (*it)->changedUsed();
     
    132132        bool success = true;
    133133        //! Set all Pickupables to used.
    134         for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     134        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    135135        {
    136136            if(!(*it)->use())
     
    158158        bool success = true;
    159159        //! Set all Pickupables to unused.
    160         for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     160        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    161161        {
    162162            if(!(*it)->unuse())
     
    187187            return false;
    188188        }
    189         for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     189        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    190190        {
    191191            (*it)->setOwner(carrier);
     
    219219       
    220220        PickupCollection* newCollection = dynamic_cast<PickupCollection*>(newObject);
    221         for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     221        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    222222        {
    223223            Pickupable* newPickup = (*it)->clone();
  • code/branches/pickup3/src/modules/pickup/PickupCollection.h

    r6420 r6421  
    6969           
    7070            bool addPickupable(Pickupable* pickup);
    71             Pickupable* getPickupable(unsigned int index);
     71            const Pickupable* getPickupable(unsigned int index);
    7272           
    7373        private:
    7474           
    75             std::list<Pickupable*> pickups_;
     75            std::vector<Pickupable*> pickups_;
    7676       
    7777    };
  • code/branches/pickup3/src/modules/pickup/PickupPrereqs.h

    r6420 r6421  
    6666{
    6767
     68    class DroppedItem;
    6869    class PickupCollection;
    6970    class PickupSpawner;
  • code/branches/pickup3/src/modules/pickup/PickupSpawner.cc

    r6419 r6421  
    5353    /**
    5454    @brief
    55         Constructor. Registers the PickupSpawner.
     55        Constructor. Creates a blank PickupSpawner.
    5656    @param creator
    5757        Pointer to the object which created this item.
     
    6262    }
    6363
     64    /**
     65    @brief
     66        Constructor, Creates a fully functional PickupSpawner.
     67    @param creator
     68        The creator of this PickupSpawner.
     69    @param pickup
     70        The Pickupable to be spawned by this PickupSpawner.
     71    @param triggerDistance
     72        The distance at which the PickupSpawner will trigger.
     73    @param respawnTime
     74        The minimum time between two spawns.
     75    @param maySpawnedItems
     76        The maximum number of items spawned by this PickupSpawner.
     77    */
    6478    PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator)
    6579    {
     
    7387    }
    7488
     89    /**
     90    @brief
     91        Registers the object and sets some default values.
     92    */
    7593    void PickupSpawner::initialize(void)
    7694    {
     
    92110    PickupSpawner::~PickupSpawner()
    93111    {
    94        
     112        if(this->pickup_ != NULL)
     113            delete this->pickup_;
    95114    }
    96115
     
    107126        SUPER(PickupSpawner, XMLPort, xmlelement, mode);
    108127
    109         XMLPortObject(PickupSpawner, Pickupable, "pickup", addPickupable, getPickupable, xmlelement, mode);
     128        XMLPortObject(PickupSpawner, Pickupable, "pickup", setPickupable, getPickupable, xmlelement, mode);
    110129       
    111130        XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode);
     
    128147        //  & load the GUI itself too, along with some empty windows
    129148        //   = even less delays
    130 //         GUIManager::showGUI("PickupInventory");
    131 //         GUIManager::hideGUI("PickupInventory");
     149//         GUIManager::getInstance().showGUI("PickupInventory");
     150//         GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
    132151//         PickupInventory::getSingleton();
    133152    }
    134153   
    135     void PickupSpawner::addPickupable(Pickupable* pickup)
     154    /**
     155    @brief
     156        Sets a Pickupable for the PickupSpawner to spawn.
     157    @param pickup
     158        The Pickupable to be set.
     159    */
     160    void PickupSpawner::setPickupable(Pickupable* pickup)
    136161    {
    137162        if(this->pickup_ != NULL)
     
    149174    }
    150175   
    151     Pickupable* PickupSpawner::getPickupable(void)
     176    /**
     177    @brief
     178        Get the Pickupable that is spawned by this PickupSpawner.
     179    @return
     180        Returns the Pickupable that is spawned by this PickupSpawner.
     181    */
     182    const Pickupable* PickupSpawner::getPickupable(void)
    152183    {
    153184        return this->pickup_;
     
    166197//     }
    167198
     199    /**
     200    @brief
     201        Sets the maximum number of spawned items.
     202    @param items
     203        The maximum number of spawned items to be set.
     204    */
    168205    void PickupSpawner::setMaxSpawnedItems(int items)
    169206    {
     
    243280    }
    244281   
     282    /**
     283    @brief
     284        Decrements the number of remaining spawns.
     285        Sets the PickupSpawner to inactive for the duration of the respawnTime.
     286        Destroys the PickupSpawner if the number of remaining spawns has reached zero.
     287       
     288    */
    245289    void PickupSpawner::decrementSpawnsRemaining(void)
    246290    {
     
    251295        if(this->spawnsRemaining_ != 0 && this->respawnTime_ > 0)
    252296        {
    253             //TODO: Nicer?
     297            //TODO: Nicer? Does this even work?
    254298            this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
    255299
  • code/branches/pickup3/src/modules/pickup/PickupSpawner.h

    r6419 r6421  
    5757            virtual ~PickupSpawner();
    5858
    59             virtual void changedActivity();                                 //!< Invoked when activity has changed (set visibilty).
     59            //virtual void changedActivity();                                 //!< Invoked when activity has changed (set visibilty).
    6060            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< Method for creating a PickupSpawner through XML.
    6161            virtual void tick(float dt);
     
    8787                { this->respawnTime_ = time; }
    8888
    89 
     89            /**
     90                @brief Get the maximum number of items that will be spawned by this PickupSpawner.
     91                @return Returns the maximum number of items spawned by this PickupSpawner.
     92            */
    9093            inline int getMaxSpawnedItems(void)
    9194                { return this->maxSpawnedItems_; }
     
    9598            virtual Pickupable* getPickup(void);
    9699           
    97             void addPickupable(Pickupable* pickup);
    98             Pickupable* getPickupable(void);
     100            void setPickupable(Pickupable* pickup);
     101            const Pickupable* getPickupable(void);
    99102           
    100103            void decrementSpawnsRemaining(void);
     104           
     105            Pickupable* pickup_; //!< The pickup to be spawned.
    101106
    102107        private:
     
    105110            void trigger(Pawn* pawn);                                       //!< Method called when a Pawn is close enough.
    106111            void respawnTimerCallback();                                    //!< Method called when the timer runs out.
    107 
    108            
    109             Pickupable* pickup_;
    110112
    111113            int maxSpawnedItems_;                   //!< Maximum number of items spawned by this PickupSpawner.
  • code/branches/pickup3/src/modules/weapons/projectiles/Rocket.cc

    r6417 r6421  
    201201
    202202            float dmg = this->damage_;
    203             if (this->owner_)
    204                 dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
     203            //TODO: This souldn't be necessary here.
     204            //if (this->owner_)
     205            //    dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
    205206
    206207            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
  • code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h

    r6419 r6421  
    4848        public:
    4949            PickupCarrier();
    50             virtual ~PickupCarrier();
     50            virtual ~PickupCarrier() {}
    5151       
    5252        private:
Note: See TracChangeset for help on using the changeset viewer.