Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

DistanceMultiTrigger

  • Property svn:eol-style set to native
File size: 5.6 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 "SpaceRace.h"
37
38namespace orxonox
39{
40    CreateFactory(RaceCheckPoint);
41   
42     
43
44    RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
45    {
46        RegisterObject(RaceCheckPoint);
47        this->setDistance(100);
48        this->setBeaconMode("off");
49        this->setBroadcast(false);
50        this->setSimultaneousTriggerers(100);
51       
52           
53        this->bCheckpointIndex_ = 0;
54        //this->bIsLast_ = false;
55        this->bTimeLimit_ = 0;
56        this->isVisible_=true;
57
58        this->setRadarObjectColour(ColourValue::Blue);
59        this->setRadarObjectShape(RadarViewable::Triangle);
60        this->setRadarVisibility(true);
61   
62    //this->addTarget("WorldEntity");
63   
64   
65    }
66   
67
68   RaceCheckPoint::~RaceCheckPoint()
69    {
70   
71         if (this->isInitialized())
72        {
73            //for (size_t i = 0; i < 3; ++i)
74            //   this->nextcheckpoints_[i]->destroy();
75        }
76       //nextcheckpoints_.destroy;
77    }
78
79    void RaceCheckPoint::tick(float dt)
80    {
81        SUPER(RaceCheckPoint, tick, dt);
82
83        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
84        assert(gametype);
85        if(this->isVisible_){this->setRadarVisibility(true);}
86        else{this->setRadarVisibility(false);}
87       
88     
89     
90       
91        /*this->setRadarVisibility(false);
92        Vector3 v =Vector3(0,0,0);
93        int j=0;
94        for (std::map<PlayerInfo*, Player>::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)
95        {
96                j=gametype->getCheckpointReached(it->first);
97                RaceCheckPoint* r=SpaceRaceManager::getCheckpoint(j);
98                v=r->getNextcheckpoint();
99                for(int i=1;i<4;i++){
100                if (this->getCheckpointIndex() == v[i])
101                 this->setRadarVisibility(true);
102                 }*/
103        //}     
104    }
105
106    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
107    {
108        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
109        Vector3 v= Vector3(0,0,0);
110        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
111        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
112        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
113    XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&).defaultValues(v);
114    }
115
116        void RaceCheckPoint::fire(bool bIsTriggered,BaseObject* player)
117    {
118       
119        //bool b= bIsTriggered;
120        //PlayerInfo* pl= player;
121        DistanceMultiTrigger::fire((bool)bIsTriggered,player);
122       
123   //SUPER(RaceCheckPoint,fire,bIsTriggered,player);
124               
125
126        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
127        assert(gametype);
128       
129                 PlayerInfo* player2 = (PlayerInfo*)player;
130        assert(player2);
131                //DistanceMultiTrigger::fire(bIsTriggered,player);
132               
133               
134               
135       
136               
137        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointReached(player2) && bIsTriggered)
138        {
139            gametype->clock_.capture();
140            float time = gametype->clock_.getSecondsPrecise();
141            if (this->bTimeLimit_!=0 && time > this->bTimeLimit_)
142            {
143                gametype->timeIsUp();
144                gametype->end();
145            }
146            else if (this->getLast())
147                gametype->end();
148            else
149            {
150                gametype->newCheckpointReached(this,player2);
151                this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
152            }
153        }
154    }
155
156    void RaceCheckPoint::setTimelimit(float timeLimit)
157    {
158        this->bTimeLimit_ = timeLimit;
159        if (this->bTimeLimit_ != 0)
160        {
161            SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
162            assert(gametype);
163            if (gametype)
164            {
165                const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
166                            + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1);
167                const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
168                ChatManager::message(message);
169            }
170        }
171    }
172
173}
Note: See TracBrowser for help on using the repository browser.