Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 6, 2009, 3:53:50 PM (16 years ago)
Author:
danielh
Message:
  • some changes to the base framework
  • added DroppedItem
  • implemented usable items and a test UsableItem (Jump), console command to use an item is "useItem"
  • added ModifierType::Acceleration
Location:
code/branches/pickups
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickups

    • Property svn:ignore set to
      build
      dependencies
  • code/branches/pickups/src/orxonox/objects/pickup/BaseItem.cc

    r2864 r2900  
    6363        this->setOwner(pawn);
    6464
    65         COUT(3) << "Adding '" << this->getPickupIdentifier() << "' item." << std::endl;
    66 
    67         return pawn->getPickups().add(this);
     65        if (pawn->getPickups().add(this))
     66        {
     67            COUT(3) << "Added '" << this->getPickupIdentifier() << "' item." << std::endl;
     68            return true;
     69        }
     70        return false;
    6871    }
    6972    /**
  • code/branches/pickups/src/orxonox/objects/pickup/CMakeLists.txt

    r2864 r2900  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    22  BaseItem.cc
     3  DroppedItem.cc
    34  EquipmentItem.cc
     5  Jump.cc
    46  ModifierPickup.cc
    57  PassiveItem.cc
  • code/branches/pickups/src/orxonox/objects/pickup/ModifierPickup.cc

    r2864 r2900  
    7474        XMLPortParamTemplate(ModifierPickup, "damageAdd", setAdditiveDamage, getAdditiveDamage, element, mode, float);
    7575        XMLPortParamTemplate(ModifierPickup, "damageMulti", setMultiplicativeDamage, getMultiplicativeDamage, element, mode, float);
     76
     77        XMLPortParamTemplate(ModifierPickup, "accelerationAdd", setAdditiveAcceleration, getAdditiveAcceleration, element, mode, float);
     78        XMLPortParamTemplate(ModifierPickup, "accelerationMulti", setMultiplicativeAcceleration, getMultiplicativeAcceleration, element, mode, float);
    7679    }
    7780    /**
     
    141144                this->timer_.stopTimer();
    142145
     146            delete this;
     147
    143148            return true;
    144149        }
  • code/branches/pickups/src/orxonox/objects/pickup/ModifierPickup.h

    r2864 r2900  
    5858        virtual bool dropped(Pawn* pawn);                               //!< Override of the BaseItem::dropped() method
    5959
     60        virtual int getMaxCarryAmount(){ return INT_MAX; }              //!< Allow the player to carry infinite ModPickups
     61
    6062        /**
    6163            @brief Get the duration of this pickup.
     
    9799            { this->setMultiplicativeModifier(ModifierType::Damage, value); }
    98100
     101        /**
     102            @brief Get the amount of acceleration this pickup adds.
     103            @return Returns how much acceleration this pickup adds.
     104        */
     105        inline float getAdditiveAcceleration() const
     106            { return this->getAdditiveModifier(ModifierType::Acceleration); }
     107        /**
     108            @brief Get the factor by which this pickup multiplies the acceleration.
     109            @return Returns the factor by which to multiply acceleration.
     110        */
     111        inline float getMultiplicativeAcceleration() const
     112            { return this->getMultiplicativeModifier(ModifierType::Acceleration); }
     113
     114        /**
     115            @brief Set the amount of acceleration this pickup adds.
     116            @param value How much acceleration this pickup adds.
     117        */
     118        inline void setAdditiveAcceleration(float value)
     119            { this->setAdditiveModifier(ModifierType::Acceleration, value); }
     120        /**
     121            @brief Set the factor by which this pickup multiplies the acceleration.
     122            @param value Factor by which to multiply acceleration.
     123        */
     124        inline void setMultiplicativeAcceleration(float value)
     125            { this->setMultiplicativeModifier(ModifierType::Acceleration, value); }
     126
    99127        void timerCallback(Pawn* pawn);     //!< Method called when the timer runs out.
    100128    private:
  • code/branches/pickups/src/orxonox/objects/pickup/ModifierType.h

    r2864 r2900  
    4545        {
    4646            Unknown = 0,
    47             Damage
     47            Damage,
     48            Acceleration
    4849        };
    4950    }
  • code/branches/pickups/src/orxonox/objects/pickup/PickupCollection.cc

    r2864 r2900  
    9494        for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++)
    9595        {
    96             (*it).second->dropped((*it).second->getOwner());
    97 
    98             delete (*it).second;
     96            if((*it).second && (*it).second->getOwner())
     97                (*it).second->dropped((*it).second->getOwner());
    9998        }
    10099        this->items_.clear();
     
    125124            return false;
    126125        }
     126    }
     127    //! Uses the first usable item in the collection on the owner.
     128    void PickupCollection::useItem()
     129    {
     130        Identifier* ident = Class(UsableItem);
     131        for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++)
     132        {
     133            if ((*it).second->isA(ident))
     134            {
     135                UsableItem* asUsable = dynamic_cast<UsableItem*>((*it).second);
     136                asUsable->used(this->owner_);
     137                return;
     138            }
     139        }
     140    }
     141    /**
     142        @brief Uses a usable item on the owner of the collection.
     143        @param item Item to use.
     144    */
     145    void PickupCollection::useItem(UsableItem* item)
     146    {
     147        if (item && this->owner_)
     148            item->used(this->owner_);
    127149    }
    128150    /**
  • code/branches/pickups/src/orxonox/objects/pickup/PickupCollection.h

    r2864 r2900  
    4848{
    4949    class BaseItem;
     50    class UsableItem;
    5051    class Pawn;
    5152
     
    6768
    6869        void remove(BaseItem* item, bool removeAllOfType = false);                  //!< Remove an item from the collection.
     70
     71        void useItem();                                                             //!< Use the first usable item.
     72        void useItem(UsableItem* item);                                             //!< Use a usable item.
    6973
    7074        void addAdditiveModifier(ModifierType::Enum type, float value);             //!< Add an additive modifier.
  • code/branches/pickups/src/orxonox/objects/pickup/UsableItem.h

    r2864 r2900  
    5252
    5353        /**
    54             @brief Method invoked if the item was used.
    55             @param pawn Pawn which used the item.
     54            @brief Method invoked when the item is being used.
     55            @param pawn Pawn which is using the item.
    5656        */
    5757        virtual void used(Pawn* pawn) { }
Note: See TracChangeset for help on using the changeset viewer.