1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "Attacher.h" |
---|
31 | |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | #include "core/XMLPort.h" |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | CreateFactory(Attacher); |
---|
38 | |
---|
39 | Attacher::Attacher(BaseObject* creator) : StaticEntity(creator) |
---|
40 | { |
---|
41 | RegisterObject(Attacher); |
---|
42 | |
---|
43 | this->target_ = 0; |
---|
44 | } |
---|
45 | |
---|
46 | void Attacher::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
47 | { |
---|
48 | SUPER(Attacher, XMLPort, xmlelement, mode); |
---|
49 | |
---|
50 | XMLPortParam(Attacher, "target", setTarget, getTarget, xmlelement, mode); |
---|
51 | XMLPortObject(Attacher, WorldEntity, "", addObject, getObject, xmlelement, mode); |
---|
52 | } |
---|
53 | |
---|
54 | void Attacher::processEvent(Event& event) |
---|
55 | { |
---|
56 | for (std::list<WorldEntity*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it) |
---|
57 | (*it)->fireEvent(event); |
---|
58 | } |
---|
59 | |
---|
60 | void Attacher::changedActivity() |
---|
61 | { |
---|
62 | SUPER(Attacher, changedActivity); |
---|
63 | |
---|
64 | for (std::list<WorldEntity*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it) |
---|
65 | (*it)->setActive(this->isActive()); |
---|
66 | } |
---|
67 | |
---|
68 | void Attacher::changedVisibility() |
---|
69 | { |
---|
70 | SUPER(Attacher, changedVisibility); |
---|
71 | |
---|
72 | for (std::list<WorldEntity*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it) |
---|
73 | (*it)->setVisible(this->isVisible()); |
---|
74 | } |
---|
75 | |
---|
76 | void Attacher::addObject(WorldEntity* object) |
---|
77 | { |
---|
78 | this->objects_.push_back(object); |
---|
79 | |
---|
80 | this->attach(object); |
---|
81 | } |
---|
82 | |
---|
83 | WorldEntity* Attacher::getObject(unsigned int index) const |
---|
84 | { |
---|
85 | unsigned int i = 0; |
---|
86 | for (std::list<WorldEntity*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it) |
---|
87 | { |
---|
88 | if (i == index) |
---|
89 | return (*it); |
---|
90 | |
---|
91 | ++i; |
---|
92 | } |
---|
93 | return 0; |
---|
94 | } |
---|
95 | |
---|
96 | void Attacher::setTarget(const std::string& target) |
---|
97 | { |
---|
98 | this->targetname_ = target; |
---|
99 | this->target_ = 0; |
---|
100 | |
---|
101 | if (this->targetname_ == "") |
---|
102 | return; |
---|
103 | |
---|
104 | for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it) |
---|
105 | if (it->getName() == this->targetname_) |
---|
106 | this->attachToParent(*it); |
---|
107 | } |
---|
108 | |
---|
109 | void Attacher::loadedNewXMLName(BaseObject* object) |
---|
110 | { |
---|
111 | if (this->target_ || this->targetname_ == "") |
---|
112 | return; |
---|
113 | |
---|
114 | WorldEntity* entity = dynamic_cast<WorldEntity*>(object); |
---|
115 | if (entity && entity->getName() == this->targetname_) |
---|
116 | { |
---|
117 | this->target_ = entity; |
---|
118 | this->attachToParent(entity); |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|