From 7146c492e82173d4fb18b39f606803214fc97701 Mon Sep 17 00:00:00 2001 From: Douglas Mencken Date: Sat, 3 Mar 2018 06:44:05 -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 IN PROGRESS ~~ 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/Color.cpp | 5 +- src/Door.cpp | 18 +-- src/FreeItem.cpp | 49 +++--- src/GameManager.cpp | 83 +++++----- src/InputManager.cpp | 6 +- src/InputManager.hpp | 44 +++--- src/Ism.cpp | 44 +++--- src/Ism.hpp | 6 + src/Isomot.cpp | 24 +-- src/Item.cpp | 39 ++--- src/Item.hpp | 4 +- src/ItemData.cpp | 3 +- src/ItemDataManager.cpp | 20 +-- src/MapRoomData.cpp | 16 +- src/Mediator.cpp | 8 +- src/PlayerItem.cpp | 47 +++--- src/Room.cpp | 8 +- src/RoomBuilder.cpp | 39 ++--- src/SoundManager.cpp | 32 ++-- src/SoundManager.hpp | 2 +- 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/gui/Font.cpp | 70 ++++----- src/gui/Font.hpp | 4 +- src/gui/GuiManager.cpp | 67 ++++---- src/gui/Label.cpp | 18 +-- src/gui/Menu.cpp | 40 ++--- src/gui/Screen.cpp | 74 ++++----- src/guiactions/ShowAuthors.cpp | 20 +-- 41 files changed, 664 insertions(+), 579 deletions(-) create mode 100644 extras/headoverheels.desktop 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/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/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/GameManager.cpp b/src/GameManager.cpp index 19097d55..80a3b319 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,7 +667,7 @@ WhyPause GameManager::update () BITMAP* view = this->isomot->update(); // se ha podido actualizar - if ( view != 0 ) + if ( view != nilPointer ) { this->drawAmbianceOfGame( view ); sleep( 10 ); @@ -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,8 +773,6 @@ WhyPause GameManager::pause () } } - // sondea la decisión del usuario cada 10 milisegundos - // poll the decision of user every 10 milliseconds sleep( 10 ); } } @@ -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++ ) 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..c4b03a45 100644 --- a/src/Ism.cpp +++ b/src/Ism.cpp @@ -6,6 +6,10 @@ #include #endif +#ifndef PATH_MAX + #define PATH_MAX 4096 +#endif + namespace isomot { @@ -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 defined ( __APPLE__ ) && defined ( __MACH__ ) + char* lastdot = strrchr ( get_filename( pathToGame ) , '.' ); if ( lastdot != 0 && 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; - 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 () ); } @@ -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..095ee51e 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 diff --git a/src/Isomot.cpp b/src/Isomot.cpp index 27655c8c..bb11db16 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 (); @@ -292,7 +292,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" ); @@ -426,7 +426,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(); } @@ -524,7 +524,7 @@ void Isomot::updateEndRoom() SoundManager::getInstance()->playOgg ( "music/begin.ogg", /* loop */ false ); /// sleep( 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/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/Mediator.cpp b/src/Mediator.cpp index e7514c12..f8b1a31c 100644 --- a/src/Mediator.cpp +++ b/src/Mediator.cpp @@ -648,7 +648,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 +659,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 +680,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 +691,7 @@ Item* Mediator::findItemByBehavior( const std::string& behavior ) } // look for grid item - if ( item == 0 ) + if ( item == nilPointer ) { std::list< GridItem * >::iterator g; 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..6b10ba1d 100644 --- a/src/Room.cpp +++ b/src/Room.cpp @@ -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 ) { @@ -703,7 +703,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 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..7400775d 100644 --- a/src/SoundManager.hpp +++ b/src/SoundManager.hpp @@ -108,7 +108,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: 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/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/GuiManager.cpp b/src/gui/GuiManager.cpp index d8c4110a..8a896208 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" ); } @@ -140,7 +151,7 @@ void GuiManager::begin () 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 ); } @@ -287,10 +298,10 @@ void GuiManager::toggleFullScreenVideo () 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/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/Screen.cpp b/src/gui/Screen.cpp index 2d6a4581..e83258d2 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 ); @@ -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 ; @@ -390,9 +390,9 @@ void Screen::wipeHorizontally( Screen* oldScreen, Screen* newScreen, bool rightT /* 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 ); @@ -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 ; diff --git a/src/guiactions/ShowAuthors.cpp b/src/guiactions/ShowAuthors.cpp index 55a5041f..5025b56f 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 (); @@ -163,9 +163,9 @@ void ShowAuthors::doAction () } } - if ( widgetForLoadingScreen != 0 ) + if ( widgetForLoadingScreen != nilPointer ) { screen->removeWidget( widgetForLoadingScreen ); - widgetForLoadingScreen = 0; + widgetForLoadingScreen = nilPointer; } }