Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9263 was 9263, checked in by landauf, 12 years ago

store the next checkpoints in a set instead of Vector3
+ some refactoring in SpaceRaceManager

  • Property svn:eol-style set to native
File size: 4.5 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
[9016]36#include <infos/PlayerInfo.h>
37#include <worldentities/ControllableEntity.h>
38
[8767]39#include "SpaceRace.h"
40
[8494]41namespace orxonox
42{
43    CreateFactory(RaceCheckPoint);
[8767]44
[9016]45    RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
[8494]46    {
[8630]47        RegisterObject(RaceCheckPoint);
[9260]48
[9016]49        this->setDistance(100);
50        this->setBeaconMode("off");
51        this->setBroadcast(false);
52        this->setSimultaneousTriggerers(100);
[8630]53
54        this->setRadarObjectColour(ColourValue::Blue);
[8616]55        this->setRadarObjectShape(RadarViewable::Triangle);
[8494]56        this->setRadarVisibility(false);
[9016]57        this->settingsChanged();
[9260]58
59        this->checkpointIndex_ = 0;
60        this->bIsLast_ = false;
61        this->timeLimit_ = 0;
62        this->player_ = NULL;
[8494]63    }
[8767]64
[9260]65
[9016]66   RaceCheckPoint::~RaceCheckPoint()
67   {
68   }
[8767]69
[8494]70    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
71    {
[8630]72        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
[9260]73
[8630]74        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
[9260]75        XMLPortParam(RaceCheckPoint, "islast", setLast, isLast, xmlelement, mode).defaultValues(false);
[8630]76        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
[9263]77        XMLPortParam(RaceCheckPoint, "nextcheckpoints", setNextCheckpointsAsVector3, getNextCheckpointsAsVector3, xmlelement, mode);
[8494]78    }
[8767]79
[9260]80    void RaceCheckPoint::fire(bool bIsTriggered, BaseObject* originator)
[8494]81    {
[9260]82        DistanceMultiTrigger::fire(bIsTriggered, originator);
83
84        if (bIsTriggered)
85        {
86            ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator);
87            if (entity)
88                this->player_ = entity->getPlayer();
89        }
[8494]90    }
[8767]91
[8616]92    void RaceCheckPoint::setTimelimit(float timeLimit)
[8630]93    {
[9260]94        this->timeLimit_ = timeLimit;
95        if (this->timeLimit_ != 0)
[8630]96        {
[9260]97            std::string message =  "You have " + multi_cast<std::string>(this->timeLimit_)
98                        + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
99            const_cast<GametypeInfo*>(this->getGametype()->getGametypeInfo())->sendAnnounceMessage(message);
100            ChatManager::message(message);
[8630]101        }
102    }
[9263]103
104    void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints)
105    {
106        this->nextCheckpoints_.clear();
107
108        if (checkpoints.x > -1)
109            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5));
110        if (checkpoints.y > -1)
111            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
112        if (checkpoints.z > -1)
113            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
114    }
115
116    Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const
117    {
118        Vector3 checkpoints = Vector3(-1, -1, -1);
119
120        size_t count = 0;
121        for (std::set<int>::iterator it = this->nextCheckpoints_.begin(); it != this->nextCheckpoints_.end(); ++it)
122        {
123            switch (count)
124            {
125                case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
126                case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
127                case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
128            }
129            ++count;
130        }
131
132        return checkpoints;
133    }
[8494]134}
Note: See TracBrowser for help on using the repository browser.