/* * 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: * Celine Egger * */ #include "SpaceRace.h" #include "core/CoreIncludes.h" #include "chat/ChatManager.h" #include "util/Convert.h" #include "util/Math.h" #include "infos/Bot.h" #include "items/Engine.h" #include "controllers/HumanController.h" #include "core/CoreIncludes.h" #include "chat/ChatManager.h" #include "infos/PlayerInfo.h" #include "worldentities/pawns/Pawn.h" #include "core/config/ConfigValueIncludes.h" #include "infos/Bot.h" #include "SpaceRaceBot.h" #include "items/Engine.h" #include "core/CoreIncludes.h" #include "chat/ChatManager.h" #include "util/Convert.h" #include "util/Math.h" #include "SpaceRaceBot.h" #include "items/Engine.h" #include namespace orxonox { RegisterUnloadableClass(SpaceRace); SpaceRace::SpaceRace(Context* context) : Gametype(context) { RegisterObject(SpaceRace); this->botclass_ = Class(SpaceRaceBot);//ClassByString("") this->cantMove_ = false; this->bTimeIsUp_ = false; this->setConfigValues(); // this->numberOfBots_ = 1; // quick fix: don't allow default-bots to enter the race // remove this line, if a raceBot has been created. } void SpaceRace::setConfigValues() { } void SpaceRace::start() { std::vector spawnpositions; spawnpositions.push_back(200); spawnpositions.push_back(0); spawnpositions.push_back(100); spawnpositions.push_back(200); spawnpositions.push_back(200); spawnpositions.push_back(0); spawnpositions.push_back(200); spawnpositions.push_back(0); spawnpositions.push_back(0); spawnpositions.push_back(100); spawnpositions.push_back(0); spawnpositions.push_back(0); spawnpositions.push_back(0); spawnpositions.push_back(100); spawnpositions.push_back(0); Gametype::start(); if (true) { this->spawnPlayersIfRequested(); this->cantMove_ = true; for (Engine* engine : ObjectList()){ engine->setActive(false); } int a,b,c; a=0; b=1; c=2; for (SpaceRaceBot* bot : ObjectList()){ bot->getControllableEntity()->setPosition(spawnpositions.at(a),spawnpositions.at(b),spawnpositions.at(c)); a= a+3; b = b+3; c+= 3; } } std::string message("BE FAST BE FIRST"); this->getGametypeInfo()->sendAnnounceMessage(message); ChatManager::message(message); Timer* countdownTimer = new Timer(); countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this))); } void SpaceRace::end() { this->clock_.capture(); int s = this->clock_.getSeconds(); int ms = static_cast(this->clock_.getMilliseconds() - 1000*s); std::string message; if (this->bTimeIsUp_) { message = multi_cast(s) + "." + multi_cast(ms) + " seconds !!\n" + "You didn't reach the check point before the time limit. You lose!"; } else { message = "You win!! Final check point reached after "+ multi_cast(s) + "." + multi_cast(ms) + " seconds."; } if (!this->hasEnded()) { this->getGametypeInfo()->sendAnnounceMessage(message); ChatManager::message(message); } this->Gametype::end(); } void SpaceRace::tick(float dt) { SUPER(SpaceRace,tick,dt); // spawns the players when the countdown starts, but deactivates their engines /* if (this->isStartCountdownRunning() && !this->cantMove_) { this->spawnPlayersIfRequested(); this->cantMove_ = true; for (Engine* engine : ObjectList()) engine->setActive(false); }*/ //gtinfo_->setStartCountdown(50.0); // activate the engines when the countdown ends /* if (!this->isStartCountdownRunning() && this->cantMove_) { for (Engine* engine : ObjectList()) engine->setActive(true); this->cantMove_= false; std::string message = "RACE STARTED!"; this->getGametypeInfo()->sendAnnounceMessage(message); ChatManager::message(message); }*/ } void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player) { this->checkpointReached_[player] = checkpoint; this->clock_.capture(); int s = this->clock_.getSeconds(); int ms = this->clock_.getMilliseconds() % 1000; const std::string& message = player->getName() + " reached the checkpoint " + multi_cast(checkpoint->getCheckpointIndex() + 1) + "after " + multi_cast(s) + "." + multi_cast(ms) + " seconds."; this->getGametypeInfo()->sendAnnounceMessage(message); ChatManager::message(message); } void SpaceRace::countdownFinished() { std::string message("RACE STARTED "); this->getGametypeInfo()->sendAnnounceMessage(message); ChatManager::message(message); for (Engine* engine : ObjectList()) engine->setActive(true); } void SpaceRace::playerEntered(PlayerInfo* player) { Gametype::playerEntered(player); const std::string& message = player->getName() + " entered the game"; ChatManager::message(message); } void SpaceRace::addBots(unsigned int amount) { for (unsigned int i = 1; i <= amount; ++i){ this->botclass_.fabricate(this->getContext()); //SpaceRaceBot* bot = new SpaceRaceBot(this->getContext()); //bot->setPosition(-i*150,0,-i*100); } } bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator) { return true; } bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator) { return true; } bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator) { return true; } }