1 | #include "PickupSpawner.h" |
---|
2 | #include "core/CoreIncludes.h" |
---|
3 | #include "core/Template.h" |
---|
4 | |
---|
5 | namespace orxonox |
---|
6 | { |
---|
7 | CreateFactory(PickupSpawner); |
---|
8 | |
---|
9 | PickupSpawner::PickupSpawner(BaseObject* creator) : PositionableEntity(creator) |
---|
10 | { |
---|
11 | RegisterObject(PickupSpawner); |
---|
12 | |
---|
13 | this->template_ = 0; |
---|
14 | } |
---|
15 | |
---|
16 | void 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 | |
---|
29 | void activateSpawner(bool active) |
---|
30 | { |
---|
31 | if active=true |
---|
32 | this->isActive =true; |
---|
33 | else |
---|
34 | this->isActive = false; |
---|
35 | } |
---|
36 | |
---|
37 | void 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 | } |
---|