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