Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/orxonox/objects/worldentities/triggers/CheckPoint.cc @ 3177

Last change on this file since 3177 was 3110, checked in by rgrieder, 16 years ago

Removed old msvc specific support for precompiled header files.

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