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" |
---|
30 | |
---|
31 | #include "items/Engine.h" |
---|
32 | #include "controllers/ArtificialController.h" |
---|
33 | |
---|
34 | #include "core/CoreIncludes.h" |
---|
35 | #include "core/command/ConsoleCommand.h" |
---|
36 | #include "infos/PlayerInfo.h" |
---|
37 | #include "network/Host.h" |
---|
38 | #include "worldentities/pawns/Pawn.h" |
---|
39 | #include "LevelManager.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | SetConsoleCommand("Mission", "endMission", &Mission::endMission); |
---|
44 | SetConsoleCommand("Mission", "setLives", &Mission::setLivesWrapper); |
---|
45 | RegisterUnloadableClass(Mission); |
---|
46 | |
---|
47 | Mission::Mission(Context* context) : TeamGametype(context) |
---|
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 | } |
---|
64 | else if (this->lives_ == 0) |
---|
65 | { |
---|
66 | this->missionAccomplished_ = false; |
---|
67 | this->end(); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | void Mission::pawnKilled(Pawn* victim, Pawn* killer) |
---|
72 | { |
---|
73 | if (victim && victim->getPlayer() && victim->getPlayer()->isHumanPlayer()) |
---|
74 | { |
---|
75 | this->lives_--; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | void Mission::start() |
---|
80 | { |
---|
81 | Gametype::start(); |
---|
82 | this->setTeams(); |
---|
83 | |
---|
84 | this->gtinfo_->sendAnnounceMessage("Your mission has started!"); |
---|
85 | } |
---|
86 | |
---|
87 | void Mission::end() |
---|
88 | { |
---|
89 | if (this->missionAccomplished_ && !this->gtinfo_->hasEnded()) |
---|
90 | { |
---|
91 | this->gtinfo_->sendAnnounceMessage("Mission accomplished!"); |
---|
92 | |
---|
93 | LevelManager::getInstance().setLastFinishedCampaignMission(this->getFilename()); |
---|
94 | } |
---|
95 | else if (!this->gtinfo_->hasEnded()) |
---|
96 | this->gtinfo_->sendAnnounceMessage("Mission failed!"); |
---|
97 | |
---|
98 | Gametype::end(); |
---|
99 | } |
---|
100 | |
---|
101 | void Mission::setTeams() |
---|
102 | { //Set pawn-colours |
---|
103 | for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) |
---|
104 | { |
---|
105 | Pawn* pawn = static_cast<Pawn*>(*it); |
---|
106 | if (!pawn) |
---|
107 | continue; |
---|
108 | this->setDefaultObjectColour(pawn); |
---|
109 | } |
---|
110 | } |
---|
111 | void Mission::endMission(bool accomplished) |
---|
112 | { |
---|
113 | for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it) |
---|
114 | { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would end ALL missions! |
---|
115 | it->setMissionAccomplished(accomplished); |
---|
116 | it->end(); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | void Mission::setLivesWrapper(unsigned int amount) |
---|
121 | { |
---|
122 | for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it) |
---|
123 | { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions! |
---|
124 | it->setLives(amount); |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|