Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/dockingsystem2/src/modules/docking/Dock.cc @ 8340

Last change on this file since 8340 was 8257, checked in by sven, 14 years ago

First working dock example..

File size: 3.9 KB
RevLine 
[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
40namespace 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    {
[8186]75        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
76        Pawn* pawn = NULL;
77
[8188]78        // Check whether it is a player trigger and extract pawn from it
[8186]79        if(pTrigger != NULL)
80        {
[8188]81            if(!pTrigger->isForPlayer()) {  // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
[8192]82                COUT(0) << "Docking:execute PlayerTrigger was not triggered by a player.." << std::endl;
[8186]83                return false;
[8188]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;
[8186]89        }
90        if(pawn == NULL)
91        {
[8192]92            COUT(0) << "Docking::execute Can't retrieve Pawn from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
[8186]93            return false;
94        }
95
96        // Extract the PlayerInfo from the Pawn.
97        PlayerInfo* player = pawn->getPlayer();
98        if(player == NULL)
99        {
[8188]100            COUT(0) << "The PlayerInfo* is NULL." << std::endl;
[8186]101            return false;
102        }
103
[8257]104        COUT(0) << "Dock triggered by player: " << player->getName() << ".." << std::endl;
[8188]105
[8185]106        if(bTriggered) {
[8186]107            DockingEffect::invokeEffect(docking::DOCKING, player, effects_);
[8257]108            DockingEffect::invokeEffect(docking::ATTACH, player, effects_);
[8185]109        } else {
[8186]110            DockingEffect::invokeEffect(docking::RELEASE, player, effects_);
[8185]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;
[8151]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;
[8185]133    }
[8137]134}
Note: See TracBrowser for help on using the repository browser.