Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

PickupSpawner

File size: 1.3 KB
Line 
1#include "PickupSpawner.h"
2#include "core/CoreIncludes.h"
3#include "core/Template.h"
4
5namespace orxonox
6{
7CreateFactory(PickupSpawner);
8
9PickupSpawner::PickupSpawner(BaseObject* creator) : PositionableEntity(creator)
10{
11        RegisterObject(PickupSpawner);
12
13        this->template_ = 0;
14}
15
16void PickupSpawner::setItemTemplate(const std::string& itemtemplate)
17{
18        this->itemtemplate_ = itemtemplate;
19        this->template_ = Template::getTemplate(itemtemplate);
20}
21
22    void PickupSpawner::processEvent(Event& event)
23    {
24        SUPER(PickupSpawner, processEvent, event);
25
26        SetSubclassEvent(PickupSpawner, "pickup", triggering, event, DistanceTrigger);
27    }
28
29void activateSpawner(bool active)
30        {
31        if active=true
32        this->isActive =true;
33        else
34        this->isActive = false;
35        }
36
37void triggering(bool active, DistanceTrigger* trigger)
38{
39        if (active= true && this->template_ && this->template_->getBaseclassIdentifier())
40        {
41                Pawn* player = trigger->getPlayer(); // getPlayer muss noch implementiert werden
42                if(player->isA(itemtemplate_->getPlayerBaseClass())) 
43                {
44                BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate();
45                Item* newitem = dynamic_cast<Item*>(newobject);
46                if (newitem)
47                newitem->addTemplate(this->itemtemplate_);
48                newitem->pickedUp(player);
49                }
50                else
51                        delete newobject;
52                activateSpawner(false);
53        }
54}
55}
Note: See TracBrowser for help on using the repository browser.