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