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
RevLine 
[8494]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
[8858]31#include "util/Convert.h"
[8494]32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
[8858]34#include "chat/ChatManager.h"
[8494]35
[8767]36#include "SpaceRace.h"
37
[8494]38namespace orxonox
39{
40    CreateFactory(RaceCheckPoint);
[8767]41
[8630]42    RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
[8494]43    {
[8630]44        RegisterObject(RaceCheckPoint);
45
46        this->bCheckpointIndex_ = 0;
47        this->bIsLast_ = false;
48        this->bTimeLimit_ = 0;
49
50        this->setRadarObjectColour(ColourValue::Blue);
[8616]51        this->setRadarObjectShape(RadarViewable::Triangle);
[8494]52        this->setRadarVisibility(false);
53    }
[8767]54
[8494]55    RaceCheckPoint::~RaceCheckPoint()
56    {
[8915]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();
[8494]63    }
[8767]64
[8494]65    void RaceCheckPoint::tick(float dt)
66    {
[8630]67        SUPER(RaceCheckPoint, tick, dt);
68
69        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
[8767]70        assert(gametype);
[8630]71        if (this->getCheckpointIndex() == gametype->getCheckpointsReached())
72            this->setRadarVisibility(true);
73        else
74            this->setRadarVisibility(false);
[8494]75    }
76
77    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
78    {
[8630]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);
[8921]84    //XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const std::vector<int>&);
[8494]85    }
[8767]86
[8494]87    void RaceCheckPoint::triggered(bool bIsTriggered)
88    {
[8630]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        }
[8494]109    }
[8767]110
[8616]111    void RaceCheckPoint::setTimelimit(float timeLimit)
[8630]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_)
[8858]120                            + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1);
[8630]121                const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
[8858]122                ChatManager::message(message);
[8630]123            }
124        }
125    }
[8767]126
[8494]127}
Note: See TracBrowser for help on using the repository browser.