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 | namespace orxonox |
---|
11 | { |
---|
12 | CreateFactory(ShrinkPickup); |
---|
13 | |
---|
14 | ShrinkPickup::ShrinkPickup(BaseObject* creator) : Pickup(creator) |
---|
15 | { |
---|
16 | RegisterObject(ShrinkPickup); |
---|
17 | |
---|
18 | this->initialize(); |
---|
19 | } |
---|
20 | |
---|
21 | ShrinkPickup::~ShrinkPickup() |
---|
22 | { |
---|
23 | |
---|
24 | } |
---|
25 | |
---|
26 | void ShrinkPickup::initialize(void) |
---|
27 | { |
---|
28 | this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); |
---|
29 | } |
---|
30 | |
---|
31 | void ShrinkPickup::changedUsed(void) |
---|
32 | { |
---|
33 | SUPER(ShrinkPickup, changedUsed); |
---|
34 | |
---|
35 | if(this->isUsed()) |
---|
36 | { |
---|
37 | this->pawn = this->carrierToPawnHelper(); |
---|
38 | if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. |
---|
39 | this->Pickupable::destroy(); |
---|
40 | |
---|
41 | COUT(0) << "shrinking..." << endl; |
---|
42 | std::set<WorldEntity*> set = this->pawn->getAttachedObjects(); |
---|
43 | for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++) |
---|
44 | { |
---|
45 | (*it)->setScale((*it)->getScale() / 5.0); |
---|
46 | } |
---|
47 | durationTimer.setTimer(10, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); |
---|
48 | } |
---|
49 | else |
---|
50 | { |
---|
51 | this->Pickupable::destroy(); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | void ShrinkPickup::terminate(void) |
---|
56 | { |
---|
57 | std::set<WorldEntity*> set = this->pawn->getAttachedObjects(); |
---|
58 | for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++) |
---|
59 | { |
---|
60 | (*it)->setScale((*it)->getScale() * 5.0); |
---|
61 | } |
---|
62 | setUsed(false); |
---|
63 | } |
---|
64 | |
---|
65 | Pawn* ShrinkPickup::carrierToPawnHelper(void) |
---|
66 | { |
---|
67 | PickupCarrier* carrier = this->getCarrier(); |
---|
68 | Pawn* pawn = dynamic_cast<Pawn*>(carrier); |
---|
69 | |
---|
70 | if(pawn == NULL) |
---|
71 | { |
---|
72 | COUT(1) << "Invalid PickupCarrier in ShrinkPickup." << std::endl; |
---|
73 | } |
---|
74 | |
---|
75 | return pawn; |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | @brief |
---|
80 | Creates a duplicate of the input OrxonoxClass. |
---|
81 | @param item |
---|
82 | A pointer to the Orxonox class. |
---|
83 | */ |
---|
84 | void ShrinkPickup::clone(OrxonoxClass*& item) |
---|
85 | { |
---|
86 | if(item == NULL) |
---|
87 | item = new ShrinkPickup(this); |
---|
88 | |
---|
89 | SUPER(ShrinkPickup, clone, item); |
---|
90 | } |
---|
91 | } |
---|