Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9963 was 9963, checked in by landauf, 10 years ago

removed unused variable. RaceCheckPoint is a WorldEntity itself, so it already has a position anyway

  • Property svn:eol-style set to native
File size: 8.1 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 <infos/PlayerInfo.h>
37#include <worldentities/ControllableEntity.h>
38
39#include "SpaceRace.h"
40
41namespace orxonox
42{
43    RegisterClass(RaceCheckPoint);
44
45    RaceCheckPoint::RaceCheckPoint(Context* context) : DistanceMultiTrigger(context),
46            RadarViewable(this, static_cast<WorldEntity*> (this))
47    {
48        RegisterObject(RaceCheckPoint);
49        this->setDistance(100);
50        this->setBeaconMode("off");
51        this->setBroadcast(false);
52        this->setSimultaneousTriggerers(100);
53
54        this->setRadarObjectColour(ColourValue::Blue);
55        this->setRadarObjectShape(RadarViewable::Triangle);
56        this->setRadarVisibility(false);
57        this->settingsChanged();
58
59        this->checkpointIndex_ = 0;
60        this->bIsLast_ = false;
61        this->timeLimit_ = 0;
62        //this->players_ = vector<PlayerInfo*>();
63
64        //orxout(user_status) << "test" << std::endl;
65    }
66
67    RaceCheckPoint::~RaceCheckPoint()
68    {
69
70    }
71
72    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
73    {
74        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
75
76        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
77        XMLPortParam(RaceCheckPoint, "islast", setLast, isLast, xmlelement, mode).defaultValues(false);
78        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
79        XMLPortParam(RaceCheckPoint, "nextcheckpoints", setNextCheckpointsAsVector3, getNextCheckpointsAsVector3, xmlelement, mode);
80    }
81
82    void RaceCheckPoint::fire(bool bIsTriggered, BaseObject* originator)
83    {
84        DistanceMultiTrigger::fire(bIsTriggered, originator);
85
86        if (bIsTriggered)
87        {
88            ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator);
89            if (entity)
90                this->players_.push_back(entity->getPlayer());
91        }
92    }
93
94    void RaceCheckPoint::setTimelimit(float timeLimit)
95    {
96        this->timeLimit_ = timeLimit;
97        if (this->timeLimit_ != 0)
98        {
99            std::string message = "You have " + multi_cast<std::string>(this->timeLimit_)
100            + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
101            this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message);
102            ChatManager::message(message);
103        }
104    }
105
106    //Must not be called before setNextCheckpointsAsVector3 at least once has been called
107    void RaceCheckPoint::setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints){
108        /*std::set<int> lastcheckpoints=this->nextCheckpoints_;
109        nextCheckpoints_.clear();
110        std::set<int>::iterator it = lastcheckpoints.begin();
111        if(checkpoints.x<-1){
112            virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.x,(*it)));
113            it++;
114        }
115        if(checkpoints.x!=-1)
116            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
117
118        if(checkpoints.y<-1){
119                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.y,(*it)));
120                    it++;
121        }
122        if(checkpoints.y!=-1)
123            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
124
125        if(checkpoints.z<-1){
126                    virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.z,(*it)));
127                    it++;
128        }
129        if(checkpoints.z!=-1)
130            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));*/
131        nextCheckpointsVirtual_.clear();
132        if(checkpoints.x!=-1)
133            nextCheckpointsVirtual_.insert(checkpoints.x);
134        if(checkpoints.y!=-1)
135                nextCheckpointsVirtual_.insert(checkpoints.y);
136        if(checkpoints.z!=-1)
137                nextCheckpointsVirtual_.insert(checkpoints.z);
138    }
139
140    void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints)
141    {
142        this->nextCheckpoints_.clear();
143
144        if (checkpoints.x > -1)
145        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
146        if (checkpoints.y > -1)
147        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
148        if (checkpoints.z > -1)
149        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
150
151        this->nextCheckpointsVirtual_=nextCheckpoints_;
152    }
153
154    PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const
155    {
156        if (players_.size() > 0)
157        {
158            for (size_t i = 0; i < players_.size(); i++)
159            {
160                if (this->players_[i]->getClientID() == clientID)
161                {
162                    return players_[i];
163                }
164            }
165        }
166        return NULL;
167    }
168
169    bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const
170    {
171        if (players_.size() > 0)
172        {
173            for (size_t i = 0; i < players_.size(); i++)
174            {
175                if (this->players_[i] == player)
176                {
177                    return true;
178                }
179            }
180        }
181        return false;
182    }
183
184    Vector3 RaceCheckPoint::getNextCheckpointsAsVector3()
185    {
186        Vector3 checkpoints(-1,-1,-1); int count=0;
187        for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ ){
188            switch (count)
189                        {
190                            case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
191                            case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
192                            case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
193                        }
194                        ++count;
195        }
196        return checkpoints;
197        //= getVirtualNextCheckpointsAsVector3();
198        int j[3];
199        j[0]=changeVirtualToRealCheckPoint(checkpoints.x);
200        j[1]=changeVirtualToRealCheckPoint(checkpoints.y);
201        j[2]=changeVirtualToRealCheckPoint(checkpoints.z);
202
203
204        return Vector3(j[0],j[1],j[2]);
205
206
207    }
208
209    int RaceCheckPoint::changeVirtualToRealCheckPoint(int checkpointID) {
210        int temp=checkpointID;
211        while(temp<-1){
212            temp = this->virtualToRealCheckPoints_[temp];
213        }
214        return temp;
215    }
216
217
218    Vector3 RaceCheckPoint::getVirtualNextCheckpointsAsVector3() const
219    {
220        Vector3 checkpoints = Vector3(-1, -1, -1);
221
222        size_t count = 0;
223        for (std::set<int>::iterator it = this->nextCheckpointsVirtual_.begin(); it != this->nextCheckpointsVirtual_.end(); ++it)
224        {
225            switch (count)
226            {
227                case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
228                case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
229                case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
230            }
231            ++count;
232        }
233
234        return checkpoints;
235    }
236}
Note: See TracBrowser for help on using the repository browser.