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 | * Sven Stucki |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file Dock.cc |
---|
31 | @brief Docking system main class |
---|
32 | */ |
---|
33 | |
---|
34 | #include "Dock.h" |
---|
35 | |
---|
36 | |
---|
37 | namespace orxonox |
---|
38 | { |
---|
39 | CreateFactory(Dock); |
---|
40 | |
---|
41 | Dock::Dock(BaseObject* creator) : StaticEntity(creator) |
---|
42 | { |
---|
43 | RegisterObject(Dock); |
---|
44 | COUT(0) << "Registering dock..." << std::endl; |
---|
45 | } |
---|
46 | |
---|
47 | Dock::~Dock() |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | void Dock::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
53 | { |
---|
54 | SUPER(Dock, XMLPort, xmlelement, mode); |
---|
55 | |
---|
56 | XMLPortObject(Dock, DockingEffect, "effects", addEffect, getEffect, xmlelement, mode); |
---|
57 | XMLPortEventSink(Dock, BaseObject, "execute", execute, xmlelement, mode); |
---|
58 | |
---|
59 | COUT(0) << "Dock created.." << std::endl; |
---|
60 | } |
---|
61 | |
---|
62 | void Dock::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
63 | { |
---|
64 | SUPER(Dock, XMLEventPort, xmlelement, mode); |
---|
65 | |
---|
66 | XMLPortEventSink(Dock, BaseObject, "execute", execute, xmlelement, mode); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | bool Dock::execute(bool bTriggered, BaseObject* trigger) |
---|
71 | { |
---|
72 | COUT(0) << "Dock executed (bTriggered = " << (bTriggered? "true":"false") << ").." << std::endl; |
---|
73 | |
---|
74 | //TODO: Handle MultiDistanceTrigger |
---|
75 | |
---|
76 | //TODO: This way too oversimplified |
---|
77 | if(bTriggered) { |
---|
78 | DockingEffect::invokeEffect(docking::DOCKING, NULL, effects_); |
---|
79 | DockingEffect::invokeEffect(docking::ATTACH, NULL, effects_); |
---|
80 | } else { |
---|
81 | DockingEffect::invokeEffect(docking::RELEASE, NULL, effects_); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | return true; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | bool Dock::addEffect(DockingEffect* effect) { |
---|
90 | assert(effect); |
---|
91 | effects_.push_back(effect); |
---|
92 | return true; |
---|
93 | } |
---|
94 | |
---|
95 | const DockingEffect* Dock::getEffect(unsigned int index) const { |
---|
96 | int i = index; |
---|
97 | for (std::list<DockingEffect*>::const_iterator effect = this->effects_.begin(); effect != this->effects_.end(); ++effect) |
---|
98 | { |
---|
99 | if(i == 0) |
---|
100 | return *effect; |
---|
101 | |
---|
102 | i--; |
---|
103 | } |
---|
104 | return NULL; |
---|
105 | } |
---|
106 | } |
---|