/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Mauro Salomon * Co-authors: * ... * */ #include "RaceCheckPoint.h" #include "util/Convert.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "chat/ChatManager.h" #include #include "SpaceRace.h" namespace orxonox { CreateFactory(RaceCheckPoint); RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast(this)) { RegisterObject(RaceCheckPoint); this->setDistance(100); this->setBeaconMode("off"); this->setBroadcast(false); this->setSimultaneousTriggerers(100); this->bTimeLimit_ = 0; this->isVisible_=true; this->setRadarObjectColour(ColourValue::Blue); this->setRadarObjectShape(RadarViewable::Triangle); this->setRadarVisibility(true); this->reached_=NULL; //this->addTarget("WorldEntity"); } RaceCheckPoint::~RaceCheckPoint() { if (this->isInitialized()) { for (size_t i = 0; i < this->next_.size(); ++i) this->next_[i]->destroy(); } //nextcheckpoints_.destroy; } void RaceCheckPoint::tick(float dt) { SUPER(RaceCheckPoint, tick, dt); SpaceRace* gametype = orxonox_cast(this->getGametype().get()); assert(gametype); if(this->isVisible_){this->setRadarVisibility(true);} else{this->setRadarVisibility(false);} /*this->setRadarVisibility(false); Vector3 v =Vector3(0,0,0); int j=0; for (std::map::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it) { j=gametype->getCheckpointReached(it->first); RaceCheckPoint* r=SpaceRaceManager::getCheckpoint(j); v=r->getNextcheckpoint(); for(int i=1;i<4;i++){ if (this->getCheckpointIndex() == v[i]) this->setRadarVisibility(true); }*/ //} } void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(RaceCheckPoint, XMLPort, xmlelement, mode); Vector3 v= Vector3(0,0,0); XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0); XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false); XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&).defaultValues(v); } void RaceCheckPoint::fire(bool bIsTriggered,BaseObject* player) { //bool b= bIsTriggered; //PlayerInfo* pl= player; DistanceMultiTrigger::fire((bool)bIsTriggered,player); SpaceRace* gametype = orxonox_cast(this->getGametype().get()); assert(gametype); // BaseObject b=*player; // PlayerInfo* p = orxonox_cast(player); //assert(player); //PlayerInfo* player3=((PlayerInfo*) player); Player* player3=((Player*) player); PlayerInfo* player2=( PlayerInfo*) player; for (std::map::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it) { unsigned int clientid1=0, clientid2=0,clientid3=0; if(it->first !=NULL)clientid1 = it->first->getClientID(); if(player3 != NULL && player3->info_ != NULL)clientid2 = player3->info_->getClientID(); if(player2 != NULL )clientid3 = player2->getClientID(); orxout()<first;}if((it->first)==player2) {orxout()<<"player2"<(player); // assert(player); //gametype->newCheckpointReached(this,player); //if(bIsTriggered)this->reached_=player2; /* for (std::map::iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it) {if(gametype->getCheckpointReached(it->first)==-1) orxout()<<"index -1"<first)orxout()<<"e"<getCheckpointReached(player2)==-1) orxout()<<"my index -1"<getCheckpointReached(player2)<getCheckpointReached(player2); bool b =false; for(int i=0;i<3;i++){ if (check->getNext[i]==this){ b=true;} } if (gametype && b && bIsTriggered) { gametype->clock_.capture(); float time = gametype->clock_.getSecondsPrecise(); if (this->bTimeLimit_!=0 && time > this->bTimeLimit_) { gametype->timeIsUp(); gametype->end(); } else if (this->getLast()) gametype->end(); else gametype->newCheckpointReached(this,player2) { this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red. } }*/ } void RaceCheckPoint::setTimelimit(float timeLimit) { this->bTimeLimit_ = timeLimit; if (this->bTimeLimit_ != 0) { SpaceRace* gametype = orxonox_cast(this->getGametype().get()); assert(gametype); if (gametype) { const std::string& message = "You have " + multi_cast(this->bTimeLimit_) + " seconds to reach the check point " + multi_cast(this->bCheckpointIndex_+1); const_cast(gametype->getGametypeInfo())->sendAnnounceMessage(message); ChatManager::message(message); } } } }