Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spaceraceTwo/src/modules/gametypes/RaceCheckPoint.cc @ 8921

Last change on this file since 8921 was 8921, checked in by eceline, 13 years ago

vectors to store the next checkpoints

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