Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/modules/objects/triggers/CheckPoint.cc @ 7579

Last change on this file since 7579 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
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 *      Aurelian Jaggi
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "CheckPoint.h"
30
31#include "core/CoreIncludes.h"
32#include "core/XMLPort.h"
33#include "gametypes/Asteroids.h"
34#include "worldentities/pawns/Pawn.h"
35
36namespace orxonox
37{
38    CreateFactory(CheckPoint);
39
40    CheckPoint::CheckPoint(BaseObject* creator)
41        : DistanceTrigger(creator)
42        , RadarViewable(creator, static_cast<WorldEntity*>(this))
43    {
44        RegisterObject(CheckPoint);
45
46        this->setStayActive(true);
47        this->setDistance(50);
48        this->bIsFirst_ = false;
49        this->bIsDestination_ = false;
50
51        this->setRadarObjectColour(ColourValue::Green);
52        this->setRadarObjectShape(RadarViewable::Dot);
53        this->setRadarVisibility(false);
54
55        this->notifyMaskUpdate();
56    }
57
58    CheckPoint::~CheckPoint()
59    {
60    }
61
62    void CheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
63    {
64        SUPER(CheckPoint, XMLPort, xmlelement, mode);
65
66        XMLPortParam(CheckPoint, "isfirst", setFirst, getFirst, xmlelement, mode).defaultValues(false);
67        XMLPortParam(CheckPoint, "isdestination", setDestination, getDestination, xmlelement, mode).defaultValues(false);
68        XMLPortParam(CheckPoint, "addtime", setAddTime, getAddTime, xmlelement, mode).defaultValues(30);
69    }
70
71    void CheckPoint::changedActivity()
72    {
73        SUPER(CheckPoint, changedActivity);
74
75        if (this->BaseObject::isActive())
76        {
77            this->setRadarVisibility(true);
78        }
79        else
80        {
81            this->setRadarVisibility(false);
82        }
83    }
84
85    void CheckPoint::triggered(bool bIsTriggered)
86    {
87        DistanceTrigger::triggered(bIsTriggered);
88
89        Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype().get());
90        if (gametype)
91        {
92            gametype->addTime(addTime_);
93            this->setRadarVisibility(false);
94
95            if (bIsTriggered)
96            {
97                if (bIsFirst_)
98                {
99                    gametype->setTimeLimit(addTime_);
100                    gametype->firstCheckpointReached(true);
101                }
102
103                if (bIsDestination_)
104                {
105                    const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage("Congratulations - you have won the match!");
106                    gametype->end();
107                }
108
109                if (!bIsFirst_ && !bIsDestination_)
110                {
111                    const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage("Checkpoint reached");
112                }
113            }
114        }
115    }
116
117    void CheckPoint::notifyMaskUpdate()
118    {
119        this->targetMask_.exclude(Class(BaseObject));
120        this->targetMask_.include(Class(Pawn));
121    }
122}
Note: See TracBrowser for help on using the repository browser.