Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6641


Ignore:
Timestamp:
Mar 29, 2010, 4:33:22 PM (14 years ago)
Author:
benedict
Message:

Invisibility works. Timer for invi works.

Location:
code/branches/ppspickups2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ppspickups2/data/levels/pickup_pps_invi.oxw

    r6555 r6641  
    77  include("templates/spaceship_assff.oxt")
    88  include("templates/spaceship_pirate.oxt")
    9   include("templates/pickup_representation_templates.oxt")
     9  include("templates/pickup_representation_templates_invisible.oxt")
    1010?>
    1111
     
    2020
    2121<?lua
    22   include("includes/pickups.oxi")
     22  include("includes/pickups_invisible.oxi")
    2323?>
    24    
    25 <!--
    26     <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
     24
     25    <PickupSpawner position="-75,0,-100" triggerDistance="10" respawnTime="5" maxSpawnedItems="10">
    2726        <pickup>
    28             <MetaPickup metaType="drop" />
    29         </pickup>
    30     </PickupSpawner>
    31    
    32     <PickupSpawner position="-75,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
    33         <pickup>
    34             <MetaPickup metaType="use" />
     27            <InvisiblePickup template=invisiblepickup />
    3528        </pickup>
    3629    </PickupSpawner>
    3730
    38     <PickupSpawner position="-50,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
    39         <pickup>
    40             <HealthPickup health=50 healthRate=5 durationType=continuous activationType=immediate healthType=permanent />
    41         </pickup>
    42     </PickupSpawner>
    43    
    44     <PickupSpawner position="-25,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
    45         <pickup>
    46             <HealthPickup template=smallhealthpickup />
    47         </pickup>
    48     </PickupSpawner>
    49    
    50     <PickupSpawner position="0,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
    51         <pickup>
    52             <HealthPickup template=mediumhealthpickup />
    53         </pickup>
    54     </PickupSpawner>
    55    
    56     <PickupSpawner position="25,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
    57         <pickup>
    58             <HealthPickup template=hugehealthpickup />
    59         </pickup>
    60     </PickupSpawner>
    61    
    62     <PickupSpawner position="50,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
    63         <pickup>
    64             <HealthPickup template=crazyhealthpickup />
    65         </pickup>
    66     </PickupSpawner>
    67    
    68     <PickupSpawner position="75,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
    69         <pickup>
    70             <PickupCollection template=doublepickup />
    71         </pickup>
    72     </PickupSpawner>
    73 
    74     <PickupSpawner position="100,100,100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
    75         <pickup>
    76             <HealthPickup health=50 healthRate=5 durationType=continuous activationType=immediate healthType=limited />
    77         </pickup>
    78     </PickupSpawner>
    79 -->
    8031
    8132    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
  • code/branches/ppspickups2/src/modules/pickup/Pickup.cc

    r6540 r6641  
    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) /*TODO*/
     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/ppspickups2/src/modules/pickup/Pickup.h

    r6540 r6641  
    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/ppspickups2/src/modules/pickup/items/CMakeLists.txt

    r6524 r6641  
    22  HealthPickup.cc
    33  MetaPickup.cc
     4  InvisiblePickup.cc
    45)
  • code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc

    r6555 r6641  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Benedict Simlinger
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29/**
     30    @file InvisiblePickup.cc
     31    @brief Implementation of the InvisiblePickup class.
     32*/
     33
     34#include "InvisiblePickup.h"
     35
     36#include "core/CoreIncludes.h"
     37#include "core/XMLPort.h"
     38#include "util/StringUtils.h"
     39
     40#include "worldentities/pawns/Pawn.h"
     41#include "pickup/PickupIdentifier.h"
     42
     43#include <sstream>
     44
     45namespace orxonox
     46{
     47   
     48   
     49    CreateFactory(InvisiblePickup);
     50   
     51    /**
     52    @brief
     53        Constructor. Registers the object and initializes the member variables.
     54    */
     55    InvisiblePickup::InvisiblePickup(BaseObject* creator) : Pickup(creator)
     56    {
     57        RegisterObject(InvisiblePickup);
     58        //! Defines who is allowed to pick up the pickup.
     59        this->initialize();
     60    }
     61   
     62    /**
     63    @brief
     64        Destructor.
     65    */
     66    InvisiblePickup::~InvisiblePickup()
     67    {       
     68    }
     69   
     70   
     71    void InvisiblePickup::initializeIdentifier(void)
     72    {
     73        std::stringstream stream;
     74        stream << this->getDuration();
     75        std::string type1 = "duration";
     76        std::string val1 = stream.str();
     77        this->pickupIdentifier_->addParameter(type1, val1);
     78    }
     79   
     80    /**
     81    @brief
     82    Initializes the member variables.
     83    */
     84    void InvisiblePickup::initialize(void)
     85    {
     86        this->duration_ = 0.0;
     87        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
     88    }
     89 
     90   
     91   
     92
     93    /**
     94    @brief
     95        Method for creating a HealthPickup object through XML.
     96    */
     97    void InvisiblePickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
     98    {
     99        SUPER(InvisiblePickup, XMLPort, xmlelement, mode);   
     100        XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode);
     101         
     102         this->initializeIdentifier();
     103    }
     104   
     105   
     106    /**
     107    @brief
     108        Is called when the pickup has transited from used to unused or the other way around.
     109    */
     110    void InvisiblePickup::changedUsed(void)
     111    {
     112        SUPER(InvisiblePickup, changedUsed);
     113       
     114       
     115        //! If the pickup is not picked up nothing must be done.
     116        if(!this->isPickedUp())
     117            return;
     118        if (this->isUsed())
     119        {
     120            this->setInvisible(true);
     121            this->startPickupTimer(this->getDuration());
     122        }
     123        else
     124          this->setInvisible(false);
     125       
     126    }
     127   
     128    /**
     129    @brief
     130        Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     131    @return
     132        A pointer to the Pawn, or NULL if the conversion failed.
     133    */
     134    Pawn* InvisiblePickup::carrierToPawnHelper(void)
     135    {
     136        PickupCarrier* carrier = this->getCarrier();
     137        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     138       
     139        if(pawn == NULL)
     140        {
     141            COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl;
     142        }
     143        return pawn;
     144    }
     145   
     146    /**
     147    @brief
     148        Creates a duplicate of the input OrxonoxClass.
     149    @param item
     150        A pointer to the Orxonox class.
     151    */
     152    void InvisiblePickup::clone(OrxonoxClass*& item)
     153    {
     154        if(item == NULL)
     155            item = new InvisiblePickup(this);
     156       
     157        SUPER(InvisiblePickup, clone, item);
     158       
     159        InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item);
     160        pickup->setDuration(this->getDuration());
     161        pickup->initializeIdentifier();
     162    }
     163   
     164   
     165   
     166   
     167     
     168    /**
     169    @brief
     170        Sets the invisibility.
     171    @param health
     172        The invisibility.
     173    */
     174    bool InvisiblePickup::setInvisible(bool invisibility)
     175    {
     176     
     177      Pawn* pawn = this->carrierToPawnHelper();
     178      pawn->setVisible(!invisibility);
     179      return 0;
     180    }
     181   
     182   
     183   
     184    /**
     185    @brief
     186    Sets the duration.
     187    @param duration
     188    The duration
     189    */
     190    void InvisiblePickup::setDuration(float duration)
     191    {
     192        if(duration >= 0.0f)
     193        {
     194            this->duration_ = duration;
     195        }
     196        else
     197        {
     198            COUT(1) << "Invalid duration in InvisiblePickup." << std::endl;
     199            this->duration_ = 0;
     200        }
     201    }
     202   
     203   
     204   
     205    void InvisiblePickup::PickupTimerCallBack(void){
     206        this->setInvisible(false);
     207    }
     208
     209}
  • code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.h

    r6555 r6641  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Benedict Simlinger
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29/**
     30    @file InvisiblePickup.h
     31    @brief Declaration of the InvisiblePickup class.
     32*/
     33
     34#ifndef _InvisiblePickup_H__
     35#define _InvisiblePickup_H__
     36
     37#include "pickup/PickupPrereqs.h"
     38
     39#include <string>
     40#include <worldentities/pawns/Pawn.h>
     41#include "worldentities/StaticEntity.h"
     42
     43#include "pickup/Pickup.h"
     44
     45namespace orxonox {
     46       
     47    /**
     48    @brief
     49        A pickup that makes the Pawn invisible.
     50        There are 2 parameters that can be chosen:
     51        1) The activation type: It can be chosen to be either 'immediate' or 'onUse'. The activation type essentially (as indicated by the name) defines when the Pawn will be invisible, either immediately after being picked up or only after the player uses it.
     52        2) The duration type: It can be chosen how long the Pawn will be invisibel.
     53    @author
     54        Benedict Simlinger
     55    */
     56    class _PickupExport InvisiblePickup : public Pickup
     57    {
     58        public:
     59       
     60            InvisiblePickup(BaseObject* creator); //!< Constructor.
     61            virtual ~InvisiblePickup(); //!< Destructor.
     62            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
     63            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
     64            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
     65           
     66             /**
     67            @brief Checks wether the Pawn is invisible.
     68            @return Returns if the Pawn is invisible.
     69            */
     70            inline bool getInvisibility(bool)
     71                { return this->invisible_; }
     72            inline float getDuration()
     73                {return this->duration_;}
     74 
     75        protected:
     76            bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again.
     77            void setDuration(float duration);
     78            void initializeIdentifier(void);
     79       
     80        private:
     81           void initialize(void); //!< Initializes the member variables.
     82            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     83            void PickupTimerCallBack(void); //!< Function that gets called when the timer ends.
     84            bool invisible_; //!< Helper to remember wether the Pawn is invisible.
     85            float duration_; //! Duration of invisibility.
     86    };
     87}
     88
     89#endif // _InvisiblePickup_H__
  • code/branches/ppspickups2/src/orxonox/interfaces/PickupCarrier.h

    r6540 r6641  
    4848{
    4949
    50     //! Pre-declarations.
    51     class Pickup;
    52     class HealthPickup;
    53     class MetaPickup;
    5450
    5551    /**
     
    6662        friend class HealthPickup;
    6763        friend class MetaPickup;
     64        friend class InvisiblePickup;
    6865       
    6966        public:
Note: See TracChangeset for help on using the changeset viewer.