Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/objects/triggers/CheckPoint.cc @ 12106

Last change on this file since 12106 was 11071, checked in by landauf, 9 years ago

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