[8904] | 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 | * Johannes Ritz |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "Mission.h" |
---|
[8923] | 30 | #include "items/Engine.h" |
---|
[8941] | 31 | #include "controllers/ArtificialController.h" |
---|
[8904] | 32 | |
---|
| 33 | #include "core/CoreIncludes.h" |
---|
[9728] | 34 | #include "core/command/ConsoleCommand.h" |
---|
[9729] | 35 | #include "infos/PlayerInfo.h" |
---|
[8904] | 36 | #include "network/Host.h" |
---|
| 37 | #include "worldentities/pawns/Pawn.h" |
---|
[10157] | 38 | #include <iostream> |
---|
| 39 | #include <fstream> |
---|
| 40 | #include <string> |
---|
| 41 | #include <ios> |
---|
[8904] | 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
[9728] | 45 | SetConsoleCommand("Mission", "endMission", &Mission::endMission); |
---|
[9729] | 46 | SetConsoleCommand("Mission", "setLives", &Mission::setLivesWrapper); |
---|
[9667] | 47 | RegisterUnloadableClass(Mission); |
---|
[8904] | 48 | |
---|
[9667] | 49 | Mission::Mission(Context* context) : TeamGametype(context) |
---|
[8904] | 50 | { |
---|
| 51 | RegisterObject(Mission); |
---|
| 52 | this->missionAccomplished_ = false; |
---|
| 53 | this->lives_ = 10; // should be 1 as default value |
---|
| 54 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void Mission::tick(float dt) |
---|
| 58 | { |
---|
| 59 | SUPER(Mission, tick, dt); |
---|
| 60 | |
---|
| 61 | if (missionAccomplished_) |
---|
| 62 | { |
---|
| 63 | this->gtinfo_->sendAnnounceMessage("Mission accomplished!"); |
---|
| 64 | this->end(); |
---|
| 65 | } |
---|
[9730] | 66 | else if (this->lives_ == 0) |
---|
| 67 | { |
---|
| 68 | this->missionAccomplished_ = false; |
---|
| 69 | this->end(); |
---|
| 70 | } |
---|
[8904] | 71 | } |
---|
| 72 | |
---|
| 73 | void Mission::pawnKilled(Pawn* victim, Pawn* killer) |
---|
| 74 | { |
---|
[9729] | 75 | if (victim && victim->getPlayer() && victim->getPlayer()->isHumanPlayer() ) |
---|
[8904] | 76 | { |
---|
[9729] | 77 | this->lives_--; |
---|
[8904] | 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | void Mission::start() |
---|
| 82 | { |
---|
[10157] | 83 | std::fstream myfile; |
---|
[10174] | 84 | |
---|
[8904] | 85 | Gametype::start(); |
---|
[8941] | 86 | this->setTeams(); |
---|
[10174] | 87 | //just for testing |
---|
| 88 | //this->missionAccomplished_=true; |
---|
[8904] | 89 | this->gtinfo_->sendAnnounceMessage("Your mission has started!"); |
---|
| 90 | } |
---|
| 91 | |
---|
[10157] | 92 | std::string GenerateHelperString(int number){ |
---|
| 93 | std::string helperstring = ""; |
---|
| 94 | while (number>1) { |
---|
| 95 | helperstring=helperstring+" "; |
---|
| 96 | number=number-1; |
---|
| 97 | } |
---|
| 98 | helperstring=helperstring+"."; |
---|
| 99 | return helperstring; |
---|
| 100 | } |
---|
| 101 | |
---|
[8904] | 102 | void Mission::end() |
---|
| 103 | { |
---|
[10157] | 104 | |
---|
| 105 | if (this->missionAccomplished_ && !this->gtinfo_->hasEnded()){ |
---|
[8904] | 106 | this->gtinfo_->sendAnnounceMessage("Mission accomplished!"); |
---|
[10157] | 107 | std::fstream myfile; |
---|
[10174] | 108 | myfile.open("/home/maxima/maxima-extra-0/orxonox/storymodeHS14/campaign.txt"); |
---|
[10157] | 109 | std::string line; |
---|
| 110 | std::string mission=this->getFilename(); |
---|
| 111 | int k=58-mission.length(); |
---|
| 112 | std::string helperstring = ""; |
---|
| 113 | if(myfile.is_open()){ |
---|
| 114 | while (k>1) { |
---|
| 115 | helperstring=helperstring+" "; |
---|
| 116 | k=k-1; |
---|
| 117 | } |
---|
| 118 | helperstring=helperstring+"."; |
---|
| 119 | while(getline (myfile,line)){ |
---|
| 120 | if(line==mission+" 0"+helperstring){ |
---|
| 121 | long pos = myfile.tellp(); |
---|
| 122 | myfile.seekp (pos-61); |
---|
| 123 | myfile << mission+" 1"+helperstring; |
---|
| 124 | } |
---|
| 125 | }} |
---|
| 126 | myfile.flush(); |
---|
| 127 | myfile.clear(); |
---|
| 128 | myfile.close(); |
---|
| 129 | } |
---|
| 130 | |
---|
[9986] | 131 | else if (!this->gtinfo_->hasEnded()) |
---|
[8904] | 132 | this->gtinfo_->sendAnnounceMessage("Mission failed!"); |
---|
[9986] | 133 | Gametype::end(); |
---|
[8904] | 134 | } |
---|
[8941] | 135 | |
---|
| 136 | void Mission::setTeams() |
---|
[8942] | 137 | {//Set pawn-colours |
---|
[8941] | 138 | for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) |
---|
[8942] | 139 | { |
---|
| 140 | Pawn* pawn = static_cast<Pawn*>(*it); |
---|
| 141 | if(!pawn) continue; |
---|
| 142 | this->setDefaultObjectColour(pawn); |
---|
| 143 | } |
---|
[8941] | 144 | } |
---|
[9728] | 145 | void Mission::endMission(bool accomplished) |
---|
| 146 | { |
---|
| 147 | for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it) |
---|
| 148 | {//TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would end ALL missions! |
---|
[10174] | 149 | /* if(accomplished){ |
---|
[10157] | 150 | std::fstream myfile; |
---|
| 151 | myfile.open("/home/pmao/pmao-extra-0/orxonox/storymodeHS14/data/gui/scripts/campaign.txt"); |
---|
| 152 | std::string line; |
---|
| 153 | std::string mission=it->getFilename(); |
---|
| 154 | int k=58-mission.length(); |
---|
| 155 | std::string helperstring = ""; |
---|
| 156 | if(myfile.is_open()){ |
---|
| 157 | while (k>1) { |
---|
| 158 | helperstring=helperstring+" "; |
---|
| 159 | k=k-1; |
---|
| 160 | } |
---|
| 161 | helperstring=helperstring+"."; |
---|
| 162 | while(getline (myfile,line)){ |
---|
| 163 | if(line==mission+" 0"+helperstring){ |
---|
| 164 | long pos = myfile.tellp(); |
---|
| 165 | myfile.seekp (pos-61); |
---|
| 166 | myfile << mission+" 1"+helperstring; |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | myfile.flush(); |
---|
| 171 | myfile.clear(); |
---|
| 172 | myfile.close(); |
---|
[10174] | 173 | }*/ |
---|
[10157] | 174 | it->setMissionAccomplished(accomplished); |
---|
[9728] | 175 | it->end(); |
---|
[10157] | 176 | |
---|
[9728] | 177 | } |
---|
| 178 | } |
---|
[10157] | 179 | |
---|
[9729] | 180 | void Mission::setLivesWrapper(unsigned int amount) |
---|
| 181 | { |
---|
| 182 | for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it) |
---|
| 183 | {//TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions! |
---|
| 184 | it->setLives(amount); |
---|
| 185 | } |
---|
| 186 | } |
---|
[8941] | 187 | |
---|
| 188 | |
---|
[8904] | 189 | } |
---|