[8137] | 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" |
---|
[8192] | 35 | #include "infos/HumanPlayer.h" |
---|
[8186] | 36 | #include "worldentities/pawns/Pawn.h" |
---|
| 37 | #include "interfaces/PlayerTrigger.h" |
---|
[8137] | 38 | |
---|
| 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
[8185] | 42 | CreateFactory(Dock); |
---|
[8137] | 43 | |
---|
| 44 | Dock::Dock(BaseObject* creator) : StaticEntity(creator) |
---|
| 45 | { |
---|
| 46 | RegisterObject(Dock); |
---|
[8185] | 47 | COUT(0) << "Registering dock..." << std::endl; |
---|
[8137] | 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 | |
---|
[8151] | 59 | XMLPortObject(Dock, DockingEffect, "effects", addEffect, getEffect, xmlelement, mode); |
---|
[8137] | 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) |
---|
[8185] | 74 | { |
---|
[8192] | 75 | //TODO: Handle DistanceMultiTrigger |
---|
[8137] | 76 | |
---|
[8186] | 77 | PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger); |
---|
| 78 | Pawn* pawn = NULL; |
---|
| 79 | |
---|
[8188] | 80 | // Check whether it is a player trigger and extract pawn from it |
---|
[8186] | 81 | if(pTrigger != NULL) |
---|
| 82 | { |
---|
[8188] | 83 | if(!pTrigger->isForPlayer()) { // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one. |
---|
[8192] | 84 | COUT(0) << "Docking:execute PlayerTrigger was not triggered by a player.." << std::endl; |
---|
[8186] | 85 | return false; |
---|
[8188] | 86 | } |
---|
| 87 | pawn = pTrigger->getTriggeringPlayer(); |
---|
| 88 | } else { |
---|
| 89 | COUT(0) << "Docking::execute Not a player trigger, can't extract pawn from it.." << std::endl; |
---|
| 90 | return false; |
---|
[8186] | 91 | } |
---|
| 92 | if(pawn == NULL) |
---|
| 93 | { |
---|
[8192] | 94 | COUT(0) << "Docking::execute Can't retrieve Pawn from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl; |
---|
[8186] | 95 | return false; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | // Extract the PlayerInfo from the Pawn. |
---|
| 99 | PlayerInfo* player = pawn->getPlayer(); |
---|
| 100 | if(player == NULL) |
---|
| 101 | { |
---|
[8188] | 102 | COUT(0) << "The PlayerInfo* is NULL." << std::endl; |
---|
[8186] | 103 | return false; |
---|
| 104 | } |
---|
| 105 | |
---|
[8188] | 106 | // Try to get HumanPlayer |
---|
[8192] | 107 | if(!player->isHumanPlayer()) { |
---|
[8188] | 108 | COUT(0) << "Docking::execute Not triggered by a human." << std::endl; |
---|
| 109 | return false; |
---|
| 110 | } |
---|
[8192] | 111 | HumanPlayer* human = orxonox_cast<HumanPlayer*>(player); |
---|
| 112 | if(human == NULL) { |
---|
| 113 | COUT(0) << "Docking::execute Player was not as human as expected.." << std::endl; |
---|
| 114 | } |
---|
[8197] | 115 | COUT(0) << "Dock triggered by player: " << human->getName() << ".." << std::endl; |
---|
[8188] | 116 | |
---|
| 117 | //TODO: This is waaay too oversimplified |
---|
[8185] | 118 | if(bTriggered) { |
---|
[8186] | 119 | DockingEffect::invokeEffect(docking::DOCKING, player, effects_); |
---|
[8192] | 120 | //DockingEffect::invokeEffect(docking::ATTACH, player, effects_); |
---|
[8185] | 121 | } else { |
---|
[8186] | 122 | DockingEffect::invokeEffect(docking::RELEASE, player, effects_); |
---|
[8185] | 123 | } |
---|
| 124 | |
---|
| 125 | return true; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | bool Dock::addEffect(DockingEffect* effect) { |
---|
| 130 | assert(effect); |
---|
| 131 | effects_.push_back(effect); |
---|
| 132 | return true; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | const DockingEffect* Dock::getEffect(unsigned int index) const { |
---|
| 136 | int i = index; |
---|
[8151] | 137 | for (std::list<DockingEffect*>::const_iterator effect = this->effects_.begin(); effect != this->effects_.end(); ++effect) |
---|
| 138 | { |
---|
| 139 | if(i == 0) |
---|
| 140 | return *effect; |
---|
| 141 | |
---|
| 142 | i--; |
---|
| 143 | } |
---|
| 144 | return NULL; |
---|
[8185] | 145 | } |
---|
[8137] | 146 | } |
---|