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 | #include "infos/HumanPlayer.h" |
---|
36 | #include "worldentities/pawns/Pawn.h" |
---|
37 | #include "interfaces/PlayerTrigger.h" |
---|
38 | |
---|
39 | |
---|
40 | namespace orxonox |
---|
41 | { |
---|
42 | CreateFactory(Dock); |
---|
43 | |
---|
44 | Dock::Dock(BaseObject* creator) : StaticEntity(creator) |
---|
45 | { |
---|
46 | RegisterObject(Dock); |
---|
47 | COUT(0) << "Registering dock..." << std::endl; |
---|
48 | } |
---|
49 | |
---|
50 | Dock::~Dock() |
---|
51 | { |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | void Dock::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
56 | { |
---|
57 | SUPER(Dock, XMLPort, xmlelement, mode); |
---|
58 | |
---|
59 | XMLPortObject(Dock, DockingEffect, "effects", addEffect, getEffect, xmlelement, mode); |
---|
60 | XMLPortEventSink(Dock, BaseObject, "execute", execute, xmlelement, mode); |
---|
61 | |
---|
62 | COUT(0) << "Dock created.." << std::endl; |
---|
63 | } |
---|
64 | |
---|
65 | void Dock::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
66 | { |
---|
67 | SUPER(Dock, XMLEventPort, xmlelement, mode); |
---|
68 | |
---|
69 | XMLPortEventSink(Dock, BaseObject, "execute", execute, xmlelement, mode); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | bool Dock::execute(bool bTriggered, BaseObject* trigger) |
---|
74 | { |
---|
75 | PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger); |
---|
76 | Pawn* pawn = NULL; |
---|
77 | |
---|
78 | // Check whether it is a player trigger and extract pawn from it |
---|
79 | if(pTrigger != NULL) |
---|
80 | { |
---|
81 | if(!pTrigger->isForPlayer()) { // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one. |
---|
82 | COUT(0) << "Docking:execute PlayerTrigger was not triggered by a player.." << std::endl; |
---|
83 | return false; |
---|
84 | } |
---|
85 | pawn = pTrigger->getTriggeringPlayer(); |
---|
86 | } else { |
---|
87 | COUT(0) << "Docking::execute Not a player trigger, can't extract pawn from it.." << std::endl; |
---|
88 | return false; |
---|
89 | } |
---|
90 | if(pawn == NULL) |
---|
91 | { |
---|
92 | COUT(0) << "Docking::execute Can't retrieve Pawn from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl; |
---|
93 | return false; |
---|
94 | } |
---|
95 | |
---|
96 | // Extract the PlayerInfo from the Pawn. |
---|
97 | PlayerInfo* player = pawn->getPlayer(); |
---|
98 | if(player == NULL) |
---|
99 | { |
---|
100 | COUT(0) << "The PlayerInfo* is NULL." << std::endl; |
---|
101 | return false; |
---|
102 | } |
---|
103 | |
---|
104 | COUT(0) << "Dock triggered by player: " << player->getName() << ".." << std::endl; |
---|
105 | |
---|
106 | if(bTriggered) { |
---|
107 | DockingEffect::invokeEffect(docking::DOCKING, player, effects_); |
---|
108 | DockingEffect::invokeEffect(docking::ATTACH, player, effects_); |
---|
109 | } else { |
---|
110 | DockingEffect::invokeEffect(docking::RELEASE, player, effects_); |
---|
111 | } |
---|
112 | |
---|
113 | return true; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | bool Dock::addEffect(DockingEffect* effect) { |
---|
118 | assert(effect); |
---|
119 | effects_.push_back(effect); |
---|
120 | return true; |
---|
121 | } |
---|
122 | |
---|
123 | const DockingEffect* Dock::getEffect(unsigned int index) const { |
---|
124 | int i = index; |
---|
125 | for (std::list<DockingEffect*>::const_iterator effect = this->effects_.begin(); effect != this->effects_.end(); ++effect) |
---|
126 | { |
---|
127 | if(i == 0) |
---|
128 | return *effect; |
---|
129 | |
---|
130 | i--; |
---|
131 | } |
---|
132 | return NULL; |
---|
133 | } |
---|
134 | } |
---|