From 579d7fb02f4f5b99580a89b11a7cd3834dbc3e76 Mon Sep 17 00:00:00 2001 From: Douglas Mencken Date: Sat, 3 Mar 2018 13:14:39 -0500 Subject: [PATCH] refactor more and deal with problem of getting game stuff ... when game lives in PATH and user runs it just by its name #22 yeah, that PathToGame is gone since yet change gui.Font & GuiManager to read the file with picture of letters once add more support for c++11 like nullptr and such change build scripts for osx with help from Atilla Kiss update Magyar ( hu_HU ) translation add extras/headoverheels.desktop --- build-osx.sh | 4 +- external/buildexternal-osx.sh | 179 ++++++++++++++++----- extras/headoverheels.desktop | 10 ++ gamedata/text/hu_HU.xml | 6 + src/BonusManager.cpp | 7 +- src/Camera.cpp | 8 +- src/Color.cpp | 5 +- src/Door.cpp | 18 +-- src/FloorTile.cpp | 10 +- src/FreeItem.cpp | 49 +++--- src/GameFileManager.cpp | 12 +- src/GameManager.cpp | 89 +++++----- src/GridItem.cpp | 10 +- src/InputManager.cpp | 6 +- src/InputManager.hpp | 44 +++-- src/Ism.cpp | 72 +++++---- src/Ism.hpp | 18 ++- src/Isomot.cpp | 48 +++--- src/Item.cpp | 39 ++--- src/Item.hpp | 4 +- src/ItemData.cpp | 3 +- src/ItemDataManager.cpp | 20 +-- src/Makefile.am | 1 - src/MapManager.cpp | 62 +++---- src/MapManager.hpp | 8 +- src/MapRoomData.cpp | 16 +- src/MapRoomData.hpp | 84 +--------- src/Mediator.cpp | 84 +++++----- src/Mediator.hpp | 10 +- src/PlayerItem.cpp | 47 +++--- src/Room.cpp | 27 ++-- src/Room.hpp | 2 +- src/RoomBuilder.cpp | 39 ++--- src/SoundManager.cpp | 32 ++-- src/SoundManager.hpp | 9 +- src/activities/DisplaceKindOfActivity.cpp | 42 +++-- src/activities/DisplaceKindOfActivity.hpp | 19 +-- src/activities/FallKindOfActivity.cpp | 14 +- src/activities/FallKindOfActivity.hpp | 3 - src/activities/JumpKindOfActivity.cpp | 12 +- src/activities/JumpKindOfActivity.hpp | 7 - src/activities/KindOfActivity.cpp | 6 +- src/activities/MoveKindOfActivity.cpp | 113 +++++++------ src/activities/MoveKindOfActivity.hpp | 31 ++-- src/behaviors/Behavior.cpp | 8 +- src/behaviors/Behavior.hpp | 4 +- src/behaviors/CannonBall.cpp | 2 +- src/behaviors/ConveyorBelt.cpp | 4 +- src/behaviors/Detector.cpp | 2 +- src/behaviors/Hunter.cpp | 8 +- src/behaviors/Mobile.cpp | 2 +- src/behaviors/PlayerHead.cpp | 8 +- src/behaviors/PlayerHeadAndHeels.cpp | 30 ++-- src/behaviors/PlayerHeels.cpp | 20 ++- src/behaviors/RemoteControl.cpp | 6 +- src/behaviors/Special.cpp | 8 +- src/behaviors/Switch.cpp | 2 +- src/behaviors/Teleport.cpp | 4 +- src/behaviors/UserControlled.cpp | 31 ++-- src/behaviors/UserControlled.hpp | 20 +-- src/behaviors/Volatile.cpp | 18 ++- src/gui/Font.cpp | 70 ++++---- src/gui/Font.hpp | 4 +- src/gui/Gui.cpp | 20 --- src/gui/Gui.hpp | 9 -- src/gui/GuiManager.cpp | 71 ++++---- src/gui/Label.cpp | 18 +-- src/gui/LanguageManager.cpp | 7 +- src/gui/Menu.cpp | 40 ++--- src/gui/MenuWithTwoColumns.cpp | 12 +- src/gui/MenuWithValues.cpp | 12 +- src/gui/Picture.cpp | 5 +- src/gui/Screen.cpp | 82 +++++----- src/guiactions/CreateAudioMenu.cpp | 16 +- src/guiactions/CreateLanguageMenu.cpp | 4 +- src/guiactions/CreateMenuOfGraphicSets.cpp | 8 +- src/guiactions/CreateVideoMenu.cpp | 12 +- src/guiactions/LoadGame.cpp | 2 +- src/guiactions/LoadGame.hpp | 4 +- src/guiactions/RedefineKey.cpp | 2 +- src/guiactions/SaveGame.cpp | 4 +- src/guiactions/SaveGame.hpp | 4 +- src/guiactions/ShowAuthors.cpp | 22 +-- 83 files changed, 954 insertions(+), 980 deletions(-) create mode 100644 extras/headoverheels.desktop delete mode 100644 src/gui/Gui.cpp diff --git a/build-osx.sh b/build-osx.sh index ceb489d3..b3c13cae 100755 --- a/build-osx.sh +++ b/build-osx.sh @@ -12,8 +12,8 @@ pathToCompiler="/Developer/GCC/${gccVersion}/PowerPC/32bit" # ="/usr" if [ ! -f src/Makefile ] then LDFLAGS="-L/opt/xerces-c-3.2.0/lib -L/opt/ogg-vorbis/lib -L/opt/libpng-1.6.34/lib -L/opt/zlib-1.2.8/lib -L${pathToCompiler}/lib" \ - CPPFLAGS="-I/opt/xerces-c-3.2.0/include" \ - CC="${pathToCompiler}/bin/gcc" CXX="${pathToCompiler}/bin/g++ -std=c++03" \ + CPPFLAGS="-I/opt/libpng-1.6.34/include -I/opt/xerces-c-3.2.0/include -I/opt/allegro-4.4.2/include" \ + CC="${pathToCompiler}/bin/gcc" CXX="${pathToCompiler}/bin/g++" \ ./configure --prefix=${installPrefix} --enable-debug fi diff --git a/external/buildexternal-osx.sh b/external/buildexternal-osx.sh index 9750fad4..4d01874e 100755 --- a/external/buildexternal-osx.sh +++ b/external/buildexternal-osx.sh @@ -14,40 +14,55 @@ echo " zlib" echo " a Massively Spiffy Yet Delicately Unobtrusive Compression Library" echo +zlib_version="1.2.8" + cd "${pathToExternal}"/zlib -tar xzf zlib-1.2.8.tar.gz -cd zlib-1.2.8 - -./configure --prefix=/opt/zlib-1.2.8 --libdir=/opt/zlib-1.2.8/lib --archs="" && make -make install DESTDIR=`pwd`/root32dir -CC="/usr/bin/gcc-4.2 -arch ppc64" CXX="/usr/bin/g++-4.2 -arch ppc64" ./configure --prefix=/opt/zlib-1.2.8 --libdir=/opt/zlib-1.2.8/lib --archs="" && make -make install DESTDIR=`pwd`/root64dir -lipo -create root32dir/opt/zlib-1.2.8/lib/libz.1.2.8.dylib root64dir/opt/zlib-1.2.8/lib/libz.1.2.8.dylib -output ./libz.1.2.8.dylib +[ -d "zlib-$zlib_version" ] || tar xzf zlib-"$zlib_version".tar.gz +cd zlib-"$zlib_version" + +if [ ! -f ./okay ]; then + +./configure --prefix=/opt/zlib-"$zlib_version" --libdir=/opt/zlib-"$zlib_version"/lib --archs="" && make make install -./configure --prefix=/opt/zlib-1.2.8 --libdir=/opt/zlib-1.2.8/lib --archs="" --static && make -make install DESTDIR=`pwd`/root32dir -CC="/usr/bin/gcc-4.2 -arch ppc64" CXX="/usr/bin/g++-4.2 -arch ppc64" ./configure --prefix=/opt/zlib-1.2.8 --libdir=/opt/zlib-1.2.8/lib --archs="" --static && make -make install DESTDIR=`pwd`/root64dir -lipo -create root32dir/opt/zlib-1.2.8/lib/libz.a root64dir/opt/zlib-1.2.8/lib/libz.a -output ./libz.a +./configure --prefix=/opt/zlib-"$zlib_version" --libdir=/opt/zlib-"$zlib_version"/lib --archs="" --static && make make install -file -h /opt/zlib-1.2.8/lib/libz* +file -h /opt/zlib-"$zlib_version"/lib/libz* +echo "okay" > ./okay + +else + +echo "already built" + +fi echo echo " libpng" echo " a Portable Network Graphics reference library which supports almost all PNG features" echo +libpng_version="1.6.34" + cd "${pathToExternal}"/libpng -tar xzf libpng-1.6.34.tar.gz -cd libpng-1.6.34 +[ -d libpng-"$libpng_version" ] || tar xzf libpng-"$libpng_version".tar.gz +cd libpng-"$libpng_version" -LDFLAGS="-L/opt/zlib-1.2.8/lib" ./configure --prefix=/opt/libpng-1.6.34 --enable-static --enable-shared --with-zlib-prefix=/opt/zlib-1.2.8 +if [ ! -f ./okay ]; then + +if [ ! -f ./Makefile ]; then + LDFLAGS="-L/opt/zlib-$zlib_version/lib" ./configure --prefix=/opt/libpng-"$libpng_version" --enable-static --enable-shared --with-zlib-prefix=/opt/zlib-"$zlib_version" +fi make make install -cd "${pathToExternal}" +echo "okay" > ./okay + +else + +echo "already built" + +fi echo echo " ogg-vorbis ( libogg, libvorbis, vorbis-tools )" @@ -57,71 +72,155 @@ echo echo " libogg" echo +libogg_version="1.3.3" + cd "${pathToExternal}"/ogg-vorbis -tar xzf libogg-1.3.3.tar.gz -cd libogg-1.3.3 +[ -d libogg-"$libogg_version" ] || tar xzf libogg-"$libogg_version".tar.gz +cd libogg-"$libogg_version" + +if [ ! -f ./okay ]; then -./configure --prefix=/opt/ogg-vorbis && make +if [ ! -f ./Makefile ]; then + ./configure --prefix=/opt/ogg-vorbis && make +fi make install rm -r -f /usr/include/ogg ln -s /opt/ogg-vorbis/include/ogg /usr/include/ogg +echo "okay" > ./okay + +else + +echo "already built" + +fi + echo echo " libvorbis" echo +libvorbis_version="1.3.5" + cd "${pathToExternal}"/ogg-vorbis -tar xzf libvorbis-1.3.5.tar.gz -cd libvorbis-1.3.5 +[ -d libvorbis-"$libvorbis_version" ] || tar xzf libvorbis-"$libvorbis_version".tar.gz +cd libvorbis-"$libvorbis_version" + +if [ ! -f ./okay ]; then -./configure --prefix=/opt/ogg-vorbis --with-ogg=/opt/ogg-vorbis && make +if [ ! -f ./Makefile ]; then + ./configure --prefix=/opt/ogg-vorbis --with-ogg=/opt/ogg-vorbis && make +fi make install rm -f -r /usr/include/vorbis ln -s /opt/ogg-vorbis/include/vorbis /usr/include/vorbis +echo "okay" > ./okay + +else + +echo "already built" + +fi + echo echo " vorbis-tools" echo +vorbistools_version="1.4.0" + cd "${pathToExternal}"/ogg-vorbis -tar xzf vorbis-tools-1.4.0.tar.gz -cd vorbis-tools-1.4.0 +[ -d vorbis-tools-"$vorbistools_version" ] || tar xzf vorbis-tools-"$vorbistools_version".tar.gz +cd vorbis-tools-"$vorbistools_version" -./configure --prefix=/opt/ogg-vorbis --with-ogg=/opt/ogg-vorbis --with-vorbis=/opt/ogg-vorbis && make +if [ ! -f ./okay ]; then + +if [ ! -f ./Makefile ]; then + ./configure --prefix=/opt/ogg-vorbis --with-ogg=/opt/ogg-vorbis --with-vorbis=/opt/ogg-vorbis && make +fi make install +echo "okay" > ./okay + +else + +echo "already built" + +fi + echo echo " xerces-c" echo " a validating XML parser written in a portable subset of C++" echo +xercesc_version="3.2.0" + cd "${pathToExternal}"/xerces-c -tar xjf xerces-c-3.2.0.tar.bz2 -cd xerces-c-3.2.0 +[ -d xerces-c-"$xercesc_version" ] || tar xjf xerces-c-"$xercesc_version".tar.bz2 +cd xerces-c-"$xercesc_version" -CC="/usr/bin/gcc-4.2" CXX="/usr/bin/g++-4.2" ./configure --prefix=/opt/xerces-c-3.2.0 +if [ ! -f ./okay ]; then + +if [ ! -f ./Makefile ]; then + ./configure --prefix=/opt/xerces-c-"$xercesc_version" +fi make make install +echo "okay" > ./okay + +else + +echo "already built" + +fi + echo echo " allegro 4" echo " a cross-platform library for video game and multimedia programming" echo -cd "${pathToExternal}"/allegro -tar xzf allegro-4.4.2.tar.gz -cd allegro-4.4.2 +allegro4_version="4.4.2" -mkdir TheBuild && cd TheBuild -export CC="/usr/bin/gcc-4.2" CXX="/usr/bin/g++-4.2" -cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/opt/allegro-4.4.2 .. -make -mkdir -p docs/txt ; cp ./docs/build/* ./docs/txt/ && make install +if [ -x "$( command -v cmake )" ]; then -rm -f /usr/bin/allegro-config -ln -s /opt/allegro-4.4.2/bin/allegro-config /usr/bin/allegro-config + cd "${pathToExternal}"/allegro + [ -d allegro-"$allegro4_version" ] || tar xzf allegro-"$allegro4_version".tar.gz + cd allegro-"$allegro4_version" + + if [ ! -f ./okay ]; then + + [ -d TheBuild ] || mkdir TheBuild + + cd TheBuild + + if [ ! -f ./Makefile ]; then + # export CC=`command -v gcc` CXX=`command -v g++` + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/opt/allegro-"$allegro4_version" -DCMAKE_C_FLAGS:STRING="-fno-common" .. + fi + + make + mkdir -p docs/txt ; cp ./docs/build/* ./docs/txt/ && make install + + cd .. + + rm -f /usr/bin/allegro-config + ln -s /opt/allegro-"$allegro4_version"/bin/allegro-config /usr/bin/allegro-config + + echo "okay" > ./okay + + else + + echo "already built" + + fi + +else + + echo "can’t build allegro 4, it needs cmake to build" + +fi echo echo " the end" diff --git a/extras/headoverheels.desktop b/extras/headoverheels.desktop new file mode 100644 index 00000000..03911992 --- /dev/null +++ b/extras/headoverheels.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=headoverheels +GenericName=Head over Heels +Comment=Solid 3d Game +Comment[hu]=Klasszikus szobás játék +Exec=headoverheels +Icon=headoverheels +StartupNotify=false +Type=Application +Categories=Game;ActionGame;PuzzleGame diff --git a/gamedata/text/hu_HU.xml b/gamedata/text/hu_HU.xml index 254393b1..286349bb 100644 --- a/gamedata/text/hu_HU.xml +++ b/gamedata/text/hu_HU.xml @@ -192,6 +192,12 @@ + + + helyiség dallamok + + + alkotók diff --git a/src/BonusManager.cpp b/src/BonusManager.cpp index b89b6443..95528cd8 100644 --- a/src/BonusManager.cpp +++ b/src/BonusManager.cpp @@ -1,5 +1,6 @@ #include "BonusManager.hpp" +#include "Ism.hpp" namespace isomot @@ -15,11 +16,11 @@ BonusManager::~BonusManager( ) bonusRooms.clear(); } -BonusManager * BonusManager::instance = 0 ; +BonusManager * BonusManager::instance = nilPointer ; BonusManager* BonusManager::getInstance () { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new BonusManager(); } @@ -101,7 +102,7 @@ bool BonusRoom::isPresent ( const std::string& label ) bool BonusRoom::operator== ( const std::string& fileName ) { - return ( this->nameOfFile.compare( fileName ) == 0 ) ; + return ( this->nameOfFile == fileName ) ; } } diff --git a/src/Camera.cpp b/src/Camera.cpp index 8c628394..b89d54a3 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -25,7 +25,7 @@ void Camera::turnOn( PlayerItem* player, const Way& wayOfEntry ) { const unsigned int maxTilesOfSingleRoom = 10 ; - if ( delta.first == 0 && delta.second == 0 && player != 0 && + if ( delta.first == 0 && delta.second == 0 && player != nilPointer && ( room->getTilesX() > maxTilesOfSingleRoom || room->getTilesY() > maxTilesOfSingleRoom ) ) { // is it double room along Y @@ -66,7 +66,7 @@ void Camera::turnOn( PlayerItem* player, const Way& wayOfEntry ) else { TripleRoomInitialPoint* initialPoint = room->findInitialPointOfEntryToTripleRoom( wayOfEntry ); - if ( initialPoint != 0 ) + if ( initialPoint != nilPointer ) { delta.first = initialPoint->getX(); delta.second = initialPoint->getY(); @@ -93,7 +93,7 @@ bool Camera::centerOn( PlayerItem* player ) bool changed = false; // Sala triple - if ( ( room->getTilesX() > maxTilesOfSingleRoom && room->getTilesY() > maxTilesOfSingleRoom ) && player != 0 ) + if ( ( room->getTilesX() > maxTilesOfSingleRoom && room->getTilesY() > maxTilesOfSingleRoom ) && player != nilPointer ) { // Debe haber cambio en el eje X para realizar los cálculos if ( reference.first - player->getX() != 0 && room->getTilesX() > maxTilesOfSingleRoom ) @@ -148,7 +148,7 @@ bool Camera::centerOn( PlayerItem* player ) } } // Sala doble - else if ( ( room->getTilesX() > maxTilesOfSingleRoom || room->getTilesY() > maxTilesOfSingleRoom ) && player != 0 ) + else if ( ( room->getTilesX() > maxTilesOfSingleRoom || room->getTilesY() > maxTilesOfSingleRoom ) && player != nilPointer ) { // Debe haber cambio en el eje X para realizar los cálculos if ( reference.first - player->getX() != 0 && room->getTilesX() > maxTilesOfSingleRoom ) diff --git a/src/Color.cpp b/src/Color.cpp index 673bdb3b..9a894aa6 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -1,5 +1,6 @@ #include "Color.hpp" +#include "Ism.hpp" #include // for sqrt @@ -22,7 +23,7 @@ BITMAP* Color::colorizePicture( BITMAP* picture, Color* color ) /* private static */ BITMAP* Color::colorizePicture( BITMAP* picture, unsigned char red, unsigned char green, unsigned char blue ) { - if ( picture == 0 ) return 0 ; + if ( picture == nilPointer ) return nilPointer ; for ( int x = 0; x < picture->w; x++ ) { @@ -41,7 +42,7 @@ BITMAP* Color::colorizePicture( BITMAP* picture, unsigned char red, unsigned cha /* public static */ BITMAP * Color::pictureToGrayscale ( BITMAP * picture ) { - if ( picture == 0 ) return 0 ; + if ( picture == nilPointer ) return nilPointer ; for ( int y = 0; y < picture->h; y++ ) { diff --git a/src/Door.cpp b/src/Door.cpp index 187bb2d9..62ca0cc3 100644 --- a/src/Door.cpp +++ b/src/Door.cpp @@ -15,9 +15,9 @@ Door::Door( ItemDataManager * itemData, const std::string& label, int cx, int cy , cy( cy ) , z( z ) , positionOfDoor( way ) - , leftJamb( 0 ) - , rightJamb( 0 ) - , lintel( 0 ) + , leftJamb( nilPointer ) + , rightJamb( nilPointer ) + , lintel( nilPointer ) { /* std::cout << "creation of door \"" << labelOfDoor << "\"" << std::endl ; */ } @@ -29,14 +29,14 @@ Door::~Door() FreeItem* Door::getLeftJamb() { - if ( leftJamb == 0 ) + if ( leftJamb == nilPointer ) { int x( 0 ), y( 0 ); int tileSize = mediator->getRoom()->getSizeOfOneTile(); ItemData* leftJambData = itemDataManager->findItemByLabel( labelOfDoor + "~leftjamb" ); - if ( leftJambData != 0 ) + if ( leftJambData != nilPointer ) { switch ( getWhereIsDoor().getIntegerOfWay() ) { @@ -85,14 +85,14 @@ FreeItem* Door::getLeftJamb() FreeItem* Door::getRightJamb() { - if ( rightJamb == 0 ) + if ( rightJamb == nilPointer ) { int x( 0 ), y( 0 ); int tileSize = mediator->getRoom()->getSizeOfOneTile(); ItemData* rightJambData = itemDataManager->findItemByLabel( labelOfDoor + "~rightjamb" ); - if ( rightJambData != 0 ) + if ( rightJambData != nilPointer ) { switch ( getWhereIsDoor().getIntegerOfWay() ) { @@ -141,14 +141,14 @@ FreeItem* Door::getRightJamb() FreeItem* Door::getLintel() { - if ( lintel == 0 ) + if ( lintel == nilPointer ) { int x( 0 ), y( 0 ); int tileSize = mediator->getRoom()->getSizeOfOneTile(); ItemData* lintelData = itemDataManager->findItemByLabel( labelOfDoor + "~lintel" ); - if ( lintelData != 0 ) + if ( lintelData != nilPointer ) { switch ( getWhereIsDoor().getIntegerOfWay() ) { diff --git a/src/FloorTile.cpp b/src/FloorTile.cpp index 7943d952..3c70d55a 100644 --- a/src/FloorTile.cpp +++ b/src/FloorTile.cpp @@ -12,7 +12,7 @@ FloorTile::FloorTile( int column, int x, int y, BITMAP* image ) : Mediated () , column( column ) , rawImage( image ) - , shadyImage( 0 ) + , shadyImage( nilPointer ) { this->coordinates.first = x; this->coordinates.second = y; @@ -28,7 +28,7 @@ FloorTile::~FloorTile() void FloorTile::calculateOffset() { - if ( mediator != 0 ) + if ( mediator != nilPointer ) { Room* room = mediator->getRoom(); this->offset.first = room->getX0() + ( ( room->getSizeOfOneTile() * ( coordinates.first - coordinates.second - 1 ) ) << 1 ) + 1; @@ -38,11 +38,11 @@ void FloorTile::calculateOffset() void FloorTile::draw( BITMAP* where ) { - if ( shadyImage != 0 ) + if ( shadyImage != nilPointer ) { // draw tile with shadow draw_sprite( where, shadyImage, offset.first, offset.second ); } - else if ( rawImage != 0 ) + else if ( rawImage != nilPointer ) { // draw tile, just tile draw_sprite( where, rawImage, offset.first, offset.second ); } @@ -58,7 +58,7 @@ void FloorTile::requestShadow() if ( this->shady != AlreadyShady && this->shadyImage ) { destroy_bitmap( this->shadyImage ); - this->shadyImage = 0; + this->shadyImage = nilPointer; } // Reinicia el atributo para el siguiente ciclo diff --git a/src/FreeItem.cpp b/src/FreeItem.cpp index e5577aee..ec8ae052 100644 --- a/src/FreeItem.cpp +++ b/src/FreeItem.cpp @@ -13,12 +13,11 @@ FreeItem::FreeItem( ItemData* itemData, int x, int y, int z, const Way& way ) , transparency ( 0 ) , collisionDetector ( true ) , frozen ( false ) - , shadyImage ( 0 ) + , shadyImage ( nilPointer ) { this->x = x; this->y = y; if ( y < 0 ) this->y = 0; - this->anchor = 0; // init frames int howManyFrames = ( getDataOfItem()->howManyMotions() - getDataOfItem()->howManyExtraFrames() ) / getDataOfItem()->howManyFramesForOrientations() ; @@ -42,9 +41,9 @@ FreeItem::FreeItem( const FreeItem& freeItem ) , transparency( freeItem.transparency ) , collisionDetector( freeItem.collisionDetector ) , frozen( freeItem.frozen ) - , shadyImage( 0 ) + , shadyImage( nilPointer ) { - if ( freeItem.shadyImage != 0 ) + if ( freeItem.shadyImage != nilPointer ) { this->shadyImage = create_bitmap_ex( 32, freeItem.shadyImage->w, freeItem.shadyImage->h ); blit( freeItem.shadyImage, this->shadyImage, 0, 0, 0, 0, this->shadyImage->w, this->shadyImage->h ); @@ -53,7 +52,7 @@ FreeItem::FreeItem( const FreeItem& freeItem ) FreeItem::~FreeItem() { - if ( shadyImage != 0 ) + if ( shadyImage != nilPointer ) destroy_bitmap( shadyImage ); } @@ -84,27 +83,27 @@ void FreeItem::draw( BITMAP* where ) void FreeItem::binProcessedImages() { - if ( this->processedImage ) + if ( this->processedImage != nilPointer ) { destroy_bitmap( this->processedImage ); - this->processedImage = 0; + this->processedImage = nilPointer; } - if ( this->shadyImage ) + if ( this->shadyImage != nilPointer ) { destroy_bitmap( this->shadyImage ); - this->shadyImage = 0; + this->shadyImage = nilPointer; } } void FreeItem::changeImage( BITMAP* image ) { - if ( image == 0 ) + if ( image == nilPointer ) { std::cout << "nil image at FreeItem.changeImage" << std::endl ; } - if ( this->rawImage == 0 ) + if ( this->rawImage == nilPointer ) { this->rawImage = image; } @@ -112,10 +111,10 @@ void FreeItem::changeImage( BITMAP* image ) { FreeItem oldFreeItem( *this ); - this->rawImage = 0; + this->rawImage = nilPointer; // recalculate displacement, it is how many pixels is this image from point of room’s origin - if ( image != 0 ) + if ( image != nilPointer ) { this->offset.first = ( ( this->x - this->y ) << 1 ) + static_cast< int >( getDataOfItem()->getWidthX() + getDataOfItem()->getWidthY() ) - ( image->w >> 1 ) - 1; this->offset.second = this->x + this->y + static_cast< int >( getDataOfItem()->getWidthX() ) - image->h - this->z; @@ -132,13 +131,13 @@ void FreeItem::changeImage( BITMAP* image ) this->myMask = WantMask; // remask with old image - if ( oldFreeItem.getRawImage() != 0 ) + if ( oldFreeItem.getRawImage() != nilPointer ) { mediator->remaskFreeItem( &oldFreeItem ); } // remask with new image - if ( image != 0 ) + if ( image != nilPointer ) { mediator->remaskFreeItem( this ); } @@ -147,7 +146,7 @@ void FreeItem::changeImage( BITMAP* image ) void FreeItem::changeShadow( BITMAP* shadow ) { - if ( this->shadow == 0 ) + if ( this->shadow == nilPointer ) { this->shadow = shadow; } @@ -183,7 +182,7 @@ void FreeItem::requestCastShadow() if ( this->myShady == WantShadow && this->shadyImage ) { destroy_bitmap( this->shadyImage ); - this->shadyImage = 0; + this->shadyImage = nilPointer; this->myMask = WantMask; } } @@ -561,7 +560,7 @@ void FreeItem::requestMask() if ( this->myMask == WantMask && this->processedImage ) { destroy_bitmap( this->processedImage ); - this->processedImage = 0; + this->processedImage = nilPointer; } this->myShady = NoShadow; @@ -570,11 +569,11 @@ void FreeItem::requestMask() void FreeItem::maskImage( int x, int y, BITMAP* image ) { - assert( image != 0 ); + assert( image != nilPointer ); // mask shaded image or raw image when item is not yet shaded - BITMAP* currentImage = ( this->shadyImage != 0 ? this->shadyImage : this->rawImage ); - assert( currentImage != 0 ); + BITMAP* currentImage = ( this->shadyImage != nilPointer ? this->shadyImage : this->rawImage ); + assert( currentImage != nilPointer ); int inix = x - this->offset.first; // initial X if ( inix < 0 ) inix = 0; @@ -589,7 +588,7 @@ void FreeItem::maskImage( int x, int y, BITMAP* image ) if ( endy > currentImage->h ) endy = currentImage->h; // in principle, image of masked item is image of unmasked item, shaded or unshaded - if ( this->processedImage == 0 ) + if ( this->processedImage == nilPointer ) { this->processedImage = create_bitmap_ex( bitmap_color_depth( currentImage ), currentImage->w, currentImage->h ); } @@ -606,12 +605,10 @@ void FreeItem::maskImage( int x, int y, BITMAP* image ) int n2i = inix + this->offset.first - x; endx *= increase1; - inix = inix * increase1; + inix *= increase1; + n2i *= increase2; #if IS_BIG_ENDIAN inix += bitmap_color_depth( currentImage ) == 32 ? 1 : 0 ; - #endif - n2i = n2i * increase2; - #if IS_BIG_ENDIAN n2i += bitmap_color_depth( image ) == 32 ? 1 : 0; #endif diff --git a/src/GameFileManager.cpp b/src/GameFileManager.cpp index 1a2df7c9..186870b4 100644 --- a/src/GameFileManager.cpp +++ b/src/GameFileManager.cpp @@ -145,23 +145,23 @@ void GameFileManager::saveGame( const std::string& fileName ) // there may be no more rooms because there are no more players // or because other player is in the same room as active player - const PlayerItem* whoWaitsToPlay = 0 ; + const PlayerItem* whoWaitsToPlay = nilPointer ; std::string nameOfWhoWaitsToPlay = "nobody"; - if ( secondRoom != 0 ) + if ( secondRoom != nilPointer ) { nameOfWhoWaitsToPlay = secondRoom->getMediator()->getActivePlayer()->getLabel(); } else - if ( activeRoom->getMediator()->getWaitingPlayer() != 0 ) + if ( activeRoom->getMediator()->getWaitingPlayer() != nilPointer ) { nameOfWhoWaitsToPlay = activeRoom->getMediator()->getWaitingPlayer()->getLabel(); } if ( nameOfWhoWaitsToPlay != "nobody" ) { - std::list< const PlayerItem * > playersOnEntry = ( secondRoom != 0 ? + std::list< const PlayerItem * > playersOnEntry = ( secondRoom != nilPointer ? secondRoom->getPlayersWhoEnteredRoom() : activeRoom->getPlayersWhoEnteredRoom() ); @@ -175,7 +175,7 @@ void GameFileManager::saveGame( const std::string& fileName ) } } - if ( whoWaitsToPlay != 0 ) + if ( whoWaitsToPlay != nilPointer ) { std::vector< std::string > tools = this->gameManager->getToolsOwnedByPlayer( whoWaitsToPlay->getLabel() ); @@ -183,7 +183,7 @@ void GameFileManager::saveGame( const std::string& fileName ) sgxml::player ( false, // inactive player - secondRoom != 0 ? secondRoom->getNameOfFileWithDataAboutRoom() : activeRoom->getNameOfFileWithDataAboutRoom(), + secondRoom != nilPointer ? secondRoom->getNameOfFileWithDataAboutRoom() : activeRoom->getNameOfFileWithDataAboutRoom(), whoWaitsToPlay->getX(), whoWaitsToPlay->getY(), whoWaitsToPlay->getZ(), diff --git a/src/GameManager.cpp b/src/GameManager.cpp index 19097d55..e11b69b4 100644 --- a/src/GameManager.cpp +++ b/src/GameManager.cpp @@ -21,7 +21,7 @@ namespace isomot { -GameManager * GameManager::instance = 0 ; +GameManager * GameManager::instance = nilPointer ; GameManager::GameManager( ) @@ -42,36 +42,36 @@ GameManager::GameManager( ) , horn( false ) , handbag( false ) , donuts( 0 ) - , itemTaken( 0 ) + , itemTaken( nilPointer ) , takenCrown( false ) , eatenFish( false ) , gameOver( false ) , freedom( false ) , emperator( false ) - , frameForJail( 0 ) - , frameForBlacktooth( 0 ) - , frameForMarket( 0 ) - , frameForMoon( 0 ) - , frameForByblos( 0 ) - , frameForSafari( 0 ) - , frameForEgyptus( 0 ) - , frameForPenitentiary( 0 ) - , pictureOfHead( 0 ) - , grayPictureOfHead( 0 ) - , pictureOfHeels( 0 ) - , grayPictureOfHeels( 0 ) - , pictureOfBag( 0 ) - , grayPictureOfBag( 0 ) - , pictureOfHorn( 0 ) - , grayPictureOfHorn( 0 ) - , pictureOfDonuts( 0 ) - , grayPictureOfDonuts( 0 ) - , pictureOfGrandesSaltos( 0 ) - , grayPictureOfGrandesSaltos( 0 ) - , pictureOfGranVelocidad( 0 ) - , grayPictureOfGranVelocidad( 0 ) - , pictureOfEscudo( 0 ) - , grayPictureOfEscudo( 0 ) + , frameForJail( nilPointer ) + , frameForBlacktooth( nilPointer ) + , frameForMarket( nilPointer ) + , frameForMoon( nilPointer ) + , frameForByblos( nilPointer ) + , frameForSafari( nilPointer ) + , frameForEgyptus( nilPointer ) + , frameForPenitentiary( nilPointer ) + , pictureOfHead( nilPointer ) + , grayPictureOfHead( nilPointer ) + , pictureOfHeels( nilPointer ) + , grayPictureOfHeels( nilPointer ) + , pictureOfBag( nilPointer ) + , grayPictureOfBag( nilPointer ) + , pictureOfHorn( nilPointer ) + , grayPictureOfHorn( nilPointer ) + , pictureOfDonuts( nilPointer ) + , grayPictureOfDonuts( nilPointer ) + , pictureOfGrandesSaltos( nilPointer ) + , grayPictureOfGrandesSaltos( nilPointer ) + , pictureOfGranVelocidad( nilPointer ) + , grayPictureOfGranVelocidad( nilPointer ) + , pictureOfEscudo( nilPointer ) + , grayPictureOfEscudo( nilPointer ) { } @@ -112,7 +112,7 @@ GameManager::~GameManager( ) /* static */ GameManager* GameManager::getInstance () { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new GameManager(); } @@ -123,7 +123,7 @@ GameManager* GameManager::getInstance () /* static */ BITMAP * GameManager::refreshPicture ( const char * nameOfPicture ) { - return load_png( isomot::pathToFile( gui::GuiManager::getInstance()->getPathToPicturesOfGui() + nameOfPicture ), 0 ); + return load_png( isomot::pathToFile( gui::GuiManager::getInstance()->getPathToPicturesOfGui() + nameOfPicture ), nilPointer ); } WhyPause GameManager::begin () @@ -140,13 +140,13 @@ WhyPause GameManager::begin () this->horn = false; this->handbag = false; this->donuts = 0; - this->itemTaken = 0; + this->itemTaken = nilPointer; this->planets.clear(); refreshAmbianceImages (); refreshBackgroundFrames (); - assert( this->isomot != 0 ); + assert( this->isomot != nilPointer ); this->isomot->beginNewGame (); return this->update (); @@ -159,7 +159,7 @@ WhyPause GameManager::resume () refreshAmbianceImages (); refreshBackgroundFrames (); - assert( this->isomot != 0 ); + assert( this->isomot != nilPointer ); this->isomot->resume (); return this->update (); @@ -276,7 +276,7 @@ void GameManager::drawAmbianceOfGame ( BITMAP * where ) if ( drawBackgroundPicture ) { // marco, varía en función del escenario - BITMAP * background = 0; + BITMAP * background = nilPointer; if ( scenery == "blacktooth" ) background = frameForBlacktooth; @@ -295,7 +295,7 @@ void GameManager::drawAmbianceOfGame ( BITMAP * where ) else if ( scenery == "egyptus" ) background = frameForEgyptus; - if ( background != 0 ) + if ( background != nilPointer ) draw_sprite( where, background, 0, 0 ); } @@ -368,7 +368,7 @@ void GameManager::drawAmbianceOfGame ( BITMAP * where ) } // item in handbag - if ( this->itemTaken != 0 ) + if ( this->itemTaken != nilPointer ) { draw_sprite( where, this->itemTaken, 559, 361 ); } @@ -589,7 +589,7 @@ void GameManager::emptyHandbag ( const std::string& player ) { if ( player == "heels" || player == "headoverheels" ) { - this->itemTaken = 0; + this->itemTaken = nilPointer; } } @@ -667,10 +667,10 @@ WhyPause GameManager::update () BITMAP* view = this->isomot->update(); // se ha podido actualizar - if ( view != 0 ) + if ( view != nilPointer ) { this->drawAmbianceOfGame( view ); - sleep( 10 ); + milliSleep( 10 ); } else { @@ -712,11 +712,8 @@ WhyPause GameManager::pause () this->eatenFish = false; isomot::InputManager* inputManager = InputManager::getInstance(); - // presenta las intrucciones en pantalla - gui::LanguageText* text = 0; gui::LanguageManager* language = gui::GuiManager::getInstance()->getLanguageManager(); - - text = language->findLanguageString( "save-game" ); + gui::LanguageText* text = language->findLanguageString( "save-game" ); int deltaY = 100; for ( size_t i = 0; i < text->getLinesCount(); i++ ) @@ -776,9 +773,7 @@ WhyPause GameManager::pause () } } - // sondea la decisión del usuario cada 10 milisegundos - // poll the decision of user every 10 milliseconds - sleep( 10 ); + milliSleep( 10 ); } } // el usuario ha acabado con las vidas de todos los jugadores @@ -807,10 +802,8 @@ WhyPause GameManager::pause () { SoundManager::getInstance()->stopEverySound (); - gui::LanguageText* text = 0; gui::LanguageManager* language = gui::GuiManager::getInstance()->getLanguageManager(); - - text = language->findLanguageString( "confirm-quit" ); + gui::LanguageText* text = language->findLanguageString( "confirm-quit" ); int deltaY = ScreenHeight / 4; for ( size_t i = 0; i < text->getLinesCount(); i++ ) @@ -858,7 +851,7 @@ WhyPause GameManager::pause () } } - sleep( 10 ); + milliSleep( 10 ); } } diff --git a/src/GridItem.cpp b/src/GridItem.cpp index a73fd46d..48f858de 100644 --- a/src/GridItem.cpp +++ b/src/GridItem.cpp @@ -48,10 +48,10 @@ void GridItem::draw( BITMAP* where ) void GridItem::binProcessedImage() { - if ( this->processedImage ) + if ( this->processedImage != nilPointer ) { destroy_bitmap( this->processedImage ); - this->processedImage = 0; + this->processedImage = nilPointer; } } @@ -59,7 +59,7 @@ void GridItem::changeImage( BITMAP* newImage ) { // when there's no image for this item, just assign it // such case usually happens during construction of the item - if ( this->rawImage == 0 ) + if ( this->rawImage == nilPointer ) { this->rawImage = newImage; } @@ -122,10 +122,10 @@ void GridItem::requestCastShadow( int column ) mediator->castShadowOnGridItem( this ); // bin already shaded image - if ( this->myShady != AlreadyShady && this->processedImage ) + if ( this->myShady != AlreadyShady && this->processedImage != nilPointer ) { destroy_bitmap( this->processedImage ); - this->processedImage = 0; + this->processedImage = nilPointer; } // to reshade at next cycle diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 3a453e31..8a1b53fd 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -5,7 +5,7 @@ using isomot::InputManager; -InputManager* InputManager::instance = 0 ; +InputManager* InputManager::instance = nilPointer ; const std::string InputManager::namesOfKeys[ ] = @@ -44,7 +44,7 @@ InputManager::~InputManager() InputManager* InputManager::getInstance() { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new InputManager(); } @@ -117,5 +117,5 @@ bool InputManager::pause() void InputManager::noRepeat( const std::string& nameOfKey ) { - key[ getUserKey( nameOfKey ) ] = 0; + key[ getUserKey( nameOfKey ) ] = false; } diff --git a/src/InputManager.hpp b/src/InputManager.hpp index 5b29afbb..de7e695a 100644 --- a/src/InputManager.hpp +++ b/src/InputManager.hpp @@ -67,62 +67,58 @@ class InputManager std::string findNameOfKeyByCode ( int scancode ) ; /** - * El usuario está moviendo al jugador a la izquierda - * @return true si pulsa la tecla indicada o mueve la palanca del joystick en ese sentido + * Move character to the north + * @return true if user types this key or moves joystick there */ bool movenorth () ; /** - * El usuario está moviendo al jugador a la derecha - * @return true si pulsa la tecla indicada o mueve la palanca del joystick en ese sentido + * Move character to the south + * @return true if user types this key or moves joystick there */ bool movesouth () ; /** - * El usuario está moviendo al jugador arriba - * @return true si pulsa la tecla indicada o mueve la palanca del joystick en ese sentido + * Move character to the east + * @return true if user types this key or moves joystick there */ bool moveeast () ; /** - * El usuario está moviendo al jugador abajo - * @return true si pulsa la tecla indicada o mueve la palanca del joystick en ese sentido + * Move character to the west + * @return true if user types this key or moves joystick there */ bool movewest () ; /** - * El usuario está cogiendo o dejando algún objeto - * @return true si pulsa la tecla o el botón indicado + * Take or drop some object + * @return true if user types this key or joystick button */ bool take () ; /** - * El usuario está saltando - * @return true si pulsa la tecla o el botón indicado + * Character jumps + * @return true if user types this key or joystick button */ bool jump () ; - /** - * El usuario está disparando - * @return true si pulsa la tecla o el botón indicado - */ - bool doughnut () ; + bool takeAndJump () ; /** - * El usuario está cogiendo o dejando algún objeto y saltando - * @return true si pulsa la tecla o el botón indicado + * Release doughnut + * @return true if user types this key or joystick button */ - bool takeAndJump () ; + bool doughnut () ; /** - * El usuario está cogiendo cambiando de personaje - * @return true si pulsa la tecla o el botón indicado + * Change characters + * @return true if user types this key or joystick button */ bool swap () ; /** - * El usuario está parando el juego - * @return true si pulsa la tecla o el botón indicado + * Pause game + * @return true if user types this key or joystick button */ bool pause () ; diff --git a/src/Ism.cpp b/src/Ism.cpp index 4f739990..5499875b 100644 --- a/src/Ism.cpp +++ b/src/Ism.cpp @@ -6,34 +6,38 @@ #include #endif +#ifndef PATH_MAX + #define PATH_MAX 4096 +#endif -namespace isomot -{ - -void sleep( unsigned long miliseconds ) +void milliSleep( unsigned long milliseconds ) { #if defined ( __WIN32 ) - Sleep( miliseconds ); + Sleep( milliseconds ); #else std::modulus< unsigned long > modulus; - unsigned long remainder = modulus( miliseconds, 1000 ); + unsigned long remainder = modulus( milliseconds, 1000 ); timespec pause; - pause.tv_sec = miliseconds / 1000; + pause.tv_sec = milliseconds / 1000; pause.tv_nsec = remainder * 1000000; - nanosleep( &pause, 0 ); + nanosleep( &pause, NULL ); #endif } + +namespace isomot +{ + const char * pathToFile( const std::string& in ) { #if defined ( __CYGWIN__ ) ssize_t length ; - char * windowsPath = 0; + char * windowsPath = nilPointer; /* ssize_t cygwin_conv_path( cygwin_conv_path_t what, const void * from, void * to, size_t size ) */ /* https://cygwin.com/cygwin-api/func-cygwin-conv-path.html */ - length = cygwin_conv_path ( CCP_POSIX_TO_WIN_A | CCP_RELATIVE, in.c_str (), 0, 0 ) ; + length = cygwin_conv_path ( CCP_POSIX_TO_WIN_A | CCP_RELATIVE, in.c_str (), nilPointer, 0 ) ; if ( length >= 0 ) { windowsPath = static_cast< char * >( malloc( length ) ); @@ -50,43 +54,50 @@ const char * pathToFile( const std::string& in ) #endif } -std::string PathToGame( "no way" ) ; -std::string FullPathToGame( "" ) ; +std::string FullPathToGame( "no way" ) ; void setPathToGame ( const char * pathToGame ) { - PathToGame = pathToGame ; FullPathToGame = pathToGame ; + const std::string whereIsGame = pathToGame ; + // for cases when game is in PATH, when running with gdb or double-clicking + if ( whereIsGame == "headoverheels" || whereIsGame == "/usr/bin/headoverheels" ) + { #if defined ( __CYGWIN__ ) - if ( PathToGame == "headoverheels" || PathToGame == "/usr/bin/headoverheels" ) - { // in case of double-clicking or running with gdb FullPathToGame = "/bin/headoverheels" ; - } +#else + FullPathToGame = "/usr/bin/headoverheels" ; /* hard-coded */ + /* for other paths like /usr/local + and~or custom names of game + it needs more sophiscated logic */ #endif + } - char* lastdot = strrchr ( get_filename( PathToGame.c_str () ) , '.' ); - if ( lastdot != 0 && strlen( lastdot ) == 4 && +#if defined ( __APPLE__ ) && defined ( __MACH__ ) + char* lastdot = strrchr ( get_filename( pathToGame ) , '.' ); + if ( lastdot != nilPointer && strlen( lastdot ) == 4 && ( lastdot[ 1 ] == 'a' && lastdot[ 2 ] == 'p' && lastdot[ 3 ] == 'p' ) ) - { // game is in OS X bundle - FullPathToGame = PathToGame + pathSeparator + "Contents" + pathSeparator + "MacOS" + pathSeparator ; + { // game is in OS X bundle + // binary itself lives inside whereIsGame/Contents/MacOS } else +#endif { if ( FullPathToGame[ 0 ] != pathSeparator[ 0 ] ) - { // pathToGame is not full path - char folderOfGame[ 1024 ]; - getcwd( folderOfGame, 1024 ) ; + { // it’s not full path + char folderOfGame[ PATH_MAX ]; + getcwd( folderOfGame, PATH_MAX ) ; size_t len = strlen( folderOfGame ); if ( folderOfGame[ len - 1 ] == pathSeparator[ 0 ] ) - folderOfGame[ len - 1 ] = 0; + folderOfGame[ len - 1 ] = '\0'; - FullPathToGame = std::string( folderOfGame ) + pathSeparator + PathToGame ; + FullPathToGame = std::string( folderOfGame ) + pathSeparator + whereIsGame ; } } - fprintf( stdout, "PathToGame is \"%s\"\n", PathToGame.c_str () ); + fprintf( stdout, "whereIsGame is \"%s\"\n", whereIsGame.c_str () ); fprintf( stdout, "FullPathToGame is \"%s\"\n", FullPathToGame.c_str () ); } @@ -100,9 +111,9 @@ std::string homePath () HomePath = sharePath(); #else /// #elif defined ( __gnu_linux__ ) char* home = getenv( "HOME" ); - assert( home != 0 ); + assert( home != nilPointer ); HomePath = std::string( home ) + "/.headoverheels/"; - if ( ! file_exists( HomePath.c_str(), FA_DIREC, 0 ) ) + if ( ! file_exists( HomePath.c_str(), FA_DIREC, nilPointer ) ) { mkdir( HomePath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ); mkdir( ( HomePath + "savegame/" ).c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ); @@ -119,11 +130,8 @@ std::string sharePath () { if ( SharePath.empty () ) { -#if defined ( __CYGWIN__ ) || defined ( __WIN32 ) const char* cpath = FullPathToGame.c_str (); -#else - const char* cpath = PathToGame.c_str (); -#endif + char* filename = get_filename( cpath ); #if defined ( __APPLE__ ) && defined ( __MACH__ ) diff --git a/src/Ism.hpp b/src/Ism.hpp index b6ebfe56..1f454ffb 100644 --- a/src/Ism.hpp +++ b/src/Ism.hpp @@ -28,6 +28,12 @@ #include #endif +#if __cplusplus > 199711L /* when complier supports c++11 */ + #define nilPointer nullptr +#else + #define nilPointer NULL +#endif + #if defined( DEBUG ) && defined( HAVE_EXECINFO_H ) && HAVE_EXECINFO_H #include #include @@ -46,6 +52,12 @@ #endif +/** + * Pause subprocess for a given period of time in milliseconds + */ +void milliSleep ( unsigned long miliseconds ); + + namespace isomot { /** print backtrace of caller */ @@ -81,12 +93,6 @@ namespace isomot typedef std::pair< int, int > JumpMotion; - /** - * Detiene un subproceso durante un periodo de tiempo - * @param miliseconds Número de milisegundos que será detenido el subproceso - */ - void sleep ( unsigned long miliseconds ); - const char * pathToFile ( const std::string& in ) ; void setPathToGame ( const char * pathToGame ) ; diff --git a/src/Isomot.cpp b/src/Isomot.cpp index 27655c8c..ec6d7e9d 100644 --- a/src/Isomot.cpp +++ b/src/Isomot.cpp @@ -20,9 +20,9 @@ namespace isomot Isomot::Isomot( ) : isEndRoom( false ), - view( 0 ), - itemDataManager( 0 ), - mapManager( 0 ) + view( nilPointer ), + itemDataManager( nilPointer ), + mapManager( nilPointer ) { } @@ -32,10 +32,10 @@ Isomot::~Isomot( ) delete this->mapManager; delete this->itemDataManager; - if ( this->view != 0 ) + if ( this->view != nilPointer ) { destroy_bitmap( this->view ); - this->view = 0; + this->view = nilPointer; } } @@ -76,19 +76,19 @@ void Isomot::prepare () { // image where the isometric view will be drawn - if ( this->view == 0 ) + if ( this->view == nilPointer ) { this->view = create_bitmap_ex( 32, ScreenWidth, ScreenHeight ); } // data for elements of the game - if ( this->itemDataManager != 0 ) + if ( this->itemDataManager != nilPointer ) { // set of graphics may change between games // new ItemDataManager is needed to refresh pictures of items delete this->itemDataManager; - this->itemDataManager = 0; + this->itemDataManager = nilPointer ; } this->itemDataManager = new ItemDataManager( "items.xml" ); @@ -96,7 +96,7 @@ void Isomot::prepare () // data for map - if ( this->mapManager == 0 ) + if ( this->mapManager == nilPointer ) { this->mapManager = new MapManager( this, "map.xml" ); this->mapManager->loadMap (); @@ -121,9 +121,7 @@ void Isomot::offInviolability () void Isomot::pause () { - // Detiene la actualización de los estados de los elementos y - // la representación de la vista isométrica - if ( mapManager->getActiveRoom() != 0 ) + if ( mapManager->getActiveRoom() != nilPointer ) { mapManager->getActiveRoom()->deactivate(); } @@ -131,7 +129,7 @@ void Isomot::pause () void Isomot::resume () { - if ( mapManager->getActiveRoom() != 0 ) + if ( mapManager->getActiveRoom() != nilPointer ) { mapManager->getActiveRoom()->activate(); } @@ -142,10 +140,10 @@ void Isomot::reset() this->isEndRoom = false; // Destruye la vista isométrica actual - if ( this->view != 0 ) + if ( this->view != nilPointer ) { destroy_bitmap( this->view ); - this->view = 0; + this->view = nilPointer; } this->mapManager->binEveryRoom(); @@ -244,15 +242,15 @@ BITMAP* Isomot::update() if( ( key_shifts & KB_ALT_FLAG ) && ( key_shifts & KB_SHIFT_FLAG ) && key[ KEY_J ] ) { PlayerItem* activePlayer = activeRoom->getMediator()->getActivePlayer(); - PlayerItem* otherPlayer = 0; + PlayerItem* otherPlayer = nilPointer; Room* roomWithInactivePlayer = this->mapManager->getRoomOfInactivePlayer(); - if ( roomWithInactivePlayer != 0 ) + if ( roomWithInactivePlayer != nilPointer ) { otherPlayer = roomWithInactivePlayer->getMediator()->getActivePlayer(); } - if ( otherPlayer != 0 && roomWithInactivePlayer != activeRoom ) + if ( otherPlayer != nilPointer && roomWithInactivePlayer != activeRoom ) { std::cout << "join characters in active room \"" << activeRoom->getNameOfFileWithDataAboutRoom() << "\" via pure magic" << std::endl ; @@ -292,7 +290,7 @@ BITMAP* Isomot::update() { if ( gameManager->countFreePlanets() < 5 ) { - if ( activeRoom->getMediator()->findItemByLabel( "crown" ) == 0 ) + if ( activeRoom->getMediator()->findItemByLabel( "crown" ) == nilPointer ) { ItemData* chapeauData = this->itemDataManager->findItemByLabel( "crown" ); @@ -393,7 +391,7 @@ BITMAP* Isomot::update() { Room* newRoom = mapManager->changeRoom( exit ); - if ( newRoom != 0 && newRoom != activeRoom ) + if ( newRoom != nilPointer && newRoom != activeRoom ) { playTuneForScenery( newRoom->getScenery () ); } @@ -403,7 +401,7 @@ BITMAP* Isomot::update() } // draw active room, if there’s any - if ( activeRoom != 0 ) + if ( activeRoom != nilPointer ) { blit ( activeRoom->getPicture(), this->view, @@ -426,7 +424,7 @@ BITMAP* Isomot::update() } // la sala final es muy especial - if ( activeRoom->getNameOfFileWithDataAboutRoom().compare( "blacktooth/blacktooth88.xml" ) == 0 ) + if ( activeRoom->getNameOfFileWithDataAboutRoom() == "blacktooth/blacktooth88.xml" ) { this->updateEndRoom(); } @@ -436,7 +434,7 @@ BITMAP* Isomot::update() { std::cout << "no room, game over" << std::endl ; destroy_bitmap( this->view ); - this->view = 0; + this->view = nilPointer; } return this->view; @@ -522,9 +520,9 @@ void Isomot::updateEndRoom() else { SoundManager::getInstance()->playOgg ( "music/begin.ogg", /* loop */ false ); - /// sleep( 2340 ); + /// milliSleep( 2340 ); - if ( activeRoom->getMediator()->findItemByLabel( "ball" ) == 0 && activeRoom->getMediator()->findItemByLabel( "bubbles" ) == 0 ) + if ( activeRoom->getMediator()->findItemByLabel( "ball" ) == nilPointer && activeRoom->getMediator()->findItemByLabel( "bubbles" ) == nilPointer ) { FreeItem* freeItem = new FreeItem( this->itemDataManager->findItemByLabel( "ball" ), 146, 93, LayerHeight, Nowhere ); freeItem->assignBehavior( "behaivor of final ball", this->itemDataManager->findItemByLabel( "bubbles" ) ); diff --git a/src/Item.cpp b/src/Item.cpp index f706b349..47d49c35 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -20,10 +20,11 @@ Item::Item( ItemData* data, int z, const Way& way ) z( z ), orientation( way ), myShady( WantShadow ), - rawImage( 0 ), - shadow( 0 ), - processedImage( 0 ), - behavior( 0 ), + rawImage( nilPointer ), + shadow( nilPointer ), + processedImage( nilPointer ), + behavior( nilPointer ), + anchor( nilPointer ), frameIndex( 0 ), backwardMotion( false ) { @@ -48,14 +49,15 @@ Item::Item( const Item& item ) myShady( item.myShady ), rawImage( item.rawImage ), shadow( item.shadow ), - processedImage( 0 ), + processedImage( nilPointer ), offset( item.offset ), motionTimer( item.motionTimer ), behavior( 0 ), + anchor( item.anchor ), frameIndex( item.frameIndex ), backwardMotion( item.backwardMotion ) { - if ( item.processedImage != 0 ) + if ( item.processedImage != nilPointer ) { this->processedImage = create_bitmap_ex( 32, item.processedImage->w, item.processedImage->h ); blit( item.processedImage, this->processedImage, 0, 0, 0, 0, this->processedImage->w, this->processedImage->h ); @@ -64,18 +66,16 @@ Item::Item( const Item& item ) Item::~Item( ) { - if ( this->behavior != 0 ) - delete this->behavior; + delete this->behavior; - if ( this->processedImage != 0 ) - destroy_bitmap( this->processedImage ); + destroy_bitmap( this->processedImage ); } bool Item::update() { bool isGone = false; - if ( behavior != 0 ) + if ( behavior != nilPointer ) isGone = behavior->update(); return isGone; @@ -116,11 +116,11 @@ bool Item::animate() int currentFrame = dataOfItem->getFrameAt( frameIndex ) + ( dataOfItem->howManyFramesForOrientations() > 1 ? framesNumber * orientOccident : 0 ); // change frame of animation - if ( this->rawImage != 0 && this->rawImage != dataOfItem->getMotionAt( currentFrame ) ) + if ( this->rawImage != nilPointer && this->rawImage != dataOfItem->getMotionAt( currentFrame ) ) { changeImage( dataOfItem->getMotionAt( currentFrame ) ); - if ( this->shadow != 0 ) + if ( this->shadow != nilPointer ) { changeShadow( dataOfItem->getShadowAt( currentFrame ) ); } @@ -159,13 +159,13 @@ void Item::changeOrientation( const Way& way ) unsigned int orientOccident = ( way.getIntegerOfWay() == Nowhere ? 0 : way.getIntegerOfWay() ); unsigned int frame = ( ( dataOfItem->howManyMotions() - dataOfItem->howManyExtraFrames() ) / dataOfItem->howManyFramesForOrientations() ) * orientOccident; - if ( this->rawImage != 0 && frame < dataOfItem->howManyMotions() && this->rawImage != dataOfItem->getMotionAt( frame ) ) + if ( this->rawImage != nilPointer && frame < dataOfItem->howManyMotions() && this->rawImage != dataOfItem->getMotionAt( frame ) ) { this->orientation = way; changeImage( dataOfItem->getMotionAt( frame ) ); - if ( this->shadow != 0 ) + if ( this->shadow != nilPointer ) changeShadow( dataOfItem->getShadowAt( frame ) ); } } @@ -183,12 +183,12 @@ void Item::changeFrame( const unsigned int frameIndex ) this->frameIndex = frameIndex; // change frame - if ( this->rawImage != 0 && this->rawImage != dataOfItem->getMotionAt( frameIndex ) ) + if ( this->rawImage != nilPointer && this->rawImage != dataOfItem->getMotionAt( frameIndex ) ) { changeImage( dataOfItem->getMotionAt( frameIndex ) ); // update shadow too - if ( this->shadow != 0 ) + if ( this->shadow != nilPointer ) changeShadow( dataOfItem->getShadowAt( frameIndex ) ); } } @@ -316,9 +316,4 @@ unsigned int Item::countFrames() const return dataOfItem->howManyMotions(); } -void Item::setAnchor( Item* item ) -{ - this->anchor = item; -} - } diff --git a/src/Item.hpp b/src/Item.hpp index 80a574b1..f5440b4f 100644 --- a/src/Item.hpp +++ b/src/Item.hpp @@ -363,14 +363,14 @@ class Item : public Mediated Behavior * getBehavior () const { return behavior ; } - void setAnchor ( Item * item ) ; - /** * Reference item used to know if it would move when others are below * @return such item or 0 if there’s none */ Item * getAnchor () const { return this->anchor ; } + void setAnchor ( Item * item ) { this->anchor = item ; } + unsigned int getIndexOfFrame() { return this->frameIndex ; } }; diff --git a/src/ItemData.cpp b/src/ItemData.cpp index 33cea5eb..f2f027f4 100644 --- a/src/ItemData.cpp +++ b/src/ItemData.cpp @@ -1,5 +1,6 @@ #include "ItemData.hpp" +#include "Ism.hpp" #include @@ -32,7 +33,7 @@ ItemData::~ItemData( ) /* static */ ItemData* ItemData::clone ( ItemData* data ) { - if ( data == 0 ) return 0; + if ( data == nilPointer ) return nilPointer ; ItemData* copyOfData = new ItemData( ); diff --git a/src/ItemDataManager.cpp b/src/ItemDataManager.cpp index 67e98ba5..96e98173 100644 --- a/src/ItemDataManager.cpp +++ b/src/ItemDataManager.cpp @@ -149,8 +149,8 @@ void ItemDataManager::loadItems () } // load graphics for door - BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + isomot::GameManager::getInstance()->getChosenGraphicSet() + pathSeparator + item->getNameOfFile( ) ), 0 ); - if ( picture == 0 ) + BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + isomot::GameManager::getInstance()->getChosenGraphicSet() + pathSeparator + item->getNameOfFile( ) ), nilPointer ); + if ( picture == nilPointer ) { std::cerr << "picture \"" << item->getNameOfFile( ) << @@ -228,7 +228,7 @@ ItemData* ItemDataManager::findItemByLabel( const std::string& label ) } std::cerr << "item with label \"" << label << "\" is absent" << std::endl; - return 0; + return nilPointer ; } ItemDataManager::DoorMeasures::DoorMeasures() @@ -249,8 +249,8 @@ ItemData* ItemDataManager::createPictureFrames( ItemData * itemData, const char* } // load graphics for item - BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + gfxPrefix + pathSeparator + itemData->getNameOfFile( ) ), 0 ); - if ( picture == 0 ) + BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + gfxPrefix + pathSeparator + itemData->getNameOfFile( ) ), nilPointer ); + if ( picture == nilPointer ) { std::cerr << "picture \"" << itemData->getNameOfFile( ) << "\" is absent at \"" << gfxPrefix << "\"" << std::endl ; throw "picture " + itemData->getNameOfFile( ) + " is absent at " + gfxPrefix ; @@ -277,7 +277,7 @@ ItemData* ItemDataManager::createPictureFrames( ItemData * itemData, const char* catch ( const std::exception& e ) { std::cerr << e.what () << std::endl ; - return 0; + return nilPointer; } return itemData; @@ -293,8 +293,8 @@ ItemData* ItemDataManager::createShadowFrames( ItemData * itemData, const char* } // load graphics for shadow - BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + gfxPrefix + pathSeparator + itemData->getNameOfShadowFile( ) ), 0 ); - if ( picture == 0 ) + BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + gfxPrefix + pathSeparator + itemData->getNameOfShadowFile( ) ), nilPointer ); + if ( picture == nilPointer ) { std::cerr << "file of shadows \"" << itemData->getNameOfShadowFile( ) << "\" is absent at \"" << gfxPrefix << "\"" << std::endl ; throw "file of shadows " + itemData->getNameOfShadowFile( ) + " is absent at " + gfxPrefix ; @@ -316,7 +316,7 @@ ItemData* ItemDataManager::createShadowFrames( ItemData * itemData, const char* catch ( const std::exception& e ) { std::cerr << e.what () << std::endl ; - return 0; + return nilPointer; } return itemData; @@ -446,7 +446,7 @@ BITMAP* ItemDataManager::cutOutRightJamb( BITMAP* door, const DoorMeasures& dm, void ItemDataManager::finalizeData( ItemData* itemData ) { - if ( itemData != 0 ) + if ( itemData != nilPointer ) { itemData->clearNameOfFile (); itemData->clearNameOfShadowFile (); diff --git a/src/Makefile.am b/src/Makefile.am index 1635501e..740a463f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -96,7 +96,6 @@ headoverheels_SOURCES = loadpng/loadpng.c \ gui/ConfigurationManager.hpp \ gui/Font.cpp \ gui/Font.hpp \ - gui/Gui.cpp \ gui/Gui.hpp \ gui/GuiManager.cpp \ gui/GuiManager.hpp \ diff --git a/src/MapManager.cpp b/src/MapManager.cpp index fdce573d..ec6cbc66 100644 --- a/src/MapManager.cpp +++ b/src/MapManager.cpp @@ -18,9 +18,9 @@ namespace isomot { MapManager::MapManager( Isomot* isomot, const std::string& fileName ) -: isomot( isomot ), - activeRoom( 0 ), - fileName( fileName ) + : isomot( isomot ) + , activeRoom( nilPointer ) + , fileName( fileName ) { } @@ -118,12 +118,12 @@ void MapManager::beginNewGame( const std::string& firstRoomFileName, const std:: MapRoomData* firstRoomData = findRoomData( firstRoomFileName ); // create first room - if ( firstRoomData != 0 ) + if ( firstRoomData != nilPointer ) { std::auto_ptr< RoomBuilder > roomBuilder( new RoomBuilder( isomot->getItemDataManager() ) ); Room* firstRoom = roomBuilder->buildRoom( isomot::sharePath() + "map" + pathSeparator + firstRoomFileName ); - if ( firstRoom != 0 ) + if ( firstRoom != nilPointer ) { ItemData* firstPlayerData = isomot->getItemDataManager()->findItemByLabel( "head" ); @@ -147,12 +147,12 @@ void MapManager::beginNewGame( const std::string& firstRoomFileName, const std:: MapRoomData* secondRoomData = findRoomData( secondRoomFileName ); // create second room - if ( secondRoomData != 0 ) + if ( secondRoomData != nilPointer ) { std::auto_ptr< RoomBuilder > roomBuilder( new RoomBuilder( isomot->getItemDataManager() ) ); Room* secondRoom = roomBuilder->buildRoom( isomot::sharePath() + "map" + pathSeparator + secondRoomFileName ); - if ( secondRoom != 0 ) + if ( secondRoom != nilPointer ) { ItemData* secondPlayerData = isomot->getItemDataManager()->findItemByLabel( "heels" ); @@ -175,12 +175,12 @@ void MapManager::beginNewGame( const std::string& firstRoomFileName, const std:: void MapManager::beginOldGameWithCharacter( const sgxml::player& data ) { MapRoomData* roomData = findRoomData( data.roomFilename() ); - Room* room = 0; + Room* room = nilPointer; - if ( roomData != 0 ) + if ( roomData != nilPointer ) { // if there is already created room it is when room of second player is the same as of first player - if ( this->activeRoom != 0 && this->activeRoom->getNameOfFileWithDataAboutRoom().compare( roomData->getNameOfRoomFile() ) == 0 ) + if ( this->activeRoom != nilPointer && this->activeRoom->getNameOfFileWithDataAboutRoom() == roomData->getNameOfRoomFile() ) { room = this->activeRoom; } @@ -191,7 +191,7 @@ void MapManager::beginOldGameWithCharacter( const sgxml::player& data ) } // place character in room - if ( room != 0 ) + if ( room != nilPointer ) { std::string nameOfCharacter = data.label(); @@ -244,7 +244,7 @@ void MapManager::binEveryRoom() { // bin rooms if ( this->rooms.size () == 2 && - this->rooms[ 0 ]->getNameOfFileWithDataAboutRoom().compare( this->rooms[ 1 ]->getNameOfFileWithDataAboutRoom() ) == 0 ) + this->rooms[ 0 ]->getNameOfFileWithDataAboutRoom() == this->rooms[ 1 ]->getNameOfFileWithDataAboutRoom() ) { delete this->rooms[ 0 ]; } @@ -271,14 +271,14 @@ Room* MapManager::changeRoom( const Way& wayOfExit ) // search the map for next room and get way of entry to it MapRoomData* nextRoomData = findRoomData( previousRoomData->findConnectedRoom( wayOfExit, &wayOfEntry ) ); - if ( nextRoomData == 0 ) + if ( nextRoomData == nilPointer ) { // no room there, so continue with current one return previousRoom ; } activeRoom->deactivate(); - this->activeRoom = 0; + this->activeRoom = nilPointer; std::cout << "\"" << previousRoom->getMediator()->getActivePlayer()->getLabel() << "\" migrates" << " from room \"" << previousRoomData->getNameOfRoomFile() << "\" with way of exit \"" << wayOfExit.toString() << "\"" @@ -307,7 +307,7 @@ Room* MapManager::changeRoom( const Way& wayOfExit ) // remove active player from previous room previousRoom->removePlayerFromRoom( oldItemOfRoamer, true ); - oldItemOfRoamer = 0; + oldItemOfRoamer = nilPointer; if ( ! previousRoom->isAnyPlayerStillInRoom() || nameOfRoamer == "headoverheels" ) { @@ -315,12 +315,12 @@ Room* MapManager::changeRoom( const Way& wayOfExit ) << " so bye that room" << std::endl ; removeRoom( previousRoom ); - previousRoom = 0; + previousRoom = nilPointer; } Room* newRoom = findRoom( nextRoomData->getNameOfRoomFile() ); - if ( newRoom != 0 ) + if ( newRoom != nilPointer ) { std::cout << "room \"" << newRoom->getNameOfFileWithDataAboutRoom() << "\" is already created" << std::endl ; newRoom->setWayOfExit( Way( "no exit" ) ); @@ -382,7 +382,7 @@ Room* MapManager::rebuildRoom() std::string nameOfActivePlayerBeforeJoining = oldRoom->getMediator()->getLastActivePlayerBeforeJoining(); Way theWay = Nowhere; - PlayerItem* alivePlayer = 0; + PlayerItem* alivePlayer = nilPointer; // for each player entered this room std::list < const PlayerItem * > playersOnEntry = oldRoom->getPlayersWhoEnteredRoom (); @@ -436,7 +436,7 @@ Room* MapManager::rebuildRoom() player->getX(), player->getY(), player->getZ(), theWay, entry ); - if ( alivePlayer != 0 ) + if ( alivePlayer != nilPointer ) alivePlayer->autoMoveOnEntry( entry ); } @@ -446,7 +446,7 @@ Room* MapManager::rebuildRoom() // remove existing room removeRoom( oldRoom ); - if ( alivePlayer != 0 ) + if ( alivePlayer != nilPointer ) { // add room just created rooms.push_back( newRoom ); @@ -476,7 +476,7 @@ Room* MapManager::rebuildRoom() else { delete newRoom; - activeRoom = newRoom = 0; + activeRoom = newRoom = nilPointer; } return newRoom; @@ -541,12 +541,12 @@ Room* MapManager::removeRoomAndSwap () // no more rooms, game over if ( inactiveRoom == activeRoom ) { - activeRoom = 0; + activeRoom = nilPointer; } removeRoom( inactiveRoom ); - if ( activeRoom != 0 ) + if ( activeRoom != nilPointer ) { activeRoom->activate(); } @@ -556,13 +556,13 @@ Room* MapManager::removeRoomAndSwap () void MapManager::removeRoom( Room* whichRoom ) { - if ( whichRoom != 0 ) + if ( whichRoom != nilPointer ) { if ( whichRoom->isActive() ) whichRoom->deactivate(); if ( whichRoom == this->activeRoom ) - this->activeRoom = 0; + this->activeRoom = nilPointer; rooms.erase( std::remove_if( rooms.begin (), rooms.end (), std::bind2nd( EqualRoom(), whichRoom->getNameOfFileWithDataAboutRoom() ) ), rooms.end() ); delete whichRoom; @@ -617,12 +617,12 @@ void MapManager::resetVisitedRooms() MapRoomData* MapManager::findRoomData( const std::string& room ) { if ( room.empty() ) - return 0; + return nilPointer; /* std::cout << "lookin’ for data of room \"" << room << "\"" << std::endl ; */ std::list< MapRoomData * >::iterator i = std::find_if( theMap.begin (), theMap.end (), std::bind2nd( EqualMapRoomData(), room ) ); - MapRoomData* data = ( i != theMap.end() ? *i : 0 ); + MapRoomData* data = ( i != theMap.end() ? *i : nilPointer ); return data; } @@ -630,12 +630,12 @@ MapRoomData* MapManager::findRoomData( const std::string& room ) Room* MapManager::findRoom( const std::string& room ) { std::vector< Room* >::iterator i = std::find_if( rooms.begin (), rooms.end (), std::bind2nd( EqualRoom(), room ) ); - return ( i != rooms.end() ? ( *i ) : 0 ); + return ( i != rooms.end() ? *i : nilPointer ); } Room* MapManager::getRoomOfInactivePlayer() { - Room* room = 0; + Room* room = nilPointer; for ( size_t i = 0; i < this->rooms.size (); ++i ) { @@ -648,12 +648,12 @@ Room* MapManager::getRoomOfInactivePlayer() bool EqualMapRoomData::operator()( const MapRoomData* mapData, const std::string& room ) const { - return ( mapData->getNameOfRoomFile().compare( room ) == 0 ); + return ( mapData->getNameOfRoomFile() == room ); } bool EqualRoom::operator()( const Room* room, const std::string& nameOfRoom ) const { - return ( room->getNameOfFileWithDataAboutRoom().compare( nameOfRoom ) == 0 ); + return ( room->getNameOfFileWithDataAboutRoom() == nameOfRoom ); } } diff --git a/src/MapManager.hpp b/src/MapManager.hpp index 1cdb6cee..ebeefee9 100644 --- a/src/MapManager.hpp +++ b/src/MapManager.hpp @@ -37,8 +37,7 @@ class MapManager /** * Constructor - * @param isomot El motor isométrico - * @param fileName Nombre del archivo XML que contiene los datos del mapa + * @param fileName Name of XML file with data of game’s map */ MapManager( Isomot * isomot, const std::string& fileName ) ; @@ -67,7 +66,6 @@ class MapManager /** * Create room by data from file - * @return La sala creada ó 0 si no se pudo construir */ Room * createRoom ( const std::string& fileName ) ; @@ -105,7 +103,7 @@ class MapManager /** * Look for room in list of created rooms * @param room name of file for room - * @return found room or 0 if it’s absent + * @return found room or nil if it’s absent */ Room * findRoom ( const std::string& room ) ; @@ -140,7 +138,7 @@ class MapManager void setActiveRoom ( Room * newRoom ) { activeRoom = newRoom ; } /** - * @return room or 0 if there’re no more players + * @return room or nil if there’re no more players */ Room * getRoomOfInactivePlayer () ; diff --git a/src/MapRoomData.cpp b/src/MapRoomData.cpp index fa930643..2607a05a 100644 --- a/src/MapRoomData.cpp +++ b/src/MapRoomData.cpp @@ -115,11 +115,11 @@ void MapRoomData::adjustEntry( Way* entry, const std::string& previousRoom ) case North: if ( north.empty() ) { - if ( northEast.compare( previousRoom ) == 0 ) + if ( previousRoom == northEast ) { *entry = Northeast; } - else if ( northWest.compare( previousRoom ) == 0 ) + else if ( previousRoom == northWest ) { *entry = Northwest; } @@ -129,11 +129,11 @@ void MapRoomData::adjustEntry( Way* entry, const std::string& previousRoom ) case South: if ( south.empty() ) { - if ( southEast.compare( previousRoom ) == 0 ) + if ( previousRoom == southEast ) { *entry = Southeast; } - else if ( southWest.compare( previousRoom ) == 0 ) + else if ( previousRoom == southWest ) { *entry = Southwest; } @@ -143,11 +143,11 @@ void MapRoomData::adjustEntry( Way* entry, const std::string& previousRoom ) case East: if ( east.empty() ) { - if ( eastNorth.compare( previousRoom ) == 0 ) + if ( eastNorth == previousRoom ) { *entry = Eastnorth; } - else if ( eastSouth.compare( previousRoom ) == 0 ) + else if ( eastSouth == previousRoom ) { *entry = Eastsouth; } @@ -157,11 +157,11 @@ void MapRoomData::adjustEntry( Way* entry, const std::string& previousRoom ) case West: if ( west.empty() ) { - if ( westNorth.compare( previousRoom ) == 0 ) + if ( westNorth == previousRoom ) { *entry = Westnorth; } - else if ( westSouth.compare( previousRoom ) == 0 ) + else if ( westSouth == previousRoom ) { *entry = Westsouth; } diff --git a/src/MapRoomData.hpp b/src/MapRoomData.hpp index 4459fc43..a18136ce 100644 --- a/src/MapRoomData.hpp +++ b/src/MapRoomData.hpp @@ -38,30 +38,28 @@ class MapRoomData virtual ~MapRoomData( ) ; /** - * Busca una sala conectada con ésta + * Find room connected to this one */ std::string findConnectedRoom ( const Way& wayOfExit, Way* wayOfEntry ) const ; /** - * Comprueba que la entrada a la sala es correcta y la corrige si no lo es - * Cuando se accede a una sala triple o cuádruple desde una simple o doble - * la entrada no es correcta porque por la estructura del mapa se devuelve - * un punto cardinal simple y las puertas de las salas triple o cuádruples - * no están situadas en esos puntos cardinales - * @param wayOfEntry Dirección de entrada a comprobar - * @param previousRoom Nombre de la sala desde la cual se ha entrado a ésta + * See if entrance to this room is okay or fix it if it’s not + * + * When triple or quadruple room is entered from single or double room + * then entrance isn’t okay because map returns simple way like south or west + * but doors of triple and quadruple rooms are out of such ways */ void adjustEntry ( Way* wayOfEntry, const std::string& previousRoom ) ; private: /** - * Nombre completo del archivo que contiene los datos de esta sala + * Name of file with data for this room */ std::string room ; /** - * Indica si la sala ha sido visitada por alguno de los jugadores + * When this room is already visited by any of characters */ bool visited ; @@ -153,102 +151,36 @@ class MapRoomData bool isVisited () const { return this->visited ; } - /** - * Establece la sala situada al norte - * @param room El nombre completo del archivo de la sala - */ void setNorth ( const std::string& room ) { this->north = room ; } - /** - * Establece la sala situada al sur - * @param room El nombre completo del archivo de la sala - */ void setSouth ( const std::string& room ) { this->south = room ; } - /** - * Establece la sala situada al este - * @param room El nombre completo del archivo de la sala - */ void setEast ( const std::string& room ) { this->east = room ; } - /** - * Establece la sala situada al oeste - * @param room El nombre completo del archivo de la sala - */ void setWest ( const std::string& room ) { this->west = room ; } - /** - * Establece la sala situada debajo. La sala no puede tener suelo - * @param room El nombre completo del archivo de la sala - */ void setFloor ( const std::string& room ) { this->floor = room ; } - /** - * Establece la sala situada encima. Dicha sala no puede tener suelo - * @param room El nombre completo del archivo de la sala - */ void setRoof ( const std::string& room ) { this->roof = room ; } - /** - * Establece la sala a la que conduce el telepuerto. La sala destino debe - * tener un telepuerto en la misma posición que la actual - * @param room El nombre completo del archivo de la sala - */ void setTeleport ( const std::string& room ) { this->teleport = room ; } - /** - * Establece la sala a la que conduce el segundo telepuerto. La sala destino debe - * tener un telepuerto en la misma posición que la actual - * @param room El nombre completo del archivo de la sala - */ void setTeleportToo ( const std::string& room ) { this->teleport2 = room ; } - /** - * Establece la sala situada en la posición norte-este - * @param room El nombre completo del archivo de la sala - */ void setNorthEast ( const std::string& room ) { this->northEast = room ; } - /** - * Establece la sala situada en la posición norte-oeste - * @param room El nombre completo del archivo de la sala - */ void setNorthWest ( const std::string& room ) { this->northWest = room ; } - /** - * Establece la sala situada en la posición sur-este - * @param room El nombre completo del archivo de la sala - */ void setSouthEast ( const std::string& room ) { this->southEast = room ; } - /** - * Establece la sala situada en la posición sur-oeste - * @param room El nombre completo del archivo de la sala - */ void setSouthWest ( const std::string& room ) { this->southWest = room ; } - /** - * Establece la sala situada en la posición este-norte - * @param room El nombre completo del archivo de la sala - */ void setEastNorth ( const std::string& room ) { this->eastNorth = room ; } - /** - * Establece la sala situada en la posición este-sur - * @param room El nombre completo del archivo de la sala - */ void setEastSouth ( const std::string& room ) { this->eastSouth = room ; } - /** - * Establece la sala situada en la posición oeste-norte - * @param room El nombre completo del archivo de la sala - */ void setWestNorth ( const std::string& room ) { this->westNorth = room ; } - /** - * Establece la sala situada en la posición oeste-sur - * @param room El nombre completo del archivo de la sala - */ void setWestSouth ( const std::string& room ) { this->westSouth = room ; } }; diff --git a/src/Mediator.cpp b/src/Mediator.cpp index e7514c12..0e980b8b 100644 --- a/src/Mediator.cpp +++ b/src/Mediator.cpp @@ -19,15 +19,14 @@ namespace isomot { Mediator::Mediator( Room* room ) + : room( room ) + , gridItemsSorting( false ) + , freeItemsSorting( false ) + , switchInRoomIsOn( false ) + , activePlayer( nilPointer ) { - this->room = room; - this->gridItemsSorting = false; - this->freeItemsSorting = false; - this->switchInRoomIsOn = false; - this->activePlayer = 0; - - pthread_mutex_init( &gridItemsMutex, 0 ); - pthread_mutex_init( &freeItemsMutex, 0 ); + pthread_mutex_init( &gridItemsMutex, nilPointer ); + pthread_mutex_init( &freeItemsMutex, nilPointer ); // items which may be freezed by doughnut or switch badBoys.push_back( "behavior of detector" ); @@ -131,7 +130,7 @@ void Mediator::update() } } - if ( activePlayer != 0 ) + if ( activePlayer != nilPointer ) { activePlayer->behave (); } @@ -178,7 +177,7 @@ void Mediator::beginUpdate() pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ); - pthread_create( &thread, 0, updateThread, reinterpret_cast< void * >( this ) ); + pthread_create( &thread, nilPointer, updateThread, reinterpret_cast< void * >( this ) ); pthread_attr_destroy( &attr ); } @@ -186,7 +185,7 @@ void Mediator::beginUpdate() void Mediator::endUpdate() { this->threadRunning = false; - pthread_join( thread, 0 ); + pthread_join( thread, nilPointer ); } void* updateThread( void* thisClass ) @@ -196,10 +195,10 @@ void* updateThread( void* thisClass ) while( mediator->isThreadRunning() ) { mediator->update(); - sleep( 10 ); + milliSleep( 10 ); } - pthread_exit( 0 ); + pthread_exit( nilPointer ); } void Mediator::remaskFreeItem( FreeItem* item ) @@ -234,7 +233,7 @@ void Mediator::remaskGridItem( GridItem* gridItem ) { FreeItem* freeItem = *f; - if ( freeItem != 0 && freeItem->getRawImage() ) + if ( freeItem != nilPointer && freeItem->getRawImage() ) { // mask item if there’s overlap between images if ( ( freeItem->getOffsetX() < gridItem->getOffsetX() + gridItem->getRawImage()->w ) @@ -275,8 +274,8 @@ void Mediator::reshadeGridItem( GridItem* item ) } } - // Marca para sombrear la loseta de la columna, si existe - if ( room->floor[ column ] != 0 ) + // mark to shade floor tile of this column, si existe + if ( room->floor[ column ] != nilPointer ) room->floor[ column ]->setWhichShade( WantShadow ); } @@ -308,8 +307,8 @@ void Mediator::reshadeFreeItem( FreeItem* item ) } } - // Marca para sombrear la loseta de la columna - if ( room->floor[ column ] != 0 ) + // mark to shade floor tile of this column, si existe + if ( room->floor[ column ] != nilPointer ) room->floor[ column ]->setWhichShade( WantShadow ); } } @@ -348,7 +347,7 @@ void Mediator::castShadowOnFloor( FloorTile* floorTile ) GridItem* gridItem = *g ; // shade image of tile when item has shadow - if ( gridItem->getImageOfShadow() != 0 ) + if ( gridItem->getImageOfShadow() != nilPointer ) { floorTile->castShadowImage ( /* x */ ( tileSize << 1 ) * ( xCell - yCell ) - ( gridItem->getImageOfShadow()->w >> 1 ) + room->getX0() + 1, @@ -365,7 +364,7 @@ void Mediator::castShadowOnFloor( FloorTile* floorTile ) { FreeItem* freeItem = *f ; - if ( freeItem->getImageOfShadow() != 0 ) + if ( freeItem->getImageOfShadow() != nilPointer ) { int xStart = freeItem->getX() / tileSize; int xEnd = ( freeItem->getX() + freeItem->getWidthX() - 1 ) / tileSize; @@ -397,7 +396,7 @@ void Mediator::castShadowOnGridItem( GridItem* gridItem ) { GridItem* tempItem = *g ; - if ( tempItem->getImageOfShadow() != 0 && tempItem->getZ() > gridItem->getZ() ) + if ( tempItem->getImageOfShadow() != nilPointer && tempItem->getZ() > gridItem->getZ() ) { gridItem->castShadowImage ( /* x */ gridItem->getOffsetX() + ( ( gridItem->getRawImage()->w - tempItem->getImageOfShadow()->w ) >> 1 ), @@ -414,7 +413,7 @@ void Mediator::castShadowOnGridItem( GridItem* gridItem ) { FreeItem* freeItem = *f ; - if ( freeItem->getImageOfShadow() != 0 && freeItem->getZ() > gridItem->getZ() ) + if ( freeItem->getImageOfShadow() != nilPointer && freeItem->getZ() > gridItem->getZ() ) { // range of columns met with item int xStart = freeItem->getX() / tileSize; @@ -458,7 +457,7 @@ void Mediator::castShadowOnFreeItem( FreeItem* freeItem ) { GridItem* gridItem = *g ; - if ( gridItem->getImageOfShadow() != 0 && gridItem->getZ() > freeItem->getZ() ) + if ( gridItem->getImageOfShadow() != nilPointer && gridItem->getZ() > freeItem->getZ() ) { # if defined( DEBUG_SHADOWS ) && DEBUG_SHADOWS std::cout << "casting shadow from " << gridItem->whichKindOfItem() << " \"" << gridItem->getLabel() << "\"" << @@ -485,7 +484,7 @@ void Mediator::castShadowOnFreeItem( FreeItem* freeItem ) { FreeItem* shadeItem = *f ; - if ( shadeItem->getImageOfShadow() != 0 && shadeItem->getId() != freeItem->getId() ) + if ( shadeItem->getImageOfShadow() != nilPointer && shadeItem->getId() != freeItem->getId() ) { // shadow with free item above if ( freeItem->getZ() < shadeItem->getZ() && @@ -614,7 +613,7 @@ void Mediator::mask( FreeItem* freeItem ) Item* Mediator::findItemById( int id ) { - Item* item = 0; + Item* item = nilPointer; // look for free item if ( id & 1 ) @@ -648,7 +647,7 @@ Item* Mediator::findItemById( int id ) Item* Mediator::findItemByLabel( const std::string& label ) { - Item* item = 0; + Item* item = nilPointer; // look for free item std::list< FreeItem * >::iterator f = std::find_if( freeItems.begin (), freeItems.end (), std::bind2nd( EqualLabelOfItem (), label ) ); @@ -659,7 +658,7 @@ Item* Mediator::findItemByLabel( const std::string& label ) } // look for grid item - if ( item == 0 ) + if ( item == nilPointer ) { std::list< GridItem * >::iterator g; @@ -680,7 +679,7 @@ Item* Mediator::findItemByLabel( const std::string& label ) Item* Mediator::findItemByBehavior( const std::string& behavior ) { - Item* item = 0; + Item* item = nilPointer; // look for free item std::list< FreeItem * >::iterator f = std::find_if( freeItems.begin (), freeItems.end (), std::bind2nd( EqualBehaviorOfItem (), behavior ) ); @@ -691,7 +690,7 @@ Item* Mediator::findItemByBehavior( const std::string& behavior ) } // look for grid item - if ( item == 0 ) + if ( item == nilPointer ) { std::list< GridItem * >::iterator g; @@ -939,11 +938,11 @@ Item* Mediator::collisionWithByLabel( const std::string& label ) { Item* item = findItemById( collisions[ i ] ); - if ( item != 0 && item->getLabel() == label ) + if ( item != nilPointer && item->getLabel() == label ) return item; } - return 0; + return nilPointer; } Item* Mediator::collisionWithByBehavior( const std::string& behavior ) @@ -952,11 +951,14 @@ Item* Mediator::collisionWithByBehavior( const std::string& behavior ) { Item* item = findItemById( collisions[ i ] ); - if ( item != 0 && item->getBehavior() != 0 && item->getBehavior()->getNameOfBehavior () == behavior ) + if ( item != nilPointer && item->getBehavior() != nilPointer && + item->getBehavior()->getNameOfBehavior () == behavior ) + { return item; + } } - return 0; + return nilPointer; } Item* Mediator::collisionWithBadBoy() @@ -965,14 +967,14 @@ Item* Mediator::collisionWithBadBoy() { Item* item = findItemById( collisions[ i ] ); - if ( item != 0 && item->getBehavior() != 0 && item->isMortal() + if ( item != nilPointer && item->getBehavior() != nilPointer && item->isMortal() && std::find( badBoys.begin(), badBoys.end(), item->getBehavior()->getNameOfBehavior () ) != badBoys.end() ) { return item; } } - return 0; + return nilPointer; } bool Mediator::selectNextPlayer( ItemDataManager* itemDataManager ) @@ -1028,7 +1030,7 @@ bool Mediator::selectNextPlayer( ItemDataManager* itemDataManager ) activePlayer = roomBuilder->createPlayerInRoom( this->room, false, "headoverheels", x, y, z, orientation ); // transfer item in handbag - if ( takenItemData != 0 ) + if ( takenItemData != nilPointer ) { std::cout << "transfer item \"" << takenItemData->getLabel() << "\" to player \"" << activePlayer->getLabel() << "\"" << std::endl ; activePlayer->assignTakenItem( takenItemData, takenItemImage, behaviorOfItemTaken ); @@ -1067,7 +1069,7 @@ bool Mediator::selectNextPlayer( ItemDataManager* itemDataManager ) PlayerItem* heelsPlayer = roomBuilder->createPlayerInRoom( this->room, false, "heels", x, y, z, orientation ); - if ( takenItemData != 0 ) + if ( takenItemData != nilPointer ) { std::cout << "transfer item \"" << takenItemData->getLabel() << "\" to player \"" << heelsPlayer->getLabel() << "\"" << std::endl ; heelsPlayer->assignTakenItem( takenItemData, takenItemImage, behaviorOfItemTaken ); @@ -1101,7 +1103,7 @@ void Mediator::toggleSwitchInRoom () { FreeItem* freeItem = *f; - if ( freeItem != 0 && freeItem->getBehavior() != 0 ) + if ( freeItem != nilPointer && freeItem->getBehavior() != nilPointer ) { std::string behavior = freeItem->getBehavior()->getNameOfBehavior (); @@ -1120,7 +1122,7 @@ void Mediator::toggleSwitchInRoom () { GridItem* gridItem = *g; - if ( gridItem != 0 && gridItem->getBehavior() != 0 ) + if ( gridItem != nilPointer && gridItem->getBehavior() != nilPointer ) { std::string behavior = gridItem->getBehavior()->getNameOfBehavior (); @@ -1164,7 +1166,7 @@ PlayerItem* Mediator::getWaitingPlayer() const } } - return 0 ; + return nilPointer ; } bool EqualItemId::operator() ( Item* item, int id ) const @@ -1179,7 +1181,7 @@ bool EqualLabelOfItem::operator() ( Item* item, const std::string& label ) const bool EqualBehaviorOfItem::operator() ( Item* item, const std::string& behavior ) const { - return ( item->getBehavior() != 0 && item->getBehavior()->getNameOfBehavior () == behavior ); + return ( item->getBehavior() != nilPointer && item->getBehavior()->getNameOfBehavior () == behavior ); } } diff --git a/src/Mediator.hpp b/src/Mediator.hpp index 72c4b455..e234c3c0 100644 --- a/src/Mediator.hpp +++ b/src/Mediator.hpp @@ -242,6 +242,11 @@ class Mediator friend class Room ; + /** + * Room where this mediator deals + */ + Room* room ; + /** * Identificador del subproceso de actualización de los elementos */ @@ -273,11 +278,6 @@ class Mediator */ std::string lastActivePlayer ; - /** - * Sala en la que negocia este mediador - */ - Room* room ; - /** * Conjunto de elementos que forman la estructura de una sala. Cada columna del vector está compuesta de * una lista de elementos rejilla cuya coordenada Z es mayor que la coordenada del elemento precedente, diff --git a/src/PlayerItem.cpp b/src/PlayerItem.cpp index 49012e92..254bca0c 100644 --- a/src/PlayerItem.cpp +++ b/src/PlayerItem.cpp @@ -18,14 +18,14 @@ PlayerItem::PlayerItem( ItemData* itemData, int x, int y, int z, const Way& way , lives( 0 ) , highSpeed( 0 ) , highJumps( 0 ) - , shield( 0 ) + , shield( 0.0 ) , howManyDoughnuts( 0 ) , exit( NoExit ) , entry( JustWait ) - , shieldTimer( 0 ) + , shieldTimer( nilPointer ) , shieldTime( 25.0 ) - , takenItemData( 0 ) - , takenItemImage( 0 ) + , takenItemData( nilPointer ) + , takenItemImage( nilPointer ) , originalDataOfItem( itemData ) { @@ -41,10 +41,10 @@ PlayerItem::PlayerItem( const PlayerItem& playerItem ) , howManyDoughnuts( playerItem.howManyDoughnuts ) , exit( playerItem.exit ) , entry( playerItem.entry ) - , shieldTimer( 0 ) + , shieldTimer( nilPointer ) , shieldTime( playerItem.shieldTime ) - , takenItemData( 0 ) - , takenItemImage( 0 ) + , takenItemData( nilPointer ) + , takenItemImage( nilPointer ) , originalDataOfItem( playerItem.getOriginalDataOfItem() ) { @@ -52,10 +52,7 @@ PlayerItem::PlayerItem( const PlayerItem& playerItem ) PlayerItem::~PlayerItem() { - if ( this->shieldTimer != 0 ) - { - delete shieldTimer; - } + delete shieldTimer; } void PlayerItem::setWayOfExit ( const Way& way ) @@ -100,7 +97,7 @@ void PlayerItem::autoMoveOnEntry ( const Way& wayOfEntry ) { setWayOfEntry( wayOfEntry ); - if ( getBehavior() == 0 ) + if ( getBehavior() == nilPointer ) { std::cerr << "nil behavior at PlayerItem::autoMoveOnEntry" << std::endl ; return; @@ -292,7 +289,7 @@ bool PlayerItem::updatePosition( int newX, int newY, int newZ, const Coordinate& WestnorthBorder, WestsouthBorder, WestBorder }; // check each limit of room - for ( int i = 0; i < 12; i++ ) + for ( unsigned int i = 0; i < 12; i++ ) { if ( isCollidingWithRoomBorder( ways[ i ] ) ) { @@ -526,7 +523,7 @@ bool PlayerItem::isCollidingWithRoomBorder( const Way& way ) void PlayerItem::behave () { UserControlled* userBehavior = dynamic_cast< UserControlled* >( this->behavior ); - if ( userBehavior != 0 ) + if ( userBehavior != nilPointer ) { userBehavior->behave ( ); } @@ -534,7 +531,7 @@ void PlayerItem::behave () bool PlayerItem::update () { - if ( behavior != 0 ) + if ( behavior != nilPointer ) { behavior->update ( ); } @@ -556,11 +553,11 @@ void PlayerItem::wait () size_t frame = ( getDataOfItem()->howManyMotions() - getDataOfItem()->howManyExtraFrames() ) / getDataOfItem()->howManyFramesForOrientations() * orientOccident ; if ( frame >= getDataOfItem()->howManyMotions() ) frame = 0; - if ( this->rawImage != 0 && /* if images differ */ this->rawImage != getDataOfItem()->getMotionAt( frame ) ) + if ( this->rawImage != nilPointer && /* if images differ */ this->rawImage != getDataOfItem()->getMotionAt( frame ) ) { changeImage( getDataOfItem()->getMotionAt( frame ) ); - if ( this->shadow != 0 ) + if ( this->shadow != nilPointer ) { changeShadow( getDataOfItem()->getShadowAt( frame ) ); } @@ -672,7 +669,7 @@ void PlayerItem::activateShield() void PlayerItem::decreaseShield() { - if ( this->shieldTimer != 0 ) + if ( this->shieldTimer != nilPointer ) { this->shield = shieldTime - shieldTimer->getValue(); GameManager::getInstance()->modifyShield( this->getLabel(), this->shield ); @@ -684,7 +681,7 @@ void PlayerItem::decreaseShield() this->shield = 0; this->shieldTimer->stop(); delete this->shieldTimer; - this->shieldTimer = 0; + this->shieldTimer = nilPointer; } } @@ -692,23 +689,23 @@ void PlayerItem::liberatePlanet () { std::string scenery = this->mediator->getRoom()->getScenery(); - if ( scenery.compare( "jail" ) == 0 || scenery.compare( "blacktooth" ) == 0 || scenery.compare( "market" ) == 0 ) + if ( scenery == "jail" || scenery == "blacktooth" || scenery == "market" ) { GameManager::getInstance()->liberatePlanet( "blacktooth" ); } - else if ( scenery.compare( "egyptus" ) == 0 ) + else if ( scenery == "egyptus" ) { GameManager::getInstance()->liberatePlanet( "egyptus" ); } - else if ( scenery.compare( "penitentiary" ) == 0 ) + else if ( scenery == "penitentiary" ) { GameManager::getInstance()->liberatePlanet( "penitentiary" ); } - else if ( scenery.compare( "safari" ) == 0 ) + else if ( scenery == "safari" ) { GameManager::getInstance()->liberatePlanet( "safari" ); } - else if ( scenery.compare( "byblos" ) == 0 ) + else if ( scenery == "byblos" ) { GameManager::getInstance()->liberatePlanet( "byblos" ); } @@ -737,7 +734,7 @@ void PlayerItem::setShieldTime ( double shield ) { this->shieldTime = shield; - if ( this->shieldTime > 0 && this->shieldTimer == 0 ) + if ( this->shieldTime > 0 && this->shieldTimer == nilPointer ) { this->shieldTimer = new Timer(); this->shieldTimer->go(); diff --git a/src/Room.cpp b/src/Room.cpp index 75518a24..fb1ae21d 100644 --- a/src/Room.cpp +++ b/src/Room.cpp @@ -64,7 +64,7 @@ Room::Room( const std::string& roomFile, const std::string& scenery, int xTiles, // create empty floor for ( int i = 0; i < xTiles * yTiles + 1; i++ ) { - this->floor.push_back( 0 ); + this->floor.push_back( nilPointer ); } // Creación del vector de índices. Asigna el contenido de los elementos de la siguiente forma @@ -104,7 +104,7 @@ Room::Room( const std::string& roomFile, const std::string& scenery, int xTiles, // 55 62 // 63 - int i( 0 ); + int pos = 0; this->drawIndex = new int[ xTiles * yTiles ]; for ( int f = 0; f <= ( xTiles + yTiles - 1 ); f++ ) @@ -114,7 +114,7 @@ Room::Room( const std::string& roomFile, const std::string& scenery, int xTiles, int temp = n * ( xTiles - 1 ) + f; if ( ( temp >= n * xTiles ) && ( temp < ( n + 1 ) * xTiles ) ) { - this->drawIndex[ i++ ] = temp; + this->drawIndex[ pos++ ] = temp; } } } @@ -233,7 +233,7 @@ void Room::addDoor( Door * door ) void Room::addGridItem( GridItem * gridItem ) { - if ( gridItem == 0 ) return; + if ( gridItem == nilPointer ) return; if ( ( gridItem->getCellX() < 0 || gridItem->getCellY() < 0 ) || ( gridItem->getCellX() >= static_cast< int >( this->numberOfTiles.first ) || @@ -300,7 +300,7 @@ void Room::addGridItem( GridItem * gridItem ) void Room::addFreeItem( FreeItem * freeItem ) { - if ( freeItem == 0 ) return; + if ( freeItem == nilPointer ) return; if ( freeItem->getX() < 0 || freeItem->getY() < 1 || freeItem->getZ() < Top ) { @@ -376,7 +376,7 @@ void Room::addFreeItem( FreeItem * freeItem ) bool Room::addPlayerToRoom( PlayerItem* playerItem, bool playerEntersRoom ) { - if ( playerItem == 0 ) return false; + if ( playerItem == nilPointer ) return false; for ( std::list< PlayerItem * >::const_iterator pi = playersYetInRoom.begin (); pi != playersYetInRoom.end (); ++pi ) { @@ -558,8 +558,7 @@ void Room::copyAnotherCharacterAsEntered( const std::string& name ) void Room::removeFloor( FloorTile * floorTile ) { - // La eliminación es en realidad una sustitución por una loseta vacía - this->floor[ floorTile->getColumn () ] = 0; + this->floor[ floorTile->getColumn () ] = nilPointer; delete floorTile; } @@ -624,7 +623,7 @@ bool Room::removePlayerFromRoom( PlayerItem* playerItem, bool playerExitsRoom ) { PlayerItem* nextPlayer = mediator->getWaitingPlayer(); - if ( nextPlayer != 0 ) + if ( nextPlayer != nilPointer ) { // activate other player in room mediator->setActivePlayer( nextPlayer ); @@ -691,7 +690,7 @@ void Room::removeBars () } } - if ( howManyBars != 0 ) + if ( howManyBars > 0 ) std::cout << howManyBars << " bars are gone" << std::endl ; } @@ -703,7 +702,7 @@ void Room::draw( BITMAP* where ) if ( active ) { // draw in picture of room itself when destination bitmap isn’t given - if ( where == 0 ) + if ( where == nilPointer ) where = this->picture ; // clean the image where to draw this room @@ -728,7 +727,7 @@ void Room::draw( BITMAP* where ) { unsigned int column = this->numberOfTiles.first * yCell + xCell; - if ( floor[ column ] != 0 ) // if there is tile of floor here + if ( floor[ column ] != nilPointer ) // if there is tile of floor here { // shade this tile when shadows are on if ( shadingScale < 256 && floor[ column ]->getRawImage() ) @@ -818,7 +817,7 @@ void Room::draw( BITMAP* where ) void Room::calculateBounds() { bounds[ North ] = doors[ North ] || doors[ Northeast ] || doors[ Northwest ] || this->kindOfFloor == "none" ? tileSize : 0; - bounds[ East ] = doors[ East ] || doors[ Eastnorth ] || doors[ Eastsouth ] || this->kindOfFloor == "none" ? tileSize : 0; + bounds[ East ] = doors[ East ] || doors[ Eastnorth ] || doors[ Eastsouth ] || this->kindOfFloor == "none" ? tileSize : 0; bounds[ South ] = tileSize * numberOfTiles.first - ( doors[ South ] || doors[ Southeast ] || doors[ Southwest ] ? tileSize : 0 ); bounds[ West ] = tileSize * numberOfTiles.second - ( doors[ West ] || doors[ Westnorth ] || doors[ Westsouth ] ? tileSize : 0 ); @@ -1097,7 +1096,7 @@ TripleRoomInitialPoint* Room::findInitialPointOfEntryToTripleRoom( const Way& wa listOfInitialPointsForTripleRoom.end (), std::bind2nd( EqualTripleRoomInitialPoint(), way ) ); - return ( i != listOfInitialPointsForTripleRoom.end () ? ( &( *i ) ) : 0 ); + return ( i != listOfInitialPointsForTripleRoom.end () ? ( &( *i ) ) : nilPointer ); } TripleRoomInitialPoint::TripleRoomInitialPoint( const Way& way, int x, int y ) diff --git a/src/Room.hpp b/src/Room.hpp index 3f2413c1..d9732f0b 100644 --- a/src/Room.hpp +++ b/src/Room.hpp @@ -363,7 +363,7 @@ class Room : public Drawable, public Mediated */ Door * getDoorAt ( const Way& way ) { return doors[ way ] ; } - bool hasDoorAt ( const Way& way ) { return ( doors[ way ] != 0 ) ; } + bool hasDoorAt ( const Way& way ) { return ( doors[ way ] != nilPointer ) ; } /** * Establece la salida por la que algún jugador abandona la sala diff --git a/src/RoomBuilder.cpp b/src/RoomBuilder.cpp index c3110cd4..984a66e6 100644 --- a/src/RoomBuilder.cpp +++ b/src/RoomBuilder.cpp @@ -19,7 +19,7 @@ namespace isomot RoomBuilder::RoomBuilder( ItemDataManager* manager ) : itemDataManager( manager ) - , room( 0 ) + , room( nilPointer ) { } @@ -37,7 +37,7 @@ Room* RoomBuilder::buildRoom ( const std::string& fileName ) // create room with basic parameters like scenery, dimensions, existence of floor this->room = new Room( roomXML->name(), roomXML->scenery(), roomXML->xTiles(), roomXML->yTiles(), roomXML->width(), roomXML->floorType() ); - if ( this->room == 0 ) + if ( this->room == nilPointer ) { std::cerr << "I can't create room \"" << fileName << "\"" << std::endl ; throw "I can't create room \"" + fileName + "\""; @@ -153,7 +153,7 @@ Room* RoomBuilder::buildRoom ( const std::string& fileName ) else if ( ( *i ).type () == rxml::type::door ) { Door* door = this->buildDoor( *i ); - if ( door == 0 ) + if ( door == nilPointer ) { std::ostringstream oss; oss << "oops, can’t build a door with coordinates " << ( *i ).x () << ", " << ( *i ).y () << ", " << ( *i ).z () ; @@ -166,7 +166,7 @@ Room* RoomBuilder::buildRoom ( const std::string& fileName ) else if( ( *i ).type () == rxml::type::griditem ) { GridItem* gridItem = this->buildGridItem( *i ); - if ( gridItem == 0 ) + if ( gridItem == nilPointer ) { std::ostringstream oss; oss << "oops, can’t build a grid item with coordinates " << ( *i ).x () << ", " << ( *i ).y () << ", " << ( *i ).z () ; @@ -179,7 +179,7 @@ Room* RoomBuilder::buildRoom ( const std::string& fileName ) else if ( ( *i ).type () == rxml::type::freeitem ) { FreeItem* freeItem = this->buildFreeItem( *i ); - if ( freeItem == 0 ) + if ( freeItem == nilPointer ) { std::ostringstream oss; oss << "free item with coordinates " << ( *i ).x () << ", " << ( *i ).y () << ", " << ( *i ).z () << " is absent"; @@ -254,10 +254,11 @@ PlayerItem* RoomBuilder::createPlayerInRoom( Room* room, bool justEntered, } ItemData* itemData = this->itemDataManager->findItemByLabel( nameOfPlayerToCreate ); - PlayerItem* player = 0; + PlayerItem* player = nilPointer; // if it is found and has some lives left, place it in room - if ( ( nameOfPlayerToCreate == "headoverheels" || nameOfPlayerToCreate == "head" || nameOfPlayerToCreate == "heels" ) && itemData != 0 ) + if ( ( nameOfPlayerToCreate == "headoverheels" || nameOfPlayerToCreate == "head" || nameOfPlayerToCreate == "heels" ) + && itemData != nilPointer ) { if ( gameManager->getLives( nameOfPlayerToCreate ) > 0 ) { @@ -296,10 +297,10 @@ PlayerItem* RoomBuilder::createPlayerInRoom( Room* room, bool justEntered, FloorTile* RoomBuilder::buildFloorTile( const rxml::tile& tile, const char* gfxPrefix ) { - BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + gfxPrefix + pathSeparator + tile.picture() ), 0 ); - if ( picture == 0 ) { + BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + gfxPrefix + pathSeparator + tile.picture() ), nilPointer ); + if ( picture == nilPointer ) { std::cerr << "picture \"" << tile.picture() << "\" at \"" << gfxPrefix << "\" is absent" << std::endl ; - return 0; + return nilPointer; } int column = room->getTilesX() * tile.y() + tile.x(); @@ -309,10 +310,10 @@ FloorTile* RoomBuilder::buildFloorTile( const rxml::tile& tile, const char* gfxP Wall* RoomBuilder::buildWall( const rxml::wall& wall, const char* gfxPrefix ) { - BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + gfxPrefix + pathSeparator + wall.picture() ), 0 ); - if ( picture == 0 ) { + BITMAP* picture = load_png( isomot::pathToFile( isomot::sharePath() + gfxPrefix + pathSeparator + wall.picture() ), nilPointer ); + if ( picture == nilPointer ) { std::cerr << "picture \"" << wall.picture() << "\" at \"" << gfxPrefix << "\" is absent" << std::endl ; - return 0; + return nilPointer; } return new Wall( wall.axis() == rxml::axis::x ? true : false, wall.index(), picture ); @@ -320,11 +321,11 @@ Wall* RoomBuilder::buildWall( const rxml::wall& wall, const char* gfxPrefix ) GridItem* RoomBuilder::buildGridItem( const rxml::item& item ) { - GridItem* gridItem = 0; + GridItem* gridItem = nilPointer; ItemData* itemData = this->itemDataManager->findItemByLabel( item.label () ); // when found place item in room - if ( itemData != 0 ) + if ( itemData != nilPointer ) { // deal with difference between position from file and position in room gridItem = new GridItem( itemData, item.x(), item.y(), ( item.z() > Top ? item.z() * LayerHeight : Top ), @@ -344,7 +345,7 @@ GridItem* RoomBuilder::buildGridItem( const rxml::item& item ) } else { - gridItem->assignBehavior( behaviorOfItem, 0 ); + gridItem->assignBehavior( behaviorOfItem, nilPointer ); } } @@ -353,12 +354,12 @@ GridItem* RoomBuilder::buildGridItem( const rxml::item& item ) FreeItem* RoomBuilder::buildFreeItem( const rxml::item& item ) { - FreeItem* freeItem = 0; + FreeItem* freeItem = nilPointer; ItemData* itemData = this->itemDataManager->findItemByLabel( item.label () ); // if item is here, place it in room - if ( itemData != 0 ) + if ( itemData != nilPointer ) { // in free coordinates int fx = item.x() * room->getSizeOfOneTile() + ( ( room->getSizeOfOneTile() - itemData->getWidthX() ) >> 1 ); @@ -416,7 +417,7 @@ FreeItem* RoomBuilder::buildFreeItem( const rxml::item& item ) } else { - freeItem->assignBehavior( behaviorOfItem, 0 ); + freeItem->assignBehavior( behaviorOfItem, nilPointer ); } } } diff --git a/src/SoundManager.cpp b/src/SoundManager.cpp index d3bfaf91..23d1b995 100644 --- a/src/SoundManager.cpp +++ b/src/SoundManager.cpp @@ -7,13 +7,13 @@ using isomot::SampleData; using isomot::SoundData; using isomot::EqualSoundData; -SoundManager* SoundManager::instance = 0; +SoundManager* SoundManager::instance = nilPointer ; SoundManager::SoundManager( ) : fileName( std::string() ), - oggPlayer( 0 ), - oggStream( 0 ), + oggPlayer( nilPointer ), + oggStream( nilPointer ), effectsVolume( 80 ), musicVolume( 75 ) { @@ -45,7 +45,7 @@ SoundManager::~SoundManager( ) SoundManager* SoundManager::getInstance() { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new SoundManager(); } @@ -88,7 +88,7 @@ void SoundManager::play( const std::string& label, const ActivityOfItem& activit { SampleData* sampleData = this->findSample( label, activity ); - if ( sampleData != 0 && sampleData->voice == -1 ) + if ( sampleData != nilPointer && sampleData->voice == -1 ) { sampleData->voice = allocate_voice( sampleData->sample ); voice_set_volume( sampleData->voice, ( this->effectsVolume * 255 ) / 100 ); @@ -117,7 +117,7 @@ void SoundManager::stop( const std::string& label, const ActivityOfItem& activit { SampleData* sampleData = this->findSample( label, activity ); - if ( sampleData != 0 ) + if ( sampleData != nilPointer ) { stop_sample( sampleData->sample ); } @@ -151,15 +151,15 @@ void SoundManager::playOgg ( const std::string& fileName, bool loop ) this->oggStream = alogg_start_streaming( isomot::pathToFile( isomot::sharePath() + fileName ), lengthOfbuffer ); if ( this->oggStream ) { - alogg_thread* oggThread = 0; + alogg_thread* oggThread = nilPointer; if ( loop ) oggThread = alogg_create_thread_which_loops( this->oggStream, isomot::pathToFile( isomot::sharePath() + fileName ), lengthOfbuffer ); else oggThread = alogg_create_thread( this->oggStream ); - if ( oggThread != 0 ) + if ( oggThread != nilPointer ) { - if ( this->oggPlayer != 0 ) + if ( this->oggPlayer != nilPointer ) this->stopAnyOgg (); // it is playback of just single Ogg yet // or previous oggPlayer will be lost // and if it is the one which loops forever it would never ever end @@ -183,7 +183,7 @@ void SoundManager::playOgg ( const std::string& fileName, bool loop ) void SoundManager::stopAnyOgg () { - if ( oggPlayer != 0 ) + if ( oggPlayer != nilPointer ) { if ( oggPlayer->stop == 0 ) { @@ -196,15 +196,15 @@ void SoundManager::stopAnyOgg () std::cout << "Ogg playback is off" << std::endl ; } - oggPlayer = 0; - oggStream = 0; + oggPlayer = nilPointer; + oggStream = nilPointer; oggPlaying.clear(); } } void SoundManager::setVolumeOfMusic( unsigned int volume ) { - this->musicVolume = volume == 0 ? 1 : volume; + this->musicVolume = ( volume == 0 ? 1 : volume ); set_volume( ( this->musicVolume * 255 ) / 100, 0 ); } @@ -212,7 +212,7 @@ SampleData* SoundManager::findSample( const std::string& label, const ActivityOf { std::list< SoundData >::iterator i = std::find_if( soundData.begin(), soundData.end(), std::bind2nd( EqualSoundData(), label ) ); - return i != soundData.end () ? ( *i ).find( this->translateActivityOfItemToString( activity ) ) : 0; + return i != soundData.end () ? ( *i ).find( this->translateActivityOfItemToString( activity ) ) : nilPointer; } std::string SoundManager::translateActivityOfItemToString ( const ActivityOfItem& activity ) @@ -359,7 +359,7 @@ void SoundData::addSound( const std::string& activity, const std::string& sample { SAMPLE* sample = load_sample( isomot::pathToFile( isomot::sharePath() + sampleFileName ) ); - if ( sample != 0 ) { + if ( sample != nilPointer ) { #if defined( DEBUG ) && DEBUG std::cout << "got sound \"" << sampleFileName << "\" for activity \"" << activity << "\" of \"" << label << "\"" << std::endl ; #endif @@ -375,7 +375,7 @@ SampleData* SoundData::find( const std::string& event ) { __gnu_cxx::hash_map< std::string, SampleData >::iterator i = this->table.find( event ); - return i != this->table.end () ? ( &( i->second ) ) : 0; + return i != this->table.end () ? ( &( i->second ) ) : nilPointer; } bool EqualSoundData::operator()( const SoundData& soundData, const std::string& label ) const diff --git a/src/SoundManager.hpp b/src/SoundManager.hpp index 3ca11f6c..42529f66 100644 --- a/src/SoundManager.hpp +++ b/src/SoundManager.hpp @@ -59,10 +59,6 @@ class SoundManager ~SoundManager( ) ; - /** - * Único objeto de esta clase para toda la aplicación - * @return Un puntero al objeto único - */ static SoundManager* getInstance () ; /** @@ -108,7 +104,7 @@ class SoundManager * @param fileName Nombre del archivo Ogg * @return true si está sonando o false en caso contrario */ - bool isPlayingOgg ( const std::string& fileName ) { return this->oggPlaying.compare( fileName ) == 0 && oggPlayer && oggPlayer->alive != 0 ; } + bool isPlayingOgg ( const std::string& fileName ) { return this->oggPlaying == fileName && oggPlayer != nilPointer && oggPlayer->alive != 0 ; } private: @@ -129,9 +125,6 @@ class SoundManager private: - /** - * Único objeto de esta clase para toda la aplicación - */ static SoundManager* instance ; /** diff --git a/src/activities/DisplaceKindOfActivity.cpp b/src/activities/DisplaceKindOfActivity.cpp index ddd7626e..423b1bfa 100644 --- a/src/activities/DisplaceKindOfActivity.cpp +++ b/src/activities/DisplaceKindOfActivity.cpp @@ -10,7 +10,7 @@ namespace isomot { -KindOfActivity * DisplaceKindOfActivity::instance = 0 ; +KindOfActivity * DisplaceKindOfActivity::instance = nilPointer ; DisplaceKindOfActivity::DisplaceKindOfActivity() : KindOfActivity() @@ -24,7 +24,7 @@ DisplaceKindOfActivity::~DisplaceKindOfActivity() KindOfActivity* DisplaceKindOfActivity::getInstance() { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new DisplaceKindOfActivity(); } @@ -35,20 +35,17 @@ KindOfActivity* DisplaceKindOfActivity::getInstance() bool DisplaceKindOfActivity::displace( Behavior* behavior, ActivityOfItem* activity, bool canFall ) { bool itemDisplaced = false; - FreeItem* freeItem = 0; - ActivityOfItem displaceActivity = *activity; - // Acceso al elemento que hay que mover si dicho elemento es libre - if ( behavior->getItem()->getId() & 1 ) - { - freeItem = dynamic_cast < FreeItem * > ( behavior->getItem () ); - } + // get free item to move from its behavior + FreeItem* freeItem = dynamic_cast < FreeItem * > ( behavior->getItem () ); + + ActivityOfItem displaceActivity = *activity; switch ( *activity ) { case DisplaceNorth: case ForceDisplaceNorth: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { itemDisplaced = freeItem->addToX( -1 ); } @@ -57,7 +54,7 @@ bool DisplaceKindOfActivity::displace( Behavior* behavior, ActivityOfItem* activ case DisplaceSouth: case ForceDisplaceSouth: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { itemDisplaced = freeItem->addToX( 1 ); } @@ -66,7 +63,7 @@ bool DisplaceKindOfActivity::displace( Behavior* behavior, ActivityOfItem* activ case DisplaceEast: case ForceDisplaceEast: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { itemDisplaced = freeItem->addToY( -1 ); } @@ -75,7 +72,7 @@ bool DisplaceKindOfActivity::displace( Behavior* behavior, ActivityOfItem* activ case DisplaceWest: case ForceDisplaceWest: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { itemDisplaced = freeItem->addToY( 1 ); } @@ -83,28 +80,28 @@ bool DisplaceKindOfActivity::displace( Behavior* behavior, ActivityOfItem* activ break; case DisplaceNortheast: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { itemDisplaced = freeItem->addToPosition( -1, -1, 0 ); } break; case DisplaceNorthwest: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { itemDisplaced = freeItem->addToPosition( -1, 1, 0 ); } break; case DisplaceSoutheast: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { itemDisplaced = freeItem->addToPosition( 1, -1, 0 ); } break; case DisplaceSouthwest: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { itemDisplaced = freeItem->addToPosition( 1, 1, 0 ); } @@ -118,24 +115,25 @@ bool DisplaceKindOfActivity::displace( Behavior* behavior, ActivityOfItem* activ ; } - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { - // En caso de colisión en los ejes X o Y se desplaza a los elementos implicados + // when there’s collision if ( ! itemDisplaced ) { + // move involved items this->propagateActivityToAdjacentItems( freeItem, displaceActivity ); } - // En caso de que el elemento se haya movido se comprueba si hay que desplazar los elementos - // que pueda tener encima else { + // look if items on top of this item needs to move too this->propagateActivityToItemsAbove( freeItem, *activity ); } } - // Si el elemento puede caer entonces se comprueba si hay que cambiar el estado + // when item can fall if ( canFall ) { + // look if it falls yet if ( FallKindOfActivity::getInstance()->fall( behavior ) ) { behavior->changeActivityTo( FallKindOfActivity::getInstance() ); diff --git a/src/activities/DisplaceKindOfActivity.hpp b/src/activities/DisplaceKindOfActivity.hpp index 4ea8deab..ee9d760d 100644 --- a/src/activities/DisplaceKindOfActivity.hpp +++ b/src/activities/DisplaceKindOfActivity.hpp @@ -20,9 +20,6 @@ namespace isomot class Behavior ; -/** - * Desplazamiento de un elemento - */ class DisplaceKindOfActivity : public KindOfActivity { @@ -35,26 +32,18 @@ class DisplaceKindOfActivity : public KindOfActivity virtual ~DisplaceKindOfActivity( ) ; - /** - * Único objeto de esta clase para toda la aplicación - * @return Un puntero a la clase madre para hacer uso del polimorfismo de clase - */ static KindOfActivity * getInstance() ; /** - * Estado que desplaza a un elemento - * @param behavior Comportamiento usuario del estado de desplazamiento - * @param canFall Indica si el elemento puede caer. Si se dan las condiciones para la caída - * se producirá el cambio de estado correspondiente - * @return true si se produjo el desplazamiento o el cambio de estado; o, false si hubo colisión + * Displace item + * @param behavior Behavior of item + * @param canFall true if item falls, false if it flies + * @return true when item displaced or changed activity, false when there’s collision */ virtual bool displace ( Behavior * behavior, ActivityOfItem * activity, bool canFall ) ; private: - /** - * Único objeto de esta clase para toda la aplicación - */ static KindOfActivity * instance ; }; diff --git a/src/activities/FallKindOfActivity.cpp b/src/activities/FallKindOfActivity.cpp index 9627bca0..958aa916 100644 --- a/src/activities/FallKindOfActivity.cpp +++ b/src/activities/FallKindOfActivity.cpp @@ -12,7 +12,7 @@ namespace isomot { -KindOfActivity * FallKindOfActivity::instance = 0; +KindOfActivity * FallKindOfActivity::instance = nilPointer ; FallKindOfActivity::FallKindOfActivity( ) : KindOfActivity() { @@ -26,7 +26,7 @@ FallKindOfActivity::~FallKindOfActivity( ) KindOfActivity* FallKindOfActivity::getInstance() { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new FallKindOfActivity(); } @@ -64,7 +64,7 @@ bool FallKindOfActivity::fall( Behavior * behavior ) { Item* item = mediator->findItemById( id ); - if ( item != 0 ) + if ( item != nilPointer ) { if ( dynamic_cast< PlayerItem * >( item ) && sender->isMortal() ) { @@ -141,7 +141,7 @@ bool FallKindOfActivity::fall( Behavior * behavior ) void FallKindOfActivity::assignAnchor( FreeItem* freeItem, std::stack< int > items ) { - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { Mediator* mediator = freeItem->getMediator(); @@ -154,7 +154,7 @@ void FallKindOfActivity::assignAnchor( FreeItem* freeItem, std::stack< int > ite // harmless item before mortal item // item with higher spatial coordinates - Item* anchor = 0; + Item* anchor = nilPointer; Item* oldAnchor = freeItem->getAnchor(); // search for anchor of this item @@ -166,7 +166,7 @@ void FallKindOfActivity::assignAnchor( FreeItem* freeItem, std::stack< int > ite count++ ; // in case when item is already anchored - if ( oldAnchor != 0 && item != 0 && oldAnchor->getId() == item->getId() ) + if ( oldAnchor != nilPointer && item != nilPointer && oldAnchor->getId() == item->getId() ) { anchor = oldAnchor; break; @@ -214,7 +214,7 @@ void FallKindOfActivity::assignAnchor( FreeItem* freeItem, std::stack< int > ite freeItem->setAnchor( anchor ); - /* if ( anchor != 0 && anchor != oldAnchor ) + /* if ( anchor != nilPointer && anchor != oldAnchor ) { std::cout << "item \"" << anchor->getLabel() << "\" at" << " x=" << anchor->getX() << " y=" << anchor->getY() << " z=" << anchor->getZ() << diff --git a/src/activities/FallKindOfActivity.hpp b/src/activities/FallKindOfActivity.hpp index d14718c5..44f6feca 100644 --- a/src/activities/FallKindOfActivity.hpp +++ b/src/activities/FallKindOfActivity.hpp @@ -51,9 +51,6 @@ class FallKindOfActivity : public KindOfActivity private: - /** - * Único objeto de esta clase para toda la aplicación - */ static KindOfActivity * instance ; }; diff --git a/src/activities/JumpKindOfActivity.cpp b/src/activities/JumpKindOfActivity.cpp index 408001ad..cc6295e7 100644 --- a/src/activities/JumpKindOfActivity.cpp +++ b/src/activities/JumpKindOfActivity.cpp @@ -12,7 +12,7 @@ namespace isomot { -KindOfActivity * JumpKindOfActivity::instance = 0; +KindOfActivity * JumpKindOfActivity::instance = nilPointer ; JumpKindOfActivity::JumpKindOfActivity( ) : KindOfActivity() { @@ -26,7 +26,7 @@ JumpKindOfActivity::~JumpKindOfActivity( ) KindOfActivity* JumpKindOfActivity::getInstance() { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new JumpKindOfActivity(); } @@ -59,7 +59,7 @@ bool JumpKindOfActivity::jump( Behavior* behavior, ActivityOfItem* activity, con { Item* item = mediator->findItemById( id ); - if ( item != 0 ) + if ( item != nilPointer ) { // mortal thing is above if ( item->isMortal() && ! playerItem->hasShield() ) @@ -74,7 +74,7 @@ bool JumpKindOfActivity::jump( Behavior* behavior, ActivityOfItem* activity, con FreeItem* freeItem = dynamic_cast< FreeItem * >( item ); // non mortal free item - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { // raise items recursively lift( playerItem, freeItem, deltaZ - ( jumpPhase > 0 && jumpPhase % 2 == 0 ? 1 : 2 ) ); @@ -140,7 +140,7 @@ bool JumpKindOfActivity::jump( Behavior* behavior, ActivityOfItem* activity, con void JumpKindOfActivity::lift( FreeItem* sender, FreeItem* freeItem, int z ) { // only for item with behavior - if ( freeItem->getBehavior() != 0 ) + if ( freeItem->getBehavior() != nilPointer ) { // when item is volatile if ( freeItem->getBehavior()->getNameOfBehavior () == "behavior of disappearance on touch" || @@ -160,7 +160,7 @@ void JumpKindOfActivity::lift( FreeItem* sender, FreeItem* freeItem, int z ) { FreeItem* topItem = dynamic_cast< FreeItem * >( mediator->findCollisionPop( ) ); - if ( topItem != 0 ) + if ( topItem != nilPointer ) { // raise free items recursively lift( sender, topItem, z ); diff --git a/src/activities/JumpKindOfActivity.hpp b/src/activities/JumpKindOfActivity.hpp index 56bc7de9..383fb316 100644 --- a/src/activities/JumpKindOfActivity.hpp +++ b/src/activities/JumpKindOfActivity.hpp @@ -37,10 +37,6 @@ class JumpKindOfActivity : public KindOfActivity virtual ~JumpKindOfActivity(); - /** - * Único objeto de esta clase para toda la aplicación - * @return Un puntero a la clase madre para hacer uso del polimorfismo de clase - */ static KindOfActivity * getInstance() ; /** @@ -64,9 +60,6 @@ class JumpKindOfActivity : public KindOfActivity private: - /** - * Único objeto de esta clase para toda la aplicación - */ static KindOfActivity * instance ; }; diff --git a/src/activities/KindOfActivity.cpp b/src/activities/KindOfActivity.cpp index 178dab63..c38e16fe 100644 --- a/src/activities/KindOfActivity.cpp +++ b/src/activities/KindOfActivity.cpp @@ -37,10 +37,10 @@ void KindOfActivity::propagateActivityToAdjacentItems( Item * sender, const Acti { Item * itemMeetsSender = mediator->findItemById( id ); - if ( itemMeetsSender != 0 ) + if ( itemMeetsSender != nilPointer ) { // is it item with behavior - if ( itemMeetsSender->getBehavior() != 0 ) + if ( itemMeetsSender->getBehavior() != nilPointer ) { // if it’s player item and sender is mortal, then player loses its life if ( dynamic_cast< PlayerItem * >( itemMeetsSender ) && sender->isMortal() && @@ -203,7 +203,7 @@ void KindOfActivity::propagateActivityToItemsAbove( Item * sender, const Activit FreeItem* freeItemAbove = dynamic_cast< FreeItem * >( mediator->findItemById( id ) ); // is it item with behavior - if ( freeItemAbove != 0 && freeItemAbove->getBehavior() != 0 ) + if ( freeItemAbove != nilPointer && freeItemAbove->getBehavior() != nilPointer ) { // look for collisions of that free item with items below it if ( ! freeItemAbove->checkPosition( 0, 0, -1, Add ) ) diff --git a/src/activities/MoveKindOfActivity.cpp b/src/activities/MoveKindOfActivity.cpp index 94478560..0be76eea 100644 --- a/src/activities/MoveKindOfActivity.cpp +++ b/src/activities/MoveKindOfActivity.cpp @@ -14,20 +14,11 @@ namespace isomot { -KindOfActivity * MoveKindOfActivity::instance = 0 ; - - -MoveKindOfActivity::MoveKindOfActivity( ) : KindOfActivity() -{ - -} - -MoveKindOfActivity::~MoveKindOfActivity( ) { } - +KindOfActivity * MoveKindOfActivity::instance = nilPointer ; KindOfActivity* MoveKindOfActivity::getInstance() { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new MoveKindOfActivity(); } @@ -35,14 +26,21 @@ KindOfActivity* MoveKindOfActivity::getInstance() return instance; } +MoveKindOfActivity::MoveKindOfActivity( ) : KindOfActivity() +{ + +} + +MoveKindOfActivity::~MoveKindOfActivity( ) { } + bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, bool canFall ) { bool moved = false; ActivityOfItem displaceActivity = Wait; - FreeItem* freeItem = 0; - Mediator* mediator = 0; + FreeItem* freeItem = nilPointer; + Mediator* mediator = nilPointer; // is item free or player if ( behavior->getItem()->whichKindOfItem() == "free item" || behavior->getItem()->whichKindOfItem() == "player item" ) @@ -55,7 +53,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo { case MoveNorth: case AutoMoveNorth: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { freeItem->changeOrientation( North ); moved = freeItem->addToX( -1 ); @@ -65,7 +63,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo case MoveSouth: case AutoMoveSouth: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { freeItem->changeOrientation( South ); moved = freeItem->addToX( 1 ); @@ -75,7 +73,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo case MoveEast: case AutoMoveEast: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { freeItem->changeOrientation( East ); moved = freeItem->addToY( -1 ); @@ -85,7 +83,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo case MoveWest: case AutoMoveWest: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { freeItem->changeOrientation( West ); moved = freeItem->addToY( 1 ); @@ -94,7 +92,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo break; case MoveNortheast: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { moved = freeItem->addToPosition( -1, -1, 0 ); displaceActivity = DisplaceNortheast; @@ -102,7 +100,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo break; case MoveNorthwest: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { moved = freeItem->addToPosition( -1, 1, 0 ); displaceActivity = DisplaceNorthwest; @@ -110,7 +108,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo break; case MoveSoutheast: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { moved = freeItem->addToPosition( 1, -1, 0 ); displaceActivity = DisplaceSoutheast; @@ -118,7 +116,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo break; case MoveSouthwest: - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { moved = freeItem->addToPosition( 1, 1, 0 ); displaceActivity = DisplaceSouthwest; @@ -135,7 +133,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo { FreeItem* topItem = dynamic_cast< FreeItem * >( mediator->findCollisionPop( ) ); - if ( topItem != 0 && freeItem->getWidthX() + freeItem->getWidthY() >= topItem->getWidthX() + topItem->getWidthY() ) + if ( topItem != nilPointer && freeItem->getWidthX() + freeItem->getWidthY() >= topItem->getWidthX() + topItem->getWidthY() ) { ascent( topItem, 1 ); } @@ -168,7 +166,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo FreeItem* topItem = dynamic_cast< FreeItem * >( mediator->findItemById( topItems.top() ) ); topItems.pop(); - if ( topItem != 0 ) + if ( topItem != nilPointer ) { descend( topItem, 2 ); } @@ -197,7 +195,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo ; } - if ( freeItem != 0 ) + if ( freeItem != nilPointer ) { // move collided items when there’s horizontal collision if ( ! moved ) @@ -213,7 +211,7 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo } // item may fall - if ( canFall && *activity ) + if ( canFall && *activity != Wait ) { if ( FallKindOfActivity::getInstance()->fall( behavior ) ) { @@ -228,40 +226,41 @@ bool MoveKindOfActivity::move( Behavior* behavior, ActivityOfItem* activity, boo void MoveKindOfActivity::ascent( FreeItem* freeItem, int z ) { - // El elemento debe poder cambiar de estado - if ( freeItem->getBehavior() != 0 ) + if ( freeItem->getBehavior() != nilPointer ) { - // Si el elemento no es el ascensor entonces se levanta + // don’t ascent elevator if ( freeItem->getBehavior()->getNameOfBehavior () != "behavior of elevator" ) { - // Si no se puede levantar, se toma el elemento con el que choca para levantarlo + // when there’s something above this item + // then raise every not bigger free item above if ( ! freeItem->addToZ( z ) ) { Mediator* mediator = freeItem->getMediator(); - // Para todo elemento que pueda tener encima while ( ! mediator->isStackOfCollisionsEmpty() ) { FreeItem* topItem = dynamic_cast< FreeItem * >( mediator->findCollisionPop( ) ); - if ( topItem != 0 && freeItem->getWidthX() + freeItem->getWidthY() >= topItem->getWidthX() + topItem->getWidthY() ) + if ( topItem != nilPointer && + freeItem->getWidthX() + freeItem->getWidthY() >= topItem->getWidthX() + topItem->getWidthY() ) { - // Levanta recursivamente a todos los elementos + // raise recursively ascent( topItem, z ); } } - // Ahora ya puede ascender + // yet it can ascend freeItem->addToZ( z ); } - // Si el elemento es un jugador y supera la altura máxima de la sala entonces pasa a - // la sala de arriba. Se supone que no hay posibilidad de alcanzar la altura máxima - // de una sala que no conduce a otra situada sobre ella - PlayerItem* playerItem = dynamic_cast< PlayerItem * >( freeItem ); - if ( playerItem != 0 && playerItem->getZ() >= MaxLayers * LayerHeight ) - { - playerItem->setWayOfExit( Up ); + if ( freeItem->whichKindOfItem() == "player item" ) + { // when item is player + PlayerItem* playerItem = dynamic_cast< PlayerItem * >( freeItem ); + if ( playerItem->getZ() >= MaxLayers * LayerHeight ) + { + // player reaches maximum height of room to possibly go to room above it + playerItem->setWayOfExit( Up ); + } } } } @@ -269,40 +268,38 @@ void MoveKindOfActivity::ascent( FreeItem* freeItem, int z ) void MoveKindOfActivity::descend( FreeItem* freeItem, int z ) { - // El elemento debe poder cambiar de estado - if ( freeItem->getBehavior() != 0 ) + if ( freeItem->getBehavior() != nilPointer ) { - Mediator* mediator = freeItem->getMediator(); - - // Comprueba si tiene elementos encima + // are there items on top bool loading = ! freeItem->checkPosition( 0, 0, z, Add ); - // Copia la pila de colisiones - std::stack< int > topItems; - while ( ! mediator->isStackOfCollisionsEmpty() ) - { - topItems.push( mediator->popCollision() ); - } - - // Si puede descender entonces hace bajar a todos los elementos apilados encima + // if item may descend itself then lower every item above it if ( freeItem->addToZ( -1 ) && loading ) { - // Desciende el resto de unidades. Se hace de una en una porque de lo contrario - // se podría detectar colisión y no descendería ninguna unidad + Mediator* mediator = freeItem->getMediator(); + + // make copy of stack of collisions + std::stack< int > topItems; + while ( ! mediator->isStackOfCollisionsEmpty() ) + { + topItems.push( mediator->popCollision() ); + } + + // descend by one at a time, otherwise there may be collision which hinders descend for ( int i = 0; i < ( z - 1 ); i++ ) { freeItem->addToZ( -1 ); } - // Para todo elemento que pueda tener encima + // for each item above while ( ! mediator->isStackOfCollisionsEmpty() ) { FreeItem* topItem = dynamic_cast< FreeItem * >( mediator->findItemById( topItems.top() ) ); topItems.pop(); - if ( topItem != 0 ) + if ( topItem != nilPointer ) { - // Desciende recursivamente a todos los elementos + // lower recursively descend( topItem, z ); } } diff --git a/src/activities/MoveKindOfActivity.hpp b/src/activities/MoveKindOfActivity.hpp index 63d1f9c4..bd039668 100644 --- a/src/activities/MoveKindOfActivity.hpp +++ b/src/activities/MoveKindOfActivity.hpp @@ -21,9 +21,6 @@ namespace isomot class Behavior ; class FreeItem ; -/** - * Movimiento de un elemento - */ class MoveKindOfActivity : public KindOfActivity { @@ -36,43 +33,35 @@ class MoveKindOfActivity : public KindOfActivity virtual ~MoveKindOfActivity( ) ; - /** - * Único objeto de esta clase para toda la aplicación - * @return Un puntero a la clase madre para hacer uso del polimorfismo de clase - */ static KindOfActivity * getInstance () ; /** - * Estado que mueve a un elemento - * @param behavior Comportamiento usuario del estado de movimiento + * Move item + * @param behavior Behavior of item * @param activity Way of movement - * @param canFall Indica si el elemento puede caer. Si se dan las condiciones para la caída - * se producirá el cambio de estado correspondiente - * @return true si se produjo el movimiento o el cambio de estado; o, false si hubo colisión + * @param canFall true if item falls, false if it flies + * @return when item displaced or changed activity, false when there’s collision */ virtual bool move ( Behavior * behavior, ActivityOfItem * activity, bool canFall ) ; protected: /** - * Operación recursiva que levanta todos los elementos apilados sobre un elemento - * @param freeItem Primer elemento de la pila - * @param z Unidades que ascenderá la pila de elementos + * Recursively lift items stacked on this item + * @param freeItem Currently first item + * @param z Units to ascend */ void ascent ( FreeItem * freeItem, int z ) ; /** - * Operación recursiva que hace descender todos los elementos apilados sobre un elemento - * @param freeItem Primer elemento de la pila - * @param z Unidades que descenderá la pila de elementos + * Recursively lower items stacked on this item + * @param freeItem Currently first item + * @param z Units to descend */ void descend ( FreeItem * freeItem, int z ) ; private: - /** - * Único objeto de esta clase para toda la aplicación - */ static KindOfActivity * instance ; }; diff --git a/src/behaviors/Behavior.cpp b/src/behaviors/Behavior.cpp index b206c4e7..3d19838e 100644 --- a/src/behaviors/Behavior.cpp +++ b/src/behaviors/Behavior.cpp @@ -37,9 +37,9 @@ namespace isomot Behavior::Behavior( Item * whichItem, const std::string & behavior ) : nameOfBehavior( behavior ) , item( whichItem ) - , whatToDo( 0 ) + , whatToDo( nilPointer ) , activity( Wait ) - , sender( 0 ) + , sender( nilPointer ) { if ( behavior != "behavior of Head" && behavior != "behavior of Heels" && behavior != "behavior of Head over Heels" ) { @@ -57,7 +57,7 @@ Behavior::~Behavior( ) Behavior* Behavior::createBehaviorByName( Item* item, const std::string& behavior, void* extraData ) { - Behavior* behaviorToReturn = 0; + Behavior* behaviorToReturn = nilPointer; if ( behavior == "behavior of conveyor" ) { @@ -242,7 +242,7 @@ void Behavior::propagateActivity( Item* sender, const ActivityOfItem& activity ) Item* item = mediator->findItemById( id ); // change activity for existing item with non-null behavior - if ( item != 0 && item->getBehavior() != 0 ) + if ( item != nilPointer && item->getBehavior() != nilPointer ) { item->getBehavior()->changeActivityOfItem( activity ); } diff --git a/src/behaviors/Behavior.hpp b/src/behaviors/Behavior.hpp index 11efd117..287cc5ee 100644 --- a/src/behaviors/Behavior.hpp +++ b/src/behaviors/Behavior.hpp @@ -39,7 +39,7 @@ class Behavior virtual ~Behavior( ) ; - static Behavior* createBehaviorByName ( Item* item, const std::string& behavior, void* extraData ) ; + static Behavior * createBehaviorByName ( Item * item, const std::string& behavior, void * extraData ) ; /** * Updates behavior of item in each cycle @@ -51,7 +51,7 @@ class Behavior * @param activity Activity of item * @param sender Item which changes activity */ - virtual void changeActivityOfItem ( const ActivityOfItem & activity, Item * sender = 0 ) ; + virtual void changeActivityOfItem ( const ActivityOfItem & activity, Item * sender = nilPointer ) ; /** * Change kind of activity diff --git a/src/behaviors/CannonBall.cpp b/src/behaviors/CannonBall.cpp index ba5b0e14..2a0af63c 100644 --- a/src/behaviors/CannonBall.cpp +++ b/src/behaviors/CannonBall.cpp @@ -55,7 +55,7 @@ bool CannonBall::update () Nowhere ); - bubbles->assignBehavior( "behavior of disappearance in time", 0 ); + bubbles->assignBehavior( "behavior of disappearance in time", nilPointer ); bubbles->setCollisionDetector( false ); item->getMediator()->getRoom()->addFreeItem( bubbles ); diff --git a/src/behaviors/ConveyorBelt.cpp b/src/behaviors/ConveyorBelt.cpp index 4d8b7424..f453f4af 100644 --- a/src/behaviors/ConveyorBelt.cpp +++ b/src/behaviors/ConveyorBelt.cpp @@ -58,9 +58,9 @@ bool ConveyorBelt::update () FreeItem* topItem = dynamic_cast< FreeItem * >( mediator->findItemById( top ) ); // is it item with behavior - if ( topItem != 0 && topItem->getBehavior() != 0 ) + if ( topItem != nilPointer && topItem->getBehavior() != nilPointer ) { - if ( topItem->getAnchor() == 0 || item->getId() == topItem->getAnchor()->getId() ) + if ( topItem->getAnchor() == nilPointer || item->getId() == topItem->getAnchor()->getId() ) { if ( item->getOrientation().toString() == "south" ) { if ( topItem->getBehavior()->getActivityOfItem() != RegularJump && topItem->getBehavior()->getActivityOfItem() != HighJump ) { diff --git a/src/behaviors/Detector.cpp b/src/behaviors/Detector.cpp index 587c5062..170d5f9b 100644 --- a/src/behaviors/Detector.cpp +++ b/src/behaviors/Detector.cpp @@ -35,7 +35,7 @@ bool Detector::update () PlayerItem* playerItem = freeItem->getMediator()->getActivePlayer(); bool isGone = false; - if ( playerItem != 0 ) + if ( playerItem != nilPointer ) { switch ( activity ) { diff --git a/src/behaviors/Hunter.cpp b/src/behaviors/Hunter.cpp index ca35d4f8..a4d995ee 100644 --- a/src/behaviors/Hunter.cpp +++ b/src/behaviors/Hunter.cpp @@ -51,7 +51,7 @@ bool Hunter::update () const unsigned int sizeOfRectangleInTiles = 3; const int delta = mediator->getRoom()->getSizeOfOneTile() * sizeOfRectangleInTiles; - if ( activePlayer != 0 && + if ( activePlayer != nilPointer && activePlayer->getX() > thisItem->getX() - delta && activePlayer->getX() < thisItem->getX() + static_cast< int >( thisItem->getWidthX() ) + delta && activePlayer->getY() > thisItem->getY() - delta && @@ -220,7 +220,7 @@ ActivityOfItem Hunter::calculateDirection4( const ActivityOfItem& activity ) FreeItem* thisItem = dynamic_cast< FreeItem * >( this->item ); PlayerItem* activePlayer = thisItem->getMediator()->getActivePlayer(); - if ( activePlayer != 0 ) // if there’s active player in room + if ( activePlayer != nilPointer ) // if there’s active player in room { int dx = thisItem->getX() - activePlayer->getX(); int dy = thisItem->getY() - activePlayer->getY(); @@ -271,7 +271,7 @@ ActivityOfItem Hunter::calculateDirection8( const ActivityOfItem& activity ) FreeItem* thisItem = dynamic_cast< FreeItem* >( this->item ); PlayerItem* activePlayer = thisItem->getMediator()->getActivePlayer(); - if ( activePlayer != 0 ) // if there’s active player in room + if ( activePlayer != nilPointer ) // if there’s active player in room { int dx = thisItem->getX() - activePlayer->getX(); int dy = thisItem->getY() - activePlayer->getY(); @@ -360,7 +360,7 @@ bool Hunter::createFullBody() thisItem->getX(), thisItem->getY(), thisItem->getZ() - LayerHeight, thisItem->getOrientation() ); - newItem->assignBehavior( "behavior of hunter in four directions", 0 ); + newItem->assignBehavior( "behavior of hunter in four directions", nilPointer ); // switch off collisions for this item // otherwise it’s impossible to create full-bodied guard diff --git a/src/behaviors/Mobile.cpp b/src/behaviors/Mobile.cpp index f1dc56c5..30945df4 100644 --- a/src/behaviors/Mobile.cpp +++ b/src/behaviors/Mobile.cpp @@ -58,7 +58,7 @@ bool Mobile::update () // Emite el sonido de de desplazamiento si está siendo empujado, no desplazado // por un elemento que haya debajo // TODO Hecho para portátiles y para Carlos ¿aplica a otros elementos? - if ( this->sender == 0 || ( this->sender != 0 && this->sender != this->item ) ) + if ( this->sender == nilPointer || ( this->sender != nilPointer && this->sender != this->item ) ) { SoundManager::getInstance()->play( freeItem->getLabel(), activity ); } diff --git a/src/behaviors/PlayerHead.cpp b/src/behaviors/PlayerHead.cpp index 3544ba2f..3057f1ba 100644 --- a/src/behaviors/PlayerHead.cpp +++ b/src/behaviors/PlayerHead.cpp @@ -21,14 +21,14 @@ PlayerHead::PlayerHead( Item* item, const std::string& behavior ) : highJumpFrames = 19; // salto normal - for ( int i = 0; i < jumpFrames; i++ ) + for ( unsigned int i = 0; i < jumpFrames; i++ ) { JumpMotion jumpMotion( 1, 3 ); jumpVector.push_back( jumpMotion ); } // salto largo - for ( int i = 0; i < highJumpFrames; i++ ) + for ( unsigned int i = 0; i < highJumpFrames; i++ ) { JumpMotion jumpMotion( 1, 4 ); highJumpVector.push_back( jumpMotion ); @@ -73,10 +73,6 @@ PlayerHead::PlayerHead( Item* item, const std::string& behavior ) : PlayerHead::~PlayerHead( ) { - delete speedTimer; - delete fallTimer; - delete glideTimer; - delete blinkingTimer; } bool PlayerHead::update () diff --git a/src/behaviors/PlayerHeadAndHeels.cpp b/src/behaviors/PlayerHeadAndHeels.cpp index 875c9d5f..34bd34c3 100644 --- a/src/behaviors/PlayerHeadAndHeels.cpp +++ b/src/behaviors/PlayerHeadAndHeels.cpp @@ -19,14 +19,14 @@ PlayerHeadAndHeels::PlayerHeadAndHeels( Item * item, const std::string & behavio highJumpFrames = 28; // salto normal - for ( int i = 0; i < jumpFrames; i++ ) + for ( unsigned int i = 0; i < jumpFrames; i++ ) { JumpMotion jumpMotion( 1, ( i < 4 ? 4 : ( i < 8 ? 3 : 2 ) ) ); jumpVector.push_back( jumpMotion ); } // salto largo - for ( int i = 0; i < highJumpFrames; i++ ) + for ( unsigned int i = 0; i < highJumpFrames; i++ ) { JumpMotion jumpMotion( 1, 3 ); highJumpVector.push_back( jumpMotion ); @@ -58,12 +58,12 @@ PlayerHeadAndHeels::PlayerHeadAndHeels( Item * item, const std::string & behavio // create and activate chronometers speedTimer = new Timer(); - fallTimer = new Timer(); - glideTimer = new Timer(); - blinkingTimer = new Timer(); speedTimer->go(); + fallTimer = new Timer(); fallTimer->go(); + glideTimer = new Timer(); glideTimer->go(); + blinkingTimer = new Timer(); blinkingTimer->go(); fireFromHooterIsPresent = false; @@ -71,10 +71,6 @@ PlayerHeadAndHeels::PlayerHeadAndHeels( Item * item, const std::string & behavio PlayerHeadAndHeels::~PlayerHeadAndHeels( ) { - delete speedTimer; - delete fallTimer; - delete glideTimer; - delete blinkingTimer; } bool PlayerHeadAndHeels::update () @@ -212,12 +208,12 @@ void PlayerHeadAndHeels::behave () } else if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } else if ( input->takeAndJump() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeAndJump : DropAndJump ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeAndJump : DropAndJump ); input->noRepeat( "take&jump" ); } else if ( input->movenorth() && ! input->movesouth() && ! input->moveeast() && ! input->movewest() ) @@ -253,12 +249,12 @@ void PlayerHeadAndHeels::behave () } else if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } else if ( input->takeAndJump() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeAndJump : DropAndJump ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeAndJump : DropAndJump ); input->noRepeat( "take&jump" ); } else if ( input->movenorth() && ! input->movesouth() && ! input->moveeast() && ! input->movewest() ) @@ -297,12 +293,12 @@ void PlayerHeadAndHeels::behave () } else if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } else if ( input->takeAndJump() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeAndJump : DropAndJump ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeAndJump : DropAndJump ); input->noRepeat( "take&jump" ); } else if ( input->movenorth() && ! input->movesouth() && ! input->moveeast() && ! input->movewest() ) @@ -381,7 +377,7 @@ void PlayerHeadAndHeels::behave () // pick or drop an item when falling else if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } // entonces Head y Heels planean @@ -404,7 +400,7 @@ void PlayerHeadAndHeels::behave () // pick or drop an item when gliding else if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } else if ( input->movenorth() && ! input->movesouth() && ! input->moveeast() && ! input->movewest() ) diff --git a/src/behaviors/PlayerHeels.cpp b/src/behaviors/PlayerHeels.cpp index 6ec4371b..61ab9501 100644 --- a/src/behaviors/PlayerHeels.cpp +++ b/src/behaviors/PlayerHeels.cpp @@ -18,14 +18,14 @@ PlayerHeels::PlayerHeels( Item* item, const std::string& behavior ) : highJumpFrames = 21; // salto normal - for ( int i = 0; i < jumpFrames; i++ ) + for ( unsigned int i = 0; i < jumpFrames; i++ ) { JumpMotion jumpMotion( i == 9 || i == 19 ? 2 : 1 , ( i < jumpFrames / 2 ) ? 3 : -3 ); jumpVector.push_back( jumpMotion ); } // salto largo - for ( int i = 0; i < highJumpFrames; i++ ) + for ( unsigned int i = 0; i < highJumpFrames; i++ ) { JumpMotion jumpMotion( 2 , ( i < 17 ) ? 3 : -3 ); highJumpVector.push_back( jumpMotion ); @@ -58,8 +58,6 @@ PlayerHeels::PlayerHeels( Item* item, const std::string& behavior ) : PlayerHeels::~PlayerHeels( ) { - delete speedTimer; - delete fallTimer; } bool PlayerHeels::update() @@ -178,12 +176,12 @@ void PlayerHeels::behave () { if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } else if ( input->takeAndJump() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeAndJump : DropAndJump ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeAndJump : DropAndJump ); input->noRepeat( "take&jump" ); } else if ( input->movenorth() && ! input->movesouth() && ! input->moveeast() && ! input->movewest() ) @@ -221,12 +219,12 @@ void PlayerHeels::behave () } else if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } else if ( input->takeAndJump() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeAndJump : DropAndJump ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeAndJump : DropAndJump ); input->noRepeat( "take&jump" ); } else if ( input->movenorth() && ! input->movesouth() && ! input->moveeast() && ! input->movewest() ) @@ -260,12 +258,12 @@ void PlayerHeels::behave () } else if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } else if ( input->takeAndJump() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeAndJump : DropAndJump ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeAndJump : DropAndJump ); input->noRepeat( "take&jump" ); } else if ( input->movenorth() && ! input->movesouth() && ! input->moveeast() && ! input->movewest() ) @@ -320,7 +318,7 @@ void PlayerHeels::behave () // pick or drop an item when falling if ( input->take() ) { - activity = ( playerItem->getTakenItemData() == 0 ? TakeItem : DropItem ); + activity = ( playerItem->getTakenItemData() == nilPointer ? TakeItem : DropItem ); input->noRepeat( "take" ); } } diff --git a/src/behaviors/RemoteControl.cpp b/src/behaviors/RemoteControl.cpp index 681355de..a3365a57 100644 --- a/src/behaviors/RemoteControl.cpp +++ b/src/behaviors/RemoteControl.cpp @@ -16,7 +16,7 @@ RemoteControl::RemoteControl( Item * item, const std::string & behavior ) : Behavior( item, behavior ) { activity = Wait; - controlledItem = 0; + controlledItem = nilPointer; // move controlled one but not controller if ( getNameOfBehavior() == "behavior of remotely controlled one" ) @@ -43,7 +43,7 @@ bool RemoteControl::update () bool vanish = false; // get controlled item - if ( getNameOfBehavior() == "behavior of remote control" && controlledItem == 0 ) + if ( getNameOfBehavior() == "behavior of remote control" && controlledItem == nilPointer ) { controlledItem = static_cast< FreeItem * >( freeItem->getMediator()->findItemByBehavior( "behavior of remotely controlled one" ) ); } @@ -90,7 +90,7 @@ bool RemoteControl::update () { // Emite el sonido de de desplazamiento si está siendo empujado, no desplazado // por un elemento que haya debajo - if ( this->sender == 0 || ( this->sender != 0 && this->sender != this->item ) ) + if ( this->sender == nilPointer || ( this->sender != nilPointer && this->sender != this->item ) ) { SoundManager::getInstance()->play( freeItem->getLabel(), activity ); } diff --git a/src/behaviors/Special.cpp b/src/behaviors/Special.cpp index 4245ff94..9b89c0ec 100644 --- a/src/behaviors/Special.cpp +++ b/src/behaviors/Special.cpp @@ -57,9 +57,9 @@ bool Special::update () // but when it’s on several items then look if all these items are also special or volatile if ( mediator->depthOfStackOfCollisions() > 1 ) { - takeIt = ( mediator->collisionWithByBehavior( "behavior of something special" ) == 0 ) && - ( mediator->collisionWithByBehavior( "behavior of disappearance on jump into" ) == 0 ) && - ( mediator->collisionWithByBehavior( "behavior of disappearance on touch" ) == 0 ) ; + takeIt = ( mediator->collisionWithByBehavior( "behavior of something special" ) == nilPointer ) && + ( mediator->collisionWithByBehavior( "behavior of disappearance on jump into" ) == nilPointer ) && + ( mediator->collisionWithByBehavior( "behavior of disappearance on touch" ) == nilPointer ) ; } // disappear on take @@ -186,7 +186,7 @@ bool Special::update () // create item "bubbles" in the place of magic item FreeItem* bubbles = new FreeItem( bubblesData, item->getX(), item->getY(), item->getZ(), Nowhere ); - bubbles->assignBehavior( "behavior of disappearance in time", 0 ); + bubbles->assignBehavior( "behavior of disappearance in time", nilPointer ); bubbles->setCollisionDetector( false ); // add to current room diff --git a/src/behaviors/Switch.cpp b/src/behaviors/Switch.cpp index b7f5eb88..5ec73c33 100644 --- a/src/behaviors/Switch.cpp +++ b/src/behaviors/Switch.cpp @@ -77,7 +77,7 @@ bool Switch::update () Item* itemAbove = mediator->findItemById( id ); // yep, switch doesn’t toggle when player jumps - if ( itemAbove != 0 && itemAbove->getBehavior() != 0 && + if ( itemAbove != nilPointer && itemAbove->getBehavior() != nilPointer && ! itemAbove->checkPosition( 0, 0, -1, Add ) && itemAbove->getBehavior()->getActivityOfItem() != RegularJump && itemAbove->getBehavior()->getActivityOfItem() != HighJump ) diff --git a/src/behaviors/Teleport.cpp b/src/behaviors/Teleport.cpp index 0ee581b8..115dbc09 100644 --- a/src/behaviors/Teleport.cpp +++ b/src/behaviors/Teleport.cpp @@ -52,7 +52,7 @@ bool Teleport::update () Item * topItem = mediator->findItemById( id ); // El elemento debe tener comportamiento - if ( topItem != 0 && topItem->getBehavior() != 0 ) + if ( topItem != nilPointer && topItem->getBehavior() != nilPointer ) { // Si debajo del elemento que está encima del elemento superior hay más elementos, // se busca cuál de estos últimos tiene unas coordenadas espaciales mayores @@ -65,7 +65,7 @@ bool Teleport::update () { Item * downItem = mediator->findCollisionPop( ); - if ( downItem != 0 && item != downItem && item->getX() + item->getY() < item->getX() + item->getY() ) + if ( downItem != nilPointer && item != downItem && item->getX() + item->getY() < item->getX() + item->getY() ) { closerItem = false; } diff --git a/src/behaviors/UserControlled.cpp b/src/behaviors/UserControlled.cpp index 53527c46..9a52a4a3 100644 --- a/src/behaviors/UserControlled.cpp +++ b/src/behaviors/UserControlled.cpp @@ -27,10 +27,10 @@ UserControlled::UserControlled( Item * item, const std::string & behavior ) , automaticStepsThruDoor( 0 ) , highSpeedSteps( 0 ) , shieldSteps( 0 ) - , speedTimer( 0 ) - , fallTimer( 0 ) - , glideTimer( 0 ) - , blinkingTimer( 0 ) + , speedTimer( nilPointer ) + , fallTimer( nilPointer ) + , glideTimer( nilPointer ) + , blinkingTimer( nilPointer ) { fallFrames[ North ] = fallFrames[ South ] = fallFrames[ East ] = fallFrames[ West ] = 0xffffffff; // wtf is this magic mask for ? } @@ -39,6 +39,11 @@ UserControlled::~UserControlled() { jumpVector.clear(); highJumpVector.clear(); + + delete speedTimer; + delete fallTimer; + delete glideTimer; + delete blinkingTimer; } void UserControlled::changeActivityOfItem( const ActivityOfItem & activityOf, Item * sender ) @@ -479,7 +484,7 @@ void UserControlled::useHooter( PlayerItem* player ) ItemData* hooterData = this->itemDataManager->findItemByLabel( labelOfFireFromHooter ); - if ( hooterData != 0 ) + if ( hooterData != nilPointer ) { SoundManager::getInstance()->stop( player->getLabel(), Doughnut ); @@ -493,7 +498,7 @@ void UserControlled::useHooter( PlayerItem* player ) player->getOrientation() ); - freeItem->assignBehavior( "behavior of freezing doughnut", 0 ); + freeItem->assignBehavior( "behavior of freezing doughnut", nilPointer ); FireDoughnut * doughnutBehavior = dynamic_cast< FireDoughnut * >( freeItem->getBehavior() ); doughnutBehavior->setPlayerItem( player ); @@ -514,7 +519,7 @@ void UserControlled::takeItem( PlayerItem * player ) if ( player->hasTool( "handbag" ) ) { Mediator* mediator = player->getMediator(); - Item* takenItem = 0; + Item* takenItem = nilPointer; // look for item below player if ( ! player->checkPosition( 0, 0, -1, Add ) ) @@ -526,7 +531,7 @@ void UserControlled::takeItem( PlayerItem * player ) Item* bottomItem = mediator->findCollisionPop( ); // choose free pushable item less than or equal to 3/4 of size of one tile - if ( bottomItem != 0 && bottomItem->getBehavior() != 0 + if ( bottomItem != nilPointer && bottomItem->getBehavior() != nilPointer && ( bottomItem->getBehavior()->getNameOfBehavior() == "behavior of thing able to move by pushing" || bottomItem->getBehavior()->getNameOfBehavior() == "behavior of big leap for player" ) && bottomItem->getWidthX() <= ( mediator->getRoom()->getSizeOfOneTile() * 3 ) >> 2 @@ -541,7 +546,7 @@ void UserControlled::takeItem( PlayerItem * player ) } // take that item - if ( takenItem != 0 ) + if ( takenItem != nilPointer ) { // get image of that item BITMAP* takenItemImage = takenItem->getRawImage(); @@ -569,7 +574,7 @@ void UserControlled::takeItem( PlayerItem * player ) void UserControlled::dropItem( PlayerItem* player ) { - if ( player->getTakenItemData() != 0 ) + if ( player->getTakenItemData() != nilPointer ) { std::cout << "drop item \"" << player->getTakenItemData()->getLabel() << "\"" << std::endl ; @@ -581,16 +586,16 @@ void UserControlled::dropItem( PlayerItem* player ) player->getZ() - LayerHeight, Nowhere ); - freeItem->assignBehavior( player->getTakenItemBehavior(), 0 ); + freeItem->assignBehavior( player->getTakenItemBehavior(), nilPointer ); player->getMediator()->getRoom()->addFreeItem( freeItem ); - player->assignTakenItem( 0, 0, "still" ); + player->assignTakenItem( nilPointer, nilPointer, "still" ); // update activity activity = ( activity == DropAndJump ? Jump : Wait ); - GameManager::getInstance()->setItemTaken( 0 ); + GameManager::getInstance()->setItemTaken( nilPointer ); SoundManager::getInstance()->stop( player->getLabel(), Fall ); SoundManager::getInstance()->play( player->getLabel(), DropItem ); diff --git a/src/behaviors/UserControlled.hpp b/src/behaviors/UserControlled.hpp index f8bda78f..edddfe62 100644 --- a/src/behaviors/UserControlled.hpp +++ b/src/behaviors/UserControlled.hpp @@ -150,47 +150,47 @@ class UserControlled : public Behavior /** * Index of phase of jump */ - int jumpIndex ; + unsigned int jumpIndex ; /** * Number of phases for normal jump */ - int jumpFrames ; + unsigned int jumpFrames ; /** * Number of phases for long jump */ - int highJumpFrames ; + unsigned int highJumpFrames ; /** * Number of steps to take when character moves automatically */ - int automaticSteps ; + unsigned int automaticSteps ; /** * Number of steps that remains after entering room through door */ - int automaticStepsThruDoor ; + unsigned int automaticStepsThruDoor ; /** * Number of steps at double speed */ - int highSpeedSteps ; + unsigned int highSpeedSteps ; /** * Number of steps for character with immunity */ - int shieldSteps ; + unsigned int shieldSteps ; /** * Frames of falling, one for each of north south west east */ - int fallFrames[ 4 ] ; + unsigned int fallFrames[ 4 ] ; /** * Blank frame, used during teleportation */ - int nullFrame ; + unsigned int nullFrame ; /** * Is there a fire from hooter in room @@ -234,7 +234,7 @@ class UserControlled : public Behavior /** * Number of phases of jump */ - int getJumpFrames () const { return jumpFrames ; } + unsigned int getJumpFrames () const { return jumpFrames ; } void setFireFromHooter ( bool isHere ) { this->fireFromHooterIsPresent = isHere ; } diff --git a/src/behaviors/Volatile.cpp b/src/behaviors/Volatile.cpp index 5bbbaf1f..9696210c 100644 --- a/src/behaviors/Volatile.cpp +++ b/src/behaviors/Volatile.cpp @@ -58,7 +58,7 @@ bool Volatile::update () // when item exists, look at whether it is volatile or special // because that item would disappear unless it is leaning on another one - if ( item != 0 && item->getBehavior() != 0 && + if ( item != nilPointer && item->getBehavior() != nilPointer && item->getBehavior()->getNameOfBehavior () != "behavior of disappearance on jump into" && item->getBehavior()->getNameOfBehavior () != "behavior of slow disappearance on jump into" && item->getBehavior()->getNameOfBehavior () != "behavior of disappearance on touch" && @@ -83,18 +83,18 @@ bool Volatile::update () { Item* bottomItem = mediator->findCollisionPop( ); - if ( bottomItem != 0 ) + if ( bottomItem != nilPointer ) { // volatile doesn’t vanish if it is leaning~ // on item without behavior, or // on item that is not volatile, or // on item that disappears - if ( ( bottomItem->getBehavior() == 0 ) || - ( bottomItem->getBehavior() != 0 + if ( ( bottomItem->getBehavior() == nilPointer ) || + ( bottomItem->getBehavior() != nilPointer && bottomItem->getBehavior()->getNameOfBehavior () != "behavior of disappearance on jump into" && bottomItem->getBehavior()->getNameOfBehavior () != "behavior of disappearance on touch" && bottomItem->getBehavior()->getNameOfBehavior () != "behavior of something special" ) || - ( bottomItem->getBehavior() != 0 + ( bottomItem->getBehavior() != nilPointer && bottomItem->getBehavior()->getActivityOfItem() == Vanish ) ) { isGone = false; @@ -113,7 +113,8 @@ bool Volatile::update () // if it is puppy which disappears when Head or composite player is in room else if ( getNameOfBehavior () == "behavior of disappearance as soon as Head appears" ) { - if ( mediator->findItemByLabel( "head" ) != 0 || mediator->findItemByLabel( "headoverheels" ) != 0 ) + if ( mediator->findItemByLabel( "head" ) != nilPointer || + mediator->findItemByLabel( "headoverheels" ) != nilPointer ) { activity = Vanish; disappearanceTimer->reset(); @@ -144,7 +145,8 @@ bool Volatile::update () } else if ( getNameOfBehavior () == "behavior of disappearance as soon as Head appears" ) { - if ( mediator->findItemByLabel( "head" ) != 0 || mediator->findItemByLabel( "headoverheels" ) != 0 ) + if ( mediator->findItemByLabel( "head" ) != nilPointer || + mediator->findItemByLabel( "headoverheels" ) != nilPointer ) { activity = Vanish; } @@ -178,7 +180,7 @@ bool Volatile::update () item->getX(), item->getY(), item->getZ(), Nowhere ); - freeItem->assignBehavior( "behavior of disappearance in time", 0 ); + freeItem->assignBehavior( "behavior of disappearance in time", nilPointer ); freeItem->setCollisionDetector( false ); mediator->getRoom()->addFreeItem( freeItem ); diff --git a/src/gui/Font.cpp b/src/gui/Font.cpp index 80c0fa36..a6c57eac 100644 --- a/src/gui/Font.cpp +++ b/src/gui/Font.cpp @@ -14,46 +14,49 @@ namespace gui /* static */ unsigned int Font::howManyLetters = 0 ; -/* static */ std::string * Font::tableOfLetters = 0 ; +/* static */ std::string * Font::tableOfLetters = nilPointer ; -Font::Font( const std::string& name, const std::string& fontFile, Color * color, bool doubleHeight ) : +Font::Font( const std::string& name, const BITMAP * pictureOfLetters, Color * color, bool doubleHeight ) : fontName( name ), fontColor( color ) { - std::string nameOfFile = fontFile; - std::cout << "reading from file \"" << nameOfFile << "\" to create font \"" << name << "\"" << std::endl ; - - BITMAP * bitmapFont = load_png( isomot::pathToFile( fontFile ), 0 ); - if ( bitmapFont == 0 ) + if ( pictureOfLetters == nilPointer ) { - std::cerr << "can’t get font \"" << name << "\" from file \"" << nameOfFile << "\"" << std::endl ; + std::cerr << "picture of letters is nil" << std::endl ; return; } + BITMAP* lettersOfFont = create_bitmap( pictureOfLetters->w, pictureOfLetters->h ); + blit( const_cast< BITMAP* >( pictureOfLetters ), lettersOfFont, 0, 0, 0, 0, lettersOfFont->w, lettersOfFont->h ); + // double height font if ( doubleHeight ) { - BITMAP* bigfont = create_bitmap_ex( bitmap_color_depth( bitmapFont ), bitmapFont->w, bitmapFont->h << 1 ); - stretch_blit( bitmapFont, bigfont, 0, 0, bitmapFont->w, bitmapFont->h, 0, 0, bigfont->w, bigfont->h ); - destroy_bitmap( bitmapFont ); - bitmapFont = bigfont; + BITMAP* bigfont = create_bitmap_ex( bitmap_color_depth( lettersOfFont ), lettersOfFont->w, lettersOfFont->h << 1 ); + stretch_blit( lettersOfFont, bigfont, 0, 0, lettersOfFont->w, lettersOfFont->h, 0, 0, bigfont->w, bigfont->h ); + destroy_bitmap( lettersOfFont ); + lettersOfFont = bigfont; } // colorize letters if ( color != Color::whiteColor () ) { - Color::colorizePicture( bitmapFont, color ) ; + Color::colorizePicture( lettersOfFont, color ) ; } // read table of letters once for all fonts - if ( tableOfLetters == 0 ) + if ( tableOfLetters == nilPointer ) { howManyLetters = 0; std::string file = isomot::sharePath() + "letters.utf8"; std::ifstream lettersFile ( isomot::pathToFile( file ), std::ifstream::binary ); - if ( lettersFile != 0 ) + if ( lettersFile ) /* no comparison with nil here, see https://gcc.gnu.org/gcc-6/porting_to.html + “ The change to iostream classes also affects code that tries + to check for stream errors by comparing to NULL or 0. + Such code should be changed to simply test the stream directly, + instead of comparing it to a null pointer ” */ { lettersFile.seekg( 0, lettersFile.end ); unsigned int length = lettersFile.tellg(); @@ -113,41 +116,38 @@ Font::Font( const std::string& name, const std::string& fontFile, Color * color, } // decompose letters - if ( bitmapFont != 0 ) - { - const unsigned int lettersPerRow = 16; - const unsigned int rowsInFont = 21; + const unsigned int lettersPerRow = 16; + const unsigned int rowsInFont = 21; - if ( rowsInFont * lettersPerRow != howManyLetters ) - std::cout << "hmmm, table of letters has more or less letters than picture of font" << std::endl ; + if ( rowsInFont * lettersPerRow != howManyLetters ) + std::cout << "hmmm, table of letters has more or less letters than picture of font" << std::endl ; - this->charWidth = bitmapFont->w / lettersPerRow; - this->charHeight = bitmapFont->h / rowsInFont; + this->charWidth = lettersOfFont->w / lettersPerRow; + this->charHeight = lettersOfFont->h / rowsInFont; - for ( int y = 0; y < bitmapFont->h; y += this->charHeight ) + for ( int y = 0; y < lettersOfFont->h; y += this->charHeight ) + { + for ( int x = 0; x < lettersOfFont->w; x += this->charWidth ) { - for ( int x = 0; x < bitmapFont->w; x += this->charWidth ) - { - BITMAP* bitmapChar = create_bitmap_ex( 32, charWidth, charHeight ); - blit( bitmapFont, bitmapChar, x, y, 0, 0, charWidth, charHeight ); - letters.push_back( bitmapChar ); - } + BITMAP* letter = create_bitmap_ex( 32, charWidth, charHeight ); + blit( lettersOfFont, letter, x, y, 0, 0, charWidth, charHeight ); + letters.push_back( letter ); } } - destroy_bitmap( bitmapFont ); + destroy_bitmap( lettersOfFont ); } Font::~Font( ) { - std::for_each( letters.begin(), letters.end(), destroy_bitmap ); + std::for_each( letters.begin (), letters.end (), destroy_bitmap ); delete fontColor ; } std::string Font::getFamily() const { - char* family = strrchr ( fontName.c_str () , '.' ); - if ( family == 0 ) return fontName; + const char * family = strrchr ( fontName.c_str () , '.' ); + if ( family == nilPointer ) return fontName; return std::string( family + /* to skip that dot */ 1 ); } @@ -155,7 +155,7 @@ BITMAP* Font::getPictureOfLetter( const std::string& letter ) { for ( unsigned int i = 0; i < howManyLetters; i++ ) { - if ( letter.compare( tableOfLetters[ i ] ) == 0 ) + if ( letter == tableOfLetters[ i ] ) { return letters.at( i ); } diff --git a/src/gui/Font.hpp b/src/gui/Font.hpp index 70499ee0..cb0d2d3e 100644 --- a/src/gui/Font.hpp +++ b/src/gui/Font.hpp @@ -33,11 +33,11 @@ class Font /** * @param name Name of this font to mention it - * @param fontFile Name of picture file with letters + * @param pictureOfLetters Picture with letters * @param color Color of letters * @param doubleHeight Double height of letters */ - Font( const std::string& name, const std::string& fontFile, Color * color, bool doubleHeight = false ) ; + Font( const std::string& name, const BITMAP * pictureOfLetters, Color * color, bool doubleHeight = false ) ; virtual ~Font( ) ; diff --git a/src/gui/Gui.cpp b/src/gui/Gui.cpp deleted file mode 100644 index 6b6c9e02..00000000 --- a/src/gui/Gui.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include "Gui.hpp" - - -namespace gui -{ - -void sleep( unsigned long miliseconds ) -{ -# ifdef __WIN32 - Sleep( miliseconds ); -# else - timespec pause; - pause.tv_sec = 0; - pause.tv_nsec = miliseconds * 1000000; - nanosleep( &pause, 0 ); -# endif -} - -} diff --git a/src/gui/Gui.hpp b/src/gui/Gui.hpp index bec9baef..d0e35ba6 100644 --- a/src/gui/Gui.hpp +++ b/src/gui/Gui.hpp @@ -12,20 +12,11 @@ #define Gui_hpp_ #include -#include -#ifdef __WIN32 - #include -#endif namespace gui { -/** - * Pause subprocess for a given period of time in milliseconds - */ -void sleep ( unsigned long miliseconds ) ; - /* * moves the iterator to next unicode character in the string, returns number of bytes skipped * from code by Albert Zeyer and Dark Charlie licensed under LGPL https://sourceforge.net/p/openlierox/code/ci/master/tree/include/Unicode.h diff --git a/src/gui/GuiManager.cpp b/src/gui/GuiManager.cpp index d8c4110a..9f2ced8e 100644 --- a/src/gui/GuiManager.cpp +++ b/src/gui/GuiManager.cpp @@ -28,12 +28,12 @@ using isomot::ScreenWidth; using isomot::ScreenHeight; -GuiManager* GuiManager::instance = 0; +GuiManager* GuiManager::instance = nilPointer ; GuiManager::GuiManager( ) : - screen( 0 ), + screen( nilPointer ), language( "" ), - languageManager( 0 ), + languageManager( nilPointer ), active( true ), atFullScreen( false ), preferencesRead( false ) @@ -52,25 +52,36 @@ GuiManager::GuiManager( ) : set_window_title ( nameOfWindow.c_str () ); - std::string pathToFont = isomot::sharePath(); - // create fonts to use in game - addFont( new Font( "white.regular", pathToFont + "font.png", Color::whiteColor() ) ); - addFont( new Font( "white.big", pathToFont + "font.png", Color::whiteColor(), true ) ); + std::string nameOfFontFile = isomot::sharePath() + "font.png" ; + std::cout << "reading from file \"" << nameOfFontFile << "\" to create fonts used in game" << std::endl ; + + BITMAP * pictureOfFont = load_png( isomot::pathToFile( nameOfFontFile.c_str () ), nilPointer ); + if ( pictureOfFont != nilPointer ) + { + addFont( new Font( "white.regular", pictureOfFont, Color::whiteColor() ) ); + addFont( new Font( "white.big", pictureOfFont, Color::whiteColor(), true ) ); + + addFont( new Font( "orange.regular", pictureOfFont, Color::orangeColor() ) ); + addFont( new Font( "cyan.regular", pictureOfFont, Color::cyanColor() ) ); + addFont( new Font( "yellow.regular", pictureOfFont, Color::yellowColor() ) ); - addFont( new Font( "orange.regular", pathToFont + "font.png", Color::orangeColor() ) ); - addFont( new Font( "cyan.regular", pathToFont + "font.png", Color::cyanColor() ) ); - addFont( new Font( "yellow.regular", pathToFont + "font.png", Color::yellowColor() ) ); + addFont( new Font( "orange.big", pictureOfFont, Color::orangeColor(), true ) ); + addFont( new Font( "cyan.big", pictureOfFont, Color::cyanColor(), true ) ); + addFont( new Font( "yellow.big", pictureOfFont, Color::yellowColor(), true ) ); - addFont( new Font( "orange.big", pathToFont + "font.png", Color::orangeColor(), true ) ); - addFont( new Font( "cyan.big", pathToFont + "font.png", Color::cyanColor(), true ) ); - addFont( new Font( "yellow.big", pathToFont + "font.png", Color::yellowColor(), true ) ); + addFont( new Font( "green.regular", pictureOfFont, Color::greenColor(), false ) ); + addFont( new Font( "green.big", pictureOfFont, Color::greenColor(), true ) ); + addFont( new Font( "magenta.regular", pictureOfFont, Color::magentaColor(), false ) ); + addFont( new Font( "magenta.big", pictureOfFont, Color::magentaColor(), true ) ); - addFont( new Font( "green.regular", pathToFont + "font.png", Color::greenColor(), false ) ); - addFont( new Font( "green.big", pathToFont + "font.png", Color::greenColor(), true ) ); - addFont( new Font( "magenta.regular", pathToFont + "font.png", Color::magentaColor(), false ) ); - addFont( new Font( "magenta.big", pathToFont + "font.png", Color::magentaColor(), true ) ); + destroy_bitmap( pictureOfFont ); + } + else + { + std::cerr << "oops, can’t get letters of fonts from file \"" << nameOfFontFile << "\"" << std::endl ; + } // create image to draw interface this->picture = create_bitmap_ex( 32, ScreenWidth, ScreenHeight ); @@ -94,7 +105,7 @@ GuiManager::~GuiManager( ) GuiManager* GuiManager::getInstance () { - if ( instance == 0 ) + if ( instance == nilPointer ) { instance = new GuiManager(); instance->readPreferences (); @@ -111,7 +122,7 @@ void GuiManager::readPreferences () { preferencesRead = configurationManager->read() ; - if ( ! preferencesRead && instance != 0 ) + if ( ! preferencesRead && instance != nilPointer ) { instance->setLanguage( "en_US" ); } @@ -134,13 +145,13 @@ void GuiManager::begin () this->screen->handleKey( readkey() ); } - sleep( 30 ); + milliSleep( 30 ); } } void GuiManager::changeScreen( Screen* newScreen, bool dive ) { - if ( newScreen == 0 ) return ; + if ( newScreen == nilPointer ) return ; # if defined( DEBUG_GUI ) && DEBUG_GUI @@ -166,7 +177,7 @@ void GuiManager::changeScreen( Screen* newScreen, bool dive ) Action* escape = screen->getEscapeAction () ; fprintf( stdout, ". previous screen was for action \" %s \" with escape action \" %s \"\n", action->getNameOfAction().c_str (), - ( escape != 0 ? escape->getNameOfAction().c_str () : "none" ) ); + ( escape != nilPointer ? escape->getNameOfAction().c_str () : "none" ) ); } if ( newScreen ) @@ -175,7 +186,7 @@ void GuiManager::changeScreen( Screen* newScreen, bool dive ) Action* escapeOfNewScreen = newScreen->getEscapeAction () ; fprintf( stdout, ". new screen is for action \" %s \" with escape action \" %s \"\n", actionOfNewScreen->getNameOfAction().c_str (), - ( escapeOfNewScreen != 0 ? escapeOfNewScreen->getNameOfAction().c_str () : "none" ) + ( escapeOfNewScreen != nilPointer ? escapeOfNewScreen->getNameOfAction().c_str () : "none" ) ) ; } @@ -196,10 +207,10 @@ void GuiManager::changeScreen( Screen* newScreen, bool dive ) Screen * GuiManager::findOrCreateScreenForAction ( Action* action ) { - if ( action == 0 ) + if ( action == nilPointer ) { std::cerr << "screen for nil action is nil screen" << std::endl ; - return 0 ; + return nilPointer ; } std::string nameOfAction = action->getNameOfAction() ; @@ -238,7 +249,7 @@ void GuiManager::refreshScreens () void GuiManager::redraw() { - if ( ( this->active ) && ( this->screen != 0 ) ) + if ( ( this->active ) && ( this->screen != nilPointer ) ) { screen->draw( this->picture ); } @@ -281,16 +292,16 @@ void GuiManager::toggleFullScreenVideo () this->atFullScreen = ! this->atFullScreen ; fprintf( stdout, "video is now %s\n", ( this->atFullScreen ? "at full screen" : "in window" ) ); - sleep( 80 ); + milliSleep( 80 ); redraw (); } void GuiManager::assignLanguage( const std::string& language ) { - if ( this->languageManager != 0 ) + if ( this->languageManager != nilPointer ) { delete this->languageManager; - this->languageManager = 0; + this->languageManager = nilPointer; } fprintf( stdout, "language \"%s\"\n", language.c_str () ); @@ -308,5 +319,5 @@ Font* GuiManager::findFontByFamilyAndColor ( const std::string& family, const st } } - return 0; + return nilPointer ; } diff --git a/src/gui/Label.cpp b/src/gui/Label.cpp index 6fbfc654..9c2ae695 100644 --- a/src/gui/Label.cpp +++ b/src/gui/Label.cpp @@ -3,7 +3,7 @@ #include "Color.hpp" #include "Action.hpp" #include "GuiManager.hpp" - +#include "Ism.hpp" #include @@ -16,8 +16,8 @@ Label::Label( const std::string& text ) fontFamily( "regular" ), color( "white" ), spacing( 0 ), - buffer( 0 ), - myAction( 0 ) + buffer( nilPointer ), + myAction( nilPointer ) { createImageOfLabel( text, Label::getFontByFamilyAndColor( fontFamily, color ) ); } @@ -28,8 +28,8 @@ Label::Label( const std::string& text, const std::string& family, const std::str fontFamily( family ), color( color ), spacing( spacing ), - buffer( 0 ), - myAction( 0 ) + buffer( nilPointer ), + myAction( nilPointer ) { createImageOfLabel( text, Label::getFontByFamilyAndColor( family, color ) ); } @@ -76,7 +76,7 @@ void Label::draw( BITMAP* where ) void Label::handleKey( int key ) { - if ( key >> 8 == KEY_ENTER && myAction != 0 ) + if ( key >> 8 == KEY_ENTER && myAction != nilPointer ) { myAction->doIt (); } @@ -85,7 +85,7 @@ void Label::handleKey( int key ) BITMAP * Label::createImageOfLabel( const std::string& text, Font * font ) { // re-create buffer - if ( this->buffer != 0 ) + if ( this->buffer != nilPointer ) { destroy_bitmap( this->buffer ); } @@ -110,7 +110,7 @@ BITMAP * Label::createImageOfLabel( const std::string& text, Font * font ) { // pick new font with color for this letter fontToUse = Label::getFontByFamilyAndColor( font->getFamily(), multiColors[ colorIndex ] ); - if ( fontToUse == 0 ) + if ( fontToUse == nilPointer ) { std::cerr << "can’t get font with family \"" << font->getFamily() << "\"" << " for color \"" << multiColors[ colorIndex ] << "\"" << std::endl ; @@ -151,7 +151,7 @@ bool EqualXYOfLabel::operator() ( const Label* label, std::pair < int, int > tha bool EqualTextOfLabel::operator() ( const Label* label, const std::string& text ) const { - return ( label->getText().compare( text ) == 0 ); + return ( label->getText() == text ); } } diff --git a/src/gui/LanguageManager.cpp b/src/gui/LanguageManager.cpp index 655d77fc..307fcbad 100644 --- a/src/gui/LanguageManager.cpp +++ b/src/gui/LanguageManager.cpp @@ -2,7 +2,7 @@ #include "csxml/LanguageXML.hpp" #include "LanguageText.hpp" #include "LanguageManager.hpp" -#include "Ism.hpp" // for DeleteObject() in destructor +#include "Ism.hpp" #include @@ -47,7 +47,6 @@ void LanguageManager::parse( const std::string& fileName, const std::string& fil { std::auto_ptr< lxml::LanguageXML > languageXML( lxml::language( fileName.c_str() ) ); - // Almacena todos los registros del archivo en la lista for ( lxml::LanguageXML::text_const_iterator t = languageXML->text().begin (); t != languageXML->text().end (); ++t ) { LanguageText* lang = new LanguageText( ( *t ).id (), ( *t ).x (), ( *t ).y () ); @@ -75,7 +74,7 @@ void LanguageManager::parse( const std::string& fileName, const std::string& fil this->texts.push_back( lang ); } - if ( fileName.compare( fileWithGuaranteedStrings ) != 0 ) + if ( fileName != fileWithGuaranteedStrings ) { // file is not the same as backup file with more strings std::auto_ptr< lxml::LanguageXML > backupLanguageXML( lxml::language( fileWithGuaranteedStrings.c_str() ) ); @@ -115,7 +114,7 @@ void LanguageManager::parse( const std::string& fileName, const std::string& fil inline bool EqualLanguageString::operator() ( const LanguageText* lang, const std::string& id ) const { - return ( lang->getId().compare( id ) == 0 ); + return ( lang->getId() == id ); } } diff --git a/src/gui/Menu.cpp b/src/gui/Menu.cpp index 644cda2b..ebe4a151 100644 --- a/src/gui/Menu.cpp +++ b/src/gui/Menu.cpp @@ -14,11 +14,11 @@ namespace gui Menu::Menu( ) : Widget( ), - activeOption( 0 ), - whereToDraw( 0 ), - optionImage( 0 ), - chosenOptionImage( 0 ), - chosenOptionImageMini( 0 ) + activeOption( nilPointer ), + whereToDraw( nilPointer ), + optionImage( nilPointer ), + chosenOptionImage( nilPointer ), + chosenOptionImageMini( nilPointer ) { refreshPictures (); } @@ -31,26 +31,26 @@ Menu::~Menu( ) void Menu::refreshPictures () { - if ( optionImage != 0 ) destroy_bitmap( optionImage ); - optionImage = load_png( isomot::pathToFile( gui::GuiManager::getInstance()->getPathToPicturesOfGui() + "option.png" ), 0 ); + if ( optionImage != nilPointer ) destroy_bitmap( optionImage ); + optionImage = load_png( isomot::pathToFile( gui::GuiManager::getInstance()->getPathToPicturesOfGui() + "option.png" ), nilPointer ); - if ( chosenOptionImage != 0 ) destroy_bitmap( chosenOptionImage ); - chosenOptionImage = load_png( isomot::pathToFile( gui::GuiManager::getInstance()->getPathToPicturesOfGui() + "chosen-option.png" ), 0 ); + if ( chosenOptionImage != nilPointer ) destroy_bitmap( chosenOptionImage ); + chosenOptionImage = load_png( isomot::pathToFile( gui::GuiManager::getInstance()->getPathToPicturesOfGui() + "chosen-option.png" ), nilPointer ); - if ( chosenOptionImageMini != 0 ) destroy_bitmap( chosenOptionImageMini ); - chosenOptionImageMini = load_png( isomot::pathToFile( gui::GuiManager::getInstance()->getPathToPicturesOfGui() + "chosen-option-mini.png" ), 0 ); + if ( chosenOptionImageMini != nilPointer ) destroy_bitmap( chosenOptionImageMini ); + chosenOptionImageMini = load_png( isomot::pathToFile( gui::GuiManager::getInstance()->getPathToPicturesOfGui() + "chosen-option-mini.png" ), nilPointer ); } void Menu::draw( BITMAP* where ) { - if ( where == 0 ) return ; + if ( where == nilPointer ) return ; if ( where != this->whereToDraw ) { this->whereToDraw = where; } - if ( activeOption == 0 ) + if ( activeOption == nilPointer ) { resetActiveOption (); } @@ -78,7 +78,7 @@ void Menu::draw( BITMAP* where ) setX( previousX + ( ( isomot::ScreenWidth - previousX ) >> 1 ) - ( getWidthOfMenu () >> 1 ) ); setY( previousY + ( ( isomot::ScreenHeight - previousY ) >> 1 ) - ( getHeightOfMenu() >> 1 ) ); - int dx( this->optionImage != 0 ? this->optionImage->w : 0 ); + int dx( this->optionImage != nilPointer ? this->optionImage->w : 0 ); int dy( 0 ); // for each label @@ -88,7 +88,7 @@ void Menu::draw( BITMAP* where ) Label* label = *i; BITMAP * mark = ( this->activeOption == label ) ? this->chosenOptionImage : this->optionImage ; - if ( mark != 0 ) + if ( mark != nilPointer ) draw_sprite( where, mark, getX (), getY () + dy ); label->moveTo( getX () + dx, getY () + dy ); @@ -122,7 +122,7 @@ void Menu::handleKey( int rawKey ) return; } - if ( this->activeOption != 0 ) + if ( this->activeOption != nilPointer ) { switch ( theKey ) { @@ -142,8 +142,8 @@ void Menu::handleKey( int rawKey ) void Menu::addOption( Label* label ) { - assert( label != 0 ); - options.push_back( label ); + if ( label != nilPointer ) + options.push_back( label ); } void Menu::setActiveOption ( Label* option ) @@ -157,7 +157,7 @@ void Menu::setActiveOption ( Label* option ) } } - if ( option != 0 ) + if ( option != nilPointer ) { std::cerr << "option \"" << option->getText() << "\" isn’t from this menu" << std::endl ; } @@ -179,7 +179,7 @@ unsigned int Menu::getWidthOfMenu () const for ( std::list< Label * >::const_iterator i = options.begin () ; i != options.end () ; ++i ) { - unsigned int theWidth = ( *i )->getWidth() + ( this->optionImage != 0 ? this->optionImage->w : 0 ) ; + unsigned int theWidth = ( *i )->getWidth() + ( this->optionImage != nilPointer ? this->optionImage->w : 0 ) ; if ( theWidth > widthOfMenu ) widthOfMenu = theWidth ; } diff --git a/src/gui/MenuWithTwoColumns.cpp b/src/gui/MenuWithTwoColumns.cpp index 81864dc1..140d4f4a 100644 --- a/src/gui/MenuWithTwoColumns.cpp +++ b/src/gui/MenuWithTwoColumns.cpp @@ -25,14 +25,14 @@ MenuWithTwoColumns::~MenuWithTwoColumns( ) void MenuWithTwoColumns::draw( BITMAP* where ) { - if ( where == 0 ) return ; + if ( where == nilPointer ) return ; if ( where != this->whereToDraw ) { this->whereToDraw = where; } - if ( activeOption == 0 ) + if ( activeOption == nilPointer ) { resetActiveOption (); } @@ -40,7 +40,7 @@ void MenuWithTwoColumns::draw( BITMAP* where ) // rows in first column, after this number options go to second column unsigned int rowsInFirstColumn = options.size () >> 1; - unsigned int widthOfOption = ( this->optionImage != 0 ) ? this->optionImage->w : 0 ; + unsigned int widthOfOption = ( this->optionImage != nilPointer ) ? this->optionImage->w : 0 ; // calculate position of second column unsigned int widthOfFirstColumn = 0; @@ -87,7 +87,7 @@ void MenuWithTwoColumns::draw( BITMAP* where ) // place option in first column if ( countOfRows <= rowsInFirstColumn ) { - if ( mark != 0 ) + if ( mark != nilPointer ) draw_sprite( where, mark, getX (), getY () + dy ); label->moveTo( getX () + dx, getY () + dy ); @@ -105,7 +105,7 @@ void MenuWithTwoColumns::draw( BITMAP* where ) // dibuja la viñeta // para cada etiqueta // ( poems, no less ) - if ( mark != 0 ) + if ( mark != nilPointer ) draw_sprite( where, mark, getX () + secondColumnX, getY () + dy ); label->moveTo( getX () + dx + secondColumnX, getY () + dy ); @@ -134,7 +134,7 @@ unsigned int MenuWithTwoColumns::getWidthOfMenu () const for ( std::list< Label* >::const_iterator i = options.begin (); i != options.end (); ++i, countOfRows++ ) { - unsigned int theWidth = ( *i )->getWidth() + ( this->optionImage != 0 ? this->optionImage->w : 0 ); + unsigned int theWidth = ( *i )->getWidth() + ( this->optionImage != nilPointer ? this->optionImage->w : 0 ); if ( countOfRows <= rowsInFirstColumn ) { diff --git a/src/gui/MenuWithValues.cpp b/src/gui/MenuWithValues.cpp index 399e9a25..91615752 100644 --- a/src/gui/MenuWithValues.cpp +++ b/src/gui/MenuWithValues.cpp @@ -24,14 +24,14 @@ MenuWithValues::~MenuWithValues( ) void MenuWithValues::draw( BITMAP* where ) { - if ( where == 0 ) return ; + if ( where == nilPointer ) return ; if ( where != this->whereToDraw ) { this->whereToDraw = where; } - if ( activeOption == 0 ) + if ( activeOption == nilPointer ) { resetActiveOption (); } @@ -67,7 +67,7 @@ void MenuWithValues::draw( BITMAP* where ) } std::list< Label * > optionsWithValues; - Label* activeOptionWithValue = 0; + Label* activeOptionWithValue = nilPointer; for ( std::list< Label* >::const_iterator i = options.begin (); i != options.end (); ++i ) { @@ -101,7 +101,7 @@ void MenuWithValues::draw( BITMAP* where ) setX( previousX + ( ( isomot::ScreenWidth - previousX ) >> 1 ) - ( getWidthOfMenu () >> 1 ) ); setY( previousY + ( ( isomot::ScreenHeight - previousY ) >> 1 ) - ( getHeightOfMenu() >> 1 ) ); - int dx( this->optionImage != 0 ? this->optionImage->w : 0 ); + int dx( this->optionImage != nilPointer ? this->optionImage->w : 0 ); int dy( 0 ); // for each label @@ -111,7 +111,7 @@ void MenuWithValues::draw( BITMAP* where ) Label* label = *i; BITMAP * mark = ( activeOptionWithValue == label ) ? this->chosenOptionImage : this->optionImage ; - if ( mark != 0 ) + if ( mark != nilPointer ) draw_sprite( where, mark, getX (), getY () + dy ); label->moveTo( getX () + dx, getY () + dy ); @@ -185,7 +185,7 @@ unsigned int MenuWithValues::getWidthOfMenu () const textOfOption = textOfOption + symbolToFill; Label optionWithValue( textOfOption + getValueOf( *o ), ( *o )->getFontFamily(), ( *o )->getColor(), ( *o )->getSpacing() ); - unsigned int theWidth = optionWithValue.getWidth() + ( this->optionImage != 0 ? this->optionImage->w : 0 ) ; + unsigned int theWidth = optionWithValue.getWidth() + ( this->optionImage != nilPointer ? this->optionImage->w : 0 ) ; if ( theWidth > widthOfMenu ) widthOfMenu = theWidth ; } diff --git a/src/gui/Picture.cpp b/src/gui/Picture.cpp index 4635052c..e9cae3bd 100644 --- a/src/gui/Picture.cpp +++ b/src/gui/Picture.cpp @@ -1,5 +1,6 @@ #include "Picture.hpp" +#include "Ism.hpp" namespace gui @@ -25,12 +26,12 @@ Picture::~Picture() /* std::cout << "forget picture with name \"" << nameOfPicture << "\"" << std::endl ; */ destroy_bitmap( picture ); - picture = 0 ; + picture = nilPointer ; } void Picture::draw( BITMAP* where ) { - if ( picture != 0 ) + if ( picture != nilPointer ) { draw_sprite( where, picture, getX(), getY() ); } diff --git a/src/gui/Screen.cpp b/src/gui/Screen.cpp index 2d6a4581..b349e9f8 100644 --- a/src/gui/Screen.cpp +++ b/src/gui/Screen.cpp @@ -20,14 +20,14 @@ const double delayBetweenFrames = 0.1 ; namespace gui { -/* static */ BITMAP * Screen::backgroundPicture = 0 ; +/* static */ BITMAP * Screen::backgroundPicture = nilPointer ; /* static */ void Screen::refreshBackground () { - if ( backgroundPicture != 0 ) + if ( backgroundPicture != nilPointer ) { destroy_bitmap( backgroundPicture ); - backgroundPicture = 0; + backgroundPicture = nilPointer; } Screen::backgroundPicture = Screen::loadPicture( "background.png" ); @@ -36,14 +36,14 @@ namespace gui Screen::Screen( Action* action ) : Widget( 0, 0 ), - imageOfScreen( 0 ), + imageOfScreen( nilPointer ), actionOfScreen( action ), - escapeAction( 0 ), - keyHandler( 0 ), - pictureOfHead( 0 ), - pictureOfHeels( 0 ) + escapeAction( nilPointer ), + keyHandler( nilPointer ), + pictureOfHead( nilPointer ), + pictureOfHeels( nilPointer ) { - if ( action != 0 && action->getWhereToDraw() != 0 ) + if ( action != nilPointer && action->getWhereToDraw() != nilPointer ) { imageOfScreen = action->getWhereToDraw (); refreshPicturesOfHeadAndHeels (); @@ -66,7 +66,7 @@ void Screen::refreshPicturesOfHeadAndHeels () int xHead = 0, yHead = 0; bool headOnScreen = false; - if ( pictureOfHead != 0 ) + if ( pictureOfHead != nilPointer ) { xHead = pictureOfHead->getX (); yHead = pictureOfHead->getY (); @@ -82,13 +82,13 @@ void Screen::refreshPicturesOfHeadAndHeels () pictureOfHead = new AnimatedPicture( xHead, yHead, loadAnimation( "head.gif" ), delayBetweenFrames, "animated Head" ); } - if ( headOnScreen && pictureOfHead != 0 ) + if ( headOnScreen && pictureOfHead != nilPointer ) addWidget( pictureOfHead ); int xHeels = 0, yHeels = 0; bool heelsOnScreen = false; - if ( pictureOfHeels != 0 ) + if ( pictureOfHeels != nilPointer ) { xHeels = pictureOfHeels->getX (); yHeels = pictureOfHeels->getY (); @@ -104,7 +104,7 @@ void Screen::refreshPicturesOfHeadAndHeels () pictureOfHeels = new AnimatedPicture( xHeels, yHeels, loadAnimation( "heels.gif" ), delayBetweenFrames, "animated Heels" ); } - if ( heelsOnScreen && pictureOfHeels != 0 ) + if ( heelsOnScreen && pictureOfHeels != nilPointer ) addWidget( pictureOfHeels ); } @@ -118,13 +118,13 @@ void Screen::draw( BITMAP* where ) void Screen::redraw( ) { - if ( imageOfScreen == 0 ) return ; + if ( imageOfScreen == nilPointer ) return ; // fill with color of background clear_to_color( imageOfScreen, Color::redColor()->toAllegroColor() ); // draw background, if any - if ( Screen::backgroundPicture != 0 ) + if ( Screen::backgroundPicture != nilPointer ) { blit( backgroundPicture, imageOfScreen, 0, 0, 0, 0, backgroundPicture->w, backgroundPicture->h ); } @@ -149,15 +149,15 @@ void Screen::handleKey( int rawKey ) return; } - if ( escapeAction != 0 && theKey == KEY_ESC ) + if ( escapeAction != nilPointer && theKey == KEY_ESC ) { - fprintf( stdout, "escape action %s ~~\n", ( escapeAction != 0 ? escapeAction->getNameOfAction().c_str () : "nope" ) ); + fprintf( stdout, "escape action %s ~~\n", ( escapeAction != nilPointer ? escapeAction->getNameOfAction().c_str () : "nope" ) ); this->escapeAction->doIt (); - fprintf( stdout, "~~ done with action %s\n", ( escapeAction != 0 ? escapeAction->getNameOfAction().c_str () : "nope" ) ); + fprintf( stdout, "~~ done with action %s\n", ( escapeAction != nilPointer ? escapeAction->getNameOfAction().c_str () : "nope" ) ); } else { - if ( this->keyHandler != 0 ) + if ( this->keyHandler != nilPointer ) { this->keyHandler->handleKey( rawKey ); } @@ -188,10 +188,10 @@ bool Screen::removeWidget( Widget* widget ) void Screen::freeWidgets () { - if ( pictureOfHead != 0 && ! pictureOfHead->isOnScreen () ) + if ( pictureOfHead != nilPointer && ! pictureOfHead->isOnScreen () ) delete pictureOfHead; - if ( pictureOfHeels != 0 && ! pictureOfHeels->isOnScreen () ) + if ( pictureOfHeels != nilPointer && ! pictureOfHeels->isOnScreen () ) delete pictureOfHeels; while ( ! this->widgets.empty () ) @@ -201,13 +201,13 @@ void Screen::freeWidgets () delete w; } - pictureOfHead = 0; - pictureOfHeels = 0; + pictureOfHead = nilPointer; + pictureOfHeels = nilPointer; } void Screen::addPictureOfHeadAt ( int x, int y ) { - if ( pictureOfHead == 0 ) + if ( pictureOfHead == nilPointer ) pictureOfHead = new AnimatedPicture( x, y, loadAnimation( "head.gif" ), delayBetweenFrames, "animated Head" ); else pictureOfHead->moveTo( x, y ); @@ -217,7 +217,7 @@ void Screen::addPictureOfHeadAt ( int x, int y ) void Screen::addPictureOfHeelsAt ( int x, int y ) { - if ( pictureOfHeels == 0 ) + if ( pictureOfHeels == nilPointer ) pictureOfHeels = new AnimatedPicture( x, y, loadAnimation( "heels.gif" ), delayBetweenFrames, "animated Heels" ); else pictureOfHeels->moveTo( x, y ); @@ -227,7 +227,7 @@ void Screen::addPictureOfHeelsAt ( int x, int y ) void Screen::placeHeadAndHeels( bool picturesToo, bool copyrightsToo ) { - Label* label = 0; + Label* label = nilPointer; label = new Label( "Jon", "regular", "multicolor" ); label->moveTo( 64, 22 ); @@ -295,7 +295,7 @@ BITMAP * Screen::loadPicture ( const char * nameOfPicture ) #if defined( DEBUG ) && DEBUG std::cout << "Screen::loadPicture( \"" << nameOfPicture << "\" )" << std::endl ; #endif - return load_png( isomot::pathToFile( GuiManager::getInstance()->getPathToPicturesOfGui() + nameOfPicture ), 0 ); + return load_png( isomot::pathToFile( GuiManager::getInstance()->getPathToPicturesOfGui() + nameOfPicture ), nilPointer ); } /* static */ @@ -305,8 +305,8 @@ std::vector< BITMAP * > Screen::loadAnimation ( const char * nameOfGif ) std::cout << "Screen::loadAnimation( \"" << nameOfGif << "\" )" ; #endif std::vector< BITMAP * > animation; - BITMAP** frames = 0; - int* durations = 0; + BITMAP** frames = nilPointer; + int* durations = nilPointer; int howManyFrames = algif_load_animation( isomot::pathToFile( GuiManager::getInstance()->getPathToPicturesOfGui() + nameOfGif ), &frames, &durations ); #if defined( DEBUG ) && DEBUG @@ -328,9 +328,9 @@ std::vector< BITMAP * > Screen::loadAnimation ( const char * nameOfGif ) /* static */ void Screen::scrollHorizontally( Screen* oldScreen, Screen* newScreen, bool rightToLeft ) { - if ( oldScreen == 0 || newScreen == 0 || + if ( oldScreen == nilPointer || newScreen == nilPointer || oldScreen == newScreen || - oldScreen->imageOfScreen == 0 || newScreen->imageOfScreen == 0 ) return ; + oldScreen->imageOfScreen == nilPointer || newScreen->imageOfScreen == nilPointer ) return ; BITMAP * oldPicture = create_bitmap( oldScreen->imageOfScreen->w, oldScreen->imageOfScreen->h ); blit( oldScreen->imageOfScreen, oldPicture, 0, 0, 0, 0, oldScreen->imageOfScreen->w, oldScreen->imageOfScreen->h ); @@ -354,7 +354,7 @@ void Screen::scrollHorizontally( Screen* oldScreen, Screen* newScreen, bool righ blit( oldPicture, screen, 0, 0, x, 0, newPicture->w - x, isomot::ScreenHeight ); } - sleep( 1 ); + milliSleep( 1 ); } destroy_bitmap( oldPicture ); @@ -363,8 +363,8 @@ void Screen::scrollHorizontally( Screen* oldScreen, Screen* newScreen, bool righ /* static */ void Screen::wipeHorizontally( Screen* oldScreen, Screen* newScreen, bool rightToLeft ) { - if ( oldScreen == 0 || newScreen == 0 || - oldScreen == newScreen || newScreen->imageOfScreen == 0 ) return ; + if ( oldScreen == nilPointer || newScreen == nilPointer || + oldScreen == newScreen || newScreen->imageOfScreen == nilPointer ) return ; newScreen->redraw (); BITMAP * newPicture = newScreen->imageOfScreen ; @@ -383,16 +383,16 @@ void Screen::wipeHorizontally( Screen* oldScreen, Screen* newScreen, bool rightT blit( newPicture, screen, 0, 0, 0, 0, x, isomot::ScreenHeight ); } - sleep( 1 ); + milliSleep( 1 ); } } /* static */ void Screen::barScrollHorizontally( Screen* oldScreen, Screen* newScreen, bool rightToLeft ) { - if ( oldScreen == 0 || newScreen == 0 || + if ( oldScreen == nilPointer || newScreen == nilPointer || oldScreen == newScreen || - oldScreen->imageOfScreen == 0 || newScreen->imageOfScreen == 0 ) return ; + oldScreen->imageOfScreen == nilPointer || newScreen->imageOfScreen == nilPointer ) return ; BITMAP * oldPicture = create_bitmap( oldScreen->imageOfScreen->w, oldScreen->imageOfScreen->h ); blit( oldScreen->imageOfScreen, oldPicture, 0, 0, 0, 0, oldScreen->imageOfScreen->w, oldScreen->imageOfScreen->h ); @@ -420,7 +420,7 @@ void Screen::barScrollHorizontally( Screen* oldScreen, Screen* newScreen, bool r } } - sleep( 4 ); + milliSleep( 4 ); } destroy_bitmap( oldPicture ); @@ -429,8 +429,8 @@ void Screen::barScrollHorizontally( Screen* oldScreen, Screen* newScreen, bool r /* static */ void Screen::barWipeHorizontally( Screen* oldScreen, Screen* newScreen, bool rightToLeft ) { - if ( oldScreen == 0 || newScreen == 0 || - oldScreen == newScreen || newScreen->imageOfScreen == 0 ) return ; + if ( oldScreen == nilPointer || newScreen == nilPointer || + oldScreen == newScreen || newScreen->imageOfScreen == nilPointer ) return ; newScreen->redraw (); BITMAP * newPicture = newScreen->imageOfScreen ; @@ -453,7 +453,7 @@ void Screen::barWipeHorizontally( Screen* oldScreen, Screen* newScreen, bool rig } } - sleep( 4 ); + milliSleep( 4 ); } } diff --git a/src/guiactions/CreateAudioMenu.cpp b/src/guiactions/CreateAudioMenu.cpp index fa9a150f..6950fec4 100644 --- a/src/guiactions/CreateAudioMenu.cpp +++ b/src/guiactions/CreateAudioMenu.cpp @@ -19,10 +19,10 @@ using isomot::SoundManager; CreateAudioMenu::CreateAudioMenu( BITMAP* picture ) : Action( picture ), - listOfOptions ( 0 ), - labelEffects ( 0 ), - labelMusic ( 0 ), - playRoomTunes ( 0 ) + listOfOptions ( nilPointer ), + labelEffects ( nilPointer ), + labelMusic ( nilPointer ), + playRoomTunes ( nilPointer ) { } @@ -86,7 +86,7 @@ void CreateAudioMenu::doAction () listOfOptions->setValueOf( playRoomTunes, isomot::GameManager::getInstance()->playMelodyOfScenery () ? yeah : nope ); } - if ( screen->getKeyHandler() == 0 ) + if ( screen->getKeyHandler() == nilPointer ) { screen->setKeyHandler( listOfOptions ); } @@ -168,8 +168,8 @@ void CreateAudioMenu::doAction () } } - // No te comas la CPU - // Do not eat the CPU - sleep( 25 ); + // no te comas la CPU + // do not eat the CPU + milliSleep( 25 ); } } diff --git a/src/guiactions/CreateLanguageMenu.cpp b/src/guiactions/CreateLanguageMenu.cpp index e0c75519..d28e938e 100644 --- a/src/guiactions/CreateLanguageMenu.cpp +++ b/src/guiactions/CreateLanguageMenu.cpp @@ -41,7 +41,7 @@ void CreateLanguageMenu::doAction () screen->setEscapeAction( new gui::CreateMainMenu( getWhereToDraw() ) ); - Label* label = 0; + Label* label = nilPointer; label = new Label( "Head", "big", "yellow" ); label->moveTo( 200, 24 ); @@ -72,7 +72,7 @@ void CreateLanguageMenu::doAction () menu->addOption( label ); - if ( ( language.empty() && i == this->texts.begin() ) || language.compare( ( *i )->getId() ) == 0 ) + if ( ( language.empty() && i == this->texts.begin() ) || language == ( *i )->getId() ) { menu->setActiveOption( label ); } diff --git a/src/guiactions/CreateMenuOfGraphicSets.cpp b/src/guiactions/CreateMenuOfGraphicSets.cpp index c4f06d48..356f8b6c 100644 --- a/src/guiactions/CreateMenuOfGraphicSets.cpp +++ b/src/guiactions/CreateMenuOfGraphicSets.cpp @@ -15,7 +15,7 @@ using gui::CreateMenuOfGraphicSets ; CreateMenuOfGraphicSets::CreateMenuOfGraphicSets( BITMAP* picture, Action* previous ) : Action( picture ), actionOnEscape( previous ), - menuOfGraphicSets( 0 ) + menuOfGraphicSets( nilPointer ) { graphicSets[ "gfx" ] = "Present" ; graphicSets[ "gfx.2009" ] = "By Davit" ; @@ -54,7 +54,7 @@ void CreateMenuOfGraphicSets::doAction () } Label * theLabel = new Label( nameOfSetSpaced + i->first ); - if ( i->first.compare( isomot::GameManager::getInstance()->getChosenGraphicSet() ) != 0 ) + if ( i->first != isomot::GameManager::getInstance()->getChosenGraphicSet() ) { theLabel->changeColor( "cyan" ); } @@ -104,7 +104,7 @@ void CreateMenuOfGraphicSets::doAction () { std::string chosenSet = menuOfGraphicSets->getActiveOption()->getText().substr( positionOfSecondColumn ) ; - if ( chosenSet.compare( isomot::GameManager::getInstance()->getChosenGraphicSet() ) != 0 ) + if ( chosenSet != isomot::GameManager::getInstance()->getChosenGraphicSet() ) { // new set is not the same as previous one isomot::GameManager::getInstance()->setChosenGraphicSet( chosenSet.c_str () ) ; @@ -132,7 +132,7 @@ void CreateMenuOfGraphicSets::doAction () // no te comas la CPU // do not eat the CPU - sleep( 25 ); + milliSleep( 25 ); } } } diff --git a/src/guiactions/CreateVideoMenu.cpp b/src/guiactions/CreateVideoMenu.cpp index 872ff9d0..9d3ce735 100644 --- a/src/guiactions/CreateVideoMenu.cpp +++ b/src/guiactions/CreateVideoMenu.cpp @@ -16,10 +16,10 @@ using gui::CreateMenuOfGraphicSets ; CreateVideoMenu::CreateVideoMenu( BITMAP* picture ) : Action( picture ), - listOfOptions ( 0 ), - labelFullscreen ( 0 ), - labelDrawBackground ( 0 ), - labelGraphicSet ( 0 ) + listOfOptions ( nilPointer ), + labelFullscreen ( nilPointer ), + labelDrawBackground ( nilPointer ), + labelGraphicSet ( nilPointer ) { } @@ -71,7 +71,7 @@ void CreateVideoMenu::doAction () screen->setEscapeAction( new CreateMainMenu( getWhereToDraw() ) ); - if ( screen->getKeyHandler() == 0 ) + if ( screen->getKeyHandler() == nilPointer ) { screen->setKeyHandler( listOfOptions ); } @@ -129,7 +129,7 @@ void CreateVideoMenu::doAction () // no te comas la CPU // do not eat the CPU - sleep( 25 ); + milliSleep( 25 ); } } } diff --git a/src/guiactions/LoadGame.cpp b/src/guiactions/LoadGame.cpp index deab7dc8..c30ecbc6 100644 --- a/src/guiactions/LoadGame.cpp +++ b/src/guiactions/LoadGame.cpp @@ -8,7 +8,7 @@ using gui::LoadGame; using gui::CreatePlanetsScreen; -LoadGame::LoadGame( BITMAP* picture, int slot ) +LoadGame::LoadGame( BITMAP* picture, unsigned int slot ) : Action( picture ) , slot( slot ) { diff --git a/src/guiactions/LoadGame.hpp b/src/guiactions/LoadGame.hpp index 0c056196..3b33e1d5 100644 --- a/src/guiactions/LoadGame.hpp +++ b/src/guiactions/LoadGame.hpp @@ -27,7 +27,7 @@ class LoadGame : public Action * @param picture Image where to draw user interface * @param slot Number of file to load */ - LoadGame( BITMAP * picture, int slot ) ; + LoadGame( BITMAP * picture, unsigned int slot ) ; std::string getNameOfAction () const { return "LoadGame" ; } @@ -43,7 +43,7 @@ class LoadGame : public Action /** * Number of file to load */ - int slot ; + unsigned int slot ; }; diff --git a/src/guiactions/RedefineKey.cpp b/src/guiactions/RedefineKey.cpp index 1d42d646..03bd639d 100644 --- a/src/guiactions/RedefineKey.cpp +++ b/src/guiactions/RedefineKey.cpp @@ -91,7 +91,7 @@ void RedefineKey::doAction () // no te comas la CPU // do not eat the CPU - sleep( 20 ); + milliSleep( 20 ); } if ( InputManager::getInstance()->getUserKey( this->nameOfKey ) != 0 ) { diff --git a/src/guiactions/SaveGame.cpp b/src/guiactions/SaveGame.cpp index 4f44e194..2f35d827 100644 --- a/src/guiactions/SaveGame.cpp +++ b/src/guiactions/SaveGame.cpp @@ -8,7 +8,7 @@ using gui::SaveGame; using gui::ContinueGame; -SaveGame::SaveGame( BITMAP* picture, int slot ) +SaveGame::SaveGame( BITMAP* picture, unsigned int slot ) : Action( picture ) , slot( slot ) { @@ -19,7 +19,7 @@ void SaveGame::doAction () { clear_keybuf(); - if ( slot != 0 ) + if ( slot > 0 ) { std::stringstream ss; isomot::GameManager* gameManager = isomot::GameManager::getInstance(); diff --git a/src/guiactions/SaveGame.hpp b/src/guiactions/SaveGame.hpp index d5d4d43d..3aa4b663 100644 --- a/src/guiactions/SaveGame.hpp +++ b/src/guiactions/SaveGame.hpp @@ -27,7 +27,7 @@ class SaveGame : public Action * @param picture Image where to draw user interface * @param slot Number of file to load */ - SaveGame( BITMAP * picture, int slot ) ; + SaveGame( BITMAP * picture, unsigned int slot ) ; std::string getNameOfAction () const { return "SaveGame" ; } @@ -43,7 +43,7 @@ class SaveGame : public Action /** * Number of file to load */ - int slot ; + unsigned int slot ; }; diff --git a/src/guiactions/ShowAuthors.cpp b/src/guiactions/ShowAuthors.cpp index 55a5041f..55769cc3 100644 --- a/src/guiactions/ShowAuthors.cpp +++ b/src/guiactions/ShowAuthors.cpp @@ -34,7 +34,7 @@ void ShowAuthors::doAction () Screen* screen = GuiManager::getInstance()->findOrCreateScreenForAction( this ); if ( screen->countWidgets() == 0 ) { - LanguageText* langString = 0; + LanguageText* langString = nilPointer; LanguageManager* languageManager = GuiManager::getInstance()->getLanguageManager(); langString = languageManager->findLanguageString( "credits-text" ); @@ -62,7 +62,7 @@ void ShowAuthors::doAction () GuiManager::getInstance()->changeScreen( screen, true ); - Picture* widgetForLoadingScreen = 0; + Picture* widgetForLoadingScreen = nilPointer; // move text up @@ -121,10 +121,10 @@ void ShowAuthors::doAction () linesOfCredits->moveTo( linesOfCredits->getX(), yNow ); - if ( yNow == heightOfWhereToDraw - heightOfCredits && widgetForLoadingScreen == 0 ) + if ( yNow == heightOfWhereToDraw - heightOfCredits && widgetForLoadingScreen == nilPointer ) { - BITMAP* loadingScreen = load_png( isomot::pathToFile( isomot::sharePath() + "loading-screen.png" ), 0 ); - if ( loadingScreen != 0 ) + BITMAP* loadingScreen = load_png( isomot::pathToFile( isomot::sharePath() + "loading-screen.png" ), nilPointer ); + if ( loadingScreen != nilPointer ) { widgetForLoadingScreen = new Picture( ( getWhereToDraw()->w - loadingScreen->w ) >> 1, heightOfWhereToDraw, @@ -134,14 +134,14 @@ void ShowAuthors::doAction () screen->addWidget( widgetForLoadingScreen ); } } - else if ( yNow < heightOfWhereToDraw - heightOfCredits && widgetForLoadingScreen != 0 ) + else if ( yNow < heightOfWhereToDraw - heightOfCredits && widgetForLoadingScreen != nilPointer ) { widgetForLoadingScreen->moveTo( widgetForLoadingScreen->getX(), yNow + heightOfCredits ); } - else if ( widgetForLoadingScreen != 0 ) + else if ( widgetForLoadingScreen != nilPointer ) { screen->removeWidget( widgetForLoadingScreen ); - widgetForLoadingScreen = 0; + widgetForLoadingScreen = nilPointer; } GuiManager::getInstance()->redraw (); @@ -153,7 +153,7 @@ void ShowAuthors::doAction () if ( ! ( keypressed() && key[ KEY_SPACE ] ) ) { - sleep( 20 ); + milliSleep( 20 ); } if ( keypressed() && key[ KEY_ESC ] ) @@ -163,9 +163,9 @@ void ShowAuthors::doAction () } } - if ( widgetForLoadingScreen != 0 ) + if ( widgetForLoadingScreen != nilPointer ) { screen->removeWidget( widgetForLoadingScreen ); - widgetForLoadingScreen = 0; + widgetForLoadingScreen = nilPointer; } }