Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/tutorialHS09/src/modules/objects/triggers/CheckPoint.cc @ 10022

Last change on this file since 10022 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

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