Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

level Spacerace2

  • Property svn:eol-style set to native
File size: 5.0 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;
[8940]47        //this->bIsLast_ = false;
[8630]48        this->bTimeLimit_ = 0;
[8934]49        this->isVisible_=false;
[8630]50
51        this->setRadarObjectColour(ColourValue::Blue);
[8616]52        this->setRadarObjectShape(RadarViewable::Triangle);
[8494]53        this->setRadarVisibility(false);
54    }
[8767]55
[8494]56    RaceCheckPoint::~RaceCheckPoint()
57    {
[8915]58         //if (this->isInitialized())
59        {
60            //for (size_t i = 0; i < this->nextcheckpoints_.size(); ++i)
61              //  this->nextcheckpoints_[i]->destroy();
62        }
[8928]63       //nextcheckpoints_.destroy;
[8494]64    }
[8767]65
[8494]66    void RaceCheckPoint::tick(float dt)
67    {
[8630]68        SUPER(RaceCheckPoint, tick, dt);
69
70        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
[8767]71        assert(gametype);
[8934]72        if(this->isVisible_){this->setRadarVisibility(true);}
73        else{this->setRadarVisibility(false);}
74        /*this->setRadarVisibility(false);
[8928]75        Vector3 v =Vector3(0,0,0);
76        int j=0;
77        for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
78        {
79                j=gametype->getCheckpointReached(it->first);
80                RaceCheckPoint* r=SpaceRaceManager::getCheckpoint(j);
81                v=r->getNextcheckpoint();
82                for(int i=1;i<4;i++){
83                if (this->getCheckpointIndex() == v[i])
84                 this->setRadarVisibility(true);
[8934]85                 }*/
86        //}     
[8494]87    }
88
89    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
90    {
[8630]91        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
[8940]92        Vector3 v= Vector3(0,0,0);
[8630]93        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
94        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
95        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
[8940]96    XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&).defaultValues(v);
[8494]97    }
[8767]98
[8934]99        void RaceCheckPoint::triggered(bool bIsTriggered, PlayerInfo* player)
[8494]100    {
[8630]101        DistanceTrigger::triggered(bIsTriggered);
102
103        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
[8940]104        assert(gametype);
[8928]105        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointReached(player) && bIsTriggered)
[8630]106        {
107            gametype->clock_.capture();
108            float time = gametype->clock_.getSecondsPrecise();
109            if (this->bTimeLimit_!=0 && time > this->bTimeLimit_)
110            {
111                gametype->timeIsUp();
112                gametype->end();
113            }
114            else if (this->getLast())
115                gametype->end();
116            else
117            {
[8940]118                gametype->newCheckpointReached(this,player);
[8630]119                this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
120            }
121        }
[8494]122    }
[8767]123
[8616]124    void RaceCheckPoint::setTimelimit(float timeLimit)
[8630]125    {
126        this->bTimeLimit_ = timeLimit;
127        if (this->bTimeLimit_ != 0)
128        {
129            SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
[8940]130            assert(gametype);
[8630]131            if (gametype)
132            {
133                const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
[8858]134                            + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1);
[8630]135                const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
[8858]136                ChatManager::message(message);
[8630]137            }
138        }
139    }
[8767]140
[8494]141}
Note: See TracBrowser for help on using the repository browser.