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