Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/pickup/PickupSpawner.cc @ 2898

Last change on this file since 2898 was 2896, checked in by landauf, 16 years ago

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

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