Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/gametypes/RaceCheckPoint.cc @ 8706

Last change on this file since 8706 was 8706, checked in by dafrick, 13 years ago

Merging presentation branch back into trunk.
There are many new features and also a lot of other changes and bugfixes, if you want to know, digg through the svn log.
Not everything is yet working as it should, but it should be fairly stable. If you habe any bug reports, just send me an email.

  • Property svn:eol-style set to native
File size: 4.0 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 *      Mauro Salomon
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "RaceCheckPoint.h"
30
31#include "core/CoreIncludes.h"
32#include "core/XMLPort.h"
33#include "SpaceRace.h"
34#include "util/Convert.h"
35
36namespace orxonox
37{
38    CreateFactory(RaceCheckPoint);
39   
40    RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
41    {
42        RegisterObject(RaceCheckPoint);
43
44        this->bCheckpointIndex_ = 0;
45        this->bIsLast_ = false;
46        this->bTimeLimit_ = 0;
47
48        this->setRadarObjectColour(ColourValue::Blue);
49        this->setRadarObjectShape(RadarViewable::Triangle);
50        this->setRadarVisibility(false);
51    }
52   
53    RaceCheckPoint::~RaceCheckPoint()
54    {
55    }
56   
57    void RaceCheckPoint::tick(float dt)
58    {
59        SUPER(RaceCheckPoint, tick, dt);
60
61        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
62        if (this->getCheckpointIndex() == gametype->getCheckpointsReached())
63            this->setRadarVisibility(true);
64        else
65            this->setRadarVisibility(false);
66    }
67
68   
69    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
70    {
71        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
72
73        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
74        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
75        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
76    }
77   
78    void RaceCheckPoint::triggered(bool bIsTriggered)
79    {
80        DistanceTrigger::triggered(bIsTriggered);
81
82        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
83        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
84        {
85            gametype->clock_.capture();
86            float time = gametype->clock_.getSecondsPrecise();
87            if (this->bTimeLimit_!=0 && time > this->bTimeLimit_)
88            {
89                gametype->timeIsUp();
90                gametype->end();
91            }
92            else if (this->getLast())
93                gametype->end();
94            else
95            {
96                gametype->newCheckpointReached();
97                this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
98            }
99        }
100    }
101   
102    void RaceCheckPoint::setTimelimit(float timeLimit)
103    {
104        this->bTimeLimit_ = timeLimit;
105        if (this->bTimeLimit_ != 0)
106        {
107            SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
108            if (gametype)
109            {
110                const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
111                            + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1) + "\n";
112                COUT(3) << message;
113                const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
114            }
115        }
116    }
117   
118}
Note: See TracBrowser for help on using the repository browser.