Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6709


Ignore:
Timestamp:
Apr 13, 2010, 9:32:08 AM (14 years ago)
Author:
dafrick
Message:

Merged ppspickups1 into trunk.

Location:
code/trunk
Files:
15 edited
5 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pickup/Pickup.cc

    r6540 r6709  
    3939#include "DroppedPickup.h"
    4040
     41#include "tools/Timer.h"
     42
    4143namespace orxonox
    4244{
    43    
     45
    4446    /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate";
    4547    /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse";
    4648    /*static*/ const std::string Pickup::durationTypeOnce_s = "once";
    4749    /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous";
    48    
     50
    4951    Pickup::Pickup(BaseObject* creator) : BaseObject(creator)
    5052    {
    5153        RegisterObject(Pickup);
    52        
     54
    5355        this->initialize();
    5456    }
    55    
     57
    5658    Pickup::~Pickup()
    5759    {
    58        
    59     }
    60    
     60
     61    }
     62
    6163    /**
    6264    @brief
     
    6870        this->durationType_ = pickupDurationType::once;
    6971    }
    70    
     72
    7173    /**
    7274    @brief
     
    7476    */
    7577    void Pickup::initializeIdentifier(void)
    76     {       
     78    {
    7779        std::string val1 = this->getActivationType();
    7880        std::string type1 = "activationType";
    7981        this->pickupIdentifier_->addParameter(type1, val1);
    80        
     82
    8183        std::string val2 = this->getDurationType();
    8284        std::string type2 = "durationType";
    8385        this->pickupIdentifier_->addParameter(type2, val2);
    8486    }
    85    
     87
    8688    /**
    8789    @brief
     
    9496        XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode);
    9597        XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode);
    96        
     98
    9799        this->initializeIdentifier();
    98100    }
    99    
     101
    100102    /**
    101103    @brief
     
    116118        }
    117119    }
    118        
     120
    119121    /**
    120122    @brief
     
    135137        }
    136138    }
    137    
     139
    138140    /**
    139141    @brief
     
    157159        }
    158160    }
    159        
     161
    160162    /**
    161163    @brief
     
    179181        }
    180182    }
    181    
     183
    182184    /**
    183185    @brief
     
    188190    {
    189191        SUPER(Pickup, changedPickedUp);
    190        
     192
    191193        //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
    192194        if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate())
     
    195197        }
    196198    }
    197    
     199
    198200    /**
    199201    @brief
     
    206208        if(item == NULL)
    207209            item = new Pickup(this);
    208        
     210
    209211        SUPER(Pickup, clone, item);
    210        
     212
    211213        Pickup* pickup = dynamic_cast<Pickup*>(item);
    212214        pickup->setActivationTypeDirect(this->getActivationTypeDirect());
    213215        pickup->setDurationTypeDirect(this->getDurationTypeDirect());
    214        
     216
    215217        pickup->initializeIdentifier();
    216218    }
    217        
     219
    218220    /**
    219221    @brief
     
    231233        return true;
    232234    }
    233    
     235
     236    /**
     237    @brief
     238        Starts the pickup duration timer.
     239        After the specified durationTime has expired the function pickupTimerCallback is called.
     240        pickupTimerCallback can be overloaded and thus the desired functionality can be implemented.
     241    @param durationTime
     242        The duration after which the expires and the callback function is called.
     243    @return
     244        Returns true if the pickup duration timer was started successfully, false if not.
     245    */
     246    bool Pickup::startPickupTimer(float durationTime)
     247    {
     248        if (durationTime<=0)
     249        {
     250            COUT(1) << "Invalid durationTime in pickup." << std::endl;
     251            return false;
     252        }
     253        if (this->durationTimer_.isActive()) //!< Check if Timer is already running
     254        {
     255            COUT(1) << "Pickup durationTimer already in use." << std::endl;
     256            return false;
     257        }
     258        this->durationTimer_.setTimer(durationTime, false, createExecutor(createFunctor(&Pickup::pickupTimerCallback, this)));
     259        return true;
     260    }
    234261}
  • code/trunk/src/modules/pickup/Pickup.h

    r6540 r6709  
    4242#include "interfaces/Pickupable.h"
    4343
     44#include "tools/Timer.h"
     45
    4446namespace orxonox
    4547{
     
    5456        };
    5557    }
    56    
     58
    5759    //! Enum for the duration tyoe.
    5860    namespace pickupDurationType
     
    6466        };
    6567    }
    66    
     68
    6769    /**
    6870    @brief
     
    7476    class _PickupExport Pickup : public Pickupable, public BaseObject
    7577    {
    76        
     78
    7779        protected:
    7880            Pickup(BaseObject* creator); //!< Constructor.
    79        
     81
    8082        public:
    8183            virtual ~Pickup(); //!< Destructor.
    82            
     84
    8385            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    84            
     86
    8587            /**
    8688            @brief Get the activation type of the pickup.
     
    9597            inline pickupDurationType::Value getDurationTypeDirect(void)
    9698                { return this->durationType_; }
    97            
     99
    98100            const std::string& getActivationType(void); //!< Get the activation type of the pickup.
    99101            const std::string& getDurationType(void); //!< Get the duration type of the pickup.
    100            
     102
    101103            /**
    102104            @brief Get whether the activation type is 'immediate'.
     
    123125            inline bool isContinuous(void)
    124126                { return this->getDurationTypeDirect() == pickupDurationType::continuous; }
    125            
     127
    126128            virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
    127                                    
     129
    128130            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the Pickup.
    129                
     131
    130132        protected:
    131133            void initializeIdentifier(void);
    132            
     134
    133135            virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    134            
     136
     137            bool startPickupTimer(float durationTime);
     138
     139            virtual void pickupTimerCallback(void) {}
     140
    135141            /**
    136142            @brief Set the activation type of the pickup.
     
    145151            inline void setDurationTypeDirect(pickupDurationType::Value type)
    146152                { this->durationType_ = type; }
    147                
     153
    148154            void setActivationType(const std::string& type); //!< Set the activation type of the pickup.
    149155            void setDurationType(const std::string& type); //!< Set the duration type of the pickup
    150                
     156
    151157        private:
    152158            void initialize(void); //!< Initializes the member variables.
    153159           
     160            //TODO: Problems, when there are more Timers needed? Solutions?
     161            Timer durationTimer_; //!< Timer at the disposal of each Class implementing Pickup.
     162
    154163            pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
    155164            pickupDurationType::Value durationType_; //!< The duration type of the pickup.
    156            
     165
    157166            static const std::string activationTypeImmediate_s;
    158167            static const std::string activationTypeOnUse_s;
    159168            static const std::string durationTypeOnce_s;
    160169            static const std::string durationTypeContinuous_s;
    161        
    162170    };
    163    
     171
    164172}
    165173#endif // _Pickup_H__
  • code/trunk/src/modules/pickup/PickupPrereqs.h

    r6524 r6709  
    7373    class PickupRepresentation;
    7474    class PickupSpawner;
    75    
     75
    7676    //items
    7777    class HealthPickup;
    7878    class MetaPickup;
    79    
     79    class SpeedPickup;
     80
    8081}
    8182
  • code/trunk/src/modules/pickup/items/CMakeLists.txt

    r6524 r6709  
    11ADD_SOURCE_FILES(PICKUP_SRC_FILES
     2
    23  HealthPickup.cc
     4
     5  SpeedPickup.cc
    36  MetaPickup.cc
     7
    48)
  • code/trunk/src/modules/pickup/items/HealthPickup.cc

    • Property svn:eol-style set to native
  • code/trunk/src/modules/pickup/items/HealthPickup.h

    • Property svn:eol-style set to native
  • code/trunk/src/modules/pickup/items/MetaPickup.cc

    • Property svn:eol-style set to native
  • code/trunk/src/modules/pickup/items/MetaPickup.h

    • Property svn:eol-style set to native
  • code/trunk/src/orxonox/interfaces/PickupCarrier.h

    r6563 r6709  
    4747namespace orxonox
    4848{
    49 
    50     //! Pre-declarations.
     49    class Pickupable;
    5150    class Pickup;
    5251    class HealthPickup;
    5352    class MetaPickup;
     53    class SpeedPickup;
    5454
    5555    /**
     
    6767        friend class HealthPickup;
    6868        friend class MetaPickup;
    69        
     69        friend class SpeedPickup;
     70
    7071        public:
    7172            PickupCarrier(); //!< Constructor.
    7273            virtual ~PickupCarrier(); //!< Destructor.
    73            
     74
    7475            /**
    7576            @brief Can be called to pick up a Pickupable.
     
    8788                    return pickedUp;
    8889                }
    89                
     90
    9091            /**
    9192            @brief Can be called to drop a Pickupable.
     
    9596            */
    9697            bool drop(Pickupable* pickup, bool drop = true)
    97                 { 
     98                {
    9899                    bool dropped = this->pickups_.erase(pickup) == 1;
    99100                    if(dropped && drop)
     
    104105                    return dropped;
    105106                }
    106                
     107
    107108            /**
    108109            @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable.
     
    114115                    if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
    115116                        return true;
    116                    
     117
    117118                    //! Go recursively through all children to check whether they are a target.
    118119                    std::list<PickupCarrier*>* children = this->getCarrierChildren();
     
    122123                            return true;
    123124                    }
    124                    
     125
    125126                    children->clear();
    126127                    delete children;
    127                    
     128
    128129                    return false;
    129130                }
    130                
     131
    131132            /**
    132133            @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable.
     
    138139                    if(!this->isTarget(pickup))
    139140                        return NULL;
    140                    
     141
    141142                    if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
    142143                        return this;
    143                    
     144
    144145                    //! Go recursively through all children to check whether they are the target.
    145146                    std::list<PickupCarrier*>* children = this->getCarrierChildren();
     
    149150                            return *it;
    150151                    }
    151                    
     152
    152153                    children->clear();
    153154                    delete children;
    154                    
     155
    155156                    return NULL;
    156157                }
    157                
     158
    158159            /**
    159160            @brief Get the (absolute) position of the PickupCarrier.
     
    162163            */
    163164            virtual const Vector3& getCarrierPosition(void) = 0;
    164            
    165         protected:       
     165
     166        protected:
    166167            /**
    167168            @brief Get all direct children of this PickupSpawner.
    168169                   This method needs to be implemented by any direct derivative class of PickupCarrier.
    169170                   The returned list will be deleted by the methods calling this function.
    170             @return Returns a pointer to a list of all direct children. 
     171            @return Returns a pointer to a list of all direct children.
    171172            */
    172173            virtual std::list<PickupCarrier*>* getCarrierChildren(void) = 0;
     
    177178            */
    178179            virtual PickupCarrier* getCarrierParent(void) = 0;
    179                            
     180
    180181            /**
    181182            @brief Get all Pickupables this PickupCarrier has.
     
    184185            std::set<Pickupable*>& getPickups(void)
    185186                { return this->pickups_; }
    186        
     187
    187188        private:
    188189            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    189            
     190
    190191    };
    191192}
  • code/trunk/src/orxonox/items/Engine.cc

    r6540 r6709  
    6464        this->boostBlur_ = 0;
    6565
     66        this->speedAdd_ = 0.0;
     67        this->speedMultiply_ = 1.0;
     68
    6669        this->setConfigValues();
    6770        this->registerVariables();
     
    119122        registerVariable(this->accelerationLeftRight_, VariableDirection::ToClient);
    120123        registerVariable(this->accelerationUpDown_,    VariableDirection::ToClient);
     124
     125        registerVariable(this->speedAdd_, VariableDirection::ToClient);
     126        registerVariable(this->speedMultiply_, VariableDirection::ToClient);
    121127    }
    122128
     
    192198        }
    193199
    194         this->ship_->setAcceleration(this->ship_->getOrientation() * acceleration);
     200        this->ship_->setAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd())));
    195201
    196202        if (!this->ship_->getPermanentBoost())
     
    241247            return Vector3::ZERO;
    242248    }
     249
     250    PickupCarrier* Engine::getCarrierParent(void)
     251    {
     252        return this->ship_;
     253    }
     254
     255    const Vector3& Engine::getCarrierPosition(void)
     256    {
     257        return this->ship_->getWorldPosition();
     258    }
    243259}
  • code/trunk/src/orxonox/items/Engine.h

    r6417 r6709  
    3535#include "Item.h"
    3636
     37#include "interfaces/PickupCarrier.h"
     38
    3739namespace orxonox
    3840{
    39     class _OrxonoxExport Engine : public Item, public Tickable
     41    class _OrxonoxExport Engine : public Item, public Tickable, public PickupCarrier
    4042    {
    4143        public:
     
    104106                { return this->accelerationUpDown_; }
    105107
     108            inline float getSpeedAdd(void)
     109                { return this->speedAdd_; }
     110            inline float getSpeedMultiply(void)
     111                { return this->speedMultiply_; }
     112
    106113            virtual const Vector3& getDirection() const;
     114
     115            virtual const Vector3& getCarrierPosition(void);
     116
     117            //TODO: Move to protected or private. How?
     118            inline void setSpeedAdd(float speedAdd)
     119                { this->speedAdd_=speedAdd; }
     120            inline void setSpeedMultiply(float speedMultiply)
     121                { this->speedMultiply_=speedMultiply; }
     122
     123        protected:
     124            virtual std::list<PickupCarrier*>* getCarrierChildren(void)
     125                { return new std::list<PickupCarrier*>(); }
     126            virtual PickupCarrier* getCarrierParent(void);
    107127
    108128        private:
     
    114134            float boostFactor_;
    115135            float speedFactor_;
     136
     137            float speedAdd_;
     138            float speedMultiply_;
    116139
    117140            float maxSpeedFront_;
  • code/trunk/src/orxonox/items/MultiStateEngine.cc

    r6417 r6709  
    129129                else
    130130                    this->state_ = Idle;
     131
     132                if (this->state_ == Idle && this->getSpeedAdd() > 0)
     133                    this->state_ = Normal;
    131134            }
    132135
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc

    r6417 r6709  
    220220            engine->addToSpaceShip(this);
    221221    }
     222
     223    std::list<PickupCarrier*>* SpaceShip::getCarrierChildren(void)
     224    {
     225        std::list<PickupCarrier*>* list = new std::list<PickupCarrier*>();
     226        list->push_front(this->engine_);
     227        return list;
     228    }
    222229}
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h

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