Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2900


Ignore:
Timestamp:
Apr 6, 2009, 3:53:50 PM (15 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
14 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickups

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

    r2662 r2900  
    4848    SetConsoleCommand(HumanController, boost,         true).keybindMode(KeybindMode::OnHold);
    4949    SetConsoleCommand(HumanController, greet,         true);
    50     SetConsoleCommand(HumanController, use,           true);
    5150    SetConsoleCommand(HumanController, switchCamera,  true);
    5251    SetConsoleCommand(HumanController, mouseLook,     true);
     
    5554    SetConsoleCommand(HumanController, killBots,      true).defaultValues(0);
    5655    SetConsoleCommand(HumanController, dropItems,     true);
     56    SetConsoleCommand(HumanController, useItem,       true);
    5757
    5858    CreateUnloadableFactory(HumanController);
     
    132132    }
    133133
    134     void HumanController::use()
    135     {
    136         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    137             HumanController::localController_s->controllableEntity_->use();
    138     }
    139 
    140134    void HumanController::switchCamera()
    141135    {
     
    160154    }
    161155
     156    void HumanController::useItem()
     157    {
     158        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     159            HumanController::localController_s->controllableEntity_->useItem();
     160    }
     161
    162162    void HumanController::addBots(unsigned int amount)
    163163    {
  • code/branches/pickups/src/orxonox/objects/controllers/HumanController.h

    r2662 r2900  
    5656            static void boost();
    5757            static void greet();
    58             static void use();
    5958            static void switchCamera();
    6059            static void mouseLook();
    6160            static void dropItems();
     61            static void useItem();
    6262
    6363            static void suicide();
  • code/branches/pickups/src/orxonox/objects/items/Engine.cc

    r2662 r2900  
    192192        }
    193193
    194         this->ship_->setAcceleration(this->ship_->getOrientation() * acceleration);
     194        this->ship_->setAcceleration(this->ship_->getPickups().processModifiers(ModifierType::Acceleration, this->ship_->getOrientation() * acceleration, false));
    195195
    196196        if (!this->ship_->getPermanentBoost())
  • 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) { }
  • code/branches/pickups/src/orxonox/objects/worldentities/ControllableEntity.h

    r2662 r2900  
    8787            virtual void boost() {}
    8888            virtual void greet() {}
    89             virtual void use() {}
     89            virtual void useItem() {}
    9090            virtual void dropItems() {}
    9191            virtual void switchCamera();
  • code/branches/pickups/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2864 r2900  
    110110            inline PickupCollection& getPickups()
    111111                { return this->pickups_; }
     112            virtual void useItem()
     113                { this->pickups_.useItem(); }
    112114
    113115        protected:
Note: See TracChangeset for help on using the changeset viewer.