Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc @ 9451

Last change on this file since 9451 was 9451, checked in by purgham, 12 years ago

working Version 19.11.2012 - Bots can allways be included

  • Property svn:eol-style set to native
File size: 5.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
[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
[9441]45    RaceCheckPoint::RaceCheckPoint(BaseObject* creator) : DistanceMultiTrigger(creator),
46            RadarViewable(creator, static_cast<WorldEntity*> (this))
[8494]47    {
[9441]48        RegisterObject(RaceCheckPoint);
49        this->setDistance(100);
[9016]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;
[9412]62        //this->players_ = vector<PlayerInfo*>();
[9441]63
[9451]64        myPosition_= this->getPosition(); //eingefuegt
[9441]65        orxout(user_status) << "test" << std::endl;
66
[8494]67    }
[8767]68
[9412]69    RaceCheckPoint::~RaceCheckPoint()
70    {
[9260]71
[9412]72    }
[8767]73
[8494]74    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
[8630]76        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
[9260]77
[8630]78        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
[9260]79        XMLPortParam(RaceCheckPoint, "islast", setLast, isLast, xmlelement, mode).defaultValues(false);
[8630]80        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
[9263]81        XMLPortParam(RaceCheckPoint, "nextcheckpoints", setNextCheckpointsAsVector3, getNextCheckpointsAsVector3, xmlelement, mode);
[8494]82    }
[8767]83
[9260]84    void RaceCheckPoint::fire(bool bIsTriggered, BaseObject* originator)
[8494]85    {
[9260]86        DistanceMultiTrigger::fire(bIsTriggered, originator);
87
88        if (bIsTriggered)
89        {
90            ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator);
91            if (entity)
[9441]92                this->players_.push_back(entity->getPlayer());
[9260]93        }
[8494]94    }
[8767]95
[8616]96    void RaceCheckPoint::setTimelimit(float timeLimit)
[8630]97    {
[9260]98        this->timeLimit_ = timeLimit;
99        if (this->timeLimit_ != 0)
[8630]100        {
[9412]101            std::string message = "You have " + multi_cast<std::string>(this->timeLimit_)
102            + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
[9348]103            this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message);
[9260]104            ChatManager::message(message);
[8630]105        }
106    }
[9263]107
108    void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints)
109    {
110        this->nextCheckpoints_.clear();
111
112        if (checkpoints.x > -1)
[9432]113        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly
[9263]114        if (checkpoints.y > -1)
[9412]115        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
[9263]116        if (checkpoints.z > -1)
[9412]117        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
[9263]118    }
119
[9412]120    PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const
121    {
122        if (players_.size() > 0)
123        {
124            for (int i = 0; i < players_.size(); i++)
125            {
126                if (this->players_[i]->getClientID() == clientID)
127                {
128                    return players_[i];
129                }
130            }
131        }
132        return NULL;
133    }
134
135    bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const
136    {
137        if (players_.size() > 0)
138        {
139            for (int i = 0; i < players_.size(); i++)
140            {
141                if (this->players_[i] == player)
142                {
143                    return true;
144                }
145            }
146        }
147        return false;
148    }
149
[9263]150    Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const
151    {
152        Vector3 checkpoints = Vector3(-1, -1, -1);
153
154        size_t count = 0;
155        for (std::set<int>::iterator it = this->nextCheckpoints_.begin(); it != this->nextCheckpoints_.end(); ++it)
156        {
157            switch (count)
158            {
159                case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
160                case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
161                case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
162            }
163            ++count;
164        }
165
166        return checkpoints;
167    }
[8494]168}
Note: See TracBrowser for help on using the repository browser.