[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: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "UnderAttack.h" |
---|
| 31 | |
---|
| 32 | #include "core/CoreIncludes.h" |
---|
| 33 | #include "core/ConfigValueIncludes.h" |
---|
| 34 | #include "objects/Teamcolourable.h" |
---|
| 35 | #include "objects/worldentities/TeamSpawnPoint.h" |
---|
| 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
| 39 | CreateUnloadableFactory(UnderAttack); |
---|
| 40 | |
---|
| 41 | UnderAttack::UnderAttack(BaseObject* creator) : TeamDeathmatch(creator) |
---|
| 42 | { |
---|
| 43 | RegisterObject(UnderAttack); |
---|
| 44 | this->gameTime_ = 30; |
---|
| 45 | this->teams_ = 2; |
---|
| 46 | this->destroyer_ = 0; |
---|
| 47 | this->gameEnded_ = false; |
---|
| 48 | |
---|
| 49 | this->setConfigValues(); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void UnderAttack::addDestroyer(Destroyer* destroyer) |
---|
| 53 | { |
---|
| 54 | this->destroyer_ = destroyer; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | void UnderAttack::destroyedPawn(Pawn* pawn) |
---|
| 59 | { |
---|
| 60 | if (pawn == this->destroyer_) |
---|
| 61 | { |
---|
| 62 | |
---|
| 63 | COUT(0) << "Ship destroyed! Team 0 has won!" << std::endl; |
---|
| 64 | // Todo: end game |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | bool UnderAttack::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
| 69 | { |
---|
| 70 | if (victim == this->destroyer_) |
---|
| 71 | { |
---|
| 72 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
| 73 | { |
---|
| 74 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
| 75 | return true; |
---|
| 76 | else |
---|
| 77 | return false; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | return false; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | return TeamDeathmatch::allowPawnHit(victim, originator); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | bool UnderAttack::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
| 87 | { |
---|
| 88 | if (victim == this->destroyer_) |
---|
| 89 | { |
---|
| 90 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
| 91 | { |
---|
| 92 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
| 93 | return true; |
---|
| 94 | else |
---|
| 95 | return false; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | return false; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | return TeamDeathmatch::allowPawnDamage(victim, originator); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | bool UnderAttack::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
| 105 | { |
---|
| 106 | if (victim == this->destroyer_) |
---|
| 107 | { |
---|
| 108 | if (originator && originator->getPlayer() && !gameEnded_) |
---|
| 109 | { |
---|
| 110 | if (this->getTeam(originator->getPlayer()) == 0) |
---|
| 111 | return true; |
---|
| 112 | else |
---|
| 113 | return false; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | return false; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | return TeamDeathmatch::allowPawnDeath(victim, originator); |
---|
| 120 | } |
---|
| 121 | void UnderAttack::tick(float dt) |
---|
| 122 | { |
---|
| 123 | gameTime_ = gameTime_ - dt; |
---|
| 124 | if (gameTime_<= 0) |
---|
| 125 | { |
---|
| 126 | gameEnded_ = true; |
---|
| 127 | COUT(0) << "Time is up! Team 1 has won!" << std::endl; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | } |
---|