Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc @ 2274

Last change on this file since 2274 was 2227, checked in by dsommer, 16 years ago

Turbo funktioniert

File size: 1.9 KB
Line 
1#include "PickupSpawner.h"
2#include "Item.h"
3#include "objects/worldentities/pawns/Pawn.h"
4#include "objects/worldentities/triggers/DistanceTrigger.h"
5#include "core/CoreIncludes.h"
6#include "core/XMLPort.h"
7#include "core/Template.h"
8
9namespace orxonox
10{
11CreateFactory(PickupSpawner);
12
13PickupSpawner::PickupSpawner(BaseObject* creator) : PositionableEntity(creator)
14{
15        RegisterObject(PickupSpawner);
16
17        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  }
44}
45
46void PickupSpawner::setItemTemplate(const std::string& itemtemplate)
47{
48        this->itemtemplate_ = itemtemplate;
49        this->template_ = Template::getTemplate(itemtemplate);
50}
51
52void PickupSpawner::triggering(Pawn* player)
53{
54        if (this->isActive() && this->template_ && this->template_->getBaseclassIdentifier())
55        {
56                COUT(0) << "activated" << std::endl;
57                //if(player->isA(itemtemplate_->getPlayerBaseClass()))
58                {
59                BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate(this);
60                Item* newitem = dynamic_cast<Item*>(newobject);
61                if (newitem)
62                {
63                        newitem->addTemplate(this->itemtemplate_);
64                        if (newitem->pickedUp(player)== true)
65                                this->setActive(false);
66                        else
67                                delete newobject;
68                }
69                }
70                //else
71                //      delete newobject;
72        }
73}
74}
Note: See TracBrowser for help on using the repository browser.