Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6607


Ignore:
Timestamp:
Mar 22, 2010, 10:45:09 PM (15 years ago)
Author:
ebeier
Message:

first working version of the SpeedPickup, needs some more work for "onUse" type. Spaceship trails need to be looked at, because they don't show when a SpeedPickup with SpeedAdd is used.

Location:
code/branches/ppspickups1
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ppspickups1/data/levels/templates/pickup_representation_templates_speed.oxt

    r6575 r6607  
    1717<Template name=smallspeedpickup>
    1818  <SpeedPickup
    19     duration = 10
    20     speedAdd = 1
    21     SpeedMultiply = 1
     19    duration = 10.0
     20    speedAdd = 0
     21    SpeedMultiply = 10
    2222    activationType = "immediate"
    2323    durationType = "once"
  • code/branches/ppspickups1/src/modules/pickup/Pickup.cc

    r6540 r6607  
    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    */
     240    bool Pickup::startPickupTimer(float durationTime)
     241    {
     242        if (durationTime<=0)
     243        {
     244            COUT(1) << "Invalid durationTime in pickup." << std::endl;
     245            return false;
     246        }
     247        if (false) /* How to check if Timer already running? */
     248        {
     249            COUT(1) << "Pickup durationTimer already in use." << std::endl;
     250            return false;
     251        }
     252        this->durationTimer_.setTimer(durationTime, false, createExecutor(createFunctor(&Pickup::PickupTimerCallBack, this)));
     253        return true;
     254    }
    234255}
  • code/branches/ppspickups1/src/modules/pickup/Pickup.h

    r6540 r6607  
    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.
    153            
     159
    154160            pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
    155161            pickupDurationType::Value durationType_; //!< The duration type of the pickup.
    156            
     162
    157163            static const std::string activationTypeImmediate_s;
    158164            static const std::string activationTypeOnUse_s;
    159165            static const std::string durationTypeOnce_s;
    160166            static const std::string durationTypeContinuous_s;
    161        
     167
     168            float durationTime_;
     169            Timer durationTimer_;
    162170    };
    163    
     171
    164172}
    165173#endif // _Pickup_H__
  • code/branches/ppspickups1/src/modules/pickup/PickupPrereqs.h

    r6524 r6607  
    7373    class PickupRepresentation;
    7474    class PickupSpawner;
    75    
     75
    7676    //items
    7777    class HealthPickup;
    7878    class MetaPickup;
    79    
     79    class SpeedPickup;
     80
    8081}
    8182
  • code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.cc

    r6575 r6607  
    3838#include "util/StringUtils.h"
    3939
    40 #include "worldentities/pawns/Pawn.h"
     40#include "worldentities/pawns/SpaceShip.h"
     41#include "items/Engine.h"
    4142#include "pickup/PickupIdentifier.h"
    4243
     
    123124    /**
    124125    @brief
    125         Is called every tick.
    126         Does count down the duration of the SpeedPickup.
    127     @param dt
    128         The duration of the last tick.
    129     */
    130     void SpeedPickup::tick(float dt)
    131     {
    132         if(this->isUsed())
    133         {
    134             Pawn* pawn = this->carrierToPawnHelper();
    135             if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    136                 this->destroy();
    137 
    138              //! Calculate the remaining duration of the Pickup
    139             float duration=this->getDuration()-dt;
    140             this->setDuration(duration);
    141 
    142             //! If duration is over
    143             if(this->getDuration() < 0)
    144             {
    145                 this->setUsed(false);
    146             }
    147         }
    148     }
    149 
    150     /**
    151     @brief
    152126        Is called when the pickup has transited from used to unused or the other way around.
    153127    */
     
    163137        if(this->isUsed())
    164138        {
    165             if(this->isOnce())
    166             {
    167                 Pawn* pawn = this->carrierToPawnHelper();
    168                 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    169                     this->destroy();
    170 
    171                 //! The pickup has been used up.
    172                 this->setUsed(false);
    173             }
    174         }
    175         else
    176         {
    177             //! If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
    178             if(this->isOnce() || (this->isContinuous() && this->getDuration() < 0))
    179             {
     139            this->startPickupTimer(this->getDuration());
     140
     141            Engine* engine = this->carrierToEngineHelper();
     142            if(engine == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    180143                this->destroy();
    181             }
    182         }
    183     }
     144            engine->setSpeedAdd(this->getSpeedAdd());
     145            engine->setSpeedMultiply(this->getSpeedMultiply());
     146        }
     147    }
     148
     149
    184150
    185151    /**
     
    189155        A pointer to the Pawn, or NULL if the conversion failed.
    190156    */
    191     Pawn* SpeedPickup::carrierToPawnHelper(void)
     157    Engine* SpeedPickup::carrierToEngineHelper(void)
    192158    {
    193159        PickupCarrier* carrier = this->getCarrier();
    194         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
    195 
    196         if(pawn == NULL)
     160        SpaceShip* ship = dynamic_cast<SpaceShip*>(carrier);
     161
     162        if(ship == NULL)
    197163        {
    198164            COUT(1) << "Invalid PickupCarrier in SpeedPickup." << std::endl;
    199165        }
    200 
    201         return pawn;
     166        else
     167        {
     168            return ship->getEngine();
     169        }
     170
     171        return 0;
    202172    }
    203173
     
    238208        {
    239209            COUT(1) << "Invalid duration in SpeedPickup." << std::endl;
    240             this->duration_ = 0.0;
     210            this->duration_ = 0;
    241211        }
    242212    }
     
    250220    void SpeedPickup::setSpeedAdd(float speedAdd)
    251221    {
    252         if(speedAdd > 0.0f)
     222        if(speedAdd >= 0.0f)
    253223        {
    254224            this->speedAdd_ = speedAdd;
     
    269239    void SpeedPickup::setSpeedMultiply(float speedMultiply)
    270240    {
    271         if(speedMultiply != 0.0f)
     241        if(speedMultiply != 0)
    272242        {
    273243            this->speedMultiply_ = speedMultiply;
     
    279249        }
    280250    }
     251
     252    void SpeedPickup::PickupTimerCallBack(void) {
     253        COUT(2) << "Timer ended!" << std::endl;
     254    }
    281255}
  • code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.h

    r6574 r6607  
    5757        Eric Beier
    5858    */
    59     class _PickupExport SpeedPickup : public Pickup, public Tickable
     59    class _PickupExport SpeedPickup : public Pickup
    6060    {
    6161        public:
     
    6565
    6666            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
    67             virtual void tick(float dt); //!< Is called every tick.
    6867
    6968            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
     
    8079            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    8180
    82             void setDuration(float duration); //!< Sets the duration
     81            void setDuration(float duration);
    8382            void setSpeedAdd(float speedAdd);
    8483            void setSpeedMultiply(float speedMultiply);
    8584
    86 
    8785        private:
    8886            void initialize(void); //!< Initializes the member variables.
    89             Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     87            void PickupTimerCallBack(void); //!< Function that gets called when timer ends.
     88            Engine* carrierToEngineHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
    9089
    9190            float duration_; //!< The health that is transferred to the Pawn.
  • code/branches/ppspickups1/src/orxonox/interfaces/PickupCarrier.h

    r6540 r6607  
    4848{
    4949
    50     //! Pre-declarations.
    51     class Pickup;
    52     class HealthPickup;
    53     class MetaPickup;
    54 
    5550    /**
    5651    @brief
     
    6661        friend class HealthPickup;
    6762        friend class MetaPickup;
    68        
     63        friend class SpeedPickup;
     64
    6965        public:
    7066            PickupCarrier(); //!< Constructor.
    7167            virtual ~PickupCarrier(); //!< Destructor.
    72            
     68
    7369            /**
    7470            @brief Can be called to pick up a Pickupable.
     
    8682                    return pickedUp;
    8783                }
    88                
     84
    8985            /**
    9086            @brief Can be called to drop a Pickupable.
     
    9490            */
    9591            bool drop(Pickupable* pickup, bool drop = true)
    96                 { 
     92                {
    9793                    bool dropped = this->pickups_.erase(pickup) == 1;
    9894                    if(dropped && drop)
     
    10399                    return dropped;
    104100                }
    105                
     101
    106102            /**
    107103            @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable.
     
    113109                    if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
    114110                        return true;
    115                    
     111
    116112                    //! Go recursively through all children to check whether they are a target.
    117113                    std::list<PickupCarrier*>* children = this->getCarrierChildren();
     
    121117                            return true;
    122118                    }
    123                    
     119
    124120                    children->clear();
    125121                    delete children;
    126                    
     122
    127123                    return false;
    128124                }
    129                
     125
    130126            /**
    131127            @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable.
     
    137133                    if(!this->isTarget(pickup))
    138134                        return NULL;
    139                    
     135
    140136                    if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
    141137                        return this;
    142                    
     138
    143139                    //! Go recursively through all children to check whether they are the target.
    144140                    std::list<PickupCarrier*>* children = this->getCarrierChildren();
     
    148144                            return *it;
    149145                    }
    150                    
     146
    151147                    children->clear();
    152148                    delete children;
    153                    
     149
    154150                    return NULL;
    155151                }
    156                
     152
    157153            /**
    158154            @brief Get the (absolute) position of the PickupCarrier.
     
    161157            */
    162158            virtual const Vector3& getCarrierPosition(void) = 0;
    163            
    164         protected:       
     159
     160        protected:
    165161            /**
    166162            @brief Get all direct children of this PickupSpawner.
    167163                   This method needs to be implemented by any direct derivative class of PickupCarrier.
    168164                   The returned list will be deleted by the methods calling this function.
    169             @return Returns a pointer to a list of all direct children. 
     165            @return Returns a pointer to a list of all direct children.
    170166            */
    171167            virtual std::list<PickupCarrier*>* getCarrierChildren(void) = 0;
     
    176172            */
    177173            virtual PickupCarrier* getCarrierParent(void) = 0;
    178                            
     174
    179175            /**
    180176            @brief Get all Pickupables this PickupCarrier has.
     
    183179            std::set<Pickupable*>& getPickups(void)
    184180                { return this->pickups_; }
    185        
     181
    186182        private:
    187183            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    188            
     184
    189185    };
    190186}
  • code/branches/ppspickups1/src/orxonox/items/Engine.cc

    r6540 r6607  
    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/branches/ppspickups1/src/orxonox/items/Engine.h

    r6417 r6607  
    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            /* not in protected ?? */
     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/branches/ppspickups1/src/orxonox/worldentities/pawns/SpaceShip.cc

    r6417 r6607  
    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(engine_);
     227        return list;
     228    }
    222229}
  • code/branches/ppspickups1/src/orxonox/worldentities/pawns/SpaceShip.h

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