/* * 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: * Johannes Ritz * Co-authors: * ... * */ #include "Mission.h" #include "items/Engine.h" #include "controllers/ArtificialController.h" #include "core/CoreIncludes.h" #include "core/command/ConsoleCommand.h" #include "infos/PlayerInfo.h" #include "network/Host.h" #include "worldentities/pawns/Pawn.h" #include #include #include #include namespace orxonox { SetConsoleCommand("Mission", "endMission", &Mission::endMission); SetConsoleCommand("Mission", "setLives", &Mission::setLivesWrapper); RegisterUnloadableClass(Mission); Mission::Mission(Context* context) : TeamGametype(context) { RegisterObject(Mission); this->missionAccomplished_ = false; this->lives_ = 10; // should be 1 as default value this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 } void Mission::tick(float dt) { SUPER(Mission, tick, dt); if (missionAccomplished_) { this->gtinfo_->sendAnnounceMessage("Mission accomplished!"); this->end(); } else if (this->lives_ == 0) { this->missionAccomplished_ = false; this->end(); } } void Mission::pawnKilled(Pawn* victim, Pawn* killer) { if (victim && victim->getPlayer() && victim->getPlayer()->isHumanPlayer() ) { this->lives_--; } } void Mission::start() { std::fstream myfile; Gametype::start(); this->setTeams(); //just for testing //this->missionAccomplished_=true; this->gtinfo_->sendAnnounceMessage("Your mission has started!"); } std::string GenerateHelperString(int number){ std::string helperstring = ""; while (number>1) { helperstring=helperstring+" "; number=number-1; } helperstring=helperstring+"."; return helperstring; } void Mission::end() { if (this->missionAccomplished_ && !this->gtinfo_->hasEnded()){ this->gtinfo_->sendAnnounceMessage("Mission accomplished!"); std::fstream myfile; myfile.open("/home/maxima/maxima-extra-0/orxonox/storymodeHS14/campaign.txt"); std::string line; std::string mission=this->getFilename(); int k=58-mission.length(); std::string helperstring = ""; if(myfile.is_open()){ while (k>1) { helperstring=helperstring+" "; k=k-1; } helperstring=helperstring+"."; while(getline (myfile,line)){ if(line==mission+" 0"+helperstring){ long pos = myfile.tellp(); myfile.seekp (pos-61); myfile << mission+" 1"+helperstring; } }} myfile.flush(); myfile.clear(); myfile.close(); } else if (!this->gtinfo_->hasEnded()) this->gtinfo_->sendAnnounceMessage("Mission failed!"); Gametype::end(); } void Mission::setTeams() {//Set pawn-colours for (ObjectList::iterator it = ObjectList::begin(); it != ObjectList::end(); ++it) { Pawn* pawn = static_cast(*it); if(!pawn) continue; this->setDefaultObjectColour(pawn); } } void Mission::endMission(bool accomplished) { for (ObjectList::iterator it = ObjectList::begin(); it != ObjectList::end(); ++it) {//TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would end ALL missions! /* if(accomplished){ std::fstream myfile; myfile.open("/home/pmao/pmao-extra-0/orxonox/storymodeHS14/data/gui/scripts/campaign.txt"); std::string line; std::string mission=it->getFilename(); int k=58-mission.length(); std::string helperstring = ""; if(myfile.is_open()){ while (k>1) { helperstring=helperstring+" "; k=k-1; } helperstring=helperstring+"."; while(getline (myfile,line)){ if(line==mission+" 0"+helperstring){ long pos = myfile.tellp(); myfile.seekp (pos-61); myfile << mission+" 1"+helperstring; } } } myfile.flush(); myfile.clear(); myfile.close(); }*/ it->setMissionAccomplished(accomplished); it->end(); } } void Mission::setLivesWrapper(unsigned int amount) { for (ObjectList::iterator it = ObjectList::begin(); it != ObjectList::end(); ++it) {//TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions! it->setLives(amount); } } }