[2933] | 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: |
---|
[3020] | 23 | * Matthias Mock |
---|
[2933] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "UnderAttack.h" |
---|
| 30 | |
---|
[3196] | 31 | #include "util/Convert.h" |
---|
[2933] | 32 | #include "core/CoreIncludes.h" |
---|
[9667] | 33 | #include "core/config/ConfigValueIncludes.h" |
---|
[8858] | 34 | #include "chat/ChatManager.h" |
---|
[5735] | 35 | #include "worldentities/pawns/Destroyer.h" |
---|
| 36 | #include "infos/PlayerInfo.h" |
---|
[3020] | 37 | |
---|
[2933] | 38 | namespace orxonox |
---|
| 39 | { |
---|
[9667] | 40 | RegisterUnloadableClass(UnderAttack); |
---|
[2933] | 41 | |
---|
[9667] | 42 | UnderAttack::UnderAttack(Context* context) : TeamDeathmatch(context) |
---|
[2933] | 43 | { |
---|
| 44 | RegisterObject(UnderAttack); |
---|
[3057] | 45 | this->gameTime_ = 180; |
---|
[2933] | 46 | this->teams_ = 2; |
---|
| 47 | this->destroyer_ = 0; |
---|
[5929] | 48 | this->destroyer_.setCallback(createFunctor(&UnderAttack::killedDestroyer, this)); |
---|
[2933] | 49 | this->gameEnded_ = false; |
---|
| 50 | |
---|
| 51 | this->setConfigValues(); |
---|
[3301] | 52 | this->timesequence_ = static_cast<int>(this->gameTime_); |
---|
[2933] | 53 | } |
---|
| 54 | |
---|
[2952] | 55 | void UnderAttack::setConfigValues() |
---|
| 56 | { |
---|
[3057] | 57 | SetConfigValue(gameTime_, 180); |
---|
[2952] | 58 | } |
---|
| 59 | |
---|
[2933] | 60 | void UnderAttack::addDestroyer(Destroyer* destroyer) |
---|
| 61 | { |
---|
| 62 | this->destroyer_ = destroyer; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
[5929] | 66 | void UnderAttack::killedDestroyer() |
---|
[2933] | 67 | { |
---|
[5929] | 68 | this->end(); //end gametype |
---|
[6417] | 69 | std::string message("Ship destroyed! Team 0 has won!"); |
---|
[8858] | 70 | ChatManager::message(message); |
---|
[5929] | 71 | this->gameEnded_ = true; |
---|
| 72 | |
---|
| 73 | for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it) |
---|
[2933] | 74 | { |
---|
[8327] | 75 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[5929] | 76 | continue; |
---|
[3099] | 77 | |
---|
[5929] | 78 | if (it->second == 0) |
---|
| 79 | this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID()); |
---|
| 80 | else |
---|
| 81 | this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID()); |
---|
[2933] | 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | bool UnderAttack::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
| 86 | { |
---|
| 87 | if (victim == this->destroyer_) |
---|
| 88 | { |
---|
| 89 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
| 90 | { |
---|
| 91 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
| 92 | return true; |
---|
| 93 | else |
---|
| 94 | return false; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | return false; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | return TeamDeathmatch::allowPawnHit(victim, originator); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | bool UnderAttack::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
| 104 | { |
---|
| 105 | if (victim == this->destroyer_) |
---|
| 106 | { |
---|
| 107 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
| 108 | { |
---|
| 109 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
| 110 | return true; |
---|
| 111 | else |
---|
| 112 | return false; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | return false; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | return TeamDeathmatch::allowPawnDamage(victim, originator); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | bool UnderAttack::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
| 122 | { |
---|
| 123 | if (victim == this->destroyer_) |
---|
| 124 | { |
---|
| 125 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
| 126 | { |
---|
| 127 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
| 128 | return true; |
---|
| 129 | else |
---|
| 130 | return false; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | return false; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | return TeamDeathmatch::allowPawnDeath(victim, originator); |
---|
| 137 | } |
---|
[2971] | 138 | |
---|
| 139 | |
---|
[2933] | 140 | void UnderAttack::tick(float dt) |
---|
| 141 | { |
---|
[2935] | 142 | SUPER(UnderAttack, tick, dt); |
---|
| 143 | |
---|
[2971] | 144 | if (this->hasStarted() && !gameEnded_) |
---|
[2933] | 145 | { |
---|
[2935] | 146 | gameTime_ = gameTime_ - dt; |
---|
[2971] | 147 | if (gameTime_<= 0) |
---|
[2935] | 148 | { |
---|
[2971] | 149 | this->gameEnded_ = true; |
---|
[2952] | 150 | this->end(); |
---|
[6417] | 151 | std::string message("Time is up! Team 1 has won!"); |
---|
[8858] | 152 | ChatManager::message(message); |
---|
[3099] | 153 | |
---|
| 154 | for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it) |
---|
| 155 | { |
---|
[8327] | 156 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[3099] | 157 | continue; |
---|
| 158 | |
---|
| 159 | if (it->second == 1) |
---|
[5929] | 160 | this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID()); |
---|
[3099] | 161 | else |
---|
[5929] | 162 | this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID()); |
---|
[3099] | 163 | } |
---|
[2935] | 164 | } |
---|
[2971] | 165 | |
---|
| 166 | //prints gametime |
---|
[3099] | 167 | if ( gameTime_ <= timesequence_ && gameTime_ > 0) |
---|
[2971] | 168 | { |
---|
[6417] | 169 | const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!"; |
---|
[3099] | 170 | /* |
---|
[8858] | 171 | ChatManager::message(message); |
---|
[3099] | 172 | */ |
---|
[5929] | 173 | this->gtinfo_->sendAnnounceMessage(message); |
---|
[3099] | 174 | |
---|
[2971] | 175 | if (timesequence_ >= 30 && timesequence_ <= 60) |
---|
| 176 | { |
---|
| 177 | timesequence_ = timesequence_ - 10; |
---|
| 178 | } |
---|
| 179 | else if (timesequence_ <= 30) |
---|
| 180 | { |
---|
| 181 | timesequence_ = timesequence_ - 5; |
---|
| 182 | } |
---|
| 183 | else |
---|
| 184 | { |
---|
| 185 | timesequence_ = timesequence_ - 30; |
---|
| 186 | } |
---|
| 187 | } |
---|
[2933] | 188 | } |
---|
| 189 | } |
---|
| 190 | } |
---|