[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" |
---|
[10253] | 38 | #include "core/config/ConfigValueIncludes.h" |
---|
[9729] | 39 | #include "infos/PlayerInfo.h" |
---|
[8904] | 40 | #include "network/Host.h" |
---|
| 41 | #include "worldentities/pawns/Pawn.h" |
---|
[10253] | 42 | #include "LevelManager.h" |
---|
[8904] | 43 | |
---|
| 44 | namespace orxonox |
---|
| 45 | { |
---|
[9728] | 46 | SetConsoleCommand("Mission", "endMission", &Mission::endMission); |
---|
[9729] | 47 | SetConsoleCommand("Mission", "setLives", &Mission::setLivesWrapper); |
---|
[9667] | 48 | RegisterUnloadableClass(Mission); |
---|
[8904] | 49 | |
---|
[9667] | 50 | Mission::Mission(Context* context) : TeamGametype(context) |
---|
[8904] | 51 | { |
---|
| 52 | RegisterObject(Mission); |
---|
| 53 | this->missionAccomplished_ = false; |
---|
| 54 | this->lives_ = 10; // should be 1 as default value |
---|
| 55 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | void Mission::tick(float dt) |
---|
| 59 | { |
---|
| 60 | SUPER(Mission, tick, dt); |
---|
| 61 | |
---|
| 62 | if (missionAccomplished_) |
---|
| 63 | { |
---|
| 64 | this->gtinfo_->sendAnnounceMessage("Mission accomplished!"); |
---|
| 65 | this->end(); |
---|
| 66 | } |
---|
[9730] | 67 | else if (this->lives_ == 0) |
---|
| 68 | { |
---|
| 69 | this->missionAccomplished_ = false; |
---|
| 70 | this->end(); |
---|
| 71 | } |
---|
[8904] | 72 | } |
---|
| 73 | |
---|
| 74 | void Mission::pawnKilled(Pawn* victim, Pawn* killer) |
---|
| 75 | { |
---|
[10249] | 76 | if (victim && victim->getPlayer() && victim->getPlayer()->isHumanPlayer()) |
---|
[8904] | 77 | { |
---|
[9729] | 78 | this->lives_--; |
---|
[8904] | 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void Mission::start() |
---|
| 83 | { |
---|
[10249] | 84 | std::fstream myfile; |
---|
[10174] | 85 | |
---|
[8904] | 86 | Gametype::start(); |
---|
[8941] | 87 | this->setTeams(); |
---|
[10174] | 88 | //just for testing |
---|
| 89 | //this->missionAccomplished_=true; |
---|
[8904] | 90 | this->gtinfo_->sendAnnounceMessage("Your mission has started!"); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void Mission::end() |
---|
| 94 | { |
---|
[10157] | 95 | |
---|
[10249] | 96 | if (this->missionAccomplished_ && !this->gtinfo_->hasEnded()) |
---|
| 97 | { |
---|
[8904] | 98 | this->gtinfo_->sendAnnounceMessage("Mission accomplished!"); |
---|
[10251] | 99 | |
---|
[10253] | 100 | LevelManager::getInstance().setLastFinishedCampaignMission(this->getFilename()); |
---|
[10249] | 101 | } |
---|
[10157] | 102 | |
---|
[9986] | 103 | else if (!this->gtinfo_->hasEnded()) |
---|
[8904] | 104 | this->gtinfo_->sendAnnounceMessage("Mission failed!"); |
---|
[9986] | 105 | Gametype::end(); |
---|
[8904] | 106 | } |
---|
[8941] | 107 | |
---|
| 108 | void Mission::setTeams() |
---|
[10249] | 109 | { //Set pawn-colours |
---|
[8941] | 110 | for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) |
---|
[8942] | 111 | { |
---|
| 112 | Pawn* pawn = static_cast<Pawn*>(*it); |
---|
[10249] | 113 | if (!pawn) |
---|
| 114 | continue; |
---|
| 115 | this->setDefaultObjectColour(pawn); |
---|
[8942] | 116 | } |
---|
[8941] | 117 | } |
---|
[9728] | 118 | void Mission::endMission(bool accomplished) |
---|
| 119 | { |
---|
| 120 | for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it) |
---|
[10249] | 121 | { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would end ALL missions! |
---|
| 122 | it->setMissionAccomplished(accomplished); |
---|
[9728] | 123 | it->end(); |
---|
[10157] | 124 | |
---|
[9728] | 125 | } |
---|
| 126 | } |
---|
[10157] | 127 | |
---|
[9729] | 128 | void Mission::setLivesWrapper(unsigned int amount) |
---|
| 129 | { |
---|
| 130 | for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it) |
---|
[10249] | 131 | { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions! |
---|
[9729] | 132 | it->setLives(amount); |
---|
| 133 | } |
---|
| 134 | } |
---|
[8941] | 135 | |
---|
[8904] | 136 | } |
---|