From 96c51acf0e491bbe5f1d2ac8fde605d823fe6777 Mon Sep 17 00:00:00 2001 From: Douglas Mencken Date: Sat, 7 Oct 2017 13:26:18 -0400 Subject: [PATCH] magic triplet to rebuild active room at any moment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit is option & shift & r inviolablility is now granted on mortal floor too and bin redundant “ preserving of orientation ” for player item there’s no issue #11 since yet --- src/Isomot.cpp | 22 +++++++++++---- src/Isomot.hpp | 2 ++ src/Item.cpp | 12 ++------ src/Item.hpp | 2 +- src/MapManager.cpp | 4 +-- src/PlayerItem.cpp | 40 +++++++++++++++++++++++++-- src/PlayerItem.hpp | 15 ++-------- src/activities/FallKindOfActivity.cpp | 6 ++-- src/activities/KindOfActivity.cpp | 12 -------- src/activities/MoveKindOfActivity.cpp | 1 - src/behaviors/UserControlled.cpp | 17 ++++-------- 11 files changed, 75 insertions(+), 58 deletions(-) diff --git a/src/Isomot.cpp b/src/Isomot.cpp index 00adf493..27560b85 100644 --- a/src/Isomot.cpp +++ b/src/Isomot.cpp @@ -204,6 +204,14 @@ BITMAP* Isomot::update() key[ KEY_MINUS ] = 0; } + if( ( key_shifts & KB_ALT_FLAG ) && ( key_shifts & KB_SHIFT_FLAG ) && key[ KEY_R ] ) + { + playTuneForScenery( activeRoom->getScenery () ); + activeRoom = mapManager->rebuildRoom(); + + key[ KEY_R ] = 0; + } + if( ( key_shifts & KB_ALT_FLAG ) && ( key_shifts & KB_SHIFT_FLAG ) && key[ KEY_J ] ) { PlayerItem* activePlayer = activeRoom->getMediator()->getActivePlayer(); @@ -358,11 +366,7 @@ BITMAP* Isomot::update() if ( activeRoom != 0 ) { - std::string scenery = activeRoom->getScenery (); - if ( scenery != "" ) - { - SoundManager::getInstance()->playOgg ( "music/" + scenery + ".ogg", /* loop */ false ); - } + playTuneForScenery( activeRoom->getScenery () ); } } } @@ -404,6 +408,14 @@ BITMAP* Isomot::update() return this->view; } +void Isomot::playTuneForScenery ( const std::string& scenery ) +{ + if ( scenery != "" ) + { + SoundManager::getInstance()->playOgg ( "music/" + scenery + ".ogg", /* loop */ false ); + } +} + void Isomot::updateEndRoom() { Room* activeRoom = mapManager->getActiveRoom(); diff --git a/src/Isomot.hpp b/src/Isomot.hpp index 759b5734..7b4ff309 100644 --- a/src/Isomot.hpp +++ b/src/Isomot.hpp @@ -67,6 +67,8 @@ class Isomot private: + void playTuneForScenery ( const std::string& scenery ) ; + void offVidasInfinitas () ; void offInviolability () ; diff --git a/src/Item.cpp b/src/Item.cpp index a2af181b..96739779 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -130,37 +130,31 @@ bool Item::animate() return cycle; } -void Item::changeItemData( ItemData* itemData, const Direction& direction, const std::string& initiatedBy ) +void Item::changeItemData( ItemData* itemData, const std::string& initiatedBy ) { std::cout << "metamorphosis of data for item with label \"" << getLabel() << "\" to data of \"" << itemData->label << "\" initiated by \"" << initiatedBy << "\"" << std::endl ; this->dataOfItem = itemData; - this->direction = direction; this->frameIndex = 0; this->backwardMotion = false; } void Item::changeDirection( const Direction& direction ) { - // Se cambia la dirección sólo si el elemento tiene distintos fotogramas para representar - // distintas direcciones + // direction is changed only when item has different frames for different directions if ( dataOfItem->directionFrames > 1 ) { - // Cálculo del fotograma correspondiente a la nueva dirección + // get frame for new direction unsigned int currentFrame = ( ( dataOfItem->motion.size() - dataOfItem->extraFrames ) / dataOfItem->directionFrames ) * direction; - // Si la imagen actual es distinta a la nueva imagen entonces se cambia if ( this->rawImage != 0 && currentFrame < dataOfItem->motion.size() && this->rawImage != dataOfItem->motion[ currentFrame ] ) { - // Actualiza la dirección this->direction = direction; - // Actualiza la imagen changeImage( dataOfItem->motion[ currentFrame ] ); - // Si cambia la imagen entonces cambia la sombra if ( this->shadow != 0 ) changeShadow( dataOfItem->shadows[ currentFrame ] ); } diff --git a/src/Item.hpp b/src/Item.hpp index de5c6640..dbe843e7 100644 --- a/src/Item.hpp +++ b/src/Item.hpp @@ -66,7 +66,7 @@ class Item : public Mediated /** * Change data of item preserving its label. Used when there’s a metamorphosis such as when player teleports */ - void changeItemData ( ItemData * itemData, const Direction& direction, const std::string& initiatedBy ) ; + void changeItemData ( ItemData * itemData, const std::string& initiatedBy ) ; /** * Cambia la dirección del elemento y establece el fotograma adecuado diff --git a/src/MapManager.cpp b/src/MapManager.cpp index 5dc1555f..db3bb7b8 100644 --- a/src/MapManager.cpp +++ b/src/MapManager.cpp @@ -296,7 +296,7 @@ Room* MapManager::changeRoom( const Direction& exit ) const int exitY = oldItemOfRoamer->getY (); const int exitZ = oldItemOfRoamer->getZ (); - const Direction exitOrientation = oldItemOfRoamer->getOrientation (); + const Direction exitOrientation = oldItemOfRoamer->getDirection (); // get limits of room // there’s possibility to exit and to enter new room in cases when player travels through floor, roof or via teletransport @@ -412,7 +412,7 @@ Room* MapManager::rebuildRoom() removeRoom( roomToForget ); } - direction = player->getOrientation(); + direction = player->getDirection(); Direction entry = player->getDirectionOfEntry(); diff --git a/src/PlayerItem.cpp b/src/PlayerItem.cpp index c7de1b98..95d4896f 100644 --- a/src/PlayerItem.cpp +++ b/src/PlayerItem.cpp @@ -20,7 +20,6 @@ PlayerItem::PlayerItem( ItemData* itemData, int x, int y, int z, const Direction , shield( 0 ) , howManyDoughnuts( 0 ) , exit( NoExit ) - , orientation( NoDirection ) , entry( JustWait ) , shieldTimer( 0 ) , shieldTime( 25.0 ) @@ -37,7 +36,6 @@ PlayerItem::PlayerItem( const PlayerItem& playerItem ) , tools( playerItem.tools ) , howManyDoughnuts( playerItem.howManyDoughnuts ) , exit( playerItem.exit ) - , orientation( playerItem.orientation ) , entry( playerItem.entry ) , shieldTimer( 0 ) , shieldTime( playerItem.shieldTime ) @@ -53,6 +51,44 @@ PlayerItem::~PlayerItem() } } +void PlayerItem::setDirectionOfExit ( const Direction& direction ) +{ + this->exit = direction; + + switch ( direction ) + { + case North: + case South: + case East: + case West: + setDirection( direction ); + break; + + case Northeast: + case Northwest: + setDirection( North ); + break; + + case Southeast: + case Southwest: + setDirection( South ); + break; + + case Eastnorth: + case Eastsouth: + setDirection( East ); + break; + + case Westnorth: + case Westsouth: + setDirection( West ); + break; + + default: + ; + } +} + void PlayerItem::autoMoveOnEntry ( const Direction& entry ) { setDirectionOfEntry( entry ); diff --git a/src/PlayerItem.hpp b/src/PlayerItem.hpp index d9ecb38f..1203fec1 100644 --- a/src/PlayerItem.hpp +++ b/src/PlayerItem.hpp @@ -22,6 +22,7 @@ namespace isomot class ItemData ; class GameManager ; + /** * Item of player controller by the user */ @@ -229,11 +230,6 @@ class PlayerItem : public FreeItem */ Direction exit ; - /** - * Direction player looks at when it leaves room - */ - Direction orientation ; - /** * How player enters room: through door, or via teleport, or going below floor or above ceiling */ @@ -310,17 +306,10 @@ class PlayerItem : public FreeItem /** * Direction of player when it leaves room */ - void setDirectionOfExit ( const Direction& direction ) { this->exit = direction ; } + void setDirectionOfExit ( const Direction& direction ) ; Direction getDirectionOfExit () const { return this->exit ; } - /** - * Direction player looks at when it leaves room - */ - void setOrientation ( const Direction& direction ) { this->orientation = direction ; } - - Direction getOrientation () const { return this->orientation ; } - /** * How player enters room */ diff --git a/src/activities/FallKindOfActivity.cpp b/src/activities/FallKindOfActivity.cpp index 2f0d4697..17a8ee02 100644 --- a/src/activities/FallKindOfActivity.cpp +++ b/src/activities/FallKindOfActivity.cpp @@ -118,12 +118,14 @@ bool FallKindOfActivity::fall( Behavior * behavior ) if ( mediator->getRoom()->getKindOfFloor() == "none" ) { playerItem->setDirectionOfExit( Down ); - playerItem->setOrientation( playerItem->getDirection() ); } else if ( mediator->getRoom()->getKindOfFloor() == "mortal" ) { - playerItem->getBehavior()->changeActivityOfItem( MeetMortalItem ); + if ( ! GameManager::getInstance()->isImmuneToCollisionsWithMortalItems () ) + { + playerItem->getBehavior()->changeActivityOfItem( MeetMortalItem ); + } } else /* if ( mediator->getRoom()->getKindOfFloor() == "plain" ) */ diff --git a/src/activities/KindOfActivity.cpp b/src/activities/KindOfActivity.cpp index cc6e7bcf..cac71b77 100644 --- a/src/activities/KindOfActivity.cpp +++ b/src/activities/KindOfActivity.cpp @@ -149,62 +149,50 @@ void KindOfActivity::propagateActivityToAdjacentItems( Item * sender, const Acti { case NorthBorder: player->setDirectionOfExit( North ); - player->setOrientation( North ); break; case SouthBorder: player->setDirectionOfExit( South ); - player->setOrientation( South ); break; case EastBorder: player->setDirectionOfExit( East ); - player->setOrientation( East ); break; case WestBorder: player->setDirectionOfExit( West ); - player->setOrientation( West ); break; case NortheastBorder: player->setDirectionOfExit( Northeast ); - player->setOrientation( North ); break; case NorthwestBorder: player->setDirectionOfExit( Northwest ); - player->setOrientation( North ); break; case SoutheastBorder: player->setDirectionOfExit( Southeast ); - player->setOrientation( South ); break; case SouthwestBorder: player->setDirectionOfExit( Southwest ); - player->setOrientation( South ); break; case EastnorthBorder: player->setDirectionOfExit( Eastnorth ); - player->setOrientation( East ); break; case EastsouthBorder: player->setDirectionOfExit( Eastsouth ); - player->setOrientation( East ); break; case WestnorthBorder: player->setDirectionOfExit( Westnorth ); - player->setOrientation( West ); break; case WestsouthBorder: player->setDirectionOfExit( Westsouth ); - player->setOrientation( West ); break; default: diff --git a/src/activities/MoveKindOfActivity.cpp b/src/activities/MoveKindOfActivity.cpp index a57a885a..32425920 100644 --- a/src/activities/MoveKindOfActivity.cpp +++ b/src/activities/MoveKindOfActivity.cpp @@ -288,7 +288,6 @@ void MoveKindOfActivity::ascent( FreeItem* freeItem, int z ) if ( playerItem != 0 && playerItem->getZ() >= MaxLayers * LayerHeight ) { playerItem->setDirectionOfExit( Up ); - playerItem->setOrientation( playerItem->getDirection() ); } } } diff --git a/src/behaviors/UserControlled.cpp b/src/behaviors/UserControlled.cpp index 52ba6b02..bc751823 100644 --- a/src/behaviors/UserControlled.cpp +++ b/src/behaviors/UserControlled.cpp @@ -315,7 +315,6 @@ void UserControlled::jump( PlayerItem * player ) if ( player->getZ() >= MaxLayers * LayerHeight ) { player->setDirectionOfExit( Up ); - player->setOrientation( player->getDirection() ); } } @@ -390,11 +389,10 @@ void UserControlled::wayInTeletransport( PlayerItem * player ) switch ( activity ) { case BeginWayInTeletransport: - // preserve orientation of player - player->setOrientation( player->getDirection() ); // change to bubbles preserving label of player playerData = player->getDataOfFreeItem() ; - player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), NoDirection, "begin way in teletransport" ); + player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), "begin way in teletransport" ); + // backward animation of bubbles player->setBackwardMotion(); @@ -407,9 +405,7 @@ void UserControlled::wayInTeletransport( PlayerItem * player ) if ( player->animate() ) { // back to original appearance of player - player->changeItemData( playerData, NoDirection, "way in teletransport" ); - // restore original orientation - player->changeDirection( player->getOrientation() ); + player->changeItemData( playerData, "way in teletransport" ); activity = Wait; } @@ -425,10 +421,9 @@ void UserControlled::wayOutTeletransport( PlayerItem * player ) switch ( activity ) { case BeginWayOutTeletransport: - // preserve orientation of player - player->setOrientation( player->getDirection() ); // change to bubbles retaining player’s label - player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), NoDirection, "begin way out teletransport" ); + player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), "begin way out teletransport" ); + // begin teleportation activity = WayOutTeletransport; break; @@ -457,7 +452,7 @@ void UserControlled::collideWithMortalItem( PlayerItem* player ) if ( player->getShieldTime() == 0 ) { // change to bubbles retaining player’s label - player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), NoDirection, "collide with mortal item" ); + player->changeItemData( itemDataManager->findItemByLabel( labelOfTransitionViaTeleport ), "collide with mortal item" ); activity = Vanish; }