Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2227


Ignore:
Timestamp:
Nov 19, 2008, 4:06:51 PM (15 years ago)
Author:
dsommer
Message:

Turbo funktioniert

Location:
code/branches/pickups2/src/orxonox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickups2/src/orxonox/CMakeLists.txt

    r2106 r2227  
    6767  objects/worldentities/ParticleEmitter.cc
    6868  objects/worldentities/ParticleSpawner.cc
     69  objects/pickup/PickupSpawner.cc
    6970#  objects/worldentities/Backlight.cc
     71
     72  objects/pickup/Item.cc
     73  objects/pickup/Turbo.cc
    7074
    7175  objects/quest/AddQuest.cc
  • code/branches/pickups2/src/orxonox/objects/pickup/Item.cc

    r2202 r2227  
     1/* has to be added to player
     2   multimap<std::string, Item*> Equipment;*/
     3
     4#include "Item.h"
     5#include "core/CoreIncludes.h"
     6#include "core/XMLPort.h"
     7#include "util/String.h"
     8#include "objects/worldentities/pawns/Pawn.h"
     9
     10namespace orxonox
     11{
     12Item::Item(BaseObject* creator) : BaseObject(creator)
     13{
     14        RegisterObject(Item);
     15
     16        this->playerBaseClass_ = 0;
     17}
     18
     19Item::~Item()
     20{
     21}
     22    void Item::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     23    {
     24        SUPER(Item, XMLPort, xmlelement, mode);
     25
     26        XMLPortParam(Item, "playerclass", setPlayerBaseClassName, getPlayerBaseClassName, xmlelement, mode);
     27    }
     28
     29void Item::addTo (Pawn* player)
     30{
     31        //player->Equipment.insert ( std::pair<std::string, Item*>(this->itemname,this) );
     32}
     33
     34void Item::setPlayerBaseClassName(const std::string& name)
     35{
     36        this->playerBaseClass_ = ClassByString(name);
     37}
     38
     39const std::string& Item::getPlayerBaseClassName() const
     40{
     41        if (this->playerBaseClass_)
     42                return this->playerBaseClass_->getName();
     43        else
     44                return BLANKSTRING;
     45}
     46}
  • code/branches/pickups2/src/orxonox/objects/pickup/Item.h

    r2202 r2227  
     1#ifndef _Item_H__
     2#define _Item_H__
     3
     4#include "core/BaseObject.h"
     5#include "OrxonoxPrereqs.h"
     6
    17namespace orxonox
    28{
    3         class _OrxonoxExport Item
     9        class _OrxonoxExport Item : public BaseObject
    410        {
    511        public:
    6         virtual bool pickedUp(Pawn* player);
    7         virtual bool dropped(Pawn* player); //erst bei festen Items
     12        Item( BaseObject* creator);
     13        virtual ~Item();
     14
     15        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     16
     17        virtual bool pickedUp(Pawn* player) { return true; }
     18        virtual bool dropped(Pawn* player) { return true; } //erst bei festen Items
    819        void addTo(Pawn* player);
    9         void removeFrom(Pawn* player);
    10         string getPlayerBaseClass();
    11         Item( BaseObject* creator);
    12         ~Item();
     20
     21        inline void setPlayerBaseClass(Identifier* identifier)
     22                { this->playerBaseClass_ = identifier; }
     23        inline Identifier* getPlayerBaseClass() const
     24                { return this->playerBaseClass_; }
    1325       
    1426        private:
    15         Identifier* PlayerBaseClass; //class(...)
    16        
    17        
    18         }
     27        void setPlayerBaseClassName(const std::string& name);
     28        const std::string& getPlayerBaseClassName() const;
     29
     30        Identifier* playerBaseClass_; //class(...)
     31        };
    1932}
    2033       
     34#endif /* _Item_H__ */
  • code/branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc

    r2202 r2227  
    11#include "PickupSpawner.h"
     2#include "Item.h"
     3#include "objects/worldentities/pawns/Pawn.h"
     4#include "objects/worldentities/triggers/DistanceTrigger.h"
    25#include "core/CoreIncludes.h"
     6#include "core/XMLPort.h"
    37#include "core/Template.h"
    48
     
    1216
    1317        this->template_ = 0;
     18        this->distance_ = 50;
     19}
     20
     21PickupSpawner::~PickupSpawner()
     22{
     23}
     24
     25void PickupSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     26{
     27        SUPER(PickupSpawner, XMLPort, xmlelement, mode);
     28
     29        XMLPortParam(PickupSpawner, "item", setItemTemplate, getItemTemplate, xmlelement, mode);
     30        XMLPortParam(PickupSpawner, "distance", setDistance, getDistance, xmlelement, mode).defaultValues(50.0f);
     31}
     32
     33void PickupSpawner::tick(float dt)
     34{
     35  if (this->isActive())
     36  {
     37    for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
     38    {
     39      Vector3 distanceVec = it->getWorldPosition() - this->getWorldPosition();
     40      if (distanceVec.length() < this->distance_)
     41        this->triggering(*it);
     42    }
     43  }
    1444}
    1545
     
    2050}
    2151
    22     void PickupSpawner::processEvent(Event& event)
    23     {
    24         SUPER(PickupSpawner, processEvent, event);
    25 
    26         SetSubclassEvent(PickupSpawner, "pickup", triggering, event, DistanceTrigger);
    27     }
    28 
    29 void activateSpawner(bool active)
     52void PickupSpawner::triggering(Pawn* player)
     53{
     54        if (this->isActive() && this->template_ && this->template_->getBaseclassIdentifier())
    3055        {
    31         if active=true
    32         this->isActive =true;
    33         else
    34         this->isActive = false;
    35         }
    36 
    37 void triggering(bool active, DistanceTrigger* trigger)
    38 {
    39         if (active= true && this->template_ && this->template_->getBaseclassIdentifier())
    40         {
    41                 Pawn* player = trigger->getPlayer(); // getPlayer muss noch implementiert werden
    42                 if(player->isA(itemtemplate_->getPlayerBaseClass()))
     56                COUT(0) << "activated" << std::endl;
     57                //if(player->isA(itemtemplate_->getPlayerBaseClass()))
    4358                {
    44                 BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate();
     59                BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate(this);
    4560                Item* newitem = dynamic_cast<Item*>(newobject);
    4661                if (newitem)
    47                 newitem->addTemplate(this->itemtemplate_);
    48                 newitem->pickedUp(player);
     62                {
     63                        newitem->addTemplate(this->itemtemplate_);
     64                        if (newitem->pickedUp(player)== true)
     65                                this->setActive(false);
     66                        else
     67                                delete newobject;
    4968                }
    50                 else
    51                         delete newobject;
    52                 activateSpawner(false);
     69                }
     70                //else
     71                //      delete newobject;
    5372        }
    5473}
  • code/branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.h

    r2202 r2227  
     1#ifndef _PickupSpawner_H__
     2#define _PickupSpawner_H__
    13
     4#include "OrxonoxPrereqs.h"
     5
     6#include "objects/worldentities/PositionableEntity.h"
     7#include "objects/Tickable.h"
    28
    39namespace orxonox
    410{
    5         class _OrxonoxExport PickupSpawner: public PositionableEnity
     11        class _OrxonoxExport PickupSpawner : public PositionableEntity, public Tickable
    612        {
    713        public:
     
    915        virtual ~PickupSpawner();
    1016
     17        virtual void tick(float dt);
     18
    1119        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    12         virtual void processEvent(Event& event);
    13         virtual void changedActivity();
    14         virtual void triggering(bool active, DistanceTrigger* trigger); // Wenn ein Spieler in die Naehe kommt
    15         void activateSpawner(bool active);
     20        virtual void triggering(Pawn* trigger); // Wenn ein Spieler in die Naehe kommt
    1621
    1722        void setItemTemplate(const std::string& itemtemplate);
    18         inline const sdt::string& getItemTemplate() const
     23        inline const std::string& getItemTemplate() const
    1924                { return this->itemtemplate_; }
     25
     26        inline void setDistance(float distance)
     27                { this->distance_ = distance; }
     28        inline float getDistance() const
     29                { return this->distance_; }
    2030       
    2131        private:
    2232        std::string itemtemplate_;
    2333        Template* template_;
    24         bool isActive;
    25         }
    26        
    27        
     34        float distance_;
     35        };
     36}
     37
     38#endif /* _PickupSpawner_H__ */
    2839       
    2940
     
    4354
    4455
    45 }
  • code/branches/pickups2/src/orxonox/objects/pickup/ShipEquipmentClasses.h

    r2136 r2227  
    2323    {
    2424        public:
    25             void AddItem(Shipitem* toAddItem);
     25            /*void AddItem(Shipitem* toAddItem);
    2626            void RemoveItem(Shipitem* toRemoveItem);
    2727            bool CheckifValid(Shipitem* toBeChecked);
    2828            bool CheckifSpace();
    2929            void SwitchItem(Permanent* toSwitchItem);
    30             string GetNameofPermanent (subItemTypePermanent NametoGet); //holt den Namen des getragenen Items im jeweiligen Slot.
     30            string GetNameofPermanent (subItemTypePermanent NametoGet);*/ //holt den Namen des getragenen Items im jeweiligen Slot.
    3131
    3232        private:
    33             multimap<std::string, ShipItem*> Equipment;
    34             multimap<std::string, ShipItem*> Usable;
    35             multimap<std::string, ShipItem*> Trunk;
     33            multimap<std::string, Item*> Equipment;
     34            multimap<std::string, Item*> Usable;
     35            multimap<std::string, Item*> Trunk;
    3636    };
    3737}
  • code/branches/pickups2/src/orxonox/objects/pickup/Turbo.cc

    r2202 r2227  
     1#include "Turbo.h"
     2
     3#include "objects/worldentities/pawns/SpaceShip.h"
    14#include "core/Executor.h"
     5#include "core/CoreIncludes.h"
     6#include "core/XMLPort.h"
    27
    38namespace orxonox
    49{
     10       
    511
    6         bool pickedUp(Pawn* player)
     12        CreateFactory(Turbo);
     13
     14        Turbo::Turbo(BaseObject* creator) : Item(creator)
    715        {
    8                 if(player-> isA(playerBaseClass))
     16                RegisterObject(Turbo);
     17
     18                this->boost_ = 0;
     19                this->duration_ = 0;
     20                this->accboost_ = 1;
     21        }
     22
     23        Turbo::~Turbo()
     24        {
     25        }
     26
     27    void Turbo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     28    {
     29        SUPER(Turbo, XMLPort, xmlelement, mode);
     30
     31        XMLPortParam(Turbo, "boost", setBoost, getBoost, xmlelement, mode);
     32        XMLPortParam(Turbo, "duration", setDuration, getDuration, xmlelement, mode);
     33        XMLPortParam(Turbo, "accboost", setAccBoost, getAccBoost, xmlelement, mode);
     34    }
     35
     36        bool Turbo::pickedUp(Pawn* player)
     37        {
     38                if(player-> isA(this->getPlayerBaseClass()))
    939                        {
    10                         Spaceship* ship = dynamic_cast <SpaceShip*>(player);
    11                         setSpeedBoost(this->boost, this->duration, Spaceship* ship)
     40                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
     41                        this->setSpeedBoost(ship);
     42                        if(duration_==0)
     43                        addTo(player);
    1244                        return true;
    1345                        }
     
    1749       
    1850       
    19         void unsetSpeedBoost(int boost, Spaceship* ship)
     51        void Turbo::unsetSpeedBoost(SpaceShip* ship)
    2052        {
    21         ship->setMaxSpeed( ship->getMaxSpeed() - boost);
    22         ship->setTransAcc( ship->getTransAcc()/ACCBOOST);
     53        ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_);
     54        ship->setTransAcc( ship->getTransAcc()/this->accboost_);
     55        COUT(3)<<"PickUp Timer expired"<<std::endl;
    2356        }
    2457
    25         void setSpeedBoost(float boost, float duration, Spaceship* ship)
     58        void Turbo::setSpeedBoost(SpaceShip* ship)
    2659        {
    27         const float ACCBOOST =1.5
    28         ship->setMaxSpeed( ship->getMaxSpeed() + boost);
    29         ship->setTransAcc( ship->getTransAcc()*ACCBOOST);
    30 
    31         turbotimer_.setTimer(duration, false, this, createExecutor(createFunctor(&Turbo::unsetSpeedBoost)))
     60        ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_);
     61        ship->setTransAcc( ship->getTransAcc()*this->accboost_);
     62        if( this->duration_ != 0)
     63        {
     64                ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost));
     65                executor->setDefaultValues(ship);
     66                turbotimer_.setTimer(this->duration_, false, this, executor);
     67        }
    3268       
    3369        }
    34        
     70        bool Turbo::dropped(Pawn* player)
     71        {
     72                if (this->duration_ == 0)
     73                {
     74                        //player->Equipment.erase ( std::pair<std::string, Item*>(this->itemname,this) );
     75                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
     76                        this->unsetSpeedBoost(ship);
     77                }
     78                return true;
     79        }
    3580       
    3681}
     82/*<Template baseclass="Turbo" name=turboitem>
     83      <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 />
     84    </Template>
     85
     86    <PickupSpawner item=turboitem>
     87      <attached>
     88        <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" />
     89      </attached>
     90    </PickupSpawner>*/
     91
    3792       
    3893       
    3994       
    4095       
    41        
  • code/branches/pickups2/src/orxonox/objects/pickup/Turbo.h

    r2202 r2227  
     1#ifndef _Turbo_H__
     2#define _Turbo_H__
     3
    14#include "tools/Timer.h"
     5#include "Item.h"
     6#include "OrxonoxPrereqs.h"
    27
    38namespace orxonox
    49{
    5         class _OrxonoxExport Turbo: public Item
     10        class _OrxonoxExport Turbo : public Item
    611        {
    712       
    813        public:
    9         void setSpeedBoost(int boost, float duration, Spaceship* ship)
    10         void unsetSpeedBoost(int boost, Spaceship* ship)
     14        Turbo(BaseObject* creator);
     15        virtual ~Turbo();
     16
     17        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     18
     19        virtual bool pickedUp(Pawn* player);
     20        virtual bool dropped(Pawn* player); //erst bei festen Items
     21
     22        void setSpeedBoost(SpaceShip* ship);
     23        void unsetSpeedBoost(SpaceShip* ship);
     24
     25        inline void setBoost(float boost)
     26                { this->boost_ = boost; }
     27        inline float getBoost() const
     28                { return this->boost_; }
     29
     30        inline void setDuration(float duration)
     31                { this->duration_ = duration; }
     32        inline float getDuration() const
     33                { return this->duration_; }
     34
     35       
     36        inline void setAccBoost(float accboost)
     37                { this->accboost_ = accboost; }
     38        inline float getAccBoost() const
     39                { return this->accboost_; }
     40
    1141        private:
    1242        Timer<Turbo> turbotimer_;
    13         float boost;
    14         float duration;
    15         }
     43        float boost_;
     44        float duration_;
     45        float accboost_;
     46        };
    1647}
     48
     49#endif /* _Turbo_H__ */
Note: See TracChangeset for help on using the changeset viewer.