Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 16, 2010, 2:18:45 PM (14 years ago)
Author:
dafrick
Message:

Resolving some more TODO's.

Location:
code/trunk/src/modules/pickup
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/pickup/DroppedPickup.cc

    r7494 r7549  
    7070
    7171        this->setPosition(carrier->getCarrierPosition());
    72         this->setActive(false);
    73 
    74         //TODO: Do more elegantly.
    75         this->startRespawnTimer();
     72        this->block(carrier, DEFAULT_BLOCKED_TIME);
    7673    }
    7774
  • code/trunk/src/modules/pickup/DroppedPickup.h

    r7533 r7549  
    6464            virtual Pickupable* getPickup(void); //!< Creates the Pickupable that is going to get picked up.
    6565
     66        private:
     67            static const unsigned int DEFAULT_BLOCKED_TIME = 10; //!< The default time a PickupCarrier is blocked from picking up the pickupable again, after it has dropped it.
     68
    6669    };
    6770}
  • code/trunk/src/modules/pickup/PickupManager.cc

    r7548 r7549  
    7575        RegisterObject(PickupManager);
    7676
    77         //TODO: Only create if isMaster().
    7877        this->defaultRepresentation_ = new PickupRepresentation();
    7978
     
    356355
    357356        // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
    358         //TODO: Needs to be added to server even if is was not picked up by it?
    359357        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
    360358        {
  • code/trunk/src/modules/pickup/PickupSpawner.cc

    r7548 r7549  
    108108    {
    109109        this->triggerDistance_ = 10;
    110         this->respawnTime_ = 0; //TODO: Smart? Shouldn't we have a better mechanism to prevent unwanted multiple pickups?
     110        this->respawnTime_ = 5.0f;
    111111        this->maxSpawnedItems_ = INF;
    112112        this->spawnsRemaining_ = INF;
     
    151151            PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
    152152            this->attach(representation->getSpawnerRepresentation(this));
    153             this->setActive(true); //TODO: Needed?
     153            this->setActive(true);
    154154        }
    155155    }
     
    183183            SmartPtr<PickupSpawner> temp = this; //Create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)
    184184
     185            // Remove PickupCarriers from the blocked list if they have exceeded their time.
     186            for(std::map<PickupCarrier*, std::time_t>::iterator it = this->blocked_.begin(); it != this->blocked_.end(); )
     187            {
     188                std::map<PickupCarrier*, std::time_t>::iterator temp = it;
     189                it++;
     190                if(temp->second < std::time(0))
     191                    this->blocked_.erase(temp);
     192            }
     193
    185194            // Iterate trough all Pawns.
    186             for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
     195            for(ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
    187196            {
    188197                Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
    189198                PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(*it);
    190                 // If a Pawn, that fits the target-range of the item spawned by this Pickup, is in trigger-distance.
    191                 if (distance.length() < this->triggerDistance_ && carrier != NULL)
     199                // If a PickupCarrier, that fits the target-range of the Pickupable spawned by this PickupSpawnder, is in trigger-distance and the carrier is not blocked.
     200                if(distance.length() < this->triggerDistance_ && carrier != NULL && this->blocked_.find(carrier) == this->blocked_.end())
    192201                {
    193202                    if(carrier->isTarget(this->pickup_))
     
    292301
    293302            PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn);
    294             if(carrier == NULL)
    295             {
    296                 COUT(1) << "This is bad. Pawn isn't PickupCarrier." << std::endl;
    297                 return;
    298             }
    299 
     303            assert(carrier);
     304
     305            // If the Pawn isn't a target of the Pickupable.
    300306            if(!carrier->isTarget(this->pickup_))
    301307            {
     
    307313            Pickupable* pickup = this->getPickup();
    308314
     315            this->block(carrier);
     316
    309317            assert(pickup);
    310318            assert(target);
  • code/trunk/src/modules/pickup/PickupSpawner.h

    r7547 r7549  
    3838#include "PickupPrereqs.h"
    3939
     40#include <map>
    4041#include <string>
    4142#include "tools/Timer.h"
     
    102103            inline int getMaxSpawnedItems(void) const
    103104                { return this->maxSpawnedItems_; }
    104            
    105105
    106106        protected:
    107107            void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns.
    108             void startRespawnTimer(void);
     108            void startRespawnTimer(void); //!< Invoked by the timer, re-activates the PickupSpawner.
     109
     110            /**
     111            @brief Helper method. Adds a PickupCarrier to the list of PickupCarrier that are blocked form getting a Pickupable from the PickupSpawner for a specified time.
     112            @param carrier A pointer to the PickupCarrier to be blocked.
     113            @param time The time for which the Pawn is blocked. Default is 5.
     114            */
     115            void block(PickupCarrier* carrier, unsigned int time = DEFAULT_BLOCKED_TIME)
     116                { this->blocked_.insert(std::pair<PickupCarrier*, std::time_t>(carrier, std::time(0)+time)); }
    109117
    110118            /**
     
    142150            float respawnTime_; //!< Time after which this gets re-actived.
    143151            Timer respawnTimer_; //!< Timer used for re-activating.
     152            std::map<PickupCarrier*, std::time_t> blocked_;
    144153
    145154            bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing.
    146155
    147156            static const int INF = -1; //!< Constant for infinity.
     157            static const unsigned int DEFAULT_BLOCKED_TIME = 5; //!< The default time a PickupCarrier is blocked after picking up a Pickupable.
    148158    };
    149159}
Note: See TracChangeset for help on using the changeset viewer.