Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem5/src/orxonox/objects/pickup/PickupSpawner.cc @ 3003

Last change on this file since 3003 was 2908, checked in by dafrick, 16 years ago

Reverted to revision 2906 (because I'm too stupid to merge correctly, 2nd try will follow shortly. ;))

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1#include "OrxonoxStableHeaders.h"
2#include "PickupSpawner.h"
3#include "BaseItem.h"
4#include "objects/worldentities/pawns/Pawn.h"
5#include "objects/worldentities/triggers/DistanceTrigger.h"
6#include "core/CoreIncludes.h"
7#include "core/XMLPort.h"
8#include "core/Template.h"
9
10namespace orxonox
11{
12CreateFactory(PickupSpawner);
13
14PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator)
15{
16        RegisterObject(PickupSpawner);
17
18        this->template_ = 0;
19        this->distance_ = 20;
20        this->respawntimer_= 0;
21}
22
23PickupSpawner::~PickupSpawner()
24{
25}
26
27void PickupSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode)
28{
29        SUPER(PickupSpawner, XMLPort, xmlelement, mode);
30
31        XMLPortParam(PickupSpawner, "item", setItemTemplate, getItemTemplate, xmlelement, mode);
32        XMLPortParam(PickupSpawner, "distance", setDistance, getDistance, xmlelement, mode).defaultValues(20.0f);
33        XMLPortParam(PickupSpawner, "respawntimer", setRespawnTimer, getRespawnTimer, xmlelement, mode);
34
35}
36
37void PickupSpawner::tick(float dt)
38{
39  if (this->isActive())
40  {
41    for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
42    {
43      Vector3 distanceVec = it->getWorldPosition() - this->getWorldPosition();
44      if (distanceVec.length() < this->distance_)
45        this->triggering(*it);
46    }
47  }
48}
49
50void PickupSpawner::setItemTemplate(const std::string& itemtemplate)
51{
52        this->itemtemplate_ = itemtemplate;
53        this->template_ = Template::getTemplate(itemtemplate);
54}
55
56void PickupSpawner::triggering(Pawn* player)
57{
58        if (this->isActive() && this->template_ && this->template_->getBaseclassIdentifier())
59        {
60                COUT(0) << "ITEM PICKED UP" << std::endl;
61                //if(player->isA(itemtemplate_->getPlayerBaseClass()))
62                {
63                BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate(this);
64                BaseItem* newitem = dynamic_cast<BaseItem*>(newobject);
65                if (newitem)
66                {
67                        newitem->addTemplate(this->itemtemplate_);
68                        if (newitem->pickedUp(player)== true)
69                        {
70                                if(respawntimer_!=0)
71                                        this->triggerRespawnTimer();
72                                this->setActive(false);
73                                this->fireEvent();
74                        }
75                        else
76                                delete newobject;
77                }
78                }
79                //else
80                //      delete newobject;
81        }
82}
83
84void PickupSpawner::triggerRespawnTimer()
85{
86
87        if(respawntimer_!=0)
88        {
89                ExecutorMember<BaseObject>* executor = createExecutor(createFunctor(&BaseObject::setActive));
90                executor->setDefaultValues(true);
91                RespawnTimer_.setTimer(this->respawntimer_, false, (BaseObject*)this, executor);
92                COUT(0) << "TIMER SET" << std::endl;
93        }
94}
95void PickupSpawner::changedActivity()
96{
97/*
98        COUT(0) << "Visble?" << std::endl;
99        if(isActive())
100        {
101                setVisible(true);
102                COUT(0) << "Visble!" << std::endl;
103        }
104        if(isActive()==false)
105        {
106                setVisible(false);
107                COUT(0) << "INvisble!" << std::endl;
108        }
109
110*/
111        SUPER(PickupSpawner, changedActivity);
112
113        for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); ++it)
114                (*it)->setVisible(this->isActive());
115}
116
117
118}
119
120
121
Note: See TracBrowser for help on using the repository browser.