Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc @ 8381

Last change on this file since 8381 was 8381, checked in by ssgier, 13 years ago

started creating a more efficient code structure

File size: 2.4 KB
Line 
1#include "ShrinkPickup.h"
2
3#include <sstream>
4#include "core/CoreIncludes.h"
5#include "core/XMLPort.h"
6
7#include "pickup/PickupIdentifier.h"
8#include "worldentities/pawns/Pawn.h"
9
10#include "weaponsystem/WeaponSlot.h"
11#include "weaponsystem/Weapon.h"
12
13namespace orxonox
14{
15    CreateFactory(ShrinkPickup);
16
17    ShrinkPickup::ShrinkPickup(BaseObject* creator) : Pickup(creator)
18    {
19        RegisterObject(ShrinkPickup);
20
21        this->initialize();
22    }
23
24    ShrinkPickup::~ShrinkPickup()
25    {
26
27    }
28
29        void ShrinkPickup::initialize(void)
30        {
31                this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
32        }
33
34    void ShrinkPickup::changedUsed(void)
35        {
36                SUPER(ShrinkPickup, changedUsed);
37
38        if(this->isUsed())
39        {
40            this->pawn = this->carrierToPawnHelper();
41            if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
42                this->Pickupable::destroy();
43       
44                        COUT(0) << "shrinking..." << endl;
45                        //this->pawn->setScale3D(this->pawn->getScale3D() / 2.0);
46                        std::set<WorldEntity*> set = this->pawn->getAttachedObjects();
47                        for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++)
48                        {
49                                (*it)->setScale((*it)->getScale() / 5.0);
50                                (*it)->setPosition((*it)->getPosition() / 5.0);
51                        }
52                       
53                        durationTimer.setTimer(10, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));
54        }
55                else
56        {
57                        this->Pickupable::destroy();
58        }
59        }
60
61        void ShrinkPickup::terminate(void)
62        {
63                //this->pawn->setScale3D(this->pawn->getScale3D() * 5.0);
64
65                std::set<WorldEntity*> set = this->pawn->getAttachedObjects();
66                for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++)
67                {
68                        (*it)->setScale((*it)->getScale() * 5.0);
69                }               
70                setUsed(false);
71        }
72
73    Pawn* ShrinkPickup::carrierToPawnHelper(void)
74    {
75        PickupCarrier* carrier = this->getCarrier();
76        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
77
78        if(pawn == NULL)
79        {
80            COUT(1) << "Invalid PickupCarrier in ShrinkPickup." << std::endl;
81        }
82
83        return pawn;
84    }
85
86        /**
87    @brief
88        Creates a duplicate of the input OrxonoxClass.
89    @param item
90        A pointer to the Orxonox class.
91    */
92    void ShrinkPickup::clone(OrxonoxClass*& item)
93    {
94        if(item == NULL)
95            item = new ShrinkPickup(this);
96
97        SUPER(ShrinkPickup, clone, item);
98    }
99}
Note: See TracBrowser for help on using the repository browser.