Skip to content

Commit

Permalink
move constants MaxLayers LayerHeight FloorZ from Isomot to the more r…
Browse files Browse the repository at this point in the history
…elevant Room
  • Loading branch information
dougmencken committed Feb 15, 2024
1 parent 0a8aae5 commit 6226613
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 67 deletions.
2 changes: 1 addition & 1 deletion source/AvatarItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ bool AvatarItem::addToPosition( int x, int y, int z )
}

// collision with ceiling
if ( z >= 0 && this->getZ() > ( Isomot::MaxLayers - 1 ) * Isomot::LayerHeight + ( Isomot::LayerHeight >> 1 ) )
if ( z >= 0 && this->getZ() > ( Room::MaxLayers - 1 ) * Room::LayerHeight + ( Room::LayerHeight >> 1 ) )
{
mediator->pushCollision( "ceiling" );
}
Expand Down
6 changes: 3 additions & 3 deletions source/Door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ FreeItemPtr Door::getLeftJamb()
;
}

leftJamb = FreeItemPtr( new FreeItem( leftJambData, x, y, Isomot::FloorZ, "none" ) );
leftJamb = FreeItemPtr( new FreeItem( leftJambData, x, y, Room::FloorZ, "none" ) );
leftJamb->getRawImageToChangeIt().expandOrCropTo( leftJambImage->getWidth (), leftJambImage->getHeight () );
allegro::bitBlit( leftJambImage->getAllegroPict(), leftJamb->getRawImageToChangeIt ().getAllegroPict() );
leftJamb->getRawImageToChangeIt().setName( leftJambImage->getName() );
Expand Down Expand Up @@ -338,7 +338,7 @@ FreeItemPtr Door::getRightJamb()
;
}

rightJamb = FreeItemPtr( new FreeItem( rightJambData, x, y, Isomot::FloorZ, "none" ) );
rightJamb = FreeItemPtr( new FreeItem( rightJambData, x, y, Room::FloorZ, "none" ) );
rightJamb->getRawImageToChangeIt().expandOrCropTo( rightJambImage->getWidth (), rightJambImage->getHeight () );
allegro::bitBlit( rightJambImage->getAllegroPict(), rightJamb->getRawImageToChangeIt ().getAllegroPict() );
rightJamb->getRawImageToChangeIt().setName( rightJambImage->getName() );
Expand Down Expand Up @@ -395,7 +395,7 @@ FreeItemPtr Door::getLintel()
;
}

lintel = FreeItemPtr( new FreeItem( lintelData, x, y, Isomot::FloorZ, "none" ) );
lintel = FreeItemPtr( new FreeItem( lintelData, x, y, Room::FloorZ, "none" ) );
lintel->getRawImageToChangeIt().expandOrCropTo( lintelImage->getWidth (), lintelImage->getHeight () );
allegro::bitBlit( lintelImage->getAllegroPict(), lintel->getRawImageToChangeIt ().getAllegroPict() );
lintel->getRawImageToChangeIt().setName( lintelImage->getName() );
Expand Down
1 change: 0 additions & 1 deletion source/GameSaverAndLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "GameManager.hpp"
#include "GameInfo.hpp"
#include "Isomot.hpp"
#include "MapManager.hpp"
#include "BonusManager.hpp"
#include "Mediator.hpp"
Expand Down
16 changes: 8 additions & 8 deletions source/Isomot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ void Isomot::handleMagicKeys ()

int characterX = activeCharacter->getX() ;
int characterY = activeCharacter->getY() ;
int characterZ = activeCharacter->getZ() + 2 * LayerHeight ;
int characterZ = activeCharacter->getZ() + 2 * Room::LayerHeight ;
const std::string & orientation = otherCharacter->getOrientation() ;

AvatarItemPtr joinedCharacter( new AvatarItem(
Expand Down Expand Up @@ -610,7 +610,7 @@ void Isomot::updateFinalRoom()

if ( arrived != nilPointer )
{
FreeItemPtr character( new FreeItem( arrived, 66, 92, Isomot::FloorZ, "south" ) );
FreeItemPtr character( new FreeItem( arrived, 66, 92, Room::FloorZ, "south" ) );
activeRoom->addFreeItem( character );
}

Expand All @@ -627,35 +627,35 @@ void Isomot::updateFinalRoom()
// la corona de Safari
if ( gameManager.isFreePlanet( "safari" ) )
{
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 66, 75, Isomot::FloorZ, "none" ) );
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 66, 75, Room::FloorZ, "none" ) );
activeRoom->addFreeItem( chapeau );
crowns++;
}
// la corona de Egyptus
if ( gameManager.isFreePlanet( "egyptus" ) )
{
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 66, 59, Isomot::FloorZ, "none" ) );
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 66, 59, Room::FloorZ, "none" ) );
activeRoom->addFreeItem( chapeau );
crowns++;
}
// la corona de Penitentiary
if ( gameManager.isFreePlanet( "penitentiary" ) )
{
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 65, 107, Isomot::FloorZ, "none" ) );
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 65, 107, Room::FloorZ, "none" ) );
activeRoom->addFreeItem( chapeau );
crowns++;
}
// la corona de Byblos
if ( gameManager.isFreePlanet( "byblos" ) )
{
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 65, 123, Isomot::FloorZ, "none" ) );
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 65, 123, Room::FloorZ, "none" ) );
activeRoom->addFreeItem( chapeau );
crowns++;
}
// la corona de Blacktooth
if ( gameManager.isFreePlanet( "blacktooth" ) )
{
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 65, 91, Isomot::FloorZ, "none" ) );
FreeItemPtr chapeau( new FreeItem( descriptionOfChapeau, 65, 91, Room::FloorZ, "none" ) );
activeRoom->addFreeItem( chapeau );
crowns++;
}
Expand All @@ -679,7 +679,7 @@ void Isomot::updateFinalRoom()
{
FreeItemPtr finalBall( new FreeItem (
ItemDescriptions::descriptions().getDescriptionByKind( "ball" ),
146, 93, LayerHeight, "none"
146, 93, Room::LayerHeight, "none"
) );
finalBall->setBehaviorOf( "behaivor of final ball" );
activeRoom->addFreeItem( finalBall );
Expand Down
17 changes: 0 additions & 17 deletions source/Isomot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,6 @@ class Isomot

void toggleCameraFollowsCharacter () { cameraFollowsCharacter = ! cameraFollowsCharacter ; }

/**
* The "z" position of the floor
*/
static const int FloorZ = -1 ;

/**
* The height in isometric units of a layer
* Item in the grid at height n is n * LayerHeight units
*/
static const int LayerHeight = 24 ;

/**
* The maximum number of layers in a room
* In isometric units, the maximum height of room is LayerHeight * MaxLayers
*/
static const int MaxLayers = 10 ;

static const unsigned int updatesPerSecond = 50 ;

private:
Expand Down
3 changes: 1 addition & 2 deletions source/MapManager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include "MapManager.hpp"

#include "Isomot.hpp"
#include "RoomBuilder.hpp"
#include "AvatarItem.hpp"
#include "Door.hpp"
Expand Down Expand Up @@ -607,7 +606,7 @@ Room* MapManager::changeRoom( const std::string& wayOfExit )
// create character

if ( wayOfEntry == "via teleport" || wayOfEntry == "via second teleport" )
entryZ = Isomot::FloorZ ;
entryZ = Room::FloorZ ;

// no taken item in new room
GameManager::getInstance().emptyHandbag();
Expand Down
6 changes: 3 additions & 3 deletions source/Mediator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,8 @@ bool Mediator::pickNextCharacter ()
&& ( previousCharacter->getX() + previousCharacter->getWidthX() - delta <= currentCharacter->getX() + currentCharacter->getWidthX() )
&& ( previousCharacter->getY() + delta >= currentCharacter->getY() )
&& ( previousCharacter->getY() + previousCharacter->getWidthY() - delta <= currentCharacter->getY() + currentCharacter->getWidthY() )
&& ( ( previousCharacter->getOriginalKind() == "head" && previousCharacter->getZ() - Isomot::LayerHeight == currentCharacter->getZ() )
|| ( previousCharacter->getOriginalKind() == "heels" && currentCharacter->getZ() - Isomot::LayerHeight == previousCharacter->getZ() ) ) )
&& ( ( previousCharacter->getOriginalKind() == "head" && previousCharacter->getZ() - Room::LayerHeight == currentCharacter->getZ() )
|| ( previousCharacter->getOriginalKind() == "heels" && currentCharacter->getZ() - Room::LayerHeight == previousCharacter->getZ() ) ) )
{
lockFreeItemsMutex ();

Expand Down Expand Up @@ -1145,7 +1145,7 @@ bool Mediator::pickNextCharacter ()
characterHeels->placeItemInBag( descriptionOfItemInBag->getKind (), behaviorOfItemInBag );
}

AvatarItemPtr characterHead = RoomBuilder::createCharacterInRoom( this->room, "head", false, x, y, z + Isomot::LayerHeight, orientation );
AvatarItemPtr characterHead = RoomBuilder::createCharacterInRoom( this->room, "head", false, x, y, z + Room::LayerHeight, orientation );

setActiveCharacter( ( this->lastActiveCharacterBeforeJoining == "head" ) ? characterHeels : characterHead );

Expand Down
22 changes: 11 additions & 11 deletions source/Room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ bool Room::saveAsXML( const std::string & file )
item->SetAttribute( "x", theItem->getCellX() );
item->SetAttribute( "y", theItem->getCellY() );
int z = theItem->getZ();
z = ( z > Isomot::FloorZ ) ? ( z / Isomot::LayerHeight ) : Isomot::FloorZ ;
z = ( z > Room::FloorZ ) ? ( z / Room::LayerHeight ) : Room::FloorZ ;
item->SetAttribute( "z", z );

tinyxml2::XMLElement* kindOfItem = roomXml.NewElement( "kind" );
Expand Down Expand Up @@ -435,7 +435,7 @@ bool Room::saveAsXML( const std::string & file )
item->SetAttribute( "x", theDoor->getCellX() );
item->SetAttribute( "y", theDoor->getCellY() );
int z = theDoor->getZ();
z = ( z > Isomot::FloorZ ) ? ( z / Isomot::LayerHeight ) : Isomot::FloorZ ;
z = ( z > Room::FloorZ ) ? ( z / Room::LayerHeight ) : Room::FloorZ ;
item->SetAttribute( "z", z );

tinyxml2::XMLElement* kindOfItem = roomXml.NewElement( "kind" );
Expand Down Expand Up @@ -656,7 +656,7 @@ void Room::addGridItem( const GridItemPtr& gridItem )

addGridItemToContainer( gridItem );

if ( gridItem->getZ() != Isomot::FloorZ )
if ( gridItem->getZ() != Room::FloorZ )
{
// when item goes lower than top, look for collisions
mediator->lookForCollisionsOf( gridItem->getUniqueName() );
Expand Down Expand Up @@ -696,7 +696,7 @@ void Room::addFreeItem( const FreeItemPtr& freeItem )
{
if ( freeItem == nilPointer ) return;

if ( freeItem->getX() < 0 || freeItem->getY() < 1 || freeItem->getZ() < Isomot::FloorZ )
if ( freeItem->getX() < 0 || freeItem->getY() < 1 || freeItem->getZ() < Room::FloorZ )
{
std::cerr << "coordinates for " << freeItem->whichItemClass() << " are out of limits" << std::endl ;
dumpItemInsideThisRoom( *freeItem );
Expand Down Expand Up @@ -735,7 +735,7 @@ void Room::addFreeItem( const FreeItemPtr& freeItem )
addFreeItemToContainer( freeItem );

// for item which is placed at some height, look for collisions
if ( freeItem->getZ() > Isomot::FloorZ )
if ( freeItem->getZ() > Room::FloorZ )
{
mediator->lookForCollisionsOf( freeItem->getUniqueName() );
}
Expand Down Expand Up @@ -807,7 +807,7 @@ bool Room::addCharacterToRoom( const AvatarItemPtr & character, bool characterEn
}
}

if ( character->getX() < 0 || character->getY() < 1 || character->getZ() < Isomot::FloorZ )
if ( character->getX() < 0 || character->getY() < 1 || character->getZ() < Room::FloorZ )
{
std::cerr << "coordinates for " << character->whichItemClass() << " are out of limits" << std::endl ;
dumpItemInsideThisRoom( *character );
Expand Down Expand Up @@ -849,12 +849,12 @@ bool Room::addCharacterToRoom( const AvatarItemPtr & character, bool characterEn
addFreeItemToContainer( character );

// for item which is placed at some height, look for collisions
if ( character->getZ() > Isomot::FloorZ )
if ( character->getZ() > Room::FloorZ )
{
mediator->lookForCollisionsOf( character->getUniqueName() );
while ( ! mediator->isStackOfCollisionsEmpty () )
{
character->setZ( character->getZ() + Isomot::LayerHeight );
character->setZ( character->getZ() + Room::LayerHeight );
mediator->clearStackOfCollisions ();
mediator->lookForCollisionsOf( character->getUniqueName() );
}
Expand Down Expand Up @@ -1225,7 +1225,7 @@ unsigned int Room::getHeightOfRoomImage () const
{
unsigned int roomH = /* height of plane */ ( getTilesX () + getTilesY () ) * getSizeOfOneTile ();

roomH += /* room’s height in 3D */ ( Isomot::MaxLayers + 2 ) * Isomot::LayerHeight ;
roomH += /* room’s height in 3D */ ( Room::MaxLayers + 2 ) * Room::LayerHeight ;
roomH += /* height of floor */ 8 ;

if ( ! hasDoorAt( "south" ) && ! hasDoorAt( "southwest" ) && ! hasDoorAt( "southeast" ) &&
Expand Down Expand Up @@ -1494,8 +1494,8 @@ bool Room::calculateEntryCoordinates( const std::string & way,
const FreeItemPtr & leftJamb = hasDoorAt( way ) ? doors[ way ]->getLeftJamb() : FreeItemPtr () ;

if ( leftJamb != nilPointer ) *z = leftJamb->getZ ();
else if ( way == "above" ) *z = Isomot::MaxLayers * Isomot::LayerHeight ;
else if ( way == "below" ) *z = Isomot::LayerHeight ;
else if ( way == "above" ) *z = Room::MaxLayers * Room::LayerHeight ;
else if ( way == "below" ) *z = Room::LayerHeight ;

bool okay = false ;
unsigned int oneTileSize = getSizeOfOneTile ();
Expand Down
20 changes: 18 additions & 2 deletions source/Room.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "Drawable.hpp"
#include "Mediated.hpp"
#include "Item.hpp"
#include "Isomot.hpp"
#include "GridItem.hpp"
#include "FreeItem.hpp"
#include "AvatarItem.hpp"
Expand Down Expand Up @@ -177,7 +176,7 @@ class Room : public Drawable, public Mediated
/**
* the Y coordinate of the room’s origin point
*/
int getY0 () const { return ( Isomot::MaxLayers + 2 ) * Isomot::LayerHeight ; }
int getY0 () const { return ( Room::MaxLayers + 2 ) * Room::LayerHeight ; }

unsigned int getWidthOfRoomImage () const ;

Expand Down Expand Up @@ -234,6 +233,23 @@ class Room : public Drawable, public Mediated

int getYCenterForItem ( const DescriptionOfItem * data ) ;

/**
* The "z" position of the floor
*/
static const int FloorZ = -1 ;

/**
* The height in isometric units of a layer
* Item in the grid at height n is n * LayerHeight units
*/
static const int LayerHeight = 24 ;

/**
* The maximum number of layers in a room
* In isometric units, the maximum height of room is LayerHeight * MaxLayers
*/
static const int MaxLayers = 10 ;

/**
* the rooms larger than this number of tiles are not "single"
*/
Expand Down
9 changes: 4 additions & 5 deletions source/RoomBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include "RoomBuilder.hpp"

#include "Isomot.hpp"
#include "MapManager.hpp"
#include "Room.hpp"
#include "Behavior.hpp"
Expand Down Expand Up @@ -624,7 +623,7 @@ GridItemPtr RoomBuilder::buildGridItem( tinyxml2::XMLElement* item, Room* room )
int itemX = std::atoi( item->Attribute( "x" ) );
int itemY = std::atoi( item->Attribute( "y" ) );
int itemZ = std::atoi( item->Attribute( "z" ) );
itemZ = ( itemZ > Isomot::FloorZ ) ? itemZ * Isomot::LayerHeight : Isomot::FloorZ ;
itemZ = ( itemZ > Room::FloorZ ) ? itemZ * Room::LayerHeight : Room::FloorZ ;

std::string theWay = "nowhere" ;
tinyxml2::XMLElement* orientation = item->FirstChildElement( "orientation" );
Expand Down Expand Up @@ -664,7 +663,7 @@ FreeItemPtr RoomBuilder::buildFreeItem( tinyxml2::XMLElement* item, Room* room )
unsigned int oneTileLong = room->getSizeOfOneTile ();
int fx = itemX * oneTileLong + ( ( oneTileLong - itemDescription->getWidthX() ) >> 1 );
int fy = ( itemY + 1 ) * oneTileLong - ( ( oneTileLong - itemDescription->getWidthY() ) >> 1 ) - 1 ;
int fz = ( itemZ != Isomot::FloorZ ) ? itemZ * Isomot::LayerHeight : Isomot::FloorZ ;
int fz = ( itemZ != Room::FloorZ ) ? itemZ * Room::LayerHeight : Room::FloorZ ;

// don’t create an item if it's a bonus that disappears once when taken
if ( BonusManager::getInstance().isAbsent( BonusInRoom( itemDescription->getKind (), room->getNameOfRoomDescriptionFile() ) ) )
Expand Down Expand Up @@ -743,8 +742,8 @@ Door* RoomBuilder::buildDoor( tinyxml2::XMLElement* item )
int itemY = std::atoi( item->Attribute( "y" ) );
int itemZ = std::atoi( item->Attribute( "z" ) );

// "z" can't be below the floor, that's less than Isomot::FloorZ = -1
itemZ = ( itemZ > Isomot::FloorZ ) ? itemZ * Isomot::LayerHeight : Isomot::FloorZ ;
// "z" can't be below the floor, that's less than Room::FloorZ = -1
itemZ = ( itemZ > Room::FloorZ ) ? itemZ * Room::LayerHeight : Room::FloorZ ;

std::string doorOrientation = "nowhere" ;
tinyxml2::XMLElement* orientation = item->FirstChildElement( "orientation" );
Expand Down
3 changes: 1 addition & 2 deletions source/behaviors/CharacterHeadAndHeels.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include "CharacterHeadAndHeels.hpp"

#include "Isomot.hpp"
#include "Item.hpp"
#include "DescriptionOfItem.hpp"
#include "AvatarItem.hpp"
Expand Down Expand Up @@ -143,7 +142,7 @@ bool CharacterHeadAndHeels::update ()
break;

case activities::Activity::ItemTaken:
characterItem.addToZ( - Isomot::LayerHeight );
characterItem.addToZ( - Room::LayerHeight );
activity = activities::Activity::Wait;
break;

Expand Down
3 changes: 1 addition & 2 deletions source/behaviors/CharacterHeels.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include "CharacterHeels.hpp"

#include "Isomot.hpp"
#include "Item.hpp"
#include "DescriptionOfItem.hpp"
#include "AvatarItem.hpp"
Expand Down Expand Up @@ -124,7 +123,7 @@ bool CharacterHeels::update()
break;

case activities::Activity::ItemTaken:
characterItem.addToZ( - Isomot::LayerHeight );
characterItem.addToZ( - Room::LayerHeight );
activity = activities::Activity::Wait;
break;

Expand Down
Loading

0 comments on commit 6226613

Please sign in to comment.