Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8959 was 8959, checked in by eceline, 12 years ago

RaceCheckPoint::fire doesn't work

  • Property svn:eol-style set to native
File size: 7.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
38#include "SpaceRace.h"
39
40namespace orxonox
41{
42    CreateFactory(RaceCheckPoint);
43   
44     
45
46    RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, 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           
55       
56       
57        this->bTimeLimit_ = 0;
58        this->isVisible_=true;
59
60        this->setRadarObjectColour(ColourValue::Blue);
61        this->setRadarObjectShape(RadarViewable::Triangle);
62        this->setRadarVisibility(true);
63   
64        this->reached_=NULL;
65    //this->addTarget("WorldEntity");
66   
67   
68    }
69   
70
71   RaceCheckPoint::~RaceCheckPoint()
72    {
73   
74         if (this->isInitialized())
75        {
76           for (size_t i = 0; i < this->next_.size(); ++i)
77                this->next_[i]->destroy();
78        }
79       //nextcheckpoints_.destroy;
80    }
81
82    void RaceCheckPoint::tick(float dt)
83    {
84        SUPER(RaceCheckPoint, tick, dt);
85
86        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
87        assert(gametype);
88        if(this->isVisible_){this->setRadarVisibility(true);}
89        else{this->setRadarVisibility(false);}
90       
91     
92     
93       
94        /*this->setRadarVisibility(false);
95        Vector3 v =Vector3(0,0,0);
96        int j=0;
97        for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
98        {
99                j=gametype->getCheckpointReached(it->first);
100                RaceCheckPoint* r=SpaceRaceManager::getCheckpoint(j);
101                v=r->getNextcheckpoint();
102                for(int i=1;i<4;i++){
103                if (this->getCheckpointIndex() == v[i])
104                 this->setRadarVisibility(true);
105                 }*/
106        //}     
107    }
108
109    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
110    {
111        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
112        Vector3 v= Vector3(0,0,0);
113        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
114        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
115        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
116    XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&).defaultValues(v);
117    }
118
119        void RaceCheckPoint::fire(bool bIsTriggered,BaseObject* player)
120    {
121       
122        //bool b= bIsTriggered;
123        //PlayerInfo* pl= player;
124        DistanceMultiTrigger::fire((bool)bIsTriggered,player);
125       
126       SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
127        assert(gametype);
128       
129       
130       
131       // BaseObject b=*player;
132       //  PlayerInfo* p = orxonox_cast<PlayerInfo*,Player>(player);
133        //assert(player);
134       //PlayerInfo* player3=((PlayerInfo*) player);
135       Player* player3=((Player*) player);
136     
137      PlayerInfo* player2=( PlayerInfo*) player;
138       
139       for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
140        {
141          unsigned int clientid1=0, clientid2=0,clientid3=0;
142          if(it->first !=NULL)clientid1 = it->first->getClientID();
143         
144          if(player3 != NULL && player3->info_ != NULL)clientid2 =         player3->info_->getClientID();
145          if(player2 != NULL )clientid3 =         player2->getClientID();
146          orxout()<<clientid1<<endl;orxout()<<clientid2<<endl;orxout()<<clientid3<<endl;
147        orxout()<<"for"<<endl;if(clientid1==clientid2) {orxout()<<"player"<<endl; player2=it->first;}if((it->first)==player2) {orxout()<<"player2"<<endl; }}
148       
149        // PlayerInfo* player2 = orxonox_cast<PlayerInfo*>(player);
150       // assert(player);
151        //gametype->newCheckpointReached(this,player);
152        //if(bIsTriggered)this->reached_=player2;
153       
154        /* for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
155        {if(gametype->getCheckpointReached(it->first)==-1) orxout()<<"index -1"<<endl;if(player2==it->first)orxout()<<"e"<<endl;}
156        if(gametype->getCheckpointReached(player2)==-1) orxout()<<"my index -1"<<endl;
157   orxout()<<gametype->getCheckpointReached(player2)<<endl;
158         
159               
160                RaceCheckPoint* check=gametype->getCheckpointReached(player2);
161               
162        bool b =false; 
163        for(int i=0;i<3;i++){
164       
165        if (check->getNext[i]==this){
166                b=true;}
167        }       
168       
169               
170        if (gametype && b && bIsTriggered)
171        {
172            gametype->clock_.capture();
173            float time = gametype->clock_.getSecondsPrecise();
174            if (this->bTimeLimit_!=0 && time > this->bTimeLimit_)
175            {
176                gametype->timeIsUp();
177                gametype->end();
178            }
179            else if (this->getLast())
180                gametype->end();
181            else
182                gametype->newCheckpointReached(this,player2)
183            {
184               
185                this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
186            }
187        }*/
188 
189               
190
191     
192    }
193
194    void RaceCheckPoint::setTimelimit(float timeLimit)
195    {
196        this->bTimeLimit_ = timeLimit;
197        if (this->bTimeLimit_ != 0)
198        {
199            SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
200            assert(gametype);
201            if (gametype)
202            {
203                const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
204                            + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1);
205                const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
206                ChatManager::message(message);
207            }
208        }
209    }
210
211}
Note: See TracBrowser for help on using the repository browser.