[5838] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
[5841] | 12 | main-programmer: Silvan Nellen |
---|
| 13 | co-programmer: Benjamin Knecht |
---|
[5838] | 14 | */ |
---|
| 15 | |
---|
[5881] | 16 | |
---|
[5838] | 17 | #include "playable.h" |
---|
[7350] | 18 | #include "event_handler.h" |
---|
[5895] | 19 | |
---|
[5875] | 20 | #include "player.h" |
---|
[6241] | 21 | #include "state.h" |
---|
[7347] | 22 | #include "camera.h" |
---|
| 23 | |
---|
[7193] | 24 | #include "util/loading/load_param.h" |
---|
[5838] | 25 | |
---|
[6547] | 26 | #include "power_ups/weapon_power_up.h" |
---|
| 27 | #include "power_ups/param_power_up.h" |
---|
[5872] | 28 | |
---|
[7044] | 29 | #include "game_rules.h" |
---|
[6547] | 30 | |
---|
[6959] | 31 | #include "dot_emitter.h" |
---|
| 32 | #include "sprite_particles.h" |
---|
| 33 | |
---|
[7121] | 34 | #include "shared_network_data.h" |
---|
| 35 | |
---|
[7118] | 36 | #include "effects/explosion.h" |
---|
[6959] | 37 | |
---|
[7350] | 38 | #include "shell_command.h" |
---|
[7351] | 39 | SHELL_COMMAND_STATIC(orxoWeapon, Playable, Playable::addSomeWeapons_CHEAT); |
---|
[7118] | 40 | |
---|
[7350] | 41 | |
---|
[5838] | 42 | Playable::Playable() |
---|
[7338] | 43 | : weaponMan(this), |
---|
| 44 | supportedPlaymodes(Playable::Full3D), |
---|
| 45 | playmode(Playable::Full3D) |
---|
[5838] | 46 | { |
---|
[6442] | 47 | this->setClassID(CL_PLAYABLE, "Playable"); |
---|
| 48 | PRINTF(4)("PLAYABLE INIT\n"); |
---|
| 49 | |
---|
| 50 | this->toList(OM_GROUP_01); |
---|
| 51 | |
---|
| 52 | // the reference to the Current Player is NULL, because we dont have one at the beginning. |
---|
| 53 | this->currentPlayer = NULL; |
---|
[6695] | 54 | |
---|
[6804] | 55 | this->bFire = false; |
---|
[6868] | 56 | this->oldFlags = 0; |
---|
[6804] | 57 | |
---|
[6695] | 58 | this->setSynchronized(true); |
---|
[6959] | 59 | |
---|
| 60 | this->score = 0; |
---|
| 61 | this->oldScore = 0; |
---|
| 62 | |
---|
[7118] | 63 | this->bDead = false; |
---|
[5838] | 64 | } |
---|
| 65 | |
---|
[6695] | 66 | |
---|
[7346] | 67 | /** |
---|
| 68 | * @brief destroys the Playable |
---|
| 69 | */ |
---|
[5875] | 70 | Playable::~Playable() |
---|
[5838] | 71 | { |
---|
[6986] | 72 | // THE DERIVED CLASS MUST UNSUBSCRIBE THE PLAYER THROUGH |
---|
| 73 | // this->setPlayer(NULL); |
---|
| 74 | // IN ITS DESTRUCTOR. |
---|
| 75 | assert(this->currentPlayer == NULL); |
---|
[5875] | 76 | } |
---|
| 77 | |
---|
[7346] | 78 | /** |
---|
| 79 | * @brief loads Playable parameters onto the Playable |
---|
| 80 | * @param root the XML-root to load from |
---|
| 81 | */ |
---|
[7092] | 82 | void Playable::loadParams(const TiXmlElement* root) |
---|
| 83 | { |
---|
| 84 | WorldEntity::loadParams(root); |
---|
| 85 | |
---|
[7346] | 86 | LoadParam(root, "abs-dir", this, Playable, setPlayDirection); |
---|
[7092] | 87 | } |
---|
| 88 | |
---|
[7346] | 89 | /** |
---|
| 90 | * @brief picks up a powerup |
---|
| 91 | * @param powerUp the PowerUp that should be picked. |
---|
| 92 | * @returns true on success (pickup was picked, false otherwise) |
---|
| 93 | * |
---|
| 94 | * This function also checks if the Pickup can be picked up by this Playable |
---|
| 95 | */ |
---|
| 96 | bool Playable::pickup(PowerUp* powerUp) |
---|
| 97 | { |
---|
| 98 | if(powerUp->isA(CL_WEAPON_POWER_UP)) |
---|
| 99 | { |
---|
| 100 | return dynamic_cast<WeaponPowerUp*>(powerUp)->process(&this->getWeaponManager()); |
---|
| 101 | } |
---|
| 102 | else if(powerUp->isA(CL_PARAM_POWER_UP)) |
---|
| 103 | { |
---|
| 104 | ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp); |
---|
| 105 | switch(ppu->getType()) |
---|
| 106 | { |
---|
| 107 | case POWERUP_PARAM_HEALTH: |
---|
| 108 | this->increaseHealth(ppu->getValue()); |
---|
| 109 | return true; |
---|
| 110 | case POWERUP_PARAM_MAX_HEALTH: |
---|
| 111 | this->increaseHealthMax(ppu->getValue()); |
---|
| 112 | return true; |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | return false; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | /** |
---|
| 119 | * @brief adds a Weapon to the Playable. |
---|
| 120 | * @param weapon the Weapon to add. |
---|
| 121 | * @param configID the Configuration ID to add this weapon to. |
---|
| 122 | * @param slotID the slotID to add the Weapon to. |
---|
| 123 | */ |
---|
[7350] | 124 | bool Playable::addWeapon(Weapon* weapon, int configID, int slotID) |
---|
[6443] | 125 | { |
---|
[7350] | 126 | if(this->weaponMan.addWeapon(weapon, configID, slotID)) |
---|
| 127 | { |
---|
| 128 | this->weaponConfigChanged(); |
---|
| 129 | return true; |
---|
| 130 | } |
---|
| 131 | else |
---|
| 132 | { |
---|
| 133 | if (weapon != NULL) |
---|
| 134 | PRINTF(2)("Unable to add Weapon (%s::%s) to %s::%s\n", |
---|
[7351] | 135 | weapon->getClassName(), weapon->getName(), this->getClassName(), this->getName()); |
---|
[7350] | 136 | else |
---|
| 137 | PRINTF(2)("No weapon defined\n"); |
---|
| 138 | return false; |
---|
[6443] | 139 | |
---|
[7350] | 140 | } |
---|
[6443] | 141 | } |
---|
| 142 | |
---|
[7346] | 143 | /** |
---|
| 144 | * @brief removes a Weapon. |
---|
| 145 | * @param weapon the Weapon to remove. |
---|
| 146 | */ |
---|
[6443] | 147 | void Playable::removeWeapon(Weapon* weapon) |
---|
| 148 | { |
---|
[7337] | 149 | this->weaponMan.removeWeapon(weapon); |
---|
[6443] | 150 | |
---|
[7338] | 151 | this->weaponConfigChanged(); |
---|
[6443] | 152 | } |
---|
| 153 | |
---|
[7346] | 154 | /** |
---|
| 155 | * @brief jumps to the next WeaponConfiguration |
---|
| 156 | */ |
---|
[6444] | 157 | void Playable::nextWeaponConfig() |
---|
| 158 | { |
---|
[7337] | 159 | this->weaponMan.nextWeaponConfig(); |
---|
[7338] | 160 | this->weaponConfigChanged(); |
---|
[6444] | 161 | } |
---|
[6443] | 162 | |
---|
[7346] | 163 | /** |
---|
| 164 | * @brief moves to the last WeaponConfiguration |
---|
| 165 | */ |
---|
[6444] | 166 | void Playable::previousWeaponConfig() |
---|
| 167 | { |
---|
[7337] | 168 | this->weaponMan.previousWeaponConfig(); |
---|
[7338] | 169 | this->weaponConfigChanged(); |
---|
[6444] | 170 | } |
---|
| 171 | |
---|
[7346] | 172 | /** |
---|
| 173 | * @brief tells the Player, that the Weapon-Configuration has changed. |
---|
| 174 | * |
---|
| 175 | * TODO remove this |
---|
| 176 | * This function is needed, so that the WeponManager of this Playable can easily update the HUD |
---|
| 177 | */ |
---|
[6568] | 178 | void Playable::weaponConfigChanged() |
---|
| 179 | { |
---|
[6578] | 180 | if (this->currentPlayer != NULL) |
---|
| 181 | this->currentPlayer->weaponConfigChanged(); |
---|
[6568] | 182 | } |
---|
[6444] | 183 | |
---|
[7350] | 184 | /** |
---|
| 185 | * @brief a Cheat that gives us some Weapons |
---|
| 186 | */ |
---|
| 187 | void Playable::addSomeWeapons_CHEAT() |
---|
| 188 | { |
---|
[7351] | 189 | if (State::getPlayer() != NULL) |
---|
| 190 | { |
---|
| 191 | Playable* playable = State::getPlayer()->getPlayable(); |
---|
| 192 | if (playable != NULL) |
---|
| 193 | { |
---|
| 194 | PRINTF(2)("ADDING WEAPONS - you cheater\n"); |
---|
| 195 | playable->addWeapon(Weapon::createWeapon(CL_HYPERBLASTER)); |
---|
| 196 | playable->addWeapon(Weapon::createWeapon(CL_TURRET)); |
---|
| 197 | playable->addWeapon(Weapon::createWeapon(CL_AIMING_TURRET)); |
---|
| 198 | playable->addWeapon(Weapon::createWeapon(CL_CANNON)); |
---|
| 199 | playable->addWeapon(Weapon::createWeapon(CL_TARGETING_TURRET)); |
---|
| 200 | PRINTF(2)("ADDING WEAPONS FINISHED\n"); |
---|
| 201 | } |
---|
| 202 | } |
---|
[7350] | 203 | } |
---|
[7346] | 204 | |
---|
[7173] | 205 | /** |
---|
[7346] | 206 | * @brief subscribe to all events the controllable needs |
---|
| 207 | * @param player the player that shall controll this Playable |
---|
| 208 | * @returns false on error true otherwise. |
---|
| 209 | */ |
---|
| 210 | bool Playable::setPlayer(Player* player) |
---|
| 211 | { |
---|
| 212 | // if we already have a Player inside do nothing |
---|
| 213 | if (this->currentPlayer != NULL && player != NULL) |
---|
| 214 | { |
---|
| 215 | return false; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | // eject the Player if player == NULL |
---|
| 219 | if (this->currentPlayer != NULL && player == NULL) |
---|
| 220 | { |
---|
| 221 | PRINTF(4)("Player gets ejected\n"); |
---|
| 222 | |
---|
| 223 | // unsubscibe all events. |
---|
| 224 | EventHandler* evh = EventHandler::getInstance(); |
---|
| 225 | std::vector<int>::iterator ev; |
---|
| 226 | for (ev = this->events.begin(); ev != events.end(); ev++) |
---|
| 227 | evh->unsubscribe( ES_GAME, (*ev)); |
---|
| 228 | |
---|
| 229 | // leave the entity |
---|
| 230 | this->leave(); |
---|
| 231 | |
---|
| 232 | // eject the current Player. |
---|
| 233 | Player* ejectPlayer = this->currentPlayer; |
---|
| 234 | this->currentPlayer = NULL; |
---|
| 235 | // eject the Player. |
---|
| 236 | ejectPlayer->setPlayable(NULL); |
---|
| 237 | |
---|
| 238 | return true; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | // get the new Player inside |
---|
| 242 | if (this->currentPlayer == NULL && player != NULL) |
---|
| 243 | { |
---|
| 244 | PRINTF(4)("New Player gets inside\n"); |
---|
| 245 | this->currentPlayer = player; |
---|
| 246 | if (this->currentPlayer->getPlayable() != this) |
---|
| 247 | this->currentPlayer->setPlayable(this); |
---|
| 248 | |
---|
| 249 | /*EventHandler*/ |
---|
| 250 | EventHandler* evh = EventHandler::getInstance(); |
---|
| 251 | std::vector<int>::iterator ev; |
---|
| 252 | for (ev = this->events.begin(); ev != events.end(); ev++) |
---|
| 253 | evh->subscribe(player, ES_GAME, (*ev)); |
---|
| 254 | |
---|
| 255 | this->enter(); |
---|
| 256 | return true; |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | return false; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | /** |
---|
| 263 | * @brief attaches the current Camera to this Playable |
---|
| 264 | * |
---|
| 265 | * this function can be derived, so that any Playable can make the attachment differently. |
---|
| 266 | */ |
---|
| 267 | void Playable::attachCamera() |
---|
| 268 | { |
---|
| 269 | State::getCameraNode()->setParentSoft(this); |
---|
| 270 | State::getCameraTargetNode()->setParentSoft(this); |
---|
| 271 | |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | /** |
---|
| 275 | * @brief detaches the Camera |
---|
| 276 | * @see void Playable::attachCamera() |
---|
| 277 | */ |
---|
| 278 | void Playable::detachCamera() |
---|
| 279 | {} |
---|
| 280 | |
---|
| 281 | |
---|
| 282 | /** |
---|
[7173] | 283 | * @brief sets the CameraMode. |
---|
| 284 | * @param cameraMode: the Mode to switch to. |
---|
| 285 | */ |
---|
| 286 | void Playable::setCameraMode(unsigned int cameraMode) |
---|
[7347] | 287 | { |
---|
| 288 | State::getCamera()->setViewMode((Camera::ViewMode)cameraMode); |
---|
| 289 | } |
---|
[7338] | 290 | |
---|
[7346] | 291 | |
---|
[7338] | 292 | /** |
---|
| 293 | * @brief sets the Playmode |
---|
| 294 | * @param playmode the Playmode |
---|
| 295 | * @returns true on success, false otherwise |
---|
| 296 | */ |
---|
[7339] | 297 | bool Playable::setPlaymode(Playable::Playmode playmode) |
---|
[7173] | 298 | { |
---|
[7338] | 299 | if (!this->playmodeSupported(playmode)) |
---|
| 300 | return false; |
---|
| 301 | else |
---|
[7345] | 302 | { |
---|
[7347] | 303 | this->enterPlaymode(playmode); |
---|
[7338] | 304 | this->playmode = playmode; |
---|
[7345] | 305 | return true; |
---|
| 306 | } |
---|
[7173] | 307 | } |
---|
| 308 | |
---|
[7346] | 309 | /** |
---|
| 310 | * @brief This function look, that the Playable rotates to the given rotation. |
---|
| 311 | * @param angle the Angle around |
---|
| 312 | * @param dirX directionX |
---|
| 313 | * @param dirY directionY |
---|
| 314 | * @param dirZ directionZ |
---|
| 315 | * @param speed how fast to turn there. |
---|
| 316 | */ |
---|
| 317 | void Playable::setPlayDirection(float angle, float dirX, float dirY, float dirZ, float speed) |
---|
| 318 | { |
---|
| 319 | this->setPlayDirection(Quaternion(angle, Vector(dirX, dirY, dirZ)), speed); |
---|
| 320 | } |
---|
[7173] | 321 | |
---|
[5872] | 322 | /** |
---|
[7346] | 323 | * @brief all Playable will enter the Playmode Differently, say here how to do it. |
---|
| 324 | * @param playmode the Playmode to enter. |
---|
| 325 | * |
---|
| 326 | * In this function all the actions that are required to enter the Playmode are described. |
---|
| 327 | * e.g: camera, rotation, wait cycle and so on... |
---|
[7347] | 328 | * |
---|
| 329 | * on enter of this function the playmode is still the old playmode. |
---|
[7346] | 330 | */ |
---|
| 331 | void Playable::enterPlaymode(Playable::Playmode playmode) |
---|
| 332 | { |
---|
[7347] | 333 | switch(playmode) |
---|
| 334 | { |
---|
| 335 | default: |
---|
| 336 | this->attachCamera(); |
---|
| 337 | break; |
---|
| 338 | case Playable::Horizontal: |
---|
| 339 | this->setCameraMode(Camera::ViewTop); |
---|
| 340 | break; |
---|
| 341 | case Playable::Vertical: |
---|
| 342 | this->setCameraMode(Camera::ViewLeft); |
---|
| 343 | break; |
---|
| 344 | case Playable::FromBehind: |
---|
| 345 | this->setCameraMode(Camera::ViewBehind); |
---|
| 346 | break; |
---|
| 347 | } |
---|
[7346] | 348 | } |
---|
| 349 | /** |
---|
[6436] | 350 | * @brief helps us colliding Playables |
---|
[7346] | 351 | * @param entity the Entity to collide |
---|
| 352 | * @param location where the collision occured. |
---|
[6436] | 353 | */ |
---|
| 354 | void Playable::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 355 | { |
---|
[7072] | 356 | if (entity == collider) |
---|
| 357 | return; |
---|
| 358 | collider = entity; |
---|
| 359 | |
---|
[7121] | 360 | if ( entity->isA(CL_PROJECTILE) && ( !State::isOnline() || SharedNetworkData::getInstance()->isGameServer() ) ) |
---|
[6966] | 361 | { |
---|
[7072] | 362 | this->decreaseHealth(entity->getHealth() *(float)rand()/(float)RAND_MAX); |
---|
[6966] | 363 | // EXTREME HACK |
---|
[7072] | 364 | if (this->getHealth() <= 0.0f) |
---|
[6966] | 365 | { |
---|
| 366 | this->die(); |
---|
| 367 | } |
---|
| 368 | } |
---|
| 369 | } |
---|
[6436] | 370 | |
---|
[6966] | 371 | |
---|
[7044] | 372 | void Playable::respawn() |
---|
[6966] | 373 | { |
---|
[7044] | 374 | PRINTF(0)("Playable respawn\n"); |
---|
| 375 | // only if this is the spaceship of the player |
---|
| 376 | if( this == State::getPlayer()->getPlayable()) |
---|
| 377 | State::getGameRules()->onPlayerSpawn(); |
---|
[6966] | 378 | |
---|
[7085] | 379 | |
---|
[7082] | 380 | if( this->getOwner() % 2 == 0) |
---|
| 381 | { |
---|
[7338] | 382 | // this->toList(OM_GROUP_00); |
---|
[7082] | 383 | this->setAbsCoor(213.37, 57.71, -47.98); |
---|
[7100] | 384 | this->setAbsDir(0, 0, 1, 0); |
---|
[7082] | 385 | } |
---|
[6966] | 386 | else |
---|
[7099] | 387 | { // red team |
---|
[7338] | 388 | // this->toList(OM_GROUP_01); |
---|
[7082] | 389 | this->setAbsCoor(-314.450, 40.701, 83.554); |
---|
[7100] | 390 | this->setAbsDir(1.0, -0.015, -0.012, 0.011); |
---|
[7082] | 391 | } |
---|
[7118] | 392 | this->reset(); |
---|
| 393 | this->bDead = false; |
---|
[6436] | 394 | } |
---|
| 395 | |
---|
[6966] | 396 | |
---|
[7088] | 397 | |
---|
[7044] | 398 | void Playable::die() |
---|
| 399 | { |
---|
[7119] | 400 | Explosion::explode(dynamic_cast<PNode*>(this), Vector(1.0f, 1.0f, 1.0f)); |
---|
| 401 | |
---|
| 402 | |
---|
[7118] | 403 | if( !this->bDead) |
---|
| 404 | { |
---|
| 405 | PRINTF(0)("Playable dies\n"); |
---|
[7338] | 406 | // only if this is the spaceship of the player |
---|
[7118] | 407 | if (State::isOnline()) |
---|
| 408 | { |
---|
| 409 | if( this == State::getPlayer()->getPlayable()) |
---|
| 410 | State::getGameRules()->onPlayerDeath(); |
---|
[7044] | 411 | |
---|
[7338] | 412 | // this->toList(OM_GROUP_05); |
---|
| 413 | //HACK: moves the entity to an unknown place far far away: in the future, GameRules will look for that |
---|
[7118] | 414 | this->setAbsCoor(-2000.0, -2000.0, -2000.0); |
---|
[7078] | 415 | |
---|
[7338] | 416 | //explosion hack |
---|
[7118] | 417 | |
---|
| 418 | } |
---|
| 419 | this->bDead = true; |
---|
[7072] | 420 | } |
---|
[7044] | 421 | } |
---|
| 422 | |
---|
| 423 | |
---|
[6986] | 424 | |
---|
| 425 | |
---|
| 426 | |
---|
[5896] | 427 | /** |
---|
[7346] | 428 | * @brief add an event to the event list of events this Playable can capture |
---|
[5898] | 429 | * @param eventType the Type of event to add |
---|
[5889] | 430 | */ |
---|
[5896] | 431 | void Playable::registerEvent(int eventType) |
---|
[5889] | 432 | { |
---|
| 433 | this->events.push_back(eventType); |
---|
| 434 | |
---|
[5896] | 435 | if (this->currentPlayer != NULL) |
---|
| 436 | EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType); |
---|
[5889] | 437 | } |
---|
| 438 | |
---|
[5896] | 439 | /** |
---|
[7339] | 440 | * @brief remove an event to the event list this Playable can capture. |
---|
[5898] | 441 | * @param event the event to unregister. |
---|
[5896] | 442 | */ |
---|
| 443 | void Playable::unregisterEvent(int eventType) |
---|
| 444 | { |
---|
[7338] | 445 | std::vector<int>::iterator rmEvent = std::find(this->events.begin(), this->events.end(), eventType); |
---|
| 446 | this->events.erase(rmEvent); |
---|
[5889] | 447 | |
---|
[5896] | 448 | if (this->currentPlayer != NULL) |
---|
| 449 | EventHandler::getInstance()->unsubscribe(ES_GAME, eventType); |
---|
| 450 | } |
---|
[5889] | 451 | |
---|
[6804] | 452 | /** |
---|
| 453 | * @brief ticks a Playable |
---|
| 454 | * @param dt: the passed time since the last Tick |
---|
| 455 | */ |
---|
| 456 | void Playable::tick(float dt) |
---|
| 457 | { |
---|
[7337] | 458 | this->weaponMan.tick(dt); |
---|
[6804] | 459 | if (this->bFire) |
---|
[7337] | 460 | weaponMan.fire(); |
---|
[6804] | 461 | } |
---|
[5896] | 462 | |
---|
[6804] | 463 | |
---|
| 464 | /** |
---|
| 465 | * @brief processes Playable events. |
---|
| 466 | * @param event the Captured Event. |
---|
| 467 | */ |
---|
| 468 | void Playable::process(const Event &event) |
---|
| 469 | { |
---|
| 470 | if( event.type == KeyMapper::PEV_FIRE1) |
---|
| 471 | this->bFire = event.bPressed; |
---|
| 472 | else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed) |
---|
| 473 | { |
---|
| 474 | this->nextWeaponConfig(); |
---|
| 475 | } |
---|
| 476 | else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed) |
---|
| 477 | this->previousWeaponConfig(); |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | |
---|
[6959] | 481 | #define DATA_FLAGS 1 |
---|
| 482 | #define DATA_SCORE 2 |
---|
| 483 | |
---|
[6868] | 484 | #define FLAGS_bFire 1 |
---|
| 485 | |
---|
| 486 | int Playable::writeSync( const byte * data, int length, int sender ) |
---|
| 487 | { |
---|
| 488 | SYNCHELP_READ_BEGIN(); |
---|
[7010] | 489 | |
---|
[6994] | 490 | byte b; |
---|
| 491 | SYNCHELP_READ_BYTE( b, NWT_PL_B ); |
---|
[7010] | 492 | |
---|
[6868] | 493 | byte flags; |
---|
[7010] | 494 | |
---|
[6994] | 495 | if ( b == DATA_FLAGS ) |
---|
| 496 | { |
---|
| 497 | SYNCHELP_READ_BYTE( flags, NWT_PL_FLAGS ); |
---|
[6871] | 498 | |
---|
[6994] | 499 | bFire = (flags & FLAGS_bFire) != 0; |
---|
[7010] | 500 | |
---|
[6994] | 501 | return SYNCHELP_READ_N; |
---|
| 502 | } |
---|
[7010] | 503 | |
---|
[6994] | 504 | if ( b == DATA_SCORE ) |
---|
| 505 | { |
---|
| 506 | int newScore; |
---|
| 507 | SYNCHELP_READ_BYTE( newScore, NWT_PL_SCORE ); |
---|
| 508 | setScore( newScore ); |
---|
[7010] | 509 | |
---|
[6994] | 510 | return SYNCHELP_READ_N; |
---|
| 511 | } |
---|
[6871] | 512 | |
---|
[6868] | 513 | return SYNCHELP_READ_N; |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | int Playable::readSync( byte * data, int maxLength ) |
---|
| 517 | { |
---|
| 518 | SYNCHELP_WRITE_BEGIN(); |
---|
[7010] | 519 | |
---|
[6994] | 520 | if ( score != oldScore && isServer() ) |
---|
| 521 | { |
---|
| 522 | SYNCHELP_WRITE_BYTE( DATA_SCORE, NWT_PL_B); |
---|
| 523 | SYNCHELP_WRITE_INT( score, NWT_PL_SCORE ); |
---|
| 524 | oldScore = score; |
---|
[7010] | 525 | |
---|
[6994] | 526 | return SYNCHELP_WRITE_N; |
---|
| 527 | } |
---|
[7010] | 528 | |
---|
[6868] | 529 | byte flags = 0; |
---|
[6871] | 530 | |
---|
[6868] | 531 | if ( bFire ) |
---|
| 532 | flags |= FLAGS_bFire; |
---|
| 533 | |
---|
[6871] | 534 | |
---|
[6994] | 535 | SYNCHELP_WRITE_BYTE( DATA_FLAGS, NWT_PL_B); |
---|
[6868] | 536 | SYNCHELP_WRITE_BYTE( flags, NWT_PL_FLAGS ); |
---|
| 537 | oldFlags = flags; |
---|
| 538 | |
---|
[6871] | 539 | |
---|
[6868] | 540 | return SYNCHELP_WRITE_N; |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | bool Playable::needsReadSync( ) |
---|
| 544 | { |
---|
[6994] | 545 | if ( score != oldScore && isServer() ) |
---|
| 546 | return true; |
---|
[6959] | 547 | |
---|
[6868] | 548 | byte flags = 0; |
---|
[6871] | 549 | |
---|
[6868] | 550 | if ( bFire ) |
---|
| 551 | flags |= FLAGS_bFire; |
---|
[6871] | 552 | |
---|
[6868] | 553 | return flags!=oldFlags; |
---|
| 554 | } |
---|
[7339] | 555 | |
---|
| 556 | |
---|
[7346] | 557 | /** |
---|
| 558 | * @brief converts a string into a Playable::Playmode. |
---|
| 559 | * @param playmode the string naming the Playable::Playmode to convert. |
---|
| 560 | * @returns the Playable::Playmode converted from playmode. |
---|
| 561 | */ |
---|
[7339] | 562 | Playable::Playmode Playable::stringToPlaymode(const std::string& playmode) |
---|
| 563 | { |
---|
| 564 | if (playmode == "Vertical") |
---|
| 565 | return Playable::Vertical; |
---|
| 566 | if (playmode == "Horizontal") |
---|
| 567 | return Playable::Horizontal; |
---|
| 568 | if (playmode == "FromBehind") |
---|
| 569 | return Playable::FromBehind; |
---|
| 570 | if (playmode == "Full3D") |
---|
| 571 | return Playable::Full3D; |
---|
| 572 | |
---|
| 573 | return Playable::Full3D; |
---|
| 574 | } |
---|
| 575 | |
---|
[7346] | 576 | |
---|
| 577 | /** |
---|
| 578 | * @brief converts a playmode into a string. |
---|
| 579 | * @param playmode the Playable::Playmode to convert. |
---|
| 580 | * @returns the String. |
---|
| 581 | */ |
---|
[7339] | 582 | const char* Playable::playmodeToString(Playable::Playmode playmode) |
---|
| 583 | { |
---|
| 584 | switch(playmode) |
---|
| 585 | { |
---|
| 586 | case Playable::Vertical: |
---|
| 587 | return "Vertical"; |
---|
| 588 | case Playable::Horizontal: |
---|
| 589 | return "Horizontal"; |
---|
| 590 | case Playable::FromBehind: |
---|
| 591 | return "FromBehind"; |
---|
| 592 | case Playable::Full3D: |
---|
| 593 | return "Full3D"; |
---|
| 594 | |
---|
| 595 | default: |
---|
| 596 | return "Full3D"; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | } |
---|