[2428] | 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 "GametypeInfo.h" |
---|
| 30 | |
---|
| 31 | #include "core/CoreIncludes.h" |
---|
[3099] | 32 | #include "core/GameMode.h" |
---|
| 33 | #include "network/NetworkFunction.h" |
---|
| 34 | #include "network/Host.h" |
---|
[3196] | 35 | #include "interfaces/GametypeMessageListener.h" |
---|
[2428] | 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
| 39 | CreateUnloadableFactory(GametypeInfo); |
---|
| 40 | |
---|
[3099] | 41 | registerMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage); |
---|
| 42 | registerMemberNetworkFunction(GametypeInfo, dispatchKillMessage); |
---|
| 43 | registerMemberNetworkFunction(GametypeInfo, dispatchDeathMessage); |
---|
[7163] | 44 | registerMemberNetworkFunction(GametypeInfo, dispatchStaticMessage); |
---|
| 45 | registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage); |
---|
[3099] | 46 | |
---|
[2428] | 47 | GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator) |
---|
| 48 | { |
---|
| 49 | RegisterObject(GametypeInfo); |
---|
| 50 | |
---|
| 51 | this->bStarted_ = false; |
---|
| 52 | this->bEnded_ = false; |
---|
| 53 | this->startCountdown_ = 0; |
---|
| 54 | this->bStartCountdownRunning_ = false; |
---|
| 55 | |
---|
| 56 | this->registerVariables(); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | GametypeInfo::~GametypeInfo() |
---|
| 60 | { |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | void GametypeInfo::registerVariables() |
---|
| 64 | { |
---|
[3280] | 65 | registerVariable(this->bStarted_, VariableDirection::ToClient); |
---|
| 66 | registerVariable(this->bEnded_, VariableDirection::ToClient); |
---|
| 67 | registerVariable(this->startCountdown_, VariableDirection::ToClient); |
---|
| 68 | registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient); |
---|
| 69 | registerVariable(this->hudtemplate_, VariableDirection::ToClient); |
---|
[2428] | 70 | } |
---|
[3099] | 71 | |
---|
[3196] | 72 | void GametypeInfo::sendAnnounceMessage(const std::string& message) |
---|
[3099] | 73 | { |
---|
| 74 | if (GameMode::isMaster()) |
---|
| 75 | { |
---|
| 76 | callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), CLIENTID_UNKNOWN, message); |
---|
| 77 | this->dispatchAnnounceMessage(message); |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
[3196] | 81 | void GametypeInfo::sendAnnounceMessage(const std::string& message, unsigned int clientID) |
---|
[3099] | 82 | { |
---|
| 83 | if (GameMode::isMaster()) |
---|
| 84 | { |
---|
| 85 | if (clientID == CLIENTID_SERVER) |
---|
| 86 | this->dispatchAnnounceMessage(message); |
---|
| 87 | else |
---|
| 88 | callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), clientID, message); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
[3196] | 92 | void GametypeInfo::sendKillMessage(const std::string& message, unsigned int clientID) |
---|
[3099] | 93 | { |
---|
| 94 | if (GameMode::isMaster()) |
---|
| 95 | { |
---|
| 96 | if (clientID == CLIENTID_SERVER) |
---|
| 97 | this->dispatchKillMessage(message); |
---|
| 98 | else |
---|
| 99 | callMemberNetworkFunction(GametypeInfo, dispatchKillMessage, this->getObjectID(), clientID, message); |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
[3196] | 103 | void GametypeInfo::sendDeathMessage(const std::string& message, unsigned int clientID) |
---|
[3099] | 104 | { |
---|
| 105 | if (GameMode::isMaster()) |
---|
| 106 | { |
---|
| 107 | if (clientID == CLIENTID_SERVER) |
---|
| 108 | this->dispatchDeathMessage(message); |
---|
| 109 | else |
---|
| 110 | callMemberNetworkFunction(GametypeInfo, dispatchDeathMessage, this->getObjectID(), clientID, message); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
[7163] | 114 | void GametypeInfo::sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour) |
---|
| 115 | { |
---|
| 116 | if (GameMode::isMaster()) |
---|
| 117 | { |
---|
| 118 | if (clientID == CLIENTID_SERVER) |
---|
| 119 | this->dispatchStaticMessage(message, colour); |
---|
| 120 | else |
---|
| 121 | callMemberNetworkFunction(GametypeInfo, dispatchStaticMessage, this->getObjectID(), clientID, message, colour); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void GametypeInfo::sendFadingMessage(const std::string& message, unsigned int clientID) |
---|
| 126 | { |
---|
| 127 | if (GameMode::isMaster()) |
---|
| 128 | { |
---|
| 129 | if (clientID == CLIENTID_SERVER) |
---|
| 130 | this->dispatchFadingMessage(message); |
---|
| 131 | else |
---|
| 132 | callMemberNetworkFunction(GametypeInfo, dispatchFadingMessage, this->getObjectID(), clientID, message); |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
[3196] | 136 | void GametypeInfo::dispatchAnnounceMessage(const std::string& message) |
---|
[3099] | 137 | { |
---|
| 138 | for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) |
---|
| 139 | it->announcemessage(this, message); |
---|
| 140 | } |
---|
| 141 | |
---|
[3196] | 142 | void GametypeInfo::dispatchKillMessage(const std::string& message) |
---|
[3099] | 143 | { |
---|
| 144 | for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) |
---|
| 145 | it->killmessage(this, message); |
---|
| 146 | } |
---|
| 147 | |
---|
[3196] | 148 | void GametypeInfo::dispatchDeathMessage(const std::string& message) |
---|
[3099] | 149 | { |
---|
| 150 | for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) |
---|
| 151 | it->deathmessage(this, message); |
---|
| 152 | } |
---|
[7163] | 153 | |
---|
| 154 | void GametypeInfo::dispatchStaticMessage(const std::string& message, const ColourValue& colour) |
---|
| 155 | { |
---|
| 156 | for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) |
---|
| 157 | it->staticmessage(this, message, colour); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | void GametypeInfo::dispatchFadingMessage(const std::string& message) |
---|
| 161 | { |
---|
| 162 | for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) |
---|
| 163 | it->fadingmessage(this, message); |
---|
| 164 | } |
---|
[2428] | 165 | } |
---|