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