From aff167beefadc32add4b44626cc2f1cbef800c7b Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 30 Jul 2006 14:33:28 +0000 Subject: Updated TMW to be compatible with Guichan 0.5.0 (merged from guichan-0.5.0 branch). --- src/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Makefile.am') diff --git a/src/Makefile.am b/src/Makefile.am index 1bb1d538..42e72829 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,8 +12,6 @@ tmw_SOURCES = graphic/imagerect.h \ gui/buysell.h \ gui/chargedialog.cpp \ gui/chargedialog.h \ - gui/char_server.cpp \ - gui/char_server.h \ gui/char_select.cpp \ gui/char_select.h \ gui/chat.cpp \ @@ -167,6 +165,8 @@ tmw_SOURCES = graphic/imagerect.h \ resources/mapreader.h \ resources/music.h \ resources/music.cpp \ + resources/openglsdlimageloader.h \ + resources/openglsdlimageloader.cpp \ resources/resource.cpp \ resources/resource.h \ resources/resourcemanager.cpp \ -- cgit v1.2.3-70-g09d2 From 0bebbc320d50178a7ece573319cd6687a950dafa Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Wed, 2 Aug 2006 12:41:35 +0000 Subject: Cleaned autotools files. --- ChangeLog | 6 ++++ configure.ac | 99 ++++++++++++++++++++++++++++----------------------------- src/Makefile.am | 8 ++--- 3 files changed, 57 insertions(+), 56 deletions(-) (limited to 'src/Makefile.am') diff --git a/ChangeLog b/ChangeLog index 1648f018..ea4ac6f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-08-02 Guillaume Melquiond + + * configure.ac, src/Makefile.am: Put object files in subdirectories. + Moved compilation flags to configure script. Added library header + checks. + 2006-08-02 Eugenio Favalli * src/gui/char_select.cpp, src/gui/char_select.h, src/gui/register.cpp, diff --git a/configure.ac b/configure.ac index d8f980d3..4c5a492a 100755 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,6 @@ AC_PREREQ(2.59) AC_INIT([The Mana World], [0.1.0], [elvenprogrammer@gmail.com], [tmw]) +AM_INIT_AUTOMAKE AC_CONFIG_HEADERS([config.h:config.h.in]) AC_LANG_CPLUSPLUS @@ -23,85 +24,83 @@ AC_FUNC_SELECT_ARGTYPES AC_FUNC_VPRINTF AC_CHECK_FUNCS([atexit floor getcwd gethostbyname memset mkdir select socket]) +# Search for *-config +AC_PATH_PROG(SDL_CONFIG, sdl-config) +AC_PATH_PROG(PKG_CONFIG, pkg-config) +AC_PATH_PROG(CURL_CONFIG, curl-config) + # Checks for libraries AC_CHECK_LIB([pthread], [pthread_create], , -AC_MSG_ERROR([ *** Unable to find pthread library ])) +AC_MSG_ERROR([ *** Unable to find pthread library])) AC_CHECK_LIB([guichan], [gcnGuichanVersion], , -AC_MSG_ERROR([ *** Unable to find Guichan library (guichan.sf.net)])) - -#AC_CHECK_LIB([guichan_sdl], [gcnSDL], , -#AC_MSG_ERROR([ *** Unable to find Guichan SDL library (guichan.sf.net)])) +AC_MSG_ERROR([ *** Unable to find Guichan library (http://guichan.sf.net/)])) +AC_CHECK_HEADERS([guichan.hpp], , +AC_MSG_ERROR([ *** Guichan library found but cannot find headers (http://guichan.sf.net/)])) -#AC_CHECK_LIB([guichan_opengl], [gcnOpenGL], , -#AC_MSG_ERROR([ *** Unable to find Guichan OpenGL library (guichan.sf.net)])) +if test -n "$SDL_CONFIG"; then + LIBS="$LIBS `$SDL_CONFIG --libs`" + CPPFLAGS="$CPPFLAGS `$SDL_CONFIG --cflags`" +fi +AC_CHECK_LIB([SDL], [SDL_Init], , +AC_MSG_ERROR([ *** Unable to find SDL library (http://www.libsdl.org/)])) +AC_CHECK_HEADERS([SDL.h], , +AC_MSG_ERROR([ *** SDL library found but cannot find headers (http://www.libsdl.org/)])) AC_CHECK_LIB([physfs], [PHYSFS_init], , -AC_MSG_ERROR([ *** Unable to find PhysFS library (icculus.org/physfs/)])) +AC_MSG_ERROR([ *** Unable to find PhysFS library (http://icculus.org/physfs/)])) +AC_CHECK_HEADERS([physfs.h], , +AC_MSG_ERROR([ *** PhysFS library found but cannot find headers (http://icculus.org/physfs/)])) +if test -n "$CURL_CONFIG"; then + LIBS="$LIBS `$CURL_CONFIG --libs`" + CPPFLAGS="$CPPFLAGS `$CURL_CONFIG --cflags`" +fi AC_CHECK_LIB([curl], [curl_global_init], , AC_MSG_ERROR([ *** Unable to find CURL library (http://curl.haxx.se/)])) -CURL_LIBS=" `curl-config --libs`" -CURL_CFLAGS=" `curl-config --cflags` " -AC_SUBST(CURL_LIBS) -AC_SUBST(CURL_CFLAGS) +AC_CHECK_HEADERS([curl/curl.h], , +AC_MSG_ERROR([ *** CURL library found but cannot find headers (http://curl.haxx.se/)])) +if test -n "$PKG_CONFIG"; then + LIBS="$LIBS `$PKG_CONFIG --libs libxml-2.0`" + CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags libxml-2.0`" +fi AC_CHECK_LIB([xml2], [xmlInitParser], , -AC_MSG_ERROR([ *** Unable to find libxml2 library (xmlsoft.org)])) +AC_MSG_ERROR([ *** Unable to find libxml2 library (http://xmlsoft.org/)])) +AC_CHECK_HEADERS([libxml/xmlreader.h], , +AC_MSG_ERROR([ *** libxml2 library found but cannot find headers (http://xmlsoft.org/)])) -AC_CHECK_LIB(SDL_image, IMG_LoadPNG_RW, , -AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support -(http://www.libsdl.org/projects/SDL_image/)])) +AC_CHECK_LIB([SDL_image], [IMG_LoadPNG_RW], , +AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support (http://www.libsdl.org/projects/SDL_image/)])) -AC_CHECK_LIB(SDL_mixer, Mix_OpenAudio, , -AC_MSG_ERROR([ *** Unable to find SDL_mixer library -(http://www.libsdl.org/projects/SDL_mixer/)])) +AC_CHECK_LIB([guichan_sdl], [gcnSDL], , +AC_MSG_ERROR([ *** Unable to find Guichan SDL library (http://guichan.sf.net/)])) + +AC_CHECK_LIB([SDL_mixer], [Mix_OpenAudio], , +AC_MSG_ERROR([ *** Unable to find SDL_mixer library (http://www.libsdl.org/projects/SDL_mixer/)])) AC_CHECK_LIB([enet], [enet_initialize], , -AC_MSG_ERROR([ *** Unable to find enet library (enet.bespin.org)])) +AC_MSG_ERROR([ *** Unable to find enet library (http://enet.bespin.org/)])) AC_CHECK_LIB(png, png_write_info, , -AC_MSG_ERROR([ *** Unable to find png library])) +AC_MSG_ERROR([ *** Unable to find png library (http://www.libpng.org/)])) # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h]) -# Check for guichan headers -AC_CHECK_HEADERS([guichan.hpp], , -AC_MSG_ERROR([*** Library found but cannot find headers (guichan.sf.net) *** ])) - -AM_INIT_AUTOMAKE - # Option to enable OpenGL -AC_ARG_WITH(opengl,[ --with-opengl use OpenGL ] ) +AC_ARG_WITH(opengl, AS_HELP_STRING([--with-opengl],[use OpenGL (default is no)])) if test "x$with_opengl" == "xyes"; then - with_opengl=yes - OPENGL_CFLAGS=' -DUSE_OPENGL' - OPENGL_LIBS=' -lGL -lguichan_opengl' - AC_SUBST(OPENGL_CFLAGS) - AC_SUBST(OPENGL_LIBS) + AC_CHECK_LIB([GL], [glBegin], , + AC_MSG_ERROR([ *** Unable to find OpenGL library])) + AC_CHECK_LIB([guichan_opengl], [gcnOpenGL], , + AC_MSG_ERROR([ *** Unable to find Guichan OpenGL library (guichan.sf.net)])) + AC_DEFINE(USE_OPENGL, 1, [Defines if tmw should use an OpenGL display]) else with_opengl=no fi -# Search for sdl-config -AC_PATH_PROG(LIBSDL_CONFIG, sdl-config) - -if test -n "$LIBSDL_CONFIG"; then - LIBSDL_LIBS="`$LIBSDL_CONFIG --libs` -lSDL_image -lSDL_mixer" - LIBSDL_CFLAGS="`$LIBSDL_CONFIG --cflags`" - AC_SUBST(LIBSDL_LIBS) - AC_SUBST(LIBSDL_CFLAGS) - - AC_DEFINE_UNQUOTED(HAVE_LIBSDL, 1, - [Defines if your system has the LIBSDL library]) -else - AC_DEFINE_UNQUOTED(HAVE_LIBSDL, 0, - [Defines if your system has the LIBSDL library]) - AC_MSG_ERROR([Could not find sdl-config, check http://www.libsdl.org]) -fi - AC_CONFIG_FILES([ Makefile src/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 42e72829..13ec7308 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,5 @@ +AUTOMAKE_OPTIONS = subdir-objects + bin_PROGRAMS = tmw tmw_SOURCES = graphic/imagerect.h \ gui/browserbox.cpp \ @@ -240,9 +242,3 @@ tmw_SOURCES = graphic/imagerect.h \ INCLUDES = \ $(all_includes) \ -DTMW_DATADIR=\""$(pkgdatadir)/"\" - -# the library search path. -tmw_LDFLAGS = $(all_libraries) $(LIBSDL_RPATH) `pkg-config --libs libxml-2.0` -tmw_CXXFLAGS = -Wall -Werror $(OPENGL_CFLAGS) $(LIBSDL_CFLAGS) `pkg-config --cflags libxml-2.0` $(CURL_CFLAGS) -tmw_LDADD = $(LIBSDL_LIBS) -lguichan_sdl $(OPENGL_LIBS) $(CURL_LIBS) -tmw_TARGET = tmw -- cgit v1.2.3-70-g09d2 From afc770043be553998555e9ac1cffca68dc482d48 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 13 Aug 2006 11:36:36 +0000 Subject: Merged cleanups and content changes from the trunk. Also fixed compiling with OpenGL enabled. --- ChangeLog | 161 ++++++++++++-- src/Makefile.am | 2 + src/animatedsprite.cpp | 382 ++++++++++++++++++++++++++++++++ src/animatedsprite.h | 178 +++++++++++++++ src/animation.cpp | 387 +++------------------------------ src/animation.h | 135 +++--------- src/being.cpp | 169 +++++++------- src/being.h | 11 +- src/configuration.cpp | 56 +++-- src/engine.cpp | 15 +- src/game.cpp | 30 +-- src/gui/browserbox.h | 1 + src/gui/chat.cpp | 81 +++---- src/gui/chat.h | 9 +- src/gui/gui.cpp | 7 +- src/gui/setup_video.cpp | 1 + src/gui/updatewindow.cpp | 2 +- src/main.cpp | 29 +-- src/monster.cpp | 4 +- src/npc.cpp | 2 + src/openglgraphics.cpp | 2 + src/player.cpp | 47 +++- src/resources/image.h | 2 + src/resources/itemmanager.cpp | 4 +- src/resources/mapreader.cpp | 214 +++++++++--------- src/resources/openglsdlimageloader.cpp | 6 +- 26 files changed, 1086 insertions(+), 851 deletions(-) create mode 100644 src/animatedsprite.cpp create mode 100644 src/animatedsprite.h (limited to 'src/Makefile.am') diff --git a/ChangeLog b/ChangeLog index b1731b9f..8bf385c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,82 @@ +2006-08-13 Bjørn Lindeijer + + * src/openglgraphics.cpp, src/gui/browserbox.h, src/gui/gui.cpp, + src/gui/chat.cpp, src/resources/image.h: Added include main.h in order + to have USE_OPENGL defined correctly, since it is no longer passed as + a compiler parameter. + +2006-08-12 Philipp Sehmisch + + * data/maps/new_9-1.tmx.gz, data/maps/new_14-1.tmx.gz, + data/maps/new_15-1.tmx.gz, data/maps/new_16-1.tmx.gz: Fixed some + inaccessible areas. + +2006-08-07 Philipp Sehmisch + * data/maps/new_9-1.tmx.gz, data/maps/new_14-1.tmx.gz, + data/maps/new_15-1.tmx.gz, data/maps/new_16-1.tmx.gz, + data/graphics/images/minimap_new_9-1.png, + data/graphics/images/minimap_new_14-1.png, + data/graphics/images/minimap_new_15-1.png, + data/graphics/images/minimap_new_16-1.png: Added minimaps for woodland + maps. + +2006-08-07 Philipp Sehmisch + + * data/maps/new_1-1.tmx.gz, data/maps/new_14-1.tmx.gz, + data/maps/new_15-1.tmx.gz, data/maps/new_16-1.tmx.gz: Added a new + woodland map and a connection map between desert and woodland. + * data/graphics/woodland_ground.png: Added some new rocks. + +2006-08-07 Björn Steinbrink + + * src/game.cpp, src/gui/chat.h, src/gui/chat.cpp, src/main.cpp: A + bunch of cleanups. + 2006-08-06 Bjørn Lindeijer * INSTALL: Updated required Guichan to version 0.5.0. +2006-08-05 Björn Steinbrink + + * src/configuration.cpp, src/game.cpp, src/engine.cpp, src/player.cpp, + src/being.cpp, src/resources/mapreader.cpp, + src/resources/itemmanager.cpp: Some cleanups, mostly lowering + indentation. + * src/being.cpp: Small code cleanup. + 2006-08-04 Guillaume Melquiond * src/gui/char_select.cpp: Fixed character gender in selection dialog. +2006-08-04 Björn Steinbrink + + * src/animatedsprite.cpp: Fix enum being treated as string. + * src/animation.cpp: Small code cleanups. Removed unused headers. + * src/animatedsprite.cpp: Small code cleanup/lower indentation. + +2006-08-04 Bjørn Lindeijer + + * src/animatedsprite.cpp: Fixed presence of NULL actions. This is + doener's version of the fix, because it was more efficient in the more + common case. + +2006-08-04 Frode Lindeijer + + * data/graphics/tiles/desert_x3.png: Replaced the old cactus with + a nice new high-res one. + +2006-08-03 Bjørn Lindeijer + + * src/player.cpp, src/being.cpp, src/being.h: Removed three + setDirection(mDirection) calls by instead specifically setting the + current direction on the newly added animated sprite. The same might + be done for the action later. + * src/animatedsprite.h, src/animatedsprite.cpp: Since this class isn't + subclassed and has no virtual functions, make protected members + private. Also added a start of a reset function which could be a + solution to unsynchronized animated sprites. + * src/net/network.cpp: Fixed two delete/delete[] errors. + 2006-08-02 Guillaume Melquiond * configure.ac, src/Makefile.am: Put object files in subdirectories. @@ -37,10 +108,26 @@ * src/gui/gui.cpp, The Mana World.dev, tmw.cbp: Fixed compilation issues in windows. +2006-08-01 Philipp Sehmisch + + * src/animation.h, src/animation.cpp, src/animatedsprite.h, + src/animatedsprite.cpp, src/being.cpp: Animations and directions + are now passed and stored as enums and no longer as strings. + 2006-07-31 Bjørn Lindeijer * src/net/network.cpp: Corrected an off by one error in packet size. +2006-07-30 Björn Steinbrink + + * src/animatedsprite.h, src/animatedsprite.cpp: Unified the play + methods. + +2006-07-30 Philipp Sehmisch + + * data/maps/new_5-1.tmx.gz: Fixed two minor mapping errors (no new + walkmap required). + 2006-07-30 Bjørn Lindeijer * src/openglgraphics.cpp, src/game.cpp, src/main.cpp, @@ -74,6 +161,21 @@ Updated TMW to be compatible with Guichan 0.5.0 (merged from guichan-0.5.0 branch). +2006-07-29 Björn Steinbrink + + * src/animatedsprite.h, src/animatedsprite.cpp, src/animation.cpp: A + bunch of cleanups. + * src/animation.h, src/animatedsprite.cpp: Moved included from header + to source file. + +2006-07-28 Björn Steinbrink + + * src/npc.cpp, src/player.cpp, src/animatedsprite.h, src/animation.h, + src/being.cpp, src/main.cpp, src/monster.cpp, src/animatedsprite.cpp, + src/animation.cpp, src/Makefile.am, src/being.h: Moved AnimatedSprite + into its own files, removed useless includes. + * src/engine.cpp: Removed an unused var. + 2006-07-27 Eugenio Favalli * src/gui/main.cpp: Modified client version to be an int. @@ -81,20 +183,32 @@ 2006-07-26 Eugenio Favalli * src/gui/char_server.cpp, src/gui/char_sever.h, src/main.cpp, - src/net/loginhandler.cpp, src/net/loginhandler.h, tmw,cbp: Removed char - server selection dialog, and added character visualization in character - selection dialog. - -2006-07-25 Bjørn Lindeijer - - * src/gui/updatewindow.cpp: Fixed updating on Windows. - * src/net/beinghandler.cpp, src/net/network.cpp, configure.ac: Fixed - Linux compiling issues. - * src/configuration.cpp: Reduced amount of logging. - * src/log.cpp, src/log.h: Added support for writing log to standard - output. - * src/main.cpp: Reorganized initialization somewhat. - * src/resources/resourcemanager.cpp: Take into account singular form. + src/net/loginhandler.cpp, src/net/loginhandler.h, tmw,cbp: Removed + char server selection dialog, and added character visualization in + character selection dialog. + * data/graphics/sprites/Makefile.am, data/graphics/tiles/Makefile.am, + data/maps/Makefile.am, data/maps/new_13-1.tmx.gz: Added map with inside + of snow village buildings and fixed makefiles. + * src/being.cpp, src/being.h, src/player.cpp: Fixed direction and + action issues when changing appeareance, frames are still out of sync. + * data/maps/Makefile.am, data/maps/new_14-1.tmx.gz, + data/maps/new_9-1.tmx.gz: Added new woodland map by Crush and fixed + connection with the old one. + +2006-07-26 Bjørn Lindeijer + + * data/maps/new_4-1.tmx.gz: Fixes to the collision layer. + +2006-07-26 Frode Lindeijer + + * data/graphics/tiles/snowset.png, data/graphics/tiles/snow_x2.png, + data/graphics/tiles/snow_x3.png: Moved the lamppost, the rock and the + bench to seperate tall tilebitmaps. + * data/maps/new_11-1.tmx.gz: Improved the snow village map, main + changes are that the player can now walk better behind houses, + lampposts, rocks and benches. + * data/graphics/sprites/item003.png, data/graphics/sprites/item003.xml: + Added the leather shirt 2006-07-25 Eugenio Favalli @@ -113,6 +227,17 @@ tmw.cbp: Switched client to use enet and modified login sequence to work with the new protocol from tmwserv. +2006-07-25 Bjørn Lindeijer + + * src/gui/updatewindow.cpp: Fixed updating on Windows. + * src/net/beinghandler.cpp, src/net/network.cpp, configure.ac: Fixed + Linux compiling issues. + * src/configuration.cpp: Reduced amount of logging. + * src/log.cpp, src/log.h: Added support for writing log to standard + output. + * src/main.cpp: Reorganized initialization somewhat. + * src/resources/resourcemanager.cpp: Take into account singular form. + 2006-07-24 Bjørn Lindeijer * src/main.cpp: Fixed the loading of updates and made skipping the @@ -126,10 +251,10 @@ 2006-07-24 Frode Lindeijer * data/graphics/sprites/npcs.png: Added the organdealer to - the NPCs + the NPCs. * data/graphics/sprites/player_male_base.png, data/graphics/sprites/player_female_base.png: Fixed some - transparency issues + transparency issues. 2006-07-24 Eugenio Favalli @@ -144,7 +269,7 @@ * data/help/about.txt, data/help/changes.txt, data/help/commands.txt, data/help/header.txt, data/help/index.txt, data/help/skills.txt, data/help/support.txt, data/help/team.txt: Forced to use UNIX end of - line character. + line character. * src/net/equipmenthandler.cpp: Equipments now use real slot positions. 2006-07-24 Bjørn Lindeijer @@ -230,7 +355,7 @@ 2006-07-17 Frode Lindeijer - * Added shorts to items.png + * data/graphics/sprites/items.png: Added shorts' icon to items.png 2006-07-12 Bjørn Lindeijer diff --git a/src/Makefile.am b/src/Makefile.am index 13ec7308..42671f64 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -183,6 +183,8 @@ tmw_SOURCES = graphic/imagerect.h \ resources/buddylist.cpp \ utils/dtor.h \ utils/tostring.h \ + animatedsprite.cpp \ + animatedsprite.h \ animation.cpp \ animation.h \ base64.cpp \ diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp new file mode 100644 index 00000000..d1201042 --- /dev/null +++ b/src/animatedsprite.cpp @@ -0,0 +1,382 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: animation.cpp 2430 2006-07-24 00:13:24Z b_lindeijer $ + */ + +#include "animatedsprite.h" + +#include "animation.h" +#include "graphics.h" +#include "log.h" + +#include "resources/resourcemanager.h" +#include "resources/spriteset.h" + +AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): + mAction(NULL), + mDirection(DIRECTION_DOWN), + mLastTime(0), + mSpeed(1.0f) +{ + int size; + ResourceManager *resman = ResourceManager::getInstance(); + char *data = (char*)resman->loadFile(animationFile.c_str(), size); + + if (!data) { + logger->error("Animation: Could not find " + animationFile + "!"); + } + + xmlDocPtr doc = xmlParseMemory(data, size); + free(data); + + if (!doc) { + logger->error("Animation: Error while parsing animation definition file!"); + } + + xmlNodePtr node = xmlDocGetRootElement(doc); + if (!node || !xmlStrEqual(node->name, BAD_CAST "sprite")) { + logger->error("Animation: this is not a valid animation definition file!"); + } + + // Get the variant + int variant_num = getProperty(node, "variants", 0); + int variant_offset = getProperty(node, "variant_offset", 0); + + if (variant_num > 0 && variant < variant_num ) { + variant_offset *= variant; + } else { + variant_offset = 0; + } + + for (node = node->xmlChildrenNode; node != NULL; node = node->next) + { + if (xmlStrEqual(node->name, BAD_CAST "imageset")) + { + int width = getProperty(node, "width", 0); + int height = getProperty(node, "height", 0); + std::string name = getProperty(node, "name", ""); + std::string imageSrc = getProperty(node, "src", ""); + + Spriteset *spriteset = + resman->getSpriteset(imageSrc, width, height); + + if (!spriteset) { + logger->error("Couldn't load spriteset!"); + } + + mSpritesets[name] = spriteset; + } + // get action + else if (xmlStrEqual(node->name, BAD_CAST "action")) + { + std::string name = getProperty(node, "name", ""); + std::string imageset = getProperty(node, "imageset", ""); + + if (name.empty()) + { + logger->log("Warning: unnamed action in %s", + animationFile.c_str()); + } + if (mSpritesets.find(imageset) == mSpritesets.end()) { + logger->log("Warning: imageset \"%s\" not defined in %s", + imageset.c_str(), + animationFile.c_str()); + + // skip loading animations + continue; + } + + Action *action = new Action(); + + action->setSpriteset(mSpritesets[imageset]); + mActions[makeSpriteAction(name)] = action; + + // get animations + for (xmlNodePtr animationNode = node->xmlChildrenNode; + animationNode != NULL; + animationNode = animationNode->next) + { + // We're only interested in animations + if (!xmlStrEqual(animationNode->name, BAD_CAST "animation")) + continue; + + std::string dir = getProperty(animationNode, "direction", ""); + Animation *animation = new Animation(); + action->setAnimation(makeSpriteDirection(dir), animation); + + // Get animation phases + for (xmlNodePtr phaseNode = animationNode->xmlChildrenNode; + phaseNode != NULL; + phaseNode = phaseNode->next) + { + int delay = getProperty(phaseNode, "delay", 0); + + if (xmlStrEqual(phaseNode->name, BAD_CAST "frame")) + { + int index = getProperty(phaseNode, "index", -1); + int offsetX = getProperty(phaseNode, "offsetX", 0); + int offsetY = getProperty(phaseNode, "offsetY", 0); + + offsetY -= mSpritesets[imageset]->getHeight() - 32; + offsetX -= mSpritesets[imageset]->getWidth() / 2 - 16; + animation->addPhase(index + variant_offset, delay, + offsetX, offsetY); + } + else if (xmlStrEqual(phaseNode->name, BAD_CAST "sequence")) + { + int start = getProperty(phaseNode, "start", 0); + int end = getProperty(phaseNode, "end", 0); + int offsetY = -mSpritesets[imageset]->getHeight() + 32; + int offsetX = -mSpritesets[imageset]->getWidth() / 2 + 16; + while (end >= start) + { + animation->addPhase(start + variant_offset, + delay, offsetX, offsetY); + start++; + } + } + } // for phaseNode + } // for animationNode + } // if "" else if "" + } // for node + + // Complete missing actions + substituteAction(ACTION_WALK, ACTION_STAND); + substituteAction(ACTION_WALK, ACTION_RUN); + substituteAction(ACTION_ATTACK, ACTION_STAND); + substituteAction(ACTION_ATTACK_SWING, ACTION_ATTACK); + substituteAction(ACTION_ATTACK_STAB, ACTION_ATTACK_SWING); + substituteAction(ACTION_ATTACK_BOW, ACTION_ATTACK_STAB); + substituteAction(ACTION_ATTACK_THROW, ACTION_ATTACK_SWING); + substituteAction(ACTION_CAST_MAGIC, ACTION_ATTACK_SWING); + substituteAction(ACTION_USE_ITEM, ACTION_CAST_MAGIC); + substituteAction(ACTION_SIT, ACTION_STAND); + substituteAction(ACTION_SLEEP, ACTION_SIT); + substituteAction(ACTION_HURT, ACTION_STAND); + substituteAction(ACTION_DEAD, ACTION_HURT); + + // Play the stand animation by default + play(ACTION_STAND); + + xmlFreeDoc(doc); +} + +int +AnimatedSprite::getProperty(xmlNodePtr node, const char* name, int def) +{ + int &ret = def; + + xmlChar *prop = xmlGetProp(node, BAD_CAST name); + if (prop) { + ret = atoi((char*)prop); + xmlFree(prop); + } + + return ret; +} + +std::string +AnimatedSprite::getProperty(xmlNodePtr node, const char* name, + const std::string& def) +{ + xmlChar *prop = xmlGetProp(node, BAD_CAST name); + if (prop) { + std::string val = (char*)prop; + xmlFree(prop); + return val; + } + + return def; +} + +void +AnimatedSprite::substituteAction(SpriteAction complete, + SpriteAction with) +{ + if (mActions.find(complete) == mActions.end()) + { + ActionIterator i = mActions.find(with); + if (i != mActions.end()) { + mActions[complete] = i->second; + } + } +} + +AnimatedSprite::~AnimatedSprite() +{ + for (SpritesetIterator i = mSpritesets.begin(); i != mSpritesets.end(); ++i) + { + i->second->decRef(); + } + mSpritesets.clear(); +} + +void +AnimatedSprite::reset() +{ + // Reset all defined actions (because of aliases, some will be resetted + // multiple times) + for (ActionIterator i = mActions.begin(); i != mActions.end(); ++i) + { + //TODO: If resetting everything is really a nice way of fixing the + // synchronization issues, finish implementing this. + //i->second->reset(); + } +} + +void +AnimatedSprite::play(SpriteAction action, int time) +{ + ActionIterator i = mActions.find(action); + + if (i == mActions.end()) + { + logger->log("Warning: no action \"%u\" defined!", action); + mAction = NULL; + return; + } + + if (mAction != i->second) + { + mAction = i->second; + mLastTime = 0; + } + + if (!mAction || !time) + mSpeed = 1.0f; + else { + int animationLength = mAction->getAnimation(mDirection)->getLength(); + mSpeed = (float) animationLength / time; + } +} + +void +AnimatedSprite::update(int time) +{ + // Avoid freaking out at first frame or when tick_time overflows + if (time < mLastTime || mLastTime == 0) + mLastTime = time; + + // If not enough time have passed yet, do nothing + if (time > mLastTime && mAction) + { + Animation *animation = mAction->getAnimation(mDirection); + animation->update((unsigned int)((time - mLastTime) * mSpeed)); + mLastTime = time; + } +} + +bool +AnimatedSprite::draw(Graphics* graphics, Sint32 posX, Sint32 posY) const +{ + if (!mAction) + return false; + + Animation *animation = mAction->getAnimation(mDirection); + int phase = animation->getCurrentPhase(); + if (phase < 0) + return false; + + Spriteset *spriteset = mAction->getSpriteset(); + Image *image = spriteset->get(phase); + Sint32 offsetX = animation->getOffsetX(); + Sint32 offsetY = animation->getOffsetY(); + return graphics->drawImage(image, posX + offsetX, posY + offsetY); +} + +int +AnimatedSprite::getWidth() const +{ + return mAction ? mAction->getSpriteset()->getWidth() : 0; +} + +int +AnimatedSprite::getHeight() const +{ + return mAction ? mAction->getSpriteset()->getHeight() : 0; +} + +SpriteAction +AnimatedSprite::makeSpriteAction(const std::string& action) +{ + if (action == "stand") { + return ACTION_STAND; + } + else if (action == "walk") { + return ACTION_WALK; + } + else if (action == "run") { + return ACTION_RUN; + } + else if (action == "attack") { + return ACTION_ATTACK; + } + else if (action == "attack_swing") { + return ACTION_ATTACK_SWING; + } + else if (action == "attack_stab") { + return ACTION_ATTACK_STAB; + } + else if (action == "attack_bow") { + return ACTION_ATTACK_BOW; + } + else if (action == "attack_throw") { + return ACTION_ATTACK_THROW; + } + else if (action == "cast_magic") { + return ACTION_CAST_MAGIC; + } + else if (action == "use_item") { + return ACTION_USE_ITEM; + } + else if (action == "sit") { + return ACTION_SIT; + } + else if (action == "sleep") { + return ACTION_SLEEP; + } + else if (action == "hurt") { + return ACTION_HURT; + } + else if (action == "dead") { + return ACTION_DEAD; + } + else { + return ACTION_DEFAULT; + } +} + +SpriteDirection +AnimatedSprite::makeSpriteDirection(const std::string& direction) +{ + if (direction == "up") { + return DIRECTION_UP; + } + else if (direction == "left") { + return DIRECTION_LEFT; + } + else if (direction == "right") { + return DIRECTION_RIGHT; + } + else { + return DIRECTION_DOWN; + } +} diff --git a/src/animatedsprite.h b/src/animatedsprite.h new file mode 100644 index 00000000..89394d6c --- /dev/null +++ b/src/animatedsprite.h @@ -0,0 +1,178 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: animation.h 2430 2006-07-24 00:13:24Z b_lindeijer $ + */ + +#ifndef _TMW_ANIMATEDSPRITE_H +#define _TMW_ANIMATEDSPRITE_H + +#include +#include +#include + +#include + +class Action; +class Graphics; +class Spriteset; + +enum SpriteAction +{ + ACTION_DEFAULT = 0, + ACTION_STAND, + ACTION_WALK, + ACTION_RUN, + ACTION_ATTACK, + ACTION_ATTACK_SWING, + ACTION_ATTACK_STAB, + ACTION_ATTACK_BOW, + ACTION_ATTACK_THROW, + ACTION_CAST_MAGIC, + ACTION_USE_ITEM, + ACTION_SIT, + ACTION_SLEEP, + ACTION_HURT, + ACTION_DEAD +}; + +enum SpriteDirection +{ + DIRECTION_DOWN = 0, + DIRECTION_UP, + DIRECTION_LEFT, + DIRECTION_RIGHT +}; + +/** + * Defines a class to load an animation. + */ +class AnimatedSprite +{ + public: + /** + * Constructor. + */ + AnimatedSprite(const std::string& animationFile, int variant); + + /** + * Destructor. + */ + ~AnimatedSprite(); + + /** + * Resets the animated sprite. This is used to synchronize several + * animated sprites. + */ + void + reset(); + + /** + * Plays an action using the current direction that will have a + * duration of the specified time, 0 means default. + */ + void + play(SpriteAction action, int time = 0); + + /** + * Inform the animation of the passed time so that it can output the + * correct animation phase. + */ + void update(int time); + + /** + * Draw the current animation phase at the coordinates given in screen + * pixels. + */ + bool + draw(Graphics* graphics, Sint32 posX, Sint32 posY) const; + + /** + * gets the width in pixels of the current animation phase. + */ + int + getWidth() const; + + /** + * gets the height in pixels of the current animation phase. + */ + int + getHeight() const; + + /** + * Sets the direction. + */ + void + setDirection(SpriteDirection direction) + { + mDirection = direction; + } + + private: + /** + * When there are no animations defined for the action "complete", its + * animations become a copy of those of the action "with". + */ + void + substituteAction(SpriteAction complete, SpriteAction with); + + /** + * Gets an integer property from an xmlNodePtr. + * + * TODO: Same function is present in MapReader. Should probably be + * TODO: shared in a static utility class. + */ + static int + getProperty(xmlNodePtr node, const char *name, int def); + + /** + * Gets a string property from an xmlNodePtr. + */ + static std::string + getProperty(xmlNodePtr node, const char *name, const std::string &def); + + /** + * Converts a string into a SpriteAction enum. + */ + static SpriteAction + makeSpriteAction(const std::string &action); + + /** + * Converts a string into a SpriteDirection enum. + */ + static SpriteDirection + makeSpriteDirection(const std::string &direction); + + + typedef std::map Spritesets; + typedef Spritesets::iterator SpritesetIterator; + + typedef std::map Actions; + typedef Actions::iterator ActionIterator; + + Spritesets mSpritesets; + Actions mActions; + Action *mAction; + SpriteDirection mDirection; + int mLastTime; + float mSpeed; +}; + +#endif diff --git a/src/animation.cpp b/src/animation.cpp index 313fd25c..1213d0d6 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -23,13 +23,9 @@ #include "animation.h" -#include +#include -#include "log.h" - -#include "resources/image.h" -#include "resources/resourcemanager.h" -#include "resources/spriteset.h" +#include "utils/dtor.h" Animation::Animation(): mTime(0) @@ -41,17 +37,20 @@ void Animation::update(unsigned int time) { mTime += time; - if (!mAnimationPhases.empty()) + if (mAnimationPhases.empty()) + return; + + unsigned int delay = iCurrentPhase->delay; + if (!delay) + return; + + while (mTime > delay) { - unsigned int delay = iCurrentPhase->delay; - while (mTime > delay && delay > 0) + mTime -= delay; + iCurrentPhase++; + if (iCurrentPhase == mAnimationPhases.end()) { - mTime -= delay; - iCurrentPhase++; - if (iCurrentPhase == mAnimationPhases.end()) - { - iCurrentPhase = mAnimationPhases.begin(); - } + iCurrentPhase = mAnimationPhases.begin(); } } } @@ -59,25 +58,15 @@ Animation::update(unsigned int time) int Animation::getCurrentPhase() const { - if (mAnimationPhases.empty()) - { - return -1; - } - else - { - return iCurrentPhase->image; - } + return mAnimationPhases.empty() ? -1 : iCurrentPhase->image; } void Animation::addPhase(int image, unsigned int delay, int offsetX, int offsetY) { //add new phase to animation list - AnimationPhase newPhase; - newPhase.image = image; - newPhase.delay = delay; - newPhase.offsetX = offsetX; - newPhase.offsetY = offsetY; + AnimationPhase newPhase = { image, delay, offsetX, offsetY }; + mAnimationPhases.push_back(newPhase); //reset animation circle iCurrentPhase = mAnimationPhases.begin(); @@ -86,14 +75,14 @@ Animation::addPhase(int image, unsigned int delay, int offsetX, int offsetY) int Animation::getLength() { + if (mAnimationPhases.empty()) + return 0; + std::list::iterator i; int length = 0; - if (!mAnimationPhases.empty()) + for (i = mAnimationPhases.begin(); i != mAnimationPhases.end(); i++) { - for (i = mAnimationPhases.begin(); i != mAnimationPhases.end(); i++) - { - length += (*i).delay; - } + length += i->delay; } return length; } @@ -105,352 +94,32 @@ Action::Action(): Action::~Action() { - for (AnimationIterator i = mAnimations.begin(); i != mAnimations.end(); i++) - { - delete i->second; - } + std::for_each(mAnimations.begin(), mAnimations.end(), make_dtor(mAnimations)); mAnimations.clear(); } Animation* -Action::getAnimation(const std::string& direction) const +Action::getAnimation(int direction) const { - Animation *animation = NULL; Animations::const_iterator i = mAnimations.find(direction); // When the direction isn't defined, try the default if (i == mAnimations.end()) { - i = mAnimations.find("default"); + i = mAnimations.find(0); } - if (i != mAnimations.end()) - { - animation = i->second; - } - - return animation; + return (i == mAnimations.end()) ? NULL : i->second; } void -Action::setAnimation(const std::string& direction, Animation *animation) +Action::setAnimation(int direction, Animation *animation) { // Set first direction as default direction if (mAnimations.empty()) { - mAnimations["default"] = animation; + mAnimations[0] = animation; } mAnimations[direction] = animation; } - - -AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): - mAction(NULL), - mDirection("down"), - mLastTime(0), - mSpeed(1.0f) -{ - int size; - ResourceManager *resman = ResourceManager::getInstance(); - char *data = (char*)resman->loadFile(animationFile.c_str(), size); - - if (!data) { - logger->error("Animation: Could not find " + animationFile + "!"); - } - - xmlDocPtr doc = xmlParseMemory(data, size); - free(data); - - if (!doc) - { - logger->error("Animation: Error while parsing animation definition file!"); - return; - } - - xmlNodePtr node = xmlDocGetRootElement(doc); - if (!node || !xmlStrEqual(node->name, BAD_CAST "sprite")) - { - logger->error("Animation: this is not a valid animation definition file!"); - return; - } - - // Get the variant - int variant_num = getProperty(node, "variants", 0); - int variant_offset = getProperty(node, "variant_offset", 0); - - if (variant_num > 0 && variant < variant_num ) - { - variant_offset *= variant; - } - else - { - variant_offset = 0; - } - - for (node = node->xmlChildrenNode; node != NULL; node = node->next) - { - if (xmlStrEqual(node->name, BAD_CAST "imageset")) - { - int width = getProperty(node, "width", 0); - int height = getProperty(node, "height", 0); - std::string name = getProperty(node, "name", ""); - std::string imageSrc = getProperty(node, "src", ""); - - Spriteset *spriteset = - resman->getSpriteset(imageSrc, width, height); - - if (!spriteset) - { - logger->error("Couldn't load spriteset!"); - } - else - { - mSpritesets[name] = spriteset; - } - } - // get action - else if (xmlStrEqual(node->name, BAD_CAST "action")) - { - std::string name = getProperty(node, "name", ""); - std::string imageset = getProperty(node, "imageset", ""); - - if (name.length() == 0) - { - logger->log("Warning: unnamed action in %s", - animationFile.c_str()); - } - - Action *action = new Action(); - - if (mSpritesets.find(imageset) != mSpritesets.end()) - { - action->setSpriteset(mSpritesets[imageset]); - mActions[name] = action; - } - else - { - logger->log("Warning: imageset \"%s\" not defined in %s", - imageset.c_str(), - animationFile.c_str()); - - // Discard action and skip loading animations - delete action; - continue; - } - - // get animations - for (xmlNodePtr animationNode = node->xmlChildrenNode; - animationNode != NULL; - animationNode = animationNode->next) - { - if (xmlStrEqual(animationNode->name, BAD_CAST "animation")) - { - std::string direction = - getProperty(animationNode, "direction", ""); - - Animation *animation = new Animation(); - - // Get animation phases - for (xmlNodePtr phaseNode = animationNode->xmlChildrenNode; - phaseNode != NULL; - phaseNode = phaseNode->next) - { - int delay = getProperty(phaseNode, "delay", 0); - - if (xmlStrEqual(phaseNode->name, BAD_CAST "frame")) - { - int index = getProperty(phaseNode, "index", -1); - int offsetX = getProperty(phaseNode, "offsetX", 0); - int offsetY = getProperty(phaseNode, "offsetY", 0); - - offsetY = offsetY - mSpritesets[imageset]->getHeight() + 32; - offsetX = offsetX - mSpritesets[imageset]->getWidth() / 2 + 16; - animation->addPhase(index + variant_offset, delay, - offsetX, offsetY); - } - else if (xmlStrEqual(phaseNode->name, BAD_CAST "sequence")) - { - int start = getProperty(phaseNode, "start", 0); - int end = getProperty(phaseNode, "end", 0); - int offsetY = 0 - mSpritesets[imageset]->getHeight() + 32; - int offsetX = 0 - mSpritesets[imageset]->getWidth() / 2 + 16; - while (end >= start) - { - animation->addPhase(start + variant_offset, - delay, offsetX, offsetY); - start++; - } - } - } // for phaseNode - action->setAnimation(direction, animation); - } // if "" - } // for animationNode - } // if "" else if "" - } // for node - - // Complete missing actions - substituteAction("walk", "stand"); - substituteAction("walk", "run"); - substituteAction("attack", "stand"); - substituteAction("attack_swing", "attack"); - substituteAction("attack_stab", "attack_swing"); - substituteAction("attack_bow", "attack_stab"); - substituteAction("attack_throw", "attack_swing"); - substituteAction("cast_magic", "attack_swing"); - substituteAction("use_item", "cast_magic"); - substituteAction("sit", "stand"); - substituteAction("sleeping", "sit"); - substituteAction("hurt", "stand"); - substituteAction("dead", "hurt"); - - // Play the stand animation by default - play("stand"); - - xmlFreeDoc(doc); -} - -int -AnimatedSprite::getProperty(xmlNodePtr node, const char* name, int def) -{ - xmlChar *prop = xmlGetProp(node, BAD_CAST name); - if (prop) { - int val = atoi((char*)prop); - xmlFree(prop); - return val; - } - else { - return def; - } -} - -std::string -AnimatedSprite::getProperty(xmlNodePtr node, const char* name, - const std::string& def) -{ - xmlChar *prop = xmlGetProp(node, BAD_CAST name); - if (prop) { - std::string val = (char*)prop; - xmlFree(prop); - return val; - } - else { - return def; - } -} - -void -AnimatedSprite::substituteAction(const std::string& complete, - const std::string& with) -{ - if (mActions.find(complete) == mActions.end()) - { - mActions[complete] = mActions[with]; - } -} - -AnimatedSprite::~AnimatedSprite() -{ - for (SpritesetIterator i = mSpritesets.begin(); i != mSpritesets.end(); ++i) - { - i->second->decRef(); - } - mSpritesets.clear(); -} - -void -AnimatedSprite::play(const std::string& action) -{ - Actions::iterator iAction; - iAction = mActions.find(action); - - if (iAction == mActions.end()) - { - logger->log("Warning: no action \"%s\" defined!", action.c_str()); - mAction = NULL; - return; - } - - if (mAction != iAction->second) - { - mAction = iAction->second; - mLastTime = 0; - } - - mSpeed = 1.0f; -} - -void -AnimatedSprite::play(const std::string& action, int time) -{ - play(action); - - if (mAction != NULL) - { - Animation *animation = mAction->getAnimation(mDirection); - int animationLength = animation->getLength(); - mSpeed = (float) animationLength / time; - } -} - -void -AnimatedSprite::update(int time) -{ - // Avoid freaking out at first frame or when tick_time overflows - if (time < mLastTime || mLastTime == 0) mLastTime = time; - - // If not enough time have passed yet, do nothing - if (time > mLastTime) - { - if (mAction != NULL) - { - Animation *animation = mAction->getAnimation(mDirection); - animation->update((unsigned int)((time - mLastTime) * mSpeed)); - mLastTime = time; - } - } -} - -bool -AnimatedSprite::draw(Graphics* graphics, Sint32 posX, Sint32 posY) const -{ - if (mAction != NULL) - { - Animation *animation = mAction->getAnimation(mDirection); - - if (animation->getCurrentPhase() >= 0) - { - Spriteset *spriteset = mAction->getSpriteset(); - Image *image = spriteset->get(animation->getCurrentPhase()); - Sint32 offsetX = animation->getOffsetX(); - Sint32 offsetY = animation->getOffsetY(); - return graphics->drawImage(image, posX + offsetX, posY + offsetY); - } - } - - return false; -} - -int -AnimatedSprite::getWidth() const -{ - if (mAction != NULL) - { - Spriteset *spriteset = mAction->getSpriteset(); - return spriteset->getWidth(); - } - - return 0; -} - -int -AnimatedSprite::getHeight() const -{ - if (mAction != NULL) - { - Spriteset *spriteset = mAction->getSpriteset(); - return spriteset->getHeight(); - } - - return 0; -} diff --git a/src/animation.h b/src/animation.h index c5adb873..c5b277b7 100644 --- a/src/animation.h +++ b/src/animation.h @@ -26,12 +26,9 @@ #include #include -#include #include -#include "graphics.h" - class Image; class Spriteset; @@ -58,16 +55,32 @@ class Animation */ Animation(); - void addPhase(int image, unsigned int delay, int offsetX, int offsetY); + void + addPhase(int image, unsigned int delay, int offsetX, int offsetY); + + void + update(unsigned int time); - void update(unsigned int time); + int + getCurrentPhase() const; - int getCurrentPhase() const; + /** + * Returns the x offset of the current frame. + */ + int + getOffsetX() const { return (*iCurrentPhase).offsetX; }; - int getOffsetX() const { return (*iCurrentPhase).offsetX; }; - int getOffsetY() const { return (*iCurrentPhase).offsetY; }; + /** + * Returns the y offset of the current frame. + */ + int + getOffsetY() const { return (*iCurrentPhase).offsetY; }; - int getLength(); + /** + * Returns the length of this animation. + */ + int + getLength(); protected: std::list mAnimationPhases; @@ -104,114 +117,16 @@ class Action getSpriteset() const { return mSpriteset; } void - setAnimation(const std::string& direction, Animation *animation); + setAnimation(int direction, Animation *animation); Animation* - getAnimation(const std::string& direction) const; + getAnimation(int direction) const; protected: Spriteset *mSpriteset; - typedef std::map Animations; + typedef std::map Animations; typedef Animations::iterator AnimationIterator; Animations mAnimations; }; -/** - * Defines a class to load an animation. - */ -class AnimatedSprite -{ - public: - /** - * Constructor. - */ - AnimatedSprite(const std::string& animationFile, int variant); - - /** - * Destructor. - */ - ~AnimatedSprite(); - - /** - * Sets a new action using the current direction. - */ - void - play(const std::string& action); - - /** - * Plays an action in a specified time. - */ - void - play(const std::string& action, int time); - - /** - * Inform the animation of the passed time so that it can output the - * correct animation phase. - */ - void update(int time); - - /** - * Draw the current animation phase at the coordinates given in screen - * pixels. - */ - bool - draw(Graphics* graphics, Sint32 posX, Sint32 posY) const; - - /** - * gets the width in pixels of the current animation phase. - */ - int - getWidth() const; - - /** - * gets the height in pixels of the current animation phase. - */ - int - getHeight() const; - - /** - * Sets the direction. - */ - void - setDirection(const std::string& direction) - { - mDirection = direction; - } - - protected: - /** - * When there are no animations defined for the action "complete", its - * animations become a copy of those of the action "with". - */ - void - substituteAction(const std::string& complete, - const std::string& with); - - typedef std::map Spritesets; - typedef Spritesets::iterator SpritesetIterator; - Spritesets mSpritesets; - typedef std::map Actions; - Actions mActions; - Action *mAction; - std::string mDirection; - int mLastTime; - float mSpeed; - - private: - /** - * Gets an integer property from an xmlNodePtr. - * - * TODO: Same function is present in MapReader. Should probably be - * TODO: shared in a static utility class. - */ - static int - getProperty(xmlNodePtr node, const char* name, int def); - - /** - * Gets a string property from an xmlNodePtr. - */ - static std::string - getProperty(xmlNodePtr node, const char* name, const std::string& def); -}; - #endif diff --git a/src/being.cpp b/src/being.cpp index 8a55f2e2..1ca8929a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -22,6 +22,9 @@ */ #include "being.h" +#include + +#include "animatedsprite.h" #include "equipment.h" #include "game.h" #include "graphics.h" @@ -32,6 +35,7 @@ #include "gui/gui.h" +#include "utils/dtor.h" #include "utils/tostring.h" extern Spriteset *emotionset; @@ -65,14 +69,7 @@ Being::Being(Uint32 id, Uint16 job, Map *map): Being::~Being() { - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i] != NULL) - { - delete mSprites[i]; - } - } - + std::for_each(mSprites.begin(), mSprites.end(), make_dtor(mSprites)); clearPath(); setMap(NULL); } @@ -164,66 +161,65 @@ Being::setMap(Map *map) } void -Being::setAction(Action action) +Being::setAction(Uint8 action) { - if (action != mAction) + SpriteAction currentAction = ACTION_STAND; + switch (action) { - std::string currentAction = "stand"; - switch (action) - { - case WALK: - currentAction = "walk"; - break; - case SIT: - currentAction = "sit"; - break; - case ATTACK: - if (getType() == MONSTER) - { - currentAction = "dead"; - }else{ - switch (getWeapon()) - { - case 2: - currentAction = "attack_bow"; - break; - case 1: - currentAction = "attack_stab"; - break; - case 0: - currentAction = "attack"; - break; - } - }; - break; - case MONSTER_ATTACK: - currentAction = "attack"; - break; - case DEAD: - currentAction = "dead"; - break; - default: - currentAction = "stand"; - break; - } - - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i] != NULL) + case WALK: + currentAction = ACTION_WALK; + break; + case SIT: + currentAction = ACTION_SIT; + break; + case ATTACK: + if (getType() == MONSTER) { - if (currentAction == "attack" || - currentAction == "attack_stab" || - currentAction == "attack_bow") - { - mSprites[i]->play(currentAction, mAttackSpeed); - } - else + currentAction = ACTION_DEAD; + } + else { + switch (getWeapon()) { - mSprites[i]->play(currentAction); + case 2: + currentAction = ACTION_ATTACK_BOW; + break; + case 1: + currentAction = ACTION_ATTACK_STAB; + break; + case 0: + currentAction = ACTION_ATTACK; + break; } - } + }; + break; + case MONSTER_ATTACK: + currentAction = ACTION_ATTACK; + break; + case DEAD: + currentAction = ACTION_DEAD; + break; + default: + currentAction = ACTION_STAND; + break; + } + + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (!mSprites[i]) + continue; + + if (currentAction == ACTION_ATTACK || + currentAction == ACTION_ATTACK_STAB || + currentAction == ACTION_ATTACK_BOW) + { + mSprites[i]->play(currentAction, mAttackSpeed); + } + else + { + mSprites[i]->play(currentAction); } } + mAction = action; } @@ -231,29 +227,37 @@ void Being::setDirection(Uint8 direction) { mDirection = direction; - std::string dir; + SpriteDirection dir = getSpriteDirection(); - if (direction & UP) + for (int i = 0; i < VECTOREND_SPRITE; i++) { - dir = "up"; + if (mSprites[i] != NULL) + mSprites[i]->setDirection(dir); } - else if (direction & RIGHT) +} + +SpriteDirection +Being::getSpriteDirection() const +{ + SpriteDirection dir; + + if (mDirection & UP) { - dir = "right"; + dir = DIRECTION_UP; } - else if (direction & DOWN) + else if (mDirection & RIGHT) { - dir = "down"; + dir = DIRECTION_RIGHT; } - else + else if (mDirection & DOWN) { - dir = "left"; + dir = DIRECTION_DOWN; } - - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i] != NULL) mSprites[i]->setDirection(dir); + else { + dir = DIRECTION_LEFT; } + + return dir; } void @@ -329,10 +333,6 @@ Being::draw(Graphics *graphics, int offsetX, int offsetY) int px = mPx + offsetX; int py = mPy + offsetY; - //what are these two lines good for? please add a comment. - unsigned char dir = 0; - while (!(mDirection & (1 << dir))) dir++; - for (int i = 0; i < VECTOREND_SPRITE; i++) { if (mSprites[i] != NULL) @@ -345,14 +345,13 @@ Being::draw(Graphics *graphics, int offsetX, int offsetY) void Being::drawEmotion(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) { - int px = mPx + offsetX; - int py = mPy + offsetY; + if (!mEmotion) + return; - if (mEmotion) - { - graphics->drawImage(emotionset->get(mEmotion - 1), - px + 3, py - 60); - } + int px = mPx + offsetX + 3; + int py = mPy + offsetY - 60; + + graphics->drawImage(emotionset->get(mEmotion - 1), px, py); } void diff --git a/src/being.h b/src/being.h index 478bc018..0735efe9 100644 --- a/src/being.h +++ b/src/being.h @@ -29,13 +29,14 @@ #include #include -#include "animation.h" #include "sprite.h" #include "map.h" +#include "animatedsprite.h" #define NR_HAIR_STYLES 7 #define NR_HAIR_COLORS 10 +class AnimatedSprite; class Equipment; class Item; class Map; @@ -290,7 +291,7 @@ class Being : public Sprite /** * Sets the current action. */ - void setAction(Action action); + void setAction(Uint8 action); /** * Sets the current direction. @@ -347,6 +348,12 @@ class Being : public Sprite */ int getOffset(char pos, char neg) const; + /** + * Returns the sprite direction of this being. + */ + SpriteDirection + getSpriteDirection() const; + Uint32 mId; /**< Unique sprite id */ Uint16 mWeapon; /**< Weapon picture id */ Uint16 mWalkSpeed; /**< Walking speed */ diff --git a/src/configuration.cpp b/src/configuration.cpp index 9c3ff008..8bb0b8ca 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -57,18 +57,18 @@ void Configuration::init(const std::string &filename) for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual(node->name, BAD_CAST "option")) - { - xmlChar *name = xmlGetProp(node, BAD_CAST "name"); - xmlChar *value = xmlGetProp(node, BAD_CAST "value"); + if (!xmlStrEqual(node->name, BAD_CAST "option")) + continue; - if (name && value) { - mOptions[(const char*)name] = (const char*)value; - } + xmlChar *name = xmlGetProp(node, BAD_CAST "name"); + xmlChar *value = xmlGetProp(node, BAD_CAST "value"); - if (name) xmlFree(name); - if (value) xmlFree(value); + if (name && value) { + mOptions[(const char*)name] = (const char*)value; } + + if (name) xmlFree(name); + if (value) xmlFree(value); } xmlFreeDoc(doc); @@ -89,31 +89,29 @@ void Configuration::write() xmlTextWriterPtr writer = xmlNewTextWriterFilename(mConfigPath.c_str(), 0); - if (writer) - { - logger->log("Configuration::write() writing configuration..."); + if (!writer) { + logger->log("Configuration::write() error while creating writer"); + return; + } - xmlTextWriterSetIndent(writer, 1); - xmlTextWriterStartDocument(writer, NULL, NULL, NULL); - xmlTextWriterStartElement(writer, BAD_CAST "configuration"); + logger->log("Configuration::write() writing configuration..."); - for (OptionIterator i = mOptions.begin(); i != mOptions.end(); i++) - { - xmlTextWriterStartElement(writer, BAD_CAST "option"); - xmlTextWriterWriteAttribute(writer, - BAD_CAST "name", BAD_CAST i->first.c_str()); - xmlTextWriterWriteAttribute(writer, - BAD_CAST "value", BAD_CAST i->second.c_str()); - xmlTextWriterEndElement(writer); - } + xmlTextWriterSetIndent(writer, 1); + xmlTextWriterStartDocument(writer, NULL, NULL, NULL); + xmlTextWriterStartElement(writer, BAD_CAST "configuration"); - xmlTextWriterEndDocument(writer); - xmlFreeTextWriter(writer); - } - else + for (OptionIterator i = mOptions.begin(); i != mOptions.end(); i++) { - logger->log("Configuration::write() error while creating writer"); + xmlTextWriterStartElement(writer, BAD_CAST "option"); + xmlTextWriterWriteAttribute(writer, + BAD_CAST "name", BAD_CAST i->first.c_str()); + xmlTextWriterWriteAttribute(writer, + BAD_CAST "value", BAD_CAST i->second.c_str()); + xmlTextWriterEndElement(writer); } + + xmlTextWriterEndDocument(writer); + xmlFreeTextWriter(writer); } void Configuration::setValue(const std::string &key, std::string value) diff --git a/src/engine.cpp b/src/engine.cpp index c6a4e55c..84574b26 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -25,7 +25,6 @@ #include -#include "animation.h" #include "being.h" #include "beingmanager.h" #include "flooritemmanager.h" @@ -34,7 +33,6 @@ #include "main.h" #include "localplayer.h" #include "log.h" -#include "main.h" #include "map.h" #include "sound.h" @@ -63,8 +61,6 @@ Spriteset *itemset; Spriteset *emotionset; Spriteset *npcset; std::vector weaponset; -AnimatedSprite *animatedSprite; - Engine::Engine(Network *network): mShowDebugPath(false), @@ -104,16 +100,11 @@ Engine::~Engine() emotionset->decRef(); itemset->decRef(); - std::vector::iterator iter; - for (iter = weaponset.begin(); iter != weaponset.end(); ++iter) - { - (*iter)->decRef(); - } + std::for_each(weaponset.begin(), weaponset.end(), + std::mem_fun(&Spriteset::decRef)); weaponset.clear(); delete itemDb; - - delete animatedSprite; } void Engine::changeMap(const std::string &mapPath) @@ -219,12 +210,12 @@ void Engine::draw(Graphics *graphics) player_node->mX, player_node->mY, mouseTileX, mouseTileY); + graphics->setColor(gcn::Color(255, 0, 0)); for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) { int squareX = i->x * 32 - map_x + 12; int squareY = i->y * 32 - map_y + 12; - graphics->setColor(gcn::Color(255, 0, 0)); graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); graphics->drawText( toString(mCurrentMap->getMetaTile(i->x, i->y)->Gcost), diff --git a/src/game.cpp b/src/game.cpp index fab88aa9..eada1128 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -167,8 +167,7 @@ int get_elapsed_time(int start_time) void createGuiWindows(Network *network) { // Create dialogs - chatWindow = new ChatWindow( - config.getValue("homeDir", "") + std::string("/chatlog.txt"), network); + chatWindow = new ChatWindow(network); menuWindow = new MenuWindow(); statusWindow = new StatusWindow(player_node); miniStatusWindow = new MiniStatusWindow(); @@ -359,29 +358,16 @@ void Game::logic() gameTime = tick_time; fpsLimit = (int)config.getValue("fpslimit", 50); - if (fpsLimit) - { - delta = 1000 / fpsLimit; - } - else - { - delta = 0; - } + delta = fpsLimit ? 1000 / fpsLimit : 0; // Update the screen when application is active, delay otherwise - if (SDL_GetAppState() & SDL_APPACTIVE) + if (SDL_GetAppState() & SDL_APPACTIVE && + (abs(tick_time * 10 - drawTime) >= delta)) { - if (abs(tick_time * 10 - drawTime) >= delta) - { - frame++; - engine->draw(graphics); - graphics->updateScreen(); - drawTime += delta; - } - else - { - SDL_Delay(10); - } + frame++; + engine->draw(graphics); + graphics->updateScreen(); + drawTime += delta; } else { diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h index 95b181ad..a2c9dd9b 100644 --- a/src/gui/browserbox.h +++ b/src/gui/browserbox.h @@ -31,6 +31,7 @@ #include #include "../guichanfwd.h" +#include "../main.h" class LinkHandler; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 133e5e3a..592439fc 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -35,18 +35,16 @@ #include "../game.h" #include "../localplayer.h" -#include "../log.h" #include "../net/messageout.h" #include "../net/protocol.h" -ChatWindow::ChatWindow(const std::string &logfile, Network *network): +ChatWindow::ChatWindow(Network *network): Window(""), mNetwork(network), mTmpVisible(false) { setWindowName("Chat"); - mChatlogFile.open(logfile.c_str(), std::ios::out | std::ios::app); mItems = 0; mItemsKeep = 20; @@ -76,12 +74,6 @@ ChatWindow::ChatWindow(const std::string &logfile, Network *network): mCurHist = mHistory.end(); } -ChatWindow::~ChatWindow() -{ - mChatlogFile.flush(); - mChatlogFile.close(); -} - void ChatWindow::logic() { @@ -251,44 +243,12 @@ ChatWindow::isFocused() void ChatWindow::chatSend(const std::string &nick, std::string msg) { - // Prepare command - if (msg.substr(0, 1) == "/") - { - /* Some messages are managed client side, while others - * require server handling by proper packet. Probably - * those if elses should be replaced by protocol calls */ - if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) - { - msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg; - outMsg.writeShort(0x0099); - outMsg.writeShort(msg.length() + 4); - outMsg.writeString(msg, msg.length()); - } - else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) - { - chatLog("-- Help --", BY_SERVER); - chatLog("/help : Display this help.", BY_SERVER); - chatLog("/announce : Global announcement (GM only)", BY_SERVER); - chatLog("/where : Display map name", BY_SERVER); - chatLog("/who : Display number of online users", BY_SERVER); - } - else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) - { - chatLog(map_path, BY_SERVER); - } - else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) - { - MessageOut outMsg; - outMsg.writeShort(0x00c1); - } - else - { - chatLog("Unknown command", BY_SERVER); - } - } + /* Some messages are managed client side, while others + * require server handling by proper packet. Probably + * those if elses should be replaced by protocol calls */ + // Prepare ordinary message - else { + if (msg.substr(0, 1) != "/") { msg = nick + " : " + msg; MessageOut outMsg; @@ -296,6 +256,35 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) outMsg.writeShort(msg.length() + 4); outMsg.writeString(msg, msg.length()); } + else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) + { + msg.erase(0, IS_ANNOUNCE_LENGTH); + MessageOut outMsg; + outMsg.writeShort(0x0099); + outMsg.writeShort(msg.length() + 4); + outMsg.writeString(msg, msg.length()); + } + else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) + { + chatLog("-- Help --", BY_SERVER); + chatLog("/help : Display this help.", BY_SERVER); + chatLog("/announce : Global announcement (GM only)", BY_SERVER); + chatLog("/where : Display map name", BY_SERVER); + chatLog("/who : Display number of online users", BY_SERVER); + } + else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) + { + chatLog(map_path, BY_SERVER); + } + else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) + { + MessageOut outMsg; + outMsg.writeShort(0x00c1); + } + else + { + chatLog("Unknown command", BY_SERVER); + } } std::string diff --git a/src/gui/chat.h b/src/gui/chat.h index addfb6b5..20841873 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -24,7 +24,6 @@ #ifndef _TMW_CHAT_H #define _TMW_CHAT_H -#include #include #include @@ -117,12 +116,7 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Constructor. */ - ChatWindow(const std::string &logfile, Network *network); - - /** - * Destructor. - */ - ~ChatWindow(); + ChatWindow(Network *network); /** * Logic (updates components' size) @@ -195,7 +189,6 @@ class ChatWindow : public Window, public gcn::ActionListener, private: Network *mNetwork; - std::ofstream mChatlogFile; bool mTmpVisible; /** One item in the chat log */ diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 88998f7a..026f24bd 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -32,10 +32,6 @@ // constant as well as guichan does #include -#ifdef USE_OPENGL -#include "../resources/openglsdlimageloader.h" -#endif - #include "focushandler.h" #include "popupmenu.h" #include "window.h" @@ -57,6 +53,9 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" #include "../resources/sdlimageloader.h" +#ifdef USE_OPENGL +#include "../resources/openglsdlimageloader.h" +#endif // Guichan stuff Gui *gui; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 9eb94520..7ac226d3 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -42,6 +42,7 @@ #include "../configuration.h" #include "../graphics.h" #include "../log.h" +#include "../main.h" #include "../utils/tostring.h" diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 9188b6de..8c69d3ef 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -300,7 +300,7 @@ int UpdaterWindow::downloadThread(void *ptr) // Any existing file with this name is deleted first, otherwise the // rename will fail on Windows. ::remove(newName.c_str()); - rename(outFilename.c_str(), newName.c_str()); + ::rename(outFilename.c_str(), newName.c_str()); } } diff --git a/src/main.cpp b/src/main.cpp index ce68b7bb..a4ef29ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,6 @@ #define NOGDI #endif -#include "animation.h" #include "configuration.h" #include "game.h" #include "graphics.h" @@ -216,15 +215,6 @@ void init_engine() resman->addToSearchPath("data", true); resman->addToSearchPath(TMW_DATADIR "data", true); - int width, height, bpp; - bool fullscreen, hwaccel; - - width = (int)config.getValue("screenwidth", 800); - height = (int)config.getValue("screenheight", 600); - bpp = 0; - fullscreen = ((int)config.getValue("screen", 0) == 1); - hwaccel = ((int)config.getValue("hwaccel", 0) == 1); - #ifdef USE_OPENGL bool useOpenGL = (config.getValue("opengl", 0) == 1); @@ -232,16 +222,18 @@ void init_engine() Image::setLoadAsOpenGL(useOpenGL); // Create the graphics context - if (useOpenGL) { - graphics = new OpenGLGraphics(); - } else { - graphics = new Graphics(); - } + graphics = useOpenGL ? new OpenGLGraphics() : new Graphics(); #else // Create the graphics context graphics = new Graphics(); #endif + int width = (int)config.getValue("screenwidth", 800); + int height = (int)config.getValue("screenheight", 600); + int bpp = 0; + bool fullscreen = ((int)config.getValue("screen", 0) == 1); + bool hwaccel = ((int)config.getValue("hwaccel", 0) == 1); + // Try to set the desired video mode if (!graphics->setVideoMode(width, height, bpp, fullscreen, hwaccel)) { @@ -299,11 +291,8 @@ void exit_engine() delete gui; delete graphics; - std::vector::iterator iter; - for (iter = hairset.begin(); iter != hairset.end(); ++iter) - { - (*iter)->decRef(); - } + std::for_each(hairset.begin(), hairset.end(), + std::mem_fun(&Spriteset::decRef)); hairset.clear(); playerset[0]->decRef(); diff --git a/src/monster.cpp b/src/monster.cpp index 43823e50..8a7e2f32 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -23,10 +23,8 @@ #include "monster.h" +#include "animatedsprite.h" #include "game.h" -#include "log.h" - -#include "resources/resourcemanager.h" #include "utils/tostring.h" diff --git a/src/npc.cpp b/src/npc.cpp index 54205ad3..a82490ae 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -23,6 +23,8 @@ #include "npc.h" +#include "animatedsprite.h" + #include "net/messageout.h" #include "net/protocol.h" diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 2a6c931d..05bbb6b3 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include "main.h" + #ifdef USE_OPENGL #include "openglgraphics.h" diff --git a/src/player.cpp b/src/player.cpp index 05825f6e..3fe608c7 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -23,8 +23,7 @@ #include "player.h" -#include "animation.h" -#include "equipment.h" +#include "animatedsprite.h" #include "game.h" #include "graphics.h" @@ -91,11 +90,13 @@ Player::setSex(Uint8 sex) delete mSprites[BASE_SPRITE]; if (sex == 0) { - mSprites[BASE_SPRITE] = new AnimatedSprite("graphics/sprites/player_male_base.xml", 0); + mSprites[BASE_SPRITE] = new AnimatedSprite( + "graphics/sprites/player_male_base.xml", 0); } else { - mSprites[BASE_SPRITE] = new AnimatedSprite("graphics/sprites/player_female_base.xml", 0); + mSprites[BASE_SPRITE] = new AnimatedSprite( + "graphics/sprites/player_female_base.xml", 0); } } Being::setSex(sex); @@ -107,8 +108,16 @@ Player::setHairColor(Uint16 color) if (color != mHairColor && mHairStyle > 0) { delete mSprites[HAIR_SPRITE]; - mSprites[HAIR_SPRITE] = new AnimatedSprite("graphics/sprites/hairstyle"+toString(mHairStyle)+".xml", color - 1); + AnimatedSprite *newHairSprite = new AnimatedSprite( + "graphics/sprites/hairstyle" + toString(mHairStyle) + ".xml", + color - 1); + newHairSprite->setDirection(getSpriteDirection()); + + mSprites[HAIR_SPRITE] = newHairSprite; + + setAction(mAction); } + Being::setHairColor(color); } @@ -118,8 +127,16 @@ Player::setHairStyle(Uint16 style) if (style != mHairStyle && mHairColor > 0) { delete mSprites[HAIR_SPRITE]; - mSprites[HAIR_SPRITE] = new AnimatedSprite("graphics/sprites/hairstyle"+toString(style)+".xml", mHairColor - 1); + AnimatedSprite *newHairSprite = new AnimatedSprite( + "graphics/sprites/hairstyle" + toString(style) + ".xml", + mHairColor - 1); + newHairSprite->setDirection(getSpriteDirection()); + + mSprites[HAIR_SPRITE] = newHairSprite; + + setAction(mAction); } + Being::setHairStyle(style); } @@ -139,18 +156,24 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) position = TOPCLOTHES_SPRITE; break; } + + delete mSprites[position]; + mSprites[position] = NULL; + // id = 0 means unequip - if (mSprites[position]) { - delete mSprites[position]; - mSprites[position] = 0; - } if (id) { char stringId[4]; sprintf(stringId, "%03i", id); - printf("Id: %i %i %s\n", id, slot, stringId); - mSprites[position] = new AnimatedSprite( + + AnimatedSprite *equipmentSprite = new AnimatedSprite( "graphics/sprites/item" + toString(stringId) + ".xml", 0); + equipmentSprite->setDirection(getSpriteDirection()); + + mSprites[position] = equipmentSprite; + + setAction(mAction); } + Being::setVisibleEquipment(slot, id); } diff --git a/src/resources/image.h b/src/resources/image.h index 1f67fcae..78751394 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -24,6 +24,8 @@ #ifndef _TMW_IMAGE_H #define _TMW_IMAGE_H +#include "../main.h" + #include #ifdef USE_OPENGL #include diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 56ac6354..63c0b036 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -30,6 +30,8 @@ #include "../log.h" +#include "../utils/dtor.h" + #define READ_PROP(node, prop, name, target, cast) \ prop = xmlGetProp(node, BAD_CAST name); \ if (prop) { \ @@ -56,14 +58,12 @@ ItemManager::ItemManager() if (!doc) { logger->error("Item Manager: Error while parsing item database (items.xml)!"); - return; } xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "items")) { logger->error("Item Manager: items.xml is not a valid database file!"); - return; } for (node = node->xmlChildrenNode; node != NULL; node = node->next) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index af79480a..382b0797 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -28,7 +28,6 @@ #include "resourcemanager.h" #include "image.h" -#include "spriteset.h" #include "../base64.h" #include "../log.h" @@ -220,34 +219,26 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) void MapReader::readProperties(xmlNodePtr node, Properties* props) { - node = node->xmlChildrenNode; + for (node = node->xmlChildrenNode; node; node = node->next) { + if (!xmlStrEqual(node->name, BAD_CAST "property")) + continue; - while (node != NULL) - { - if (xmlStrEqual(node->name, BAD_CAST "property")) - { - // Example: - - xmlChar *name = xmlGetProp(node, BAD_CAST "name"); - xmlChar *value = xmlGetProp(node, BAD_CAST "value"); + // Example: + xmlChar *name = xmlGetProp(node, BAD_CAST "name"); + xmlChar *value = xmlGetProp(node, BAD_CAST "value"); - if (name && value) - { - props->setProperty((const char*) name, (const char*) value); - } - - if (name) xmlFree(name); - if (value) xmlFree(value); + if (name && value) { + props->setProperty((const char*)name, (const char*)value); } - node = node->next; + if (name) xmlFree(name); + if (value) xmlFree(value); } } void MapReader::readLayer(xmlNodePtr node, Map *map, int layer) { - node = node->xmlChildrenNode; int h = map->getHeight(); int w = map->getWidth(); int x = 0; @@ -255,89 +246,86 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer) // Load the tile data. Layers are assumed to be map size, with (0,0) as // origin. - while (node != NULL) - { - if (xmlStrEqual(node->name, BAD_CAST "data")) + for (node = node->xmlChildrenNode; node; node = node->next) { + if (!xmlStrEqual(node->name, BAD_CAST "data")) + continue; + + xmlChar *encoding = xmlGetProp(node, BAD_CAST "encoding"); + xmlChar *compression = xmlGetProp(node, BAD_CAST "compression"); + + if (encoding && xmlStrEqual(encoding, BAD_CAST "base64")) { - xmlChar *encoding = xmlGetProp(node, BAD_CAST "encoding"); - xmlChar *compression = xmlGetProp(node, BAD_CAST "compression"); + xmlFree(encoding); - if (encoding && xmlStrEqual(encoding, BAD_CAST "base64")) - { - xmlFree(encoding); + if (compression) { + logger->log("Warning: no layer compression supported!"); + xmlFree(compression); + return; + } - if (compression) { - logger->log("Warning: no layer compression supported!"); - xmlFree(compression); - return; - } + // Read base64 encoded map file + xmlNodePtr dataChild = node->xmlChildrenNode; + if (!dataChild) + continue; - // Read base64 encoded map file - xmlNodePtr dataChild = node->xmlChildrenNode; - if (!dataChild) continue; - - int len = strlen((const char*)dataChild->content) + 1; - unsigned char *charData = new unsigned char[len + 1]; - const char *charStart = (const char*)dataChild->content; - unsigned char *charIndex = charData; - - while (*charStart) { - if (*charStart != ' ' && *charStart != '\t' && - *charStart != '\n') - { - *charIndex = *charStart; - charIndex++; - } - charStart++; + int len = strlen((const char*)dataChild->content) + 1; + unsigned char *charData = new unsigned char[len + 1]; + const char *charStart = (const char*)dataChild->content; + unsigned char *charIndex = charData; + + while (*charStart) { + if (*charStart != ' ' && *charStart != '\t' && + *charStart != '\n') + { + *charIndex = *charStart; + charIndex++; } - *charIndex = '\0'; + charStart++; + } + *charIndex = '\0'; - int binLen; - unsigned char *binData = - php_base64_decode(charData, strlen((char*)charData), - &binLen); + int binLen; + unsigned char *binData = + php_base64_decode(charData, strlen((char*)charData), + &binLen); - delete[] charData; + delete[] charData; - if (binData) { - for (int i = 0; i < binLen - 3; i += 4) { - int gid = binData[i] | - binData[i + 1] << 8 | - binData[i + 2] << 16 | - binData[i + 3] << 24; + if (binData) { + for (int i = 0; i < binLen - 3; i += 4) { + int gid = binData[i] | + binData[i + 1] << 8 | + binData[i + 2] << 16 | + binData[i + 3] << 24; - map->setTileWithGid(x, y, layer, gid); + map->setTileWithGid(x, y, layer, gid); - x++; - if (x == w) {x = 0; y++;} - } - free(binData); + x++; + if (x == w) {x = 0; y++;} } + free(binData); } - else { - // Read plain XML map file - xmlNodePtr n2 = node->xmlChildrenNode; - - while (n2 != NULL) - { - if (xmlStrEqual(n2->name, BAD_CAST "tile") && y < h) - { - int gid = getProperty(n2, "gid", -1); - map->setTileWithGid(x, y, layer, gid); - - x++; - if (x == w) {x = 0; y++;} - } - - n2 = n2->next; + } + else { + // Read plain XML map file + for (xmlNodePtr n2 = node->xmlChildrenNode; n2; n2 = n2->next) { + if (!xmlStrEqual(n2->name, BAD_CAST "tile")) + continue; + + int gid = getProperty(n2, "gid", -1); + map->setTileWithGid(x, y, layer, gid); + + x++; + if (x == w) { + x = 0; y++; + if (y >= h) + break; } } - - // There can be only one data element - break; } - node = node->next; + // There can be only one data element + break; } } @@ -356,38 +344,33 @@ MapReader::readTileset(xmlNodePtr node, int tw = getProperty(node, "tilewidth", map->getTileWidth()); int th = getProperty(node, "tileheight", map->getTileHeight()); - node = node->xmlChildrenNode; + for (node = node->xmlChildrenNode; node; node = node->next) { + if (!xmlStrEqual(node->name, BAD_CAST "image")) + continue; - while (node != NULL) - { - if (xmlStrEqual(node->name, BAD_CAST "image")) - { - xmlChar* source = xmlGetProp(node, BAD_CAST "source"); + xmlChar* source = xmlGetProp(node, BAD_CAST "source"); - if (source) - { - std::string sourceStr = std::string((const char*)source); - sourceStr.erase(0, 3); // Remove "../" + if (source) + { + std::string sourceStr = std::string((const char*)source); + sourceStr.erase(0, 3); // Remove "../" - ResourceManager *resman = ResourceManager::getInstance(); - Image* tilebmp = resman->getImage(sourceStr); + ResourceManager *resman = ResourceManager::getInstance(); + Image* tilebmp = resman->getImage(sourceStr); - if (tilebmp) - { - Tileset *set = new Tileset(tilebmp, tw, th, firstGid); - tilebmp->decRef(); - xmlFree(source); - return set; - } - else { - logger->log("Warning: Failed to load tileset (%s)", source); - } + if (tilebmp) + { + Tileset *set = new Tileset(tilebmp, tw, th, firstGid); + tilebmp->decRef(); + xmlFree(source); + return set; + } + else { + logger->log("Warning: Failed to load tileset (%s)", source); } - - break; } - node = node->next; + break; } return NULL; @@ -396,13 +379,12 @@ MapReader::readTileset(xmlNodePtr node, int MapReader::getProperty(xmlNodePtr node, const char* name, int def) { + int &ret = def; + xmlChar *prop = xmlGetProp(node, BAD_CAST name); if (prop) { - int val = atoi((char*)prop); + ret = atoi((char*)prop); xmlFree(prop); - return val; - } - else { - return def; } + return ret; } diff --git a/src/resources/openglsdlimageloader.cpp b/src/resources/openglsdlimageloader.cpp index c7ddec74..b3e1601e 100644 --- a/src/resources/openglsdlimageloader.cpp +++ b/src/resources/openglsdlimageloader.cpp @@ -21,14 +21,16 @@ * $Id: sdlimageloader.cpp 2121 2006-01-31 02:55:26Z der_doener $ */ -#ifdef USE_OPENGL - #include "openglsdlimageloader.h" #include #include "resourcemanager.h" +#include "../main.h" + +#ifdef USE_OPENGL + SDL_Surface* OpenGLSDLImageLoader::loadSDLSurface(const std::string& filename) { ResourceManager *resman = ResourceManager::getInstance(); -- cgit v1.2.3-70-g09d2 From 2fe42d32c6d368a66586c605cc1b38ee8d85ed1d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 20 Aug 2006 16:14:12 +0000 Subject: Changed MessageHandler::handleMessage to take a reference instead of a pointer. Removed unused Packet class. Added stub for handling GPMSG_BEING_ENTER. --- ChangeLog | 3 + src/Makefile.am | 2 - src/net/beinghandler.cpp | 237 +++++++++++++++++++++++------------------- src/net/beinghandler.h | 6 +- src/net/buysellhandler.cpp | 32 +++--- src/net/buysellhandler.h | 2 +- src/net/charserverhandler.cpp | 28 ++--- src/net/charserverhandler.h | 5 +- src/net/chathandler.cpp | 20 ++-- src/net/chathandler.h | 2 +- src/net/equipmenthandler.cpp | 46 ++++---- src/net/equipmenthandler.h | 2 +- src/net/inventoryhandler.cpp | 58 +++++------ src/net/inventoryhandler.h | 2 +- src/net/itemhandler.cpp | 16 +-- src/net/itemhandler.h | 2 +- src/net/loginhandler.cpp | 8 +- src/net/loginhandler.h | 2 +- src/net/maploginhandler.cpp | 6 +- src/net/maploginhandler.h | 2 +- src/net/messagehandler.h | 2 +- src/net/messagein.cpp | 2 - src/net/messageout.cpp | 2 - src/net/network.cpp | 2 +- src/net/npchandler.cpp | 18 ++-- src/net/npchandler.h | 2 +- src/net/packet.cpp | 40 ------- src/net/packet.h | 47 --------- src/net/playerhandler.cpp | 112 ++++++++++---------- src/net/playerhandler.h | 2 +- src/net/skillhandler.cpp | 34 +++--- src/net/skillhandler.h | 2 +- src/net/tradehandler.cpp | 26 ++--- src/net/tradehandler.h | 2 +- 34 files changed, 358 insertions(+), 416 deletions(-) delete mode 100644 src/net/packet.cpp delete mode 100644 src/net/packet.h (limited to 'src/Makefile.am') diff --git a/ChangeLog b/ChangeLog index 12e30213..8f589dcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,9 @@ selection of player character and implemented sending of game and chat server tokens. It gets you in the game (or what's left of it), but not on any map yet. + * src/net/*: Changed MessageHandler::handleMessage to take a reference + instead of a pointer. Removed unused Packet class. Added stub for + handling GPMSG_BEING_ENTER. 2006-08-19 Bjørn Lindeijer diff --git a/src/Makefile.am b/src/Makefile.am index 42671f64..8f40c506 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -146,8 +146,6 @@ tmw_SOURCES = graphic/imagerect.h \ net/network.h \ net/npchandler.cpp \ net/npchandler.h \ - net/packet.cpp \ - net/packet.h \ net/playerhandler.cpp \ net/playerhandler.h \ net/protocol.cpp \ diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 549797f9..ed0fc4b2 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -41,24 +41,25 @@ const int EMOTION_TIME = 150; /**< Duration of emotion icon */ BeingHandler::BeingHandler() { static const Uint16 _messages[] = { - SMSG_BEING_VISIBLE, - SMSG_BEING_MOVE, - SMSG_BEING_REMOVE, - SMSG_BEING_ACTION, - SMSG_BEING_LEVELUP, - SMSG_BEING_EMOTION, - SMSG_BEING_CHANGE_LOOKS, - SMSG_BEING_NAME_RESPONSE, - SMSG_PLAYER_UPDATE_1, - SMSG_PLAYER_UPDATE_2, - SMSG_PLAYER_MOVE, - 0x0119, + //SMSG_BEING_VISIBLE, + //SMSG_BEING_MOVE, + //SMSG_BEING_REMOVE, + //SMSG_BEING_ACTION, + //SMSG_BEING_LEVELUP, + //SMSG_BEING_EMOTION, + //SMSG_BEING_CHANGE_LOOKS, + //SMSG_BEING_NAME_RESPONSE, + //SMSG_PLAYER_UPDATE_1, + //SMSG_PLAYER_UPDATE_2, + //SMSG_PLAYER_MOVE, + //0x0119, + GPMSG_BEING_ENTER, 0 }; handledMessages = _messages; } -void BeingHandler::handleMessage(MessageIn *msg) +void BeingHandler::handleMessage(MessageIn &msg) { Uint32 id; Uint16 job, speed; @@ -66,17 +67,21 @@ void BeingHandler::handleMessage(MessageIn *msg) Sint8 type; Being *srcBeing, *dstBeing; - switch (msg->getId()) + switch (msg.getId()) { + case GPMSG_BEING_ENTER: + handleBeingEnterMessage(msg); + break; + case SMSG_BEING_VISIBLE: case SMSG_BEING_MOVE: // Information about a being in range - id = msg->readLong(); - speed = msg->readShort(); - msg->readShort(); // unknown - msg->readShort(); // unknown - msg->readShort(); // option - job = msg->readShort(); // class + id = msg.readLong(); + speed = msg.readShort(); + msg.readShort(); // unknown + msg.readShort(); // unknown + msg.readShort(); // option + job = msg.readShort(); // class dstBeing = beingManager->findBeing(id); @@ -91,7 +96,7 @@ void BeingHandler::handleMessage(MessageIn *msg) dstBeing = beingManager->createBeing(id, job); } - else if (msg->getId() == 0x0078) + else if (msg.getId() == 0x0078) { dstBeing->clearPath(); dstBeing->mFrame = 0; @@ -104,33 +109,33 @@ void BeingHandler::handleMessage(MessageIn *msg) dstBeing->setWalkSpeed(speed); dstBeing->mJob = job; - dstBeing->setHairStyle(msg->readShort()); - dstBeing->setWeapon(msg->readShort()); - dstBeing->setVisibleEquipment(3, msg->readShort()); // head bottom + dstBeing->setHairStyle(msg.readShort()); + dstBeing->setWeapon(msg.readShort()); + dstBeing->setVisibleEquipment(3, msg.readShort()); // head bottom - if (msg->getId() == SMSG_BEING_MOVE) + if (msg.getId() == SMSG_BEING_MOVE) { - msg->readLong(); // server tick + msg.readLong(); // server tick } - msg->readShort(); // shield - dstBeing->setVisibleEquipment(4, msg->readShort()); // head top - dstBeing->setVisibleEquipment(5, msg->readShort()); // head mid - dstBeing->setHairColor(msg->readShort()); - msg->readShort(); // unknown - msg->readShort(); // head dir - msg->readShort(); // guild - msg->readShort(); // unknown - msg->readShort(); // unknown - msg->readShort(); // manner - msg->readShort(); // karma - msg->readByte(); // unknown - dstBeing->setSex(1 - msg->readByte()); // sex - - if (msg->getId() == SMSG_BEING_MOVE) + msg.readShort(); // shield + dstBeing->setVisibleEquipment(4, msg.readShort()); // head top + dstBeing->setVisibleEquipment(5, msg.readShort()); // head mid + dstBeing->setHairColor(msg.readShort()); + msg.readShort(); // unknown + msg.readShort(); // head dir + msg.readShort(); // guild + msg.readShort(); // unknown + msg.readShort(); // unknown + msg.readShort(); // manner + msg.readShort(); // karma + msg.readByte(); // unknown + dstBeing->setSex(1 - msg.readByte()); // sex + + if (msg.getId() == SMSG_BEING_MOVE) { //Uint16 srcX, srcY, dstX, dstY; - //msg->readCoordinatePair(srcX, srcY, dstX, dstY); + //msg.readCoordinatePair(srcX, srcY, dstX, dstY); //dstBeing->setAction(Being::STAND); //dstBeing->mX = srcX; //dstBeing->mY = srcY; @@ -138,22 +143,22 @@ void BeingHandler::handleMessage(MessageIn *msg) } else { - //msg->readCoordinates(dstBeing->mX, dstBeing->mY, dstBeing->mDirection); + //msg.readCoordinates(dstBeing->mX, dstBeing->mY, dstBeing->mDirection); } - msg->readByte(); // unknown - msg->readByte(); // unknown - msg->readByte(); // unknown / sit + msg.readByte(); // unknown + msg.readByte(); // unknown + msg.readByte(); // unknown / sit break; case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readLong()); + dstBeing = beingManager->findBeing(msg.readLong()); if (!dstBeing) break; - if (msg->readByte() == 1) + if (msg.readByte() == 1) { // Death switch (dstBeing->getType()) @@ -181,15 +186,15 @@ void BeingHandler::handleMessage(MessageIn *msg) break; case SMSG_BEING_ACTION: - srcBeing = beingManager->findBeing(msg->readLong()); - dstBeing = beingManager->findBeing(msg->readLong()); - msg->readLong(); // server tick - msg->readLong(); // src speed - msg->readLong(); // dst speed - param1 = msg->readShort(); - msg->readShort(); // param 2 - type = msg->readByte(); - msg->readShort(); // param 3 + srcBeing = beingManager->findBeing(msg.readLong()); + dstBeing = beingManager->findBeing(msg.readLong()); + msg.readLong(); // server tick + msg.readLong(); // src speed + msg.readLong(); // dst speed + param1 = msg.readShort(); + msg.readShort(); // param 2 + type = msg.readByte(); + msg.readShort(); // param 3 switch (type) { @@ -230,63 +235,63 @@ void BeingHandler::handleMessage(MessageIn *msg) break; case SMSG_BEING_LEVELUP: - if ((Uint32)msg->readLong() == player_node->getId()) { + if ((Uint32) msg.readLong() == player_node->getId()) { logger->log("Level up"); sound.playSfx("sfx/levelup.ogg"); } else { logger->log("Someone else went level up"); } - msg->readLong(); // type + msg.readLong(); // type break; case SMSG_BEING_EMOTION: - if (!(dstBeing = beingManager->findBeing(msg->readLong()))) + if (!(dstBeing = beingManager->findBeing(msg.readLong()))) { break; } - dstBeing->mEmotion = msg->readByte(); + dstBeing->mEmotion = msg.readByte(); dstBeing->mEmotionTime = EMOTION_TIME; break; case SMSG_BEING_CHANGE_LOOKS: { - if (!(dstBeing = beingManager->findBeing(msg->readLong()))) + if (!(dstBeing = beingManager->findBeing(msg.readLong()))) { break; } - int type = msg->readByte(); + int type = msg.readByte(); switch (type) { case 1: - dstBeing->setHairStyle(msg->readByte()); + dstBeing->setHairStyle(msg.readByte()); break; case 2: - dstBeing->setWeapon(msg->readByte()); + dstBeing->setWeapon(msg.readByte()); break; case 3: case 4: case 5: // Equip/unequip head 3. Bottom 4. Top 5. Middle - dstBeing->setVisibleEquipment(type, msg->readByte()); + dstBeing->setVisibleEquipment(type, msg.readByte()); // First 3 slots of mVisibleEquipments are reserved for // later use, probably accessories. break; case 6: - dstBeing->setHairColor(msg->readByte()); + dstBeing->setHairColor(msg.readByte()); break; default: - printf("c3: %i\n", msg->readByte()); // unsupported + printf("c3: %i\n", msg.readByte()); // unsupported break; } } break; case SMSG_BEING_NAME_RESPONSE: - if ((dstBeing = beingManager->findBeing(msg->readLong()))) + if ((dstBeing = beingManager->findBeing(msg.readLong()))) { - dstBeing->setName(msg->readString(24)); + dstBeing->setName(msg.readString(24)); } break; @@ -294,12 +299,12 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_UPDATE_2: case SMSG_PLAYER_MOVE: // An update about a player, potentially including movement. - id = msg->readLong(); - speed = msg->readShort(); - msg->readShort(); // option 1 - msg->readShort(); // option 2 - msg->readShort(); // option - job = msg->readShort(); + id = msg.readLong(); + speed = msg.readShort(); + msg.readShort(); // option 1 + msg.readShort(); // option 2 + msg.readShort(); // option + job = msg.readShort(); dstBeing = beingManager->findBeing(id); @@ -310,57 +315,57 @@ void BeingHandler::handleMessage(MessageIn *msg) dstBeing->setWalkSpeed(speed); dstBeing->mJob = job; - dstBeing->setHairStyle(msg->readShort()); - dstBeing->setWeaponById(msg->readShort()); // item id 1 - msg->readShort(); // item id 2 - dstBeing->setVisibleEquipment(3, msg->readShort()); // head bottom + dstBeing->setHairStyle(msg.readShort()); + dstBeing->setWeaponById(msg.readShort()); // item id 1 + msg.readShort(); // item id 2 + dstBeing->setVisibleEquipment(3, msg.readShort()); // head bottom - if (msg->getId() == SMSG_PLAYER_MOVE) + if (msg.getId() == SMSG_PLAYER_MOVE) { - msg->readLong(); // server tick + msg.readLong(); // server tick } - dstBeing->setVisibleEquipment(4, msg->readShort()); // head top - dstBeing->setVisibleEquipment(5, msg->readShort()); // head mid - dstBeing->setHairColor(msg->readShort()); - msg->readShort(); // unknown - msg->readShort(); // head dir - msg->readLong(); // guild - msg->readLong(); // emblem - msg->readShort(); // manner - msg->readByte(); // karma - dstBeing->setSex(1 - msg->readByte()); // sex - - if (msg->getId() == SMSG_PLAYER_MOVE) + dstBeing->setVisibleEquipment(4, msg.readShort()); // head top + dstBeing->setVisibleEquipment(5, msg.readShort()); // head mid + dstBeing->setHairColor(msg.readShort()); + msg.readShort(); // unknown + msg.readShort(); // head dir + msg.readLong(); // guild + msg.readLong(); // emblem + msg.readShort(); // manner + msg.readByte(); // karma + dstBeing->setSex(1 - msg.readByte()); // sex + + if (msg.getId() == SMSG_PLAYER_MOVE) { //Uint16 srcX, srcY, dstX, dstY; - //msg->readCoordinatePair(srcX, srcY, dstX, dstY); + //msg.readCoordinatePair(srcX, srcY, dstX, dstY); //dstBeing->mX = srcX; //dstBeing->mY = srcY; //dstBeing->setDestination(dstX, dstY); } else { - //msg->readCoordinates(dstBeing->mX, dstBeing->mY, dstBeing->mDirection); + //msg.readCoordinates(dstBeing->mX, dstBeing->mY, dstBeing->mDirection); } - msg->readByte(); // unknown - msg->readByte(); // unknown + msg.readByte(); // unknown + msg.readByte(); // unknown - if (msg->getId() == SMSG_PLAYER_UPDATE_1) + if (msg.getId() == SMSG_PLAYER_UPDATE_1) { - if (msg->readByte() == 2) + if (msg.readByte() == 2) { dstBeing->setAction(Being::SIT); } } - else if (msg->getId() == SMSG_PLAYER_MOVE) + else if (msg.getId() == SMSG_PLAYER_MOVE) { - msg->readByte(); // unknown + msg.readByte(); // unknown } - msg->readByte(); // Lv - msg->readByte(); // unknown + msg.readByte(); // Lv + msg.readByte(); // unknown dstBeing->mWalkTime = tick_time; dstBeing->mFrame = 0; @@ -368,9 +373,27 @@ void BeingHandler::handleMessage(MessageIn *msg) case 0x0119: // Change in players look - printf("0x0119 %li %i %i %x %i\n", msg->readLong(), - msg->readShort(), msg->readShort(), msg->readShort(), - msg->readByte()); + printf("0x0119 %li %i %i %x %i\n", msg.readLong(), + msg.readShort(), msg.readShort(), msg.readShort(), + msg.readByte()); break; } } + +void +BeingHandler::handleBeingEnterMessage(MessageIn &msg) +{ + // Not sure what do to exactly with this message yet. + /* + unsigned char type = msg.readByte(); + unsigned long id = msg.readLong(); + + if (type == OBJECT_PLAYER) + { + std::string name = msg.readString(); + unsigned char hairStyle = msg.readByte(); + unsigned char hairColor = msg.readByte(); + unsigned char gender = msg.readByte(); + } + */ +} diff --git a/src/net/beinghandler.h b/src/net/beinghandler.h index 03012f39..2dd81e1a 100644 --- a/src/net/beinghandler.h +++ b/src/net/beinghandler.h @@ -31,7 +31,11 @@ class BeingHandler : public MessageHandler public: BeingHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); + + private: + void + handleBeingEnterMessage(MessageIn &msg); }; #endif diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 3b5fc87d..173c59d2 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -54,10 +54,10 @@ BuySellHandler::BuySellHandler() handledMessages = _messages; } -void BuySellHandler::handleMessage(MessageIn *msg) +void BuySellHandler::handleMessage(MessageIn &msg) { int n_items; - switch (msg->getId()) + switch (msg.getId()) { case SMSG_NPC_BUY_SELL_CHOICE: buyDialog->setVisible(false); @@ -65,38 +65,38 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast(beingManager->findBeing(msg->readLong())); + current_npc = dynamic_cast(beingManager->findBeing(msg.readLong())); break; case SMSG_NPC_BUY: - msg->readShort(); // length - n_items = (msg->getLength() - 4) / 11; + msg.readShort(); // length + n_items = (msg.getLength() - 4) / 11; buyDialog->reset(); buyDialog->setMoney(player_node->mMoney); buyDialog->setVisible(true); for (int k = 0; k < n_items; k++) { - Sint32 value = msg->readLong(); - msg->readLong(); // DCvalue - msg->readByte(); // type - Sint16 itemId = msg->readShort(); + Sint32 value = msg.readLong(); + msg.readLong(); // DCvalue + msg.readByte(); // type + Sint16 itemId = msg.readShort(); buyDialog->addItem(itemId, value); } break; case SMSG_NPC_SELL: - msg->readShort(); // length - n_items = (msg->getLength() - 4) / 10; + msg.readShort(); // length + n_items = (msg.getLength() - 4) / 10; if (n_items > 0) { sellDialog->reset(); sellDialog->setVisible(true); for (int k = 0; k < n_items; k++) { - Sint16 index = msg->readShort(); - Sint32 value = msg->readLong(); - msg->readLong(); // OCvalue + Sint16 index = msg.readShort(); + Sint32 value = msg.readLong(); + msg.readLong(); // OCvalue Item *item = player_node->getInvItem(index); if (item && !(item->isEquipped())) { @@ -111,7 +111,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) break; case SMSG_NPC_BUY_RESPONSE: - if (msg->readByte() == 0) { + if (msg.readByte() == 0) { chatWindow->chatLog("Thanks for buying", BY_SERVER); } else { chatWindow->chatLog("Unable to buy", BY_SERVER); @@ -119,7 +119,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) break; case SMSG_NPC_SELL_RESPONSE: - if (msg->readByte() == 0) { + if (msg.readByte() == 0) { chatWindow->chatLog("Thanks for selling", BY_SERVER); } else { chatWindow->chatLog("Unable to sell", BY_SERVER); diff --git a/src/net/buysellhandler.h b/src/net/buysellhandler.h index 673aaac1..e242d373 100644 --- a/src/net/buysellhandler.h +++ b/src/net/buysellhandler.h @@ -31,7 +31,7 @@ class BuySellHandler : public MessageHandler public: BuySellHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 2bf2c4b4..5a2be683 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -48,20 +48,20 @@ CharServerHandler::CharServerHandler() } void -CharServerHandler::handleMessage(MessageIn *msg) +CharServerHandler::handleMessage(MessageIn &msg) { int slot; LocalPlayer *tempPlayer; - switch (msg->getId()) + switch (msg.getId()) { case APMSG_CHAR_CREATE_RESPONSE: - handleCharCreateResponse(*msg); + handleCharCreateResponse(msg); break; case APMSG_CHAR_DELETE_RESPONSE: { - int errMsg = msg->readByte(); + int errMsg = msg.readByte(); // Character deletion successful if (errMsg == ERRMSG_OK) { @@ -101,7 +101,7 @@ CharServerHandler::handleMessage(MessageIn *msg) break; case APMSG_CHAR_SELECT_RESPONSE: - handleCharSelectResponse(*msg); + handleCharSelectResponse(msg); break; } } @@ -193,18 +193,18 @@ CharServerHandler::handleCharSelectResponse(MessageIn &msg) } LocalPlayer* -CharServerHandler::readPlayerData(MessageIn *msg, int &slot) +CharServerHandler::readPlayerData(MessageIn &msg, int &slot) { LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL); - slot = msg->readByte(); // character slot - tempPlayer->mName = msg->readString(); - tempPlayer->mSex = msg->readByte(); - tempPlayer->setHairStyle(msg->readByte()); - tempPlayer->setHairColor(msg->readByte()); - tempPlayer->mLevel = msg->readByte(); - tempPlayer->mMoney = msg->readShort(); + slot = msg.readByte(); // character slot + tempPlayer->mName = msg.readString(); + tempPlayer->mSex = msg.readByte(); + tempPlayer->setHairStyle(msg.readByte()); + tempPlayer->setHairColor(msg.readByte()); + tempPlayer->mLevel = msg.readByte(); + tempPlayer->mMoney = msg.readShort(); for (int i = 0; i < 6; i++) { - tempPlayer->mAttr[i] = msg->readByte(); + tempPlayer->mAttr[i] = msg.readByte(); } return tempPlayer; } diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h index b034b513..9ad11c6a 100644 --- a/src/net/charserverhandler.h +++ b/src/net/charserverhandler.h @@ -37,7 +37,7 @@ class CharServerHandler : public MessageHandler CharServerHandler(); void - handleMessage(MessageIn *msg); + handleMessage(MessageIn &msg); void setCharInfo(LockedArray *charInfo) @@ -58,7 +58,8 @@ class CharServerHandler : public MessageHandler LoginData *mLoginData; LockedArray *mCharInfo; - LocalPlayer* readPlayerData(MessageIn *msg, int &slot); + LocalPlayer* + readPlayerData(MessageIn &msg, int &slot); }; #endif diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index d6f822f8..795b2a27 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -52,25 +52,25 @@ ChatHandler::ChatHandler() handledMessages = _messages; } -void ChatHandler::handleMessage(MessageIn *msg) +void ChatHandler::handleMessage(MessageIn &msg) { Being *being; std::string chatMsg; Sint16 chatMsgLength; - switch (msg->getId()) + switch (msg.getId()) { // Received speech from being case SMSG_BEING_CHAT: - chatMsgLength = msg->readShort() - 8; - being = beingManager->findBeing(msg->readLong()); + chatMsgLength = msg.readShort() - 8; + being = beingManager->findBeing(msg.readLong()); if (!being || chatMsgLength <= 0) { break; } - chatMsg = msg->readString(chatMsgLength); + chatMsg = msg.readString(chatMsgLength); chatWindow->chatLog(chatMsg, BY_OTHER); chatMsg.erase(0, chatMsg.find(" : ", 0) + 3); being->setSpeech(chatMsg, SPEECH_TIME); @@ -78,16 +78,16 @@ void ChatHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_CHAT: case SMSG_GM_CHAT: - chatMsgLength = msg->readShort() - 4; + chatMsgLength = msg.readShort() - 4; if (chatMsgLength <= 0) { break; } - chatMsg = msg->readString(chatMsgLength); + chatMsg = msg.readString(chatMsgLength); - if (msg->getId() == SMSG_PLAYER_CHAT) + if (msg.getId() == SMSG_PLAYER_CHAT) { chatWindow->chatLog(chatMsg, BY_PLAYER); @@ -105,13 +105,13 @@ void ChatHandler::handleMessage(MessageIn *msg) break; case SMSG_WHO_ANSWER: - chatWindow->chatLog("Online users: " + toString(msg->readLong()), + chatWindow->chatLog("Online users: " + toString(msg.readLong()), BY_SERVER); break; case 0x010c: // Display MVP player - msg->readLong(); // id + msg.readLong(); // id chatWindow->chatLog("MVP player", BY_SERVER); break; } diff --git a/src/net/chathandler.h b/src/net/chathandler.h index eed19206..e9db3575 100644 --- a/src/net/chathandler.h +++ b/src/net/chathandler.h @@ -31,7 +31,7 @@ class ChatHandler : public MessageHandler public: ChatHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index aa372961..1c0fd4ca 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -48,7 +48,7 @@ EquipmentHandler::EquipmentHandler() handledMessages = _messages; } -void EquipmentHandler::handleMessage(MessageIn *msg) +void EquipmentHandler::handleMessage(MessageIn &msg) { Sint32 itemCount; Sint16 index, equipPoint, itemId; @@ -57,22 +57,22 @@ void EquipmentHandler::handleMessage(MessageIn *msg) Being *being; Item *item; - switch (msg->getId()) + switch (msg.getId()) { case SMSG_PLAYER_EQUIPMENT: - msg->readShort(); // length - itemCount = (msg->getLength() - 4) / 20; + msg.readShort(); // length + itemCount = (msg.getLength() - 4) / 20; for (int loop = 0; loop < itemCount; loop++) { - index = msg->readShort(); - itemId = msg->readShort(); - msg->readByte(); // type - msg->readByte(); // identify flag - msg->readShort(); // equip type - equipPoint = msg->readShort(); - msg->readByte(); // attribute - msg->readByte(); // refine + index = msg.readShort(); + itemId = msg.readShort(); + msg.readByte(); // type + msg.readByte(); // identify flag + msg.readShort(); // equip type + equipPoint = msg.readShort(); + msg.readByte(); // attribute + msg.readByte(); // refine player_node->addInvItem(index, itemId, 1, true); @@ -92,9 +92,9 @@ void EquipmentHandler::handleMessage(MessageIn *msg) break; case SMSG_PLAYER_EQUIP: - index = msg->readShort(); - equipPoint = msg->readShort(); - type = msg->readByte(); + index = msg.readShort(); + equipPoint = msg.readShort(); + type = msg.readByte(); logger->log("Equipping: %i %i %i", index, equipPoint, type); @@ -128,10 +128,10 @@ void EquipmentHandler::handleMessage(MessageIn *msg) case 0x01d7: // Equipment related - being = beingManager->findBeing(msg->readLong()); - msg->readByte(); // equip point - itemId = msg->readShort(); - msg->readShort(); // item id 2 + being = beingManager->findBeing(msg.readLong()); + msg.readByte(); // equip point + itemId = msg.readShort(); + msg.readShort(); // item id 2 if (!being) break; @@ -140,9 +140,9 @@ void EquipmentHandler::handleMessage(MessageIn *msg) break; case SMSG_PLAYER_UNEQUIP: - index = msg->readShort(); - equipPoint = msg->readShort(); - type = msg->readByte(); + index = msg.readShort(); + equipPoint = msg.readShort(); + type = msg.readByte(); if (!type) { chatWindow->chatLog("Unable to unequip.", BY_SERVER); @@ -192,7 +192,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) break; case SMSG_PLAYER_ARROW_EQUIP: - itemId = msg->readShort(); + itemId = msg.readShort(); if (itemId <= 1) break; diff --git a/src/net/equipmenthandler.h b/src/net/equipmenthandler.h index 656f7a73..c9c65d67 100644 --- a/src/net/equipmenthandler.h +++ b/src/net/equipmenthandler.h @@ -31,7 +31,7 @@ class EquipmentHandler : public MessageHandler public: EquipmentHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 51c71f8d..cb1883b0 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -46,27 +46,27 @@ InventoryHandler::InventoryHandler() handledMessages = _messages; } -void InventoryHandler::handleMessage(MessageIn *msg) +void InventoryHandler::handleMessage(MessageIn &msg) { Sint32 number; Sint16 index, amount, itemId, equipType; - switch (msg->getId()) + switch (msg.getId()) { case SMSG_PLAYER_INVENTORY: // Only called on map load / warp. First reset all items // to not load them twice on map change. player_node->clearInventory(); - msg->readShort(); // length - number = (msg->getLength() - 4) / 18; + msg.readShort(); // length + number = (msg.getLength() - 4) / 18; for (int loop = 0; loop < number; loop++) { - index = msg->readShort(); - itemId = msg->readShort(); - msg->readByte(); // type - msg->readByte(); // identify flag - amount = msg->readShort(); + index = msg.readShort(); + itemId = msg.readShort(); + msg.readByte(); // type + msg.readByte(); // identify flag + amount = msg.readShort(); player_node->addInvItem(index, itemId, amount, false); @@ -79,16 +79,16 @@ void InventoryHandler::handleMessage(MessageIn *msg) break; case SMSG_PLAYER_INVENTORY_ADD: - index = msg->readShort(); - amount = msg->readShort(); - itemId = msg->readShort(); - msg->readByte(); // identify flag - msg->readByte(); // attribute - msg->readByte(); // refine - equipType = msg->readShort(); - msg->readByte(); // type - - if (msg->readByte()> 0) { + index = msg.readShort(); + amount = msg.readShort(); + itemId = msg.readShort(); + msg.readByte(); // identify flag + msg.readByte(); // attribute + msg.readByte(); // refine + equipType = msg.readShort(); + msg.readByte(); // type + + if (msg.readByte()> 0) { chatWindow->chatLog("Unable to pick up item", BY_SERVER); } else { player_node->addInvItem(index, itemId, amount, equipType != 0); @@ -96,26 +96,26 @@ void InventoryHandler::handleMessage(MessageIn *msg) break; case SMSG_PLAYER_INVENTORY_REMOVE: - index = msg->readShort(); - amount = msg->readShort(); + index = msg.readShort(); + amount = msg.readShort(); player_node->getInvItem(index)->increaseQuantity(-amount); break; case SMSG_PLAYER_INVENTORY_USE: - index = msg->readShort(); - msg->readShort(); // item id - msg->readLong(); // id - amount = msg->readShort(); - msg->readByte(); // type + index = msg.readShort(); + msg.readShort(); // item id + msg.readLong(); // id + amount = msg.readShort(); + msg.readByte(); // type player_node->getInvItem(index)->setQuantity(amount); break; case SMSG_ITEM_USE_RESPONSE: - index = msg->readShort(); - amount = msg->readShort(); + index = msg.readShort(); + amount = msg.readShort(); - if (msg->readByte() == 0) { + if (msg.readByte() == 0) { chatWindow->chatLog("Failed to use item", BY_SERVER); } else { player_node->getInvItem(index)->setQuantity(amount); diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index aedbc3a1..4190bf83 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -31,7 +31,7 @@ class InventoryHandler : public MessageHandler public: InventoryHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/itemhandler.cpp b/src/net/itemhandler.cpp index 23a9fa60..2961f71b 100644 --- a/src/net/itemhandler.cpp +++ b/src/net/itemhandler.cpp @@ -40,28 +40,28 @@ ItemHandler::ItemHandler() handledMessages = _messages; } -void ItemHandler::handleMessage(MessageIn *msg) +void ItemHandler::handleMessage(MessageIn &msg) { Uint32 id; Uint16 x, y; Sint16 itemId; - switch (msg->getId()) + switch (msg.getId()) { case SMSG_ITEM_VISIBLE: case SMSG_ITEM_DROPPED: - id = msg->readLong(); - itemId = msg->readShort(); - msg->readByte(); // identify flag - x = msg->readShort(); - y = msg->readShort(); + id = msg.readLong(); + itemId = msg.readShort(); + msg.readByte(); // identify flag + x = msg.readShort(); + y = msg.readShort(); floorItemManager->create(id, itemId, x, y, engine->getCurrentMap()); break; case SMSG_ITEM_REMOVE: FloorItem *item; - item = floorItemManager->findById(msg->readLong()); + item = floorItemManager->findById(msg.readLong()); if (item) floorItemManager->destroy(item); break; diff --git a/src/net/itemhandler.h b/src/net/itemhandler.h index b2104722..5ffcb134 100644 --- a/src/net/itemhandler.h +++ b/src/net/itemhandler.h @@ -31,7 +31,7 @@ class ItemHandler : public MessageHandler public: ItemHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index 4790d7d1..700fb75a 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -41,13 +41,13 @@ LoginHandler::LoginHandler() handledMessages = _messages; } -void LoginHandler::handleMessage(MessageIn *msg) +void LoginHandler::handleMessage(MessageIn &msg) { - switch (msg->getId()) + switch (msg.getId()) { case APMSG_LOGIN_RESPONSE: { - int errMsg = msg->readByte(); + int errMsg = msg.readByte(); // Successful login if (errMsg == ERRMSG_OK) { @@ -79,7 +79,7 @@ void LoginHandler::handleMessage(MessageIn *msg) break; case APMSG_REGISTER_RESPONSE: { - int errMsg = msg->readByte(); + int errMsg = msg.readByte(); // Successful registration if (errMsg == ERRMSG_OK) { diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index 1b15b736..508ec0f5 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -36,7 +36,7 @@ class LoginHandler : public MessageHandler public: LoginHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); void setLoginData(LoginData *loginData) { mLoginData = loginData; }; diff --git a/src/net/maploginhandler.cpp b/src/net/maploginhandler.cpp index 579e8542..323e07fb 100644 --- a/src/net/maploginhandler.cpp +++ b/src/net/maploginhandler.cpp @@ -40,14 +40,14 @@ MapLoginHandler::MapLoginHandler() handledMessages = _messages; } -void MapLoginHandler::handleMessage(MessageIn *msg) +void MapLoginHandler::handleMessage(MessageIn &msg) { //unsigned char direction; - switch (msg->getId()) + switch (msg.getId()) { case SMSG_LOGIN_SUCCESS: - msg->readLong(); // server tick + msg.readLong(); // server tick //logger->log("Protocol: Player start position: (%d, %d), Direction: %d", // player_node->mX, player_node->mY, direction); state = STATE_GAME; diff --git a/src/net/maploginhandler.h b/src/net/maploginhandler.h index fe597549..3f779753 100644 --- a/src/net/maploginhandler.h +++ b/src/net/maploginhandler.h @@ -31,7 +31,7 @@ class MapLoginHandler : public MessageHandler public: MapLoginHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/messagehandler.h b/src/net/messagehandler.h index c09037f6..9f92636d 100644 --- a/src/net/messagehandler.h +++ b/src/net/messagehandler.h @@ -37,7 +37,7 @@ class MessageHandler MessageHandler(); virtual ~MessageHandler(); - virtual void handleMessage(MessageIn *msg) =0; + virtual void handleMessage(MessageIn &msg) = 0; void setNetwork(Network *network); diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 7e85a813..23ea8181 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -27,8 +27,6 @@ #include -#include "packet.h" - MessageIn::MessageIn(const char *data, unsigned int length): mData(data), mLength(length), diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 426a1c0d..4fca662a 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -27,8 +27,6 @@ #include -#include "packet.h" - MessageOut::MessageOut(): mData(0), mDataSize(0), diff --git a/src/net/network.cpp b/src/net/network.cpp index 2ce6fc2b..08b5fe92 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -160,7 +160,7 @@ Network::dispatchMessage(ENetPacket *packet) if (iter != mMessageHandlers.end()) { logger->log("Received packet %x (%i B)", msg.getId(), msg.getLength()); - iter->second->handleMessage(&msg); + iter->second->handleMessage(msg); } else { logger->log("Unhandled packet %x (%i B)", diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 62355180..9c89e71f 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -47,21 +47,23 @@ NPCHandler::NPCHandler() handledMessages = _messages; } -void NPCHandler::handleMessage(MessageIn *msg) +void NPCHandler::handleMessage(MessageIn &msg) { - switch (msg->getId()) + switch (msg.getId()) { case SMSG_NPC_CHOICE: - msg->readShort(); // length - current_npc = dynamic_cast(beingManager->findBeing(msg->readLong())); - npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); + msg.readShort(); // length + current_npc = dynamic_cast( + beingManager->findBeing(msg.readLong())); + npcListDialog->parseItems(msg.readString(msg.getLength() - 8)); npcListDialog->setVisible(true); break; case SMSG_NPC_MESSAGE: - msg->readShort(); // length - current_npc = dynamic_cast(beingManager->findBeing(msg->readLong())); - npcTextDialog->addText(msg->readString(msg->getLength() - 8)); + msg.readShort(); // length + current_npc = dynamic_cast( + beingManager->findBeing(msg.readLong())); + npcTextDialog->addText(msg.readString(msg.getLength() - 8)); npcListDialog->setVisible(false); npcTextDialog->setVisible(true); break; diff --git a/src/net/npchandler.h b/src/net/npchandler.h index 903ecd10..0cb40f64 100644 --- a/src/net/npchandler.h +++ b/src/net/npchandler.h @@ -31,7 +31,7 @@ class NPCHandler : public MessageHandler public: NPCHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/packet.cpp b/src/net/packet.cpp deleted file mode 100644 index e77ac117..00000000 --- a/src/net/packet.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "packet.h" - -#include - -Packet::Packet(const char *data, int length): - mLength(length) -{ - // Create a copy of the data - mData = new char[mLength]; - memcpy(mData, data, mLength); -} - -Packet::~Packet() -{ - // Clean up the data - delete[] mData; -} diff --git a/src/net/packet.h b/src/net/packet.h deleted file mode 100644 index 84d16d5e..00000000 --- a/src/net/packet.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_PACKET_ -#define _TMW_PACKET_ - -/** - * A packet wraps a certain amount of bytes for sending and receiving. - */ -class Packet -{ - public: - /** - * Constructor. - */ - Packet(const char *data, int length); - - /** - * Destructor. - */ - ~Packet(); - - char *mData; /**< Packet data */ - unsigned int mLength; /**< Length of data in bytes */ -}; - -#endif diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index d8ff81f4..f6065aaf 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -46,7 +46,9 @@ OkDialog *deathNotice = NULL; namespace { struct WeightListener : public gcn::ActionListener { - void action(const std::string &eventId, gcn::Widget *widget) { weightNotice = NULL; } + void action(const std::string &eventId, gcn::Widget *widget) { + weightNotice = NULL; + } } weightListener; } @@ -80,9 +82,9 @@ PlayerHandler::PlayerHandler() handledMessages = _messages; } -void PlayerHandler::handleMessage(MessageIn *msg) +void PlayerHandler::handleMessage(MessageIn &msg) { - switch (msg->getId()) + switch (msg.getId()) { case SMSG_WALK_RESPONSE: // It is assumed by the client any request to walk actually @@ -93,9 +95,9 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_WARP: { - std::string mapPath = msg->readString(16); - Uint16 x = msg->readShort(); - Uint16 y = msg->readShort(); + std::string mapPath = msg.readString(16); + Uint16 x = msg.readShort(); + Uint16 y = msg.readShort(); logger->log("Warping to %s (%d, %d)", mapPath.c_str(), x, y); @@ -114,13 +116,13 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_1: { - Sint16 type = msg->readShort(); - Uint32 value = msg->readLong(); + Sint16 type = msg.readShort(); + Uint32 value = msg.readLong(); switch (type) { //case 0x0000: - // player_node->setWalkSpeed(msg->readLong()); + // player_node->setWalkSpeed(msg.readLong()); // break; case 0x0005: player_node->mHp = value; break; case 0x0006: player_node->mMaxHp = value; break; @@ -169,30 +171,30 @@ void PlayerHandler::handleMessage(MessageIn *msg) break; case SMSG_PLAYER_STAT_UPDATE_2: - switch (msg->readShort()) { + switch (msg.readShort()) { case 0x0001: - player_node->mXp = msg->readLong(); + player_node->mXp = msg.readLong(); break; case 0x0002: - player_node->mJobXp = msg->readLong(); + player_node->mJobXp = msg.readLong(); break; case 0x0014: - player_node->mMoney = msg->readLong(); + player_node->mMoney = msg.readLong(); break; case 0x0016: - player_node->mXpForNextLevel = msg->readLong(); + player_node->mXpForNextLevel = msg.readLong(); break; case 0x0017: - player_node->mJobXpForNextLevel = msg->readLong(); + player_node->mJobXpForNextLevel = msg.readLong(); break; } break; case SMSG_PLAYER_STAT_UPDATE_3: { - Sint32 type = msg->readLong(); - Sint32 base = msg->readLong(); - Sint32 bonus = msg->readLong(); + Sint32 type = msg.readLong(); + Sint32 base = msg.readLong(); + Sint32 bonus = msg.readLong(); Sint32 total = base + bonus; switch (type) { @@ -214,9 +216,9 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_4: { - Sint16 type = msg->readShort(); - Sint8 fail = msg->readByte(); - Sint8 value = msg->readByte(); + Sint16 type = msg.readShort(); + Sint8 fail = msg.readByte(); + Sint8 value = msg.readByte(); if (fail != 1) break; @@ -240,60 +242,60 @@ void PlayerHandler::handleMessage(MessageIn *msg) // Updates stats and status points case SMSG_PLAYER_STAT_UPDATE_5: - player_node->mStatsPointsToAttribute = msg->readShort(); - player_node->mAttr[LocalPlayer::STR] = msg->readByte(); - player_node->mAttrUp[LocalPlayer::STR] = msg->readByte(); - player_node->mAttr[LocalPlayer::AGI] = msg->readByte(); - player_node->mAttrUp[LocalPlayer::AGI] = msg->readByte(); - player_node->mAttr[LocalPlayer::VIT] = msg->readByte(); - player_node->mAttrUp[LocalPlayer::VIT] = msg->readByte(); - player_node->mAttr[LocalPlayer::INT] = msg->readByte(); - player_node->mAttrUp[LocalPlayer::INT] = msg->readByte(); - player_node->mAttr[LocalPlayer::DEX] = msg->readByte(); - player_node->mAttrUp[LocalPlayer::DEX] = msg->readByte(); - player_node->mAttr[LocalPlayer::LUK] = msg->readByte(); - player_node->mAttrUp[LocalPlayer::LUK] = msg->readByte(); - player_node->ATK = msg->readShort(); // ATK - player_node->ATK_BONUS = msg->readShort(); // ATK bonus - player_node->MATK = msg->readShort(); // MATK max - player_node->MATK_BONUS = msg->readShort(); // MATK min - player_node->DEF = msg->readShort(); // DEF - player_node->DEF_BONUS = msg->readShort(); // DEF bonus - player_node->MDEF = msg->readShort(); // MDEF - player_node->MDEF_BONUS = msg->readShort(); // MDEF bonus - player_node->HIT = msg->readShort(); // HIT - player_node->FLEE = msg->readShort(); // FLEE - player_node->FLEE_BONUS = msg->readShort(); // FLEE bonus - msg->readShort(); // critical - msg->readShort(); // unknown + player_node->mStatsPointsToAttribute = msg.readShort(); + player_node->mAttr[LocalPlayer::STR] = msg.readByte(); + player_node->mAttrUp[LocalPlayer::STR] = msg.readByte(); + player_node->mAttr[LocalPlayer::AGI] = msg.readByte(); + player_node->mAttrUp[LocalPlayer::AGI] = msg.readByte(); + player_node->mAttr[LocalPlayer::VIT] = msg.readByte(); + player_node->mAttrUp[LocalPlayer::VIT] = msg.readByte(); + player_node->mAttr[LocalPlayer::INT] = msg.readByte(); + player_node->mAttrUp[LocalPlayer::INT] = msg.readByte(); + player_node->mAttr[LocalPlayer::DEX] = msg.readByte(); + player_node->mAttrUp[LocalPlayer::DEX] = msg.readByte(); + player_node->mAttr[LocalPlayer::LUK] = msg.readByte(); + player_node->mAttrUp[LocalPlayer::LUK] = msg.readByte(); + player_node->ATK = msg.readShort(); // ATK + player_node->ATK_BONUS = msg.readShort(); // ATK bonus + player_node->MATK = msg.readShort(); // MATK max + player_node->MATK_BONUS = msg.readShort(); // MATK min + player_node->DEF = msg.readShort(); // DEF + player_node->DEF_BONUS = msg.readShort(); // DEF bonus + player_node->MDEF = msg.readShort(); // MDEF + player_node->MDEF_BONUS = msg.readShort(); // MDEF bonus + player_node->HIT = msg.readShort(); // HIT + player_node->FLEE = msg.readShort(); // FLEE + player_node->FLEE_BONUS = msg.readShort(); // FLEE bonus + msg.readShort(); // critical + msg.readShort(); // unknown break; case SMSG_PLAYER_STAT_UPDATE_6: - switch (msg->readShort()) { + switch (msg.readShort()) { case 0x0020: - player_node->mAttrUp[LocalPlayer::STR] = msg->readByte(); + player_node->mAttrUp[LocalPlayer::STR] = msg.readByte(); break; case 0x0021: - player_node->mAttrUp[LocalPlayer::AGI] = msg->readByte(); + player_node->mAttrUp[LocalPlayer::AGI] = msg.readByte(); break; case 0x0022: - player_node->mAttrUp[LocalPlayer::VIT] = msg->readByte(); + player_node->mAttrUp[LocalPlayer::VIT] = msg.readByte(); break; case 0x0023: - player_node->mAttrUp[LocalPlayer::INT] = msg->readByte(); + player_node->mAttrUp[LocalPlayer::INT] = msg.readByte(); break; case 0x0024: - player_node->mAttrUp[LocalPlayer::DEX] = msg->readByte(); + player_node->mAttrUp[LocalPlayer::DEX] = msg.readByte(); break; case 0x0025: - player_node->mAttrUp[LocalPlayer::LUK] = msg->readByte(); + player_node->mAttrUp[LocalPlayer::LUK] = msg.readByte(); break; } break; case SMSG_PLAYER_ARROW_MESSAGE: { - Sint16 type = msg->readShort(); + Sint16 type = msg.readShort(); switch (type) { case 0: diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index b28a23f5..6d0baef7 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -31,7 +31,7 @@ class PlayerHandler : public MessageHandler public: PlayerHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/skillhandler.cpp b/src/net/skillhandler.cpp index 89009e47..d9bea775 100644 --- a/src/net/skillhandler.cpp +++ b/src/net/skillhandler.cpp @@ -39,27 +39,27 @@ SkillHandler::SkillHandler() handledMessages = _messages; } -void SkillHandler::handleMessage(MessageIn *msg) +void SkillHandler::handleMessage(MessageIn &msg) { int skillCount; - switch (msg->getId()) + switch (msg.getId()) { case SMSG_PLAYER_SKILLS: - msg->readShort(); // length - skillCount = (msg->getLength() - 4) / 37; + msg.readShort(); // length + skillCount = (msg.getLength() - 4) / 37; skillDialog->cleanList(); for (int k = 0; k < skillCount; k++) { - Sint16 skillId = msg->readShort(); - msg->readShort(); // target type - msg->readShort(); // unknown - Sint16 level = msg->readShort(); - Sint16 sp = msg->readShort(); - msg->readShort(); // range - std::string skillName = msg->readString(24); - Sint8 up = msg->readByte(); + Sint16 skillId = msg.readShort(); + msg.readShort(); // target type + msg.readShort(); // unknown + Sint16 level = msg.readShort(); + Sint16 sp = msg.readShort(); + msg.readShort(); // range + std::string skillName = msg.readString(24); + Sint8 up = msg.readByte(); if (level != 0 || up != 0) { @@ -77,11 +77,11 @@ void SkillHandler::handleMessage(MessageIn *msg) // Action failed (ex. sit because you have not reached the // right level) CHATSKILL action; - action.skill = msg->readShort(); - action.bskill = msg->readShort(); - action.unused = msg->readShort(); // unknown - action.success = msg->readByte(); - action.reason = msg->readByte(); + action.skill = msg.readShort(); + action.bskill = msg.readShort(); + action.unused = msg.readShort(); // unknown + action.success = msg.readByte(); + action.reason = msg.readByte(); if (action.success != SKILL_FAILED && action.bskill == BSKILL_EMOTE) { diff --git a/src/net/skillhandler.h b/src/net/skillhandler.h index 820a7b6a..8c0653d4 100644 --- a/src/net/skillhandler.h +++ b/src/net/skillhandler.h @@ -31,7 +31,7 @@ class SkillHandler : public MessageHandler public: SkillHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index b0baa5ea..2ebc160f 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -63,9 +63,9 @@ TradeHandler::TradeHandler() handledMessages = _messages; } -void TradeHandler::handleMessage(MessageIn *msg) +void TradeHandler::handleMessage(MessageIn &msg) { - switch (msg->getId()) + switch (msg.getId()) { case SMSG_TRADE_REQUEST: // If a trade window or request window is already open, send a @@ -81,7 +81,7 @@ void TradeHandler::handleMessage(MessageIn *msg) } player_node->setTrading(true); - tradePartnerName = msg->readString(24); + tradePartnerName = msg.readString(24); ConfirmDialog *dlg; dlg = new ConfirmDialog("Request for trade", tradePartnerName + @@ -90,7 +90,7 @@ void TradeHandler::handleMessage(MessageIn *msg) break; case SMSG_TRADE_RESPONSE: - switch (msg->readByte()) + switch (msg.readByte()) { case 0: // Too far away chatWindow->chatLog("Trading isn't possible. " @@ -126,11 +126,11 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_ITEM_ADD: { - Sint32 amount = msg->readLong(); - Sint16 type = msg->readShort(); - msg->readByte(); // identified flag - msg->readByte(); // attribute - msg->readByte(); // refine + Sint32 amount = msg.readLong(); + Sint16 type = msg.readShort(); + msg.readByte(); // identified flag + msg.readByte(); // attribute + msg.readByte(); // refine // TODO: handle also identified, etc if (type == 0) { @@ -144,10 +144,10 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_ITEM_ADD_RESPONSE: // Trade: New Item add response (was 0x00ea, now 01b1) { - Item *item = player_node->getInvItem(msg->readShort()); - Sint16 quantity = msg->readShort(); + Item *item = player_node->getInvItem(msg.readShort()); + Sint16 quantity = msg.readShort(); - switch (msg->readByte()) + switch (msg.readByte()) { case 0: // Successfully added item @@ -175,7 +175,7 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_OK: // 0 means ok from myself, 1 means ok from other; - tradeWindow->receivedOk(msg->readByte() == 0); + tradeWindow->receivedOk(msg.readByte() == 0); break; case SMSG_TRADE_CANCEL: diff --git a/src/net/tradehandler.h b/src/net/tradehandler.h index a1971004..0b73c871 100644 --- a/src/net/tradehandler.h +++ b/src/net/tradehandler.h @@ -33,7 +33,7 @@ class TradeHandler : public MessageHandler public: TradeHandler(); - void handleMessage(MessageIn *msg); + void handleMessage(MessageIn &msg); }; #endif -- cgit v1.2.3-70-g09d2 From fe682b5d44571749d8b28c42c7a9ec803324a672 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 27 Aug 2006 11:35:13 +0000 Subject: Got rid of no longer used protocol.cpp --- ChangeLog | 19 +++++++----- src/Makefile.am | 1 - src/net/messagein.cpp | 2 +- src/net/playerhandler.cpp | 13 -------- src/net/protocol.cpp | 79 ----------------------------------------------- src/net/protocol.h | 3 -- 6 files changed, 12 insertions(+), 105 deletions(-) delete mode 100644 src/net/protocol.cpp (limited to 'src/Makefile.am') diff --git a/ChangeLog b/ChangeLog index 2c1dd5ac..86ea7b87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-08-27 Bjørn Lindeijer + + * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, + src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, + src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, + src/net/messageout.cpp, src/net/messageout.h: Got rid of the default + MessageOut constructor, since all messages should have an ID. + * src/net/protocol.cpp, src/net/protocol.h, src/net/messagein.cpp, + src/net/playerhandler.cpp, src/Makefile.am: Got rid of no longer used + protocol.cpp. + 2006-08-26 Guillaume Melquiond * src/localplayer.cpp, src/net/protocol.h: Send move message @@ -9,14 +20,6 @@ tile-based coordinates to pixel-based coordinates (almost, they point to tile centers for now). -2006-08-27 Bjørn Lindeijer - - * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, - src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, - src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, - src/net/messageout.cpp, src/net/messageout.h: Got rid of the default - MessageOut constructor, since all messages should have an ID. - 2006-08-26 Bjørn Lindeijer * src/gui/char_select.cpp, src/gui/playerbox.cpp, src/player.cpp, diff --git a/src/Makefile.am b/src/Makefile.am index 8f40c506..aac3a8d3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -148,7 +148,6 @@ tmw_SOURCES = graphic/imagerect.h \ net/npchandler.h \ net/playerhandler.cpp \ net/playerhandler.h \ - net/protocol.cpp \ net/protocol.h \ net/skillhandler.cpp \ net/skillhandler.h \ diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 23ea8181..2c452a4d 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -90,7 +90,7 @@ std::string MessageIn::readString(int length) return ""; } - // Read the string + // Read the string char const *stringBeg = mData + mPos, *stringEnd = (char const *)memchr(stringBeg, '\0', length); std::string readString(stringBeg, stringEnd ? stringEnd - stringBeg : length); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index fc6bb37d..d21de6c4 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -283,19 +283,6 @@ void PlayerHandler::handleMessage(MessageIn &msg) } } break; - - //Stop walking - //case 0x0088: // Disabled because giving some problems - //if (being = beingManager->findBeing(readLong(2))) { - // if (being->getId() != player_node->getId()) { - // being->action = STAND; - // being->mFrame = 0; - // set_coordinates(being->coordinates, - // readWord(6), readWord(8), - // get_direction(being->coordinates)); - // } - //} - //break; } } diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp deleted file mode 100644 index d3db50bf..00000000 --- a/src/net/protocol.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "protocol.h" - -#define LOBYTE(w) ((unsigned char)(w)) -#define HIBYTE(w) ((unsigned char)(((unsigned short)(w)) >> 8)) - -void set_coordinates(char *data, - unsigned short x, - unsigned short y, - unsigned char direction) -{ - short temp; - temp = x; - temp <<= 6; - data[0] = 0; - data[1] = 1; - data[2] = 2; - data[0] = HIBYTE(temp); - data[1] = (unsigned char)(temp); - temp = y; - temp <<= 4; - data[1] |= HIBYTE(temp); - data[2] = LOBYTE(temp); - - // Translate direction to eAthena format - switch (direction) - { - case 1: - direction = 0; - break; - case 3: - direction = 1; - break; - case 2: - direction = 2; - break; - case 6: - direction = 3; - break; - case 4: - direction = 4; - break; - case 12: - direction = 5; - break; - case 8: - direction = 6; - break; - case 9: - direction = 7; - break; - default: - // OOPSIE! Impossible or unknown - direction = (unsigned char)-1; - } - data[2] |= direction; -} diff --git a/src/net/protocol.h b/src/net/protocol.h index be6e27cb..d99351f2 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -223,7 +223,4 @@ enum { CREATE_TOO_MUCH_CHARACTERS }; -/** Encodes coords and direction in 3 bytes data */ -void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction); - #endif -- cgit v1.2.3-70-g09d2 From 391203d83ed7a72b54fb7d7c72dbe35db14f0ea9 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 28 Aug 2006 23:04:08 +0000 Subject: Merged trunk development between revisions 2530 and 2618 to the 0.1.0 branch. --- AUTHORS | 2 +- ChangeLog | 171 +++++++++++++++++++++++++++++++++++---- NEWS | 9 ++- README | 1 + configure.ac | 13 +-- data/graphics/Makefile.am | 2 +- data/graphics/images/Makefile.am | 1 + data/help/commands.txt | 1 + debian/control | 2 +- debian/tmw-data.install | 1 + src/Makefile.am | 1 + src/animatedsprite.cpp | 17 ++-- src/animation.cpp | 20 ++++- src/animation.h | 16 +++- src/engine.cpp | 104 +++++++++++++++++------- src/engine.h | 5 ++ src/floor_item.cpp | 5 +- src/floor_item.h | 1 + src/game.cpp | 29 ++++++- src/gui/char_select.cpp | 5 ++ src/gui/char_select.h | 5 ++ src/gui/chat.cpp | 2 +- src/gui/equipmentwindow.cpp | 9 +-- src/gui/equipmentwindow.h | 3 - src/gui/gui.cpp | 10 ++- src/gui/itemcontainer.cpp | 21 +++-- src/gui/itemcontainer.h | 2 - src/gui/ministatus.cpp | 42 ++++++++-- src/gui/ministatus.h | 10 ++- src/gui/setup.cpp | 4 +- src/gui/setup_joystick.cpp | 57 ++++++++++--- src/gui/setup_joystick.h | 6 +- src/gui/setup_video.cpp | 78 +++++++++++++++++- src/gui/setup_video.h | 16 ++++ src/gui/window.cpp | 21 +++++ src/gui/window.h | 20 +++++ src/joystick.cpp | 20 ++--- src/joystick.h | 39 ++++++--- src/main.cpp | 25 +++++- src/map.cpp | 113 +++++++++++++++++++++++++- src/map.h | 30 ++++++- src/net/inventoryhandler.cpp | 9 +++ src/player.cpp | 16 +++- src/player.h | 8 ++ src/resources/iteminfo.cpp | 44 ++++++++++ src/resources/iteminfo.h | 16 ++-- src/resources/itemmanager.cpp | 12 +-- src/resources/mapreader.cpp | 27 +++++++ tmw.cbp | 14 ++++ 49 files changed, 924 insertions(+), 161 deletions(-) create mode 100644 src/resources/iteminfo.cpp (limited to 'src/Makefile.am') diff --git a/AUTHORS b/AUTHORS index 2a0628cf..19d28884 100644 --- a/AUTHORS +++ b/AUTHORS @@ -25,7 +25,7 @@ The Mana World Dev Team Magick (music and sound effects) Neko-mon (player sprites, various things) Neorice (monster sprites, tiles) - Modanung (mohawk) + Modanung (pixel art, concept art) Pajarico (concepts) Rotonen (backstory, art director, music, sound) Talaroc (sprites) diff --git a/ChangeLog b/ChangeLog index fccfe4b8..5f20fdb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,20 +4,19 @@ * src/net/beinghandler.cpp, src/net/protocol.h: Added support for entering monsters. -2006-08-27 Bjørn Lindeijer +2006-08-28 Philipp Sehmisch - * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, - src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, - src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, - src/net/messageout.cpp, src/net/messageout.h: Got rid of the default - MessageOut constructor, since all messages should have an ID. - * src/net/protocol.cpp, src/net/protocol.h, src/net/messagein.cpp, - src/net/playerhandler.cpp, src/Makefile.am: Got rid of no longer used - protocol.cpp. - * src/gui/login.cpp, src/gui/register.h, src/gui/login.h, - src/gui/register.cpp: Got rid of server input field since connecting - to the account server now happens before the login and register - dialogs. + * src/gui/setup_video.cpp: Modified the ranges of the ScrollLaziness + and ScrollRadius sliders. + +2006-08-28 Eugenio Favalli + + * data/graphics/items/*: Changed svn properties. + * data/graphics/sprites/item001.xml, data/graphics/sprites/item002.xml, + data/graphics/sprites/item003.xml, data/graphics/sprites/item004.xml, + data/graphics/sprites/item005.xml, data/graphics/sprites/item006.png, + data/graphics/sprites/item006.xml, data/graphics/sprites/Makefile.am: + Added headband and fixed svn properties. 2006-08-27 Guillaume Melquiond @@ -39,6 +38,35 @@ * src/engine.cpp, src/localplayer.cpp, src/gui/gui.cpp, src/being.cpp, src/being.h: Implemented pixel-grained movements. +2006-08-27 Bjørn Lindeijer + + * src/net/inventoryhandler.cpp: Applied patch by AHarrison that adds + item pickup messages to the chat window. + * NEWS: Updated with some recently added and fixed issues. Doesn't + mention any of the recent content updates yet. + * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, + src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, + src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, + src/net/messageout.cpp, src/net/messageout.h: Got rid of the default + MessageOut constructor, since all messages should have an ID. + * src/net/protocol.cpp, src/net/protocol.h, src/net/messagein.cpp, + src/net/playerhandler.cpp, src/Makefile.am: Got rid of no longer used + protocol.cpp. + * src/gui/login.cpp, src/gui/register.h, src/gui/login.h, + src/gui/register.cpp: Got rid of server input field since connecting + to the account server now happens before the login and register + dialogs. + +2006-08-26 Pascal Ganaye + + * src/joystick.h, src/joystick.cpp, src/gui/setup.cpp, + src/gui/setup_joystick.h, src/gui/setup_video.cpp, + src/gui/setup_joystick.cpp, src/gui/setup_video.h: Added sliders to + the video section of the setup window to configure the laziness and + radius of the scrolling behaviour. Added a checkbox to the joystick + section to allow enabling/disabling the joystick (patch applied by + Bjørn Lindeijer). + 2006-08-26 Bjørn Lindeijer * src/gui/char_select.cpp, src/gui/playerbox.cpp, src/player.cpp, @@ -49,6 +77,15 @@ defined as being bald (so bald is no longer a hardcoded style). * src/player.cpp, src/being.cpp, src/net/charserverhandler.cpp, src/being.h: Fixed player sprite not showing up. + * src/gui/ministatus.cpp, src/gui/ministatus.h: Applied patch by mrha + (Herbi), adding experience bar to the ministatus in the top left. + * configure.ac, data/graphics/items/Makefile.am, + data/graphics/Makefile.am: Added Makefile.am to make sure the item + icons are installed. + * src/player.cpp, src/animation.h, src/player.h, + src/animatedsprite.cpp, src/animation.cpp: Applied patch by Bahamut81 + which implements resetting of Animation, Action and AnimatedSprite. + This fixes the animation synchronization issues. 2006-08-26 Guillaume Melquiond @@ -68,10 +105,91 @@ * src/net/beinghandler.cpp, src/net/beinghandler.h, src/net/protocol.h: Added support for "beings move" messages. +2006-08-25 Matthias Hartmann + + * src/gui/char_select.cpp, src/gui/char_select.h, src/main.cpp: Added + --playername command line option for selecting the character you want + to play with (patch applied by Bjørn Lindeijer). + +2006-08-25 Philipp Sehmisch + + * src/engine.cpp, src/map.h, src/map.cpp: Addded new config variable + "OverlayDetail" to control the number of drawn overlays. + 2 (or more) = all (default), 1 = only the first one, 0 = none. + +2006-08-24 Eugenio Favalli + + * data/help/commands.txt, README, src/game.cpp, src/gui/chat.cpp, + src/gui/window.cpp, src/gui/window.h: Added support for sticky windows + as discussed with doener. Patch by AHarrison. + * data/items.xml: Added jeans shorts. + +2006-08-24 Philipp Sehmisch + + * src/engine.cpp: Scrolling speed no longer affected by framerate. + * src/map.cpp, scr/map.h: Overlay speed no longer affected by + framerate. + * data/maps/new_1-1.tmx.gz, data/graphics/new_7-1.tmx.gz, + data/graphics/images/ambient/sandstorm.png: Redone sandstorm effect + (larger and more transparent image, tripple layer parallax scrolling) + +2006-08-24 Frode Lindeijer + + * data/graphics/sprites/item004.png, + data/graphics/sprites/item005.png, data/graphics/sprites/Makefile.am, + data/graphics/items/armor-legs-cottonshorts, + data/graphics/items/armor-legs-jeanshorts: Added the equip graphics of + the short jeans and the cotton shorts and an inventory icon of the + cotton shorts. Also added all added files to the makefile. + +2006-08-23 Philipp Sehmisch + + * data/maps/new_7-1.tmx.gz: Fixed a minor mapping bug reported on the + forum (no new walkmap required). + * data/maps/new_9-1.tmx.gz: Fixed two minor mapping bugs (new walkmap + required). + +2006-08-22 Bjørn Lindeijer + + * configure.ac, data/graphics/images/ambient, + data/graphics/images/ambient/Makefile.am, + data/graphics/images/Makefile.am: Updated makefiles to account for new + ambient images and changed the version from 0.0.20.1 to 0.0.21. + 2006-08-21 Eugenio Favalli * The Mana World.dev, tmw.cbp: Updated project files. +2006-08-21 Philipp Sehmisch + + * src/mapreader.cpp: Added logic for initialisation of the overlays. + * src/map.cpp, src/map.h: Code for updating and drawing the overlays. + * src/engine.cpp, src/engine.h: Added smooth scrolling and the call + to draw the overlays. + * data/maps/new_1-1.tmx.gz, data/graphics/new_7-1.tmx.gz, + data/graphics/images/ambient/sandstorm.png: Added sandstorm effect + to the desert maps outside of the city (feedback, please). + * data/maps/new_2-1.tmx.gz, data/maps/new_4-1.tmx.gz, + data/maps/new_5-1.tmx.gz, data/graphics/images/ambient/spotlight.png + Added spotlight effect to the cave maps (feedback, please) + * data/graphics/maps/new_9-1.tmx.gz, + data/graphics/images/ambient/clouds.png: + Added cloudshadow effect to the woodland map (feedback, please). + +2006-08-20 Bjørn Lindeijer + + * configure.ac: Moved libpng check before SDL_image check, since the + latter requires the former. + +2006-08-20 Yohann Ferreira + + * data/graphics/sprites/Makefile.am : Following the splitting from + Philipp, moved out the items.png file from the Makefile.am. + * debian/control, debian/tmw-data.install : Updated debian package + creation process. + * src/Makefile.am : Added iteminfo.cpp to avoid an undefined reference + with gcc 4.1.2. Happy to be back :) + 2006-08-20 Bjørn Lindeijer * src/gui/connection.cpp, src/gui/login.cpp, src/gui/gui.cpp, @@ -111,6 +229,22 @@ * src/game.cpp, src/net/network.h, src/net/network.cpp: Removed incoming packets queue. Messages are now processed as they come in. +2006-08-17 Philipp Sehmisch + + * data/graphics/items/*: Splitted the items.png into separate images + with more distinctive names. (no, i won't list all 114) + * src/itemmanager.cpp, data/items.xml: Replaced indices on the item + spriteset with filenames. added names and descriptions for all missing + items. Changed names and dascriptions of some items. + * src/engine.cpp: removed global item spriteset. + * src/floor_item.cpp, src/floor_item.h, src/iteminfo.cpp, + src/iteminfo.h, src/equipmentwindow.cpp, src/equipmentwindow.h, + src/itemcontainer.cpp, src/itemcontainer.h: the iteminfo class now + provides a pointer to the item icon image instead of providing the + index on the item spriteset. + * data/graphics/tiles/trans_desert-woodland.png: added transmission + tileset between desert and woodland. + 2006-08-15 Bjørn Lindeijer * src/gui/char_select.cpp, src/net/charserverhandler.h, @@ -143,6 +277,15 @@ * src/player.cpp: Verify the gender to prevent crashing when something is wrong with the communication. +2006-08-13 Eugenio Favalli + + * data/graphics/sprites/Makefile.am, + data/graphics/sprites/monster18.png, + data/graphics/sprites/monster18.xml, + data/graphics/sprites/npcs.png: Added new monster and npcs. + * src/gui.cpp, tmw.cbp, The Mana World.dev: Fixed Guichan 0.5.0 + compilation issues. + 2006-08-13 Bjørn Lindeijer * src/openglgraphics.cpp, src/gui/browserbox.h, src/gui/gui.cpp, @@ -672,7 +815,7 @@ * data/items.xml, src/being.cpp, src/being.h src/net/beinghandler.cpp, src/player.cpp: Clients get notified of equipping visible items. * src/net/beinghandler.cpp: GCC 4 fix. - + 2006-06-28 Philipp Sehmisch * src/animation.cpp, src/animation.h: Parser now works like described diff --git a/NEWS b/NEWS index ad78fc4f..cf837a25 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,12 @@ -0.0.20.1 (25 July 2006) +0.0.21 (.. September 2006) +- Added item pickup messages to the chat dialog +- Added XP bar to ministatus in the top left +- Added configurable smooth and lazy scrolling +- Added option to turn off the joystick +- Added --playername command line option for automatic character picking - Fixed updating system on Windows +- Fixed player animations going out of sync on changing equipment or hairstyle +- Fixed SDL_image configure check on some systems by first checking for libpng 0.0.20 (24 July 2006) - Added new hairstyle, and some fixes to the old ones diff --git a/README b/README index 8fdd2b72..5fad4312 100644 --- a/README +++ b/README @@ -53,6 +53,7 @@ Use arrow keys to move around. Other keys: - Alt + S sit down / stand up - Alt + F toggle debug pathfinding feature - Alt + P take screenshot +- H hide all non-sticky windows - G or Z pick up item - Enter focus chat window / send message - Shift hold it when attacking to lock target for auto attack diff --git a/configure.ac b/configure.ac index 4c5a492a..ce4c6cc5 100755 --- a/configure.ac +++ b/configure.ac @@ -70,8 +70,12 @@ AC_MSG_ERROR([ *** Unable to find libxml2 library (http://xmlsoft.org/)])) AC_CHECK_HEADERS([libxml/xmlreader.h], , AC_MSG_ERROR([ *** libxml2 library found but cannot find headers (http://xmlsoft.org/)])) -AC_CHECK_LIB([SDL_image], [IMG_LoadPNG_RW], , -AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support (http://www.libsdl.org/projects/SDL_image/)])) +AC_CHECK_LIB(png, png_write_info, , +AC_MSG_ERROR([ *** Unable to find png library])) + +AC_CHECK_LIB(SDL_image, IMG_LoadPNG_RW, , +AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support +(http://www.libsdl.org/projects/SDL_image/)])) AC_CHECK_LIB([guichan_sdl], [gcnSDL], , AC_MSG_ERROR([ *** Unable to find Guichan SDL library (http://guichan.sf.net/)])) @@ -82,9 +86,6 @@ AC_MSG_ERROR([ *** Unable to find SDL_mixer library (http://www.libsdl.org/proje AC_CHECK_LIB([enet], [enet_initialize], , AC_MSG_ERROR([ *** Unable to find enet library (http://enet.bespin.org/)])) -AC_CHECK_LIB(png, png_write_info, , -AC_MSG_ERROR([ *** Unable to find png library (http://www.libpng.org/)])) - # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h]) @@ -108,6 +109,8 @@ data/Makefile data/graphics/Makefile data/graphics/gui/Makefile data/graphics/images/Makefile +data/graphics/images/ambient/Makefile +data/graphics/items/Makefile data/graphics/sprites/Makefile data/graphics/tiles/Makefile data/help/Makefile diff --git a/data/graphics/Makefile.am b/data/graphics/Makefile.am index 43354894..19e95869 100644 --- a/data/graphics/Makefile.am +++ b/data/graphics/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = gui images sprites tiles +SUBDIRS = gui images items sprites tiles diff --git a/data/graphics/images/Makefile.am b/data/graphics/images/Makefile.am index 8fbe3694..e0707698 100644 --- a/data/graphics/images/Makefile.am +++ b/data/graphics/images/Makefile.am @@ -1,3 +1,4 @@ +SUBDIRS = ambient imagesdir = $(pkgdatadir)/data/graphics/images diff --git a/data/help/commands.txt b/data/help/commands.txt index dbb37195..37c77df2 100644 --- a/data/help/commands.txt +++ b/data/help/commands.txt @@ -23,6 +23,7 @@ ##2Alt + S##P sit down / stand up ##2Alt + F##P toggle debug pathfinding feature ##2Alt + P##P take screenshot + ##2H##P hide all non-sticky windows ##2G or Z##P pick up item ##2Enter##P focus chat window / send message ##2Shift##P hold it when attacking to lock target for auto diff --git a/debian/control b/debian/control index ad079b7d..45a906b6 100644 --- a/debian/control +++ b/debian/control @@ -1,7 +1,7 @@ Source: tmw Priority: optional Maintainer: FERREIRA Yohann -Build-Depends: debhelper (>= 4.0.0), autotools-dev, docbook-to-man, libsdl1.2-dev (>= 1.2.7), libsdl-image1.2-dev (>= 1.2.3), libsdl-mixer1.2-dev (>= 1.2.5), libguichan0-dev (>= 0.4.0-4), libcurl3-gnutls-dev (>= 7.15.0-1), libxml2-dev (>= 2.4.19), libphysfs-dev (>= 1.0.0-1), libgl1-mesa-dev (>= 6.4.1), libpng12-dev (>= 1.2.5), libsdl-net1.2-dev (>= 1.2.5) +Build-Depends: debhelper (>= 4.0.0), autotools-dev, docbook-to-man, libsdl1.2-dev (>= 1.2.7), libsdl-image1.2-dev (>= 1.2.3), libsdl-mixer1.2-dev (>= 1.2.5), libguichan0-dev (>= 0.5.0-1), libcurl3-gnutls-dev (>= 7.15.0-1), libxml2-dev (>= 2.4.19), libphysfs-dev (>= 1.0.0-1), libgl1-mesa-dev (>= 6.4.1), libpng12-dev (>= 1.2.5), libsdl-net1.2-dev (>= 1.2.5) Standards-Version: 3.6.2 Package: tmw diff --git a/debian/tmw-data.install b/debian/tmw-data.install index 5e2e537e..71b34a98 100644 --- a/debian/tmw-data.install +++ b/debian/tmw-data.install @@ -2,6 +2,7 @@ data/items.xml usr/share/games/tmw/data data/help/*.txt usr/share/games/tmw/data/help data/graphics/gui/*.png usr/share/games/tmw/data/graphics/gui data/graphics/sprites/*.png usr/share/games/tmw/data/graphics/sprites +data/graphics/sprites/*.xml usr/share/games/tmw/data/graphics/sprites data/graphics/images/*.png usr/share/games/tmw/data/graphics/images data/graphics/tiles/*.png usr/share/games/tmw/data/graphics/tiles data/maps/*.tmx.gz usr/share/games/tmw/data/maps diff --git a/src/Makefile.am b/src/Makefile.am index aac3a8d3..1e8a1424 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -158,6 +158,7 @@ tmw_SOURCES = graphic/imagerect.h \ resources/imagewriter.cpp \ resources/imagewriter.h \ resources/iteminfo.h \ + resources/iteminfo.cpp \ resources/itemmanager.cpp \ resources/itemmanager.h \ resources/mapreader.cpp \ diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 8f9c0600..f984d13f 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -49,12 +49,14 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): free(data); if (!doc) { - logger->error("Animation: Error while parsing animation definition file!"); + logger->error( + "Animation: Error while parsing animation definition file!"); } xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "sprite")) { - logger->error("Animation: this is not a valid animation definition file!"); + logger->error( + "Animation: this is not a valid animation definition file!"); } // Get the variant @@ -233,13 +235,14 @@ AnimatedSprite::~AnimatedSprite() void AnimatedSprite::reset() { - // Reset all defined actions (because of aliases, some will be resetted - // multiple times) + // Reset all defined actions (because of aliases some will be resetted + // multiple times, but this doesn't matter) for (ActionIterator i = mActions.begin(); i != mActions.end(); ++i) { - //TODO: If resetting everything is really a nice way of fixing the - // synchronization issues, finish implementing this. - //i->second->reset(); + if (i->second) + { + i->second->reset(); + } } } diff --git a/src/animation.cpp b/src/animation.cpp index 1213d0d6..c1b27ebd 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -27,9 +27,15 @@ #include "utils/dtor.h" -Animation::Animation(): - mTime(0) +Animation::Animation() { + reset(); +} + +void +Animation::reset() +{ + mTime = 0; iCurrentPhase = mAnimationPhases.begin(); } @@ -123,3 +129,13 @@ Action::setAnimation(int direction, Animation *animation) mAnimations[direction] = animation; } + +void +Action::reset() +{ + for (AnimationIterator i = mAnimations.begin(); + i != mAnimations.end(); ++i) + { + i->second->reset(); + } +} diff --git a/src/animation.h b/src/animation.h index c5b277b7..60dcd287 100644 --- a/src/animation.h +++ b/src/animation.h @@ -55,6 +55,12 @@ class Animation */ Animation(); + /** + * Restarts the animation from the first frame. + */ + void + reset(); + void addPhase(int image, unsigned int delay, int offsetX, int offsetY); @@ -68,13 +74,13 @@ class Animation * Returns the x offset of the current frame. */ int - getOffsetX() const { return (*iCurrentPhase).offsetX; }; + getOffsetX() const { return iCurrentPhase->offsetX; }; /** * Returns the y offset of the current frame. */ int - getOffsetY() const { return (*iCurrentPhase).offsetY; }; + getOffsetY() const { return iCurrentPhase->offsetY; }; /** * Returns the length of this animation. @@ -119,6 +125,12 @@ class Action void setAnimation(int direction, Animation *animation); + /** + * Resets all animations associated with this action. + */ + void + reset(); + Animation* getAnimation(int direction) const; diff --git a/src/engine.cpp b/src/engine.cpp index eda154f3..28410748 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -27,6 +27,7 @@ #include "being.h" #include "beingmanager.h" +#include "configuration.h" #include "flooritemmanager.h" #include "game.h" #include "graphics.h" @@ -54,7 +55,6 @@ int camera_x, camera_y; ItemManager *itemDb; /**< Item database object */ -Spriteset *itemset; Spriteset *emotionset; Spriteset *npcset; std::vector weaponset; @@ -79,11 +79,9 @@ Engine::Engine(): weaponset.push_back(tmp); } } - itemset = resman->getSpriteset("graphics/sprites/items.png", 32, 32); if (!npcset) logger->error("Unable to load NPC spriteset!"); if (!emotionset) logger->error("Unable to load emotions spriteset!"); - if (!itemset) logger->error("Unable to load item spriteset!"); // Initialize item manager itemDb = new ItemManager(); @@ -94,7 +92,6 @@ Engine::~Engine() // Delete sprite sets npcset->decRef(); emotionset->decRef(); - itemset->decRef(); std::for_each(weaponset.begin(), weaponset.end(), std::mem_fun(&Spriteset::decRef)); @@ -157,34 +154,85 @@ void Engine::draw(Graphics *graphics) { int midTileX = graphics->getWidth() / 2; int midTileY = graphics->getHeight() / 2; + static int lastTick = tick_time; - int map_x = (player_node->mX - midTileX) + player_node->getXOffset(); - int map_y = (player_node->mY - midTileY) + player_node->getYOffset(); + // Avoid freaking out when tick_time overflows + if (tick_time < lastTick) + { + lastTick = tick_time; + } + + int player_x = player_node->mX - midTileX + player_node->getXOffset(); + int player_y = player_node->mY - midTileY + player_node->getYOffset(); + + scrollLaziness = (int)config.getValue("ScrollLaziness", 32); + scrollRadius = (int)config.getValue("ScrollRadius", 32); + + if (scrollLaziness < 1) + scrollLaziness = 1; //avoids division by zero + + //apply lazy scrolling + while (lastTick < tick_time) + { + if (player_x > view_x + scrollRadius) + { + view_x += (player_x - view_x - scrollRadius) / scrollLaziness; + } + if (player_x < view_x - scrollRadius) + { + view_x += (player_x - view_x + scrollRadius) / scrollLaziness; + } + if (player_y > view_y + scrollRadius) + { + view_y += (player_y - view_y - scrollRadius) / scrollLaziness; + } + if (player_y < view_y - scrollRadius) + { + view_y += (player_y - view_y + scrollRadius) / scrollLaziness; + } + lastTick++; + } + + //auto center when player is off screen + if ( player_x - view_x > graphics->getWidth() / 2 + || view_x - player_x > graphics->getWidth() / 2 + || view_y - player_y > graphics->getHeight() / 2 + || player_y - view_y > graphics->getHeight() / 2 + ) + { + view_x = player_x; + view_y = player_y; + }; if (mCurrentMap) { - if (map_x < 0) { - map_x = 0; + if (view_x < 0) { + view_x = 0; } - if (map_y < 0) { - map_y = 0; + if (view_y < 0) { + view_y = 0; } - if (map_x > mCurrentMap->getWidth() * 32 - midTileX) { - map_x = mCurrentMap->getWidth() * 32 - midTileX; + if (view_x > mCurrentMap->getWidth() * 32 - midTileX) { + view_x = mCurrentMap->getWidth() * 32 - midTileX; } - if (map_y > mCurrentMap->getHeight() * 32 - midTileY) { - map_y = mCurrentMap->getHeight() * 32 - midTileY; + if (view_y > mCurrentMap->getHeight() * 32 - midTileY) { + view_y = mCurrentMap->getHeight() * 32 - midTileY; } } - camera_x = map_x; - camera_y = map_y; + camera_x = (int)(view_x + 16); + camera_y = (int)(view_y + 16); // Draw tiles and sprites if (mCurrentMap != NULL) { - mCurrentMap->draw(graphics, map_x, map_y, 0); - mCurrentMap->draw(graphics, map_x, map_y, 1); - mCurrentMap->draw(graphics, map_x, map_y, 2); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 0); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 1); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 2); + mCurrentMap->drawOverlay( graphics, + view_x, + view_y, + (int)config.getValue("OverlayDetail", 2) + ); } else { @@ -202,8 +250,8 @@ void Engine::draw(Graphics *graphics) int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = (mouseX + map_x) / 32; - int mouseTileY = (mouseY + map_y) / 32; + int mouseTileX = (int)(mouseX + view_x) / 32; + int mouseTileY = (int)(mouseY + view_y) / 32; Path debugPath = mCurrentMap->findPath( player_node->mX / 32, player_node->mY / 32, @@ -212,8 +260,8 @@ void Engine::draw(Graphics *graphics) graphics->setColor(gcn::Color(255, 0, 0)); for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) { - int squareX = i->x * 32 - map_x + 12; - int squareY = i->y * 32 - map_y + 12; + int squareX = i->x * 32 - int(view_x) + 12; + int squareY = i->y * 32 - int(view_y) + 12; graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); graphics->drawText( @@ -226,9 +274,9 @@ void Engine::draw(Graphics *graphics) Beings *beings = beingManager->getAll(); for (BeingIterator i = beings->begin(); i != beings->end(); i++) { - (*i)->drawSpeech(graphics, -map_x, -map_y); - (*i)->drawName(graphics, -map_x, -map_y); - (*i)->drawEmotion(graphics, -map_x, -map_y); + (*i)->drawSpeech(graphics, -(int)view_x, -(int)view_y); + (*i)->drawName(graphics, -(int)view_x, -(int)view_y); + (*i)->drawEmotion(graphics, -(int)view_x, -(int)view_y); } // Draw target marker if needed @@ -239,8 +287,8 @@ void Engine::draw(Graphics *graphics) graphics->setColor(gcn::Color(255, 255, 255)); int dy = (target->getType() == Being::PLAYER) ? 90 : 52; - graphics->drawText("[TARGET]", target->getPixelX() - map_x + 15, - target->getPixelY() - map_y - dy, gcn::Graphics::CENTER); + graphics->drawText("[TARGET]", target->getPixelX() - (int)view_x + 15, + target->getPixelY() - (int)view_y - dy, gcn::Graphics::CENTER); } gui->draw(); diff --git a/src/engine.h b/src/engine.h index bdf8419a..e8ef7e33 100644 --- a/src/engine.h +++ b/src/engine.h @@ -76,6 +76,11 @@ class Engine bool mShowDebugPath; Map *mCurrentMap; + + int scrollRadius; + int scrollLaziness; + float view_x; // current viewpoint in pixels + float view_y; // current viewpoint in pixels }; extern Engine *engine; diff --git a/src/floor_item.cpp b/src/floor_item.cpp index 1581b201..edd5d4a7 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -29,7 +29,6 @@ #include "resources/iteminfo.h" #include "resources/spriteset.h" -extern Spriteset *itemset; FloorItem::FloorItem(unsigned int id, unsigned int itemId, @@ -42,8 +41,8 @@ FloorItem::FloorItem(unsigned int id, mY(y), mMap(map) { - // Retrieve item image using a global itemset and itemDb (alternative?) - mImage = itemset->get(itemDb->getItemInfo(itemId)->getImage() - 1); + // Retrieve item image from item info + mImage = itemDb->getItemInfo(itemId)->getImage(); // Add ourselves to the map mSpriteIterator = mMap->addSprite(this); diff --git a/src/floor_item.h b/src/floor_item.h index 24eb495d..386d0759 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -27,6 +27,7 @@ #include "graphics.h" #include "map.h" #include "sprite.h" +#include "resources/image.h" /** * An item lying on the floor. diff --git a/src/game.cpp b/src/game.cpp index 3e789728..f5ebe095 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -202,6 +202,10 @@ void createGuiWindows() minimap->getHeight() + 30);*/ // Set initial window visibility + chatWindow->setSticky(true); + miniStatusWindow->setSticky(true); + menuWindow->setSticky(true); + chatWindow->setVisible(true); miniStatusWindow->setVisible(true); statusWindow->setVisible(false); @@ -457,7 +461,30 @@ void Game::handleInput() } break; - // Picking up items on the floor + // Attempt to hide all windows + case SDLK_h: + chatWindow->setVisible(false); + miniStatusWindow->setVisible(false); + statusWindow->setVisible(false); + menuWindow->setVisible(false); + buyDialog->setVisible(false); + sellDialog->setVisible(false); + buySellDialog->setVisible(false); + inventoryWindow->setVisible(false); + npcTextDialog->setVisible(false); + npcListDialog->setVisible(false); + skillDialog->setVisible(false); + //newSkillWindow->setVisible(false); + setupWindow->setVisible(false); + equipmentWindow->setVisible(false); + chargeDialog->setVisible(false); + tradeWindow->setVisible(false); + //buddyWindow->setVisible(false); + helpWindow->setVisible(false); + debugWindow->setVisible(false); + break; + + // Picking up items on the floor case SDLK_g: case SDLK_z: if (!chatWindow->isFocused()) diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index adcbe290..042a5be8 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -224,6 +224,11 @@ void CharSelectDialog::logic() updatePlayerInfo(); } +std::string CharSelectDialog::getName() +{ + return mNameLabel->getCaption(); +} + CharCreateDialog::CharCreateDialog(Window *parent, int slot): Window("Create Character", true, parent), mSlot(slot) { diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 73fc8b2d..06881bb5 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -54,6 +54,11 @@ class CharSelectDialog : public Window, public gcn::ActionListener void logic(); + /** + * Returns name of selected player + */ + std::string getName(); + private: LockedArray *mCharInfo; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 9098f9f0..9a5d60b0 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -395,7 +395,7 @@ ChatWindow::setInputText(std::string input_str) void ChatWindow::setVisible(bool isVisible) { - Widget::setVisible(isVisible); + Window::setVisible(isVisible); /* * For whatever reason, if setVisible is called, the mTmpVisible effect diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index bef39dff..2cbffde4 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -40,15 +40,10 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): setWindowName("Equipment"); setDefaultSize(5, 230, 200, 120); loadWindowState(); - - mItemset = ResourceManager::getInstance()->getSpriteset( - "graphics/sprites/items.png", 32, 32); - if (!mItemset) logger->error("Unable to load items.png"); } EquipmentWindow::~EquipmentWindow() { - mItemset->decRef(); } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -70,7 +65,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) continue; } - image = mItemset->get(item->getInfo()->getImage() - 1); + image = item->getInfo()->getImage(); dynamic_cast(graphics)->drawImage( image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); } @@ -81,7 +76,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) return; } - image = mItemset->get(item->getInfo()->getImage() - 1); + image = item->getInfo()->getImage(); dynamic_cast(graphics)->drawImage(image, 160, 25); graphics->drawText(toString(item->getQuantity()), 170, 62, diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index aeaae58c..99a3cc60 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -27,7 +27,6 @@ #include "window.h" class Equipment; -class Spriteset; /** * Equipment dialog. @@ -53,8 +52,6 @@ class EquipmentWindow : public Window void draw(gcn::Graphics *graphics); private: - Spriteset *mItemset; - Equipment *mEquipment; }; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 69563dc1..b27868e3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -27,11 +27,13 @@ #include #include - -// Moved up because of nested inclusion of winnt.h which defines DELETE -// constant as well as guichan does +// Should stay here because of Guichan being sensitive to headers order #include +#ifdef USE_OPENGL +#include "../resources/openglsdlimageloader.h" +#endif + #include "focushandler.h" #include "popupmenu.h" #include "window.h" @@ -231,6 +233,7 @@ Gui::draw() void Gui::mousePress(int mx, int my, int button) { + printf("Gui::mousePress(%d,%d)\n", mx, my); // Mouse pressed on window container (basically, the map) // Are we in-game yet? @@ -247,6 +250,7 @@ Gui::mousePress(int mx, int my, int button) int tilex = (mx + camera_x) / 32; int tiley = (my + camera_y) / 32; + printf("tilex,tiley: %d,%d\n", tilex, tiley); // Right click might open a popup if (button == gcn::MouseInput::RIGHT) diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index edcf9764..c7c55fd9 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -41,8 +41,6 @@ ItemContainer::ItemContainer(Inventory *inventory): mInventory(inventory) { ResourceManager *resman = ResourceManager::getInstance(); - mItemset = resman->getSpriteset("graphics/sprites/items.png", 32, 32); - if (!mItemset) logger->error("Unable to load items.png"); mSelImg = resman->getImage("graphics/gui/selection.png"); if (!mSelImg) logger->error("Unable to load selection.png"); @@ -55,7 +53,6 @@ ItemContainer::ItemContainer(Inventory *inventory): ItemContainer::~ItemContainer() { - mItemset->decRef(); mSelImg->decRef(); } @@ -73,8 +70,8 @@ void ItemContainer::logic() void ItemContainer::draw(gcn::Graphics* graphics) { - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 10; + int gridWidth = 36; //(item icon width + 4) + int gridHeight = 42; //(item icon height + 10) int columns = getWidth() / gridWidth; // Have at least 1 column @@ -113,11 +110,11 @@ void ItemContainer::draw(gcn::Graphics* graphics) } // Draw item icon - int idx; - if ((idx = item->getInfo()->getImage()) > 0) + Image* image; + if ((image = item->getInfo()->getImage()) != NULL) { dynamic_cast(graphics)->drawImage( - mItemset->get(idx - 1), itemX, itemY); + image, itemX, itemY); } // Draw item caption @@ -133,8 +130,8 @@ void ItemContainer::setWidth(int width) { gcn::Widget::setWidth(width); - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 14; + int gridWidth = 36; //item icon width + 4 + int gridHeight = 46; //item icon height + 14 int columns = getWidth() / gridWidth; if (columns < 1) @@ -158,8 +155,8 @@ void ItemContainer::selectNone() void ItemContainer::mousePress(int mx, int my, int button) { - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 10; + int gridWidth = 36; //(item icon width + 4) + int gridHeight = 42; //(item icon height + 10) int columns = getWidth() / gridWidth; if (button == gcn::MouseInput::LEFT || gcn::MouseInput::RIGHT) diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 63e8bf47..f52f37ec 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -30,7 +30,6 @@ class Image; class Inventory; class Item; -class Spriteset; /** * An item container. Used to show items in inventory and trade dialog. @@ -83,7 +82,6 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener private: Inventory *mInventory; - Spriteset *mItemset; Image *mSelImg; Item *mSelectedItem; diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 53849550..932b1f22 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -29,6 +29,8 @@ #include "progressbar.h" #include "../localplayer.h" +#include "../configuration.h" +#include "../graphics.h" #include "../utils/tostring.h" @@ -42,31 +44,40 @@ MiniStatusWindow::MiniStatusWindow(): mHpBar = new ProgressBar(1.0f, 100, 20, 0, 171, 34); mMpBar = new ProgressBar(1.0f, 100, 20, 26, 102, 230); + mXpBar = new ProgressBar(1.0f, 100, 20, 143, 192, 211); mHpLabel = new gcn::Label(""); mMpLabel = new gcn::Label(""); + mXpLabel = new gcn::Label(""); mHpBar->setPosition(0, 3); mMpBar->setPosition(mHpBar->getWidth() + 3, 3); + mXpBar->setPosition(mMpBar->getX() + mMpBar->getWidth() + 3, 3); mHpLabel->setDimension(mHpBar->getDimension()); mMpLabel->setDimension(mMpBar->getDimension()); + mXpLabel->setDimension(mXpBar->getDimension()); mHpLabel->setForegroundColor(gcn::Color(255, 255, 255)); mMpLabel->setForegroundColor(gcn::Color(255, 255, 255)); + mXpLabel->setForegroundColor(gcn::Color(255, 255, 255)); mHpLabel->setFont(speechFont); mMpLabel->setFont(speechFont); + mXpLabel->setFont(speechFont); mHpLabel->setAlignment(gcn::Graphics::CENTER); mMpLabel->setAlignment(gcn::Graphics::CENTER); + mXpLabel->setAlignment(gcn::Graphics::CENTER); add(mHpBar); add(mMpBar); + add(mXpBar); add(mHpLabel); add(mMpLabel); + add(mXpLabel); - setDefaultSize(0, 0, mMpBar->getX() + mMpBar->getWidth(), - mMpBar->getY() + mMpBar->getHeight()); + setDefaultSize(0, 0, mXpBar->getX() + mXpBar->getWidth(), + mXpBar->getY() + mXpBar->getHeight()); } void MiniStatusWindow::update() @@ -85,12 +96,33 @@ void MiniStatusWindow::update() mHpBar->setColor(0, 171, 34); // Green } - mHpBar->setProgress((float)player_node->mHp / (float)player_node->mMaxHp); - // mpBar->setProgress((float)player_node->mp / (float)player_node->maxMp); + mHpBar->setProgress((float) player_node->mHp / player_node->mMaxHp); + // mMpBar->setProgress((float) player_node->mMp / player_node->mMaxMp); + mXpBar->setProgress((float) player_node->mXp / player_node->mXpForNextLevel); - // Update and center labels + // Update labels mHpLabel->setCaption(toString(player_node->mHp)); mMpLabel->setCaption(toString(player_node->mMp)); + + std::stringstream updatedText; + updatedText << (int) ( + (float) player_node->mXp / + player_node->mXpForNextLevel * 100) << "%"; + + // Displays the number of monsters to next lvl + // (disabled for now but interesting idea) + /* + if(config.getValue("xpBarMonsterCounterExp", 0)!=0) + { + updatedText << " | " + << (int)(((float)player_node->mXpForNextLevel - (float)player_node->mXp) + / (float)config.getValue("xpBarMonsterCounterExp", 0)) + << " " + << config.getValue("xpBarMonsterCounterName", "Monsters") <<" left..."; + } + */ + + mXpLabel->setCaption(updatedText.str()); } void MiniStatusWindow::draw(gcn::Graphics *graphics) diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index f56f847c..718fe140 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -56,11 +56,15 @@ class MiniStatusWindow : public Window */ void update(); - /** + /* * Mini Status Bars */ - ProgressBar *mHpBar, *mMpBar; - gcn::Label *mHpLabel, *mMpLabel; + ProgressBar *mHpBar; + ProgressBar *mMpBar; + ProgressBar *mXpBar; + gcn::Label *mHpLabel; + gcn::Label *mMpLabel; + gcn::Label *mXpLabel; }; #endif diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 6af9119b..d12ace75 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -43,7 +43,7 @@ Setup::Setup(): Window("Setup") { int width = 230; - int height = 185; + int height = 225; setContentSize(width, height); const char *buttonNames[] = { @@ -58,7 +58,7 @@ Setup::Setup(): } TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, 220, 150)); + panel->setDimension(gcn::Rectangle(5, 5, 220, 185)); panel->setOpaque(false); SetupTab *tab; diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index 36b0ee20..d9212728 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -26,22 +26,31 @@ #include #include "button.h" - +#include "checkbox.h" +#include "../configuration.h" #include "../joystick.h" extern Joystick *joystick; Setup_Joystick::Setup_Joystick(): mCalibrateLabel(new gcn::Label("Press the button to start calibration")), - mCalibrateButton(new Button("Calibrate", "calibrate", this)) + mCalibrateButton(new Button("Calibrate", "calibrate", this)), + mJoystickEnabled(new CheckBox("Enable joystick")) { setOpaque(false); + mJoystickEnabled->setPosition(10, 10); + mCalibrateLabel->setPosition(10, 25); + mCalibrateButton->setPosition(10, 30 + mCalibrateLabel->getHeight()); + + mOriginalJoystickEnabled = (joystick ? joystick->isEnabled() : false); + mJoystickEnabled->setMarked(mOriginalJoystickEnabled); - mCalibrateLabel->setPosition(5, 10); - mCalibrateButton->setPosition(10, 20 + mCalibrateLabel->getHeight()); + mJoystickEnabled->setEventId("joystickEnabled"); + mJoystickEnabled->addActionListener(this); add(mCalibrateLabel); add(mCalibrateButton); + add(mJoystickEnabled); } void Setup_Joystick::action(const std::string &event, gcn::Widget *widget) @@ -50,13 +59,37 @@ void Setup_Joystick::action(const std::string &event, gcn::Widget *widget) return; } - if (joystick->isCalibrating()) { - mCalibrateButton->setCaption("Calibrate"); - mCalibrateLabel->setCaption("Press the button to start calibration"); - joystick->finishCalibration(); - } else { - mCalibrateButton->setCaption("Stop"); - mCalibrateLabel->setCaption("Rotate the stick"); - joystick->startCalibration(); + if (event == "joystickEnabled") + { + joystick->setEnabled(mJoystickEnabled->isMarked()); + } + else + { + if (joystick->isCalibrating()) { + mCalibrateButton->setCaption("Calibrate"); + mCalibrateLabel->setCaption( + "Press the button to start calibration"); + joystick->finishCalibration(); + } else { + mCalibrateButton->setCaption("Stop"); + mCalibrateLabel->setCaption("Rotate the stick"); + joystick->startCalibration(); + } } } + +void Setup_Joystick::cancel() +{ + if (joystick) + { + joystick->setEnabled(mOriginalJoystickEnabled); + } + mJoystickEnabled->setMarked(mOriginalJoystickEnabled); +} + +void Setup_Joystick::apply() +{ + config.setValue("joystickEnabled", + joystick ? joystick->isEnabled() : false); +} + diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h index da773c8f..4cc2b3d9 100644 --- a/src/gui/setup_joystick.h +++ b/src/gui/setup_joystick.h @@ -35,14 +35,16 @@ class Setup_Joystick : public SetupTab, public gcn::ActionListener public: Setup_Joystick(); - void apply() {} - void cancel() {} + void apply(); + void cancel(); void action(const std::string& eventId, gcn::Widget* widget); private: gcn::Label *mCalibrateLabel; gcn::Button *mCalibrateButton; + bool mOriginalJoystickEnabled; + gcn::CheckBox *mJoystickEnabled; }; #endif diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 7ac226d3..7c72975a 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -115,7 +115,13 @@ Setup_Video::Setup_Video(): mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox("FPS Limit: ")), mFpsSlider(new Slider(10, 200)), - mFpsField(new TextField()) + mFpsField(new TextField()), + mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 32)), + mScrollLazinessSlider(new Slider(1, 64)), + mScrollLazinessField(new TextField()), + mOriginalScrollRadius((int) config.getValue("ScrollRadius", 32)), + mScrollRadiusSlider(new Slider(0, 128)), + mScrollRadiusField(new TextField()) { setOpaque(false); @@ -153,12 +159,36 @@ Setup_Video::Setup_Video(): mAlphaSlider->setEventId("guialpha"); mFpsCheckBox->setEventId("fpslimitcheckbox"); mFpsSlider->setEventId("fpslimitslider"); + mScrollRadiusSlider->setEventId("scrollradiusslider"); + mScrollRadiusField->setEventId("scrollradiusfield"); + mScrollLazinessSlider->setEventId("scrolllazinessslider"); + mScrollLazinessField->setEventId("scrolllazinessfield"); mCustomCursorCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); mFpsCheckBox->addActionListener(this); mFpsSlider->addActionListener(this); mFpsField->addKeyListener(this); + mScrollRadiusSlider->addActionListener(this); + mScrollRadiusField->addKeyListener(this); + mScrollLazinessSlider->addActionListener(this); + mScrollLazinessField->addKeyListener(this); + + mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 120, 75, 10)); + gcn::Label *scrollRadiusLabel = new gcn::Label("Scroll radius"); + scrollRadiusLabel->setPosition(90, 120); + mScrollRadiusField->setPosition(180, 120); + mScrollRadiusField->setWidth(30); + mScrollRadiusField->setText(toString(mOriginalScrollRadius)); + mScrollRadiusSlider->setValue(mOriginalScrollRadius); + + mScrollLazinessSlider->setDimension(gcn::Rectangle(10, 140, 75, 10)); + gcn::Label *scrollLazinessLabel = new gcn::Label("Scroll laziness"); + scrollLazinessLabel->setPosition(90, 140); + mScrollLazinessField->setPosition(180, 140); + mScrollLazinessField->setWidth(30); + mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); + mScrollLazinessSlider->setValue(mOriginalScrollLaziness); add(scrollArea); add(mFsCheckBox); @@ -169,6 +199,12 @@ Setup_Video::Setup_Video(): add(mFpsCheckBox); add(mFpsSlider); add(mFpsField); + add(mScrollRadiusSlider); + add(scrollRadiusLabel); + add(mScrollRadiusField); + add(mScrollLazinessSlider); + add(scrollLazinessLabel); + add(mScrollLazinessField); } Setup_Video::~Setup_Video() @@ -225,6 +261,27 @@ void Setup_Video::apply() mOpenGLEnabled = config.getValue("opengl", 0); } +int +Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, + const std::string &configName) +{ + int value; + std::stringstream temp(field->getText()); + temp >> value; + if (value < slider->getScaleStart()) + { + value = (int) slider->getScaleStart(); + } + else if (value > slider->getScaleEnd()) + { + value = (int) slider->getScaleEnd(); + } + field->setText(toString(value)); + slider->setValue(value); + config.setValue(configName, value); + return value; +} + void Setup_Video::cancel() { mFsCheckBox->setMarked(mFullScreenEnabled); @@ -232,6 +289,11 @@ void Setup_Video::cancel() mCustomCursorCheckBox->setMarked(mCustomCursorEnabled); mAlphaSlider->setValue(mOpacity); + mScrollRadiusField->setText(toString(mOriginalScrollRadius)); + mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); + updateSlider(mScrollRadiusSlider, mScrollRadiusField, "ScrollRadius"); + updateSlider(mScrollLazinessSlider, mScrollLazinessField, "ScrollLaziness"); + config.setValue("screen", mFullScreenEnabled ? 1 : 0); config.setValue("customcursor", mCustomCursorEnabled ? 1 : 0); config.setValue("guialpha", mOpacity); @@ -254,6 +316,18 @@ void Setup_Video::action(const std::string &event, gcn::Widget *widget) mFps = (int)mFpsSlider->getValue(); mFpsField->setText(toString(mFps)); } + else if (event == "scrollradiusslider") + { + int val = (int)mScrollRadiusSlider->getValue(); + mScrollRadiusField->setText(toString(val)); + config.setValue("ScrollRadius", val); + } + else if (event == "scrolllazinessslider") + { + int val = (int)mScrollLazinessSlider->getValue(); + mScrollLazinessField->setText(toString(val)); + config.setValue("ScrollLaziness", val); + } else if (event == "fpslimitcheckbox") { if (mFpsCheckBox->isMarked()) @@ -293,4 +367,6 @@ void Setup_Video::keyPress(const gcn::Key &key) mFpsField->setText(""); mFps = 0; } + updateSlider(mScrollRadiusSlider, mScrollRadiusField, "ScrollRadius"); + updateSlider(mScrollLazinessSlider, mScrollLazinessField, "ScrollLaziness"); } diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index d0a10925..a3fd8884 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -59,10 +59,26 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, gcn::CheckBox *mFsCheckBox; gcn::CheckBox *mOpenGLCheckBox; gcn::CheckBox *mCustomCursorCheckBox; + gcn::Slider *mAlphaSlider; gcn::CheckBox *mFpsCheckBox; gcn::Slider *mFpsSlider; gcn::TextField *mFpsField; + + int mOriginalScrollLaziness; + gcn::Slider *mScrollLazinessSlider; + gcn::TextField *mScrollLazinessField; + + int mOriginalScrollRadius; + gcn::Slider *mScrollRadiusSlider; + gcn::TextField *mScrollRadiusField; + + void + updateSliders(bool originalValues); + + int + updateSlider(gcn::Slider *slider, gcn::TextField *field, + const std::string &configName); }; #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 9a07111f..2172baa8 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -63,6 +63,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): mModal(modal), mResizable(false), mMouseResize(false), + mSticky(false), mMinWinWidth(100), mMinWinHeight(28), mMaxWinWidth(INT_MAX), @@ -243,6 +244,26 @@ bool Window::isResizable() return mResizable; } +void Window::setSticky(bool sticky) +{ + mSticky = sticky; +} + +bool Window::isSticky() { + return mSticky; +} + +void Window::setVisible(bool visible) { + if(isSticky()) + { + gcn::Window::setVisible(true); + } + else + { + gcn::Window::setVisible(visible); + } +} + void Window::scheduleDelete() { windowContainer->scheduleDelete(this); diff --git a/src/gui/window.h b/src/gui/window.h index 42ce444c..51c876e3 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -133,6 +133,25 @@ class Window : public gcn::Window */ void setMaxHeight(unsigned int height); + /** + * Sets whether the window is sticky. + * A sticky window will not have its visibility set to false + * on a general setVisible(false) call. + */ + void setSticky(bool sticky); + + /** + * Returns whether the window is sticky. + */ + bool isSticky(); + + /** + * Overloads window setVisible by guichan to allow sticky window + * Handling + */ + + void setVisible(bool visible); + /** * Returns the parent window. * @@ -204,6 +223,7 @@ class Window : public gcn::Window bool mModal; /**< Window is modal */ bool mResizable; /**< Window can be resized */ bool mMouseResize; /**< Window is being resized */ + bool mSticky; /**< Window resists minimzation */ int mMinWinWidth; /**< Minimum window width */ int mMinWinHeight; /**< Minimum window height */ int mMaxWinWidth; /**< Maximum window width */ diff --git a/src/joystick.cpp b/src/joystick.cpp index bb6e887b..a5dab4f4 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -59,10 +59,11 @@ Joystick::Joystick(int no): logger->log("Hats: %i", SDL_JoystickNumHats(mJoystick)); logger->log("Buttons: %i", SDL_JoystickNumButtons(mJoystick)); - mUpTolerance = (int)config.getValue("upTolerance", 100); - mDownTolerance = (int)config.getValue("downTolerance", 100); - mLeftTolerance = (int)config.getValue("leftTolerance", 100); - mRightTolerance = (int)config.getValue("rightTolerance", 100); + mEnabled = (int) config.getValue("joystickEnabled", 0) != 0; + mUpTolerance = (int) config.getValue("upTolerance", 100); + mDownTolerance = (int) config.getValue("downTolerance", 100); + mLeftTolerance = (int) config.getValue("leftTolerance", 100); + mRightTolerance = (int) config.getValue("rightTolerance", 100); } Joystick::~Joystick() @@ -73,6 +74,7 @@ Joystick::~Joystick() void Joystick::update() { mDirection = 0; + SDL_JoystickUpdate(); // When calibrating, don't bother the outside with our state @@ -81,6 +83,8 @@ void Joystick::update() return; }; + if (!mEnabled) return; + // X-Axis int position = SDL_JoystickGetAxis(mJoystick, 0); if (position >= mRightTolerance) @@ -144,7 +148,6 @@ void Joystick::doCalibration() } } - void Joystick::finishCalibration() { config.setValue("leftTolerance", mLeftTolerance); @@ -154,10 +157,7 @@ void Joystick::finishCalibration() mCalibrating = false; } -bool Joystick::buttonPressed(unsigned char no) +bool Joystick::buttonPressed(unsigned char no) const { - if (no > MAX_BUTTONS) - return false; - - return mButtons[no]; + return (no < MAX_BUTTONS) ? mButtons[no] : false; } diff --git a/src/joystick.h b/src/joystick.h index ebdfabeb..f0759add 100644 --- a/src/joystick.h +++ b/src/joystick.h @@ -30,12 +30,12 @@ class Joystick { public: /** - * Number of buttons we can handle + * Number of buttons we can handle. */ static const unsigned char MAX_BUTTONS = 6; /** - * Directions, to be used as bitmask values + * Directions, to be used as bitmask values. */ static const char UP = 1; static const char DOWN = 2; @@ -43,12 +43,12 @@ class Joystick static const char RIGHT = 8; /** - * Initializes the joystick subsystem + * Initializes the joystick subsystem. */ static void init(); /** - * Returns the number of available joysticks + * Returns the number of available joysticks. */ static int getNumberOfJoysticks() { return joystickCount; } @@ -60,21 +60,33 @@ class Joystick ~Joystick(); + bool + isEnabled() const { return mEnabled; } + + void + setEnabled(bool enabled) { mEnabled = enabled; } + /** * Updates the direction and button information. */ - void update(); + void + update(); + + void + startCalibration(); + + void + finishCalibration(); - void startCalibration(); - void finishCalibration(); - bool isCalibrating() { return mCalibrating; }; + bool + isCalibrating() const { return mCalibrating; } - bool buttonPressed(unsigned char no); + bool buttonPressed(unsigned char no) const; - bool isUp() { return mDirection & UP; }; - bool isDown() { return mDirection & DOWN; }; - bool isLeft() { return mDirection & LEFT; }; - bool isRight() { return mDirection & RIGHT; }; + bool isUp() const { return mDirection & UP; }; + bool isDown() const { return mDirection & DOWN; }; + bool isLeft() const { return mDirection & LEFT; }; + bool isRight() const { return mDirection & RIGHT; }; protected: unsigned char mDirection; @@ -83,6 +95,7 @@ class Joystick int mUpTolerance, mDownTolerance, mLeftTolerance, mRightTolerance; bool mCalibrating; + bool mEnabled; static int joystickCount; diff --git a/src/main.cpp b/src/main.cpp index 573b1a79..f540dacd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -330,6 +330,7 @@ struct Options bool chooseDefault; std::string username; std::string password; + std::string playername; }; void printHelp() @@ -341,13 +342,14 @@ void printHelp() << " -u --skipupdate : Skip the update process" << std::endl << " -U --username : Login with this username" << std::endl << " -P --password : Login with this password" << std::endl - << " -D --default : Bypass the login process with default settings" + << " -D --default : Bypass the login process with default settings" << std::endl + << " -p --playername : Login with this player" << std::endl; } void parseOptions(int argc, char *argv[], Options &options) { - const char *optstring = "huU:P:D"; + const char *optstring = "huU:P:Dp:"; const struct option long_options[] = { { "help", no_argument, 0, 'h' }, @@ -355,6 +357,7 @@ void parseOptions(int argc, char *argv[], Options &options) { "username", required_argument, 0, 'U' }, { "password", required_argument, 0, 'P' }, { "default", no_argument, 0, 'D' }, + { "playername", required_argument, 0, 'p' }, { 0 } }; @@ -382,6 +385,9 @@ void parseOptions(int argc, char *argv[], Options &options) case 'D': options.chooseDefault = true; break; + case 'p': + options.playername = optarg; + break; } } } @@ -668,7 +674,20 @@ int main(int argc, char *argv[]) case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); currentDialog = new CharSelectDialog(&charInfo); - if (options.chooseDefault) { + if (options.playername != "") { + n_character = 0; + while (((CharSelectDialog*) currentDialog)->getName() + != options.playername && + n_character < MAX_SLOT + 1) + { + ((CharSelectDialog*) currentDialog)->action("next", + NULL); + ((CharSelectDialog*) currentDialog)->updatePlayerInfo(); + n_character++; + } + n_character = MAX_SLOT + 1; + } + if (options.chooseDefault || options.playername != "") { ((CharSelectDialog*)currentDialog)->action("ok", NULL); } diff --git a/src/map.cpp b/src/map.cpp index 1b2ce1e8..cbebc41c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -60,7 +60,8 @@ struct Location Map::Map(int width, int height, int tileWidth, int tileHeight): mWidth(width), mHeight(height), mTileWidth(tileWidth), mTileHeight(tileHeight), - mOnClosedList(1), mOnOpenList(2) + mOnClosedList(1), mOnOpenList(2), + mLastScrollX(0.0f), mLastScrollY(0.0f) { mMetaTiles = new MetaTile[mWidth * mHeight]; mTiles = new Image*[mWidth * mHeight * 3]; @@ -68,12 +69,18 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): Map::~Map() { + // clean up map data delete[] mMetaTiles; delete[] mTiles; - - // Clean up tilesets + // clean up tilesets for_each(mTilesets.begin(), mTilesets.end(), make_dtor(mTilesets)); mTilesets.clear(); + // clean up overlays + std::list::iterator i; + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + (*i).image->decRef(); + } } void @@ -159,6 +166,106 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) } } +void +Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail) +{ + static int lastTick = tick_time; + + // detail 0: no overlays + if (detail <= 0) return; + + std::list::iterator i; + + // Avoid freaking out when tick_time overflows + if (tick_time < lastTick) + { + lastTick = tick_time; + } + + if (mLastScrollX == 0.0f && mLastScrollY == 0.0f) + { + // first call - initialisation + mLastScrollX = scrollX; + mLastScrollY = scrollY; + } + + //update Overlays + while (lastTick < tick_time) + { + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + if ((*i).image != NULL) + { + //apply self scrolling + (*i).scrollX -= (*i).scrollSpeedX; + (*i).scrollY -= (*i).scrollSpeedY; + + //apply parallaxing + (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax; + (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax; + + //keep the image pattern on the screen + while ((*i).scrollX > (*i).image->getWidth()) + { + (*i).scrollX -= (*i).image->getWidth(); + } + while ((*i).scrollY > (*i).image->getHeight()) + { + (*i).scrollY -= (*i).image->getHeight(); + } + while ((*i).scrollX < 0) + { + (*i).scrollX += (*i).image->getWidth(); + } + while ((*i).scrollY < 0) + { + (*i).scrollY += (*i).image->getHeight(); + } + } + } + mLastScrollX = scrollX; + mLastScrollY = scrollY; + lastTick++; + + // detail 1: only one overlay, higher: all overlays + if (detail == 1) break; + } + + //draw overlays + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + if ((*i).image != NULL) + { + graphics->drawImagePattern ( (*i).image, + 0 - (int)(*i).scrollX, + 0 - (int)(*i).scrollY, + graphics->getWidth() + (int)(*i).scrollX, + graphics->getHeight() + (int)(*i).scrollY + ); + }; + // detail 1: only one overlay, higher: all overlays + if (detail == 1) break; + }; +} + +void +Map::setOverlay(Image *image, float speedX, float speedY, float parallax) +{ + if (image != NULL) + { + AmbientOverlay newOverlay; + + newOverlay.image = image; + newOverlay.parallax = parallax; + newOverlay.scrollSpeedX = speedX; + newOverlay.scrollSpeedY = speedY; + newOverlay.scrollX = 0; + newOverlay.scrollY = 0; + + mOverlays.push_back(newOverlay); + } +} + void Map::setTileWithGid(int x, int y, int layer, int gid) { diff --git a/src/map.h b/src/map.h index a91b815f..317a0b59 100644 --- a/src/map.h +++ b/src/map.h @@ -41,6 +41,8 @@ typedef Tilesets::iterator TilesetIterator; typedef std::list Sprites; typedef Sprites::iterator SpriteIterator; +extern volatile int tick_time; + /** * A meta tile stores additional information about a location on a tile map. * This is information that doesn't need to be repeated for each tile in each @@ -63,6 +65,16 @@ struct MetaTile bool walkable; /**< Can beings walk on this tile */ }; +struct AmbientOverlay +{ + Image *image; + float parallax; + float scrollX; + float scrollY; + float scrollSpeedX; + float scrollSpeedY; +}; + /** * A tile map. */ @@ -80,10 +92,20 @@ class Map : public Properties ~Map(); /** - * Draws the map to the given graphics output. + * Draws a map layer to the given graphics output. */ void draw(Graphics *graphics, int scrollX, int scrollY, int layer); + /** + * Sets Overlay Graphic and Scrollspeed + */ + void setOverlay(Image *image, float speedX, float speedY, float parallax); + + /** + * Draws the overlay graphic to the given graphics output. + */ + void drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail); + /** * Sets the size of the map. This will destroy any existing map data. */ @@ -198,6 +220,12 @@ class Map : public Properties // Pathfinding members int mOnClosedList, mOnOpenList; + + //overlay Data + AmbientOverlay mFoo; + std::list mOverlays; + float mLastScrollX; + float mLastScrollY; }; #endif diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index cb1883b0..c4192bc5 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -28,6 +28,7 @@ #include "messagein.h" #include "protocol.h" +#include "../resources/iteminfo.h" #include "../item.h" #include "../localplayer.h" @@ -91,6 +92,14 @@ void InventoryHandler::handleMessage(MessageIn &msg) if (msg.readByte()> 0) { chatWindow->chatLog("Unable to pick up item", BY_SERVER); } else { + ItemInfo *itemInfo = itemDb->getItemInfo(itemId); + if (itemInfo) { + chatWindow->chatLog("You picked up a " + + itemInfo->getName(), BY_SERVER); + } else { + chatWindow->chatLog("You picked up an unknown item", + BY_SERVER); + } player_node->addInvItem(index, itemId, amount, equipType != 0); } break; diff --git a/src/player.cpp b/src/player.cpp index b635397e..af9a3344 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -84,6 +84,7 @@ Player::setSex(Uint8 sex) } Being::setSex(sex); + resetAnimations(); } } @@ -99,6 +100,7 @@ Player::setHairColor(Uint16 color) newHairSprite->setDirection(getSpriteDirection()); mSprites[HAIR_SPRITE] = newHairSprite; + resetAnimations(); setAction(mAction); } @@ -118,6 +120,7 @@ Player::setHairStyle(Uint16 style) newHairSprite->setDirection(getSpriteDirection()); mSprites[HAIR_SPRITE] = newHairSprite; + resetAnimations(); setAction(mAction); } @@ -155,6 +158,7 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) equipmentSprite->setDirection(getSpriteDirection()); mSprites[position] = equipmentSprite; + resetAnimations(); setAction(mAction); } @@ -162,4 +166,14 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) Being::setVisibleEquipment(slot, id); } - +void +Player::resetAnimations() +{ + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (mSprites[i] != NULL) + { + mSprites[i]->reset(); + } + } +} diff --git a/src/player.h b/src/player.h index d0d55cc8..65b0303d 100644 --- a/src/player.h +++ b/src/player.h @@ -57,6 +57,14 @@ class Player : public Being virtual void setVisibleEquipment(Uint8 slot, Uint8 id); + + private: + /** + * Resets all animations associated with this player. This is used to + * synchronize the animations after a new one has been added. + */ + void + resetAnimations(); }; #endif diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp new file mode 100644 index 00000000..5d39d832 --- /dev/null +++ b/src/resources/iteminfo.cpp @@ -0,0 +1,44 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "iteminfo.h" + +#include "resourcemanager.h" + +Image* +ItemInfo::getImage() { + if (mImage == NULL && mImageName != "") { + mImage = ResourceManager::getInstance()->getImage(mImageName); + } + return mImage; +} + +void +ItemInfo::setImage(const std::string &image) { + mImageName = "graphics/items/" + image; +} + +ItemInfo::~ItemInfo() { + if (mImage != NULL){ + mImage->decRef(); + } +} diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 54e7907b..afa2e857 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -26,6 +26,8 @@ #include +#include "image.h" + /** * Defines a class for storing item infos. */ @@ -38,7 +40,8 @@ class ItemInfo * Constructor. */ ItemInfo(): - mImage(0), + mImage(NULL), + mImageName(""), mArt(0), mType(0), mWeight(0), @@ -59,10 +62,10 @@ class ItemInfo getName() { return mName; } void - setImage(short image) { mImage = image; } + setImage(const std::string &image); - short - getImage() { return mImage; } + Image* + getImage(); void setDescription(const std::string &description) @@ -101,9 +104,10 @@ class ItemInfo /** * Destructor. */ - ~ItemInfo() {} + ~ItemInfo(); - short mImage; + Image* mImage; + std::string mImageName; short mArt; std::string mName; std::string mDescription; diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 63c0b036..a497b3c8 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -68,8 +68,8 @@ ItemManager::ItemManager() for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - int id = 0, image = 0, art = 0, type = 0, weight = 0, slot = 0; - std::string name = "", description = "", effect = ""; + int id = 0, art = 0, type = 0, weight = 0, slot = 0; + std::string name = "", description = "", effect = "", image = ""; if (!xmlStrEqual(node->name, BAD_CAST "item")) { continue; @@ -77,7 +77,7 @@ ItemManager::ItemManager() xmlChar *prop = NULL; READ_PROP(node, prop, "id", id, atoi); - READ_PROP(node, prop, "image", image, atoi); + READ_PROP(node, prop, "image", image, ); READ_PROP(node, prop, "art", art, atoi); READ_PROP(node, prop, "name", name, ); READ_PROP(node, prop, "description", description, ); @@ -86,6 +86,7 @@ ItemManager::ItemManager() READ_PROP(node, prop, "weight", weight, atoi); READ_PROP(node, prop, "slot", slot, atoi); + if (id && name != "") { ItemInfo *itemInfo = new ItemInfo(); @@ -100,6 +101,7 @@ ItemManager::ItemManager() mItemInfos[id] = itemInfo; } + if (id == 0) { logger->log("Item Manager: An item has no ID in items.xml!"); @@ -109,7 +111,7 @@ ItemManager::ItemManager() logger->log("Item Manager: An item has no name in items.xml!"); } - if (image == 0) + if (image == "") { logger->log("Item Manager: Missing image parameter for item: %i. %s", id, name.c_str()); @@ -141,7 +143,7 @@ ItemManager::ItemManager() } if (slot == 0) { - logger->log("Item Manager: Missing image parameter for item: %i. %s", + logger->log("Item Manager: Missing slot parameter for item: %i. %s", id, name.c_str()); } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 382b0797..c1ae911c 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -34,6 +34,7 @@ #include "../map.h" #include "../tileset.h" +#include "../utils/tostring.h" const unsigned int DEFAULT_TILE_WIDTH = 32; const unsigned int DEFAULT_TILE_HEIGHT = 32; @@ -213,6 +214,32 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) } } + //set Overlays + int i = 0; + ResourceManager *resman = ResourceManager::getInstance(); + + while (map->hasProperty("overlay" + toString(i) + "image")) + { + Image *overlayImage = resman->getImage(map->getProperty("overlay" + toString(i) + "image")); + float scrollX = 0.0f; + float scrollY = 0.0f; + float parallax = 0.0f; + if (map->hasProperty("overlay" + toString(i) + "scrollX")) + { + scrollX = atof(map->getProperty("overlay" + toString(i) + "scrollX").c_str()); + } + if (map->hasProperty("overlay" + toString(i) + "scrollY")) + { + scrollY = atof(map->getProperty("overlay" + toString(i) + "scrollY").c_str()); + } + if (map->hasProperty("overlay" + toString(i) + "parallax")) + { + parallax = atof(map->getProperty("overlay" + toString(i) + "parallax").c_str()); + } + map->setOverlay (overlayImage, scrollX, scrollY, parallax); + i++; + } + return map; } diff --git a/tmw.cbp b/tmw.cbp index d80ebe55..ff060fe4 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -48,6 +48,16 @@