[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 | { |
---|
[10249] | 75 | if (victim && victim->getPlayer() && victim->getPlayer()->isHumanPlayer()) |
---|
[8904] | 76 | { |
---|
[9729] | 77 | this->lives_--; |
---|
[8904] | 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | void Mission::start() |
---|
| 82 | { |
---|
[10249] | 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 | |
---|
[10249] | 92 | std::string GenerateHelperString(int number) |
---|
| 93 | { |
---|
| 94 | std::string helperstring = ""; |
---|
| 95 | while (number > 1) |
---|
| 96 | { |
---|
| 97 | helperstring = helperstring + " "; |
---|
| 98 | number = number - 1; |
---|
| 99 | } |
---|
| 100 | helperstring = helperstring + "."; |
---|
| 101 | return helperstring; |
---|
[10157] | 102 | } |
---|
| 103 | |
---|
[8904] | 104 | void Mission::end() |
---|
| 105 | { |
---|
[10157] | 106 | |
---|
[10249] | 107 | if (this->missionAccomplished_ && !this->gtinfo_->hasEnded()) |
---|
| 108 | { |
---|
[8904] | 109 | this->gtinfo_->sendAnnounceMessage("Mission accomplished!"); |
---|
[10157] | 110 | std::fstream myfile; |
---|
[10249] | 111 | myfile.open("/home/maxima/maxima-extra-0/orxonox/storymodeHS14/campaign.txt"); |
---|
| 112 | std::string line; |
---|
| 113 | std::string mission = this->getFilename(); |
---|
| 114 | int k = 58 - mission.length(); |
---|
| 115 | std::string helperstring = ""; |
---|
| 116 | if (myfile.is_open()) |
---|
| 117 | { |
---|
| 118 | while (k > 1) |
---|
| 119 | { |
---|
| 120 | helperstring = helperstring + " "; |
---|
| 121 | k = k - 1; |
---|
| 122 | } |
---|
| 123 | helperstring = helperstring + "."; |
---|
| 124 | while (getline(myfile, line)) |
---|
| 125 | { |
---|
| 126 | if (line == mission + " 0" + helperstring) |
---|
| 127 | { |
---|
| 128 | long pos = myfile.tellp(); |
---|
| 129 | myfile.seekp(pos - 61); |
---|
| 130 | myfile << mission + " 1" + helperstring; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | myfile.flush(); |
---|
| 135 | myfile.clear(); |
---|
| 136 | myfile.close(); |
---|
| 137 | } |
---|
[10157] | 138 | |
---|
[9986] | 139 | else if (!this->gtinfo_->hasEnded()) |
---|
[8904] | 140 | this->gtinfo_->sendAnnounceMessage("Mission failed!"); |
---|
[9986] | 141 | Gametype::end(); |
---|
[8904] | 142 | } |
---|
[8941] | 143 | |
---|
| 144 | void Mission::setTeams() |
---|
[10249] | 145 | { //Set pawn-colours |
---|
[8941] | 146 | for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) |
---|
[8942] | 147 | { |
---|
| 148 | Pawn* pawn = static_cast<Pawn*>(*it); |
---|
[10249] | 149 | if (!pawn) |
---|
| 150 | continue; |
---|
| 151 | this->setDefaultObjectColour(pawn); |
---|
[8942] | 152 | } |
---|
[8941] | 153 | } |
---|
[9728] | 154 | void Mission::endMission(bool accomplished) |
---|
| 155 | { |
---|
| 156 | for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it) |
---|
[10249] | 157 | { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would end ALL missions! |
---|
| 158 | it->setMissionAccomplished(accomplished); |
---|
[9728] | 159 | it->end(); |
---|
[10157] | 160 | |
---|
[9728] | 161 | } |
---|
| 162 | } |
---|
[10157] | 163 | |
---|
[9729] | 164 | void Mission::setLivesWrapper(unsigned int amount) |
---|
| 165 | { |
---|
| 166 | for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it) |
---|
[10249] | 167 | { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions! |
---|
[9729] | 168 | it->setLives(amount); |
---|
| 169 | } |
---|
| 170 | } |
---|
[8941] | 171 | |
---|
[8904] | 172 | } |
---|