[6586] | 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 "Dynamicmatch.h" |
---|
| 30 | |
---|
[6686] | 31 | #include "util/Convert.h" |
---|
[6586] | 32 | #include "core/CoreIncludes.h" |
---|
| 33 | #include "network/Host.h" |
---|
| 34 | #include "infos/PlayerInfo.h" |
---|
| 35 | #include "worldentities/pawns/Pawn.h" |
---|
[6697] | 36 | #include "worldentities/pawns/SpaceShip.h" |
---|
[6686] | 37 | #include "core/ConfigValueIncludes.h" |
---|
| 38 | #include "interfaces/TeamColourable.h" |
---|
[6697] | 39 | #include "items/Engine.h" |
---|
| 40 | #include "tools/Timer.h" |
---|
| 41 | |
---|
[6586] | 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | CreateUnloadableFactory(Dynamicmatch); |
---|
| 45 | |
---|
| 46 | Dynamicmatch::Dynamicmatch(BaseObject* creator) : Gametype(creator) |
---|
| 47 | { |
---|
| 48 | RegisterObject(Dynamicmatch); |
---|
[6686] | 49 | this->gameTime_ = 180; |
---|
| 50 | this->setConfigValues(); |
---|
| 51 | this->chaser=0; |
---|
| 52 | this->piggy=1; |
---|
| 53 | this->onlyChasers=true; |
---|
| 54 | this->gameEnded_ =false; |
---|
| 55 | this->timesequence_ = static_cast<int>(this->gameTime_); |
---|
| 56 | this->friendlyfire=true; |
---|
[6586] | 57 | } |
---|
| 58 | |
---|
[6697] | 59 | void Dynamicmatch::setConfigValues() |
---|
| 60 | { |
---|
| 61 | SetConfigValue(gameTime_, 180);//just for test cases |
---|
| 62 | SetConfigValue(friendlyfire, true); |
---|
| 63 | static ColourValue colours[] = |
---|
| 64 | { |
---|
| 65 | ColourValue(0.3f, 0.3f, 1.0f), |
---|
| 66 | ColourValue(1.0f, 0.3f, 0.3f) |
---|
| 67 | |
---|
| 68 | }; |
---|
| 69 | static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue)); |
---|
| 70 | |
---|
| 71 | SetConfigValue(partyColours_, defaultcolours); |
---|
| 72 | } |
---|
| 73 | |
---|
[6686] | 74 | void Dynamicmatch::setPlayerColour(PlayerInfo* player) // not sure if this is the right place - helper function |
---|
| 75 | { |
---|
| 76 | std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player); |
---|
| 77 | Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity()); |
---|
| 78 | if (pawn) |
---|
| 79 | { |
---|
| 80 | pawn->setRadarObjectColour(this->partyColours_[it_player->second]); //does this work? //what about playerParty_[it_player] instead of it_player->second |
---|
[6586] | 81 | |
---|
[6686] | 82 | std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects(); |
---|
| 83 | for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it) |
---|
| 84 | { |
---|
| 85 | if ((*it)->isA(Class(TeamColourable)))//not sure if this works |
---|
| 86 | { |
---|
| 87 | TeamColourable* tc = orxonox_cast<TeamColourable*>(*it); |
---|
| 88 | tc->setTeamColour(this->partyColours_[it_player->second]); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
[6586] | 93 | |
---|
| 94 | |
---|
[6686] | 95 | int Dynamicmatch::getParty(PlayerInfo* player) // helper function for ArtificialController |
---|
| 96 | { |
---|
| 97 | return this->playerParty_[player]; |
---|
| 98 | } |
---|
[6586] | 99 | |
---|
| 100 | |
---|
[6692] | 101 | bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)//tested - works fine |
---|
[6686] | 102 | { |
---|
[6586] | 103 | |
---|
[6686] | 104 | if (victim && victim->getPlayer()) |
---|
[6692] | 105 | { |
---|
| 106 | //Case 1: a chaser hits piggy // BUG: playerParty_[originator->getPlayer()]==chaser) is true even if victim is a chaser |
---|
| 107 | if ((!onlyChasers)&&(playerParty_[originator->getPlayer()]==chaser)&&playerParty_[victim->getPlayer()]==piggy) { |
---|
[6686] | 108 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer()); |
---|
| 109 | if (it != this->players_.end()) |
---|
| 110 | { |
---|
| 111 | it->second.frags_++; |
---|
| 112 | } |
---|
| 113 | } |
---|
[6692] | 114 | //Case 2: piggy hits chaser |
---|
[6686] | 115 | else if ((!onlyChasers)&&(playerParty_[originator->getPlayer()]==piggy)){ |
---|
| 116 | //partyswitch: victim bcomes piggy and the orginator(piggy) becomes chaser |
---|
| 117 | playerParty_[victim->getPlayer()]=piggy; |
---|
| 118 | playerParty_[originator->getPlayer()]=chaser; |
---|
| 119 | //announce |
---|
| 120 | const std::string& messageVictim = victim->getPlayer()->getName() + " is victim"; |
---|
| 121 | COUT(0) << messageVictim << std::endl; |
---|
| 122 | Host::Broadcast(messageVictim); |
---|
[6697] | 123 | |
---|
| 124 | //party switch -> colour switch |
---|
| 125 | setPlayerColour(victim->getPlayer()); //victim colour |
---|
| 126 | setPlayerColour(originator->getPlayer());//orginator colour |
---|
| 127 | |
---|
| 128 | //Give new pig boost |
---|
| 129 | SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim); |
---|
| 130 | if (spaceship && spaceship->getEngine()) |
---|
| 131 | { |
---|
| 132 | spaceship->getEngine()->setSpeedFactor(5); |
---|
| 133 | WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine()); |
---|
| 134 | new Timer(10, false, &createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this))->setDefaultValue(0, ptr), true); |
---|
| 135 | } |
---|
| 136 | |
---|
[6686] | 137 | } |
---|
| 138 | //Case 3: there are only chasers -> new piggy is needed |
---|
| 139 | else if (onlyChasers){ |
---|
| 140 | //Rollenzuweisung victim wird piggy |
---|
| 141 | playerParty_[victim->getPlayer()]=piggy; |
---|
| 142 | onlyChasers=false; |
---|
| 143 | setPlayerColour(victim->getPlayer()); //victim colour |
---|
[6697] | 144 | |
---|
| 145 | //Give new pig boost |
---|
| 146 | SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim); |
---|
| 147 | if (spaceship && spaceship->getEngine()) |
---|
| 148 | { |
---|
| 149 | spaceship->getEngine()->setSpeedFactor(5); |
---|
| 150 | WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine()); |
---|
| 151 | new Timer(10, false, &createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this))->setDefaultValue(0, ptr), true); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | |
---|
[6686] | 155 | std::string message("First victim."); |
---|
| 156 | COUT(0) << message << std::endl; |
---|
| 157 | Host::Broadcast(message); |
---|
| 158 | } |
---|
| 159 | else if (friendlyfire) |
---|
| 160 | { |
---|
| 161 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer()); |
---|
| 162 | if (it != this->players_.end()) |
---|
| 163 | { |
---|
| 164 | it->second.frags_--; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | return false; |
---|
| 170 | } |
---|
[6586] | 171 | |
---|
[6697] | 172 | void Dynamicmatch::resetSpeedFactor(WeakPtr<Engine>* ptr) |
---|
| 173 | { |
---|
| 174 | if (*ptr) |
---|
| 175 | { |
---|
| 176 | (*ptr)->setSpeedFactor(1.0f); |
---|
| 177 | } |
---|
| 178 | delete ptr; |
---|
| 179 | } |
---|
[6686] | 180 | |
---|
| 181 | bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator)// |
---|
[6586] | 182 | { |
---|
[6686] | 183 | return false; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | void Dynamicmatch::start() |
---|
| 187 | { |
---|
[6586] | 188 | Gametype::start(); |
---|
| 189 | |
---|
[6686] | 190 | std::string message("Don't be a victim!"); |
---|
[6586] | 191 | COUT(0) << message << std::endl; |
---|
| 192 | Host::Broadcast(message); |
---|
[6686] | 193 | |
---|
[6586] | 194 | } |
---|
| 195 | |
---|
| 196 | void Dynamicmatch::end() |
---|
| 197 | { |
---|
| 198 | Gametype::end(); |
---|
| 199 | |
---|
[6686] | 200 | std::string message("Time out. Press F2 to see the soreboard"); |
---|
[6586] | 201 | COUT(0) << message << std::endl; |
---|
| 202 | Host::Broadcast(message); |
---|
[6686] | 203 | /*for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it) |
---|
| 204 | { |
---|
| 205 | if (it->first->getClientID() == CLIENTID_UNKNOWN) |
---|
| 206 | continue; |
---|
| 207 | |
---|
| 208 | if (it->second == 1) |
---|
| 209 | this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID()); |
---|
| 210 | else |
---|
| 211 | this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID()); |
---|
| 212 | }*/ |
---|
[6586] | 213 | } |
---|
| 214 | |
---|
[6686] | 215 | |
---|
[6692] | 216 | void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring |
---|
[6586] | 217 | { |
---|
[6686] | 218 | if (!player) |
---|
| 219 | return; |
---|
[6697] | 220 | playerParty_[player]=chaser;//playerparty |
---|
| 221 | Dynamicmatch::setPlayerColour(player); //Set playercolour |
---|
[6686] | 222 | } |
---|
| 223 | |
---|
[6692] | 224 | void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction |
---|
[6686] | 225 | { |
---|
| 226 | |
---|
| 227 | if (!player)// only for safety |
---|
| 228 | return; |
---|
| 229 | |
---|
[6586] | 230 | Gametype::playerEntered(player); |
---|
[6686] | 231 | |
---|
[6586] | 232 | const std::string& message = player->getName() + " entered the game"; |
---|
| 233 | COUT(0) << message << std::endl; |
---|
| 234 | Host::Broadcast(message); |
---|
| 235 | } |
---|
| 236 | |
---|
[6686] | 237 | bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction |
---|
[6586] | 238 | { |
---|
| 239 | bool valid_player = Gametype::playerLeft(player); |
---|
[6686] | 240 | |
---|
| 241 | |
---|
[6586] | 242 | if (valid_player) |
---|
| 243 | { |
---|
| 244 | const std::string& message = player->getName() + " left the game"; |
---|
| 245 | COUT(0) << message << std::endl; |
---|
| 246 | Host::Broadcast(message); |
---|
[6686] | 247 | //remove player from map |
---|
| 248 | playerParty_.erase (player); |
---|
[6586] | 249 | } |
---|
| 250 | |
---|
| 251 | return valid_player; |
---|
| 252 | } |
---|
| 253 | |
---|
[6686] | 254 | bool Dynamicmatch::playerChangedName(PlayerInfo* player) //standardfunction |
---|
[6586] | 255 | { |
---|
| 256 | bool valid_player = Gametype::playerChangedName(player); |
---|
| 257 | |
---|
| 258 | if (valid_player) |
---|
| 259 | { |
---|
| 260 | const std::string& message = player->getOldName() + " changed name to " + player->getName(); |
---|
| 261 | COUT(0) << message << std::endl; |
---|
| 262 | Host::Broadcast(message); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | return valid_player; |
---|
| 266 | } |
---|
| 267 | |
---|
[6686] | 268 | |
---|
| 269 | |
---|
| 270 | void Dynamicmatch::tick(float dt) |
---|
[6586] | 271 | { |
---|
[6686] | 272 | SUPER(Dynamicmatch, tick, dt);//TODO - was bedeutet diese Zeile |
---|
| 273 | |
---|
| 274 | if (this->hasStarted() && !gameEnded_) |
---|
[6586] | 275 | { |
---|
[6686] | 276 | gameTime_ = gameTime_ - dt; |
---|
| 277 | if (gameTime_<= 0) |
---|
[6586] | 278 | { |
---|
[6686] | 279 | this->gameEnded_ = true; |
---|
| 280 | this->end(); |
---|
[6586] | 281 | } |
---|
[6686] | 282 | if ( gameTime_ <= timesequence_ && gameTime_ > 0) |
---|
| 283 | { |
---|
| 284 | const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!"; |
---|
[6586] | 285 | |
---|
[6686] | 286 | this->gtinfo_->sendAnnounceMessage(message); |
---|
[6586] | 287 | |
---|
[6686] | 288 | if (timesequence_ >= 30 && timesequence_ <= 60) |
---|
| 289 | { |
---|
| 290 | timesequence_ = timesequence_ - 10; |
---|
| 291 | } |
---|
| 292 | else if (timesequence_ <= 30) |
---|
| 293 | { |
---|
| 294 | timesequence_ = timesequence_ - 5; |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
| 298 | timesequence_ = timesequence_ - 30; |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | } |
---|
[6586] | 302 | } |
---|
| 303 | } |
---|