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
RevLine 
[2202]1#include "PickupSpawner.h"
[2227]2#include "Item.h"
3#include "objects/worldentities/pawns/Pawn.h"
4#include "objects/worldentities/triggers/DistanceTrigger.h"
[2202]5#include "core/CoreIncludes.h"
[2227]6#include "core/XMLPort.h"
[2202]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;
[2227]18        this->distance_ = 50;
[2202]19}
20
[2227]21PickupSpawner::~PickupSpawner()
[2202]22{
23}
24
[2227]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)
[2202]38    {
[2227]39      Vector3 distanceVec = it->getWorldPosition() - this->getWorldPosition();
40      if (distanceVec.length() < this->distance_)
41        this->triggering(*it);
[2202]42    }
[2227]43  }
44}
[2202]45
[2227]46void PickupSpawner::setItemTemplate(const std::string& itemtemplate)
47{
48        this->itemtemplate_ = itemtemplate;
49        this->template_ = Template::getTemplate(itemtemplate);
50}
[2202]51
[2227]52void PickupSpawner::triggering(Pawn* player)
[2202]53{
[2227]54        if (this->isActive() && this->template_ && this->template_->getBaseclassIdentifier())
[2202]55        {
[2227]56                COUT(0) << "activated" << std::endl;
57                //if(player->isA(itemtemplate_->getPlayerBaseClass()))
[2202]58                {
[2227]59                BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate(this);
[2202]60                Item* newitem = dynamic_cast<Item*>(newobject);
61                if (newitem)
[2227]62                {
63                        newitem->addTemplate(this->itemtemplate_);
64                        if (newitem->pickedUp(player)== true)
65                                this->setActive(false);
66                        else
67                                delete newobject;
[2202]68                }
[2227]69                }
70                //else
71                //      delete newobject;
[2202]72        }
73}
[2227]74}
Note: See TracBrowser for help on using the repository browser.